ih264d_parse_islice.c revision 8ef4c3f6142028732a155cbfc1febd6ef5da72fd
1/****************************************************************************** 2 * 3 * Copyright (C) 2015 The Android Open Source Project 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 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore 19*/ 20 21/*! 22 ************************************************************************** 23 * \file ih264d_parse_islice.c 24 * 25 * \brief 26 * Contains routines that decode a I slice type 27 * 28 * Detailed_description 29 * 30 * \date 31 * 07/07/2003 32 * 33 * \author NS 34 ************************************************************************** 35 */ 36#include "ih264d_error_handler.h" 37#include "ih264d_debug.h" 38#include <string.h> 39#include "ih264d_bitstrm.h" 40#include "ih264d_defs.h" 41#include "ih264d_debug.h" 42#include "ih264d_tables.h" 43#include "ih264d_structs.h" 44#include "ih264d_defs.h" 45#include "ih264d_parse_cavlc.h" 46#include "ih264d_mb_utils.h" 47#include "ih264d_deblocking.h" 48#include "ih264d_cabac.h" 49#include "ih264d_parse_cabac.h" 50#include "ih264d_parse_mb_header.h" 51#include "ih264d_parse_slice.h" 52#include "ih264d_process_pslice.h" 53#include "ih264d_process_intra_mb.h" 54#include "ih264d_parse_islice.h" 55#include "ih264d_error_handler.h" 56#include "ih264d_mvpred.h" 57#include "ih264d_defs.h" 58#include "ih264d_thread_parse_decode.h" 59#include "ithread.h" 60#include "ih264d_parse_mb_header.h" 61#include "assert.h" 62#include "ih264d_utils.h" 63#include "ih264d_format_conv.h" 64 65void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec); 66 67void ih264d_itrans_recon_luma_dc(dec_struct_t *ps_dec, 68 WORD16* pi2_src, 69 WORD16* pi2_coeff_block, 70 const UWORD16 *pu2_weigh_mat); 71 72 73 74/*! 75 ************************************************************************** 76 * \if Function name : ParseIMb \endif 77 * 78 * \brief 79 * This function parses CAVLC syntax of a I MB. If 16x16 Luma DC transform 80 * is also done here. Transformed Luma DC values are copied in their 81 * 0th pixel location of corrosponding CoeffBlock. 82 * 83 * \return 84 * 0 on Success and Error code otherwise 85 ************************************************************************** 86 */ 87WORD32 ih264d_parse_imb_cavlc(dec_struct_t * ps_dec, 88 dec_mb_info_t * ps_cur_mb_info, 89 UWORD8 u1_mb_num, 90 UWORD8 u1_mb_type) 91{ 92 WORD32 i4_delta_qp; 93 UWORD32 u4_temp; 94 UWORD32 ui_is_top_mb_available; 95 UWORD32 ui_is_left_mb_available; 96 UWORD32 u4_cbp; 97 UWORD32 u4_offset; 98 UWORD32 *pu4_bitstrm_buf; 99 WORD32 ret; 100 101 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm; 102 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst; 103 UNUSED(u1_mb_num); 104 ps_cur_mb_info->u1_tran_form8x8 = 0; 105 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0; 106 107 ps_cur_mb_info->u1_yuv_dc_block_flag = 0; 108 109 u4_temp = ps_dec->u1_mb_ngbr_availablity; 110 ui_is_top_mb_available = BOOLEAN(u4_temp & TOP_MB_AVAILABLE_MASK); 111 ui_is_left_mb_available = BOOLEAN(u4_temp & LEFT_MB_AVAILABLE_MASK); 112 113 pu4_bitstrm_buf = ps_bitstrm->pu4_buffer; 114 115 if(u1_mb_type == I_4x4_MB) 116 { 117 ps_cur_mb_info->ps_curmb->u1_mb_type = I_4x4_MB; 118 u4_offset = 0; 119 120 /*--------------------------------------------------------------------*/ 121 /* Read transform_size_8x8_flag if present */ 122 /*--------------------------------------------------------------------*/ 123 if(ps_dec->s_high_profile.u1_transform8x8_present) 124 { 125 ps_cur_mb_info->u1_tran_form8x8 = ih264d_get_bit_h264(ps_bitstrm); 126 COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8); 127 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8; 128 } 129 130 /*--------------------------------------------------------------------*/ 131 /* Read the IntraPrediction modes for LUMA */ 132 /*--------------------------------------------------------------------*/ 133 if (!ps_cur_mb_info->u1_tran_form8x8) 134 { 135 ih264d_read_intra_pred_modes(ps_dec, 136 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data), 137 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+16), 138 ps_cur_mb_info->u1_tran_form8x8); 139 UWORD8 *pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data; 140 pu1_temp += 32; 141 ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp; 142 } 143 else 144 { 145 ih264d_read_intra_pred_modes(ps_dec, 146 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data), 147 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+4), 148 ps_cur_mb_info->u1_tran_form8x8); 149 UWORD8 *pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data; 150 pu1_temp += 8; 151 ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp; 152 } 153 /*--------------------------------------------------------------------*/ 154 /* Read the IntraPrediction mode for CHROMA */ 155 /*--------------------------------------------------------------------*/ 156//Inlined ih264d_uev 157 { 158 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst; 159 UWORD32 u4_word, u4_ldz, u4_temp; 160 161 /***************************************************************/ 162 /* Find leading zeros in next 32 bits */ 163 /***************************************************************/ 164 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf); 165 u4_ldz = CLZ(u4_word); 166 /* Flush the ps_bitstrm */ 167 u4_bitstream_offset += (u4_ldz + 1); 168 /* Read the suffix from the ps_bitstrm */ 169 u4_word = 0; 170 if(u4_ldz) 171 { 172 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, 173 u4_ldz); 174 } 175 *pu4_bitstrm_ofst = u4_bitstream_offset; 176 u4_temp = ((1 << u4_ldz) + u4_word - 1); 177 if(u4_temp > 3) 178 { 179 return ERROR_CHROMA_PRED_MODE; 180 } 181 ps_cur_mb_info->u1_chroma_pred_mode = u4_temp; 182 COPYTHECONTEXT("intra_chroma_pred_mode", ps_cur_mb_info->u1_chroma_pred_mode); 183 } 184 /*--------------------------------------------------------------------*/ 185 /* Read the Coded block pattern */ 186 /*--------------------------------------------------------------------*/ 187 { 188 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst; 189 UWORD32 u4_word, u4_ldz; 190 191 /***************************************************************/ 192 /* Find leading zeros in next 32 bits */ 193 /***************************************************************/ 194 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf); 195 u4_ldz = CLZ(u4_word); 196 /* Flush the ps_bitstrm */ 197 u4_bitstream_offset += (u4_ldz + 1); 198 /* Read the suffix from the ps_bitstrm */ 199 u4_word = 0; 200 if(u4_ldz) 201 { 202 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, 203 u4_ldz); 204 } 205 *pu4_bitstrm_ofst = u4_bitstream_offset; 206 u4_cbp = ((1 << u4_ldz) + u4_word - 1); 207 } 208 if(u4_cbp > 47) 209 { 210 return ERROR_CBP; 211 } 212 213 u4_cbp = gau1_ih264d_cbp_table[u4_cbp][0]; 214 COPYTHECONTEXT("coded_block_pattern", u1_cbp); 215 ps_cur_mb_info->u1_cbp = u4_cbp; 216 217 /*--------------------------------------------------------------------*/ 218 /* Read mb_qp_delta */ 219 /*--------------------------------------------------------------------*/ 220 if(ps_cur_mb_info->u1_cbp) 221 { 222 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst; 223 UWORD32 u4_word, u4_ldz, u4_abs_val; 224 225 /***************************************************************/ 226 /* Find leading zeros in next 32 bits */ 227 /***************************************************************/ 228 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf); 229 u4_ldz = CLZ(u4_word); 230 231 /* Flush the ps_bitstrm */ 232 u4_bitstream_offset += (u4_ldz + 1); 233 234 /* Read the suffix from the ps_bitstrm */ 235 u4_word = 0; 236 if(u4_ldz) 237 { 238 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, 239 u4_ldz); 240 } 241 242 *pu4_bitstrm_ofst = u4_bitstream_offset; 243 u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1; 244 245 if(u4_word & 0x1) 246 { 247 i4_delta_qp = (-(WORD32)u4_abs_val); 248 } 249 else 250 { 251 i4_delta_qp = (u4_abs_val); 252 } 253 254 if((i4_delta_qp < -26) || (i4_delta_qp > 25)) 255 { 256 return ERROR_INV_RANGE_QP_T; 257 } 258 259 COPYTHECONTEXT("mb_qp_delta", i1_delta_qp); 260 if(i4_delta_qp != 0) 261 { 262 ret = ih264d_update_qp(ps_dec, (WORD8)i4_delta_qp); 263 if(ret != OK) 264 return ret; 265 } 266 } 267 268 } 269 else 270 { 271 u4_offset = 1; 272 ps_cur_mb_info->ps_curmb->u1_mb_type = I_16x16_MB; 273 /*-------------------------------------------------------------------*/ 274 /* Read the IntraPrediction mode for CHROMA */ 275 /*-------------------------------------------------------------------*/ 276 { 277 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst; 278 UWORD32 u4_word, u4_ldz; 279 280 /***************************************************************/ 281 /* Find leading zeros in next 32 bits */ 282 /***************************************************************/ 283 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf); 284 u4_ldz = CLZ(u4_word); 285 /* Flush the ps_bitstrm */ 286 u4_bitstream_offset += (u4_ldz + 1); 287 /* Read the suffix from the ps_bitstrm */ 288 u4_word = 0; 289 if(u4_ldz) 290 { 291 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, 292 u4_ldz); 293 } 294 *pu4_bitstrm_ofst = u4_bitstream_offset; 295 u4_temp = ((1 << u4_ldz) + u4_word - 1); 296 297//Inlined ih264d_uev 298 299 if(u4_temp > 3) 300 { 301 return ERROR_CHROMA_PRED_MODE; 302 } 303 ps_cur_mb_info->u1_chroma_pred_mode = u4_temp; 304 COPYTHECONTEXT("intra_chroma_pred_mode", ps_cur_mb_info->u1_chroma_pred_mode); 305 } 306 /*-------------------------------------------------------------------*/ 307 /* Read the Coded block pattern */ 308 /*-------------------------------------------------------------------*/ 309 u4_cbp = gau1_ih264d_cbp_tab[(u1_mb_type - 1) >> 2]; 310 ps_cur_mb_info->u1_cbp = u4_cbp; 311 312 /*-------------------------------------------------------------------*/ 313 /* Read mb_qp_delta */ 314 /*-------------------------------------------------------------------*/ 315 { 316 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst; 317 UWORD32 u4_word, u4_ldz, u4_abs_val; 318 319 /***************************************************************/ 320 /* Find leading zeros in next 32 bits */ 321 /***************************************************************/ 322 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf); 323 u4_ldz = CLZ(u4_word); 324 325 /* Flush the ps_bitstrm */ 326 u4_bitstream_offset += (u4_ldz + 1); 327 328 /* Read the suffix from the ps_bitstrm */ 329 u4_word = 0; 330 if(u4_ldz) 331 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, 332 u4_ldz); 333 334 *pu4_bitstrm_ofst = u4_bitstream_offset; 335 u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1; 336 337 if(u4_word & 0x1) 338 i4_delta_qp = (-(WORD32)u4_abs_val); 339 else 340 i4_delta_qp = (u4_abs_val); 341 342 if((i4_delta_qp < -26) || (i4_delta_qp > 25)) 343 return ERROR_INV_RANGE_QP_T; 344 345 } 346//inlinined ih264d_sev 347 COPYTHECONTEXT("Delta quant", i1_delta_qp); 348 349 if(i4_delta_qp != 0) 350 { 351 ret = ih264d_update_qp(ps_dec, (WORD8)i4_delta_qp); 352 if(ret != OK) 353 return ret; 354 } 355 356 { 357 WORD16 i_scaleFactor; 358 UWORD32 ui_N = 0; 359 WORD16 *pi2_scale_matrix_ptr; 360 /*******************************************************************/ 361 /* for luma DC coefficients the scaling is done during the parsing */ 362 /* to preserve the precision */ 363 /*******************************************************************/ 364 if(ps_dec->s_high_profile.u1_scaling_present) 365 { 366 pi2_scale_matrix_ptr = 367 ps_dec->s_high_profile.i2_scalinglist4x4[0]; 368 } 369 else 370 { 371 i_scaleFactor = 16; 372 pi2_scale_matrix_ptr = &i_scaleFactor; 373 } 374 375 /*---------------------------------------------------------------*/ 376 /* Decode DC coefficients */ 377 /*---------------------------------------------------------------*/ 378 /*---------------------------------------------------------------*/ 379 /* Calculation of N */ 380 /*---------------------------------------------------------------*/ 381 if(ui_is_left_mb_available) 382 { 383 384 if(ui_is_top_mb_available) 385 { 386 ui_N = ((ps_cur_mb_info->ps_top_mb->pu1_nnz_y[0] 387 + ps_dec->pu1_left_nnz_y[0] + 1) >> 1); 388 } 389 else 390 { 391 ui_N = ps_dec->pu1_left_nnz_y[0]; 392 } 393 } 394 else if(ui_is_top_mb_available) 395 { 396 ui_N = ps_cur_mb_info->ps_top_mb->pu1_nnz_y[0]; 397 } 398 399 { 400 WORD16 pi2_dc_coef[16]; 401 WORD32 pi4_tmp[16]; 402 tu_sblk4x4_coeff_data_t *ps_tu_4x4 = 403 (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data; 404 WORD16 *pi2_coeff_block = 405 (WORD16 *)ps_dec->pv_parse_tu_coeff_data; 406 ps_tu_4x4->u2_sig_coeff_map = 0; 407 UWORD32 u4_num_coeff; 408 409 ret = ps_dec->pf_cavlc_parse4x4coeff[(ui_N > 7)](pi2_dc_coef, 0, ui_N, 410 ps_dec, &u4_num_coeff); 411 if(ret != OK) 412 return ret; 413 414 if(EXCEED_OFFSET(ps_bitstrm)) 415 return ERROR_EOB_TERMINATE_T; 416 if(ps_tu_4x4->u2_sig_coeff_map) 417 { 418 memset(pi2_dc_coef,0,sizeof(pi2_dc_coef)); 419 ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4, 420 pi2_dc_coef, 421 ps_dec->pu1_inv_scan); 422 423 PROFILE_DISABLE_IQ_IT_RECON() 424 ps_dec->pf_ihadamard_scaling_4x4(pi2_dc_coef, 425 pi2_coeff_block, 426 ps_dec->pu2_quant_scale_y, 427 (UWORD16 *)pi2_scale_matrix_ptr, 428 ps_dec->u1_qp_y_div6, 429 pi4_tmp); 430 pi2_coeff_block += 16; 431 ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_block; 432 SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,0); 433 } 434 435 } 436 } 437 } 438 439 440 if(u4_cbp) 441 { 442 443 ret = ih264d_parse_residual4x4_cavlc(ps_dec, ps_cur_mb_info, 444 (UWORD8)u4_offset); 445 if(ret != OK) 446 return ret; 447 if(EXCEED_OFFSET(ps_bitstrm)) 448 return ERROR_EOB_TERMINATE_T; 449 450 /* Store Left Mb NNZ and TOP chroma NNZ */ 451 } 452 else 453 { 454 ps_cur_mb_info->u1_qp_div6 = ps_dec->u1_qp_y_div6; 455 ps_cur_mb_info->u1_qpc_div6 = ps_dec->u1_qp_u_div6; 456 ps_cur_mb_info->u1_qpcr_div6 = ps_dec->u1_qp_v_div6; 457 ps_cur_mb_info->u1_qp_rem6 = ps_dec->u1_qp_y_rem6; 458 ps_cur_mb_info->u1_qpc_rem6 = ps_dec->u1_qp_u_rem6; 459 ps_cur_mb_info->u1_qpcr_rem6 = ps_dec->u1_qp_v_rem6; 460 ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CAVLC); 461 } 462 463 return OK; 464} 465 466/*! 467 ************************************************************************** 468 * \if Function name : ParseIMbCab \endif 469 * 470 * \brief 471 * This function parses CABAC syntax of a I MB. If 16x16 Luma DC transform 472 * is also done here. Transformed Luma DC values are copied in their 473 * 0th pixel location of corrosponding CoeffBlock. 474 * 475 * \return 476 * 0 on Success and Error code otherwise 477 ************************************************************************** 478 */ 479WORD32 ih264d_parse_imb_cabac(dec_struct_t * ps_dec, 480 dec_mb_info_t * ps_cur_mb_info, 481 UWORD8 u1_mb_type) 482{ 483 WORD8 i1_delta_qp; 484 UWORD8 u1_cbp; 485 UWORD8 u1_offset; 486 /* Variables for handling Cabac contexts */ 487 ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info; 488 ctxt_inc_mb_info_t *ps_left_ctxt = ps_dec->p_left_ctxt_mb_info; 489 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm; 490 bin_ctxt_model_t *p_bin_ctxt; 491 492 UWORD8 u1_intra_chrom_pred_mode; 493 UWORD8 u1_dc_block_flag = 0; 494 WORD32 ret; 495 496 ps_cur_mb_info->u1_yuv_dc_block_flag = 0; 497 498 if(ps_left_ctxt == ps_dec->ps_def_ctxt_mb_info) 499 { 500 ps_dec->pu1_left_yuv_dc_csbp[0] = 0xf; 501 } 502 503 if(ps_dec->ps_cur_slice->u1_slice_type != I_SLICE) 504 { 505 WORD32 *pi4_buf; 506 WORD8 *pi1_buf; 507 MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0); 508 *((UWORD32 *)ps_dec->pi1_left_ref_idx_ctxt_inc) = 0; 509 MEMSET_16BYTES(p_curr_ctxt->u1_mv, 0); 510 pi1_buf = p_curr_ctxt->i1_ref_idx; 511 pi4_buf = (WORD32 *)pi1_buf; 512 *pi4_buf = 0; 513 } 514 515 if(u1_mb_type == I_4x4_MB) 516 { 517 ps_cur_mb_info->ps_curmb->u1_mb_type = I_4x4_MB; 518 p_curr_ctxt->u1_mb_type = CAB_I4x4; 519 u1_offset = 0; 520 521 ps_cur_mb_info->u1_tran_form8x8 = 0; 522 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0; 523 524 /*--------------------------------------------------------------------*/ 525 /* Read transform_size_8x8_flag if present */ 526 /*--------------------------------------------------------------------*/ 527 if(ps_dec->s_high_profile.u1_transform8x8_present) 528 { 529 ps_cur_mb_info->u1_tran_form8x8 = ih264d_parse_transform8x8flag_cabac( 530 ps_dec, ps_cur_mb_info); 531 COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8); 532 p_curr_ctxt->u1_transform8x8_ctxt = ps_cur_mb_info->u1_tran_form8x8; 533 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8; 534 } 535 else 536 { 537 p_curr_ctxt->u1_transform8x8_ctxt = 0; 538 } 539 540 /*--------------------------------------------------------------------*/ 541 /* Read the IntraPrediction modes for LUMA */ 542 /*--------------------------------------------------------------------*/ 543 if (!ps_cur_mb_info->u1_tran_form8x8) 544 { 545 ih264d_read_intra_pred_modes_cabac( 546 ps_dec, 547 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data), 548 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+16), 549 ps_cur_mb_info->u1_tran_form8x8); 550 UWORD8 *pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data; 551 pu1_temp += 32; 552 ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp; 553 } 554 else 555 { 556 ih264d_read_intra_pred_modes_cabac( 557 ps_dec, 558 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data), 559 ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+4), 560 ps_cur_mb_info->u1_tran_form8x8); 561 UWORD8 *pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data; 562 pu1_temp += 8; 563 ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp; 564 } 565 /*--------------------------------------------------------------------*/ 566 /* Read the IntraPrediction mode for CHROMA */ 567 /*--------------------------------------------------------------------*/ 568 u1_intra_chrom_pred_mode = ih264d_parse_chroma_pred_mode_cabac(ps_dec); 569 COPYTHECONTEXT("intra_chroma_pred_mode", u1_intra_chrom_pred_mode); 570 p_curr_ctxt->u1_intra_chroma_pred_mode = ps_cur_mb_info->u1_chroma_pred_mode = 571 u1_intra_chrom_pred_mode; 572 573 /*--------------------------------------------------------------------*/ 574 /* Read the Coded block pattern */ 575 /*--------------------------------------------------------------------*/ 576 u1_cbp = ih264d_parse_ctx_cbp_cabac(ps_dec); 577 COPYTHECONTEXT("coded_block_pattern", u1_cbp); 578 ps_cur_mb_info->u1_cbp = u1_cbp; 579 p_curr_ctxt->u1_cbp = u1_cbp; 580 581 /*--------------------------------------------------------------------*/ 582 /* Read mb_qp_delta */ 583 /*--------------------------------------------------------------------*/ 584 if(ps_cur_mb_info->u1_cbp) 585 { 586 ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &i1_delta_qp); 587 if(ret != OK) 588 return ret; 589 COPYTHECONTEXT("mb_qp_delta", i1_delta_qp); 590 if(i1_delta_qp != 0) 591 { 592 ret = ih264d_update_qp(ps_dec, i1_delta_qp); 593 if(ret != OK) 594 return ret; 595 } 596 } 597 else 598 ps_dec->i1_prev_mb_qp_delta = 0; 599 p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE; 600 } 601 else 602 { 603 u1_offset = 1; 604 ps_cur_mb_info->ps_curmb->u1_mb_type = I_16x16_MB; 605 p_curr_ctxt->u1_mb_type = CAB_I16x16; 606 ps_cur_mb_info->u1_tran_form8x8 = 0; 607 p_curr_ctxt->u1_transform8x8_ctxt = 0; 608 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0; 609 /*--------------------------------------------------------------------*/ 610 /* Read the IntraPrediction mode for CHROMA */ 611 /*--------------------------------------------------------------------*/ 612 u1_intra_chrom_pred_mode = ih264d_parse_chroma_pred_mode_cabac(ps_dec); 613 if(u1_intra_chrom_pred_mode > 3) 614 return ERROR_CHROMA_PRED_MODE; 615 616 COPYTHECONTEXT("Chroma intra_chroma_pred_mode pred mode", u1_intra_chrom_pred_mode); 617 p_curr_ctxt->u1_intra_chroma_pred_mode = ps_cur_mb_info->u1_chroma_pred_mode = 618 u1_intra_chrom_pred_mode; 619 620 /*--------------------------------------------------------------------*/ 621 /* Read the Coded block pattern */ 622 /*--------------------------------------------------------------------*/ 623 u1_cbp = gau1_ih264d_cbp_tab[(u1_mb_type - 1) >> 2]; 624 ps_cur_mb_info->u1_cbp = u1_cbp; 625 p_curr_ctxt->u1_cbp = u1_cbp; 626 627 /*--------------------------------------------------------------------*/ 628 /* Read mb_qp_delta */ 629 /*--------------------------------------------------------------------*/ 630 ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &i1_delta_qp); 631 if(ret != OK) 632 return ret; 633 COPYTHECONTEXT("mb_qp_delta", i1_delta_qp); 634 if(i1_delta_qp != 0) 635 { 636 ret = ih264d_update_qp(ps_dec, i1_delta_qp); 637 if(ret != OK) 638 return ret; 639 } 640 641 { 642 WORD16 i_scaleFactor; 643 WORD16* pi2_scale_matrix_ptr; 644 /*******************************************************************/ 645 /* for luma DC coefficients the scaling is done during the parsing */ 646 /* to preserve the precision */ 647 /*******************************************************************/ 648 if(ps_dec->s_high_profile.u1_scaling_present) 649 { 650 pi2_scale_matrix_ptr = 651 ps_dec->s_high_profile.i2_scalinglist4x4[0]; 652 653 } 654 else 655 { 656 i_scaleFactor = 16; 657 pi2_scale_matrix_ptr = &i_scaleFactor; 658 } 659 { 660 ctxt_inc_mb_info_t *ps_top_ctxt = ps_dec->p_top_ctxt_mb_info; 661 UWORD8 uc_a, uc_b; 662 UWORD32 u4_ctx_inc; 663 664 INC_SYM_COUNT(&(ps_dec->s_cab_dec_env)); 665 666 /* if MbAddrN not available then CondTermN = 1 */ 667 uc_b = ((ps_top_ctxt->u1_yuv_dc_csbp) & 0x01); 668 669 /* if MbAddrN not available then CondTermN = 1 */ 670 uc_a = ((ps_dec->pu1_left_yuv_dc_csbp[0]) & 0x01); 671 672 u4_ctx_inc = (uc_a + (uc_b << 1)); 673 674 { 675 WORD16 pi2_dc_coef[16]; 676 tu_sblk4x4_coeff_data_t *ps_tu_4x4 = 677 (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data; 678 WORD16 *pi2_coeff_block = 679 (WORD16 *)ps_dec->pv_parse_tu_coeff_data; 680 681 p_bin_ctxt = (ps_dec->p_cbf_t[LUMA_DC_CTXCAT]) + u4_ctx_inc; 682 683 u1_dc_block_flag = 684 ih264d_read_coeff4x4_cabac(ps_bitstrm, 685 LUMA_DC_CTXCAT, 686 ps_dec->p_significant_coeff_flag_t[LUMA_DC_CTXCAT], 687 ps_dec, p_bin_ctxt); 688 689 /* Store coded_block_flag */ 690 p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE; 691 p_curr_ctxt->u1_yuv_dc_csbp |= u1_dc_block_flag; 692 if(u1_dc_block_flag) 693 { 694 WORD32 pi4_tmp[16]; 695 memset(pi2_dc_coef,0,sizeof(pi2_dc_coef)); 696 ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4, 697 pi2_dc_coef, 698 ps_dec->pu1_inv_scan); 699 700 PROFILE_DISABLE_IQ_IT_RECON() 701 ps_dec->pf_ihadamard_scaling_4x4(pi2_dc_coef, 702 pi2_coeff_block, 703 ps_dec->pu2_quant_scale_y, 704 (UWORD16 *)pi2_scale_matrix_ptr, 705 ps_dec->u1_qp_y_div6, 706 pi4_tmp); 707 pi2_coeff_block += 16; 708 ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_block; 709 SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,0); 710 } 711 712 } 713 714 } 715 } 716 } 717 718 ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x6; 719 ps_dec->pu1_left_yuv_dc_csbp[0] |= u1_dc_block_flag; 720 721 ih264d_parse_residual4x4_cabac(ps_dec, ps_cur_mb_info, u1_offset); 722 if(EXCEED_OFFSET(ps_bitstrm)) 723 return ERROR_EOB_TERMINATE_T; 724 return OK; 725} 726 727/*****************************************************************************/ 728/* */ 729/* Function Name : ih264d_parse_islice_data_cavlc */ 730/* */ 731/* Description : This function parses cabac syntax of a inter slice on */ 732/* N MB basis. */ 733/* */ 734/* Inputs : ps_dec */ 735/* sliceparams */ 736/* firstMbInSlice */ 737/* */ 738/* Processing : 1. After parsing syntax for N MBs those N MBs are */ 739/* decoded till the end of slice. */ 740/* */ 741/* Returns : 0 */ 742/* */ 743/* Issues : <List any issues or problems with this function> */ 744/* */ 745/* Revision History: */ 746/* */ 747/* DD MM YYYY Author(s) Changes (Describe the changes made) */ 748/* 24 06 2005 ARNY Draft */ 749/* */ 750/*****************************************************************************/ 751WORD32 ih264d_parse_islice_data_cavlc(dec_struct_t * ps_dec, 752 dec_slice_params_t * ps_slice, 753 UWORD16 u2_first_mb_in_slice) 754{ 755 UWORD8 uc_more_data_flag; 756 UWORD8 u1_num_mbs, u1_mb_idx; 757 dec_mb_info_t *ps_cur_mb_info; 758 deblk_mb_t *ps_cur_deblk_mb; 759 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm; 760 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst; 761 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer; 762 UWORD16 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs; 763 WORD16 i2_cur_mb_addr; 764 UWORD8 u1_mbaff; 765 UWORD8 u1_num_mbs_next, u1_end_of_row, u1_tfr_n_mb; 766 WORD32 ret = OK; 767 768 ps_dec->u1_qp = ps_slice->u1_slice_qp; 769 ih264d_update_qp(ps_dec, 0); 770 u1_mbaff = ps_slice->u1_mbaff_frame_flag; 771 772 /* initializations */ 773 u1_mb_idx = ps_dec->u1_mb_idx; 774 u1_num_mbs = u1_mb_idx; 775 776 uc_more_data_flag = 1; 777 i2_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff; 778 779 do 780 { 781 UWORD8 u1_mb_type; 782 783 ps_dec->pv_prev_mb_parse_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data; 784 785 if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr) 786 { 787 ret = ERROR_MB_ADDRESS_T; 788 break; 789 } 790 791 ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs; 792 ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs; 793 ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff); 794 795 ps_cur_mb_info->u1_end_of_slice = 0; 796 797 /***************************************************************/ 798 /* Get the required information for decoding of MB */ 799 /* mb_x, mb_y , neighbour availablity, */ 800 /***************************************************************/ 801 ps_dec->pf_get_mb_info(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, 0); 802 803 /***************************************************************/ 804 /* Set the deblocking parameters for this MB */ 805 /***************************************************************/ 806 ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs; 807 808 if(ps_dec->u4_app_disable_deblk_frm == 0) 809 ih264d_set_deblocking_parameters(ps_cur_deblk_mb, ps_slice, 810 ps_dec->u1_mb_ngbr_availablity, 811 ps_dec->u1_cur_mb_fld_dec_flag); 812 813 ps_cur_deblk_mb->u1_mb_type = ps_cur_deblk_mb->u1_mb_type | D_INTRA_MB; 814 815 /**************************************************************/ 816 /* Macroblock Layer Begins, Decode the u1_mb_type */ 817 /**************************************************************/ 818//Inlined ih264d_uev 819 { 820 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst; 821 UWORD32 u4_word, u4_ldz, u4_temp; 822 823 /***************************************************************/ 824 /* Find leading zeros in next 32 bits */ 825 /***************************************************************/ 826 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf); 827 u4_ldz = CLZ(u4_word); 828 /* Flush the ps_bitstrm */ 829 u4_bitstream_offset += (u4_ldz + 1); 830 /* Read the suffix from the ps_bitstrm */ 831 u4_word = 0; 832 if(u4_ldz) 833 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, 834 u4_ldz); 835 *pu4_bitstrm_ofst = u4_bitstream_offset; 836 u4_temp = ((1 << u4_ldz) + u4_word - 1); 837 if(u4_temp > 25) 838 return ERROR_MB_TYPE; 839 u1_mb_type = u4_temp; 840 841 } 842//Inlined ih264d_uev 843 ps_cur_mb_info->u1_mb_type = u1_mb_type; 844 COPYTHECONTEXT("u1_mb_type", u1_mb_type); 845 846 /**************************************************************/ 847 /* Parse Macroblock data */ 848 /**************************************************************/ 849 if(25 == u1_mb_type) 850 { 851 /* I_PCM_MB */ 852 ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB; 853 ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u1_num_mbs); 854 if(ret != OK) 855 return ret; 856 ps_cur_deblk_mb->u1_mb_qp = 0; 857 } 858 else 859 { 860 ret = ih264d_parse_imb_cavlc(ps_dec, ps_cur_mb_info, u1_num_mbs, u1_mb_type); 861 if(ret != OK) 862 return ret; 863 ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp; 864 } 865 866 if(u1_mbaff) 867 { 868 ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info); 869 } 870 /**************************************************************/ 871 /* Get next Macroblock address */ 872 /**************************************************************/ 873 874 i2_cur_mb_addr++; 875 uc_more_data_flag = MORE_RBSP_DATA(ps_bitstrm); 876 877 /* Store the colocated information */ 878 { 879 mv_pred_t *ps_mv_nmb_start = ps_dec->ps_mv_cur + (u1_num_mbs << 4); 880 881 mv_pred_t s_mvPred = 882 { 883 { 0, 0, 0, 0 }, 884 { -1, -1 }, 0, 0}; 885 ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0, 886 (UWORD8)(ps_dec->u1_cur_mb_fld_dec_flag << 1), 4, 887 4); 888 } 889 890 /*if num _cores is set to 3,compute bs will be done in another thread*/ 891 if(ps_dec->u4_num_cores < 3) 892 { 893 if(ps_dec->u4_app_disable_deblk_frm == 0) 894 ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info, 895 (UWORD16)(u1_num_mbs >> u1_mbaff)); 896 } 897 u1_num_mbs++; 898 ps_dec->u2_total_mbs_coded++; 899 900 /****************************************************************/ 901 /* Check for End Of Row */ 902 /****************************************************************/ 903 u1_num_mbs_next = i2_pic_wdin_mbs - ps_dec->u2_mbx - 1; 904 u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01))); 905 u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row 906 || (!uc_more_data_flag); 907 ps_cur_mb_info->u1_end_of_slice = (!uc_more_data_flag); 908 909 /*H264_DEC_DEBUG_PRINT("Pic: %d Mb_X=%d Mb_Y=%d", 910 ps_slice->i4_poc >> ps_slice->u1_field_pic_flag, 911 ps_dec->u2_mbx,ps_dec->u2_mby + (1 - ps_cur_mb_info->u1_topmb)); 912 H264_DEC_DEBUG_PRINT("u1_tfr_n_mb || (!uc_more_data_flag): %d", u1_tfr_n_mb || (!uc_more_data_flag));*/ 913 if(u1_tfr_n_mb || (!uc_more_data_flag)) 914 { 915 916 if(ps_dec->u1_separate_parse) 917 { 918 ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs, 919 u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row); 920 ps_dec->ps_nmb_info += u1_num_mbs; 921 } 922 else 923 { 924 ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs, 925 u1_num_mbs_next, u1_tfr_n_mb, 926 u1_end_of_row); 927 } 928 929 if(u1_tfr_n_mb) 930 u1_num_mbs = 0; 931 u1_mb_idx = u1_num_mbs; 932 ps_dec->u1_mb_idx = u1_num_mbs; 933 934 } 935 } 936 while(uc_more_data_flag); 937 938 ps_dec->u4_num_mbs_cur_nmb = 0; 939 ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr 940 941 - (u2_first_mb_in_slice << u1_mbaff); 942 943 return ret; 944} 945 946/*****************************************************************************/ 947/* */ 948/* Function Name : ih264d_parse_islice_data_cabac */ 949/* */ 950/* Description : This function parses cabac syntax of a inter slice on */ 951/* N MB basis. */ 952/* */ 953/* Inputs : ps_dec */ 954/* sliceparams */ 955/* firstMbInSlice */ 956/* */ 957/* Processing : 1. After parsing syntax for N MBs those N MBs are */ 958/* decoded till the end of slice. */ 959/* */ 960/* Returns : 0 */ 961/* */ 962/* Issues : <List any issues or problems with this function> */ 963/* */ 964/* Revision History: */ 965/* */ 966/* DD MM YYYY Author(s) Changes (Describe the changes made) */ 967/* 24 06 2005 ARNY Draft */ 968/* */ 969/*****************************************************************************/ 970WORD32 ih264d_parse_islice_data_cabac(dec_struct_t * ps_dec, 971 dec_slice_params_t * ps_slice, 972 UWORD16 u2_first_mb_in_slice) 973{ 974 UWORD8 uc_more_data_flag; 975 UWORD8 u1_num_mbs, u1_mb_idx; 976 dec_mb_info_t *ps_cur_mb_info; 977 deblk_mb_t *ps_cur_deblk_mb; 978 979 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm; 980 UWORD16 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs; 981 WORD16 i2_cur_mb_addr; 982 UWORD8 u1_mbaff; 983 UWORD8 u1_num_mbs_next, u1_end_of_row, u1_tfr_n_mb; 984 WORD32 ret = OK; 985 986 ps_dec->u1_qp = ps_slice->u1_slice_qp; 987 ih264d_update_qp(ps_dec, 0); 988 u1_mbaff = ps_slice->u1_mbaff_frame_flag; 989 990 if(ps_bitstrm->u4_ofst & 0x07) 991 { 992 ps_bitstrm->u4_ofst += 8; 993 ps_bitstrm->u4_ofst &= 0xFFFFFFF8; 994 } 995 ret = ih264d_init_cabac_dec_envirnoment(&(ps_dec->s_cab_dec_env), ps_bitstrm); 996 if(ret != OK) 997 return ret; 998 ih264d_init_cabac_contexts(I_SLICE, ps_dec); 999 1000 ps_dec->i1_prev_mb_qp_delta = 0; 1001 1002 /* initializations */ 1003 u1_mb_idx = ps_dec->u1_mb_idx; 1004 u1_num_mbs = u1_mb_idx; 1005 1006 uc_more_data_flag = 1; 1007 i2_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff; 1008 do 1009 { 1010 UWORD16 u2_mbx; 1011 1012 ps_dec->pv_prev_mb_parse_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data; 1013 1014 if(i2_cur_mb_addr > ps_dec->ps_cur_sps->u2_max_mb_addr) 1015 { 1016 ret = ERROR_MB_ADDRESS_T; 1017 break; 1018 } 1019 1020 { 1021 UWORD8 u1_mb_type; 1022 1023 ps_cur_mb_info = ps_dec->ps_nmb_info + u1_num_mbs; 1024 ps_dec->u4_num_mbs_cur_nmb = u1_num_mbs; 1025 ps_dec->u4_num_pmbair = (u1_num_mbs >> u1_mbaff); 1026 1027 ps_cur_mb_info->u1_end_of_slice = 0; 1028 1029 /***************************************************************/ 1030 /* Get the required information for decoding of MB */ 1031 /* mb_x, mb_y , neighbour availablity, */ 1032 /***************************************************************/ 1033 ps_dec->pf_get_mb_info(ps_dec, i2_cur_mb_addr, ps_cur_mb_info, 0); 1034 u2_mbx = ps_dec->u2_mbx; 1035 1036 /*********************************************************************/ 1037 /* initialize u1_tran_form8x8 to zero to aviod uninitialized accesses */ 1038 /*********************************************************************/ 1039 ps_cur_mb_info->u1_tran_form8x8 = 0; 1040 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0; 1041 1042 /***************************************************************/ 1043 /* Set the deblocking parameters for this MB */ 1044 /***************************************************************/ 1045 ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_num_mbs; 1046 if(ps_dec->u4_app_disable_deblk_frm == 0) 1047 ih264d_set_deblocking_parameters( 1048 ps_cur_deblk_mb, ps_slice, 1049 ps_dec->u1_mb_ngbr_availablity, 1050 ps_dec->u1_cur_mb_fld_dec_flag); 1051 1052 ps_cur_deblk_mb->u1_mb_type = ps_cur_deblk_mb->u1_mb_type 1053 | D_INTRA_MB; 1054 1055 /* Macroblock Layer Begins */ 1056 /* Decode the u1_mb_type */ 1057 u1_mb_type = ih264d_parse_mb_type_intra_cabac(0, ps_dec); 1058 if(u1_mb_type > 25) 1059 return ERROR_MB_TYPE; 1060 ps_cur_mb_info->u1_mb_type = u1_mb_type; 1061 COPYTHECONTEXT("u1_mb_type", u1_mb_type); 1062 1063 /* Parse Macroblock Data */ 1064 if(25 == u1_mb_type) 1065 { 1066 /* I_PCM_MB */ 1067 ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB; 1068 ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u1_num_mbs); 1069 if(ret != OK) 1070 return ret; 1071 ps_cur_deblk_mb->u1_mb_qp = 0; 1072 } 1073 else 1074 { 1075 ret = ih264d_parse_imb_cabac(ps_dec, ps_cur_mb_info, u1_mb_type); 1076 if(ret != OK) 1077 return ret; 1078 ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp; 1079 } 1080 1081 if(u1_mbaff) 1082 { 1083 ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info); 1084 } 1085 /* Next macroblock information */ 1086 i2_cur_mb_addr++; 1087 1088 if(ps_cur_mb_info->u1_topmb && u1_mbaff) 1089 uc_more_data_flag = 1; 1090 else 1091 { 1092 uc_more_data_flag = ih264d_decode_terminate(&ps_dec->s_cab_dec_env, 1093 ps_bitstrm); 1094 uc_more_data_flag = !uc_more_data_flag; 1095 COPYTHECONTEXT("Decode Sliceterm",!uc_more_data_flag); 1096 } 1097 /* Store the colocated information */ 1098 { 1099 1100 mv_pred_t *ps_mv_nmb_start = ps_dec->ps_mv_cur + (u1_num_mbs << 4); 1101 mv_pred_t s_mvPred = 1102 { 1103 { 0, 0, 0, 0 }, 1104 { -1, -1 }, 0, 0}; 1105 ih264d_rep_mv_colz( 1106 ps_dec, &s_mvPred, ps_mv_nmb_start, 0, 1107 (UWORD8)(ps_dec->u1_cur_mb_fld_dec_flag << 1), 1108 4, 4); 1109 } 1110 /*if num _cores is set to 3,compute bs will be done in another thread*/ 1111 if(ps_dec->u4_num_cores < 3) 1112 { 1113 if(ps_dec->u4_app_disable_deblk_frm == 0) 1114 ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info, 1115 (UWORD16)(u1_num_mbs >> u1_mbaff)); 1116 } 1117 u1_num_mbs++; 1118 ps_dec->u2_total_mbs_coded++; 1119 1120 } 1121 1122 /****************************************************************/ 1123 /* Check for End Of Row */ 1124 /****************************************************************/ 1125 u1_num_mbs_next = i2_pic_wdin_mbs - u2_mbx - 1; 1126 u1_end_of_row = (!u1_num_mbs_next) && (!(u1_mbaff && (u1_num_mbs & 0x01))); 1127 u1_tfr_n_mb = (u1_num_mbs == ps_dec->u1_recon_mb_grp) || u1_end_of_row 1128 || (!uc_more_data_flag); 1129 ps_cur_mb_info->u1_end_of_slice = (!uc_more_data_flag); 1130 1131 if(u1_tfr_n_mb || (!uc_more_data_flag)) 1132 { 1133 1134 1135 if(ps_dec->u1_separate_parse) 1136 { 1137 ih264d_parse_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs, 1138 u1_num_mbs_next, u1_tfr_n_mb, u1_end_of_row); 1139 ps_dec->ps_nmb_info += u1_num_mbs; 1140 } 1141 else 1142 { 1143 ih264d_decode_recon_tfr_nmb(ps_dec, u1_mb_idx, u1_num_mbs, 1144 u1_num_mbs_next, u1_tfr_n_mb, 1145 u1_end_of_row); 1146 } 1147 1148 if(u1_tfr_n_mb) 1149 u1_num_mbs = 0; 1150 u1_mb_idx = u1_num_mbs; 1151 ps_dec->u1_mb_idx = u1_num_mbs; 1152 1153 } 1154 } 1155 while(uc_more_data_flag); 1156 1157 ps_dec->u4_num_mbs_cur_nmb = 0; 1158 ps_dec->ps_cur_slice->u4_mbs_in_slice = i2_cur_mb_addr 1159 1160 - (u2_first_mb_in_slice << u1_mbaff); 1161 1162 return ret; 1163} 1164 1165/*****************************************************************************/ 1166/* */ 1167/* Function Name : ih264d_parse_ipcm_mb */ 1168/* */ 1169/* Description : This function decodes the pixel values of I_PCM Mb. */ 1170/* */ 1171/* Inputs : ps_dec, ps_cur_mb_info and mb number */ 1172/* */ 1173/* Description : This function reads the luma and chroma pixels directly */ 1174/* from the bitstream when the mbtype is I_PCM and stores */ 1175/* them in recon buffer. If the entropy coding mode is */ 1176/* cabac, decoding engine is re-initialized. The nnzs and */ 1177/* cabac contexts are appropriately modified. */ 1178/* Returns : void */ 1179/* */ 1180/* Revision History: */ 1181/* DD MM YYYY Author(s) Changes (Describe the changes made) */ 1182/* 13 07 2002 Jay */ 1183/* */ 1184/*****************************************************************************/ 1185 1186WORD32 ih264d_parse_ipcm_mb(dec_struct_t * ps_dec, 1187 dec_mb_info_t *ps_cur_mb_info, 1188 UWORD8 u1_mbNum) 1189{ 1190 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm; 1191 UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag; 1192 UWORD8 *pu1_y, *pu1_u, *pu1_v; 1193 WORD32 ret; 1194 1195 UWORD32 u4_rec_width_y, u4_rec_width_uv; 1196 UWORD32 u1_num_mb_pair; 1197 UWORD8 u1_x, u1_y; 1198 /* CHANGED CODE */ 1199 tfr_ctxt_t *ps_frame_buf; 1200 UWORD8 u1_mb_field_decoding_flag; 1201 UWORD32 *pu4_buf; 1202 UWORD8 *pu1_buf; 1203 /* CHANGED CODE */ 1204 1205 if(ps_dec->u1_separate_parse) 1206 { 1207 ps_frame_buf = &ps_dec->s_tran_addrecon_parse; 1208 } 1209 else 1210 { 1211 ps_frame_buf = &ps_dec->s_tran_addrecon; 1212 } 1213 /* align bistream to byte boundary. */ 1214 /* pcm_alignment_zero_bit discarded */ 1215 /* For XX GotoByteBoundary */ 1216 if(ps_bitstrm->u4_ofst & 0x07) 1217 { 1218 ps_bitstrm->u4_ofst += 8; 1219 ps_bitstrm->u4_ofst &= 0xFFFFFFF8; 1220 } 1221 1222 /* Store left Nnz as 16 for each 4x4 blk */ 1223 1224 pu1_buf = ps_dec->pu1_left_nnz_y; 1225 pu4_buf = (UWORD32 *)pu1_buf; 1226 *pu4_buf = 0x10101010; 1227 pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_y; 1228 pu4_buf = (UWORD32 *)pu1_buf; 1229 *pu4_buf = 0x10101010; 1230 pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_uv; 1231 pu4_buf = (UWORD32 *)pu1_buf; 1232 *pu4_buf = 0x10101010; 1233 pu1_buf = ps_dec->pu1_left_nnz_uv; 1234 pu4_buf = (UWORD32 *)pu1_buf; 1235 *pu4_buf = 0x10101010; 1236 ps_cur_mb_info->u1_cbp = 0xff; 1237 1238 ps_dec->i1_prev_mb_qp_delta = 0; 1239 /* Get neighbour MB's */ 1240 u1_num_mb_pair = (u1_mbNum >> u1_mbaff); 1241 1242 /*****************************************************************************/ 1243 /* calculate the RECON buffer YUV pointers for the PCM data */ 1244 /*****************************************************************************/ 1245 /* CHANGED CODE */ 1246 u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag; 1247 pu1_y = ps_frame_buf->pu1_dest_y + (u1_num_mb_pair << 4); 1248 pu1_u = ps_frame_buf->pu1_dest_u + (u1_num_mb_pair << 4); 1249 pu1_v = pu1_u + 1; 1250 1251 u4_rec_width_y = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag; 1252 u4_rec_width_uv = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag; 1253 /* CHANGED CODE */ 1254 1255 if(u1_mbaff) 1256 { 1257 UWORD8 u1_top_mb; 1258 1259 u1_top_mb = ps_cur_mb_info->u1_topmb; 1260 1261 if(u1_top_mb == 0) 1262 { 1263 pu1_y += (u1_mb_field_decoding_flag ? 1264 (u4_rec_width_y >> 1) : (u4_rec_width_y << 4)); 1265 pu1_u += (u1_mb_field_decoding_flag ? 1266 (u4_rec_width_uv) : (u4_rec_width_uv << 4)); 1267 pu1_v = pu1_u + 1; 1268 } 1269 } 1270 1271 /* Read Luma samples */ 1272 for(u1_y = 0; u1_y < 16; u1_y++) 1273 { 1274 for(u1_x = 0; u1_x < 16; u1_x++) 1275 pu1_y[u1_x] = ih264d_get_bits_h264(ps_bitstrm, 8); 1276 1277 pu1_y += u4_rec_width_y; 1278 } 1279 1280 /* Read Chroma samples */ 1281 for(u1_y = 0; u1_y < 8; u1_y++) 1282 { 1283 for(u1_x = 0; u1_x < 8; u1_x++) 1284 pu1_u[u1_x * YUV420SP_FACTOR] = ih264d_get_bits_h264(ps_bitstrm, 8); 1285 1286 pu1_u += u4_rec_width_uv; 1287 } 1288 1289 for(u1_y = 0; u1_y < 8; u1_y++) 1290 { 1291 for(u1_x = 0; u1_x < 8; u1_x++) 1292 pu1_v[u1_x * YUV420SP_FACTOR] = ih264d_get_bits_h264(ps_bitstrm, 8); 1293 1294 pu1_v += u4_rec_width_uv; 1295 } 1296 1297 if(CABAC == ps_dec->ps_cur_pps->u1_entropy_coding_mode) 1298 { 1299 UWORD32 *pu4_buf; 1300 UWORD8 *pu1_buf; 1301 ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info; 1302 /* Re-initialize the cabac decoding engine. */ 1303 ret = ih264d_init_cabac_dec_envirnoment(&(ps_dec->s_cab_dec_env), ps_bitstrm); 1304 if(ret != OK) 1305 return ret; 1306 /* update the cabac contetxs */ 1307 p_curr_ctxt->u1_mb_type = CAB_I_PCM; 1308 p_curr_ctxt->u1_cbp = 47; 1309 p_curr_ctxt->u1_intra_chroma_pred_mode = 0; 1310 p_curr_ctxt->u1_transform8x8_ctxt = 0; 1311 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0; 1312 1313 pu1_buf = ps_dec->pu1_left_nnz_y; 1314 pu4_buf = (UWORD32 *)pu1_buf; 1315 *pu4_buf = 0x01010101; 1316 1317 pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_y; 1318 pu4_buf = (UWORD32 *)pu1_buf; 1319 *pu4_buf = 0x01010101; 1320 1321 pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_uv; 1322 pu4_buf = (UWORD32 *)pu1_buf; 1323 *pu4_buf = 0x01010101; 1324 1325 pu1_buf = ps_dec->pu1_left_nnz_uv; 1326 pu4_buf = (UWORD32 *)pu1_buf; 1327 *pu4_buf = 0x01010101; 1328 1329 p_curr_ctxt->u1_yuv_dc_csbp = 0x7; 1330 ps_dec->pu1_left_yuv_dc_csbp[0] = 0x7; 1331 if(ps_dec->ps_cur_slice->u1_slice_type != I_SLICE) 1332 { 1333 1334 MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0); 1335 memset(ps_dec->pi1_left_ref_idx_ctxt_inc, 0, 4); 1336 MEMSET_16BYTES(p_curr_ctxt->u1_mv, 0); 1337 memset(p_curr_ctxt->i1_ref_idx, 0, 4); 1338 1339 } 1340 } 1341 return OK; 1342} 1343 1344/*! 1345 ************************************************************************** 1346 * \if Function name : ih264d_decode_islice \endif 1347 * 1348 * \brief 1349 * Decodes an I Slice 1350 * 1351 * 1352 * \return 1353 * 0 on Success and Error code otherwise 1354 ************************************************************************** 1355 */ 1356WORD32 ih264d_parse_islice(dec_struct_t *ps_dec, 1357 UWORD16 u2_first_mb_in_slice) 1358{ 1359 dec_pic_params_t * ps_pps = ps_dec->ps_cur_pps; 1360 dec_slice_params_t * ps_slice = ps_dec->ps_cur_slice; 1361 UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer; 1362 UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst; 1363 UWORD32 u4_temp; 1364 WORD32 i_temp; 1365 WORD32 ret; 1366 1367 /*--------------------------------------------------------------------*/ 1368 /* Read remaining contents of the slice header */ 1369 /*--------------------------------------------------------------------*/ 1370 /* dec_ref_pic_marking function */ 1371 /* G050 */ 1372 if(ps_slice->u1_nal_ref_idc != 0) 1373 { 1374 if(!ps_dec->ps_dpb_cmds->u1_dpb_commands_read) 1375 ps_dec->u4_bitoffset = ih264d_read_mmco_commands( 1376 ps_dec); 1377 else 1378 ps_dec->ps_bitstrm->u4_ofst += ps_dec->u4_bitoffset; 1379 } 1380 /* G050 */ 1381 1382 /* Read slice_qp_delta */ 1383 i_temp = ps_pps->u1_pic_init_qp 1384 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf); 1385 if((i_temp < 0) || (i_temp > 51)) 1386 return ERROR_INV_RANGE_QP_T; 1387 ps_slice->u1_slice_qp = i_temp; 1388 COPYTHECONTEXT("SH: slice_qp_delta", 1389 ps_slice->u1_slice_qp - ps_pps->u1_pic_init_qp); 1390 1391 if(ps_pps->u1_deblocking_filter_parameters_present_flag == 1) 1392 { 1393 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf); 1394 COPYTHECONTEXT("SH: disable_deblocking_filter_idc", u4_temp); 1395 1396 if(u4_temp > SLICE_BOUNDARY_DBLK_DISABLED) 1397 { 1398 return ERROR_INV_SLICE_HDR_T; 1399 } 1400 ps_slice->u1_disable_dblk_filter_idc = u4_temp; 1401 if(u4_temp != 1) 1402 { 1403 i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf) 1404 << 1; 1405 if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF)) 1406 { 1407 return ERROR_INV_SLICE_HDR_T; 1408 } 1409 ps_slice->i1_slice_alpha_c0_offset = i_temp; 1410 COPYTHECONTEXT("SH: slice_alpha_c0_offset_div2", 1411 ps_slice->i1_slice_alpha_c0_offset >> 1); 1412 1413 i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf) 1414 << 1; 1415 if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF)) 1416 { 1417 return ERROR_INV_SLICE_HDR_T; 1418 } 1419 ps_slice->i1_slice_beta_offset = i_temp; 1420 COPYTHECONTEXT("SH: slice_beta_offset_div2", 1421 ps_slice->i1_slice_beta_offset >> 1); 1422 1423 } 1424 else 1425 { 1426 ps_slice->i1_slice_alpha_c0_offset = 0; 1427 ps_slice->i1_slice_beta_offset = 0; 1428 } 1429 } 1430 else 1431 { 1432 ps_slice->u1_disable_dblk_filter_idc = 0; 1433 ps_slice->i1_slice_alpha_c0_offset = 0; 1434 ps_slice->i1_slice_beta_offset = 0; 1435 } 1436 1437 /* Initialization to check if number of motion vector per 2 Mbs */ 1438 /* are exceeding the range or not */ 1439 ps_dec->u2_mv_2mb[0] = 0; 1440 ps_dec->u2_mv_2mb[1] = 0; 1441 1442 1443 /*set slice header cone to 2 ,to indicate correct header*/ 1444 ps_dec->u1_slice_header_done = 2; 1445 1446 if(ps_pps->u1_entropy_coding_mode) 1447 { 1448 SWITCHOFFTRACE; SWITCHONTRACECABAC; 1449 if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag) 1450 { 1451 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_mbaff; 1452 } 1453 else 1454 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_nonmbaff; 1455 1456 ret = ih264d_parse_islice_data_cabac(ps_dec, ps_slice, 1457 u2_first_mb_in_slice); 1458 if(ret != OK) 1459 return ret; 1460 SWITCHONTRACE; SWITCHOFFTRACECABAC; 1461 } 1462 else 1463 { 1464 if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag) 1465 { 1466 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_mbaff; 1467 } 1468 else 1469 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_nonmbaff; 1470 ret = ih264d_parse_islice_data_cavlc(ps_dec, ps_slice, 1471 u2_first_mb_in_slice); 1472 if(ret != OK) 1473 return ret; 1474 } 1475 1476 return OK; 1477} 1478