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 __FFmpegDecoderModule_h__
8 : #define __FFmpegDecoderModule_h__
9 :
10 : #include "PlatformDecoderModule.h"
11 : #include "FFmpegLibWrapper.h"
12 : #include "FFmpegAudioDecoder.h"
13 : #include "FFmpegVideoDecoder.h"
14 : #include "MediaPrefs.h"
15 :
16 : namespace mozilla {
17 :
18 : template <int V>
19 : class FFmpegDecoderModule : public PlatformDecoderModule
20 : {
21 : public:
22 : static already_AddRefed<PlatformDecoderModule>
23 0 : Create(FFmpegLibWrapper* aLib)
24 : {
25 0 : RefPtr<PlatformDecoderModule> pdm = new FFmpegDecoderModule(aLib);
26 :
27 0 : return pdm.forget();
28 : }
29 :
30 0 : explicit FFmpegDecoderModule(FFmpegLibWrapper* aLib) : mLib(aLib) { }
31 0 : virtual ~FFmpegDecoderModule() { }
32 :
33 : already_AddRefed<MediaDataDecoder>
34 0 : CreateVideoDecoder(const CreateDecoderParams& aParams) override
35 : {
36 : // Temporary - forces use of VPXDecoder when alpha is present.
37 : // Bug 1263836 will handle alpha scenario once implemented. It will shift
38 : // the check for alpha to PDMFactory but not itself remove the need for a
39 : // check.
40 0 : if (aParams.VideoConfig().HasAlpha()) {
41 0 : return nullptr;
42 : }
43 0 : if (aParams.mOptions.contains(
44 0 : CreateDecoderParams::Option::LowLatency) &&
45 0 : !MediaPrefs::PDMFFmpegLowLatencyEnabled()) {
46 0 : return nullptr;
47 : }
48 0 : RefPtr<MediaDataDecoder> decoder = new FFmpegVideoDecoder<V>(
49 : mLib,
50 0 : aParams.mTaskQueue,
51 : aParams.VideoConfig(),
52 : aParams.mKnowsCompositor,
53 0 : aParams.mImageContainer,
54 0 : aParams.mOptions.contains(CreateDecoderParams::Option::LowLatency));
55 0 : return decoder.forget();
56 : }
57 :
58 : already_AddRefed<MediaDataDecoder>
59 0 : CreateAudioDecoder(const CreateDecoderParams& aParams) override
60 : {
61 : RefPtr<MediaDataDecoder> decoder =
62 0 : new FFmpegAudioDecoder<V>(mLib,
63 0 : aParams.mTaskQueue,
64 0 : aParams.AudioConfig());
65 0 : return decoder.forget();
66 : }
67 :
68 0 : bool SupportsMimeType(const nsACString& aMimeType,
69 : DecoderDoctorDiagnostics* aDiagnostics) const override
70 : {
71 0 : AVCodecID videoCodec = FFmpegVideoDecoder<V>::GetCodecId(aMimeType);
72 0 : AVCodecID audioCodec = FFmpegAudioDecoder<V>::GetCodecId(aMimeType);
73 0 : if (audioCodec == AV_CODEC_ID_NONE && videoCodec == AV_CODEC_ID_NONE) {
74 0 : return false;
75 : }
76 0 : AVCodecID codec = audioCodec != AV_CODEC_ID_NONE ? audioCodec : videoCodec;
77 0 : return !!FFmpegDataDecoder<V>::FindAVCodec(mLib, codec);
78 : }
79 :
80 : private:
81 : FFmpegLibWrapper* mLib;
82 : };
83 :
84 : } // namespace mozilla
85 :
86 : #endif // __FFmpegDecoderModule_h__
|