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

Commit 48a7c1d2 authored by James Dong's avatar James Dong Committed by Android Git Automerger
Browse files

am 42a18c09: Check and clip some video encoding parameters against media...

am 42a18c09: Check and clip some video encoding parameters against media profiles before passing them to video encoder

Merge commit '42a18c09' into gingerbread-plus-aosp

* commit '42a18c09':
  Check and clip some video encoding parameters against media profiles before passing them to video encoder
parents d8402d78 42a18c09
Loading
Loading
Loading
Loading
+75 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@
#include <media/stagefright/MetaData.h>
#include <media/stagefright/MetaData.h>
#include <media/stagefright/OMXClient.h>
#include <media/stagefright/OMXClient.h>
#include <media/stagefright/OMXCodec.h>
#include <media/stagefright/OMXCodec.h>
#include <media/MediaProfiles.h>
#include <camera/ICamera.h>
#include <camera/ICamera.h>
#include <camera/Camera.h>
#include <camera/Camera.h>
#include <camera/CameraParameters.h>
#include <camera/CameraParameters.h>
@@ -561,6 +562,74 @@ status_t StagefrightRecorder::startAMRRecording() {
    return OK;
    return OK;
}
}


void StagefrightRecorder::clipVideoFrameRate() {
    LOGV("clipVideoFrameRate: encoder %d", mVideoEncoder);
    int minFrameRate = mEncoderProfiles->getVideoEncoderParamByName(
                        "enc.vid.fps.min", mVideoEncoder);
    int maxFrameRate = mEncoderProfiles->getVideoEncoderParamByName(
                        "enc.vid.fps.max", mVideoEncoder);
    if (mFrameRate < minFrameRate) {
        LOGW("Intended video encoding frame rate (%d fps) is too small"
             " and will be set to (%d fps)", mFrameRate, minFrameRate);
        mFrameRate = minFrameRate;
    } else if (mFrameRate > maxFrameRate) {
        LOGW("Intended video encoding frame rate (%d fps) is too large"
             " and will be set to (%d fps)", mFrameRate, maxFrameRate);
        mFrameRate = maxFrameRate;
    }
}

void StagefrightRecorder::clipVideoBitRate() {
    LOGV("clipVideoBitRate: encoder %d", mVideoEncoder);
    int minBitRate = mEncoderProfiles->getVideoEncoderParamByName(
                        "enc.vid.bps.min", mVideoEncoder);
    int maxBitRate = mEncoderProfiles->getVideoEncoderParamByName(
                        "enc.vid.bps.max", mVideoEncoder);
    if (mVideoBitRate < minBitRate) {
        LOGW("Intended video encoding bit rate (%d bps) is too small"
             " and will be set to (%d bps)", mVideoBitRate, minBitRate);
        mVideoBitRate = minBitRate;
    } else if (mVideoBitRate > maxBitRate) {
        LOGW("Intended video encoding bit rate (%d bps) is too large"
             " and will be set to (%d bps)", mVideoBitRate, maxBitRate);
        mVideoBitRate = maxBitRate;
    }
}

void StagefrightRecorder::clipVideoFrameWidth() {
    LOGV("clipVideoFrameWidth: encoder %d", mVideoEncoder);
    int minFrameWidth = mEncoderProfiles->getVideoEncoderParamByName(
                        "enc.vid.width.min", mVideoEncoder);
    int maxFrameWidth = mEncoderProfiles->getVideoEncoderParamByName(
                        "enc.vid.width.max", mVideoEncoder);
    if (mVideoWidth < minFrameWidth) {
        LOGW("Intended video encoding frame width (%d) is too small"
             " and will be set to (%d)", mVideoWidth, minFrameWidth);
        mVideoWidth = minFrameWidth;
    } else if (mVideoWidth > maxFrameWidth) {
        LOGW("Intended video encoding frame width (%d) is too large"
             " and will be set to (%d)", mVideoWidth, maxFrameWidth);
        mVideoWidth = maxFrameWidth;
    }
}

void StagefrightRecorder::clipVideoFrameHeight() {
    LOGV("clipVideoFrameHeight: encoder %d", mVideoEncoder);
    int minFrameHeight = mEncoderProfiles->getVideoEncoderParamByName(
                        "enc.vid.height.min", mVideoEncoder);
    int maxFrameHeight = mEncoderProfiles->getVideoEncoderParamByName(
                        "enc.vid.height.max", mVideoEncoder);
    if (mVideoHeight < minFrameHeight) {
        LOGW("Intended video encoding frame height (%d) is too small"
             " and will be set to (%d)", mVideoHeight, minFrameHeight);
        mVideoHeight = minFrameHeight;
    } else if (mVideoHeight > maxFrameHeight) {
        LOGW("Intended video encoding frame height (%d) is too large"
             " and will be set to (%d)", mVideoHeight, maxFrameHeight);
        mVideoHeight = maxFrameHeight;
    }
}

status_t StagefrightRecorder::startMPEG4Recording() {
status_t StagefrightRecorder::startMPEG4Recording() {
    mWriter = new MPEG4Writer(dup(mOutputFd));
    mWriter = new MPEG4Writer(dup(mOutputFd));


@@ -587,6 +656,11 @@ status_t StagefrightRecorder::startMPEG4Recording() {
    if (mVideoSource == VIDEO_SOURCE_DEFAULT
    if (mVideoSource == VIDEO_SOURCE_DEFAULT
            || mVideoSource == VIDEO_SOURCE_CAMERA) {
            || mVideoSource == VIDEO_SOURCE_CAMERA) {


        clipVideoBitRate();
        clipVideoFrameRate();
        clipVideoFrameWidth();
        clipVideoFrameHeight();

        int64_t token = IPCThreadState::self()->clearCallingIdentity();
        int64_t token = IPCThreadState::self()->clearCallingIdentity();
        if (mCamera == 0) {
        if (mCamera == 0) {
            mCamera = Camera::connect(0);
            mCamera = Camera::connect(0);
@@ -748,6 +822,7 @@ status_t StagefrightRecorder::reset() {
    mAudioBitRate  = 12200;
    mAudioBitRate  = 12200;
    mInterleaveDurationUs = 0;
    mInterleaveDurationUs = 0;
    mIFramesInterval = 1;
    mIFramesInterval = 1;
    mEncoderProfiles = MediaProfiles::getInstance();


    mOutputFd = -1;
    mOutputFd = -1;
    mFlags = 0;
    mFlags = 0;
+7 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ namespace android {
class Camera;
class Camera;
struct MediaSource;
struct MediaSource;
struct MediaWriter;
struct MediaWriter;
class MediaProfiles;


struct StagefrightRecorder : public MediaRecorderBase {
struct StagefrightRecorder : public MediaRecorderBase {
    StagefrightRecorder();
    StagefrightRecorder();
@@ -84,6 +85,8 @@ private:
    int mOutputFd;
    int mOutputFd;
    int32_t mFlags;
    int32_t mFlags;


    MediaProfiles *mEncoderProfiles;

    status_t startMPEG4Recording();
    status_t startMPEG4Recording();
    status_t startAMRRecording();
    status_t startAMRRecording();
    status_t startAACRecording();
    status_t startAACRecording();
@@ -96,6 +99,10 @@ private:
    status_t setParamInterleaveDuration(int32_t durationUs);
    status_t setParamInterleaveDuration(int32_t durationUs);
    status_t setParamIFramesInterval(int32_t interval);
    status_t setParamIFramesInterval(int32_t interval);
    status_t setParamMaxDurationOrFileSize(int64_t limit, bool limit_is_duration);
    status_t setParamMaxDurationOrFileSize(int64_t limit, bool limit_is_duration);
    void clipVideoBitRate();
    void clipVideoFrameRate();
    void clipVideoFrameWidth();
    void clipVideoFrameHeight();


    StagefrightRecorder(const StagefrightRecorder &);
    StagefrightRecorder(const StagefrightRecorder &);
    StagefrightRecorder &operator=(const StagefrightRecorder &);
    StagefrightRecorder &operator=(const StagefrightRecorder &);