5 #include "packager/media/formats/webm/webm_video_client.h"
7 #include "packager/base/logging.h"
8 #include "packager/base/stl_util.h"
9 #include "packager/media/codecs/vp_codec_configuration_record.h"
10 #include "packager/media/formats/webm/webm_constants.h"
15 const uint32_t kWebMTimeScale = 1000000u;
17 int64_t GetGreatestCommonDivisor(int64_t a, int64_t b) {
31 WebMVideoClient::WebMVideoClient() {
35 WebMVideoClient::~WebMVideoClient() {
53 const std::string& codec_id,
54 const std::vector<uint8_t>& codec_private,
56 VideoCodec video_codec = kUnknownVideoCodec;
57 if (codec_id ==
"V_VP8") {
58 video_codec = kCodecVP8;
59 }
else if (codec_id ==
"V_VP9") {
60 video_codec = kCodecVP9;
64 }
else if (codec_id ==
"V_VP10") {
65 video_codec = kCodecVP10;
67 LOG(ERROR) <<
"Unsupported video codec_id " << codec_id;
68 return scoped_refptr<VideoStreamInfo>();
71 if (pixel_width_ <= 0 || pixel_height_ <= 0)
72 return scoped_refptr<VideoStreamInfo>();
75 if (crop_bottom_ == -1)
84 if (crop_right_ == -1)
87 if (display_unit_ == -1)
90 uint16_t width_after_crop = pixel_width_ - (crop_left_ + crop_right_);
91 uint16_t height_after_crop = pixel_height_ - (crop_top_ + crop_bottom_);
93 if (display_unit_ == 0) {
94 if (display_width_ <= 0)
95 display_width_ = width_after_crop;
96 if (display_height_ <= 0)
97 display_height_ = height_after_crop;
98 }
else if (display_unit_ == 3) {
99 if (display_width_ <= 0 || display_height_ <= 0)
100 return scoped_refptr<VideoStreamInfo>();
102 LOG(ERROR) <<
"Unsupported display unit type " << display_unit_;
103 return scoped_refptr<VideoStreamInfo>();
106 int64_t sar_x = display_width_ * height_after_crop;
107 int64_t sar_y = display_height_ * width_after_crop;
108 int64_t gcd = GetGreatestCommonDivisor(sar_x, sar_y);
113 track_num, kWebMTimeScale, 0, video_codec, std::string(), std::string(),
114 width_after_crop, height_after_crop, sar_x, sar_y, 0, 0,
115 codec_private.data(), codec_private.size(), is_encrypted));
118 bool WebMVideoClient::OnUInt(
int id, int64_t val) {
122 case kWebMIdPixelWidth:
125 case kWebMIdPixelHeight:
126 dst = &pixel_height_;
128 case kWebMIdPixelCropTop:
131 case kWebMIdPixelCropBottom:
134 case kWebMIdPixelCropLeft:
137 case kWebMIdPixelCropRight:
140 case kWebMIdDisplayWidth:
141 dst = &display_width_;
143 case kWebMIdDisplayHeight:
144 dst = &display_height_;
146 case kWebMIdDisplayUnit:
147 dst = &display_unit_;
149 case kWebMIdAlphaMode:
157 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
158 << *dst <<
" and " << val <<
")";
166 bool WebMVideoClient::OnBinary(
int id,
const uint8_t* data,
int size) {
171 bool WebMVideoClient::OnFloat(
int id,
double val) {