OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "media/base/media.h" | |
17 #include "media/base/mime_util.h" | 18 #include "media/base/mime_util.h" |
18 #include "media/media_features.h" | 19 #include "media/media_features.h" |
19 | 20 |
20 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
21 #include "base/android/build_info.h" | 22 #include "base/android/build_info.h" |
22 #endif | 23 #endif |
23 | 24 |
24 namespace media { | 25 namespace media { |
25 | 26 |
26 // Singleton utility class for mime types. | 27 // Singleton utility class for mime types. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 145 |
145 case MimeUtil::PCM: | 146 case MimeUtil::PCM: |
146 case MimeUtil::MP3: | 147 case MimeUtil::MP3: |
147 case MimeUtil::MPEG4_AAC_LC: | 148 case MimeUtil::MPEG4_AAC_LC: |
148 case MimeUtil::MPEG4_AAC_SBR_v1: | 149 case MimeUtil::MPEG4_AAC_SBR_v1: |
149 case MimeUtil::MPEG4_AAC_SBR_PS_v2: | 150 case MimeUtil::MPEG4_AAC_SBR_PS_v2: |
150 case MimeUtil::VORBIS: | 151 case MimeUtil::VORBIS: |
151 case MimeUtil::H264_BASELINE: | 152 case MimeUtil::H264_BASELINE: |
152 case MimeUtil::H264_MAIN: | 153 case MimeUtil::H264_MAIN: |
153 case MimeUtil::H264_HIGH: | 154 case MimeUtil::H264_HIGH: |
154 case MimeUtil::VP8: | 155 case MimeUtil::VP8: |
ddorwin
2016/02/12 18:45:12
There is also the codec-specific blacklist (https:
DaleCurtis
2016/02/13 02:01:43
Fixed. For now I've just added an IsVp8Blacklisted
| |
155 return true; | 156 return true; |
156 | 157 |
157 case MimeUtil::AC3: | 158 case MimeUtil::AC3: |
158 case MimeUtil::EAC3: | 159 case MimeUtil::EAC3: |
159 // TODO(servolk): Revisit this for AC3/EAC3 support on AndroidTV | 160 // TODO(servolk): Revisit this for AC3/EAC3 support on AndroidTV |
160 return false; | 161 return false; |
161 | 162 |
162 case MimeUtil::MPEG2_AAC_LC: | 163 case MimeUtil::MPEG2_AAC_LC: |
163 case MimeUtil::MPEG2_AAC_MAIN: | 164 case MimeUtil::MPEG2_AAC_MAIN: |
164 case MimeUtil::MPEG2_AAC_SSR: | 165 case MimeUtil::MPEG2_AAC_SSR: |
165 // MPEG-2 variants of AAC are not supported on Android. | 166 // MPEG-2 variants of AAC are not supported on Android. |
166 return false; | 167 return IsUnifiedMediaPipelineEnabled(); |
ddorwin
2016/02/12 18:45:12
As mentioned previously, we need to know that it c
DaleCurtis
2016/02/13 02:01:43
We'll either be using MediaPlayer or the unified m
| |
167 | 168 |
168 case MimeUtil::OPUS: | 169 case MimeUtil::OPUS: |
169 // Opus is supported only in Lollipop+ (API Level 21). | 170 // Opus is supported only in Lollipop+ (API Level 21). |
170 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | 171 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21 || |
172 IsUnifiedMediaPipelineEnabled(); | |
171 | 173 |
172 case MimeUtil::HEVC_MAIN: | 174 case MimeUtil::HEVC_MAIN: |
173 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 175 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
174 // HEVC/H.265 is supported in Lollipop+ (API Level 21), according to | 176 // HEVC/H.265 is supported in Lollipop+ (API Level 21), according to |
175 // http://developer.android.com/reference/android/media/MediaFormat.html | 177 // http://developer.android.com/reference/android/media/MediaFormat.html |
176 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; | 178 return base::android::BuildInfo::GetInstance()->sdk_int() >= 21; |
177 #else | 179 #else |
178 return false; | 180 return false; |
179 #endif | 181 #endif |
180 | 182 |
181 case MimeUtil::VP9: | 183 case MimeUtil::VP9: |
182 // VP9 is supported only in KitKat+ (API Level 19). | 184 // VP9 is supported only in KitKat+ (API Level 19). |
183 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19; | 185 return base::android::BuildInfo::GetInstance()->sdk_int() >= 19 || |
186 IsUnifiedMediaPipelineEnabled(); | |
ddorwin
2016/02/12 18:45:12
This one may not be affected by the blacklist (bas
DaleCurtis
2016/02/13 02:01:43
The blacklist doesn't matter here (currently), so
| |
184 | 187 |
185 case MimeUtil::THEORA: | 188 case MimeUtil::THEORA: |
186 return false; | 189 return false; |
187 } | 190 } |
188 | 191 |
189 return false; | 192 return false; |
190 } | 193 } |
194 | |
195 static bool IsMimeTypeAndCodecSupportedOnAndroid(const std::string& mime_type, | |
196 MimeUtil::Codec codec) { | |
197 // Opus in ogg is not allowed on Android unless the unified media pipeline is | |
198 // available. | |
199 if (base::EndsWith(mime_type, "ogg", base::CompareCase::INSENSITIVE_ASCII) && | |
ddorwin
2016/02/12 18:45:12
Minor: Since this comes from our code, the check c
DaleCurtis
2016/02/13 02:01:43
Done.
| |
200 codec == MimeUtil::OPUS) { | |
201 return IsUnifiedMediaPipelineEnabled(); | |
ddorwin
2016/02/12 18:45:12
Ditto on the blacklist.
(As long as we support WM
DaleCurtis
2016/02/13 02:01:43
Blacklist doesn't matter here since either the pip
| |
202 } | |
203 | |
204 return true; | |
ddorwin
2016/02/12 18:45:12
As mentioned below, we might want to call IsCodecS
DaleCurtis
2016/02/13 02:01:43
Done.
| |
205 } | |
206 | |
191 #endif | 207 #endif |
192 | 208 |
193 enum MediaFormatType { COMMON, PROPRIETARY }; | 209 enum MediaFormatType { COMMON, PROPRIETARY }; |
194 | 210 |
195 struct MediaFormat { | 211 struct MediaFormat { |
196 const char* const mime_type; | 212 const char* const mime_type; |
197 MediaFormatType format_type; | 213 MediaFormatType format_type; |
198 const char* const codecs_list; | 214 const char* const codecs_list; |
199 }; | 215 }; |
200 | 216 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 | 263 |
248 // A list of media types (https://en.wikipedia.org/wiki/Media_type) and | 264 // A list of media types (https://en.wikipedia.org/wiki/Media_type) and |
249 // corresponding media codecs supported by these types/containers. | 265 // corresponding media codecs supported by these types/containers. |
250 // Media formats marked as PROPRIETARY are not supported by Chromium, only | 266 // Media formats marked as PROPRIETARY are not supported by Chromium, only |
251 // Google Chrome browser supports them. | 267 // Google Chrome browser supports them. |
252 static const MediaFormat kFormatCodecMappings[] = { | 268 static const MediaFormat kFormatCodecMappings[] = { |
253 {"video/webm", COMMON, "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, | 269 {"video/webm", COMMON, "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, |
254 {"audio/webm", COMMON, "opus,vorbis"}, | 270 {"audio/webm", COMMON, "opus,vorbis"}, |
255 {"audio/wav", COMMON, "1"}, | 271 {"audio/wav", COMMON, "1"}, |
256 {"audio/x-wav", COMMON, "1"}, | 272 {"audio/x-wav", COMMON, "1"}, |
257 #if defined(OS_ANDROID) | 273 #if !defined(OS_ANDROID) |
ddorwin
2016/02/12 18:45:12
Should we retain this comment?
// Android does not
DaleCurtis
2016/02/13 02:01:43
Done.
| |
258 // Android does not support Opus in Ogg container. | |
259 // Android does not support Theora and thus video/ogg. | |
260 {"audio/ogg", COMMON, "vorbis"}, | |
261 {"application/ogg", COMMON, "vorbis"}, | |
262 #else | |
263 {"video/ogg", COMMON, "opus,theora,vorbis"}, | 274 {"video/ogg", COMMON, "opus,theora,vorbis"}, |
275 #endif | |
264 {"audio/ogg", COMMON, "opus,vorbis"}, | 276 {"audio/ogg", COMMON, "opus,vorbis"}, |
277 // Note: Theora is not supported on Android and will be rejected during the | |
278 // call to IsCodecSupportedOnAndroid(). | |
265 {"application/ogg", COMMON, "opus,theora,vorbis"}, | 279 {"application/ogg", COMMON, "opus,theora,vorbis"}, |
266 #endif | |
267 #if defined(USE_PROPRIETARY_CODECS) | 280 #if defined(USE_PROPRIETARY_CODECS) |
268 {"audio/mpeg", PROPRIETARY, "mp3"}, | 281 {"audio/mpeg", PROPRIETARY, "mp3"}, |
269 {"audio/mp3", PROPRIETARY, ""}, | 282 {"audio/mp3", PROPRIETARY, ""}, |
270 {"audio/x-mp3", PROPRIETARY, ""}, | 283 {"audio/x-mp3", PROPRIETARY, ""}, |
271 {"audio/aac", PROPRIETARY, ""}, // AAC / ADTS | 284 {"audio/aac", PROPRIETARY, ""}, // AAC / ADTS |
272 {"audio/mp4", PROPRIETARY, kMP4AudioCodecsExpression}, | 285 {"audio/mp4", PROPRIETARY, kMP4AudioCodecsExpression}, |
273 {"audio/x-m4a", PROPRIETARY, kMP4AudioCodecsExpression}, | 286 {"audio/x-m4a", PROPRIETARY, kMP4AudioCodecsExpression}, |
274 {"video/mp4", PROPRIETARY, kMP4VideoCodecsExpression}, | 287 {"video/mp4", PROPRIETARY, kMP4VideoCodecsExpression}, |
275 {"video/x-m4v", PROPRIETARY, kMP4VideoCodecsExpression}, | 288 {"video/x-m4v", PROPRIETARY, kMP4VideoCodecsExpression}, |
276 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) | 289 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 std::vector<std::string> mime_type_codecs; | 453 std::vector<std::string> mime_type_codecs; |
441 ParseCodecString(kFormatCodecMappings[i].codecs_list, &mime_type_codecs, | 454 ParseCodecString(kFormatCodecMappings[i].codecs_list, &mime_type_codecs, |
442 false); | 455 false); |
443 | 456 |
444 CodecSet codecs; | 457 CodecSet codecs; |
445 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { | 458 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { |
446 Codec codec = INVALID_CODEC; | 459 Codec codec = INVALID_CODEC; |
447 bool is_ambiguous = true; | 460 bool is_ambiguous = true; |
448 CHECK(StringToCodec(mime_type_codecs[j], &codec, &is_ambiguous)); | 461 CHECK(StringToCodec(mime_type_codecs[j], &codec, &is_ambiguous)); |
449 DCHECK(!is_ambiguous); | 462 DCHECK(!is_ambiguous); |
463 | |
464 #if defined(OS_ANDROID) | |
465 // Android has container retrictions on codecs which may vary at runtime, | |
466 // filter out container and codec combinations which are disallowed. | |
467 if (!IsMimeTypeAndCodecSupportedOnAndroid( | |
468 kFormatCodecMappings[i].mime_type, codec)) { | |
469 continue; | |
470 } | |
471 #endif | |
472 | |
450 codecs.insert(codec); | 473 codecs.insert(codec); |
451 } | 474 } |
452 | 475 |
453 media_format_map_[kFormatCodecMappings[i].mime_type] = codecs; | 476 media_format_map_[kFormatCodecMappings[i].mime_type] = codecs; |
454 } | 477 } |
455 } | 478 } |
456 | 479 |
457 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 480 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { |
458 return media_format_map_.find(base::ToLowerASCII(mime_type)) != | 481 return media_format_map_.find(base::ToLowerASCII(mime_type)) != |
459 media_format_map_.end(); | 482 media_format_map_.end(); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 return true; | 675 return true; |
653 } | 676 } |
654 #endif | 677 #endif |
655 return ParseH264CodecID(codec_id, codec, is_ambiguous); | 678 return ParseH264CodecID(codec_id, codec, is_ambiguous); |
656 } | 679 } |
657 | 680 |
658 bool MimeUtil::IsCodecSupported(Codec codec) const { | 681 bool MimeUtil::IsCodecSupported(Codec codec) const { |
659 DCHECK_NE(codec, INVALID_CODEC); | 682 DCHECK_NE(codec, INVALID_CODEC); |
660 | 683 |
661 #if defined(OS_ANDROID) | 684 #if defined(OS_ANDROID) |
662 if (!IsCodecSupportedOnAndroid(codec)) | 685 if (!IsCodecSupportedOnAndroid(codec)) |
ddorwin
2016/02/12 18:45:12
We check unsupported codecs for each call but cont
DaleCurtis
2016/02/13 02:01:43
Done.
| |
663 return false; | 686 return false; |
664 #endif | 687 #endif |
665 | 688 |
666 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); | 689 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); |
667 } | 690 } |
668 | 691 |
669 bool MimeUtil::IsCodecProprietary(Codec codec) const { | 692 bool MimeUtil::IsCodecProprietary(Codec codec) const { |
670 switch (codec) { | 693 switch (codec) { |
671 case INVALID_CODEC: | 694 case INVALID_CODEC: |
672 case AC3: | 695 case AC3: |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
734 std::vector<std::string>* codecs_out, | 757 std::vector<std::string>* codecs_out, |
735 const bool strip) { | 758 const bool strip) { |
736 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); | 759 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); |
737 } | 760 } |
738 | 761 |
739 void RemoveProprietaryMediaTypesAndCodecsForTests() { | 762 void RemoveProprietaryMediaTypesAndCodecsForTests() { |
740 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | 763 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); |
741 } | 764 } |
742 | 765 |
743 } // namespace media | 766 } // namespace media |
OLD | NEW |