Bug 1111978 - RTSP error in browser app blocks playing video in other apps. r=bechen
authorEthan Tseng <ettseng@mozilla.com>
Wed, 31 Dec 2014 14:34:19 +0800
changeset 247923 8768e1f8108ed4b898a83713ea83efe08c1754ff
parent 247922 621cf332663d476f68b359043c816e41b35390f6
child 247924 67ea86c1f2e9d6bb2a80199300e3aa518bc1f0c5
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbechen
bugs1111978
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1111978 - RTSP error in browser app blocks playing video in other apps. r=bechen
dom/media/RtspMediaResource.cpp
--- a/dom/media/RtspMediaResource.cpp
+++ b/dom/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,
@@ -764,16 +772,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();
     }
   }