History

avcodec/evc_parse: pass a GetBitContext to the slice header parsing function

James Almer committed 3 years ago

Commit e5da2ec1 parent 22128084 files · +35 −33Browse files

Unified · Split

4 files
  1. libavcodec/evc_frame_merge_bsf.c +5 −1
  2. libavcodec/evc_parse.c +23 −29
  3. libavcodec/evc_parse.h +2 −2
  4. libavcodec/evc_parser.c +5 −1
libavcodec/evc_frame_merge_bsf.c+5−1
@@ -145,7 +145,11 @@ static int evc_frame_merge_filter(AVBSFContext *bsf, AVPacket *out) · 144 unmodified lines
145145 case EVC_NOIDR_NUT: {
146146 EVCParserSliceHeader sh;
147147
148− err = ff_evc_parse_slice_header(&sh, &ctx->ps, nalu_type, nalu, nalu_size);
148+ err = init_get_bits8(&gb, nalu, nalu_size);
149+ if (err < 0)
150+ return err;
151+
152+ err = ff_evc_parse_slice_header(&gb, &sh, &ctx->ps, nalu_type);
149153 if (err < 0) {
150154 av_log(bsf, AV_LOG_ERROR, "Slice header parsing error\n");
151155 goto end;
libavcodec/evc_parse.c+23−29
@@ -44,21 +44,15 @@ int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx) · 43 unmodified lines
4444 }
4545
4646 // @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax)
47−int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps,
48− enum EVCNALUnitType nalu_type, const uint8_t *bs, int bs_size)
47+int ff_evc_parse_slice_header(GetBitContext *gb, EVCParserSliceHeader *sh,
48+ const EVCParamSets *ps, enum EVCNALUnitType nalu_type)
4949 {
50− GetBitContext gb;
5150 const EVCParserPPS *pps;
5251 const EVCParserSPS *sps;
53−
5452 int num_tiles_in_slice = 0;
5553 int slice_pic_parameter_set_id;
56− int ret;
57−
58− if ((ret = init_get_bits8(&gb, bs, bs_size)) < 0)
59− return ret;
6054
61− slice_pic_parameter_set_id = get_ue_golomb(&gb);
55+ slice_pic_parameter_set_id = get_ue_golomb(gb);
6256
6357 if (slice_pic_parameter_set_id < 0 || slice_pic_parameter_set_id >= EVC_MAX_PPS_COUNT)
6458 return AVERROR_INVALIDDATA;
@@ -75,47 +69,47 @@ int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps, · 10 unmodified lines
7569 sh->slice_pic_parameter_set_id = slice_pic_parameter_set_id;
7670
7771 if (!pps->single_tile_in_pic_flag) {
78− sh->single_tile_in_slice_flag = get_bits1(&gb);
79− sh->first_tile_id = get_bits(&gb, pps->tile_id_len_minus1 + 1);
72+ sh->single_tile_in_slice_flag = get_bits1(gb);
73+ sh->first_tile_id = get_bits(gb, pps->tile_id_len_minus1 + 1);
8074 } else
8175 sh->single_tile_in_slice_flag = 1;
8276
8377 if (!sh->single_tile_in_slice_flag) {
8478 if (pps->arbitrary_slice_present_flag)
85− sh->arbitrary_slice_flag = get_bits1(&gb);
79+ sh->arbitrary_slice_flag = get_bits1(gb);
8680
8781 if (!sh->arbitrary_slice_flag)
88− sh->last_tile_id = get_bits(&gb, pps->tile_id_len_minus1 + 1);
82+ sh->last_tile_id = get_bits(gb, pps->tile_id_len_minus1 + 1);
8983 else {
90− sh->num_remaining_tiles_in_slice_minus1 = get_ue_golomb(&gb);
84+ sh->num_remaining_tiles_in_slice_minus1 = get_ue_golomb(gb);
9185 num_tiles_in_slice = sh->num_remaining_tiles_in_slice_minus1 + 2;
9286 for (int i = 0; i < num_tiles_in_slice - 1; ++i)
93− sh->delta_tile_id_minus1[i] = get_ue_golomb(&gb);
87+ sh->delta_tile_id_minus1[i] = get_ue_golomb(gb);
9488 }
9589 }
9690
97− sh->slice_type = get_ue_golomb(&gb);
91+ sh->slice_type = get_ue_golomb(gb);
9892
9993 if (nalu_type == EVC_IDR_NUT)
100− sh->no_output_of_prior_pics_flag = get_bits1(&gb);
94+ sh->no_output_of_prior_pics_flag = get_bits1(gb);
10195
10296 if (sps->sps_mmvd_flag && ((sh->slice_type == EVC_SLICE_TYPE_B) || (sh->slice_type == EVC_SLICE_TYPE_P)))
103− sh->mmvd_group_enable_flag = get_bits1(&gb);
97+ sh->mmvd_group_enable_flag = get_bits1(gb);
10498 else
10599 sh->mmvd_group_enable_flag = 0;
106100
107101 if (sps->sps_alf_flag) {
108102 int ChromaArrayType = sps->chroma_format_idc;
109103
110− sh->slice_alf_enabled_flag = get_bits1(&gb);
104+ sh->slice_alf_enabled_flag = get_bits1(gb);
111105
112106 if (sh->slice_alf_enabled_flag) {
113− sh->slice_alf_luma_aps_id = get_bits(&gb, 5);
114− sh->slice_alf_map_flag = get_bits1(&gb);
115− sh->slice_alf_chroma_idc = get_bits(&gb, 2);
107+ sh->slice_alf_luma_aps_id = get_bits(gb, 5);
108+ sh->slice_alf_map_flag = get_bits1(gb);
109+ sh->slice_alf_chroma_idc = get_bits(gb, 2);
116110
117111 if ((ChromaArrayType == 1 || ChromaArrayType == 2) && sh->slice_alf_chroma_idc > 0)
118− sh->slice_alf_chroma_aps_id = get_bits(&gb, 5);
112+ sh->slice_alf_chroma_aps_id = get_bits(gb, 5);
119113 }
120114 if (ChromaArrayType == 3) {
121115 int sliceChromaAlfEnabledFlag = 0;
@@ -136,23 +130,23 @@ int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps, · 14 unmodified lines
136130 }
137131
138132 if (!sh->slice_alf_enabled_flag)
139− sh->slice_alf_chroma_idc = get_bits(&gb, 2);
133+ sh->slice_alf_chroma_idc = get_bits(gb, 2);
140134
141135 if (sliceChromaAlfEnabledFlag) {
142− sh->slice_alf_chroma_aps_id = get_bits(&gb, 5);
143− sh->slice_alf_chroma_map_flag = get_bits1(&gb);
136+ sh->slice_alf_chroma_aps_id = get_bits(gb, 5);
137+ sh->slice_alf_chroma_map_flag = get_bits1(gb);
144138 }
145139
146140 if (sliceChroma2AlfEnabledFlag) {
147− sh->slice_alf_chroma2_aps_id = get_bits(&gb, 5);
148− sh->slice_alf_chroma2_map_flag = get_bits1(&gb);
141+ sh->slice_alf_chroma2_aps_id = get_bits(gb, 5);
142+ sh->slice_alf_chroma2_map_flag = get_bits1(gb);
149143 }
150144 }
151145 }
152146
153147 if (nalu_type != EVC_IDR_NUT) {
154148 if (sps->sps_pocs_flag)
155− sh->slice_pic_order_cnt_lsb = get_bits(&gb, sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
149+ sh->slice_pic_order_cnt_lsb = get_bits(gb, sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
156150 }
157151
158152 // @note
libavcodec/evc_parse.h+2−2
@@ -117,8 +117,8 @@ static inline uint32_t evc_read_nal_unit_length(const uint8_t *bits, int bits_si · 116 unmodified lines
117117 // nuh_temporal_id specifies a temporal identifier for the NAL unit
118118 int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx);
119119
120−int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps,
121− enum EVCNALUnitType nalu_type, const uint8_t *buf, int buf_size);
120+int ff_evc_parse_slice_header(GetBitContext *gb, EVCParserSliceHeader *sh,
121+ const EVCParamSets *ps, enum EVCNALUnitType nalu_type);
122122
123123 // POC (picture order count of the current picture) derivation
124124 // @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count
libavcodec/evc_parser.c+5−1
@@ -116,7 +116,11 @@ static int parse_nal_unit(AVCodecParserContext *s, AVCodecContext *avctx, · 115 unmodified lines
116116 EVCParserSliceHeader sh;
117117 int bit_depth;
118118
119− ret = ff_evc_parse_slice_header(&sh, &ctx->ps, nalu_type, buf, buf_size);
119+ ret = init_get_bits8(&gb, buf, buf_size);
120+ if (ret < 0)
121+ return ret;
122+
123+ ret = ff_evc_parse_slice_header(&gb, &sh, &ctx->ps, nalu_type);
120124 if (ret < 0) {
121125 av_log(avctx, AV_LOG_ERROR, "Slice header parsing error\n");
122126 return ret;

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