Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / media / base / video_decoder_config.h
blob356b467f640f0732e7ccdef62a8c6cda3f818788
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_frame.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 // DO NOT ADD RANDOM VIDEO CODECS!
33 // The only acceptable time to add a new codec is if there is production code
34 // that uses said codec in the same CL.
36 kVideoCodecMax = kCodecVP9 // Must equal the last "real" codec above.
39 // Video stream profile. This *must* match PP_VideoDecoder_Profile.
40 // (enforced in webkit/plugins/ppapi/ppb_video_decoder_impl.cc) and
41 // gpu::VideoCodecProfile.
42 enum VideoCodecProfile {
43 // Keep the values in this enum unique, as they imply format (h.264 vs. VP8,
44 // for example), and keep the values for a particular format grouped
45 // together for clarity.
46 VIDEO_CODEC_PROFILE_UNKNOWN = -1,
47 VIDEO_CODEC_PROFILE_MIN = VIDEO_CODEC_PROFILE_UNKNOWN,
48 H264PROFILE_MIN = 0,
49 H264PROFILE_BASELINE = H264PROFILE_MIN,
50 H264PROFILE_MAIN = 1,
51 H264PROFILE_EXTENDED = 2,
52 H264PROFILE_HIGH = 3,
53 H264PROFILE_HIGH10PROFILE = 4,
54 H264PROFILE_HIGH422PROFILE = 5,
55 H264PROFILE_HIGH444PREDICTIVEPROFILE = 6,
56 H264PROFILE_SCALABLEBASELINE = 7,
57 H264PROFILE_SCALABLEHIGH = 8,
58 H264PROFILE_STEREOHIGH = 9,
59 H264PROFILE_MULTIVIEWHIGH = 10,
60 H264PROFILE_MAX = H264PROFILE_MULTIVIEWHIGH,
61 VP8PROFILE_MIN = 11,
62 VP8PROFILE_ANY = VP8PROFILE_MIN,
63 VP8PROFILE_MAX = VP8PROFILE_ANY,
64 VP9PROFILE_MIN = 12,
65 VP9PROFILE_ANY = VP9PROFILE_MIN,
66 VP9PROFILE_MAX = VP9PROFILE_ANY,
67 VIDEO_CODEC_PROFILE_MAX = VP9PROFILE_MAX,
70 class MEDIA_EXPORT VideoDecoderConfig {
71 public:
72 // Constructs an uninitialized object. Clients should call Initialize() with
73 // appropriate values before using.
74 VideoDecoderConfig();
76 // Constructs an initialized object. It is acceptable to pass in NULL for
77 // |extra_data|, otherwise the memory is copied.
78 VideoDecoderConfig(VideoCodec codec,
79 VideoCodecProfile profile,
80 VideoFrame::Format format,
81 const gfx::Size& coded_size,
82 const gfx::Rect& visible_rect,
83 const gfx::Size& natural_size,
84 const uint8* extra_data, size_t extra_data_size,
85 bool is_encrypted);
87 ~VideoDecoderConfig();
89 // Resets the internal state of this object.
90 void Initialize(VideoCodec codec,
91 VideoCodecProfile profile,
92 VideoFrame::Format format,
93 const gfx::Size& coded_size,
94 const gfx::Rect& visible_rect,
95 const gfx::Size& natural_size,
96 const uint8* extra_data, size_t extra_data_size,
97 bool is_encrypted,
98 bool record_stats);
100 // Returns true if this object has appropriate configuration values, false
101 // otherwise.
102 bool IsValidConfig() const;
104 // Returns true if all fields in |config| match this config.
105 // Note: The contents of |extra_data_| are compared not the raw pointers.
106 bool Matches(const VideoDecoderConfig& config) const;
108 // Returns a human-readable string describing |*this|. For debugging & test
109 // output only.
110 std::string AsHumanReadableString() const;
112 std::string GetHumanReadableCodecName() const;
114 VideoCodec codec() const;
115 VideoCodecProfile profile() const;
117 // Video format used to determine YUV buffer sizes.
118 VideoFrame::Format format() const;
120 // Width and height of video frame immediately post-decode. Not all pixels
121 // in this region are valid.
122 gfx::Size coded_size() const;
124 // Region of |coded_size_| that is visible.
125 gfx::Rect visible_rect() const;
127 // Final visible width and height of a video frame with aspect ratio taken
128 // into account.
129 gfx::Size natural_size() const;
131 // Optional byte data required to initialize video decoders, such as H.264
132 // AAVC data.
133 const uint8* extra_data() const;
134 size_t extra_data_size() const;
136 // Whether the video stream is potentially encrypted.
137 // Note that in a potentially encrypted video stream, individual buffers
138 // can be encrypted or not encrypted.
139 bool is_encrypted() const;
141 private:
142 VideoCodec codec_;
143 VideoCodecProfile profile_;
145 VideoFrame::Format format_;
147 gfx::Size coded_size_;
148 gfx::Rect visible_rect_;
149 gfx::Size natural_size_;
151 std::vector<uint8> extra_data_;
153 bool is_encrypted_;
155 // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
156 // generated copy constructor and assignment operator. Since the extra data is
157 // typically small, the performance impact is minimal.
160 } // namespace media
162 #endif // MEDIA_BASE_VIDEO_DECODER_CONFIG_H_