Bug 951117 - [RTSP][Video][V1.3] Crash happened while stop playing RTSP strreaming. r=sworkman, a=1.3+
authorEthan Tseng <ettseng@mozilla.com>
Mon, 23 Dec 2013 17:05:11 +0800
changeset 175570 dc95e43fc5dd0d3110b1d8be11cf804fa2b833a4
parent 175569 bad5fd00645efc1b346a3d8e9da85dd80c3ecc80
child 175571 4b45e4f20261d08982b944f15cc8dda5d6cb735b
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssworkman, 1
bugs951117
milestone28.0a2
Bug 951117 - [RTSP][Video][V1.3] Crash happened while stop playing RTSP strreaming. r=sworkman, a=1.3+
content/media/RtspMediaResource.cpp
--- a/content/media/RtspMediaResource.cpp
+++ b/content/media/RtspMediaResource.cpp
@@ -472,16 +472,20 @@ RtspMediaResource::OnConnected(uint8_t a
     trackMeta->GetHeight(&h);
     slotSize = clamped((int32_t)(w * h), BUFFER_SLOT_DEFAULT_SIZE,
                        BUFFER_SLOT_MAX_SIZE);
     mTrackBuffer.AppendElement(new RtspTrackBuffer(rtspTrackId.get(),
                                                    i, slotSize));
     mTrackBuffer[i]->Start();
   }
 
+  if (!mDecoder) {
+    return NS_ERROR_FAILURE;
+  }
+
   // If the duration is 0, imply the stream is live stream.
   if (duration) {
     // Not live stream.
     mRealTime = false;
     bool seekable = true;
     mDecoder->SetInfinite(false);
     mDecoder->SetTransportSeekable(seekable);
     mDecoder->SetDuration(duration);
@@ -522,16 +526,23 @@ RtspMediaResource::OnDisconnected(uint8_
 {
   NS_ASSERTION(NS_IsMainThread(), "Don't call on non-main thread");
 
   for (uint32_t i = 0 ; i < mTrackBuffer.Length(); ++i) {
     mTrackBuffer[i]->Stop();
     mTrackBuffer[i]->Reset();
   }
 
+  // If mDecoder is null pointer, it means this OnDisconnected event is
+  // triggered when media element was destroyed and mDecoder was already
+  // shutdown.
+  if (!mDecoder) {
+    return NS_OK;
+  }
+
   if (aReason == NS_ERROR_NOT_INITIALIZED ||
       aReason == NS_ERROR_CONNECTION_REFUSED ||
       aReason == NS_ERROR_NOT_CONNECTED) {
 
     RTSPMLOG("Error in OnDisconnected 0x%x", aReason);
 
     mDecoder->NetworkError();
     return NS_OK;
@@ -575,16 +586,22 @@ nsresult RtspMediaResource::Open(nsIStre
 {
   return NS_OK;
 }
 
 nsresult RtspMediaResource::Close()
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
   mMediaStreamController->Stop();
+  // Since mDecoder is not an nsCOMPtr in BaseMediaResource, we have to
+  // explicitly set it as null pointer in order to prevent misuse from this
+  // object (RtspMediaResource).
+  if (mDecoder) {
+    mDecoder = nullptr;
+  }
   return NS_OK;
 }
 
 already_AddRefed<nsIPrincipal> RtspMediaResource::GetCurrentPrincipal()
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
   nsCOMPtr<nsIPrincipal> principal;