History

lavc/hevcdec: implement slice header parsing for nuh_layer_id>0

Cf. F.7.3.6.1 "General slice segment header syntax"

Anton Khirnov committed 2 years ago

Commit 02a94351 parent a811ab72 files · +33 −4Browse files

Unified · Split

2 files
  1. libavcodec/hevc/hevcdec.c +32 −4
  2. libavcodec/hevc/hevcdec.h +1 −0
libavcodec/hevc/hevcdec.c+32−4
@@ -584,7 +584,8 @@ static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext · 583 unmodified lines
584{584{
585 const HEVCPPS *pps;585 const HEVCPPS *pps;
586 const HEVCSPS *sps;586 const HEVCSPS *sps;
587 unsigned pps_id;587 const HEVCVPS *vps;
588 unsigned pps_id, layer_idx;
588 int i, ret;589 int i, ret;
589 590
590 // Coded parameters591 // Coded parameters
@@ -607,6 +608,8 @@ static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext · 16 unmodified lines
607 608
608 pps = s->ps.pps_list[pps_id];609 pps = s->ps.pps_list[pps_id];
609 sps = pps->sps;610 sps = pps->sps;
611 vps = sps->vps;
612 layer_idx = vps->layer_idx[s->nuh_layer_id];
610 613
611 if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)614 if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
612 sh->no_output_of_prior_pics_flag = 1;615 sh->no_output_of_prior_pics_flag = 1;
@@ -652,7 +655,8 @@ static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext · 39 unmodified lines
652 return AVERROR_INVALIDDATA;655 return AVERROR_INVALIDDATA;
653 }656 }
654 if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I &&657 if (IS_IRAP(s) && sh->slice_type != HEVC_SLICE_I &&
655 !pps->pps_curr_pic_ref_enabled_flag) {658 !pps->pps_curr_pic_ref_enabled_flag &&
659 s->nuh_layer_id == 0) {
656 av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");660 av_log(s->avctx, AV_LOG_ERROR, "Inter slices in an IRAP frame.\n");
657 return AVERROR_INVALIDDATA;661 return AVERROR_INVALIDDATA;
658 }662 }
@@ -665,8 +669,10 @@ static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext · 6 unmodified lines
665 if (sps->separate_colour_plane)669 if (sps->separate_colour_plane)
666 sh->colour_plane_id = get_bits(gb, 2);670 sh->colour_plane_id = get_bits(gb, 2);
667 671
668 if (!IS_IDR(s)) {672 if (!IS_IDR(s) ||
669 int poc, pos;673 (s->nuh_layer_id > 0 &&
674 !(vps->poc_lsb_not_present & (1 << layer_idx)))) {
675 int poc;
670 676
671 sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);677 sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
672 poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type);678 poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, s->nal_unit_type);
@@ -678,6 +684,10 @@ static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext · 5 unmodified lines
678 poc = sh->poc;684 poc = sh->poc;
679 }685 }
680 sh->poc = poc;686 sh->poc = poc;
687 }
688
689 if (!IS_IDR(s)) {
690 int pos;
681 691
682 sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);692 sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);
683 pos = get_bits_left(gb);693 pos = get_bits_left(gb);
@@ -724,6 +734,23 @@ static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, GetBitContext · 40 unmodified lines
724 sh->slice_temporal_mvp_enabled_flag = 0;734 sh->slice_temporal_mvp_enabled_flag = 0;
725 }735 }
726 736
737 sh->inter_layer_pred = 0;
738 if (s->nuh_layer_id > 0) {
739 int num_direct_ref_layers = vps->num_direct_ref_layers[layer_idx];
740
741 if (vps->default_ref_layers_active)
742 sh->inter_layer_pred = !!num_direct_ref_layers;
743 else if (num_direct_ref_layers) {
744 sh->inter_layer_pred = get_bits1(gb);
745
746 if (sh->inter_layer_pred && num_direct_ref_layers > 1) {
747 av_log(s->avctx, AV_LOG_ERROR,
748 "NumDirectRefLayers>1 not supported\n");
749 return AVERROR_PATCHWELCOME;
750 }
751 }
752 }
753
727 if (sps->sao_enabled) {754 if (sps->sao_enabled) {
728 sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);755 sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);
729 if (sps->chroma_format_idc) {756 if (sps->chroma_format_idc) {
@@ -3238,6 +3265,7 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal) · 2508 unmodified lines
3238 int ret;3265 int ret;
3239 3266
3240 s->nal_unit_type = nal->type;3267 s->nal_unit_type = nal->type;
3268 s->nuh_layer_id = nal->nuh_layer_id;
3241 s->temporal_id = nal->temporal_id;3269 s->temporal_id = nal->temporal_id;
3242 3270
3243 if (FF_HW_HAS_CB(s->avctx, decode_params) &&3271 if (FF_HW_HAS_CB(s->avctx, decode_params) &&
libavcodec/hevc/hevcdec.h+1−0
@@ -215,6 +215,7 @@ typedef struct SliceHeader { · 214 unmodified lines
215 uint8_t dependent_slice_segment_flag;215 uint8_t dependent_slice_segment_flag;
216 uint8_t pic_output_flag;216 uint8_t pic_output_flag;
217 uint8_t colour_plane_id;217 uint8_t colour_plane_id;
218 uint8_t inter_layer_pred;
218 219
219 ///< RPS coded in the slice header itself is stored here220 ///< RPS coded in the slice header itself is stored here
220 int short_term_ref_pic_set_sps_flag;221 int short_term_ref_pic_set_sps_flag;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t