/src/libhevc/decoder/ihevcd_parse_slice_header.c
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ******************************************************************************/ |
18 | | /** |
19 | | ******************************************************************************* |
20 | | * @file |
21 | | * ihevcd_parse_headers.c |
22 | | * |
23 | | * @brief |
24 | | * Contains functions for parsing headers |
25 | | * |
26 | | * @author |
27 | | * Harish |
28 | | * |
29 | | * @par List of Functions: |
30 | | * |
31 | | * @remarks |
32 | | * None |
33 | | * |
34 | | ******************************************************************************* |
35 | | */ |
36 | | |
37 | | /*****************************************************************************/ |
38 | | /* File Includes */ |
39 | | /*****************************************************************************/ |
40 | | #include <stdio.h> |
41 | | #include <stddef.h> |
42 | | #include <stdlib.h> |
43 | | #include <string.h> |
44 | | #include <assert.h> |
45 | | |
46 | | #include "ihevc_typedefs.h" |
47 | | #include "iv.h" |
48 | | #include "ivd.h" |
49 | | #include "ihevcd_cxa.h" |
50 | | |
51 | | #include "ihevc_defs.h" |
52 | | #include "ihevc_debug.h" |
53 | | #include "ihevc_defs.h" |
54 | | #include "ihevc_structs.h" |
55 | | #include "ihevc_buf_mgr.h" |
56 | | #include "ihevc_dpb_mgr.h" |
57 | | #include "ihevc_macros.h" |
58 | | #include "ihevc_platform_macros.h" |
59 | | #include "ihevc_cabac_tables.h" |
60 | | #include "ihevc_common_tables.h" |
61 | | #include "ihevc_quant_tables.h" |
62 | | |
63 | | #include "ihevcd_trace.h" |
64 | | #include "ihevcd_defs.h" |
65 | | #include "ihevcd_function_selector.h" |
66 | | #include "ihevcd_structs.h" |
67 | | #include "ihevcd_error.h" |
68 | | #include "ihevcd_debug.h" |
69 | | #include "ihevcd_nal.h" |
70 | | #include "ihevcd_bitstream.h" |
71 | | #include "ihevcd_parse_headers.h" |
72 | | #include "ihevcd_parse_slice_header.h" |
73 | | #include "ihevcd_ref_list.h" |
74 | | |
75 | | mv_buf_t* ihevcd_mv_mgr_get_poc(buf_mgr_t *ps_mv_buf_mgr, UWORD32 abs_poc); |
76 | | |
77 | | /** |
78 | | ******************************************************************************* |
79 | | * |
80 | | * @brief |
81 | | * Parses VPS operation point |
82 | | * |
83 | | * @par Description |
84 | | * Parses VPS operation point as per section 7.3.5 |
85 | | * |
86 | | * @param[out] ps_vps |
87 | | * Pointer to VPS structure |
88 | | * |
89 | | * @param[in] ps_bitstrm |
90 | | * Pointer to bitstream structure |
91 | | * |
92 | | * @param[in] ops_idx |
93 | | * Operating point index |
94 | | * |
95 | | * @returns Error code from IHEVCD_ERROR_T |
96 | | * |
97 | | * @remarks |
98 | | * |
99 | | ******************************************************************************* |
100 | | */ |
101 | | IHEVCD_ERROR_T ihevcd_operation_point_set(vps_t *ps_vps, bitstrm_t *ps_bitstrm, WORD32 ops_idx) |
102 | 0 | { |
103 | 0 | WORD32 i; |
104 | 0 | WORD32 value; |
105 | |
|
106 | 0 | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
107 | 0 | UNUSED(ops_idx); |
108 | 0 | for(i = 0; i <= ps_vps->i1_vps_max_nuh_reserved_zero_layer_id; i++) |
109 | 0 | { |
110 | 0 | BITS_PARSE("list_entry_l0[ i ]", value, ps_bitstrm, 1); |
111 | | //ps_vps->ai1_layer_id_included_flag[ops_idx][i] = value; |
112 | |
|
113 | 0 | } |
114 | 0 | UNUSED(value); |
115 | |
|
116 | 0 | return ret; |
117 | 0 | } |
118 | | |
119 | | /** |
120 | | ******************************************************************************* |
121 | | * |
122 | | * @brief |
123 | | * Parses pic_lismod_t (picture list mod syntax) Section:7.3.8.3 Reference |
124 | | * picture list mod syntax |
125 | | * |
126 | | * @par Description: |
127 | | * Parse pict list mod synt and update pic_lismod_t struct |
128 | | * |
129 | | * @param[in] ps_codec |
130 | | * Pointer to codec context |
131 | | * |
132 | | * @returns Error code from IHEVCD_ERROR_T |
133 | | * |
134 | | * @remarks |
135 | | * |
136 | | * |
137 | | ******************************************************************************* |
138 | | */ |
139 | | |
140 | | WORD32 ihevcd_ref_pic_list_modification(bitstrm_t *ps_bitstrm, |
141 | | slice_header_t *ps_slice_hdr, |
142 | | WORD32 num_poc_total_curr) |
143 | 4.35k | { |
144 | 4.35k | WORD32 ret = IHEVCD_SUCCESS; |
145 | 4.35k | WORD32 value; |
146 | 4.35k | WORD32 i; |
147 | 4.35k | rplm_t *ps_rplm; |
148 | 4.35k | WORD32 num_bits_list_entry; |
149 | | |
150 | 4.35k | ps_rplm = &(ps_slice_hdr->s_rplm); |
151 | | |
152 | | /* Calculate Ceil(Log2(num_poc_total_curr)) */ |
153 | 4.35k | { |
154 | 4.35k | num_bits_list_entry = 32 - CLZ(num_poc_total_curr); |
155 | | /* Check if num_poc_total_curr is power of 2 */ |
156 | 4.35k | if(0 == (num_poc_total_curr & (num_poc_total_curr - 1))) |
157 | 2.72k | { |
158 | 2.72k | num_bits_list_entry--; |
159 | 2.72k | } |
160 | 4.35k | } |
161 | | |
162 | 4.35k | if(ps_slice_hdr->i1_slice_type == PSLICE || ps_slice_hdr->i1_slice_type == BSLICE) |
163 | 4.35k | { |
164 | 4.35k | BITS_PARSE("ref_pic_list_modification_flag_l0", value, ps_bitstrm, 1); |
165 | 4.35k | ps_rplm->i1_ref_pic_list_modification_flag_l0 = value; |
166 | | |
167 | 4.35k | if(ps_rplm->i1_ref_pic_list_modification_flag_l0) |
168 | 9.63k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++) |
169 | 7.61k | { |
170 | 7.61k | BITS_PARSE("list_entry_l0", value, ps_bitstrm, num_bits_list_entry); |
171 | 7.61k | ps_rplm->i1_list_entry_l0[i] = value; |
172 | | |
173 | 7.61k | ps_rplm->i1_list_entry_l0[i] = CLIP3(ps_rplm->i1_list_entry_l0[i], 0, num_poc_total_curr - 1); |
174 | 7.61k | } |
175 | 4.35k | } |
176 | | |
177 | 4.35k | if(ps_slice_hdr->i1_slice_type == BSLICE) |
178 | 4.31k | { |
179 | 4.31k | BITS_PARSE("ref_pic_list_modification_flag_l1", value, ps_bitstrm, 1); |
180 | 4.31k | ps_rplm->i1_ref_pic_list_modification_flag_l1 = value; |
181 | | |
182 | 4.31k | if(ps_rplm->i1_ref_pic_list_modification_flag_l1) |
183 | 9.01k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++) |
184 | 6.66k | { |
185 | 6.66k | BITS_PARSE("list_entry_l1", value, ps_bitstrm, num_bits_list_entry); |
186 | 6.66k | ps_rplm->i1_list_entry_l1[i] = value; |
187 | | |
188 | 6.66k | ps_rplm->i1_list_entry_l1[i] = CLIP3(ps_rplm->i1_list_entry_l1[i], 0, num_poc_total_curr - 1); |
189 | 6.66k | } |
190 | | |
191 | 4.31k | } |
192 | | |
193 | 4.35k | return ret; |
194 | 4.35k | } |
195 | | |
196 | | /** |
197 | | ******************************************************************************* |
198 | | * |
199 | | * @brief |
200 | | * Parse Slice Header |
201 | | * slice_header_syntax() |
202 | | * |
203 | | * @par Description: |
204 | | * Parse Slice Header as per Section: 7.3.8 |
205 | | * |
206 | | * @param[in] ps_codec |
207 | | * Pointer to codec context |
208 | | * |
209 | | * @returns Error code from IHEVCD_ERROR_T |
210 | | * |
211 | | * @remarks |
212 | | * |
213 | | * |
214 | | ******************************************************************************* |
215 | | */ |
216 | | |
217 | | IHEVCD_ERROR_T ihevcd_parse_slice_header(codec_t *ps_codec, |
218 | | nal_header_t *ps_nal) |
219 | 119k | { |
220 | 119k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
221 | 119k | UWORD32 value; |
222 | 119k | WORD32 i4_value; |
223 | 119k | WORD32 i, j; |
224 | 119k | WORD32 sps_id; |
225 | | |
226 | 119k | pps_t *ps_pps; |
227 | 119k | sps_t *ps_sps; |
228 | 119k | slice_header_t *ps_slice_hdr; |
229 | 119k | WORD32 disable_deblocking_filter_flag; |
230 | 119k | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
231 | 119k | WORD32 idr_pic_flag; |
232 | 119k | WORD32 pps_id; |
233 | 119k | WORD32 first_slice_in_pic_flag; |
234 | 119k | WORD32 no_output_of_prior_pics_flag = 0; |
235 | 119k | WORD8 i1_nal_unit_type = ps_nal->i1_nal_unit_type; |
236 | 119k | WORD32 num_poc_total_curr = 0; |
237 | 119k | UWORD32 slice_address; |
238 | 119k | WORD32 prev_slice_incomplete_flag = 0; |
239 | | |
240 | 119k | if(ps_codec->i4_slice_error == 1) |
241 | 7.83k | return ret; |
242 | | |
243 | 112k | idr_pic_flag = (NAL_IDR_W_LP == i1_nal_unit_type) || |
244 | 106k | (NAL_IDR_N_LP == i1_nal_unit_type); |
245 | | |
246 | | |
247 | 112k | BITS_PARSE("first_slice_in_pic_flag", first_slice_in_pic_flag, ps_bitstrm, 1); |
248 | 112k | if((NAL_BLA_W_LP <= i1_nal_unit_type) && |
249 | 43.4k | (NAL_RSV_RAP_VCL23 >= i1_nal_unit_type)) |
250 | 43.4k | { |
251 | 43.4k | BITS_PARSE("no_output_of_prior_pics_flag", no_output_of_prior_pics_flag, ps_bitstrm, 1); |
252 | 43.4k | } |
253 | 112k | UEV_PARSE("pic_parameter_set_id", pps_id, ps_bitstrm); |
254 | 112k | if(pps_id < 0 || pps_id > MAX_PPS_CNT - 2) |
255 | 15.8k | { |
256 | 15.8k | return IHEVCD_INVALID_PARAMETER; |
257 | 15.8k | } |
258 | | |
259 | | /* Get the current PPS structure */ |
260 | 96.2k | ps_pps = ps_codec->s_parse.ps_pps_base + pps_id; |
261 | 96.2k | if(0 == ps_pps->i1_pps_valid) |
262 | 7.17k | { |
263 | 7.17k | pps_t *ps_pps_ref = ps_codec->ps_pps_base; |
264 | 14.2k | while(0 == ps_pps_ref->i1_pps_valid) |
265 | 7.12k | { |
266 | 7.12k | ps_pps_ref++; |
267 | 7.12k | if((ps_pps_ref - ps_codec->ps_pps_base >= MAX_PPS_CNT - 1)) |
268 | 5 | return IHEVCD_INVALID_HEADER; |
269 | 7.12k | } |
270 | | |
271 | 7.16k | ihevcd_copy_pps(ps_codec, pps_id, ps_pps_ref->i1_pps_id); |
272 | 7.16k | } |
273 | | |
274 | | /* Get SPS id for the current PPS */ |
275 | 96.2k | sps_id = ps_pps->i1_sps_id; |
276 | | |
277 | | /* Get the current SPS structure */ |
278 | 96.2k | ps_sps = ps_codec->s_parse.ps_sps_base + sps_id; |
279 | | |
280 | | /* When the current slice is the first in a pic, |
281 | | * check whether the previous frame is complete |
282 | | * If the previous frame is incomplete - |
283 | | * treat the remaining CTBs as skip */ |
284 | 96.2k | if((0 != ps_codec->u4_pic_cnt || ps_codec->i4_pic_present) && |
285 | 81.6k | first_slice_in_pic_flag) |
286 | 48.8k | { |
287 | 48.8k | if(ps_codec->i4_pic_present) |
288 | 4.27k | { |
289 | 4.27k | slice_header_t *ps_slice_hdr_next; |
290 | 4.27k | ps_codec->i4_slice_error = 1; |
291 | 4.27k | ps_codec->s_parse.i4_cur_slice_idx--; |
292 | 4.27k | if(ps_codec->s_parse.i4_cur_slice_idx < 0) |
293 | 0 | ps_codec->s_parse.i4_cur_slice_idx = 0; |
294 | | |
295 | 4.27k | ps_slice_hdr_next = ps_codec->s_parse.ps_slice_hdr_base + ((ps_codec->s_parse.i4_cur_slice_idx + 1) & (MAX_SLICE_HDR_CNT - 1)); |
296 | 4.27k | ps_slice_hdr_next->i2_ctb_x = 0; |
297 | 4.27k | ps_slice_hdr_next->i2_ctb_y = ps_codec->s_parse.ps_sps->i2_pic_ht_in_ctb; |
298 | 4.27k | return ret; |
299 | 4.27k | } |
300 | 44.5k | else |
301 | 44.5k | { |
302 | 44.5k | ps_codec->i4_slice_error = 0; |
303 | 44.5k | } |
304 | 48.8k | } |
305 | | |
306 | 91.9k | if(first_slice_in_pic_flag) |
307 | 56.6k | { |
308 | 56.6k | ps_codec->s_parse.i4_cur_slice_idx = 0; |
309 | 56.6k | } |
310 | 35.3k | else |
311 | 35.3k | { |
312 | | /* If the current slice is not the first slice in the pic, |
313 | | * but the first one to be parsed, set the current slice indx to 1 |
314 | | * Treat the first slice to be missing and copy the current slice header |
315 | | * to the first one */ |
316 | 35.3k | if(0 == ps_codec->i4_pic_present) |
317 | 16.6k | ps_codec->s_parse.i4_cur_slice_idx = 1; |
318 | 35.3k | } |
319 | | |
320 | 91.9k | ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr_base + (ps_codec->s_parse.i4_cur_slice_idx & (MAX_SLICE_HDR_CNT - 1)); |
321 | 91.9k | memset(ps_slice_hdr, 0, sizeof(*ps_slice_hdr)); |
322 | | |
323 | 91.9k | if((ps_pps->i1_dependent_slice_enabled_flag) && |
324 | 56.6k | (!first_slice_in_pic_flag)) |
325 | 19.4k | { |
326 | 19.4k | BITS_PARSE("dependent_slice_flag", value, ps_bitstrm, 1); |
327 | | |
328 | | /* First slice to be decoded in the current picture can't be dependent slice */ |
329 | 19.4k | if (value && 0 == ps_codec->i4_pic_present) |
330 | 3.21k | { |
331 | 3.21k | return IHEVCD_IGNORE_SLICE; |
332 | 3.21k | } |
333 | | |
334 | | /* If dependendent slice, copy slice header from previous slice */ |
335 | 16.1k | if(value && (ps_codec->s_parse.i4_cur_slice_idx > 0)) |
336 | 5.63k | { |
337 | 5.63k | ihevcd_copy_slice_hdr(ps_codec, |
338 | 5.63k | (ps_codec->s_parse.i4_cur_slice_idx & (MAX_SLICE_HDR_CNT - 1)), |
339 | 5.63k | ((ps_codec->s_parse.i4_cur_slice_idx - 1) & (MAX_SLICE_HDR_CNT - 1))); |
340 | 5.63k | } |
341 | 16.1k | ps_slice_hdr->i1_dependent_slice_flag = value; |
342 | 16.1k | } |
343 | 72.5k | else |
344 | 72.5k | { |
345 | 72.5k | ps_slice_hdr->i1_dependent_slice_flag = 0; |
346 | 72.5k | } |
347 | 88.7k | ps_slice_hdr->i1_nal_unit_type = i1_nal_unit_type; |
348 | 88.7k | ps_slice_hdr->i1_pps_id = pps_id; |
349 | 88.7k | ps_slice_hdr->i1_first_slice_in_pic_flag = first_slice_in_pic_flag; |
350 | | |
351 | 88.7k | ps_slice_hdr->i1_no_output_of_prior_pics_flag = 1; |
352 | 88.7k | if((NAL_BLA_W_LP <= i1_nal_unit_type) && |
353 | 39.8k | (NAL_RSV_RAP_VCL23 >= i1_nal_unit_type)) |
354 | 39.8k | { |
355 | 39.8k | ps_slice_hdr->i1_no_output_of_prior_pics_flag = no_output_of_prior_pics_flag; |
356 | 39.8k | } |
357 | 88.7k | ps_slice_hdr->i1_pps_id = pps_id; |
358 | | |
359 | 88.7k | if(!ps_slice_hdr->i1_first_slice_in_pic_flag) |
360 | 32.0k | { |
361 | 32.0k | WORD32 num_bits; |
362 | | |
363 | | /* Use CLZ to compute Ceil( Log2( PicSizeInCtbsY ) ) */ |
364 | 32.0k | num_bits = 32 - CLZ(ps_sps->i4_pic_size_in_ctb - 1); |
365 | 32.0k | BITS_PARSE("slice_address", value, ps_bitstrm, num_bits); |
366 | | |
367 | 32.0k | slice_address = value; |
368 | | /* If slice address is greater than the number of CTBs in a picture, |
369 | | * ignore the slice */ |
370 | 32.0k | if(value >= ps_sps->i4_pic_size_in_ctb || value == 0) |
371 | 1.98k | return IHEVCD_IGNORE_SLICE; |
372 | 32.0k | } |
373 | 56.6k | else |
374 | 56.6k | { |
375 | 56.6k | slice_address = 0; |
376 | 56.6k | } |
377 | | |
378 | 86.7k | if(!ps_slice_hdr->i1_dependent_slice_flag) |
379 | 81.2k | { |
380 | 81.2k | ps_slice_hdr->i1_pic_output_flag = 1; |
381 | 81.2k | ps_slice_hdr->i4_pic_order_cnt_lsb = 0; |
382 | 81.2k | ps_slice_hdr->i1_num_long_term_sps = 0; |
383 | 81.2k | ps_slice_hdr->i1_num_long_term_pics = 0; |
384 | | |
385 | 190k | for(i = 0; i < ps_pps->i1_num_extra_slice_header_bits; i++) |
386 | 108k | { |
387 | 108k | BITS_PARSE("slice_reserved_undetermined_flag[ i ]", value, ps_bitstrm, 1); |
388 | | //slice_reserved_undetermined_flag[ i ] |
389 | 108k | } |
390 | 81.2k | UEV_PARSE("slice_type", value, ps_bitstrm); |
391 | 81.2k | if(value > 2) |
392 | 3.15k | { |
393 | 3.15k | return IHEVCD_INVALID_PARAMETER; |
394 | 3.15k | } |
395 | 78.0k | ps_slice_hdr->i1_slice_type = value; |
396 | | |
397 | | /* If the picture is IRAP, slice type must be equal to ISLICE */ |
398 | 78.0k | if((ps_slice_hdr->i1_nal_unit_type >= NAL_BLA_W_LP) && |
399 | 36.6k | (ps_slice_hdr->i1_nal_unit_type <= NAL_RSV_RAP_VCL23)) |
400 | 36.6k | ps_slice_hdr->i1_slice_type = ISLICE; |
401 | | |
402 | 78.0k | if((ps_slice_hdr->i1_slice_type < 0) || |
403 | 78.0k | (ps_slice_hdr->i1_slice_type > 2)) |
404 | 0 | return IHEVCD_IGNORE_SLICE; |
405 | | |
406 | | |
407 | 78.0k | if(ps_pps->i1_output_flag_present_flag) |
408 | 13.9k | { |
409 | 13.9k | BITS_PARSE("pic_output_flag", value, ps_bitstrm, 1); |
410 | 13.9k | ps_slice_hdr->i1_pic_output_flag = value; |
411 | 13.9k | } |
412 | 78.0k | ps_slice_hdr->i1_colour_plane_id = 0; |
413 | 78.0k | if(1 == ps_sps->i1_separate_colour_plane_flag) |
414 | 0 | { |
415 | 0 | BITS_PARSE("colour_plane_id", value, ps_bitstrm, 2); |
416 | 0 | ps_slice_hdr->i1_colour_plane_id = value; |
417 | 0 | } |
418 | 78.0k | ps_slice_hdr->i1_slice_temporal_mvp_enable_flag = 0; |
419 | | |
420 | 78.0k | if(!idr_pic_flag) |
421 | 55.4k | { |
422 | | |
423 | 55.4k | WORD32 st_rps_idx; |
424 | 55.4k | WORD32 num_neg_pics; |
425 | 55.4k | WORD32 num_pos_pics; |
426 | 55.4k | WORD8 *pi1_used; |
427 | | |
428 | 55.4k | BITS_PARSE("pic_order_cnt_lsb", value, ps_bitstrm, ps_sps->i1_log2_max_pic_order_cnt_lsb); |
429 | | //value = ihevcd_extend_sign_bit(value, ps_sps->i1_log2_max_pic_order_cnt_lsb); |
430 | 55.4k | ps_slice_hdr->i4_pic_order_cnt_lsb = value; |
431 | | |
432 | 55.4k | BITS_PARSE("short_term_ref_pic_set_sps_flag", value, ps_bitstrm, 1); |
433 | 55.4k | ps_slice_hdr->i1_short_term_ref_pic_set_sps_flag = value; |
434 | | |
435 | 55.4k | if(1 == ps_slice_hdr->i1_short_term_ref_pic_set_sps_flag) |
436 | 45.7k | { |
437 | 45.7k | WORD32 numbits; |
438 | | |
439 | 45.7k | ps_slice_hdr->i1_short_term_ref_pic_set_idx = 0; |
440 | 45.7k | if(ps_sps->i1_num_short_term_ref_pic_sets > 1) |
441 | 18.6k | { |
442 | 18.6k | numbits = 32 - CLZ(ps_sps->i1_num_short_term_ref_pic_sets - 1); |
443 | 18.6k | BITS_PARSE("short_term_ref_pic_set_idx", value, ps_bitstrm, numbits); |
444 | 18.6k | if (value >= ps_sps->i1_num_short_term_ref_pic_sets) { |
445 | 839 | return IHEVCD_INVALID_PARAMETER; |
446 | 839 | } |
447 | 17.8k | ps_slice_hdr->i1_short_term_ref_pic_set_idx = value; |
448 | 17.8k | } |
449 | | |
450 | 44.9k | st_rps_idx = ps_slice_hdr->i1_short_term_ref_pic_set_idx; |
451 | 44.9k | num_neg_pics = ps_sps->as_stref_picset[st_rps_idx].i1_num_neg_pics; |
452 | 44.9k | num_pos_pics = ps_sps->as_stref_picset[st_rps_idx].i1_num_pos_pics; |
453 | 44.9k | pi1_used = ps_sps->as_stref_picset[st_rps_idx].ai1_used; |
454 | 44.9k | } |
455 | 9.73k | else |
456 | 9.73k | { |
457 | 9.73k | ret = ihevcd_short_term_ref_pic_set(ps_bitstrm, |
458 | 9.73k | &ps_sps->as_stref_picset[0], |
459 | 9.73k | ps_sps->i1_num_short_term_ref_pic_sets, |
460 | 9.73k | ps_sps->i1_num_short_term_ref_pic_sets, |
461 | 9.73k | &ps_slice_hdr->s_stref_picset); |
462 | 9.73k | if (ret != IHEVCD_SUCCESS) |
463 | 1.32k | { |
464 | 1.32k | return ret; |
465 | 1.32k | } |
466 | 8.41k | st_rps_idx = ps_sps->i1_num_short_term_ref_pic_sets; |
467 | 8.41k | num_neg_pics = ps_slice_hdr->s_stref_picset.i1_num_neg_pics; |
468 | 8.41k | num_pos_pics = ps_slice_hdr->s_stref_picset.i1_num_pos_pics; |
469 | 8.41k | pi1_used = ps_slice_hdr->s_stref_picset.ai1_used; |
470 | 8.41k | } |
471 | | |
472 | 53.3k | if(ps_sps->i1_long_term_ref_pics_present_flag) |
473 | 11.6k | { |
474 | 11.6k | if(ps_sps->i1_num_long_term_ref_pics_sps > 0) |
475 | 4.98k | { |
476 | 4.98k | UEV_PARSE("num_long_term_sps", value, ps_bitstrm); |
477 | 4.98k | if(value > ps_sps->i1_num_long_term_ref_pics_sps) |
478 | 129 | { |
479 | 129 | return IHEVCD_INVALID_PARAMETER; |
480 | 129 | } |
481 | 4.85k | ps_slice_hdr->i1_num_long_term_sps = value; |
482 | 4.85k | } |
483 | 11.5k | UEV_PARSE("num_long_term_pics", value, ps_bitstrm); |
484 | 11.5k | if(((ULWORD64)value + ps_slice_hdr->i1_num_long_term_sps + num_neg_pics + |
485 | 11.5k | num_pos_pics) > (MAX_DPB_SIZE - 1)) |
486 | 311 | { |
487 | 311 | return IHEVCD_INVALID_PARAMETER; |
488 | 311 | } |
489 | 11.2k | ps_slice_hdr->i1_num_long_term_pics = value; |
490 | | |
491 | 62.4k | for(i = 0; i < (ps_slice_hdr->i1_num_long_term_sps + |
492 | 62.4k | ps_slice_hdr->i1_num_long_term_pics); i++) |
493 | 51.2k | { |
494 | 51.2k | if(i < ps_slice_hdr->i1_num_long_term_sps) |
495 | 839 | { |
496 | | /* Use CLZ to compute Ceil( Log2( num_long_term_ref_pics_sps ) ) */ |
497 | 839 | if (ps_sps->i1_num_long_term_ref_pics_sps > 1) |
498 | 837 | { |
499 | 837 | WORD32 num_bits = 32 - CLZ(ps_sps->i1_num_long_term_ref_pics_sps - 1); |
500 | 837 | BITS_PARSE("lt_idx_sps[ i ]", value, ps_bitstrm, num_bits); |
501 | 837 | if(value >= ps_sps->i1_num_long_term_ref_pics_sps) |
502 | 76 | { |
503 | 76 | return IHEVCD_INVALID_PARAMETER; |
504 | 76 | } |
505 | 837 | } |
506 | 2 | else |
507 | 2 | { |
508 | 2 | value = 0; |
509 | 2 | } |
510 | 763 | ps_slice_hdr->ai4_poc_lsb_lt[i] = ps_sps->au2_lt_ref_pic_poc_lsb_sps[value]; |
511 | 763 | ps_slice_hdr->ai1_used_by_curr_pic_lt_flag[i] = ps_sps->ai1_used_by_curr_pic_lt_sps_flag[value]; |
512 | | |
513 | 763 | } |
514 | 50.4k | else |
515 | 50.4k | { |
516 | 50.4k | BITS_PARSE("poc_lsb_lt[ i ]", value, ps_bitstrm, ps_sps->i1_log2_max_pic_order_cnt_lsb); |
517 | 50.4k | ps_slice_hdr->ai4_poc_lsb_lt[i] = value; |
518 | | |
519 | 50.4k | BITS_PARSE("used_by_curr_pic_lt_flag[ i ]", value, ps_bitstrm, 1); |
520 | 50.4k | ps_slice_hdr->ai1_used_by_curr_pic_lt_flag[i] = value; |
521 | | |
522 | 50.4k | } |
523 | 51.2k | BITS_PARSE("delta_poc_msb_present_flag[ i ]", value, ps_bitstrm, 1); |
524 | 51.2k | ps_slice_hdr->ai1_delta_poc_msb_present_flag[i] = value; |
525 | | |
526 | | |
527 | 51.2k | ps_slice_hdr->ai1_delta_poc_msb_cycle_lt[i] = 0; |
528 | 51.2k | if(ps_slice_hdr->ai1_delta_poc_msb_present_flag[i]) |
529 | 7.87k | { |
530 | | |
531 | 7.87k | UEV_PARSE("delata_poc_msb_cycle_lt[ i ]", value, ps_bitstrm); |
532 | 7.87k | ps_slice_hdr->ai1_delta_poc_msb_cycle_lt[i] = value; |
533 | 7.87k | } |
534 | | |
535 | 51.2k | if((i != 0) && (i != ps_slice_hdr->i1_num_long_term_sps)) |
536 | 44.3k | { |
537 | 44.3k | ps_slice_hdr->ai1_delta_poc_msb_cycle_lt[i] += ps_slice_hdr->ai1_delta_poc_msb_cycle_lt[i - 1]; |
538 | 44.3k | } |
539 | | |
540 | 51.2k | } |
541 | 11.2k | } |
542 | | |
543 | 192k | for(i = 0; i < num_neg_pics + num_pos_pics; i++) |
544 | 139k | { |
545 | 139k | if(pi1_used[i]) |
546 | 125k | { |
547 | 125k | num_poc_total_curr++; |
548 | 125k | } |
549 | 139k | } |
550 | 104k | for(i = 0; i < ps_slice_hdr->i1_num_long_term_sps + ps_slice_hdr->i1_num_long_term_pics; i++) |
551 | 51.2k | { |
552 | 51.2k | if(ps_slice_hdr->ai1_used_by_curr_pic_lt_flag[i]) |
553 | 11.9k | { |
554 | 11.9k | num_poc_total_curr++; |
555 | 11.9k | } |
556 | 51.2k | } |
557 | | |
558 | | |
559 | 52.8k | if(ps_sps->i1_sps_temporal_mvp_enable_flag) |
560 | 30.5k | { |
561 | 30.5k | BITS_PARSE("enable_temporal_mvp_flag", value, ps_bitstrm, 1); |
562 | 30.5k | ps_slice_hdr->i1_slice_temporal_mvp_enable_flag = value; |
563 | 30.5k | } |
564 | | |
565 | 52.8k | } |
566 | 75.3k | ps_slice_hdr->i1_slice_sao_luma_flag = 0; |
567 | 75.3k | ps_slice_hdr->i1_slice_sao_chroma_flag = 0; |
568 | 75.3k | if(ps_sps->i1_sample_adaptive_offset_enabled_flag) |
569 | 58.8k | { |
570 | 58.8k | BITS_PARSE("slice_sao_luma_flag", value, ps_bitstrm, 1); |
571 | 58.8k | ps_slice_hdr->i1_slice_sao_luma_flag = value; |
572 | | |
573 | 58.8k | if (CHROMA_FMT_IDC_MONOCHROME != ps_sps->i1_chroma_format_idc) { |
574 | 58.8k | BITS_PARSE("slice_sao_chroma_flag", value, ps_bitstrm, 1); |
575 | 58.8k | ps_slice_hdr->i1_slice_sao_chroma_flag = value; |
576 | 58.8k | } |
577 | | |
578 | 58.8k | } |
579 | | |
580 | 75.3k | ps_slice_hdr->i1_max_num_merge_cand = 1; |
581 | 75.3k | ps_slice_hdr->i1_cabac_init_flag = 0; |
582 | | |
583 | 75.3k | ps_slice_hdr->i1_num_ref_idx_l0_active = 0; |
584 | 75.3k | ps_slice_hdr->i1_num_ref_idx_l1_active = 0; |
585 | 75.3k | ps_slice_hdr->i1_slice_cb_qp_offset = 0; |
586 | 75.3k | ps_slice_hdr->i1_slice_cr_qp_offset = 0; |
587 | 75.3k | if((PSLICE == ps_slice_hdr->i1_slice_type) || |
588 | 73.4k | (BSLICE == ps_slice_hdr->i1_slice_type)) |
589 | 38.1k | { |
590 | 38.1k | BITS_PARSE("num_ref_idx_active_override_flag", value, ps_bitstrm, 1); |
591 | 38.1k | ps_slice_hdr->i1_num_ref_idx_active_override_flag = value; |
592 | | |
593 | 38.1k | if(ps_slice_hdr->i1_num_ref_idx_active_override_flag) |
594 | 13.4k | { |
595 | 13.4k | UEV_PARSE("num_ref_idx_l0_active_minus1", value, ps_bitstrm); |
596 | 13.4k | if(value > MAX_DPB_SIZE - 2) |
597 | 94 | { |
598 | 94 | return IHEVCD_INVALID_PARAMETER; |
599 | 94 | } |
600 | 13.3k | ps_slice_hdr->i1_num_ref_idx_l0_active = value + 1; |
601 | | |
602 | 13.3k | if(BSLICE == ps_slice_hdr->i1_slice_type) |
603 | 12.6k | { |
604 | 12.6k | UEV_PARSE("num_ref_idx_l1_active_minus1", value, ps_bitstrm); |
605 | 12.6k | if(value > MAX_DPB_SIZE - 2) |
606 | 208 | { |
607 | 208 | return IHEVCD_INVALID_PARAMETER; |
608 | 208 | } |
609 | 12.4k | ps_slice_hdr->i1_num_ref_idx_l1_active = value + 1; |
610 | 12.4k | } |
611 | | |
612 | 13.3k | } |
613 | 24.7k | else |
614 | 24.7k | { |
615 | 24.7k | ps_slice_hdr->i1_num_ref_idx_l0_active = ps_pps->i1_num_ref_idx_l0_default_active; |
616 | 24.7k | if(BSLICE == ps_slice_hdr->i1_slice_type) |
617 | 23.5k | { |
618 | 23.5k | ps_slice_hdr->i1_num_ref_idx_l1_active = ps_pps->i1_num_ref_idx_l1_default_active; |
619 | 23.5k | } |
620 | 24.7k | } |
621 | | |
622 | 37.8k | if(0 == num_poc_total_curr) |
623 | 2.37k | return IHEVCD_IGNORE_SLICE; |
624 | 35.5k | if((ps_pps->i1_lists_modification_present_flag) && (num_poc_total_curr > 1)) |
625 | 4.35k | { |
626 | 4.35k | ihevcd_ref_pic_list_modification(ps_bitstrm, |
627 | 4.35k | ps_slice_hdr, num_poc_total_curr); |
628 | 4.35k | } |
629 | 31.1k | else |
630 | 31.1k | { |
631 | 31.1k | ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l0 = 0; |
632 | 31.1k | ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l1 = 0; |
633 | 31.1k | } |
634 | | |
635 | 35.5k | if(BSLICE == ps_slice_hdr->i1_slice_type) |
636 | 33.7k | { |
637 | 33.7k | BITS_PARSE("mvd_l1_zero_flag", value, ps_bitstrm, 1); |
638 | 33.7k | ps_slice_hdr->i1_mvd_l1_zero_flag = value; |
639 | 33.7k | } |
640 | | |
641 | 35.5k | ps_slice_hdr->i1_cabac_init_flag = 0; |
642 | 35.5k | if(ps_pps->i1_cabac_init_present_flag) |
643 | 29.1k | { |
644 | 29.1k | BITS_PARSE("cabac_init_flag", value, ps_bitstrm, 1); |
645 | 29.1k | ps_slice_hdr->i1_cabac_init_flag = value; |
646 | | |
647 | 29.1k | } |
648 | 35.5k | ps_slice_hdr->i1_collocated_from_l0_flag = 1; |
649 | 35.5k | ps_slice_hdr->i1_collocated_ref_idx = 0; |
650 | 35.5k | if(ps_slice_hdr->i1_slice_temporal_mvp_enable_flag) |
651 | 21.2k | { |
652 | 21.2k | if(BSLICE == ps_slice_hdr->i1_slice_type) |
653 | 20.6k | { |
654 | 20.6k | BITS_PARSE("collocated_from_l0_flag", value, ps_bitstrm, 1); |
655 | 20.6k | ps_slice_hdr->i1_collocated_from_l0_flag = value; |
656 | 20.6k | } |
657 | | |
658 | 21.2k | if((ps_slice_hdr->i1_collocated_from_l0_flag && (ps_slice_hdr->i1_num_ref_idx_l0_active > 1)) || |
659 | 14.0k | (!ps_slice_hdr->i1_collocated_from_l0_flag && (ps_slice_hdr->i1_num_ref_idx_l1_active > 1))) |
660 | 17.3k | { |
661 | 17.3k | UEV_PARSE("collocated_ref_idx", value, ps_bitstrm); |
662 | 17.3k | if((PSLICE == ps_slice_hdr->i1_slice_type || BSLICE == ps_slice_hdr->i1_slice_type) && |
663 | 17.3k | ps_slice_hdr->i1_collocated_from_l0_flag) |
664 | 7.13k | { |
665 | 7.13k | if(value >= ps_slice_hdr->i1_num_ref_idx_l0_active) |
666 | 361 | { |
667 | 361 | return IHEVCD_INVALID_PARAMETER; |
668 | 361 | } |
669 | 7.13k | } |
670 | 16.9k | if(BSLICE == ps_slice_hdr->i1_slice_type && !ps_slice_hdr->i1_collocated_from_l0_flag) |
671 | 10.1k | { |
672 | 10.1k | if(value >= ps_slice_hdr->i1_num_ref_idx_l1_active) |
673 | 337 | { |
674 | 337 | return IHEVCD_INVALID_PARAMETER; |
675 | 337 | } |
676 | 10.1k | } |
677 | 16.6k | ps_slice_hdr->i1_collocated_ref_idx = value; |
678 | 16.6k | } |
679 | | |
680 | 21.2k | } |
681 | | |
682 | 34.8k | if((ps_pps->i1_weighted_pred_flag && (PSLICE == ps_slice_hdr->i1_slice_type)) || |
683 | 33.2k | (ps_pps->i1_weighted_bipred_flag && (BSLICE == ps_slice_hdr->i1_slice_type))) |
684 | 9.59k | { |
685 | 9.59k | ihevcd_parse_pred_wt_ofst(ps_bitstrm, ps_sps, ps_pps, ps_slice_hdr); |
686 | 9.59k | } |
687 | 34.8k | UEV_PARSE("five_minus_max_num_merge_cand", value, ps_bitstrm); |
688 | 34.8k | if(value > 4) |
689 | 3.65k | { |
690 | 3.65k | return IHEVCD_INVALID_PARAMETER; |
691 | 3.65k | } |
692 | 31.1k | ps_slice_hdr->i1_max_num_merge_cand = 5 - value; |
693 | | |
694 | 31.1k | } |
695 | 68.3k | SEV_PARSE("slice_qp_delta", i4_value, ps_bitstrm); |
696 | 68.3k | if((i4_value < (MIN_HEVC_QP - ps_pps->i1_pic_init_qp)) || |
697 | 68.1k | (i4_value > (MAX_HEVC_QP - ps_pps->i1_pic_init_qp))) |
698 | 746 | { |
699 | 746 | return IHEVCD_INVALID_PARAMETER; |
700 | 746 | } |
701 | 67.5k | ps_slice_hdr->i1_slice_qp_delta = i4_value; |
702 | | |
703 | 67.5k | if(ps_pps->i1_pic_slice_level_chroma_qp_offsets_present_flag) |
704 | 23.8k | { |
705 | 23.8k | SEV_PARSE("slice_cb_qp_offset", i4_value, ps_bitstrm); |
706 | 23.8k | if(i4_value < -12 || i4_value > 12) |
707 | 491 | { |
708 | 491 | return IHEVCD_INVALID_PARAMETER; |
709 | 491 | } |
710 | 23.3k | ps_slice_hdr->i1_slice_cb_qp_offset = i4_value; |
711 | | |
712 | 23.3k | SEV_PARSE("slice_cr_qp_offset", i4_value, ps_bitstrm); |
713 | 23.3k | if(i4_value < -12 || i4_value > 12) |
714 | 517 | { |
715 | 517 | return IHEVCD_INVALID_PARAMETER; |
716 | 517 | } |
717 | 22.8k | ps_slice_hdr->i1_slice_cr_qp_offset = i4_value; |
718 | | |
719 | 22.8k | } |
720 | 66.5k | ps_slice_hdr->i1_deblocking_filter_override_flag = 0; |
721 | 66.5k | ps_slice_hdr->i1_slice_disable_deblocking_filter_flag = ps_pps->i1_pic_disable_deblocking_filter_flag; |
722 | 66.5k | ps_slice_hdr->i1_beta_offset_div2 = ps_pps->i1_beta_offset_div2; |
723 | 66.5k | ps_slice_hdr->i1_tc_offset_div2 = ps_pps->i1_tc_offset_div2; |
724 | | |
725 | 66.5k | disable_deblocking_filter_flag = ps_pps->i1_pic_disable_deblocking_filter_flag; |
726 | | |
727 | 66.5k | if(ps_pps->i1_deblocking_filter_control_present_flag) |
728 | 9.55k | { |
729 | | |
730 | 9.55k | if(ps_pps->i1_deblocking_filter_override_enabled_flag) |
731 | 4.63k | { |
732 | 4.63k | BITS_PARSE("deblocking_filter_override_flag", value, ps_bitstrm, 1); |
733 | 4.63k | ps_slice_hdr->i1_deblocking_filter_override_flag = value; |
734 | 4.63k | } |
735 | | |
736 | 9.55k | if(ps_slice_hdr->i1_deblocking_filter_override_flag) |
737 | 2.04k | { |
738 | 2.04k | BITS_PARSE("slice_disable_deblocking_filter_flag", value, ps_bitstrm, 1); |
739 | 2.04k | ps_slice_hdr->i1_slice_disable_deblocking_filter_flag = value; |
740 | 2.04k | disable_deblocking_filter_flag = ps_slice_hdr->i1_slice_disable_deblocking_filter_flag; |
741 | | |
742 | 2.04k | if(!ps_slice_hdr->i1_slice_disable_deblocking_filter_flag) |
743 | 456 | { |
744 | 456 | SEV_PARSE("beta_offset_div2", i4_value, ps_bitstrm); |
745 | 456 | if(i4_value < -6 || i4_value > 6) |
746 | 225 | { |
747 | 225 | return IHEVCD_INVALID_PARAMETER; |
748 | 225 | } |
749 | 231 | ps_slice_hdr->i1_beta_offset_div2 = i4_value; |
750 | | |
751 | 231 | SEV_PARSE("tc_offset_div2", i4_value, ps_bitstrm); |
752 | 231 | if(i4_value < -6 || i4_value > 6) |
753 | 39 | { |
754 | 39 | return IHEVCD_INVALID_PARAMETER; |
755 | 39 | } |
756 | 192 | ps_slice_hdr->i1_tc_offset_div2 = i4_value; |
757 | | |
758 | 192 | } |
759 | 2.04k | } |
760 | 9.55k | } |
761 | | |
762 | 66.3k | ps_slice_hdr->i1_slice_loop_filter_across_slices_enabled_flag = ps_pps->i1_loop_filter_across_slices_enabled_flag; |
763 | 66.3k | if(ps_pps->i1_loop_filter_across_slices_enabled_flag && |
764 | 33.1k | (ps_slice_hdr->i1_slice_sao_luma_flag || ps_slice_hdr->i1_slice_sao_chroma_flag || !disable_deblocking_filter_flag)) |
765 | 30.8k | { |
766 | 30.8k | BITS_PARSE("slice_loop_filter_across_slices_enabled_flag", value, ps_bitstrm, 1); |
767 | 30.8k | ps_slice_hdr->i1_slice_loop_filter_across_slices_enabled_flag = value; |
768 | 30.8k | } |
769 | | |
770 | 66.3k | } |
771 | | |
772 | | /* Check sanity of slice */ |
773 | 71.9k | if((!first_slice_in_pic_flag) && |
774 | 26.5k | (ps_codec->i4_pic_present)) |
775 | 17.7k | { |
776 | 17.7k | slice_header_t *ps_slice_hdr_base = ps_codec->ps_slice_hdr_base; |
777 | | |
778 | | |
779 | | /* According to the standard, the above conditions must be satisfied - But for error resilience, |
780 | | * only the following conditions are checked */ |
781 | 17.7k | if((ps_slice_hdr_base->i1_pps_id != ps_slice_hdr->i1_pps_id) || |
782 | 17.0k | (ps_slice_hdr_base->i4_pic_order_cnt_lsb != ps_slice_hdr->i4_pic_order_cnt_lsb)) |
783 | 1.61k | { |
784 | 1.61k | return IHEVCD_IGNORE_SLICE; |
785 | 1.61k | } |
786 | | |
787 | 17.7k | } |
788 | | |
789 | | |
790 | 70.2k | if(0 == ps_codec->i4_pic_present) |
791 | 54.1k | { |
792 | 54.1k | ps_slice_hdr->i4_abs_pic_order_cnt = ihevcd_calc_poc(ps_codec, ps_nal, ps_sps->i1_log2_max_pic_order_cnt_lsb, ps_slice_hdr->i4_pic_order_cnt_lsb); |
793 | 54.1k | } |
794 | 16.1k | else |
795 | 16.1k | { |
796 | 16.1k | ps_slice_hdr->i4_abs_pic_order_cnt = ps_codec->s_parse.i4_abs_pic_order_cnt; |
797 | 16.1k | } |
798 | | |
799 | | |
800 | 70.2k | if(!first_slice_in_pic_flag) |
801 | 24.9k | { |
802 | | /* Check if the current slice belongs to the same pic (Pic being parsed) */ |
803 | 24.9k | if(ps_codec->s_parse.i4_abs_pic_order_cnt == ps_slice_hdr->i4_abs_pic_order_cnt) |
804 | 20.1k | { |
805 | | |
806 | | /* If the Next CTB's index is less than the slice address, |
807 | | * the previous slice is incomplete. |
808 | | * Indicate slice error, and treat the remaining CTBs as skip */ |
809 | 20.1k | if(slice_address > ps_codec->s_parse.i4_next_ctb_indx) |
810 | 799 | { |
811 | 799 | if(ps_codec->i4_pic_present) |
812 | 799 | { |
813 | 799 | prev_slice_incomplete_flag = 1; |
814 | 799 | ps_codec->i4_slice_error = 1; |
815 | 799 | ps_codec->s_parse.i4_cur_slice_idx--; |
816 | 799 | if(ps_codec->s_parse.i4_cur_slice_idx < 0) |
817 | 0 | ps_codec->s_parse.i4_cur_slice_idx = 0; |
818 | 799 | } |
819 | 799 | return IHEVCD_IGNORE_SLICE; |
820 | 799 | } |
821 | | /* If the slice address is less than the next CTB's index, |
822 | | * extra CTBs have been decoded in the previous slice. |
823 | | * Ignore the current slice. Treat it as incomplete */ |
824 | 19.3k | else if(slice_address < ps_codec->s_parse.i4_next_ctb_indx) |
825 | 5.23k | { |
826 | 5.23k | return IHEVCD_IGNORE_SLICE; |
827 | 5.23k | } |
828 | 14.0k | else |
829 | 14.0k | { |
830 | 14.0k | ps_codec->i4_slice_error = 0; |
831 | 14.0k | } |
832 | 20.1k | } |
833 | | |
834 | | /* The current slice does not belong to the pic that is being parsed */ |
835 | 4.79k | else |
836 | 4.79k | { |
837 | | /* The previous pic is incomplete. |
838 | | * Treat the remaining CTBs as skip */ |
839 | 4.79k | if(ps_codec->i4_pic_present) |
840 | 0 | { |
841 | 0 | slice_header_t *ps_slice_hdr_next; |
842 | 0 | ps_codec->i4_slice_error = 1; |
843 | 0 | ps_codec->s_parse.i4_cur_slice_idx--; |
844 | 0 | if(ps_codec->s_parse.i4_cur_slice_idx < 0) |
845 | 0 | ps_codec->s_parse.i4_cur_slice_idx = 0; |
846 | |
|
847 | 0 | ps_slice_hdr_next = ps_codec->s_parse.ps_slice_hdr_base + ((ps_codec->s_parse.i4_cur_slice_idx + 1) & (MAX_SLICE_HDR_CNT - 1)); |
848 | 0 | ps_slice_hdr_next->i2_ctb_x = 0; |
849 | 0 | ps_slice_hdr_next->i2_ctb_y = ps_codec->s_parse.ps_sps->i2_pic_ht_in_ctb; |
850 | 0 | return ret; |
851 | 0 | } |
852 | | |
853 | | /* If the previous pic is complete, |
854 | | * return if the current slice is dependant |
855 | | * otherwise, update the parse context's POC */ |
856 | 4.79k | else |
857 | 4.79k | { |
858 | 4.79k | if(ps_slice_hdr->i1_dependent_slice_flag) |
859 | 0 | return IHEVCD_IGNORE_SLICE; |
860 | | |
861 | 4.79k | ps_codec->s_parse.i4_abs_pic_order_cnt = ps_slice_hdr->i4_abs_pic_order_cnt; |
862 | 4.79k | } |
863 | 4.79k | } |
864 | 24.9k | } |
865 | | |
866 | | /* If the slice is the first slice in the pic, update the parse context's POC */ |
867 | 45.3k | else |
868 | 45.3k | { |
869 | | /* If the first slice is repeated, ignore the second occurrence |
870 | | * If any other slice is repeated, the CTB addr will be greater than the slice addr, |
871 | | * and hence the second occurrence is ignored */ |
872 | 45.3k | if(ps_codec->s_parse.i4_abs_pic_order_cnt == ps_slice_hdr->i4_abs_pic_order_cnt) |
873 | 13.6k | return IHEVCD_IGNORE_SLICE; |
874 | | |
875 | 31.7k | ps_codec->s_parse.i4_abs_pic_order_cnt = ps_slice_hdr->i4_abs_pic_order_cnt; |
876 | 31.7k | } |
877 | | |
878 | | // printf("POC: %d\n", ps_slice_hdr->i4_abs_pic_order_cnt); |
879 | | // AEV_TRACE("POC", ps_slice_hdr->i4_abs_pic_order_cnt, 0); |
880 | 50.6k | ps_slice_hdr->i4_num_entry_point_offsets = 0; |
881 | 50.6k | if((ps_pps->i1_tiles_enabled_flag) || |
882 | 35.8k | (ps_pps->i1_entropy_coding_sync_enabled_flag)) |
883 | 22.5k | { |
884 | 22.5k | UEV_PARSE("num_entry_point_offsets", value, ps_bitstrm); |
885 | 22.5k | ps_slice_hdr->i4_num_entry_point_offsets = value; |
886 | | |
887 | 22.5k | { |
888 | 22.5k | WORD32 max_num_entry_point_offsets; |
889 | 22.5k | if((ps_pps->i1_tiles_enabled_flag) && |
890 | 14.7k | (ps_pps->i1_entropy_coding_sync_enabled_flag)) |
891 | 8.57k | { |
892 | 8.57k | max_num_entry_point_offsets = ps_pps->i1_num_tile_columns * ps_sps->i2_pic_ht_in_ctb - 1; |
893 | 8.57k | } |
894 | 13.9k | else if(ps_pps->i1_tiles_enabled_flag) |
895 | 6.22k | { |
896 | 6.22k | max_num_entry_point_offsets = ps_pps->i1_num_tile_columns * ps_pps->i1_num_tile_rows - 1 ; |
897 | 6.22k | } |
898 | 7.71k | else |
899 | 7.71k | { |
900 | 7.71k | max_num_entry_point_offsets = (ps_sps->i2_pic_ht_in_ctb - 1); |
901 | 7.71k | } |
902 | | |
903 | 22.5k | if(ps_slice_hdr->i4_num_entry_point_offsets < 0 || ps_slice_hdr->i4_num_entry_point_offsets > max_num_entry_point_offsets) |
904 | 672 | { |
905 | 672 | return IHEVCD_INVALID_PARAMETER; |
906 | 672 | } |
907 | 22.5k | } |
908 | | |
909 | 21.8k | if(ps_slice_hdr->i4_num_entry_point_offsets > 0) |
910 | 7.91k | { |
911 | 7.91k | UEV_PARSE("offset_len_minus1", value, ps_bitstrm); |
912 | 7.91k | if(value > 31) |
913 | 205 | { |
914 | 205 | return IHEVCD_INVALID_PARAMETER; |
915 | 205 | } |
916 | 7.70k | ps_slice_hdr->i1_offset_len = value + 1; |
917 | | |
918 | 29.5k | for(i = 0; i < ps_slice_hdr->i4_num_entry_point_offsets; i++) |
919 | 21.8k | { |
920 | 21.8k | BITS_PARSE("entry_point_offset", value, ps_bitstrm, ps_slice_hdr->i1_offset_len); |
921 | | |
922 | | /* TODO: pu4_entry_point_offset needs to be initialized */ |
923 | | //ps_slice_hdr->pu4_entry_point_offset[i] = value; |
924 | 21.8k | } |
925 | | |
926 | 7.70k | } |
927 | 21.8k | } |
928 | | |
929 | 49.7k | if(ps_pps->i1_slice_header_extension_present_flag) |
930 | 4.41k | { |
931 | 4.41k | UEV_PARSE("slice_header_extension_length", value, ps_bitstrm); |
932 | 4.41k | if(value > 256) |
933 | 811 | { |
934 | 811 | return IHEVCD_INVALID_PARAMETER; |
935 | 811 | } |
936 | 3.60k | ps_slice_hdr->i2_slice_header_extension_length = value; |
937 | | |
938 | | |
939 | 31.3k | for(i = 0; i < ps_slice_hdr->i2_slice_header_extension_length; i++) |
940 | 27.7k | { |
941 | 27.7k | BITS_PARSE("slice_header_extension_data_byte", value, ps_bitstrm, 8); |
942 | 27.7k | } |
943 | | |
944 | 3.60k | } |
945 | | |
946 | 48.9k | ihevcd_bits_flush_to_byte_boundary(ps_bitstrm); |
947 | | |
948 | 48.9k | if((UWORD8 *)ps_bitstrm->pu4_buf > ps_bitstrm->pu1_buf_max) |
949 | 862 | return IHEVCD_INVALID_PARAMETER; |
950 | | |
951 | 48.0k | { |
952 | 48.0k | dpb_mgr_t *ps_dpb_mgr = (dpb_mgr_t *)ps_codec->pv_dpb_mgr; |
953 | 48.0k | WORD32 r_idx; |
954 | | |
955 | 48.0k | if((NAL_IDR_W_LP == ps_slice_hdr->i1_nal_unit_type) || |
956 | 44.5k | (NAL_IDR_N_LP == ps_slice_hdr->i1_nal_unit_type) || |
957 | 30.3k | (NAL_BLA_N_LP == ps_slice_hdr->i1_nal_unit_type) || |
958 | 28.4k | (NAL_BLA_W_DLP == ps_slice_hdr->i1_nal_unit_type) || |
959 | 26.7k | (NAL_BLA_W_LP == ps_slice_hdr->i1_nal_unit_type) || |
960 | 26.4k | (0 == ps_codec->u4_pic_cnt)) |
961 | 25.2k | { |
962 | 1.63M | for(i = 0; i < MAX_DPB_BUFS; i++) |
963 | 1.61M | { |
964 | 1.61M | if(ps_dpb_mgr->as_dpb_info[i].ps_pic_buf) |
965 | 15.0k | { |
966 | 15.0k | pic_buf_t *ps_pic_buf = ps_dpb_mgr->as_dpb_info[i].ps_pic_buf; |
967 | 15.0k | mv_buf_t *ps_mv_buf; |
968 | | |
969 | | /* Long term index is set to MAX_DPB_BUFS to ensure it is not added as LT */ |
970 | 15.0k | ihevc_dpb_mgr_del_ref((dpb_mgr_t *)ps_codec->pv_dpb_mgr, (buf_mgr_t *)ps_codec->pv_pic_buf_mgr, ps_pic_buf->i4_abs_poc); |
971 | | /* Find buffer id of the MV bank corresponding to the buffer being freed (Buffer with POC of u4_abs_poc) */ |
972 | 15.0k | ps_mv_buf = (mv_buf_t *)ps_codec->ps_mv_buf; |
973 | 15.9k | for(j = 0; j < ps_codec->i4_max_dpb_size; j++) |
974 | 15.9k | { |
975 | 15.9k | if(ps_mv_buf && ps_mv_buf->i4_abs_poc == ps_pic_buf->i4_abs_poc) |
976 | 15.0k | { |
977 | 15.0k | ihevc_buf_mgr_release((buf_mgr_t *)ps_codec->pv_mv_buf_mgr, j, BUF_MGR_REF); |
978 | 15.0k | break; |
979 | 15.0k | } |
980 | 860 | ps_mv_buf++; |
981 | 860 | } |
982 | | |
983 | 15.0k | } |
984 | | |
985 | 1.61M | } |
986 | | |
987 | | /* Initialize the reference lists to NULL |
988 | | * This is done to take care of the cases where the first pic is not IDR |
989 | | * but the reference list is not created for the first pic because |
990 | | * pic count is zero leaving the reference list uninitialised */ |
991 | 428k | for(r_idx = 0; r_idx < MAX_DPB_SIZE; r_idx++) |
992 | 403k | { |
993 | 403k | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_pic_buf = NULL; |
994 | 403k | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_mv_buf = NULL; |
995 | | |
996 | 403k | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_pic_buf = NULL; |
997 | 403k | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_mv_buf = NULL; |
998 | 403k | } |
999 | | |
1000 | 25.2k | } |
1001 | 22.8k | else |
1002 | 22.8k | { |
1003 | 22.8k | ret = ihevcd_ref_list(ps_codec, ps_pps, ps_sps, ps_slice_hdr); |
1004 | 22.8k | if ((WORD32)IHEVCD_SUCCESS != ret) |
1005 | 1.63k | { |
1006 | 1.63k | return ret; |
1007 | 1.63k | } |
1008 | | |
1009 | 22.8k | } |
1010 | | |
1011 | 48.0k | } |
1012 | | |
1013 | | /* Fill the remaining entries of the reference lists with the nearest POC |
1014 | | * This is done to handle cases where there is a corruption in the reference index */ |
1015 | 46.4k | if(ps_codec->i4_pic_present) |
1016 | 14.0k | { |
1017 | 14.0k | pic_buf_t *ps_pic_buf_ref; |
1018 | 14.0k | mv_buf_t *ps_mv_buf_ref; |
1019 | 14.0k | WORD32 r_idx; |
1020 | 14.0k | dpb_mgr_t *ps_dpb_mgr = (dpb_mgr_t *)ps_codec->pv_dpb_mgr; |
1021 | 14.0k | buf_mgr_t *ps_mv_buf_mgr = (buf_mgr_t *)ps_codec->pv_mv_buf_mgr; |
1022 | | |
1023 | 14.0k | ps_pic_buf_ref = ihevc_dpb_mgr_get_ref_by_nearest_poc(ps_dpb_mgr, ps_slice_hdr->i4_abs_pic_order_cnt); |
1024 | 14.0k | if(NULL == ps_pic_buf_ref) |
1025 | 4.80k | { |
1026 | 4.80k | ps_pic_buf_ref = ps_codec->as_process[0].ps_cur_pic; |
1027 | 4.80k | ps_mv_buf_ref = ps_codec->s_parse.ps_cur_mv_buf; |
1028 | 4.80k | } |
1029 | 9.25k | else |
1030 | 9.25k | { |
1031 | 9.25k | ps_mv_buf_ref = ihevcd_mv_mgr_get_poc(ps_mv_buf_mgr, ps_pic_buf_ref->i4_abs_poc); |
1032 | 9.25k | } |
1033 | | |
1034 | 34.5k | for(r_idx = 0; r_idx < ps_slice_hdr->i1_num_ref_idx_l0_active; r_idx++) |
1035 | 20.5k | { |
1036 | 20.5k | if(NULL == ps_slice_hdr->as_ref_pic_list0[r_idx].pv_pic_buf) |
1037 | 1.60k | { |
1038 | 1.60k | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_pic_buf = (void *)ps_pic_buf_ref; |
1039 | 1.60k | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_mv_buf = (void *)ps_mv_buf_ref; |
1040 | 1.60k | } |
1041 | 20.5k | } |
1042 | | |
1043 | 218k | for(r_idx = ps_slice_hdr->i1_num_ref_idx_l0_active; r_idx < MAX_DPB_SIZE; r_idx++) |
1044 | 204k | { |
1045 | 204k | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_pic_buf = (void *)ps_pic_buf_ref; |
1046 | 204k | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_mv_buf = (void *)ps_mv_buf_ref; |
1047 | 204k | } |
1048 | | |
1049 | 34.9k | for(r_idx = 0; r_idx < ps_slice_hdr->i1_num_ref_idx_l1_active; r_idx++) |
1050 | 20.8k | { |
1051 | 20.8k | if(NULL == ps_slice_hdr->as_ref_pic_list1[r_idx].pv_pic_buf) |
1052 | 2.52k | { |
1053 | 2.52k | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_pic_buf = (void *)ps_pic_buf_ref; |
1054 | 2.52k | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_mv_buf = (void *)ps_mv_buf_ref; |
1055 | 2.52k | } |
1056 | 20.8k | } |
1057 | | |
1058 | 218k | for(r_idx = ps_slice_hdr->i1_num_ref_idx_l1_active; r_idx < MAX_DPB_SIZE; r_idx++) |
1059 | 204k | { |
1060 | 204k | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_pic_buf = (void *)ps_pic_buf_ref; |
1061 | 204k | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_mv_buf = (void *)ps_mv_buf_ref; |
1062 | 204k | } |
1063 | 14.0k | } |
1064 | | |
1065 | | /* Update slice address in the header */ |
1066 | 46.4k | if(!ps_slice_hdr->i1_first_slice_in_pic_flag) |
1067 | 18.2k | { |
1068 | 18.2k | ps_slice_hdr->i2_ctb_x = slice_address % ps_sps->i2_pic_wd_in_ctb; |
1069 | 18.2k | ps_slice_hdr->i2_ctb_y = slice_address / ps_sps->i2_pic_wd_in_ctb; |
1070 | | |
1071 | 18.2k | if(!ps_slice_hdr->i1_dependent_slice_flag) |
1072 | 14.0k | { |
1073 | 14.0k | ps_slice_hdr->i2_independent_ctb_x = ps_slice_hdr->i2_ctb_x; |
1074 | 14.0k | ps_slice_hdr->i2_independent_ctb_y = ps_slice_hdr->i2_ctb_y; |
1075 | 14.0k | } |
1076 | 18.2k | } |
1077 | 28.1k | else |
1078 | 28.1k | { |
1079 | 28.1k | ps_slice_hdr->i2_ctb_x = 0; |
1080 | 28.1k | ps_slice_hdr->i2_ctb_y = 0; |
1081 | | |
1082 | 28.1k | ps_slice_hdr->i2_independent_ctb_x = 0; |
1083 | 28.1k | ps_slice_hdr->i2_independent_ctb_y = 0; |
1084 | 28.1k | } |
1085 | | |
1086 | | /* If the first slice in the pic is missing, copy the current slice header to |
1087 | | * the first slice's header */ |
1088 | 46.4k | if((!first_slice_in_pic_flag) && |
1089 | 18.2k | (0 == ps_codec->i4_pic_present)) |
1090 | 4.18k | { |
1091 | 4.18k | slice_header_t *ps_slice_hdr_prev = ps_codec->s_parse.ps_slice_hdr_base; |
1092 | 4.18k | ihevcd_copy_slice_hdr(ps_codec, 0, (ps_codec->s_parse.i4_cur_slice_idx & (MAX_SLICE_HDR_CNT - 1))); |
1093 | | |
1094 | 4.18k | prev_slice_incomplete_flag = 1; |
1095 | 4.18k | ASSERT(ps_codec->s_parse.i4_cur_slice_idx == 1); |
1096 | | |
1097 | 4.18k | ps_slice_hdr_prev->i2_ctb_x = 0; |
1098 | 4.18k | ps_slice_hdr_prev->i2_ctb_y = 0; |
1099 | | |
1100 | 4.18k | ps_codec->s_parse.i4_ctb_x = 0; |
1101 | 4.18k | ps_codec->s_parse.i4_ctb_y = 0; |
1102 | | |
1103 | 4.18k | ps_codec->s_parse.i4_cur_slice_idx = 0; |
1104 | | |
1105 | 4.18k | if((ps_slice_hdr->i2_ctb_x == 0) && |
1106 | 1.70k | (ps_slice_hdr->i2_ctb_y == 0)) |
1107 | 0 | { |
1108 | 0 | ps_slice_hdr->i2_ctb_x++; |
1109 | 0 | } |
1110 | 4.18k | } |
1111 | | |
1112 | 46.4k | { |
1113 | | /* If skip B is enabled, |
1114 | | * ignore pictures that are non-reference |
1115 | | * TODO: (i1_nal_unit_type < NAL_BLA_W_LP) && (i1_nal_unit_type % 2 == 0) only says it is |
1116 | | * sub-layer non-reference slice. May need to find a way to detect actual non-reference pictures*/ |
1117 | | |
1118 | 46.4k | if((i1_nal_unit_type < NAL_BLA_W_LP) && |
1119 | 23.8k | (i1_nal_unit_type % 2 == 0)) |
1120 | 17.3k | { |
1121 | 17.3k | if(IVD_SKIP_B == ps_codec->e_pic_skip_mode) |
1122 | 0 | return IHEVCD_IGNORE_SLICE; |
1123 | 17.3k | } |
1124 | | |
1125 | | /* If skip PB is enabled, |
1126 | | * decode only I slices */ |
1127 | 46.4k | if((IVD_SKIP_PB == ps_codec->e_pic_skip_mode) && |
1128 | 0 | (ISLICE != ps_slice_hdr->i1_slice_type)) |
1129 | 0 | { |
1130 | 0 | return IHEVCD_IGNORE_SLICE; |
1131 | 0 | } |
1132 | 46.4k | } |
1133 | | |
1134 | 46.4k | if(prev_slice_incomplete_flag) |
1135 | 4.18k | { |
1136 | 4.18k | ps_codec->i4_slice_error = 1; |
1137 | 4.18k | ps_codec->s_parse.i4_cur_slice_idx--; |
1138 | 4.18k | if(ps_codec->s_parse.i4_cur_slice_idx < 0) |
1139 | 4.18k | ps_codec->s_parse.i4_cur_slice_idx = 0; |
1140 | 4.18k | } |
1141 | | |
1142 | 46.4k | return ret; |
1143 | 46.4k | } |