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

Commit 9ee53a49 authored by Chong Zhang's avatar Chong Zhang
Browse files

MediaRecorder: pass capture fps in float

bug: 19460202

Change-Id: Ic8f2dc02dfd482c4b2065b16e28721fc6e3cf696
parent 96faa25f
Loading
Loading
Loading
Loading
+36 −9
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ StagefrightRecorder::StagefrightRecorder()
      mAudioSource(AUDIO_SOURCE_CNT),
      mVideoSource(VIDEO_SOURCE_LIST_END),
      mCaptureTimeLapse(false),
      mCaptureFps(0.0f),
      mStarted(false) {

    ALOGV("Constructor");
@@ -263,6 +264,31 @@ status_t StagefrightRecorder::setOutputFile(int fd, int64_t offset, int64_t leng
    return OK;
}

// Attempt to parse an float literal optionally surrounded by whitespace,
// returns true on success, false otherwise.
static bool safe_strtof(const char *s, float *val) {
    char *end;

    // It is lame, but according to man page, we have to set errno to 0
    // before calling strtof().
    errno = 0;
    *val = strtof(s, &end);

    if (end == s || errno == ERANGE) {
        return false;
    }

    // Skip trailing whitespace
    while (isspace(*end)) {
        ++end;
    }

    // For a successful return, the string must contain nothing but a valid
    // float literal optionally surrounded by whitespace.

    return *end == '\0';
}

// Attempt to parse an int64 literal optionally surrounded by whitespace,
// returns true on success, false otherwise.
static bool safe_strtoi64(const char *s, int64_t *val) {
@@ -546,8 +572,10 @@ status_t StagefrightRecorder::setParamTimeLapseEnable(int32_t timeLapseEnable) {
    return OK;
}

status_t StagefrightRecorder::setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs) {
    ALOGV("setParamTimeBetweenTimeLapseFrameCapture: %lld us", timeUs);
status_t StagefrightRecorder::setParamTimeLapseFps(float fps) {
    ALOGV("setParamTimeLapseFps: %.2f", fps);

    int64_t timeUs = (int64_t) (1000000.0 / fps + 0.5f);

    // Not allowing time more than a day
    if (timeUs <= 0 || timeUs > 86400*1E6) {
@@ -555,6 +583,7 @@ status_t StagefrightRecorder::setParamTimeBetweenTimeLapseFrameCapture(int64_t t
        return BAD_VALUE;
    }

    mCaptureFps = fps;
    mTimeBetweenTimeLapseFrameCaptureUs = timeUs;
    return OK;
}
@@ -682,11 +711,10 @@ status_t StagefrightRecorder::setParameter(
        if (safe_strtoi32(value.string(), &timeLapseEnable)) {
            return setParamTimeLapseEnable(timeLapseEnable);
        }
    } else if (key == "time-between-time-lapse-frame-capture") {
        int64_t timeBetweenTimeLapseFrameCaptureUs;
        if (safe_strtoi64(value.string(), &timeBetweenTimeLapseFrameCaptureUs)) {
            return setParamTimeBetweenTimeLapseFrameCapture(
                    timeBetweenTimeLapseFrameCaptureUs);
    } else if (key == "time-lapse-fps") {
        float fps;
        if (safe_strtof(value.string(), &fps)) {
            return setParamTimeLapseFps(fps);
        }
    } else {
        ALOGE("setParameter: failed to find key %s", key.string());
@@ -1619,8 +1647,7 @@ status_t StagefrightRecorder::setupMPEG4orWEBMRecording() {
        }

        if (mCaptureTimeLapse) {
            // TODO(chz): pass down fps in float from MediaRecorder.java
            mp4writer->setCaptureRate(1000000.0f / mTimeBetweenTimeLapseFrameCaptureUs);
            mp4writer->setCaptureRate(mCaptureFps);
        }

        if (mInterleaveDurationUs > 0) {
+2 −1
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ private:
    int32_t mTotalBitRate;

    bool mCaptureTimeLapse;
    float mCaptureFps;
    int64_t mTimeBetweenTimeLapseFrameCaptureUs;
    sp<CameraSourceTimeLapse> mCameraSourceTimeLapse;

@@ -155,7 +156,7 @@ private:
    status_t setParamAudioSamplingRate(int32_t sampleRate);
    status_t setParamAudioTimeScale(int32_t timeScale);
    status_t setParamTimeLapseEnable(int32_t timeLapseEnable);
    status_t setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs);
    status_t setParamTimeLapseFps(float fps);
    status_t setParamVideoEncodingBitRate(int32_t bitRate);
    status_t setParamVideoIFramesInterval(int32_t seconds);
    status_t setParamVideoEncoderProfile(int32_t profile);