[MD settings] moving attached() code
[chromium-blink-merge.git] / media / formats / webm / webm_video_client.cc
blob2d3f43b9ce7f1471e3aed8f3f44abf1bed91b62e
1 // Copyright 2014 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 "media/formats/webm/webm_video_client.h"
7 #include "media/base/video_decoder_config.h"
8 #include "media/formats/webm/webm_constants.h"
10 namespace media {
12 WebMVideoClient::WebMVideoClient(const scoped_refptr<MediaLog>& media_log)
13 : media_log_(media_log) {
14 Reset();
17 WebMVideoClient::~WebMVideoClient() {
20 void WebMVideoClient::Reset() {
21 pixel_width_ = -1;
22 pixel_height_ = -1;
23 crop_bottom_ = -1;
24 crop_top_ = -1;
25 crop_left_ = -1;
26 crop_right_ = -1;
27 display_width_ = -1;
28 display_height_ = -1;
29 display_unit_ = -1;
30 alpha_mode_ = -1;
33 bool WebMVideoClient::InitializeConfig(
34 const std::string& codec_id, const std::vector<uint8>& codec_private,
35 bool is_encrypted, VideoDecoderConfig* config) {
36 DCHECK(config);
38 VideoCodec video_codec = kUnknownVideoCodec;
39 VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN;
40 if (codec_id == "V_VP8") {
41 video_codec = kCodecVP8;
42 profile = VP8PROFILE_ANY;
43 } else if (codec_id == "V_VP9") {
44 video_codec = kCodecVP9;
45 profile = VP9PROFILE_ANY;
46 } else {
47 MEDIA_LOG(ERROR, media_log_) << "Unsupported video codec_id " << codec_id;
48 return false;
51 VideoPixelFormat format =
52 (alpha_mode_ == 1) ? PIXEL_FORMAT_YV12A : PIXEL_FORMAT_YV12;
54 if (pixel_width_ <= 0 || pixel_height_ <= 0)
55 return false;
57 // Set crop and display unit defaults if these elements are not present.
58 if (crop_bottom_ == -1)
59 crop_bottom_ = 0;
61 if (crop_top_ == -1)
62 crop_top_ = 0;
64 if (crop_left_ == -1)
65 crop_left_ = 0;
67 if (crop_right_ == -1)
68 crop_right_ = 0;
70 if (display_unit_ == -1)
71 display_unit_ = 0;
73 gfx::Size coded_size(pixel_width_, pixel_height_);
74 gfx::Rect visible_rect(crop_top_, crop_left_,
75 pixel_width_ - (crop_left_ + crop_right_),
76 pixel_height_ - (crop_top_ + crop_bottom_));
77 if (display_unit_ == 0) {
78 if (display_width_ <= 0)
79 display_width_ = visible_rect.width();
80 if (display_height_ <= 0)
81 display_height_ = visible_rect.height();
82 } else if (display_unit_ == 3) {
83 if (display_width_ <= 0 || display_height_ <= 0)
84 return false;
85 } else {
86 MEDIA_LOG(ERROR, media_log_) << "Unsupported display unit type "
87 << display_unit_;
88 return false;
90 gfx::Size natural_size = gfx::Size(display_width_, display_height_);
91 const uint8* extra_data = NULL;
92 size_t extra_data_size = 0;
93 if (codec_private.size() > 0) {
94 extra_data = &codec_private[0];
95 extra_data_size = codec_private.size();
98 config->Initialize(video_codec, profile, format, COLOR_SPACE_HD_REC709,
99 coded_size, visible_rect, natural_size, extra_data,
100 extra_data_size, is_encrypted);
101 return config->IsValidConfig();
104 bool WebMVideoClient::OnUInt(int id, int64 val) {
105 int64* dst = NULL;
107 switch (id) {
108 case kWebMIdPixelWidth:
109 dst = &pixel_width_;
110 break;
111 case kWebMIdPixelHeight:
112 dst = &pixel_height_;
113 break;
114 case kWebMIdPixelCropTop:
115 dst = &crop_top_;
116 break;
117 case kWebMIdPixelCropBottom:
118 dst = &crop_bottom_;
119 break;
120 case kWebMIdPixelCropLeft:
121 dst = &crop_left_;
122 break;
123 case kWebMIdPixelCropRight:
124 dst = &crop_right_;
125 break;
126 case kWebMIdDisplayWidth:
127 dst = &display_width_;
128 break;
129 case kWebMIdDisplayHeight:
130 dst = &display_height_;
131 break;
132 case kWebMIdDisplayUnit:
133 dst = &display_unit_;
134 break;
135 case kWebMIdAlphaMode:
136 dst = &alpha_mode_;
137 break;
138 default:
139 return true;
142 if (*dst != -1) {
143 MEDIA_LOG(ERROR, media_log_) << "Multiple values for id " << std::hex << id
144 << " specified (" << *dst << " and " << val
145 << ")";
146 return false;
149 *dst = val;
150 return true;
153 bool WebMVideoClient::OnBinary(int id, const uint8* data, int size) {
154 // Accept binary fields we don't care about for now.
155 return true;
158 bool WebMVideoClient::OnFloat(int id, double val) {
159 // Accept float fields we don't care about for now.
160 return true;
163 } // namespace media