diff options
author | Wonsik Kim <wonsik@google.com> | 2015-05-29 10:32:10 +0900 |
---|---|---|
committer | Wonsik Kim <wonsik@google.com> | 2015-05-29 10:40:28 +0900 |
commit | 3d83a2089f7000180a1a3ff5a9d376efe92f596c (patch) | |
tree | 7e4b281605cd1a5c77c27405dbece3b45e069a66 | |
parent | c6be086e367e080b0e498e9c6971d55ccc8e73a7 (diff) | |
download | frameworks_av-3d83a2089f7000180a1a3ff5a9d376efe92f596c.zip frameworks_av-3d83a2089f7000180a1a3ff5a9d376efe92f596c.tar.gz frameworks_av-3d83a2089f7000180a1a3ff5a9d376efe92f596c.tar.bz2 |
mpeg2ts: revise duration estimation logic
Estimate duration based on GOP duration and size to yield more
accurate result. For a fully buffered stream, just use the buffered
duration.
Bug: 21391417
Change-Id: I116ae8f596007a0b9fca427a4875c10820ddfea2
-rw-r--r-- | media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp b/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp index e0ee87b..aae3e9f 100644 --- a/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp +++ b/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp @@ -194,18 +194,19 @@ void MPEG2TSExtractor::init() { ATSParser::VIDEO).get() : (AnotherPacketSource *)mParser->getSource( ATSParser::AUDIO).get(); - int64_t prevBufferedDurationUs = 0; + size_t prevSyncSize = 1; int64_t durationUs = -1; List<int64_t> durations; // Estimate duration --- stabilize until you get <500ms deviation. - while (feedMore() == OK && ALooper::GetNowUs() - startTime <= 2000000ll) { - status_t err; - int64_t bufferedDurationUs = impl->getBufferedDurationUs(&err); - if (err != OK) { - break; - } - if (bufferedDurationUs != prevBufferedDurationUs) { - durationUs = size * bufferedDurationUs / mOffset; + while (feedMore() == OK + && ALooper::GetNowUs() - startTime <= 2000000ll) { + if (mSeekSyncPoints->size() > prevSyncSize) { + prevSyncSize = mSeekSyncPoints->size(); + int64_t diffUs = mSeekSyncPoints->keyAt(prevSyncSize - 1) + - mSeekSyncPoints->keyAt(0); + off64_t diffOffset = mSeekSyncPoints->valueAt(prevSyncSize - 1) + - mSeekSyncPoints->valueAt(0); + durationUs = size * diffUs / diffOffset; durations.push_back(durationUs); if (durations.size() > 5) { durations.erase(durations.begin()); @@ -225,9 +226,14 @@ void MPEG2TSExtractor::init() { break; } } - prevBufferedDurationUs = bufferedDurationUs; } } + status_t err; + int64_t bufferedDurationUs; + bufferedDurationUs = impl->getBufferedDurationUs(&err); + if (err == ERROR_END_OF_STREAM) { + durationUs = bufferedDurationUs; + } if (durationUs > 0) { const sp<MetaData> meta = impl->getFormat(); meta->setInt64(kKeyDuration, durationUs); |