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() {}
32 WebMVideoClient::~WebMVideoClient() {}
46 matrix_coefficients_ = -1;
47 bits_per_channel_ = -1;
48 chroma_subsampling_horz_ = -1;
49 chroma_subsampling_vert_ = -1;
50 chroma_siting_horz_ = -1;
51 chroma_siting_vert_ = -1;
53 transfer_characteristics_ = -1;
54 color_primaries_ = -1;
59 const std::string& codec_id,
61 Codec video_codec = kUnknownCodec;
62 if (codec_id ==
"V_VP8") {
63 video_codec = kCodecVP8;
64 }
else if (codec_id ==
"V_VP9") {
65 video_codec = kCodecVP9;
69 }
else if (codec_id ==
"V_VP10") {
70 video_codec = kCodecVP10;
72 LOG(ERROR) <<
"Unsupported video codec_id " << codec_id;
73 return std::shared_ptr<VideoStreamInfo>();
76 if (pixel_width_ <= 0 || pixel_height_ <= 0)
77 return std::shared_ptr<VideoStreamInfo>();
80 if (crop_bottom_ == -1)
89 if (crop_right_ == -1)
92 if (display_unit_ == -1)
95 uint16_t width_after_crop = pixel_width_ - (crop_left_ + crop_right_);
96 uint16_t height_after_crop = pixel_height_ - (crop_top_ + crop_bottom_);
98 if (display_unit_ == 0) {
99 if (display_width_ <= 0)
100 display_width_ = width_after_crop;
101 if (display_height_ <= 0)
102 display_height_ = height_after_crop;
103 }
else if (display_unit_ == 3) {
104 if (display_width_ <= 0 || display_height_ <= 0)
105 return std::shared_ptr<VideoStreamInfo>();
107 LOG(ERROR) <<
"Unsupported display unit type " << display_unit_;
108 return std::shared_ptr<VideoStreamInfo>();
111 int64_t sar_x = display_width_ * height_after_crop;
112 int64_t sar_y = display_height_ * width_after_crop;
113 int64_t gcd = GetGreatestCommonDivisor(sar_x, sar_y);
117 return std::make_shared<VideoStreamInfo>(
118 track_num, kWebMTimeScale, 0, video_codec, H26xStreamFormat::kUnSpecified,
119 std::string(),
nullptr, 0, width_after_crop, height_after_crop, sar_x,
120 sar_y, 0, 0, std::string(), is_encrypted);
124 const std::vector<uint8_t>& codec_private) {
127 if (matrix_coefficients_ != -1) {
128 vp_config.set_matrix_coefficients(matrix_coefficients_);
130 if (bits_per_channel_ != -1) {
131 vp_config.set_bit_depth(bits_per_channel_);
133 if (chroma_subsampling_horz_ != -1 && chroma_subsampling_vert_ != -1) {
134 vp_config.SetChromaSubsampling(chroma_subsampling_horz_,
135 chroma_subsampling_vert_);
137 if (chroma_siting_horz_ != -1 && chroma_siting_vert_ != -1) {
138 vp_config.SetChromaLocation(chroma_siting_horz_, chroma_siting_vert_);
140 if (color_range_ != -1) {
141 if (color_range_ == 0)
142 vp_config.set_video_full_range_flag(
false);
143 else if (color_range_ == 1)
144 vp_config.set_video_full_range_flag(
true);
147 if (transfer_characteristics_ != -1) {
148 vp_config.set_transfer_characteristics(transfer_characteristics_);
150 if (color_primaries_ != -1) {
151 vp_config.set_color_primaries(color_primaries_);
157 return id == kWebMIdColor ?
this : WebMParserClient::OnListStart(
id);
160 bool WebMVideoClient::OnListEnd(
int id) {
161 return id == kWebMIdColor ?
true : WebMParserClient::OnListEnd(
id);
164 bool WebMVideoClient::OnUInt(
int id, int64_t val) {
165 int64_t* dst =
nullptr;
168 case kWebMIdPixelWidth:
171 case kWebMIdPixelHeight:
172 dst = &pixel_height_;
174 case kWebMIdPixelCropTop:
177 case kWebMIdPixelCropBottom:
180 case kWebMIdPixelCropLeft:
183 case kWebMIdPixelCropRight:
186 case kWebMIdDisplayWidth:
187 dst = &display_width_;
189 case kWebMIdDisplayHeight:
190 dst = &display_height_;
192 case kWebMIdDisplayUnit:
193 dst = &display_unit_;
195 case kWebMIdAlphaMode:
198 case kWebMIdColorMatrixCoefficients:
199 dst = &matrix_coefficients_;
201 case kWebMIdColorBitsPerChannel:
202 dst = &bits_per_channel_;
204 case kWebMIdColorChromaSubsamplingHorz:
205 dst = &chroma_subsampling_horz_;
207 case kWebMIdColorChromaSubsamplingVert:
208 dst = &chroma_subsampling_vert_;
210 case kWebMIdColorChromaSitingHorz:
211 dst = &chroma_siting_horz_;
213 case kWebMIdColorChromaSitingVert:
214 dst = &chroma_siting_vert_;
216 case kWebMIdColorRange:
219 case kWebMIdColorTransferCharacteristics:
220 dst = &transfer_characteristics_;
222 case kWebMIdColorPrimaries:
223 dst = &color_primaries_;
225 case kWebMIdColorMaxCLL:
226 case kWebMIdColorMaxFALL:
227 NOTIMPLEMENTED() <<
"HDR is not supported yet.";
234 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
235 << *dst <<
" and " << val <<
")";
243 bool WebMVideoClient::OnBinary(
int id,
const uint8_t* data,
int size) {
248 bool WebMVideoClient::OnFloat(
int id,
double val) {