Bug 1120075: Use Movie Extend Header's duration as fallback when available. r=kentuckyfriedtakahe

--HG--
extra : rebase_source : 54e554e183d9072908ec02b6c14de5c2f46e8204
This commit is contained in:
Jean-Yves Avenard 2015-01-16 23:49:01 +11:00
parent 52d3bbb9ae
commit 2ceb0057af
3 changed files with 48 additions and 0 deletions

View File

@ -144,6 +144,13 @@ MP4Demuxer::Init()
sp<MetaData> 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();
}

View File

@ -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

View File

@ -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);