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

Commit a821d858 authored by Wonsik Kim's avatar Wonsik Kim
Browse files

Revise capture interval calculation in StagefrightRecorder

Bug: 37302530
Test: cts-tradefed run cts-dev --module CtsMediaTestCases --test android.media.cts.MediaRecorderTest
Change-Id: Idfb4aea475a40f928380835db9e6f304fe435377
parent 5c1b4f3a
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;
}