1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/fmp4/demuxer/video_decoder_config.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,159 @@ 1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "mp4_demuxer/video_decoder_config.h" 1.9 + 1.10 +#include <sstream> 1.11 +#include <string.h> 1.12 + 1.13 +namespace mp4_demuxer { 1.14 + 1.15 +VideoDecoderConfig::VideoDecoderConfig() 1.16 + : codec_(kUnknownVideoCodec), 1.17 + profile_(VIDEO_CODEC_PROFILE_UNKNOWN), 1.18 + format_(VideoFrameFormat::INVALID), 1.19 + is_encrypted_(false) { 1.20 +} 1.21 + 1.22 +VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec, 1.23 + VideoCodecProfile profile, 1.24 + VideoFrameFormat format, 1.25 + const IntSize& coded_size, 1.26 + const IntRect& visible_rect, 1.27 + const IntSize& natural_size, 1.28 + const uint8_t* extra_data, 1.29 + size_t extra_data_size, 1.30 + bool is_encrypted) { 1.31 + Initialize(codec, profile, format, coded_size, visible_rect, natural_size, 1.32 + extra_data, extra_data_size, is_encrypted, true); 1.33 +} 1.34 + 1.35 +VideoDecoderConfig::~VideoDecoderConfig() {} 1.36 + 1.37 +// Some videos just want to watch the world burn, with a height of 0; cap the 1.38 +// "infinite" aspect ratio resulting. 1.39 +static const int kInfiniteRatio = 99999; 1.40 + 1.41 +// Common aspect ratios (multiplied by 100 and truncated) used for histogramming 1.42 +// video sizes. These were taken on 20111103 from 1.43 +// http://wikipedia.org/wiki/Aspect_ratio_(image)#Previous_and_currently_used_aspect_ratios 1.44 +static const int kCommonAspectRatios100[] = { 1.45 + 100, 115, 133, 137, 143, 150, 155, 160, 166, 175, 177, 185, 200, 210, 220, 1.46 + 221, 235, 237, 240, 255, 259, 266, 276, 293, 400, 1200, kInfiniteRatio, 1.47 +}; 1.48 + 1.49 +void VideoDecoderConfig::Initialize(VideoCodec codec, 1.50 + VideoCodecProfile profile, 1.51 + VideoFrameFormat format, 1.52 + const IntSize& coded_size, 1.53 + const IntRect& visible_rect, 1.54 + const IntSize& natural_size, 1.55 + const uint8_t* extra_data, 1.56 + size_t extra_data_size, 1.57 + bool is_encrypted, 1.58 + bool record_stats) { 1.59 + CHECK((extra_data_size != 0) == (extra_data != NULL)); 1.60 + 1.61 + codec_ = codec; 1.62 + profile_ = profile; 1.63 + format_ = format; 1.64 + coded_size_ = coded_size; 1.65 + visible_rect_ = visible_rect; 1.66 + natural_size_ = natural_size; 1.67 + extra_data_.assign(extra_data, extra_data + extra_data_size); 1.68 + is_encrypted_ = is_encrypted; 1.69 +} 1.70 + 1.71 +bool VideoDecoderConfig::IsValidConfig() const { 1.72 + return codec_ != kUnknownVideoCodec && 1.73 + natural_size_.width() > 0 && 1.74 + natural_size_.height() > 0 && 1.75 + 1.76 + // Copied from: 1.77 + // VideoFrame::IsValidConfig(format_, coded_size_, visible_rect_, natural_size_) 1.78 + format_ != VideoFrameFormat::INVALID && 1.79 + !coded_size_.IsEmpty() && 1.80 + coded_size_.GetArea() <= kMaxCanvas && 1.81 + coded_size_.width() <= kMaxDimension && 1.82 + coded_size_.height() <= kMaxDimension && 1.83 + !visible_rect_.IsEmpty() && 1.84 + visible_rect_.x() >= 0 && visible_rect_.y() >= 0 && 1.85 + visible_rect_.right() <= coded_size_.width() && 1.86 + visible_rect_.bottom() <= coded_size_.height() && 1.87 + !natural_size_.IsEmpty() && 1.88 + natural_size_.GetArea() <= kMaxCanvas && 1.89 + natural_size_.width() <= kMaxDimension && 1.90 + natural_size_.height() <= kMaxDimension; 1.91 +} 1.92 + 1.93 +bool VideoDecoderConfig::Matches(const VideoDecoderConfig& config) const { 1.94 + return ((codec() == config.codec()) && 1.95 + (format() == config.format()) && 1.96 + (profile() == config.profile()) && 1.97 + (coded_size() == config.coded_size()) && 1.98 + (visible_rect() == config.visible_rect()) && 1.99 + (natural_size() == config.natural_size()) && 1.100 + (extra_data_size() == config.extra_data_size()) && 1.101 + (!extra_data() || !memcmp(extra_data(), config.extra_data(), 1.102 + extra_data_size())) && 1.103 + (is_encrypted() == config.is_encrypted())); 1.104 +} 1.105 + 1.106 +std::string VideoDecoderConfig::AsHumanReadableString() const { 1.107 + std::ostringstream s; 1.108 + s << "codec: " << codec() 1.109 + << " format: " << format() 1.110 + << " profile: " << profile() 1.111 + << " coded size: [" << coded_size().width() 1.112 + << "," << coded_size().height() << "]" 1.113 + << " visible rect: [" << visible_rect().x() 1.114 + << "," << visible_rect().y() 1.115 + << "," << visible_rect().width() 1.116 + << "," << visible_rect().height() << "]" 1.117 + << " natural size: [" << natural_size().width() 1.118 + << "," << natural_size().height() << "]" 1.119 + << " has extra data? " << (extra_data() ? "true" : "false") 1.120 + << " encrypted? " << (is_encrypted() ? "true" : "false"); 1.121 + return s.str(); 1.122 +} 1.123 + 1.124 +VideoCodec VideoDecoderConfig::codec() const { 1.125 + return codec_; 1.126 +} 1.127 + 1.128 +VideoCodecProfile VideoDecoderConfig::profile() const { 1.129 + return profile_; 1.130 +} 1.131 + 1.132 +VideoFrameFormat VideoDecoderConfig::format() const { 1.133 + return format_; 1.134 +} 1.135 + 1.136 +IntSize VideoDecoderConfig::coded_size() const { 1.137 + return coded_size_; 1.138 +} 1.139 + 1.140 +IntRect VideoDecoderConfig::visible_rect() const { 1.141 + return visible_rect_; 1.142 +} 1.143 + 1.144 +IntSize VideoDecoderConfig::natural_size() const { 1.145 + return natural_size_; 1.146 +} 1.147 + 1.148 +const uint8_t* VideoDecoderConfig::extra_data() const { 1.149 + if (extra_data_.empty()) 1.150 + return NULL; 1.151 + return &extra_data_[0]; 1.152 +} 1.153 + 1.154 +size_t VideoDecoderConfig::extra_data_size() const { 1.155 + return extra_data_.size(); 1.156 +} 1.157 + 1.158 +bool VideoDecoderConfig::is_encrypted() const { 1.159 + return is_encrypted_; 1.160 +} 1.161 + 1.162 +} // namespace mp4_demuxer