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 1322 memcpy(&ps_sps->s_ptl, &s_ptl, sizeof(profile_tier_lvl_info_t)); 1323 1324 UEV_PARSE("chroma_format_idc", value, ps_bitstrm); 1325 ps_sps->i1_chroma_format_idc = value; 1326 1327 if(ps_sps->i1_chroma_format_idc != CHROMA_FMT_IDC_YUV420) 1328 { 1329 ps_codec->s_parse.i4_error_code = IHEVCD_UNSUPPORTED_CHROMA_FMT_IDC; 1330 return (IHEVCD_ERROR_T)IHEVCD_UNSUPPORTED_CHROMA_FMT_IDC; 1331 } 1332 1333 if(CHROMA_FMT_IDC_YUV444_PLANES == ps_sps->i1_chroma_format_idc) 1334 { 1335 BITS_PARSE("separate_colour_plane_flag", value, ps_bitstrm, 1); 1336 ps_sps->i1_separate_colour_plane_flag = value; 1337 } 1338 else 1339 { 1340 ps_sps->i1_separate_colour_plane_flag = 0; 1341 } 1342 1343 UEV_PARSE("pic_width_in_luma_samples", value, ps_bitstrm); 1344 ps_sps->i2_pic_width_in_luma_samples = value; 1345 1346 UEV_PARSE("pic_height_in_luma_samples", value, ps_bitstrm); 1347 ps_sps->i2_pic_height_in_luma_samples = value; 1348 1349 if((0 >= ps_sps->i2_pic_width_in_luma_samples) || (0 >= ps_sps->i2_pic_height_in_luma_samples)) 1350 return IHEVCD_INVALID_PARAMETER; 1351 1352 BITS_PARSE("pic_cropping_flag", value, ps_bitstrm, 1); 1353 ps_sps->i1_pic_cropping_flag = value; 1354 1355 if(ps_sps->i1_pic_cropping_flag) 1356 { 1357 1358 UEV_PARSE("pic_crop_left_offset", value, ps_bitstrm); 1359 if (value < 0 || value >= ps_sps->i2_pic_width_in_luma_samples) 1360 { 1361 return IHEVCD_INVALID_PARAMETER; 1362 } 1363 ps_sps->i2_pic_crop_left_offset = value; 1364 1365 UEV_PARSE("pic_crop_right_offset", value, ps_bitstrm); 1366 if (value < 0 || value >= ps_sps->i2_pic_width_in_luma_samples) 1367 { 1368 return IHEVCD_INVALID_PARAMETER; 1369 } 1370 ps_sps->i2_pic_crop_right_offset = value; 1371 1372 UEV_PARSE("pic_crop_top_offset", value, ps_bitstrm); 1373 if (value < 0 || value >= ps_sps->i2_pic_height_in_luma_samples) 1374 { 1375 return IHEVCD_INVALID_PARAMETER; 1376 } 1377 ps_sps->i2_pic_crop_top_offset = value; 1378 1379 UEV_PARSE("pic_crop_bottom_offset", value, ps_bitstrm); 1380 if (value < 0 || value >= ps_sps->i2_pic_height_in_luma_samples) 1381 { 1382 return IHEVCD_INVALID_PARAMETER; 1383 } 1384 ps_sps->i2_pic_crop_bottom_offset = value; 1385 } 1386 else 1387 { 1388 ps_sps->i2_pic_crop_left_offset = 0; 1389 ps_sps->i2_pic_crop_right_offset = 0; 1390 ps_sps->i2_pic_crop_top_offset = 0; 1391 ps_sps->i2_pic_crop_bottom_offset = 0; 1392 } 1393 1394 1395 UEV_PARSE("bit_depth_luma_minus8", value, ps_bitstrm); 1396 if(0 != value) 1397 return IHEVCD_UNSUPPORTED_BIT_DEPTH; 1398 1399 UEV_PARSE("bit_depth_chroma_minus8", value, ps_bitstrm); 1400 if(0 != value) 1401 return IHEVCD_UNSUPPORTED_BIT_DEPTH; 1402 1403 UEV_PARSE("log2_max_pic_order_cnt_lsb_minus4", value, ps_bitstrm); 1404 if(value < 0 || value > 12) 1405 return IHEVCD_INVALID_PARAMETER; 1406 ps_sps->i1_log2_max_pic_order_cnt_lsb = value + 4; 1407 1408 BITS_PARSE("sps_sub_layer_ordering_info_present_flag", value, ps_bitstrm, 1); 1409 ps_sps->i1_sps_sub_layer_ordering_info_present_flag = value; 1410 1411 1412 i = (ps_sps->i1_sps_sub_layer_ordering_info_present_flag ? 0 : (ps_sps->i1_sps_max_sub_layers - 1)); 1413 for(; i < ps_sps->i1_sps_max_sub_layers; i++) 1414 { 1415 UEV_PARSE("max_dec_pic_buffering", value, ps_bitstrm); 1416 if(value < 0 || (value + 1) > MAX_DPB_SIZE) 1417 { 1418 return IHEVCD_INVALID_PARAMETER; 1419 } 1420 ps_sps->ai1_sps_max_dec_pic_buffering[i] = value + 1; 1421 1422 UEV_PARSE("num_reorder_pics", value, ps_bitstrm); 1423 if(value < 0 || value > ps_sps->ai1_sps_max_dec_pic_buffering[i]) 1424 { 1425 return IHEVCD_INVALID_PARAMETER; 1426 } 1427 ps_sps->ai1_sps_max_num_reorder_pics[i] = value; 1428 1429 UEV_PARSE("max_latency_increase", value, ps_bitstrm); 1430 ps_sps->ai1_sps_max_latency_increase[i] = value; 1431 } 1432 1433 /* Check if sps_max_dec_pic_buffering or sps_max_num_reorder_pics 1434 has changed */ 1435 if(0 != ps_codec->u4_allocate_dynamic_done) 1436 { 1437 sps_t *ps_sps_old = ps_codec->s_parse.ps_sps; 1438 if(ps_sps_old->ai1_sps_max_dec_pic_buffering[ps_sps_old->i1_sps_max_sub_layers - 1] != 1439 ps_sps->ai1_sps_max_dec_pic_buffering[ps_sps->i1_sps_max_sub_layers - 1]) 1440 { 1441 if(0 == ps_codec->i4_first_pic_done) 1442 { 1443 return IHEVCD_INVALID_PARAMETER; 1444 } 1445 ps_codec->i4_reset_flag = 1; 1446 return (IHEVCD_ERROR_T)IVD_RES_CHANGED; 1447 } 1448 1449 if(ps_sps_old->ai1_sps_max_num_reorder_pics[ps_sps_old->i1_sps_max_sub_layers - 1] != 1450 ps_sps->ai1_sps_max_num_reorder_pics[ps_sps->i1_sps_max_sub_layers - 1]) 1451 { 1452 if(0 == ps_codec->i4_first_pic_done) 1453 { 1454 return IHEVCD_INVALID_PARAMETER; 1455 } 1456 ps_codec->i4_reset_flag = 1; 1457 return (IHEVCD_ERROR_T)IVD_RES_CHANGED; 1458 } 1459 } 1460 1461 UEV_PARSE("log2_min_coding_block_size_minus3", value, ps_bitstrm); 1462 ps_sps->i1_log2_min_coding_block_size = value + 3; 1463 1464 UEV_PARSE("log2_diff_max_min_coding_block_size", value, ps_bitstrm); 1465 ps_sps->i1_log2_diff_max_min_coding_block_size = value; 1466 1467 ctb_log2_size_y = ps_sps->i1_log2_min_coding_block_size + ps_sps->i1_log2_diff_max_min_coding_block_size; 1468 1469 UEV_PARSE("log2_min_transform_block_size_minus2", value, ps_bitstrm); 1470 ps_sps->i1_log2_min_transform_block_size = value + 2; 1471 1472 UEV_PARSE("log2_diff_max_min_transform_block_size", value, ps_bitstrm); 1473 ps_sps->i1_log2_diff_max_min_transform_block_size = value; 1474 1475 ps_sps->i1_log2_max_transform_block_size = ps_sps->i1_log2_min_transform_block_size + 1476 ps_sps->i1_log2_diff_max_min_transform_block_size; 1477 1478 if ((ps_sps->i1_log2_max_transform_block_size < 0) || 1479 (ps_sps->i1_log2_max_transform_block_size > MIN(ctb_log2_size_y, 5))) 1480 { 1481 return IHEVCD_INVALID_PARAMETER; 1482 } 1483 1484 ps_sps->i1_log2_ctb_size = ps_sps->i1_log2_min_coding_block_size + 1485 ps_sps->i1_log2_diff_max_min_coding_block_size; 1486 1487 if((ps_sps->i1_log2_min_coding_block_size < 3) || 1488 (ps_sps->i1_log2_min_transform_block_size < 2) || 1489 (ps_sps->i1_log2_diff_max_min_transform_block_size < 0) || 1490 (ps_sps->i1_log2_max_transform_block_size > ps_sps->i1_log2_ctb_size) || 1491 (ps_sps->i1_log2_ctb_size < 4) || 1492 (ps_sps->i1_log2_ctb_size > 6) || 1493 (ps_sps->i2_pic_width_in_luma_samples % (1 << ps_sps->i1_log2_min_coding_block_size) != 0) || 1494 (ps_sps->i2_pic_height_in_luma_samples % (1 << ps_sps->i1_log2_min_coding_block_size) != 0)) 1495 { 1496 return IHEVCD_INVALID_PARAMETER; 1497 } 1498 1499 ps_sps->i1_log2_min_pcm_coding_block_size = 0; 1500 ps_sps->i1_log2_diff_max_min_pcm_coding_block_size = 0; 1501 1502 UEV_PARSE("max_transform_hierarchy_depth_inter", value, ps_bitstrm); 1503 if(value < 0 || value > (ps_sps->i1_log2_ctb_size - ps_sps->i1_log2_min_transform_block_size)) 1504 { 1505 return IHEVCD_INVALID_PARAMETER; 1506 } 1507 ps_sps->i1_max_transform_hierarchy_depth_inter = value; 1508 1509 UEV_PARSE("max_transform_hierarchy_depth_intra", value, ps_bitstrm); 1510 if(value < 0 || value > (ps_sps->i1_log2_ctb_size - ps_sps->i1_log2_min_transform_block_size)) 1511 { 1512 return IHEVCD_INVALID_PARAMETER; 1513 } 1514 ps_sps->i1_max_transform_hierarchy_depth_intra = value; 1515 1516 /* String has a d (enabled) in order to match with HM */ 1517 BITS_PARSE("scaling_list_enabled_flag", value, ps_bitstrm, 1); 1518 ps_sps->i1_scaling_list_enable_flag = value; 1519 1520 if(ps_sps->i1_scaling_list_enable_flag) 1521 { 1522 COPY_DEFAULT_SCALING_LIST(ps_sps->pi2_scaling_mat); 1523 BITS_PARSE("sps_scaling_list_data_present_flag", value, ps_bitstrm, 1); 1524 ps_sps->i1_sps_scaling_list_data_present_flag = value; 1525 1526 if(ps_sps->i1_sps_scaling_list_data_present_flag) 1527 ihevcd_scaling_list_data(ps_codec, ps_sps->pi2_scaling_mat); 1528 } 1529 else 1530 { 1531 COPY_FLAT_SCALING_LIST(ps_sps->pi2_scaling_mat); 1532 } 1533 /* String is asymmetric_motion_partitions_enabled_flag instead of amp_enabled_flag in order to match with HM */ 1534 BITS_PARSE("asymmetric_motion_partitions_enabled_flag", value, ps_bitstrm, 1); 1535 ps_sps->i1_amp_enabled_flag = value; 1536 1537 BITS_PARSE("sample_adaptive_offset_enabled_flag", value, ps_bitstrm, 1); 1538 ps_sps->i1_sample_adaptive_offset_enabled_flag = value; 1539 1540 BITS_PARSE("pcm_enabled_flag", value, ps_bitstrm, 1); 1541 ps_sps->i1_pcm_enabled_flag = value; 1542 1543 if(ps_sps->i1_pcm_enabled_flag) 1544 { 1545 BITS_PARSE("pcm_sample_bit_depth_luma", value, ps_bitstrm, 4); 1546 ps_sps->i1_pcm_sample_bit_depth_luma = value + 1; 1547 1548 BITS_PARSE("pcm_sample_bit_depth_chroma", value, ps_bitstrm, 4); 1549 ps_sps->i1_pcm_sample_bit_depth_chroma = value + 1; 1550 1551 UEV_PARSE("log2_min_pcm_coding_block_size_minus3", value, ps_bitstrm); 1552 ps_sps->i1_log2_min_pcm_coding_block_size = value + 3; 1553 1554 UEV_PARSE("log2_diff_max_min_pcm_coding_block_size", value, ps_bitstrm); 1555 ps_sps->i1_log2_diff_max_min_pcm_coding_block_size = value; 1556 BITS_PARSE("pcm_loop_filter_disable_flag", value, ps_bitstrm, 1); 1557 ps_sps->i1_pcm_loop_filter_disable_flag = value; 1558 1559 } 1560 UEV_PARSE("num_short_term_ref_pic_sets", value, ps_bitstrm); 1561 if(value < 0 || value > MAX_STREF_PICS_SPS) 1562 { 1563 return IHEVCD_INVALID_PARAMETER; 1564 } 1565 ps_sps->i1_num_short_term_ref_pic_sets = value; 1566 1567 for(i = 0; i < ps_sps->i1_num_short_term_ref_pic_sets; i++) 1568 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]); 1569 1570 BITS_PARSE("long_term_ref_pics_present_flag", value, ps_bitstrm, 1); 1571 ps_sps->i1_long_term_ref_pics_present_flag = value; 1572 1573 if(ps_sps->i1_long_term_ref_pics_present_flag) 1574 { 1575 UEV_PARSE("num_long_term_ref_pics_sps", value, ps_bitstrm); 1576 if(value < 0 || value > MAX_LTREF_PICS_SPS) 1577 { 1578 return IHEVCD_INVALID_PARAMETER; 1579 } 1580 ps_sps->i1_num_long_term_ref_pics_sps = value; 1581 1582 for(i = 0; i < ps_sps->i1_num_long_term_ref_pics_sps; i++) 1583 { 1584 BITS_PARSE("lt_ref_pic_poc_lsb_sps[ i ]", value, ps_bitstrm, ps_sps->i1_log2_max_pic_order_cnt_lsb); 1585 ps_sps->au2_lt_ref_pic_poc_lsb_sps[i] = value; 1586 1587 BITS_PARSE("used_by_curr_pic_lt_sps_flag[ i ]", value, ps_bitstrm, 1); 1588 ps_sps->ai1_used_by_curr_pic_lt_sps_flag[i] = value; 1589 } 1590 } 1591 1592 BITS_PARSE("sps_temporal_mvp_enable_flag", value, ps_bitstrm, 1); 1593 ps_sps->i1_sps_temporal_mvp_enable_flag = value; 1594 1595 /* Print matches HM 8-2 */ 1596 BITS_PARSE("sps_strong_intra_smoothing_enable_flag", value, ps_bitstrm, 1); 1597 ps_sps->i1_strong_intra_smoothing_enable_flag = value; 1598 1599 BITS_PARSE("vui_parameters_present_flag", value, ps_bitstrm, 1); 1600 ps_sps->i1_vui_parameters_present_flag = value; 1601 1602 if(ps_sps->i1_vui_parameters_present_flag) 1603 { 1604 ret = ihevcd_parse_vui_parameters(ps_bitstrm, 1605 &ps_sps->s_vui_parameters, 1606 ps_sps->i1_sps_max_sub_layers - 1); 1607 RETURN_IF((ret != (IHEVCD_ERROR_T)IHEVCD_SUCCESS), ret); 1608 } 1609 1610 BITS_PARSE("sps_extension_flag", value, ps_bitstrm, 1); 1611 1612 if((UWORD8 *)ps_bitstrm->pu4_buf > ps_bitstrm->pu1_buf_max) 1613 { 1614 return IHEVCD_INVALID_PARAMETER; 1615 } 1616 1617 { 1618 WORD32 numerator; 1619 WORD32 ceil_offset; 1620 1621 ceil_offset = (1 << ps_sps->i1_log2_ctb_size) - 1; 1622 numerator = ps_sps->i2_pic_width_in_luma_samples; 1623 1624 ps_sps->i2_pic_wd_in_ctb = ((numerator + ceil_offset) / 1625 (1 << ps_sps->i1_log2_ctb_size)); 1626 1627 numerator = ps_sps->i2_pic_height_in_luma_samples; 1628 ps_sps->i2_pic_ht_in_ctb = ((numerator + ceil_offset) / 1629 (1 << ps_sps->i1_log2_ctb_size)); 1630 1631 ps_sps->i4_pic_size_in_ctb = ps_sps->i2_pic_ht_in_ctb * 1632 ps_sps->i2_pic_wd_in_ctb; 1633 1634 if(0 == ps_codec->i4_sps_done) 1635 ps_codec->s_parse.i4_next_ctb_indx = ps_sps->i4_pic_size_in_ctb; 1636 1637 numerator = ps_sps->i2_pic_width_in_luma_samples; 1638 ps_sps->i2_pic_wd_in_min_cb = numerator / 1639 (1 << ps_sps->i1_log2_min_coding_block_size); 1640 1641 numerator = ps_sps->i2_pic_height_in_luma_samples; 1642 ps_sps->i2_pic_ht_in_min_cb = numerator / 1643 (1 << ps_sps->i1_log2_min_coding_block_size); 1644 } 1645 if((0 != ps_codec->u4_allocate_dynamic_done) && 1646 ((ps_codec->i4_wd != ps_sps->i2_pic_width_in_luma_samples) || 1647 (ps_codec->i4_ht != ps_sps->i2_pic_height_in_luma_samples))) 1648 { 1649 if(0 == ps_codec->i4_first_pic_done) 1650 { 1651 return IHEVCD_INVALID_PARAMETER; 1652 } 1653 ps_codec->i4_reset_flag = 1; 1654 return (IHEVCD_ERROR_T)IVD_RES_CHANGED; 1655 } 1656 1657 if((ps_sps->i2_pic_width_in_luma_samples > MAX_WD) || 1658 ((ps_sps->i2_pic_width_in_luma_samples * ps_sps->i2_pic_height_in_luma_samples) > 1659 (MAX_WD * MAX_HT))) 1660 { 1661 return (IHEVCD_ERROR_T)IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED; 1662 } 1663 1664 /* Update display width and display height */ 1665 { 1666 WORD32 disp_wd, disp_ht; 1667 WORD32 crop_unit_x, crop_unit_y; 1668 crop_unit_x = 1; 1669 crop_unit_y = 1; 1670 1671 if(CHROMA_FMT_IDC_YUV420 == ps_sps->i1_chroma_format_idc) 1672 { 1673 crop_unit_x = 2; 1674 crop_unit_y = 2; 1675 } 1676 1677 disp_wd = ps_sps->i2_pic_width_in_luma_samples; 1678 disp_wd -= ps_sps->i2_pic_crop_left_offset * crop_unit_x; 1679 disp_wd -= ps_sps->i2_pic_crop_right_offset * crop_unit_x; 1680 1681 1682 disp_ht = ps_sps->i2_pic_height_in_luma_samples; 1683 disp_ht -= ps_sps->i2_pic_crop_top_offset * crop_unit_y; 1684 disp_ht -= ps_sps->i2_pic_crop_bottom_offset * crop_unit_y; 1685 1686 if((0 >= disp_wd) || (0 >= disp_ht)) 1687 return IHEVCD_INVALID_PARAMETER; 1688 1689 ps_codec->i4_disp_wd = disp_wd; 1690 ps_codec->i4_disp_ht = disp_ht; 1691 1692 1693 ps_codec->i4_wd = ps_sps->i2_pic_width_in_luma_samples; 1694 ps_codec->i4_ht = ps_sps->i2_pic_height_in_luma_samples; 1695 1696 { 1697 WORD32 ref_strd; 1698 ref_strd = ALIGN32(ps_sps->i2_pic_width_in_luma_samples + PAD_WD); 1699 if(ps_codec->i4_strd < ref_strd) 1700 { 1701 ps_codec->i4_strd = ref_strd; 1702 } 1703 } 1704 1705 if(0 == ps_codec->i4_share_disp_buf) 1706 { 1707 if(ps_codec->i4_disp_strd < ps_codec->i4_disp_wd) 1708 { 1709 ps_codec->i4_disp_strd = ps_codec->i4_disp_wd; 1710 } 1711 } 1712 else 1713 { 1714 if(ps_codec->i4_disp_strd < ps_codec->i4_strd) 1715 { 1716 ps_codec->i4_disp_strd = ps_codec->i4_strd; 1717 } 1718 } 1719 } 1720 1721 /* This is used only during initialization to get reorder count etc */ 1722 ps_codec->i4_sps_id = sps_id; 1723 1724 ps_codec->i4_sps_done = 1; 1725 return ret; 1726 } 1727 1728 1729 void ihevcd_unmark_pps(codec_t *ps_codec, WORD32 sps_id) 1730 { 1731 WORD32 pps_id = 0; 1732 pps_t *ps_pps = ps_codec->ps_pps_base; 1733 1734 for(pps_id = 0; pps_id < MAX_PPS_CNT - 1; pps_id++, ps_pps++) 1735 { 1736 if((ps_pps->i1_pps_valid) && 1737 (ps_pps->i1_sps_id == sps_id)) 1738 ps_pps->i1_pps_valid = 0; 1739 } 1740 } 1741 1742 1743 void ihevcd_copy_sps(codec_t *ps_codec, WORD32 sps_id, WORD32 sps_id_ref) 1744 { 1745 sps_t *ps_sps, *ps_sps_ref; 1746 WORD16 *pi2_scaling_mat_backup; 1747 WORD32 scaling_mat_size; 1748 1749 SCALING_MAT_SIZE(scaling_mat_size); 1750 ps_sps_ref = ps_codec->ps_sps_base + sps_id_ref; 1751 ps_sps = ps_codec->ps_sps_base + sps_id; 1752 1753 if(ps_sps->i1_sps_valid) 1754 { 1755 if((ps_sps->i1_log2_ctb_size != ps_sps_ref->i1_log2_ctb_size) || 1756 (ps_sps->i2_pic_wd_in_ctb != ps_sps_ref->i2_pic_wd_in_ctb) || 1757 (ps_sps->i2_pic_ht_in_ctb != ps_sps_ref->i2_pic_ht_in_ctb)) 1758 { 1759 ihevcd_unmark_pps(ps_codec, sps_id); 1760 } 1761 } 1762 1763 pi2_scaling_mat_backup = ps_sps->pi2_scaling_mat; 1764 1765 memcpy(ps_sps, ps_sps_ref, sizeof(sps_t)); 1766 ps_sps->pi2_scaling_mat = pi2_scaling_mat_backup; 1767 memcpy(ps_sps->pi2_scaling_mat, ps_sps_ref->pi2_scaling_mat, scaling_mat_size * sizeof(WORD16)); 1768 ps_sps->i1_sps_valid = 1; 1769 1770 ps_codec->s_parse.ps_sps = ps_sps; 1771 } 1772 1773 1774 /** 1775 ******************************************************************************* 1776 * 1777 * @brief 1778 * Parses PPS (Picture Parameter Set) 1779 * 1780 * @par Description: 1781 * Parse Picture Parameter Set as per section Section: 7.3.2.3 1782 * The pps is written to a temporary buffer and copied later to the 1783 * appropriate location 1784 * 1785 * @param[in] ps_codec 1786 * Pointer to codec context 1787 * 1788 * @returns Error code from IHEVCD_ERROR_T 1789 * 1790 * @remarks 1791 * 1792 * 1793 ******************************************************************************* 1794 */ 1795 IHEVCD_ERROR_T ihevcd_parse_pps(codec_t *ps_codec) 1796 { 1797 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 1798 WORD32 value; 1799 WORD32 pps_id; 1800 1801 pps_t *ps_pps; 1802 sps_t *ps_sps; 1803 bitstrm_t *ps_bitstrm = &ps_codec->s_parse.s_bitstrm; 1804 1805 1806 if(0 == ps_codec->i4_sps_done) 1807 return IHEVCD_INVALID_HEADER; 1808 1809 UEV_PARSE("pic_parameter_set_id", value, ps_bitstrm); 1810 1811 pps_id = value; 1812 if((pps_id >= MAX_PPS_CNT) || (pps_id < 0)) 1813 { 1814 if(ps_codec->i4_pps_done) 1815 return IHEVCD_UNSUPPORTED_PPS_ID; 1816 else 1817 pps_id = 0; 1818 } 1819 1820 1821 ps_pps = (ps_codec->s_parse.ps_pps_base + MAX_PPS_CNT - 1); 1822 1823 ps_pps->i1_pps_id = pps_id; 1824 1825 UEV_PARSE("seq_parameter_set_id", value, ps_bitstrm); 1826 ps_pps->i1_sps_id = value; 1827 ps_pps->i1_sps_id = CLIP3(ps_pps->i1_sps_id, 0, MAX_SPS_CNT - 2); 1828 1829 ps_sps = (ps_codec->s_parse.ps_sps_base + ps_pps->i1_sps_id); 1830 1831 /* If the SPS that is being referred to has not been parsed, 1832 * copy an existing SPS to the current location */ 1833 if(0 == ps_sps->i1_sps_valid) 1834 { 1835 return IHEVCD_INVALID_HEADER; 1836 1837 /* 1838 sps_t *ps_sps_ref = ps_codec->ps_sps_base; 1839 while(0 == ps_sps_ref->i1_sps_valid) 1840 ps_sps_ref++; 1841 ihevcd_copy_sps(ps_codec, ps_pps->i1_sps_id, ps_sps_ref->i1_sps_id); 1842 */ 1843 } 1844 1845 BITS_PARSE("dependent_slices_enabled_flag", value, ps_bitstrm, 1); 1846 ps_pps->i1_dependent_slice_enabled_flag = value; 1847 1848 BITS_PARSE("output_flag_present_flag", value, ps_bitstrm, 1); 1849 ps_pps->i1_output_flag_present_flag = value; 1850 1851 BITS_PARSE("num_extra_slice_header_bits", value, ps_bitstrm, 3); 1852 ps_pps->i1_num_extra_slice_header_bits = value; 1853 1854 1855 BITS_PARSE("sign_data_hiding_flag", value, ps_bitstrm, 1); 1856 ps_pps->i1_sign_data_hiding_flag = value; 1857 1858 BITS_PARSE("cabac_init_present_flag", value, ps_bitstrm, 1); 1859 ps_pps->i1_cabac_init_present_flag = value; 1860 1861 UEV_PARSE("num_ref_idx_l0_default_active_minus1", value, ps_bitstrm); 1862 ps_pps->i1_num_ref_idx_l0_default_active = value + 1; 1863 1864 UEV_PARSE("num_ref_idx_l1_default_active_minus1", value, ps_bitstrm); 1865 ps_pps->i1_num_ref_idx_l1_default_active = value + 1; 1866 1867 SEV_PARSE("pic_init_qp_minus26", value, ps_bitstrm); 1868 ps_pps->i1_pic_init_qp = value + 26; 1869 1870 BITS_PARSE("constrained_intra_pred_flag", value, ps_bitstrm, 1); 1871 ps_pps->i1_constrained_intra_pred_flag = value; 1872 1873 BITS_PARSE("transform_skip_enabled_flag", value, ps_bitstrm, 1); 1874 ps_pps->i1_transform_skip_enabled_flag = value; 1875 1876 BITS_PARSE("cu_qp_delta_enabled_flag", value, ps_bitstrm, 1); 1877 ps_pps->i1_cu_qp_delta_enabled_flag = value; 1878 1879 if(ps_pps->i1_cu_qp_delta_enabled_flag) 1880 { 1881 UEV_PARSE("diff_cu_qp_delta_depth", value, ps_bitstrm); 1882 ps_pps->i1_diff_cu_qp_delta_depth = value; 1883 } 1884 else 1885 { 1886 ps_pps->i1_diff_cu_qp_delta_depth = 0; 1887 } 1888 ps_pps->i1_log2_min_cu_qp_delta_size = ps_sps->i1_log2_ctb_size - ps_pps->i1_diff_cu_qp_delta_depth; 1889 /* Print different */ 1890 SEV_PARSE("cb_qp_offset", value, ps_bitstrm); 1891 ps_pps->i1_pic_cb_qp_offset = value; 1892 1893 /* Print different */ 1894 SEV_PARSE("cr_qp_offset", value, ps_bitstrm); 1895 ps_pps->i1_pic_cr_qp_offset = value; 1896 1897 /* Print different */ 1898 BITS_PARSE("slicelevel_chroma_qp_flag", value, ps_bitstrm, 1); 1899 ps_pps->i1_pic_slice_level_chroma_qp_offsets_present_flag = value; 1900 1901 BITS_PARSE("weighted_pred_flag", value, ps_bitstrm, 1); 1902 ps_pps->i1_weighted_pred_flag = value; 1903 1904 BITS_PARSE("weighted_bipred_flag", value, ps_bitstrm, 1); 1905 ps_pps->i1_weighted_bipred_flag = value; 1906 1907 BITS_PARSE("transquant_bypass_enable_flag", value, ps_bitstrm, 1); 1908 ps_pps->i1_transquant_bypass_enable_flag = value; 1909 1910 BITS_PARSE("tiles_enabled_flag", value, ps_bitstrm, 1); 1911 ps_pps->i1_tiles_enabled_flag = value; 1912 1913 /* When tiles are enabled and width or height is >= 4096, 1914 * CTB Size should at least be 32. 16x16 CTBs can result 1915 * in tile position greater than 255 for 4096, 1916 * which decoder does not support. 1917 */ 1918 if((ps_pps->i1_tiles_enabled_flag) && 1919 (ps_sps->i1_log2_ctb_size == 4) && 1920 ((ps_sps->i2_pic_width_in_luma_samples >= 4096) || 1921 (ps_sps->i2_pic_height_in_luma_samples >= 4096))) 1922 { 1923 return IHEVCD_INVALID_HEADER; 1924 } 1925 1926 BITS_PARSE("entropy_coding_sync_enabled_flag", value, ps_bitstrm, 1); 1927 ps_pps->i1_entropy_coding_sync_enabled_flag = value; 1928 1929 ps_pps->i1_loop_filter_across_tiles_enabled_flag = 0; 1930 if(ps_pps->i1_tiles_enabled_flag) 1931 { 1932 WORD32 wd = ALIGN64(ps_codec->i4_wd); 1933 WORD32 ht = ALIGN64(ps_codec->i4_ht); 1934 1935 WORD32 max_tile_cols = (wd + MIN_TILE_WD - 1) / MIN_TILE_WD; 1936 WORD32 max_tile_rows = (ht + MIN_TILE_HT - 1) / MIN_TILE_HT; 1937 1938 UEV_PARSE("num_tile_columns_minus1", value, ps_bitstrm); 1939 ps_pps->i1_num_tile_columns = value + 1; 1940 1941 UEV_PARSE("num_tile_rows_minus1", value, ps_bitstrm); 1942 ps_pps->i1_num_tile_rows = value + 1; 1943 1944 if((ps_pps->i1_num_tile_columns < 1) || 1945 (ps_pps->i1_num_tile_columns > max_tile_cols) || 1946 (ps_pps->i1_num_tile_rows < 1) || 1947 (ps_pps->i1_num_tile_rows > max_tile_rows)) 1948 return IHEVCD_INVALID_HEADER; 1949 1950 BITS_PARSE("uniform_spacing_flag", value, ps_bitstrm, 1); 1951 ps_pps->i1_uniform_spacing_flag = value; 1952 1953 1954 { 1955 1956 WORD32 start; 1957 WORD32 i, j; 1958 1959 1960 start = 0; 1961 for(i = 0; i < ps_pps->i1_num_tile_columns; i++) 1962 { 1963 tile_t *ps_tile; 1964 if(!ps_pps->i1_uniform_spacing_flag) 1965 { 1966 if(i < (ps_pps->i1_num_tile_columns - 1)) 1967 { 1968 UEV_PARSE("column_width_minus1[ i ]", value, ps_bitstrm); 1969 value += 1; 1970 } 1971 else 1972 { 1973 value = ps_sps->i2_pic_wd_in_ctb - start; 1974 } 1975 } 1976 else 1977 { 1978 value = ((i + 1) * ps_sps->i2_pic_wd_in_ctb) / ps_pps->i1_num_tile_columns - 1979 (i * ps_sps->i2_pic_wd_in_ctb) / ps_pps->i1_num_tile_columns; 1980 } 1981 1982 for(j = 0; j < ps_pps->i1_num_tile_rows; j++) 1983 { 1984 ps_tile = ps_pps->ps_tile + j * ps_pps->i1_num_tile_columns + i; 1985 ps_tile->u1_pos_x = start; 1986 ps_tile->u2_wd = value; 1987 } 1988 start += value; 1989 1990 if((start > ps_sps->i2_pic_wd_in_ctb) || 1991 (value <= 0)) 1992 return IHEVCD_INVALID_HEADER; 1993 } 1994 1995 start = 0; 1996 for(i = 0; i < (ps_pps->i1_num_tile_rows); i++) 1997 { 1998 tile_t *ps_tile; 1999 if(!ps_pps->i1_uniform_spacing_flag) 2000 { 2001 if(i < (ps_pps->i1_num_tile_rows - 1)) 2002 { 2003 2004 UEV_PARSE("row_height_minus1[ i ]", value, ps_bitstrm); 2005 value += 1; 2006 } 2007 else 2008 { 2009 value = ps_sps->i2_pic_ht_in_ctb - start; 2010 } 2011 } 2012 else 2013 { 2014 value = ((i + 1) * ps_sps->i2_pic_ht_in_ctb) / ps_pps->i1_num_tile_rows - 2015 (i * ps_sps->i2_pic_ht_in_ctb) / ps_pps->i1_num_tile_rows; 2016 } 2017 2018 for(j = 0; j < ps_pps->i1_num_tile_columns; j++) 2019 { 2020 ps_tile = ps_pps->ps_tile + i * ps_pps->i1_num_tile_columns + j; 2021 ps_tile->u1_pos_y = start; 2022 ps_tile->u2_ht = value; 2023 } 2024 start += value; 2025 2026 if((start > ps_sps->i2_pic_ht_in_ctb) || 2027 (value <= 0)) 2028 return IHEVCD_INVALID_HEADER; 2029 } 2030 } 2031 2032 2033 BITS_PARSE("loop_filter_across_tiles_enabled_flag", value, ps_bitstrm, 1); 2034 ps_pps->i1_loop_filter_across_tiles_enabled_flag = value; 2035 2036 } 2037 else 2038 { 2039 /* If tiles are not present, set first tile in each PPS to have tile 2040 width and height equal to picture width and height */ 2041 ps_pps->i1_num_tile_columns = 1; 2042 ps_pps->i1_num_tile_rows = 1; 2043 ps_pps->i1_uniform_spacing_flag = 1; 2044 2045 ps_pps->ps_tile->u1_pos_x = 0; 2046 ps_pps->ps_tile->u1_pos_y = 0; 2047 ps_pps->ps_tile->u2_wd = ps_sps->i2_pic_wd_in_ctb; 2048 ps_pps->ps_tile->u2_ht = ps_sps->i2_pic_ht_in_ctb; 2049 } 2050 2051 BITS_PARSE("loop_filter_across_slices_enabled_flag", value, ps_bitstrm, 1); 2052 ps_pps->i1_loop_filter_across_slices_enabled_flag = value; 2053 2054 BITS_PARSE("deblocking_filter_control_present_flag", value, ps_bitstrm, 1); 2055 ps_pps->i1_deblocking_filter_control_present_flag = value; 2056 2057 /* Default values */ 2058 ps_pps->i1_pic_disable_deblocking_filter_flag = 0; 2059 ps_pps->i1_deblocking_filter_override_enabled_flag = 0; 2060 ps_pps->i1_beta_offset_div2 = 0; 2061 ps_pps->i1_tc_offset_div2 = 0; 2062 2063 if(ps_pps->i1_deblocking_filter_control_present_flag) 2064 { 2065 2066 BITS_PARSE("deblocking_filter_override_enabled_flag", value, ps_bitstrm, 1); 2067 ps_pps->i1_deblocking_filter_override_enabled_flag = value; 2068 2069 BITS_PARSE("pic_disable_deblocking_filter_flag", value, ps_bitstrm, 1); 2070 ps_pps->i1_pic_disable_deblocking_filter_flag = value; 2071 2072 if(!ps_pps->i1_pic_disable_deblocking_filter_flag) 2073 { 2074 2075 SEV_PARSE("pps_beta_offset_div2", value, ps_bitstrm); 2076 ps_pps->i1_beta_offset_div2 = value; 2077 2078 SEV_PARSE("pps_tc_offset_div2", value, ps_bitstrm); 2079 ps_pps->i1_tc_offset_div2 = value; 2080 2081 } 2082 } 2083 2084 BITS_PARSE("pps_scaling_list_data_present_flag", value, ps_bitstrm, 1); 2085 ps_pps->i1_pps_scaling_list_data_present_flag = value; 2086 2087 if(ps_pps->i1_pps_scaling_list_data_present_flag) 2088 { 2089 COPY_DEFAULT_SCALING_LIST(ps_pps->pi2_scaling_mat); 2090 ihevcd_scaling_list_data(ps_codec, ps_pps->pi2_scaling_mat); 2091 } 2092 2093 BITS_PARSE("lists_modification_present_flag", value, ps_bitstrm, 1); 2094 ps_pps->i1_lists_modification_present_flag = value; 2095 UEV_PARSE("log2_parallel_merge_level_minus2", value, ps_bitstrm); 2096 ps_pps->i1_log2_parallel_merge_level = value + 2; 2097 2098 BITS_PARSE("slice_header_extension_present_flag", value, ps_bitstrm, 1); 2099 ps_pps->i1_slice_header_extension_present_flag = value; 2100 /* Not present in HM */ 2101 BITS_PARSE("pps_extension_flag", value, ps_bitstrm, 1); 2102 2103 if((UWORD8 *)ps_bitstrm->pu4_buf > ps_bitstrm->pu1_buf_max) 2104 return IHEVCD_INVALID_PARAMETER; 2105 2106 ps_codec->i4_pps_done = 1; 2107 return ret; 2108 } 2109 2110 2111 void ihevcd_copy_pps(codec_t *ps_codec, WORD32 pps_id, WORD32 pps_id_ref) 2112 { 2113 pps_t *ps_pps, *ps_pps_ref; 2114 WORD16 *pi2_scaling_mat_backup; 2115 WORD32 scaling_mat_size; 2116 tile_t *ps_tile_backup; 2117 WORD32 max_tile_cols, max_tile_rows; 2118 WORD32 wd, ht; 2119 wd = ALIGN64(ps_codec->i4_wd); 2120 ht = ALIGN64(ps_codec->i4_ht); 2121 2122 SCALING_MAT_SIZE(scaling_mat_size); 2123 max_tile_cols = (wd + MIN_TILE_WD - 1) / MIN_TILE_WD; 2124 max_tile_rows = (ht + MIN_TILE_HT - 1) / MIN_TILE_HT; 2125 2126 ps_pps_ref = ps_codec->ps_pps_base + pps_id_ref; 2127 ps_pps = ps_codec->ps_pps_base + pps_id; 2128 2129 pi2_scaling_mat_backup = ps_pps->pi2_scaling_mat; 2130 ps_tile_backup = ps_pps->ps_tile; 2131 2132 memcpy(ps_pps, ps_pps_ref, sizeof(pps_t)); 2133 ps_pps->pi2_scaling_mat = pi2_scaling_mat_backup; 2134 ps_pps->ps_tile = ps_tile_backup; 2135 memcpy(ps_pps->pi2_scaling_mat, ps_pps_ref->pi2_scaling_mat, scaling_mat_size * sizeof(WORD16)); 2136 memcpy(ps_pps->ps_tile, ps_pps_ref->ps_tile, max_tile_cols * max_tile_rows * sizeof(tile_t)); 2137 2138 ps_pps->i1_pps_valid = 1; 2139 2140 ps_codec->s_parse.ps_pps = ps_pps; 2141 } 2142 2143 2144 IHEVCD_ERROR_T ihevcd_parse_buffering_period_sei(codec_t *ps_codec, 2145 sps_t *ps_sps) 2146 { 2147 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2148 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2149 UWORD32 value; 2150 vui_t *ps_vui; 2151 buf_period_sei_params_t *ps_buf_period_sei_params; 2152 UWORD32 i; 2153 hrd_params_t *ps_vui_hdr; 2154 UWORD32 u4_cpb_cnt; 2155 2156 ps_vui = &ps_sps->s_vui_parameters; 2157 ps_vui_hdr = &ps_vui->s_vui_hrd_parameters; 2158 2159 ps_buf_period_sei_params = &ps_parse->s_sei_params.s_buf_period_sei_params; 2160 2161 ps_parse->s_sei_params.i1_buf_period_params_present_flag = 1; 2162 2163 UEV_PARSE("bp_seq_parameter_set_id", value, ps_bitstrm); 2164 ps_buf_period_sei_params->u1_bp_seq_parameter_set_id = value; 2165 2166 if(!ps_vui_hdr->u1_sub_pic_cpb_params_present_flag) 2167 { 2168 BITS_PARSE("irap_cpb_params_present_flag", value, ps_bitstrm, 1); 2169 ps_buf_period_sei_params->u1_rap_cpb_params_present_flag = value; 2170 } 2171 2172 if(ps_buf_period_sei_params->u1_rap_cpb_params_present_flag) 2173 { 2174 BITS_PARSE("cpb_delay_offset", 2175 value, 2176 ps_bitstrm, 2177 (ps_vui_hdr->u1_au_cpb_removal_delay_length_minus1 2178 + 1)); 2179 ps_buf_period_sei_params->u4_cpb_delay_offset = value; 2180 2181 BITS_PARSE("dpb_delay_offset", 2182 value, 2183 ps_bitstrm, 2184 (ps_vui_hdr->u1_dpb_output_delay_length_minus1 2185 + 1)); 2186 ps_buf_period_sei_params->u4_dpb_delay_offset = value; 2187 } 2188 else 2189 { 2190 ps_buf_period_sei_params->u4_cpb_delay_offset = 0; 2191 ps_buf_period_sei_params->u4_dpb_delay_offset = 0; 2192 } 2193 2194 BITS_PARSE("concatenation_flag", value, ps_bitstrm, 1); 2195 ps_buf_period_sei_params->u1_concatenation_flag = value; 2196 2197 BITS_PARSE("au_cpb_removal_delay_delta_minus1", 2198 value, 2199 ps_bitstrm, 2200 (ps_vui_hdr->u1_au_cpb_removal_delay_length_minus1 2201 + 1)); 2202 ps_buf_period_sei_params->u4_au_cpb_removal_delay_delta_minus1 = value; 2203 2204 if(ps_vui_hdr->u1_nal_hrd_parameters_present_flag) 2205 { 2206 u4_cpb_cnt = ps_vui_hdr->au1_cpb_cnt_minus1[0]; 2207 2208 for(i = 0; i <= u4_cpb_cnt; i++) 2209 { 2210 BITS_PARSE("nal_initial_cpb_removal_delay[i]", 2211 value, 2212 ps_bitstrm, 2213 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2214 + 1)); 2215 ps_buf_period_sei_params->au4_nal_initial_cpb_removal_delay[i] = 2216 value; 2217 2218 BITS_PARSE("nal_initial_cpb_removal_delay_offset", 2219 value, 2220 ps_bitstrm, 2221 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2222 + 1)); 2223 ps_buf_period_sei_params->au4_nal_initial_cpb_removal_delay_offset[i] = 2224 value; 2225 2226 if(ps_vui_hdr->u1_sub_pic_cpb_params_present_flag 2227 || ps_buf_period_sei_params->u1_rap_cpb_params_present_flag) 2228 { 2229 BITS_PARSE("nal_initial_alt_cpb_removal_delay[i]", 2230 value, 2231 ps_bitstrm, 2232 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2233 + 1)); 2234 ps_buf_period_sei_params->au4_nal_initial_alt_cpb_removal_delay[i] = 2235 value; 2236 2237 BITS_PARSE("nal_initial_alt_cpb_removal_delay_offset", 2238 value, 2239 ps_bitstrm, 2240 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2241 + 1)); 2242 ps_buf_period_sei_params->au4_nal_initial_alt_cpb_removal_delay_offset[i] = 2243 value; 2244 } 2245 } 2246 } 2247 2248 if(ps_vui_hdr->u1_vcl_hrd_parameters_present_flag) 2249 { 2250 u4_cpb_cnt = ps_vui_hdr->au1_cpb_cnt_minus1[0]; 2251 2252 for(i = 0; i <= u4_cpb_cnt; i++) 2253 { 2254 BITS_PARSE("vcl_initial_cpb_removal_delay[i]", 2255 value, 2256 ps_bitstrm, 2257 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2258 + 1)); 2259 ps_buf_period_sei_params->au4_vcl_initial_cpb_removal_delay[i] = 2260 value; 2261 2262 BITS_PARSE("vcl_initial_cpb_removal_delay_offset", 2263 value, 2264 ps_bitstrm, 2265 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2266 + 1)); 2267 ps_buf_period_sei_params->au4_vcl_initial_cpb_removal_delay_offset[i] = 2268 value; 2269 2270 if(ps_vui_hdr->u1_sub_pic_cpb_params_present_flag 2271 || ps_buf_period_sei_params->u1_rap_cpb_params_present_flag) 2272 { 2273 BITS_PARSE("vcl_initial_alt_cpb_removal_delay[i]", 2274 value, 2275 ps_bitstrm, 2276 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2277 + 1)); 2278 ps_buf_period_sei_params->au4_vcl_initial_alt_cpb_removal_delay[i] = 2279 value; 2280 2281 BITS_PARSE("vcl_initial_alt_cpb_removal_delay_offset", 2282 value, 2283 ps_bitstrm, 2284 (ps_vui_hdr->u1_initial_cpb_removal_delay_length_minus1 2285 + 1)); 2286 ps_buf_period_sei_params->au4_vcl_initial_alt_cpb_removal_delay_offset[i] = 2287 value; 2288 } 2289 } 2290 } 2291 2292 return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2293 } 2294 2295 IHEVCD_ERROR_T ihevcd_parse_pic_timing_sei(codec_t *ps_codec, sps_t *ps_sps) 2296 { 2297 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2298 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2299 UWORD32 value; 2300 vui_t *ps_vui; 2301 UWORD32 i; 2302 hrd_params_t *ps_vui_hdr; 2303 UWORD32 u4_cpb_dpb_delays_present_flag = 0; 2304 pic_timing_sei_params_t *ps_pic_timing; 2305 2306 ps_pic_timing = &ps_parse->s_sei_params.s_pic_timing_sei_params; 2307 ps_vui = &ps_sps->s_vui_parameters; 2308 ps_vui_hdr = &ps_vui->s_vui_hrd_parameters; 2309 ps_parse->s_sei_params.i1_pic_timing_params_present_flag = 1; 2310 if(ps_vui->u1_frame_field_info_present_flag) 2311 { 2312 BITS_PARSE("pic_struct", value, ps_bitstrm, 4); 2313 ps_pic_timing->u4_pic_struct = value; 2314 2315 BITS_PARSE("source_scan_type", value, ps_bitstrm, 2); 2316 ps_pic_timing->u4_source_scan_type = value; 2317 2318 BITS_PARSE("duplicate_flag", value, ps_bitstrm, 1); 2319 ps_pic_timing->u1_duplicate_flag = value; 2320 } 2321 2322 if(ps_vui_hdr->u1_nal_hrd_parameters_present_flag 2323 || ps_vui_hdr->u1_vcl_hrd_parameters_present_flag) 2324 { 2325 u4_cpb_dpb_delays_present_flag = 1; 2326 } 2327 else 2328 { 2329 u4_cpb_dpb_delays_present_flag = 0; 2330 } 2331 2332 if(u4_cpb_dpb_delays_present_flag) 2333 { 2334 BITS_PARSE("au_cpb_removal_delay_minus1", value, ps_bitstrm, 2335 (ps_vui_hdr->u1_au_cpb_removal_delay_length_minus1 + 1)); 2336 ps_pic_timing->u4_au_cpb_removal_delay_minus1 = value; 2337 2338 BITS_PARSE("pic_dpb_output_delay", value, ps_bitstrm, 2339 (ps_vui_hdr->u1_dpb_output_delay_length_minus1 + 1)); 2340 ps_pic_timing->u4_pic_dpb_output_delay = value; 2341 2342 if(ps_vui_hdr->u1_sub_pic_cpb_params_present_flag) 2343 { 2344 BITS_PARSE("pic_dpb_output_du_delay", value, ps_bitstrm, 2345 (ps_vui_hdr->u1_dpb_output_delay_du_length_minus1 + 1)); 2346 ps_pic_timing->u4_pic_dpb_output_du_delay = value; 2347 } 2348 2349 if(ps_vui_hdr->u1_sub_pic_cpb_params_present_flag 2350 && ps_vui_hdr->u1_sub_pic_cpb_params_in_pic_timing_sei_flag) 2351 { 2352 UWORD32 num_units_minus1; 2353 UWORD32 array_size; 2354 2355 UEV_PARSE("num_decoding_units_minus1", value, ps_bitstrm); 2356 ps_pic_timing->u4_num_decoding_units_minus1 = value; 2357 2358 num_units_minus1 = ps_pic_timing->u4_num_decoding_units_minus1; 2359 array_size = (sizeof(ps_pic_timing->au4_num_nalus_in_du_minus1) 2360 / sizeof(ps_pic_timing->au4_num_nalus_in_du_minus1[0])); 2361 num_units_minus1 = CLIP3(num_units_minus1, 0,(array_size - 1)); 2362 ps_pic_timing->u4_num_decoding_units_minus1 = num_units_minus1; 2363 2364 BITS_PARSE("du_common_cpb_removal_delay_flag", value, ps_bitstrm, 1); 2365 ps_pic_timing->u1_du_common_cpb_removal_delay_flag = value; 2366 2367 if(ps_pic_timing->u1_du_common_cpb_removal_delay_flag) 2368 { 2369 BITS_PARSE("du_common_cpb_removal_delay_increment_minus1", 2370 value, 2371 ps_bitstrm, 2372 (ps_vui_hdr->u1_du_cpb_removal_delay_increment_length_minus1 2373 + 1)); 2374 ps_pic_timing->u4_du_common_cpb_removal_delay_increment_minus1 = 2375 value; 2376 } 2377 2378 for(i = 0; i <= ps_pic_timing->u4_num_decoding_units_minus1; i++) 2379 { 2380 UEV_PARSE("num_nalus_in_du_minus1", value, ps_bitstrm); 2381 ps_pic_timing->au4_num_nalus_in_du_minus1[i] = value; 2382 2383 if((!ps_pic_timing->u1_du_common_cpb_removal_delay_flag) 2384 && (i < ps_pic_timing->u4_num_decoding_units_minus1)) 2385 { 2386 BITS_PARSE("du_common_cpb_removal_delay_increment_minus1", 2387 value, 2388 ps_bitstrm, 2389 (ps_vui_hdr->u1_du_cpb_removal_delay_increment_length_minus1 2390 + 1)); 2391 ps_pic_timing->au4_du_cpb_removal_delay_increment_minus1[i] = 2392 value; 2393 } 2394 } 2395 } 2396 } 2397 2398 return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2399 } 2400 2401 IHEVCD_ERROR_T ihevcd_parse_time_code_sei(codec_t *ps_codec) 2402 { 2403 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2404 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2405 UWORD32 value; 2406 time_code_t *ps_time_code; 2407 WORD32 i; 2408 2409 ps_parse->s_sei_params.i1_time_code_present_flag = 1; 2410 ps_time_code = &ps_parse->s_sei_params.s_time_code; 2411 2412 BITS_PARSE("num_clock_ts", value, ps_bitstrm, 2); 2413 ps_time_code->u1_num_clock_ts = value; 2414 2415 for(i = 0; i < ps_time_code->u1_num_clock_ts; i++) 2416 { 2417 BITS_PARSE("clock_timestamp_flag[i]", value, ps_bitstrm, 1); 2418 ps_time_code->au1_clock_timestamp_flag[i] = value; 2419 2420 if(ps_time_code->au1_clock_timestamp_flag[i]) 2421 { 2422 BITS_PARSE("units_field_based_flag[i]", value, ps_bitstrm, 1); 2423 ps_time_code->au1_units_field_based_flag[i] = value; 2424 2425 BITS_PARSE("counting_type[i]", value, ps_bitstrm, 5); 2426 ps_time_code->au1_counting_type[i] = value; 2427 2428 BITS_PARSE("full_timestamp_flag[i]", value, ps_bitstrm, 1); 2429 ps_time_code->au1_full_timestamp_flag[i] = value; 2430 2431 BITS_PARSE("discontinuity_flag[i]", value, ps_bitstrm, 1); 2432 ps_time_code->au1_discontinuity_flag[i] = value; 2433 2434 BITS_PARSE("cnt_dropped_flag[i]", value, ps_bitstrm, 1); 2435 ps_time_code->au1_cnt_dropped_flag[i] = value; 2436 2437 BITS_PARSE("n_frames[i]", value, ps_bitstrm, 9); 2438 ps_time_code->au2_n_frames[i] = value; 2439 2440 if(ps_time_code->au1_full_timestamp_flag[i]) 2441 { 2442 BITS_PARSE("seconds_value[i]", value, ps_bitstrm, 6); 2443 ps_time_code->au1_seconds_value[i] = value; 2444 2445 BITS_PARSE("minutes_value[i]", value, ps_bitstrm, 6); 2446 ps_time_code->au1_minutes_value[i] = value; 2447 2448 BITS_PARSE("hours_value[i]", value, ps_bitstrm, 5); 2449 ps_time_code->au1_hours_value[i] = value; 2450 } 2451 else 2452 { 2453 BITS_PARSE("seconds_flag[i]", value, ps_bitstrm, 1); 2454 ps_time_code->au1_seconds_flag[i] = value; 2455 2456 if(ps_time_code->au1_seconds_flag[i]) 2457 { 2458 BITS_PARSE("seconds_value[i]", value, ps_bitstrm, 6); 2459 ps_time_code->au1_seconds_value[i] = value; 2460 2461 BITS_PARSE("minutes_flag[i]", value, ps_bitstrm, 1); 2462 ps_time_code->au1_minutes_flag[i] = value; 2463 2464 if(ps_time_code->au1_minutes_flag[i]) 2465 { 2466 BITS_PARSE("minutes_value[i]", value, ps_bitstrm, 6); 2467 ps_time_code->au1_minutes_value[i] = value; 2468 2469 BITS_PARSE("hours_flag[i]", value, ps_bitstrm, 1); 2470 ps_time_code->au1_hours_flag[i] = value; 2471 2472 if(ps_time_code->au1_hours_flag[i]) 2473 { 2474 BITS_PARSE("hours_value[i]", value, ps_bitstrm, 5); 2475 ps_time_code->au1_hours_value[i] = value; 2476 } 2477 } 2478 } 2479 } 2480 2481 BITS_PARSE("time_offset_length[i]", value, ps_bitstrm, 5); 2482 ps_time_code->au1_time_offset_length[i] = value; 2483 2484 if(ps_time_code->au1_time_offset_length[i] > 0) 2485 { 2486 BITS_PARSE("time_offset_value[i]", value, ps_bitstrm, 2487 ps_time_code->au1_time_offset_length[i]); 2488 ps_time_code->au1_time_offset_value[i] = value; 2489 } 2490 else 2491 { 2492 ps_time_code->au1_time_offset_value[i] = 0; 2493 } 2494 } 2495 } 2496 2497 return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2498 } 2499 2500 IHEVCD_ERROR_T ihevcd_parse_mastering_disp_params_sei(codec_t *ps_codec) 2501 { 2502 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2503 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2504 UWORD32 value; 2505 mastering_dis_col_vol_sei_params_t *ps_mastering_dis_col_vol; 2506 WORD32 i; 2507 2508 ps_parse->s_sei_params.i4_sei_mastering_disp_colour_vol_params_present_flags = 1; 2509 2510 ps_mastering_dis_col_vol = &ps_parse->s_sei_params.s_mastering_dis_col_vol_sei_params; 2511 2512 for(i = 0; i < 3; i++) 2513 { 2514 BITS_PARSE("display_primaries_x[c]", value, ps_bitstrm, 16); 2515 ps_mastering_dis_col_vol->au2_display_primaries_x[i] = value; 2516 2517 BITS_PARSE("display_primaries_y[c]", value, ps_bitstrm, 16); 2518 ps_mastering_dis_col_vol->au2_display_primaries_y[i] = value; 2519 } 2520 2521 BITS_PARSE("white_point_x", value, ps_bitstrm, 16); 2522 ps_mastering_dis_col_vol->u2_white_point_x = value; 2523 2524 BITS_PARSE("white_point_y", value, ps_bitstrm, 16); 2525 ps_mastering_dis_col_vol->u2_white_point_y = value; 2526 2527 BITS_PARSE("max_display_mastering_luminance", value, ps_bitstrm, 32); 2528 ps_mastering_dis_col_vol->u4_max_display_mastering_luminance = value; 2529 2530 BITS_PARSE("min_display_mastering_luminance", value, ps_bitstrm, 32); 2531 ps_mastering_dis_col_vol->u4_min_display_mastering_luminance = value; 2532 2533 return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2534 } 2535 2536 IHEVCD_ERROR_T ihevcd_parse_user_data_registered_itu_t_t35(codec_t *ps_codec, 2537 UWORD32 u4_payload_size) 2538 { 2539 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2540 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2541 UWORD32 value; 2542 user_data_registered_itu_t_t35_t *ps_user_data_registered_itu_t_t35; 2543 UWORD32 i; 2544 UWORD32 j = 0; 2545 2546 ps_parse->s_sei_params.i1_user_data_registered_present_flag = 1; 2547 ps_user_data_registered_itu_t_t35 = 2548 &ps_parse->s_sei_params.as_user_data_registered_itu_t_t35[ps_parse->s_sei_params.i4_sei_user_data_cnt]; 2549 ps_parse->s_sei_params.i4_sei_user_data_cnt++; 2550 2551 ps_user_data_registered_itu_t_t35->i4_payload_size = u4_payload_size; 2552 2553 if(u4_payload_size > MAX_USERDATA_PAYLOAD) 2554 { 2555 u4_payload_size = MAX_USERDATA_PAYLOAD; 2556 } 2557 2558 ps_user_data_registered_itu_t_t35->i4_valid_payload_size = u4_payload_size; 2559 2560 BITS_PARSE("itu_t_t35_country_code", value, ps_bitstrm, 8); 2561 ps_user_data_registered_itu_t_t35->u1_itu_t_t35_country_code = value; 2562 2563 if(0xFF != ps_user_data_registered_itu_t_t35->u1_itu_t_t35_country_code) 2564 { 2565 i = 1; 2566 } 2567 else 2568 { 2569 BITS_PARSE("itu_t_t35_country_code_extension_byte", value, ps_bitstrm, 2570 8); 2571 ps_user_data_registered_itu_t_t35->u1_itu_t_t35_country_code_extension_byte = 2572 value; 2573 2574 i = 2; 2575 } 2576 2577 do 2578 { 2579 BITS_PARSE("itu_t_t35_payload_byte", value, ps_bitstrm, 8); 2580 ps_user_data_registered_itu_t_t35->u1_itu_t_t35_payload_byte[j++] = 2581 value; 2582 2583 i++; 2584 }while(i < u4_payload_size); 2585 2586 return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2587 } 2588 2589 void ihevcd_parse_sei_payload(codec_t *ps_codec, 2590 UWORD32 u4_payload_type, 2591 UWORD32 u4_payload_size, 2592 WORD8 i1_nal_type) 2593 { 2594 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2595 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2596 WORD32 payload_bits_remaining = 0; 2597 sps_t *ps_sps; 2598 2599 UWORD32 i; 2600 2601 for(i = 0; i < MAX_SPS_CNT; i++) 2602 { 2603 ps_sps = ps_codec->ps_sps_base + i; 2604 if(ps_sps->i1_sps_valid) 2605 { 2606 break; 2607 } 2608 } 2609 if(NULL == ps_sps) 2610 { 2611 return; 2612 } 2613 2614 if(NAL_PREFIX_SEI == i1_nal_type) 2615 { 2616 switch(u4_payload_type) 2617 { 2618 case SEI_BUFFERING_PERIOD: 2619 ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; 2620 ihevcd_parse_buffering_period_sei(ps_codec, ps_sps); 2621 break; 2622 2623 case SEI_PICTURE_TIMING: 2624 ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; 2625 ihevcd_parse_pic_timing_sei(ps_codec, ps_sps); 2626 break; 2627 2628 case SEI_TIME_CODE: 2629 ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; 2630 ihevcd_parse_time_code_sei(ps_codec); 2631 break; 2632 2633 case SEI_MASTERING_DISPLAY_COLOUR_VOLUME: 2634 ps_parse->s_sei_params.i4_sei_mastering_disp_colour_vol_params_present_flags = 1; 2635 ihevcd_parse_mastering_disp_params_sei(ps_codec); 2636 break; 2637 2638 case SEI_USER_DATA_REGISTERED_ITU_T_T35: 2639 ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; 2640 if(ps_parse->s_sei_params.i4_sei_user_data_cnt >= USER_DATA_MAX) 2641 { 2642 for(i = 0; i < u4_payload_size / 4; i++) 2643 { 2644 ihevcd_bits_flush(ps_bitstrm, 4 * 8); 2645 } 2646 2647 ihevcd_bits_flush(ps_bitstrm, (u4_payload_size - i * 4) * 8); 2648 } 2649 else 2650 { 2651 ihevcd_parse_user_data_registered_itu_t_t35(ps_codec, 2652 u4_payload_size); 2653 } 2654 break; 2655 2656 default: 2657 for(i = 0; i < u4_payload_size; i++) 2658 { 2659 ihevcd_bits_flush(ps_bitstrm, 8); 2660 } 2661 break; 2662 } 2663 } 2664 else /* NAL_SUFFIX_SEI */ 2665 { 2666 switch(u4_payload_type) 2667 { 2668 case SEI_USER_DATA_REGISTERED_ITU_T_T35: 2669 ps_parse->s_sei_params.i1_sei_parameters_present_flag = 1; 2670 if(ps_parse->s_sei_params.i4_sei_user_data_cnt >= USER_DATA_MAX) 2671 { 2672 for(i = 0; i < u4_payload_size / 4; i++) 2673 { 2674 ihevcd_bits_flush(ps_bitstrm, 4 * 8); 2675 } 2676 2677 ihevcd_bits_flush(ps_bitstrm, (u4_payload_size - i * 4) * 8); 2678 } 2679 else 2680 { 2681 ihevcd_parse_user_data_registered_itu_t_t35(ps_codec, 2682 u4_payload_size); 2683 } 2684 break; 2685 2686 default: 2687 for(i = 0; i < u4_payload_size; i++) 2688 { 2689 ihevcd_bits_flush(ps_bitstrm, 8); 2690 } 2691 break; 2692 } 2693 } 2694 2695 /** 2696 * By definition the underlying bitstream terminates in a byte-aligned manner. 2697 * 1. Extract all bar the last MIN(bitsremaining,nine) bits as reserved_payload_extension_data 2698 * 2. Examine the final 8 bits to determine the payload_bit_equal_to_one marker 2699 * 3. Extract the remainingreserved_payload_extension_data bits. 2700 * 2701 * If there are fewer than 9 bits available, extract them. 2702 */ 2703 2704 payload_bits_remaining = ihevcd_bits_num_bits_remaining(ps_bitstrm); 2705 if(payload_bits_remaining) /* more_data_in_payload() */ 2706 { 2707 WORD32 final_bits; 2708 WORD32 final_payload_bits = 0; 2709 WORD32 mask = 0xFF; 2710 UWORD32 u4_dummy; 2711 UWORD32 u4_reserved_payload_extension_data; 2712 UNUSED(u4_dummy); 2713 UNUSED(u4_reserved_payload_extension_data); 2714 2715 while(payload_bits_remaining > 9) 2716 { 2717 BITS_PARSE("reserved_payload_extension_data", 2718 u4_reserved_payload_extension_data, ps_bitstrm, 1); 2719 payload_bits_remaining--; 2720 } 2721 2722 final_bits = ihevcd_bits_nxt(ps_bitstrm, payload_bits_remaining); 2723 2724 while(final_bits & (mask >> final_payload_bits)) 2725 { 2726 final_payload_bits++; 2727 continue; 2728 } 2729 2730 while(payload_bits_remaining > (9 - final_payload_bits)) 2731 { 2732 BITS_PARSE("reserved_payload_extension_data", 2733 u4_reserved_payload_extension_data, ps_bitstrm, 1); 2734 payload_bits_remaining--; 2735 } 2736 2737 BITS_PARSE("payload_bit_equal_to_one", u4_dummy, ps_bitstrm, 1); 2738 payload_bits_remaining--; 2739 while(payload_bits_remaining) 2740 { 2741 BITS_PARSE("payload_bit_equal_to_zero", u4_dummy, ps_bitstrm, 1); 2742 payload_bits_remaining--; 2743 } 2744 } 2745 2746 return; 2747 } 2748 2749 IHEVCD_ERROR_T ihevcd_read_rbsp_trailing_bits(codec_t *ps_codec, 2750 UWORD32 u4_bits_left) 2751 { 2752 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2753 UWORD32 value; 2754 WORD32 cnt = 0; 2755 BITS_PARSE("rbsp_stop_one_bit", value, &ps_parse->s_bitstrm, 1); 2756 u4_bits_left--; 2757 if(value != 1) 2758 { 2759 return (IHEVCD_ERROR_T)IHEVCD_FAIL; 2760 } 2761 while(u4_bits_left) 2762 { 2763 BITS_PARSE("rbsp_alignment_zero_bit", value, &ps_parse->s_bitstrm, 1); 2764 u4_bits_left--; 2765 cnt++; 2766 } 2767 ASSERT(cnt < 8); 2768 2769 return (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2770 } 2771 /** 2772 ******************************************************************************* 2773 * 2774 * @brief 2775 * Parses SEI (Supplemental Enhancement Information) 2776 * 2777 * @par Description: 2778 * Parses SEI (Supplemental Enhancement Information) as per Section: 7.3.7 2779 * 2780 * @param[in] ps_codec 2781 * Pointer to codec context 2782 * 2783 * @returns Error code from IHEVCD_ERROR_T 2784 * 2785 * @remarks 2786 * 2787 * 2788 ******************************************************************************* 2789 */ 2790 IHEVCD_ERROR_T ihevcd_parse_sei(codec_t *ps_codec, nal_header_t *ps_nal) 2791 { 2792 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2793 parse_ctxt_t *ps_parse = &ps_codec->s_parse; 2794 UWORD32 u4_payload_type = 0, u4_last_payload_type_byte = 0; 2795 UWORD32 u4_payload_size = 0, u4_last_payload_size_byte = 0; 2796 UWORD32 value; 2797 bitstrm_t *ps_bitstrm = &ps_parse->s_bitstrm; 2798 UWORD32 u4_bits_left; 2799 2800 u4_bits_left = ihevcd_bits_num_bits_remaining(ps_bitstrm); 2801 2802 while(u4_bits_left > 8) 2803 { 2804 while(ihevcd_bits_nxt(ps_bitstrm, 8) == 0xFF) 2805 { 2806 ihevcd_bits_flush(ps_bitstrm, 8); /* equal to 0xFF */ 2807 u4_payload_type += 255; 2808 } 2809 2810 BITS_PARSE("last_payload_type_byte", value, ps_bitstrm, 8); 2811 u4_last_payload_type_byte = value; 2812 2813 u4_payload_type += u4_last_payload_type_byte; 2814 2815 while(ihevcd_bits_nxt(ps_bitstrm, 8) == 0xFF) 2816 { 2817 ihevcd_bits_flush(ps_bitstrm, 8); /* equal to 0xFF */ 2818 u4_payload_size += 255; 2819 } 2820 2821 BITS_PARSE("last_payload_size_byte", value, ps_bitstrm, 8); 2822 u4_last_payload_size_byte = value; 2823 2824 u4_payload_size += u4_last_payload_size_byte; 2825 u4_bits_left = ihevcd_bits_num_bits_remaining(ps_bitstrm); 2826 u4_payload_size = MIN(u4_payload_size, u4_bits_left / 8); 2827 ihevcd_parse_sei_payload(ps_codec, u4_payload_type, u4_payload_size, 2828 ps_nal->i1_nal_unit_type); 2829 2830 /* Calculate the bits left in the current payload */ 2831 u4_bits_left = ihevcd_bits_num_bits_remaining(ps_bitstrm); 2832 } 2833 2834 // read rbsp_trailing_bits 2835 if(u4_bits_left) 2836 { 2837 ihevcd_read_rbsp_trailing_bits(ps_codec, u4_bits_left); 2838 } 2839 2840 return ret; 2841 } 2842 2843 /** 2844 ******************************************************************************* 2845 * 2846 * @brief 2847 * Parses Access unit delimiter 2848 * 2849 * @par Description: 2850 * Parses Access unit delimiter as per section Section: 7.3.2.5 2851 * 2852 * @param[in] ps_codec 2853 * Pointer to codec context 2854 * 2855 * @returns Error code from IHEVCD_ERROR_T 2856 * 2857 * @remarks 2858 * 2859 * 2860 ******************************************************************************* 2861 */ 2862 WORD32 ihevcd_parse_aud(codec_t *ps_codec) 2863 { 2864 IHEVCD_ERROR_T ret = (IHEVCD_ERROR_T)IHEVCD_SUCCESS; 2865 UNUSED(ps_codec); 2866 return ret; 2867 } 2868 2869 WORD32 ihevcd_extend_sign_bit(WORD32 value, WORD32 num_bits) 2870 { 2871 WORD32 ret_value = value; 2872 if(value >> (num_bits - 1)) 2873 { 2874 ret_value |= (0xFFFFFFFF << num_bits); 2875 } 2876 return ret_value; 2877 } 2878 2879 /** 2880 ******************************************************************************* 2881 * 2882 * @brief 2883 * Calculate POC of the current slice 2884 * 2885 * @par Description: 2886 * Calculates the current POC using the previous POC lsb and previous POC msb 2887 * 2888 * @param[in] ps_codec 2889 * Pointer to codec context 2890 * 2891 * @param[in] i1_pic_order_cnt_lsb 2892 * Current POC lsb 2893 * 2894 * @returns Current absolute POC 2895 * 2896 * @remarks 2897 * 2898 * 2899 ******************************************************************************* 2900 */ 2901 2902 WORD32 ihevcd_calc_poc(codec_t *ps_codec, nal_header_t *ps_nal, WORD8 i1_log2_max_poc_lsb, WORD32 i2_poc_lsb) 2903 { 2904 WORD32 i4_abs_poc, i4_poc_msb; 2905 WORD32 max_poc_lsb; 2906 WORD8 i1_nal_unit_type = ps_nal->i1_nal_unit_type; 2907 max_poc_lsb = (1 << i1_log2_max_poc_lsb); 2908 2909 if((!ps_codec->i4_first_pic_done) && (!ps_codec->i4_pic_present)) 2910 ps_codec->i4_prev_poc_msb = -2 * max_poc_lsb; 2911 2912 if(NAL_IDR_N_LP == i1_nal_unit_type 2913 || NAL_IDR_W_LP == i1_nal_unit_type 2914 || NAL_BLA_N_LP == i1_nal_unit_type 2915 || NAL_BLA_W_DLP == i1_nal_unit_type 2916 || NAL_BLA_W_LP == i1_nal_unit_type 2917 || (NAL_CRA == i1_nal_unit_type && !ps_codec->i4_first_pic_done)) 2918 { 2919 i4_poc_msb = ps_codec->i4_prev_poc_msb + 2 * max_poc_lsb; 2920 ps_codec->i4_prev_poc_lsb = 0; 2921 ps_codec->i4_max_prev_poc_lsb = 0; 2922 // ps_codec->i4_prev_poc_msb = 0; 2923 } 2924 else 2925 { 2926 2927 if((i2_poc_lsb < ps_codec->i4_prev_poc_lsb) 2928 && ((ps_codec->i4_prev_poc_lsb - i2_poc_lsb) >= max_poc_lsb / 2)) 2929 { 2930 i4_poc_msb = ps_codec->i4_prev_poc_msb + max_poc_lsb; 2931 } 2932 else if((i2_poc_lsb > ps_codec->i4_prev_poc_lsb) 2933 && ((i2_poc_lsb - ps_codec->i4_prev_poc_lsb) > max_poc_lsb / 2)) 2934 { 2935 i4_poc_msb = ps_codec->i4_prev_poc_msb - max_poc_lsb; 2936 } 2937 else 2938 { 2939 i4_poc_msb = ps_codec->i4_prev_poc_msb; 2940 } 2941 2942 2943 } 2944 2945 i4_abs_poc = i4_poc_msb + i2_poc_lsb; 2946 ps_codec->i4_max_prev_poc_lsb = MAX(ps_codec->i4_max_prev_poc_lsb, i2_poc_lsb); 2947 2948 { 2949 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)); 2950 WORD32 update_prev_poc = ((is_reference_nal) && ((i1_nal_unit_type < NAL_RADL_N) || (i1_nal_unit_type > NAL_RASL_R))); 2951 2952 if((0 == ps_nal->i1_nuh_temporal_id) && 2953 (update_prev_poc)) 2954 { 2955 ps_codec->i4_prev_poc_lsb = i2_poc_lsb; 2956 ps_codec->i4_prev_poc_msb = i4_poc_msb; 2957 } 2958 } 2959 2960 return i4_abs_poc; 2961 } 2962 2963 2964 void ihevcd_copy_slice_hdr(codec_t *ps_codec, WORD32 slice_idx, WORD32 slice_idx_ref) 2965 { 2966 slice_header_t *ps_slice_hdr, *ps_slice_hdr_ref; 2967 WORD32 *pu4_entry_offset_backup; 2968 2969 ps_slice_hdr = ps_codec->s_parse.ps_slice_hdr_base + slice_idx; 2970 ps_slice_hdr_ref = ps_codec->s_parse.ps_slice_hdr_base + slice_idx_ref; 2971 2972 pu4_entry_offset_backup = ps_slice_hdr->pu4_entry_point_offset; 2973 memcpy(ps_slice_hdr, ps_slice_hdr_ref, sizeof(slice_header_t)); 2974 ps_slice_hdr->pu4_entry_point_offset = pu4_entry_offset_backup; 2975 } 2976 2977 2978 2979