зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1271508. Part 3 - extract code to the parent class and remove use of mTaskQueue from sub-classes. r=jya.
This commit is contained in:
Родитель
663cb8f7b8
Коммит
651acd2608
|
@ -99,7 +99,6 @@ CopyAndPackAudio(AVFrame* aFrame, uint32_t aNumChannels, uint32_t aNumAFrames)
|
|||
FFmpegAudioDecoder<LIBAV_VER>::DecodeResult
|
||||
FFmpegAudioDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample)
|
||||
{
|
||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
AVPacket packet;
|
||||
mLib->av_init_packet(&packet);
|
||||
|
||||
|
@ -108,7 +107,6 @@ FFmpegAudioDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample)
|
|||
|
||||
if (!PrepareFrame()) {
|
||||
NS_WARNING("FFmpeg audio decoder failed to allocate frame.");
|
||||
mCallback->Error();
|
||||
return DecodeResult::DECODE_ERROR;
|
||||
}
|
||||
|
||||
|
@ -122,7 +120,6 @@ FFmpegAudioDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample)
|
|||
|
||||
if (bytesConsumed < 0) {
|
||||
NS_WARNING("FFmpeg audio decoder error.");
|
||||
mCallback->Error();
|
||||
return DecodeResult::DECODE_ERROR;
|
||||
}
|
||||
|
||||
|
@ -130,7 +127,6 @@ FFmpegAudioDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample)
|
|||
uint32_t numChannels = mCodecContext->channels;
|
||||
AudioConfig::ChannelLayout layout(numChannels);
|
||||
if (!layout.IsValid()) {
|
||||
mCallback->Error();
|
||||
return DecodeResult::DECODE_ERROR;
|
||||
}
|
||||
|
||||
|
@ -143,7 +139,6 @@ FFmpegAudioDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample)
|
|||
FramesToTimeUnit(mFrame->nb_samples, samplingRate);
|
||||
if (!audio || !duration.IsValid()) {
|
||||
NS_WARNING("Invalid count of accumulated audio samples");
|
||||
mCallback->Error();
|
||||
return DecodeResult::DECODE_ERROR;
|
||||
}
|
||||
|
||||
|
@ -158,7 +153,6 @@ FFmpegAudioDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample)
|
|||
pts += duration;
|
||||
if (!pts.IsValid()) {
|
||||
NS_WARNING("Invalid count of accumulated audio samples");
|
||||
mCallback->Error();
|
||||
return DecodeResult::DECODE_ERROR;
|
||||
}
|
||||
}
|
||||
|
@ -170,27 +164,9 @@ FFmpegAudioDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample)
|
|||
return DecodeResult::DECODE_FRAME;
|
||||
}
|
||||
|
||||
void
|
||||
FFmpegAudioDecoder<LIBAV_VER>::ProcessDecode(MediaRawData* aSample)
|
||||
{
|
||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
if (DoDecode(aSample) != DecodeResult::DECODE_ERROR && mTaskQueue->IsEmpty()) {
|
||||
mCallback->InputExhausted();
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
FFmpegAudioDecoder<LIBAV_VER>::Input(MediaRawData* aSample)
|
||||
{
|
||||
mTaskQueue->Dispatch(NewRunnableMethod<RefPtr<MediaRawData>>(
|
||||
this, &FFmpegAudioDecoder::ProcessDecode, aSample));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
FFmpegAudioDecoder<LIBAV_VER>::ProcessDrain()
|
||||
{
|
||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
ProcessFlush();
|
||||
mCallback->DrainComplete();
|
||||
}
|
||||
|
|
|
@ -20,12 +20,6 @@ template <int V> class FFmpegAudioDecoder
|
|||
template <>
|
||||
class FFmpegAudioDecoder<LIBAV_VER> : public FFmpegDataDecoder<LIBAV_VER>
|
||||
{
|
||||
enum DecodeResult {
|
||||
DECODE_FRAME,
|
||||
DECODE_NO_FRAME,
|
||||
DECODE_ERROR
|
||||
};
|
||||
|
||||
public:
|
||||
FFmpegAudioDecoder(FFmpegLibWrapper* aLib, FlushableTaskQueue* aTaskQueue,
|
||||
MediaDataDecoderCallback* aCallback,
|
||||
|
@ -33,8 +27,6 @@ public:
|
|||
virtual ~FFmpegAudioDecoder();
|
||||
|
||||
RefPtr<InitPromise> Init() override;
|
||||
nsresult Input(MediaRawData* aSample) override;
|
||||
void ProcessDrain() override;
|
||||
void InitCodecContext() override;
|
||||
static AVCodecID GetCodecId(const nsACString& aMimeType);
|
||||
const char* GetDescriptionName() const override
|
||||
|
@ -43,8 +35,8 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
void ProcessDecode(MediaRawData* aSample);
|
||||
DecodeResult DoDecode(MediaRawData* aSample);
|
||||
DecodeResult DoDecode(MediaRawData* aSample) override;
|
||||
void ProcessDrain() override;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -26,12 +26,12 @@ StaticMutex FFmpegDataDecoder<LIBAV_VER>::sMonitor;
|
|||
MediaDataDecoderCallback* aCallback,
|
||||
AVCodecID aCodecID)
|
||||
: mLib(aLib)
|
||||
, mTaskQueue(aTaskQueue)
|
||||
, mCallback(aCallback)
|
||||
, mCodecContext(nullptr)
|
||||
, mFrame(NULL)
|
||||
, mExtraData(nullptr)
|
||||
, mCodecID(aCodecID)
|
||||
, mTaskQueue(aTaskQueue)
|
||||
{
|
||||
MOZ_ASSERT(aLib);
|
||||
MOZ_COUNT_CTOR(FFmpegDataDecoder);
|
||||
|
@ -111,6 +111,29 @@ FFmpegDataDecoder<LIBAV_VER>::Shutdown()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
FFmpegDataDecoder<LIBAV_VER>::ProcessDecode(MediaRawData* aSample)
|
||||
{
|
||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
switch (DoDecode(aSample)) {
|
||||
case DecodeResult::DECODE_ERROR:
|
||||
mCallback->Error();
|
||||
break;
|
||||
default:
|
||||
if (mTaskQueue->IsEmpty()) {
|
||||
mCallback->InputExhausted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
FFmpegDataDecoder<LIBAV_VER>::Input(MediaRawData* aSample)
|
||||
{
|
||||
mTaskQueue->Dispatch(NewRunnableMethod<RefPtr<MediaRawData>>(
|
||||
this, &FFmpegDataDecoder::ProcessDecode, aSample));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
FFmpegDataDecoder<LIBAV_VER>::Flush()
|
||||
{
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
static bool Link();
|
||||
|
||||
RefPtr<InitPromise> Init() override = 0;
|
||||
nsresult Input(MediaRawData* aSample) override = 0;
|
||||
nsresult Input(MediaRawData* aSample) override;
|
||||
nsresult Flush() override;
|
||||
nsresult Drain() override;
|
||||
nsresult Shutdown() override;
|
||||
|
@ -40,16 +40,20 @@ public:
|
|||
static AVCodec* FindAVCodec(FFmpegLibWrapper* aLib, AVCodecID aCodec);
|
||||
|
||||
protected:
|
||||
enum DecodeResult {
|
||||
DECODE_FRAME,
|
||||
DECODE_NO_FRAME,
|
||||
DECODE_ERROR
|
||||
};
|
||||
|
||||
// Flush and Drain operation, always run
|
||||
virtual void ProcessFlush();
|
||||
virtual void ProcessDrain() = 0;
|
||||
virtual void ProcessShutdown();
|
||||
virtual void InitCodecContext() {}
|
||||
AVFrame* PrepareFrame();
|
||||
nsresult InitDecoder();
|
||||
|
||||
FFmpegLibWrapper* mLib;
|
||||
RefPtr<FlushableTaskQueue> mTaskQueue;
|
||||
MediaDataDecoderCallback* mCallback;
|
||||
|
||||
AVCodecContext* mCodecContext;
|
||||
|
@ -58,7 +62,12 @@ protected:
|
|||
AVCodecID mCodecID;
|
||||
|
||||
private:
|
||||
void ProcessDecode(MediaRawData* aSample);
|
||||
virtual DecodeResult DoDecode(MediaRawData* aSample) = 0;
|
||||
virtual void ProcessDrain() = 0;
|
||||
|
||||
static StaticMutex sMonitor;
|
||||
const RefPtr<FlushableTaskQueue> mTaskQueue;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -161,8 +161,6 @@ FFmpegVideoDecoder<LIBAV_VER>::InitCodecContext()
|
|||
FFmpegVideoDecoder<LIBAV_VER>::DecodeResult
|
||||
FFmpegVideoDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample)
|
||||
{
|
||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
|
||||
uint8_t* inputData = const_cast<uint8_t*>(aSample->Data());
|
||||
size_t inputSize = aSample->Size();
|
||||
|
||||
|
@ -181,7 +179,6 @@ FFmpegVideoDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample)
|
|||
aSample->mTime, aSample->mTimecode,
|
||||
aSample->mOffset);
|
||||
if (size_t(len) > inputSize) {
|
||||
mCallback->Error();
|
||||
return DecodeResult::DECODE_ERROR;
|
||||
}
|
||||
inputData += len;
|
||||
|
@ -208,8 +205,6 @@ FFmpegVideoDecoder<LIBAV_VER>::DecodeResult
|
|||
FFmpegVideoDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample,
|
||||
uint8_t* aData, int aSize)
|
||||
{
|
||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
|
||||
AVPacket packet;
|
||||
mLib->av_init_packet(&packet);
|
||||
|
||||
|
@ -229,7 +224,6 @@ FFmpegVideoDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample,
|
|||
|
||||
if (!PrepareFrame()) {
|
||||
NS_WARNING("FFmpeg h264 decoder failed to allocate frame.");
|
||||
mCallback->Error();
|
||||
return DecodeResult::DECODE_ERROR;
|
||||
}
|
||||
|
||||
|
@ -248,7 +242,6 @@ FFmpegVideoDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample,
|
|||
|
||||
if (bytesConsumed < 0) {
|
||||
NS_WARNING("FFmpeg video decoder error.");
|
||||
mCallback->Error();
|
||||
return DecodeResult::DECODE_ERROR;
|
||||
}
|
||||
|
||||
|
@ -307,7 +300,6 @@ FFmpegVideoDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample,
|
|||
|
||||
if (!v) {
|
||||
NS_WARNING("image allocation error.");
|
||||
mCallback->Error();
|
||||
return DecodeResult::DECODE_ERROR;
|
||||
}
|
||||
mCallback->Output(v);
|
||||
|
@ -316,27 +308,9 @@ FFmpegVideoDecoder<LIBAV_VER>::DoDecode(MediaRawData* aSample,
|
|||
return DecodeResult::DECODE_NO_FRAME;
|
||||
}
|
||||
|
||||
void
|
||||
FFmpegVideoDecoder<LIBAV_VER>::ProcessDecode(MediaRawData* aSample)
|
||||
{
|
||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
if (DoDecode(aSample) != DecodeResult::DECODE_ERROR && mTaskQueue->IsEmpty()) {
|
||||
mCallback->InputExhausted();
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
FFmpegVideoDecoder<LIBAV_VER>::Input(MediaRawData* aSample)
|
||||
{
|
||||
mTaskQueue->Dispatch(NewRunnableMethod<RefPtr<MediaRawData>>(
|
||||
this, &FFmpegVideoDecoder::ProcessDecode, aSample));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
FFmpegVideoDecoder<LIBAV_VER>::ProcessDrain()
|
||||
{
|
||||
MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
|
||||
RefPtr<MediaRawData> empty(new MediaRawData());
|
||||
empty->mTimecode = mPtsContext.LastDts();
|
||||
while (DoDecode(empty) == DecodeResult::DECODE_FRAME) {
|
||||
|
|
|
@ -26,12 +26,6 @@ class FFmpegVideoDecoder<LIBAV_VER> : public FFmpegDataDecoder<LIBAV_VER>
|
|||
typedef mozilla::layers::Image Image;
|
||||
typedef mozilla::layers::ImageContainer ImageContainer;
|
||||
|
||||
enum DecodeResult {
|
||||
DECODE_FRAME,
|
||||
DECODE_NO_FRAME,
|
||||
DECODE_ERROR
|
||||
};
|
||||
|
||||
public:
|
||||
FFmpegVideoDecoder(FFmpegLibWrapper* aLib, FlushableTaskQueue* aTaskQueue,
|
||||
MediaDataDecoderCallback* aCallback,
|
||||
|
@ -40,9 +34,6 @@ public:
|
|||
virtual ~FFmpegVideoDecoder();
|
||||
|
||||
RefPtr<InitPromise> Init() override;
|
||||
nsresult Input(MediaRawData* aSample) override;
|
||||
void ProcessDrain() override;
|
||||
void ProcessFlush() override;
|
||||
void InitCodecContext() override;
|
||||
const char* GetDescriptionName() const override
|
||||
{
|
||||
|
@ -55,10 +46,10 @@ public:
|
|||
static AVCodecID GetCodecId(const nsACString& aMimeType);
|
||||
|
||||
private:
|
||||
void ProcessDecode(MediaRawData* aSample);
|
||||
DecodeResult DoDecode(MediaRawData* aSample);
|
||||
DecodeResult DoDecode(MediaRawData* aSample) override;
|
||||
DecodeResult DoDecode(MediaRawData* aSample, uint8_t* aData, int aSize);
|
||||
void DoDrain();
|
||||
void ProcessDrain() override;
|
||||
void ProcessFlush() override;
|
||||
void OutputDelayedFrames();
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче