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