diff --git a/dom/media/MediaDataDecodedListener.h b/dom/media/MediaDataDecodedListener.h index 2d5e9d0c9942..cbcb67b2c311 100644 --- a/dom/media/MediaDataDecodedListener.h +++ b/dom/media/MediaDataDecodedListener.h @@ -20,6 +20,8 @@ class MediaData; template class MediaDataDecodedListener : public RequestSampleCallback { public: + using RequestSampleCallback::NotDecodedReason; + MediaDataDecodedListener(Target* aTarget, MediaTaskQueue* aTaskQueue) : mMonitor("MediaDataDecodedListener") @@ -50,8 +52,7 @@ public: mTaskQueue->Dispatch(task); } - virtual void OnNotDecoded(MediaData::Type aType, - MediaDecoderReader::NotDecodedReason aReason) MOZ_OVERRIDE { + virtual void OnNotDecoded(MediaData::Type aType, NotDecodedReason aReason) MOZ_OVERRIDE { MonitorAutoLock lock(mMonitor); if (!mTarget || !mTaskQueue) { // We've been shutdown, abort. @@ -132,7 +133,7 @@ private: class DeliverNotDecodedTask : public nsRunnable { public: DeliverNotDecodedTask(MediaData::Type aType, - MediaDecoderReader::NotDecodedReason aReason, + RequestSampleCallback::NotDecodedReason aReason, Target* aTarget) : mType(aType) , mReason(aReason) @@ -152,7 +153,7 @@ private: } private: MediaData::Type mType; - MediaDecoderReader::NotDecodedReason mReason; + RequestSampleCallback::NotDecodedReason mReason; RefPtr mTarget; }; diff --git a/dom/media/MediaDecoderReader.cpp b/dom/media/MediaDecoderReader.cpp index 1de9b6f12580..e0bdfb389da7 100644 --- a/dom/media/MediaDecoderReader.cpp +++ b/dom/media/MediaDecoderReader.cpp @@ -204,7 +204,7 @@ MediaDecoderReader::RequestVideoData(bool aSkipToNextKeyframe, } GetCallback()->OnVideoDecoded(v); } else if (VideoQueue().IsFinished()) { - GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA, END_OF_STREAM); + GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA, RequestSampleCallback::END_OF_STREAM); } } @@ -237,7 +237,7 @@ MediaDecoderReader::RequestAudioData() GetCallback()->OnAudioDecoded(a); return; } else if (AudioQueue().IsFinished()) { - GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, END_OF_STREAM); + GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, RequestSampleCallback::END_OF_STREAM); return; } } @@ -307,13 +307,12 @@ AudioDecodeRendezvous::OnAudioDecoded(AudioData* aSample) } void -AudioDecodeRendezvous::OnNotDecoded(MediaData::Type aType, - MediaDecoderReader::NotDecodedReason aReason) +AudioDecodeRendezvous::OnNotDecoded(MediaData::Type aType, NotDecodedReason aReason) { MOZ_ASSERT(aType == MediaData::AUDIO_DATA); MonitorAutoLock mon(mMonitor); mSample = nullptr; - mStatus = aReason == MediaDecoderReader::DECODE_ERROR ? NS_ERROR_FAILURE : NS_OK; + mStatus = aReason == DECODE_ERROR ? NS_ERROR_FAILURE : NS_OK; mHaveResult = true; mon.NotifyAll(); } diff --git a/dom/media/MediaDecoderReader.h b/dom/media/MediaDecoderReader.h index 508ee8fa8bd7..e759e9d15947 100644 --- a/dom/media/MediaDecoderReader.h +++ b/dom/media/MediaDecoderReader.h @@ -30,13 +30,6 @@ class SharedDecoderManager; // be accessed on the decode task queue. class MediaDecoderReader { public: - enum NotDecodedReason { - END_OF_STREAM, - DECODE_ERROR, - WAITING_FOR_DATA, - CANCELED - }; - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaDecoderReader) explicit MediaDecoderReader(AbstractMediaDecoder* aDecoder); @@ -297,6 +290,13 @@ class RequestSampleCallback { public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RequestSampleCallback) + enum NotDecodedReason { + END_OF_STREAM, + DECODE_ERROR, + WAITING_FOR_DATA, + CANCELED + }; + // Receives the result of a RequestAudioData() call. virtual void OnAudioDecoded(AudioData* aSample) = 0; @@ -305,8 +305,7 @@ public: // Called when a RequestAudioData() or RequestVideoData() call can't be // fulfiled. The reason is passed as aReason. - virtual void OnNotDecoded(MediaData::Type aType, - MediaDecoderReader::NotDecodedReason aReason) = 0; + virtual void OnNotDecoded(MediaData::Type aType, NotDecodedReason aReason) = 0; virtual void OnSeekCompleted(nsresult aResult) = 0; @@ -323,6 +322,8 @@ protected: // model of the MediaDecoderReader to a synchronous model. class AudioDecodeRendezvous : public RequestSampleCallback { public: + using RequestSampleCallback::NotDecodedReason; + AudioDecodeRendezvous(); ~AudioDecodeRendezvous(); @@ -330,8 +331,7 @@ public: // Note: aSample is null at end of stream. virtual void OnAudioDecoded(AudioData* aSample) MOZ_OVERRIDE; virtual void OnVideoDecoded(VideoData* aSample) MOZ_OVERRIDE {} - virtual void OnNotDecoded(MediaData::Type aType, - MediaDecoderReader::NotDecodedReason aReason) MOZ_OVERRIDE; + virtual void OnNotDecoded(MediaData::Type aType, NotDecodedReason aReason) MOZ_OVERRIDE; virtual void OnSeekCompleted(nsresult aResult) MOZ_OVERRIDE {}; virtual void BreakCycles() MOZ_OVERRIDE {}; void Reset(); diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 0d5b2a8d310d..44376a6a96a5 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -805,7 +805,7 @@ MediaDecoderStateMachine::Push(VideoData* aSample) void MediaDecoderStateMachine::OnNotDecoded(MediaData::Type aType, - MediaDecoderReader::NotDecodedReason aReason) + RequestSampleCallback::NotDecodedReason aReason) { ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); SAMPLE_LOG("OnNotDecoded (aType=%u, aReason=%u)", aType, aReason); @@ -820,7 +820,7 @@ MediaDecoderStateMachine::OnNotDecoded(MediaData::Type aType, } // If this is a decode error, delegate to the generic error path. - if (aReason == MediaDecoderReader::DECODE_ERROR) { + if (aReason == RequestSampleCallback::DECODE_ERROR) { DecodeError(); return; } @@ -828,7 +828,7 @@ MediaDecoderStateMachine::OnNotDecoded(MediaData::Type aType, // If the decoder is waiting for data, we need to make sure that the requests // are cleared, which happened above. Additionally, if we're out of decoded // samples, we need to switch to buffering mode. - if (aReason == MediaDecoderReader::WAITING_FOR_DATA) { + if (aReason == RequestSampleCallback::WAITING_FOR_DATA) { bool outOfSamples = isAudio ? !AudioQueue().GetSize() : !VideoQueue().GetSize(); if (outOfSamples) { StartBuffering(); @@ -837,14 +837,14 @@ MediaDecoderStateMachine::OnNotDecoded(MediaData::Type aType, return; } - if (aReason == MediaDecoderReader::CANCELED) { + if (aReason == RequestSampleCallback::CANCELED) { DispatchDecodeTasksIfNeeded(); return; } // This is an EOS. Finish off the queue, and then handle things based on our // state. - MOZ_ASSERT(aReason == MediaDecoderReader::END_OF_STREAM); + MOZ_ASSERT(aReason == RequestSampleCallback::END_OF_STREAM); if (!isAudio && mState == DECODER_STATE_SEEKING && mCurrentSeekTarget.IsValid() && mFirstVideoFrameAfterSeek) { // Null sample. Hit end of stream. If we have decoded a frame, diff --git a/dom/media/MediaDecoderStateMachine.h b/dom/media/MediaDecoderStateMachine.h index 5f23f21c5db6..11609112a0ee 100644 --- a/dom/media/MediaDecoderStateMachine.h +++ b/dom/media/MediaDecoderStateMachine.h @@ -368,7 +368,7 @@ public: void OnAudioDecoded(AudioData* aSample); void OnVideoDecoded(VideoData* aSample); - void OnNotDecoded(MediaData::Type aType, MediaDecoderReader::NotDecodedReason aReason); + void OnNotDecoded(MediaData::Type aType, RequestSampleCallback::NotDecodedReason aReason); void OnSeekCompleted(nsresult aResult); private: diff --git a/dom/media/mediasource/MediaSourceReader.cpp b/dom/media/mediasource/MediaSourceReader.cpp index d6770e640e4b..994ae82547f7 100644 --- a/dom/media/mediasource/MediaSourceReader.cpp +++ b/dom/media/mediasource/MediaSourceReader.cpp @@ -100,7 +100,7 @@ MediaSourceReader::RequestAudioData() MSE_DEBUGV("MediaSourceReader(%p)::RequestAudioData", this); if (!mAudioReader) { MSE_DEBUG("MediaSourceReader(%p)::RequestAudioData called with no audio reader", this); - GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, DECODE_ERROR); + GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, RequestSampleCallback::DECODE_ERROR); return; } mAudioIsSeeking = false; @@ -139,7 +139,7 @@ MediaSourceReader::RequestVideoData(bool aSkipToNextKeyframe, int64_t aTimeThres this, aSkipToNextKeyframe, aTimeThreshold); if (!mVideoReader) { MSE_DEBUG("MediaSourceReader(%p)::RequestVideoData called with no video reader", this); - GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA, DECODE_ERROR); + GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA, RequestSampleCallback::DECODE_ERROR); return; } if (aSkipToNextKeyframe) { @@ -177,16 +177,17 @@ MediaSourceReader::OnVideoDecoded(VideoData* aSample) } void -MediaSourceReader::OnNotDecoded(MediaData::Type aType, NotDecodedReason aReason) +MediaSourceReader::OnNotDecoded(MediaData::Type aType, RequestSampleCallback::NotDecodedReason aReason) { MSE_DEBUG("MediaSourceReader(%p)::OnNotDecoded aType=%u aReason=%u IsEnded: %d", this, aType, aReason, IsEnded()); - if (aReason == DECODE_ERROR || aReason == CANCELED) { + if (aReason == RequestSampleCallback::DECODE_ERROR || + aReason == RequestSampleCallback::CANCELED) { GetCallback()->OnNotDecoded(aType, aReason); return; } // End of stream. Force switching past this stream to another reader by // switching to the end of the buffered range. - MOZ_ASSERT(aReason == END_OF_STREAM); + MOZ_ASSERT(aReason == RequestSampleCallback::END_OF_STREAM); nsRefPtr reader = aType == MediaData::AUDIO_DATA ? mAudioReader : mVideoReader; @@ -227,13 +228,13 @@ MediaSourceReader::OnNotDecoded(MediaData::Type aType, NotDecodedReason aReason) // If the entire MediaSource is done, generate an EndOfStream. if (IsEnded()) { - GetCallback()->OnNotDecoded(aType, END_OF_STREAM); + GetCallback()->OnNotDecoded(aType, RequestSampleCallback::END_OF_STREAM); return; } // We don't have the data the caller wants. Tell that we're waiting for JS to // give us more data. - GetCallback()->OnNotDecoded(aType, WAITING_FOR_DATA); + GetCallback()->OnNotDecoded(aType, RequestSampleCallback::WAITING_FOR_DATA); } void diff --git a/dom/media/mediasource/MediaSourceReader.h b/dom/media/mediasource/MediaSourceReader.h index fdeb09b21d36..d710dd1d5d3a 100644 --- a/dom/media/mediasource/MediaSourceReader.h +++ b/dom/media/mediasource/MediaSourceReader.h @@ -54,7 +54,7 @@ public: void OnVideoDecoded(VideoData* aSample); - void OnNotDecoded(MediaData::Type aType, NotDecodedReason aReason); + void OnNotDecoded(MediaData::Type aType, RequestSampleCallback::NotDecodedReason aReason); void OnSeekCompleted(nsresult aResult); diff --git a/dom/media/omx/MediaCodecReader.cpp b/dom/media/omx/MediaCodecReader.cpp index 634a62ab198c..d13cfac3acf5 100644 --- a/dom/media/omx/MediaCodecReader.cpp +++ b/dom/media/omx/MediaCodecReader.cpp @@ -488,7 +488,7 @@ MediaCodecReader::DecodeAudioDataTask() } } if (AudioQueue().AtEndOfStream()) { - GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, END_OF_STREAM); + GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, RequestSampleCallback::END_OF_STREAM); } return result; } @@ -508,7 +508,7 @@ MediaCodecReader::DecodeVideoFrameTask(int64_t aTimeThreshold) } } if (VideoQueue().AtEndOfStream()) { - GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA, END_OF_STREAM); + GetCallback()->OnNotDecoded(MediaData::VIDEO_DATA, RequestSampleCallback::END_OF_STREAM); } return result; } diff --git a/dom/media/webm/WebMReader.cpp b/dom/media/webm/WebMReader.cpp index 5b47c331a1e5..eafa1272d7c1 100644 --- a/dom/media/webm/WebMReader.cpp +++ b/dom/media/webm/WebMReader.cpp @@ -743,7 +743,7 @@ bool WebMReader::DecodeOpus(const unsigned char* aData, size_t aLength, // Discard padding should be used only on the final packet, so // decoding after a padding discard is invalid. LOG(PR_LOG_DEBUG, ("Opus error, discard padding on interstitial packet")); - GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, DECODE_ERROR); + GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, RequestSampleCallback::DECODE_ERROR); return false; } @@ -797,7 +797,7 @@ bool WebMReader::DecodeOpus(const unsigned char* aData, size_t aLength, if (discardPadding < 0) { // Negative discard padding is invalid. LOG(PR_LOG_DEBUG, ("Opus error, negative discard padding")); - GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, DECODE_ERROR); + GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, RequestSampleCallback::DECODE_ERROR); return false; } if (discardPadding > 0) { @@ -810,7 +810,7 @@ bool WebMReader::DecodeOpus(const unsigned char* aData, size_t aLength, if (discardFrames.value() > frames) { // Discarding more than the entire packet is invalid. LOG(PR_LOG_DEBUG, ("Opus error, discard padding larger than packet")); - GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, DECODE_ERROR); + GetCallback()->OnNotDecoded(MediaData::AUDIO_DATA, RequestSampleCallback::DECODE_ERROR); return false; } LOG(PR_LOG_DEBUG, ("Opus decoder discarding %d of %d frames",