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: #include "mp4_demuxer/video_decoder_config.h" michael@0: michael@0: #include michael@0: #include michael@0: michael@0: namespace mp4_demuxer { michael@0: michael@0: VideoDecoderConfig::VideoDecoderConfig() michael@0: : codec_(kUnknownVideoCodec), michael@0: profile_(VIDEO_CODEC_PROFILE_UNKNOWN), michael@0: format_(VideoFrameFormat::INVALID), michael@0: is_encrypted_(false) { michael@0: } michael@0: michael@0: VideoDecoderConfig::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, michael@0: size_t extra_data_size, michael@0: bool is_encrypted) { michael@0: Initialize(codec, profile, format, coded_size, visible_rect, natural_size, michael@0: extra_data, extra_data_size, is_encrypted, true); michael@0: } michael@0: michael@0: VideoDecoderConfig::~VideoDecoderConfig() {} michael@0: michael@0: // Some videos just want to watch the world burn, with a height of 0; cap the michael@0: // "infinite" aspect ratio resulting. michael@0: static const int kInfiniteRatio = 99999; michael@0: michael@0: // Common aspect ratios (multiplied by 100 and truncated) used for histogramming michael@0: // video sizes. These were taken on 20111103 from michael@0: // http://wikipedia.org/wiki/Aspect_ratio_(image)#Previous_and_currently_used_aspect_ratios michael@0: static const int kCommonAspectRatios100[] = { michael@0: 100, 115, 133, 137, 143, 150, 155, 160, 166, 175, 177, 185, 200, 210, 220, michael@0: 221, 235, 237, 240, 255, 259, 266, 276, 293, 400, 1200, kInfiniteRatio, michael@0: }; michael@0: michael@0: void VideoDecoderConfig::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, michael@0: size_t extra_data_size, michael@0: bool is_encrypted, michael@0: bool record_stats) { michael@0: CHECK((extra_data_size != 0) == (extra_data != NULL)); michael@0: michael@0: codec_ = codec; michael@0: profile_ = profile; michael@0: format_ = format; michael@0: coded_size_ = coded_size; michael@0: visible_rect_ = visible_rect; michael@0: natural_size_ = natural_size; michael@0: extra_data_.assign(extra_data, extra_data + extra_data_size); michael@0: is_encrypted_ = is_encrypted; michael@0: } michael@0: michael@0: bool VideoDecoderConfig::IsValidConfig() const { michael@0: return codec_ != kUnknownVideoCodec && michael@0: natural_size_.width() > 0 && michael@0: natural_size_.height() > 0 && michael@0: michael@0: // Copied from: michael@0: // VideoFrame::IsValidConfig(format_, coded_size_, visible_rect_, natural_size_) michael@0: format_ != VideoFrameFormat::INVALID && michael@0: !coded_size_.IsEmpty() && michael@0: coded_size_.GetArea() <= kMaxCanvas && michael@0: coded_size_.width() <= kMaxDimension && michael@0: coded_size_.height() <= kMaxDimension && michael@0: !visible_rect_.IsEmpty() && michael@0: visible_rect_.x() >= 0 && visible_rect_.y() >= 0 && michael@0: visible_rect_.right() <= coded_size_.width() && michael@0: visible_rect_.bottom() <= coded_size_.height() && michael@0: !natural_size_.IsEmpty() && michael@0: natural_size_.GetArea() <= kMaxCanvas && michael@0: natural_size_.width() <= kMaxDimension && michael@0: natural_size_.height() <= kMaxDimension; michael@0: } michael@0: michael@0: bool VideoDecoderConfig::Matches(const VideoDecoderConfig& config) const { michael@0: return ((codec() == config.codec()) && michael@0: (format() == config.format()) && michael@0: (profile() == config.profile()) && michael@0: (coded_size() == config.coded_size()) && michael@0: (visible_rect() == config.visible_rect()) && michael@0: (natural_size() == config.natural_size()) && michael@0: (extra_data_size() == config.extra_data_size()) && michael@0: (!extra_data() || !memcmp(extra_data(), config.extra_data(), michael@0: extra_data_size())) && michael@0: (is_encrypted() == config.is_encrypted())); michael@0: } michael@0: michael@0: std::string VideoDecoderConfig::AsHumanReadableString() const { michael@0: std::ostringstream s; michael@0: s << "codec: " << codec() michael@0: << " format: " << format() michael@0: << " profile: " << profile() michael@0: << " coded size: [" << coded_size().width() michael@0: << "," << coded_size().height() << "]" michael@0: << " visible rect: [" << visible_rect().x() michael@0: << "," << visible_rect().y() michael@0: << "," << visible_rect().width() michael@0: << "," << visible_rect().height() << "]" michael@0: << " natural size: [" << natural_size().width() michael@0: << "," << natural_size().height() << "]" michael@0: << " has extra data? " << (extra_data() ? "true" : "false") michael@0: << " encrypted? " << (is_encrypted() ? "true" : "false"); michael@0: return s.str(); michael@0: } michael@0: michael@0: VideoCodec VideoDecoderConfig::codec() const { michael@0: return codec_; michael@0: } michael@0: michael@0: VideoCodecProfile VideoDecoderConfig::profile() const { michael@0: return profile_; michael@0: } michael@0: michael@0: VideoFrameFormat VideoDecoderConfig::format() const { michael@0: return format_; michael@0: } michael@0: michael@0: IntSize VideoDecoderConfig::coded_size() const { michael@0: return coded_size_; michael@0: } michael@0: michael@0: IntRect VideoDecoderConfig::visible_rect() const { michael@0: return visible_rect_; michael@0: } michael@0: michael@0: IntSize VideoDecoderConfig::natural_size() const { michael@0: return natural_size_; michael@0: } michael@0: michael@0: const uint8_t* VideoDecoderConfig::extra_data() const { michael@0: if (extra_data_.empty()) michael@0: return NULL; michael@0: return &extra_data_[0]; michael@0: } michael@0: michael@0: size_t VideoDecoderConfig::extra_data_size() const { michael@0: return extra_data_.size(); michael@0: } michael@0: michael@0: bool VideoDecoderConfig::is_encrypted() const { michael@0: return is_encrypted_; michael@0: } michael@0: michael@0: } // namespace mp4_demuxer