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
|
# Use MP3Demuxer/MediaFormatReader by default when available
diff --git a/dom/media/DecoderTraits.cpp b/dom/media/DecoderTraits.cpp
--- dom/media/DecoderTraits.cpp
+++ dom/media/DecoderTraits.cpp
@@ -200,10 +200,10 @@ DecoderTraits::IsWebMTypeAndEnabled(cons
static bool
IsGStreamerSupportedType(const nsACString& aMimeType)
{
- if (!MediaDecoder::IsGStreamerEnabled())
+ if (DecoderTraits::IsWebMTypeAndEnabled(aMimeType))
return false;
- if (DecoderTraits::IsWebMTypeAndEnabled(aMimeType) && !Preferences::GetBool("media.prefer-gstreamer", false))
+ if (!MediaDecoder::IsGStreamerEnabled())
return false;
if (IsOggType(aMimeType) && !Preferences::GetBool("media.prefer-gstreamer", false))
@@ -366,7 +366,7 @@ static bool
IsMP3SupportedType(const nsACString& aType,
const nsAString& aCodecs = EmptyString())
{
- return aType.EqualsASCII("audio/mpeg") && MP3Decoder::IsEnabled();
+ return MP3Decoder::CanHandleMediaType(aType, aCodecs);
}
#ifdef MOZ_APPLEMEDIA
diff --git a/dom/media/MP3Decoder.cpp b/dom/media/MP3Decoder.cpp
--- dom/media/MP3Decoder.cpp
+++ dom/media/MP3Decoder.cpp
@@ -10,10 +10,7 @@
#include "MediaFormatReader.h"
#include "MP3Demuxer.h"
#include "mozilla/Preferences.h"
-
-#ifdef MOZ_WIDGET_ANDROID
-#include "AndroidBridge.h"
-#endif
+#include "PlatformDecoderModule.h"
namespace mozilla {
@@ -32,14 +29,61 @@ MP3Decoder::CreateStateMachine() {
return new MediaDecoderStateMachine(this, reader);
}
+static already_AddRefed<MediaDataDecoder>
+CreateTestMP3Decoder(AudioInfo& aConfig)
+{
+ PlatformDecoderModule::Init();
+
+ nsRefPtr<PlatformDecoderModule> platform = PlatformDecoderModule::Create();
+ if (!platform || !platform->SupportsMimeType(aConfig.mMimeType)) {
+ return nullptr;
+ }
+
+ nsRefPtr<MediaDataDecoder> decoder(
+ platform->CreateDecoder(aConfig, nullptr, nullptr));
+ if (!decoder) {
+ return nullptr;
+ }
+
+ return decoder.forget();
+}
+
+static bool
+CanCreateMP3Decoder()
+{
+ static bool haveCachedResult = false;
+ static bool result = false;
+ if (haveCachedResult) {
+ return result;
+ }
+ AudioInfo config;
+ config.mMimeType = "audio/mpeg";
+ config.mRate = 48000;
+ config.mChannels = 2;
+ config.mBitDepth = 16;
+ nsRefPtr<MediaDataDecoder> decoder(CreateTestMP3Decoder(config));
+ if (decoder) {
+ result = true;
+ }
+ haveCachedResult = true;
+ return result;
+}
+
+/* static */
bool
MP3Decoder::IsEnabled() {
-#ifdef MOZ_WIDGET_ANDROID
- // We need android.media.MediaCodec which exists in API level 16 and higher.
- return AndroidBridge::Bridge()->GetAPIVersion() >= 16;
-#else
- return Preferences::GetBool("media.mp3.enabled");
-#endif
+ return CanCreateMP3Decoder();
+}
+
+/* static */
+bool MP3Decoder::CanHandleMediaType(const nsACString& aType,
+ const nsAString& aCodecs)
+{
+ if (aType.EqualsASCII("audio/mp3") || aType.EqualsASCII("audio/mpeg")) {
+ return CanCreateMP3Decoder() &&
+ (aCodecs.IsEmpty() || aCodecs.EqualsASCII("mp3"));
+ }
+ return false;
}
} // namespace mozilla
diff --git a/dom/media/MP3Decoder.h b/dom/media/MP3Decoder.h
--- dom/media/MP3Decoder.h
+++ dom/media/MP3Decoder.h
@@ -19,6 +19,8 @@ public:
// Returns true if the MP3 backend is preffed on, and we're running on a
// platform that is likely to have decoders for the format.
static bool IsEnabled();
+ static bool CanHandleMediaType(const nsACString& aType,
+ const nsAString& aCodecs);
};
} // namespace mozilla
diff --git a/dom/media/test/manifest.js b/dom/media/test/manifest.js
--- dom/media/test/manifest.js
+++ dom/media/test/manifest.js
@@ -76,7 +76,7 @@ var gPlayedTests = [
{ name:"seek.ogv", type:"video/ogg", duration:3.966 },
{ name:"seek.webm", type:"video/webm", duration:3.966 },
{ name:"gizmo.mp4", type:"video/mp4", duration:5.56 },
- { name:"owl.mp3", type:"audio/mpeg", duration:3.29 },
+ { name:"owl.mp3", type:"audio/mpeg", duration:3.343 },
// Disable vbr.mp3 to see if it reduces the error of AUDCLNT_E_CPUUSAGE_EXCEEDED.
// See bug 1110922 comment 26.
//{ name:"vbr.mp3", type:"audio/mpeg", duration:10.0 },
@@ -237,13 +237,13 @@ var gPlayTests = [
{ name:"small-shot.m4a", type:"audio/mp4", duration:0.29 },
{ name:"small-shot.mp3", type:"audio/mpeg", duration:0.27 },
- { name:"owl.mp3", type:"audio/mpeg", duration:3.29 },
+ { name:"owl.mp3", type:"audio/mpeg", duration:3.343 },
// owl.mp3 as above, but with something funny going on in the ID3v2 tag
// that causes DirectShow to fail.
- { name:"owl-funny-id3.mp3", type:"audio/mpeg", duration:3.29 },
+ { name:"owl-funny-id3.mp3", type:"audio/mpeg", duration:3.343 },
// owl.mp3 as above, but with something even funnier going on in the ID3v2 tag
// that causes DirectShow to fail.
- { name:"owl-funnier-id3.mp3", type:"audio/mpeg", duration:3.29 },
+ { name:"owl-funnier-id3.mp3", type:"audio/mpeg", duration:3.343 },
// One second of silence with ~140KB of ID3 tags. Usually when the first MP3
// frame is at such a high offset into the file, MP3FrameParser will give up
// and report that the stream is not MP3. However, it does not count ID3 tags
@@ -469,7 +469,7 @@ var gSeekTests = [
{ name:"split.webm", type:"video/webm", duration:1.967 },
{ name:"detodos.opus", type:"audio/ogg; codecs=opus", duration:2.9135 },
{ name:"gizmo.mp4", type:"video/mp4", duration:5.56 },
- { name:"owl.mp3", type:"audio/mpeg", duration:3.29 },
+ { name:"owl.mp3", type:"audio/mpeg", duration:3.343 },
{ name:"bogus.duh", type:"bogus/duh", duration:123 }
];
@@ -523,7 +523,7 @@ if (getAndroidVersion() >= 18) {
var gAudioTests = [
{ name:"r11025_s16_c1.wav", type:"audio/x-wav", duration:1.0 },
{ name:"sound.ogg", type:"audio/ogg" },
- { name:"owl.mp3", type:"audio/mpeg", duration:3.29 },
+ { name:"owl.mp3", type:"audio/mpeg", duration:3.343 },
{ name:"small-shot.m4a", type:"audio/mp4", duration:0.29 },
{ name:"bogus.duh", type:"bogus/duh", duration:123 }
];
|