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