5 #include "packager/media/formats/webm/webm_video_client.h" 7 #include "packager/base/logging.h" 8 #include "packager/media/codecs/av1_codec_configuration_record.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() {}
33 WebMVideoClient::~WebMVideoClient() {}
47 matrix_coefficients_ = -1;
48 bits_per_channel_ = -1;
49 chroma_subsampling_horz_ = -1;
50 chroma_subsampling_vert_ = -1;
51 chroma_siting_horz_ = -1;
52 chroma_siting_vert_ = -1;
54 transfer_characteristics_ = -1;
55 color_primaries_ = -1;
60 const std::string& codec_id,
61 const std::vector<uint8_t>& codec_private,
63 std::string codec_string;
64 Codec video_codec = kUnknownCodec;
65 if (codec_id ==
"V_AV1") {
66 video_codec = kCodecAV1;
71 if (!av1_config.
Parse(codec_private)) {
72 LOG(ERROR) <<
"Failed to parse AV1 codec_private.";
76 }
else if (codec_id ==
"V_VP8") {
77 video_codec = kCodecVP8;
79 }
else if (codec_id ==
"V_VP9") {
80 video_codec = kCodecVP9;
83 LOG(ERROR) <<
"Unsupported video codec_id " << codec_id;
87 if (pixel_width_ <= 0 || pixel_height_ <= 0)
91 if (crop_bottom_ == -1)
100 if (crop_right_ == -1)
103 if (display_unit_ == -1)
106 uint16_t width_after_crop = pixel_width_ - (crop_left_ + crop_right_);
107 uint16_t height_after_crop = pixel_height_ - (crop_top_ + crop_bottom_);
109 if (display_unit_ == 0) {
110 if (display_width_ <= 0)
111 display_width_ = width_after_crop;
112 if (display_height_ <= 0)
113 display_height_ = height_after_crop;
114 }
else if (display_unit_ == 3) {
115 if (display_width_ <= 0 || display_height_ <= 0)
118 LOG(ERROR) <<
"Unsupported display unit type " << display_unit_;
122 int64_t sar_x = display_width_ * height_after_crop;
123 int64_t sar_y = display_height_ * width_after_crop;
124 int64_t gcd = GetGreatestCommonDivisor(sar_x, sar_y);
131 return std::make_shared<VideoStreamInfo>(
132 track_num, kWebMTimeScale, 0, video_codec, H26xStreamFormat::kUnSpecified,
133 codec_string, codec_private.data(), codec_private.size(),
134 width_after_crop, height_after_crop, sar_x, sar_y, 0, 0, std::string(),
139 const std::vector<uint8_t>& codec_private) {
142 if (matrix_coefficients_ != -1) {
143 vp_config.set_matrix_coefficients(matrix_coefficients_);
145 if (bits_per_channel_ != -1) {
146 vp_config.set_bit_depth(bits_per_channel_);
148 if (chroma_subsampling_horz_ != -1 && chroma_subsampling_vert_ != -1) {
149 vp_config.SetChromaSubsampling(chroma_subsampling_horz_,
150 chroma_subsampling_vert_);
152 if (chroma_siting_horz_ != -1 && chroma_siting_vert_ != -1) {
153 vp_config.SetChromaLocation(chroma_siting_horz_, chroma_siting_vert_);
155 if (color_range_ != -1) {
156 if (color_range_ == 0)
157 vp_config.set_video_full_range_flag(
false);
158 else if (color_range_ == 1)
159 vp_config.set_video_full_range_flag(
true);
162 if (transfer_characteristics_ != -1) {
163 vp_config.set_transfer_characteristics(transfer_characteristics_);
165 if (color_primaries_ != -1) {
166 vp_config.set_color_primaries(color_primaries_);
172 return id == kWebMIdColor ? this : WebMParserClient::OnListStart(
id);
175 bool WebMVideoClient::OnListEnd(
int id) {
176 return id == kWebMIdColor ? true : WebMParserClient::OnListEnd(
id);
179 bool WebMVideoClient::OnUInt(
int id, int64_t val) {
180 int64_t* dst =
nullptr;
183 case kWebMIdPixelWidth:
186 case kWebMIdPixelHeight:
187 dst = &pixel_height_;
189 case kWebMIdPixelCropTop:
192 case kWebMIdPixelCropBottom:
195 case kWebMIdPixelCropLeft:
198 case kWebMIdPixelCropRight:
201 case kWebMIdDisplayWidth:
202 dst = &display_width_;
204 case kWebMIdDisplayHeight:
205 dst = &display_height_;
207 case kWebMIdDisplayUnit:
208 dst = &display_unit_;
210 case kWebMIdAlphaMode:
213 case kWebMIdColorMatrixCoefficients:
214 dst = &matrix_coefficients_;
216 case kWebMIdColorBitsPerChannel:
217 dst = &bits_per_channel_;
219 case kWebMIdColorChromaSubsamplingHorz:
220 dst = &chroma_subsampling_horz_;
222 case kWebMIdColorChromaSubsamplingVert:
223 dst = &chroma_subsampling_vert_;
225 case kWebMIdColorChromaSitingHorz:
226 dst = &chroma_siting_horz_;
228 case kWebMIdColorChromaSitingVert:
229 dst = &chroma_siting_vert_;
231 case kWebMIdColorRange:
234 case kWebMIdColorTransferCharacteristics:
235 dst = &transfer_characteristics_;
237 case kWebMIdColorPrimaries:
238 dst = &color_primaries_;
240 case kWebMIdColorMaxCLL:
241 case kWebMIdColorMaxFALL:
242 NOTIMPLEMENTED() <<
"HDR is not supported yet.";
249 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified (" 250 << *dst <<
" and " << val <<
")";
258 bool WebMVideoClient::OnBinary(
int id,
const uint8_t* data,
int size) {
263 bool WebMVideoClient::OnFloat(
int id,
double val) {
All the methods that are virtual are virtual for mocking.