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

Commit cfa7fbb4 authored by Wonsik Kim's avatar Wonsik Kim Committed by android-build-merger
Browse files

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

am: 5551797e

Change-Id: I002fc0da6bdf7ee2baddc160a7936a0f5ed46e14
parents d95b316b 5551797e
Loading
Loading
Loading
Loading
+8 −16
Original line number Diff line number Diff line
@@ -709,26 +709,18 @@ status_t StagefrightRecorder::setParamCaptureFpsEnable(int32_t captureFpsEnable)
status_t StagefrightRecorder::setParamCaptureFps(double fps) {
    ALOGV("setParamCaptureFps: %.2f", fps);

    constexpr int64_t k1E12 = 1000000000000ll;
    int64_t fpsx1e12 = k1E12 * fps;
    if (fpsx1e12 == 0) {
        ALOGE("FPS is zero or too small");
        return BAD_VALUE;
    }

    // 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);
    // FPS value is from Java layer where double follows IEEE-754, which is not
    // necessarily true for double here.
    constexpr double kIeee754Epsilon = 2.220446049250313e-16;
    constexpr double kEpsilon = std::max(std::numeric_limits<double>::epsilon(), kIeee754Epsilon);
    // 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);
        return BAD_VALUE;
    }

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