Bug 1416724 - part 3 - AbstractThread::Dispatch return value check in dom/media, r=jwwang
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 15 Nov 2017 07:58:03 +0100
changeset 391970 ddbbd455f0589af4de3d2046528e575d820e9e5b
parent 391969 64c4030422704671d85e17092cb4de01dc6c0528
child 391971 05c7a8ba56328d53baf87acb2f810649c8c24d3e
push id32909
push usercbrindusan@mozilla.com
push dateWed, 15 Nov 2017 22:25:14 +0000
treeherdermozilla-central@f41930a869a8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwwang
bugs1416724
milestone59.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 1416724 - part 3 - AbstractThread::Dispatch return value check in dom/media, r=jwwang
dom/media/MediaDecoder.cpp
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
dom/media/MediaEventSource.h
dom/media/MediaFormatReader.cpp
dom/media/MediaRecorder.cpp
dom/media/ReaderProxy.cpp
dom/media/encoder/MediaEncoder.cpp
dom/media/gtest/TestMP4Demuxer.cpp
dom/media/hls/HLSDemuxer.cpp
dom/media/mediasource/AutoTaskQueue.h
dom/media/mediasource/MediaSourceDemuxer.cpp
dom/media/mediasource/TrackBuffersManager.cpp
dom/media/platforms/android/RemoteDataDecoder.cpp
dom/media/platforms/omx/OmxDataDecoder.cpp
dom/media/webaudio/MediaBufferDecoder.cpp
media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -20,16 +20,17 @@
 #include "mozilla/Preferences.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/dom/AudioTrack.h"
 #include "mozilla/dom/AudioTrackList.h"
 #include "mozilla/dom/VideoTrack.h"
 #include "mozilla/dom/VideoTrackList.h"
 #include "mozilla/layers/ShadowLayers.h"
+#include "mozilla/Unused.h"
 #include "nsComponentManagerUtils.h"
 #include "nsContentUtils.h"
 #include "nsError.h"
 #include "nsIMemoryReporter.h"
 #include "nsIObserver.h"
 #include "nsPrintfCString.h"
 #include "nsTArray.h"
 #include <algorithm>
@@ -1094,18 +1095,17 @@ MediaDecoder::NotifyCompositor()
   RefPtr<KnowsCompositor> knowsCompositor = GetCompositor();
   if (knowsCompositor) {
     nsCOMPtr<nsIRunnable> r =
       NewRunnableMethod<already_AddRefed<KnowsCompositor>&&>(
         "MediaFormatReader::UpdateCompositor",
         mReader,
         &MediaFormatReader::UpdateCompositor,
         knowsCompositor.forget());
-    mReader->OwnerThread()->Dispatch(r.forget(),
-                                     AbstractThread::DontAssertDispatchSuccess);
+    Unused << mReader->OwnerThread()->Dispatch(r.forget());
   }
 }
 
 void
 MediaDecoder::SetElementVisibility(bool aIsDocumentVisible,
                                    Visibility aElementVisibility,
                                    bool aIsElementInTree)
 {
@@ -1375,20 +1375,23 @@ MediaDecoder::SizeOfAudioQueue()
   return 0;
 }
 
 void
 MediaDecoder::NotifyDataArrivedInternal()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
-  mReader->OwnerThread()->Dispatch(
-    NewRunnableMethod("MediaFormatReader::NotifyDataArrived",
-                      mReader.get(),
-                      &MediaFormatReader::NotifyDataArrived));
+
+  nsresult rv =
+    mReader->OwnerThread()->Dispatch(
+      NewRunnableMethod("MediaFormatReader::NotifyDataArrived",
+                        mReader.get(),
+                        &MediaFormatReader::NotifyDataArrived));
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 void
 MediaDecoder::NotifyDataArrived()
 {
   NotifyDataArrivedInternal();
   DownloadProgressed();
 }
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1495,17 +1495,18 @@ public:
     // then switch to the CompletedState which dispatches an "ended" event.
     // However, the ThenValue of the SeekPromise has not yet been set, so the
     // promise resolving is postponed and then the JS developer receives the
     // "ended" event before the seek promise is resolved.
     // An asynchronous seek operation helps to solve this issue since while the
     // seek is actually performed, the ThenValue of SeekPromise has already
     // been set so that it won't be postponed.
     RefPtr<Runnable> r = mAsyncSeekTask = new AysncNextFrameSeekTask(this);
-    OwnerThread()->Dispatch(r.forget());
+    nsresult rv = OwnerThread()->Dispatch(r.forget());
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
 private:
   void DoSeekInternal()
   {
     // We don't need to discard frames to the mCurrentTime here because we have
     // done it at DoSeek() and any video data received in between either
     // finishes the seek operation or be discarded, see HandleVideoDecoded().
@@ -3492,20 +3493,22 @@ void
 MediaDecoderStateMachine::ScheduleStateMachine()
 {
   MOZ_ASSERT(OnTaskQueue());
   if (mDispatchedStateMachine) {
     return;
   }
   mDispatchedStateMachine = true;
 
-  OwnerThread()->Dispatch(
-    NewRunnableMethod("MediaDecoderStateMachine::RunStateMachine",
-                      this,
-                      &MediaDecoderStateMachine::RunStateMachine));
+  nsresult rv =
+    OwnerThread()->Dispatch(
+      NewRunnableMethod("MediaDecoderStateMachine::RunStateMachine",
+                        this,
+                        &MediaDecoderStateMachine::RunStateMachine));
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 void
 MediaDecoderStateMachine::ScheduleStateMachineIn(const TimeUnit& aTime)
 {
   MOZ_ASSERT(OnTaskQueue()); // mDelayedScheduler.Ensure() may Disconnect()
                              // the promise, which must happen on the state
                              // machine task queue.
@@ -3725,51 +3728,53 @@ MediaDecoderStateMachine::GetDebugInfo()
 }
 
 RefPtr<MediaDecoder::DebugInfoPromise>
 MediaDecoderStateMachine::RequestDebugInfo()
 {
   using PromiseType = MediaDecoder::DebugInfoPromise;
   RefPtr<PromiseType::Private> p = new PromiseType::Private(__func__);
   RefPtr<MediaDecoderStateMachine> self = this;
-  OwnerThread()->Dispatch(
+  nsresult rv = OwnerThread()->Dispatch(
     NS_NewRunnableFunction(
       "MediaDecoderStateMachine::RequestDebugInfo",
       [self, p]() { p->Resolve(self->GetDebugInfo(), __func__); }),
-    AbstractThread::AssertDispatchSuccess,
     AbstractThread::TailDispatch);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   return p.forget();
 }
 
 void MediaDecoderStateMachine::AddOutputStream(ProcessedMediaStream* aStream,
                                                bool aFinishWhenEnded)
 {
   MOZ_ASSERT(NS_IsMainThread());
   LOG("AddOutputStream aStream=%p!", aStream);
   mOutputStreamManager->Add(aStream, aFinishWhenEnded);
   nsCOMPtr<nsIRunnable> r =
     NewRunnableMethod<bool>("MediaDecoderStateMachine::SetAudioCaptured",
                             this,
                             &MediaDecoderStateMachine::SetAudioCaptured,
                             true);
-  OwnerThread()->Dispatch(r.forget());
+  nsresult rv = OwnerThread()->Dispatch(r.forget());
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 void MediaDecoderStateMachine::RemoveOutputStream(MediaStream* aStream)
 {
   MOZ_ASSERT(NS_IsMainThread());
   LOG("RemoveOutputStream=%p!", aStream);
   mOutputStreamManager->Remove(aStream);
   if (mOutputStreamManager->IsEmpty()) {
     nsCOMPtr<nsIRunnable> r =
       NewRunnableMethod<bool>("MediaDecoderStateMachine::SetAudioCaptured",
                               this,
                               &MediaDecoderStateMachine::SetAudioCaptured,
                               false);
-    OwnerThread()->Dispatch(r.forget());
+    nsresult rv = OwnerThread()->Dispatch(r.forget());
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 }
 
 class VideoQueueMemoryFunctor : public nsDequeFunctor
 {
 public:
   VideoQueueMemoryFunctor()
     : mSize(0)
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -199,17 +199,18 @@ public:
     nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
       "MediaDecoderStateMachine::DispatchSetFragmentEndTime",
       [self, aEndTime]() {
         // A negative number means we don't have a fragment end time at all.
         self->mFragmentEndTime = aEndTime >= media::TimeUnit::Zero()
                                    ? aEndTime
                                    : media::TimeUnit::Invalid();
       });
-    OwnerThread()->Dispatch(r.forget());
+    nsresult rv = OwnerThread()->Dispatch(r.forget());
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
   void DispatchCanPlayThrough(bool aCanPlayThrough)
   {
     RefPtr<MediaDecoderStateMachine> self = this;
     nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
       "MediaDecoderStateMachine::DispatchCanPlayThrough",
       [self, aCanPlayThrough]() {
--- a/dom/media/MediaEventSource.h
+++ b/dom/media/MediaEventSource.h
@@ -8,16 +8,17 @@
 #define MediaEventSource_h_
 
 #include "mozilla/AbstractThread.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/IndexSequence.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Tuple.h"
 #include "mozilla/TypeTraits.h"
+#include "mozilla/Unused.h"
 
 #include "nsISupportsImpl.h"
 #include "nsTArray.h"
 #include "nsThreadUtils.h"
 
 namespace mozilla {
 
 /**
@@ -104,17 +105,17 @@ struct EventTarget<nsIEventTarget> {
     aTarget->Dispatch(Move(aTask), NS_DISPATCH_NORMAL);
   }
 };
 
 template <>
 struct EventTarget<AbstractThread> {
   static void
   Dispatch(AbstractThread* aTarget, already_AddRefed<nsIRunnable> aTask) {
-    aTarget->Dispatch(Move(aTask), AbstractThread::DontAssertDispatchSuccess);
+    Unused << aTarget->Dispatch(Move(aTask));
   }
 };
 
 /**
  * Encapsulate a raw pointer to be captured by a lambda without causing
  * static-analysis errors.
  */
 template <typename T>
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1020,19 +1020,21 @@ public:
   bool GetSamplesMayBlock() const override
   {
     return mGetSamplesMayBlock;
   }
 
   void Reset() override
   {
     RefPtr<Wrapper> self = this;
-    mTaskQueue->Dispatch(
-      NS_NewRunnableFunction("MediaFormatReader::DemuxerProxy::Wrapper::Reset",
-                             [self]() { self->mTrackDemuxer->Reset(); }));
+    nsresult rv =
+      mTaskQueue->Dispatch(
+        NS_NewRunnableFunction("MediaFormatReader::DemuxerProxy::Wrapper::Reset",
+                               [self]() { self->mTrackDemuxer->Reset(); }));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
   nsresult GetNextRandomAccessPoint(TimeUnit* aTime) override
   {
     MutexAutoLock lock(mMutex);
     if (NS_SUCCEEDED(mNextRandomAccessPointResult)) {
       *aTime = mNextRandomAccessPoint;
     }
@@ -1079,19 +1081,21 @@ private:
   nsresult mNextRandomAccessPointResult = NS_OK;
   TimeUnit mNextRandomAccessPoint;
   TimeIntervals mBuffered;
   friend class DemuxerProxy;
 
   ~Wrapper()
   {
     RefPtr<MediaTrackDemuxer> trackDemuxer = mTrackDemuxer.forget();
-    mTaskQueue->Dispatch(NS_NewRunnableFunction(
-      "MediaFormatReader::DemuxerProxy::Wrapper::~Wrapper",
-      [trackDemuxer]() { trackDemuxer->BreakCycles(); }));
+    nsresult rv =
+      mTaskQueue->Dispatch(NS_NewRunnableFunction(
+        "MediaFormatReader::DemuxerProxy::Wrapper::~Wrapper",
+        [trackDemuxer]() { trackDemuxer->BreakCycles(); }));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
   void UpdateRandomAccessPoint()
   {
     MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
     if (!mTrackDemuxer) {
       // Detached.
       return;
@@ -1989,17 +1993,18 @@ MediaFormatReader::ScheduleUpdate(TrackT
   auto& decoder = GetDecoderData(aTrack);
   if (decoder.mUpdateScheduled) {
     return;
   }
   LOGV("SchedulingUpdate(%s)", TrackTypeToStr(aTrack));
   decoder.mUpdateScheduled = true;
   RefPtr<nsIRunnable> task(NewRunnableMethod<TrackType>(
     "MediaFormatReader::Update", this, &MediaFormatReader::Update, aTrack));
-  OwnerThread()->Dispatch(task.forget());
+  nsresult rv = OwnerThread()->Dispatch(task.forget());
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 bool
 MediaFormatReader::UpdateReceivedNewData(TrackType aTrack)
 {
   MOZ_ASSERT(OnTaskQueue());
   auto& decoder = GetDecoderData(aTrack);
 
@@ -2887,18 +2892,20 @@ MediaFormatReader::SetSeekTarget(const S
 
 void
 MediaFormatReader::ScheduleSeek()
 {
   if (mSeekScheduled) {
     return;
   }
   mSeekScheduled = true;
-  OwnerThread()->Dispatch(NewRunnableMethod(
-    "MediaFormatReader::AttemptSeek", this, &MediaFormatReader::AttemptSeek));
+  nsresult rv =
+    OwnerThread()->Dispatch(NewRunnableMethod(
+      "MediaFormatReader::AttemptSeek", this, &MediaFormatReader::AttemptSeek));
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 void
 MediaFormatReader::AttemptSeek()
 {
   MOZ_ASSERT(OnTaskQueue());
 
   mSeekScheduled = false;
--- a/dom/media/MediaRecorder.cpp
+++ b/dom/media/MediaRecorder.cpp
@@ -957,20 +957,22 @@ private:
 
     if (!mEncoder) {
       LOG(LogLevel::Error, ("Session.InitEncoder !mEncoder %p", this));
       DoSessionEndTask(NS_ERROR_ABORT);
       return;
     }
 
     mEncoderListener = MakeAndAddRef<EncoderListener>(mEncoderThread, this);
-    mEncoderThread->Dispatch(
-      NewRunnableMethod<RefPtr<EncoderListener>>(
-        "mozilla::MediaEncoder::RegisterListener",
-        mEncoder, &MediaEncoder::RegisterListener, mEncoderListener));
+    nsresult rv =
+      mEncoderThread->Dispatch(
+        NewRunnableMethod<RefPtr<EncoderListener>>(
+          "mozilla::MediaEncoder::RegisterListener",
+          mEncoder, &MediaEncoder::RegisterListener, mEncoderListener));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 
     if (mRecorder->mAudioNode) {
       mEncoder->ConnectAudioNode(mRecorder->mAudioNode,
                                  mRecorder->mAudioNodeOutput);
     }
 
     for (auto& track : mMediaStreamTracks) {
       mEncoder->ConnectMediaStreamTrack(track);
--- a/dom/media/ReaderProxy.cpp
+++ b/dom/media/ReaderProxy.cpp
@@ -130,29 +130,31 @@ ReaderProxy::WaitForData(MediaData::Type
 void
 ReaderProxy::ReleaseResources()
 {
   MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
   nsCOMPtr<nsIRunnable> r =
     NewRunnableMethod("MediaFormatReader::ReleaseResources",
                       mReader,
                       &MediaFormatReader::ReleaseResources);
-  mReader->OwnerThread()->Dispatch(r.forget());
+  nsresult rv = mReader->OwnerThread()->Dispatch(r.forget());
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 void
 ReaderProxy::ResetDecode(TrackSet aTracks)
 {
   MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
   nsCOMPtr<nsIRunnable> r =
     NewRunnableMethod<TrackSet>("MediaFormatReader::ResetDecode",
                                 mReader,
                                 &MediaFormatReader::ResetDecode,
                                 aTracks);
-  mReader->OwnerThread()->Dispatch(r.forget());
+  nsresult rv = mReader->OwnerThread()->Dispatch(r.forget());
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 RefPtr<ShutdownPromise>
 ReaderProxy::Shutdown()
 {
   MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
   mShutdown = true;
   RefPtr<ReaderProxy> self = this;
@@ -188,17 +190,18 @@ void
 ReaderProxy::SetVideoBlankDecode(bool aIsBlankDecode)
 {
   MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
   nsCOMPtr<nsIRunnable> r =
     NewRunnableMethod<bool>("MediaFormatReader::SetVideoNullDecode",
                             mReader,
                             &MediaFormatReader::SetVideoNullDecode,
                             aIsBlankDecode);
-  mReader->OwnerThread()->Dispatch(r.forget());
+  nsresult rv = mReader->OwnerThread()->Dispatch(r.forget());
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 void
 ReaderProxy::UpdateDuration()
 {
   MOZ_ASSERT(mReader->OwnerThread()->IsCurrentThreadIn());
   mReader->UpdateDuration(mDuration.Ref().ref());
 }
@@ -210,12 +213,13 @@ ReaderProxy::SetCanonicalDuration(
   using DurationT = AbstractCanonical<media::NullableTimeUnit>;
   RefPtr<ReaderProxy> self = this;
   RefPtr<DurationT> canonical = aCanonical;
   nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
     "ReaderProxy::SetCanonicalDuration", [this, self, canonical]() {
       mDuration.Connect(canonical);
       mWatchManager.Watch(mDuration, &ReaderProxy::UpdateDuration);
     });
-  mReader->OwnerThread()->Dispatch(r.forget());
+  nsresult rv = mReader->OwnerThread()->Dispatch(r.forget());
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 } // namespace mozilla
--- a/dom/media/encoder/MediaEncoder.cpp
+++ b/dom/media/encoder/MediaEncoder.cpp
@@ -16,16 +16,17 @@
 #include "mozilla/dom/MediaStreamTrack.h"
 #include "mozilla/dom/VideoStreamTrack.h"
 #include "mozilla/gfx/Point.h" // IntSize
 #include "mozilla/Logging.h"
 #include "mozilla/media/MediaUtils.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/TaskQueue.h"
+#include "mozilla/Unused.h"
 #include "nsIPrincipal.h"
 #include "nsMimeTypes.h"
 #include "OggWriter.h"
 #include "OpusTrackEncoder.h"
 #include "TimeUnits.h"
 
 #ifdef MOZ_WEBM_ENCODER
 #include "VP8TrackEncoder.h"
@@ -91,41 +92,47 @@ public:
     MOZ_ASSERT(mEncoder);
     MOZ_ASSERT(mEncoderThread);
 
     if (mShutdown) {
       return;
     }
 
     if (!mInitialized) {
-      mEncoderThread->Dispatch(
-        NewRunnableMethod<StreamTime>(
-          "mozilla::AudioTrackEncoder::SetStartOffset",
-          mEncoder, &AudioTrackEncoder::SetStartOffset, aTrackOffset));
+      nsresult rv =
+        mEncoderThread->Dispatch(
+          NewRunnableMethod<StreamTime>(
+            "mozilla::AudioTrackEncoder::SetStartOffset",
+            mEncoder, &AudioTrackEncoder::SetStartOffset, aTrackOffset));
+      MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
       mInitialized = true;
     }
 
     if (mDirectConnected) {
       if (aQueuedMedia.IsNull()) {
-        mEncoderThread->Dispatch(
-          NewRunnableMethod<StreamTime>(
-            "mozilla::AudioTrackEncoder::AdvanceBlockedInput",
-            mEncoder, &AudioTrackEncoder::AdvanceBlockedInput,
-            aQueuedMedia.GetDuration()));
+        nsresult rv =
+          mEncoderThread->Dispatch(
+            NewRunnableMethod<StreamTime>(
+              "mozilla::AudioTrackEncoder::AdvanceBlockedInput",
+              mEncoder, &AudioTrackEncoder::AdvanceBlockedInput,
+              aQueuedMedia.GetDuration()));
+        MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
         return;
       }
     } else {
       NotifyRealtimeTrackData(aGraph, aTrackOffset, aQueuedMedia);
     }
 
-    mEncoderThread->Dispatch(
-      NewRunnableMethod<StreamTime>(
-        "mozilla::AudioTrackEncoder::AdvanceCurrentTime",
-        mEncoder, &AudioTrackEncoder::AdvanceCurrentTime,
-        aQueuedMedia.GetDuration()));
+    nsresult rv =
+      mEncoderThread->Dispatch(
+        NewRunnableMethod<StreamTime>(
+          "mozilla::AudioTrackEncoder::AdvanceCurrentTime",
+          mEncoder, &AudioTrackEncoder::AdvanceCurrentTime,
+          aQueuedMedia.GetDuration()));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
   void NotifyRealtimeTrackData(MediaStreamGraph* aGraph,
                                StreamTime aTrackOffset,
                                const MediaSegment& aMedia) override
   {
     MOZ_ASSERT(mEncoder);
     MOZ_ASSERT(mEncoderThread);
@@ -134,42 +141,48 @@ public:
       return;
     }
 
     const AudioSegment& audio = static_cast<const AudioSegment&>(aMedia);
 
     AudioSegment copy;
     copy.AppendSlice(audio, 0, audio.GetDuration());
 
-    mEncoderThread->Dispatch(
-      NewRunnableMethod<StoreCopyPassByRRef<AudioSegment>>(
-        "mozilla::AudioTrackEncoder::AppendAudioSegment",
-        mEncoder, &AudioTrackEncoder::AppendAudioSegment, Move(copy)));
+    nsresult rv =
+      mEncoderThread->Dispatch(
+        NewRunnableMethod<StoreCopyPassByRRef<AudioSegment>>(
+          "mozilla::AudioTrackEncoder::AppendAudioSegment",
+          mEncoder, &AudioTrackEncoder::AppendAudioSegment, Move(copy)));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
   void NotifyEnded() override
   {
     MOZ_ASSERT(mEncoder);
     MOZ_ASSERT(mEncoderThread);
 
     if (mShutdown) {
       return;
     }
 
-    mEncoderThread->Dispatch(
-      NewRunnableMethod("mozilla::AudioTrackEncoder::NotifyEndOfStream",
-                        mEncoder, &AudioTrackEncoder::NotifyEndOfStream));
+    nsresult rv =
+      mEncoderThread->Dispatch(
+        NewRunnableMethod("mozilla::AudioTrackEncoder::NotifyEndOfStream",
+                          mEncoder, &AudioTrackEncoder::NotifyEndOfStream));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
   void NotifyRemoved() override
   {
     if (!mShutdown) {
-      mEncoderThread->Dispatch(
-        NewRunnableMethod("mozilla::AudioTrackEncoder::NotifyEndOfStream",
-                          mEncoder, &AudioTrackEncoder::NotifyEndOfStream));
+      nsresult rv =
+        mEncoderThread->Dispatch(
+          NewRunnableMethod("mozilla::AudioTrackEncoder::NotifyEndOfStream",
+                            mEncoder, &AudioTrackEncoder::NotifyEndOfStream));
+      MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
     }
 
     mRemoved = true;
 
     if (!mDirectConnected) {
       mEncoder = nullptr;
       mEncoderThread = nullptr;
     }
@@ -233,79 +246,91 @@ public:
     MOZ_ASSERT(mEncoder);
     MOZ_ASSERT(mEncoderThread);
 
     if (mShutdown) {
       return;
     }
 
     if (!mInitialized) {
-      mEncoderThread->Dispatch(
-        NewRunnableMethod<StreamTime>(
-          "mozilla::VideoTrackEncoder::SetStartOffset",
-          mEncoder, &VideoTrackEncoder::SetStartOffset, aTrackOffset));
+      nsresult rv =
+        mEncoderThread->Dispatch(
+          NewRunnableMethod<StreamTime>(
+            "mozilla::VideoTrackEncoder::SetStartOffset",
+            mEncoder, &VideoTrackEncoder::SetStartOffset, aTrackOffset));
+      MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
       mInitialized = true;
     }
 
     if (aQueuedMedia.IsNull()) {
-      mEncoderThread->Dispatch(
-        NewRunnableMethod<StreamTime>(
-          "mozilla::VideoTrackEncoder::AdvanceBlockedInput",
-          mEncoder, &VideoTrackEncoder::AdvanceBlockedInput,
-          aQueuedMedia.GetDuration()));
+      nsresult rv =
+        mEncoderThread->Dispatch(
+          NewRunnableMethod<StreamTime>(
+            "mozilla::VideoTrackEncoder::AdvanceBlockedInput",
+            mEncoder, &VideoTrackEncoder::AdvanceBlockedInput,
+            aQueuedMedia.GetDuration()));
+      MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
       return;
     }
 
-    mEncoderThread->Dispatch(
-      NewRunnableMethod<StreamTime>(
-        "mozilla::VideoTrackEncoder::AdvanceCurrentTime",
-        mEncoder, &VideoTrackEncoder::AdvanceCurrentTime,
-        aQueuedMedia.GetDuration()));
+    nsresult rv =
+      mEncoderThread->Dispatch(
+        NewRunnableMethod<StreamTime>(
+          "mozilla::VideoTrackEncoder::AdvanceCurrentTime",
+          mEncoder, &VideoTrackEncoder::AdvanceCurrentTime,
+          aQueuedMedia.GetDuration()));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
   void SetCurrentFrames(const VideoSegment& aMedia) override
   {
     MOZ_ASSERT(mEncoder);
     MOZ_ASSERT(mEncoderThread);
 
     if (mShutdown) {
       return;
     }
 
     VideoSegment copy;
     copy.AppendSlice(aMedia, 0, aMedia.GetDuration());
 
-    mEncoderThread->Dispatch(
-      NewRunnableMethod<StoreCopyPassByRRef<VideoSegment>>(
-        "mozilla::VideoTrackEncoder::AppendVideoSegment",
-        mEncoder, &VideoTrackEncoder::AppendVideoSegment, Move(copy)));
+    nsresult rv =
+      mEncoderThread->Dispatch(
+        NewRunnableMethod<StoreCopyPassByRRef<VideoSegment>>(
+          "mozilla::VideoTrackEncoder::AppendVideoSegment",
+          mEncoder, &VideoTrackEncoder::AppendVideoSegment, Move(copy)));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
   void ClearFrames() override {}
 
   void NotifyEnded() override
   {
     MOZ_ASSERT(mEncoder);
     MOZ_ASSERT(mEncoderThread);
 
     if (mShutdown) {
       return;
     }
 
-    mEncoderThread->Dispatch(
-      NewRunnableMethod("mozilla::VideoTrackEncoder::NotifyEndOfStream",
-                        mEncoder, &VideoTrackEncoder::NotifyEndOfStream));
+    nsresult rv =
+      mEncoderThread->Dispatch(
+        NewRunnableMethod("mozilla::VideoTrackEncoder::NotifyEndOfStream",
+                          mEncoder, &VideoTrackEncoder::NotifyEndOfStream));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
   void NotifyRemoved() override
   {
     if (!mShutdown) {
-      mEncoderThread->Dispatch(
-        NewRunnableMethod("mozilla::VideoTrackEncoder::NotifyEndOfStream",
-                          mEncoder, &VideoTrackEncoder::NotifyEndOfStream));
+      nsresult rv =
+        mEncoderThread->Dispatch(
+          NewRunnableMethod("mozilla::VideoTrackEncoder::NotifyEndOfStream",
+                            mEncoder, &VideoTrackEncoder::NotifyEndOfStream));
+      MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
     }
 
     mRemoved = true;
 
     if (!mDirectConnected) {
       mEncoder = nullptr;
       mEncoderThread = nullptr;
     }
@@ -340,37 +365,41 @@ public:
   {
     MOZ_ASSERT(mEncoderThread->IsCurrentThreadIn());
     MOZ_ASSERT(aTrackEncoder->IsInitialized());
 
     if (!mEncoder) {
       return;
     }
 
-    mEncoderThread->Dispatch(
-      NewRunnableMethod("mozilla::MediaEncoder::NotifyInitialized",
-                        mEncoder, &MediaEncoder::NotifyInitialized));
+    nsresult rv =
+      mEncoderThread->Dispatch(
+        NewRunnableMethod("mozilla::MediaEncoder::NotifyInitialized",
+                          mEncoder, &MediaEncoder::NotifyInitialized));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
   void DataAvailable(TrackEncoder* aTrackEncoder) override
   {
     MOZ_ASSERT(mEncoderThread->IsCurrentThreadIn());
     MOZ_ASSERT(aTrackEncoder->IsInitialized());
 
     if (!mEncoder) {
       return;
     }
 
     if (mPendingDataAvailable) {
       return;
     }
 
-    mEncoderThread->Dispatch(
-      NewRunnableMethod("mozilla::MediaEncoder::EncoderListener::DataAvailableImpl",
-                        this, &EncoderListener::DataAvailableImpl));
+    nsresult rv =
+      mEncoderThread->Dispatch(
+        NewRunnableMethod("mozilla::MediaEncoder::EncoderListener::DataAvailableImpl",
+                          this, &EncoderListener::DataAvailableImpl));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 
     mPendingDataAvailable = true;
   }
 
   void DataAvailableImpl()
   {
     MOZ_ASSERT(mEncoderThread->IsCurrentThreadIn());
 
@@ -385,19 +414,21 @@ public:
   void Error(TrackEncoder* aTrackEncoder) override
   {
     MOZ_ASSERT(mEncoderThread->IsCurrentThreadIn());
 
     if (!mEncoder) {
       return;
     }
 
-    mEncoderThread->Dispatch(
-      NewRunnableMethod("mozilla::MediaEncoder::SetError",
-                        mEncoder, &MediaEncoder::SetError));
+    nsresult rv =
+      mEncoderThread->Dispatch(
+        NewRunnableMethod("mozilla::MediaEncoder::SetError",
+                          mEncoder, &MediaEncoder::SetError));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
 protected:
   RefPtr<TaskQueue> mEncoderThread;
   RefPtr<MediaEncoder> mEncoder;
   bool mPendingDataAvailable;
 };
 
@@ -418,66 +449,76 @@ MediaEncoder::MediaEncoder(TaskQueue* aE
   , mCompleted(false)
   , mError(false)
   , mCanceled(false)
   , mShutdown(false)
 {
   if (mAudioEncoder) {
     mAudioListener =
       MakeAndAddRef<AudioTrackListener>(mAudioEncoder, mEncoderThread);
-    mEncoderThread->Dispatch(
-      NewRunnableMethod<RefPtr<EncoderListener>>(
-        "mozilla::AudioTrackEncoder::RegisterListener",
-        mAudioEncoder, &AudioTrackEncoder::RegisterListener, mEncoderListener));
+    nsresult rv =
+      mEncoderThread->Dispatch(
+        NewRunnableMethod<RefPtr<EncoderListener>>(
+          "mozilla::AudioTrackEncoder::RegisterListener",
+          mAudioEncoder, &AudioTrackEncoder::RegisterListener,
+          mEncoderListener));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
   if (mVideoEncoder) {
     mVideoListener =
       MakeAndAddRef<VideoTrackListener>(mVideoEncoder, mEncoderThread);
-    mEncoderThread->Dispatch(
-      NewRunnableMethod<RefPtr<EncoderListener>>(
-        "mozilla::VideoTrackEncoder::RegisterListener",
-        mVideoEncoder, &VideoTrackEncoder::RegisterListener, mEncoderListener));
+    nsresult rv =
+      mEncoderThread->Dispatch(
+        NewRunnableMethod<RefPtr<EncoderListener>>(
+          "mozilla::VideoTrackEncoder::RegisterListener",
+          mVideoEncoder, &VideoTrackEncoder::RegisterListener,
+          mEncoderListener));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 }
 
 MediaEncoder::~MediaEncoder()
 {
   MOZ_ASSERT(mListeners.IsEmpty());
 }
 
 void
 MediaEncoder::Suspend(TimeStamp aTime)
 {
   auto& ae = mAudioEncoder;
   auto& ve = mVideoEncoder;
-  mEncoderThread->Dispatch(NewRunnableFrom([ae, ve, aTime]() {
-    if (ae) {
-      ae->Suspend(aTime);
-    }
-    if (ve) {
-      ve->Suspend(aTime);
-    }
-    return NS_OK;
-  }));
+  nsresult rv =
+    mEncoderThread->Dispatch(NewRunnableFrom([ae, ve, aTime]() {
+      if (ae) {
+        ae->Suspend(aTime);
+      }
+      if (ve) {
+        ve->Suspend(aTime);
+      }
+      return NS_OK;
+    }));
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 void
 MediaEncoder::Resume(TimeStamp aTime)
 {
   auto& ae = mAudioEncoder;
   auto& ve = mVideoEncoder;
-  mEncoderThread->Dispatch(NewRunnableFrom([ae, ve, aTime]() {
-    if (ae) {
-      ae->Resume(aTime);
-    }
-    if (ve) {
-      ve->Resume(aTime);
-    }
-    return NS_OK;
-  }));
+  nsresult rv =
+    mEncoderThread->Dispatch(NewRunnableFrom([ae, ve, aTime]() {
+      if (ae) {
+        ae->Resume(aTime);
+      }
+      if (ve) {
+        ve->Resume(aTime);
+      }
+      return NS_OK;
+    }));
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 void
 MediaEncoder::ConnectAudioNode(AudioNode* aNode, uint32_t aOutput)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (mAudioNode) {
@@ -832,19 +873,21 @@ MediaEncoder::Shutdown()
     // Shutting down after being canceled. We cannot use the encoder thread.
     return;
   }
 
   auto listeners(mListeners);
   for (auto& l : listeners) {
     // We dispatch here since this method is typically called from
     // a DataAvailable() handler.
-    mEncoderThread->Dispatch(
-      NewRunnableMethod("mozilla::MediaEncoderListener::Shutdown",
-                        l, &MediaEncoderListener::Shutdown));
+    nsresult rv =
+      mEncoderThread->Dispatch(
+        NewRunnableMethod("mozilla::MediaEncoderListener::Shutdown",
+                          l, &MediaEncoderListener::Shutdown));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 }
 
 nsresult
 MediaEncoder::WriteEncodedDataToMuxer(TrackEncoder *aTrackEncoder)
 {
   AUTO_PROFILER_LABEL("MediaEncoder::WriteEncodedDataToMuxer", OTHER);
 
@@ -912,28 +955,30 @@ MediaEncoder::IsShutdown()
 }
 
 void
 MediaEncoder::Cancel()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   RefPtr<MediaEncoder> self = this;
-  mEncoderThread->Dispatch(NewRunnableFrom([self]() mutable {
-    self->mCanceled = true;
+  nsresult rv =
+    mEncoderThread->Dispatch(NewRunnableFrom([self]() mutable {
+      self->mCanceled = true;
 
-    if (self->mAudioEncoder) {
-      self->mAudioEncoder->Cancel();
-    }
-    if (self->mVideoEncoder) {
-      self->mVideoEncoder->Cancel();
-    }
-    self->Shutdown();
-    return NS_OK;
-  }));
+      if (self->mAudioEncoder) {
+        self->mAudioEncoder->Cancel();
+      }
+      if (self->mVideoEncoder) {
+        self->mVideoEncoder->Cancel();
+      }
+      self->Shutdown();
+      return NS_OK;
+    }));
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 bool
 MediaEncoder::HasError()
 {
   MOZ_ASSERT(mEncoderThread->IsCurrentThreadIn());
   return mError;
 }
--- a/dom/media/gtest/TestMP4Demuxer.cpp
+++ b/dom/media/gtest/TestMP4Demuxer.cpp
@@ -5,16 +5,17 @@
 
 #include "gtest/gtest.h"
 #include "MP4Demuxer.h"
 #include "mozilla/MozPromise.h"
 #include "MediaDataDemuxer.h"
 #include "mozilla/SharedThreadPool.h"
 #include "mozilla/TaskQueue.h"
 #include "mozilla/ArrayUtils.h"
+#include "mozilla/Unused.h"
 #include "MockMediaResource.h"
 #include "VideoUtils.h"
 
 using namespace mozilla;
 using namespace mp4_demuxer;
 using media::TimeUnit;
 
 class AutoTaskQueue;
@@ -144,17 +145,17 @@ public:
 private:
 
   template<typename FunctionType>
   void
   DispatchTask(FunctionType aFun)
   {
     RefPtr<Runnable> r =
       NS_NewRunnableFunction("MP4DemuxerBinding::DispatchTask", aFun);
-    mTaskQueue->Dispatch(r.forget());
+    Unused << mTaskQueue->Dispatch(r.forget());
   }
 
   virtual ~MP4DemuxerBinding()
   {
   }
 };
 
 TEST(MP4Demuxer, Seek)
--- a/dom/media/hls/HLSDemuxer.cpp
+++ b/dom/media/hls/HLSDemuxer.cpp
@@ -81,40 +81,44 @@ public:
   }
 
   void OnInitialized(bool aHasAudio, bool aHasVideo)
   {
     HLS_DEBUG("HLSDemuxerCallbacksSupport", "OnInitialized");
     MutexAutoLock lock(mMutex);
     if (!mDemuxer) { return; }
     RefPtr<HLSDemuxerCallbacksSupport> self = this;
-    mDemuxer->GetTaskQueue()->Dispatch(NS_NewRunnableFunction(
-     "HLSDemuxer::HLSDemuxerCallbacksSupport::OnInitialized",
-     [=] () {
-       MutexAutoLock lock(self->mMutex);
-       if (self->mDemuxer) {
-         self->mDemuxer->OnInitialized(aHasAudio, aHasVideo);
-       }
-     }));
+    nsresult rv =
+      mDemuxer->GetTaskQueue()->Dispatch(NS_NewRunnableFunction(
+       "HLSDemuxer::HLSDemuxerCallbacksSupport::OnInitialized",
+       [=] () {
+         MutexAutoLock lock(self->mMutex);
+         if (self->mDemuxer) {
+           self->mDemuxer->OnInitialized(aHasAudio, aHasVideo);
+         }
+       }));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
   void OnError(int aErrorCode)
   {
     HLS_DEBUG("HLSDemuxerCallbacksSupport", "Got error(%d) from java side", aErrorCode);
     MutexAutoLock lock(mMutex);
     if (!mDemuxer) { return; }
     RefPtr<HLSDemuxerCallbacksSupport> self = this;
-    mDemuxer->GetTaskQueue()->Dispatch(NS_NewRunnableFunction(
-     "HLSDemuxer::HLSDemuxerCallbacksSupport::OnError",
-     [=] () {
-       MutexAutoLock lock(self->mMutex);
-       if (self->mDemuxer) {
-         self->mDemuxer->OnError(aErrorCode);
-       }
-     }));
+    nsresult rv =
+      mDemuxer->GetTaskQueue()->Dispatch(NS_NewRunnableFunction(
+       "HLSDemuxer::HLSDemuxerCallbacksSupport::OnError",
+       [=] () {
+         MutexAutoLock lock(self->mMutex);
+         if (self->mDemuxer) {
+           self->mDemuxer->OnError(aErrorCode);
+         }
+       }));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
   void Detach()
   {
     MutexAutoLock lock(mMutex);
     mDemuxer = nullptr;
   }
 
@@ -631,16 +635,17 @@ void
 HLSTrackDemuxer::BreakCycles()
 {
   RefPtr<HLSTrackDemuxer> self = this;
   nsCOMPtr<nsIRunnable> task =
     NS_NewRunnableFunction("HLSTrackDemuxer::BreakCycles",
     [self]() {
       self->mParent = nullptr;
     } );
-  mParent->GetTaskQueue()->Dispatch(task.forget());
+  nsresult rv = mParent->GetTaskQueue()->Dispatch(task.forget());
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 HLSTrackDemuxer::~HLSTrackDemuxer()
 {
 }
 
 } // namespace mozilla
--- a/dom/media/mediasource/AutoTaskQueue.h
+++ b/dom/media/mediasource/AutoTaskQueue.h
@@ -31,21 +31,21 @@ public:
   , mTaskQueue(new TaskQueue(Move(aPool), aName, aSupportsTailDispatch))
   {}
 
   TaskDispatcher& TailDispatcher() override
   {
     return mTaskQueue->TailDispatcher();
   }
 
-  nsresult Dispatch(already_AddRefed<nsIRunnable> aRunnable,
-                    DispatchFailureHandling aFailureHandling = AssertDispatchSuccess,
-                    DispatchReason aReason = NormalDispatch) override
+  MOZ_MUST_USE nsresult
+  Dispatch(already_AddRefed<nsIRunnable> aRunnable,
+           DispatchReason aReason = NormalDispatch) override
   {
-    return mTaskQueue->Dispatch(Move(aRunnable), aFailureHandling, aReason);
+    return mTaskQueue->Dispatch(Move(aRunnable), aReason);
   }
 
   // Prevent a GCC warning about the other overload of Dispatch being hidden.
   using AbstractThread::Dispatch;
 
   // Blocks until all tasks finish executing.
   void AwaitIdle() { mTaskQueue->AwaitIdle(); }
 
--- a/dom/media/mediasource/MediaSourceDemuxer.cpp
+++ b/dom/media/mediasource/MediaSourceDemuxer.cpp
@@ -59,32 +59,34 @@ MediaSourceDemuxer::AddSizeOfResources(
   RefPtr<MediaSourceDecoder::ResourceSizes> sizes = aSizes;
   nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction(
     "MediaSourceDemuxer::AddSizeOfResources", [self, sizes]() {
       for (const RefPtr<TrackBuffersManager>& manager : self->mSourceBuffers) {
         manager->AddSizeOfResources(sizes);
       }
     });
 
-  GetTaskQueue()->Dispatch(task.forget());
+  nsresult rv = GetTaskQueue()->Dispatch(task.forget());
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 void MediaSourceDemuxer::NotifyInitDataArrived()
 {
   RefPtr<MediaSourceDemuxer> self = this;
   nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction(
     "MediaSourceDemuxer::NotifyInitDataArrived", [self]() {
       if (self->mInitPromise.IsEmpty()) {
         return;
       }
       if (self->ScanSourceBuffersForContent()) {
         self->mInitPromise.ResolveIfExists(NS_OK, __func__);
       }
     });
-  GetTaskQueue()->Dispatch(task.forget());
+  nsresult rv = GetTaskQueue()->Dispatch(task.forget());
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 bool
 MediaSourceDemuxer::ScanSourceBuffersForContent()
 {
   MOZ_ASSERT(OnTaskQueue());
 
   if (mSourceBuffers.IsEmpty()) {
@@ -165,17 +167,18 @@ void
 MediaSourceDemuxer::AttachSourceBuffer(
   RefPtr<TrackBuffersManager>& aSourceBuffer)
 {
   nsCOMPtr<nsIRunnable> task = NewRunnableMethod<RefPtr<TrackBuffersManager>&&>(
     "MediaSourceDemuxer::DoAttachSourceBuffer",
     this,
     &MediaSourceDemuxer::DoAttachSourceBuffer,
     aSourceBuffer);
-  GetTaskQueue()->Dispatch(task.forget());
+  nsresult rv = GetTaskQueue()->Dispatch(task.forget());
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 void
 MediaSourceDemuxer::DoAttachSourceBuffer(
   RefPtr<mozilla::TrackBuffersManager>&& aSourceBuffer)
 {
   MOZ_ASSERT(OnTaskQueue());
   mSourceBuffers.AppendElement(Move(aSourceBuffer));
@@ -186,17 +189,18 @@ void
 MediaSourceDemuxer::DetachSourceBuffer(
   RefPtr<TrackBuffersManager>& aSourceBuffer)
 {
   nsCOMPtr<nsIRunnable> task = NewRunnableMethod<RefPtr<TrackBuffersManager>&&>(
     "MediaSourceDemuxer::DoDetachSourceBuffer",
     this,
     &MediaSourceDemuxer::DoDetachSourceBuffer,
     aSourceBuffer);
-  GetTaskQueue()->Dispatch(task.forget());
+  nsresult rv = GetTaskQueue()->Dispatch(task.forget());
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 void
 MediaSourceDemuxer::DoDetachSourceBuffer(
   RefPtr<TrackBuffersManager>&& aSourceBuffer)
 {
   MOZ_ASSERT(OnTaskQueue());
   mSourceBuffers.RemoveElementsBy(
@@ -359,17 +363,18 @@ MediaSourceTrackDemuxer::Reset()
       MOZ_ASSERT(self->OnTaskQueue());
       self->mManager->Seek(self->mType, TimeUnit::Zero(), TimeUnit::Zero());
       {
         MonitorAutoLock mon(self->mMonitor);
         self->mNextRandomAccessPoint = self->mManager->GetNextRandomAccessPoint(
           self->mType, MediaSourceDemuxer::EOS_FUZZ);
       }
     });
-  mParent->GetTaskQueue()->Dispatch(task.forget());
+  nsresult rv = mParent->GetTaskQueue()->Dispatch(task.forget());
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 nsresult
 MediaSourceTrackDemuxer::GetNextRandomAccessPoint(TimeUnit* aTime)
 {
   MonitorAutoLock mon(mMonitor);
   *aTime = mNextRandomAccessPoint;
   return NS_OK;
@@ -399,17 +404,18 @@ void
 MediaSourceTrackDemuxer::BreakCycles()
 {
   RefPtr<MediaSourceTrackDemuxer> self = this;
   nsCOMPtr<nsIRunnable> task =
     NS_NewRunnableFunction("MediaSourceTrackDemuxer::BreakCycles", [self]() {
       self->DetachManager();
       self->mParent = nullptr;
     });
-  mParent->GetTaskQueue()->Dispatch(task.forget());
+  nsresult rv = mParent->GetTaskQueue()->Dispatch(task.forget());
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
 }
 
 RefPtr<MediaSourceTrackDemuxer::SeekPromise>
 MediaSourceTrackDemuxer::DoSeek(const TimeUnit& aTime)
 {
   if (!mManager) {
     return SeekPromise::CreateAndReject(
       MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -160,21 +160,23 @@ TrackBuffersManager::QueueTask(SourceBuf
     MOZ_ASSERT(aTask->GetType() == SourceBufferTask::Type::Detach,
                "only detach task could happen here!");
     MSE_DEBUG("Could not queue the task '%s' without task queue",
               aTask->GetTypeName());
     return;
   }
 
   if (!taskQueue->IsCurrentThreadIn()) {
-    taskQueue->Dispatch(NewRunnableMethod<RefPtr<SourceBufferTask>>(
-      "TrackBuffersManager::QueueTask",
-      this,
-      &TrackBuffersManager::QueueTask,
-      aTask));
+    nsresult rv =
+        taskQueue->Dispatch(NewRunnableMethod<RefPtr<SourceBufferTask>>(
+        "TrackBuffersManager::QueueTask",
+        this,
+        &TrackBuffersManager::QueueTask,
+        aTask));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
     return;
   }
   mQueue.Push(aTask);
   ProcessTasks();
 }
 
 void
 TrackBuffersManager::ProcessTasks()
--- a/dom/media/platforms/android/RemoteDataDecoder.cpp
+++ b/dom/media/platforms/android/RemoteDataDecoder.cpp
@@ -633,22 +633,24 @@ RemoteDataDecoder::Decode(MediaRawData* 
 
   });
 }
 
 void
 RemoteDataDecoder::UpdateInputStatus(int64_t aTimestamp, bool aProcessed)
 {
   if (!mTaskQueue->IsCurrentThreadIn()) {
-    mTaskQueue->Dispatch(
-      NewRunnableMethod<int64_t, bool>("RemoteDataDecoder::UpdateInputStatus",
-                                       this,
-                                       &RemoteDataDecoder::UpdateInputStatus,
-                                       aTimestamp,
-                                       aProcessed));
+    nsresult rv =
+      mTaskQueue->Dispatch(
+        NewRunnableMethod<int64_t, bool>("RemoteDataDecoder::UpdateInputStatus",
+                                         this,
+                                         &RemoteDataDecoder::UpdateInputStatus,
+                                         aTimestamp,
+                                         aProcessed));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
     return;
   }
   AssertOnTaskQueue();
   if (mShutdown) {
     return;
   }
 
   if (!aProcessed) {
@@ -662,21 +664,23 @@ RemoteDataDecoder::UpdateInputStatus(int
     ReturnDecodedData();
   }
 }
 
 void
 RemoteDataDecoder::UpdateOutputStatus(RefPtr<MediaData>&& aSample)
 {
   if (!mTaskQueue->IsCurrentThreadIn()) {
-    mTaskQueue->Dispatch(
-      NewRunnableMethod<const RefPtr<MediaData>>("RemoteDataDecoder::UpdateOutputStatus",
-                                                 this,
-                                                 &RemoteDataDecoder::UpdateOutputStatus,
-                                                 Move(aSample)));
+    nsresult rv =
+      mTaskQueue->Dispatch(
+        NewRunnableMethod<const RefPtr<MediaData>>("RemoteDataDecoder::UpdateOutputStatus",
+                                                   this,
+                                                   &RemoteDataDecoder::UpdateOutputStatus,
+                                                   Move(aSample)));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
     return;
   }
   AssertOnTaskQueue();
   if (mShutdown) {
     return;
   }
   if (IsUsefulData(aSample)) {
     mDecodedData.AppendElement(Move(aSample));
@@ -700,38 +704,43 @@ RemoteDataDecoder::ReturnDecodedData()
     mDecodedData.Clear();
   }
 }
 
 void
 RemoteDataDecoder::DrainComplete()
 {
   if (!mTaskQueue->IsCurrentThreadIn()) {
-    mTaskQueue->Dispatch(
-      NewRunnableMethod("RemoteDataDecoder::DrainComplete",
-                        this, &RemoteDataDecoder::DrainComplete));
+    nsresult rv =
+      mTaskQueue->Dispatch(
+        NewRunnableMethod("RemoteDataDecoder::DrainComplete",
+                          this, &RemoteDataDecoder::DrainComplete));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
     return;
   }
   AssertOnTaskQueue();
   if (mShutdown) {
     return;
   }
   mDrainStatus = DrainStatus::DRAINED;
   ReturnDecodedData();
   // Make decoder accept input again.
   mJavaDecoder->Flush();
 }
 
 void
 RemoteDataDecoder::Error(const MediaResult& aError)
 {
   if (!mTaskQueue->IsCurrentThreadIn()) {
-    mTaskQueue->Dispatch(
-      NewRunnableMethod<MediaResult>("RemoteDataDecoder::Error",
-                                     this, &RemoteDataDecoder::Error, aError));
+    nsresult rv =
+      mTaskQueue->Dispatch(
+        NewRunnableMethod<MediaResult>("RemoteDataDecoder::Error",
+                                       this, &RemoteDataDecoder::Error,
+                                       aError));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
     return;
   }
   AssertOnTaskQueue();
   if (mShutdown) {
     return;
   }
   mDecodePromise.RejectIfExists(aError, __func__);
   mDrainPromise.RejectIfExists(aError, __func__);
--- a/dom/media/platforms/omx/OmxDataDecoder.cpp
+++ b/dom/media/platforms/omx/OmxDataDecoder.cpp
@@ -391,17 +391,18 @@ OmxDataDecoder::EmptyBufferDone(BufferDa
         if (mMediaRawDatas.Length()) {
           return;
         }
 
         mDecodePromise.ResolveIfExists(mDecodedData, __func__);
         mDecodedData.Clear();
       });
 
-    mOmxTaskQueue->Dispatch(r.forget());
+    nsresult rv = mOmxTaskQueue->Dispatch(r.forget());
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 }
 
 void
 OmxDataDecoder::EmptyBufferFailure(OmxBufferFailureHolder aFailureHolder)
 {
   NotifyError(aFailureHolder.mError, __func__);
 }
--- a/dom/media/webaudio/MediaBufferDecoder.cpp
+++ b/dom/media/webaudio/MediaBufferDecoder.cpp
@@ -505,17 +505,18 @@ AsyncDecodeWebAudio(const char* aContent
                            WebAudioDecodeJob::UnknownError);
     aDecodeJob.mContext->Dispatch(event.forget());
   } else {
     // If we did this without a temporary:
     //   task->Reader()->OwnerThread()->Dispatch(task.forget())
     // we might evaluate the task.forget() before calling Reader(). Enforce
     // a non-crashy order-of-operations.
     TaskQueue* taskQueue = task->Reader()->OwnerThread();
-    taskQueue->Dispatch(task.forget());
+    nsresult rv = taskQueue->Dispatch(task.forget());
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 }
 
 WebAudioDecodeJob::WebAudioDecodeJob(AudioContext* aContext,
                                      Promise* aPromise,
                                      DecodeSuccessCallback* aSuccessCallback,
                                      DecodeErrorCallback* aFailureCallback)
   : mContext(aContext)
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -202,17 +202,18 @@ public:
 
     ++mLength; // Atomic
 
     nsCOMPtr<nsIRunnable> runnable =
       NewRunnableMethod<StoreRefPtrPassByPtr<Image>, bool>(
         "VideoFrameConverter::ProcessVideoFrame",
         this, &VideoFrameConverter::ProcessVideoFrame,
         aChunk.mFrame.GetImage(), forceBlack);
-    mTaskQueue->Dispatch(runnable.forget());
+    nsresult rv = mTaskQueue->Dispatch(runnable.forget());
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   }
 
   void AddListener(VideoConverterListener* aListener)
   {
     MutexAutoLock lock(mMutex);
 
     MOZ_ASSERT(!mListeners.Contains(aListener));
     mListeners.AppendElement(aListener);