content/media/fmp4/demuxer/video_decoder_config.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 #include "mp4_demuxer/video_decoder_config.h"
michael@0 6
michael@0 7 #include <sstream>
michael@0 8 #include <string.h>
michael@0 9
michael@0 10 namespace mp4_demuxer {
michael@0 11
michael@0 12 VideoDecoderConfig::VideoDecoderConfig()
michael@0 13 : codec_(kUnknownVideoCodec),
michael@0 14 profile_(VIDEO_CODEC_PROFILE_UNKNOWN),
michael@0 15 format_(VideoFrameFormat::INVALID),
michael@0 16 is_encrypted_(false) {
michael@0 17 }
michael@0 18
michael@0 19 VideoDecoderConfig::VideoDecoderConfig(VideoCodec codec,
michael@0 20 VideoCodecProfile profile,
michael@0 21 VideoFrameFormat format,
michael@0 22 const IntSize& coded_size,
michael@0 23 const IntRect& visible_rect,
michael@0 24 const IntSize& natural_size,
michael@0 25 const uint8_t* extra_data,
michael@0 26 size_t extra_data_size,
michael@0 27 bool is_encrypted) {
michael@0 28 Initialize(codec, profile, format, coded_size, visible_rect, natural_size,
michael@0 29 extra_data, extra_data_size, is_encrypted, true);
michael@0 30 }
michael@0 31
michael@0 32 VideoDecoderConfig::~VideoDecoderConfig() {}
michael@0 33
michael@0 34 // Some videos just want to watch the world burn, with a height of 0; cap the
michael@0 35 // "infinite" aspect ratio resulting.
michael@0 36 static const int kInfiniteRatio = 99999;
michael@0 37
michael@0 38 // Common aspect ratios (multiplied by 100 and truncated) used for histogramming
michael@0 39 // video sizes. These were taken on 20111103 from
michael@0 40 // http://wikipedia.org/wiki/Aspect_ratio_(image)#Previous_and_currently_used_aspect_ratios
michael@0 41 static const int kCommonAspectRatios100[] = {
michael@0 42 100, 115, 133, 137, 143, 150, 155, 160, 166, 175, 177, 185, 200, 210, 220,
michael@0 43 221, 235, 237, 240, 255, 259, 266, 276, 293, 400, 1200, kInfiniteRatio,
michael@0 44 };
michael@0 45
michael@0 46 void VideoDecoderConfig::Initialize(VideoCodec codec,
michael@0 47 VideoCodecProfile profile,
michael@0 48 VideoFrameFormat format,
michael@0 49 const IntSize& coded_size,
michael@0 50 const IntRect& visible_rect,
michael@0 51 const IntSize& natural_size,
michael@0 52 const uint8_t* extra_data,
michael@0 53 size_t extra_data_size,
michael@0 54 bool is_encrypted,
michael@0 55 bool record_stats) {
michael@0 56 CHECK((extra_data_size != 0) == (extra_data != NULL));
michael@0 57
michael@0 58 codec_ = codec;
michael@0 59 profile_ = profile;
michael@0 60 format_ = format;
michael@0 61 coded_size_ = coded_size;
michael@0 62 visible_rect_ = visible_rect;
michael@0 63 natural_size_ = natural_size;
michael@0 64 extra_data_.assign(extra_data, extra_data + extra_data_size);
michael@0 65 is_encrypted_ = is_encrypted;
michael@0 66 }
michael@0 67
michael@0 68 bool VideoDecoderConfig::IsValidConfig() const {
michael@0 69 return codec_ != kUnknownVideoCodec &&
michael@0 70 natural_size_.width() > 0 &&
michael@0 71 natural_size_.height() > 0 &&
michael@0 72
michael@0 73 // Copied from:
michael@0 74 // VideoFrame::IsValidConfig(format_, coded_size_, visible_rect_, natural_size_)
michael@0 75 format_ != VideoFrameFormat::INVALID &&
michael@0 76 !coded_size_.IsEmpty() &&
michael@0 77 coded_size_.GetArea() <= kMaxCanvas &&
michael@0 78 coded_size_.width() <= kMaxDimension &&
michael@0 79 coded_size_.height() <= kMaxDimension &&
michael@0 80 !visible_rect_.IsEmpty() &&
michael@0 81 visible_rect_.x() >= 0 && visible_rect_.y() >= 0 &&
michael@0 82 visible_rect_.right() <= coded_size_.width() &&
michael@0 83 visible_rect_.bottom() <= coded_size_.height() &&
michael@0 84 !natural_size_.IsEmpty() &&
michael@0 85 natural_size_.GetArea() <= kMaxCanvas &&
michael@0 86 natural_size_.width() <= kMaxDimension &&
michael@0 87 natural_size_.height() <= kMaxDimension;
michael@0 88 }
michael@0 89
michael@0 90 bool VideoDecoderConfig::Matches(const VideoDecoderConfig& config) const {
michael@0 91 return ((codec() == config.codec()) &&
michael@0 92 (format() == config.format()) &&
michael@0 93 (profile() == config.profile()) &&
michael@0 94 (coded_size() == config.coded_size()) &&
michael@0 95 (visible_rect() == config.visible_rect()) &&
michael@0 96 (natural_size() == config.natural_size()) &&
michael@0 97 (extra_data_size() == config.extra_data_size()) &&
michael@0 98 (!extra_data() || !memcmp(extra_data(), config.extra_data(),
michael@0 99 extra_data_size())) &&
michael@0 100 (is_encrypted() == config.is_encrypted()));
michael@0 101 }
michael@0 102
michael@0 103 std::string VideoDecoderConfig::AsHumanReadableString() const {
michael@0 104 std::ostringstream s;
michael@0 105 s << "codec: " << codec()
michael@0 106 << " format: " << format()
michael@0 107 << " profile: " << profile()
michael@0 108 << " coded size: [" << coded_size().width()
michael@0 109 << "," << coded_size().height() << "]"
michael@0 110 << " visible rect: [" << visible_rect().x()
michael@0 111 << "," << visible_rect().y()
michael@0 112 << "," << visible_rect().width()
michael@0 113 << "," << visible_rect().height() << "]"
michael@0 114 << " natural size: [" << natural_size().width()
michael@0 115 << "," << natural_size().height() << "]"
michael@0 116 << " has extra data? " << (extra_data() ? "true" : "false")
michael@0 117 << " encrypted? " << (is_encrypted() ? "true" : "false");
michael@0 118 return s.str();
michael@0 119 }
michael@0 120
michael@0 121 VideoCodec VideoDecoderConfig::codec() const {
michael@0 122 return codec_;
michael@0 123 }
michael@0 124
michael@0 125 VideoCodecProfile VideoDecoderConfig::profile() const {
michael@0 126 return profile_;
michael@0 127 }
michael@0 128
michael@0 129 VideoFrameFormat VideoDecoderConfig::format() const {
michael@0 130 return format_;
michael@0 131 }
michael@0 132
michael@0 133 IntSize VideoDecoderConfig::coded_size() const {
michael@0 134 return coded_size_;
michael@0 135 }
michael@0 136
michael@0 137 IntRect VideoDecoderConfig::visible_rect() const {
michael@0 138 return visible_rect_;
michael@0 139 }
michael@0 140
michael@0 141 IntSize VideoDecoderConfig::natural_size() const {
michael@0 142 return natural_size_;
michael@0 143 }
michael@0 144
michael@0 145 const uint8_t* VideoDecoderConfig::extra_data() const {
michael@0 146 if (extra_data_.empty())
michael@0 147 return NULL;
michael@0 148 return &extra_data_[0];
michael@0 149 }
michael@0 150
michael@0 151 size_t VideoDecoderConfig::extra_data_size() const {
michael@0 152 return extra_data_.size();
michael@0 153 }
michael@0 154
michael@0 155 bool VideoDecoderConfig::is_encrypted() const {
michael@0 156 return is_encrypted_;
michael@0 157 }
michael@0 158
michael@0 159 } // namespace mp4_demuxer

mercurial