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

Commit ef67203e authored by Praveen Chavan's avatar Praveen Chavan Committed by Linux Build Service Account
Browse files

Stagefright: Allow setting high-framerates in CameraSource

CameraSource (legacy Camera) treats framerate set via
MediaRecorder.setVideoFrameRate as _both_ camera-preview-fps
and video-encoder-fps. Trying to set high fps for encoder
will inadvertently fail trying to set the same value for
camera-preview.
Read the custom camera parameter to detect if this is a
high-speed request, selectively set the fps only for
video, and default to 30fps for preview fps.

Squash the below change as well

Stagefright: Update start-time once input-time reaches expected start-time
Change-Id: I696aef51398ed59be0bad7e0e6f9a85504c1f408

Change-Id: If66211dd81b2a08d4df4c6f23e87304e9e7013f4
parent b8bec911
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -313,6 +313,12 @@ status_t CameraSource::isCameraColorFormatSupported(
    return OK;
}

static int32_t getHighSpeedFrameRate(const CameraParameters& params) {
    const char* hsr = params.get("video-hsr");
    int32_t rate = (hsr != NULL && strncmp(hsr, "off", 3)) ? atoi(hsr) : 0;
    return rate > 240 ? 240 : rate;
}

/*
 * Configure the camera to use the requested video size
 * (width and height) and/or frame rate. If both width and
@@ -365,6 +371,10 @@ status_t CameraSource::configureCamera(
                params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES);
        CHECK(supportedFrameRates != NULL);
        ALOGV("Supported frame rates: %s", supportedFrameRates);
        if (getHighSpeedFrameRate(*params)) {
            ALOGI("Use default 30fps for HighSpeed %dfps", frameRate);
            frameRate = 30;
        }
        char buf[4];
        snprintf(buf, 4, "%d", frameRate);
        if (strstr(supportedFrameRates, buf) == NULL) {
@@ -466,6 +476,8 @@ status_t CameraSource::checkFrameRate(
        ALOGE("Failed to retrieve preview frame rate (%d)", frameRateActual);
        return UNKNOWN_ERROR;
    }
    int32_t highSpeedRate = getHighSpeedFrameRate(params);
    frameRateActual = highSpeedRate ? highSpeedRate : frameRateActual;

    // Check the actual video frame rate against the target/requested
    // video frame rate.
+6 −0
Original line number Diff line number Diff line
@@ -296,6 +296,12 @@ bool CameraSourceTimeLapse::skipFrameAndModifyTimeStamp(int64_t *timestampUs) {

        mLastTimeLapseFrameRealTimestampUs = *timestampUs;
        *timestampUs = mLastFrameTimestampUs + mTimeBetweenTimeLapseVideoFramesUs;
        // Update start-time once the captured-time reaches the expected start-time.
        // Not doing so will result in CameraSource always dropping frames since
        // updated-timestamp will never intersect start-timestamp
        if ((mNumFramesReceived == 0 && mLastTimeLapseFrameRealTimestampUs >= mStartTimeUs)) {
            mStartTimeUs = *timestampUs;
        }
        return false;
    }
    return false;