Part of fix for double spins & faster startup

This change alters the way that the media player
interacts with the Widevine adaptive streaming buffer
logic.  It eliminates the reliance on cached buffer
duration to determine pause/play states and instead
only generates buffering events when the widevine
library is not producing data (i.e. when it is
buffering).  This eliminates unnecessary pause and
rebuffer cycles, reducing startup time and the
frequency and duration of spinners.

Multi-repo commit, depends on related changes in frameworks/av

Change-Id: I5b71f954268fbd390eed7f27db98a1bb470d5cfb
related-to-bug:6503294
related-to-bug:6463780
This commit is contained in:
Jeff Tinker
2012-05-31 21:41:40 -07:00
parent b83e7ca14a
commit 1024b041e8
3 changed files with 21 additions and 11 deletions

View File

@@ -499,19 +499,24 @@ int64_t WVMExtractorImpl::getCachedDurationUs(status_t *finalStatus) {
}
uint64_t durationUs = 0;
float secondsBuffered;
status = WV_Info_TimeBuffered(mSession, &secondsBuffered);
if (!mVideoSource->isStalled() && !mAudioSource->isStalled()) {
// Data is buffered as long as the pull isn't stalled.
// The amount indicated doesn't matter as long as it
// is more than the high water mark.
durationUs = 10000000LL;
}
if (status == WV_Status_End_Of_Media) {
*finalStatus = ERROR_END_OF_STREAM;
} else if (status != WV_Status_OK) {
*finalStatus = ERROR_IO;
} else {
durationUs = (uint64_t)(secondsBuffered * 1000000LL);
if (mIsLiveStream) {
*finalStatus = ERROR_END_OF_STREAM;
} else {
*finalStatus = OK;
int64_t current_time = 0; // usec.
if (mVideoSource != NULL) {
current_time = mVideoSource->getTime();
@@ -530,13 +535,7 @@ int64_t WVMExtractorImpl::getCachedDurationUs(status_t *finalStatus) {
}
}
// Scale the duration to account for Stagefright's conservative buffering.
// This provides much more responsive operation and due to the ability to
// adapt, we don't need to prebuffer so much data. Based on testing, 2x
// is a reasonable compromise between faster startup time and additional
// pauses after playback starts.
return durationUs * 2;
return durationUs;
}
void WVMExtractorImpl::setAdaptiveStreamingMode(bool adaptive)

View File

@@ -35,6 +35,7 @@ WVMMediaSource::WVMMediaSource(WVSession *session, WVEsSelector esSelector,
mIsLiveStream(isLive),
mNewSegment(false),
mCryptoInitialized(false),
mIsStalled(false),
mGroup(NULL),
mKeyTime(0),
mDts(0),
@@ -203,6 +204,8 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
{
Mutex::Autolock autoLock(mLock);
mIsStalled = false;
CHECK(mStarted);
*buffer = NULL;
@@ -333,16 +336,20 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
return ERROR_IO;
} else {
// Didn't get anything, sleep a bit so we don't hog the CPU then try again
if (retryCount > 10)
mIsStalled = true;
usleep(10000);
continue;
}
}
#define PCR_HZ 90000
mKeyTime = (int64_t)mPts * 1000000 / PCR_HZ;
if (seekNextSync && ((mKeyTime < seekTimeUs) || !syncFrame)) {
// drop frames up to next sync if requested
mIsStalled = true;
usleep(10000);
#ifdef REQUIRE_SECURE_BUFFERS
mDecryptContext.Initialize(mediaBuf);
@@ -351,6 +358,8 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options)
continue;
}
mIsStalled = false;
if (offset + bytesRead < mediaBuf->size())
break;

View File

@@ -41,6 +41,7 @@ public:
virtual status_t read(MediaBuffer **buffer, const ReadOptions *options = NULL);
void addEncryptedSize(size_t size) { mEncryptedSizes.push_back(size); }
bool isStalled() const { return mIsStalled; }
static int sLastError;
@@ -83,6 +84,7 @@ private:
bool mIsLiveStream;
bool mNewSegment;
bool mCryptoInitialized;
bool mIsStalled;
MediaBufferGroup *mGroup;