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