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, H26xStreamFormat::kUnSpecified,
113 std::string(), codec_private.data(), codec_private.size(),
114 width_after_crop, height_after_crop, sar_x, sar_y, 0, 0, std::string(),
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) {