1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "GMPDecoderModule.h"
#include "DecoderDoctorDiagnostics.h"
#include "GMPAudioDecoder.h"
#include "GMPVideoDecoder.h"
#include "GMPUtils.h"
#include "MediaDataDecoderProxy.h"
#include "MediaPrefs.h"
#include "VideoUtils.h"
#include "mozIGeckoMediaPluginService.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/StaticMutex.h"
#include "gmp-audio-decode.h"
#include "gmp-video-decode.h"
#include "MP4Decoder.h"
#include "VPXDecoder.h"
#ifdef XP_WIN
#include "WMFDecoderModule.h"
#endif
namespace mozilla {
GMPDecoderModule::GMPDecoderModule()
{
}
GMPDecoderModule::~GMPDecoderModule()
{
}
static already_AddRefed<MediaDataDecoderProxy>
CreateDecoderWrapper(MediaDataDecoderCallback* aCallback)
{
RefPtr<gmp::GeckoMediaPluginService> s(gmp::GeckoMediaPluginService::GetGeckoMediaPluginService());
if (!s) {
return nullptr;
}
RefPtr<AbstractThread> thread(s->GetAbstractGMPThread());
if (!thread) {
return nullptr;
}
RefPtr<MediaDataDecoderProxy> decoder(new MediaDataDecoderProxy(thread.forget(), aCallback));
return decoder.forget();
}
already_AddRefed<MediaDataDecoder>
GMPDecoderModule::CreateVideoDecoder(const CreateDecoderParams& aParams)
{
if (!MP4Decoder::IsH264(aParams.mConfig.mMimeType) &&
!VPXDecoder::IsVP8(aParams.mConfig.mMimeType) &&
!VPXDecoder::IsVP9(aParams.mConfig.mMimeType)) {
return nullptr;
}
if (aParams.mDiagnostics) {
const Maybe<nsCString> preferredGMP = PreferredGMP(aParams.mConfig.mMimeType);
if (preferredGMP.isSome()) {
aParams.mDiagnostics->SetGMP(preferredGMP.value());
}
}
RefPtr<MediaDataDecoderProxy> wrapper = CreateDecoderWrapper(aParams.mCallback);
auto params = GMPVideoDecoderParams(aParams).WithCallback(wrapper);
wrapper->SetProxyTarget(new GMPVideoDecoder(params));
return wrapper.forget();
}
already_AddRefed<MediaDataDecoder>
GMPDecoderModule::CreateAudioDecoder(const CreateDecoderParams& aParams)
{
if (!aParams.mConfig.mMimeType.EqualsLiteral("audio/mp4a-latm")) {
return nullptr;
}
if (aParams.mDiagnostics) {
const Maybe<nsCString> preferredGMP = PreferredGMP(aParams.mConfig.mMimeType);
if (preferredGMP.isSome()) {
aParams.mDiagnostics->SetGMP(preferredGMP.value());
}
}
RefPtr<MediaDataDecoderProxy> wrapper = CreateDecoderWrapper(aParams.mCallback);
auto params = GMPAudioDecoderParams(aParams).WithCallback(wrapper);
wrapper->SetProxyTarget(new GMPAudioDecoder(params));
return wrapper.forget();
}
PlatformDecoderModule::ConversionRequired
GMPDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
{
// GMPVideoCodecType::kGMPVideoCodecH264 specifies that encoded frames must be in AVCC format.
if (aConfig.IsVideo() && MP4Decoder::IsH264(aConfig.mMimeType)) {
return ConversionRequired::kNeedAVCC;
} else {
return ConversionRequired::kNeedNone;
}
}
/* static */
const Maybe<nsCString>
GMPDecoderModule::PreferredGMP(const nsACString& aMimeType)
{
Maybe<nsCString> rv;
if (aMimeType.EqualsLiteral("audio/mp4a-latm")) {
switch (MediaPrefs::GMPAACPreferred()) {
case 1: rv.emplace(kEMEKeySystemClearkey); break;
case 2: rv.emplace(kEMEKeySystemPrimetime); break;
default: break;
}
}
if (MP4Decoder::IsH264(aMimeType)) {
switch (MediaPrefs::GMPH264Preferred()) {
case 1: rv.emplace(kEMEKeySystemClearkey); break;
case 2: rv.emplace(kEMEKeySystemPrimetime); break;
default: break;
}
}
return rv;
}
/* static */
bool
GMPDecoderModule::SupportsMimeType(const nsACString& aMimeType,
const Maybe<nsCString>& aGMP)
{
if (aGMP.isNothing()) {
return false;
}
if (MP4Decoder::IsH264(aMimeType)) {
return HaveGMPFor(NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
{ NS_LITERAL_CSTRING("h264"), aGMP.value()});
}
if (VPXDecoder::IsVP9(aMimeType)) {
return HaveGMPFor(NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
{ NS_LITERAL_CSTRING("vp9"), aGMP.value()});
}
if (VPXDecoder::IsVP8(aMimeType)) {
return HaveGMPFor(NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
{ NS_LITERAL_CSTRING("vp8"), aGMP.value()});
}
if (MP4Decoder::IsAAC(aMimeType)) {
return HaveGMPFor(NS_LITERAL_CSTRING(GMP_API_AUDIO_DECODER),
{ NS_LITERAL_CSTRING("aac"), aGMP.value()});
}
return false;
}
bool
GMPDecoderModule::SupportsMimeType(const nsACString& aMimeType,
DecoderDoctorDiagnostics* aDiagnostics) const
{
const Maybe<nsCString> preferredGMP = PreferredGMP(aMimeType);
bool rv = SupportsMimeType(aMimeType, preferredGMP);
if (rv && aDiagnostics && preferredGMP.isSome()) {
aDiagnostics->SetGMP(preferredGMP.value());
}
return rv;
}
} // namespace mozilla
|