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_ref_list.h" 73 74 #define COPY_DEFAULT_SCALING_LIST(pi2_scaling_mat) \ 75 { \ 76 WORD32 scaling_mat_offset[]={0, 16, 32, 48, 64, 80, 96, 160, 224, 288, 352, 416, 480, 736, 992, 1248, 1504, 1760, 2016, 3040}; \ 77 \ 78 /* scaling matrix for 4x4 */ \ 79 memcpy(pi2_scaling_mat, gi2_flat_scale_mat_32x32, 6*16*sizeof(WORD16)); \ 80 /* scaling matrix for 8x8 */ \ 81 memcpy(pi2_scaling_mat + scaling_mat_offset[6], gi2_intra_default_scale_mat_8x8, 64*sizeof(WORD16)); \ 82 memcpy(pi2_scaling_mat + scaling_mat_offset[7], gi2_intra_default_scale_mat_8x8, 64*sizeof(WORD16)); \ 83 memcpy(pi2_scaling_mat + scaling_mat_offset[8], gi2_intra_default_scale_mat_8x8, 64*sizeof(WORD16)); \ 84 memcpy(pi2_scaling_mat + scaling_mat_offset[9], gi2_inter_default_scale_mat_8x8, 64*sizeof(WORD16)); \ 85 memcpy(pi2_scaling_mat + scaling_mat_offset[10], gi2_inter_default_scale_mat_8x8, 64*sizeof(WORD16)); \ 86 memcpy(pi2_scaling_mat + scaling_mat_offset[11], gi2_inter_default_scale_mat_8x8, 64*sizeof(WORD16)); \ 87 /* scaling matrix for 16x16 */ \ 88 memcpy(pi2_scaling_mat + scaling_mat_offset[12], gi2_intra_default_scale_mat_16x16, 256*sizeof(WORD16)); \ 89 memcpy(pi2_scaling_mat + scaling_mat_offset[13], gi2_intra_default_scale_mat_16x16, 256*sizeof(WORD16)); \ 90 memcpy(pi2_scaling_mat + scaling_mat_offset[14], gi2_intra_default_scale_mat_16x16, 256*sizeof(WORD16)); \ 91 memcpy(pi2_scaling_mat + scaling_mat_offset[15], gi2_inter_default_scale_mat_16x16, 256*sizeof(WORD16)); \ 92 memcpy(pi2_scaling_mat + scaling_mat_offset[16], gi2_inter_default_scale_mat_16x16, 256*sizeof(WORD16)); \ 93 memcpy(pi2_scaling_mat + scaling_mat_offset[17], gi2_inter_default_scale_mat_16x16, 256*sizeof(WORD16)); \ 94 /* scaling matrix for 32x32 */ \ 95 memcpy(pi2_scaling_mat + scaling_mat_offset[18], gi2_intra_default_scale_mat_32x32, 1024*sizeof(WORD16)); \ 96 memcpy(pi2_scaling_mat + scaling_mat_offset[19], gi2_inter_default_scale_mat_32x32, 1024*sizeof(WORD16)); \ 97 } 98 99 #define COPY_FLAT_SCALING_LIST(pi2_scaling_mat) \ 100 { \ 101 WORD32 scaling_mat_offset[]={0, 16, 32, 48, 64, 80, 96, 160, 224, 288, 352, 416, 480, 736, 992, 1248, 1504, 1760, 2016, 3040}; \ 102 \ 103 /* scaling matrix for 4x4 */ \ 104 memcpy(pi2_scaling_mat, gi2_flat_scale_mat_32x32, 6*16*sizeof(WORD16)); \ 105 /* scaling matrix for 8x8 */ \ 106 memcpy(pi2_scaling_mat + scaling_mat_offset[6], gi2_flat_scale_mat_32x32, 6*64*sizeof(WORD16)); \ 107 /* scaling matrix for 16x16 */ \ 108 memcpy(pi2_scaling_mat + scaling_mat_offset[12], gi2_flat_scale_mat_32x32, 3*256*sizeof(WORD16)); \ 109 memcpy(pi2_scaling_mat + scaling_mat_offset[15], gi2_flat_scale_mat_32x32, 3*256*sizeof(WORD16)); \ 110 /* scaling matrix for 32x32 */ \ 111 memcpy(pi2_scaling_mat + scaling_mat_offset[18], gi2_flat_scale_mat_32x32, 1024*sizeof(WORD16)); \ 112 memcpy(pi2_scaling_mat + scaling_mat_offset[19], gi2_flat_scale_mat_32x32, 1024*sizeof(WORD16)); \ 113 } 114 115 /* Function declarations */ 116 117 /** 118 ******************************************************************************* 119 * 120 * @brief 121 * Parses Prediction weight table syntax 122 * 123 * @par Description: 124 * Parse Prediction weight table syntax as per Section: 7.3.8.4 125 * 126 * @param[in] ps_bitstrm 127 * Pointer to bitstream context 128 * 129 * @param[in] ps_sps 130 * Current SPS 131 * 132 * @param[in] ps_pps 133 * Current PPS 134 * 135 * @param[in] ps_slice_hdr 136 * Current Slice header 137 * 138 * @returns Error code from IHEVCD_ERROR_T 139 * 140 * @remarks 141 * 142 * 143 ******************************************************************************* 144 */ 145 146 WORD32 ihevcd_parse_pred_wt_ofst(bitstrm_t *ps_bitstrm, 147 sps_t *ps_sps, 148 pps_t *ps_pps, 149 slice_header_t *ps_slice_hdr) 150 { 151 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 152 WORD32 value; 153 WORD32 i; 154 155 pred_wt_ofst_t *ps_wt_ofst = &ps_slice_hdr->s_wt_ofst; 156 UNUSED(ps_pps); 157 158 UEV_PARSE("luma_log2_weight_denom", value, ps_bitstrm); 159 ps_wt_ofst->i1_luma_log2_weight_denom = value; 160 161 if(ps_sps->i1_chroma_format_idc != 0) 162 { 163 SEV_PARSE("delta_chroma_log2_weight_denom", value, ps_bitstrm); 164 ps_wt_ofst->i1_chroma_log2_weight_denom = ps_wt_ofst->i1_luma_log2_weight_denom + value; 165 } 166 167 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++) 168 { 169 BITS_PARSE("luma_weight_l0_flag[ i ]", value, ps_bitstrm, 1); 170 ps_wt_ofst->i1_luma_weight_l0_flag[i] = value; 171 } 172 173 174 175 if(ps_sps->i1_chroma_format_idc != 0) 176 { 177 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++) 178 { 179 BITS_PARSE("chroma_weight_l0_flag[ i ]", value, ps_bitstrm, 1); 180 ps_wt_ofst->i1_chroma_weight_l0_flag[i] = value; 181 } 182 } 183 else 184 { 185 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++) 186 { 187 ps_wt_ofst->i1_chroma_weight_l0_flag[i] = 0; 188 } 189 } 190 191 192 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l0_active; i++) 193 { 194 if(ps_wt_ofst->i1_luma_weight_l0_flag[i]) 195 { 196 SEV_PARSE("delta_luma_weight_l0[ i ]", value, ps_bitstrm); 197 198 199 ps_wt_ofst->i2_luma_weight_l0[i] = (1 << ps_wt_ofst->i1_luma_log2_weight_denom) + value; 200 201 SEV_PARSE("luma_offset_l0[ i ]", value, ps_bitstrm); 202 ps_wt_ofst->i2_luma_offset_l0[i] = value; 203 204 } 205 else 206 { 207 ps_wt_ofst->i2_luma_weight_l0[i] = (1 << ps_wt_ofst->i1_luma_log2_weight_denom); 208 ps_wt_ofst->i2_luma_offset_l0[i] = 0; 209 } 210 if(ps_wt_ofst->i1_chroma_weight_l0_flag[i]) 211 { 212 WORD32 ofst; 213 WORD32 shift = (1 << (BIT_DEPTH_CHROMA - 1)); 214 SEV_PARSE("delta_chroma_weight_l0[ i ][ j ]", value, ps_bitstrm); 215 ps_wt_ofst->i2_chroma_weight_l0_cb[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom) + value; 216 217 218 SEV_PARSE("delta_chroma_offset_l0[ i ][ j ]", value, ps_bitstrm); 219 ofst = ((shift * ps_wt_ofst->i2_chroma_weight_l0_cb[i]) >> ps_wt_ofst->i1_chroma_log2_weight_denom); 220 ofst = value - ofst + shift; 221 222 ps_wt_ofst->i2_chroma_offset_l0_cb[i] = CLIP_S8(ofst); 223 224 SEV_PARSE("delta_chroma_weight_l0[ i ][ j ]", value, ps_bitstrm); 225 ps_wt_ofst->i2_chroma_weight_l0_cr[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom) + value; 226 227 228 SEV_PARSE("delta_chroma_offset_l0[ i ][ j ]", value, ps_bitstrm); 229 ofst = ((shift * ps_wt_ofst->i2_chroma_weight_l0_cr[i]) >> ps_wt_ofst->i1_chroma_log2_weight_denom); 230 ofst = value - ofst + shift; 231 232 ps_wt_ofst->i2_chroma_offset_l0_cr[i] = CLIP_S8(ofst); 233 234 } 235 else 236 { 237 ps_wt_ofst->i2_chroma_weight_l0_cb[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom); 238 ps_wt_ofst->i2_chroma_weight_l0_cr[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom); 239 240 ps_wt_ofst->i2_chroma_offset_l0_cb[i] = 0; 241 ps_wt_ofst->i2_chroma_offset_l0_cr[i] = 0; 242 } 243 } 244 if(BSLICE == ps_slice_hdr->i1_slice_type) 245 { 246 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++) 247 { 248 BITS_PARSE("luma_weight_l1_flag[ i ]", value, ps_bitstrm, 1); 249 ps_wt_ofst->i1_luma_weight_l1_flag[i] = value; 250 } 251 252 if(ps_sps->i1_chroma_format_idc != 0) 253 { 254 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++) 255 { 256 BITS_PARSE("chroma_weight_l1_flag[ i ]", value, ps_bitstrm, 1); 257 ps_wt_ofst->i1_chroma_weight_l1_flag[i] = value; 258 } 259 } 260 else 261 { 262 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++) 263 { 264 ps_wt_ofst->i1_chroma_weight_l1_flag[i] = 0; 265 } 266 } 267 268 for(i = 0; i < ps_slice_hdr->i1_num_ref_idx_l1_active; i++) 269 { 270 if(ps_wt_ofst->i1_luma_weight_l1_flag[i]) 271 { 272 SEV_PARSE("delta_luma_weight_l1[ i ]", value, ps_bitstrm); 273 274 275 ps_wt_ofst->i2_luma_weight_l1[i] = (1 << ps_wt_ofst->i1_luma_log2_weight_denom) + value; 276 277 SEV_PARSE("luma_offset_l1[ i ]", value, ps_bitstrm); 278 ps_wt_ofst->i2_luma_offset_l1[i] = value; 279 280 } 281 else 282 { 283 ps_wt_ofst->i2_luma_weight_l1[i] = (1 << ps_wt_ofst->i1_luma_log2_weight_denom); 284 ps_wt_ofst->i2_luma_offset_l1[i] = 0; 285 } 286 287 if(ps_wt_ofst->i1_chroma_weight_l1_flag[i]) 288 { 289 WORD32 ofst; 290 WORD32 shift = (1 << (BIT_DEPTH_CHROMA - 1)); 291 SEV_PARSE("delta_chroma_weight_l1[ i ][ j ]", value, ps_bitstrm); 292 ps_wt_ofst->i2_chroma_weight_l1_cb[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom) + value;; 293 294 295 SEV_PARSE("delta_chroma_offset_l1[ i ][ j ]", value, ps_bitstrm); 296 ofst = ((shift * ps_wt_ofst->i2_chroma_weight_l1_cb[i]) >> ps_wt_ofst->i1_chroma_log2_weight_denom); 297 ofst = value - ofst + shift; 298 299 ps_wt_ofst->i2_chroma_offset_l1_cb[i] = CLIP_S8(ofst);; 300 301 SEV_PARSE("delta_chroma_weight_l1[ i ][ j ]", value, ps_bitstrm); 302 ps_wt_ofst->i2_chroma_weight_l1_cr[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom) + value; 303 304 305 SEV_PARSE("delta_chroma_offset_l1[ i ][ j ]", value, ps_bitstrm); 306 ofst = ((shift * ps_wt_ofst->i2_chroma_weight_l1_cr[i]) >> ps_wt_ofst->i1_chroma_log2_weight_denom); 307 ofst = value - ofst + shift; 308 309 ps_wt_ofst->i2_chroma_offset_l1_cr[i] = CLIP_S8(ofst);; 310 311 } 312 else 313 { 314 ps_wt_ofst->i2_chroma_weight_l1_cb[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom); 315 ps_wt_ofst->i2_chroma_weight_l1_cr[i] = (1 << ps_wt_ofst->i1_chroma_log2_weight_denom); 316 317 ps_wt_ofst->i2_chroma_offset_l1_cb[i] = 0; 318 ps_wt_ofst->i2_chroma_offset_l1_cr[i] = 0; 319 320 } 321 } 322 } 323 return ret; 324 } 325 326 /** 327 ******************************************************************************* 328 * 329 * @brief 330 * Parses short term reference picture set 331 * 332 * @par Description 333 * Parses short term reference picture set as per section 7.3.8.2. 334 * Can be called by either SPS or Slice header parsing modules. 335 * 336 * @param[in] ps_bitstrm 337 * Pointer to bitstream structure 338 * 339 * @param[out] ps_stref_picset_base 340 * Pointer to first short term ref pic set structure 341 * 342 * @param[in] num_short_term_ref_pic_sets 343 * Number of short term reference pic sets 344 * 345 * @param[in] idx 346 * Current short term ref pic set id 347 * 348 * @returns Error code from IHEVCD_ERROR_T 349 * 350 * @remarks 351 * 352 ******************************************************************************* 353 */ 354 IHEVCD_ERROR_T ihevcd_short_term_ref_pic_set(bitstrm_t *ps_bitstrm, 355 stref_picset_t *ps_stref_picset_base, 356 WORD32 num_short_term_ref_pic_sets, 357 WORD32 idx, 358 stref_picset_t *ps_stref_picset) 359 { 360 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 361 WORD32 value; 362 stref_picset_t *ps_stref_picset_ref; 363 WORD32 delta_idx, delta_rps; 364 WORD32 r_idx; 365 WORD32 i; 366 WORD32 j, k, temp; 367 if(idx > 0) 368 { 369 BITS_PARSE("inter_ref_pic_set_prediction_flag", value, ps_bitstrm, 1); 370 ps_stref_picset->i1_inter_ref_pic_set_prediction_flag = value; 371 } 372 else 373 ps_stref_picset->i1_inter_ref_pic_set_prediction_flag = 0; 374 375 if(ps_stref_picset->i1_inter_ref_pic_set_prediction_flag) 376 { 377 WORD32 delta_rps_sign; 378 WORD32 abs_delta_rps; 379 WORD32 num_neg_pics = 0; 380 WORD32 num_pos_pics = 0; 381 WORD32 num_pics = 0; 382 383 if(idx == num_short_term_ref_pic_sets) 384 { 385 UEV_PARSE("delta_idx_minus1", value, ps_bitstrm); 386 delta_idx = value + 1; 387 } 388 else 389 { 390 delta_idx = 1; 391 } 392 r_idx = idx - delta_idx; 393 r_idx = CLIP3(r_idx, 0, idx - 1); 394 395 ps_stref_picset_ref = ps_stref_picset_base + r_idx; 396 397 BITS_PARSE("delta_rps_sign", value, ps_bitstrm, 1); 398 delta_rps_sign = value; 399 400 UEV_PARSE("abs_delta_rps_minus1", value, ps_bitstrm); 401 abs_delta_rps = value + 1; 402 403 delta_rps = (1 - 2 * delta_rps_sign) * (abs_delta_rps); 404 405 406 407 for(i = 0; i <= ps_stref_picset_ref->i1_num_delta_pocs; i++) 408 { 409 WORD32 ref_idc; 410 411 /*****************************************************************/ 412 /* ref_idc is parsed as below */ 413 /* bits "1" ref_idc 1 */ 414 /* bits "01" ref_idc 2 */ 415 /* bits "00" ref_idc 0 */ 416 /*****************************************************************/ 417 BITS_PARSE("used_by_curr_pic_flag", value, ps_bitstrm, 1); 418 ref_idc = value; 419 ps_stref_picset->ai1_used[num_pics] = value; 420 /* If ref_idc is zero check for next bit */ 421 if(0 == ref_idc) 422 { 423 BITS_PARSE("use_delta_flag", value, ps_bitstrm, 1); 424 ref_idc = value << 1; 425 } 426 if((ref_idc == 1) || (ref_idc == 2)) 427 { 428 WORD32 delta_poc; 429 delta_poc = delta_rps; 430 delta_poc += 431 ((i < ps_stref_picset_ref->i1_num_delta_pocs) ? 432 ps_stref_picset_ref->ai2_delta_poc[i] : 433 0); 434 435 ps_stref_picset->ai2_delta_poc[num_pics] = delta_poc; 436 437 if(delta_poc < 0) 438 { 439 num_neg_pics++; 440 } 441 else 442 { 443 num_pos_pics++; 444 } 445 num_pics++; 446 } 447 ps_stref_picset->ai1_ref_idc[i] = ref_idc; 448 } 449 450 num_neg_pics = CLIP3(num_neg_pics, 0, MAX_DPB_SIZE - 1); 451 num_pos_pics = CLIP3(num_pos_pics, 0, (MAX_DPB_SIZE - 1 - num_neg_pics)); 452 num_pics = num_neg_pics + num_pos_pics; 453 454 ps_stref_picset->i1_num_ref_idc = 455 ps_stref_picset_ref->i1_num_delta_pocs + 1; 456 ps_stref_picset->i1_num_delta_pocs = num_pics; 457 ps_stref_picset->i1_num_pos_pics = num_pos_pics; 458 ps_stref_picset->i1_num_neg_pics = num_neg_pics; 459 460 461 for(j = 1; j < num_pics; j++) 462 { 463 WORD32 delta_poc = ps_stref_picset->ai2_delta_poc[j]; 464 WORD8 i1_used = ps_stref_picset->ai1_used[j]; 465 for(k = j - 1; k >= 0; k--) 466 { 467 temp = ps_stref_picset->ai2_delta_poc[k]; 468 if(delta_poc < temp) 469 { 470 ps_stref_picset->ai2_delta_poc[k + 1] = temp; 471 ps_stref_picset->ai1_used[k + 1] = ps_stref_picset->ai1_used[k]; 472 ps_stref_picset->ai2_delta_poc[k] = delta_poc; 473 ps_stref_picset->ai1_used[k] = i1_used; 474 } 475 } 476 } 477 // flip the negative values to largest first 478 for(j = 0, k = num_neg_pics - 1; j < num_neg_pics >> 1; j++, k--) 479 { 480 WORD32 delta_poc = ps_stref_picset->ai2_delta_poc[j]; 481 WORD8 i1_used = ps_stref_picset->ai1_used[j]; 482 ps_stref_picset->ai2_delta_poc[j] = ps_stref_picset->ai2_delta_poc[k]; 483 ps_stref_picset->ai1_used[j] = ps_stref_picset->ai1_used[k]; 484 ps_stref_picset->ai2_delta_poc[k] = delta_poc; 485 ps_stref_picset->ai1_used[k] = i1_used; 486 } 487 488 } 489 else 490 { 491 WORD32 prev_poc = 0; 492 WORD32 poc; 493 494 UEV_PARSE("num_negative_pics", value, ps_bitstrm); 495 ps_stref_picset->i1_num_neg_pics = value; 496 ps_stref_picset->i1_num_neg_pics = CLIP3(ps_stref_picset->i1_num_neg_pics, 497 0, 498 MAX_DPB_SIZE - 1); 499 500 UEV_PARSE("num_positive_pics", value, ps_bitstrm); 501 ps_stref_picset->i1_num_pos_pics = value; 502 ps_stref_picset->i1_num_pos_pics = CLIP3(ps_stref_picset->i1_num_pos_pics, 503 0, 504 (MAX_DPB_SIZE - 1 - ps_stref_picset->i1_num_neg_pics)); 505 506 ps_stref_picset->i1_num_delta_pocs = 507 ps_stref_picset->i1_num_neg_pics + 508 ps_stref_picset->i1_num_pos_pics; 509 510 511 for(i = 0; i < ps_stref_picset->i1_num_neg_pics; i++) 512 { 513 UEV_PARSE("delta_poc_s0_minus1", value, ps_bitstrm); 514 poc = prev_poc - (value + 1); 515 prev_poc = poc; 516 ps_stref_picset->ai2_delta_poc[i] = poc; 517 518 BITS_PARSE("used_by_curr_pic_s0_flag", value, ps_bitstrm, 1); 519 ps_stref_picset->ai1_used[i] = value; 520 521 } 522 prev_poc = 0; 523 for(i = ps_stref_picset->i1_num_neg_pics; 524 i < ps_stref_picset->i1_num_delta_pocs; 525 i++) 526 { 527 UEV_PARSE("delta_poc_s1_minus1", value, ps_bitstrm); 528 poc = prev_poc + (value + 1); 529 prev_poc = poc; 530 ps_stref_picset->ai2_delta_poc[i] = poc; 531 532 BITS_PARSE("used_by_curr_pic_s1_flag", value, ps_bitstrm, 1); 533 ps_stref_picset->ai1_used[i] = value; 534 535 } 536 537 } 538 539 return ret; 540 } 541 542 543 static WORD32 ihevcd_parse_sub_layer_hrd_parameters(bitstrm_t *ps_bitstrm, 544 sub_lyr_hrd_params_t *ps_sub_layer_hrd_params, 545 WORD32 cpb_cnt, 546 WORD32 sub_pic_cpb_params_present_flag) 547 { 548 WORD32 ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 549 WORD32 i; 550 551 for(i = 0; i <= cpb_cnt; i++) 552 { 553 UEV_PARSE("bit_rate_value_minus1[ i ]", ps_sub_layer_hrd_params->au4_bit_rate_value_minus1[i], ps_bitstrm); 554 UEV_PARSE("cpb_size_value_minus1[ i ]", ps_sub_layer_hrd_params->au4_cpb_size_value_minus1[i], ps_bitstrm); 555 556 if(sub_pic_cpb_params_present_flag) 557 { 558 UEV_PARSE("cpb_size_du_value_minus1[ i ]", ps_sub_layer_hrd_params->au4_cpb_size_du_value_minus1[i], ps_bitstrm); 559 UEV_PARSE("bit_rate_du_value_minus1[ i ]", ps_sub_layer_hrd_params->au4_bit_rate_du_value_minus1[i], ps_bitstrm); 560 } 561 BITS_PARSE("cbr_flag[ i ]", ps_sub_layer_hrd_params->au1_cbr_flag[i], ps_bitstrm, 1); 562 } 563 564 return ret; 565 } 566 567 568 static WORD32 ihevcd_parse_hrd_parameters(bitstrm_t *ps_bitstrm, 569 hrd_params_t *ps_hrd, 570 WORD32 common_info_present_flag, 571 WORD32 max_num_sub_layers_minus1) 572 { 573 WORD32 ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 574 WORD32 i; 575 576 ps_hrd->u1_nal_hrd_parameters_present_flag = 0; 577 ps_hrd->u1_vcl_hrd_parameters_present_flag = 0; 578 579 ps_hrd->u1_sub_pic_cpb_params_present_flag = 0; 580 581 ps_hrd->u1_tick_divisor_minus2 = 0; 582 ps_hrd->u1_du_cpb_removal_delay_increment_length_minus1 = 0; 583 ps_hrd->u1_sub_pic_cpb_params_in_pic_timing_sei_flag = 0; 584 ps_hrd->u1_dpb_output_delay_du_length_minus1 = 0; 585 586 ps_hrd->u4_bit_rate_scale = 0; 587 ps_hrd->u4_cpb_size_scale = 0; 588 ps_hrd->u4_cpb_size_du_scale = 0; 589 590 ps_hrd->u1_initial_cpb_removal_delay_length_minus1 = 23; 591 ps_hrd->u1_au_cpb_removal_delay_length_minus1 = 23; 592 ps_hrd->u1_dpb_output_delay_length_minus1 = 23; 593 594 if(common_info_present_flag) 595 { 596 BITS_PARSE("nal_hrd_parameters_present_flag", ps_hrd->u1_nal_hrd_parameters_present_flag, ps_bitstrm, 1); 597 BITS_PARSE("vcl_hrd_parameters_present_flag", ps_hrd->u1_vcl_hrd_parameters_present_flag, ps_bitstrm, 1); 598 599 if(ps_hrd->u1_nal_hrd_parameters_present_flag || ps_hrd->u1_vcl_hrd_parameters_present_flag) 600 { 601 BITS_PARSE("sub_pic_cpb_params_present_flag", ps_hrd->u1_sub_pic_cpb_params_present_flag, ps_bitstrm, 1); 602 if(ps_hrd->u1_sub_pic_cpb_params_present_flag) 603 { 604 BITS_PARSE("tick_divisor_minus2", ps_hrd->u1_tick_divisor_minus2, ps_bitstrm, 8); 605 BITS_PARSE("du_cpb_removal_delay_increment_length_minus1", ps_hrd->u1_du_cpb_removal_delay_increment_length_minus1, ps_bitstrm, 5); 606 BITS_PARSE("sub_pic_cpb_params_in_pic_timing_sei_flag", ps_hrd->u1_sub_pic_cpb_params_in_pic_timing_sei_flag, ps_bitstrm, 1); 607 BITS_PARSE("dpb_output_delay_du_length_minus1", ps_hrd->u1_dpb_output_delay_du_length_minus1, ps_bitstrm, 5); 608 } 609 610 BITS_PARSE("bit_rate_scale", ps_hrd->u4_bit_rate_scale, ps_bitstrm, 4); 611 BITS_PARSE("cpb_size_scale", ps_hrd->u4_cpb_size_scale, ps_bitstrm, 4); 612 if(ps_hrd->u1_sub_pic_cpb_params_present_flag) 613 BITS_PARSE("cpb_size_du_scale", ps_hrd->u4_cpb_size_du_scale, ps_bitstrm, 4); 614 615 BITS_PARSE("initial_cpb_removal_delay_length_minus1", ps_hrd->u1_initial_cpb_removal_delay_length_minus1, ps_bitstrm, 5); 616 BITS_PARSE("au_cpb_removal_delay_length_minus1", ps_hrd->u1_au_cpb_removal_delay_length_minus1, ps_bitstrm, 5); 617 BITS_PARSE("dpb_output_delay_length_minus1", ps_hrd->u1_dpb_output_delay_length_minus1, ps_bitstrm, 5); 618 } 619 } 620 621 622 for(i = 0; i <= max_num_sub_layers_minus1; i++) 623 { 624 BITS_PARSE("fixed_pic_rate_general_flag[ i ]", ps_hrd->au1_fixed_pic_rate_general_flag[i], ps_bitstrm, 1); 625 626 ps_hrd->au1_fixed_pic_rate_within_cvs_flag[i] = 1; 627 ps_hrd->au1_elemental_duration_in_tc_minus1[i] = 0; 628 ps_hrd->au1_low_delay_hrd_flag[i] = 0; 629 ps_hrd->au1_cpb_cnt_minus1[i] = 0; 630 631 if(!ps_hrd->au1_fixed_pic_rate_general_flag[i]) 632 BITS_PARSE("fixed_pic_rate_within_cvs_flag[ i ]", ps_hrd->au1_fixed_pic_rate_within_cvs_flag[i], ps_bitstrm, 1); 633 634 if(ps_hrd->au1_fixed_pic_rate_within_cvs_flag[i]) 635 { 636 UEV_PARSE("elemental_duration_in_tc_minus1[ i ]", ps_hrd->au1_elemental_duration_in_tc_minus1[i], ps_bitstrm); 637 } 638 else 639 { 640 BITS_PARSE("low_delay_hrd_flag[ i ]", ps_hrd->au1_low_delay_hrd_flag[i], ps_bitstrm, 1); 641 } 642 643 if(!ps_hrd->au1_low_delay_hrd_flag[i]) 644 UEV_PARSE("cpb_cnt_minus1[ i ]", ps_hrd->au1_cpb_cnt_minus1[i], ps_bitstrm); 645 646 if(ps_hrd->au1_cpb_cnt_minus1[i] >= (MAX_CPB_CNT - 1)) 647 return IHEVCD_INVALID_PARAMETER; 648 649 if(ps_hrd->u1_nal_hrd_parameters_present_flag) 650 ihevcd_parse_sub_layer_hrd_parameters(ps_bitstrm, 651 &ps_hrd->as_sub_layer_hrd_params[i], 652 ps_hrd->au1_cpb_cnt_minus1[i], 653 ps_hrd->u1_sub_pic_cpb_params_present_flag); 654 655 if(ps_hrd->u1_vcl_hrd_parameters_present_flag) 656 ihevcd_parse_sub_layer_hrd_parameters(ps_bitstrm, 657 &ps_hrd->as_sub_layer_hrd_params[i], 658 ps_hrd->au1_cpb_cnt_minus1[i], 659 ps_hrd->u1_sub_pic_cpb_params_present_flag); 660 } 661 662 return ret; 663 } 664 665 666 static WORD32 ihevcd_parse_vui_parameters(bitstrm_t *ps_bitstrm, 667 vui_t *ps_vui, 668 WORD32 sps_max_sub_layers_minus1) 669 { 670 WORD32 ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 671 UWORD16 u2_sar_width = 0; 672 UWORD16 u2_sar_height = 0; 673 674 BITS_PARSE("aspect_ratio_info_present_flag", ps_vui->u1_aspect_ratio_info_present_flag, ps_bitstrm, 1); 675 676 ps_vui->u1_aspect_ratio_idc = SAR_UNUSED; 677 u2_sar_width = 0; 678 u2_sar_height = 0; 679 if(ps_vui->u1_aspect_ratio_info_present_flag) 680 { 681 BITS_PARSE("aspect_ratio_idc", ps_vui->u1_aspect_ratio_idc, ps_bitstrm, 8); 682 switch(ps_vui->u1_aspect_ratio_idc) 683 { 684 case SAR_1_1: 685 u2_sar_width = 1; 686 u2_sar_height = 1; 687 break; 688 case SAR_12_11: 689 u2_sar_width = 12; 690 u2_sar_height = 11; 691 break; 692 case SAR_10_11: 693 u2_sar_width = 10; 694 u2_sar_height = 11; 695 break; 696 case SAR_16_11: 697 u2_sar_width = 16; 698 u2_sar_height = 11; 699 break; 700 case SAR_40_33: 701 u2_sar_width = 40; 702 u2_sar_height = 33; 703 break; 704 case SAR_24_11: 705 u2_sar_width = 24; 706 u2_sar_height = 11; 707 break; 708 case SAR_20_11: 709 u2_sar_width = 20; 710 u2_sar_height = 11; 711 break; 712 case SAR_32_11: 713 u2_sar_width = 32; 714 u2_sar_height = 11; 715 break; 716 case SAR_80_33: 717 u2_sar_width = 80; 718 u2_sar_height = 33; 719 break; 720 case SAR_18_11: 721 u2_sar_width = 18; 722 u2_sar_height = 11; 723 break; 724 case SAR_15_11: 725 u2_sar_width = 15; 726 u2_sar_height = 11; 727 break; 728 case SAR_64_33: 729 u2_sar_width = 64; 730 u2_sar_height = 33; 731 break; 732 case SAR_160_99: 733 u2_sar_width = 160; 734 u2_sar_height = 99; 735 break; 736 case SAR_4_3: 737 u2_sar_width = 4; 738 u2_sar_height = 3; 739 break; 740 case SAR_3_2: 741 u2_sar_width = 3; 742 u2_sar_height = 2; 743 break; 744 case SAR_2_1: 745 u2_sar_width = 2; 746 u2_sar_height = 1; 747 break; 748 case EXTENDED_SAR: 749 BITS_PARSE("sar_width", u2_sar_width, ps_bitstrm, 16); 750 BITS_PARSE("sar_height", u2_sar_height, ps_bitstrm, 16); 751 break; 752 default: 753 u2_sar_width = 0; 754 u2_sar_height = 0; 755 break; 756 } 757 } 758 759 ps_vui->u2_sar_width = u2_sar_width; 760 ps_vui->u2_sar_height = u2_sar_height; 761 762 BITS_PARSE("overscan_info_present_flag", ps_vui->u1_overscan_info_present_flag, ps_bitstrm, 1); 763 ps_vui->u1_overscan_appropriate_flag = 0; 764 if(ps_vui->u1_overscan_info_present_flag) 765 BITS_PARSE("overscan_appropriate_flag", ps_vui->u1_overscan_appropriate_flag, ps_bitstrm, 1); 766 767 BITS_PARSE("video_signal_type_present_flag", ps_vui->u1_video_signal_type_present_flag, ps_bitstrm, 1); 768 ps_vui->u1_video_format = VID_FMT_UNSPECIFIED; 769 ps_vui->u1_video_full_range_flag = 0; 770 ps_vui->u1_colour_description_present_flag = 0; 771 ps_vui->u1_colour_primaries = 2; 772 ps_vui->u1_transfer_characteristics = 2; 773 ps_vui->u1_matrix_coefficients = 2; 774 775 if(ps_vui->u1_video_signal_type_present_flag) 776 { 777 BITS_PARSE("video_format", ps_vui->u1_video_format, ps_bitstrm, 3); 778 BITS_PARSE("video_full_range_flag", ps_vui->u1_video_full_range_flag, ps_bitstrm, 1); 779 BITS_PARSE("colour_description_present_flag", ps_vui->u1_colour_description_present_flag, ps_bitstrm, 1); 780 if(ps_vui->u1_colour_description_present_flag) 781 { 782 BITS_PARSE("colour_primaries", ps_vui->u1_colour_primaries, ps_bitstrm, 8); 783 BITS_PARSE("transfer_characteristics", ps_vui->u1_transfer_characteristics, ps_bitstrm, 8); 784 BITS_PARSE("matrix_coeffs", ps_vui->u1_matrix_coefficients, ps_bitstrm, 8); 785 } 786 } 787 788 BITS_PARSE("chroma_loc_info_present_flag", ps_vui->u1_chroma_loc_info_present_flag, ps_bitstrm, 1); 789 ps_vui->u1_chroma_sample_loc_type_top_field = 0; 790 ps_vui->u1_chroma_sample_loc_type_bottom_field = 0; 791 if(ps_vui->u1_chroma_loc_info_present_flag) 792 { 793 UEV_PARSE("chroma_sample_loc_type_top_field", ps_vui->u1_chroma_sample_loc_type_top_field, ps_bitstrm); 794 UEV_PARSE("chroma_sample_loc_type_bottom_field", ps_vui->u1_chroma_sample_loc_type_bottom_field, ps_bitstrm); 795 } 796 797 BITS_PARSE("neutral_chroma_indication_flag", ps_vui->u1_neutral_chroma_indication_flag, ps_bitstrm, 1); 798 BITS_PARSE("field_seq_flag", ps_vui->u1_field_seq_flag, ps_bitstrm, 1); 799 BITS_PARSE("frame_field_info_present_flag", ps_vui->u1_frame_field_info_present_flag, ps_bitstrm, 1); 800 BITS_PARSE("default_display_window_flag", ps_vui->u1_default_display_window_flag, ps_bitstrm, 1); 801 ps_vui->u4_def_disp_win_left_offset = 0; 802 ps_vui->u4_def_disp_win_right_offset = 0; 803 ps_vui->u4_def_disp_win_top_offset = 0; 804 ps_vui->u4_def_disp_win_bottom_offset = 0; 805 if(ps_vui->u1_default_display_window_flag) 806 { 807 UEV_PARSE("def_disp_win_left_offset", ps_vui->u4_def_disp_win_left_offset, ps_bitstrm); 808 UEV_PARSE("def_disp_win_right_offset", ps_vui->u4_def_disp_win_right_offset, ps_bitstrm); 809 UEV_PARSE("def_disp_win_top_offset", ps_vui->u4_def_disp_win_top_offset, ps_bitstrm); 810 UEV_PARSE("def_disp_win_bottom_offset", ps_vui->u4_def_disp_win_bottom_offset, ps_bitstrm); 811 } 812 813 BITS_PARSE("vui_timing_info_present_flag", ps_vui->u1_vui_timing_info_present_flag, ps_bitstrm, 1); 814 if(ps_vui->u1_vui_timing_info_present_flag) 815 { 816 BITS_PARSE("vui_num_units_in_tick", ps_vui->u4_vui_num_units_in_tick, ps_bitstrm, 32); 817 BITS_PARSE("vui_time_scale", ps_vui->u4_vui_time_scale, ps_bitstrm, 32); 818 BITS_PARSE("vui_poc_proportional_to_timing_flag", ps_vui->u1_poc_proportional_to_timing_flag, ps_bitstrm, 1); 819 if(ps_vui->u1_poc_proportional_to_timing_flag) 820 UEV_PARSE("vui_num_ticks_poc_diff_one_minus1", ps_vui->u1_num_ticks_poc_diff_one_minus1, ps_bitstrm); 821 822 BITS_PARSE("vui_hrd_parameters_present_flag", ps_vui->u1_vui_hrd_parameters_present_flag, ps_bitstrm, 1); 823 if(ps_vui->u1_vui_hrd_parameters_present_flag) 824 { 825 ret = ihevcd_parse_hrd_parameters(ps_bitstrm, &ps_vui->s_vui_hrd_parameters, 1, sps_max_sub_layers_minus1); 826 RETURN_IF((ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS), ret); 827 } 828 } 829 830 BITS_PARSE("bitstream_restriction_flag", ps_vui->u1_bitstream_restriction_flag, ps_bitstrm, 1); 831 ps_vui->u1_tiles_fixed_structure_flag = 0; 832 ps_vui->u1_motion_vectors_over_pic_boundaries_flag = 1; 833 ps_vui->u1_restricted_ref_pic_lists_flag = 0; 834 ps_vui->u4_min_spatial_segmentation_idc = 0; 835 ps_vui->u1_max_bytes_per_pic_denom = 2; 836 ps_vui->u1_max_bits_per_mincu_denom = 1; 837 ps_vui->u1_log2_max_mv_length_horizontal = 15; 838 ps_vui->u1_log2_max_mv_length_vertical = 15; 839 if(ps_vui->u1_bitstream_restriction_flag) 840 { 841 BITS_PARSE("tiles_fixed_structure_flag", ps_vui->u1_tiles_fixed_structure_flag, ps_bitstrm, 1); 842 BITS_PARSE("motion_vectors_over_pic_boundaries_flag", ps_vui->u1_motion_vectors_over_pic_boundaries_flag, ps_bitstrm, 1); 843 BITS_PARSE("restricted_ref_pic_lists_flag", ps_vui->u1_restricted_ref_pic_lists_flag, ps_bitstrm, 1); 844 845 UEV_PARSE("min_spatial_segmentation_idc", ps_vui->u4_min_spatial_segmentation_idc, ps_bitstrm); 846 UEV_PARSE("max_bytes_per_pic_denom", ps_vui->u1_max_bytes_per_pic_denom, ps_bitstrm); 847 UEV_PARSE("max_bits_per_min_cu_denom", ps_vui->u1_max_bits_per_mincu_denom, ps_bitstrm); 848 UEV_PARSE("log2_max_mv_length_horizontal", ps_vui->u1_log2_max_mv_length_horizontal, ps_bitstrm); 849 UEV_PARSE("log2_max_mv_length_vertical", ps_vui->u1_log2_max_mv_length_vertical, ps_bitstrm); 850 } 851 852 return ret; 853 } 854 855 /** 856 ******************************************************************************* 857 * 858 * @brief 859 * Parses profile tier and level info for either general layer of sub_layer 860 * 861 * @par Description 862 * Parses profile tier and level info for either general layer of sub_layer 863 * as per section 7.3.3 864 * 865 * Since the same function is called for parsing general_profile and 866 * sub_layer_profile etc, variables do not specify whether the syntax is 867 * for general or sub_layer. Similarly trace functions also do not differentiate 868 * 869 * @param[in] ps_bitstrm 870 * Pointer to bitstream structure 871 * 872 * @param[out] ps_ptl 873 * Pointer to profile, tier level structure 874 * 875 * @returns Error code from IHEVCD_ERROR_T 876 * 877 * @remarks 878 * 879 ******************************************************************************* 880 */ 881 882 static IHEVCD_ERROR_T ihevcd_parse_profile_tier_level_layer(bitstrm_t *ps_bitstrm, 883 profile_tier_lvl_t *ps_ptl) 884 { 885 WORD32 value; 886 WORD32 i; 887 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 888 889 BITS_PARSE("XXX_profile_space[]", value, ps_bitstrm, 2); 890 ps_ptl->i1_profile_space = value; 891 892 BITS_PARSE("XXX_tier_flag[]", value, ps_bitstrm, 1); 893 ps_ptl->i1_tier_flag = value; 894 895 BITS_PARSE("XXX_profile_idc[]", value, ps_bitstrm, 5); 896 ps_ptl->i1_profile_idc = value; 897 898 for(i = 0; i < MAX_PROFILE_COMPATBLTY; i++) 899 { 900 BITS_PARSE("XXX_profile_compatibility_flag[][j]", value, ps_bitstrm, 1); 901 ps_ptl->ai1_profile_compatibility_flag[i] = value; 902 } 903 904 BITS_PARSE("general_progressive_source_flag", value, ps_bitstrm, 1); 905 ps_ptl->i1_general_progressive_source_flag = value; 906 907 BITS_PARSE("general_interlaced_source_flag", value, ps_bitstrm, 1); 908 ps_ptl->i1_general_interlaced_source_flag = value; 909 910 BITS_PARSE("general_non_packed_constraint_flag", value, ps_bitstrm, 1); 911 ps_ptl->i1_general_non_packed_constraint_flag = value; 912 913 BITS_PARSE("general_frame_only_constraint_flag", value, ps_bitstrm, 1); 914 ps_ptl->i1_frame_only_constraint_flag = value; 915 916 BITS_PARSE("XXX_reserved_zero_44bits[0..15]", value, ps_bitstrm, 16); 917 918 BITS_PARSE("XXX_reserved_zero_44bits[16..31]", value, ps_bitstrm, 16); 919 920 BITS_PARSE("XXX_reserved_zero_44bits[32..43]", value, ps_bitstrm, 12); 921 return ret; 922 } 923 924 925 /** 926 ******************************************************************************* 927 * 928 * @brief 929 * Parses profile tier and level info 930 * 931 * @par Description 932 * Parses profile tier and level info as per section 7.3.3 933 * Called during VPS and SPS parsing 934 * calls ihevcd_parse_profile_tier_level() for general layer and each sub_layers 935 * 936 * @param[in] ps_bitstrm 937 * Pointer to bitstream structure 938 * 939 * @param[out] ps_ptl 940 * Pointer to structure that contains profile, tier level for each layers 941 * 942 * @param[in] profile_present 943 * Flag to indicate if profile data is present 944 * 945 * @param[in] max_num_sub_layers 946 * Number of sub layers present 947 * 948 * @returns Error code from IHEVCD_ERROR_T 949 * 950 * @remarks 951 * 952 ******************************************************************************* 953 */ 954 955 static IHEVCD_ERROR_T ihevcd_profile_tier_level(bitstrm_t *ps_bitstrm, 956 profile_tier_lvl_info_t *ps_ptl, 957 WORD32 profile_present, 958 WORD32 max_num_sub_layers) 959 { 960 WORD32 value; 961 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 962 WORD32 i; 963 964 if(profile_present) 965 { 966 ret = ihevcd_parse_profile_tier_level_layer(ps_bitstrm, &ps_ptl->s_ptl_gen); 967 if((IHEVCD_ERROR_T)IHEVCD_SUCCESS != ret) 968 { 969 return ret; 970 } 971 } 972 973 BITS_PARSE("general_level_idc", value, ps_bitstrm, 8); 974 ps_ptl->s_ptl_gen.u1_level_idc = value; 975 976 977 for(i = 0; i < max_num_sub_layers; i++) 978 { 979 BITS_PARSE("sub_layer_profile_present_flag[i]", value, ps_bitstrm, 1); 980 ps_ptl->ai1_sub_layer_profile_present_flag[i] = value; 981 982 BITS_PARSE("sub_layer_level_present_flag[i]", value, ps_bitstrm, 1); 983 ps_ptl->ai1_sub_layer_level_present_flag[i] = value; 984 } 985 986 if(max_num_sub_layers > 0) 987 { 988 for(i = max_num_sub_layers; i < 8; i++) 989 { 990 BITS_PARSE("reserved_zero_2bits", value, ps_bitstrm, 2); 991 } 992 } 993 994 for(i = 0; i < max_num_sub_layers; i++) 995 { 996 if(ps_ptl->ai1_sub_layer_profile_present_flag[i]) 997 { 998 ret = ihevcd_parse_profile_tier_level_layer(ps_bitstrm, 999 &ps_ptl->as_ptl_sub[i]); 1000 } 1001 if(ps_ptl->ai1_sub_layer_level_present_flag[i]) 1002 { 1003 BITS_PARSE("sub_layer_level_idc[i]", value, ps_bitstrm, 8); 1004 ps_ptl->as_ptl_sub[i].u1_level_idc = value; 1005 1006 } 1007 } 1008 1009 1010 1011 return ret; 1012 } 1013 1014 /** 1015 ******************************************************************************* 1016 * 1017 * @brief 1018 * Parses Scaling List Data syntax 1019 * 1020 * @par Description: 1021 * Parses Scaling List Data syntax as per Section: 7.3.6 1022 * 1023 * @param[in] ps_codec 1024 * Pointer to codec context 1025 * 1026 * @returns Error code from IHEVCD_ERROR_T 1027 * 1028 * @remarks 1029 * 1030 * 1031 ******************************************************************************* 1032 */ 1033 IHEVCD_ERROR_T ihevcd_scaling_list_data(codec_t *ps_codec, WORD16 *pi2_scaling_mat) 1034 { 1035 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 1036 WORD32 size_id; 1037 WORD32 matrix_id; 1038 WORD32 value, dc_value = 0; 1039 WORD32 next_coef; 1040 WORD32 coef_num; 1041 WORD32 i, j, offset; 1042 bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; 1043 WORD16 *pi2_scaling_mat_offset; 1044 WORD32 scaling_mat_offset[] = { 0, 16, 32, 48, 64, 80, 96, 160, 224, 288, 352, 416, 480, 736, 992, 1248, 1504, 1760, 2016, 3040 }; 1045 UWORD8 *scan_table; 1046 1047 for(size_id = 0; size_id < 4; size_id++) 1048 { 1049 for(matrix_id = 0; matrix_id < ((size_id == 3) ? 2 : 6); matrix_id++) 1050 { 1051 WORD32 scaling_list_pred_mode_flag; 1052 WORD32 scaling_list_delta_coef; 1053 BITS_PARSE("scaling_list_pred_mode_flag", scaling_list_pred_mode_flag, ps_bitstrm, 1); 1054 1055 offset = size_id * 6 + matrix_id; 1056 pi2_scaling_mat_offset = pi2_scaling_mat + scaling_mat_offset[offset]; 1057 1058 if(!scaling_list_pred_mode_flag) 1059 { 1060 WORD32 num_elements; 1061 UEV_PARSE("scaling_list_pred_matrix_id_delta", value, 1062 ps_bitstrm); 1063 value = CLIP3(value, 0, matrix_id); 1064 1065 num_elements = (1 << (4 + (size_id << 1))); 1066 if(0 != value) 1067 memcpy(pi2_scaling_mat_offset, pi2_scaling_mat_offset - value * num_elements, num_elements * sizeof(WORD16)); 1068 } 1069 else 1070 { 1071 next_coef = 8; 1072 coef_num = MIN(64, (1 << (4 + (size_id << 1)))); 1073 1074 if(size_id > 1) 1075 { 1076 SEV_PARSE("scaling_list_dc_coef_minus8", value, 1077 ps_bitstrm); 1078 1079 next_coef = value + 8; 1080 dc_value = next_coef; 1081 } 1082 if(size_id < 2) 1083 { 1084 scan_table = (UWORD8 *)gapv_ihevc_invscan[size_id + 1]; 1085 1086 for(i = 0; i < coef_num; i++) 1087 { 1088 SEV_PARSE("scaling_list_delta_coef", 1089 scaling_list_delta_coef, ps_bitstrm); 1090 next_coef = (next_coef + scaling_list_delta_coef + 256) 1091 % 256; 1092 pi2_scaling_mat_offset[scan_table[i]] = next_coef; 1093 } 1094 } 1095 else if(size_id == 2) 1096 { 1097 scan_table = (UWORD8 *)gapv_ihevc_invscan[2]; 1098 1099 for(i = 0; i < coef_num; i++) 1100 { 1101 SEV_PARSE("scaling_list_delta_coef", 1102 scaling_list_delta_coef, ps_bitstrm); 1103 next_coef = (next_coef + scaling_list_delta_coef + 256) 1104 % 256; 1105 1106 offset = scan_table[i]; 1107 offset = (offset >> 3) * 16 * 2 + (offset & 0x7) * 2; 1108 pi2_scaling_mat_offset[offset] = next_coef; 1109 pi2_scaling_mat_offset[offset + 1] = next_coef; 1110 pi2_scaling_mat_offset[offset + 16] = next_coef; 1111 pi2_scaling_mat_offset[offset + 16 + 1] = next_coef; 1112 } 1113 pi2_scaling_mat_offset[0] = dc_value; 1114 } 1115 else 1116 { 1117 scan_table = (UWORD8 *)gapv_ihevc_invscan[2]; 1118 1119 for(i = 0; i < coef_num; i++) 1120 { 1121 SEV_PARSE("scaling_list_delta_coef", 1122 scaling_list_delta_coef, ps_bitstrm); 1123 next_coef = (next_coef + scaling_list_delta_coef + 256) 1124 % 256; 1125 1126 offset = scan_table[i]; 1127 offset = (offset >> 3) * 32 * 4 + (offset & 0x7) * 4; 1128 1129 for(j = 0; j < 4; j++) 1130 { 1131 pi2_scaling_mat_offset[offset + j * 32] = next_coef; 1132 pi2_scaling_mat_offset[offset + 1 + j * 32] = next_coef; 1133 pi2_scaling_mat_offset[offset + 2 + j * 32] = next_coef; 1134 pi2_scaling_mat_offset[offset + 3 + j * 32] = next_coef; 1135 } 1136 pi2_scaling_mat_offset[0] = dc_value; 1137 } 1138 } 1139 } 1140 } 1141 } 1142 1143 return ret; 1144 } 1145 1146 /** 1147 ******************************************************************************* 1148 * 1149 * @brief 1150 * Parses VPS (Video Parameter Set) 1151 * 1152 * @par Description: 1153 * Parse Video Parameter Set as per Section 7.3.2.1 1154 * update vps structure corresponding to vps ID 1155 * Till parsing VPS id, the elements are stored in local variables and are copied 1156 * later 1157 * 1158 * @param[in] ps_codec 1159 * Pointer to codec context. 1160 * 1161 * @returns Error code from IHEVCD_ERROR_T 1162 * 1163 * @remarks 1164 * 1165 * 1166 ******************************************************************************* 1167 */ 1168 IHEVCD_ERROR_T ihevcd_parse_vps(codec_t *ps_codec) 1169 { 1170 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 1171 WORD32 i; 1172 WORD32 value; 1173 WORD32 vps_id; 1174 vps_t *ps_vps; 1175 bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; 1176 BITS_PARSE("vps_video_parameter_set_id", value, ps_bitstrm, 4); 1177 vps_id = value; 1178 1179 if(vps_id >= MAX_VPS_CNT) 1180 { 1181 ps_codec->s_parse.i4_error_code = IHEVCD_UNSUPPORTED_VPS_ID; 1182 return IHEVCD_UNSUPPORTED_VPS_ID; 1183 } 1184 1185 1186 ps_vps = (ps_codec->s_parse.ps_vps_base + vps_id); 1187 1188 ps_vps->i1_vps_id = vps_id; 1189 1190 BITS_PARSE("vps_reserved_three_2bits", value, ps_bitstrm, 2); 1191 ASSERT(value == 3); 1192 1193 BITS_PARSE("vps_max_layers_minus1", value, ps_bitstrm, 6); 1194 //ps_vps->i1_vps_max_layers = value + 1; 1195 1196 1197 1198 BITS_PARSE("vps_max_sub_layers_minus1", value, ps_bitstrm, 3); 1199 ps_vps->i1_vps_max_sub_layers = value + 1; 1200 1201 ASSERT(ps_vps->i1_vps_max_sub_layers < VPS_MAX_SUB_LAYERS); 1202 1203 BITS_PARSE("vps_temporal_id_nesting_flag", value, ps_bitstrm, 1); 1204 ps_vps->i1_vps_temporal_id_nesting_flag = value; 1205 1206 BITS_PARSE("vps_reserved_ffff_16bits", value, ps_bitstrm, 16); 1207 ASSERT(value == 0xFFFF); 1208 // profile_and_level( 1, vps_max_sub_layers_minus1 ) 1209 ret = ihevcd_profile_tier_level(ps_bitstrm, &(ps_vps->s_ptl), 1210 1, (ps_vps->i1_vps_max_sub_layers - 1)); 1211 1212 BITS_PARSE("vps_sub_layer_ordering_info_present_flag", value, ps_bitstrm, 1); 1213 ps_vps->i1_sub_layer_ordering_info_present_flag = value; 1214 i = (ps_vps->i1_sub_layer_ordering_info_present_flag ? 1215 0 : (ps_vps->i1_vps_max_sub_layers - 1)); 1216 for(; i < ps_vps->i1_vps_max_sub_layers; i++) 1217 { 1218 UEV_PARSE("vps_max_dec_pic_buffering[i]", value, ps_bitstrm); 1219 ps_vps->ai1_vps_max_dec_pic_buffering[i] = value; 1220 1221 /* vps_num_reorder_pics (no max) used in print in order to match with HM */ 1222 UEV_PARSE("vps_num_reorder_pics[i]", value, ps_bitstrm); 1223 ps_vps->ai1_vps_max_num_reorder_pics[i] = value; 1224 1225 UEV_PARSE("vps_max_latency_increase[i]", value, ps_bitstrm); 1226 ps_vps->ai1_vps_max_latency_increase[i] = value; 1227 } 1228 1229 1230 1231 BITS_PARSE("vps_max_layer_id", value, ps_bitstrm, 6); 1232 //ps_vps->i1_vps_max_layer_id = value; 1233 1234 UEV_PARSE("vps_num_layer_sets_minus1", value, ps_bitstrm); 1235 //ps_vps->i1_vps_num_layer_sets = value + 1; 1236 1237 BITS_PARSE("vps_timing_info_present_flag", value, ps_bitstrm, 1); 1238 //ps_vps->i1_vps_timing_info_present_flag = value; 1239 1240 1241 1242 return ret; 1243 } 1244 1245 /** 1246 ******************************************************************************* 1247 * 1248 * @brief 1249 * Parses SPS (Sequence Parameter Set) 1250 * sequence_parameter_set_rbsp() 1251 * 1252 * @par Description: 1253 * Parse Sequence Parameter Set as per section Section: 7.3.2.2 1254 * The sps is written to a temporary buffer and copied later to the 1255 * appropriate location 1256 * 1257 * @param[in] ps_codec 1258 * Pointer to codec context 1259 * 1260 * @returns Error code from IHEVCD_ERROR_T 1261 * 1262 * @remarks 1263 * 1264 * 1265 ******************************************************************************* 1266 */ 1267 IHEVCD_ERROR_T ihevcd_parse_sps(codec_t *ps_codec) 1268 { 1269 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 1270 WORD32 value; 1271 1272 WORD32 i; 1273 WORD32 vps_id; 1274 WORD32 sps_max_sub_layers; 1275 WORD32 sps_id; 1276 WORD32 sps_temporal_id_nesting_flag; 1277 sps_t *ps_sps; 1278 profile_tier_lvl_info_t s_ptl; 1279 bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; 1280 WORD32 ctb_log2_size_y = 0; 1281 1282 1283 BITS_PARSE("video_parameter_set_id", value, ps_bitstrm, 4); 1284 vps_id = value; 1285 vps_id = CLIP3(vps_id, 0, MAX_VPS_CNT - 1); 1286 1287 BITS_PARSE("sps_max_sub_layers_minus1", value, ps_bitstrm, 3); 1288 sps_max_sub_layers = value + 1; 1289 sps_max_sub_layers = CLIP3(sps_max_sub_layers, 1, 7); 1290 1291 BITS_PARSE("sps_temporal_id_nesting_flag", value, ps_bitstrm, 1); 1292 sps_temporal_id_nesting_flag = value; 1293 1294 //profile_and_level( 1, sps_max_sub_layers_minus1 ) 1295 ret = ihevcd_profile_tier_level(ps_bitstrm, &(s_ptl), 1, 1296 (sps_max_sub_layers - 1)); 1297 1298 UEV_PARSE("seq_parameter_set_id", value, ps_bitstrm); 1299 sps_id = value; 1300 1301 if((sps_id >= MAX_SPS_CNT) || (sps_id < 0)) 1302 { 1303 if(ps_codec->i4_sps_done) 1304 return IHEVCD_UNSUPPORTED_SPS_ID; 1305 else 1306 sps_id = 0; 1307 } 1308 1309 1310 ps_sps = (ps_codec->s_parse.ps_sps_base + MAX_SPS_CNT - 1); 1311 /* Reset SPS to zero */ 1312 { 1313 WORD16 *pi2_scaling_mat = ps_sps->pi2_scaling_mat; 1314 memset(ps_sps, 0, sizeof(sps_t)); 1315 ps_sps->pi2_scaling_mat = pi2_scaling_mat; 1316 } 1317 ps_sps->i1_sps_id = sps_id; 1318 ps_sps->i1_vps_id = vps_id; 1319 ps_sps->i1_sps_max_sub_layers = sps_max_sub_layers; 1320 ps_sps->i1_sps_temporal_id_nesting_flag = sps_temporal_id_nesting_flag; 1321 /* This is used only during initialization to get reorder count etc */ 1322 ps_codec->i4_sps_id = sps_id; 1323 memcpy(&ps_sps->s_ptl, &s_ptl, sizeof(profile_tier_lvl_info_t)); 1324 1325 UEV_PARSE("chroma_format_idc", value, ps_bitstrm); 1326 ps_sps->i1_chroma_format_idc = value; 1327 1328 if(ps_sps->i1_chroma_format_idc != CHROMA_FMT_IDC_YUV420) 1329 { 1330 ps_codec->s_parse.i4_error_code = IHEVCD_UNSUPPORTED_CHROMA_FMT_IDC; 1331 return (IHEVCD_ERROR_T)IHEVCD_UNSUPPORTED_CHROMA_FMT_IDC; 1332 } 1333 1334 if(CHROMA_FMT_IDC_YUV444_PLANES == ps_sps->i1_chroma_format_idc) 1335 { 1336 BITS_PARSE("separate_colour_plane_flag", value, ps_bitstrm, 1); 1337 ps_sps->i1_separate_colour_plane_flag = value; 1338 } 1339 else 1340 { 1341 ps_sps->i1_separate_colour_plane_flag = 0; 1342 } 1343 1344 UEV_PARSE("pic_width_in_luma_samples", value, ps_bitstrm); 1345 ps_sps->i2_pic_width_in_luma_samples = value; 1346 1347 UEV_PARSE("pic_height_in_luma_samples", value, ps_bitstrm); 1348 ps_sps->i2_pic_height_in_luma_samples = value; 1349 1350 if((0 >= ps_sps->i2_pic_width_in_luma_samples) || (0 >= ps_sps->i2_pic_height_in_luma_samples)) 1351 return IHEVCD_INVALID_PARAMETER; 1352 1353 /* i2_pic_width_in_luma_samples and i2_pic_height_in_luma_samples 1354 should be multiples of min_cb_size. Here these are aligned to 8, 1355 i.e. smallest CB size */ 1356 ps_sps->i2_pic_width_in_luma_samples = ALIGN8(ps_sps->i2_pic_width_in_luma_samples); 1357 ps_sps->i2_pic_height_in_luma_samples = ALIGN8(ps_sps->i2_pic_height_in_luma_samples); 1358 1359 BITS_PARSE("pic_cropping_flag", value, ps_bitstrm, 1); 1360 ps_sps->i1_pic_cropping_flag = value; 1361 1362 if(ps_sps->i1_pic_cropping_flag) 1363 { 1364 1365 UEV_PARSE("pic_crop_left_offset", value, ps_bitstrm); 1366 if (value >= ps_sps->i2_pic_width_in_luma_samples) 1367 { 1368 return IHEVCD_INVALID_PARAMETER; 1369 } 1370 ps_sps->i2_pic_crop_left_offset = value; 1371 1372 UEV_PARSE("pic_crop_right_offset", value, ps_bitstrm); 1373 if (value >= ps_sps->i2_pic_width_in_luma_samples) 1374 { 1375 return IHEVCD_INVALID_PARAMETER; 1376 } 1377 ps_sps->i2_pic_crop_right_offset = value; 1378 1379 UEV_PARSE("pic_crop_top_offset", value, ps_bitstrm); 1380 if (value >= ps_sps->i2_pic_height_in_luma_samples) 1381 { 1382 return IHEVCD_INVALID_PARAMETER; 1383 } 1384 ps_sps->i2_pic_crop_top_offset = value; 1385 1386 UEV_PARSE("pic_crop_bottom_offset", value, ps_bitstrm); 1387 if (value >= ps_sps->i2_pic_height_in_luma_samples) 1388 { 1389 return IHEVCD_INVALID_PARAMETER; 1390 } 1391 ps_sps->i2_pic_crop_bottom_offset = value; 1392 } 1393 else 1394 { 1395 ps_sps->i2_pic_crop_left_offset = 0; 1396 ps_sps->i2_pic_crop_right_offset = 0; 1397 ps_sps->i2_pic_crop_top_offset = 0; 1398 ps_sps->i2_pic_crop_bottom_offset = 0; 1399 } 1400 1401 1402 UEV_PARSE("bit_depth_luma_minus8", value, ps_bitstrm); 1403 if(0 != value) 1404 return IHEVCD_UNSUPPORTED_BIT_DEPTH; 1405 1406 UEV_PARSE("bit_depth_chroma_minus8", value, ps_bitstrm); 1407 if(0 != value) 1408 return IHEVCD_UNSUPPORTED_BIT_DEPTH; 1409 1410 UEV_PARSE("log2_max_pic_order_cnt_lsb_minus4", value, ps_bitstrm); 1411 ps_sps->i1_log2_max_pic_order_cnt_lsb = value + 4; 1412 1413 BITS_PARSE("sps_sub_layer_ordering_info_present_flag", value, ps_bitstrm, 1); 1414 ps_sps->i1_sps_sub_layer_ordering_info_present_flag = value; 1415 1416 1417 i = (ps_sps->i1_sps_sub_layer_ordering_info_present_flag ? 0 : (ps_sps->i1_sps_max_sub_layers - 1)); 1418 for(; i < ps_sps->i1_sps_max_sub_layers; i++) 1419 { 1420 UEV_PARSE("max_dec_pic_buffering", value, ps_bitstrm); 1421 ps_sps->ai1_sps_max_dec_pic_buffering[i] = value + 1; 1422 1423 if(ps_sps->ai1_sps_max_dec_pic_buffering[i] > MAX_DPB_SIZE) 1424 { 1425 return IHEVCD_INVALID_PARAMETER; 1426 } 1427 1428 UEV_PARSE("num_reorder_pics", value, ps_bitstrm); 1429 ps_sps->ai1_sps_max_num_reorder_pics[i] = value; 1430 1431 if(ps_sps->ai1_sps_max_num_reorder_pics[i] > ps_sps->ai1_sps_max_dec_pic_buffering[i]) 1432 { 1433 return IHEVCD_INVALID_PARAMETER; 1434 } 1435 1436 UEV_PARSE("max_latency_increase", value, ps_bitstrm); 1437 ps_sps->ai1_sps_max_latency_increase[i] = value; 1438 } 1439 1440 /* Check if sps_max_dec_pic_buffering or sps_max_num_reorder_pics 1441 has changed */ 1442 if(0 != ps_codec->u4_allocate_dynamic_done) 1443 { 1444 sps_t *ps_sps_old = ps_codec->s_parse.ps_sps; 1445 if(ps_sps_old->ai1_sps_max_dec_pic_buffering[ps_sps_old->i1_sps_max_sub_layers - 1] != 1446 ps_sps->ai1_sps_max_dec_pic_buffering[ps_sps->i1_sps_max_sub_layers - 1]) 1447 { 1448 if(0 == ps_codec->i4_first_pic_done) 1449 { 1450 return IHEVCD_INVALID_PARAMETER; 1451 } 1452 ps_codec->i4_reset_flag = 1; 1453 return (IHEVCD_ERROR_T)IVD_RES_CHANGED; 1454 } 1455 1456 if(ps_sps_old->ai1_sps_max_num_reorder_pics[ps_sps_old->i1_sps_max_sub_layers - 1] != 1457 ps_sps->ai1_sps_max_num_reorder_pics[ps_sps->i1_sps_max_sub_layers - 1]) 1458 { 1459 if(0 == ps_codec->i4_first_pic_done) 1460 { 1461 return IHEVCD_INVALID_PARAMETER; 1462 } 1463 ps_codec->i4_reset_flag = 1; 1464 return (IHEVCD_ERROR_T)IVD_RES_CHANGED; 1465 } 1466 } 1467 1468 UEV_PARSE("log2_min_coding_block_size_minus3", value, ps_bitstrm); 1469 ps_sps->i1_log2_min_coding_block_size = value + 3; 1470 1471 UEV_PARSE("log2_diff_max_min_coding_block_size", value, ps_bitstrm); 1472 ps_sps->i1_log2_diff_max_min_coding_block_size = value; 1473 1474 ctb_log2_size_y = ps_sps->i1_log2_min_coding_block_size + ps_sps->i1_log2_diff_max_min_coding_block_size; 1475 1476 UEV_PARSE("log2_min_transform_block_size_minus2", value, ps_bitstrm); 1477 ps_sps->i1_log2_min_transform_block_size = value + 2; 1478 1479 UEV_PARSE("log2_diff_max_min_transform_block_size", value, ps_bitstrm); 1480 ps_sps->i1_log2_diff_max_min_transform_block_size = value; 1481 1482 ps_sps->i1_log2_max_transform_block_size = ps_sps->i1_log2_min_transform_block_size + 1483 ps_sps->i1_log2_diff_max_min_transform_block_size; 1484 1485 if ((ps_sps->i1_log2_max_transform_block_size < 0) || 1486 (ps_sps->i1_log2_max_transform_block_size > MIN(ctb_log2_size_y, 5))) 1487 { 1488 return IHEVCD_INVALID_PARAMETER; 1489 } 1490 1491 ps_sps->i1_log2_ctb_size = ps_sps->i1_log2_min_coding_block_size + 1492 ps_sps->i1_log2_diff_max_min_coding_block_size; 1493 1494 if((ps_sps->i1_log2_min_coding_block_size < 3) || 1495 (ps_sps->i1_log2_min_transform_block_size < 2) || 1496 (ps_sps->i1_log2_diff_max_min_transform_block_size < 0) || 1497 (ps_sps->i1_log2_max_transform_block_size > ps_sps->i1_log2_ctb_size) || 1498 (ps_sps->i1_log2_ctb_size < 4) || 1499 (ps_sps->i1_log2_ctb_size > 6)) 1500 { 1501 return IHEVCD_INVALID_PARAMETER; 1502 } 1503 1504 ps_sps->i1_log2_min_pcm_coding_block_size = 0; 1505 ps_sps->i1_log2_diff_max_min_pcm_coding_block_size = 0; 1506 1507 UEV_PARSE("max_transform_hierarchy_depth_inter", value, ps_bitstrm); 1508 ps_sps->i1_max_transform_hierarchy_depth_inter = value; 1509 1510 UEV_PARSE("max_transform_hierarchy_depth_intra", value, ps_bitstrm); 1511 ps_sps->i1_max_transform_hierarchy_depth_intra = value; 1512 1513 /* String has a d (enabled) in order to match with HM */ 1514 BITS_PARSE("scaling_list_enabled_flag", value, ps_bitstrm, 1); 1515 ps_sps->i1_scaling_list_enable_flag = value; 1516 1517 if(ps_sps->i1_scaling_list_enable_flag) 1518 { 1519 COPY_DEFAULT_SCALING_LIST(ps_sps->pi2_scaling_mat); 1520 BITS_PARSE("sps_scaling_list_data_present_flag", value, ps_bitstrm, 1); 1521 ps_sps->i1_sps_scaling_list_data_present_flag = value; 1522 1523 if(ps_sps->i1_sps_scaling_list_data_present_flag) 1524 ihevcd_scaling_list_data(ps_codec, ps_sps->pi2_scaling_mat); 1525 } 1526 else 1527 { 1528 COPY_FLAT_SCALING_LIST(ps_sps->pi2_scaling_mat); 1529 } 1530 /* String is asymmetric_motion_partitions_enabled_flag instead of amp_enabled_flag in order to match with HM */ 1531 BITS_PARSE("asymmetric_motion_partitions_enabled_flag", value, ps_bitstrm, 1); 1532 ps_sps->i1_amp_enabled_flag = value; 1533 1534 BITS_PARSE("sample_adaptive_offset_enabled_flag", value, ps_bitstrm, 1); 1535 ps_sps->i1_sample_adaptive_offset_enabled_flag = value; 1536 1537 BITS_PARSE("pcm_enabled_flag", value, ps_bitstrm, 1); 1538 ps_sps->i1_pcm_enabled_flag = value; 1539 1540 if(ps_sps->i1_pcm_enabled_flag) 1541 { 1542 BITS_PARSE("pcm_sample_bit_depth_luma", value, ps_bitstrm, 4); 1543 ps_sps->i1_pcm_sample_bit_depth_luma = value + 1; 1544 1545 BITS_PARSE("pcm_sample_bit_depth_chroma", value, ps_bitstrm, 4); 1546 ps_sps->i1_pcm_sample_bit_depth_chroma = value + 1; 1547 1548 UEV_PARSE("log2_min_pcm_coding_block_size_minus3", value, ps_bitstrm); 1549 ps_sps->i1_log2_min_pcm_coding_block_size = value + 3; 1550 1551 UEV_PARSE("log2_diff_max_min_pcm_coding_block_size", value, ps_bitstrm); 1552 ps_sps->i1_log2_diff_max_min_pcm_coding_block_size = value; 1553 BITS_PARSE("pcm_loop_filter_disable_flag", value, ps_bitstrm, 1); 1554 ps_sps->i1_pcm_loop_filter_disable_flag = value; 1555 1556 } 1557 UEV_PARSE("num_short_term_ref_pic_sets", value, ps_bitstrm); 1558 ps_sps->i1_num_short_term_ref_pic_sets = value; 1559 1560 ps_sps->i1_num_short_term_ref_pic_sets = CLIP3(ps_sps->i1_num_short_term_ref_pic_sets, 0, MAX_STREF_PICS_SPS); 1561 1562 for(i = 0; i < ps_sps->i1_num_short_term_ref_pic_sets; i++) 1563 ihevcd_short_term_ref_pic_set(ps_bitstrm, &ps_sps->as_stref_picset[0], ps_sps->i1_num_short_term_ref_pic_sets, i, &ps_sps->as_stref_picset[i]); 1564 1565 BITS_PARSE("long_term_ref_pics_present_flag", value, ps_bitstrm, 1); 1566 ps_sps->i1_long_term_ref_pics_present_flag = value; 1567 1568 if(ps_sps->i1_long_term_ref_pics_present_flag) 1569 { 1570 UEV_PARSE("num_long_term_ref_pics_sps", value, ps_bitstrm); 1571 ps_sps->i1_num_long_term_ref_pics_sps = value; 1572 1573 for(i = 0; i < ps_sps->i1_num_long_term_ref_pics_sps; i++) 1574 { 1575 BITS_PARSE("lt_ref_pic_poc_lsb_sps[ i ]", value, ps_bitstrm, ps_sps->i1_log2_max_pic_order_cnt_lsb); 1576 ps_sps->au2_lt_ref_pic_poc_lsb_sps[i] = value; 1577 1578 BITS_PARSE("used_by_curr_pic_lt_sps_flag[ i ]", value, ps_bitstrm, 1); 1579 ps_sps->ai1_used_by_curr_pic_lt_sps_flag[i] = value; 1580 } 1581 } 1582 1583 BITS_PARSE("sps_temporal_mvp_enable_flag", value, ps_bitstrm, 1); 1584 ps_sps->i1_sps_temporal_mvp_enable_flag = value; 1585 1586 /* Print matches HM 8-2 */ 1587 BITS_PARSE("sps_strong_intra_smoothing_enable_flag", value, ps_bitstrm, 1); 1588 ps_sps->i1_strong_intra_smoothing_enable_flag = value; 1589 1590 BITS_PARSE("vui_parameters_present_flag", value, ps_bitstrm, 1); 1591 ps_sps->i1_vui_parameters_present_flag = value; 1592 1593 if(ps_sps->i1_vui_parameters_present_flag) 1594 { 1595 ret = ihevcd_parse_vui_parameters(ps_bitstrm, 1596 &ps_sps->s_vui_parameters, 1597 ps_sps->i1_sps_max_sub_layers - 1); 1598 RETURN_IF((ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS), ret); 1599 } 1600 1601 BITS_PARSE("sps_extension_flag", value, ps_bitstrm, 1); 1602 1603 if((UWORD8 *)ps_bitstrm->pu4_buf > ps_bitstrm->pu1_buf_max) 1604 { 1605 return IHEVCD_INVALID_PARAMETER; 1606 } 1607 1608 { 1609 WORD32 numerator; 1610 WORD32 ceil_offset; 1611 1612 ceil_offset = (1 << ps_sps->i1_log2_ctb_size) - 1; 1613 numerator = ps_sps->i2_pic_width_in_luma_samples; 1614 1615 ps_sps->i2_pic_wd_in_ctb = ((numerator + ceil_offset) / 1616 (1 << ps_sps->i1_log2_ctb_size)); 1617 1618 numerator = ps_sps->i2_pic_height_in_luma_samples; 1619 ps_sps->i2_pic_ht_in_ctb = ((numerator + ceil_offset) / 1620 (1 << ps_sps->i1_log2_ctb_size)); 1621 1622 ps_sps->i4_pic_size_in_ctb = ps_sps->i2_pic_ht_in_ctb * 1623 ps_sps->i2_pic_wd_in_ctb; 1624 1625 if(0 == ps_codec->i4_sps_done) 1626 ps_codec->s_parse.i4_next_ctb_indx = ps_sps->i4_pic_size_in_ctb; 1627 1628 numerator = ps_sps->i2_pic_width_in_luma_samples; 1629 ps_sps->i2_pic_wd_in_min_cb = numerator / 1630 (1 << ps_sps->i1_log2_min_coding_block_size); 1631 1632 numerator = ps_sps->i2_pic_height_in_luma_samples; 1633 ps_sps->i2_pic_ht_in_min_cb = numerator / 1634 (1 << ps_sps->i1_log2_min_coding_block_size); 1635 } 1636 if((0 != ps_codec->u4_allocate_dynamic_done) && 1637 ((ps_codec->i4_wd != ps_sps->i2_pic_width_in_luma_samples) || 1638 (ps_codec->i4_ht != ps_sps->i2_pic_height_in_luma_samples))) 1639 { 1640 if(0 == ps_codec->i4_first_pic_done) 1641 { 1642 return IHEVCD_INVALID_PARAMETER; 1643 } 1644 ps_codec->i4_reset_flag = 1; 1645 return (IHEVCD_ERROR_T)IVD_RES_CHANGED; 1646 } 1647 1648 if((ps_sps->i2_pic_width_in_luma_samples > MAX_WD) || 1649 ((ps_sps->i2_pic_width_in_luma_samples * ps_sps->i2_pic_height_in_luma_samples) > 1650 (MAX_WD * MAX_HT))) 1651 { 1652 return (IHEVCD_ERROR_T)IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED; 1653 } 1654 1655 /* Update display width and display height */ 1656 { 1657 WORD32 disp_wd, disp_ht; 1658 WORD32 crop_unit_x, crop_unit_y; 1659 crop_unit_x = 1; 1660 crop_unit_y = 1; 1661 1662 if(CHROMA_FMT_IDC_YUV420 == ps_sps->i1_chroma_format_idc) 1663 { 1664 crop_unit_x = 2; 1665 crop_unit_y = 2; 1666 } 1667 1668 disp_wd = ps_sps->i2_pic_width_in_luma_samples; 1669 disp_wd -= ps_sps->i2_pic_crop_left_offset * crop_unit_x; 1670 disp_wd -= ps_sps->i2_pic_crop_right_offset * crop_unit_x; 1671 1672 1673 disp_ht = ps_sps->i2_pic_height_in_luma_samples; 1674 disp_ht -= ps_sps->i2_pic_crop_top_offset * crop_unit_y; 1675 disp_ht -= ps_sps->i2_pic_crop_bottom_offset * crop_unit_y; 1676 1677 if((0 >= disp_wd) || (0 >= disp_ht)) 1678 return IHEVCD_INVALID_PARAMETER; 1679 1680 ps_codec->i4_disp_wd = disp_wd; 1681 ps_codec->i4_disp_ht = disp_ht; 1682 1683 1684 ps_codec->i4_wd = ps_sps->i2_pic_width_in_luma_samples; 1685 ps_codec->i4_ht = ps_sps->i2_pic_height_in_luma_samples; 1686 1687 { 1688 WORD32 ref_strd; 1689 ref_strd = ALIGN32(ps_sps->i2_pic_width_in_luma_samples + PAD_WD); 1690 if(ps_codec->i4_strd < ref_strd) 1691 { 1692 ps_codec->i4_strd = ref_strd; 1693 } 1694 } 1695 1696 if(0 == ps_codec->i4_share_disp_buf) 1697 { 1698 if(ps_codec->i4_disp_strd < ps_codec->i4_disp_wd) 1699 { 1700 ps_codec->i4_disp_strd = ps_codec->i4_disp_wd; 1701 } 1702 } 1703 else 1704 { 1705 if(ps_codec->i4_disp_strd < ps_codec->i4_strd) 1706 { 1707 ps_codec->i4_disp_strd = ps_codec->i4_strd; 1708 } 1709 } 1710 } 1711 1712 ps_codec->i4_sps_done = 1; 1713 return ret; 1714 } 1715 1716 1717 void ihevcd_unmark_pps(codec_t *ps_codec, WORD32 sps_id) 1718 { 1719 WORD32 pps_id = 0; 1720 pps_t *ps_pps = ps_codec->ps_pps_base; 1721 1722 for(pps_id = 0; pps_id < MAX_PPS_CNT - 1; pps_id++, ps_pps++) 1723 { 1724 if((ps_pps->i1_pps_valid) && 1725 (ps_pps->i1_sps_id == sps_id)) 1726 ps_pps->i1_pps_valid = 0; 1727 } 1728 } 1729 1730 1731 void ihevcd_copy_sps(codec_t *ps_codec, WORD32 sps_id, WORD32 sps_id_ref) 1732 { 1733 sps_t *ps_sps, *ps_sps_ref; 1734 WORD16 *pi2_scaling_mat_backup; 1735 WORD32 scaling_mat_size; 1736 1737 SCALING_MAT_SIZE(scaling_mat_size); 1738 ps_sps_ref = ps_codec->ps_sps_base + sps_id_ref; 1739 ps_sps = ps_codec->ps_sps_base + sps_id; 1740 1741 if(ps_sps->i1_sps_valid) 1742 { 1743 if((ps_sps->i1_log2_ctb_size != ps_sps_ref->i1_log2_ctb_size) || 1744 (ps_sps->i2_pic_wd_in_ctb != ps_sps_ref->i2_pic_wd_in_ctb) || 1745 (ps_sps->i2_pic_ht_in_ctb != ps_sps_ref->i2_pic_ht_in_ctb)) 1746 { 1747 ihevcd_unmark_pps(ps_codec, sps_id); 1748 } 1749 } 1750 1751 pi2_scaling_mat_backup = ps_sps->pi2_scaling_mat; 1752 1753 memcpy(ps_sps, ps_sps_ref, sizeof(sps_t)); 1754 ps_sps->pi2_scaling_mat = pi2_scaling_mat_backup; 1755 memcpy(ps_sps->pi2_scaling_mat, ps_sps_ref->pi2_scaling_mat, scaling_mat_size * sizeof(WORD16)); 1756 ps_sps->i1_sps_valid = 1; 1757 1758 ps_codec->s_parse.ps_sps = ps_sps; 1759 } 1760 1761 1762 /** 1763 ******************************************************************************* 1764 * 1765 * @brief 1766 * Parses PPS (Picture Parameter Set) 1767 * 1768 * @par Description: 1769 * Parse Picture Parameter Set as per section Section: 7.3.2.3 1770 * The pps is written to a temporary buffer and copied later to the 1771 * appropriate location 1772 * 1773 * @param[in] ps_codec 1774 * Pointer to codec context 1775 * 1776 * @returns Error code from IHEVCD_ERROR_T 1777 * 1778 * @remarks 1779 * 1780 * 1781 ******************************************************************************* 1782 */ 1783 IHEVCD_ERROR_T ihevcd_parse_pps(codec_t *ps_codec) 1784 { 1785 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 1786 WORD32 value; 1787 WORD32 pps_id; 1788 1789 pps_t *ps_pps; 1790 sps_t *ps_sps; 1791 bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; 1792 1793 1794 if(0 == ps_codec->i4_sps_done) 1795 return IHEVCD_INVALID_HEADER; 1796 1797 UEV_PARSE("pic_parameter_set_id", value, ps_bitstrm); 1798 1799 pps_id = value; 1800 if((pps_id >= MAX_PPS_CNT) || (pps_id < 0)) 1801 { 1802 if(ps_codec->i4_pps_done) 1803 return IHEVCD_UNSUPPORTED_PPS_ID; 1804 else 1805 pps_id = 0; 1806 } 1807 1808 1809 ps_pps = (ps_codec->s_parse.ps_pps_base + MAX_PPS_CNT - 1); 1810 1811 ps_pps->i1_pps_id = pps_id; 1812 1813 UEV_PARSE("seq_parameter_set_id", value, ps_bitstrm); 1814 ps_pps->i1_sps_id = value; 1815 ps_pps->i1_sps_id = CLIP3(ps_pps->i1_sps_id, 0, MAX_SPS_CNT - 2); 1816 1817 ps_sps = (ps_codec->s_parse.ps_sps_base + ps_pps->i1_sps_id); 1818 1819 /* If the SPS that is being referred to has not been parsed, 1820 * copy an existing SPS to the current location */ 1821 if(0 == ps_sps->i1_sps_valid) 1822 { 1823 return IHEVCD_INVALID_HEADER; 1824 1825 /* 1826 sps_t *ps_sps_ref = ps_codec->ps_sps_base; 1827 while(0 == ps_sps_ref->i1_sps_valid) 1828 ps_sps_ref++; 1829 ihevcd_copy_sps(ps_codec, ps_pps->i1_sps_id, ps_sps_ref->i1_sps_id); 1830 */ 1831 } 1832 1833 BITS_PARSE("dependent_slices_enabled_flag", value, ps_bitstrm, 1); 1834 ps_pps->i1_dependent_slice_enabled_flag = value; 1835 1836 BITS_PARSE("output_flag_present_flag", value, ps_bitstrm, 1); 1837 ps_pps->i1_output_flag_present_flag = value; 1838 1839 BITS_PARSE("num_extra_slice_header_bits", value, ps_bitstrm, 3); 1840 ps_pps->i1_num_extra_slice_header_bits = value; 1841 1842 1843 BITS_PARSE("sign_data_hiding_flag", value, ps_bitstrm, 1); 1844 ps_pps->i1_sign_data_hiding_flag = value; 1845 1846 BITS_PARSE("cabac_init_present_flag", value, ps_bitstrm, 1); 1847 ps_pps->i1_cabac_init_present_flag = value; 1848 1849 UEV_PARSE("num_ref_idx_l0_default_active_minus1", value, ps_bitstrm); 1850 ps_pps->i1_num_ref_idx_l0_default_active = value + 1; 1851 1852 UEV_PARSE("num_ref_idx_l1_default_active_minus1", value, ps_bitstrm); 1853 ps_pps->i1_num_ref_idx_l1_default_active = value + 1; 1854 1855 SEV_PARSE("pic_init_qp_minus26", value, ps_bitstrm); 1856 ps_pps->i1_pic_init_qp = value + 26; 1857 1858 BITS_PARSE("constrained_intra_pred_flag", value, ps_bitstrm, 1); 1859 ps_pps->i1_constrained_intra_pred_flag = value; 1860 1861 BITS_PARSE("transform_skip_enabled_flag", value, ps_bitstrm, 1); 1862 ps_pps->i1_transform_skip_enabled_flag = value; 1863 1864 BITS_PARSE("cu_qp_delta_enabled_flag", value, ps_bitstrm, 1); 1865 ps_pps->i1_cu_qp_delta_enabled_flag = value; 1866 1867 if(ps_pps->i1_cu_qp_delta_enabled_flag) 1868 { 1869 UEV_PARSE("diff_cu_qp_delta_depth", value, ps_bitstrm); 1870 ps_pps->i1_diff_cu_qp_delta_depth = value; 1871 } 1872 else 1873 { 1874 ps_pps->i1_diff_cu_qp_delta_depth = 0; 1875 } 1876 ps_pps->i1_log2_min_cu_qp_delta_size = ps_sps->i1_log2_ctb_size - ps_pps->i1_diff_cu_qp_delta_depth; 1877 /* Print different */ 1878 SEV_PARSE("cb_qp_offset", value, ps_bitstrm); 1879 ps_pps->i1_pic_cb_qp_offset = value; 1880 1881 /* Print different */ 1882 SEV_PARSE("cr_qp_offset", value, ps_bitstrm); 1883 ps_pps->i1_pic_cr_qp_offset = value; 1884 1885 /* Print different */ 1886 BITS_PARSE("slicelevel_chroma_qp_flag", value, ps_bitstrm, 1); 1887 ps_pps->i1_pic_slice_level_chroma_qp_offsets_present_flag = value; 1888 1889 BITS_PARSE("weighted_pred_flag", value, ps_bitstrm, 1); 1890 ps_pps->i1_weighted_pred_flag = value; 1891 1892 BITS_PARSE("weighted_bipred_flag", value, ps_bitstrm, 1); 1893 ps_pps->i1_weighted_bipred_flag = value; 1894 1895 BITS_PARSE("transquant_bypass_enable_flag", value, ps_bitstrm, 1); 1896 ps_pps->i1_transquant_bypass_enable_flag = value; 1897 1898 BITS_PARSE("tiles_enabled_flag", value, ps_bitstrm, 1); 1899 ps_pps->i1_tiles_enabled_flag = value; 1900 1901 /* When tiles are enabled and width or height is >= 4096, 1902 * CTB Size should at least be 32. 16x16 CTBs can result 1903 * in tile position greater than 255 for 4096, 1904 * which decoder does not support. 1905 */ 1906 if((ps_pps->i1_tiles_enabled_flag) && 1907 (ps_sps->i1_log2_ctb_size == 4) && 1908 ((ps_sps->i2_pic_width_in_luma_samples >= 4096) || 1909 (ps_sps->i2_pic_height_in_luma_samples >= 4096))) 1910 { 1911 return IHEVCD_INVALID_HEADER; 1912 } 1913 1914 BITS_PARSE("entropy_coding_sync_enabled_flag", value, ps_bitstrm, 1); 1915 ps_pps->i1_entropy_coding_sync_enabled_flag = value; 1916 1917 ps_pps->i1_loop_filter_across_tiles_enabled_flag = 0; 1918 if(ps_pps->i1_tiles_enabled_flag) 1919 { 1920 WORD32 wd = ALIGN64(ps_codec->i4_wd); 1921 WORD32 ht = ALIGN64(ps_codec->i4_ht); 1922 1923 WORD32 max_tile_cols = (wd + MIN_TILE_WD - 1) / MIN_TILE_WD; 1924 WORD32 max_tile_rows = (ht + MIN_TILE_HT - 1) / MIN_TILE_HT; 1925 1926 UEV_PARSE("num_tile_columns_minus1", value, ps_bitstrm); 1927 ps_pps->i1_num_tile_columns = value + 1; 1928 1929 UEV_PARSE("num_tile_rows_minus1", value, ps_bitstrm); 1930 ps_pps->i1_num_tile_rows = value + 1; 1931 1932 if((ps_pps->i1_num_tile_columns < 1) || 1933 (ps_pps->i1_num_tile_columns > max_tile_cols) || 1934 (ps_pps->i1_num_tile_rows < 1) || 1935 (ps_pps->i1_num_tile_rows > max_tile_rows)) 1936 return IHEVCD_INVALID_HEADER; 1937 1938 BITS_PARSE("uniform_spacing_flag", value, ps_bitstrm, 1); 1939 ps_pps->i1_uniform_spacing_flag = value; 1940 1941 1942 { 1943 1944 WORD32 start; 1945 WORD32 i, j; 1946 1947 1948 start = 0; 1949 for(i = 0; i < ps_pps->i1_num_tile_columns; i++) 1950 { 1951 tile_t *ps_tile; 1952 if(!ps_pps->i1_uniform_spacing_flag) 1953 { 1954 if(i < (ps_pps->i1_num_tile_columns - 1)) 1955 { 1956 UEV_PARSE("column_width_minus1[ i ]", value, ps_bitstrm); 1957 value += 1; 1958 } 1959 else 1960 { 1961 value = ps_sps->i2_pic_wd_in_ctb - start; 1962 } 1963 } 1964 else 1965 { 1966 value = ((i + 1) * ps_sps->i2_pic_wd_in_ctb) / ps_pps->i1_num_tile_columns - 1967 (i * ps_sps->i2_pic_wd_in_ctb) / ps_pps->i1_num_tile_columns; 1968 } 1969 1970 for(j = 0; j < ps_pps->i1_num_tile_rows; j++) 1971 { 1972 ps_tile = ps_pps->ps_tile + j * ps_pps->i1_num_tile_columns + i; 1973 ps_tile->u1_pos_x = start; 1974 ps_tile->u2_wd = value; 1975 } 1976 start += value; 1977 1978 if((start > ps_sps->i2_pic_wd_in_ctb) || 1979 (value <= 0)) 1980 return IHEVCD_INVALID_HEADER; 1981 } 1982 1983 start = 0; 1984 for(i = 0; i < (ps_pps->i1_num_tile_rows); i++) 1985 { 1986 tile_t *ps_tile; 1987 if(!ps_pps->i1_uniform_spacing_flag) 1988 { 1989 if(i < (ps_pps->i1_num_tile_rows - 1)) 1990 { 1991 1992 UEV_PARSE("row_height_minus1[ i ]", value, ps_bitstrm); 1993 value += 1; 1994 } 1995 else 1996 { 1997 value = ps_sps->i2_pic_ht_in_ctb - start; 1998 } 1999 } 2000 else 2001 { 2002 value = ((i + 1) * ps_sps->i2_pic_ht_in_ctb) / ps_pps->i1_num_tile_rows - 2003 (i * ps_sps->i2_pic_ht_in_ctb) / ps_pps->i1_num_tile_rows; 2004 } 2005 2006 for(j = 0; j < ps_pps->i1_num_tile_columns; j++) 2007 { 2008 ps_tile = ps_pps->ps_tile + i * ps_pps->i1_num_tile_columns + j; 2009 ps_tile->u1_pos_y = start; 2010 ps_tile->u2_ht = value; 2011 } 2012 start += value; 2013 2014 if((start > ps_sps->i2_pic_ht_in_ctb) || 2015 (value <= 0)) 2016 return IHEVCD_INVALID_HEADER; 2017 } 2018 } 2019 2020 2021 BITS_PARSE("loop_filter_across_tiles_enabled_flag", value, ps_bitstrm, 1); 2022 ps_pps->i1_loop_filter_across_tiles_enabled_flag = value; 2023 2024 } 2025 else 2026 { 2027 /* If tiles are not present, set first tile in each PPS to have tile 2028 width and height equal to picture width and height */ 2029 ps_pps->i1_num_tile_columns = 1; 2030 ps_pps->i1_num_tile_rows = 1; 2031 ps_pps->i1_uniform_spacing_flag = 1; 2032 2033 ps_pps->ps_tile->u1_pos_x = 0; 2034 ps_pps->ps_tile->u1_pos_y = 0; 2035 ps_pps->ps_tile->u2_wd = ps_sps->i2_pic_wd_in_ctb; 2036 ps_pps->ps_tile->u2_ht = ps_sps->i2_pic_ht_in_ctb; 2037 } 2038 2039 BITS_PARSE("loop_filter_across_slices_enabled_flag", value, ps_bitstrm, 1); 2040 ps_pps->i1_loop_filter_across_slices_enabled_flag = value; 2041 2042 BITS_PARSE("deblocking_filter_control_present_flag", value, ps_bitstrm, 1); 2043 ps_pps->i1_deblocking_filter_control_present_flag = value; 2044 2045 /* Default values */ 2046 ps_pps->i1_pic_disable_deblocking_filter_flag = 0; 2047 ps_pps->i1_deblocking_filter_override_enabled_flag = 0; 2048 ps_pps->i1_beta_offset_div2 = 0; 2049 ps_pps->i1_tc_offset_div2 = 0; 2050 2051 if(ps_pps->i1_deblocking_filter_control_present_flag) 2052 { 2053 2054 BITS_PARSE("deblocking_filter_override_enabled_flag", value, ps_bitstrm, 1); 2055 ps_pps->i1_deblocking_filter_override_enabled_flag = value; 2056 2057 BITS_PARSE("pic_disable_deblocking_filter_flag", value, ps_bitstrm, 1); 2058 ps_pps->i1_pic_disable_deblocking_filter_flag = value; 2059 2060 if(!ps_pps->i1_pic_disable_deblocking_filter_flag) 2061 { 2062 2063 SEV_PARSE("pps_beta_offset_div2", value, ps_bitstrm); 2064 ps_pps->i1_beta_offset_div2 = value; 2065 2066 SEV_PARSE("pps_tc_offset_div2", value, ps_bitstrm); 2067 ps_pps->i1_tc_offset_div2 = value; 2068 2069 } 2070 } 2071 2072 BITS_PARSE("pps_scaling_list_data_present_flag", value, ps_bitstrm, 1); 2073 ps_pps->i1_pps_scaling_list_data_present_flag = value; 2074 2075 if(ps_pps->i1_pps_scaling_list_data_present_flag) 2076 { 2077 COPY_DEFAULT_SCALING_LIST(ps_pps->pi2_scaling_mat); 2078 ihevcd_scaling_list_data(ps_codec, ps_pps->pi2_scaling_mat); 2079 } 2080 2081 BITS_PARSE("lists_modification_present_flag", value, ps_bitstrm, 1); 2082 ps_pps->i1_lists_modification_present_flag = value; 2083 UEV_PARSE("log2_parallel_merge_level_minus2", value, ps_bitstrm); 2084 ps_pps->i1_log2_parallel_merge_level = value + 2; 2085 2086 BITS_PARSE("slice_header_extension_present_flag", value, ps_bitstrm, 1); 2087 ps_pps->i1_slice_header_extension_present_flag = value; 2088 /* Not present in HM */ 2089 BITS_PARSE("pps_extension_flag", value, ps_bitstrm, 1); 2090 2091 if((UWORD8 *)ps_bitstrm->pu4_buf > ps_bitstrm->pu1_buf_max) 2092 return IHEVCD_INVALID_PARAMETER; 2093 2094 ps_codec->i4_pps_done = 1; 2095 return ret; 2096 } 2097 2098 2099 void ihevcd_copy_pps(codec_t *ps_codec, WORD32 pps_id, WORD32 pps_id_ref) 2100 { 2101 pps_t *ps_pps, *ps_pps_ref; 2102 WORD16 *pi2_scaling_mat_backup; 2103 WORD32 scaling_mat_size; 2104 tile_t *ps_tile_backup; 2105 WORD32 max_tile_cols, max_tile_rows; 2106 WORD32 wd, ht; 2107 wd = ALIGN64(ps_codec->i4_wd); 2108 ht = ALIGN64(ps_codec->i4_ht); 2109 2110 SCALING_MAT_SIZE(scaling_mat_size); 2111 max_tile_cols = (wd + MIN_TILE_WD - 1) / MIN_TILE_WD; 2112 max_tile_rows = (ht + MIN_TILE_HT - 1) / MIN_TILE_HT; 2113 2114 ps_pps_ref = ps_codec->ps_pps_base + pps_id_ref; 2115 ps_pps = ps_codec->ps_pps_base + pps_id; 2116 2117 pi2_scaling_mat_backup = ps_pps->pi2_scaling_mat; 2118 ps_tile_backup = ps_pps->ps_tile; 2119 2120 memcpy(ps_pps, ps_pps_ref, sizeof(pps_t)); 2121 ps_pps->pi2_scaling_mat = pi2_scaling_mat_backup; 2122 ps_pps->ps_tile = ps_tile_backup; 2123 memcpy(ps_pps->pi2_scaling_mat, ps_pps_ref->pi2_scaling_mat, scaling_mat_size * sizeof(WORD16)); 2124 memcpy(ps_pps->ps_tile, ps_pps_ref->ps_tile, max_tile_cols * max_tile_rows * sizeof(tile_t)); 2125 2126 ps_pps->i1_pps_valid = 1; 2127 2128 ps_codec->s_parse.ps_pps = ps_pps; 2129 } 2130 2131 2132 IHEVCD_ERROR_T ihevcd_parse_buffering_period_sei(codec_t *ps_codec, 2133 sps_t *ps_sps) 2134 { 2135 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2136 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2137 UWORD32 value; 2138 vui_t *ps_vui; 2139 buf_period_sei_params_t *ps_buf_period_sei_params; 2140 UWORD32 i; 2141 hrd_params_t *ps_vui_hdr; 2142 UWORD32 u4_cpb_cnt; 2143 2144 ps_vui = &ps_sps->s_vui_parameters; 2145 ps_vui_hdr = &ps_vui->s_vui_hrd_parameters; 2146 2147 ps_buf_period_sei_params = &ps_parse->s_sei_params.s_buf_period_sei_params; 2148 2149 ps_parse->s_sei_params.i1_buf_period_params_present_flag = 1; 2150 2151 UEV_PARSE("bp_seq_parameter_set_id", value, ps_bitstrm); 2152 ps_buf_period_sei_params->u1_bp_seq_parameter_set_id = value; 2153 2154 if(!ps_vui_hdr->u1_sub_pic_cpb_params_present_flag) 2155 { 2156 BITS_PARSE("irap_cpb_params_present_flag", value, ps_bitstrm, 1); 2157 ps_buf_period_sei_params->u1_rap_cpb_params_present_flag = value; 2158 } 2159 2160 if(ps_buf_period_sei_params->u1_rap_cpb_params_present_flag) 2161 { 2162 BITS_PARSE("cpb_delay_offset", 2163 value, 2164 ps_bitstrm, 2165 (ps_vui_hdr->u1_au_cpb_removal_delay_length_minus1 2166 + 1)); 2167 ps_buf_period_sei_params->u4_cpb_delay_offset = value; 2168 2169 BITS_PARSE("dpb_delay_offset", 2170 value, 2171 ps_bitstrm, 2172 (ps_vui_hdr->u1_dpb_output_delay_length_minus1 2173 + 1)); 2174 ps_buf_period_sei_params->u4_dpb_delay_offset = value; 2175 } 2176 else 2177 { 2178 ps_buf_period_sei_params->u4_cpb_delay_offset = 0; 2179 ps_buf_period_sei_params->u4_dpb_delay_offset = 0; 2180 } 2181 2182 BITS_PARSE("concatenation_flag", value, ps_bitstrm, 1); 2183 ps_buf_period_sei_params->u1_concatenation_flag = value; 2184 2185 BITS_PARSE("au_cpb_removal_delay_delta_minus1", 2186 value, 2187 ps_bitstrm, 2188 (ps_vui_hdr->u1_au_cpb_removal_delay_length_minus1 2189 + 1)); 2190 ps_buf_period_sei_params->u4_au_cpb_removal_delay_delta_minus1 = value; 2191 2192 if(ps_vui_hdr->u1_nal_hrd_parameters_present_flag) 2193 { 2194 u4_cpb_cnt = ps_vui_hdr->au1_cpb_cnt_minus1[0]; 2195 2196 for(i = 0; i <= u4_cpb_cnt; i++) 2197 { 2198 BITS_PARSE("nal_initial_cpb_removal_delay[i]", 2199 value, 2200 ps_bitstrm, 2201 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2202 + 1)); 2203 ps_buf_period_sei_params->au4_nal_initial_cpb_removal_delay[i] = 2204 value; 2205 2206 BITS_PARSE("nal_initial_cpb_removal_delay_offset", 2207 value, 2208 ps_bitstrm, 2209 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2210 + 1)); 2211 ps_buf_period_sei_params->au4_nal_initial_cpb_removal_delay_offset[i] = 2212 value; 2213 2214 if(ps_vui_hdr->u1_sub_pic_cpb_params_present_flag 2215 || ps_buf_period_sei_params->u1_rap_cpb_params_present_flag) 2216 { 2217 BITS_PARSE("nal_initial_alt_cpb_removal_delay[i]", 2218 value, 2219 ps_bitstrm, 2220 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2221 + 1)); 2222 ps_buf_period_sei_params->au4_nal_initial_alt_cpb_removal_delay[i] = 2223 value; 2224 2225 BITS_PARSE("nal_initial_alt_cpb_removal_delay_offset", 2226 value, 2227 ps_bitstrm, 2228 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2229 + 1)); 2230 ps_buf_period_sei_params->au4_nal_initial_alt_cpb_removal_delay_offset[i] = 2231 value; 2232 } 2233 } 2234 } 2235 2236 if(ps_vui_hdr->u1_vcl_hrd_parameters_present_flag) 2237 { 2238 u4_cpb_cnt = ps_vui_hdr->au1_cpb_cnt_minus1[0]; 2239 2240 for(i = 0; i <= u4_cpb_cnt; i++) 2241 { 2242 BITS_PARSE("vcl_initial_cpb_removal_delay[i]", 2243 value, 2244 ps_bitstrm, 2245 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2246 + 1)); 2247 ps_buf_period_sei_params->au4_vcl_initial_cpb_removal_delay[i] = 2248 value; 2249 2250 BITS_PARSE("vcl_initial_cpb_removal_delay_offset", 2251 value, 2252 ps_bitstrm, 2253 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2254 + 1)); 2255 ps_buf_period_sei_params->au4_vcl_initial_cpb_removal_delay_offset[i] = 2256 value; 2257 2258 if(ps_vui_hdr->u1_sub_pic_cpb_params_present_flag 2259 || ps_buf_period_sei_params->u1_rap_cpb_params_present_flag) 2260 { 2261 BITS_PARSE("vcl_initial_alt_cpb_removal_delay[i]", 2262 value, 2263 ps_bitstrm, 2264 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2265 + 1)); 2266 ps_buf_period_sei_params->au4_vcl_initial_alt_cpb_removal_delay[i] = 2267 value; 2268 2269 BITS_PARSE("vcl_initial_alt_cpb_removal_delay_offset", 2270 value, 2271 ps_bitstrm, 2272 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2273 + 1)); 2274 ps_buf_period_sei_params->au4_vcl_initial_alt_cpb_removal_delay_offset[i] = 2275 value; 2276 } 2277 } 2278 } 2279 2280 return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2281 } 2282 2283 IHEVCD_ERROR_T ihevcd_parse_pic_timing_sei(codec_t *ps_codec, sps_t *ps_sps) 2284 { 2285 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2286 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2287 UWORD32 value; 2288 vui_t *ps_vui; 2289 UWORD32 i; 2290 hrd_params_t *ps_vui_hdr; 2291 UWORD32 u4_cpb_dpb_delays_present_flag = 0; 2292 pic_timing_sei_params_t *ps_pic_timing; 2293 2294 ps_pic_timing = &ps_parse->s_sei_params.s_pic_timing_sei_params; 2295 ps_vui = &ps_sps->s_vui_parameters; 2296 ps_vui_hdr = &ps_vui->s_vui_hrd_parameters; 2297 ps_parse->s_sei_params.i1_pic_timing_params_present_flag = 1; 2298 if(ps_vui->u1_frame_field_info_present_flag) 2299 { 2300 BITS_PARSE("pic_struct", value, ps_bitstrm, 4); 2301 ps_pic_timing->u4_pic_struct = value; 2302 2303 BITS_PARSE("source_scan_type", value, ps_bitstrm, 2); 2304 ps_pic_timing->u4_source_scan_type = value; 2305 2306 BITS_PARSE("duplicate_flag", value, ps_bitstrm, 1); 2307 ps_pic_timing->u1_duplicate_flag = value; 2308 } 2309 2310 if(ps_vui_hdr->u1_nal_hrd_parameters_present_flag 2311 || ps_vui_hdr->u1_vcl_hrd_parameters_present_flag) 2312 { 2313 u4_cpb_dpb_delays_present_flag = 1; 2314 } 2315 else 2316 { 2317 u4_cpb_dpb_delays_present_flag = 0; 2318 } 2319 2320 if(u4_cpb_dpb_delays_present_flag) 2321 { 2322 BITS_PARSE("au_cpb_removal_delay_minus1", value, ps_bitstrm, 2323 (ps_vui_hdr->u1_au_cpb_removal_delay_length_minus1 + 1)); 2324 ps_pic_timing->u4_au_cpb_removal_delay_minus1 = value; 2325 2326 BITS_PARSE("pic_dpb_output_delay", value, ps_bitstrm, 2327 (ps_vui_hdr->u1_dpb_output_delay_length_minus1 + 1)); 2328 ps_pic_timing->u4_pic_dpb_output_delay = value; 2329 2330 if(ps_vui_hdr->u1_sub_pic_cpb_params_present_flag) 2331 { 2332 BITS_PARSE("pic_dpb_output_du_delay", value, ps_bitstrm, 2333 (ps_vui_hdr->u1_dpb_output_delay_du_length_minus1 + 1)); 2334 ps_pic_timing->u4_pic_dpb_output_du_delay = value; 2335 } 2336 2337 if(ps_vui_hdr->u1_sub_pic_cpb_params_present_flag 2338 && ps_vui_hdr->u1_sub_pic_cpb_params_in_pic_timing_sei_flag) 2339 { 2340 UWORD32 num_units_minus1; 2341 UWORD32 array_size; 2342 2343 UEV_PARSE("num_decoding_units_minus1", value, ps_bitstrm); 2344 ps_pic_timing->u4_num_decoding_units_minus1 = value; 2345 2346 num_units_minus1 = ps_pic_timing->u4_num_decoding_units_minus1; 2347 array_size = (sizeof(ps_pic_timing->au4_num_nalus_in_du_minus1) 2348 / sizeof(ps_pic_timing->au4_num_nalus_in_du_minus1[0])); 2349 num_units_minus1 = CLIP3(num_units_minus1, 0,(array_size - 1)); 2350 ps_pic_timing->u4_num_decoding_units_minus1 = num_units_minus1; 2351 2352 BITS_PARSE("du_common_cpb_removal_delay_flag", value, ps_bitstrm, 1); 2353 ps_pic_timing->u1_du_common_cpb_removal_delay_flag = value; 2354 2355 if(ps_pic_timing->u1_du_common_cpb_removal_delay_flag) 2356 { 2357 BITS_PARSE("du_common_cpb_removal_delay_increment_minus1", 2358 value, 2359 ps_bitstrm, 2360 (ps_vui_hdr->u1_du_cpb_removal_delay_increment_length_minus1 2361 + 1)); 2362 ps_pic_timing->u4_du_common_cpb_removal_delay_increment_minus1 = 2363 value; 2364 } 2365 2366 for(i = 0; i <= ps_pic_timing->u4_num_decoding_units_minus1; i++) 2367 { 2368 UEV_PARSE("num_nalus_in_du_minus1", value, ps_bitstrm); 2369 ps_pic_timing->au4_num_nalus_in_du_minus1[i] = value; 2370 2371 if((!ps_pic_timing->u1_du_common_cpb_removal_delay_flag) 2372 && (i < ps_pic_timing->u4_num_decoding_units_minus1)) 2373 { 2374 BITS_PARSE("du_common_cpb_removal_delay_increment_minus1", 2375 value, 2376 ps_bitstrm, 2377 (ps_vui_hdr->u1_du_cpb_removal_delay_increment_length_minus1 2378 + 1)); 2379 ps_pic_timing->au4_du_cpb_removal_delay_increment_minus1[i] = 2380 value; 2381 } 2382 } 2383 } 2384 } 2385 2386 return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2387 } 2388 2389 IHEVCD_ERROR_T ihevcd_parse_time_code_sei(codec_t *ps_codec) 2390 { 2391 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2392 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2393 UWORD32 value; 2394 time_code_t *ps_time_code; 2395 WORD32 i; 2396 2397 ps_parse->s_sei_params.i1_time_code_present_flag = 1; 2398 ps_time_code = &ps_parse->s_sei_params.s_time_code; 2399 2400 BITS_PARSE("num_clock_ts", value, ps_bitstrm, 2); 2401 ps_time_code->u1_num_clock_ts = value; 2402 2403 for(i = 0; i < ps_time_code->u1_num_clock_ts; i++) 2404 { 2405 BITS_PARSE("clock_timestamp_flag[i]", value, ps_bitstrm, 1); 2406 ps_time_code->au1_clock_timestamp_flag[i] = value; 2407 2408 if(ps_time_code->au1_clock_timestamp_flag[i]) 2409 { 2410 BITS_PARSE("units_field_based_flag[i]", value, ps_bitstrm, 1); 2411 ps_time_code->au1_units_field_based_flag[i] = value; 2412 2413 BITS_PARSE("counting_type[i]", value, ps_bitstrm, 5); 2414 ps_time_code->au1_counting_type[i] = value; 2415 2416 BITS_PARSE("full_timestamp_flag[i]", value, ps_bitstrm, 1); 2417 ps_time_code->au1_full_timestamp_flag[i] = value; 2418 2419 BITS_PARSE("discontinuity_flag[i]", value, ps_bitstrm, 1); 2420 ps_time_code->au1_discontinuity_flag[i] = value; 2421 2422 BITS_PARSE("cnt_dropped_flag[i]", value, ps_bitstrm, 1); 2423 ps_time_code->au1_cnt_dropped_flag[i] = value; 2424 2425 BITS_PARSE("n_frames[i]", value, ps_bitstrm, 9); 2426 ps_time_code->au2_n_frames[i] = value; 2427 2428 if(ps_time_code->au1_full_timestamp_flag[i]) 2429 { 2430 BITS_PARSE("seconds_value[i]", value, ps_bitstrm, 6); 2431 ps_time_code->au1_seconds_value[i] = value; 2432 2433 BITS_PARSE("minutes_value[i]", value, ps_bitstrm, 6); 2434 ps_time_code->au1_minutes_value[i] = value; 2435 2436 BITS_PARSE("hours_value[i]", value, ps_bitstrm, 5); 2437 ps_time_code->au1_hours_value[i] = value; 2438 } 2439 else 2440 { 2441 BITS_PARSE("seconds_flag[i]", value, ps_bitstrm, 1); 2442 ps_time_code->au1_seconds_flag[i] = value; 2443 2444 if(ps_time_code->au1_seconds_flag[i]) 2445 { 2446 BITS_PARSE("seconds_value[i]", value, ps_bitstrm, 6); 2447 ps_time_code->au1_seconds_value[i] = value; 2448 2449 BITS_PARSE("minutes_flag[i]", value, ps_bitstrm, 1); 2450 ps_time_code->au1_minutes_flag[i] = value; 2451 2452 if(ps_time_code->au1_minutes_flag[i]) 2453 { 2454 BITS_PARSE("minutes_value[i]", value, ps_bitstrm, 6); 2455 ps_time_code->au1_minutes_value[i] = value; 2456 2457 BITS_PARSE("hours_flag[i]", value, ps_bitstrm, 1); 2458 ps_time_code->au1_hours_flag[i] = value; 2459 2460 if(ps_time_code->au1_hours_flag[i]) 2461 { 2462 BITS_PARSE("hours_value[i]", value, ps_bitstrm, 5); 2463 ps_time_code->au1_hours_value[i] = value; 2464 } 2465 } 2466 } 2467 } 2468 2469 BITS_PARSE("time_offset_length[i]", value, ps_bitstrm, 5); 2470 ps_time_code->au1_time_offset_length[i] = value; 2471 2472 if(ps_time_code->au1_time_offset_length[i] > 0) 2473 { 2474 BITS_PARSE("time_offset_value[i]", value, ps_bitstrm, 2475 ps_time_code->au1_time_offset_length[i]); 2476 ps_time_code->au1_time_offset_value[i] = value; 2477 } 2478 else 2479 { 2480 ps_time_code->au1_time_offset_value[i] = 0; 2481 } 2482 } 2483 } 2484 2485 return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2486 } 2487 2488 IHEVCD_ERROR_T ihevcd_parse_mastering_disp_params_sei(codec_t *ps_codec) 2489 { 2490 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2491 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2492 UWORD32 value; 2493 mastering_dis_col_vol_sei_params_t *ps_mastering_dis_col_vol; 2494 WORD32 i; 2495 2496 ps_parse->s_sei_params.i4_sei_mastering_disp_colour_vol_params_present_flags = 1; 2497 2498 ps_mastering_dis_col_vol = &ps_parse->s_sei_params.s_mastering_dis_col_vol_sei_params; 2499 2500 for(i = 0; i < 3; i++) 2501 { 2502 BITS_PARSE("display_primaries_x[c]", value, ps_bitstrm, 16); 2503 ps_mastering_dis_col_vol->au2_display_primaries_x[i] = value; 2504 2505 BITS_PARSE("display_primaries_y[c]", value, ps_bitstrm, 16); 2506 ps_mastering_dis_col_vol->au2_display_primaries_y[i] = value; 2507 } 2508 2509 BITS_PARSE("white_point_x", value, ps_bitstrm, 16); 2510 ps_mastering_dis_col_vol->u2_white_point_x = value; 2511 2512 BITS_PARSE("white_point_y", value, ps_bitstrm, 16); 2513 ps_mastering_dis_col_vol->u2_white_point_y = value; 2514 2515 BITS_PARSE("max_display_mastering_luminance", value, ps_bitstrm, 32); 2516 ps_mastering_dis_col_vol->u4_max_display_mastering_luminance = value; 2517 2518 BITS_PARSE("min_display_mastering_luminance", value, ps_bitstrm, 32); 2519 ps_mastering_dis_col_vol->u4_min_display_mastering_luminance = value; 2520 2521 return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2522 } 2523 2524 IHEVCD_ERROR_T ihevcd_parse_user_data_registered_itu_t_t35(codec_t *ps_codec, 2525 UWORD32 u4_payload_size) 2526 { 2527 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2528 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2529 UWORD32 value; 2530 user_data_registered_itu_t_t35_t *ps_user_data_registered_itu_t_t35; 2531 UWORD32 i; 2532 UWORD32 j = 0; 2533 2534 ps_parse->s_sei_params.i1_user_data_registered_present_flag = 1; 2535 ps_user_data_registered_itu_t_t35 = 2536 &ps_parse->s_sei_params.as_user_data_registered_itu_t_t35[ps_parse->s_sei_params.i4_sei_user_data_cnt]; 2537 ps_parse->s_sei_params.i4_sei_user_data_cnt++; 2538 2539 ps_user_data_registered_itu_t_t35->i4_payload_size = u4_payload_size; 2540 2541 if(u4_payload_size > MAX_USERDATA_PAYLOAD) 2542 { 2543 u4_payload_size = MAX_USERDATA_PAYLOAD; 2544 } 2545 2546 ps_user_data_registered_itu_t_t35->i4_valid_payload_size = u4_payload_size; 2547 2548 BITS_PARSE("itu_t_t35_country_code", value, ps_bitstrm, 8); 2549 ps_user_data_registered_itu_t_t35->u1_itu_t_t35_country_code = value; 2550 2551 if(0xFF != ps_user_data_registered_itu_t_t35->u1_itu_t_t35_country_code) 2552 { 2553 i = 1; 2554 } 2555 else 2556 { 2557 BITS_PARSE("itu_t_t35_country_code_extension_byte", value, ps_bitstrm, 2558 8); 2559 ps_user_data_registered_itu_t_t35->u1_itu_t_t35_country_code_extension_byte = 2560 value; 2561 2562 i = 2; 2563 } 2564 2565 do 2566 { 2567 BITS_PARSE("itu_t_t35_payload_byte", value, ps_bitstrm, 8); 2568 ps_user_data_registered_itu_t_t35->u1_itu_t_t35_payload_byte[j++] = 2569 value; 2570 2571 i++; 2572 }while(i < u4_payload_size); 2573 2574 return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2575 } 2576 2577 void ihevcd_parse_sei_payload(codec_t *ps_codec, 2578 UWORD32 u4_payload_type, 2579 UWORD32 u4_payload_size, 2580 WORD8 i1_nal_type) 2581 { 2582 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2583 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2584 WORD32 payload_bits_remaining = 0; 2585 sps_t *ps_sps; 2586 2587 UWORD32 i; 2588 2589 for(i = 0; i < MAX_SPS_CNT; i++) 2590 { 2591 ps_sps = ps_codec->ps_sps_base + i; 2592 if(ps_sps->i1_sps_valid) 2593 { 2594 break; 2595 } 2596 } 2597 if(NULL == ps_sps) 2598 { 2599 return; 2600 } 2601 2602 if(NAL_PREFIX_SEI == i1_nal_type) 2603 { 2604 switch(u4_payload_type) 2605 { 2606 case SEI_BUFFERING_PERIOD: 2607 ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; 2608 ihevcd_parse_buffering_period_sei(ps_codec, ps_sps); 2609 break; 2610 2611 case SEI_PICTURE_TIMING: 2612 ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; 2613 ihevcd_parse_pic_timing_sei(ps_codec, ps_sps); 2614 break; 2615 2616 case SEI_TIME_CODE: 2617 ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; 2618 ihevcd_parse_time_code_sei(ps_codec); 2619 break; 2620 2621 case SEI_MASTERING_DISPLAY_COLOUR_VOLUME: 2622 ps_parse->s_sei_params.i4_sei_mastering_disp_colour_vol_params_present_flags = 1; 2623 ihevcd_parse_mastering_disp_params_sei(ps_codec); 2624 break; 2625 2626 case SEI_USER_DATA_REGISTERED_ITU_T_T35: 2627 ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; 2628 if(ps_parse->s_sei_params.i4_sei_user_data_cnt >= USER_DATA_MAX) 2629 { 2630 for(i = 0; i < u4_payload_size / 4; i++) 2631 { 2632 ihevcd_bits_flush(ps_bitstrm, 4 * 8); 2633 } 2634 2635 ihevcd_bits_flush(ps_bitstrm, (u4_payload_size - i * 4) * 8); 2636 } 2637 else 2638 { 2639 ihevcd_parse_user_data_registered_itu_t_t35(ps_codec, 2640 u4_payload_size); 2641 } 2642 break; 2643 2644 default: 2645 for(i = 0; i < u4_payload_size; i++) 2646 { 2647 ihevcd_bits_flush(ps_bitstrm, 8); 2648 } 2649 break; 2650 } 2651 } 2652 else /* NAL_SUFFIX_SEI */ 2653 { 2654 switch(u4_payload_type) 2655 { 2656 case SEI_USER_DATA_REGISTERED_ITU_T_T35: 2657 ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; 2658 if(ps_parse->s_sei_params.i4_sei_user_data_cnt >= USER_DATA_MAX) 2659 { 2660 for(i = 0; i < u4_payload_size / 4; i++) 2661 { 2662 ihevcd_bits_flush(ps_bitstrm, 4 * 8); 2663 } 2664 2665 ihevcd_bits_flush(ps_bitstrm, (u4_payload_size - i * 4) * 8); 2666 } 2667 else 2668 { 2669 ihevcd_parse_user_data_registered_itu_t_t35(ps_codec, 2670 u4_payload_size); 2671 } 2672 break; 2673 2674 default: 2675 for(i = 0; i < u4_payload_size; i++) 2676 { 2677 ihevcd_bits_flush(ps_bitstrm, 8); 2678 } 2679 break; 2680 } 2681 } 2682 2683 /** 2684 * By definition the underlying bitstream terminates in a byte-aligned manner. 2685 * 1. Extract all bar the last MIN(bitsremaining,nine) bits as reserved_payload_extension_data 2686 * 2. Examine the final 8 bits to determine the payload_bit_equal_to_one marker 2687 * 3. Extract the remainingreserved_payload_extension_data bits. 2688 * 2689 * If there are fewer than 9 bits available, extract them. 2690 */ 2691 2692 payload_bits_remaining = ihevcd_bits_num_bits_remaining(ps_bitstrm); 2693 if(payload_bits_remaining) /* more_data_in_payload() */ 2694 { 2695 WORD32 final_bits; 2696 WORD32 final_payload_bits = 0; 2697 WORD32 mask = 0xFF; 2698 UWORD32 u4_dummy; 2699 UWORD32 u4_reserved_payload_extension_data; 2700 UNUSED(u4_dummy); 2701 UNUSED(u4_reserved_payload_extension_data); 2702 2703 while(payload_bits_remaining > 9) 2704 { 2705 BITS_PARSE("reserved_payload_extension_data", 2706 u4_reserved_payload_extension_data, ps_bitstrm, 1); 2707 payload_bits_remaining--; 2708 } 2709 2710 final_bits = ihevcd_bits_nxt(ps_bitstrm, payload_bits_remaining); 2711 2712 while(final_bits & (mask >> final_payload_bits)) 2713 { 2714 final_payload_bits++; 2715 continue; 2716 } 2717 2718 while(payload_bits_remaining > (9 - final_payload_bits)) 2719 { 2720 BITS_PARSE("reserved_payload_extension_data", 2721 u4_reserved_payload_extension_data, ps_bitstrm, 1); 2722 payload_bits_remaining--; 2723 } 2724 2725 BITS_PARSE("payload_bit_equal_to_one", u4_dummy, ps_bitstrm, 1); 2726 payload_bits_remaining--; 2727 while(payload_bits_remaining) 2728 { 2729 BITS_PARSE("payload_bit_equal_to_zero", u4_dummy, ps_bitstrm, 1); 2730 payload_bits_remaining--; 2731 } 2732 } 2733 2734 return; 2735 } 2736 2737 IHEVCD_ERROR_T ihevcd_read_rbsp_trailing_bits(codec_t *ps_codec, 2738 UWORD32 u4_bits_left) 2739 { 2740 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2741 UWORD32 value; 2742 WORD32 cnt = 0; 2743 BITS_PARSE("rbsp_stop_one_bit", value, &ps_parse->s_bitstrm, 1); 2744 u4_bits_left--; 2745 if(value != 1) 2746 { 2747 return (IHEVCD_ERROR_T)IHEVCD_FAIL; 2748 } 2749 while(u4_bits_left) 2750 { 2751 BITS_PARSE("rbsp_alignment_zero_bit", value, &ps_parse->s_bitstrm, 1); 2752 u4_bits_left--; 2753 cnt++; 2754 } 2755 ASSERT(cnt < 8); 2756 2757 return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2758 } 2759 /** 2760 ******************************************************************************* 2761 * 2762 * @brief 2763 * Parses SEI (Supplemental Enhancement Information) 2764 * 2765 * @par Description: 2766 * Parses SEI (Supplemental Enhancement Information) as per Section: 7.3.7 2767 * 2768 * @param[in] ps_codec 2769 * Pointer to codec context 2770 * 2771 * @returns Error code from IHEVCD_ERROR_T 2772 * 2773 * @remarks 2774 * 2775 * 2776 ******************************************************************************* 2777 */ 2778 IHEVCD_ERROR_T ihevcd_parse_sei(codec_t *ps_codec, nal_header_t *ps_nal) 2779 { 2780 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2781 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2782 UWORD32 u4_payload_type = 0, u4_last_payload_type_byte = 0; 2783 UWORD32 u4_payload_size = 0, u4_last_payload_size_byte = 0; 2784 UWORD32 value; 2785 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2786 UWORD32 u4_bits_left; 2787 2788 u4_bits_left = ihevcd_bits_num_bits_remaining(ps_bitstrm); 2789 2790 while(u4_bits_left > 8) 2791 { 2792 while(ihevcd_bits_nxt(ps_bitstrm, 8) == 0xFF) 2793 { 2794 ihevcd_bits_flush(ps_bitstrm, 8); /* equal to 0xFF */ 2795 u4_payload_type += 255; 2796 } 2797 2798 BITS_PARSE("last_payload_type_byte", value, ps_bitstrm, 8); 2799 u4_last_payload_type_byte = value; 2800 2801 u4_payload_type += u4_last_payload_type_byte; 2802 2803 while(ihevcd_bits_nxt(ps_bitstrm, 8) == 0xFF) 2804 { 2805 ihevcd_bits_flush(ps_bitstrm, 8); /* equal to 0xFF */ 2806 u4_payload_size += 255; 2807 } 2808 2809 BITS_PARSE("last_payload_size_byte", value, ps_bitstrm, 8); 2810 u4_last_payload_size_byte = value; 2811 2812 u4_payload_size += u4_last_payload_size_byte; 2813 u4_bits_left = ihevcd_bits_num_bits_remaining(ps_bitstrm); 2814 u4_payload_size = MIN(u4_payload_size, u4_bits_left / 8); 2815 ihevcd_parse_sei_payload(ps_codec, u4_payload_type, u4_payload_size, 2816 ps_nal->i1_nal_unit_type); 2817 2818 /* Calculate the bits left in the current payload */ 2819 u4_bits_left = ihevcd_bits_num_bits_remaining(ps_bitstrm); 2820 } 2821 2822 // read rbsp_trailing_bits 2823 if(u4_bits_left) 2824 { 2825 ihevcd_read_rbsp_trailing_bits(ps_codec, u4_bits_left); 2826 } 2827 2828 return ret; 2829 } 2830 2831 /** 2832 ******************************************************************************* 2833 * 2834 * @brief 2835 * Parses Access unit delimiter 2836 * 2837 * @par Description: 2838 * Parses Access unit delimiter as per section Section: 7.3.2.5 2839 * 2840 * @param[in] ps_codec 2841 * Pointer to codec context 2842 * 2843 * @returns Error code from IHEVCD_ERROR_T 2844 * 2845 * @remarks 2846 * 2847 * 2848 ******************************************************************************* 2849 */ 2850 WORD32 ihevcd_parse_aud(codec_t *ps_codec) 2851 { 2852 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2853 UNUSED(ps_codec); 2854 return ret; 2855 } 2856 2857 WORD32 ihevcd_extend_sign_bit(WORD32 value, WORD32 num_bits) 2858 { 2859 WORD32 ret_value = value; 2860 if(value >> (num_bits - 1)) 2861 { 2862 ret_value |= (0xFFFFFFFF << num_bits); 2863 } 2864 return ret_value; 2865 } 2866 2867 /** 2868 ******************************************************************************* 2869 * 2870 * @brief 2871 * Calculate POC of the current slice 2872 * 2873 * @par Description: 2874 * Calculates the current POC using the previous POC lsb and previous POC msb 2875 * 2876 * @param[in] ps_codec 2877 * Pointer to codec context 2878 * 2879 * @param[in] i1_pic_order_cnt_lsb 2880 * Current POC lsb 2881 * 2882 * @returns Current absolute POC 2883 * 2884 * @remarks 2885 * 2886 * 2887 ******************************************************************************* 2888 */ 2889 2890 WORD32 ihevcd_calc_poc(codec_t *ps_codec, nal_header_t *ps_nal, WORD8 i1_log2_max_poc_lsb, WORD32 i2_poc_lsb) 2891 { 2892 WORD32 i4_abs_poc, i4_poc_msb; 2893 WORD32 max_poc_lsb; 2894 WORD8 i1_nal_unit_type = ps_nal->i1_nal_unit_type; 2895 max_poc_lsb = (1 << i1_log2_max_poc_lsb); 2896 2897 if((!ps_codec->i4_first_pic_done) && (!ps_codec->i4_pic_present)) 2898 ps_codec->i4_prev_poc_msb = -2 * max_poc_lsb; 2899 2900 if(NAL_IDR_N_LP == i1_nal_unit_type 2901 || NAL_IDR_W_LP == i1_nal_unit_type 2902 || NAL_BLA_N_LP == i1_nal_unit_type 2903 || NAL_BLA_W_DLP == i1_nal_unit_type 2904 || NAL_BLA_W_LP == i1_nal_unit_type 2905 || (NAL_CRA == i1_nal_unit_type && !ps_codec->i4_first_pic_done)) 2906 { 2907 i4_poc_msb = ps_codec->i4_prev_poc_msb + 2 * max_poc_lsb; 2908 ps_codec->i4_prev_poc_lsb = 0; 2909 ps_codec->i4_max_prev_poc_lsb = 0; 2910 // ps_codec->i4_prev_poc_msb = 0; 2911 } 2912 else 2913 { 2914 2915 if((i2_poc_lsb < ps_codec->i4_prev_poc_lsb) 2916 && ((ps_codec->i4_prev_poc_lsb - i2_poc_lsb) >= max_poc_lsb / 2)) 2917 { 2918 i4_poc_msb = ps_codec->i4_prev_poc_msb + max_poc_lsb; 2919 } 2920 else if((i2_poc_lsb > ps_codec->i4_prev_poc_lsb) 2921 && ((i2_poc_lsb - ps_codec->i4_prev_poc_lsb) > max_poc_lsb / 2)) 2922 { 2923 i4_poc_msb = ps_codec->i4_prev_poc_msb - max_poc_lsb; 2924 } 2925 else 2926 { 2927 i4_poc_msb = ps_codec->i4_prev_poc_msb; 2928 } 2929 2930 2931 } 2932 2933 i4_abs_poc = i4_poc_msb + i2_poc_lsb; 2934 ps_codec->i4_max_prev_poc_lsb = MAX(ps_codec->i4_max_prev_poc_lsb, i2_poc_lsb); 2935 2936 { 2937 WORD32 is_reference_nal = ((i1_nal_unit_type <= NAL_RSV_VCL_R15) && (i1_nal_unit_type % 2 != 0)) || ((i1_nal_unit_type >= NAL_BLA_W_LP) && (i1_nal_unit_type <= NAL_RSV_RAP_VCL23)); 2938 WORD32 update_prev_poc = ((is_reference_nal) && ((i1_nal_unit_type < NAL_RADL_N) || (i1_nal_unit_type > NAL_RASL_R))); 2939 2940 if((0 == ps_nal->i1_nuh_temporal_id) && 2941 (update_prev_poc)) 2942 { 2943 ps_codec->i4_prev_poc_lsb = i2_poc_lsb; 2944 ps_codec->i4_prev_poc_msb = i4_poc_msb; 2945 } 2946 } 2947 2948 return i4_abs_poc; 2949 } 2950 2951 2952 void ihevcd_copy_slice_hdr(codec_t *ps_codec, WORD32 slice_idx, WORD32 slice_idx_ref) 2953 { 2954 slice_header_t *ps_slice_hdr, *ps_slice_hdr_ref; 2955 WORD32 *pu4_entry_offset_backup; 2956 2957 ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr_base + slice_idx; 2958 ps_slice_hdr_ref = ps_codec->s_parse.ps_slice_hdr_base + slice_idx_ref; 2959 2960 pu4_entry_offset_backup = ps_slice_hdr->pu4_entry_point_offset; 2961 memcpy(ps_slice_hdr, ps_slice_hdr_ref, sizeof(slice_header_t)); 2962 ps_slice_hdr->pu4_entry_point_offset = pu4_entry_offset_backup; 2963 } 2964 2965 2966 2967