diff options
author | James Dong <jdong@google.com> | 2010-06-10 12:28:15 -0700 |
---|---|---|
committer | James Dong <jdong@google.com> | 2010-06-11 13:48:48 -0700 |
commit | a7d1a2dd776bf356c228785a94ba8e0ff6a2ec7f (patch) | |
tree | 5c1bfd25a405fcf485512ffb3ced827b3d2ab630 /media/libstagefright/AMRWriter.cpp | |
parent | 6f5aae1bcba130d5b8092a19fca3627aa565df56 (diff) | |
download | frameworks_av-a7d1a2dd776bf356c228785a94ba8e0ff6a2ec7f.zip frameworks_av-a7d1a2dd776bf356c228785a94ba8e0ff6a2ec7f.tar.gz frameworks_av-a7d1a2dd776bf356c228785a94ba8e0ff6a2ec7f.tar.bz2 |
Initial checkin for pause and resume control
Change-Id: Ibdcf7bea5fb66baa81878704ba4091dfcfe382ee
Diffstat (limited to 'media/libstagefright/AMRWriter.cpp')
-rw-r--r-- | media/libstagefright/AMRWriter.cpp | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/media/libstagefright/AMRWriter.cpp b/media/libstagefright/AMRWriter.cpp index aec7394..8951f5b 100644 --- a/media/libstagefright/AMRWriter.cpp +++ b/media/libstagefright/AMRWriter.cpp @@ -29,13 +29,17 @@ namespace android { AMRWriter::AMRWriter(const char *filename) : mFile(fopen(filename, "wb")), mInitCheck(mFile != NULL ? OK : NO_INIT), - mStarted(false) { + mStarted(false), + mPaused(false), + mResumed(false) { } AMRWriter::AMRWriter(int fd) : mFile(fdopen(fd, "wb")), mInitCheck(mFile != NULL ? OK : NO_INIT), - mStarted(false) { + mStarted(false), + mPaused(false), + mResumed(false) { } AMRWriter::~AMRWriter() { @@ -98,10 +102,19 @@ status_t AMRWriter::start() { return mInitCheck; } - if (mStarted || mSource == NULL) { + if (mSource == NULL) { return UNKNOWN_ERROR; } + if (mStarted && mPaused) { + mPaused = false; + mResumed = true; + return OK; + } else if (mStarted) { + // Already started, does nothing + return OK; + } + status_t err = mSource->start(); if (err != OK) { @@ -123,6 +136,13 @@ status_t AMRWriter::start() { return OK; } +void AMRWriter::pause() { + if (!mStarted) { + return; + } + mPaused = true; +} + void AMRWriter::stop() { if (!mStarted) { return; @@ -163,6 +183,9 @@ void AMRWriter::threadFunc() { mEstimatedDurationUs = 0; mEstimatedSizeBytes = 0; bool stoppedPrematurely = true; + int64_t previousPausedDurationUs = 0; + int64_t maxTimestampUs = 0; + while (!mDone) { MediaBuffer *buffer; status_t err = mSource->read(&buffer); @@ -171,6 +194,12 @@ void AMRWriter::threadFunc() { break; } + if (mPaused) { + buffer->release(); + buffer = NULL; + continue; + } + mEstimatedSizeBytes += buffer->range_length(); if (exceedsFileSizeLimit()) { buffer->release(); @@ -184,6 +213,17 @@ void AMRWriter::threadFunc() { if (timestampUs > mEstimatedDurationUs) { mEstimatedDurationUs = timestampUs; } + if (mResumed) { + previousPausedDurationUs += (timestampUs - maxTimestampUs - 20000); + mResumed = false; + } + timestampUs -= previousPausedDurationUs; + LOGV("time stamp: %lld, previous paused duration: %lld", + timestampUs, previousPausedDurationUs); + if (timestampUs > maxTimestampUs) { + maxTimestampUs = timestampUs; + } + if (exceedsFileDurationLimit()) { buffer->release(); buffer = NULL; |