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 "media/base/mime_util_internal.h" | 5 #include "media/base/mime_util_internal.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 | 401 |
402 // Strip everything past the first '.' | 402 // Strip everything past the first '.' |
403 for (std::vector<std::string>::iterator it = codecs_out->begin(); | 403 for (std::vector<std::string>::iterator it = codecs_out->begin(); |
404 it != codecs_out->end(); ++it) { | 404 it != codecs_out->end(); ++it) { |
405 size_t found = it->find_first_of('.'); | 405 size_t found = it->find_first_of('.'); |
406 if (found != std::string::npos) | 406 if (found != std::string::npos) |
407 it->resize(found); | 407 it->resize(found); |
408 } | 408 } |
409 } | 409 } |
410 | 410 |
411 bool MimeUtil::ParseVideoCodecString(const std::string& mime_type, | |
412 const std::string& codec_id, | |
413 bool* out_is_ambiguous, | |
414 VideoCodec* out_codec, | |
415 VideoCodecProfile* out_profile, | |
416 uint8_t* out_level, | |
417 VideoColorSpace* out_colorspace) { | |
418 DCHECK(out_is_ambiguous); | |
419 DCHECK(out_codec); | |
420 DCHECK(out_profile); | |
421 DCHECK(out_level); | |
422 DCHECK(out_colorspace); | |
423 | |
424 Codec mime_internal_codec; | |
425 bool parsed_ok = ParseCodecString(base::ToLowerASCII(mime_type), codec_id, | |
426 &mime_internal_codec, out_is_ambiguous, | |
427 out_profile, out_level, out_colorspace); | |
428 if (!parsed_ok) | |
429 return false; | |
430 | |
431 *out_codec = MimeUtilToVideoCodec(mime_internal_codec); | |
432 if (*out_codec == kUnknownVideoCodec) | |
433 return false; | |
434 | |
435 return true; | |
436 } | |
437 | |
438 bool MimeUtil::ParseAudioCodecString(const std::string& mime_type, | |
439 const std::string& codec_id, | |
440 bool* out_is_ambiguous, | |
441 AudioCodec* out_codec) { | |
442 DCHECK(out_is_ambiguous); | |
443 DCHECK(out_codec); | |
444 | |
445 Codec mime_internal_codec; | |
446 | |
447 // Some audio containers unambiguously imply a codec. | |
448 if (codec_id.empty()) { | |
449 if (!GetDefaultCodec(mime_type, &mime_internal_codec)) | |
450 return false; | |
451 | |
452 *out_is_ambiguous = false; | |
453 } else { | |
454 // Not part of audio parsing, but its possible users will mistakenly put | |
tguilbert
2017/05/08 23:19:57
Pure curiosity and not a CL comment: why do we han
| |
455 // video codecs in the audio config string, causing the common parsing algo | |
456 // to set these output values. Passing non-null values avoids issues. | |
457 VideoCodecProfile out_profile = VIDEO_CODEC_PROFILE_UNKNOWN; | |
458 uint8_t out_level = 0; | |
459 VideoColorSpace out_colorspace; | |
460 | |
461 if (!ParseCodecString(base::ToLowerASCII(mime_type), codec_id, | |
462 &mime_internal_codec, out_is_ambiguous, &out_profile, | |
463 &out_level, &out_colorspace)) { | |
464 return false; | |
465 } | |
466 } | |
467 | |
468 *out_codec = MimeUtilToAudioCodec(mime_internal_codec); | |
469 if (*out_codec == kUnknownAudioCodec) | |
470 return false; | |
471 | |
472 return true; | |
473 } | |
474 | |
411 SupportsType MimeUtil::IsSupportedMediaFormat( | 475 SupportsType MimeUtil::IsSupportedMediaFormat( |
412 const std::string& mime_type, | 476 const std::string& mime_type, |
413 const std::vector<std::string>& codecs, | 477 const std::vector<std::string>& codecs, |
414 bool is_encrypted) const { | 478 bool is_encrypted) const { |
415 const std::string mime_type_lower_case = base::ToLowerASCII(mime_type); | 479 const std::string mime_type_lower_case = base::ToLowerASCII(mime_type); |
416 MediaFormatMappings::const_iterator it_media_format_map = | 480 MediaFormatMappings::const_iterator it_media_format_map = |
417 media_format_map_.find(mime_type_lower_case); | 481 media_format_map_.find(mime_type_lower_case); |
418 if (it_media_format_map == media_format_map_.end()) { | 482 if (it_media_format_map == media_format_map_.end()) { |
419 DVLOG(3) << __func__ << " Unrecognized mime type: " << mime_type; | 483 DVLOG(3) << __func__ << " Unrecognized mime type: " << mime_type; |
420 return IsNotSupported; | 484 return IsNotSupported; |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
807 case VP9: | 871 case VP9: |
808 case THEORA: | 872 case THEORA: |
809 return false; | 873 return false; |
810 } | 874 } |
811 | 875 |
812 return true; | 876 return true; |
813 } | 877 } |
814 | 878 |
815 bool MimeUtil::GetDefaultCodec(const std::string& mime_type, | 879 bool MimeUtil::GetDefaultCodec(const std::string& mime_type, |
816 Codec* default_codec) const { | 880 Codec* default_codec) const { |
881 // Codecs below are unambiguously implied by the mime type string. DO NOT add | |
882 // default codecs for ambiguous mime types. | |
883 | |
817 if (mime_type == "audio/mpeg" || mime_type == "audio/mp3" || | 884 if (mime_type == "audio/mpeg" || mime_type == "audio/mp3" || |
818 mime_type == "audio/x-mp3") { | 885 mime_type == "audio/x-mp3") { |
819 *default_codec = MimeUtil::MP3; | 886 *default_codec = MimeUtil::MP3; |
820 return true; | 887 return true; |
821 } | 888 } |
822 | 889 |
823 if (mime_type == "audio/aac") { | 890 if (mime_type == "audio/aac") { |
824 *default_codec = MimeUtil::MPEG4_AAC; | 891 *default_codec = MimeUtil::MPEG4_AAC; |
825 return true; | 892 return true; |
826 } | 893 } |
827 | 894 |
828 if (mime_type == "audio/flac") { | 895 if (mime_type == "audio/flac") { |
829 *default_codec = MimeUtil::FLAC; | 896 *default_codec = MimeUtil::FLAC; |
830 return true; | 897 return true; |
831 } | 898 } |
832 | 899 |
833 return false; | 900 return false; |
834 } | 901 } |
835 | 902 |
836 SupportsType MimeUtil::IsDefaultCodecSupported(const std::string& mime_type, | 903 SupportsType MimeUtil::IsDefaultCodecSupported(const std::string& mime_type, |
837 bool is_encrypted) const { | 904 bool is_encrypted) const { |
838 Codec default_codec = Codec::INVALID_CODEC; | 905 Codec default_codec = Codec::INVALID_CODEC; |
839 if (!GetDefaultCodec(mime_type, &default_codec)) | 906 if (!GetDefaultCodec(mime_type, &default_codec)) |
840 return IsNotSupported; | 907 return IsNotSupported; |
841 return IsSimpleCodecSupported(mime_type, default_codec, is_encrypted); | 908 return IsSimpleCodecSupported(mime_type, default_codec, is_encrypted); |
842 } | 909 } |
843 | 910 |
844 } // namespace internal | 911 } // namespace internal |
845 } // namespace media | 912 } // namespace media |
OLD | NEW |