From bfd4d0d9fe0033abf3f55b94f30f6a58846a875e Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Thu, 17 May 2012 14:18:50 -0700 Subject: Buffer at least 2 secs worth of data at startup of after a seek before resuming starting RTSP playback. Change-Id: I060c6c7fd627ab7ebd5c095ddcfdb4cc0f637aad related-to-bug: 6364126 --- .../libstagefright/mpeg2ts/AnotherPacketSource.cpp | 34 ++++++++++++++++++++++ media/libstagefright/mpeg2ts/AnotherPacketSource.h | 4 +++ 2 files changed, 38 insertions(+) (limited to 'media/libstagefright/mpeg2ts') diff --git a/media/libstagefright/mpeg2ts/AnotherPacketSource.cpp b/media/libstagefright/mpeg2ts/AnotherPacketSource.cpp index d708ba6..a605a05 100644 --- a/media/libstagefright/mpeg2ts/AnotherPacketSource.cpp +++ b/media/libstagefright/mpeg2ts/AnotherPacketSource.cpp @@ -198,6 +198,40 @@ bool AnotherPacketSource::hasBufferAvailable(status_t *finalResult) { return false; } +int64_t AnotherPacketSource::getBufferedDurationUs(status_t *finalResult) { + Mutex::Autolock autoLock(mLock); + + *finalResult = mEOSResult; + + if (mBuffers.empty()) { + return 0; + } + + int64_t time1 = -1; + int64_t time2 = -1; + + List >::iterator it = mBuffers.begin(); + while (it != mBuffers.end()) { + const sp &buffer = *it; + + int64_t timeUs; + if (buffer->meta()->findInt64("timeUs", &timeUs)) { + if (time1 < 0) { + time1 = timeUs; + } + + time2 = timeUs; + } else { + // This is a discontinuity, reset everything. + time1 = time2 = -1; + } + + ++it; + } + + return time2 - time1; +} + status_t AnotherPacketSource::nextBufferTime(int64_t *timeUs) { *timeUs = 0; diff --git a/media/libstagefright/mpeg2ts/AnotherPacketSource.h b/media/libstagefright/mpeg2ts/AnotherPacketSource.h index c99f7f2..d685b98 100644 --- a/media/libstagefright/mpeg2ts/AnotherPacketSource.h +++ b/media/libstagefright/mpeg2ts/AnotherPacketSource.h @@ -43,6 +43,10 @@ struct AnotherPacketSource : public MediaSource { bool hasBufferAvailable(status_t *finalResult); + // Returns the difference between the last and the first queued + // presentation timestamps since the last discontinuity (if any). + int64_t getBufferedDurationUs(status_t *finalResult); + status_t nextBufferTime(int64_t *timeUs); void queueAccessUnit(const sp &buffer); -- cgit v1.1