5 #include "packager/media/formats/webm/webm_video_client.h"
7 #include "packager/base/logging.h"
8 #include "packager/media/base/video_util.h"
9 #include "packager/media/codecs/av1_codec_configuration_record.h"
10 #include "packager/media/codecs/vp_codec_configuration_record.h"
11 #include "packager/media/formats/webm/webm_constants.h"
16 const uint32_t kWebMTimeScale = 1000000u;
23 WebMVideoClient::WebMVideoClient() {}
25 WebMVideoClient::~WebMVideoClient() {}
39 matrix_coefficients_ = -1;
40 bits_per_channel_ = -1;
41 chroma_subsampling_horz_ = -1;
42 chroma_subsampling_vert_ = -1;
43 chroma_siting_horz_ = -1;
44 chroma_siting_vert_ = -1;
46 transfer_characteristics_ = -1;
47 color_primaries_ = -1;
52 const std::string& codec_id,
53 const std::vector<uint8_t>& codec_private,
55 std::string codec_string;
56 Codec video_codec = kUnknownCodec;
57 if (codec_id ==
"V_AV1") {
58 video_codec = kCodecAV1;
63 if (!av1_config.
Parse(codec_private)) {
64 LOG(ERROR) <<
"Failed to parse AV1 codec_private.";
68 }
else if (codec_id ==
"V_VP8") {
69 video_codec = kCodecVP8;
71 }
else if (codec_id ==
"V_VP9") {
72 video_codec = kCodecVP9;
75 LOG(ERROR) <<
"Unsupported video codec_id " << codec_id;
79 if (pixel_width_ <= 0 || pixel_height_ <= 0)
83 if (crop_bottom_ == -1)
92 if (crop_right_ == -1)
95 if (display_unit_ == -1)
98 uint16_t width_after_crop = pixel_width_ - (crop_left_ + crop_right_);
99 uint16_t height_after_crop = pixel_height_ - (crop_top_ + crop_bottom_);
101 if (display_unit_ == 0) {
102 if (display_width_ <= 0)
103 display_width_ = width_after_crop;
104 if (display_height_ <= 0)
105 display_height_ = height_after_crop;
106 }
else if (display_unit_ == 3) {
107 if (display_width_ <= 0 || display_height_ <= 0)
110 LOG(ERROR) <<
"Unsupported display unit type " << display_unit_;
115 uint32_t pixel_width;
116 uint32_t pixel_height;
117 DerivePixelWidthHeight(width_after_crop, height_after_crop, display_width_,
118 display_height_, &pixel_width, &pixel_height);
123 return std::make_shared<VideoStreamInfo>(
124 track_num, kWebMTimeScale, 0, video_codec, H26xStreamFormat::kUnSpecified,
125 codec_string, codec_private.data(), codec_private.size(),
126 width_after_crop, height_after_crop, pixel_width, pixel_height, 0, 0,
127 0 , std::string(), is_encrypted);
131 const std::vector<uint8_t>& codec_private) {
134 if (matrix_coefficients_ != -1) {
135 vp_config.set_matrix_coefficients(matrix_coefficients_);
137 if (bits_per_channel_ != -1) {
138 vp_config.set_bit_depth(bits_per_channel_);
140 if (chroma_subsampling_horz_ != -1 && chroma_subsampling_vert_ != -1) {
141 vp_config.SetChromaSubsampling(chroma_subsampling_horz_,
142 chroma_subsampling_vert_);
144 if (chroma_siting_horz_ != -1 && chroma_siting_vert_ != -1) {
145 vp_config.SetChromaLocation(chroma_siting_horz_, chroma_siting_vert_);
147 if (color_range_ != -1) {
148 if (color_range_ == 0)
149 vp_config.set_video_full_range_flag(
false);
150 else if (color_range_ == 1)
151 vp_config.set_video_full_range_flag(
true);
154 if (transfer_characteristics_ != -1) {
155 vp_config.set_transfer_characteristics(transfer_characteristics_);
157 if (color_primaries_ != -1) {
158 vp_config.set_color_primaries(color_primaries_);
164 return id == kWebMIdColor ||
id == kWebMIdProjection
166 : WebMParserClient::OnListStart(
id);
169 bool WebMVideoClient::OnListEnd(
int id) {
170 return id == kWebMIdColor ||
id == kWebMIdProjection
172 : WebMParserClient::OnListEnd(
id);
175 bool WebMVideoClient::OnUInt(
int id, int64_t val) {
176 int64_t* dst =
nullptr;
179 case kWebMIdPixelWidth:
182 case kWebMIdPixelHeight:
183 dst = &pixel_height_;
185 case kWebMIdPixelCropTop:
188 case kWebMIdPixelCropBottom:
191 case kWebMIdPixelCropLeft:
194 case kWebMIdPixelCropRight:
197 case kWebMIdDisplayWidth:
198 dst = &display_width_;
200 case kWebMIdDisplayHeight:
201 dst = &display_height_;
203 case kWebMIdDisplayUnit:
204 dst = &display_unit_;
206 case kWebMIdAlphaMode:
209 case kWebMIdColorMatrixCoefficients:
210 dst = &matrix_coefficients_;
212 case kWebMIdColorBitsPerChannel:
213 dst = &bits_per_channel_;
215 case kWebMIdColorChromaSubsamplingHorz:
216 dst = &chroma_subsampling_horz_;
218 case kWebMIdColorChromaSubsamplingVert:
219 dst = &chroma_subsampling_vert_;
221 case kWebMIdColorChromaSitingHorz:
222 dst = &chroma_siting_horz_;
224 case kWebMIdColorChromaSitingVert:
225 dst = &chroma_siting_vert_;
227 case kWebMIdColorRange:
230 case kWebMIdColorTransferCharacteristics:
231 dst = &transfer_characteristics_;
233 case kWebMIdColorPrimaries:
234 dst = &color_primaries_;
236 case kWebMIdColorMaxCLL:
237 case kWebMIdColorMaxFALL:
238 NOTIMPLEMENTED() <<
"HDR is not supported yet.";
240 case kWebMIdProjectionType:
241 LOG(WARNING) <<
"Ignoring ProjectionType with value " << val;
248 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
249 << *dst <<
" and " << val <<
")";
257 bool WebMVideoClient::OnBinary(
int id,
const uint8_t* data,
int size) {
262 bool WebMVideoClient::OnFloat(
int id,
double val) {