5 #include "packager/media/formats/webm/webm_video_client.h"
7 #include "packager/base/logging.h"
8 #include "packager/media/codecs/vp_codec_configuration_record.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) {
30 WebMVideoClient::WebMVideoClient() {
34 WebMVideoClient::~WebMVideoClient() {
52 const std::string& codec_id,
53 const std::vector<uint8_t>& codec_private,
55 Codec video_codec = kUnknownCodec;
56 if (codec_id ==
"V_VP8") {
57 video_codec = kCodecVP8;
58 }
else if (codec_id ==
"V_VP9") {
59 video_codec = kCodecVP9;
63 }
else if (codec_id ==
"V_VP10") {
64 video_codec = kCodecVP10;
66 LOG(ERROR) <<
"Unsupported video codec_id " << codec_id;
67 return std::shared_ptr<VideoStreamInfo>();
70 if (pixel_width_ <= 0 || pixel_height_ <= 0)
71 return std::shared_ptr<VideoStreamInfo>();
74 if (crop_bottom_ == -1)
83 if (crop_right_ == -1)
86 if (display_unit_ == -1)
89 uint16_t width_after_crop = pixel_width_ - (crop_left_ + crop_right_);
90 uint16_t height_after_crop = pixel_height_ - (crop_top_ + crop_bottom_);
92 if (display_unit_ == 0) {
93 if (display_width_ <= 0)
94 display_width_ = width_after_crop;
95 if (display_height_ <= 0)
96 display_height_ = height_after_crop;
97 }
else if (display_unit_ == 3) {
98 if (display_width_ <= 0 || display_height_ <= 0)
99 return std::shared_ptr<VideoStreamInfo>();
101 LOG(ERROR) <<
"Unsupported display unit type " << display_unit_;
102 return std::shared_ptr<VideoStreamInfo>();
105 int64_t sar_x = display_width_ * height_after_crop;
106 int64_t sar_y = display_height_ * width_after_crop;
107 int64_t gcd = GetGreatestCommonDivisor(sar_x, sar_y);
111 return std::make_shared<VideoStreamInfo>(
112 track_num, kWebMTimeScale, 0, video_codec, std::string(),
113 codec_private.data(), codec_private.size(), width_after_crop,
114 height_after_crop, sar_x, sar_y, 0, 0, std::string(), is_encrypted);
117 bool WebMVideoClient::OnUInt(
int id, int64_t val) {
121 case kWebMIdPixelWidth:
124 case kWebMIdPixelHeight:
125 dst = &pixel_height_;
127 case kWebMIdPixelCropTop:
130 case kWebMIdPixelCropBottom:
133 case kWebMIdPixelCropLeft:
136 case kWebMIdPixelCropRight:
139 case kWebMIdDisplayWidth:
140 dst = &display_width_;
142 case kWebMIdDisplayHeight:
143 dst = &display_height_;
145 case kWebMIdDisplayUnit:
146 dst = &display_unit_;
148 case kWebMIdAlphaMode:
156 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
157 << *dst <<
" and " << val <<
")";
165 bool WebMVideoClient::OnBinary(
int id,
const uint8_t* data,
int size) {
170 bool WebMVideoClient::OnFloat(
int id,
double val) {