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 : #include "DecoderDoctorDiagnostics.h"
8 : #include "GMPDecoderModule.h"
9 : #include "GMPService.h"
10 : #include "GMPUtils.h"
11 : #include "GMPVideoDecoder.h"
12 : #include "MP4Decoder.h"
13 : #include "MediaDataDecoderProxy.h"
14 : #include "MediaPrefs.h"
15 : #include "VPXDecoder.h"
16 : #include "VideoUtils.h"
17 : #include "gmp-video-decode.h"
18 : #include "mozIGeckoMediaPluginService.h"
19 : #include "mozilla/StaticMutex.h"
20 : #include "nsServiceManagerUtils.h"
21 : #ifdef XP_WIN
22 : #include "WMFDecoderModule.h"
23 : #endif
24 :
25 : namespace mozilla {
26 :
27 0 : GMPDecoderModule::GMPDecoderModule()
28 : {
29 0 : }
30 :
31 0 : GMPDecoderModule::~GMPDecoderModule()
32 : {
33 0 : }
34 :
35 : static already_AddRefed<MediaDataDecoderProxy>
36 0 : CreateDecoderWrapper()
37 : {
38 : RefPtr<gmp::GeckoMediaPluginService> s(
39 0 : gmp::GeckoMediaPluginService::GetGeckoMediaPluginService());
40 0 : if (!s) {
41 0 : return nullptr;
42 : }
43 0 : RefPtr<AbstractThread> thread(s->GetAbstractGMPThread());
44 0 : if (!thread) {
45 0 : return nullptr;
46 : }
47 : RefPtr<MediaDataDecoderProxy> decoder(
48 0 : new MediaDataDecoderProxy(thread.forget()));
49 0 : return decoder.forget();
50 : }
51 :
52 : already_AddRefed<MediaDataDecoder>
53 0 : GMPDecoderModule::CreateVideoDecoder(const CreateDecoderParams& aParams)
54 : {
55 0 : if (!MP4Decoder::IsH264(aParams.mConfig.mMimeType)
56 0 : && !VPXDecoder::IsVP8(aParams.mConfig.mMimeType)
57 0 : && !VPXDecoder::IsVP9(aParams.mConfig.mMimeType)) {
58 0 : return nullptr;
59 : }
60 :
61 0 : RefPtr<MediaDataDecoderProxy> wrapper = CreateDecoderWrapper();
62 0 : auto params = GMPVideoDecoderParams(aParams);
63 0 : wrapper->SetProxyTarget(new GMPVideoDecoder(params));
64 0 : return wrapper.forget();
65 : }
66 :
67 : already_AddRefed<MediaDataDecoder>
68 0 : GMPDecoderModule::CreateAudioDecoder(const CreateDecoderParams& aParams)
69 : {
70 0 : return nullptr;
71 : }
72 :
73 : /* static */
74 : bool
75 0 : GMPDecoderModule::SupportsMimeType(const nsACString& aMimeType,
76 : const Maybe<nsCString>& aGMP)
77 : {
78 0 : if (aGMP.isNothing()) {
79 0 : return false;
80 : }
81 :
82 0 : nsCString api = MediaPrefs::EMEChromiumAPIEnabled()
83 0 : ? NS_LITERAL_CSTRING(CHROMIUM_CDM_API)
84 0 : : NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER);
85 :
86 0 : if (MP4Decoder::IsH264(aMimeType)) {
87 0 : return HaveGMPFor(api, { NS_LITERAL_CSTRING("h264"), aGMP.value()});
88 : }
89 :
90 0 : if (VPXDecoder::IsVP9(aMimeType)) {
91 0 : return HaveGMPFor(api, { NS_LITERAL_CSTRING("vp9"), aGMP.value()});
92 : }
93 :
94 0 : if (VPXDecoder::IsVP8(aMimeType)) {
95 0 : return HaveGMPFor(api, { NS_LITERAL_CSTRING("vp8"), aGMP.value()});
96 : }
97 :
98 0 : return false;
99 : }
100 :
101 : bool
102 0 : GMPDecoderModule::SupportsMimeType(const nsACString& aMimeType,
103 : DecoderDoctorDiagnostics* aDiagnostics) const
104 : {
105 0 : return false;
106 : }
107 :
108 : } // namespace mozilla
|