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/filters/vp_codec_configuration.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) {
28 namespace edash_packager {
31 WebMVideoClient::WebMVideoClient() {
35 WebMVideoClient::~WebMVideoClient() {
53 const std::string& codec_id,
54 const std::vector<uint8_t>& codec_private,
56 VideoCodec video_codec = kUnknownVideoCodec;
57 if (codec_id ==
"V_VP8") {
58 video_codec = kCodecVP8;
59 }
else if (codec_id ==
"V_VP9") {
60 video_codec = kCodecVP9;
61 }
else if (codec_id ==
"V_VP10") {
62 video_codec = kCodecVP10;
64 LOG(ERROR) <<
"Unsupported video codec_id " << codec_id;
65 return scoped_refptr<VideoStreamInfo>();
68 if (pixel_width_ <= 0 || pixel_height_ <= 0)
69 return scoped_refptr<VideoStreamInfo>();
72 if (crop_bottom_ == -1)
81 if (crop_right_ == -1)
84 if (display_unit_ == -1)
87 uint16_t width_after_crop = pixel_width_ - (crop_left_ + crop_right_);
88 uint16_t height_after_crop = pixel_height_ - (crop_top_ + crop_bottom_);
90 if (display_unit_ == 0) {
91 if (display_width_ <= 0)
92 display_width_ = width_after_crop;
93 if (display_height_ <= 0)
94 display_height_ = height_after_crop;
95 }
else if (display_unit_ == 3) {
96 if (display_width_ <= 0 || display_height_ <= 0)
97 return scoped_refptr<VideoStreamInfo>();
99 LOG(ERROR) <<
"Unsupported display unit type " << display_unit_;
100 return scoped_refptr<VideoStreamInfo>();
103 int64_t sar_x = display_width_ * height_after_crop;
104 int64_t sar_y = display_height_ * width_after_crop;
105 int64_t gcd = GetGreatestCommonDivisor(sar_x, sar_y);
110 const uint8_t profile = 0;
111 const uint8_t level = 0;
112 const uint8_t bit_depth = 8;
113 const uint8_t color_space = 0;
114 const uint8_t chroma_subsampling = 0;
115 const uint8_t transfer_function = 0;
116 const bool video_full_range_flag =
false;
118 chroma_subsampling, transfer_function,
119 video_full_range_flag, codec_private);
120 std::vector<uint8_t> extra_data;
121 vp_config.
Write(&extra_data);
124 track_num, kWebMTimeScale, 0, video_codec,
125 vp_config.
GetCodecString(video_codec), std::string(), width_after_crop,
126 height_after_crop, sar_x, sar_y, 0, 0, vector_as_array(&extra_data),
127 extra_data.size(), is_encrypted));
130 bool WebMVideoClient::OnUInt(
int id, int64_t val) {
134 case kWebMIdPixelWidth:
137 case kWebMIdPixelHeight:
138 dst = &pixel_height_;
140 case kWebMIdPixelCropTop:
143 case kWebMIdPixelCropBottom:
146 case kWebMIdPixelCropLeft:
149 case kWebMIdPixelCropRight:
152 case kWebMIdDisplayWidth:
153 dst = &display_width_;
155 case kWebMIdDisplayHeight:
156 dst = &display_height_;
158 case kWebMIdDisplayUnit:
159 dst = &display_unit_;
161 case kWebMIdAlphaMode:
169 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
170 << *dst <<
" and " << val <<
")";
178 bool WebMVideoClient::OnBinary(
int id,
const uint8_t* data,
int size) {
183 bool WebMVideoClient::OnFloat(
int id,
double val) {