summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/AMRWriter.cpp
diff options
context:
space:
mode:
authorJames Dong <jdong@google.com>2010-05-11 14:57:02 -0700
committerJames Dong <jdong@google.com>2010-05-14 10:46:56 -0700
commitd599cd4573b5a2d5914c5040e0565ef866749b77 (patch)
treef7b799092087742c9cfdda8b21a141f9934cf0ae /media/libstagefright/AMRWriter.cpp
parent2e90514be4c98b5fa6e1df5f2049a5e005a4263d (diff)
downloadframeworks_av-d599cd4573b5a2d5914c5040e0565ef866749b77.zip
frameworks_av-d599cd4573b5a2d5914c5040e0565ef866749b77.tar.gz
frameworks_av-d599cd4573b5a2d5914c5040e0565ef866749b77.tar.bz2
Handle recording file size and/or duration limit
Change-Id: Ib9ed1f3ebd8fef550cc130a7ef11f2905fa9aedc
Diffstat (limited to 'media/libstagefright/AMRWriter.cpp')
-rw-r--r--media/libstagefright/AMRWriter.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/media/libstagefright/AMRWriter.cpp b/media/libstagefright/AMRWriter.cpp
index 73ea56d..0d54235 100644
--- a/media/libstagefright/AMRWriter.cpp
+++ b/media/libstagefright/AMRWriter.cpp
@@ -22,6 +22,7 @@
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MediaSource.h>
#include <media/stagefright/MetaData.h>
+#include <media/mediarecorder.h>
namespace android {
@@ -137,6 +138,20 @@ void AMRWriter::stop() {
mStarted = false;
}
+bool AMRWriter::exceedsFileSizeLimit() {
+ if (mMaxFileSizeLimitBytes == 0) {
+ return false;
+ }
+ return mEstimatedSizeBytes >= mMaxFileSizeLimitBytes;
+}
+
+bool AMRWriter::exceedsFileDurationLimit() {
+ if (mMaxFileDurationLimitUs == 0) {
+ return false;
+ }
+ return mEstimatedDurationUs >= mMaxFileDurationLimitUs;
+}
+
// static
void *AMRWriter::ThreadWrapper(void *me) {
static_cast<AMRWriter *>(me)->threadFunc();
@@ -145,6 +160,8 @@ void *AMRWriter::ThreadWrapper(void *me) {
}
void AMRWriter::threadFunc() {
+ mEstimatedDurationUs = 0;
+ mEstimatedSizeBytes = 0;
while (!mDone) {
MediaBuffer *buffer;
status_t err = mSource->read(&buffer);
@@ -153,6 +170,25 @@ void AMRWriter::threadFunc() {
break;
}
+ mEstimatedSizeBytes += buffer->range_length();
+ if (exceedsFileSizeLimit()) {
+ buffer->release();
+ buffer = NULL;
+ notify(MEDIA_RECORDER_EVENT_INFO, MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED, 0);
+ break;
+ }
+
+ int64_t timestampUs;
+ CHECK(buffer->meta_data()->findInt64(kKeyTime, &timestampUs));
+ if (timestampUs > mEstimatedDurationUs) {
+ mEstimatedDurationUs = timestampUs;
+ }
+ if (exceedsFileDurationLimit()) {
+ buffer->release();
+ buffer = NULL;
+ notify(MEDIA_RECORDER_EVENT_INFO, MEDIA_RECORDER_INFO_MAX_DURATION_REACHED, 0);
+ break;
+ }
ssize_t n = fwrite(
(const uint8_t *)buffer->data() + buffer->range_offset(),
1,