am 9db798d0: Audio/video initial recording time synchronization
This commit is contained in:
@@ -68,12 +68,16 @@ private:
|
|||||||
bool mStreamableFile;
|
bool mStreamableFile;
|
||||||
off_t mEstimatedMoovBoxSize;
|
off_t mEstimatedMoovBoxSize;
|
||||||
uint32_t mInterleaveDurationUs;
|
uint32_t mInterleaveDurationUs;
|
||||||
|
int64_t mStartTimestampUs;
|
||||||
Mutex mLock;
|
Mutex mLock;
|
||||||
|
|
||||||
List<Track *> mTracks;
|
List<Track *> mTracks;
|
||||||
|
|
||||||
List<off_t> mBoxes;
|
List<off_t> mBoxes;
|
||||||
|
|
||||||
|
void setStartTimestamp(int64_t timeUs);
|
||||||
|
int64_t getStartTimestamp(); // Not const
|
||||||
|
|
||||||
void lock();
|
void lock();
|
||||||
void unlock();
|
void unlock();
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ private:
|
|||||||
bool mGotAllCodecSpecificData;
|
bool mGotAllCodecSpecificData;
|
||||||
|
|
||||||
bool mReachedEOS;
|
bool mReachedEOS;
|
||||||
|
int64_t mStartTimestampUs;
|
||||||
|
|
||||||
static void *ThreadWrapper(void *me);
|
static void *ThreadWrapper(void *me);
|
||||||
void threadEntry();
|
void threadEntry();
|
||||||
@@ -152,6 +153,7 @@ status_t MPEG4Writer::start() {
|
|||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mStartTimestampUs = 0;
|
||||||
mStreamableFile = true;
|
mStreamableFile = true;
|
||||||
mWriteMoovBoxToMemory = false;
|
mWriteMoovBoxToMemory = false;
|
||||||
mMoovBoxBuffer = NULL;
|
mMoovBoxBuffer = NULL;
|
||||||
@@ -500,6 +502,21 @@ bool MPEG4Writer::reachedEOS() {
|
|||||||
return allDone;
|
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(
|
MPEG4Writer::Track::Track(
|
||||||
@@ -836,6 +853,10 @@ void MPEG4Writer::Track::threadEntry() {
|
|||||||
|
|
||||||
int64_t timestampUs;
|
int64_t timestampUs;
|
||||||
CHECK(buffer->meta_data()->findInt64(kKeyTime, ×tampUs));
|
CHECK(buffer->meta_data()->findInt64(kKeyTime, ×tampUs));
|
||||||
|
if (mSampleInfos.empty()) {
|
||||||
|
mOwner->setStartTimestamp(timestampUs);
|
||||||
|
mStartTimestampUs = (timestampUs - mOwner->getStartTimestamp());
|
||||||
|
}
|
||||||
|
|
||||||
if (timestampUs > mMaxTimeStampUs) {
|
if (timestampUs > mMaxTimeStampUs) {
|
||||||
mMaxTimeStampUs = timestampUs;
|
mMaxTimeStampUs = timestampUs;
|
||||||
@@ -1005,6 +1026,19 @@ void MPEG4Writer::Track::writeTrackHeader(int32_t trackID) {
|
|||||||
}
|
}
|
||||||
mOwner->endBox(); // tkhd
|
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("mdia");
|
||||||
|
|
||||||
mOwner->beginBox("mdhd");
|
mOwner->beginBox("mdhd");
|
||||||
|
|||||||
Reference in New Issue
Block a user