Source code

Revision control

Other Tools

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 "AgnosticDecoderModule.h"
8
#include "OpusDecoder.h"
9
#include "TheoraDecoder.h"
10
#include "VPXDecoder.h"
11
#include "VorbisDecoder.h"
12
#include "WAVDecoder.h"
13
#include "mozilla/Logging.h"
14
#include "mozilla/StaticPrefs_media.h"
15
16
#ifdef MOZ_AV1
17
# include "AOMDecoder.h"
18
# include "DAV1DDecoder.h"
19
#endif
20
21
namespace mozilla {
22
23
bool AgnosticDecoderModule::SupportsMimeType(
24
const nsACString& aMimeType, DecoderDoctorDiagnostics* aDiagnostics) const {
25
bool supports =
26
VPXDecoder::IsVPX(aMimeType) || TheoraDecoder::IsTheora(aMimeType);
27
if (!StaticPrefs::media_rdd_vorbis_enabled() ||
28
!StaticPrefs::media_rdd_process_enabled() ||
29
!BrowserTabsRemoteAutostart()) {
30
supports |= VorbisDataDecoder::IsVorbis(aMimeType);
31
}
32
if (!StaticPrefs::media_rdd_wav_enabled() ||
33
!StaticPrefs::media_rdd_process_enabled() ||
34
!BrowserTabsRemoteAutostart()) {
35
supports |= WaveDataDecoder::IsWave(aMimeType);
36
}
37
if (!StaticPrefs::media_rdd_opus_enabled() ||
38
!StaticPrefs::media_rdd_process_enabled() ||
39
!BrowserTabsRemoteAutostart()) {
40
supports |= OpusDataDecoder::IsOpus(aMimeType);
41
}
42
#ifdef MOZ_AV1
43
// We remove support for decoding AV1 here if RDD is enabled so that
44
// decoding on the content process doesn't accidentally happen in case
45
// something goes wrong with launching the RDD process.
46
if (StaticPrefs::media_av1_enabled() &&
47
!StaticPrefs::media_rdd_process_enabled()) {
48
supports |= AOMDecoder::IsAV1(aMimeType);
49
}
50
#endif
51
MOZ_LOG(sPDMLog, LogLevel::Debug,
52
("Agnostic decoder %s requested type",
53
supports ? "supports" : "rejects"));
54
return supports;
55
}
56
57
already_AddRefed<MediaDataDecoder> AgnosticDecoderModule::CreateVideoDecoder(
58
const CreateDecoderParams& aParams) {
59
RefPtr<MediaDataDecoder> m;
60
61
if (VPXDecoder::IsVPX(aParams.mConfig.mMimeType)) {
62
m = new VPXDecoder(aParams);
63
}
64
#ifdef MOZ_AV1
65
// see comment above about AV1 and the RDD process
66
else if (AOMDecoder::IsAV1(aParams.mConfig.mMimeType) &&
67
!StaticPrefs::media_rdd_process_enabled() &&
68
StaticPrefs::media_av1_enabled()) {
69
if (StaticPrefs::media_av1_use_dav1d()) {
70
m = new DAV1DDecoder(aParams);
71
} else {
72
m = new AOMDecoder(aParams);
73
}
74
}
75
#endif
76
else if (TheoraDecoder::IsTheora(aParams.mConfig.mMimeType)) {
77
m = new TheoraDecoder(aParams);
78
}
79
80
return m.forget();
81
}
82
83
already_AddRefed<MediaDataDecoder> AgnosticDecoderModule::CreateAudioDecoder(
84
const CreateDecoderParams& aParams) {
85
RefPtr<MediaDataDecoder> m;
86
87
const TrackInfo& config = aParams.mConfig;
88
if (VorbisDataDecoder::IsVorbis(config.mMimeType)) {
89
m = new VorbisDataDecoder(aParams);
90
} else if (OpusDataDecoder::IsOpus(config.mMimeType)) {
91
CreateDecoderParams params(aParams);
92
// Check IsDefaultPlaybackDeviceMono here and set the option in
93
// mOptions so OpusDataDecoder doesn't have to do it later (in case
94
// it is running on RDD).
95
if (IsDefaultPlaybackDeviceMono()) {
96
params.mOptions += CreateDecoderParams::Option::DefaultPlaybackDeviceMono;
97
}
98
m = new OpusDataDecoder(params);
99
} else if (WaveDataDecoder::IsWave(config.mMimeType)) {
100
m = new WaveDataDecoder(aParams);
101
}
102
103
return m.forget();
104
}
105
106
} // namespace mozilla