| 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 #ifndef MEDIA_BASE_MIME_UTIL_INTERNAL_H_ | 5 #ifndef MEDIA_BASE_MIME_UTIL_INTERNAL_H_ |
| 6 #define MEDIA_BASE_MIME_UTIL_INTERNAL_H_ | 6 #define MEDIA_BASE_MIME_UTIL_INTERNAL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 struct PlatformInfo { | 49 struct PlatformInfo { |
| 50 bool has_platform_decoders = false; | 50 bool has_platform_decoders = false; |
| 51 | 51 |
| 52 bool has_platform_vp8_decoder = false; | 52 bool has_platform_vp8_decoder = false; |
| 53 bool has_platform_vp9_decoder = false; | 53 bool has_platform_vp9_decoder = false; |
| 54 bool supports_opus = false; | 54 bool supports_opus = false; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // See mime_util.h for more information on these methods. | 57 // See mime_util.h for more information on these methods. |
| 58 bool IsSupportedMediaMimeType(const std::string& mime_type) const; | 58 bool IsSupportedMediaMimeType(const std::string& mime_type) const; |
| 59 void ParseCodecString(const std::string& codecs, | 59 void SplitCodecsToVector(const std::string& codecs, |
| 60 std::vector<std::string>* codecs_out, | 60 std::vector<std::string>* codecs_out, |
| 61 bool strip); | 61 bool strip); |
| 62 SupportsType IsSupportedMediaFormat(const std::string& mime_type, | 62 SupportsType IsSupportedMediaFormat(const std::string& mime_type, |
| 63 const std::vector<std::string>& codecs, | 63 const std::vector<std::string>& codecs, |
| 64 bool is_encrypted) const; | 64 bool is_encrypted) const; |
| 65 | 65 |
| 66 void RemoveProprietaryMediaTypesAndCodecs(); | 66 void RemoveProprietaryMediaTypesAndCodecs(); |
| 67 | 67 |
| 68 // Checks special platform specific codec restrictions. Returns true if | 68 // Checks android platform specific codec restrictions. Returns true if |
| 69 // |codec| is supported when contained in |mime_type_lower_case|. | 69 // |codec| is supported when contained in |mime_type_lower_case|. |
| 70 // |is_encrypted| means the codec will be used with encrypted blocks. | 70 // |is_encrypted| means the codec will be used with encrypted blocks. |
| 71 // |platform_info| describes the availability of various platform features; | 71 // |platform_info| describes the availability of various platform features; |
| 72 // see PlatformInfo for more details. | 72 // see PlatformInfo for more details. |
| 73 static bool IsCodecSupportedOnPlatform( | 73 static bool IsCodecSupportedOnAndroid(Codec codec, |
| 74 Codec codec, | 74 const std::string& mime_type_lower_case, |
| 75 const std::string& mime_type_lower_case, | 75 bool is_encrypted, |
| 76 bool is_encrypted, | 76 const PlatformInfo& platform_info); |
| 77 const PlatformInfo& platform_info); | |
| 78 | 77 |
| 79 private: | 78 private: |
| 80 typedef base::hash_set<int> CodecSet; | 79 typedef base::hash_set<int> CodecSet; |
| 81 typedef std::map<std::string, CodecSet> MediaFormatMappings; | 80 typedef std::map<std::string, CodecSet> MediaFormatMappings; |
| 82 struct CodecEntry { | |
| 83 CodecEntry() : codec(INVALID_CODEC), is_ambiguous(true) {} | |
| 84 CodecEntry(Codec c, bool ambiguous) : codec(c), is_ambiguous(ambiguous) {} | |
| 85 Codec codec; | |
| 86 bool is_ambiguous; | |
| 87 }; | |
| 88 typedef std::map<std::string, CodecEntry> StringToCodecMappings; | |
| 89 | 81 |
| 90 // Initializes the supported media types into hash sets for faster lookup. | 82 // Initializes the supported media types into hash sets for faster lookup. |
| 91 void InitializeMimeTypeMaps(); | 83 void InitializeMimeTypeMaps(); |
| 92 | 84 |
| 93 // Initializes the supported media formats (|media_format_map_|). | 85 // Initializes the supported media formats (|media_format_map_|). |
| 94 void AddSupportedMediaFormats(); | 86 void AddSupportedMediaFormats(); |
| 95 | 87 |
| 96 // Adds |mime_type| with the specified codecs to |media_format_map_|. | 88 // Adds |mime_type| with the specified codecs to |media_format_map_|. |
| 97 void AddContainerWithCodecs(const std::string& mime_type, | 89 void AddContainerWithCodecs(const std::string& mime_type, |
| 98 const CodecSet& codecs_list, | 90 const CodecSet& codecs_list, |
| 99 bool is_proprietary_mime_type); | 91 bool is_proprietary_mime_type); |
| 100 | 92 |
| 101 // Returns IsSupported if all codec IDs in |codecs| are unambiguous and are | 93 // Returns IsSupported if all codec IDs in |codecs| are unambiguous and are |
| 102 // supported in |mime_type_lower_case|. MayBeSupported is returned if at least | 94 // supported in |mime_type_lower_case|. MayBeSupported is returned if at least |
| 103 // one codec ID in |codecs| is ambiguous but all the codecs are supported. | 95 // one codec ID in |codecs| is ambiguous but all the codecs are supported. |
| 104 // IsNotSupported is returned if |mime_type_lower_case| is not supported or at | 96 // IsNotSupported is returned if |mime_type_lower_case| is not supported or at |
| 105 // least one is not supported in |mime_type_lower_case|. |is_encrypted| means | 97 // least one is not supported in |mime_type_lower_case|. |is_encrypted| means |
| 106 // the codec will be used with encrypted blocks. | 98 // the codec will be used with encrypted blocks. |
| 107 SupportsType AreSupportedCodecs(const CodecSet& supported_codecs, | 99 SupportsType AreSupportedCodecs(const CodecSet& supported_codecs, |
| 108 const std::vector<std::string>& codecs, | 100 const std::vector<std::string>& codecs, |
| 109 const std::string& mime_type_lower_case, | 101 const std::string& mime_type_lower_case, |
| 110 bool is_encrypted) const; | 102 bool is_encrypted) const; |
| 111 | 103 |
| 112 // Converts a codec ID into an Codec enum value and indicates | 104 // Converts a codec ID into an Codec enum value and attempts to output the |
| 113 // whether the conversion was ambiguous. | 105 // |out_profile| and |out_level|. |
| 114 // Returns true if this method was able to map |codec_id| with | 106 // Returns true if this method was able to map |codec_id| with |
| 115 // |mime_type_lower_case| to a specific Codec enum value. |codec| and | 107 // |mime_type_lower_case| to a specific Codec enum value. |codec| is only |
| 116 // |is_ambiguous| are only valid if true is returned. Otherwise their value is | 108 // valid if true is returned. |
| 117 // undefined after the call. | 109 // |ambiguous_codec_string| will be set to true when the codec string matches |
| 118 // |is_ambiguous| is true if |codec_id| did not have enough information to | 110 // one of a small number of non-RFC compliant strings (e.g. "avc"). |
| 119 // unambiguously determine the proper Codec enum value. If |is_ambiguous| | |
| 120 // is true |codec| contains the best guess for the intended Codec enum value. | |
| 121 // |profile| and |level| indicate video codec profile and level (unused for | 111 // |profile| and |level| indicate video codec profile and level (unused for |
| 122 // audio codecs). | 112 // audio codecs). These will be VIDEO_CODEC_PROFILE_UNKNOWN and 0 respectively |
| 113 // whenever |codec_id| is incomplete/invalid, or in some cases when |
| 114 // |ambiguous_codec_string| is set to true. |
| 123 // |is_encrypted| means the codec will be used with encrypted blocks. | 115 // |is_encrypted| means the codec will be used with encrypted blocks. |
| 124 bool StringToCodec(const std::string& mime_type_lower_case, | 116 bool ParseCodecString(const std::string& mime_type_lower_case, |
| 125 const std::string& codec_id, | 117 const std::string& codec_id, |
| 126 Codec* codec, | 118 Codec* codec, |
| 127 bool* is_ambiguous, | 119 bool* ambiguous_codec_string, |
| 128 VideoCodecProfile* out_profile, | 120 VideoCodecProfile* out_profile, |
| 129 uint8_t* out_level, | 121 uint8_t* out_level) const; |
| 130 bool is_encrypted) const; | |
| 131 | 122 |
| 132 // Returns true if |codec| is supported when contained in | 123 // Returns IsSupported if |codec| when platform supports codec contained in |
| 133 // |mime_type_lower_case|. Note: This method will always return false for | 124 // |mime_type_lower_case|. Returns MayBeSupported when platform support is |
| 134 // proprietary codecs if |allow_proprietary_codecs_| is set to false. | 125 // unclear. Otherwise returns NotSupported. Note: This method will always |
| 135 // |is_encrypted| means the codec will be used with encrypted blocks. | 126 // return NotSupported for proprietary codecs if |allow_proprietary_codecs_| |
| 136 bool IsCodecSupported(Codec codec, | 127 // is set to false. |is_encrypted| means the codec will be used with encrypted |
| 137 const std::string& mime_type_lower_case, | 128 // blocks. |
| 138 bool is_encrypted) const; | 129 // TODO(chcunningham): Make this method return a bool. Platform support should |
| 130 // always be knowable for a fully specified codec. |
| 131 SupportsType IsCodecSupported(const std::string& mime_type_lower_case, |
| 132 Codec codec, |
| 133 VideoCodecProfile video_profile, |
| 134 uint8_t video_level, |
| 135 bool is_encrypted) const; |
| 136 |
| 137 // Wrapper around IsCodecSupported for simple codecs that are entirely |
| 138 // described (or implied) by the container mime-type. |
| 139 SupportsType IsSimpleCodecSupported(const std::string& mime_type_lower_case, |
| 140 Codec codec, |
| 141 bool is_encrypted) const; |
| 139 | 142 |
| 140 // Returns true if |codec| refers to a proprietary codec. | 143 // Returns true if |codec| refers to a proprietary codec. |
| 141 bool IsCodecProprietary(Codec codec) const; | 144 bool IsCodecProprietary(Codec codec) const; |
| 142 | 145 |
| 143 // Returns true and sets |*default_codec| if |mime_type| has a default codec | 146 // Returns true and sets |*default_codec| if |mime_type_lower_case| has a |
| 144 // associated with it. Returns false otherwise and the value of | 147 // default codec associated with it. Returns false otherwise and the value of |
| 145 // |*default_codec| is undefined. | 148 // |*default_codec| is undefined. |
| 146 bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, | 149 bool GetDefaultCodec(const std::string& mime_type_lower_case, |
| 147 Codec* default_codec) const; | 150 Codec* default_codec) const; |
| 148 | 151 |
| 149 // Returns true if |mime_type_lower_case| has a default codec associated with | 152 // Returns IsSupported if |mime_type_lower_case| has a default codec |
| 150 // it and IsCodecSupported() returns true for that particular codec. | 153 // associated with it and IsCodecSupported() returns IsSupported for that |
| 151 // |is_encrypted| means the codec will be used with encrypted blocks. | 154 // particular codec. |is_encrypted| means the codec will be used with |
| 152 bool IsDefaultCodecSupportedLowerCase(const std::string& mime_type_lower_case, | 155 // encrypted blocks. |
| 153 bool is_encrypted) const; | 156 SupportsType IsDefaultCodecSupported(const std::string& mime_type_lower_case, |
| 157 bool is_encrypted) const; |
| 154 | 158 |
| 155 #if defined(OS_ANDROID) | 159 #if defined(OS_ANDROID) |
| 156 // Indicates the support of various codecs within the platform. | 160 // Indicates the support of various codecs within the platform. |
| 157 PlatformInfo platform_info_; | 161 PlatformInfo platform_info_; |
| 158 #endif | 162 #endif |
| 159 | 163 |
| 160 // A map of mime_types and hash map of the supported codecs for the mime_type. | 164 // A map of mime_types and hash map of the supported codecs for the mime_type. |
| 161 MediaFormatMappings media_format_map_; | 165 MediaFormatMappings media_format_map_; |
| 162 | 166 |
| 163 // List of proprietary containers in |media_format_map_|. | 167 // List of proprietary containers in |media_format_map_|. |
| 164 std::vector<std::string> proprietary_media_containers_; | 168 std::vector<std::string> proprietary_media_containers_; |
| 165 // Whether proprietary codec support should be advertised to callers. | 169 // Whether proprietary codec support should be advertised to callers. |
| 166 bool allow_proprietary_codecs_; | 170 bool allow_proprietary_codecs_; |
| 167 | 171 |
| 168 // Lookup table for string compare based string -> Codec mappings. | |
| 169 StringToCodecMappings string_to_codec_map_; | |
| 170 | |
| 171 DISALLOW_COPY_AND_ASSIGN(MimeUtil); | 172 DISALLOW_COPY_AND_ASSIGN(MimeUtil); |
| 172 }; | 173 }; |
| 173 | 174 |
| 174 } // namespace internal | 175 } // namespace internal |
| 175 } // namespace media | 176 } // namespace media |
| 176 | 177 |
| 177 #endif // MEDIA_BASE_MIME_UTIL_INTERNAL_H_ | 178 #endif // MEDIA_BASE_MIME_UTIL_INTERNAL_H_ |
| OLD | NEW |