From 35b42afd0fc5690084e44eaa89c8644bc6a34bd0 Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Fri, 5 Dec 2014 09:52:20 -0800 Subject: [PATCH] widevine: return -EAGAIN sooner in non-blocking mode Bug: 18536934 Change-Id: Ib9344851fceb418a2e614e966c981a997c32c466 --- proprietary/wvm/WVMMediaSource.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/proprietary/wvm/WVMMediaSource.cpp b/proprietary/wvm/WVMMediaSource.cpp index 6e077688..b1070cd8 100644 --- a/proprietary/wvm/WVMMediaSource.cpp +++ b/proprietary/wvm/WVMMediaSource.cpp @@ -208,6 +208,7 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options) *buffer = NULL; bool seekNextSync = false; + bool seeking = false; int64_t seekTimeUs; @@ -215,6 +216,7 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options) ReadOptions::SeekMode mode; if (options != NULL && options->getSeekTo(&seekTimeUs, &mode)) { + seeking = true; // When doing a seek, use a longer timeout since we need to set up a new connection retryLimit = 1500; @@ -251,9 +253,9 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options) } MediaBuffer *mediaBuf = NULL; + bool nonBlocking = (options != NULL && options->getNonBlocking()); - status_t err = mGroup->acquire_buffer( - &mediaBuf, options != NULL && options->getNonBlocking()); + status_t err = mGroup->acquire_buffer(&mediaBuf, nonBlocking); if (err != OK) { CHECK(mediaBuf == NULL); @@ -328,17 +330,20 @@ status_t WVMMediaSource::read(MediaBuffer **buffer, const ReadOptions *options) #endif if (bytesRead == 0) { - if (retryCount++ >= retryLimit) { + float secondsBuffered = 0.0; + WV_Info_TimeBuffered(mSession, &secondsBuffered); + if (retryCount++ >= retryLimit + || (secondsBuffered > 2.0 && nonBlocking && !seeking)) { // If no data received within the retry limit, return ERROR_IO // This prevents the player from becoming unresponsive mediaBuf->release(); - float secondsBuffered = 0.0; - unsigned long bandwidth = 0; - WV_Info_TimeBuffered(mSession, &secondsBuffered); - WV_Info_CurrentBandwidth(mSession, &bandwidth); - ALOGI("Retry count exhausted: secondsBuffered=%5.2f, bandwidth=%ld", - secondsBuffered, bandwidth); + if (retryCount > retryLimit) { + unsigned long bandwidth = 0; + WV_Info_CurrentBandwidth(mSession, &bandwidth); + ALOGI("Retry count exhausted: secondsBuffered=%5.2f, bandwidth=%ld", + secondsBuffered, bandwidth); + } if (secondsBuffered > 2.0) { // If there's some data buffered but no packets are for