/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 | 2.14k | { |
144 | 2.14k | WORD32 ret = IHEVCD_SUCCESS; |
145 | 2.14k | WORD32 value; |
146 | 2.14k | WORD32 i; |
147 | 2.14k | rplm_t *ps_rplm; |
148 | 2.14k | WORD32 num_bits_list_entry; |
149 | | |
150 | 2.14k | ps_rplm = &(ps_slice_hdr->s_rplm); |
151 | | |
152 | | /* Calculate Ceil(Log2(num_poc_total_curr)) */ |
153 | 2.14k | { |
154 | 2.14k | num_bits_list_entry = 32 - CLZ(num_poc_total_curr); |
155 | | /* Check if num_poc_total_curr is power of 2 */ |
156 | 2.14k | if(0 == (num_poc_total_curr & (num_poc_total_curr - 1))) |
157 | 1.39k | { |
158 | 1.39k | num_bits_list_entry--; |
159 | 1.39k | } |
160 | 2.14k | } |
161 | | |
162 | 2.14k | if(ps_slice_hdr->i1_slice_type == PSLICE || ps_slice_hdr->i1_slice_type == BSLICE) |
163 | 2.14k | { |
164 | 2.14k | BITS_PARSE("ref_pic_list_modification_flag_l0", value, ps_bitstrm, 1); |
165 | 2.14k | ps_rplm->i1_ref_pic_list_modification_flag_l0 = value; |
166 | | |
167 | 2.14k | if(ps_rplm->i1_ref_pic_list_modification_flag_l0) |
168 | 6.58k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++) |
169 | 4.95k | { |
170 | 4.95k | BITS_PARSE("list_entry_l0", value, ps_bitstrm, num_bits_list_entry); |
171 | 4.95k | ps_rplm->i1_list_entry_l0[i] = value; |
172 | | |
173 | 4.95k | ps_rplm->i1_list_entry_l0[i] = CLIP3(ps_rplm->i1_list_entry_l0[i], 0, num_poc_total_curr - 1); |
174 | 4.95k | } |
175 | 2.14k | } |
176 | | |
177 | 2.14k | if(ps_slice_hdr->i1_slice_type == BSLICE) |
178 | 1.94k | { |
179 | 1.94k | BITS_PARSE("ref_pic_list_modification_flag_l1", value, ps_bitstrm, 1); |
180 | 1.94k | ps_rplm->i1_ref_pic_list_modification_flag_l1 = value; |
181 | | |
182 | 1.94k | if(ps_rplm->i1_ref_pic_list_modification_flag_l1) |
183 | 3.66k | for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++) |
184 | 2.35k | { |
185 | 2.35k | BITS_PARSE("list_entry_l1", value, ps_bitstrm, num_bits_list_entry); |
186 | 2.35k | ps_rplm->i1_list_entry_l1[i] = value; |
187 | | |
188 | 2.35k | ps_rplm->i1_list_entry_l1[i] = CLIP3(ps_rplm->i1_list_entry_l1[i], 0, num_poc_total_curr - 1); |
189 | 2.35k | } |
190 | | |
191 | 1.94k | } |
192 | | |
193 | 2.14k | return ret; |
194 | 2.14k | } |
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 | 69.1k | { |
220 | 69.1k | IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; |
221 | 69.1k | UWORD32 value; |
222 | 69.1k | WORD32 i4_value; |
223 | 69.1k | WORD32 i, j; |
224 | 69.1k | WORD32 sps_id; |
225 | | |
226 | 69.1k | pps_t *ps_pps; |
227 | 69.1k | sps_t *ps_sps; |
228 | 69.1k | slice_header_t *ps_slice_hdr; |
229 | 69.1k | WORD32 disable_deblocking_filter_flag; |
230 | 69.1k | bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; |
231 | 69.1k | WORD32 idr_pic_flag; |
232 | 69.1k | WORD32 pps_id; |
233 | 69.1k | WORD32 first_slice_in_pic_flag; |
234 | 69.1k | WORD32 no_output_of_prior_pics_flag = 0; |
235 | 69.1k | WORD8 i1_nal_unit_type = ps_nal->i1_nal_unit_type; |
236 | 69.1k | WORD32 num_poc_total_curr = 0; |
237 | 69.1k | UWORD32 slice_address; |
238 | 69.1k | WORD32 prev_slice_incomplete_flag = 0; |
239 | | |
240 | 69.1k | if(ps_codec->i4_slice_error == 1) |
241 | 6.18k | return ret; |
242 | | |
243 | 63.0k | idr_pic_flag = (NAL_IDR_W_LP == i1_nal_unit_type) || |
244 | 57.0k | (NAL_IDR_N_LP == i1_nal_unit_type); |
245 | | |
246 | | |
247 | 63.0k | BITS_PARSE("first_slice_in_pic_flag", first_slice_in_pic_flag, ps_bitstrm, 1); |
248 | 63.0k | if((NAL_BLA_W_LP <= i1_nal_unit_type) && |
249 | 21.1k | (NAL_RSV_RAP_VCL23 >= i1_nal_unit_type)) |
250 | 21.1k | { |
251 | 21.1k | BITS_PARSE("no_output_of_prior_pics_flag", no_output_of_prior_pics_flag, ps_bitstrm, 1); |
252 | 21.1k | } |
253 | 63.0k | UEV_PARSE("pic_parameter_set_id", pps_id, ps_bitstrm); |
254 | 63.0k | if(pps_id < 0 || pps_id > MAX_PPS_CNT - 2) |
255 | 8.53k | { |
256 | 8.53k | return IHEVCD_INVALID_PARAMETER; |
257 | 8.53k | } |
258 | | |
259 | | /* Get the current PPS structure */ |
260 | 54.4k | ps_pps = ps_codec->s_parse.ps_pps_base + pps_id; |
261 | 54.4k | if(0 == ps_pps->i1_pps_valid) |
262 | 2.84k | { |
263 | 2.84k | pps_t *ps_pps_ref = ps_codec->ps_pps_base; |
264 | 4.15k | while(0 == ps_pps_ref->i1_pps_valid) |
265 | 1.31k | { |
266 | 1.31k | ps_pps_ref++; |
267 | 1.31k | if((ps_pps_ref - ps_codec->ps_pps_base >= MAX_PPS_CNT - 1)) |
268 | 0 | return IHEVCD_INVALID_HEADER; |
269 | 1.31k | } |
270 | | |
271 | 2.84k | ihevcd_copy_pps(ps_codec, pps_id, ps_pps_ref->i1_pps_id); |
272 | 2.84k | } |
273 | | |
274 | | /* Get SPS id for the current PPS */ |
275 | 54.4k | sps_id = ps_pps->i1_sps_id; |
276 | | |
277 | | /* Get the current SPS structure */ |
278 | 54.4k | 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 | 54.4k | if((0 != ps_codec->u4_pic_cnt || ps_codec->i4_pic_present) && |
285 | 51.1k | first_slice_in_pic_flag) |
286 | 27.0k | { |
287 | 27.0k | if(ps_codec->i4_pic_present) |
288 | 2.05k | { |
289 | 2.05k | slice_header_t *ps_slice_hdr_next; |
290 | 2.05k | ps_codec->i4_slice_error = 1; |
291 | 2.05k | ps_codec->s_parse.i4_cur_slice_idx--; |
292 | 2.05k | if(ps_codec->s_parse.i4_cur_slice_idx < 0) |
293 | 0 | ps_codec->s_parse.i4_cur_slice_idx = 0; |
294 | | |
295 | 2.05k | 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 | 2.05k | ps_slice_hdr_next->i2_ctb_x = 0; |
297 | 2.05k | ps_slice_hdr_next->i2_ctb_y = ps_codec->s_parse.ps_sps->i2_pic_ht_in_ctb; |
298 | 2.05k | return ret; |
299 | 2.05k | } |
300 | 25.0k | else |
301 | 25.0k | { |
302 | 25.0k | ps_codec->i4_slice_error = 0; |
303 | 25.0k | } |
304 | 27.0k | } |
305 | | |
306 | 52.4k | if(first_slice_in_pic_flag) |
307 | 27.8k | { |
308 | 27.8k | ps_codec->s_parse.i4_cur_slice_idx = 0; |
309 | 27.8k | } |
310 | 24.5k | else |
311 | 24.5k | { |
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 | 24.5k | if(0 == ps_codec->i4_pic_present) |
317 | 10.0k | ps_codec->s_parse.i4_cur_slice_idx = 1; |
318 | 24.5k | } |
319 | | |
320 | 52.4k | 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 | 52.4k | memset(ps_slice_hdr, 0, sizeof(*ps_slice_hdr)); |
322 | | |
323 | 52.4k | if((ps_pps->i1_dependent_slice_enabled_flag) && |
324 | 33.5k | (!first_slice_in_pic_flag)) |
325 | 15.4k | { |
326 | 15.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 | 15.4k | if (value && 0 == ps_codec->i4_pic_present) |
330 | 3.75k | { |
331 | 3.75k | return IHEVCD_IGNORE_SLICE; |
332 | 3.75k | } |
333 | | |
334 | | /* If dependendent slice, copy slice header from previous slice */ |
335 | 11.7k | if(value && (ps_codec->s_parse.i4_cur_slice_idx > 0)) |
336 | 6.12k | { |
337 | 6.12k | ihevcd_copy_slice_hdr(ps_codec, |
338 | 6.12k | (ps_codec->s_parse.i4_cur_slice_idx & (MAX_SLICE_HDR_CNT - 1)), |
339 | 6.12k | ((ps_codec->s_parse.i4_cur_slice_idx - 1) & (MAX_SLICE_HDR_CNT - 1))); |
340 | 6.12k | } |
341 | 11.7k | ps_slice_hdr->i1_dependent_slice_flag = value; |
342 | 11.7k | } |
343 | 36.9k | else |
344 | 36.9k | { |
345 | 36.9k | ps_slice_hdr->i1_dependent_slice_flag = 0; |
346 | 36.9k | } |
347 | 48.6k | ps_slice_hdr->i1_nal_unit_type = i1_nal_unit_type; |
348 | 48.6k | ps_slice_hdr->i1_pps_id = pps_id; |
349 | 48.6k | ps_slice_hdr->i1_first_slice_in_pic_flag = first_slice_in_pic_flag; |
350 | | |
351 | 48.6k | ps_slice_hdr->i1_no_output_of_prior_pics_flag = 1; |
352 | 48.6k | if((NAL_BLA_W_LP <= i1_nal_unit_type) && |
353 | 19.4k | (NAL_RSV_RAP_VCL23 >= i1_nal_unit_type)) |
354 | 19.4k | { |
355 | 19.4k | ps_slice_hdr->i1_no_output_of_prior_pics_flag = no_output_of_prior_pics_flag; |
356 | 19.4k | } |
357 | 48.6k | ps_slice_hdr->i1_pps_id = pps_id; |
358 | | |
359 | 48.6k | if(!ps_slice_hdr->i1_first_slice_in_pic_flag) |
360 | 20.7k | { |
361 | 20.7k | WORD32 num_bits; |
362 | | |
363 | | /* Use CLZ to compute Ceil( Log2( PicSizeInCtbsY ) ) */ |
364 | 20.7k | num_bits = 32 - CLZ(ps_sps->i4_pic_size_in_ctb - 1); |
365 | 20.7k | BITS_PARSE("slice_address", value, ps_bitstrm, num_bits); |
366 | | |
367 | 20.7k | slice_address = value; |
368 | | /* If slice address is greater than the number of CTBs in a picture, |
369 | | * ignore the slice */ |
370 | 20.7k | if(value >= ps_sps->i4_pic_size_in_ctb || value == 0) |
371 | 895 | return IHEVCD_IGNORE_SLICE; |
372 | 20.7k | } |
373 | 27.8k | else |
374 | 27.8k | { |
375 | 27.8k | slice_address = 0; |
376 | 27.8k | } |
377 | | |
378 | 47.7k | if(!ps_slice_hdr->i1_dependent_slice_flag) |
379 | 41.7k | { |
380 | 41.7k | ps_slice_hdr->i1_pic_output_flag = 1; |
381 | 41.7k | ps_slice_hdr->i4_pic_order_cnt_lsb = 0; |
382 | 41.7k | ps_slice_hdr->i1_num_long_term_sps = 0; |
383 | 41.7k | ps_slice_hdr->i1_num_long_term_pics = 0; |
384 | | |
385 | 145k | for(i = 0; i < ps_pps->i1_num_extra_slice_header_bits; i++) |
386 | 103k | { |
387 | 103k | BITS_PARSE("slice_reserved_undetermined_flag[ i ]", value, ps_bitstrm, 1); |
388 | | //slice_reserved_undetermined_flag[ i ] |
389 | 103k | } |
390 | 41.7k | UEV_PARSE("slice_type", value, ps_bitstrm); |
391 | 41.7k | if(value > 2) |
392 | 1.42k | { |
393 | 1.42k | return IHEVCD_INVALID_PARAMETER; |
394 | 1.42k | } |
395 | 40.3k | ps_slice_hdr->i1_slice_type = value; |
396 | | |
397 | | /* If the picture is IRAP, slice type must be equal to ISLICE */ |
398 | 40.3k | if((ps_slice_hdr->i1_nal_unit_type >= NAL_BLA_W_LP) && |
399 | 17.6k | (ps_slice_hdr->i1_nal_unit_type <= NAL_RSV_RAP_VCL23)) |
400 | 17.6k | ps_slice_hdr->i1_slice_type = ISLICE; |
401 | | |
402 | 40.3k | if((ps_slice_hdr->i1_slice_type < 0) || |
403 | 40.3k | (ps_slice_hdr->i1_slice_type > 2)) |
404 | 0 | return IHEVCD_IGNORE_SLICE; |
405 | | |
406 | 40.3k | if(ps_pps->i1_output_flag_present_flag) |
407 | 15.0k | { |
408 | 15.0k | BITS_PARSE("pic_output_flag", value, ps_bitstrm, 1); |
409 | 15.0k | ps_slice_hdr->i1_pic_output_flag = value; |
410 | 15.0k | } |
411 | 40.3k | ps_slice_hdr->i1_colour_plane_id = 0; |
412 | 40.3k | if(1 == ps_sps->i1_separate_colour_plane_flag) |
413 | 0 | { |
414 | 0 | BITS_PARSE("colour_plane_id", value, ps_bitstrm, 2); |
415 | 0 | ps_slice_hdr->i1_colour_plane_id = value; |
416 | 0 | } |
417 | 40.3k | ps_slice_hdr->i1_slice_temporal_mvp_enable_flag = 0; |
418 | | |
419 | 40.3k | if(!idr_pic_flag) |
420 | 27.8k | { |
421 | | |
422 | 27.8k | WORD32 st_rps_idx; |
423 | 27.8k | WORD32 num_neg_pics; |
424 | 27.8k | WORD32 num_pos_pics; |
425 | 27.8k | WORD8 *pi1_used; |
426 | | |
427 | 27.8k | BITS_PARSE("pic_order_cnt_lsb", value, ps_bitstrm, ps_sps->i1_log2_max_pic_order_cnt_lsb); |
428 | | //value = ihevcd_extend_sign_bit(value, ps_sps->i1_log2_max_pic_order_cnt_lsb); |
429 | 27.8k | ps_slice_hdr->i4_pic_order_cnt_lsb = value; |
430 | | |
431 | 27.8k | BITS_PARSE("short_term_ref_pic_set_sps_flag", value, ps_bitstrm, 1); |
432 | 27.8k | ps_slice_hdr->i1_short_term_ref_pic_set_sps_flag = value; |
433 | | |
434 | 27.8k | if(1 == ps_slice_hdr->i1_short_term_ref_pic_set_sps_flag) |
435 | 18.6k | { |
436 | 18.6k | WORD32 numbits; |
437 | | |
438 | 18.6k | ps_slice_hdr->i1_short_term_ref_pic_set_idx = 0; |
439 | 18.6k | if(ps_sps->i1_num_short_term_ref_pic_sets > 1) |
440 | 8.44k | { |
441 | 8.44k | numbits = 32 - CLZ(ps_sps->i1_num_short_term_ref_pic_sets - 1); |
442 | 8.44k | BITS_PARSE("short_term_ref_pic_set_idx", value, ps_bitstrm, numbits); |
443 | 8.44k | if (value >= ps_sps->i1_num_short_term_ref_pic_sets) { |
444 | 149 | return IHEVCD_INVALID_PARAMETER; |
445 | 149 | } |
446 | 8.29k | ps_slice_hdr->i1_short_term_ref_pic_set_idx = value; |
447 | 8.29k | } |
448 | | |
449 | 18.4k | st_rps_idx = ps_slice_hdr->i1_short_term_ref_pic_set_idx; |
450 | 18.4k | num_neg_pics = ps_sps->as_stref_picset[st_rps_idx].i1_num_neg_pics; |
451 | 18.4k | num_pos_pics = ps_sps->as_stref_picset[st_rps_idx].i1_num_pos_pics; |
452 | 18.4k | pi1_used = ps_sps->as_stref_picset[st_rps_idx].ai1_used; |
453 | 18.4k | } |
454 | 9.16k | else |
455 | 9.16k | { |
456 | 9.16k | ret = ihevcd_short_term_ref_pic_set(ps_bitstrm, |
457 | 9.16k | &ps_sps->as_stref_picset[0], |
458 | 9.16k | ps_sps->i1_num_short_term_ref_pic_sets, |
459 | 9.16k | ps_sps->i1_num_short_term_ref_pic_sets, |
460 | 9.16k | &ps_slice_hdr->s_stref_picset); |
461 | 9.16k | if (ret != IHEVCD_SUCCESS) |
462 | 1.44k | { |
463 | 1.44k | return ret; |
464 | 1.44k | } |
465 | 7.72k | st_rps_idx = ps_sps->i1_num_short_term_ref_pic_sets; |
466 | 7.72k | num_neg_pics = ps_slice_hdr->s_stref_picset.i1_num_neg_pics; |
467 | 7.72k | num_pos_pics = ps_slice_hdr->s_stref_picset.i1_num_pos_pics; |
468 | 7.72k | pi1_used = ps_slice_hdr->s_stref_picset.ai1_used; |
469 | 7.72k | } |
470 | | |
471 | 26.2k | if(ps_sps->i1_long_term_ref_pics_present_flag) |
472 | 8.64k | { |
473 | 8.64k | if(ps_sps->i1_num_long_term_ref_pics_sps > 0) |
474 | 1.84k | { |
475 | 1.84k | UEV_PARSE("num_long_term_sps", value, ps_bitstrm); |
476 | 1.84k | if(value > ps_sps->i1_num_long_term_ref_pics_sps) |
477 | 29 | { |
478 | 29 | return IHEVCD_INVALID_PARAMETER; |
479 | 29 | } |
480 | 1.81k | ps_slice_hdr->i1_num_long_term_sps = value; |
481 | 1.81k | } |
482 | 8.61k | UEV_PARSE("num_long_term_pics", value, ps_bitstrm); |
483 | 8.61k | if(((ULWORD64)value + ps_slice_hdr->i1_num_long_term_sps + num_neg_pics + |
484 | 8.61k | num_pos_pics) > (MAX_DPB_SIZE - 1)) |
485 | 34 | { |
486 | 34 | return IHEVCD_INVALID_PARAMETER; |
487 | 34 | } |
488 | 8.57k | ps_slice_hdr->i1_num_long_term_pics = value; |
489 | | |
490 | 23.3k | for(i = 0; i < (ps_slice_hdr->i1_num_long_term_sps + |
491 | 23.3k | ps_slice_hdr->i1_num_long_term_pics); i++) |
492 | 14.8k | { |
493 | 14.8k | if(i < ps_slice_hdr->i1_num_long_term_sps) |
494 | 811 | { |
495 | | /* Use CLZ to compute Ceil( Log2( num_long_term_ref_pics_sps ) ) */ |
496 | 811 | if (ps_sps->i1_num_long_term_ref_pics_sps > 1) |
497 | 494 | { |
498 | 494 | WORD32 num_bits = 32 - CLZ(ps_sps->i1_num_long_term_ref_pics_sps - 1); |
499 | 494 | BITS_PARSE("lt_idx_sps[ i ]", value, ps_bitstrm, num_bits); |
500 | 494 | if(value >= ps_sps->i1_num_long_term_ref_pics_sps) |
501 | 0 | { |
502 | 0 | return IHEVCD_INVALID_PARAMETER; |
503 | 0 | } |
504 | 494 | } |
505 | 317 | else |
506 | 317 | { |
507 | 317 | value = 0; |
508 | 317 | } |
509 | 811 | ps_slice_hdr->ai4_poc_lsb_lt[i] = ps_sps->au2_lt_ref_pic_poc_lsb_sps[value]; |
510 | 811 | ps_slice_hdr->ai1_used_by_curr_pic_lt_flag[i] = ps_sps->ai1_used_by_curr_pic_lt_sps_flag[value]; |
511 | | |
512 | 811 | } |
513 | 14.0k | else |
514 | 14.0k | { |
515 | 14.0k | BITS_PARSE("poc_lsb_lt[ i ]", value, ps_bitstrm, ps_sps->i1_log2_max_pic_order_cnt_lsb); |
516 | 14.0k | ps_slice_hdr->ai4_poc_lsb_lt[i] = value; |
517 | | |
518 | 14.0k | BITS_PARSE("used_by_curr_pic_lt_flag[ i ]", value, ps_bitstrm, 1); |
519 | 14.0k | ps_slice_hdr->ai1_used_by_curr_pic_lt_flag[i] = value; |
520 | | |
521 | 14.0k | } |
522 | 14.8k | BITS_PARSE("delta_poc_msb_present_flag[ i ]", value, ps_bitstrm, 1); |
523 | 14.8k | ps_slice_hdr->ai1_delta_poc_msb_present_flag[i] = value; |
524 | | |
525 | | |
526 | 14.8k | ps_slice_hdr->ai1_delta_poc_msb_cycle_lt[i] = 0; |
527 | 14.8k | if(ps_slice_hdr->ai1_delta_poc_msb_present_flag[i]) |
528 | 3.15k | { |
529 | | |
530 | 3.15k | UEV_PARSE("delata_poc_msb_cycle_lt[ i ]", value, ps_bitstrm); |
531 | 3.15k | ps_slice_hdr->ai1_delta_poc_msb_cycle_lt[i] = value; |
532 | 3.15k | } |
533 | | |
534 | 14.8k | if((i != 0) && (i != ps_slice_hdr->i1_num_long_term_sps)) |
535 | 11.4k | { |
536 | 11.4k | ps_slice_hdr->ai1_delta_poc_msb_cycle_lt[i] += ps_slice_hdr->ai1_delta_poc_msb_cycle_lt[i - 1]; |
537 | 11.4k | } |
538 | | |
539 | 14.8k | } |
540 | 8.57k | } |
541 | | |
542 | 74.1k | for(i = 0; i < num_neg_pics + num_pos_pics; i++) |
543 | 47.9k | { |
544 | 47.9k | if(pi1_used[i]) |
545 | 44.4k | { |
546 | 44.4k | num_poc_total_curr++; |
547 | 44.4k | } |
548 | 47.9k | } |
549 | 40.9k | for(i = 0; i < ps_slice_hdr->i1_num_long_term_sps + ps_slice_hdr->i1_num_long_term_pics; i++) |
550 | 14.8k | { |
551 | 14.8k | if(ps_slice_hdr->ai1_used_by_curr_pic_lt_flag[i]) |
552 | 5.74k | { |
553 | 5.74k | num_poc_total_curr++; |
554 | 5.74k | } |
555 | 14.8k | } |
556 | | |
557 | | |
558 | 26.1k | if(ps_sps->i1_sps_temporal_mvp_enable_flag) |
559 | 17.1k | { |
560 | 17.1k | BITS_PARSE("enable_temporal_mvp_flag", value, ps_bitstrm, 1); |
561 | 17.1k | ps_slice_hdr->i1_slice_temporal_mvp_enable_flag = value; |
562 | 17.1k | } |
563 | | |
564 | 26.1k | } |
565 | 38.6k | ps_slice_hdr->i1_slice_sao_luma_flag = 0; |
566 | 38.6k | ps_slice_hdr->i1_slice_sao_chroma_flag = 0; |
567 | 38.6k | if(ps_sps->i1_sample_adaptive_offset_enabled_flag) |
568 | 21.1k | { |
569 | 21.1k | BITS_PARSE("slice_sao_luma_flag", value, ps_bitstrm, 1); |
570 | 21.1k | ps_slice_hdr->i1_slice_sao_luma_flag = value; |
571 | | |
572 | 21.1k | BITS_PARSE("slice_sao_chroma_flag", value, ps_bitstrm, 1); |
573 | 21.1k | ps_slice_hdr->i1_slice_sao_chroma_flag = value; |
574 | | |
575 | 21.1k | } |
576 | | |
577 | 38.6k | ps_slice_hdr->i1_max_num_merge_cand = 1; |
578 | 38.6k | ps_slice_hdr->i1_cabac_init_flag = 0; |
579 | | |
580 | 38.6k | ps_slice_hdr->i1_num_ref_idx_l0_active = 0; |
581 | 38.6k | ps_slice_hdr->i1_num_ref_idx_l1_active = 0; |
582 | 38.6k | ps_slice_hdr->i1_slice_cb_qp_offset = 0; |
583 | 38.6k | ps_slice_hdr->i1_slice_cr_qp_offset = 0; |
584 | 38.6k | if((PSLICE == ps_slice_hdr->i1_slice_type) || |
585 | 37.5k | (BSLICE == ps_slice_hdr->i1_slice_type)) |
586 | 20.5k | { |
587 | 20.5k | BITS_PARSE("num_ref_idx_active_override_flag", value, ps_bitstrm, 1); |
588 | 20.5k | ps_slice_hdr->i1_num_ref_idx_active_override_flag = value; |
589 | | |
590 | 20.5k | if(ps_slice_hdr->i1_num_ref_idx_active_override_flag) |
591 | 5.51k | { |
592 | 5.51k | UEV_PARSE("num_ref_idx_l0_active_minus1", value, ps_bitstrm); |
593 | 5.51k | if(value > MAX_DPB_SIZE - 2) |
594 | 20 | { |
595 | 20 | return IHEVCD_INVALID_PARAMETER; |
596 | 20 | } |
597 | 5.49k | ps_slice_hdr->i1_num_ref_idx_l0_active = value + 1; |
598 | | |
599 | 5.49k | if(BSLICE == ps_slice_hdr->i1_slice_type) |
600 | 4.87k | { |
601 | 4.87k | UEV_PARSE("num_ref_idx_l1_active_minus1", value, ps_bitstrm); |
602 | 4.87k | if(value > MAX_DPB_SIZE - 2) |
603 | 32 | { |
604 | 32 | return IHEVCD_INVALID_PARAMETER; |
605 | 32 | } |
606 | 4.84k | ps_slice_hdr->i1_num_ref_idx_l1_active = value + 1; |
607 | 4.84k | } |
608 | | |
609 | 5.49k | } |
610 | 15.0k | else |
611 | 15.0k | { |
612 | 15.0k | ps_slice_hdr->i1_num_ref_idx_l0_active = ps_pps->i1_num_ref_idx_l0_default_active; |
613 | 15.0k | if(BSLICE == ps_slice_hdr->i1_slice_type) |
614 | 14.5k | { |
615 | 14.5k | ps_slice_hdr->i1_num_ref_idx_l1_active = ps_pps->i1_num_ref_idx_l1_default_active; |
616 | 14.5k | } |
617 | 15.0k | } |
618 | | |
619 | 20.5k | if(0 == num_poc_total_curr) |
620 | 4.35k | return IHEVCD_IGNORE_SLICE; |
621 | 16.1k | if((ps_pps->i1_lists_modification_present_flag) && (num_poc_total_curr > 1)) |
622 | 2.14k | { |
623 | 2.14k | ihevcd_ref_pic_list_modification(ps_bitstrm, |
624 | 2.14k | ps_slice_hdr, num_poc_total_curr); |
625 | 2.14k | } |
626 | 14.0k | else |
627 | 14.0k | { |
628 | 14.0k | ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l0 = 0; |
629 | 14.0k | ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l1 = 0; |
630 | 14.0k | } |
631 | | |
632 | 16.1k | if(BSLICE == ps_slice_hdr->i1_slice_type) |
633 | 15.2k | { |
634 | 15.2k | BITS_PARSE("mvd_l1_zero_flag", value, ps_bitstrm, 1); |
635 | 15.2k | ps_slice_hdr->i1_mvd_l1_zero_flag = value; |
636 | 15.2k | } |
637 | | |
638 | 16.1k | ps_slice_hdr->i1_cabac_init_flag = 0; |
639 | 16.1k | if(ps_pps->i1_cabac_init_present_flag) |
640 | 12.1k | { |
641 | 12.1k | BITS_PARSE("cabac_init_flag", value, ps_bitstrm, 1); |
642 | 12.1k | ps_slice_hdr->i1_cabac_init_flag = value; |
643 | | |
644 | 12.1k | } |
645 | 16.1k | ps_slice_hdr->i1_collocated_from_l0_flag = 1; |
646 | 16.1k | ps_slice_hdr->i1_collocated_ref_idx = 0; |
647 | 16.1k | if(ps_slice_hdr->i1_slice_temporal_mvp_enable_flag) |
648 | 11.2k | { |
649 | 11.2k | if(BSLICE == ps_slice_hdr->i1_slice_type) |
650 | 11.1k | { |
651 | 11.1k | BITS_PARSE("collocated_from_l0_flag", value, ps_bitstrm, 1); |
652 | 11.1k | ps_slice_hdr->i1_collocated_from_l0_flag = value; |
653 | 11.1k | } |
654 | | |
655 | 11.2k | if((ps_slice_hdr->i1_collocated_from_l0_flag && (ps_slice_hdr->i1_num_ref_idx_l0_active > 1)) || |
656 | 6.64k | (!ps_slice_hdr->i1_collocated_from_l0_flag && (ps_slice_hdr->i1_num_ref_idx_l1_active > 1))) |
657 | 9.74k | { |
658 | 9.74k | UEV_PARSE("collocated_ref_idx", value, ps_bitstrm); |
659 | 9.74k | if((PSLICE == ps_slice_hdr->i1_slice_type || BSLICE == ps_slice_hdr->i1_slice_type) && |
660 | 9.74k | ps_slice_hdr->i1_collocated_from_l0_flag) |
661 | 4.55k | { |
662 | 4.55k | if(value >= ps_slice_hdr->i1_num_ref_idx_l0_active) |
663 | 127 | { |
664 | 127 | return IHEVCD_INVALID_PARAMETER; |
665 | 127 | } |
666 | 4.55k | } |
667 | 9.62k | if(BSLICE == ps_slice_hdr->i1_slice_type && !ps_slice_hdr->i1_collocated_from_l0_flag) |
668 | 5.19k | { |
669 | 5.19k | if(value >= ps_slice_hdr->i1_num_ref_idx_l1_active) |
670 | 22 | { |
671 | 22 | return IHEVCD_INVALID_PARAMETER; |
672 | 22 | } |
673 | 5.19k | } |
674 | 9.59k | ps_slice_hdr->i1_collocated_ref_idx = value; |
675 | 9.59k | } |
676 | | |
677 | 11.2k | } |
678 | | |
679 | 16.0k | if((ps_pps->i1_weighted_pred_flag && (PSLICE == ps_slice_hdr->i1_slice_type)) || |
680 | 15.6k | (ps_pps->i1_weighted_bipred_flag && (BSLICE == ps_slice_hdr->i1_slice_type))) |
681 | 5.14k | { |
682 | 5.14k | ihevcd_parse_pred_wt_ofst(ps_bitstrm, ps_sps, ps_pps, ps_slice_hdr); |
683 | 5.14k | } |
684 | 16.0k | UEV_PARSE("five_minus_max_num_merge_cand", value, ps_bitstrm); |
685 | 16.0k | if(value > 4) |
686 | 360 | { |
687 | 360 | return IHEVCD_INVALID_PARAMETER; |
688 | 360 | } |
689 | 15.6k | ps_slice_hdr->i1_max_num_merge_cand = 5 - value; |
690 | | |
691 | 15.6k | } |
692 | 33.7k | SEV_PARSE("slice_qp_delta", i4_value, ps_bitstrm); |
693 | 33.7k | if((i4_value < (MIN_HEVC_QP - ps_pps->i1_pic_init_qp)) || |
694 | 33.6k | (i4_value > (MAX_HEVC_QP - ps_pps->i1_pic_init_qp))) |
695 | 369 | { |
696 | 369 | return IHEVCD_INVALID_PARAMETER; |
697 | 369 | } |
698 | 33.4k | ps_slice_hdr->i1_slice_qp_delta = i4_value; |
699 | | |
700 | 33.4k | if(ps_pps->i1_pic_slice_level_chroma_qp_offsets_present_flag) |
701 | 13.3k | { |
702 | 13.3k | SEV_PARSE("slice_cb_qp_offset", i4_value, ps_bitstrm); |
703 | 13.3k | if(i4_value < -12 || i4_value > 12) |
704 | 78 | { |
705 | 78 | return IHEVCD_INVALID_PARAMETER; |
706 | 78 | } |
707 | 13.2k | ps_slice_hdr->i1_slice_cb_qp_offset = i4_value; |
708 | | |
709 | 13.2k | SEV_PARSE("slice_cr_qp_offset", i4_value, ps_bitstrm); |
710 | 13.2k | if(i4_value < -12 || i4_value > 12) |
711 | 21 | { |
712 | 21 | return IHEVCD_INVALID_PARAMETER; |
713 | 21 | } |
714 | 13.2k | ps_slice_hdr->i1_slice_cr_qp_offset = i4_value; |
715 | | |
716 | 13.2k | } |
717 | 33.3k | ps_slice_hdr->i1_deblocking_filter_override_flag = 0; |
718 | 33.3k | ps_slice_hdr->i1_slice_disable_deblocking_filter_flag = ps_pps->i1_pic_disable_deblocking_filter_flag; |
719 | 33.3k | ps_slice_hdr->i1_beta_offset_div2 = ps_pps->i1_beta_offset_div2; |
720 | 33.3k | ps_slice_hdr->i1_tc_offset_div2 = ps_pps->i1_tc_offset_div2; |
721 | | |
722 | 33.3k | disable_deblocking_filter_flag = ps_pps->i1_pic_disable_deblocking_filter_flag; |
723 | | |
724 | 33.3k | if(ps_pps->i1_deblocking_filter_control_present_flag) |
725 | 5.81k | { |
726 | | |
727 | 5.81k | if(ps_pps->i1_deblocking_filter_override_enabled_flag) |
728 | 2.53k | { |
729 | 2.53k | BITS_PARSE("deblocking_filter_override_flag", value, ps_bitstrm, 1); |
730 | 2.53k | ps_slice_hdr->i1_deblocking_filter_override_flag = value; |
731 | 2.53k | } |
732 | | |
733 | 5.81k | if(ps_slice_hdr->i1_deblocking_filter_override_flag) |
734 | 1.31k | { |
735 | 1.31k | BITS_PARSE("slice_disable_deblocking_filter_flag", value, ps_bitstrm, 1); |
736 | 1.31k | ps_slice_hdr->i1_slice_disable_deblocking_filter_flag = value; |
737 | 1.31k | disable_deblocking_filter_flag = ps_slice_hdr->i1_slice_disable_deblocking_filter_flag; |
738 | | |
739 | 1.31k | if(!ps_slice_hdr->i1_slice_disable_deblocking_filter_flag) |
740 | 157 | { |
741 | 157 | SEV_PARSE("beta_offset_div2", i4_value, ps_bitstrm); |
742 | 157 | if(i4_value < -6 || i4_value > 6) |
743 | 14 | { |
744 | 14 | return IHEVCD_INVALID_PARAMETER; |
745 | 14 | } |
746 | 143 | ps_slice_hdr->i1_beta_offset_div2 = i4_value; |
747 | | |
748 | 143 | SEV_PARSE("tc_offset_div2", i4_value, ps_bitstrm); |
749 | 143 | if(i4_value < -6 || i4_value > 6) |
750 | 1 | { |
751 | 1 | return IHEVCD_INVALID_PARAMETER; |
752 | 1 | } |
753 | 142 | ps_slice_hdr->i1_tc_offset_div2 = i4_value; |
754 | | |
755 | 142 | } |
756 | 1.31k | } |
757 | 5.81k | } |
758 | | |
759 | 33.2k | ps_slice_hdr->i1_slice_loop_filter_across_slices_enabled_flag = ps_pps->i1_loop_filter_across_slices_enabled_flag; |
760 | 33.2k | if(ps_pps->i1_loop_filter_across_slices_enabled_flag && |
761 | 21.1k | (ps_slice_hdr->i1_slice_sao_luma_flag || ps_slice_hdr->i1_slice_sao_chroma_flag || !disable_deblocking_filter_flag)) |
762 | 19.1k | { |
763 | 19.1k | BITS_PARSE("slice_loop_filter_across_slices_enabled_flag", value, ps_bitstrm, 1); |
764 | 19.1k | ps_slice_hdr->i1_slice_loop_filter_across_slices_enabled_flag = value; |
765 | 19.1k | } |
766 | | |
767 | 33.2k | } |
768 | | |
769 | | /* Check sanity of slice */ |
770 | 39.3k | if((!first_slice_in_pic_flag) && |
771 | 15.1k | (ps_codec->i4_pic_present)) |
772 | 11.8k | { |
773 | 11.8k | slice_header_t *ps_slice_hdr_base = ps_codec->ps_slice_hdr_base; |
774 | | |
775 | | |
776 | | /* According to the standard, the above conditions must be satisfied - But for error resilience, |
777 | | * only the following conditions are checked */ |
778 | 11.8k | if((ps_slice_hdr_base->i1_pps_id != ps_slice_hdr->i1_pps_id) || |
779 | 11.3k | (ps_slice_hdr_base->i4_pic_order_cnt_lsb != ps_slice_hdr->i4_pic_order_cnt_lsb)) |
780 | 758 | { |
781 | 758 | return IHEVCD_IGNORE_SLICE; |
782 | 758 | } |
783 | | |
784 | 11.8k | } |
785 | | |
786 | | |
787 | 38.5k | if(0 == ps_codec->i4_pic_present) |
788 | 27.4k | { |
789 | 27.4k | 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); |
790 | 27.4k | } |
791 | 11.0k | else |
792 | 11.0k | { |
793 | 11.0k | ps_slice_hdr->i4_abs_pic_order_cnt = ps_codec->s_parse.i4_abs_pic_order_cnt; |
794 | 11.0k | } |
795 | | |
796 | | |
797 | 38.5k | if(!first_slice_in_pic_flag) |
798 | 14.3k | { |
799 | | /* Check if the current slice belongs to the same pic (Pic being parsed) */ |
800 | 14.3k | if(ps_codec->s_parse.i4_abs_pic_order_cnt == ps_slice_hdr->i4_abs_pic_order_cnt) |
801 | 13.3k | { |
802 | | |
803 | | /* If the Next CTB's index is less than the slice address, |
804 | | * the previous slice is incomplete. |
805 | | * Indicate slice error, and treat the remaining CTBs as skip */ |
806 | 13.3k | if(slice_address > ps_codec->s_parse.i4_next_ctb_indx) |
807 | 827 | { |
808 | 827 | if(ps_codec->i4_pic_present) |
809 | 827 | { |
810 | 827 | prev_slice_incomplete_flag = 1; |
811 | 827 | ps_codec->i4_slice_error = 1; |
812 | 827 | ps_codec->s_parse.i4_cur_slice_idx--; |
813 | 827 | if(ps_codec->s_parse.i4_cur_slice_idx < 0) |
814 | 0 | ps_codec->s_parse.i4_cur_slice_idx = 0; |
815 | 827 | } |
816 | 827 | return IHEVCD_IGNORE_SLICE; |
817 | 827 | } |
818 | | /* If the slice address is less than the next CTB's index, |
819 | | * extra CTBs have been decoded in the previous slice. |
820 | | * Ignore the current slice. Treat it as incomplete */ |
821 | 12.5k | else if(slice_address < ps_codec->s_parse.i4_next_ctb_indx) |
822 | 3.70k | { |
823 | 3.70k | return IHEVCD_IGNORE_SLICE; |
824 | 3.70k | } |
825 | 8.85k | else |
826 | 8.85k | { |
827 | 8.85k | ps_codec->i4_slice_error = 0; |
828 | 8.85k | } |
829 | 13.3k | } |
830 | | |
831 | | /* The current slice does not belong to the pic that is being parsed */ |
832 | 994 | else |
833 | 994 | { |
834 | | /* The previous pic is incomplete. |
835 | | * Treat the remaining CTBs as skip */ |
836 | 994 | if(ps_codec->i4_pic_present) |
837 | 0 | { |
838 | 0 | slice_header_t *ps_slice_hdr_next; |
839 | 0 | ps_codec->i4_slice_error = 1; |
840 | 0 | ps_codec->s_parse.i4_cur_slice_idx--; |
841 | 0 | if(ps_codec->s_parse.i4_cur_slice_idx < 0) |
842 | 0 | ps_codec->s_parse.i4_cur_slice_idx = 0; |
843 | |
|
844 | 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)); |
845 | 0 | ps_slice_hdr_next->i2_ctb_x = 0; |
846 | 0 | ps_slice_hdr_next->i2_ctb_y = ps_codec->s_parse.ps_sps->i2_pic_ht_in_ctb; |
847 | 0 | return ret; |
848 | 0 | } |
849 | | |
850 | | /* If the previous pic is complete, |
851 | | * return if the current slice is dependant |
852 | | * otherwise, update the parse context's POC */ |
853 | 994 | else |
854 | 994 | { |
855 | 994 | if(ps_slice_hdr->i1_dependent_slice_flag) |
856 | 0 | return IHEVCD_IGNORE_SLICE; |
857 | | |
858 | 994 | ps_codec->s_parse.i4_abs_pic_order_cnt = ps_slice_hdr->i4_abs_pic_order_cnt; |
859 | 994 | } |
860 | 994 | } |
861 | 14.3k | } |
862 | | |
863 | | /* If the slice is the first slice in the pic, update the parse context's POC */ |
864 | 24.1k | else |
865 | 24.1k | { |
866 | | /* If the first slice is repeated, ignore the second occurrence |
867 | | * If any other slice is repeated, the CTB addr will be greater than the slice addr, |
868 | | * and hence the second occurrence is ignored */ |
869 | 24.1k | if(ps_codec->s_parse.i4_abs_pic_order_cnt == ps_slice_hdr->i4_abs_pic_order_cnt) |
870 | 9.39k | return IHEVCD_IGNORE_SLICE; |
871 | | |
872 | 14.7k | ps_codec->s_parse.i4_abs_pic_order_cnt = ps_slice_hdr->i4_abs_pic_order_cnt; |
873 | 14.7k | } |
874 | | |
875 | | // printf("POC: %d\n", ps_slice_hdr->i4_abs_pic_order_cnt); |
876 | | // AEV_TRACE("POC", ps_slice_hdr->i4_abs_pic_order_cnt, 0); |
877 | 24.6k | ps_slice_hdr->i4_num_entry_point_offsets = 0; |
878 | 24.6k | if((ps_pps->i1_tiles_enabled_flag) || |
879 | 19.2k | (ps_pps->i1_entropy_coding_sync_enabled_flag)) |
880 | 7.17k | { |
881 | 7.17k | UEV_PARSE("num_entry_point_offsets", value, ps_bitstrm); |
882 | 7.17k | ps_slice_hdr->i4_num_entry_point_offsets = value; |
883 | | |
884 | 7.17k | { |
885 | 7.17k | WORD32 max_num_entry_point_offsets; |
886 | 7.17k | if((ps_pps->i1_tiles_enabled_flag) && |
887 | 5.37k | (ps_pps->i1_entropy_coding_sync_enabled_flag)) |
888 | 899 | { |
889 | 899 | max_num_entry_point_offsets = ps_pps->i1_num_tile_columns * ps_sps->i2_pic_ht_in_ctb - 1; |
890 | 899 | } |
891 | 6.27k | else if(ps_pps->i1_tiles_enabled_flag) |
892 | 4.47k | { |
893 | 4.47k | max_num_entry_point_offsets = ps_pps->i1_num_tile_columns * ps_pps->i1_num_tile_rows - 1 ; |
894 | 4.47k | } |
895 | 1.79k | else |
896 | 1.79k | { |
897 | 1.79k | max_num_entry_point_offsets = (ps_sps->i2_pic_ht_in_ctb - 1); |
898 | 1.79k | } |
899 | | |
900 | 7.17k | if(ps_slice_hdr->i4_num_entry_point_offsets < 0 || ps_slice_hdr->i4_num_entry_point_offsets > max_num_entry_point_offsets) |
901 | 53 | { |
902 | 53 | return IHEVCD_INVALID_PARAMETER; |
903 | 53 | } |
904 | 7.17k | } |
905 | | |
906 | 7.11k | if(ps_slice_hdr->i4_num_entry_point_offsets > 0) |
907 | 292 | { |
908 | 292 | UEV_PARSE("offset_len_minus1", value, ps_bitstrm); |
909 | 292 | if(value > 31) |
910 | 21 | { |
911 | 21 | return IHEVCD_INVALID_PARAMETER; |
912 | 21 | } |
913 | 271 | ps_slice_hdr->i1_offset_len = value + 1; |
914 | | |
915 | 1.21k | for(i = 0; i < ps_slice_hdr->i4_num_entry_point_offsets; i++) |
916 | 941 | { |
917 | 941 | BITS_PARSE("entry_point_offset", value, ps_bitstrm, ps_slice_hdr->i1_offset_len); |
918 | | |
919 | | /* TODO: pu4_entry_point_offset needs to be initialized */ |
920 | | //ps_slice_hdr->pu4_entry_point_offset[i] = value; |
921 | 941 | } |
922 | | |
923 | 271 | } |
924 | 7.11k | } |
925 | | |
926 | 24.5k | if(ps_pps->i1_slice_header_extension_present_flag) |
927 | 4.77k | { |
928 | 4.77k | UEV_PARSE("slice_header_extension_length", value, ps_bitstrm); |
929 | 4.77k | if(value > 256) |
930 | 220 | { |
931 | 220 | return IHEVCD_INVALID_PARAMETER; |
932 | 220 | } |
933 | 4.55k | ps_slice_hdr->i2_slice_header_extension_length = value; |
934 | | |
935 | | |
936 | 6.52k | for(i = 0; i < ps_slice_hdr->i2_slice_header_extension_length; i++) |
937 | 1.96k | { |
938 | 1.96k | BITS_PARSE("slice_header_extension_data_byte", value, ps_bitstrm, 8); |
939 | 1.96k | } |
940 | | |
941 | 4.55k | } |
942 | | |
943 | 24.3k | ihevcd_bits_flush_to_byte_boundary(ps_bitstrm); |
944 | | |
945 | 24.3k | if((UWORD8 *)ps_bitstrm->pu4_buf > ps_bitstrm->pu1_buf_max) |
946 | 143 | return IHEVCD_INVALID_PARAMETER; |
947 | | |
948 | 24.1k | { |
949 | 24.1k | dpb_mgr_t *ps_dpb_mgr = (dpb_mgr_t *)ps_codec->pv_dpb_mgr; |
950 | 24.1k | WORD32 r_idx; |
951 | | |
952 | 24.1k | if((NAL_IDR_W_LP == ps_slice_hdr->i1_nal_unit_type) || |
953 | 20.4k | (NAL_IDR_N_LP == ps_slice_hdr->i1_nal_unit_type) || |
954 | 15.3k | (NAL_BLA_N_LP == ps_slice_hdr->i1_nal_unit_type) || |
955 | 15.0k | (NAL_BLA_W_DLP == ps_slice_hdr->i1_nal_unit_type) || |
956 | 14.1k | (NAL_BLA_W_LP == ps_slice_hdr->i1_nal_unit_type) || |
957 | 13.5k | (0 == ps_codec->u4_pic_cnt)) |
958 | 11.4k | { |
959 | 747k | for(i = 0; i < MAX_DPB_BUFS; i++) |
960 | 735k | { |
961 | 735k | if(ps_dpb_mgr->as_dpb_info[i].ps_pic_buf) |
962 | 8.78k | { |
963 | 8.78k | pic_buf_t *ps_pic_buf = ps_dpb_mgr->as_dpb_info[i].ps_pic_buf; |
964 | 8.78k | mv_buf_t *ps_mv_buf; |
965 | | |
966 | | /* Long term index is set to MAX_DPB_BUFS to ensure it is not added as LT */ |
967 | 8.78k | 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); |
968 | | /* Find buffer id of the MV bank corresponding to the buffer being freed (Buffer with POC of u4_abs_poc) */ |
969 | 8.78k | ps_mv_buf = (mv_buf_t *)ps_codec->ps_mv_buf; |
970 | 9.47k | for(j = 0; j < ps_codec->i4_max_dpb_size; j++) |
971 | 9.47k | { |
972 | 9.47k | if(ps_mv_buf && ps_mv_buf->i4_abs_poc == ps_pic_buf->i4_abs_poc) |
973 | 8.78k | { |
974 | 8.78k | ihevc_buf_mgr_release((buf_mgr_t *)ps_codec->pv_mv_buf_mgr, j, BUF_MGR_REF); |
975 | 8.78k | break; |
976 | 8.78k | } |
977 | 693 | ps_mv_buf++; |
978 | 693 | } |
979 | | |
980 | 8.78k | } |
981 | | |
982 | 735k | } |
983 | | |
984 | | /* Initialize the reference lists to NULL |
985 | | * This is done to take care of the cases where the first pic is not IDR |
986 | | * but the reference list is not created for the first pic because |
987 | | * pic count is zero leaving the reference list uninitialised */ |
988 | 195k | for(r_idx = 0; r_idx < MAX_DPB_SIZE; r_idx++) |
989 | 183k | { |
990 | 183k | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_pic_buf = NULL; |
991 | 183k | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_mv_buf = NULL; |
992 | | |
993 | 183k | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_pic_buf = NULL; |
994 | 183k | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_mv_buf = NULL; |
995 | 183k | } |
996 | | |
997 | 11.4k | } |
998 | 12.6k | else |
999 | 12.6k | { |
1000 | 12.6k | ret = ihevcd_ref_list(ps_codec, ps_pps, ps_sps, ps_slice_hdr); |
1001 | 12.6k | if ((WORD32)IHEVCD_SUCCESS != ret) |
1002 | 838 | { |
1003 | 838 | return ret; |
1004 | 838 | } |
1005 | | |
1006 | 12.6k | } |
1007 | | |
1008 | 24.1k | } |
1009 | | |
1010 | | /* Fill the remaining entries of the reference lists with the nearest POC |
1011 | | * This is done to handle cases where there is a corruption in the reference index */ |
1012 | 23.3k | if(ps_codec->i4_pic_present) |
1013 | 8.85k | { |
1014 | 8.85k | pic_buf_t *ps_pic_buf_ref; |
1015 | 8.85k | mv_buf_t *ps_mv_buf_ref; |
1016 | 8.85k | WORD32 r_idx; |
1017 | 8.85k | dpb_mgr_t *ps_dpb_mgr = (dpb_mgr_t *)ps_codec->pv_dpb_mgr; |
1018 | 8.85k | buf_mgr_t *ps_mv_buf_mgr = (buf_mgr_t *)ps_codec->pv_mv_buf_mgr; |
1019 | | |
1020 | 8.85k | ps_pic_buf_ref = ihevc_dpb_mgr_get_ref_by_nearest_poc(ps_dpb_mgr, ps_slice_hdr->i4_abs_pic_order_cnt); |
1021 | 8.85k | if(NULL == ps_pic_buf_ref) |
1022 | 2.14k | { |
1023 | 2.14k | ps_pic_buf_ref = ps_codec->as_process[0].ps_cur_pic; |
1024 | 2.14k | ps_mv_buf_ref = ps_codec->s_parse.ps_cur_mv_buf; |
1025 | 2.14k | } |
1026 | 6.71k | else |
1027 | 6.71k | { |
1028 | 6.71k | ps_mv_buf_ref = ihevcd_mv_mgr_get_poc(ps_mv_buf_mgr, ps_pic_buf_ref->i4_abs_poc); |
1029 | 6.71k | } |
1030 | | |
1031 | 22.2k | for(r_idx = 0; r_idx < ps_slice_hdr->i1_num_ref_idx_l0_active; r_idx++) |
1032 | 13.3k | { |
1033 | 13.3k | if(NULL == ps_slice_hdr->as_ref_pic_list0[r_idx].pv_pic_buf) |
1034 | 28 | { |
1035 | 28 | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_pic_buf = (void *)ps_pic_buf_ref; |
1036 | 28 | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_mv_buf = (void *)ps_mv_buf_ref; |
1037 | 28 | } |
1038 | 13.3k | } |
1039 | | |
1040 | 137k | for(r_idx = ps_slice_hdr->i1_num_ref_idx_l0_active; r_idx < MAX_DPB_SIZE; r_idx++) |
1041 | 128k | { |
1042 | 128k | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_pic_buf = (void *)ps_pic_buf_ref; |
1043 | 128k | ps_slice_hdr->as_ref_pic_list0[r_idx].pv_mv_buf = (void *)ps_mv_buf_ref; |
1044 | 128k | } |
1045 | | |
1046 | 22.2k | for(r_idx = 0; r_idx < ps_slice_hdr->i1_num_ref_idx_l1_active; r_idx++) |
1047 | 13.3k | { |
1048 | 13.3k | if(NULL == ps_slice_hdr->as_ref_pic_list1[r_idx].pv_pic_buf) |
1049 | 41 | { |
1050 | 41 | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_pic_buf = (void *)ps_pic_buf_ref; |
1051 | 41 | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_mv_buf = (void *)ps_mv_buf_ref; |
1052 | 41 | } |
1053 | 13.3k | } |
1054 | | |
1055 | 137k | for(r_idx = ps_slice_hdr->i1_num_ref_idx_l1_active; r_idx < MAX_DPB_SIZE; r_idx++) |
1056 | 128k | { |
1057 | 128k | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_pic_buf = (void *)ps_pic_buf_ref; |
1058 | 128k | ps_slice_hdr->as_ref_pic_list1[r_idx].pv_mv_buf = (void *)ps_mv_buf_ref; |
1059 | 128k | } |
1060 | 8.85k | } |
1061 | | |
1062 | | /* Update slice address in the header */ |
1063 | 23.3k | if(!ps_slice_hdr->i1_first_slice_in_pic_flag) |
1064 | 9.73k | { |
1065 | 9.73k | ps_slice_hdr->i2_ctb_x = slice_address % ps_sps->i2_pic_wd_in_ctb; |
1066 | 9.73k | ps_slice_hdr->i2_ctb_y = slice_address / ps_sps->i2_pic_wd_in_ctb; |
1067 | | |
1068 | 9.73k | if(!ps_slice_hdr->i1_dependent_slice_flag) |
1069 | 5.87k | { |
1070 | 5.87k | ps_slice_hdr->i2_independent_ctb_x = ps_slice_hdr->i2_ctb_x; |
1071 | 5.87k | ps_slice_hdr->i2_independent_ctb_y = ps_slice_hdr->i2_ctb_y; |
1072 | 5.87k | } |
1073 | 9.73k | } |
1074 | 13.6k | else |
1075 | 13.6k | { |
1076 | 13.6k | ps_slice_hdr->i2_ctb_x = 0; |
1077 | 13.6k | ps_slice_hdr->i2_ctb_y = 0; |
1078 | | |
1079 | 13.6k | ps_slice_hdr->i2_independent_ctb_x = 0; |
1080 | 13.6k | ps_slice_hdr->i2_independent_ctb_y = 0; |
1081 | 13.6k | } |
1082 | | |
1083 | | /* If the first slice in the pic is missing, copy the current slice header to |
1084 | | * the first slice's header */ |
1085 | 23.3k | if((!first_slice_in_pic_flag) && |
1086 | 9.73k | (0 == ps_codec->i4_pic_present)) |
1087 | 887 | { |
1088 | 887 | slice_header_t *ps_slice_hdr_prev = ps_codec->s_parse.ps_slice_hdr_base; |
1089 | 887 | ihevcd_copy_slice_hdr(ps_codec, 0, (ps_codec->s_parse.i4_cur_slice_idx & (MAX_SLICE_HDR_CNT - 1))); |
1090 | | |
1091 | 887 | prev_slice_incomplete_flag = 1; |
1092 | 887 | ASSERT(ps_codec->s_parse.i4_cur_slice_idx == 1); |
1093 | | |
1094 | 887 | ps_slice_hdr_prev->i2_ctb_x = 0; |
1095 | 887 | ps_slice_hdr_prev->i2_ctb_y = 0; |
1096 | | |
1097 | 887 | ps_codec->s_parse.i4_ctb_x = 0; |
1098 | 887 | ps_codec->s_parse.i4_ctb_y = 0; |
1099 | | |
1100 | 887 | ps_codec->s_parse.i4_cur_slice_idx = 0; |
1101 | | |
1102 | 887 | if((ps_slice_hdr->i2_ctb_x == 0) && |
1103 | 142 | (ps_slice_hdr->i2_ctb_y == 0)) |
1104 | 0 | { |
1105 | 0 | ps_slice_hdr->i2_ctb_x++; |
1106 | 0 | } |
1107 | 887 | } |
1108 | | |
1109 | 23.3k | { |
1110 | | /* If skip B is enabled, |
1111 | | * ignore pictures that are non-reference |
1112 | | * TODO: (i1_nal_unit_type < NAL_BLA_W_LP) && (i1_nal_unit_type % 2 == 0) only says it is |
1113 | | * sub-layer non-reference slice. May need to find a way to detect actual non-reference pictures*/ |
1114 | | |
1115 | 23.3k | if((i1_nal_unit_type < NAL_BLA_W_LP) && |
1116 | 12.4k | (i1_nal_unit_type % 2 == 0)) |
1117 | 7.63k | { |
1118 | 7.63k | if(IVD_SKIP_B == ps_codec->e_pic_skip_mode) |
1119 | 0 | return IHEVCD_IGNORE_SLICE; |
1120 | 7.63k | } |
1121 | | |
1122 | | /* If skip PB is enabled, |
1123 | | * decode only I slices */ |
1124 | 23.3k | if((IVD_SKIP_PB == ps_codec->e_pic_skip_mode) && |
1125 | 0 | (ISLICE != ps_slice_hdr->i1_slice_type)) |
1126 | 0 | { |
1127 | 0 | return IHEVCD_IGNORE_SLICE; |
1128 | 0 | } |
1129 | 23.3k | } |
1130 | | |
1131 | 23.3k | if(prev_slice_incomplete_flag) |
1132 | 887 | { |
1133 | 887 | ps_codec->i4_slice_error = 1; |
1134 | 887 | ps_codec->s_parse.i4_cur_slice_idx--; |
1135 | 887 | if(ps_codec->s_parse.i4_cur_slice_idx < 0) |
1136 | 887 | ps_codec->s_parse.i4_cur_slice_idx = 0; |
1137 | 887 | } |
1138 | | |
1139 | 23.3k | return ret; |
1140 | 23.3k | } |