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

Commit 63573083 authored by James Dong's avatar James Dong
Browse files

Don't change the video recording frame rate if it is not requested.

o set the default video frame rate to the current frame rate being used
o add check on whether the requested frame rate is supported
o fix an issue where the hardware video encoder setting was bypassed
o increases the max frame rate from 30 t0 120 frames per second
  the actual frame rate will be clipped if the requested frame rate is too
  high when recording starts by checking the hardware encoder capabilities

Change-Id: I1b47671d74da0ebcb9601bdca390d430cc048fbc
parent e09591ef
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -165,7 +165,8 @@ status_t StagefrightRecorder::setVideoSize(int width, int height) {

status_t StagefrightRecorder::setVideoFrameRate(int frames_per_second) {
    LOGV("setVideoFrameRate: %d", frames_per_second);
    if (frames_per_second <= 0 || frames_per_second > 30) {
    if ((frames_per_second <= 0 && frames_per_second != -1) ||
        frames_per_second > 120) {
        LOGE("Invalid video frame rate: %d", frames_per_second);
        return BAD_VALUE;
    }
@@ -960,7 +961,7 @@ void StagefrightRecorder::clipVideoFrameRate() {
                        "enc.vid.fps.min", mVideoEncoder);
    int maxFrameRate = mEncoderProfiles->getVideoEncoderParamByName(
                        "enc.vid.fps.max", mVideoEncoder);
    if (mFrameRate < minFrameRate) {
    if (mFrameRate < minFrameRate && mFrameRate != -1) {
        LOGW("Intended video encoding frame rate (%d fps) is too small"
             " and will be set to (%d fps)", mFrameRate, minFrameRate);
        mFrameRate = minFrameRate;
@@ -1035,6 +1036,10 @@ void StagefrightRecorder::clipVideoFrameHeight() {
}

status_t StagefrightRecorder::setupCameraSource(sp<CameraSource> *cameraSource) {
    status_t err = OK;
    if ((err = checkVideoEncoderCapabilities()) != OK) {
        return err;
    }
    Size videoSize;
    videoSize.width = mVideoWidth;
    videoSize.height = mVideoHeight;
@@ -1050,6 +1055,18 @@ status_t StagefrightRecorder::setupCameraSource(sp<CameraSource> *cameraSource)
    }
    CHECK(*cameraSource != NULL);

    // When frame rate is not set, the actual frame rate will be set to
    // the current frame rate being used.
    if (mFrameRate == -1) {
        int32_t frameRate = 0;
        CHECK ((*cameraSource)->getFormat()->findInt32(
                    kKeySampleRate, &frameRate));
        LOGI("Frame rate is not explicitly set. Use the current frame "
             "rate (%d fps)", frameRate);
        mFrameRate = frameRate;
    }

    CHECK(mFrameRate != -1);
    return OK;
}

@@ -1371,7 +1388,7 @@ status_t StagefrightRecorder::reset() {
    mVideoHeight   = 144;
    mAuxVideoWidth    = 176;
    mAuxVideoHeight   = 144;
    mFrameRate     = 20;
    mFrameRate     = -1;
    mVideoBitRate  = 192000;
    mAuxVideoBitRate = 192000;
    mSampleRate    = 8000;
+15 −0
Original line number Diff line number Diff line
@@ -313,6 +313,20 @@ status_t CameraSource::configureCamera(
    }

    if (frameRate != -1) {
        CHECK(frameRate > 0 && frameRate <= 120);
        const char* supportedFrameRates =
                params->get(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES);
        CHECK(supportedFrameRates != NULL);
        LOGV("Supported frame rates: %s", supportedFrameRates);
        char buf[4];
        snprintf(buf, 4, "%d", frameRate);
        if (strstr(supportedFrameRates, buf) == NULL) {
            LOGE("Requested frame rate (%d) is not supported: %s",
                frameRate, supportedFrameRates);
            return BAD_VALUE;
        }

        // The frame rate is supported, set the camera to the requested value.
        params->setPreviewFrameRate(frameRate);
        isCameraParamChanged = true;
    } else {  // frameRate == -1
@@ -517,6 +531,7 @@ status_t CameraSource::init(
    mMeta->setInt32(kKeyHeight,      mVideoSize.height);
    mMeta->setInt32(kKeyStride,      mVideoSize.width);
    mMeta->setInt32(kKeySliceHeight, mVideoSize.height);
    mMeta->setInt32(kKeySampleRate,  mVideoFrameRate);
    return OK;
}