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

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: Simplify, test, rebase on split. 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/lazy_instance.h"
14 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "media/base/media_export.h"
15 #include "media/base/mime_util.h" 15 #include "media/base/mime_util.h"
16 16
17 namespace media { 17 namespace media {
18 namespace internal { 18 namespace internal {
19 19
20 #if defined(OS_ANDROID)
21 // Platform configuration structure. Controls which codecs are supported at
ddorwin 2016/02/17 21:18:39 Is there a reason this isn't nested in the class?
DaleCurtis 2016/02/18 03:58:09 Done.
22 // runtime. Also used by tests to simulate platform differences.
23 struct PlatformCodecInfo {
24 bool has_platform_decoder;
ddorwin 2016/02/17 21:18:39 nit: decoder*s*? Since it's Android, should we jus
DaleCurtis 2016/02/18 03:58:09 I'd like to keep the name consistent with what we
25 bool has_unified_media_pipeline;
ddorwin 2016/02/17 21:18:39 nit: This isn't really a platform property. Perhap
DaleCurtis 2016/02/18 03:58:09 Done.
26 bool has_opus;
27 bool has_vp8;
28 bool has_vp9;
ddorwin 2016/02/17 21:18:39 define default values?
DaleCurtis 2016/02/18 03:58:09 Done.
29 };
30 #endif
31
20 // Internal utility class for handling mime types. Should only be invoked by 32 // Internal utility class for handling mime types. Should only be invoked by
21 // tests and the functions within mime_util.cc -- NOT for direct use by others. 33 // tests and the functions within mime_util.cc -- NOT for direct use by others.
22 class MimeUtil { 34 class MEDIA_EXPORT MimeUtil {
23 public: 35 public:
36 MimeUtil();
37
24 enum Codec { 38 enum Codec {
25 INVALID_CODEC, 39 INVALID_CODEC,
26 PCM, 40 PCM,
27 MP3, 41 MP3,
28 AC3, 42 AC3,
29 EAC3, 43 EAC3,
30 MPEG2_AAC_LC, 44 MPEG2_AAC_LC,
31 MPEG2_AAC_MAIN, 45 MPEG2_AAC_MAIN,
32 MPEG2_AAC_SSR, 46 MPEG2_AAC_SSR,
33 MPEG4_AAC_LC, 47 MPEG4_AAC_LC,
34 MPEG4_AAC_SBR_v1, 48 MPEG4_AAC_SBR_v1,
35 MPEG4_AAC_SBR_PS_v2, 49 MPEG4_AAC_SBR_PS_v2,
36 VORBIS, 50 VORBIS,
37 OPUS, 51 OPUS,
38 H264_BASELINE, 52 H264_BASELINE,
39 H264_MAIN, 53 H264_MAIN,
40 H264_HIGH, 54 H264_HIGH,
41 HEVC_MAIN, 55 HEVC_MAIN,
42 VP8, 56 VP8,
43 VP9, 57 VP9,
44 THEORA 58 THEORA,
59 LAST_CODEC = THEORA
45 }; 60 };
46 61
47 // See mime_util.h for more information on these methods. 62 // See mime_util.h for more information on these methods.
48 bool IsSupportedMediaMimeType(const std::string& mime_type) const; 63 bool IsSupportedMediaMimeType(const std::string& mime_type) const;
49 void ParseCodecString(const std::string& codecs, 64 void ParseCodecString(const std::string& codecs,
50 std::vector<std::string>* codecs_out, 65 std::vector<std::string>* codecs_out,
51 bool strip); 66 bool strip);
52 SupportsType IsSupportedMediaFormat( 67 SupportsType IsSupportedMediaFormat(const std::string& mime_type,
53 const std::string& mime_type, 68 const std::vector<std::string>& codecs,
54 const std::vector<std::string>& codecs) const; 69 bool is_encrypted) const;
55 70
56 void RemoveProprietaryMediaTypesAndCodecs(); 71 void RemoveProprietaryMediaTypesAndCodecs();
57 72
73 void SetPlatformCodecInfoForTests(const PlatformCodecInfo& info);
ddorwin 2016/02/17 21:18:39 Move inside #ifdef.
DaleCurtis 2016/02/18 03:58:09 Actually instead I removed all of the #ifdefs from
ddorwin 2016/02/18 20:37:44 See my comment in the next PS.
74
75 #if defined(OS_ANDROID)
76 // Checks special Android only codec restrictions.
77 bool IsCodecSupportedOnAndroidForTests(
78 Codec codec,
79 const std::string& mime_type_lower_case,
80 bool is_encrypted) const {
81 return IsCodecSupportedOnAndroid(codec, mime_type_lower_case, is_encrypted);
82 }
83 #endif
84
58 private: 85 private:
59 friend struct base::DefaultLazyInstanceTraits<MimeUtil>;
60
61 typedef base::hash_set<int> CodecSet; 86 typedef base::hash_set<int> CodecSet;
62 typedef std::map<std::string, CodecSet> MediaFormatMappings; 87 typedef std::map<std::string, CodecSet> MediaFormatMappings;
63 struct CodecEntry { 88 struct CodecEntry {
64 CodecEntry() : codec(INVALID_CODEC), is_ambiguous(true) {} 89 CodecEntry() : codec(INVALID_CODEC), is_ambiguous(true) {}
65 CodecEntry(Codec c, bool ambiguous) : codec(c), is_ambiguous(ambiguous) {} 90 CodecEntry(Codec c, bool ambiguous) : codec(c), is_ambiguous(ambiguous) {}
66 Codec codec; 91 Codec codec;
67 bool is_ambiguous; 92 bool is_ambiguous;
68 }; 93 };
69 typedef std::map<std::string, CodecEntry> StringToCodecMappings; 94 typedef std::map<std::string, CodecEntry> StringToCodecMappings;
70 95
71 MimeUtil();
72
73 // For faster lookup, keep hash sets. 96 // For faster lookup, keep hash sets.
74 void InitializeMimeTypeMaps(); 97 void InitializeMimeTypeMaps();
75 98
76 // Returns IsSupported if all codec IDs in |codecs| are unambiguous 99 // Returns IsSupported if all codec IDs in |codecs| are unambiguous and are
77 // and are supported by the platform. MayBeSupported is returned if 100 // supported when contained in |mime_type_lower_case|. MayBeSupported is
78 // at least one codec ID in |codecs| is ambiguous but all the codecs 101 // returned if at least one codec ID in |codecs| is ambiguous but all the
79 // are supported by the platform. IsNotSupported is returned if at 102 // codecs are supported. IsNotSupported is returned if at least one codec ID
ddorwin 2016/02/17 21:18:39 To be absolutely clear: ... supported in |mime_typ
DaleCurtis 2016/02/18 03:58:09 Done.
80 // least one codec ID is not supported by the platform. 103 // is not supported. |is_encrypted| means the codec will be used with
104 // encrypted blocks.
81 SupportsType AreSupportedCodecs(const CodecSet& supported_codecs, 105 SupportsType AreSupportedCodecs(const CodecSet& supported_codecs,
82 const std::vector<std::string>& codecs) const; 106 const std::vector<std::string>& codecs,
107 const std::string& mime_type_lower_case,
ddorwin 2016/02/17 21:18:39 consistency nit: Elsewhere, the mime_type paramete
DaleCurtis 2016/02/18 03:58:09 I intentionally left codecs first here since that'
108 bool is_encrypted) const;
83 109
84 // Converts a codec ID into an Codec enum value and indicates 110 // Converts a codec ID into an Codec enum value and indicates
85 // whether the conversion was ambiguous. 111 // whether the conversion was ambiguous.
86 // Returns true if this method was able to map |codec_id| to a specific 112 // Returns true if this method was able to map |codec_id| to a specific
87 // Codec enum value. |codec| and |is_ambiguous| are only valid if true 113 // Codec enum value. |codec| and |is_ambiguous| are only valid if true
88 // is returned. Otherwise their value is undefined after the call. 114 // is returned. Otherwise their value is undefined after the call.
89 // |is_ambiguous| is true if |codec_id| did not have enough information to 115 // |is_ambiguous| is true if |codec_id| did not have enough information to
90 // unambiguously determine the proper Codec enum value. If |is_ambiguous| 116 // unambiguously determine the proper Codec enum value. If |is_ambiguous|
91 // is true |codec| contains the best guess for the intended Codec enum value. 117 // is true |codec| contains the best guess for the intended Codec enum value.
92 bool StringToCodec(const std::string& codec_id, 118 bool StringToCodec(const std::string& codec_id,
93 Codec* codec, 119 Codec* codec,
94 bool* is_ambiguous) const; 120 bool* is_ambiguous) const;
95 121
96 // Returns true if |codec| is supported by the platform. 122 // Returns true if |codec| is supported when contained in
97 // Note: This method will return false if the platform supports proprietary 123 // |mime_type_lower_case|. Note: This method will always return false if
98 // codecs but |allow_proprietary_codecs_| is set to false. 124 // |allow_proprietary_codecs_| is set to false. |is_encrypted| means the codec
ddorwin 2016/02/17 21:18:39 You dropped part of the text from the Note. It wil
DaleCurtis 2016/02/18 03:58:09 Yes, I intentionally dropped that since the new wo
99 bool IsCodecSupported(Codec codec) const; 125 // will be used with encrypted blocks.
126 bool IsCodecSupported(Codec codec,
127 const std::string& mime_type_lower_case,
ddorwin 2016/02/17 21:18:39 ditto on order consistency
DaleCurtis 2016/02/18 03:58:09 Acknowledged.
128 bool is_encrypted) const;
100 129
101 // Returns true if |codec| refers to a proprietary codec. 130 // Returns true if |codec| refers to a proprietary codec.
102 bool IsCodecProprietary(Codec codec) const; 131 bool IsCodecProprietary(Codec codec) const;
103 132
104 // Returns true and sets |*default_codec| if |mime_type| has a default codec 133 // Returns true and sets |*default_codec| if |mime_type| has a default codec
105 // associated with it. Returns false otherwise and the value of 134 // associated with it. Returns false otherwise and the value of
106 // |*default_codec| is undefined. 135 // |*default_codec| is undefined.
107 bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case, 136 bool GetDefaultCodecLowerCase(const std::string& mime_type_lower_case,
108 Codec* default_codec) const; 137 Codec* default_codec) const;
109 138
110 // Returns true if |mime_type_lower_case| has a default codec associated with 139 // Returns true if |mime_type_lower_case| has a default codec associated with
111 // it and IsCodecSupported() returns true for that particular codec. 140 // it and IsCodecSupported() returns true for that particular codec.
112 bool IsDefaultCodecSupportedLowerCase( 141 // |is_encrypted| means the codec will be used with encrypted blocks.
113 const std::string& mime_type_lower_case) const; 142 bool IsDefaultCodecSupportedLowerCase(const std::string& mime_type_lower_case,
143 bool is_encrypted) const;
114 144
115 #if defined(OS_ANDROID) 145 #if defined(OS_ANDROID)
116 // Checks special Android only codec restrictions. 146 // Checks special Android only codec restrictions.
117 bool IsCodecSupportedOnAndroid(Codec codec) const; 147 bool IsCodecSupportedOnAndroid(Codec codec,
148 const std::string& mime_type_lower_case,
ddorwin 2016/02/17 21:18:39 ditto on order consistency
DaleCurtis 2016/02/18 03:58:09 Acknowledged.
149 bool is_encrypted) const;
150
151 // Indicates the support of various codecs within the platform.
152 PlatformCodecInfo platform_info_;
118 #endif 153 #endif
119 154
120 // A map of mime_types and hash map of the supported codecs for the mime_type. 155 // A map of mime_types and hash map of the supported codecs for the mime_type.
121 MediaFormatMappings media_format_map_; 156 MediaFormatMappings media_format_map_;
122 157
123 // Keeps track of whether proprietary codec support should be 158 // Keeps track of whether proprietary codec support should be
124 // advertised to callers. 159 // advertised to callers.
125 bool allow_proprietary_codecs_; 160 bool allow_proprietary_codecs_;
126 161
127 // Lookup table for string compare based string -> Codec mappings. 162 // Lookup table for string compare based string -> Codec mappings.
128 StringToCodecMappings string_to_codec_map_; 163 StringToCodecMappings string_to_codec_map_;
129 164
130 DISALLOW_COPY_AND_ASSIGN(MimeUtil); 165 DISALLOW_COPY_AND_ASSIGN(MimeUtil);
131 }; 166 };
132 167
133 } // namespace internal 168 } // namespace internal
134 } // namespace media 169 } // namespace media
135 170
136 #endif // MEDIA_BASE_MIME_UTIL_INTERNAL_H_ 171 #endif // MEDIA_BASE_MIME_UTIL_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698