diff options
Diffstat (limited to 'media/libstagefright/MPEG4Writer.cpp')
-rwxr-xr-x | media/libstagefright/MPEG4Writer.cpp | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp index 755b502..ab0a8a8 100755 --- a/media/libstagefright/MPEG4Writer.cpp +++ b/media/libstagefright/MPEG4Writer.cpp @@ -42,6 +42,7 @@ namespace android { +static const int64_t kMinStreamableFileSizeInBytes = 5 * 1024 * 1024; static const int64_t kMax32BitFileSize = 0x007fffffffLL; static const uint8_t kNalUnitTypeSeqParamSet = 0x07; static const uint8_t kNalUnitTypePicParamSet = 0x08; @@ -90,7 +91,6 @@ private: int64_t mMaxChunkDurationUs; bool mIsRealTimeRecording; - int64_t mMaxTimeStampUs; int64_t mEstimatedTrackSizeBytes; int64_t mMdatSizeBytes; int32_t mTimeScale; @@ -269,7 +269,7 @@ MPEG4Writer::MPEG4Writer(const char *filename) mAreGeoTagsAvailable(false), mStartTimeOffsetMs(-1) { - mFd = open(filename, O_CREAT | O_LARGEFILE | O_TRUNC | O_RDWR); + mFd = open(filename, O_CREAT | O_LARGEFILE | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR); if (mFd >= 0) { mInitCheck = OK; } @@ -333,6 +333,10 @@ status_t MPEG4Writer::Track::dump( snprintf(buffer, SIZE, " reached EOS: %s\n", mReachedEOS? "true": "false"); result.append(buffer); + snprintf(buffer, SIZE, " frames encoded : %d\n", mNumSamples); + result.append(buffer); + snprintf(buffer, SIZE, " duration encoded : %lld us\n", mTrackDurationUs); + result.append(buffer); ::write(fd, result.string(), result.size()); return OK; } @@ -487,8 +491,16 @@ status_t MPEG4Writer::start(MetaData *param) { CHECK_GT(mTimeScale, 0); ALOGV("movie time scale: %d", mTimeScale); - mStreamableFile = true; - mWriteMoovBoxToMemory = false; + /* + * When the requested file size limit is small, the priority + * is to meet the file size limit requirement, rather than + * to make the file streamable. + */ + mStreamableFile = + (mMaxFileSizeLimitBytes != 0 && + mMaxFileSizeLimitBytes >= kMinStreamableFileSizeInBytes); + + mWriteMoovBoxToMemory = mStreamableFile; mMoovBoxBuffer = NULL; mMoovBoxBufferOffset = 0; @@ -504,11 +516,16 @@ status_t MPEG4Writer::start(MetaData *param) { mEstimatedMoovBoxSize = estimateMoovBoxSize(bitRate); } CHECK_GE(mEstimatedMoovBoxSize, 8); - lseek64(mFd, mFreeBoxOffset, SEEK_SET); - writeInt32(mEstimatedMoovBoxSize); - write("free", 4); + if (mStreamableFile) { + // Reserve a 'free' box only for streamable file + lseek64(mFd, mFreeBoxOffset, SEEK_SET); + writeInt32(mEstimatedMoovBoxSize); + write("free", 4); + mMdatOffset = mFreeBoxOffset + mEstimatedMoovBoxSize; + } else { + mMdatOffset = mOffset; + } - mMdatOffset = mFreeBoxOffset + mEstimatedMoovBoxSize; mOffset = mMdatOffset; lseek64(mFd, mMdatOffset, SEEK_SET); if (mUse32BitOffset) { @@ -689,7 +706,7 @@ status_t MPEG4Writer::reset() { lseek64(mFd, mOffset, SEEK_SET); const off64_t moovOffset = mOffset; - mWriteMoovBoxToMemory = true; + mWriteMoovBoxToMemory = mStreamableFile; mMoovBoxBuffer = (uint8_t *) malloc(mEstimatedMoovBoxSize); mMoovBoxBufferOffset = 0; CHECK(mMoovBoxBuffer != NULL); @@ -1062,6 +1079,10 @@ bool MPEG4Writer::exceedsFileSizeLimit() { nTotalBytesEstimate += (*it)->getEstimatedTrackSizeBytes(); } + if (!mStreamableFile) { + // Add 1024 bytes as error tolerance + return nTotalBytesEstimate + 1024 >= mMaxFileSizeLimitBytes; + } // Be conservative in the estimate: do not exceed 95% of // the target file limit. For small target file size limit, though, // this will not help. @@ -1129,6 +1150,7 @@ MPEG4Writer::Track::Track( mStarted(false), mTrackId(trackId), mTrackDurationUs(0), + mNumSamples(0), mEstimatedTrackSizeBytes(0), mSamplesHaveSameSize(true), mCodecSpecificData(NULL), |