summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2010-02-02 12:13:30 -0800
committerAndreas Huber <andih@google.com>2010-02-02 12:13:30 -0800
commit3b240d6bf235f6f6b40ee4c37a2862de286ca1e4 (patch)
tree059a2b04a3b2ccae26a29e71025e98eab1b277e5
parent4cf04b1bf703522b37a60427ef02f2a18b218c19 (diff)
downloadframeworks_av-3b240d6bf235f6f6b40ee4c37a2862de286ca1e4.zip
frameworks_av-3b240d6bf235f6f6b40ee4c37a2862de286ca1e4.tar.gz
frameworks_av-3b240d6bf235f6f6b40ee4c37a2862de286ca1e4.tar.bz2
Properly report the duration of a recording into .mp4 files.
related-to-bug: 2295468
-rw-r--r--media/libstagefright/MPEG4Writer.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index aee4d15..2cf0ddf 100644
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -38,7 +38,7 @@ public:
void stop();
bool reachedEOS();
- int64_t getDuration() const;
+ int64_t getDurationUs() const;
void writeTrackHeader(int32_t trackID);
private:
@@ -46,6 +46,7 @@ private:
sp<MetaData> mMeta;
sp<MediaSource> mSource;
volatile bool mDone;
+ int64_t mMaxTimeStampUs;
pthread_t mThread;
@@ -140,7 +141,7 @@ void MPEG4Writer::stop() {
it != mTracks.end(); ++it) {
(*it)->stop();
- int64_t duration = (*it)->getDuration();
+ int64_t duration = (*it)->getDurationUs();
if (duration > max_duration) {
max_duration = duration;
}
@@ -162,7 +163,7 @@ void MPEG4Writer::stop() {
writeInt32(now); // creation time
writeInt32(now); // modification time
writeInt32(1000); // timescale
- writeInt32(max_duration);
+ writeInt32(max_duration / 1000);
writeInt32(0x10000); // rate
writeInt16(0x100); // volume
writeInt16(0); // reserved
@@ -316,6 +317,7 @@ MPEG4Writer::Track::Track(
mMeta(source->getFormat()),
mSource(source),
mDone(false),
+ mMaxTimeStampUs(0),
mCodecSpecificData(NULL),
mCodecSpecificDataSize(0),
mReachedEOS(false) {
@@ -343,6 +345,7 @@ status_t MPEG4Writer::Track::start() {
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
mDone = false;
+ mMaxTimeStampUs = 0;
mReachedEOS = false;
pthread_create(&mThread, &attr, ThreadWrapper, this);
@@ -483,6 +486,10 @@ void MPEG4Writer::Track::threadEntry() {
int64_t timestampUs;
CHECK(buffer->meta_data()->findInt64(kKeyTime, &timestampUs));
+ if (timestampUs > mMaxTimeStampUs) {
+ mMaxTimeStampUs = timestampUs;
+ }
+
// Our timestamp is in ms.
info.timestamp = (timestampUs + 500) / 1000;
@@ -495,8 +502,8 @@ void MPEG4Writer::Track::threadEntry() {
mReachedEOS = true;
}
-int64_t MPEG4Writer::Track::getDuration() const {
- return 10000; // XXX
+int64_t MPEG4Writer::Track::getDurationUs() const {
+ return mMaxTimeStampUs;
}
void MPEG4Writer::Track::writeTrackHeader(int32_t trackID) {
@@ -516,7 +523,7 @@ void MPEG4Writer::Track::writeTrackHeader(int32_t trackID) {
mOwner->writeInt32(now); // modification time
mOwner->writeInt32(trackID);
mOwner->writeInt32(0); // reserved
- mOwner->writeInt32(getDuration());
+ mOwner->writeInt32(getDurationUs() / 1000);
mOwner->writeInt32(0); // reserved
mOwner->writeInt32(0); // reserved
mOwner->writeInt16(0); // layer
@@ -555,7 +562,7 @@ void MPEG4Writer::Track::writeTrackHeader(int32_t trackID) {
mOwner->writeInt32(now); // creation time
mOwner->writeInt32(now); // modification time
mOwner->writeInt32(1000); // timescale
- mOwner->writeInt32(getDuration());
+ mOwner->writeInt32(getDurationUs() / 1000);
mOwner->writeInt16(0); // language code XXX
mOwner->writeInt16(0); // predefined
mOwner->endBox();