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/formats/webm/webm_constants.h"
14 const uint32_t kWebMTimeScale = 1000000u;
16 int64_t GetGreatestCommonDivisor(int64_t a, int64_t b) {
27 namespace edash_packager {
30 WebMVideoClient::WebMVideoClient() {
34 WebMVideoClient::~WebMVideoClient() {
52 const std::string& codec_id,
53 const std::vector<uint8_t>& codec_private,
55 VideoCodec video_codec = kUnknownVideoCodec;
56 if (codec_id ==
"V_VP8") {
57 video_codec = kCodecVP8;
58 }
else if (codec_id ==
"V_VP9") {
59 video_codec = kCodecVP9;
60 }
else if (codec_id ==
"V_VP10") {
61 video_codec = kCodecVP10;
63 LOG(ERROR) <<
"Unsupported video codec_id " << codec_id;
64 return scoped_refptr<VideoStreamInfo>();
67 if (pixel_width_ <= 0 || pixel_height_ <= 0)
68 return scoped_refptr<VideoStreamInfo>();
71 if (crop_bottom_ == -1)
80 if (crop_right_ == -1)
83 if (display_unit_ == -1)
86 uint16_t width_after_crop = pixel_width_ - (crop_left_ + crop_right_);
87 uint16_t height_after_crop = pixel_height_ - (crop_top_ + crop_bottom_);
89 if (display_unit_ == 0) {
90 if (display_width_ <= 0)
91 display_width_ = width_after_crop;
92 if (display_height_ <= 0)
93 display_height_ = height_after_crop;
94 }
else if (display_unit_ == 3) {
95 if (display_width_ <= 0 || display_height_ <= 0)
96 return scoped_refptr<VideoStreamInfo>();
98 LOG(ERROR) <<
"Unsupported display unit type " << display_unit_;
99 return scoped_refptr<VideoStreamInfo>();
102 int64_t sar_x = display_width_ * height_after_crop;
103 int64_t sar_y = display_height_ * width_after_crop;
104 int64_t gcd = GetGreatestCommonDivisor(sar_x, sar_y);
109 track_num, kWebMTimeScale, 0, video_codec, std::string(), std::string(),
110 width_after_crop, height_after_crop, sar_x, sar_y, 0, 0, NULL, 0,
114 bool WebMVideoClient::OnUInt(
int id, int64_t val) {
118 case kWebMIdPixelWidth:
121 case kWebMIdPixelHeight:
122 dst = &pixel_height_;
124 case kWebMIdPixelCropTop:
127 case kWebMIdPixelCropBottom:
130 case kWebMIdPixelCropLeft:
133 case kWebMIdPixelCropRight:
136 case kWebMIdDisplayWidth:
137 dst = &display_width_;
139 case kWebMIdDisplayHeight:
140 dst = &display_height_;
142 case kWebMIdDisplayUnit:
143 dst = &display_unit_;
145 case kWebMIdAlphaMode:
153 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
154 << *dst <<
" and " << val <<
")";
162 bool WebMVideoClient::OnBinary(
int id,
const uint8_t* data,
int size) {
167 bool WebMVideoClient::OnFloat(
int id,
double val) {