|
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 "MP4Decoder.h" |
|
8 #include "MP4Reader.h" |
|
9 #include "MediaDecoderStateMachine.h" |
|
10 #include "mozilla/Preferences.h" |
|
11 |
|
12 #ifdef XP_WIN |
|
13 #include "mozilla/WindowsVersion.h" |
|
14 #endif |
|
15 #ifdef MOZ_FFMPEG |
|
16 #include "FFmpegDecoderModule.h" |
|
17 #endif |
|
18 |
|
19 namespace mozilla { |
|
20 |
|
21 MediaDecoderStateMachine* MP4Decoder::CreateStateMachine() |
|
22 { |
|
23 return new MediaDecoderStateMachine(this, new MP4Reader(this)); |
|
24 } |
|
25 |
|
26 bool |
|
27 MP4Decoder::GetSupportedCodecs(const nsACString& aType, |
|
28 char const *const ** aCodecList) |
|
29 { |
|
30 if (!IsEnabled()) { |
|
31 return false; |
|
32 } |
|
33 |
|
34 // AAC in M4A. |
|
35 static char const *const aacAudioCodecs[] = { |
|
36 "mp4a.40.2", // AAC-LC |
|
37 // TODO: AAC-HE ? |
|
38 nullptr |
|
39 }; |
|
40 if (aType.EqualsASCII("audio/mp4") || |
|
41 aType.EqualsASCII("audio/x-m4a")) { |
|
42 if (aCodecList) { |
|
43 *aCodecList = aacAudioCodecs; |
|
44 } |
|
45 return true; |
|
46 } |
|
47 |
|
48 // H.264 + AAC in MP4. |
|
49 static char const *const h264Codecs[] = { |
|
50 "avc1.42E01E", // H.264 Constrained Baseline Profile Level 3.0 |
|
51 "avc1.42001E", // H.264 Baseline Profile Level 3.0 |
|
52 "avc1.58A01E", // H.264 Extended Profile Level 3.0 |
|
53 "avc1.4D401E", // H.264 Main Profile Level 3.0 |
|
54 "avc1.64001E", // H.264 High Profile Level 3.0 |
|
55 "avc1.64001F", // H.264 High Profile Level 3.1 |
|
56 "mp4a.40.2", // AAC-LC |
|
57 // TODO: There must be more profiles here? |
|
58 nullptr |
|
59 }; |
|
60 if (aType.EqualsASCII("video/mp4")) { |
|
61 if (aCodecList) { |
|
62 *aCodecList = h264Codecs; |
|
63 } |
|
64 return true; |
|
65 } |
|
66 |
|
67 return false; |
|
68 } |
|
69 |
|
70 static bool |
|
71 IsFFmpegAvailable() |
|
72 { |
|
73 #ifndef MOZ_FFMPEG |
|
74 return false; |
|
75 #else |
|
76 if (!Preferences::GetBool("media.fragmented-mp4.ffmpeg.enabled", false)) { |
|
77 return false; |
|
78 } |
|
79 |
|
80 // If we can link to FFmpeg, then we can almost certainly play H264 and AAC |
|
81 // with it. |
|
82 return FFmpegDecoderModule::Link(); |
|
83 #endif |
|
84 } |
|
85 |
|
86 static bool |
|
87 HavePlatformMPEGDecoders() |
|
88 { |
|
89 return Preferences::GetBool("media.fragmented-mp4.use-blank-decoder") || |
|
90 #ifdef XP_WIN |
|
91 // We have H.264/AAC platform decoders on Windows Vista and up. |
|
92 IsVistaOrLater() || |
|
93 #endif |
|
94 IsFFmpegAvailable() || |
|
95 // TODO: Other platforms... |
|
96 false; |
|
97 } |
|
98 |
|
99 /* static */ |
|
100 bool |
|
101 MP4Decoder::IsEnabled() |
|
102 { |
|
103 return HavePlatformMPEGDecoders() && |
|
104 Preferences::GetBool("media.fragmented-mp4.enabled"); |
|
105 } |
|
106 |
|
107 } // namespace mozilla |
|
108 |