summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/MPEG4Writer.cpp
diff options
context:
space:
mode:
authorJames Dong <jdong@google.com>2010-05-13 11:47:36 -0700
committerJames Dong <jdong@google.com>2010-05-14 10:51:12 -0700
commit3c0131f02b6f008321608044c53bccce2ac5f6dd (patch)
treecf03faa5dc5f5323fdf16eb1374c12623b6f7961 /media/libstagefright/MPEG4Writer.cpp
parentd599cd4573b5a2d5914c5040e0565ef866749b77 (diff)
downloadframeworks_av-3c0131f02b6f008321608044c53bccce2ac5f6dd.zip
frameworks_av-3c0131f02b6f008321608044c53bccce2ac5f6dd.tar.gz
frameworks_av-3c0131f02b6f008321608044c53bccce2ac5f6dd.tar.bz2
Audio/video initial recording time synchronization
Change-Id: Iac58b63d474fe09c1d36ba6ecde91dafbb7fef9a
Diffstat (limited to 'media/libstagefright/MPEG4Writer.cpp')
-rw-r--r--media/libstagefright/MPEG4Writer.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index 044460c..788534d 100644
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -98,6 +98,7 @@ private:
bool mGotAllCodecSpecificData;
bool mReachedEOS;
+ int64_t mStartTimestampUs;
static void *ThreadWrapper(void *me);
void threadEntry();
@@ -152,6 +153,7 @@ status_t MPEG4Writer::start() {
return UNKNOWN_ERROR;
}
+ mStartTimestampUs = 0;
mStreamableFile = true;
mWriteMoovBoxToMemory = false;
mMoovBoxBuffer = NULL;
@@ -500,6 +502,21 @@ bool MPEG4Writer::reachedEOS() {
return allDone;
}
+void MPEG4Writer::setStartTimestamp(int64_t timeUs) {
+ LOGI("setStartTimestamp: %lld", timeUs);
+ Mutex::Autolock autoLock(mLock);
+ if (mStartTimestampUs != 0) {
+ return; // Sorry, too late
+ }
+ mStartTimestampUs = timeUs;
+}
+
+int64_t MPEG4Writer::getStartTimestamp() {
+ LOGI("getStartTimestamp: %lld", mStartTimestampUs);
+ Mutex::Autolock autoLock(mLock);
+ return mStartTimestampUs;
+}
+
////////////////////////////////////////////////////////////////////////////////
MPEG4Writer::Track::Track(
@@ -836,6 +853,10 @@ void MPEG4Writer::Track::threadEntry() {
int64_t timestampUs;
CHECK(buffer->meta_data()->findInt64(kKeyTime, &timestampUs));
+ if (mSampleInfos.empty()) {
+ mOwner->setStartTimestamp(timestampUs);
+ mStartTimestampUs = (timestampUs - mOwner->getStartTimestamp());
+ }
if (timestampUs > mMaxTimeStampUs) {
mMaxTimeStampUs = timestampUs;
@@ -1005,6 +1026,19 @@ void MPEG4Writer::Track::writeTrackHeader(int32_t trackID) {
}
mOwner->endBox(); // tkhd
+ if (mStartTimestampUs != 0) {
+ mOwner->beginBox("edts");
+ mOwner->writeInt32(0); // version=0, flags=0
+ mOwner->beginBox("elst");
+ mOwner->writeInt32(0); // version=0, flags=0
+ mOwner->writeInt32(1); // a single entry
+ mOwner->writeInt32(mStartTimestampUs / 1000); // edit duration
+ mOwner->writeInt32(0); // edit media starting time
+ mOwner->writeInt32(1); // x1 rate
+ mOwner->endBox();
+ mOwner->endBox();
+ }
+
mOwner->beginBox("mdia");
mOwner->beginBox("mdhd");