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> |
11 | 11 |
12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "media/base/media_export.h" | |
14 #include "media/base/mime_util.h" | 15 #include "media/base/mime_util.h" |
15 | 16 |
16 namespace media { | 17 namespace media { |
17 namespace internal { | 18 namespace internal { |
18 | 19 |
19 // Internal utility class for handling mime types. Should only be invoked by | 20 // Internal utility class for handling mime types. Should only be invoked by |
20 // tests and the functions within mime_util.cc -- NOT for direct use by others. | 21 // tests and the functions within mime_util.cc -- NOT for direct use by others. |
21 class MimeUtil { | 22 class MEDIA_EXPORT MimeUtil { |
22 public: | 23 public: |
23 MimeUtil(); | 24 MimeUtil(); |
24 ~MimeUtil(); | 25 ~MimeUtil(); |
25 | 26 |
26 enum Codec { | 27 enum Codec { |
27 INVALID_CODEC, | 28 INVALID_CODEC, |
28 PCM, | 29 PCM, |
29 MP3, | 30 MP3, |
30 AC3, | 31 AC3, |
31 EAC3, | 32 EAC3, |
32 MPEG2_AAC_LC, | 33 MPEG2_AAC_LC, |
33 MPEG2_AAC_MAIN, | 34 MPEG2_AAC_MAIN, |
34 MPEG2_AAC_SSR, | 35 MPEG2_AAC_SSR, |
35 MPEG4_AAC_LC, | 36 MPEG4_AAC_LC, |
36 MPEG4_AAC_SBR_v1, | 37 MPEG4_AAC_SBR_v1, |
37 MPEG4_AAC_SBR_PS_v2, | 38 MPEG4_AAC_SBR_PS_v2, |
38 VORBIS, | 39 VORBIS, |
39 OPUS, | 40 OPUS, |
40 H264, | 41 H264, |
41 HEVC_MAIN, | 42 HEVC_MAIN, |
42 VP8, | 43 VP8, |
43 VP9, | 44 VP9, |
44 THEORA | 45 THEORA, |
46 LAST_CODEC = THEORA | |
47 }; | |
48 | |
49 // Platform configuration structure. Controls which codecs are supported at | |
50 // runtime. Also used by tests to simulate platform differences. | |
51 struct PlatformInfo { | |
52 bool has_platform_decoders = false; | |
53 | |
54 bool supports_encrypted_vp8 = false; | |
55 bool supports_opus = false; | |
56 bool supports_vp9 = false; | |
57 | |
58 bool using_unified_media_pipeline = false; | |
ddorwin
2016/02/18 20:37:45
nit: We don't actually know whether the unified pi
DaleCurtis
2016/02/19 01:35:47
Went with |is_unified_media_pipeline_enabled|
| |
45 }; | 59 }; |
46 | 60 |
47 // See mime_util.h for more information on these methods. | 61 // See mime_util.h for more information on these methods. |
48 bool IsSupportedMediaMimeType(const std::string& mime_type) const; | 62 bool IsSupportedMediaMimeType(const std::string& mime_type) const; |
49 void ParseCodecString(const std::string& codecs, | 63 void ParseCodecString(const std::string& codecs, |
50 std::vector<std::string>* codecs_out, | 64 std::vector<std::string>* codecs_out, |
51 bool strip); | 65 bool strip); |
52 SupportsType IsSupportedMediaFormat( | 66 SupportsType IsSupportedMediaFormat(const std::string& mime_type, |
53 const std::string& mime_type, | 67 const std::vector<std::string>& codecs, |
54 const std::vector<std::string>& codecs) const; | 68 bool is_encrypted) const; |
55 | 69 |
56 void RemoveProprietaryMediaTypesAndCodecs(); | 70 void RemoveProprietaryMediaTypesAndCodecs(); |
57 | 71 |
72 void SetPlatformInfoForTests(const PlatformInfo& info); | |
73 | |
74 // Checks special Android only codec restrictions. | |
75 bool IsCodecSupportedOnAndroidForTests( | |
76 Codec codec, | |
77 const std::string& mime_type_lower_case, | |
78 bool is_encrypted) const { | |
79 return IsCodecSupportedOnAndroid(codec, mime_type_lower_case, is_encrypted); | |
80 } | |
81 | |
58 private: | 82 private: |
59 typedef base::hash_set<int> CodecSet; | 83 typedef base::hash_set<int> CodecSet; |
60 typedef std::map<std::string, CodecSet> MediaFormatMappings; | 84 typedef std::map<std::string, CodecSet> MediaFormatMappings; |
61 struct CodecEntry { | 85 struct CodecEntry { |
62 CodecEntry() : codec(INVALID_CODEC), is_ambiguous(true) {} | 86 CodecEntry() : codec(INVALID_CODEC), is_ambiguous(true) {} |
63 CodecEntry(Codec c, bool ambiguous) : codec(c), is_ambiguous(ambiguous) {} | 87 CodecEntry(Codec c, bool ambiguous) : codec(c), is_ambiguous(ambiguous) {} |
64 Codec codec; | 88 Codec codec; |
65 bool is_ambiguous; | 89 bool is_ambiguous; |
66 }; | 90 }; |
67 typedef std::map<std::string, CodecEntry> StringToCodecMappings; | 91 typedef std::map<std::string, CodecEntry> StringToCodecMappings; |
68 | 92 |
69 // For faster lookup, keep hash sets. | 93 // For faster lookup, keep hash sets. |
70 void InitializeMimeTypeMaps(); | 94 void InitializeMimeTypeMaps(); |
71 | 95 |
72 // Returns IsSupported if all codec IDs in |codecs| are unambiguous | 96 // Returns IsSupported if all codec IDs in |codecs| are unambiguous and are |
73 // and are supported by the platform. MayBeSupported is returned if | 97 // supported in |mime_type_lower_case|. IsNotSupported is returned if |
ddorwin
2016/02/18 20:37:45
Did you mean to drop the MayBeSupported sentence?
DaleCurtis
2016/02/19 01:35:47
Nope, restored.
| |
74 // at least one codec ID in |codecs| is ambiguous but all the codecs | 98 // |mime_type_lower_case| is not supported or at least one is not supported in |
75 // are supported by the platform. IsNotSupported is returned if at | 99 // |mime_type_lower_case|. |is_encrypted| means the codec will be used with |
76 // least one codec ID is not supported by the platform. | 100 // encrypted blocks. |
77 SupportsType AreSupportedCodecs(const CodecSet& supported_codecs, | 101 SupportsType AreSupportedCodecs(const CodecSet& supported_codecs, |
78 const std::vector<std::string>& codecs) const; | 102 const std::vector<std::string>& codecs, |
103 const std::string& mime_type_lower_case, | |
104 bool is_encrypted) const; | |
79 | 105 |
80 // Converts a codec ID into an Codec enum value and indicates | 106 // Converts a codec ID into an Codec enum value and indicates |
81 // whether the conversion was ambiguous. | 107 // whether the conversion was ambiguous. |
82 // Returns true if this method was able to map |codec_id| to a specific | 108 // Returns true if this method was able to map |codec_id| to a specific |
83 // Codec enum value. |codec| and |is_ambiguous| are only valid if true | 109 // Codec enum value. |codec| and |is_ambiguous| are only valid if true |
84 // is returned. Otherwise their value is undefined after the call. | 110 // is returned. Otherwise their value is undefined after the call. |
85 // |is_ambiguous| is true if |codec_id| did not have enough information to | 111 // |is_ambiguous| is true if |codec_id| did not have enough information to |
86 // unambiguously determine the proper Codec enum value. If |is_ambiguous| | 112 // unambiguously determine the proper Codec enum value. If |is_ambiguous| |
87 // is true |codec| contains the best guess for the intended Codec enum value. | 113 // is true |codec| contains the best guess for the intended Codec enum value. |
88 bool StringToCodec(const std::string& codec_id, | 114 bool StringToCodec(const std::string& codec_id, |
89 Codec* codec, | 115 Codec* codec, |
90 bool* is_ambiguous) const; | 116 bool* is_ambiguous) const; |
91 | 117 |
92 // Returns true if |codec| is supported by the platform. | 118 // Returns true if |codec| is supported when contained in |
93 // Note: This method will return false if the platform supports proprietary | 119 // |mime_type_lower_case|. Note: This method will always return false if |
94 // codecs but |allow_proprietary_codecs_| is set to false. | 120 // |allow_proprietary_codecs_| is set to false. |is_encrypted| means the codec |
ddorwin
2016/02/18 20:37:44
I still think you are missing a qualification in t
DaleCurtis
2016/02/19 01:35:47
Ah, I see what you were saying. Done.
| |
95 bool IsCodecSupported(Codec codec) const; | 121 // will be used with encrypted blocks. |
122 bool IsCodecSupported(Codec codec, | |
123 const std::string& mime_type_lower_case, | |
124 bool is_encrypted) const; | |
96 | 125 |
97 // Returns true if |codec| refers to a proprietary codec. | 126 // Returns true if |codec| refers to a proprietary codec. |
98 bool IsCodecProprietary(Codec codec) const; | 127 bool IsCodecProprietary(Codec codec) const; |
99 | 128 |
100 // Returns true and sets |*default_codec| if |mime_type| has a default codec | 129 // Returns true and sets |*default_codec| if |mime_type| has a default codec |
101 // associated with it. Returns false otherwise and the value of | 130 // associated with it. Returns false otherwise and the value of |
102 // |*default_codec| is undefined. | 131 // |*default_codec| is undefined. |
103 bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, | 132 bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, |
104 Codec* default_codec) const; | 133 Codec* default_codec) const; |
105 | 134 |
106 // Returns true if |mime_type_lower_case| has a default codec associated with | 135 // Returns true if |mime_type_lower_case| has a default codec associated with |
107 // it and IsCodecSupported() returns true for that particular codec. | 136 // it and IsCodecSupported() returns true for that particular codec. |
108 bool IsDefaultCodecSupportedLowerCase( | 137 // |is_encrypted| means the codec will be used with encrypted blocks. |
109 const std::string& mime_type_lower_case) const; | 138 bool IsDefaultCodecSupportedLowerCase(const std::string& mime_type_lower_case, |
139 bool is_encrypted) const; | |
110 | 140 |
111 #if defined(OS_ANDROID) | |
112 // Checks special Android only codec restrictions. | 141 // Checks special Android only codec restrictions. |
113 bool IsCodecSupportedOnAndroid(Codec codec) const; | 142 bool IsCodecSupportedOnAndroid(Codec codec, |
ddorwin
2016/02/18 20:37:45
It is weird that we have multiple "OnAndroid" func
DaleCurtis
2016/02/19 01:35:47
I had a similar idea this morning. Done.
| |
114 #endif | 143 const std::string& mime_type_lower_case, |
144 bool is_encrypted) const; | |
145 | |
146 // Indicates the support of various codecs within the platform. | |
147 PlatformInfo platform_info_; | |
115 | 148 |
116 // A map of mime_types and hash map of the supported codecs for the mime_type. | 149 // A map of mime_types and hash map of the supported codecs for the mime_type. |
117 MediaFormatMappings media_format_map_; | 150 MediaFormatMappings media_format_map_; |
118 | 151 |
119 // Keeps track of whether proprietary codec support should be | 152 // Keeps track of whether proprietary codec support should be |
120 // advertised to callers. | 153 // advertised to callers. |
121 bool allow_proprietary_codecs_; | 154 bool allow_proprietary_codecs_; |
122 | 155 |
123 // Lookup table for string compare based string -> Codec mappings. | 156 // Lookup table for string compare based string -> Codec mappings. |
124 StringToCodecMappings string_to_codec_map_; | 157 StringToCodecMappings string_to_codec_map_; |
125 | 158 |
126 DISALLOW_COPY_AND_ASSIGN(MimeUtil); | 159 DISALLOW_COPY_AND_ASSIGN(MimeUtil); |
127 }; | 160 }; |
128 | 161 |
129 } // namespace internal | 162 } // namespace internal |
130 } // namespace media | 163 } // namespace media |
131 | 164 |
132 #endif // MEDIA_BASE_MIME_UTIL_INTERNAL_H_ | 165 #endif // MEDIA_BASE_MIME_UTIL_INTERNAL_H_ |
OLD | NEW |