Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(787)

Side by Side Diff: media/base/mime_util_internal.h

Issue 1690063002: Fix mime type mappings when the unified media pipeline is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments. Fix vp8 inversion. Fix vp9 exclusion. Fix hevc. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 has_platform_vp8_decoder = false;
55 bool supports_opus = false;
56 bool supports_vp9 = false;
57
58 bool is_unified_media_pipeline_enabled = false;
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 // Checks special platform specific codec restrictions. Returns true if
73 // |codec| is supported when contained in |mime_type_lower_case|.
74 // |is_encrypted| means the codec will be used with encrypted blocks.
75 // |platform_info| describes the availability of various platform features;
76 // see PlatformInfo for more details.
77 static bool IsCodecSupportedOnPlatform(
78 Codec codec,
79 const std::string& mime_type_lower_case,
80 bool is_encrypted,
81 const PlatformInfo& platform_info);
82
58 private: 83 private:
59 typedef base::hash_set<int> CodecSet; 84 typedef base::hash_set<int> CodecSet;
60 typedef std::map<std::string, CodecSet> MediaFormatMappings; 85 typedef std::map<std::string, CodecSet> MediaFormatMappings;
61 struct CodecEntry { 86 struct CodecEntry {
62 CodecEntry() : codec(INVALID_CODEC), is_ambiguous(true) {} 87 CodecEntry() : codec(INVALID_CODEC), is_ambiguous(true) {}
63 CodecEntry(Codec c, bool ambiguous) : codec(c), is_ambiguous(ambiguous) {} 88 CodecEntry(Codec c, bool ambiguous) : codec(c), is_ambiguous(ambiguous) {}
64 Codec codec; 89 Codec codec;
65 bool is_ambiguous; 90 bool is_ambiguous;
66 }; 91 };
67 typedef std::map<std::string, CodecEntry> StringToCodecMappings; 92 typedef std::map<std::string, CodecEntry> StringToCodecMappings;
68 93
69 // For faster lookup, keep hash sets. 94 // For faster lookup, keep hash sets.
70 void InitializeMimeTypeMaps(); 95 void InitializeMimeTypeMaps();
71 96
72 // Returns IsSupported if all codec IDs in |codecs| are unambiguous 97 // Returns IsSupported if all codec IDs in |codecs| are unambiguous and are
73 // and are supported by the platform. MayBeSupported is returned if 98 // supported in |mime_type_lower_case|. MayBeSupported is returned if at least
74 // at least one codec ID in |codecs| is ambiguous but all the codecs 99 // one codec ID in |codecs| is ambiguous but all the codecs are supported.
75 // are supported by the platform. IsNotSupported is returned if at 100 // IsNotSupported is returned if |mime_type_lower_case| is not supported or at
76 // least one codec ID is not supported by the platform. 101 // least one is not supported in |mime_type_lower_case|. |is_encrypted| means
102 // the codec will be used with encrypted blocks.
77 SupportsType AreSupportedCodecs(const CodecSet& supported_codecs, 103 SupportsType AreSupportedCodecs(const CodecSet& supported_codecs,
78 const std::vector<std::string>& codecs) const; 104 const std::vector<std::string>& codecs,
105 const std::string& mime_type_lower_case,
106 bool is_encrypted) const;
79 107
80 // Converts a codec ID into an Codec enum value and indicates 108 // Converts a codec ID into an Codec enum value and indicates
81 // whether the conversion was ambiguous. 109 // whether the conversion was ambiguous.
82 // Returns true if this method was able to map |codec_id| to a specific 110 // 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 111 // Codec enum value. |codec| and |is_ambiguous| are only valid if true
84 // is returned. Otherwise their value is undefined after the call. 112 // is returned. Otherwise their value is undefined after the call.
85 // |is_ambiguous| is true if |codec_id| did not have enough information to 113 // |is_ambiguous| is true if |codec_id| did not have enough information to
86 // unambiguously determine the proper Codec enum value. If |is_ambiguous| 114 // unambiguously determine the proper Codec enum value. If |is_ambiguous|
87 // is true |codec| contains the best guess for the intended Codec enum value. 115 // is true |codec| contains the best guess for the intended Codec enum value.
88 bool StringToCodec(const std::string& codec_id, 116 bool StringToCodec(const std::string& codec_id,
89 Codec* codec, 117 Codec* codec,
90 bool* is_ambiguous) const; 118 bool* is_ambiguous) const;
91 119
92 // Returns true if |codec| is supported by the platform. 120 // Returns true if |codec| is supported when contained in
93 // Note: This method will return false if the platform supports proprietary 121 // |mime_type_lower_case|. Note: This method will always return false for
94 // codecs but |allow_proprietary_codecs_| is set to false. 122 // proprietary codecs if |allow_proprietary_codecs_| is set to false.
95 bool IsCodecSupported(Codec codec) const; 123 // |is_encrypted| means the codec will be used with encrypted blocks.
124 bool IsCodecSupported(Codec codec,
125 const std::string& mime_type_lower_case,
126 bool is_encrypted) const;
96 127
97 // Returns true if |codec| refers to a proprietary codec. 128 // Returns true if |codec| refers to a proprietary codec.
98 bool IsCodecProprietary(Codec codec) const; 129 bool IsCodecProprietary(Codec codec) const;
99 130
100 // Returns true and sets |*default_codec| if |mime_type| has a default codec 131 // Returns true and sets |*default_codec| if |mime_type| has a default codec
101 // associated with it. Returns false otherwise and the value of 132 // associated with it. Returns false otherwise and the value of
102 // |*default_codec| is undefined. 133 // |*default_codec| is undefined.
103 bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, 134 bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case,
104 Codec* default_codec) const; 135 Codec* default_codec) const;
105 136
106 // Returns true if |mime_type_lower_case| has a default codec associated with 137 // Returns true if |mime_type_lower_case| has a default codec associated with
107 // it and IsCodecSupported() returns true for that particular codec. 138 // it and IsCodecSupported() returns true for that particular codec.
108 bool IsDefaultCodecSupportedLowerCase( 139 // |is_encrypted| means the codec will be used with encrypted blocks.
109 const std::string& mime_type_lower_case) const; 140 bool IsDefaultCodecSupportedLowerCase(const std::string& mime_type_lower_case,
141 bool is_encrypted) const;
110 142
111 #if defined(OS_ANDROID) 143 #if defined(OS_ANDROID)
112 // Checks special Android only codec restrictions. 144 // Indicates the support of various codecs within the platform.
113 bool IsCodecSupportedOnAndroid(Codec codec) const; 145 PlatformInfo platform_info_;
114 #endif 146 #endif
115 147
116 // A map of mime_types and hash map of the supported codecs for the mime_type. 148 // A map of mime_types and hash map of the supported codecs for the mime_type.
117 MediaFormatMappings media_format_map_; 149 MediaFormatMappings media_format_map_;
118 150
119 // Keeps track of whether proprietary codec support should be 151 // Keeps track of whether proprietary codec support should be
120 // advertised to callers. 152 // advertised to callers.
121 bool allow_proprietary_codecs_; 153 bool allow_proprietary_codecs_;
122 154
123 // Lookup table for string compare based string -> Codec mappings. 155 // Lookup table for string compare based string -> Codec mappings.
124 StringToCodecMappings string_to_codec_map_; 156 StringToCodecMappings string_to_codec_map_;
125 157
126 DISALLOW_COPY_AND_ASSIGN(MimeUtil); 158 DISALLOW_COPY_AND_ASSIGN(MimeUtil);
127 }; 159 };
128 160
129 } // namespace internal 161 } // namespace internal
130 } // namespace media 162 } // namespace media
131 163
132 #endif // MEDIA_BASE_MIME_UTIL_INTERNAL_H_ 164 #endif // MEDIA_BASE_MIME_UTIL_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698