From 6feaa46496bae85adbe10e84611592612f898081 Mon Sep 17 00:00:00 2001 From: James Dong Date: Sun, 20 Jun 2010 08:20:54 -0700 Subject: Enable passing parameters to the MediaWriter at runtime (at start() call). - estimate the moov box size for mp4 file writer based on the file size/duration limit and target bit rate. - can switch to use 64 bit file offset at runtime rebased Change-Id: Ibbe1f57e91ab2605820d5d96e8048d11e5559c53 --- .../libmediaplayerservice/StagefrightRecorder.cpp | 26 ++++++++++++++++++---- media/libmediaplayerservice/StagefrightRecorder.h | 2 ++ 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'media/libmediaplayerservice') diff --git a/media/libmediaplayerservice/StagefrightRecorder.cpp b/media/libmediaplayerservice/StagefrightRecorder.cpp index ba04d1b..6834491 100644 --- a/media/libmediaplayerservice/StagefrightRecorder.cpp +++ b/media/libmediaplayerservice/StagefrightRecorder.cpp @@ -316,6 +316,13 @@ status_t StagefrightRecorder::setParamIFramesInterval(int32_t interval) { return OK; } +status_t StagefrightRecorder::setParam64BitFileOffset(bool use64Bit) { + LOGV("setParam64BitFileOffset: %s", + use64Bit? "use 64 bit file offset": "use 32 bit file offset"); + mUse64BitFileOffset = use64Bit; + return OK; +} + status_t StagefrightRecorder::setParameter( const String8 &key, const String8 &value) { LOGV("setParameter: key (%s) => value (%s)", key.string(), value.string()); @@ -361,6 +368,11 @@ status_t StagefrightRecorder::setParameter( if (safe_strtoi32(value.string(), &interval)) { return setParamIFramesInterval(interval); } + } else if (key == "param-use-64bit-offset") { + int32_t use64BitOffset; + if (safe_strtoi32(value.string(), &use64BitOffset)) { + return setParam64BitFileOffset(use64BitOffset != 0); + } } else { LOGE("setParameter: failed to find key %s", key.string()); } @@ -633,6 +645,7 @@ void StagefrightRecorder::clipVideoFrameHeight() { status_t StagefrightRecorder::startMPEG4Recording() { mWriter = new MPEG4Writer(dup(mOutputFd)); + int32_t totalBitRate = 0; // Add audio source first if it exists if (mAudioSource != AUDIO_SOURCE_LIST_END) { @@ -651,7 +664,7 @@ status_t StagefrightRecorder::startMPEG4Recording() { if (audioEncoder == NULL) { return UNKNOWN_ERROR; } - + totalBitRate += mAudioBitRate; mWriter->addSource(audioEncoder); } if (mVideoSource == VIDEO_SOURCE_DEFAULT @@ -704,7 +717,7 @@ status_t StagefrightRecorder::startMPEG4Recording() { sp enc_meta = new MetaData; enc_meta->setInt32(kKeyBitRate, mVideoBitRate); - enc_meta->setInt32(kKeySampleRate, mFrameRate); // XXX: kKeySampleRate? + enc_meta->setInt32(kKeySampleRate, mFrameRate); switch (mVideoEncoder) { case VIDEO_ENCODER_H263: @@ -747,12 +760,13 @@ status_t StagefrightRecorder::startMPEG4Recording() { true /* createEncoder */, cameraSource); CHECK(mOutputFd >= 0); + totalBitRate += mVideoBitRate; mWriter->addSource(encoder); } { // MPEGWriter specific handling - MPEG4Writer *writer = ((MPEG4Writer *) mWriter.get()); // mWriter is an MPEGWriter + MPEG4Writer *writer = ((MPEG4Writer *) mWriter.get()); writer->setInterleaveDuration(mInterleaveDurationUs); } @@ -763,7 +777,10 @@ status_t StagefrightRecorder::startMPEG4Recording() { mWriter->setMaxFileSize(mMaxFileSizeBytes); } mWriter->setListener(mListener); - mWriter->start(); + sp meta = new MetaData; + meta->setInt32(kKeyBitRate, totalBitRate); + meta->setInt32(kKey64BitFileOffset, mUse64BitFileOffset); + mWriter->start(meta.get()); return OK; } @@ -824,6 +841,7 @@ status_t StagefrightRecorder::reset() { mInterleaveDurationUs = 0; mIFramesInterval = 1; mAudioSourceNode = 0; + mUse64BitFileOffset = false; mEncoderProfiles = MediaProfiles::getInstance(); mOutputFd = -1; diff --git a/media/libmediaplayerservice/StagefrightRecorder.h b/media/libmediaplayerservice/StagefrightRecorder.h index 6eedf0c..2943e97 100644 --- a/media/libmediaplayerservice/StagefrightRecorder.h +++ b/media/libmediaplayerservice/StagefrightRecorder.h @@ -72,6 +72,7 @@ private: output_format mOutputFormat; audio_encoder mAudioEncoder; video_encoder mVideoEncoder; + bool mUse64BitFileOffset; int32_t mVideoWidth, mVideoHeight; int32_t mFrameRate; int32_t mVideoBitRate; @@ -100,6 +101,7 @@ private: status_t setParamAudioSamplingRate(int32_t sampleRate); status_t setParamInterleaveDuration(int32_t durationUs); status_t setParamIFramesInterval(int32_t interval); + status_t setParam64BitFileOffset(bool use64BitFileOffset); status_t setParamMaxDurationOrFileSize(int64_t limit, bool limit_is_duration); void clipVideoBitRate(); void clipVideoFrameRate(); -- cgit v1.1