Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5551797e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revise capture interval calculation in StagefrightRecorder" into oc-dev

parents 13f2ff3d a821d858
Loading
Loading
Loading
Loading
+8 −16
Original line number Original line Diff line number Diff line
@@ -709,26 +709,18 @@ status_t StagefrightRecorder::setParamCaptureFpsEnable(int32_t captureFpsEnable)
status_t StagefrightRecorder::setParamCaptureFps(double fps) {
status_t StagefrightRecorder::setParamCaptureFps(double fps) {
    ALOGV("setParamCaptureFps: %.2f", fps);
    ALOGV("setParamCaptureFps: %.2f", fps);


    constexpr int64_t k1E12 = 1000000000000ll;
    // FPS value is from Java layer where double follows IEEE-754, which is not
    int64_t fpsx1e12 = k1E12 * fps;
    // necessarily true for double here.
    if (fpsx1e12 == 0) {
    constexpr double kIeee754Epsilon = 2.220446049250313e-16;
        ALOGE("FPS is zero or too small");
    constexpr double kEpsilon = std::max(std::numeric_limits<double>::epsilon(), kIeee754Epsilon);
        return BAD_VALUE;
    // Not allowing fps less than 1 frame / day minus epsilon.
    }
    if (fps < 1.0 / 86400 - kEpsilon) {

        ALOGE("fps (%lf) is out of range (>= 1 frame / day)", fps);
    // This does not overflow since 10^6 * 10^12 < 2^63
    int64_t timeUs = 1000000ll * k1E12 / fpsx1e12;

    // Not allowing time more than a day and a millisecond for error margin.
    // Note: 1e12 / 86400 = 11574074.(074) and 1e18 / 11574074 = 86400000553;
    //       therefore 1 ms of margin should be sufficient.
    if (timeUs <= 0 || timeUs > 86400001000ll) {
        ALOGE("Time between frame capture (%lld) is out of range [0, 1 Day]", (long long)timeUs);
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }


    mCaptureFps = fps;
    mCaptureFps = fps;
    mTimeBetweenCaptureUs = timeUs;
    mTimeBetweenCaptureUs = std::llround(1e6 / fps);
    return OK;
    return OK;
}
}