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