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() {
34 WebMVideoClient::~WebMVideoClient() {
50 chroma_subsampling_horz_ = -1;
51 chroma_subsampling_vert_ = -1;
52 chroma_siting_horz_ = -1;
53 chroma_siting_vert_ = -1;
58 const std::string& codec_id,
60 Codec video_codec = kUnknownCodec;
61 if (codec_id ==
"V_VP8") {
62 video_codec = kCodecVP8;
63 }
else if (codec_id ==
"V_VP9") {
64 video_codec = kCodecVP9;
68 }
else if (codec_id ==
"V_VP10") {
69 video_codec = kCodecVP10;
71 LOG(ERROR) <<
"Unsupported video codec_id " << codec_id;
72 return std::shared_ptr<VideoStreamInfo>();
75 if (pixel_width_ <= 0 || pixel_height_ <= 0)
76 return std::shared_ptr<VideoStreamInfo>();
79 if (crop_bottom_ == -1)
88 if (crop_right_ == -1)
91 if (display_unit_ == -1)
94 uint16_t width_after_crop = pixel_width_ - (crop_left_ + crop_right_);
95 uint16_t height_after_crop = pixel_height_ - (crop_top_ + crop_bottom_);
97 if (display_unit_ == 0) {
98 if (display_width_ <= 0)
99 display_width_ = width_after_crop;
100 if (display_height_ <= 0)
101 display_height_ = height_after_crop;
102 }
else if (display_unit_ == 3) {
103 if (display_width_ <= 0 || display_height_ <= 0)
104 return std::shared_ptr<VideoStreamInfo>();
106 LOG(ERROR) <<
"Unsupported display unit type " << display_unit_;
107 return std::shared_ptr<VideoStreamInfo>();
110 int64_t sar_x = display_width_ * height_after_crop;
111 int64_t sar_y = display_height_ * width_after_crop;
112 int64_t gcd = GetGreatestCommonDivisor(sar_x, sar_y);
116 return std::make_shared<VideoStreamInfo>(
117 track_num, kWebMTimeScale, 0, video_codec, H26xStreamFormat::kUnSpecified,
118 std::string(),
nullptr, 0, width_after_crop, height_after_crop, sar_x,
119 sar_y, 0, 0, std::string(), is_encrypted);
123 const std::vector<uint8_t>& codec_private) {
125 if (chroma_subsampling_horz_ != -1 && chroma_subsampling_vert_ != -1) {
126 vp_config_.SetChromaSubsampling(chroma_subsampling_horz_,
127 chroma_subsampling_vert_);
129 if (chroma_siting_horz_ != -1 && chroma_siting_vert_ != -1) {
130 vp_config_.SetChromaLocation(chroma_siting_horz_, chroma_siting_vert_);
136 return id == kWebMIdColor ?
this : WebMParserClient::OnListStart(
id);
139 bool WebMVideoClient::OnListEnd(
int id) {
140 return id == kWebMIdColor ?
true : WebMParserClient::OnListEnd(
id);
143 bool WebMVideoClient::OnUInt(
int id, int64_t val) {
144 VPCodecConfigurationRecord vp_config;
148 case kWebMIdPixelWidth:
151 case kWebMIdPixelHeight:
152 dst = &pixel_height_;
154 case kWebMIdPixelCropTop:
157 case kWebMIdPixelCropBottom:
160 case kWebMIdPixelCropLeft:
163 case kWebMIdPixelCropRight:
166 case kWebMIdDisplayWidth:
167 dst = &display_width_;
169 case kWebMIdDisplayHeight:
170 dst = &display_height_;
172 case kWebMIdDisplayUnit:
173 dst = &display_unit_;
175 case kWebMIdAlphaMode:
178 case kWebMIdColorMatrixCoefficients:
179 vp_config.set_matrix_coefficients(static_cast<uint8_t>(val));
181 case kWebMIdColorBitsPerChannel:
182 vp_config.set_bit_depth(static_cast<uint8_t>(val));
184 case kWebMIdColorChromaSubsamplingHorz:
185 dst = &chroma_subsampling_horz_;
187 case kWebMIdColorChromaSubsamplingVert:
188 dst = &chroma_subsampling_vert_;
190 case kWebMIdColorChromaSitingHorz:
191 dst = &chroma_siting_horz_;
193 case kWebMIdColorChromaSitingVert:
194 dst = &chroma_siting_vert_;
196 case kWebMIdColorRange:
198 vp_config.set_video_full_range_flag(
false);
200 vp_config.set_video_full_range_flag(
true);
203 case kWebMIdColorTransferCharacteristics:
204 vp_config.set_transfer_characteristics(static_cast<uint8_t>(val));
206 case kWebMIdColorPrimaries:
207 vp_config.set_color_primaries(static_cast<uint8_t>(val));
209 case kWebMIdColorMaxCLL:
210 case kWebMIdColorMaxFALL:
211 NOTIMPLEMENTED() <<
"HDR is not supported yet.";
218 LOG(ERROR) <<
"Multiple values for id " << std::hex <<
id <<
" specified ("
219 << *dst <<
" and " << val <<
")";
227 bool WebMVideoClient::OnBinary(
int id,
const uint8_t* data,
int size) {
232 bool WebMVideoClient::OnFloat(
int id,
double val) {