Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef __FFmpegDataDecoder_h__
8 : #define __FFmpegDataDecoder_h__
9 :
10 : #include "PlatformDecoderModule.h"
11 : #include "FFmpegLibWrapper.h"
12 : #include "mozilla/StaticMutex.h"
13 : #include "FFmpegLibs.h"
14 :
15 : namespace mozilla {
16 :
17 : template <int V>
18 : class FFmpegDataDecoder : public MediaDataDecoder
19 : {
20 : };
21 :
22 : template <>
23 : class FFmpegDataDecoder<LIBAV_VER> : public MediaDataDecoder
24 : {
25 : public:
26 : FFmpegDataDecoder(FFmpegLibWrapper* aLib, TaskQueue* aTaskQueue,
27 : AVCodecID aCodecID);
28 : virtual ~FFmpegDataDecoder();
29 :
30 : static bool Link();
31 :
32 : RefPtr<InitPromise> Init() override = 0;
33 : RefPtr<DecodePromise> Decode(MediaRawData* aSample) override;
34 : RefPtr<DecodePromise> Drain() override;
35 : RefPtr<FlushPromise> Flush() override;
36 : RefPtr<ShutdownPromise> Shutdown() override;
37 :
38 : static AVCodec* FindAVCodec(FFmpegLibWrapper* aLib, AVCodecID aCodec);
39 :
40 : protected:
41 : // Flush and Drain operation, always run
42 : virtual RefPtr<FlushPromise> ProcessFlush();
43 : virtual void ProcessShutdown();
44 0 : virtual void InitCodecContext() { }
45 : AVFrame* PrepareFrame();
46 : nsresult InitDecoder();
47 :
48 : FFmpegLibWrapper* mLib;
49 :
50 : AVCodecContext* mCodecContext;
51 : AVFrame* mFrame;
52 : RefPtr<MediaByteBuffer> mExtraData;
53 : AVCodecID mCodecID;
54 :
55 : private:
56 : virtual RefPtr<DecodePromise> ProcessDecode(MediaRawData* aSample) = 0;
57 : virtual RefPtr<DecodePromise> ProcessDrain() = 0;
58 :
59 : static StaticMutex sMonitor;
60 : const RefPtr<TaskQueue> mTaskQueue;
61 : MozPromiseHolder<DecodePromise> mPromise;
62 : };
63 :
64 : } // namespace mozilla
65 :
66 : #endif // __FFmpegDataDecoder_h__
|