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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // Returns true if this method was able to map |codec_id| to a specific | 94 // Returns true if this method was able to map |codec_id| to a specific |
94 // Codec enum value. |codec| and |is_ambiguous| are only valid if true | 95 // Codec enum value. |codec| and |is_ambiguous| are only valid if true |
95 // is returned. Otherwise their value is undefined after the call. | 96 // is returned. Otherwise their value is undefined after the call. |
96 // |is_ambiguous| is true if |codec_id| did not have enough information to | 97 // |is_ambiguous| is true if |codec_id| did not have enough information to |
97 // unambiguously determine the proper Codec enum value. If |is_ambiguous| | 98 // unambiguously determine the proper Codec enum value. If |is_ambiguous| |
98 // is true |codec| contains the best guess for the intended Codec enum value. | 99 // is true |codec| contains the best guess for the intended Codec enum value. |
99 bool StringToCodec(const std::string& codec_id, | 100 bool StringToCodec(const std::string& codec_id, |
100 Codec* codec, | 101 Codec* codec, |
101 bool* is_ambiguous) const; | 102 bool* is_ambiguous) const; |
102 | 103 |
| 104 media::AudioCodec MediaCodecToAudioCodec(Codec codec) const; |
| 105 media::VideoCodec MediaCodecToVideoCodec(Codec codec) const; |
| 106 |
103 // Returns true if |codec| is supported by the platform. | 107 // Returns true if |codec| is supported by the platform. |
104 // Note: This method will return false if the platform supports proprietary | 108 // Note: This method will return false if the platform supports proprietary |
105 // codecs but |allow_proprietary_codecs_| is set to false. | 109 // codecs but |allow_proprietary_codecs_| is set to false. |
106 bool IsCodecSupported(Codec codec) const; | 110 bool IsCodecSupported(Codec codec) const; |
107 | 111 |
108 // Returns true if |codec| refers to a proprietary codec. | 112 // Returns true if |codec| refers to a proprietary codec. |
109 bool IsCodecProprietary(Codec codec) const; | 113 bool IsCodecProprietary(Codec codec) const; |
110 | 114 |
111 // Returns true and sets |*default_codec| if |mime_type| has a default codec | 115 // Returns true and sets |*default_codec| if |mime_type| has a default codec |
112 // associated with it. Returns false otherwise and the value of | 116 // associated with it. Returns false otherwise and the value of |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 489 |
486 SupportsType MimeUtil::IsSupportedMediaFormat( | 490 SupportsType MimeUtil::IsSupportedMediaFormat( |
487 const std::string& mime_type, | 491 const std::string& mime_type, |
488 const std::vector<std::string>& codecs) const { | 492 const std::vector<std::string>& codecs) const { |
489 const std::string mime_type_lower_case = base::ToLowerASCII(mime_type); | 493 const std::string mime_type_lower_case = base::ToLowerASCII(mime_type); |
490 MediaFormatMappings::const_iterator it_media_format_map = | 494 MediaFormatMappings::const_iterator it_media_format_map = |
491 media_format_map_.find(mime_type_lower_case); | 495 media_format_map_.find(mime_type_lower_case); |
492 if (it_media_format_map == media_format_map_.end()) | 496 if (it_media_format_map == media_format_map_.end()) |
493 return IsNotSupported; | 497 return IsNotSupported; |
494 | 498 |
| 499 // TODO: implement and use media::IsMediaContainerSupported |
| 500 // similar to IsVideoCodecSupported |
| 501 |
495 if (it_media_format_map->second.empty()) { | 502 if (it_media_format_map->second.empty()) { |
496 // We get here if the mimetype does not expect a codecs parameter. | 503 // We get here if the mimetype does not expect a codecs parameter. |
497 return (codecs.empty() && | 504 return (codecs.empty() && |
498 IsDefaultCodecSupportedLowerCase(mime_type_lower_case)) | 505 IsDefaultCodecSupportedLowerCase(mime_type_lower_case)) |
499 ? IsSupported | 506 ? IsSupported |
500 : IsNotSupported; | 507 : IsNotSupported; |
501 } | 508 } |
502 | 509 |
503 if (codecs.empty()) { | 510 if (codecs.empty()) { |
504 // We get here if the mimetype expects to get a codecs parameter, | 511 // We get here if the mimetype expects to get a codecs parameter, |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 // either H.264 or HEVC/H.265 codec ID because currently those are the only | 655 // either H.264 or HEVC/H.265 codec ID because currently those are the only |
649 // ones that are not added to the |string_to_codec_map_| and require parsing. | 656 // ones that are not added to the |string_to_codec_map_| and require parsing. |
650 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 657 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) |
651 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { | 658 if (ParseHEVCCodecID(codec_id, codec, is_ambiguous)) { |
652 return true; | 659 return true; |
653 } | 660 } |
654 #endif | 661 #endif |
655 return ParseH264CodecID(codec_id, codec, is_ambiguous); | 662 return ParseH264CodecID(codec_id, codec, is_ambiguous); |
656 } | 663 } |
657 | 664 |
| 665 media::AudioCodec MimeUtil::MediaCodecToAudioCodec(Codec codec) const { |
| 666 switch (codec) { |
| 667 case PCM: |
| 668 return kCodecPCM_S16BE; // kCodecPCM_S24BE |
| 669 case MP3: |
| 670 return kCodecMP3; |
| 671 case AC3: |
| 672 return kCodecAC3; |
| 673 case EAC3: |
| 674 return kCodecEAC3; |
| 675 case MPEG2_AAC_LC: |
| 676 case MPEG2_AAC_MAIN: |
| 677 case MPEG2_AAC_SSR: |
| 678 case MPEG4_AAC_LC: |
| 679 case MPEG4_AAC_SBR_v1: |
| 680 case MPEG4_AAC_SBR_PS_v2: |
| 681 return kCodecAAC; |
| 682 case VORBIS: |
| 683 return kCodecVorbis; |
| 684 case OPUS: |
| 685 return kCodecOpus; |
| 686 /* |
| 687 case ? |
| 688 return kCodecFLAC; |
| 689 case ? |
| 690 return kCodecAMR_NB; |
| 691 case ? |
| 692 return kCodecAMR_WB; |
| 693 case ? |
| 694 return kCodecPCM_ALAW; |
| 695 return kCodecPCM_MULAW; |
| 696 case ? |
| 697 return kCodecGSM_MS; |
| 698 case ? |
| 699 return kCodecALAC;; |
| 700 */ |
| 701 |
| 702 default: |
| 703 DVLOG(1) << "Unknown Codec: " << codec; |
| 704 } |
| 705 return kUnknownAudioCodec; |
| 706 } |
| 707 |
| 708 VideoCodec MimeUtil::MediaCodecToVideoCodec(Codec codec) const { |
| 709 switch (codec) { |
| 710 case H264_BASELINE: |
| 711 case H264_MAIN: |
| 712 case H264_HIGH: |
| 713 return kCodecH264; |
| 714 case HEVC_MAIN: |
| 715 return kCodecHEVC; |
| 716 case VP8: |
| 717 return kCodecVP8; |
| 718 case VP9: |
| 719 return kCodecVP9; |
| 720 case THEORA: |
| 721 return kCodecTheora; |
| 722 /* |
| 723 case ?: |
| 724 return kCodecVC1; |
| 725 case ?: |
| 726 return kCodecMPEG2; |
| 727 case ?: |
| 728 return kCodecMPEG4; |
| 729 */ |
| 730 default: |
| 731 DVLOG(1) << "Unknown Codec: " << codec; |
| 732 } |
| 733 return kUnknownVideoCodec; |
| 734 } |
| 735 |
658 bool MimeUtil::IsCodecSupported(Codec codec) const { | 736 bool MimeUtil::IsCodecSupported(Codec codec) const { |
659 DCHECK_NE(codec, INVALID_CODEC); | 737 DCHECK_NE(codec, INVALID_CODEC); |
660 | 738 |
661 #if defined(OS_ANDROID) | 739 #if defined(OS_ANDROID) |
662 if (!IsCodecSupportedOnAndroid(codec)) | 740 if (!IsCodecSupportedOnAndroid(codec)) |
663 return false; | 741 return false; |
664 #endif | 742 #endif |
665 | 743 |
666 return allow_proprietary_codecs_ || !IsCodecProprietary(codec); | 744 bool allow = allow_proprietary_codecs_ || !IsCodecProprietary(codec); |
| 745 |
| 746 // Not allowed because of build configuration. |
| 747 if (!allow) |
| 748 return false; |
| 749 |
| 750 // Check if the underlying media library actually supports the codec. Useful |
| 751 // when the build configuration allows proprietary codecs but not the |
| 752 // underlying media library. |
| 753 |
| 754 AudioCodec audio_codec = MediaCodecToAudioCodec(codec); |
| 755 if (audio_codec != kUnknownAudioCodec && |
| 756 media::IsAudioCodecSupported(audio_codec)) |
| 757 return true; |
| 758 |
| 759 media::VideoCodec video_codec = MediaCodecToVideoCodec(codec); |
| 760 if (video_codec != kUnknownVideoCodec && |
| 761 media::IsVideoCodecSupported(video_codec)) |
| 762 return true; |
| 763 |
| 764 return false; |
667 } | 765 } |
668 | 766 |
669 bool MimeUtil::IsCodecProprietary(Codec codec) const { | 767 bool MimeUtil::IsCodecProprietary(Codec codec) const { |
670 switch (codec) { | 768 switch (codec) { |
671 case INVALID_CODEC: | 769 case INVALID_CODEC: |
672 case AC3: | 770 case AC3: |
673 case EAC3: | 771 case EAC3: |
674 case MP3: | 772 case MP3: |
675 case MPEG2_AAC_LC: | 773 case MPEG2_AAC_LC: |
676 case MPEG2_AAC_MAIN: | 774 case MPEG2_AAC_MAIN: |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 std::vector<std::string>* codecs_out, | 832 std::vector<std::string>* codecs_out, |
735 const bool strip) { | 833 const bool strip) { |
736 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); | 834 g_media_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); |
737 } | 835 } |
738 | 836 |
739 void RemoveProprietaryMediaTypesAndCodecsForTests() { | 837 void RemoveProprietaryMediaTypesAndCodecsForTests() { |
740 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); | 838 g_media_mime_util.Get().RemoveProprietaryMediaTypesAndCodecsForTests(); |
741 } | 839 } |
742 | 840 |
743 } // namespace media | 841 } // namespace media |
OLD | NEW |