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

Showing the changes to libavcodec (4 of 4 files). Show all

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
145 case EVC_NOIDR_NUT: {145 case EVC_NOIDR_NUT: {
146 EVCParserSliceHeader sh;146 EVCParserSliceHeader sh;
147 147
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);
149 if (err < 0) {153 if (err < 0) {
150 av_log(bsf, AV_LOG_ERROR, "Slice header parsing error\n");154 av_log(bsf, AV_LOG_ERROR, "Slice header parsing error\n");
151 goto end;155 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
44}44}
45 45
46// @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax)46// @see ISO_IEC_23094-1 (7.3.2.6 Slice layer RBSP syntax)
47int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps,47int ff_evc_parse_slice_header(GetBitContext *gb, EVCParserSliceHeader *sh,
48 enum EVCNALUnitType nalu_type, const uint8_t *bs, int bs_size)48 const EVCParamSets *ps, enum EVCNALUnitType nalu_type)
49{49{
50 GetBitContext gb;
51 const EVCParserPPS *pps;50 const EVCParserPPS *pps;
52 const EVCParserSPS *sps;51 const EVCParserSPS *sps;
53
54 int num_tiles_in_slice = 0;52 int num_tiles_in_slice = 0;
55 int slice_pic_parameter_set_id;53 int slice_pic_parameter_set_id;
56 int ret;
57
58 if ((ret = init_get_bits8(&gb, bs, bs_size)) < 0)
59 return ret;
60 54
61 slice_pic_parameter_set_id = get_ue_golomb(&gb);55 slice_pic_parameter_set_id = get_ue_golomb(gb);
62 56
63 if (slice_pic_parameter_set_id < 0 || slice_pic_parameter_set_id >= EVC_MAX_PPS_COUNT)57 if (slice_pic_parameter_set_id < 0 || slice_pic_parameter_set_id >= EVC_MAX_PPS_COUNT)
64 return AVERROR_INVALIDDATA;58 return AVERROR_INVALIDDATA;
@@ -75,47 +69,47 @@ int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps, · 10 unmodified lines
75 sh->slice_pic_parameter_set_id = slice_pic_parameter_set_id;69 sh->slice_pic_parameter_set_id = slice_pic_parameter_set_id;
76 70
77 if (!pps->single_tile_in_pic_flag) {71 if (!pps->single_tile_in_pic_flag) {
78 sh->single_tile_in_slice_flag = get_bits1(&gb);72 sh->single_tile_in_slice_flag = get_bits1(gb);
79 sh->first_tile_id = get_bits(&gb, pps->tile_id_len_minus1 + 1);73 sh->first_tile_id = get_bits(gb, pps->tile_id_len_minus1 + 1);
80 } else74 } else
81 sh->single_tile_in_slice_flag = 1;75 sh->single_tile_in_slice_flag = 1;
82 76
83 if (!sh->single_tile_in_slice_flag) {77 if (!sh->single_tile_in_slice_flag) {
84 if (pps->arbitrary_slice_present_flag)78 if (pps->arbitrary_slice_present_flag)
85 sh->arbitrary_slice_flag = get_bits1(&gb);79 sh->arbitrary_slice_flag = get_bits1(gb);
86 80
87 if (!sh->arbitrary_slice_flag)81 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);
89 else {83 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);
91 num_tiles_in_slice = sh->num_remaining_tiles_in_slice_minus1 + 2;85 num_tiles_in_slice = sh->num_remaining_tiles_in_slice_minus1 + 2;
92 for (int i = 0; i < num_tiles_in_slice - 1; ++i)86 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);
94 }88 }
95 }89 }
96 90
97 sh->slice_type = get_ue_golomb(&gb);91 sh->slice_type = get_ue_golomb(gb);
98 92
99 if (nalu_type == EVC_IDR_NUT)93 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);
101 95
102 if (sps->sps_mmvd_flag && ((sh->slice_type == EVC_SLICE_TYPE_B) || (sh->slice_type == EVC_SLICE_TYPE_P)))96 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);
104 else98 else
105 sh->mmvd_group_enable_flag = 0;99 sh->mmvd_group_enable_flag = 0;
106 100
107 if (sps->sps_alf_flag) {101 if (sps->sps_alf_flag) {
108 int ChromaArrayType = sps->chroma_format_idc;102 int ChromaArrayType = sps->chroma_format_idc;
109 103
110 sh->slice_alf_enabled_flag = get_bits1(&gb);104 sh->slice_alf_enabled_flag = get_bits1(gb);
111 105
112 if (sh->slice_alf_enabled_flag) {106 if (sh->slice_alf_enabled_flag) {
113 sh->slice_alf_luma_aps_id = get_bits(&gb, 5);107 sh->slice_alf_luma_aps_id = get_bits(gb, 5);
114 sh->slice_alf_map_flag = get_bits1(&gb);108 sh->slice_alf_map_flag = get_bits1(gb);
115 sh->slice_alf_chroma_idc = get_bits(&gb, 2);109 sh->slice_alf_chroma_idc = get_bits(gb, 2);
116 110
117 if ((ChromaArrayType == 1 || ChromaArrayType == 2) && sh->slice_alf_chroma_idc > 0)111 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);
119 }113 }
120 if (ChromaArrayType == 3) {114 if (ChromaArrayType == 3) {
121 int sliceChromaAlfEnabledFlag = 0;115 int sliceChromaAlfEnabledFlag = 0;
@@ -136,23 +130,23 @@ int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps, · 14 unmodified lines
136 }130 }
137 131
138 if (!sh->slice_alf_enabled_flag)132 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);
140 134
141 if (sliceChromaAlfEnabledFlag) {135 if (sliceChromaAlfEnabledFlag) {
142 sh->slice_alf_chroma_aps_id = get_bits(&gb, 5);136 sh->slice_alf_chroma_aps_id = get_bits(gb, 5);
143 sh->slice_alf_chroma_map_flag = get_bits1(&gb);137 sh->slice_alf_chroma_map_flag = get_bits1(gb);
144 }138 }
145 139
146 if (sliceChroma2AlfEnabledFlag) {140 if (sliceChroma2AlfEnabledFlag) {
147 sh->slice_alf_chroma2_aps_id = get_bits(&gb, 5);141 sh->slice_alf_chroma2_aps_id = get_bits(gb, 5);
148 sh->slice_alf_chroma2_map_flag = get_bits1(&gb);142 sh->slice_alf_chroma2_map_flag = get_bits1(gb);
149 }143 }
150 }144 }
151 }145 }
152 146
153 if (nalu_type != EVC_IDR_NUT) {147 if (nalu_type != EVC_IDR_NUT) {
154 if (sps->sps_pocs_flag)148 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);
156 }150 }
157 151
158 // @note152 // @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
117// nuh_temporal_id specifies a temporal identifier for the NAL unit117// nuh_temporal_id specifies a temporal identifier for the NAL unit
118int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx);118int ff_evc_get_temporal_id(const uint8_t *bits, int bits_size, void *logctx);
119 119
120int ff_evc_parse_slice_header(EVCParserSliceHeader *sh, const EVCParamSets *ps,120int ff_evc_parse_slice_header(GetBitContext *gb, EVCParserSliceHeader *sh,
121 enum EVCNALUnitType nalu_type, const uint8_t *buf, int buf_size);121 const EVCParamSets *ps, enum EVCNALUnitType nalu_type);
122 122
123// POC (picture order count of the current picture) derivation123// POC (picture order count of the current picture) derivation
124// @see ISO/IEC 23094-1:2020(E) 8.3.1 Decoding process for picture order count124// @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
116 EVCParserSliceHeader sh;116 EVCParserSliceHeader sh;
117 int bit_depth;117 int bit_depth;
118 118
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);
120 if (ret < 0) {124 if (ret < 0) {
121 av_log(avctx, AV_LOG_ERROR, "Slice header parsing error\n");125 av_log(avctx, AV_LOG_ERROR, "Slice header parsing error\n");
122 return ret;126 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