Bug 1111978 - RTSP error in browser app blocks playing video in other apps. r=bechen, a=bajaj
authorEthan Tseng <ettseng@mozilla.com>
Wed, 31 Dec 2014 14:35:23 +0800
changeset 221571 ae2af1ecd237f0148f34b0ad12fbda138e5615ca
parent 221570 74489778f3659e0f2dafb3cb1ce92bbd59fe2be2
child 221572 5f6569afe82226d747f52776c6412e759e4b370d
push id297
push userryanvm@gmail.com
push dateWed, 07 Jan 2015 22:19:33 +0000
treeherdermozilla-b2g34_v2_1@ae2af1ecd237 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbechen, bajaj
bugs1111978
milestone34.0
Bug 1111978 - RTSP error in browser app blocks playing video in other apps. r=bechen, a=bajaj
content/media/RtspMediaResource.cpp
--- a/content/media/RtspMediaResource.cpp
+++ b/content/media/RtspMediaResource.cpp
@@ -215,16 +215,23 @@ nsresult RtspTrackBuffer::ReadBuffer(uin
            ,mBufferSlotData[mConsumerIdx].mLength);
   // Reader should skip the slots with mLength==BUFFER_SLOT_INVALID.
   // The loop ends when
   // 1. Read data successfully
   // 2. Fail to read data due to aToBuffer's space
   // 3. No data in this buffer
   // 4. mIsStarted is not set
   while (1) {
+    // Make sure the track buffer is started.
+    // It could be stopped when RTSP connection is disconnected.
+    if (!mIsStarted) {
+      RTSPMLOG("ReadBuffer: mIsStarted is false");
+      return NS_ERROR_FAILURE;
+    }
+
     // Do not read from buffer if we are still in the playout delay duration.
     if (mDuringPlayoutDelay) {
       monitor.Wait();
       continue;
     }
 
     if (mBufferSlotData[mConsumerIdx].mFrameType & MEDIASTREAM_FRAMETYPE_END_OF_STREAM) {
       return NS_BASE_STREAM_CLOSED;
@@ -256,20 +263,16 @@ nsresult RtspTrackBuffer::ReadBuffer(uin
         mBufferSlotData[i].mTime = BUFFER_SLOT_EMPTY;
       }
       mConsumerIdx = (mConsumerIdx + slots) % BUFFER_SLOT_NUM;
       break;
     } else if (mBufferSlotData[mConsumerIdx].mLength == BUFFER_SLOT_INVALID) {
       mConsumerIdx = (mConsumerIdx + 1) % BUFFER_SLOT_NUM;
       RTSPMLOG("BUFFER_SLOT_INVALID move forward");
     } else {
-      // No data, and disconnected.
-      if (!mIsStarted) {
-        return NS_ERROR_FAILURE;
-      }
       // No data, the decode thread is blocked here until we receive
       // OnMediaDataAvailable. The OnMediaDataAvailable will call WriteBuffer()
       // to wake up the decode thread.
       RTSPMLOG("monitor.Wait()");
       monitor.Wait();
     }
   }
   return NS_OK;
@@ -611,16 +614,21 @@ RtspMediaResource::ReadFrameFromTrack(ui
                                       uint32_t aTrackIdx, uint32_t& aBytes,
                                       uint64_t& aTime, uint32_t& aFrameSize)
 {
   NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
   NS_ASSERTION(aTrackIdx < mTrackBuffer.Length(),
                "ReadTrack index > mTrackBuffer");
   MOZ_ASSERT(aBuffer);
 
+  if (!mIsConnected) {
+    RTSPMLOG("ReadFrameFromTrack: RTSP not connected");
+    return NS_ERROR_FAILURE;
+  }
+
   return mTrackBuffer[aTrackIdx]->ReadBuffer(aBuffer, aBufferSize, aBytes,
                                              aTime, aFrameSize);
 }
 
 nsresult
 RtspMediaResource::OnMediaDataAvailable(uint8_t aTrackIdx,
                                         const nsACString &data,
                                         uint32_t length,
@@ -765,16 +773,17 @@ RtspMediaResource::OnDisconnected(uint8_
 
   if (mDecoder) {
     if (aReason == NS_ERROR_NOT_INITIALIZED ||
         aReason == NS_ERROR_CONNECTION_REFUSED ||
         aReason == NS_ERROR_NOT_CONNECTED ||
         aReason == NS_ERROR_NET_TIMEOUT) {
       // Report error code to Decoder.
       RTSPMLOG("Error in OnDisconnected 0x%x", aReason);
+      mIsConnected = false;
       mDecoder->NetworkError();
     } else {
       // Resetting the decoder and media element when the connection
       // between RTSP client and server goes down.
       mDecoder->ResetConnectionState();
     }
   }