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