5 #include <packager/media/formats/webm/webm_video_client.h>
7 #include <absl/log/log.h>
9 #include <packager/macros/logging.h>
10 #include <packager/media/base/video_util.h>
11 #include <packager/media/codecs/av1_codec_configuration_record.h>
12 #include <packager/media/codecs/vp_codec_configuration_record.h>
13 #include <packager/media/formats/webm/webm_constants.h>
18 const int32_t kWebMTimeScale = 1000000;
25 WebMVideoClient::WebMVideoClient() {}
27 WebMVideoClient::~WebMVideoClient() {}
41 matrix_coefficients_ = -1;
42 bits_per_channel_ = -1;
43 chroma_subsampling_horz_ = -1;
44 chroma_subsampling_vert_ = -1;
45 chroma_siting_horz_ = -1;
46 chroma_siting_vert_ = -1;
48 transfer_characteristics_ = -1;
49 color_primaries_ = -1;
54 const std::string& codec_id,
55 const std::vector<uint8_t>& codec_private,
57 std::string codec_string;
58 Codec video_codec = kUnknownCodec;
59 if (codec_id ==
"V_AV1") {
60 video_codec = kCodecAV1;
65 if (!av1_config.
Parse(codec_private)) {
66 LOG(ERROR) <<
"Failed to parse AV1 codec_private.";
70 }
else if (codec_id ==
"V_VP8") {
71 video_codec = kCodecVP8;
73 }
else if (codec_id ==
"V_VP9") {
74 video_codec = kCodecVP9;
77 LOG(ERROR) <<
"Unsupported video codec_id " << codec_id;
81 if (pixel_width_ <= 0 || pixel_height_ <= 0)
85 if (crop_bottom_ == -1)
94 if (crop_right_ == -1)
97 if (display_unit_ == -1)
100 uint16_t width_after_crop = pixel_width_ - (crop_left_ + crop_right_);
101 uint16_t height_after_crop = pixel_height_ - (crop_top_ + crop_bottom_);
103 if (display_unit_ == 0) {
104 if (display_width_ <= 0)
105 display_width_ = width_after_crop;
106 if (display_height_ <= 0)
107 display_height_ = height_after_crop;
108 }
else if (display_unit_ == 3) {
109 if (display_width_ <= 0 || display_height_ <= 0)
112 LOG(ERROR) <<
"Unsupported display unit type " << display_unit_;
117 uint32_t pixel_width;
118 uint32_t pixel_height;
119 DerivePixelWidthHeight(width_after_crop, height_after_crop, display_width_,
120 display_height_, &pixel_width, &pixel_height);
125 return std::make_shared<VideoStreamInfo>(
126 track_num, kWebMTimeScale, 0, video_codec, H26xStreamFormat::kUnSpecified,
127 codec_string, codec_private.data(), codec_private.size(),
128 width_after_crop, height_after_crop, pixel_width, pixel_height, 0, 0, 0,
129 0, 0, std::string(), is_encrypted);
133 const std::vector<uint8_t>& codec_private) {
136 if (matrix_coefficients_ != -1) {
137 vp_config.set_matrix_coefficients(matrix_coefficients_);
139 if (bits_per_channel_ != -1) {
140 vp_config.set_bit_depth(bits_per_channel_);
142 if (chroma_subsampling_horz_ != -1 && chroma_subsampling_vert_ != -1) {
143 vp_config.SetChromaSubsampling(chroma_subsampling_horz_,
144 chroma_subsampling_vert_);
146 if (chroma_siting_horz_ != -1 && chroma_siting_vert_ != -1) {
147 vp_config.SetChromaLocation(chroma_siting_horz_, chroma_siting_vert_);
149 if (color_range_ != -1) {
150 if (color_range_ == 0)
151 vp_config.set_video_full_range_flag(
false);
152 else if (color_range_ == 1)
153 vp_config.set_video_full_range_flag(
true);
156 if (transfer_characteristics_ != -1) {
157 vp_config.set_transfer_characteristics(transfer_characteristics_);
159 if (color_primaries_ != -1) {
160 vp_config.set_color_primaries(color_primaries_);
166 return id == kWebMIdColor ||
id == kWebMIdProjection
168 : WebMParserClient::OnListStart(
id);
171 bool WebMVideoClient::OnListEnd(
int id) {
172 return id == kWebMIdColor ||
id == kWebMIdProjection
174 : WebMParserClient::OnListEnd(
id);
177 bool WebMVideoClient::OnUInt(
int id, int64_t val) {
178 int64_t* dst =
nullptr;
181 case kWebMIdPixelWidth:
184 case kWebMIdPixelHeight:
185 dst = &pixel_height_;
187 case kWebMIdPixelCropTop:
190 case kWebMIdPixelCropBottom:
193 case kWebMIdPixelCropLeft:
196 case kWebMIdPixelCropRight:
199 case kWebMIdDisplayWidth:
200 dst = &display_width_;
202 case kWebMIdDisplayHeight:
203 dst = &display_height_;
205 case kWebMIdDisplayUnit:
206 dst = &display_unit_;
208 case kWebMIdAlphaMode:
211 case kWebMIdColorMatrixCoefficients:
212 dst = &matrix_coefficients_;
214 case kWebMIdColorBitsPerChannel:
215 dst = &bits_per_channel_;
217 case kWebMIdColorChromaSubsamplingHorz:
218 dst = &chroma_subsampling_horz_;
220 case kWebMIdColorChromaSubsamplingVert:
221 dst = &chroma_subsampling_vert_;
223 case kWebMIdColorChromaSitingHorz:
224 dst = &chroma_siting_horz_;
226 case kWebMIdColorChromaSitingVert:
227 dst = &chroma_siting_vert_;
229 case kWebMIdColorRange:
232 case kWebMIdColorTransferCharacteristics:
233 dst = &transfer_characteristics_;
235 case kWebMIdColorPrimaries:
236 dst = &color_primaries_;
238 case kWebMIdColorMaxCLL:
239 case kWebMIdColorMaxFALL:
240 NOTIMPLEMENTED() <<
"HDR is not supported yet.";
242 case kWebMIdProjectionType:
243 LOG(WARNING) <<
"Ignoring ProjectionType with value " << val;
250 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
251 << *dst <<
" and " << val <<
")";
259 bool WebMVideoClient::OnBinary(
int ,
266 bool WebMVideoClient::OnFloat(
int ,
double ) {
All the methods that are virtual are virtual for mocking.