diff --git a/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp b/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp index 8fcacb935008..a41ec79bc869 100644 --- a/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp +++ b/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp @@ -96,8 +96,8 @@ CopyAndPackAudio(AVFrame* aFrame, uint32_t aNumChannels, uint32_t aNumAFrames) return audio; } -void -FFmpegAudioDecoder::DecodePacket(MediaRawData* aSample) +FFmpegAudioDecoder::DecodeResult +FFmpegAudioDecoder::DoDecode(MediaRawData* aSample) { MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn()); AVPacket packet; @@ -109,7 +109,7 @@ FFmpegAudioDecoder::DecodePacket(MediaRawData* aSample) if (!PrepareFrame()) { NS_WARNING("FFmpeg audio decoder failed to allocate frame."); mCallback->Error(); - return; + return DecodeResult::DECODE_ERROR; } int64_t samplePosition = aSample->mOffset; @@ -123,7 +123,7 @@ FFmpegAudioDecoder::DecodePacket(MediaRawData* aSample) if (bytesConsumed < 0) { NS_WARNING("FFmpeg audio decoder error."); mCallback->Error(); - return; + return DecodeResult::DECODE_ERROR; } if (decoded) { @@ -131,7 +131,7 @@ FFmpegAudioDecoder::DecodePacket(MediaRawData* aSample) AudioConfig::ChannelLayout layout(numChannels); if (!layout.IsValid()) { mCallback->Error(); - return; + return DecodeResult::DECODE_ERROR; } uint32_t samplingRate = mCodecContext->sample_rate; @@ -144,7 +144,7 @@ FFmpegAudioDecoder::DecodePacket(MediaRawData* aSample) if (!audio || !duration.IsValid()) { NS_WARNING("Invalid count of accumulated audio samples"); mCallback->Error(); - return; + return DecodeResult::DECODE_ERROR; } RefPtr data = new AudioData(samplePosition, @@ -159,7 +159,7 @@ FFmpegAudioDecoder::DecodePacket(MediaRawData* aSample) if (!pts.IsValid()) { NS_WARNING("Invalid count of accumulated audio samples"); mCallback->Error(); - return; + return DecodeResult::DECODE_ERROR; } } packet.data += bytesConsumed; @@ -167,7 +167,14 @@ FFmpegAudioDecoder::DecodePacket(MediaRawData* aSample) samplePosition += bytesConsumed; } - if (mTaskQueue->IsEmpty()) { + return DecodeResult::DECODE_FRAME; +} + +void +FFmpegAudioDecoder::ProcessDecode(MediaRawData* aSample) +{ + MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn()); + if (DoDecode(aSample) != DecodeResult::DECODE_ERROR && mTaskQueue->IsEmpty()) { mCallback->InputExhausted(); } } @@ -175,9 +182,8 @@ FFmpegAudioDecoder::DecodePacket(MediaRawData* aSample) nsresult FFmpegAudioDecoder::Input(MediaRawData* aSample) { - nsCOMPtr runnable(NewRunnableMethod>( - this, &FFmpegAudioDecoder::DecodePacket, RefPtr(aSample))); - mTaskQueue->Dispatch(runnable.forget()); + mTaskQueue->Dispatch(NewRunnableMethod>( + this, &FFmpegAudioDecoder::ProcessDecode, aSample)); return NS_OK; } diff --git a/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.h b/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.h index c6092722e3cd..15d58d06f71f 100644 --- a/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.h +++ b/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.h @@ -20,6 +20,12 @@ template class FFmpegAudioDecoder template <> class FFmpegAudioDecoder : public FFmpegDataDecoder { + enum DecodeResult { + DECODE_FRAME, + DECODE_NO_FRAME, + DECODE_ERROR + }; + public: FFmpegAudioDecoder(FFmpegLibWrapper* aLib, FlushableTaskQueue* aTaskQueue, MediaDataDecoderCallback* aCallback, @@ -37,7 +43,8 @@ public: } private: - void DecodePacket(MediaRawData* aSample); + void ProcessDecode(MediaRawData* aSample); + DecodeResult DoDecode(MediaRawData* aSample); }; } // namespace mozilla