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 * \file ih264d_process_bslice.c 23 * 24 * \brief 25 * Contains routines that decode B slice type 26 * 27 * Detailed_description 28 * 29 * \date 30 * 21/12/2002 31 * 32 * \author NS 33 ************************************************************************** 34 */ 35#include "ih264_typedefs.h" 36#include "ih264_macros.h" 37#include "ih264_platform_macros.h" 38 39#include <string.h> 40#include "ih264d_structs.h" 41#include "ih264d_bitstrm.h" 42#include "ih264d_parse_cavlc.h" 43#include "ih264d_mb_utils.h" 44#include "ih264d_mvpred.h" 45#include "ih264d_inter_pred.h" 46#include "ih264d_process_pslice.h" 47#include "ih264d_error_handler.h" 48#include "ih264d_tables.h" 49#include "ih264d_parse_slice.h" 50#include "ih264d_process_pslice.h" 51#include "ih264d_process_bslice.h" 52#include "ih264d_tables.h" 53#include "ih264d_parse_islice.h" 54#include "ih264d_mvpred.h" 55 56void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec); 57//UWORD32 g_hits = 0; 58//UWORD32 g_miss = 0; 59/*! 60 ************************************************************************** 61 * \if Function name : ih264d_decode_spatial_direct \endif 62 * 63 * \brief 64 * Decodes spatial direct mode. 65 * 66 * \return 67 * None. 68 * Arunoday T 69 ************************************************************************** 70 */ 71WORD32 ih264d_decode_spatial_direct(dec_struct_t * ps_dec, 72 UWORD8 u1_wd_x, 73 dec_mb_info_t * ps_cur_mb_info, 74 UWORD8 u1_mb_num) 75{ 76 mv_pred_t s_mv_pred, *ps_mv; 77 UWORD8 u1_col_zero_flag, u1_sub_mb_num, u1_direct_zero_pred_flag = 0; 78 UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag; 79 mv_pred_t *ps_mv_ntop_start; 80 mv_pred_t *ps_mv_nmb_start = ps_dec->ps_mv_cur + (u1_mb_num << 4); 81 UWORD8 partition_size, sub_partition, u1_mb_partw, u1_mb_parth; 82 UWORD8 i; 83 WORD8 i1_pred, i1_ref_frame0, i1_ref_frame1; 84 struct pic_buffer_t *ps_ref_frame = NULL, *ps_col_pic, *ps_pic_buff0 = NULL, 85 *ps_pic_buff1 = NULL; 86 87 UWORD8 u1_zero_pred_cond_f, u1_zero_pred_cond_b; 88 WORD16 i2_def_mv[2], i2_spat_pred_mv[4], *pi2_final_mv0, *pi2_final_mv1; 89 UWORD16 ui2_mask_fwd = 0, ui2_mask_bwd = 0, u2_mask = 0; 90 UWORD32 *pui32_weight_ofsts = NULL; 91 directmv_t s_mvdirect; 92 UWORD8 u1_colz; 93 UWORD8 u1_final_ref_idx = 0; 94 const UWORD8 *pu1_mb_parth = (const UWORD8 *)gau1_ih264d_mb_parth; 95 const UWORD8 *pu1_mb_partw = (const UWORD8 *)gau1_ih264d_mb_partw; 96 const UWORD16 sub_mask_table[] = 97 { 0x33, 0x3, 0x11, 0x1 }; 98 const UWORD16 mask_table[] = 99 { 0xffff, /*16x16 NA */ 100 0xff, /* 16x8*/ 101 0x3333, /* 8x16*/ 102 0x33 };/* 8x8*/ 103 mv_pred_t s_temp_mv_pred; 104 WORD32 ret = 0; 105 106 /* CHANGED CODE */ 107 ps_mv_ntop_start = ps_dec->ps_mv_cur + (u1_mb_num << 4) 108 - (ps_dec->u2_frm_wd_in_mbs << (4 + u1_mbaff)) + 12; 109 110 /* assign default values for MotionVector as zero */ 111 i2_def_mv[0] = 0; 112 i2_def_mv[1] = 0; 113 114 u1_direct_zero_pred_flag = ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb_start, 115 ps_mv_ntop_start, &s_mv_pred, 0, 4, 116 0, 1, B_DIRECT_SPATIAL); 117 118 i2_spat_pred_mv[0] = s_mv_pred.i2_mv[0]; 119 i2_spat_pred_mv[1] = s_mv_pred.i2_mv[1]; 120 i2_spat_pred_mv[2] = s_mv_pred.i2_mv[2]; 121 i2_spat_pred_mv[3] = s_mv_pred.i2_mv[3]; 122 123 i1_ref_frame0 = s_mv_pred.i1_ref_frame[0]; 124 i1_ref_frame1 = s_mv_pred.i1_ref_frame[1]; 125 126 i1_ref_frame0 = (i1_ref_frame0 < 0) ? -1 : i1_ref_frame0; 127 i1_ref_frame1 = (i1_ref_frame1 < 0) ? -1 : i1_ref_frame1; 128 129 i1_pred = 0; 130 131 { 132 WORD8 u1_ref_idx, u1_ref_idx1; 133 UWORD32 uc_Idx, uc_Idx1; 134 UWORD8 u1_scale_ref = (ps_dec->ps_cur_slice->u1_mbaff_frame_flag 135 && ps_cur_mb_info->u1_mb_field_decodingflag); 136 u1_final_ref_idx = i1_ref_frame0; 137 if(i1_ref_frame0 >= 0) 138 { 139 /* convert RefIdx if it is MbAff */ 140 u1_ref_idx = i1_ref_frame0; 141 u1_ref_idx1 = i1_ref_frame0; 142 if(u1_scale_ref) 143 { 144 u1_ref_idx1 = u1_ref_idx >> 1; 145 if((u1_ref_idx & 0x01) != (1 - ps_cur_mb_info->u1_topmb)) 146 u1_ref_idx1 += MAX_REF_BUFS; 147 } 148 /* If i1_ref_frame0 < 0 then refIdxCol is obtained from ps_pic_buff1 */ 149 ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][u1_ref_idx1]; 150 ps_ref_frame = ps_pic_buff0; 151 i1_pred = PRED_L0; 152 } 153 154 if(i1_ref_frame1 >= 0) 155 { 156 /* convert RefIdx if it is MbAff */ 157 u1_ref_idx = i1_ref_frame1; 158 u1_ref_idx1 = i1_ref_frame1; 159 if(u1_scale_ref) 160 { 161 u1_ref_idx1 = u1_ref_idx >> 1; 162 if((u1_ref_idx & 0x01) != (1 - ps_cur_mb_info->u1_topmb)) 163 u1_ref_idx1 += MAX_REF_BUFS; 164 } 165 ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][u1_ref_idx1]; 166 i1_pred = i1_pred | PRED_L1; 167 } 168 if(i1_ref_frame0 < 0) 169 { 170 ps_ref_frame = ps_pic_buff1; 171 u1_final_ref_idx = i1_ref_frame1; 172 } 173 174 u1_zero_pred_cond_f = (u1_direct_zero_pred_flag) || (i1_ref_frame0 < 0); 175 u1_zero_pred_cond_b = (u1_direct_zero_pred_flag) || (i1_ref_frame1 < 0); 176 177 if(ps_dec->ps_cur_pps->u1_wted_bipred_idc) 178 { 179 uc_Idx = ((i1_ref_frame0 < 1) ? 0 : i1_ref_frame0) 180 * ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1]; 181 if(u1_scale_ref) 182 uc_Idx >>= 1; 183 uc_Idx1 = (i1_ref_frame1 < 0) ? 0 : i1_ref_frame1; 184 uc_Idx += (u1_scale_ref) ? (uc_Idx1 >> 1) : uc_Idx1; 185 pui32_weight_ofsts = 186 (UWORD32*)&ps_dec->pu4_wt_ofsts[2 * X3(uc_Idx)]; 187 188 if(i1_ref_frame0 < 0) 189 pui32_weight_ofsts += 1; 190 191 if(u1_scale_ref && (ps_dec->ps_cur_pps->u1_wted_bipred_idc == 2)) 192 { 193 WORD16 i2_ref_idx; 194 i2_ref_idx = MAX(i1_ref_frame0, 0); 195 i2_ref_idx *= (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1] 196 << 1); 197 i2_ref_idx += MAX(i1_ref_frame1, 0); 198 if(!ps_cur_mb_info->u1_topmb) 199 i2_ref_idx += 200 (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0] 201 << 1) 202 * (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1] 203 << 1); 204 pui32_weight_ofsts = (UWORD32*)&ps_dec->pu4_mbaff_wt_mat[2 205 * X3(i2_ref_idx)]; 206 } 207 } 208 } 209 210 s_temp_mv_pred.i1_ref_frame[0] = i1_ref_frame0; 211 s_temp_mv_pred.i1_ref_frame[1] = i1_ref_frame1; 212 s_temp_mv_pred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id; 213 s_temp_mv_pred.u1_pic_type = ps_ref_frame->u1_pic_type; 214 215 /**********************************************************************/ 216 /* Call the function which gets the number of partitions and */ 217 /* partition info of colocated Mb */ 218 /**********************************************************************/ 219 220 ps_dec->pf_parse_mvdirect(ps_dec, ps_dec->ps_col_pic, &s_mvdirect, u1_wd_x, 221 ps_dec->i4_submb_ofst, ps_cur_mb_info); 222 ps_col_pic = ps_dec->ps_col_pic; 223 if((s_mvdirect.u1_col_zeroflag_change == 0) || u1_direct_zero_pred_flag) 224 { 225 WORD16 i2_mv_x, i2_mv_y, i2_mvX1, i2_mvY1; 226 /* Most probable case */ 227 u1_col_zero_flag = *(ps_col_pic->pu1_col_zero_flag 228 + s_mvdirect.i4_mv_indices[0]); 229 u1_col_zero_flag = u1_col_zero_flag & 0x01; 230 231 if(u1_zero_pred_cond_f || ((i1_ref_frame0 == 0) && (u1_col_zero_flag == 1))) 232 { 233 i2_mv_x = 0; 234 i2_mv_y = 0; 235 } 236 else 237 { 238 i2_mv_x = i2_spat_pred_mv[0]; 239 i2_mv_y = i2_spat_pred_mv[1]; 240 241 } 242 243 if(u1_zero_pred_cond_b || ((i1_ref_frame1 == 0) && (u1_col_zero_flag == 1))) 244 { 245 i2_mvX1 = 0; 246 i2_mvY1 = 0; 247 } 248 else 249 { 250 i2_mvX1 = i2_spat_pred_mv[2]; 251 i2_mvY1 = i2_spat_pred_mv[3]; 252 } 253 254 u1_sub_mb_num = ps_dec->u1_sub_mb_num; 255 u1_mb_partw = (u1_wd_x >> 2); 256 257 258 if(i1_ref_frame0 >= 0) 259 { 260 { 261 pred_info_pkd_t *ps_pred_pkd; 262 WORD16 i2_mv[2]; 263 WORD8 i1_ref_idx= 0; 264 265 i2_mv[0] = i2_mv_x; 266 i2_mv[1] = i2_mv_y; 267 268 ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx; 269 ih264d_fill_pred_info(i2_mv,u1_mb_partw,u1_mb_partw,u1_sub_mb_num,i1_pred, 270 ps_pred_pkd,ps_pic_buff0->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts, 271 ps_pic_buff0->u1_pic_type); 272 ps_dec->u4_pred_info_pkd_idx++; 273 ps_cur_mb_info->u1_num_pred_parts++; 274 275 276 } 277 278 } 279 280 if(i1_ref_frame1 >= 0) 281 { 282 { 283 pred_info_pkd_t *ps_pred_pkd; 284 WORD16 i2_mv[2]; 285 WORD8 i1_ref_idx= 0; 286 287 i2_mv[0] = i2_mvX1; 288 i2_mv[1] = i2_mvY1; 289 290 ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx; 291 ih264d_fill_pred_info(i2_mv,u1_mb_partw,u1_mb_partw,u1_sub_mb_num,i1_pred, 292 ps_pred_pkd,ps_pic_buff1->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts, 293 ps_pic_buff1->u1_pic_type); 294 ps_dec->u4_pred_info_pkd_idx++; 295 ps_cur_mb_info->u1_num_pred_parts++; 296 297 298 } 299 } 300 301 302 /* Replication optimisation */ 303 s_temp_mv_pred.i2_mv[0] = i2_mv_x; 304 s_temp_mv_pred.i2_mv[1] = i2_mv_y; 305 s_temp_mv_pred.i2_mv[2] = i2_mvX1; 306 s_temp_mv_pred.i2_mv[3] = i2_mvY1; 307 308 /* Calculating colocated zero information */ 309 { 310 /*************************************/ 311 /* If(bit2 and bit3 set) */ 312 /* then */ 313 /* (bit0 and bit1) => submmbmode */ 314 /* (bit2 and bit3) => mbmode */ 315 /* else */ 316 /* (bit0 and bit1) => mbmode */ 317 /*************************************/ 318 /*UWORD8 u1_packed_mb_sub_mb_mode = sub_partition ? 319 (s_mvdirect.i1_partitionsize[0]) : ((s_mvdirect.i1_partitionsize[0]) << 2);*/ 320 UWORD8 u1_packed_mb_sub_mb_mode = (u1_mb_partw == 2) ? 0x03 : 0; 321 322 if(i1_ref_frame0 < 0) 323 { 324 i2_mv_x = i2_mvX1; 325 i2_mv_y = i2_mvY1; 326 } 327 328 /* Change from left shift 4 to 6 - Varun */ 329 u1_colz = (ps_cur_mb_info->u1_mb_field_decodingflag << 1) 330 | ((u1_final_ref_idx == 0) && (ABS(i2_mv_x) <= 1) 331 && (ABS(i2_mv_y) <= 1)); 332 u1_colz |= (u1_packed_mb_sub_mb_mode << 6); 333 } 334 ps_mv = ps_mv_nmb_start + u1_sub_mb_num; 335 ih264d_rep_mv_colz(ps_dec, &s_temp_mv_pred, ps_mv, u1_sub_mb_num, u1_colz, 336 u1_mb_partw, u1_mb_partw); 337 if(u1_wd_x == MB_SIZE) 338 ps_dec->u1_currB_type = 0; 339 340 341 342 return OK; 343 } 344 /***************************************************************************/ 345 /* If present MB is 16x16 and the partition of colocated Mb is >= PRED_8x8 */ 346 /* i.e 8x8 or less than 8x8 partitions then set up DMA for (0,0) and */ 347 /* spatially predicted motion vector and do the multiplexing after */ 348 /* motion compensation */ 349 /***************************************************************************/ 350 351 352 if((u1_wd_x == MB_SIZE) && (s_mvdirect.i1_num_partitions > 2)) 353 { 354 ps_cur_mb_info->u1_Mux = 1; 355 if(i1_ref_frame0 >= 0) 356 { 357 358 { 359 pred_info_pkd_t *ps_pred_pkd; 360 WORD8 i1_ref_idx= 0; 361 362 ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx; 363 ih264d_fill_pred_info(&(i2_spat_pred_mv[0]),4,4,0,i1_pred, 364 ps_pred_pkd,ps_pic_buff0->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts, 365 ps_pic_buff0->u1_pic_type); 366 ps_dec->u4_pred_info_pkd_idx++; 367 ps_cur_mb_info->u1_num_pred_parts++; 368 369 370 } 371 372 /****** (0,0) Motion vectors DMA *****/ 373 { 374 pred_info_pkd_t *ps_pred_pkd; 375 WORD16 i2_mv[2]; 376 WORD8 i1_ref_idx= 0; 377 378 i2_mv[0] = 0; 379 i2_mv[1] = 0; 380 381 ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx; 382 ih264d_fill_pred_info(i2_mv,4,4,0,i1_pred, 383 ps_pred_pkd,ps_pic_buff0->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts, 384 ps_pic_buff0->u1_pic_type); 385 ps_dec->u4_pred_info_pkd_idx++; 386 ps_cur_mb_info->u1_num_pred_parts++; 387 388 389 } 390 } 391 if(i1_ref_frame1 >= 0) 392 { 393 { 394 pred_info_pkd_t *ps_pred_pkd; 395 WORD16 i2_mv[2]; 396 WORD8 i1_ref_idx= 0; 397 398 ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx; 399 ih264d_fill_pred_info(&(i2_spat_pred_mv[2]),4,4,0,i1_pred, 400 ps_pred_pkd,ps_pic_buff1->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts, 401 ps_pic_buff1->u1_pic_type); 402 ps_dec->u4_pred_info_pkd_idx++; 403 ps_cur_mb_info->u1_num_pred_parts++; 404 405 406 } 407 408 /****** (0,0) Motion vectors DMA *****/ 409 410 { 411 pred_info_pkd_t *ps_pred_pkd; 412 WORD16 i2_mv[2]; 413 WORD8 i1_ref_idx= 0; 414 415 i2_mv[0] = 0; 416 i2_mv[1] = 0; 417 418 ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx; 419 ih264d_fill_pred_info(i2_mv,4,4,0,i1_pred, 420 ps_pred_pkd,ps_pic_buff1->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts, 421 ps_pic_buff1->u1_pic_type); 422 ps_dec->u4_pred_info_pkd_idx++; 423 ps_cur_mb_info->u1_num_pred_parts++; 424 425 426 } 427 } 428 } 429 430 /*u1_col = *(ps_col_pic->pu1_col_zero_flag + s_mvdirect.i4_mv_indices[0]); 431 u1_col &= 1; 432 u1_init = 0;*/ 433 434 for(i = 0; i < s_mvdirect.i1_num_partitions; i++) 435 { 436 partition_size = s_mvdirect.i1_partitionsize[i]; 437 u1_sub_mb_num = s_mvdirect.i1_submb_num[i]; 438 439 sub_partition = partition_size >> 2; 440 partition_size &= 0x3; 441 u1_mb_partw = pu1_mb_partw[partition_size]; 442 u1_mb_parth = pu1_mb_parth[partition_size]; 443 u2_mask = mask_table[partition_size]; 444 if(sub_partition != 0) 445 { 446 u1_mb_partw >>= 1; 447 u1_mb_parth >>= 1; 448 u2_mask = sub_mask_table[partition_size]; 449 } 450 451 u1_col_zero_flag = *(ps_col_pic->pu1_col_zero_flag 452 + s_mvdirect.i4_mv_indices[i]); 453 u1_col_zero_flag = u1_col_zero_flag & 0x01; 454 455 /*if(u1_col != u1_col_zero_flag) 456 u1_init = 1;*/ 457 458 if(u1_zero_pred_cond_f || ((i1_ref_frame0 == 0) && (u1_col_zero_flag == 1))) 459 { 460 pi2_final_mv0 = &i2_def_mv[0]; 461 ui2_mask_fwd |= (u2_mask << u1_sub_mb_num); 462 } 463 else 464 pi2_final_mv0 = &i2_spat_pred_mv[0]; 465 466 if(u1_zero_pred_cond_b || ((i1_ref_frame1 == 0) && (u1_col_zero_flag == 1))) 467 { 468 pi2_final_mv1 = &i2_def_mv[0]; 469 ui2_mask_bwd |= (u2_mask << u1_sub_mb_num); 470 } 471 else 472 pi2_final_mv1 = &i2_spat_pred_mv[2]; 473 474 if(ps_cur_mb_info->u1_Mux != 1) 475 { 476 /*u1_sub_mb_x = u1_sub_mb_num & 0x03; 477 uc_sub_mb_y = (u1_sub_mb_num >> 2);*/ 478 if(i1_ref_frame0 >= 0) 479 { 480 481 { 482 pred_info_pkd_t *ps_pred_pkd; 483 WORD8 i1_ref_idx= 0; 484 485 ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx; 486 ih264d_fill_pred_info(pi2_final_mv0,u1_mb_partw,u1_mb_parth,u1_sub_mb_num,i1_pred, 487 ps_pred_pkd,ps_pic_buff0->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts, 488 ps_pic_buff0->u1_pic_type); 489 ps_dec->u4_pred_info_pkd_idx++; 490 ps_cur_mb_info->u1_num_pred_parts++; 491 492 493 } 494 495 } 496 497 if(i1_ref_frame1 >= 0) 498 { 499 { 500 pred_info_pkd_t *ps_pred_pkd; 501 WORD8 i1_ref_idx= 0; 502 503 ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx; 504 ih264d_fill_pred_info(pi2_final_mv1,u1_mb_partw,u1_mb_parth,u1_sub_mb_num,i1_pred, 505 ps_pred_pkd,ps_pic_buff1->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts, 506 ps_pic_buff1->u1_pic_type); 507 ps_dec->u4_pred_info_pkd_idx++; 508 ps_cur_mb_info->u1_num_pred_parts++; 509 510 511 } 512 } 513 } 514 515 /* Replication optimisation */ 516 s_temp_mv_pred.i2_mv[0] = pi2_final_mv0[0]; 517 s_temp_mv_pred.i2_mv[1] = pi2_final_mv0[1]; 518 s_temp_mv_pred.i2_mv[2] = pi2_final_mv1[0]; 519 s_temp_mv_pred.i2_mv[3] = pi2_final_mv1[1]; 520 521 /* Calculating colocated zero information */ 522 { 523 WORD16 i2_mv_x = 0, i2_mv_y = 0; 524 /*************************************/ 525 /* If(bit2 and bit3 set) */ 526 /* then */ 527 /* (bit0 and bit1) => submmbmode */ 528 /* (bit2 and bit3) => mbmode */ 529 /* else */ 530 /* (bit0 and bit1) => mbmode */ 531 /*************************************/ 532 UWORD8 u1_packed_mb_sub_mb_mode = 533 sub_partition ? (s_mvdirect.i1_partitionsize[i]) : ((s_mvdirect.i1_partitionsize[i]) 534 << 2); 535 536 if(i1_ref_frame0 >= 0) 537 { 538 i2_mv_x = pi2_final_mv0[0]; 539 i2_mv_y = pi2_final_mv0[1]; 540 } 541 else 542 { 543 i2_mv_x = pi2_final_mv1[0]; 544 i2_mv_y = pi2_final_mv1[1]; 545 } 546 547 u1_colz = (ps_cur_mb_info->u1_mb_field_decodingflag << 1) 548 | ((u1_final_ref_idx == 0) && (ABS(i2_mv_x) <= 1) 549 && (ABS(i2_mv_y) <= 1)); 550 u1_colz |= (u1_packed_mb_sub_mb_mode << 4); 551 } 552 ps_mv = ps_mv_nmb_start + u1_sub_mb_num; 553 ih264d_rep_mv_colz(ps_dec, &s_temp_mv_pred, ps_mv, u1_sub_mb_num, u1_colz, 554 u1_mb_parth, u1_mb_partw); 555 } 556 i = 0; 557 if(i1_ref_frame0 >= 0) 558 ps_cur_mb_info->u2_mask[i++] = ui2_mask_fwd; 559 if(i1_ref_frame1 >= 0) 560 ps_cur_mb_info->u2_mask[i] = ui2_mask_bwd; 561 562 /*if(u1_init) 563 H264_DEC_DEBUG_PRINT("hit\n"); 564 else 565 H264_DEC_DEBUG_PRINT("miss\n");*/ 566 567 return OK; 568} 569 570/*! 571 ************************************************************************** 572 * \if Function name : ih264d_decode_temporal_direct \endif 573 * 574 * \brief 575 * Decodes temporal direct mode. 576 * 577 * \return 578 * None. 579 * 580 ************************************************************************** 581 */ 582WORD32 ih264d_decode_temporal_direct(dec_struct_t * ps_dec, 583 UWORD8 u1_wd_x, 584 dec_mb_info_t * ps_cur_mb_info, 585 UWORD8 u1_mb_num) 586{ 587 struct pic_buffer_t *ps_pic_buff0, *ps_pic_buff1, *ps_col_pic; 588 mv_pred_t *ps_mv, s_temp_mv_pred; 589 UWORD8 u1_sub_mb_num; 590 UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag; 591 WORD16 i2_mv_x0, i2_mv_y0, i2_mv_x1, i2_mv_y1; 592 UWORD8 u1_mb_partw, u1_mb_parth; 593 UWORD8 i, partition_size, sub_partition; 594 UWORD32 *pui32_weight_ofsts = NULL; 595 directmv_t s_mvdirect; 596 const UWORD8 *pu1_mb_parth = (const UWORD8 *)gau1_ih264d_mb_parth; 597 const UWORD8 *pu1_mb_partw = (const UWORD8 *)gau1_ih264d_mb_partw; 598 WORD8 c_refFrm0, c_refFrm1; 599 UWORD8 u1_ref_idx0, u1_is_cur_mb_fld; 600 UWORD32 pic0_poc, pic1_poc, cur_poc; 601 WORD32 ret = 0; 602 603 u1_is_cur_mb_fld = ps_cur_mb_info->u1_mb_field_decodingflag; 604 ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][0]; 605 606 /**********************************************************************/ 607 /* Call the function which gets the number of partitions and */ 608 /* partition info of colocated Mb */ 609 /**********************************************************************/ 610 ps_dec->pf_parse_mvdirect(ps_dec, ps_dec->ps_col_pic, &s_mvdirect, u1_wd_x, 611 ps_dec->i4_submb_ofst, ps_cur_mb_info); 612 ps_col_pic = ps_dec->ps_col_pic; 613 614 for(i = 0; i < s_mvdirect.i1_num_partitions; i++) 615 { 616 UWORD8 u1_colz; 617 partition_size = s_mvdirect.i1_partitionsize[i]; 618 u1_sub_mb_num = s_mvdirect.i1_submb_num[i]; 619 ps_mv = ps_col_pic->ps_mv + s_mvdirect.i4_mv_indices[i]; 620 621 /* This should be removed to catch unitialized memory read */ 622 u1_ref_idx0 = 0; 623 624 sub_partition = partition_size >> 2; 625 partition_size &= 0x3; 626 u1_mb_partw = pu1_mb_partw[partition_size]; 627 u1_mb_parth = pu1_mb_parth[partition_size]; 628 if(sub_partition != 0) 629 { 630 u1_mb_partw >>= 1; 631 u1_mb_parth >>= 1; 632 } 633 c_refFrm0 = ps_mv->i1_ref_frame[0]; 634 c_refFrm1 = ps_mv->i1_ref_frame[1]; 635 636 if((c_refFrm0 == -1) && (c_refFrm1 == -1)) 637 { 638 u1_ref_idx0 = 0; 639 ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][0]; 640 if(u1_mbaff && u1_is_cur_mb_fld) 641 { 642 if(ps_cur_mb_info->u1_topmb) 643 { 644 pic0_poc = ps_pic_buff0->i4_top_field_order_cnt; 645 pic1_poc = ps_pic_buff1->i4_top_field_order_cnt; 646 cur_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt; 647 } 648 else 649 { 650 pic1_poc = ps_pic_buff1->i4_bottom_field_order_cnt; 651 cur_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt; 652 ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][MAX_REF_BUFS]; 653 pic0_poc = ps_pic_buff0->i4_bottom_field_order_cnt; 654 ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][MAX_REF_BUFS]; 655 } 656 } 657 else 658 { 659 pic0_poc = ps_pic_buff0->i4_avg_poc; 660 pic1_poc = ps_pic_buff1->i4_avg_poc; 661 cur_poc = ps_dec->ps_cur_pic->i4_poc; 662 } 663 } 664 else 665 { 666 UWORD8 uc_i, u1_num_frw_ref_pics; 667 UWORD8 buf_id, u1_pic_type; 668 buf_id = ps_mv->u1_col_ref_pic_idx; 669 u1_pic_type = ps_mv->u1_pic_type; 670 if(ps_dec->ps_cur_slice->u1_field_pic_flag) 671 { 672 if(s_mvdirect.u1_vert_mv_scale == FRM_TO_FLD) 673 { 674 u1_pic_type = TOP_FLD; 675 if(ps_dec->ps_cur_slice->u1_bottom_field_flag) 676 u1_pic_type = BOT_FLD; 677 } 678 } 679 u1_num_frw_ref_pics = 680 ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0]; 681 682 for(uc_i = 0; uc_i < u1_num_frw_ref_pics; uc_i++) 683 { 684 if(ps_dec->ps_cur_slice->u1_field_pic_flag) 685 { 686 if(ps_dec->ps_ref_pic_buf_lx[0][uc_i]->u1_mv_buf_id == buf_id) 687 { 688 if(ps_dec->ps_ref_pic_buf_lx[0][uc_i]->u1_pic_type 689 == u1_pic_type) 690 { 691 u1_ref_idx0 = uc_i; 692 break; 693 } 694 } 695 } 696 else 697 { 698 if(ps_dec->ps_ref_pic_buf_lx[0][uc_i]->u1_mv_buf_id == buf_id) 699 { 700 u1_ref_idx0 = uc_i; 701 break; 702 } 703 } 704 } 705 706 ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][u1_ref_idx0]; 707 ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][0]; 708 709 if(u1_mbaff && u1_is_cur_mb_fld) 710 { 711 pic0_poc = ps_pic_buff0->i4_top_field_order_cnt; 712 u1_ref_idx0 <<= 1; 713 if(s_mvdirect.u1_vert_mv_scale == ONE_TO_ONE) 714 { 715 if(u1_pic_type == BOT_FLD) 716 { 717 pic0_poc = ps_pic_buff0->i4_bottom_field_order_cnt; 718 ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][(u1_ref_idx0 719 >> 1) + MAX_REF_BUFS]; 720 if(ps_cur_mb_info->u1_topmb) 721 u1_ref_idx0++; 722 } 723 else 724 { 725 if(1 - ps_cur_mb_info->u1_topmb) 726 u1_ref_idx0++; 727 } 728 } 729 if(s_mvdirect.u1_vert_mv_scale == FRM_TO_FLD) 730 { 731 if(1 - ps_cur_mb_info->u1_topmb) 732 { 733 pic0_poc = ps_pic_buff0->i4_bottom_field_order_cnt; 734 ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][(u1_ref_idx0 735 >> 1) + MAX_REF_BUFS]; 736 } 737 } 738 if(ps_cur_mb_info->u1_topmb) 739 { 740 pic1_poc = ps_pic_buff1->i4_top_field_order_cnt; 741 cur_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt; 742 } 743 else 744 { 745 pic1_poc = ps_pic_buff1->i4_bottom_field_order_cnt; 746 cur_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt; 747 ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][MAX_REF_BUFS]; 748 } 749 } 750 else 751 { 752 pic0_poc = ps_pic_buff0->i4_avg_poc; 753 pic1_poc = ps_pic_buff1->i4_avg_poc; 754 cur_poc = ps_dec->ps_cur_pic->i4_poc; 755 } 756 } 757 { 758 WORD16 i16_td; 759 760 if(c_refFrm0 >= 0) 761 { 762 i2_mv_x0 = ps_mv->i2_mv[0]; 763 i2_mv_y0 = ps_mv->i2_mv[1]; 764 } 765 else if(c_refFrm1 >= 0) 766 { 767 i2_mv_x0 = ps_mv->i2_mv[2]; 768 i2_mv_y0 = ps_mv->i2_mv[3]; 769 } 770 else 771 { 772 i2_mv_x0 = 0; 773 i2_mv_y0 = 0; 774 } 775 /* If FRM_TO_FLD or FLD_TO_FRM scale the "y" component of the colocated Mv*/ 776 if(s_mvdirect.u1_vert_mv_scale == FRM_TO_FLD) 777 { 778 i2_mv_y0 /= 2; 779 } 780 else if(s_mvdirect.u1_vert_mv_scale == FLD_TO_FRM) 781 { 782 i2_mv_y0 *= 2; 783 } 784 785 i16_td = pic1_poc - pic0_poc; 786 if((ps_pic_buff0->u1_is_short == 0) || (i16_td == 0)) 787 { 788 i2_mv_x1 = 0; 789 i2_mv_y1 = 0; 790 } 791 else 792 { 793 WORD16 i16_tb, i16_tx, i2_dist_scale_factor, i16_temp; 794 795 i16_td = CLIP3(-128, 127, i16_td); 796 i16_tb = cur_poc - pic0_poc; 797 i16_tb = CLIP3(-128, 127, i16_tb); 798 799 i16_tx = (16384 + ABS(SIGN_POW2_DIV(i16_td, 1))) / i16_td; 800 i2_dist_scale_factor = CLIP3(-1024, 1023, 801 (((i16_tb * i16_tx) + 32) >> 6)); 802 i16_temp = (i2_mv_x0 * i2_dist_scale_factor + 128) >> 8; 803 i2_mv_x1 = i16_temp - i2_mv_x0; 804 i2_mv_x0 = i16_temp; 805 806 i16_temp = (i2_mv_y0 * i2_dist_scale_factor + 128) >> 8; 807 i2_mv_y1 = i16_temp - i2_mv_y0; 808 i2_mv_y0 = i16_temp; 809 } 810 { 811 mv_pred_t *ps_mv; 812 813 /*u1_sub_mb_x = u1_sub_mb_num & 0x03; 814 uc_sub_mb_y = u1_sub_mb_num >> 2;*/ 815 if(ps_dec->ps_cur_pps->u1_wted_bipred_idc) 816 { 817 UWORD8 u1_idx = 818 u1_ref_idx0 819 * ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1]; 820 UWORD8 u1_scale_ref = u1_mbaff && u1_is_cur_mb_fld; 821 if(u1_scale_ref) 822 u1_idx >>= 1; 823 pui32_weight_ofsts = (UWORD32*)&ps_dec->pu4_wt_ofsts[2 824 * X3(u1_idx)]; 825 if(u1_scale_ref 826 && (ps_dec->ps_cur_pps->u1_wted_bipred_idc 827 == 2)) 828 { 829 WORD16 i2_ref_idx; 830 i2_ref_idx = u1_ref_idx0; 831 i2_ref_idx *= 832 (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1] 833 << 1); 834 if(!ps_cur_mb_info->u1_topmb) 835 i2_ref_idx += 836 (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0] 837 << 1) 838 * (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1] 839 << 1); 840 pui32_weight_ofsts = 841 (UWORD32*)&ps_dec->pu4_mbaff_wt_mat[2 842 * X3(i2_ref_idx)]; 843 } 844 } 845 { 846 pred_info_pkd_t *ps_pred_pkd; 847 WORD16 i2_mv[2]; 848 WORD8 i1_ref_idx= 0; 849 850 i2_mv[0] = i2_mv_x0; 851 i2_mv[1] = i2_mv_y0; 852 853 ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx; 854 ih264d_fill_pred_info(i2_mv,u1_mb_partw,u1_mb_parth,u1_sub_mb_num,PRED_L0 | PRED_L1, 855 ps_pred_pkd,ps_pic_buff0->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts, 856 ps_pic_buff0->u1_pic_type); 857 ps_dec->u4_pred_info_pkd_idx++; 858 ps_cur_mb_info->u1_num_pred_parts++; 859 860 861 } 862 { 863 pred_info_pkd_t *ps_pred_pkd; 864 WORD16 i2_mv[2]; 865 WORD8 i1_ref_idx= 0; 866 867 i2_mv[0] = i2_mv_x1; 868 i2_mv[1] = i2_mv_y1; 869 870 ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx; 871 ih264d_fill_pred_info(i2_mv,u1_mb_partw,u1_mb_parth,u1_sub_mb_num,PRED_L0 | PRED_L1, 872 ps_pred_pkd,ps_pic_buff1->u1_pic_buf_id,i1_ref_idx,pui32_weight_ofsts, 873 ps_pic_buff1->u1_pic_type); 874 ps_dec->u4_pred_info_pkd_idx++; 875 ps_cur_mb_info->u1_num_pred_parts++; 876 877 878 } 879 880 /* Replication optimisation */ 881 s_temp_mv_pred.i2_mv[0] = i2_mv_x0; 882 s_temp_mv_pred.i2_mv[1] = i2_mv_y0; 883 s_temp_mv_pred.i2_mv[2] = i2_mv_x1; 884 s_temp_mv_pred.i2_mv[3] = i2_mv_y1; 885 s_temp_mv_pred.i1_ref_frame[0] = u1_ref_idx0; 886 s_temp_mv_pred.i1_ref_frame[1] = 0; 887 s_temp_mv_pred.u1_col_ref_pic_idx = ps_pic_buff0->u1_mv_buf_id; 888 s_temp_mv_pred.u1_pic_type = ps_pic_buff0->u1_pic_type; 889 ps_mv = ps_dec->ps_mv_cur + (u1_mb_num << 4) + u1_sub_mb_num; 890 891 { 892 WORD16 i2_mv_x = 0, i2_mv_y = 0; 893 UWORD8 u1_packed_mb_sub_mb_mode = 894 sub_partition ? (s_mvdirect.i1_partitionsize[i]) : ((s_mvdirect.i1_partitionsize[i]) 895 << 2); 896 897 if(c_refFrm0 >= 0) 898 { 899 i2_mv_x = i2_mv_x0; 900 i2_mv_y = i2_mv_y0; 901 } 902 else 903 { 904 i2_mv_x = i2_mv_x1; 905 i2_mv_y = i2_mv_y1; 906 } 907 908 u1_colz = 909 (ps_cur_mb_info->u1_mb_field_decodingflag << 1) 910 | ((u1_ref_idx0 == 0) 911 && (ABS(i2_mv_x) 912 <= 1) 913 && (ABS(i2_mv_y) 914 <= 1)); 915 u1_colz |= (u1_packed_mb_sub_mb_mode << 4); 916 } 917 ih264d_rep_mv_colz(ps_dec, &s_temp_mv_pred, ps_mv, u1_sub_mb_num, 918 u1_colz, u1_mb_parth, u1_mb_partw); 919 } 920 } 921 } 922 /* return value set to UWORD8 to make it homogeneous */ 923 /* with decodespatialdirect */ 924 return OK; 925} 926 927void ih264d_convert_frm_to_fld_list(struct pic_buffer_t *ps_ref_pic_buf_lx, 928 UWORD8 *pu1_L0, 929 dec_struct_t *ps_dec, 930 UWORD8 u1_num_short_term_bufs) 931{ 932 UWORD8 uc_count = *pu1_L0, i, uc_l1, uc_lx, j; 933 struct pic_buffer_t *ps_ref_lx[2], *ps_ref_pic_lx; 934 UWORD8 u1_bottom_field_flag; 935 dec_slice_params_t *ps_cur_slice; 936 UWORD8 u1_ref[2], u1_fld[2], u1_same_fld, u1_op_fld; 937 UWORD32 ui_half_num_of_sub_mbs; 938 939 uc_l1 = 0; 940 uc_lx = 0; 941 ps_cur_slice = ps_dec->ps_cur_slice; 942 ps_ref_pic_lx = ps_ref_pic_buf_lx - MAX_REF_BUFS; 943 ps_ref_lx[0] = ps_ref_pic_buf_lx; 944 ps_ref_lx[1] = ps_ref_pic_buf_lx; 945 u1_bottom_field_flag = ps_cur_slice->u1_bottom_field_flag; 946 ui_half_num_of_sub_mbs = ((ps_dec->u2_pic_ht * ps_dec->u2_pic_wd) >> 5); 947 if(u1_bottom_field_flag) 948 { 949 u1_ref[0] = BOT_REF; 950 u1_ref[1] = TOP_REF; 951 u1_fld[0] = BOT_FLD; 952 u1_fld[1] = TOP_FLD; 953 u1_same_fld = BOT_FLD; 954 u1_op_fld = TOP_FLD; 955 } 956 else 957 { 958 u1_ref[0] = TOP_REF; 959 u1_ref[1] = BOT_REF; 960 u1_fld[0] = TOP_FLD; 961 u1_fld[1] = BOT_FLD; 962 u1_same_fld = TOP_FLD; 963 u1_op_fld = BOT_FLD; 964 } 965 966 /* Create the field list starting with all the short term */ 967 /* frames followed by all the long term frames. No long term */ 968 /* reference field should have a list idx less than a short */ 969 /* term reference field during initiailization. */ 970 971 for(j = 0; j < 2; j++) 972 { 973 i = ((j == 0) ? 0 : u1_num_short_term_bufs); 974 uc_count = ((j == 0) ? u1_num_short_term_bufs : *pu1_L0); 975 for(; i < uc_count; i++, ps_ref_lx[0]++) 976 { 977 /* Search field of same parity in Frame list */ 978 if((ps_ref_lx[0]->u1_pic_type & u1_ref[0])) // || ((ps_ref_lx[0]->u1_picturetype & 0x3) == 0)) 979 { 980 /* Insert PIC of same parity in RefPicList */ 981 ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_lx, ps_ref_lx[0]); 982 ps_ref_pic_lx->i4_pic_num = (ps_ref_pic_lx->i4_pic_num * 2 + 1); 983 ps_ref_pic_lx->u1_long_term_pic_num = 984 (ps_ref_pic_lx->u1_long_term_frm_idx * 2 + 1); 985 ps_ref_pic_lx->u1_pic_type = u1_same_fld; 986 if(u1_fld[0] & BOT_FLD) 987 { 988 ps_ref_pic_lx->u1_pic_type = BOT_FLD; 989 ps_ref_pic_lx->pu1_buf1 += ps_ref_pic_lx->u2_frm_wd_y; 990 ps_ref_pic_lx->pu1_buf2 += ps_ref_pic_lx->u2_frm_wd_uv; 991 ps_ref_pic_lx->pu1_buf3 += ps_ref_pic_lx->u2_frm_wd_uv; 992 if(ps_ref_pic_lx->u1_picturetype & 0x3) 993 { 994 ps_ref_pic_lx->pu1_col_zero_flag += ui_half_num_of_sub_mbs; 995 ps_ref_pic_lx->ps_mv += ui_half_num_of_sub_mbs; 996 } 997 ps_ref_pic_lx->i4_poc = 998 ps_ref_pic_lx->i4_bottom_field_order_cnt; 999 ps_ref_pic_lx->i4_avg_poc = 1000 ps_ref_pic_lx->i4_bottom_field_order_cnt; 1001 } 1002 else 1003 { 1004 ps_ref_pic_lx->u1_pic_type = TOP_FLD; 1005 ps_ref_pic_lx->i4_poc = ps_ref_pic_lx->i4_top_field_order_cnt; 1006 ps_ref_pic_lx->i4_avg_poc = 1007 ps_ref_pic_lx->i4_top_field_order_cnt; 1008 } 1009 1010 ps_ref_pic_lx++; 1011 uc_lx++; 1012 /* Find field of opposite parity */ 1013 if(uc_l1 < uc_count && ps_ref_lx[1]) 1014 { 1015 while(!(ps_ref_lx[1]->u1_pic_type & u1_ref[1])) 1016 { 1017 ps_ref_lx[1]++; 1018 uc_l1++; 1019 if(uc_l1 >= uc_count) 1020 ps_ref_lx[1] = 0; 1021 if(!ps_ref_lx[1]) 1022 break; 1023 } 1024 1025 if(ps_ref_lx[1]) 1026 { 1027 uc_l1++; 1028 ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_lx, 1029 ps_ref_lx[1]); 1030 ps_ref_pic_lx->u1_pic_type = u1_op_fld; 1031 ps_ref_pic_lx->i4_pic_num = (ps_ref_pic_lx->i4_pic_num * 2); 1032 ps_ref_pic_lx->u1_long_term_pic_num = 1033 (ps_ref_pic_lx->u1_long_term_frm_idx * 2); 1034 if(u1_fld[1] & BOT_FLD) 1035 { 1036 ps_ref_pic_lx->u1_pic_type = BOT_FLD; 1037 ps_ref_pic_lx->pu1_buf1 += ps_ref_pic_lx->u2_frm_wd_y; 1038 ps_ref_pic_lx->pu1_buf2 += ps_ref_pic_lx->u2_frm_wd_uv; 1039 ps_ref_pic_lx->pu1_buf3 += ps_ref_pic_lx->u2_frm_wd_uv; 1040 if(ps_ref_pic_lx->u1_picturetype & 0x3) 1041 { 1042 ps_ref_pic_lx->pu1_col_zero_flag += 1043 ui_half_num_of_sub_mbs; 1044 ps_ref_pic_lx->ps_mv += ui_half_num_of_sub_mbs; 1045 } 1046 ps_ref_pic_lx->i4_poc = 1047 ps_ref_pic_lx->i4_bottom_field_order_cnt; 1048 ps_ref_pic_lx->i4_avg_poc = 1049 ps_ref_pic_lx->i4_bottom_field_order_cnt; 1050 } 1051 else 1052 { 1053 ps_ref_pic_lx->u1_pic_type = TOP_FLD; 1054 ps_ref_pic_lx->i4_poc = 1055 ps_ref_pic_lx->i4_top_field_order_cnt; 1056 ps_ref_pic_lx->i4_avg_poc = 1057 ps_ref_pic_lx->i4_top_field_order_cnt; 1058 } 1059 ps_ref_pic_lx++; 1060 uc_lx++; 1061 ps_ref_lx[1]++; 1062 } 1063 } 1064 } 1065 } 1066 1067 /* Same parity fields are over, now insert left over opposite parity fields */ 1068 /** Added if(ps_ref_lx[1]) for error checks */ 1069 if(ps_ref_lx[1]) 1070 { 1071 for(; uc_l1 < uc_count; uc_l1++) 1072 { 1073 if(ps_ref_lx[1]->u1_pic_type & u1_ref[1]) 1074 { 1075 /* Insert PIC of opposite parity in RefPicList */ 1076 ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_lx, 1077 ps_ref_lx[1]); 1078 ps_ref_pic_lx->u1_pic_type = u1_op_fld; 1079 ps_ref_pic_lx->i4_pic_num = (ps_ref_pic_lx->i4_pic_num * 2); 1080 ps_ref_pic_lx->u1_long_term_pic_num = 1081 (ps_ref_pic_lx->u1_long_term_frm_idx * 2); 1082 if(u1_op_fld == BOT_FLD) 1083 { 1084 ps_ref_pic_lx->u1_pic_type = BOT_FLD; 1085 ps_ref_pic_lx->pu1_buf1 += ps_ref_pic_lx->u2_frm_wd_y; 1086 ps_ref_pic_lx->pu1_buf2 += ps_ref_pic_lx->u2_frm_wd_uv; 1087 ps_ref_pic_lx->pu1_buf3 += ps_ref_pic_lx->u2_frm_wd_uv; 1088 if(ps_ref_pic_lx->u1_picturetype & 0x3) 1089 { 1090 ps_ref_pic_lx->pu1_col_zero_flag += 1091 ui_half_num_of_sub_mbs; 1092 ps_ref_pic_lx->ps_mv += ui_half_num_of_sub_mbs; 1093 } 1094 ps_ref_pic_lx->i4_poc = 1095 ps_ref_pic_lx->i4_bottom_field_order_cnt; 1096 ps_ref_pic_lx->i4_avg_poc = 1097 ps_ref_pic_lx->i4_bottom_field_order_cnt; 1098 } 1099 else 1100 { 1101 ps_ref_pic_lx->i4_poc = 1102 ps_ref_pic_lx->i4_top_field_order_cnt; 1103 ps_ref_pic_lx->i4_avg_poc = 1104 ps_ref_pic_lx->i4_top_field_order_cnt; 1105 } 1106 ps_ref_pic_lx++; 1107 uc_lx++; 1108 ps_ref_lx[1]++; 1109 } 1110 } 1111 } 1112 } 1113 *pu1_L0 = uc_lx; 1114} 1115 1116void ih264d_convert_frm_mbaff_list(dec_struct_t *ps_dec) 1117{ 1118 struct pic_buffer_t **ps_ref_pic_lx; 1119 UWORD8 u1_max_ref_idx, idx; 1120 UWORD16 u2_frm_wd_y, u2_frm_wd_uv; 1121 struct pic_buffer_t **ps_ref_pic_buf_lx; 1122 UWORD32 u4_half_num_of_sub_mbs = ((ps_dec->u2_pic_ht * ps_dec->u2_pic_wd) >> 5); 1123 1124 ps_ref_pic_buf_lx = ps_dec->ps_ref_pic_buf_lx[0]; 1125 ps_ref_pic_lx = ps_dec->ps_ref_pic_buf_lx[0]; 1126 u1_max_ref_idx = ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0]; 1127 for(idx = 0; idx < u1_max_ref_idx; idx++) 1128 { 1129 ps_ref_pic_lx[idx]->u1_pic_type = TOP_FLD; 1130 ps_ref_pic_lx[idx]->i4_poc = ps_ref_pic_lx[idx]->i4_top_field_order_cnt; 1131 1132 } 1133 u2_frm_wd_y = ps_dec->u2_frm_wd_y; 1134 u2_frm_wd_uv = ps_dec->u2_frm_wd_uv; 1135 1136 for(idx = 0; idx < u1_max_ref_idx; idx++) 1137 { 1138 *ps_ref_pic_lx[idx + MAX_REF_BUFS] = *ps_ref_pic_buf_lx[idx]; 1139 ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_buf1 = 1140 ps_ref_pic_buf_lx[idx]->pu1_buf1 + u2_frm_wd_y; 1141 ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_buf2 = 1142 ps_ref_pic_buf_lx[idx]->pu1_buf2 + u2_frm_wd_uv; 1143 ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_buf3 = 1144 ps_ref_pic_buf_lx[idx]->pu1_buf3 + u2_frm_wd_uv; 1145 1146 ps_ref_pic_lx[idx + MAX_REF_BUFS]->u1_pic_type = BOT_FLD; 1147 ps_ref_pic_lx[idx + MAX_REF_BUFS]->i4_poc = 1148 ps_ref_pic_buf_lx[idx]->i4_bottom_field_order_cnt; 1149 if(ps_ref_pic_buf_lx[idx]->u1_picturetype & 0x3) 1150 { 1151 ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_col_zero_flag = 1152 ps_ref_pic_buf_lx[idx]->pu1_col_zero_flag 1153 + u4_half_num_of_sub_mbs; 1154 ps_ref_pic_lx[idx + MAX_REF_BUFS]->ps_mv = 1155 ps_ref_pic_buf_lx[idx]->ps_mv + u4_half_num_of_sub_mbs; 1156 } 1157 } 1158 1159 if(ps_dec->u1_B) 1160 { 1161 ps_ref_pic_buf_lx = ps_dec->ps_ref_pic_buf_lx[1]; 1162 ps_ref_pic_lx = ps_dec->ps_ref_pic_buf_lx[1]; 1163 u1_max_ref_idx = ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1]; 1164 for(idx = 0; idx < u1_max_ref_idx; idx++) 1165 { 1166 ps_ref_pic_lx[idx]->u1_pic_type = TOP_FLD; 1167 ps_ref_pic_lx[idx]->i4_poc = ps_ref_pic_lx[idx]->i4_top_field_order_cnt; 1168 1169 } 1170 1171 for(idx = 0; idx < u1_max_ref_idx; idx++) 1172 { 1173 *ps_ref_pic_lx[idx + MAX_REF_BUFS] = *ps_ref_pic_buf_lx[idx]; 1174 ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_buf1 = 1175 ps_ref_pic_buf_lx[idx]->pu1_buf1 + u2_frm_wd_y; 1176 ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_buf2 = 1177 ps_ref_pic_buf_lx[idx]->pu1_buf2 + u2_frm_wd_uv; 1178 ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_buf3 = 1179 ps_ref_pic_buf_lx[idx]->pu1_buf3 + u2_frm_wd_uv; 1180 ps_ref_pic_lx[idx + MAX_REF_BUFS]->u1_pic_type = BOT_FLD; 1181 ps_ref_pic_lx[idx + MAX_REF_BUFS]->i4_poc = 1182 ps_ref_pic_buf_lx[idx]->i4_bottom_field_order_cnt; 1183 1184 if(ps_ref_pic_buf_lx[idx]->u1_picturetype & 0x3) 1185 { 1186 ps_ref_pic_lx[idx + MAX_REF_BUFS]->pu1_col_zero_flag = 1187 ps_ref_pic_buf_lx[idx]->pu1_col_zero_flag 1188 + u4_half_num_of_sub_mbs; 1189 ps_ref_pic_lx[idx + MAX_REF_BUFS]->ps_mv = 1190 ps_ref_pic_buf_lx[idx]->ps_mv 1191 + u4_half_num_of_sub_mbs; 1192 } 1193 } 1194 } 1195} 1196/*! 1197 ************************************************************************** 1198 * \if Function name : ih264d_init_ref_idx_lx_b \endif 1199 * 1200 * \brief 1201 * Initializes forward and backward refernce lists for B slice decoding. 1202 * 1203 * 1204 * \return 1205 * 0 on Success and Error code otherwise 1206 ************************************************************************** 1207 */ 1208void ih264d_init_ref_idx_lx_b(dec_struct_t *ps_dec) 1209{ 1210 struct pic_buffer_t *ps_ref_pic_buf_lx; 1211 dpb_manager_t *ps_dpb_mgr; 1212 struct dpb_info_t *ps_next_dpb; 1213 WORD32 i_cur_poc, i_max_st_poc, i_min_st_poc, i_ref_poc, i_temp_poc; 1214 WORD8 i; 1215 UWORD8 u1_max_lt_index, u1_min_lt_index, u1_lt_index; 1216 UWORD8 u1_field_pic_flag; 1217 dec_slice_params_t *ps_cur_slice; 1218 UWORD8 u1_L0, u1_L1; 1219 UWORD8 u1_num_short_term_bufs; 1220 UWORD8 u1_max_ref_idx_l0, u1_max_ref_idx_l1; 1221 1222 ps_cur_slice = ps_dec->ps_cur_slice; 1223 u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag; 1224 u1_max_ref_idx_l0 = ps_cur_slice->u1_num_ref_idx_lx_active[0] 1225 << u1_field_pic_flag; 1226 u1_max_ref_idx_l1 = ps_cur_slice->u1_num_ref_idx_lx_active[1] 1227 << u1_field_pic_flag; 1228 1229 ps_dpb_mgr = ps_dec->ps_dpb_mgr; 1230 /* Get the current POC */ 1231 i_cur_poc = ps_dec->ps_cur_pic->i4_poc; 1232 1233 /* Get MaxStPOC,MinStPOC,MaxLt,MinLt */ 1234 i_max_st_poc = i_cur_poc; 1235 i_min_st_poc = i_cur_poc; 1236 u1_max_lt_index = MAX_REF_BUFS + 1; 1237 u1_min_lt_index = MAX_REF_BUFS + 1; 1238 /* Start from ST head */ 1239 ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head; 1240 for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++) 1241 { 1242 i_ref_poc = ps_next_dpb->ps_pic_buf->i4_poc; 1243 if(i_ref_poc < i_cur_poc) 1244 { 1245 /* RefPic Buf POC is before Current POC in display order */ 1246 i_min_st_poc = MIN(i_min_st_poc, i_ref_poc); 1247 } 1248 else 1249 { 1250 /* RefPic Buf POC is after Current POC in display order */ 1251 i_max_st_poc = MAX(i_max_st_poc, i_ref_poc); 1252 } 1253 1254 /* Chase the next link */ 1255 ps_next_dpb = ps_next_dpb->ps_prev_short; 1256 } 1257 1258 /* Start from LT head */ 1259 ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head; 1260 if(ps_next_dpb) 1261 { 1262 u1_max_lt_index = ps_next_dpb->u1_lt_idx; 1263 u1_min_lt_index = ps_next_dpb->u1_lt_idx; 1264 } 1265 for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++) 1266 { 1267 u1_lt_index = ps_next_dpb->u1_lt_idx; 1268 u1_max_lt_index = (UWORD8)(MAX(u1_max_lt_index, u1_lt_index)); 1269 u1_min_lt_index = (UWORD8)(MIN(u1_min_lt_index, u1_lt_index)); 1270 1271 /* Chase the next link */ 1272 ps_next_dpb = ps_next_dpb->ps_prev_long; 1273 } 1274 1275 /* 1. Initialize refIdxL0 */ 1276 u1_L0 = 0; 1277 if(u1_field_pic_flag) 1278 { 1279 ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0]; 1280 ps_ref_pic_buf_lx += MAX_REF_BUFS; 1281 i_temp_poc = i_cur_poc; 1282 } 1283 else 1284 { 1285 ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0]; 1286 i_temp_poc = i_cur_poc - 1; 1287 } 1288 /* Arrange all short term buffers in output order as given by POC */ 1289 /* 1.1 Arrange POC's less than CurrPOC in the descending POC order starting 1290 from (CurrPOC - 1)*/ 1291 for(; i_temp_poc >= i_min_st_poc; i_temp_poc--) 1292 { 1293 /* Start from ST head */ 1294 ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head; 1295 for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++) 1296 { 1297 if((WORD32)ps_next_dpb->ps_pic_buf->i4_poc == i_temp_poc) 1298 { 1299 /* Copy info in pic buffer */ 1300 ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx, 1301 ps_next_dpb->ps_pic_buf); 1302 ps_ref_pic_buf_lx++; 1303 u1_L0++; 1304 break; 1305 } 1306 ps_next_dpb = ps_next_dpb->ps_prev_short; 1307 } 1308 } 1309 1310 { 1311 /* 1.2. Arrange POC's more than CurrPOC in the ascending POC order starting 1312 from (CurrPOC + 1)*/ 1313 for(i_temp_poc = i_cur_poc + 1; i_temp_poc <= i_max_st_poc; i_temp_poc++) 1314 { 1315 /* Start from ST head */ 1316 ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head; 1317 for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++) 1318 { 1319 if((WORD32)ps_next_dpb->ps_pic_buf->i4_poc == i_temp_poc) 1320 { 1321 ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx, 1322 ps_next_dpb->ps_pic_buf); 1323 ps_ref_pic_buf_lx++; 1324 u1_L0++; 1325 break; 1326 } 1327 ps_next_dpb = ps_next_dpb->ps_prev_short; 1328 } 1329 } 1330 } 1331 1332 /* 1.3 Arrange all Long term buffers in ascending order, in LongtermIndex */ 1333 /* Start from ST head */ 1334 1335 u1_num_short_term_bufs = u1_L0; 1336 for(u1_lt_index = u1_min_lt_index; u1_lt_index <= u1_max_lt_index; u1_lt_index++) 1337 { 1338 ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head; 1339 for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++) 1340 { 1341 if(ps_next_dpb->u1_lt_idx == u1_lt_index) 1342 { 1343 ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx, 1344 ps_next_dpb->ps_pic_buf); 1345 ps_ref_pic_buf_lx->u1_long_term_pic_num = 1346 ps_ref_pic_buf_lx->u1_long_term_frm_idx; 1347 1348 ps_ref_pic_buf_lx++; 1349 u1_L0++; 1350 break; 1351 } 1352 ps_next_dpb = ps_next_dpb->ps_prev_long; 1353 } 1354 } 1355 1356 if(u1_field_pic_flag) 1357 { 1358 /* Initialize the rest of the entries in the */ 1359 /* reference list to handle of errors */ 1360 { 1361 UWORD8 u1_i; 1362 pic_buffer_t *ps_ref_pic; 1363 1364 ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS; 1365 1366 if(NULL == ps_ref_pic->pu1_buf1) 1367 { 1368 ps_ref_pic = ps_dec->ps_cur_pic; 1369 } 1370 for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++) 1371 { 1372 *ps_ref_pic_buf_lx = *ps_ref_pic; 1373 ps_ref_pic_buf_lx++; 1374 } 1375 } 1376 ih264d_convert_frm_to_fld_list( 1377 ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS, &u1_L0, 1378 ps_dec, u1_num_short_term_bufs); 1379 1380 ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0] + u1_L0; 1381 } 1382 1383 ps_dec->ps_cur_slice->u1_initial_list_size[0] = u1_L0; 1384 1385 /* Initialize the rest of the entries in the */ 1386 /* reference list to handle of errors */ 1387 { 1388 UWORD8 u1_i; 1389 pic_buffer_t *ps_ref_pic; 1390 1391 ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0]; 1392 1393 if(NULL == ps_ref_pic->pu1_buf1) 1394 { 1395 ps_ref_pic = ps_dec->ps_cur_pic; 1396 } 1397 for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++) 1398 { 1399 *ps_ref_pic_buf_lx = *ps_ref_pic; 1400 ps_ref_pic_buf_lx++; 1401 } 1402 } 1403 { 1404 /* 2. Initialize refIdxL1 */ 1405 u1_L1 = 0; 1406 if(u1_field_pic_flag) 1407 { 1408 ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[1][0] + MAX_REF_BUFS; 1409 } 1410 else 1411 { 1412 ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[1][0]; 1413 } 1414 1415 /* 2.1. Arrange POC's more than CurrPOC in the ascending POC order starting 1416 from (CurrPOC + 1)*/ 1417 for(i_temp_poc = i_cur_poc + 1; i_temp_poc <= i_max_st_poc; i_temp_poc++) 1418 { 1419 /* Start from ST head */ 1420 ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head; 1421 for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++) 1422 { 1423 if((WORD32)ps_next_dpb->ps_pic_buf->i4_poc == i_temp_poc) 1424 { 1425 ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx, 1426 ps_next_dpb->ps_pic_buf); 1427 ps_ref_pic_buf_lx++; 1428 u1_L1++; 1429 break; 1430 } 1431 ps_next_dpb = ps_next_dpb->ps_prev_short; 1432 } 1433 } 1434 1435 if(u1_field_pic_flag) 1436 { 1437 i_temp_poc = i_cur_poc; 1438 } 1439 else 1440 { 1441 i_temp_poc = i_cur_poc - 1; 1442 } 1443 1444 /* Arrange all short term buffers in output order as given by POC */ 1445 /* 2.2 Arrange POC's less than CurrPOC in the descending POC order starting 1446 from (CurrPOC - 1)*/ 1447 for(; i_temp_poc >= i_min_st_poc; i_temp_poc--) 1448 { 1449 /* Start from ST head */ 1450 ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head; 1451 for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++) 1452 { 1453 if((WORD32)ps_next_dpb->ps_pic_buf->i4_poc == i_temp_poc) 1454 { 1455 ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx, 1456 ps_next_dpb->ps_pic_buf); 1457 ps_ref_pic_buf_lx++; 1458 u1_L1++; 1459 break; 1460 } 1461 ps_next_dpb = ps_next_dpb->ps_prev_short; 1462 } 1463 } 1464 1465 /* 2.3 Arrange all Long term buffers in ascending order, in LongtermIndex */ 1466 /* Start from ST head */ 1467 u1_num_short_term_bufs = u1_L1; 1468 1469 for(u1_lt_index = u1_min_lt_index; u1_lt_index <= u1_max_lt_index; 1470 u1_lt_index++) 1471 { 1472 ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head; 1473 for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++) 1474 { 1475 if(ps_next_dpb->u1_lt_idx == u1_lt_index) 1476 { 1477 ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx, 1478 ps_next_dpb->ps_pic_buf); 1479 ps_ref_pic_buf_lx->u1_long_term_pic_num = 1480 ps_ref_pic_buf_lx->u1_long_term_frm_idx; 1481 ps_ref_pic_buf_lx++; 1482 u1_L1++; 1483 break; 1484 } 1485 ps_next_dpb = ps_next_dpb->ps_prev_long; 1486 } 1487 } 1488 1489 if(u1_field_pic_flag) 1490 { 1491 /* Initialize the rest of the entries in the */ 1492 /* reference list to handle of errors */ 1493 { 1494 UWORD8 u1_i; 1495 pic_buffer_t *ps_ref_pic; 1496 1497 ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS; 1498 1499 if(NULL == ps_ref_pic->pu1_buf1) 1500 { 1501 ps_ref_pic = ps_dec->ps_cur_pic; 1502 } 1503 for(u1_i = u1_L1; u1_i < u1_max_ref_idx_l1; u1_i++) 1504 { 1505 *ps_ref_pic_buf_lx = *ps_ref_pic; 1506 ps_ref_pic_buf_lx++; 1507 } 1508 } 1509 1510 ih264d_convert_frm_to_fld_list( 1511 ps_dpb_mgr->ps_init_dpb[1][0] + MAX_REF_BUFS, 1512 &u1_L1, ps_dec, u1_num_short_term_bufs); 1513 ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[1][0] + u1_L1; 1514 } 1515 1516 ps_dec->ps_cur_slice->u1_initial_list_size[1] = u1_L1; 1517 1518 /* Initialize the rest of the entries in the */ 1519 /* reference list to handle of errors */ 1520 { 1521 UWORD8 u1_i; 1522 pic_buffer_t *ps_ref_pic; 1523 1524 ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0]; 1525 1526 if(NULL == ps_ref_pic->pu1_buf1) 1527 { 1528 ps_ref_pic = ps_dec->ps_cur_pic; 1529 } 1530 for(u1_i = u1_L1; u1_i < u1_max_ref_idx_l1; u1_i++) 1531 { 1532 *ps_ref_pic_buf_lx = *ps_ref_pic; 1533 ps_ref_pic_buf_lx++; 1534 } 1535 } 1536 1537 /* If list0 and list 1 ebtries are same then swap the 0th and 1st entry */ 1538 /* of list 1 */ 1539 { 1540 struct pic_buffer_t *ps_ref_pic1_buf_l0, *ps_ref_pic1_buf_l1; 1541 struct pic_buffer_t s_ref_pic1_buf_temp; 1542 1543 ps_ref_pic1_buf_l0 = ps_dpb_mgr->ps_init_dpb[0][0]; 1544 ps_ref_pic1_buf_l1 = ps_dpb_mgr->ps_init_dpb[1][0]; 1545 1546 if((u1_L0 == u1_L1) && (u1_L0 > 1)) 1547 { 1548 WORD32 i_index, i_swap; 1549 1550 i_swap = 1; 1551 1552 for(i_index = 0; i_index < u1_L0; i_index++) 1553 { 1554 if((ps_ref_pic1_buf_l0[i_index]).pu1_buf1 1555 != (ps_ref_pic1_buf_l1[i_index]).pu1_buf1) 1556 { 1557 i_swap = 0; 1558 break; 1559 } 1560 } 1561 if(1 == i_swap) 1562 { 1563 memcpy(&s_ref_pic1_buf_temp, &ps_ref_pic1_buf_l1[1], 1564 sizeof(struct pic_buffer_t)); 1565 memcpy(&ps_ref_pic1_buf_l1[1], &ps_ref_pic1_buf_l1[0], 1566 sizeof(struct pic_buffer_t)); 1567 memcpy(&ps_ref_pic1_buf_l1[0], &s_ref_pic1_buf_temp, 1568 sizeof(struct pic_buffer_t)); 1569 } 1570 } 1571 } 1572 } 1573} 1574 1575 1576 1577void ih264d_get_implicit_weights(dec_struct_t *ps_dec); 1578 1579/*! 1580 ************************************************************************** 1581 * \if Function name : ih264d_one_to_one \endif 1582 * 1583 * \brief 1584 * Initializes forward and backward refernce lists for B slice decoding. 1585 * 1586 * 1587 * \return 1588 * 0 on Success and Error code otherwise 1589 ************************************************************************** 1590 */ 1591void ih264d_one_to_one(dec_struct_t *ps_dec, 1592 struct pic_buffer_t *ps_col_pic, 1593 directmv_t *ps_direct, 1594 UWORD8 u1_wd_x, 1595 WORD32 u2_sub_mb_ofst, 1596 dec_mb_info_t * ps_cur_mb_info) 1597{ 1598 UWORD8 *pu1_col_zero_flag_start, u1_col_mb_pred_mode, u1_num_blks, u1_sub_mb_num; 1599 UWORD8 u1_init_colzero_flag; 1600 UNUSED(ps_cur_mb_info); 1601 pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag + u2_sub_mb_ofst; 1602 u1_col_mb_pred_mode = pu1_col_zero_flag_start[ps_dec->u1_sub_mb_num]; 1603 u1_init_colzero_flag = u1_col_mb_pred_mode & 1; 1604 u1_col_mb_pred_mode >>= 6; 1605 ps_direct->u1_vert_mv_scale = ONE_TO_ONE; 1606 ps_direct->u1_col_zeroflag_change = 0; 1607 1608 if(u1_wd_x == MB_SIZE) 1609 { 1610 ps_dec->u1_currB_type = (!!u1_col_mb_pred_mode); 1611 if(u1_col_mb_pred_mode == PRED_16x16) 1612 { 1613 ps_direct->i1_num_partitions = 1; 1614 ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst; 1615 ps_direct->i1_submb_num[0] = 0; 1616 ps_direct->i1_partitionsize[0] = PRED_16x16; 1617 1618 return; 1619 } 1620 else if(u1_col_mb_pred_mode < PRED_8x8) 1621 { 1622 ps_direct->i1_num_partitions = 2; 1623 ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst; 1624 ps_direct->i1_submb_num[0] = 0; 1625 ps_direct->i1_partitionsize[0] = u1_col_mb_pred_mode; 1626 u1_sub_mb_num = (u1_col_mb_pred_mode == PRED_16x8) ? 8 : 2; 1627 ps_direct->i1_submb_num[1] = u1_sub_mb_num; 1628 ps_direct->i4_mv_indices[1] = u2_sub_mb_ofst 1629 + ps_direct->i1_submb_num[1]; 1630 ps_direct->i1_partitionsize[1] = u1_col_mb_pred_mode; 1631 if((pu1_col_zero_flag_start[u1_sub_mb_num] & 1) != u1_init_colzero_flag) 1632 ps_direct->u1_col_zeroflag_change = 1; 1633 return; 1634 } 1635 else 1636 { 1637 u1_num_blks = 4; 1638 } 1639 } 1640 else 1641 { 1642 u1_num_blks = 1; 1643 } 1644 1645 { 1646 const UWORD8 *pu1_top_lt_mb_part_idx; 1647 UWORD8 u1_col_sub_mb_pred_mode, uc_blk, u1_sub_blk, u1_submb_col = 0; 1648 UWORD8 u1_num_sub_blks, uc_direct8x8inf, *pu1_col_zero_flag, u1_sub_mb_num; 1649 const UWORD8 *pu1_num_sub_mb_part = 1650 (const UWORD8 *)gau1_ih264d_num_submb_part; 1651 UWORD8 i1_num_partitions = 0, partition_size; 1652 WORD32 mv_index; 1653 const UWORD8 *pu1_top_lt_sub_mb_idx = gau1_ih264d_submb_indx_mod_sp_drct; 1654 1655 u1_sub_mb_num = ps_dec->u1_sub_mb_num; 1656 uc_direct8x8inf = ps_dec->ps_cur_slice->u1_direct_8x8_inference_flag; 1657 pu1_top_lt_mb_part_idx = gau1_ih264d_top_left_mb_part_indx_mod 1658 + (PRED_8x8 << 1) + 1; 1659 1660 for(uc_blk = 0; uc_blk < u1_num_blks; uc_blk++) 1661 { 1662 partition_size = PRED_8x8; 1663 pu1_top_lt_sub_mb_idx = gau1_ih264d_submb_indx_mod_sp_drct; 1664 if(uc_direct8x8inf == 1) 1665 { 1666 u1_submb_col = u1_sub_mb_num | (u1_sub_mb_num >> 1); 1667 mv_index = u2_sub_mb_ofst + u1_submb_col; 1668 u1_num_sub_blks = 1; 1669 } 1670 else 1671 { 1672 /* colMbPart is either 8x8, 8x4, 4x8, 4x4 */ 1673 pu1_col_zero_flag = pu1_col_zero_flag_start + u1_sub_mb_num; 1674 u1_col_sub_mb_pred_mode = *pu1_col_zero_flag; 1675 u1_col_sub_mb_pred_mode = (u1_col_sub_mb_pred_mode & 0x30) >> 4; 1676 partition_size = (UWORD8)((u1_col_sub_mb_pred_mode) 1677 | (PRED_8x8 << 2)); 1678 mv_index = u2_sub_mb_ofst + u1_sub_mb_num; 1679 pu1_top_lt_sub_mb_idx += (u1_col_sub_mb_pred_mode << 1); 1680 u1_num_sub_blks = pu1_num_sub_mb_part[u1_col_sub_mb_pred_mode]; 1681 1682 } 1683 1684 for(u1_sub_blk = 0; u1_sub_blk < u1_num_sub_blks; 1685 u1_sub_blk++, pu1_top_lt_sub_mb_idx++) 1686 { 1687 u1_sub_mb_num += *pu1_top_lt_sub_mb_idx; 1688 mv_index += *pu1_top_lt_sub_mb_idx; 1689 ps_direct->i4_mv_indices[i1_num_partitions] = mv_index; 1690 ps_direct->i1_submb_num[i1_num_partitions] = u1_sub_mb_num; 1691 ps_direct->i1_partitionsize[i1_num_partitions] = partition_size; 1692 i1_num_partitions++; 1693 if(!uc_direct8x8inf) 1694 u1_submb_col = u1_sub_mb_num; 1695 if((pu1_col_zero_flag_start[u1_submb_col] & 1) 1696 != u1_init_colzero_flag) 1697 ps_direct->u1_col_zeroflag_change = 1; 1698 } 1699 u1_sub_mb_num = *pu1_top_lt_mb_part_idx++; 1700 } 1701 ps_direct->i1_num_partitions = i1_num_partitions; 1702 } 1703} 1704/*! 1705 ************************************************************************** 1706 * \if Function name : ih264d_mbaff_cross_pmbair \endif 1707 * 1708 * \brief 1709 * Initializes forward and backward refernce lists for B slice decoding. 1710 * 1711 * 1712 * \return 1713 * 0 on Success and Error code otherwise 1714 ************************************************************************** 1715 */ 1716void ih264d_mbaff_cross_pmbair(dec_struct_t *ps_dec, 1717 struct pic_buffer_t *ps_col_pic, 1718 directmv_t *ps_direct, 1719 UWORD8 u1_wd_x, 1720 WORD32 u2_sub_mb_ofst, 1721 dec_mb_info_t * ps_cur_mb_info) 1722{ 1723 UWORD8 *pu1_col_zero_flag_start, *pu1_col_zero_flag, u1_sub_mb_num, 1724 uc_sub_mb_num_col; 1725 UWORD8 *pu1_col_zero_flag_right_half; 1726 WORD32 i4_force_8X8; 1727 UWORD8 u1_num_blks, u1_col_mb_pred_mode, uc_blk, u1_col_sub_mb_pred_mode, 1728 u1_col_sub_mb_pred_mode_rt; 1729 UWORD8 i1_num_partitions = 0, partition_size; 1730 1731 WORD32 mv_index; 1732 1733 UWORD8 u1_num_sub_blks; 1734 UWORD8 u1_is_cur_mb_fld, i; 1735 UWORD8 u1_init_colzero_flag; 1736 1737 u1_is_cur_mb_fld = ps_cur_mb_info->u1_mb_field_decodingflag; 1738 u1_sub_mb_num = ps_dec->u1_sub_mb_num; 1739 ps_direct->u1_col_zeroflag_change = 0; 1740 /*pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag + u2_sub_mb_ofst; 1741 u1_col_mb_pred_mode = pu1_col_zero_flag_start[u1_sub_mb_num]; 1742 u1_init_colzero_flag = u1_col_mb_pred_mode & 1; 1743 u1_col_mb_pred_mode >>= 6; */ 1744 if(0 == u1_is_cur_mb_fld) 1745 { 1746 ps_direct->u1_vert_mv_scale = FLD_TO_FRM; 1747 if(u1_wd_x == MB_SIZE) 1748 { 1749 pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag 1750 + u2_sub_mb_ofst; 1751 u1_col_mb_pred_mode = pu1_col_zero_flag_start[0]; 1752 u1_init_colzero_flag = u1_col_mb_pred_mode & 1; 1753 u1_col_mb_pred_mode >>= 6; 1754 1755 1756 if(u1_col_mb_pred_mode & 0x2) 1757 { 1758 ps_dec->u1_currB_type = 1; 1759 if(u1_col_mb_pred_mode == PRED_8x16) 1760 { 1761 ps_direct->i1_num_partitions = 2; 1762 ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst; 1763 ps_direct->i1_submb_num[0] = 0; 1764 ps_direct->i1_partitionsize[0] = PRED_8x16; 1765 ps_direct->i4_mv_indices[1] = u2_sub_mb_ofst + 2; 1766 ps_direct->i1_submb_num[1] = 2; 1767 ps_direct->i1_partitionsize[1] = PRED_8x16; 1768 if((pu1_col_zero_flag_start[2] & 1) != u1_init_colzero_flag) 1769 ps_direct->u1_col_zeroflag_change = 1; 1770 } 1771 else 1772 { 1773 pu1_col_zero_flag = pu1_col_zero_flag_start + u1_sub_mb_num; 1774 u1_col_sub_mb_pred_mode = (*pu1_col_zero_flag & 0x10);/* 8x4 or 4x4 mode */ 1775 1776 pu1_col_zero_flag_right_half = pu1_col_zero_flag_start 1777 + u1_sub_mb_num + 2; 1778 u1_col_sub_mb_pred_mode_rt = 1779 (*pu1_col_zero_flag_right_half & 0x10);/* 8x4 or 4x4 mode */ 1780 1781 i4_force_8X8 = (u1_col_sub_mb_pred_mode) 1782 || (u1_col_sub_mb_pred_mode_rt); 1783 if(i4_force_8X8) 1784 { 1785 u1_num_sub_blks = 2; 1786 partition_size = PRED_8x8; 1787 } 1788 else 1789 { 1790 partition_size = PRED_8x16; 1791 u1_num_sub_blks = 1; 1792 } 1793 1794 for(i = 0; i < 2; i++) 1795 { 1796 for(uc_blk = 0; uc_blk < u1_num_sub_blks; uc_blk++) 1797 { 1798 uc_sub_mb_num_col = u1_sub_mb_num | (u1_sub_mb_num >> 1); 1799 uc_sub_mb_num_col &= 0x7; 1800 mv_index = u2_sub_mb_ofst + uc_sub_mb_num_col; 1801 1802 ps_direct->i4_mv_indices[i1_num_partitions] = 1803 mv_index; 1804 ps_direct->i1_submb_num[i1_num_partitions] = 1805 u1_sub_mb_num; 1806 ps_direct->i1_partitionsize[i1_num_partitions] = 1807 partition_size; 1808 i1_num_partitions++; 1809 if((pu1_col_zero_flag_start[uc_sub_mb_num_col] & 1) 1810 != u1_init_colzero_flag) 1811 ps_direct->u1_col_zeroflag_change = 1; 1812 u1_sub_mb_num += 8; 1813 } 1814 u1_sub_mb_num = 2; /* move to second half of Cur MB */ 1815 } 1816 ps_direct->i1_num_partitions = i1_num_partitions; 1817 return; 1818 } 1819 } 1820 else 1821 { 1822 ps_direct->i1_num_partitions = 1; 1823 ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst; 1824 ps_direct->i1_submb_num[0] = 0; 1825 ps_direct->i1_partitionsize[0] = PRED_16x16; 1826 ps_dec->u1_currB_type = 0; 1827 return; 1828 } 1829 } 1830 else 1831 { 1832 uc_sub_mb_num_col = u1_sub_mb_num | (u1_sub_mb_num >> 1); 1833 uc_sub_mb_num_col &= 0x7; 1834 1835 ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst + uc_sub_mb_num_col; 1836 ps_direct->i1_submb_num[0] = u1_sub_mb_num; 1837 ps_direct->i1_partitionsize[0] = PRED_8x8; 1838 ps_direct->i1_num_partitions = 1; 1839 } 1840 } 1841 else 1842 { 1843 ps_direct->u1_vert_mv_scale = FRM_TO_FLD; 1844 pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag + u2_sub_mb_ofst; 1845 u1_init_colzero_flag = pu1_col_zero_flag_start[0] & 1; 1846 1847 if(u1_wd_x == MB_SIZE) 1848 { 1849 UWORD8 u1_submb_col; 1850 UWORD8 *puc_colZeroFlagStart_bot_mb, uc_colMbPredMode_bot_mb; 1851 1852 pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag 1853 + u2_sub_mb_ofst; 1854 u1_col_mb_pred_mode = pu1_col_zero_flag_start[u1_sub_mb_num] >> 6; 1855 1856 puc_colZeroFlagStart_bot_mb = ps_col_pic->pu1_col_zero_flag 1857 + u2_sub_mb_ofst + 16; 1858 uc_colMbPredMode_bot_mb = puc_colZeroFlagStart_bot_mb[8] >> 6; 1859 1860 i4_force_8X8 = (u1_col_mb_pred_mode & 0x2) 1861 || (uc_colMbPredMode_bot_mb & 0x2); 1862 if(i4_force_8X8) 1863 { 1864 u1_num_blks = 2; 1865 partition_size = PRED_8x8; 1866 } 1867 else 1868 { 1869 u1_num_blks = 1; 1870 partition_size = PRED_16x8; 1871 } 1872 1873 ps_dec->u1_currB_type = 1; 1874 /*As this mb is derived from 2 Mbs min no of partitions = 2*/ 1875 for(i = 0; i < 2; i++) 1876 { 1877 1878 pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag 1879 + u2_sub_mb_ofst; 1880 u1_col_mb_pred_mode = pu1_col_zero_flag_start[u1_sub_mb_num] >> 6; 1881 1882 for(uc_blk = 0; uc_blk < u1_num_blks; uc_blk++) 1883 { 1884 u1_submb_col = (u1_sub_mb_num & 0x7) ? 1 : 0; 1885 u1_submb_col += u1_sub_mb_num; 1886 mv_index = u2_sub_mb_ofst + u1_submb_col; 1887 1888 1889 ps_direct->i4_mv_indices[i1_num_partitions] = mv_index; 1890 ps_direct->i1_submb_num[i1_num_partitions] = u1_sub_mb_num; 1891 ps_direct->i1_partitionsize[i1_num_partitions] = 1892 partition_size; 1893 i1_num_partitions++; 1894 if((pu1_col_zero_flag_start[u1_submb_col] & 1) 1895 != u1_init_colzero_flag) 1896 ps_direct->u1_col_zeroflag_change = 1; 1897 u1_sub_mb_num += 2; 1898 } 1899 u1_sub_mb_num = 8; /* move to second half of Cur MB */ 1900 u2_sub_mb_ofst += 16;/* move to next Colocated MB */ 1901 } 1902 ps_direct->i1_num_partitions = i1_num_partitions; 1903 return; 1904 } 1905 else 1906 { 1907 uc_sub_mb_num_col = u1_sub_mb_num | (u1_sub_mb_num >> 1); 1908 uc_sub_mb_num_col &= 0xb; 1909 u2_sub_mb_ofst += (u1_sub_mb_num >> 3) ? 16 : 0; 1910 1911 ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst + uc_sub_mb_num_col; 1912 ps_direct->i1_submb_num[0] = u1_sub_mb_num; 1913 ps_direct->i1_partitionsize[0] = PRED_8x8; 1914 ps_direct->i1_num_partitions = 1; 1915 return; 1916 } 1917 } 1918} 1919/*! 1920 ************************************************************************** 1921 * \if Function name : ih264d_cal_col_pic \endif 1922 * 1923 * \brief 1924 * Finds the colocated picture. 1925 * 1926 * 1927 * \return 1928 * 0 on Success and Error code otherwise 1929 ************************************************************************** 1930 */ 1931WORD32 ih264d_cal_col_pic(dec_struct_t *ps_dec) 1932{ 1933 struct pic_buffer_t* ps_col_pic = ps_dec->ps_col_pic; 1934 UWORD8 uc_curpictype, uc_colpictype; 1935 ps_col_pic = ps_dec->ps_ref_pic_buf_lx[1][0]; 1936 uc_curpictype = (ps_dec->ps_cur_pic->u1_picturetype & 0x7); 1937 uc_colpictype = (ps_col_pic->u1_picturetype & 0x7); 1938 if(uc_curpictype == FRM_PIC) 1939 { 1940 if(uc_colpictype == FRM_PIC) 1941 ps_dec->pf_parse_mvdirect = ih264d_one_to_one; 1942 else if(uc_colpictype == COMP_FLD_PAIR) 1943 { 1944 ps_dec->pf_parse_mvdirect = ih264d_fld_to_frm; 1945 if(ps_col_pic->i4_top_field_order_cnt 1946 >= ps_col_pic->i4_bottom_field_order_cnt) 1947 { 1948 struct pic_buffer_t* ps_tempPic = ps_col_pic; 1949 UWORD32 ui_half_num_of_sub_mbs = ((ps_dec->u2_pic_ht 1950 * ps_dec->u2_pic_wd) >> 5); 1951 ps_col_pic = ps_dec->ps_ref_pic_buf_lx[1][MAX_REF_BUFS]; 1952 /* memcpy ps_tempPic to ps_col_pic */ 1953 *ps_col_pic = *ps_tempPic; 1954 ps_col_pic->pu1_buf1 = ps_tempPic->pu1_buf1 1955 + ps_tempPic->u2_frm_wd_y; 1956 ps_col_pic->pu1_buf2 = ps_tempPic->pu1_buf2 1957 + ps_tempPic->u2_frm_wd_uv; 1958 ps_col_pic->pu1_buf3 = ps_tempPic->pu1_buf3 1959 + ps_tempPic->u2_frm_wd_uv; 1960 ps_col_pic->pu1_col_zero_flag = ps_tempPic->pu1_col_zero_flag 1961 + ui_half_num_of_sub_mbs; 1962 ps_col_pic->ps_mv = ps_tempPic->ps_mv + ui_half_num_of_sub_mbs; 1963 1964 1965 ps_col_pic->u1_pic_type = 0;/*complementary reference field pair-refering as frame */ 1966 1967 1968 1969 } 1970 } 1971 else 1972 { 1973 UWORD32 i4_error_code; 1974 i4_error_code = ERROR_DBP_MANAGER_T; 1975// i4_error_code |= 1<<IVD_CORRUPTEDDATA; 1976 return i4_error_code; 1977 } 1978 } 1979 else if(uc_curpictype == AFRM_PIC) 1980 { 1981 ps_dec->pf_parse_mvdirect = ih264d_fld_to_mbaff; 1982 } 1983 else /* must be a field*/ 1984 { 1985 if(uc_colpictype == FRM_PIC) 1986 ps_dec->pf_parse_mvdirect = ih264d_frm_to_fld; 1987 else if(uc_colpictype == AFRM_PIC) 1988 ps_dec->pf_parse_mvdirect = ih264d_mbaff_to_fld; 1989 else 1990 ps_dec->pf_parse_mvdirect = ih264d_one_to_one; 1991 } 1992 ps_dec->ps_col_pic = ps_col_pic; 1993 return OK; 1994} 1995 1996/*! 1997 ************************************************************************** 1998 * \if Function name : ih264d_frm_to_fld \endif 1999 * 2000 * \brief 2001 * Initializes forward and backward refernce lists for B slice decoding. 2002 * 2003 * 2004 * \return 2005 * 0 on Success and Error code otherwise 2006 ************************************************************************** 2007 */ 2008void ih264d_frm_to_fld(dec_struct_t *ps_dec, 2009 struct pic_buffer_t *ps_col_pic, 2010 directmv_t *ps_direct, 2011 UWORD8 u1_wd_x, 2012 WORD32 u2_sub_mb_ofst, 2013 dec_mb_info_t * ps_cur_mb_info) 2014{ 2015 UWORD8 *pu1_col_zero_flag_start, u1_sub_mb_num; 2016 UWORD8 u1_num_blks, u1_col_mb_pred_mode, uc_blk; 2017 UWORD8 i1_num_partitions = 0, partition_size, i; 2018 WORD32 mv_index; 2019 UWORD32 increment; 2020 WORD32 i4_force_8X8; 2021 UNUSED(ps_cur_mb_info); 2022 ps_direct->u1_col_zeroflag_change = 1; 2023 ps_direct->u1_vert_mv_scale = FRM_TO_FLD; 2024 u1_sub_mb_num = ps_dec->u1_sub_mb_num; 2025 2026 /* new calculation specific to this function */ 2027 if((ps_col_pic->u1_picturetype & 0x7) == FRM_PIC) 2028 { 2029 UWORD16 u2_frm_wd_in_mbs = ps_dec->u2_frm_wd_in_mbs; 2030 increment = (u2_frm_wd_in_mbs << 4); 2031 /*mbAddrCol = mbAddrCol1 */ 2032 u2_sub_mb_ofst = (ps_dec->u2_mbx 2033 + (2 * ps_dec->u2_mby * u2_frm_wd_in_mbs)) << 4; 2034 } 2035 else 2036 increment = 16; 2037 2038 if(u1_wd_x == MB_SIZE) 2039 { 2040 ps_dec->u1_currB_type = 1; 2041 2042 { 2043 UWORD8 *puc_colZeroFlagStart_bot_mb, uc_colMbPredMode_bot_mb; 2044 2045 pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag 2046 + u2_sub_mb_ofst; 2047 u1_col_mb_pred_mode = (*pu1_col_zero_flag_start >> 6); 2048 2049 puc_colZeroFlagStart_bot_mb = ps_col_pic->pu1_col_zero_flag 2050 + u2_sub_mb_ofst + increment; 2051 uc_colMbPredMode_bot_mb = (*puc_colZeroFlagStart_bot_mb >> 6); 2052 2053 i4_force_8X8 = (u1_col_mb_pred_mode & 0x2) 2054 || (uc_colMbPredMode_bot_mb & 0x2); 2055 2056 if(i4_force_8X8) 2057 { 2058 u1_num_blks = 2; 2059 partition_size = PRED_8x8; 2060 } 2061 else 2062 { 2063 partition_size = PRED_16x8; 2064 u1_num_blks = 1; 2065 } 2066 } 2067 2068 /*As this mb is derived from 2 Mbs, min no of partitions = 2*/ 2069 for(i = 0; i < 2; i++) 2070 { 2071 for(uc_blk = 0; uc_blk < u1_num_blks; uc_blk++) 2072 { 2073 mv_index = u2_sub_mb_ofst + u1_sub_mb_num; 2074 mv_index += (u1_sub_mb_num & 0x7) ? 1 : 0; 2075 2076 ps_direct->i4_mv_indices[i1_num_partitions] = mv_index; 2077 ps_direct->i1_submb_num[i1_num_partitions] = u1_sub_mb_num; 2078 ps_direct->i1_partitionsize[i1_num_partitions] = partition_size; 2079 i1_num_partitions++; 2080 2081 u1_sub_mb_num += 2; 2082 } 2083 u1_sub_mb_num = 8; /* move to second half of Cur MB */ 2084 u2_sub_mb_ofst += increment;/* move to next Colocated MB */ 2085 } 2086 ps_direct->i1_num_partitions = i1_num_partitions; 2087 return; 2088 } 2089 else 2090 { 2091 UWORD8 u1_sub_mb_num_col; 2092 u1_sub_mb_num_col = u1_sub_mb_num | (u1_sub_mb_num >> 1); 2093 u1_sub_mb_num_col &= 0xb; 2094 u2_sub_mb_ofst += (u1_sub_mb_num >> 3) ? increment : 0; 2095 2096 ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst + u1_sub_mb_num_col; 2097 ps_direct->i1_submb_num[0] = u1_sub_mb_num; 2098 ps_direct->i1_partitionsize[0] = PRED_8x8; 2099 ps_direct->i1_num_partitions = 1; 2100 return; 2101 } 2102} 2103/*! 2104 ************************************************************************** 2105 * \if Function name : ih264d_fld_to_frm \endif 2106 * 2107 * \brief 2108 * Initializes forward and backward refernce lists for B slice decoding. 2109 * 2110 * 2111 * \return 2112 * 0 on Success and Error code otherwise 2113 ************************************************************************** 2114 */ 2115void ih264d_fld_to_frm(dec_struct_t *ps_dec, 2116 struct pic_buffer_t *ps_col_pic, 2117 directmv_t *ps_direct, 2118 UWORD8 u1_wd_x, 2119 WORD32 u2_sub_mb_ofst, 2120 dec_mb_info_t * ps_cur_mb_info) 2121{ 2122 UWORD8 *pu1_col_zero_flag_start, *pu1_col_zero_flag, 2123 *pu1_col_zero_flag_right_half, u1_sub_mb_num, uc_sub_mb_num_col; 2124 UWORD8 u1_col_mb_pred_mode, uc_blk; 2125 WORD32 i4_force_8X8; 2126 2127 UNUSED(ps_cur_mb_info); 2128 ps_direct->u1_vert_mv_scale = FLD_TO_FRM; 2129 ps_direct->u1_col_zeroflag_change = 1; 2130 /* new calculation specific to this function for u2_sub_mb_ofst*/ 2131 u2_sub_mb_ofst = (ps_dec->u2_mbx 2132 + ((ps_dec->u2_mby >> 1) * ps_dec->u2_frm_wd_in_mbs)) << 4; 2133 u2_sub_mb_ofst += ((ps_dec->u2_mby & 1) << 3); 2134 2135 if(u1_wd_x == MB_SIZE) 2136 { 2137 pu1_col_zero_flag_start = ps_col_pic->pu1_col_zero_flag + u2_sub_mb_ofst; 2138 u1_col_mb_pred_mode = (*pu1_col_zero_flag_start >> 6); 2139 ps_dec->u1_currB_type = (!!u1_col_mb_pred_mode); 2140 2141 if(u1_col_mb_pred_mode & 0x2) 2142 { 2143 if(u1_col_mb_pred_mode == PRED_8x16) 2144 { 2145 ps_direct->i1_num_partitions = 2; 2146 ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst; 2147 ps_direct->i1_submb_num[0] = 0; 2148 ps_direct->i1_partitionsize[0] = PRED_8x16; 2149 ps_direct->i4_mv_indices[1] = u2_sub_mb_ofst + 2; 2150 ps_direct->i1_submb_num[1] = 2; 2151 ps_direct->i1_partitionsize[1] = PRED_8x16; 2152 } 2153 else 2154 { 2155 UWORD8 i1_num_partitions = 0, partition_size; 2156 UWORD32 mv_index; 2157 UWORD8 u1_num_sub_blks, i, u1_col_sub_mb_pred_mode, 2158 u1_col_sub_mb_pred_mode_rt; 2159 2160 u1_sub_mb_num = ps_dec->u1_sub_mb_num; 2161 2162 pu1_col_zero_flag = pu1_col_zero_flag_start + u1_sub_mb_num; 2163 u1_col_sub_mb_pred_mode = (*pu1_col_zero_flag & 0x10);/* 8x4 or 4x4 mode */ 2164 2165 pu1_col_zero_flag_right_half = pu1_col_zero_flag_start + u1_sub_mb_num 2166 + 2; 2167 u1_col_sub_mb_pred_mode_rt = (*pu1_col_zero_flag_right_half 2168 & 0x10);/* 8x4 or 4x4 mode */ 2169 2170 i4_force_8X8 = (u1_col_sub_mb_pred_mode) 2171 || (u1_col_sub_mb_pred_mode_rt); 2172 if(i4_force_8X8) 2173 { 2174 u1_num_sub_blks = 2; 2175 partition_size = PRED_8x8; 2176 } 2177 else 2178 { 2179 partition_size = PRED_8x16; 2180 u1_num_sub_blks = 1; 2181 } 2182 2183 for(i = 0; i < 2; i++) 2184 { 2185 for(uc_blk = 0; uc_blk < u1_num_sub_blks; uc_blk++) 2186 { 2187 uc_sub_mb_num_col = u1_sub_mb_num | (u1_sub_mb_num >> 1); 2188 uc_sub_mb_num_col &= 0x7; 2189 mv_index = u2_sub_mb_ofst + uc_sub_mb_num_col; 2190 2191 ps_direct->i4_mv_indices[i1_num_partitions] = mv_index; 2192 ps_direct->i1_submb_num[i1_num_partitions] = 2193 u1_sub_mb_num; 2194 ps_direct->i1_partitionsize[i1_num_partitions] = 2195 partition_size; 2196 i1_num_partitions++; 2197 u1_sub_mb_num += 8; 2198 } 2199 2200 u1_sub_mb_num = 2; /* move to second half of Cur MB */ 2201 2202 } 2203 ps_direct->i1_num_partitions = i1_num_partitions; 2204 return; 2205 } 2206 } 2207 else 2208 { 2209 ps_direct->i1_num_partitions = 1; 2210 ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst; 2211 ps_direct->i1_submb_num[0] = 0; 2212 ps_direct->i1_partitionsize[0] = PRED_16x16; 2213 return; 2214 } 2215 } 2216 else 2217 { 2218 u1_sub_mb_num = ps_dec->u1_sub_mb_num; 2219 uc_sub_mb_num_col = u1_sub_mb_num | (u1_sub_mb_num >> 1); 2220 uc_sub_mb_num_col &= 0x7; 2221 2222 ps_direct->i4_mv_indices[0] = u2_sub_mb_ofst + uc_sub_mb_num_col; 2223 ps_direct->i1_submb_num[0] = u1_sub_mb_num; 2224 ps_direct->i1_partitionsize[0] = PRED_8x8; 2225 ps_direct->i1_num_partitions = 1; 2226 } 2227} 2228/*! 2229 ************************************************************************** 2230 * \if Function name : ih264d_one_to_one \endif 2231 * 2232 * \brief 2233 * Initializes forward and backward refernce lists for B slice decoding. 2234 * 2235 * 2236 * \return 2237 * 0 on Success and Error code otherwise 2238 ************************************************************************** 2239 */ 2240void ih264d_mbaff_to_fld(dec_struct_t *ps_dec, 2241 struct pic_buffer_t *ps_col_pic, 2242 directmv_t *ps_direct, 2243 UWORD8 u1_wd_x, 2244 WORD32 u2_sub_mb_ofst, 2245 dec_mb_info_t * ps_cur_mb_info) 2246{ 2247 UWORD8* pu1_col_zero_flag, u1_iscol_mb_fld; 2248 u2_sub_mb_ofst <<= 1; 2249 pu1_col_zero_flag = ps_col_pic->pu1_col_zero_flag + u2_sub_mb_ofst; 2250 u1_iscol_mb_fld = (*pu1_col_zero_flag & 0x2) >> 1; 2251 if(u1_iscol_mb_fld) 2252 { 2253 u2_sub_mb_ofst += (ps_dec->ps_cur_slice->u1_bottom_field_flag << 4); 2254 ih264d_one_to_one(ps_dec, ps_col_pic, ps_direct, u1_wd_x, 2255 u2_sub_mb_ofst, ps_cur_mb_info); 2256 } 2257 else 2258 ih264d_frm_to_fld(ps_dec, ps_col_pic, ps_direct, u1_wd_x, 2259 u2_sub_mb_ofst, ps_cur_mb_info); 2260} 2261/*! 2262 ************************************************************************** 2263 * \if Function name : ih264d_one_to_one \endif 2264 * 2265 * \brief 2266 * Initializes forward and backward refernce lists for B slice decoding. 2267 * 2268 * 2269 * \return 2270 * 0 on Success and Error code otherwise 2271 ************************************************************************** 2272 */ 2273void ih264d_fld_to_mbaff(dec_struct_t *ps_dec, 2274 struct pic_buffer_t *ps_col_pic, 2275 directmv_t *ps_direct, 2276 UWORD8 u1_wd_x, 2277 WORD32 u2_sub_mb_ofst, 2278 dec_mb_info_t * ps_cur_mb_info) 2279{ 2280 if((ps_col_pic->u1_picturetype & 0x7) == COMP_FLD_PAIR) 2281 { 2282 /* first calculate the colocated picture which varies with Mb */ 2283 UWORD8 u1_is_cur_mb_fld; 2284 u1_is_cur_mb_fld = ps_cur_mb_info->u1_mb_field_decodingflag; 2285 u2_sub_mb_ofst = (u2_sub_mb_ofst & 0xffe0); /* mbaddrCol5 = curmbaddr/2;*/ 2286 u2_sub_mb_ofst >>= 1; 2287 2288 ps_col_pic = ps_dec->ps_ref_pic_buf_lx[1][0]; 2289 if(u1_is_cur_mb_fld) 2290 { 2291 if(1 - ps_cur_mb_info->u1_topmb) 2292 ps_col_pic = ps_dec->ps_ref_pic_buf_lx[1][MAX_REF_BUFS]; 2293 2294 ih264d_one_to_one(ps_dec, ps_col_pic, ps_direct, u1_wd_x, 2295 u2_sub_mb_ofst, ps_cur_mb_info); 2296 } 2297 else 2298 { 2299 2300 if(ABS(ps_col_pic->i4_top_field_order_cnt 2301 - ps_dec->ps_cur_pic->i4_poc) >= 2302 ABS(ps_dec->ps_cur_pic->i4_poc - ps_col_pic->i4_bottom_field_order_cnt)) 2303 { 2304 ps_col_pic = ps_dec->ps_ref_pic_buf_lx[1][MAX_REF_BUFS]; 2305 } 2306 2307 if(ps_cur_mb_info->u1_topmb == 0) 2308 u2_sub_mb_ofst += 8; 2309 ih264d_mbaff_cross_pmbair(ps_dec, ps_col_pic, ps_direct, u1_wd_x, 2310 u2_sub_mb_ofst, ps_cur_mb_info); 2311 } 2312 ps_dec->ps_col_pic = ps_col_pic; 2313 } 2314 else 2315 { 2316 UWORD8* pu1_col_zero_flag = ps_col_pic->pu1_col_zero_flag 2317 + u2_sub_mb_ofst; 2318 UWORD8 temp, u1_is_cur_mb_fld, u1_iscol_mb_fld; 2319 2320 u1_iscol_mb_fld = (*pu1_col_zero_flag & 0x2) >> 1; 2321 u1_is_cur_mb_fld = ps_cur_mb_info->u1_mb_field_decodingflag; 2322 temp = (u1_iscol_mb_fld ^ u1_is_cur_mb_fld); 2323 2324 if(temp == 0) 2325 ih264d_one_to_one(ps_dec, ps_col_pic, ps_direct, u1_wd_x, 2326 u2_sub_mb_ofst, ps_cur_mb_info); 2327 else 2328 { 2329 u2_sub_mb_ofst &= 0xffef; 2330 if(u1_is_cur_mb_fld == 0) 2331 { 2332 if(ABS(ps_col_pic->i4_top_field_order_cnt 2333 - ps_dec->ps_cur_pic->i4_poc) >= 2334 ABS(ps_dec->ps_cur_pic->i4_poc - ps_col_pic->i4_bottom_field_order_cnt)) 2335 { 2336 u2_sub_mb_ofst += 0x10; 2337 } 2338 if(ps_cur_mb_info->u1_topmb == 0) 2339 u2_sub_mb_ofst += 8; 2340 } 2341 ih264d_mbaff_cross_pmbair(ps_dec, ps_col_pic, ps_direct, u1_wd_x, 2342 u2_sub_mb_ofst, ps_cur_mb_info); 2343 } 2344 } 2345} 2346 2347