michael@0: // Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef MEDIA_BASE_VIDEO_DECODER_CONFIG_H_ michael@0: #define MEDIA_BASE_VIDEO_DECODER_CONFIG_H_ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "mp4_demuxer/basictypes.h" michael@0: michael@0: namespace mp4_demuxer { michael@0: michael@0: enum VideoCodec { michael@0: // These values are histogrammed over time; do not change their ordinal michael@0: // values. When deleting a codec replace it with a dummy value; when adding a michael@0: // codec, do so at the bottom (and update kVideoCodecMax). michael@0: kUnknownVideoCodec = 0, michael@0: kCodecH264, michael@0: kCodecVC1, michael@0: kCodecMPEG2, michael@0: kCodecMPEG4, michael@0: kCodecTheora, michael@0: kCodecVP8, michael@0: kCodecVP9, michael@0: // DO NOT ADD RANDOM VIDEO CODECS! michael@0: // michael@0: // The only acceptable time to add a new codec is if there is production code michael@0: // that uses said codec in the same CL. michael@0: michael@0: kVideoCodecMax = kCodecVP9 // Must equal the last "real" codec above. michael@0: }; michael@0: michael@0: // Video stream profile. This *must* match PP_VideoDecoder_Profile. michael@0: // (enforced in webkit/plugins/ppapi/ppb_video_decoder_impl.cc) michael@0: enum VideoCodecProfile { michael@0: // Keep the values in this enum unique, as they imply format (h.264 vs. VP8, michael@0: // for example), and keep the values for a particular format grouped michael@0: // together for clarity. michael@0: VIDEO_CODEC_PROFILE_UNKNOWN = -1, michael@0: H264PROFILE_MIN = 0, michael@0: H264PROFILE_BASELINE = H264PROFILE_MIN, michael@0: H264PROFILE_MAIN = 1, michael@0: H264PROFILE_EXTENDED = 2, michael@0: H264PROFILE_HIGH = 3, michael@0: H264PROFILE_HIGH10PROFILE = 4, michael@0: H264PROFILE_HIGH422PROFILE = 5, michael@0: H264PROFILE_HIGH444PREDICTIVEPROFILE = 6, michael@0: H264PROFILE_SCALABLEBASELINE = 7, michael@0: H264PROFILE_SCALABLEHIGH = 8, michael@0: H264PROFILE_STEREOHIGH = 9, michael@0: H264PROFILE_MULTIVIEWHIGH = 10, michael@0: H264PROFILE_MAX = H264PROFILE_MULTIVIEWHIGH, michael@0: VP8PROFILE_MIN = 11, michael@0: VP8PROFILE_MAIN = VP8PROFILE_MIN, michael@0: VP8PROFILE_MAX = VP8PROFILE_MAIN, michael@0: VP9PROFILE_MIN = 12, michael@0: VP9PROFILE_MAIN = VP9PROFILE_MIN, michael@0: VP9PROFILE_MAX = VP9PROFILE_MAIN, michael@0: VIDEO_CODEC_PROFILE_MAX = VP9PROFILE_MAX, michael@0: }; michael@0: michael@0: // Surface formats roughly based on FOURCC labels, see: michael@0: // http://www.fourcc.org/rgb.php michael@0: // http://www.fourcc.org/yuv.php michael@0: enum VideoFrameFormat { // VideoFrame::Format michael@0: INVALID = 0, // Invalid format value. Used for error reporting. michael@0: RGB32 = 4, // 32bpp RGB packed with extra byte 8:8:8 michael@0: YV12 = 6, // 12bpp YVU planar 1x1 Y, 2x2 VU samples michael@0: YV16 = 7, // 16bpp YVU planar 1x1 Y, 2x1 VU samples michael@0: EMPTY = 9, // An empty frame. michael@0: I420 = 11, // 12bpp YVU planar 1x1 Y, 2x2 UV samples. michael@0: NATIVE_TEXTURE = 12, // Native texture. Pixel-format agnostic. michael@0: #if defined(GOOGLE_TV) michael@0: HOLE = 13, // Hole frame. michael@0: #endif michael@0: YV12A = 14, // 20bpp YUVA planar 1x1 Y, 2x2 VU, 1x1 A samples. michael@0: }; michael@0: michael@0: class VideoDecoderConfig { michael@0: public: michael@0: // Constructs an uninitialized object. Clients should call Initialize() with michael@0: // appropriate values before using. michael@0: VideoDecoderConfig(); michael@0: michael@0: // Constructs an initialized object. It is acceptable to pass in NULL for michael@0: // |extra_data|, otherwise the memory is copied. michael@0: VideoDecoderConfig(VideoCodec codec, michael@0: VideoCodecProfile profile, michael@0: VideoFrameFormat format, michael@0: const IntSize& coded_size, michael@0: const IntRect& visible_rect, michael@0: const IntSize& natural_size, michael@0: const uint8_t* extra_data, size_t extra_data_size, michael@0: bool is_encrypted); michael@0: michael@0: ~VideoDecoderConfig(); michael@0: michael@0: // Resets the internal state of this object. michael@0: void Initialize(VideoCodec codec, michael@0: VideoCodecProfile profile, michael@0: VideoFrameFormat format, michael@0: const IntSize& coded_size, michael@0: const IntRect& visible_rect, michael@0: const IntSize& natural_size, michael@0: const uint8_t* extra_data, size_t extra_data_size, michael@0: bool is_encrypted, michael@0: bool record_stats); michael@0: michael@0: // Returns true if this object has appropriate configuration values, false michael@0: // otherwise. michael@0: bool IsValidConfig() const; michael@0: michael@0: // Returns true if all fields in |config| match this config. michael@0: // Note: The contents of |extra_data_| are compared not the raw pointers. michael@0: bool Matches(const VideoDecoderConfig& config) const; michael@0: michael@0: // Returns a human-readable string describing |*this|. For debugging & test michael@0: // output only. michael@0: std::string AsHumanReadableString() const; michael@0: michael@0: VideoCodec codec() const; michael@0: VideoCodecProfile profile() const; michael@0: michael@0: // Video format used to determine YUV buffer sizes. michael@0: VideoFrameFormat format() const; michael@0: michael@0: // Width and height of video frame immediately post-decode. Not all pixels michael@0: // in this region are valid. michael@0: IntSize coded_size() const; michael@0: michael@0: // Region of |coded_size_| that is visible. michael@0: IntRect visible_rect() const; michael@0: michael@0: // Final visible width and height of a video frame with aspect ratio taken michael@0: // into account. michael@0: IntSize natural_size() const; michael@0: michael@0: // Optional byte data required to initialize video decoders, such as H.264 michael@0: // AAVC data. michael@0: const uint8_t* extra_data() const; michael@0: size_t extra_data_size() const; michael@0: michael@0: // Whether the video stream is potentially encrypted. michael@0: // Note that in a potentially encrypted video stream, individual buffers michael@0: // can be encrypted or not encrypted. michael@0: bool is_encrypted() const; michael@0: michael@0: private: michael@0: VideoCodec codec_; michael@0: VideoCodecProfile profile_; michael@0: michael@0: VideoFrameFormat format_; michael@0: michael@0: IntSize coded_size_; michael@0: IntRect visible_rect_; michael@0: IntSize natural_size_; michael@0: michael@0: std::vector extra_data_; michael@0: michael@0: bool is_encrypted_; michael@0: michael@0: // Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler michael@0: // generated copy constructor and assignment operator. Since the extra data is michael@0: // typically small, the performance impact is minimal. michael@0: }; michael@0: michael@0: } // namespace mp4_demuxer michael@0: michael@0: #endif // MEDIA_BASE_VIDEO_DECODER_CONFIG_H_