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_
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"
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,
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
,
49 H264PROFILE_BASELINE
= H264PROFILE_MIN
,
51 H264PROFILE_EXTENDED
= 2,
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
,
62 VP8PROFILE_ANY
= VP8PROFILE_MIN
,
63 VP8PROFILE_MAX
= VP8PROFILE_ANY
,
65 VP9PROFILE_ANY
= VP9PROFILE_MIN
,
66 VP9PROFILE_MAX
= VP9PROFILE_ANY
,
67 VIDEO_CODEC_PROFILE_MAX
= VP9PROFILE_MAX
,
70 MEDIA_EXPORT VideoCodec
71 VideoCodecProfileToVideoCodec(VideoCodecProfile profile
);
73 class MEDIA_EXPORT VideoDecoderConfig
{
75 // Constructs an uninitialized object. Clients should call Initialize() with
76 // appropriate values before using.
79 // Constructs an initialized object. It is acceptable to pass in NULL for
80 // |extra_data|, otherwise the memory is copied.
81 VideoDecoderConfig(VideoCodec codec
,
82 VideoCodecProfile profile
,
83 VideoPixelFormat format
,
84 ColorSpace color_space
,
85 const gfx::Size
& coded_size
,
86 const gfx::Rect
& visible_rect
,
87 const gfx::Size
& natural_size
,
88 const uint8
* extra_data
,
89 size_t extra_data_size
,
92 ~VideoDecoderConfig();
94 // Resets the internal state of this object.
95 void Initialize(VideoCodec codec
,
96 VideoCodecProfile profile
,
97 VideoPixelFormat format
,
98 ColorSpace color_space
,
99 const gfx::Size
& coded_size
,
100 const gfx::Rect
& visible_rect
,
101 const gfx::Size
& natural_size
,
102 const uint8
* extra_data
,
103 size_t extra_data_size
,
106 // Returns true if this object has appropriate configuration values, false
108 bool IsValidConfig() const;
110 // Returns true if all fields in |config| match this config.
111 // Note: The contents of |extra_data_| are compared not the raw pointers.
112 bool Matches(const VideoDecoderConfig
& config
) const;
114 // Returns a human-readable string describing |*this|. For debugging & test
116 std::string
AsHumanReadableString() const;
118 std::string
GetHumanReadableCodecName() const;
120 VideoCodec
codec() const { return codec_
; }
121 VideoCodecProfile
profile() const { return profile_
; }
123 // Video format used to determine YUV buffer sizes.
124 VideoPixelFormat
format() const { return format_
; }
126 // The default color space of the decoded frames. Decoders should output
127 // frames tagged with this color space unless they find a different value in
129 ColorSpace
color_space() const { return color_space_
; }
131 // Width and height of video frame immediately post-decode. Not all pixels
132 // in this region are valid.
133 gfx::Size
coded_size() const { return coded_size_
; }
135 // Region of |coded_size_| that is visible.
136 gfx::Rect
visible_rect() const { return visible_rect_
; }
138 // Final visible width and height of a video frame with aspect ratio taken
140 gfx::Size
natural_size() const { return natural_size_
; }
142 // Optional byte data required to initialize video decoders, such as H.264
144 const uint8
* extra_data() const;
145 size_t extra_data_size() const { return extra_data_
.size(); }
147 // Whether the video stream is potentially encrypted.
148 // Note that in a potentially encrypted video stream, individual buffers
149 // can be encrypted or not encrypted.
150 bool is_encrypted() const { return is_encrypted_
; }
154 VideoCodecProfile profile_
;
156 VideoPixelFormat format_
;
157 ColorSpace color_space_
;
159 gfx::Size coded_size_
;
160 gfx::Rect visible_rect_
;
161 gfx::Size natural_size_
;
163 std::vector
<uint8
> extra_data_
;
167 // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
168 // generated copy constructor and assignment operator. Since the extra data is
169 // typically small, the performance impact is minimal.
174 #endif // MEDIA_BASE_VIDEO_DECODER_CONFIG_H_