Bug 1144519 - Switch MediaDecoderReader subclasses to use OnTaskQueue(). r=jya
authorBobby Holley <bobbyholley@gmail.com>
Tue, 17 Mar 2015 15:22:44 -0700
changeset 265119 cd788ba50fb0009126938027a0be15c321682352
parent 265118 5423b7356facc4049e26acaef4a0749361d10349
child 265120 1d0ffffbcc3b88ed370be268cabfc7b97a83cdef
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1144519
milestone39.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 1144519 - Switch MediaDecoderReader subclasses to use OnTaskQueue(). r=jya
dom/media/android/AndroidMediaReader.cpp
dom/media/apple/AppleMP3Reader.cpp
dom/media/directshow/DirectShowReader.cpp
dom/media/gstreamer/GStreamerReader.cpp
dom/media/ogg/OggReader.cpp
dom/media/omx/MediaCodecReader.cpp
dom/media/omx/MediaOmxCommonReader.cpp
dom/media/omx/MediaOmxReader.cpp
dom/media/raw/RawReader.cpp
dom/media/wave/WaveReader.cpp
dom/media/webm/IntelWebMVideoDecoder.cpp
dom/media/webm/SoftwareWebMVideoDecoder.cpp
dom/media/webm/WebMReader.cpp
dom/media/webm/WebMReader.h
dom/media/wmf/WMFReader.cpp
--- a/dom/media/android/AndroidMediaReader.cpp
+++ b/dom/media/android/AndroidMediaReader.cpp
@@ -38,17 +38,17 @@ AndroidMediaReader::AndroidMediaReader(A
 nsresult AndroidMediaReader::Init(MediaDecoderReader* aCloneDonor)
 {
   return NS_OK;
 }
 
 nsresult AndroidMediaReader::ReadMetadata(MediaInfo* aInfo,
                                           MetadataTags** aTags)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   if (!mPlugin) {
     mPlugin = GetAndroidMediaPluginHost()->CreateDecoder(mDecoder->GetResource(), mType);
     if (!mPlugin) {
       return NS_ERROR_FAILURE;
     }
   }
 
@@ -284,17 +284,17 @@ bool AndroidMediaReader::DecodeVideoFram
     break;
   }
 
   return true;
 }
 
 bool AndroidMediaReader::DecodeAudioData()
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   // This is the approximate byte position in the stream.
   int64_t pos = mDecoder->GetResource()->Tell();
 
   // Read next frame
   MPAPI::AudioFrame source;
   if (!mPlugin->ReadAudio(mPlugin, &source, mAudioSeekTimeUs)) {
     return false;
@@ -317,17 +317,17 @@ bool AndroidMediaReader::DecodeAudioData
                               MPCopy(static_cast<uint8_t *>(source.mData),
                                      source.mSize,
                                      source.mAudioChannels));
 }
 
 nsRefPtr<MediaDecoderReader::SeekPromise>
 AndroidMediaReader::Seek(int64_t aTarget, int64_t aEndTime)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   if (mHasAudio && mHasVideo) {
     // The decoder seeks/demuxes audio and video streams separately. So if
     // we seek both audio and video to aTarget, the audio stream can typically
     // seek closer to the seek target, since typically every audio block is
     // a sync point, whereas for video there are only keyframes once every few
     // seconds. So if we have both audio and video, we must seek the video
     // stream to the preceeding keyframe first, get the stream time, and then
--- a/dom/media/apple/AppleMP3Reader.cpp
+++ b/dom/media/apple/AppleMP3Reader.cpp
@@ -275,17 +275,17 @@ AppleMP3Reader::AudioSampleCallback(UInt
       break;
     }
   } while (true);
 }
 
 bool
 AppleMP3Reader::DecodeAudioData()
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread");
+  MOZ_ASSERT(OnTaskQueue());
 
   // Read AUDIO_READ_BYTES if we can
   char bytes[AUDIO_READ_BYTES];
   uint32_t numBytes = AUDIO_READ_BYTES;
 
   nsresult readrv = Read(&numBytes, bytes);
 
   // This function calls |AudioSampleCallback| above, synchronously, when it
@@ -309,32 +309,32 @@ AppleMP3Reader::DecodeAudioData()
 
   return true;
 }
 
 bool
 AppleMP3Reader::DecodeVideoFrame(bool &aKeyframeSkip,
                                  int64_t aTimeThreshold)
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread");
+  MOZ_ASSERT(OnTaskQueue());
   return false;
 }
 
 
 bool
 AppleMP3Reader::HasAudio()
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread");
+  MOZ_ASSERT(OnTaskQueue());
   return mStreamReady;
 }
 
 bool
 AppleMP3Reader::HasVideo()
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread");
+  MOZ_ASSERT(OnTaskQueue());
   return false;
 }
 
 bool
 AppleMP3Reader::IsMediaSeekable()
 {
   // not used
   return true;
@@ -364,17 +364,17 @@ GetProperty(AudioFileStreamID aAudioFile
   return NS_OK;
 }
 
 
 nsresult
 AppleMP3Reader::ReadMetadata(MediaInfo* aInfo,
                              MetadataTags** aTags)
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread");
+  MOZ_ASSERT(OnTaskQueue());
 
   *aTags = nullptr;
 
   /*
    * Feed bytes into the parser until we have all the metadata we need to
    * set up the decoder. When the parser has enough data, it will
    * synchronously call back to |AudioMetadataCallback| below.
    */
@@ -490,17 +490,17 @@ AppleMP3Reader::SetupDecoder()
     return;
   }
 }
 
 
 nsRefPtr<MediaDecoderReader::SeekPromise>
 AppleMP3Reader::Seek(int64_t aTime, int64_t aEndTime)
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread");
+  MOZ_ASSERT(OnTaskQueue());
 
   // Find the exact frame/packet that contains |aTime|.
   mCurrentAudioFrame = aTime * mAudioSampleRate / USECS_PER_S;
   SInt64 packet = mCurrentAudioFrame / mAudioFramesPerCompressedPacket;
 
   // |AudioFileStreamSeek| will pass back through |byteOffset| the byte offset
   // into the stream it expects next time it reads.
   SInt64 byteOffset;
--- a/dom/media/directshow/DirectShowReader.cpp
+++ b/dom/media/directshow/DirectShowReader.cpp
@@ -99,17 +99,17 @@ ParseMP3Headers(MP3FrameParser *aParser,
 // and later we can use the DMO Wrapper filter and MP3 decoder DMO.
 static const GUID CLSID_MPEG_LAYER_3_DECODER_FILTER =
 { 0x38BE3000, 0xDBF4, 0x11D0, {0x86, 0x0E, 0x00, 0xA0, 0x24, 0xCF, 0xEF, 0x6D} };
 
 nsresult
 DirectShowReader::ReadMetadata(MediaInfo* aInfo,
                                MetadataTags** aTags)
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   HRESULT hr;
   nsresult rv;
 
   // Create the filter graph, reference it by the GraphBuilder interface,
   // to make graph building more convenient.
   hr = CoCreateInstance(CLSID_FilterGraph,
                         nullptr,
                         CLSCTX_INPROC_SERVER,
@@ -240,17 +240,17 @@ inline float
 UnsignedByteToAudioSample(uint8_t aValue)
 {
   return aValue * (2.0f / UINT8_MAX) - 1.0f;
 }
 
 bool
 DirectShowReader::Finish(HRESULT aStatus)
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   LOG("DirectShowReader::Finish(0x%x)", aStatus);
   // Notify the filter graph of end of stream.
   RefPtr<IMediaEventSink> eventSink;
   HRESULT hr = mGraph->QueryInterface(static_cast<IMediaEventSink**>(byRef(eventSink)));
   if (SUCCEEDED(hr) && eventSink) {
     eventSink->Notify(EC_COMPLETE, aStatus, 0);
   }
@@ -297,17 +297,17 @@ private:
   const uint32_t mSamples;
   const uint32_t mChannels;
   uint32_t mNextSample;
 };
 
 bool
 DirectShowReader::DecodeAudioData()
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   HRESULT hr;
 
   SampleSink* sink = mAudioSinkFilter->GetSampleSink();
   if (sink->AtEOS()) {
     // End of stream.
     return Finish(S_OK);
   }
 
@@ -344,31 +344,31 @@ DirectShowReader::DecodeAudioData()
                                       mNumChannels));
   return true;
 }
 
 bool
 DirectShowReader::DecodeVideoFrame(bool &aKeyframeSkip,
                                    int64_t aTimeThreshold)
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   return false;
 }
 
 bool
 DirectShowReader::HasAudio()
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   return true;
 }
 
 bool
 DirectShowReader::HasVideo()
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   return false;
 }
 
 nsRefPtr<MediaDecoderReader::SeekPromise>
 DirectShowReader::Seek(int64_t aTargetUs, int64_t aEndTime)
 {
   nsresult res = SeekInternal(aTargetUs);
   if (NS_FAILED(res)) {
@@ -377,17 +377,17 @@ DirectShowReader::Seek(int64_t aTargetUs
     return SeekPromise::CreateAndResolve(aTargetUs, __func__);
   }
 }
 
 nsresult
 DirectShowReader::SeekInternal(int64_t aTargetUs)
 {
   HRESULT hr;
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread.");\
+  MOZ_ASSERT(OnTaskQueue());
 
   LOG("DirectShowReader::Seek() target=%lld", aTargetUs);
 
   hr = mControl->Pause();
   NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE);
 
   nsresult rv = ResetDecode();
   NS_ENSURE_SUCCESS(rv, rv);
--- a/dom/media/gstreamer/GStreamerReader.cpp
+++ b/dom/media/gstreamer/GStreamerReader.cpp
@@ -361,17 +361,17 @@ GStreamerReader::GetDataLength()
   }
 
   return streamLen - mDataOffset;
 }
 
 nsresult GStreamerReader::ReadMetadata(MediaInfo* aInfo,
                                        MetadataTags** aTags)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   nsresult ret = NS_OK;
 
   /*
    * Parse MP3 headers before we kick off the GStreamer pipeline otherwise there
    * might be concurrent stream operations happening on both decoding and gstreamer
    * threads which will screw the GStreamer state machine.
    */
   bool isMP3 = mDecoder->GetResource()->GetContentType().EqualsASCII(AUDIO_MP3);
@@ -633,17 +633,17 @@ nsresult GStreamerReader::ResetDecode()
 
   LOG(PR_LOG_DEBUG, "reset decode done");
 
   return res;
 }
 
 bool GStreamerReader::DecodeAudioData()
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   GstBuffer *buffer = nullptr;
 
   {
     ReentrantMonitorAutoEnter mon(mGstThreadsMonitor);
 
     if (mReachedAudioEos && !mAudioSinkBufferCount) {
       return false;
@@ -719,17 +719,17 @@ bool GStreamerReader::DecodeAudioData()
   gst_buffer_unref(buffer);
 
   return true;
 }
 
 bool GStreamerReader::DecodeVideoFrame(bool &aKeyFrameSkip,
                                        int64_t aTimeThreshold)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   GstBuffer *buffer = nullptr;
 
   {
     ReentrantMonitorAutoEnter mon(mGstThreadsMonitor);
 
     if (mReachedVideoEos && !mVideoSinkBufferCount) {
       return false;
@@ -839,17 +839,17 @@ bool GStreamerReader::DecodeVideoFrame(b
   gst_buffer_unref(buffer);
 
   return true;
 }
 
 nsRefPtr<MediaDecoderReader::SeekPromise>
 GStreamerReader::Seek(int64_t aTarget, int64_t aEndTime)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   gint64 seekPos = aTarget * GST_USECOND;
   LOG(PR_LOG_DEBUG, "%p About to seek to %" GST_TIME_FORMAT,
         mDecoder, GST_TIME_ARGS(seekPos));
 
   int flags = GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT;
   if (!gst_element_seek_simple(mPlayBin,
                                GST_FORMAT_TIME,
--- a/dom/media/ogg/OggReader.cpp
+++ b/dom/media/ogg/OggReader.cpp
@@ -160,17 +160,17 @@ nsresult OggReader::Init(MediaDecoderRea
 
 nsresult OggReader::ResetDecode()
 {
   return ResetDecode(false);
 }
 
 nsresult OggReader::ResetDecode(bool start)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   nsresult res = NS_OK;
 
   if (NS_FAILED(MediaDecoderReader::ResetDecode())) {
     res = NS_ERROR_FAILURE;
   }
 
   // Discard any previously buffered packets/pages.
   ogg_sync_reset(&mOggState);
@@ -364,17 +364,17 @@ void OggReader::SetupMediaTracksInfo(con
       mInfo.mAudio.mChannels = opusState->mChannels;
     }
   }
 }
 
 nsresult OggReader::ReadMetadata(MediaInfo* aInfo,
                                  MetadataTags** aTags)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   // We read packets until all bitstreams have read all their header packets.
   // We record the offset of the first non-header page so that we know
   // what page to seek to when seeking to the media start.
 
   NS_ASSERTION(aTags, "Called with null MetadataTags**.");
   *aTags = nullptr;
 
@@ -666,17 +666,17 @@ nsresult OggReader::DecodeOpus(ogg_packe
 
   mDecodedAudioFrames += frames;
 
   return NS_OK;
 }
 
 bool OggReader::DecodeAudioData()
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   DebugOnly<bool> haveCodecState = mVorbisState != nullptr ||
                                    mOpusState != nullptr;
   NS_ASSERTION(haveCodecState, "Need audio codec state to decode audio");
 
   // Read the next data packet. Skip any non-data packets we encounter.
   ogg_packet* packet = 0;
   OggCodecState* codecState;
   if (mVorbisState)
@@ -890,17 +890,17 @@ nsresult OggReader::DecodeTheora(ogg_pac
     mVideoQueue.Push(v);
   }
   return NS_OK;
 }
 
 bool OggReader::DecodeVideoFrame(bool &aKeyframeSkip,
                                      int64_t aTimeThreshold)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   // Record number of frames decoded and parsed. Automatically update the
   // stats counters using the AutoNotifyDecoded stack-based class.
   AbstractMediaDecoder::AutoNotifyDecoded a(mDecoder);
 
   // Read the next data packet. Skip any non-data packets we encounter.
   ogg_packet* packet = 0;
   do {
@@ -936,17 +936,17 @@ bool OggReader::DecodeVideoFrame(bool &a
     return false;
   }
 
   return true;
 }
 
 bool OggReader::ReadOggPage(ogg_page* aPage)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   int ret = 0;
   while((ret = ogg_sync_pageseek(&mOggState, aPage)) <= 0) {
     if (ret < 0) {
       // Lost page sync, have to skip up to next page.
       continue;
     }
     // Returns a buffer that can be written too
@@ -970,17 +970,17 @@ bool OggReader::ReadOggPage(ogg_page* aP
     NS_ENSURE_TRUE(ret == 0, false);
   }
 
   return true;
 }
 
 ogg_packet* OggReader::NextOggPacket(OggCodecState* aCodecState)
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   if (!aCodecState || !aCodecState->mActive) {
     return nullptr;
   }
 
   ogg_packet* packet;
   while ((packet = aCodecState->PacketOut()) == nullptr) {
     // The codec state does not have any buffered pages, so try to read another
@@ -1013,17 +1013,17 @@ GetChecksum(ogg_page* page)
                (p[1] << 8) +
                (p[2] << 16) +
                (p[3] << 24);
   return c;
 }
 
 int64_t OggReader::RangeStartTime(int64_t aOffset)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   MediaResource* resource = mDecoder->GetResource();
   NS_ENSURE_TRUE(resource != nullptr, 0);
   nsresult res = resource->Seek(nsISeekableStream::NS_SEEK_SET, aOffset);
   NS_ENSURE_SUCCESS(res, 0);
   int64_t startTime = 0;
   FindStartTime(startTime);
   return startTime;
 }
@@ -1035,18 +1035,17 @@ struct nsAutoOggSyncState {
   ~nsAutoOggSyncState() {
     ogg_sync_clear(&mState);
   }
   ogg_sync_state mState;
 };
 
 int64_t OggReader::RangeEndTime(int64_t aEndOffset)
 {
-  NS_ASSERTION(mDecoder->OnStateMachineTaskQueue() || mDecoder->OnDecodeThread(),
-               "Should be on state machine or decode taks queue");
+  MOZ_ASSERT(OnTaskQueue() || mDecoder->OnStateMachineTaskQueue());
 
   MediaResource* resource = mDecoder->GetResource();
   NS_ENSURE_TRUE(resource != nullptr, -1);
   int64_t position = resource->Tell();
   int64_t endTime = RangeEndTime(0, aEndOffset, false);
   nsresult res = resource->Seek(nsISeekableStream::NS_SEEK_SET, position);
   NS_ENSURE_SUCCESS(res, -1);
   return endTime;
@@ -1176,17 +1175,17 @@ int64_t OggReader::RangeEndTime(int64_t 
     }
   }
 
   return endTime;
 }
 
 nsresult OggReader::GetSeekRanges(nsTArray<SeekRange>& aRanges)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   AutoPinned<MediaResource> resource(mDecoder->GetResource());
   nsTArray<MediaByteRange> cached;
   nsresult res = resource->GetCachedRanges(cached);
   NS_ENSURE_SUCCESS(res, res);
 
   for (uint32_t index = 0; index < cached.Length(); index++) {
     MediaByteRange& range = cached[index];
     int64_t startTime = -1;
@@ -1216,17 +1215,17 @@ nsresult OggReader::GetSeekRanges(nsTArr
 
 OggReader::SeekRange
 OggReader::SelectSeekRange(const nsTArray<SeekRange>& ranges,
                              int64_t aTarget,
                              int64_t aStartTime,
                              int64_t aEndTime,
                              bool aExact)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   int64_t so = 0;
   int64_t eo = mDecoder->GetResource()->GetLength();
   int64_t st = aStartTime;
   int64_t et = aEndTime;
   for (uint32_t i = 0; i < ranges.Length(); i++) {
     const SeekRange &r = ranges[i];
     if (r.mTimeStart < aTarget) {
       so = r.mOffsetStart;
@@ -1432,17 +1431,17 @@ OggReader::Seek(int64_t aTarget, int64_t
     return SeekPromise::CreateAndReject(res, __func__);
   } else {
     return SeekPromise::CreateAndResolve(aTarget, __func__);
   }
 }
 
 nsresult OggReader::SeekInternal(int64_t aTarget, int64_t aEndTime)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   if (mIsChained)
     return NS_ERROR_FAILURE;
   LOG(PR_LOG_DEBUG, ("%p About to seek to %lld", mDecoder, aTarget));
   nsresult res;
   MediaResource* resource = mDecoder->GetResource();
   NS_ENSURE_TRUE(resource != nullptr, NS_ERROR_FAILURE);
   int64_t adjustedTarget = aTarget;
   if (HasAudio() && mOpusState){
@@ -1589,17 +1588,17 @@ PageSync(MediaResource* aResource,
 
   return PAGE_SYNC_OK;
 }
 
 nsresult OggReader::SeekBisection(int64_t aTarget,
                                     const SeekRange& aRange,
                                     uint32_t aFuzz)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   nsresult res;
   MediaResource* resource = mDecoder->GetResource();
 
   if (aTarget == aRange.mTimeStart) {
     if (NS_FAILED(ResetDecode())) {
       return NS_ERROR_FAILURE;
     }
     res = resource->Seek(nsISeekableStream::NS_SEEK_SET, 0);
@@ -1961,18 +1960,17 @@ nsresult OggReader::GetBuffered(dom::Tim
   }
 
   return NS_OK;
 #endif
 }
 
 VideoData* OggReader::FindStartTime(int64_t& aOutStartTime)
 {
-  NS_ASSERTION(mDecoder->OnStateMachineTaskQueue() || mDecoder->OnDecodeThread(),
-               "Should be on state machine or decode task queue");
+  MOZ_ASSERT(OnTaskQueue() || mDecoder->OnStateMachineTaskQueue());
 
   // Extract the start times of the bitstreams in order to calculate
   // the duration.
   int64_t videoStartTime = INT64_MAX;
   int64_t audioStartTime = INT64_MAX;
   VideoData* videoData = nullptr;
 
   if (HasVideo()) {
--- a/dom/media/omx/MediaCodecReader.cpp
+++ b/dom/media/omx/MediaCodecReader.cpp
@@ -653,17 +653,17 @@ MediaCodecReader::PreReadMetadata()
   UpdateIsWaitingMediaResources();
 }
 
 
 nsresult
 MediaCodecReader::ReadMetadata(MediaInfo* aInfo,
                                MetadataTags** aTags)
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   if (!ReallocateResources()) {
     return NS_ERROR_FAILURE;
   }
 
   bool incrementalParserNeeded =
     mDecoder->GetResource()->GetContentType().EqualsASCII(AUDIO_MP3);
   if (incrementalParserNeeded && !TriggerIncrementalParser()) {
@@ -1026,17 +1026,17 @@ MediaCodecReader::DecodeVideoFrameSync(i
   } else {
     mVideoTrack.mCodec->releaseOutputBuffer(bufferInfo.mIndex);
   }
 }
 
 nsRefPtr<MediaDecoderReader::SeekPromise>
 MediaCodecReader::Seek(int64_t aTime, int64_t aEndTime)
 {
-  MOZ_ASSERT(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   mVideoTrack.mSeekTimeUs = aTime;
   mAudioTrack.mSeekTimeUs = aTime;
   mVideoTrack.mInputEndOfStream = false;
   mVideoTrack.mOutputEndOfStream = false;
   mAudioTrack.mInputEndOfStream = false;
   mAudioTrack.mOutputEndOfStream = false;
   mAudioTrack.mFlushed = false;
--- a/dom/media/omx/MediaOmxCommonReader.cpp
+++ b/dom/media/omx/MediaOmxCommonReader.cpp
@@ -39,17 +39,17 @@ MediaOmxCommonReader::MediaOmxCommonRead
 #endif
 
   mAudioChannel = dom::AudioChannelService::GetDefaultAudioChannel();
 }
 
 #ifdef MOZ_AUDIO_OFFLOAD
 void MediaOmxCommonReader::CheckAudioOffload()
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   char offloadProp[128];
   property_get("audio.offload.disable", offloadProp, "0");
   bool offloadDisable =  atoi(offloadProp) != 0;
   if (offloadDisable) {
     return;
   }
 
--- a/dom/media/omx/MediaOmxReader.cpp
+++ b/dom/media/omx/MediaOmxReader.cpp
@@ -250,17 +250,17 @@ nsresult MediaOmxReader::InitOmxDecoder(
 void MediaOmxReader::PreReadMetadata()
 {
   UpdateIsWaitingMediaResources();
 }
 
 nsresult MediaOmxReader::ReadMetadata(MediaInfo* aInfo,
                                       MetadataTags** aTags)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   EnsureActive();
 
   *aTags = nullptr;
 
   // Initialize the internal OMX Decoder.
   nsresult rv = InitOmxDecoder();
   if (NS_FAILED(rv)) {
     return rv;
@@ -360,17 +360,17 @@ MediaOmxReader::IsMediaSeekable()
 {
   // Check the MediaExtract flag if the source is seekable.
   return (mExtractor->flags() & MediaExtractor::CAN_SEEK);
 }
 
 bool MediaOmxReader::DecodeVideoFrame(bool &aKeyframeSkip,
                                       int64_t aTimeThreshold)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   EnsureActive();
 
   // Record number of frames decoded and parsed. Automatically update the
   // stats counters using the AutoNotifyDecoded stack-based class.
   AbstractMediaDecoder::AutoNotifyDecoded a(mDecoder);
 
   bool doSeek = mVideoSeekTimeUs != -1;
   if (doSeek) {
@@ -504,17 +504,17 @@ void MediaOmxReader::NotifyDataArrived(c
   if (duration != mLastParserDuration && mUseParserDuration) {
     mLastParserDuration = duration;
     decoder->UpdateEstimatedMediaDuration(mLastParserDuration);
   }
 }
 
 bool MediaOmxReader::DecodeAudioData()
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   EnsureActive();
 
   // This is the approximate byte position in the stream.
   int64_t pos = mDecoder->GetResource()->Tell();
 
   // Read next frame
   MPAPI::AudioFrame source;
   if (!mOmxDecoder->ReadAudio(&source, mAudioSeekTimeUs)) {
@@ -539,17 +539,17 @@ bool MediaOmxReader::DecodeAudioData()
                               OmxCopy(static_cast<uint8_t *>(source.mData),
                                       source.mSize,
                                       source.mAudioChannels));
 }
 
 nsRefPtr<MediaDecoderReader::SeekPromise>
 MediaOmxReader::Seek(int64_t aTarget, int64_t aEndTime)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   EnsureActive();
 
   VideoFrameContainer* container = mDecoder->GetVideoFrameContainer();
   if (container && container->GetImageContainer()) {
     container->GetImageContainer()->ClearAllImagesExceptFront();
   }
 
   if (mHasAudio && mHasVideo) {
--- a/dom/media/raw/RawReader.cpp
+++ b/dom/media/raw/RawReader.cpp
@@ -34,18 +34,17 @@ nsresult RawReader::ResetDecode()
 {
   mCurrentFrame = 0;
   return MediaDecoderReader::ResetDecode();
 }
 
 nsresult RawReader::ReadMetadata(MediaInfo* aInfo,
                                  MetadataTags** aTags)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(),
-               "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   MediaResource* resource = mDecoder->GetResource();
   NS_ASSERTION(resource, "Decoder has no media resource");
 
   if (!ReadFromResource(resource, reinterpret_cast<uint8_t*>(&mMetadata),
                         sizeof(mMetadata)))
     return NS_ERROR_FAILURE;
 
@@ -116,18 +115,17 @@ bool
 RawReader::IsMediaSeekable()
 {
   // not used
   return true;
 }
 
  bool RawReader::DecodeAudioData()
 {
-  NS_ASSERTION(mDecoder->OnStateMachineTaskQueue() || mDecoder->OnDecodeThread(),
-               "Should be on state machine or decode task queue.");
+  MOZ_ASSERT(OnTaskQueue() || mDecoder->OnStateMachineTaskQueue());
   return false;
 }
 
 // Helper method that either reads until it gets aLength bytes
 // or returns false
 bool RawReader::ReadFromResource(MediaResource *aResource, uint8_t* aBuf,
                                    uint32_t aLength)
 {
@@ -147,18 +145,17 @@ bool RawReader::ReadFromResource(MediaRe
   }
 
   return true;
 }
 
 bool RawReader::DecodeVideoFrame(bool &aKeyframeSkip,
                                      int64_t aTimeThreshold)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(),
-               "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   // Record number of frames decoded and parsed. Automatically update the
   // stats counters using the AutoNotifyDecoded stack-based class.
   AbstractMediaDecoder::AutoNotifyDecoded a(mDecoder);
 
   if (!mFrameSize)
     return false; // Metadata read failed.  We should refuse to play.
 
@@ -241,18 +238,17 @@ RawReader::Seek(int64_t aTime, int64_t a
     return SeekPromise::CreateAndReject(res, __func__);
   } else {
     return SeekPromise::CreateAndResolve(aTime, __func__);
   }
 }
 
 nsresult RawReader::SeekInternal(int64_t aTime)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(),
-               "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   MediaResource *resource = mDecoder->GetResource();
   NS_ASSERTION(resource, "Decoder has no media resource");
 
   uint32_t frame = mCurrentFrame;
   if (aTime >= UINT_MAX)
     return NS_ERROR_FAILURE;
   mCurrentFrame = aTime * mFrameRate / USECS_PER_S;
--- a/dom/media/wave/WaveReader.cpp
+++ b/dom/media/wave/WaveReader.cpp
@@ -123,17 +123,17 @@ WaveReader::~WaveReader()
 nsresult WaveReader::Init(MediaDecoderReader* aCloneDonor)
 {
   return NS_OK;
 }
 
 nsresult WaveReader::ReadMetadata(MediaInfo* aInfo,
                                   MetadataTags** aTags)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   bool loaded = LoadRIFFChunk();
   if (!loaded) {
     return NS_ERROR_FAILURE;
   }
 
   nsAutoPtr<dom::HTMLMediaElement::MetadataTags> tags;
 
@@ -187,17 +187,17 @@ SignedShortToAudioSample<float>(int16_t 
 template <> inline int16_t
 SignedShortToAudioSample<int16_t>(int16_t aValue)
 {
   return aValue;
 }
 
 bool WaveReader::DecodeAudioData()
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   int64_t pos = GetPosition() - mWavePCMOffset;
   int64_t len = GetDataLength();
   int64_t remaining = len - pos;
   NS_ASSERTION(remaining >= 0, "Current wave position is greater than wave file length");
 
   static const int64_t BLOCK_SIZE = 4096;
   int64_t readSize = std::min(BLOCK_SIZE, remaining);
@@ -247,25 +247,25 @@ bool WaveReader::DecodeAudioData()
                                  mSampleRate));
 
   return true;
 }
 
 bool WaveReader::DecodeVideoFrame(bool &aKeyframeSkip,
                                       int64_t aTimeThreshold)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   return false;
 }
 
 nsRefPtr<MediaDecoderReader::SeekPromise>
 WaveReader::Seek(int64_t aTarget, int64_t aEndTime)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   LOG(PR_LOG_DEBUG, ("%p About to seek to %lld", mDecoder, aTarget));
 
   if (NS_FAILED(ResetDecode())) {
     return SeekPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
   }
   double d = BytesToTime(GetDataLength());
   NS_ASSERTION(d < INT64_MAX / USECS_PER_S, "Duration overflow");
   int64_t duration = static_cast<int64_t>(d * USECS_PER_S);
--- a/dom/media/webm/IntelWebMVideoDecoder.cpp
+++ b/dom/media/webm/IntelWebMVideoDecoder.cpp
@@ -348,17 +348,17 @@ IntelWebMVideoDecoder::DecodeVideoFrame(
       return false;
     }
     a.mParsed = a.mDropped;
     aKeyframeSkip = false;
     nsresult rv = mMediaDataDecoder->Flush();
     NS_ENSURE_SUCCESS(rv, false);
   }
 
-  NS_ASSERTION(mReader->GetDecoder()->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(mReader->OnTaskQueue());
   bool rv = Decode();
   {
     // Report the number of "decoded" frames as the difference in the
     // mNumSamplesOutput field since the last time we were called.
     MonitorAutoLock mon(mMonitor);
     uint64_t delta = mNumSamplesOutput - mLastReportedNumDecodedFrames;
     a.mDecoded = static_cast<uint32_t>(delta);
     mLastReportedNumDecodedFrames = mNumSamplesOutput;
--- a/dom/media/webm/SoftwareWebMVideoDecoder.cpp
+++ b/dom/media/webm/SoftwareWebMVideoDecoder.cpp
@@ -69,18 +69,17 @@ SoftwareWebMVideoDecoder::Init(unsigned 
   }
   return NS_OK;
 }
 
 bool
 SoftwareWebMVideoDecoder::DecodeVideoFrame(bool &aKeyframeSkip,
                                            int64_t aTimeThreshold)
 {
-  NS_ASSERTION(mReader->GetDecoder()->OnDecodeThread(),
-               "Should be on decode thread.");
+  MOZ_ASSERT(mReader->OnTaskQueue());
 
   // Record number of frames decoded and parsed. Automatically update the
   // stats counters using the AutoNotifyDecoded stack-based class.
   AbstractMediaDecoder::AutoNotifyDecoded a(mReader->GetDecoder());
 
   nsAutoRef<NesteggPacketHolder> holder(mReader->NextPacket(WebMReader::VIDEO));
   if (!holder) {
     return false;
--- a/dom/media/webm/WebMReader.cpp
+++ b/dom/media/webm/WebMReader.cpp
@@ -324,17 +324,20 @@ void WebMReader::Cleanup()
     nestegg_destroy(mContext);
     mContext = nullptr;
   }
 }
 
 nsresult WebMReader::ReadMetadata(MediaInfo* aInfo,
                                   MetadataTags** aTags)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  // We can't use OnTaskQueue() here because of the wacky initialization task
+  // queue that TrackBuffer uses. We should be able to fix this when we do
+  // bug 1148234.
+  MOZ_ASSERT(mDecoder->OnDecodeThread());
 
   nestegg_io io;
   io.read = webm_read;
   io.seek = webm_seek;
   io.tell = webm_tell;
   io.userdata = mDecoder;
   int64_t maxOffset = mDecoder->HasInitializationData() ?
     mBufferedState->GetInitEndOffset() : -1;
@@ -578,17 +581,17 @@ bool WebMReader::InitOpusDecoder()
   mSkip = mOpusParser->mPreSkip;
   mPaddingDiscarded = false;
 
   return r == OPUS_OK;
 }
 
 bool WebMReader::DecodeAudioPacket(nestegg_packet* aPacket, int64_t aOffset)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   int r = 0;
   unsigned int count = 0;
   r = nestegg_packet_count(aPacket, &count);
   if (r == -1) {
     return false;
   }
 
@@ -926,17 +929,17 @@ nsReturnRef<NesteggPacketHolder> WebMRea
     } while (true);
   }
 
   return holder.out();
 }
 
 bool WebMReader::DecodeAudioData()
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   nsAutoRef<NesteggPacketHolder> holder(NextPacket(AUDIO));
   if (!holder) {
     return false;
   }
 
   return DecodeAudioPacket(holder->mPacket, holder->mOffset);
 }
@@ -1059,17 +1062,17 @@ WebMReader::Seek(int64_t aTarget, int64_
     return SeekPromise::CreateAndReject(res, __func__);
   } else {
     return SeekPromise::CreateAndResolve(aTarget, __func__);
   }
 }
 
 nsresult WebMReader::SeekInternal(int64_t aTarget)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   if (mVideoDecoder) {
     nsresult rv = mVideoDecoder->Flush();
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   LOG(PR_LOG_DEBUG, ("Reader [%p] for Decoder [%p]: About to seek to %fs",
                      this, mDecoder, double(aTarget) / USECS_PER_S));
   if (NS_FAILED(ResetDecode())) {
--- a/dom/media/webm/WebMReader.h
+++ b/dom/media/webm/WebMReader.h
@@ -138,23 +138,23 @@ public:
   virtual nsresult ResetDecode() override;
   virtual bool DecodeAudioData() override;
 
   virtual bool DecodeVideoFrame(bool &aKeyframeSkip,
                                 int64_t aTimeThreshold) override;
 
   virtual bool HasAudio() override
   {
-    NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+    MOZ_ASSERT(OnTaskQueue());
     return mHasAudio;
   }
 
   virtual bool HasVideo() override
   {
-    NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+    MOZ_ASSERT(OnTaskQueue());
     return mHasVideo;
   }
 
   virtual nsresult ReadMetadata(MediaInfo* aInfo,
                                 MetadataTags** aTags) override;
   virtual nsRefPtr<SeekPromise>
   Seek(int64_t aTime, int64_t aEndTime) override;
 
--- a/dom/media/wmf/WMFReader.cpp
+++ b/dom/media/wmf/WMFReader.cpp
@@ -149,24 +149,24 @@ WMFReader::Init(MediaDecoderReader* aClo
   }
 
   return NS_OK;
 }
 
 bool
 WMFReader::HasAudio()
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   return mHasAudio;
 }
 
 bool
 WMFReader::HasVideo()
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
   return mHasVideo;
 }
 
 static HRESULT
 ConfigureSourceReaderStream(IMFSourceReader *aReader,
                             const DWORD aStreamIndex,
                             const GUID& aOutputSubType,
                             const GUID* aAllowedInSubTypes,
@@ -502,17 +502,17 @@ WMFReader::CreateSourceReader()
   }
   return hr;
 }
 
 nsresult
 WMFReader::ReadMetadata(MediaInfo* aInfo,
                         MetadataTags** aTags)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   DECODER_LOG("WMFReader::ReadMetadata()");
   HRESULT hr;
 
   const bool triedToInitDXVA = mUseHwAccel;
   if (FAILED(CreateSourceReader())) {
     mSourceReader = nullptr;
     if (triedToInitDXVA && !mUseHwAccel) {
@@ -570,17 +570,17 @@ WMFReader::IsMediaSeekable()
     return false;
   }
   return true;
 }
 
 bool
 WMFReader::DecodeAudioData()
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   HRESULT hr;
   hr = mSourceReader->ReadSample(MF_SOURCE_READER_FIRST_AUDIO_STREAM,
                                  0, // control flags
                                  0, // read stream index
                                  nullptr,
                                  nullptr,
                                  nullptr);
@@ -799,17 +799,17 @@ WMFReader::CreateD3DVideoFrame(IMFSample
 
   return S_OK;
 }
 
 bool
 WMFReader::DecodeVideoFrame(bool &aKeyframeSkip,
                             int64_t aTimeThreshold)
 {
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 
   // Record number of frames decoded and parsed. Automatically update the
   // stats counters using the AutoNotifyDecoded stack-based class.
   AbstractMediaDecoder::AutoNotifyDecoded a(mDecoder);
 
   HRESULT hr;
 
   hr = mSourceReader->ReadSample(MF_SOURCE_READER_FIRST_VIDEO_STREAM,
@@ -904,17 +904,17 @@ WMFReader::Seek(int64_t aTargetUs, int64
   }
 }
 
 nsresult
 WMFReader::SeekInternal(int64_t aTargetUs)
 {
   DECODER_LOG("WMFReader::Seek() %lld", aTargetUs);
 
-  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
+  MOZ_ASSERT(OnTaskQueue());
 #ifdef DEBUG
   bool canSeek = false;
   GetSourceReaderCanSeek(mSourceReader, canSeek);
   NS_ASSERTION(canSeek, "WMFReader::Seek() should only be called if we can seek!");
 #endif
 
   nsresult rv = ResetDecode();
   NS_ENSURE_SUCCESS(rv, rv);