5 #include "packager/media/formats/webm/webm_video_client.h"
7 #include "packager/base/logging.h"
8 #include "packager/media/formats/webm/webm_constants.h"
13 const uint32_t kWebMTimeScale = 1000000u;
15 int64_t GetGreatestCommonDivisor(int64_t a, int64_t b) {
26 namespace edash_packager {
29 WebMVideoClient::WebMVideoClient() {
33 WebMVideoClient::~WebMVideoClient() {
51 const std::string& codec_id,
52 const std::vector<uint8_t>& codec_private,
54 VideoCodec video_codec = kUnknownVideoCodec;
55 if (codec_id ==
"V_VP8") {
56 video_codec = kCodecVP8;
57 }
else if (codec_id ==
"V_VP9") {
58 video_codec = kCodecVP9;
60 LOG(ERROR) <<
"Unsupported video codec_id " << codec_id;
61 return scoped_refptr<VideoStreamInfo>();
64 if (pixel_width_ <= 0 || pixel_height_ <= 0)
65 return scoped_refptr<VideoStreamInfo>();
68 if (crop_bottom_ == -1)
77 if (crop_right_ == -1)
80 if (display_unit_ == -1)
83 uint16_t width_after_crop = pixel_width_ - (crop_left_ + crop_right_);
84 uint16_t height_after_crop = pixel_height_ - (crop_top_ + crop_bottom_);
86 if (display_unit_ == 0) {
87 if (display_width_ <= 0)
88 display_width_ = width_after_crop;
89 if (display_height_ <= 0)
90 display_height_ = height_after_crop;
91 }
else if (display_unit_ == 3) {
92 if (display_width_ <= 0 || display_height_ <= 0)
93 return scoped_refptr<VideoStreamInfo>();
95 LOG(ERROR) <<
"Unsupported display unit type " << display_unit_;
96 return scoped_refptr<VideoStreamInfo>();
99 int64_t sar_x = display_width_ * height_after_crop;
100 int64_t sar_y = display_height_ * width_after_crop;
101 int64_t gcd = GetGreatestCommonDivisor(sar_x, sar_y);
105 const uint8_t* extra_data = NULL;
106 size_t extra_data_size = 0;
107 if (codec_private.size() > 0) {
108 extra_data = &codec_private[0];
109 extra_data_size = codec_private.size();
113 std::string codec_string;
116 track_num, kWebMTimeScale, 0, video_codec, codec_string, std::string(),
117 width_after_crop, height_after_crop, sar_x, sar_y, 0, 0, extra_data,
118 extra_data_size, is_encrypted));
121 bool WebMVideoClient::OnUInt(
int id, int64_t val) {
125 case kWebMIdPixelWidth:
128 case kWebMIdPixelHeight:
129 dst = &pixel_height_;
131 case kWebMIdPixelCropTop:
134 case kWebMIdPixelCropBottom:
137 case kWebMIdPixelCropLeft:
140 case kWebMIdPixelCropRight:
143 case kWebMIdDisplayWidth:
144 dst = &display_width_;
146 case kWebMIdDisplayHeight:
147 dst = &display_height_;
149 case kWebMIdDisplayUnit:
150 dst = &display_unit_;
152 case kWebMIdAlphaMode:
160 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
161 << *dst <<
" and " << val <<
")";
169 bool WebMVideoClient::OnBinary(
int id,
const uint8_t* data,
int size) {
174 bool WebMVideoClient::OnFloat(
int id,
double val) {