From 648a303842d8f7e257e554bd30e6e65f1a7ad7d7 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Fri, 16 Jan 2015 23:49:01 +1100 Subject: [PATCH] Bug 1120075: Use Movie Extend Header's duration as fallback when available. r=kentuckyfriedtakahe --- media/libstagefright/binding/mp4_demuxer.cpp | 7 ++++ .../av/include/media/stagefright/MetaData.h | 1 + .../media/libstagefright/MPEG4Extractor.cpp | 40 +++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/media/libstagefright/binding/mp4_demuxer.cpp b/media/libstagefright/binding/mp4_demuxer.cpp index d2505d62707..e77e01c026e 100644 --- a/media/libstagefright/binding/mp4_demuxer.cpp +++ b/media/libstagefright/binding/mp4_demuxer.cpp @@ -144,6 +144,13 @@ MP4Demuxer::Init() sp metaData = e->getMetaData(); mCrypto.Update(metaData); + int64_t movieDuration; + if (!mVideoConfig.duration && !mAudioConfig.duration && + metaData->findInt64(kKeyMovieDuration, &movieDuration)) { + // No duration were found in either tracks, use movie extend header box one. + mVideoConfig.duration = mAudioConfig.duration = movieDuration; + } + return mPrivate->mAudio.get() || mPrivate->mVideo.get(); } diff --git a/media/libstagefright/frameworks/av/include/media/stagefright/MetaData.h b/media/libstagefright/frameworks/av/include/media/stagefright/MetaData.h index 9c78a6948b3..30d969d29fd 100644 --- a/media/libstagefright/frameworks/av/include/media/stagefright/MetaData.h +++ b/media/libstagefright/frameworks/av/include/media/stagefright/MetaData.h @@ -67,6 +67,7 @@ enum { kKeyDriftTime = 'dftT', // int64_t (usecs) kKeyAnchorTime = 'ancT', // int64_t (usecs) kKeyDuration = 'dura', // int64_t (usecs) + kKeyMovieDuration = 'mdur', // int64_t (usecs) kKeyColorFormat = 'colf', kKeyPlatformPrivate = 'priv', // pointer kKeyDecoderComponent = 'decC', // cstring diff --git a/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp b/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp index 06ebd1b4fec..34adcf21b62 100644 --- a/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp +++ b/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp @@ -1697,6 +1697,46 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) { break; } + case FOURCC('m', 'e', 'h', 'd'): + { + if (chunk_data_size < 8) { + return ERROR_MALFORMED; + } + + uint8_t version; + if (mDataSource->readAt( + data_offset, &version, sizeof(version)) + < (ssize_t)sizeof(version)) { + return ERROR_IO; + } + if (version > 1) { + break; + } + int64_t duration = 0; + if (version == 1) { + if (mDataSource->readAt( + data_offset + 4, &duration, sizeof(duration)) + < (ssize_t)sizeof(duration)) { + return ERROR_IO; + } + duration = ntoh64(duration); + } else { + uint32_t duration32; + if (mDataSource->readAt( + data_offset + 4, &duration32, sizeof(duration32)) + < (ssize_t)sizeof(duration32)) { + return ERROR_IO; + } + duration = ntohl(duration32); + } + if (duration) { + mFileMetaData->setInt64(kKeyMovieDuration, duration * 1000LL); + } + + *offset += chunk_size; + break; + } + case FOURCC('m', 'd', 'a', 't'): { ALOGV("mdat chunk, drm: %d", mIsDrm);