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();
112 return scoped_refptr<VideoStreamInfo>(
115 "", width_after_crop, height_after_crop, sar_x, sar_y,
116 0, 0, extra_data, extra_data_size, is_encrypted));
119 bool WebMVideoClient::OnUInt(
int id, int64_t val) {
123 case kWebMIdPixelWidth:
126 case kWebMIdPixelHeight:
127 dst = &pixel_height_;
129 case kWebMIdPixelCropTop:
132 case kWebMIdPixelCropBottom:
135 case kWebMIdPixelCropLeft:
138 case kWebMIdPixelCropRight:
141 case kWebMIdDisplayWidth:
142 dst = &display_width_;
144 case kWebMIdDisplayHeight:
145 dst = &display_height_;
147 case kWebMIdDisplayUnit:
148 dst = &display_unit_;
150 case kWebMIdAlphaMode:
158 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
159 << *dst <<
" and " << val <<
")";
167 bool WebMVideoClient::OnBinary(
int id,
const uint8_t* data,
int size) {
172 bool WebMVideoClient::OnFloat(
int id,
double val) {