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_in,
56 std::vector<uint8_t> codec_private = codec_private_in;
57 VideoCodec video_codec = kUnknownVideoCodec;
58 if (codec_id ==
"V_VP8") {
59 video_codec = kCodecVP8;
60 }
else if (codec_id ==
"V_VP9") {
61 video_codec = kCodecVP9;
65 if (!vp_config.
ParseWebM(codec_private)) {
66 LOG(ERROR) <<
"Unable to parse VP9 codec configuration";
67 return scoped_refptr<VideoStreamInfo>();
70 }
else if (codec_id ==
"V_VP10") {
71 video_codec = kCodecVP10;
73 LOG(ERROR) <<
"Unsupported video codec_id " << codec_id;
74 return scoped_refptr<VideoStreamInfo>();
77 if (pixel_width_ <= 0 || pixel_height_ <= 0)
78 return scoped_refptr<VideoStreamInfo>();
81 if (crop_bottom_ == -1)
90 if (crop_right_ == -1)
93 if (display_unit_ == -1)
96 uint16_t width_after_crop = pixel_width_ - (crop_left_ + crop_right_);
97 uint16_t height_after_crop = pixel_height_ - (crop_top_ + crop_bottom_);
99 if (display_unit_ == 0) {
100 if (display_width_ <= 0)
101 display_width_ = width_after_crop;
102 if (display_height_ <= 0)
103 display_height_ = height_after_crop;
104 }
else if (display_unit_ == 3) {
105 if (display_width_ <= 0 || display_height_ <= 0)
106 return scoped_refptr<VideoStreamInfo>();
108 LOG(ERROR) <<
"Unsupported display unit type " << display_unit_;
109 return scoped_refptr<VideoStreamInfo>();
112 int64_t sar_x = display_width_ * height_after_crop;
113 int64_t sar_y = display_height_ * width_after_crop;
114 int64_t gcd = GetGreatestCommonDivisor(sar_x, sar_y);
119 track_num, kWebMTimeScale, 0, video_codec, std::string(), std::string(),
120 width_after_crop, height_after_crop, sar_x, sar_y, 0, 0,
121 codec_private.data(), codec_private.size(), is_encrypted));
124 bool WebMVideoClient::OnUInt(
int id, int64_t val) {
128 case kWebMIdPixelWidth:
131 case kWebMIdPixelHeight:
132 dst = &pixel_height_;
134 case kWebMIdPixelCropTop:
137 case kWebMIdPixelCropBottom:
140 case kWebMIdPixelCropLeft:
143 case kWebMIdPixelCropRight:
146 case kWebMIdDisplayWidth:
147 dst = &display_width_;
149 case kWebMIdDisplayHeight:
150 dst = &display_height_;
152 case kWebMIdDisplayUnit:
153 dst = &display_unit_;
155 case kWebMIdAlphaMode:
163 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
164 << *dst <<
" and " << val <<
")";
172 bool WebMVideoClient::OnBinary(
int id,
const uint8_t* data,
int size) {
177 bool WebMVideoClient::OnFloat(
int id,
double val) {