7 #include "packager/media/filters/h265_parser.h"
12 #include "packager/base/logging.h"
13 #include "packager/media/filters/nalu_reader.h"
15 #define TRUE_OR_RETURN(a) \
18 DVLOG(1) << "Failure while processing " << #a; \
19 return kInvalidStream; \
23 #define OK_OR_RETURN(a) \
25 Result status = (a); \
30 namespace edash_packager {
34 int GetNumPicTotalCurr(
const H265SliceHeader& slice_header,
36 int num_pic_total_curr = 0;
37 const H265ReferencePictureSet& ref_pic_set =
38 slice_header.short_term_ref_pic_set_sps_flag
39 ? sps.st_ref_pic_sets[slice_header.short_term_ref_pic_set_idx]
40 : slice_header.st_ref_pic_set;
42 for (
int i = 0; i < ref_pic_set.num_negative_pics; i++) {
43 if (ref_pic_set.used_by_curr_pic_s0[i])
46 for (
int i = 0; i < ref_pic_set.num_positive_pics; i++) {
47 if (ref_pic_set.used_by_curr_pic_s1[i])
51 return num_pic_total_curr + slice_header.used_by_curr_pic_lt;
56 H265Pps::~H265Pps() {}
59 H265Sps::~H265Sps() {}
61 int H265Sps::GetPicSizeInCtbsY()
const {
62 int min_cb_log2_size_y = log2_min_luma_coding_block_size_minus3 + 3;
64 min_cb_log2_size_y + log2_diff_max_min_luma_coding_block_size;
65 int ctb_size_y = 1 << ctb_log2_size_y;
68 int pic_width_in_ctbs_y = (pic_width_in_luma_samples - 1) / ctb_size_y + 1;
69 int pic_height_in_ctbs_y = (pic_height_in_luma_samples - 1) / ctb_size_y + 1;
70 return pic_width_in_ctbs_y * pic_height_in_ctbs_y;
73 int H265Sps::GetChromaArrayType()
const {
74 if (!separate_colour_plane_flag)
75 return chroma_format_idc;
80 H265ReferencePictureListModifications::H265ReferencePictureListModifications() {
82 H265ReferencePictureListModifications::
83 ~H265ReferencePictureListModifications() {}
85 H265SliceHeader::H265SliceHeader() {}
86 H265SliceHeader::~H265SliceHeader() {}
88 H265Parser::H265Parser() {}
89 H265Parser::~H265Parser() {}
93 DCHECK(nalu.is_video_slice());
98 reader.Initialize(nalu.data() + nalu.header_size(), nalu.payload_size());
101 TRUE_OR_RETURN(br->ReadBool(&slice_header->first_slice_segment_in_pic_flag));
102 if (nalu.type() >= Nalu::H265_BLA_W_LP &&
103 nalu.type() <= Nalu::H265_RSV_IRAP_VCL23) {
104 TRUE_OR_RETURN(br->ReadBool(&slice_header->no_output_of_prior_pics_flag));
107 TRUE_OR_RETURN(br->ReadUE(&slice_header->pic_parameter_set_id));
108 const H265Pps* pps =
GetPps(slice_header->pic_parameter_set_id);
114 if (!slice_header->first_slice_segment_in_pic_flag) {
115 if (pps->dependent_slice_segments_enabled_flag) {
116 TRUE_OR_RETURN(br->ReadBool(&slice_header->dependent_slice_segment_flag));
118 const int bit_length = ceil(log2(sps->GetPicSizeInCtbsY()));
119 TRUE_OR_RETURN(br->ReadBits(bit_length, &slice_header->segment_address));
122 if (!slice_header->dependent_slice_segment_flag) {
123 TRUE_OR_RETURN(br->SkipBits(pps->num_extra_slice_header_bits));
124 TRUE_OR_RETURN(br->ReadUE(&slice_header->slice_type));
125 if (pps->output_flag_present_flag) {
126 TRUE_OR_RETURN(br->ReadBool(&slice_header->pic_output_flag));
128 if (sps->separate_colour_plane_flag) {
129 TRUE_OR_RETURN(br->ReadBits(2, &slice_header->colour_plane_id));
132 if (nalu.type() != Nalu::H265_IDR_W_RADL &&
133 nalu.type() != Nalu::H265_IDR_N_LP) {
134 TRUE_OR_RETURN(br->ReadBits(sps->log2_max_pic_order_cnt_lsb_minus4 + 4,
135 &slice_header->slice_pic_order_cnt_lsb));
138 br->ReadBool(&slice_header->short_term_ref_pic_set_sps_flag));
139 if (!slice_header->short_term_ref_pic_set_sps_flag) {
140 OK_OR_RETURN(ParseReferencePictureSet(
141 sps->num_short_term_ref_pic_sets, sps->num_short_term_ref_pic_sets,
142 sps->st_ref_pic_sets, br, &slice_header->st_ref_pic_set));
143 }
else if (sps->num_short_term_ref_pic_sets > 1) {
145 br->ReadBits(ceil(log2(sps->num_short_term_ref_pic_sets)),
146 &slice_header->short_term_ref_pic_set_idx));
149 if (sps->long_term_ref_pic_present_flag) {
150 if (sps->num_long_term_ref_pics > 0) {
151 TRUE_OR_RETURN(br->ReadUE(&slice_header->num_long_term_sps));
153 TRUE_OR_RETURN(br->ReadUE(&slice_header->num_long_term_pics));
155 const int pic_count =
156 slice_header->num_long_term_sps + slice_header->num_long_term_pics;
157 slice_header->long_term_pics_info.resize(pic_count);
158 for (
int i = 0; i < pic_count; i++) {
159 if (i < slice_header->num_long_term_sps) {
161 if (sps->num_long_term_ref_pics > 1) {
162 TRUE_OR_RETURN(br->ReadBits(
163 ceil(log2(sps->num_long_term_ref_pics)), <_idx_sps));
165 if (sps->used_by_curr_pic_lt_flag[lt_idx_sps])
166 slice_header->used_by_curr_pic_lt++;
168 TRUE_OR_RETURN(br->SkipBits(sps->log2_max_pic_order_cnt_lsb_minus4 +
170 bool used_by_curr_pic_lt_flag;
171 TRUE_OR_RETURN(br->ReadBool(&used_by_curr_pic_lt_flag));
172 if (used_by_curr_pic_lt_flag)
173 slice_header->used_by_curr_pic_lt++;
175 TRUE_OR_RETURN(br->ReadBool(&slice_header->long_term_pics_info[i]
176 .delta_poc_msb_present_flag));
177 if (slice_header->long_term_pics_info[i].delta_poc_msb_present_flag) {
178 TRUE_OR_RETURN(br->ReadUE(
179 &slice_header->long_term_pics_info[i].delta_poc_msb_cycle_lt));
184 if (sps->temporal_mvp_enabled_flag) {
186 br->ReadBool(&slice_header->slice_temporal_mvp_enabled_flag));
190 if (nalu.nuh_layer_id() != 0) {
191 NOTIMPLEMENTED() <<
"Multi-layer streams are not supported.";
192 return kUnsupportedStream;
195 if (sps->sample_adaptive_offset_enabled_flag) {
196 TRUE_OR_RETURN(br->ReadBool(&slice_header->slice_sao_luma_flag));
197 if (sps->GetChromaArrayType() != 0) {
198 TRUE_OR_RETURN(br->ReadBool(&slice_header->slice_sao_chroma_flag));
202 slice_header->num_ref_idx_l0_active_minus1 =
203 pps->num_ref_idx_l0_default_active_minus1;
204 slice_header->num_ref_idx_l1_active_minus1 =
205 pps->num_ref_idx_l1_default_active_minus1;
206 if (slice_header->slice_type == kPSlice ||
207 slice_header->slice_type == kBSlice) {
209 br->ReadBool(&slice_header->num_ref_idx_active_override_flag));
210 if (slice_header->num_ref_idx_active_override_flag) {
211 TRUE_OR_RETURN(br->ReadUE(&slice_header->num_ref_idx_l0_active_minus1));
212 if (slice_header->slice_type == kBSlice) {
214 br->ReadUE(&slice_header->num_ref_idx_l1_active_minus1));
218 const int num_pic_total_curr = GetNumPicTotalCurr(*slice_header, *sps);
219 if (pps->lists_modification_present_flag && num_pic_total_curr > 1) {
220 OK_OR_RETURN(SkipReferencePictureListModification(
221 *slice_header, *pps, num_pic_total_curr, br));
224 if (slice_header->slice_type == kBSlice) {
225 TRUE_OR_RETURN(br->ReadBool(&slice_header->mvd_l1_zero_flag));
227 if (pps->cabac_init_present_flag) {
228 TRUE_OR_RETURN(br->ReadBool(&slice_header->cabac_init_flag));
230 if (slice_header->slice_temporal_mvp_enabled_flag) {
231 if (slice_header->slice_type == kBSlice) {
232 TRUE_OR_RETURN(br->ReadBool(&slice_header->collocated_from_l0));
234 bool l0_greater_than_0 = slice_header->num_ref_idx_l0_active_minus1 > 0;
235 bool l1_greater_than_0 = slice_header->num_ref_idx_l1_active_minus1 > 0;
236 if (slice_header->collocated_from_l0 ? l0_greater_than_0
237 : l1_greater_than_0) {
238 TRUE_OR_RETURN(br->ReadUE(&slice_header->collocated_ref_idx));
242 if ((pps->weighted_pred_flag && slice_header->slice_type == kPSlice) ||
243 (pps->weighted_bipred_flag && slice_header->slice_type == kBSlice)) {
244 OK_OR_RETURN(SkipPredictionWeightTable(
245 slice_header->slice_type == kBSlice, *sps, *slice_header, br));
247 TRUE_OR_RETURN(br->ReadUE(&slice_header->five_minus_max_num_merge_cand));
250 TRUE_OR_RETURN(br->ReadSE(&slice_header->slice_qp_delta));
251 if (pps->slice_chroma_qp_offsets_present_flag) {
252 TRUE_OR_RETURN(br->ReadSE(&slice_header->slice_cb_qp_offset));
253 TRUE_OR_RETURN(br->ReadSE(&slice_header->slice_cr_qp_offset));
256 if (pps->chroma_qp_offset_list_enabled_flag) {
258 br->ReadBool(&slice_header->cu_chroma_qp_offset_enabled_flag));
260 if (pps->deblocking_filter_override_enabled_flag) {
262 br->ReadBool(&slice_header->deblocking_filter_override_flag));
264 if (slice_header->deblocking_filter_override_flag) {
266 br->ReadBool(&slice_header->slice_deblocking_filter_disabled_flag));
267 if (!slice_header->slice_deblocking_filter_disabled_flag) {
268 TRUE_OR_RETURN(br->ReadSE(&slice_header->slice_beta_offset_div2));
269 TRUE_OR_RETURN(br->ReadSE(&slice_header->slice_tc_offset_div2));
272 if (pps->loop_filter_across_slices_enabled_flag &&
273 (slice_header->slice_sao_luma_flag ||
274 slice_header->slice_sao_chroma_flag ||
275 !slice_header->slice_deblocking_filter_disabled_flag)) {
276 TRUE_OR_RETURN(br->ReadBool(
277 &slice_header->slice_loop_filter_across_slices_enabled_flag));
281 if (pps->tiles_enabled_flag || pps->entropy_coding_sync_enabled_flag) {
282 TRUE_OR_RETURN(br->ReadUE(&slice_header->num_entry_point_offsets));
283 if (slice_header->num_entry_point_offsets > 0) {
284 TRUE_OR_RETURN(br->ReadUE(&slice_header->offset_len_minus1));
285 slice_header->entry_point_offset_minus1.resize(
286 slice_header->num_entry_point_offsets);
287 for (
int i = 0; i < slice_header->num_entry_point_offsets; i++) {
289 br->ReadBits(slice_header->offset_len_minus1 + 1,
290 &slice_header->entry_point_offset_minus1[i]));
295 if (pps->slice_segment_header_extension_present_flag) {
296 int extension_length;
297 TRUE_OR_RETURN(br->ReadUE(&extension_length));
298 TRUE_OR_RETURN(br->SkipBits(extension_length * 8));
301 size_t epb = br->NumEmulationPreventionBytesRead();
302 slice_header->header_bit_size =
303 (nalu.payload_size() - epb) * 8 - br->NumBitsLeft();
309 DCHECK_EQ(Nalu::H265_PPS, nalu.type());
313 reader.Initialize(nalu.data() + nalu.header_size(), nalu.payload_size());
317 scoped_ptr<H265Pps> pps(
new H265Pps);
319 TRUE_OR_RETURN(br->ReadUE(&pps->pic_parameter_set_id));
320 TRUE_OR_RETURN(br->ReadUE(&pps->seq_parameter_set_id));
322 TRUE_OR_RETURN(br->ReadBool(&pps->dependent_slice_segments_enabled_flag));
323 TRUE_OR_RETURN(br->ReadBool(&pps->output_flag_present_flag));
324 TRUE_OR_RETURN(br->ReadBits(3, &pps->num_extra_slice_header_bits));
325 TRUE_OR_RETURN(br->ReadBool(&pps->sign_data_hiding_enabled_flag));
326 TRUE_OR_RETURN(br->ReadBool(&pps->cabac_init_present_flag));
328 TRUE_OR_RETURN(br->ReadUE(&pps->num_ref_idx_l0_default_active_minus1));
329 TRUE_OR_RETURN(br->ReadUE(&pps->num_ref_idx_l1_default_active_minus1));
330 TRUE_OR_RETURN(br->ReadSE(&pps->init_qp_minus26));
331 TRUE_OR_RETURN(br->ReadBool(&pps->constrained_intra_pred_flag));
332 TRUE_OR_RETURN(br->ReadBool(&pps->transform_skip_enabled_flag));
334 TRUE_OR_RETURN(br->ReadBool(&pps->cu_qp_delta_enabled_flag));
335 if (pps->cu_qp_delta_enabled_flag)
336 TRUE_OR_RETURN(br->ReadUE(&pps->diff_cu_qp_delta_depth));
337 TRUE_OR_RETURN(br->ReadSE(&pps->cb_qp_offset));
338 TRUE_OR_RETURN(br->ReadSE(&pps->cr_qp_offset));
340 TRUE_OR_RETURN(br->ReadBool(&pps->slice_chroma_qp_offsets_present_flag));
341 TRUE_OR_RETURN(br->ReadBool(&pps->weighted_pred_flag));
342 TRUE_OR_RETURN(br->ReadBool(&pps->weighted_bipred_flag));
343 TRUE_OR_RETURN(br->ReadBool(&pps->transquant_bypass_enabled_flag));
344 TRUE_OR_RETURN(br->ReadBool(&pps->tiles_enabled_flag));
345 TRUE_OR_RETURN(br->ReadBool(&pps->entropy_coding_sync_enabled_flag));
347 if (pps->tiles_enabled_flag) {
348 TRUE_OR_RETURN(br->ReadUE(&pps->num_tile_columns_minus1));
349 TRUE_OR_RETURN(br->ReadUE(&pps->num_tile_rows_minus1));
350 TRUE_OR_RETURN(br->ReadBool(&pps->uniform_spacing_flag));
351 if (!pps->uniform_spacing_flag) {
352 pps->column_width_minus1.resize(pps->num_tile_columns_minus1);
353 for (
int i = 0; i < pps->num_tile_columns_minus1; i++) {
354 TRUE_OR_RETURN(br->ReadUE(&pps->column_width_minus1[i]));
356 pps->row_height_minus1.resize(pps->num_tile_rows_minus1);
357 for (
int i = 0; i < pps->num_tile_rows_minus1; i++) {
358 TRUE_OR_RETURN(br->ReadUE(&pps->row_height_minus1[i]));
361 TRUE_OR_RETURN(br->ReadBool(&pps->loop_filter_across_tiles_enabled_flag));
364 TRUE_OR_RETURN(br->ReadBool(&pps->loop_filter_across_slices_enabled_flag));
365 TRUE_OR_RETURN(br->ReadBool(&pps->deblocking_filter_control_present_flag));
366 if (pps->deblocking_filter_control_present_flag) {
367 TRUE_OR_RETURN(br->ReadBool(&pps->deblocking_filter_override_enabled_flag));
368 TRUE_OR_RETURN(br->ReadBool(&pps->deblocking_filter_disabled_flag));
369 if (!pps->deblocking_filter_disabled_flag) {
370 TRUE_OR_RETURN(br->ReadSE(&pps->beta_offset_div2));
371 TRUE_OR_RETURN(br->ReadSE(&pps->tc_offset_div2));
375 TRUE_OR_RETURN(br->ReadBool(&pps->scaling_list_data_present_flag));
376 if (pps->scaling_list_data_present_flag) {
377 OK_OR_RETURN(SkipScalingListData(br));
380 TRUE_OR_RETURN(br->ReadBool(&pps->lists_modification_present_flag));
381 TRUE_OR_RETURN(br->ReadUE(&pps->log2_parallel_merge_level_minus2));
384 br->ReadBool(&pps->slice_segment_header_extension_present_flag));
386 bool pps_extension_present_flag;
387 bool pps_range_extension_flag =
false;
388 TRUE_OR_RETURN(br->ReadBool(&pps_extension_present_flag));
389 if (pps_extension_present_flag) {
390 TRUE_OR_RETURN(br->ReadBool(&pps_range_extension_flag));
392 TRUE_OR_RETURN(br->SkipBits(1 + 1 + 5));
395 if (pps_range_extension_flag) {
396 if (pps->transform_skip_enabled_flag) {
399 TRUE_OR_RETURN(br->ReadUE(&ignored));
402 TRUE_OR_RETURN(br->SkipBits(1));
403 TRUE_OR_RETURN(br->ReadBool(&pps->chroma_qp_offset_list_enabled_flag));
411 *pps_id = pps->pic_parameter_set_id;
412 active_ppses_[*pps_id] = pps.Pass();
418 DCHECK_EQ(Nalu::H265_SPS, nalu.type());
422 reader.Initialize(nalu.data() + nalu.header_size(), nalu.payload_size());
427 scoped_ptr<H265Sps> sps(
new H265Sps);
429 TRUE_OR_RETURN(br->ReadBits(4, &sps->video_parameter_set_id));
430 TRUE_OR_RETURN(br->ReadBits(3, &sps->max_sub_layers_minus1));
431 TRUE_OR_RETURN(br->ReadBool(&sps->temporal_id_nesting_flag));
433 OK_OR_RETURN(SkipProfileTierLevel(
true, sps->max_sub_layers_minus1, br));
435 TRUE_OR_RETURN(br->ReadUE(&sps->seq_parameter_set_id));
436 TRUE_OR_RETURN(br->ReadUE(&sps->chroma_format_idc));
437 if (sps->chroma_format_idc == 3) {
438 TRUE_OR_RETURN(br->ReadBool(&sps->separate_colour_plane_flag));
440 TRUE_OR_RETURN(br->ReadUE(&sps->pic_width_in_luma_samples));
441 TRUE_OR_RETURN(br->ReadUE(&sps->pic_height_in_luma_samples));
443 TRUE_OR_RETURN(br->ReadBool(&sps->conformance_window_flag));
444 if (sps->conformance_window_flag) {
445 TRUE_OR_RETURN(br->ReadUE(&sps->conf_win_left_offset));
446 TRUE_OR_RETURN(br->ReadUE(&sps->conf_win_right_offset));
447 TRUE_OR_RETURN(br->ReadUE(&sps->conf_win_top_offset));
448 TRUE_OR_RETURN(br->ReadUE(&sps->conf_win_bottom_offset));
451 TRUE_OR_RETURN(br->ReadUE(&sps->bit_depth_luma_minus8));
452 TRUE_OR_RETURN(br->ReadUE(&sps->bit_depth_chroma_minus8));
453 TRUE_OR_RETURN(br->ReadUE(&sps->log2_max_pic_order_cnt_lsb_minus4));
455 TRUE_OR_RETURN(br->ReadBool(&sps->sub_layer_ordering_info_present_flag));
456 int start = sps->sub_layer_ordering_info_present_flag
458 : sps->max_sub_layers_minus1;
459 for (
int i = start; i <= sps->max_sub_layers_minus1; i++) {
460 TRUE_OR_RETURN(br->ReadUE(&sps->max_dec_pic_buffering_minus1[i]));
461 TRUE_OR_RETURN(br->ReadUE(&sps->max_num_reorder_pics[i]));
462 TRUE_OR_RETURN(br->ReadUE(&sps->max_latency_increase_plus1[i]));
465 TRUE_OR_RETURN(br->ReadUE(&sps->log2_min_luma_coding_block_size_minus3));
466 TRUE_OR_RETURN(br->ReadUE(&sps->log2_diff_max_min_luma_coding_block_size));
467 TRUE_OR_RETURN(br->ReadUE(&sps->log2_min_luma_transform_block_size_minus2));
468 TRUE_OR_RETURN(br->ReadUE(&sps->log2_diff_max_min_luma_transform_block_size));
469 TRUE_OR_RETURN(br->ReadUE(&sps->max_transform_hierarchy_depth_inter));
470 TRUE_OR_RETURN(br->ReadUE(&sps->max_transform_hierarchy_depth_intra));
472 TRUE_OR_RETURN(br->ReadBool(&sps->scaling_list_enabled_flag));
473 if (sps->scaling_list_enabled_flag) {
474 TRUE_OR_RETURN(br->ReadBool(&sps->scaling_list_data_present_flag));
475 if (sps->scaling_list_data_present_flag) {
476 OK_OR_RETURN(SkipScalingListData(br));
480 TRUE_OR_RETURN(br->ReadBool(&sps->amp_enabled_flag));
481 TRUE_OR_RETURN(br->ReadBool(&sps->sample_adaptive_offset_enabled_flag));
482 TRUE_OR_RETURN(br->ReadBool(&sps->pcm_enabled_flag));
483 if (sps->pcm_enabled_flag) {
484 TRUE_OR_RETURN(br->ReadBits(4, &sps->pcm_sample_bit_depth_luma_minus1));
485 TRUE_OR_RETURN(br->ReadBits(4, &sps->pcm_sample_bit_depth_chroma_minus1));
487 br->ReadUE(&sps->log2_min_pcm_luma_coding_block_size_minus3));
489 br->ReadUE(&sps->log2_diff_max_min_pcm_luma_coding_block_size));
490 TRUE_OR_RETURN(br->ReadBool(&sps->pcm_loop_filter_disabled_flag));
493 TRUE_OR_RETURN(br->ReadUE(&sps->num_short_term_ref_pic_sets));
494 sps->st_ref_pic_sets.resize(sps->num_short_term_ref_pic_sets);
495 for (
int i = 0; i < sps->num_short_term_ref_pic_sets; i++) {
496 OK_OR_RETURN(ParseReferencePictureSet(sps->num_short_term_ref_pic_sets, i,
497 sps->st_ref_pic_sets, br,
498 &sps->st_ref_pic_sets[i]));
501 TRUE_OR_RETURN(br->ReadBool(&sps->long_term_ref_pic_present_flag));
502 if (sps->long_term_ref_pic_present_flag) {
503 TRUE_OR_RETURN(br->ReadUE(&sps->num_long_term_ref_pics));
504 sps->lt_ref_pic_poc_lsb.resize(sps->num_long_term_ref_pics);
505 sps->used_by_curr_pic_lt_flag.resize(sps->num_long_term_ref_pics);
506 for (
int i = 0; i < sps->num_long_term_ref_pics; i++) {
507 TRUE_OR_RETURN(br->ReadBits(sps->log2_max_pic_order_cnt_lsb_minus4 + 4,
508 &sps->lt_ref_pic_poc_lsb[i]));
510 TRUE_OR_RETURN(br->ReadBool(&temp));
511 sps->used_by_curr_pic_lt_flag[i] = temp;
515 TRUE_OR_RETURN(br->ReadBool(&sps->temporal_mvp_enabled_flag));
516 TRUE_OR_RETURN(br->ReadBool(&sps->strong_intra_smoothing_enabled_flag));
522 *sps_id = sps->seq_parameter_set_id;
523 active_spses_[*sps_id] = sps.Pass();
529 return active_ppses_[pps_id].get();
533 return active_spses_[sps_id].get();
536 H265Parser::Result H265Parser::ParseReferencePictureSet(
537 int num_short_term_ref_pic_sets,
539 const std::vector<H265ReferencePictureSet>& ref_pic_sets,
546 bool inter_ref_pic_set_prediction =
false;
547 if (st_rps_idx != 0) {
548 TRUE_OR_RETURN(br->ReadBool(&inter_ref_pic_set_prediction));
551 if (inter_ref_pic_set_prediction) {
553 if (st_rps_idx == num_short_term_ref_pic_sets) {
554 TRUE_OR_RETURN(br->ReadUE(&delta_idx));
556 TRUE_OR_RETURN(delta_idx <= st_rps_idx);
559 int ref_rps_idx = st_rps_idx - delta_idx;
560 DCHECK_LE(0, ref_rps_idx);
561 DCHECK_LT(ref_rps_idx, st_rps_idx);
564 int abs_delta_rps_minus1;
565 TRUE_OR_RETURN(br->ReadBool(&delta_rps_sign));
566 TRUE_OR_RETURN(br->ReadUE(&abs_delta_rps_minus1));
568 delta_rps_sign ? -(abs_delta_rps_minus1 + 1) : abs_delta_rps_minus1 + 1;
570 int ref_num_delta_pocs = ref_pic_sets[ref_rps_idx].num_delta_pocs;
571 std::vector<bool> used_by_curr_pic(ref_num_delta_pocs + 1);
572 std::vector<bool> use_delta(ref_num_delta_pocs + 1);
573 for (
int j = 0; j <= ref_num_delta_pocs; j++) {
575 TRUE_OR_RETURN(br->ReadBool(&temp));
576 used_by_curr_pic[j] = temp;
578 if (!used_by_curr_pic[j]) {
579 TRUE_OR_RETURN(br->ReadBool(&temp));
586 int ref_num_positive_pics = ref_pic_sets[ref_rps_idx].num_positive_pics;
587 int ref_num_negative_pics = ref_pic_sets[ref_rps_idx].num_negative_pics;
593 for (
int j = ref_num_positive_pics - 1; j >= 0; j--) {
594 int d_poc = ref_pic_sets[ref_rps_idx].delta_poc_s1[j] + delta_rps;
595 if (d_poc < 0 && use_delta[ref_num_negative_pics + j]) {
596 out_ref_pic_set->delta_poc_s0[i] = d_poc;
597 out_ref_pic_set->used_by_curr_pic_s0[i] =
598 used_by_curr_pic[ref_num_negative_pics + j];
602 if (delta_rps < 0 && use_delta[ref_num_delta_pocs]) {
603 out_ref_pic_set->delta_poc_s0[i] = delta_rps;
604 out_ref_pic_set->used_by_curr_pic_s0[i] =
605 used_by_curr_pic[ref_num_delta_pocs];
608 for (
int j = 0; j < ref_num_negative_pics; j++) {
609 int d_poc = ref_pic_sets[ref_rps_idx].delta_poc_s0[j] + delta_rps;
610 if (d_poc < 0 && use_delta[j]) {
611 out_ref_pic_set->delta_poc_s0[i] = d_poc;
612 out_ref_pic_set->used_by_curr_pic_s0[i] = used_by_curr_pic[j];
616 out_ref_pic_set->num_negative_pics = i;
622 for (
int j = ref_num_negative_pics - 1; j >= 0; j--) {
623 int d_poc = ref_pic_sets[ref_rps_idx].delta_poc_s0[j] + delta_rps;
624 if (d_poc > 0 && use_delta[j]) {
625 out_ref_pic_set->delta_poc_s1[i] = d_poc;
626 out_ref_pic_set->used_by_curr_pic_s1[i] = used_by_curr_pic[j];
630 if (delta_rps > 0 && use_delta[ref_num_delta_pocs]) {
631 out_ref_pic_set->delta_poc_s1[i] = delta_rps;
632 out_ref_pic_set->used_by_curr_pic_s1[i] =
633 used_by_curr_pic[ref_num_delta_pocs];
636 for (
int j = 0; j < ref_num_positive_pics; j++) {
637 int d_poc = ref_pic_sets[ref_rps_idx].delta_poc_s1[j] + delta_rps;
638 if (d_poc > 0 && use_delta[ref_num_negative_pics + j]) {
639 out_ref_pic_set->delta_poc_s1[i] = d_poc;
640 out_ref_pic_set->used_by_curr_pic_s1[i] =
641 used_by_curr_pic[ref_num_negative_pics + j];
645 out_ref_pic_set->num_positive_pics = i;
648 TRUE_OR_RETURN(br->ReadUE(&out_ref_pic_set->num_negative_pics));
649 TRUE_OR_RETURN(br->ReadUE(&out_ref_pic_set->num_positive_pics));
652 for (
int i = 0; i < out_ref_pic_set->num_negative_pics; i++) {
653 int delta_poc_s0_minus1;
654 TRUE_OR_RETURN(br->ReadUE(&delta_poc_s0_minus1));
655 out_ref_pic_set->delta_poc_s0[i] = prev_poc - (delta_poc_s0_minus1 + 1);
656 prev_poc = out_ref_pic_set->delta_poc_s0[i];
658 TRUE_OR_RETURN(br->ReadBool(&out_ref_pic_set->used_by_curr_pic_s0[i]));
662 for (
int i = 0; i < out_ref_pic_set->num_positive_pics; i++) {
663 int delta_poc_s1_minus1;
664 TRUE_OR_RETURN(br->ReadUE(&delta_poc_s1_minus1));
665 out_ref_pic_set->delta_poc_s1[i] = prev_poc + delta_poc_s1_minus1 + 1;
666 prev_poc = out_ref_pic_set->delta_poc_s1[i];
668 TRUE_OR_RETURN(br->ReadBool(&out_ref_pic_set->used_by_curr_pic_s1[i]));
672 out_ref_pic_set->num_delta_pocs =
673 out_ref_pic_set->num_positive_pics + out_ref_pic_set->num_negative_pics;
677 H265Parser::Result H265Parser::SkipReferencePictureListModification(
678 const H265SliceHeader& slice_header,
680 int num_pic_total_curr,
684 bool ref_pic_list_modification_flag_l0;
685 TRUE_OR_RETURN(br->ReadBool(&ref_pic_list_modification_flag_l0));
686 if (ref_pic_list_modification_flag_l0) {
687 for (
int i = 0; i <= pps.num_ref_idx_l0_default_active_minus1; i++) {
688 TRUE_OR_RETURN(br->SkipBits(ceil(log2(num_pic_total_curr))));
692 if (slice_header.slice_type == kBSlice) {
693 bool ref_pic_list_modification_flag_l1;
694 TRUE_OR_RETURN(br->ReadBool(&ref_pic_list_modification_flag_l1));
695 if (ref_pic_list_modification_flag_l1) {
696 for (
int i = 0; i <= pps.num_ref_idx_l1_default_active_minus1; i++) {
697 TRUE_OR_RETURN(br->SkipBits(ceil(log2(num_pic_total_curr))));
705 H265Parser::Result H265Parser::SkipPredictionWeightTablePart(
706 int num_ref_idx_minus1,
707 int chroma_array_type,
711 std::vector<bool> luma_weight_flag(num_ref_idx_minus1 + 1);
712 std::vector<bool> chroma_weight_flag(num_ref_idx_minus1 + 1);
714 for (
int i = 0; i <= num_ref_idx_minus1; i++) {
716 TRUE_OR_RETURN(br->ReadBool(&temp));
717 luma_weight_flag[i] = temp;
719 if (chroma_array_type != 0) {
720 for (
int i = 0; i <= num_ref_idx_minus1; i++) {
722 TRUE_OR_RETURN(br->ReadBool(&temp));
723 chroma_weight_flag[i] = temp;
726 for (
int i = 0; i <= num_ref_idx_minus1; i++) {
727 if (luma_weight_flag[i]) {
728 TRUE_OR_RETURN(br->ReadSE(&ignored));
729 TRUE_OR_RETURN(br->ReadSE(&ignored));
731 if (chroma_weight_flag[i]) {
732 for (
int j = 0; j < 2; j++) {
733 TRUE_OR_RETURN(br->ReadSE(&ignored));
734 TRUE_OR_RETURN(br->ReadSE(&ignored));
742 H265Parser::Result H265Parser::SkipPredictionWeightTable(
745 const H265SliceHeader& slice_header,
749 int chroma_array_type = sps.GetChromaArrayType();
751 TRUE_OR_RETURN(br->ReadUE(&ignored));
752 if (chroma_array_type != 0) {
753 TRUE_OR_RETURN(br->ReadSE(&ignored));
755 OK_OR_RETURN(SkipPredictionWeightTablePart(
756 slice_header.num_ref_idx_l0_active_minus1, chroma_array_type, br));
758 OK_OR_RETURN(SkipPredictionWeightTablePart(
759 slice_header.num_ref_idx_l1_active_minus1, chroma_array_type, br));
765 H265Parser::Result H265Parser::SkipProfileTierLevel(
766 bool profile_present,
767 int max_num_sub_layers_minus1,
771 if (profile_present) {
779 TRUE_OR_RETURN(br->SkipBits(2 + 1 + 5 + 32 + 4 + 44));
782 TRUE_OR_RETURN(br->SkipBits(8));
784 std::vector<bool> sub_layer_profile_present(max_num_sub_layers_minus1);
785 std::vector<bool> sub_layer_level_present(max_num_sub_layers_minus1);
786 for (
int i = 0; i < max_num_sub_layers_minus1; i++) {
788 TRUE_OR_RETURN(br->ReadBool(&profile));
789 TRUE_OR_RETURN(br->ReadBool(&level));
790 sub_layer_profile_present[i] = profile;
791 sub_layer_level_present[i] = level;
794 if (max_num_sub_layers_minus1 > 0) {
795 for (
int i = max_num_sub_layers_minus1; i < 8; i++)
796 TRUE_OR_RETURN(br->SkipBits(2));
799 for (
int i = 0; i < max_num_sub_layers_minus1; i++) {
800 if (sub_layer_profile_present[i]) {
805 TRUE_OR_RETURN(br->SkipBits(2 + 1 + 5 + 32 + 4 + 43 + 1));
807 if (sub_layer_level_present[i]) {
808 TRUE_OR_RETURN(br->SkipBits(8));
815 H265Parser::Result H265Parser::SkipScalingListData(H26xBitReader* br) {
818 for (
int size_id = 0; size_id < 4; size_id++) {
819 for (
int matrix_id = 0; matrix_id < 6;
820 matrix_id += ((size_id == 3) ? 3 : 1)) {
821 bool scaling_list_pred_mode;
822 TRUE_OR_RETURN(br->ReadBool(&scaling_list_pred_mode));
823 if (!scaling_list_pred_mode) {
825 TRUE_OR_RETURN(br->ReadUE(&ignored));
827 int coefNum = std::min(64, (1 << (4 + (size_id << 1))));
829 TRUE_OR_RETURN(br->ReadSE(&ignored));
832 for (
int i = 0; i < coefNum; i++) {
833 TRUE_OR_RETURN(br->ReadSE(&ignored));