From 95c4d6034dc356f70c6293ea53d4858415b2d020 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Mon, 17 Oct 2011 15:49:01 -0700 Subject: Don't hold onto the lock while reconnecting to the server to avoid stalling the readers. Change-Id: I73b646587c8a654a73ff7d800c0f17bd78001855 --- media/libstagefright/NuCachedSource2.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'media/libstagefright/NuCachedSource2.cpp') diff --git a/media/libstagefright/NuCachedSource2.cpp b/media/libstagefright/NuCachedSource2.cpp index 4f183f5..1e1de04 100644 --- a/media/libstagefright/NuCachedSource2.cpp +++ b/media/libstagefright/NuCachedSource2.cpp @@ -279,6 +279,8 @@ void NuCachedSource2::onMessageReceived(const sp &msg) { void NuCachedSource2::fetchInternal() { LOGV("fetchInternal"); + bool reconnect = false; + { Mutex::Autolock autoLock(mLock); CHECK(mFinalStatus == OK || mNumRetriesLeft > 0); @@ -286,18 +288,24 @@ void NuCachedSource2::fetchInternal() { if (mFinalStatus != OK) { --mNumRetriesLeft; - status_t err = - mSource->reconnectAtOffset(mCacheOffset + mCache->totalSize()); + reconnect = true; + } + } - if (err == ERROR_UNSUPPORTED) { - mNumRetriesLeft = 0; - return; - } else if (err != OK) { - LOGI("The attempt to reconnect failed, %d retries remaining", - mNumRetriesLeft); + if (reconnect) { + status_t err = + mSource->reconnectAtOffset(mCacheOffset + mCache->totalSize()); - return; - } + Mutex::Autolock autoLock(mLock); + + if (err == ERROR_UNSUPPORTED) { + mNumRetriesLeft = 0; + return; + } else if (err != OK) { + LOGI("The attempt to reconnect failed, %d retries remaining", + mNumRetriesLeft); + + return; } } -- cgit v1.1