Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / media / base / video_decoder_config.h
blobabc1de8de53b37aa920eb30a1a1acc0997c00e61
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_BASE_VIDEO_DECODER_CONFIG_H_
6 #define MEDIA_BASE_VIDEO_DECODER_CONFIG_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "media/base/media_export.h"
13 #include "media/base/video_types.h"
14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/geometry/size.h"
17 namespace media {
19 enum VideoCodec {
20 // These values are histogrammed over time; do not change their ordinal
21 // values. When deleting a codec replace it with a dummy value; when adding a
22 // codec, do so at the bottom (and update kVideoCodecMax).
23 kUnknownVideoCodec = 0,
24 kCodecH264,
25 kCodecVC1,
26 kCodecMPEG2,
27 kCodecMPEG4,
28 kCodecTheora,
29 kCodecVP8,
30 kCodecVP9,
31 kCodecHEVC,
32 // DO NOT ADD RANDOM VIDEO CODECS!
34 // The only acceptable time to add a new codec is if there is production code
35 // that uses said codec in the same CL.
37 kVideoCodecMax = kCodecHEVC // Must equal the last "real" codec above.
40 // Video stream profile. This *must* match PP_VideoDecoder_Profile.
41 // (enforced in webkit/plugins/ppapi/ppb_video_decoder_impl.cc) and
42 // gpu::VideoCodecProfile.
43 enum VideoCodecProfile {
44 // Keep the values in this enum unique, as they imply format (h.264 vs. VP8,
45 // for example), and keep the values for a particular format grouped
46 // together for clarity.
47 VIDEO_CODEC_PROFILE_UNKNOWN = -1,
48 VIDEO_CODEC_PROFILE_MIN = VIDEO_CODEC_PROFILE_UNKNOWN,
49 H264PROFILE_MIN = 0,
50 H264PROFILE_BASELINE = H264PROFILE_MIN,
51 H264PROFILE_MAIN = 1,
52 H264PROFILE_EXTENDED = 2,
53 H264PROFILE_HIGH = 3,
54 H264PROFILE_HIGH10PROFILE = 4,
55 H264PROFILE_HIGH422PROFILE = 5,
56 H264PROFILE_HIGH444PREDICTIVEPROFILE = 6,
57 H264PROFILE_SCALABLEBASELINE = 7,
58 H264PROFILE_SCALABLEHIGH = 8,
59 H264PROFILE_STEREOHIGH = 9,
60 H264PROFILE_MULTIVIEWHIGH = 10,
61 H264PROFILE_MAX = H264PROFILE_MULTIVIEWHIGH,
62 VP8PROFILE_MIN = 11,
63 VP8PROFILE_ANY = VP8PROFILE_MIN,
64 VP8PROFILE_MAX = VP8PROFILE_ANY,
65 VP9PROFILE_MIN = 12,
66 VP9PROFILE_ANY = VP9PROFILE_MIN,
67 VP9PROFILE_MAX = VP9PROFILE_ANY,
68 VIDEO_CODEC_PROFILE_MAX = VP9PROFILE_MAX,
71 MEDIA_EXPORT VideoCodec
72 VideoCodecProfileToVideoCodec(VideoCodecProfile profile);
74 class MEDIA_EXPORT VideoDecoderConfig {
75 public:
76 // Constructs an uninitialized object. Clients should call Initialize() with
77 // appropriate values before using.
78 VideoDecoderConfig();
80 // Constructs an initialized object. It is acceptable to pass in NULL for
81 // |extra_data|, otherwise the memory is copied.
82 VideoDecoderConfig(VideoCodec codec,
83 VideoCodecProfile profile,
84 VideoPixelFormat format,
85 ColorSpace color_space,
86 const gfx::Size& coded_size,
87 const gfx::Rect& visible_rect,
88 const gfx::Size& natural_size,
89 const uint8* extra_data,
90 size_t extra_data_size,
91 bool is_encrypted);
93 ~VideoDecoderConfig();
95 // Resets the internal state of this object.
96 void Initialize(VideoCodec codec,
97 VideoCodecProfile profile,
98 VideoPixelFormat format,
99 ColorSpace color_space,
100 const gfx::Size& coded_size,
101 const gfx::Rect& visible_rect,
102 const gfx::Size& natural_size,
103 const uint8* extra_data,
104 size_t extra_data_size,
105 bool is_encrypted);
107 // Returns true if this object has appropriate configuration values, false
108 // otherwise.
109 bool IsValidConfig() const;
111 // Returns true if all fields in |config| match this config.
112 // Note: The contents of |extra_data_| are compared not the raw pointers.
113 bool Matches(const VideoDecoderConfig& config) const;
115 // Returns a human-readable string describing |*this|. For debugging & test
116 // output only.
117 std::string AsHumanReadableString() const;
119 std::string GetHumanReadableCodecName() const;
121 VideoCodec codec() const { return codec_; }
122 VideoCodecProfile profile() const { return profile_; }
124 // Video format used to determine YUV buffer sizes.
125 VideoPixelFormat format() const { return format_; }
127 // The default color space of the decoded frames. Decoders should output
128 // frames tagged with this color space unless they find a different value in
129 // the bitstream.
130 ColorSpace color_space() const { return color_space_; }
132 // Width and height of video frame immediately post-decode. Not all pixels
133 // in this region are valid.
134 gfx::Size coded_size() const { return coded_size_; }
136 // Region of |coded_size_| that is visible.
137 gfx::Rect visible_rect() const { return visible_rect_; }
139 // Final visible width and height of a video frame with aspect ratio taken
140 // into account.
141 gfx::Size natural_size() const { return natural_size_; }
143 // Optional byte data required to initialize video decoders, such as H.264
144 // AAVC data.
145 const uint8* extra_data() const;
146 size_t extra_data_size() const { return extra_data_.size(); }
148 // Whether the video stream is potentially encrypted.
149 // Note that in a potentially encrypted video stream, individual buffers
150 // can be encrypted or not encrypted.
151 bool is_encrypted() const { return is_encrypted_; }
153 private:
154 VideoCodec codec_;
155 VideoCodecProfile profile_;
157 VideoPixelFormat format_;
158 ColorSpace color_space_;
160 gfx::Size coded_size_;
161 gfx::Rect visible_rect_;
162 gfx::Size natural_size_;
164 std::vector<uint8> extra_data_;
166 bool is_encrypted_;
168 // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
169 // generated copy constructor and assignment operator. Since the extra data is
170 // typically small, the performance impact is minimal.
173 } // namespace media
175 #endif // MEDIA_BASE_VIDEO_DECODER_CONFIG_H_