Chromium Code Reviews| 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" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 // mp4a.40.2 - MPEG-4 AAC LC | 208 // mp4a.40.2 - MPEG-4 AAC LC |
| 209 // mp4a.40.02 - MPEG-4 AAC LC (leading 0 in aud-oti for compatibility) | 209 // mp4a.40.02 - MPEG-4 AAC LC (leading 0 in aud-oti for compatibility) |
| 210 // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR) | 210 // mp4a.40.5 - MPEG-4 HE-AAC v1 (AAC LC + SBR) |
| 211 // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for | 211 // mp4a.40.05 - MPEG-4 HE-AAC v1 (AAC LC + SBR) (leading 0 in aud-oti for |
| 212 // compatibility) | 212 // compatibility) |
| 213 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) | 213 // mp4a.40.29 - MPEG-4 HE-AAC v2 (AAC LC + SBR + PS) |
| 214 // | 214 // |
| 215 // avc1.42E0xx - H.264 Baseline | 215 // avc1.42E0xx - H.264 Baseline |
| 216 // avc1.4D40xx - H.264 Main | 216 // avc1.4D40xx - H.264 Main |
| 217 // avc1.6400xx - H.264 High | 217 // avc1.6400xx - H.264 High |
| 218 // vp08.... - VP8 | |
|
ddorwin
2016/01/27 01:39:15
We should have playback tests (both clear and encr
ddorwin
2016/01/27 03:17:09
Specifically, playback tests for src=, MSE, and MS
kqyang
2016/01/29 00:34:17
Added tests and test files. Let me know if you'd l
| |
| 219 // vp09.... - VP9 | |
|
ddorwin
2016/01/27 03:17:09
Do we want to turn this on by default before the s
kqyang
2016/01/29 00:34:17
Sure, added flag ENABLE_MP4_VP8_VP9_DEMUXING, off
| |
| 218 static const char kMP4AudioCodecsExpression[] = | 220 static const char kMP4AudioCodecsExpression[] = |
| 219 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 221 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
| 220 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 222 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
| 221 // Only one variant each of ac3 and eac3 codec string is sufficient here, | 223 // Only one variant each of ac3 and eac3 codec string is sufficient here, |
| 222 // since these strings are parsed and mapped to MimeUtil::Codec enum values. | 224 // since these strings are parsed and mapped to MimeUtil::Codec enum values. |
| 223 "ac-3,ec-3," | 225 "ac-3,ec-3," |
| 224 #endif | 226 #endif |
| 225 "mp4a.40.05,mp4a.40.29"; | 227 "mp4a.40.05,mp4a.40.29"; |
| 226 static const char kMP4VideoCodecsExpression[] = | 228 static const char kMP4VideoCodecsExpression[] = |
| 227 // This is not a complete list of supported avc1 codecs. It is simply used | 229 // This is not a complete list of supported avc1 codecs. It is simply used |
| 228 // to register support for the corresponding Codec enum. Instead of using | 230 // to register support for the corresponding Codec enum. Instead of using |
| 229 // strings in these three arrays, we should use the Codec enum values. | 231 // strings in these three arrays, we should use the Codec enum values. |
| 230 // This will avoid confusion and unnecessary parsing at runtime. | 232 // This will avoid confusion and unnecessary parsing at runtime. |
| 231 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only | 233 // kUnambiguousCodecStringMap/kAmbiguousCodecStringMap should be the only |
| 232 // mapping from strings to codecs. See crbug.com/461009. | 234 // mapping from strings to codecs. See crbug.com/461009. |
| 233 "avc1.42E00A,avc1.4D400A,avc1.64000A," | 235 "avc1.42E00A,avc1.4D400A,avc1.64000A," |
| 234 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 236 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 235 // Any valid unambiguous HEVC codec id will work here, since these strings | 237 // Any valid unambiguous HEVC codec id will work here, since these strings |
| 236 // are parsed and mapped to MimeUtil::Codec enum values. | 238 // are parsed and mapped to MimeUtil::Codec enum values. |
| 237 "hev1.1.6.L93.B0," | 239 "hev1.1.6.L93.B0," |
| 238 #endif | 240 #endif |
| 241 // This is not a complete list of supported vpx codecs. | |
|
ddorwin
2016/01/27 01:39:15
Does the same comment as for avc1 apply? Perhaps r
kqyang
2016/01/29 00:34:17
Done.
| |
| 242 "vp08.00.00.08.01.01.00.00,vp09.00.00.08.00.01.00.00," | |
| 239 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," | 243 "mp4a.66,mp4a.67,mp4a.68,mp4a.69,mp4a.6B,mp4a.40.2,mp4a.40.02,mp4a.40.5," |
| 240 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) | 244 #if BUILDFLAG(ENABLE_AC3_EAC3_AUDIO_DEMUXING) |
|
ddorwin
2016/01/27 01:39:15
It's unfortunate how this was inserted in the mp4a
kqyang
2016/01/29 00:34:17
Since it is just reordering, I'll fix it in this c
| |
| 241 // Only one variant each of ac3 and eac3 codec string is sufficient here, | 245 // Only one variant each of ac3 and eac3 codec string is sufficient here, |
| 242 // since these strings are parsed and mapped to MimeUtil::Codec enum values. | 246 // since these strings are parsed and mapped to MimeUtil::Codec enum values. |
| 243 "ac-3,ec-3," | 247 "ac-3,ec-3," |
| 244 #endif | 248 #endif |
| 245 "mp4a.40.05,mp4a.40.29"; | 249 "mp4a.40.05,mp4a.40.29"; |
| 246 #endif // USE_PROPRIETARY_CODECS | 250 #endif // USE_PROPRIETARY_CODECS |
| 247 | 251 |
| 248 // A list of media types (https://en.wikipedia.org/wiki/Media_type) and | 252 // A list of media types (https://en.wikipedia.org/wiki/Media_type) and |
| 249 // corresponding media codecs supported by these types/containers. | 253 // corresponding media codecs supported by these types/containers. |
| 250 // Media formats marked as PROPRIETARY are not supported by Chromium, only | 254 // Media formats marked as PROPRIETARY are not supported by Chromium, only |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 }; | 294 }; |
| 291 | 295 |
| 292 // List of codec IDs that provide enough information to determine the | 296 // List of codec IDs that provide enough information to determine the |
| 293 // codec and profile being requested. | 297 // codec and profile being requested. |
| 294 // | 298 // |
| 295 // The "mp4a" strings come from RFC 6381. | 299 // The "mp4a" strings come from RFC 6381. |
| 296 static const CodecIDMappings kUnambiguousCodecStringMap[] = { | 300 static const CodecIDMappings kUnambiguousCodecStringMap[] = { |
| 297 {"1", MimeUtil::PCM}, // We only allow this for WAV so it isn't ambiguous. | 301 {"1", MimeUtil::PCM}, // We only allow this for WAV so it isn't ambiguous. |
| 298 // avc1/avc3.XXXXXX may be unambiguous; handled by ParseH264CodecID(). | 302 // avc1/avc3.XXXXXX may be unambiguous; handled by ParseH264CodecID(). |
| 299 // hev1/hvc1.XXXXXX may be unambiguous; handled by ParseHEVCCodecID(). | 303 // hev1/hvc1.XXXXXX may be unambiguous; handled by ParseHEVCCodecID(). |
| 304 // vp08/vp09.xx.xx.xx.xx.xx.xx.xx may be unambiguous; handled by | |
| 305 // ParseVpxCodecID(). | |
| 300 {"mp3", MimeUtil::MP3}, | 306 {"mp3", MimeUtil::MP3}, |
| 301 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, | 307 {"mp4a.66", MimeUtil::MPEG2_AAC_MAIN}, |
| 302 {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, | 308 {"mp4a.67", MimeUtil::MPEG2_AAC_LC}, |
| 303 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, | 309 {"mp4a.68", MimeUtil::MPEG2_AAC_SSR}, |
| 304 {"mp4a.69", MimeUtil::MP3}, | 310 {"mp4a.69", MimeUtil::MP3}, |
| 305 {"mp4a.6B", MimeUtil::MP3}, | 311 {"mp4a.6B", MimeUtil::MP3}, |
| 306 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, | 312 {"mp4a.40.2", MimeUtil::MPEG4_AAC_LC}, |
| 307 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, | 313 {"mp4a.40.02", MimeUtil::MPEG4_AAC_LC}, |
| 308 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, | 314 {"mp4a.40.5", MimeUtil::MPEG4_AAC_SBR_v1}, |
| 309 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, | 315 {"mp4a.40.05", MimeUtil::MPEG4_AAC_SBR_v1}, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 332 | 338 |
| 333 // List of codec IDs that are ambiguous and don't provide | 339 // List of codec IDs that are ambiguous and don't provide |
| 334 // enough information to determine the codec and profile. | 340 // enough information to determine the codec and profile. |
| 335 // The codec in these entries indicate the codec and profile | 341 // The codec in these entries indicate the codec and profile |
| 336 // we assume the user is trying to indicate. | 342 // we assume the user is trying to indicate. |
| 337 static const CodecIDMappings kAmbiguousCodecStringMap[] = { | 343 static const CodecIDMappings kAmbiguousCodecStringMap[] = { |
| 338 {"mp4a.40", MimeUtil::MPEG4_AAC_LC}, | 344 {"mp4a.40", MimeUtil::MPEG4_AAC_LC}, |
| 339 {"avc1", MimeUtil::H264_BASELINE}, | 345 {"avc1", MimeUtil::H264_BASELINE}, |
| 340 {"avc3", MimeUtil::H264_BASELINE}, | 346 {"avc3", MimeUtil::H264_BASELINE}, |
| 341 // avc1/avc3.XXXXXX may be ambiguous; handled by ParseH264CodecID(). | 347 // avc1/avc3.XXXXXX may be ambiguous; handled by ParseH264CodecID(). |
| 348 {"vp08", MimeUtil::VP8}, | |
| 349 {"vp09", MimeUtil::VP9}, | |
| 350 // vp08/vp09.xx.xx.xx.xx.xx.xx.xx may be ambiguous; handled by | |
| 351 // ParseVpxCodecID(). | |
| 342 }; | 352 }; |
| 343 | 353 |
| 344 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) | 354 #if BUILDFLAG(ENABLE_MSE_MPEG2TS_STREAM_PARSER) |
| 345 static const char kHexString[] = "0123456789ABCDEF"; | 355 static const char kHexString[] = "0123456789ABCDEF"; |
| 346 static char IntToHex(int i) { | 356 static char IntToHex(int i) { |
| 347 DCHECK_GE(i, 0) << i << " not a hex value"; | 357 DCHECK_GE(i, 0) << i << " not a hex value"; |
| 348 DCHECK_LE(i, 15) << i << " not a hex value"; | 358 DCHECK_LE(i, 15) << i << " not a hex value"; |
| 349 return kHexString[i]; | 359 return kHexString[i]; |
| 350 } | 360 } |
| 351 | 361 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 626 *is_ambiguous = false; | 636 *is_ambiguous = false; |
| 627 } | 637 } |
| 628 | 638 |
| 629 return true; | 639 return true; |
| 630 } | 640 } |
| 631 | 641 |
| 632 return false; | 642 return false; |
| 633 } | 643 } |
| 634 #endif | 644 #endif |
| 635 | 645 |
| 646 // Handle parsing of vpx codec IDs. | |
| 647 static bool ParseVpxCodecID(const std::string& codec_id, | |
| 648 MimeUtil::Codec* codec, | |
| 649 bool* is_ambiguous) { | |
| 650 std::vector<std::string> fields = base::SplitString( | |
| 651 codec_id, ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | |
| 652 DCHECK_GE(fields.size(), 1u); | |
| 653 if (fields[0] == "vp08") { | |
| 654 *codec = MimeUtil::VP8; | |
| 655 } else if (fields[0] == "vp09") { | |
| 656 *codec = MimeUtil::VP9; | |
| 657 } else { | |
| 658 return false; | |
| 659 } | |
| 660 | |
| 661 if (fields.size() > 8) | |
| 662 return false; | |
| 663 | |
| 664 std::vector<int> values; | |
| 665 for (size_t i = 1; i < fields.size(); ++i) { | |
| 666 // Missing value is ambiguous. | |
| 667 if (fields[i] == "") { | |
| 668 *is_ambiguous = true; | |
| 669 return true; | |
| 670 } | |
| 671 int value; | |
| 672 if (!base::StringToInt(fields[i], &value)) | |
| 673 return false; | |
| 674 if (value < 0) | |
| 675 return false; | |
| 676 values.push_back(value); | |
| 677 } | |
| 678 | |
| 679 *is_ambiguous = true; | |
| 680 // The spec specifies 8 fields (7 values excluding the first codec field). | |
| 681 // It is ambiguous with missing fields. | |
|
ddorwin
2016/01/27 01:39:15
Do we want to support this? Having supported just
kqyang
2016/01/29 00:34:17
I am not sure whether that is a good idea as the s
| |
| 682 if (values.size() < 7) | |
| 683 return true; | |
| 684 | |
| 685 const int profile = values[0]; | |
| 686 if (profile > 3) | |
| 687 return true; | |
| 688 | |
| 689 const int bit_depth = values[2]; | |
| 690 if (bit_depth != 8 && bit_depth != 10 && bit_depth != 12) | |
| 691 return true; | |
| 692 | |
| 693 const int color_space = values[3]; | |
| 694 if (color_space > 7) | |
| 695 return true; | |
| 696 | |
| 697 const int chroma_subsampling = values[4]; | |
| 698 if (chroma_subsampling > 3) | |
| 699 return true; | |
| 700 | |
| 701 const int transfer_function = values[5]; | |
| 702 if (transfer_function > 1) | |
| 703 return true; | |
| 704 | |
| 705 const int video_full_range_flag = values[6]; | |
| 706 if (video_full_range_flag > 1) | |
| 707 return true; | |
| 708 | |
| 709 *is_ambiguous = false; | |
| 710 return true; | |
| 711 } | |
| 712 | |
| 636 bool MimeUtil::StringToCodec(const std::string& codec_id, | 713 bool MimeUtil::StringToCodec(const std::string& codec_id, |
| 637 Codec* codec, | 714 Codec* codec, |
| 638 bool* is_ambiguous) const { | 715 bool* is_ambiguous) const { |
| 639 StringToCodecMappings::const_iterator itr = | 716 StringToCodecMappings::const_iterator itr = |
| 640 string_to_codec_map_.find(codec_id); | 717 string_to_codec_map_.find(codec_id); |
| 641 if (itr != string_to_codec_map_.end()) { | 718 if (itr != string_to_codec_map_.end()) { |
| 642 *codec = itr->second.codec; | 719 *codec = itr->second.codec; |
| 643 *is_ambiguous = itr->second.is_ambiguous; | 720 *is_ambiguous = itr->second.is_ambiguous; |
| 644 return true; | 721 return true; |
| 645 } | 722 } |
| 646 | 723 |
| 647 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is | 724 // If |codec_id| is not in |string_to_codec_map_|, then we assume that it is |
| 648 // either H.264 or HEVC/H.265 codec ID because currently those are the only | 725 // either VPx, H.264 or HEVC/H.265 codec ID because currently those are the |
| 649 // ones that are not added to the |string_to_codec_map_| and require parsing. | 726 // only ones that are not added to the |string_to_codec_map_| and require |
| 727 // parsing. | |
| 650 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 728 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
| 651 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { | 729 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { |
| 652 return true; | 730 return true; |
| 653 } | 731 } |
| 654 #endif | 732 #endif |
| 655 return ParseH264CodecID(codec_id, codec, is_ambiguous); | 733 if (ParseH264CodecID(codec_id, codec, is_ambiguous)) { |
| 734 return true; | |
| 735 } | |
| 736 if (ParseVpxCodecID(codec_id, codec, is_ambiguous)) { | |
| 737 return true; | |
| 738 } | |
| 739 return false; | |
| 656 } | 740 } |
| 657 | 741 |
| 658 bool MimeUtil::IsCodecSupported(Codec codec) const { | 742 bool MimeUtil::IsCodecSupported(Codec codec) const { |
| 659 DCHECK_NE(codec, INVALID_CODEC); | 743 DCHECK_NE(codec, INVALID_CODEC); |
| 660 | 744 |
| 661 #if defined(OS_ANDROID) | 745 #if defined(OS_ANDROID) |
| 662 if (!IsCodecSupportedOnAndroid(codec)) | 746 if (!IsCodecSupportedOnAndroid(codec)) |
| 663 return false; | 747 return false; |
| 664 #endif | 748 #endif |
| 665 | 749 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 std::vector<std::string>* codecs_out, | 818 std::vector<std::string>* codecs_out, |
| 735 const bool strip) { | 819 const bool strip) { |
| 736 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); | 820 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); |
| 737 } | 821 } |
| 738 | 822 |
| 739 void RemoveProprietaryMediaTypesAndCodecsForTests() { | 823 void RemoveProprietaryMediaTypesAndCodecsForTests() { |
| 740 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | 824 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); |
| 741 } | 825 } |
| 742 | 826 |
| 743 } // namespace media | 827 } // namespace media |
| OLD | NEW |