Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef MEDIA_BASE_VIDEO_DECODER_CONFIG_H_ |
michael@0 | 6 | #define MEDIA_BASE_VIDEO_DECODER_CONFIG_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include <string> |
michael@0 | 9 | #include <vector> |
michael@0 | 10 | |
michael@0 | 11 | #include "mp4_demuxer/basictypes.h" |
michael@0 | 12 | |
michael@0 | 13 | namespace mp4_demuxer { |
michael@0 | 14 | |
michael@0 | 15 | enum VideoCodec { |
michael@0 | 16 | // These values are histogrammed over time; do not change their ordinal |
michael@0 | 17 | // values. When deleting a codec replace it with a dummy value; when adding a |
michael@0 | 18 | // codec, do so at the bottom (and update kVideoCodecMax). |
michael@0 | 19 | kUnknownVideoCodec = 0, |
michael@0 | 20 | kCodecH264, |
michael@0 | 21 | kCodecVC1, |
michael@0 | 22 | kCodecMPEG2, |
michael@0 | 23 | kCodecMPEG4, |
michael@0 | 24 | kCodecTheora, |
michael@0 | 25 | kCodecVP8, |
michael@0 | 26 | kCodecVP9, |
michael@0 | 27 | // DO NOT ADD RANDOM VIDEO CODECS! |
michael@0 | 28 | // |
michael@0 | 29 | // The only acceptable time to add a new codec is if there is production code |
michael@0 | 30 | // that uses said codec in the same CL. |
michael@0 | 31 | |
michael@0 | 32 | kVideoCodecMax = kCodecVP9 // Must equal the last "real" codec above. |
michael@0 | 33 | }; |
michael@0 | 34 | |
michael@0 | 35 | // Video stream profile. This *must* match PP_VideoDecoder_Profile. |
michael@0 | 36 | // (enforced in webkit/plugins/ppapi/ppb_video_decoder_impl.cc) |
michael@0 | 37 | enum VideoCodecProfile { |
michael@0 | 38 | // Keep the values in this enum unique, as they imply format (h.264 vs. VP8, |
michael@0 | 39 | // for example), and keep the values for a particular format grouped |
michael@0 | 40 | // together for clarity. |
michael@0 | 41 | VIDEO_CODEC_PROFILE_UNKNOWN = -1, |
michael@0 | 42 | H264PROFILE_MIN = 0, |
michael@0 | 43 | H264PROFILE_BASELINE = H264PROFILE_MIN, |
michael@0 | 44 | H264PROFILE_MAIN = 1, |
michael@0 | 45 | H264PROFILE_EXTENDED = 2, |
michael@0 | 46 | H264PROFILE_HIGH = 3, |
michael@0 | 47 | H264PROFILE_HIGH10PROFILE = 4, |
michael@0 | 48 | H264PROFILE_HIGH422PROFILE = 5, |
michael@0 | 49 | H264PROFILE_HIGH444PREDICTIVEPROFILE = 6, |
michael@0 | 50 | H264PROFILE_SCALABLEBASELINE = 7, |
michael@0 | 51 | H264PROFILE_SCALABLEHIGH = 8, |
michael@0 | 52 | H264PROFILE_STEREOHIGH = 9, |
michael@0 | 53 | H264PROFILE_MULTIVIEWHIGH = 10, |
michael@0 | 54 | H264PROFILE_MAX = H264PROFILE_MULTIVIEWHIGH, |
michael@0 | 55 | VP8PROFILE_MIN = 11, |
michael@0 | 56 | VP8PROFILE_MAIN = VP8PROFILE_MIN, |
michael@0 | 57 | VP8PROFILE_MAX = VP8PROFILE_MAIN, |
michael@0 | 58 | VP9PROFILE_MIN = 12, |
michael@0 | 59 | VP9PROFILE_MAIN = VP9PROFILE_MIN, |
michael@0 | 60 | VP9PROFILE_MAX = VP9PROFILE_MAIN, |
michael@0 | 61 | VIDEO_CODEC_PROFILE_MAX = VP9PROFILE_MAX, |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | // Surface formats roughly based on FOURCC labels, see: |
michael@0 | 65 | // http://www.fourcc.org/rgb.php |
michael@0 | 66 | // http://www.fourcc.org/yuv.php |
michael@0 | 67 | enum VideoFrameFormat { // VideoFrame::Format |
michael@0 | 68 | INVALID = 0, // Invalid format value. Used for error reporting. |
michael@0 | 69 | RGB32 = 4, // 32bpp RGB packed with extra byte 8:8:8 |
michael@0 | 70 | YV12 = 6, // 12bpp YVU planar 1x1 Y, 2x2 VU samples |
michael@0 | 71 | YV16 = 7, // 16bpp YVU planar 1x1 Y, 2x1 VU samples |
michael@0 | 72 | EMPTY = 9, // An empty frame. |
michael@0 | 73 | I420 = 11, // 12bpp YVU planar 1x1 Y, 2x2 UV samples. |
michael@0 | 74 | NATIVE_TEXTURE = 12, // Native texture. Pixel-format agnostic. |
michael@0 | 75 | #if defined(GOOGLE_TV) |
michael@0 | 76 | HOLE = 13, // Hole frame. |
michael@0 | 77 | #endif |
michael@0 | 78 | YV12A = 14, // 20bpp YUVA planar 1x1 Y, 2x2 VU, 1x1 A samples. |
michael@0 | 79 | }; |
michael@0 | 80 | |
michael@0 | 81 | class VideoDecoderConfig { |
michael@0 | 82 | public: |
michael@0 | 83 | // Constructs an uninitialized object. Clients should call Initialize() with |
michael@0 | 84 | // appropriate values before using. |
michael@0 | 85 | VideoDecoderConfig(); |
michael@0 | 86 | |
michael@0 | 87 | // Constructs an initialized object. It is acceptable to pass in NULL for |
michael@0 | 88 | // |extra_data|, otherwise the memory is copied. |
michael@0 | 89 | VideoDecoderConfig(VideoCodec codec, |
michael@0 | 90 | VideoCodecProfile profile, |
michael@0 | 91 | VideoFrameFormat format, |
michael@0 | 92 | const IntSize& coded_size, |
michael@0 | 93 | const IntRect& visible_rect, |
michael@0 | 94 | const IntSize& natural_size, |
michael@0 | 95 | const uint8_t* extra_data, size_t extra_data_size, |
michael@0 | 96 | bool is_encrypted); |
michael@0 | 97 | |
michael@0 | 98 | ~VideoDecoderConfig(); |
michael@0 | 99 | |
michael@0 | 100 | // Resets the internal state of this object. |
michael@0 | 101 | void Initialize(VideoCodec codec, |
michael@0 | 102 | VideoCodecProfile profile, |
michael@0 | 103 | VideoFrameFormat format, |
michael@0 | 104 | const IntSize& coded_size, |
michael@0 | 105 | const IntRect& visible_rect, |
michael@0 | 106 | const IntSize& natural_size, |
michael@0 | 107 | const uint8_t* extra_data, size_t extra_data_size, |
michael@0 | 108 | bool is_encrypted, |
michael@0 | 109 | bool record_stats); |
michael@0 | 110 | |
michael@0 | 111 | // Returns true if this object has appropriate configuration values, false |
michael@0 | 112 | // otherwise. |
michael@0 | 113 | bool IsValidConfig() const; |
michael@0 | 114 | |
michael@0 | 115 | // Returns true if all fields in |config| match this config. |
michael@0 | 116 | // Note: The contents of |extra_data_| are compared not the raw pointers. |
michael@0 | 117 | bool Matches(const VideoDecoderConfig& config) const; |
michael@0 | 118 | |
michael@0 | 119 | // Returns a human-readable string describing |*this|. For debugging & test |
michael@0 | 120 | // output only. |
michael@0 | 121 | std::string AsHumanReadableString() const; |
michael@0 | 122 | |
michael@0 | 123 | VideoCodec codec() const; |
michael@0 | 124 | VideoCodecProfile profile() const; |
michael@0 | 125 | |
michael@0 | 126 | // Video format used to determine YUV buffer sizes. |
michael@0 | 127 | VideoFrameFormat format() const; |
michael@0 | 128 | |
michael@0 | 129 | // Width and height of video frame immediately post-decode. Not all pixels |
michael@0 | 130 | // in this region are valid. |
michael@0 | 131 | IntSize coded_size() const; |
michael@0 | 132 | |
michael@0 | 133 | // Region of |coded_size_| that is visible. |
michael@0 | 134 | IntRect visible_rect() const; |
michael@0 | 135 | |
michael@0 | 136 | // Final visible width and height of a video frame with aspect ratio taken |
michael@0 | 137 | // into account. |
michael@0 | 138 | IntSize natural_size() const; |
michael@0 | 139 | |
michael@0 | 140 | // Optional byte data required to initialize video decoders, such as H.264 |
michael@0 | 141 | // AAVC data. |
michael@0 | 142 | const uint8_t* extra_data() const; |
michael@0 | 143 | size_t extra_data_size() const; |
michael@0 | 144 | |
michael@0 | 145 | // Whether the video stream is potentially encrypted. |
michael@0 | 146 | // Note that in a potentially encrypted video stream, individual buffers |
michael@0 | 147 | // can be encrypted or not encrypted. |
michael@0 | 148 | bool is_encrypted() const; |
michael@0 | 149 | |
michael@0 | 150 | private: |
michael@0 | 151 | VideoCodec codec_; |
michael@0 | 152 | VideoCodecProfile profile_; |
michael@0 | 153 | |
michael@0 | 154 | VideoFrameFormat format_; |
michael@0 | 155 | |
michael@0 | 156 | IntSize coded_size_; |
michael@0 | 157 | IntRect visible_rect_; |
michael@0 | 158 | IntSize natural_size_; |
michael@0 | 159 | |
michael@0 | 160 | std::vector<uint8_t> extra_data_; |
michael@0 | 161 | |
michael@0 | 162 | bool is_encrypted_; |
michael@0 | 163 | |
michael@0 | 164 | // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler |
michael@0 | 165 | // generated copy constructor and assignment operator. Since the extra data is |
michael@0 | 166 | // typically small, the performance impact is minimal. |
michael@0 | 167 | }; |
michael@0 | 168 | |
michael@0 | 169 | } // namespace mp4_demuxer |
michael@0 | 170 | |
michael@0 | 171 | #endif // MEDIA_BASE_VIDEO_DECODER_CONFIG_H_ |