Merge "Fix 5468644: Use the proper audio stream type to play sound." into ics-mr0
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::fetchInternal() {
     LOGV("fetchInternal");
 
+    bool reconnect = false;
+
     {
         Mutex::Autolock autoLock(mLock);
         CHECK(mFinalStatus == OK || mNumRetriesLeft > 0);
@@ -286,18 +288,24 @@
         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;
         }
     }