blob: b7d3d526ff9e4e4f5c49c494150c1e70aa361f17 [file] [log] [blame]
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301/******************************************************************************
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_parse_bslice.c
23 *
24 * \brief
25 * Contains routines that decode a I slice type
26 *
27 * Detailed_description
28 *
29 * \date
30 * 07/07/2003
31 *
32 * \author NS
33 **************************************************************************
34 */
35
36#include <string.h>
Harish Mahendrakar08b77b22019-07-02 15:28:05 -070037#include "ih264_defs.h"
Hamsalekha S8d3d3032015-03-13 21:24:58 +053038#include "ih264d_bitstrm.h"
39#include "ih264d_defs.h"
40#include "ih264d_debug.h"
41#include "ih264d_tables.h"
42#include "ih264d_structs.h"
43#include "ih264d_defs.h"
44#include "ih264d_parse_cavlc.h"
45#include "ih264d_mb_utils.h"
46#include "ih264d_parse_slice.h"
47#include "ih264d_process_intra_mb.h"
48#include "ih264d_mvpred.h"
49#include "ih264d_parse_islice.h"
50#include "ih264d_inter_pred.h"
51#include "ih264d_process_pslice.h"
52#include "ih264d_process_bslice.h"
53#include "ih264d_deblocking.h"
54#include "ih264d_cabac.h"
55#include "ih264d_parse_mb_header.h"
56#include "ih264d_error_handler.h"
57#include "ih264d_mvpred.h"
58#include "ih264d_cabac.h"
59#include "ih264d_utils.h"
60
61void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec);
62
63/*!
64 **************************************************************************
65 * \if Function name : ParseMb_SubMb_PredBCav\endif
66 *
67 * \brief
68 * Implements sub_mb_pred() of 7.3.5.2. & mb_pred() of 7.3.5.1
69 *
70 * \return
71 * None.
72 *
73 **************************************************************************
74 */
75WORD32 ih264d_parse_bmb_non_direct_cavlc(dec_struct_t * ps_dec,
76 dec_mb_info_t * ps_cur_mb_info,
77 UWORD8 u1_mb_num,
78 UWORD8 u1_num_mbsNby2)
79{
80 dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
81 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
82 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
83 UWORD8 * pu1_sub_mb_pred_modes = (UWORD8 *)(gau1_ih264d_submb_pred_modes) + 4;
84 const UWORD8 (*pu1_mb_pred_modes)[32] =
85 (const UWORD8 (*)[32])gau1_ih264d_mb_pred_modes;
86 const UWORD8 * pu1_num_mb_part = (const UWORD8 *)gau1_ih264d_num_mb_part;
87 const UWORD8 * pu1_sub_mb_mc_mode = (const UWORD8 *)(gau1_ih264d_submb_mc_mode)
88 + 4;
89
90 parse_pmbarams_t * ps_parse_mb_data = ps_dec->ps_parse_mb_data
91 + u1_num_mbsNby2;
92 UWORD8 * pu1_col_info = ps_parse_mb_data->u1_col_info;
93 WORD8 (*pi1_ref_idx)[MAX_REFIDX_INFO_PER_MB] = ps_parse_mb_data->i1_ref_idx;
94 UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
95 UWORD8 u1_mb_mc_mode, u1_num_mb_part, u1_sub_mb = !(u1_mb_type ^ B_8x8);
96 UWORD32 u4_mb_mc_mode = 0, u4_mb_pred_mode = 0;
97 WORD32 ret;
98
99 if(u1_sub_mb)
100 {
101 UWORD8 uc_i;
102 u1_mb_mc_mode = 0;
103 u1_num_mb_part = 4;
104 /* Reading the subMB type */
105 for(uc_i = 0; uc_i < 4; uc_i++)
106 {
107
108 UWORD32 ui_sub_mb_mode;
109
110//Inlined ih264d_uev
111 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
112 UWORD32 u4_word, u4_ldz;
113
114 /***************************************************************/
115 /* Find leading zeros in next 32 bits */
116 /***************************************************************/
117 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
118 u4_ldz = CLZ(u4_word);
119 /* Flush the ps_bitstrm */
120 u4_bitstream_offset += (u4_ldz + 1);
121 /* Read the suffix from the ps_bitstrm */
122 u4_word = 0;
123 if(u4_ldz)
124 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
125 u4_ldz);
126 *pu4_bitstrm_ofst = u4_bitstream_offset;
127 ui_sub_mb_mode = ((1 << u4_ldz) + u4_word - 1);
128//Inlined ih264d_uev
129
130 if(ui_sub_mb_mode > 12)
131 return ERROR_SUB_MB_TYPE;
132 else
133 {
134 UWORD8 u1_subMbPredMode = pu1_sub_mb_pred_modes[ui_sub_mb_mode];
135 u4_mb_mc_mode = (u4_mb_mc_mode << 8)
136 | pu1_sub_mb_mc_mode[ui_sub_mb_mode];
137 u4_mb_pred_mode = (u4_mb_pred_mode << 8) | u1_subMbPredMode;
138 pi1_ref_idx[0][uc_i] = ((u1_subMbPredMode & PRED_L0) - 1) >> 1;
139 pi1_ref_idx[1][uc_i] = ((u1_subMbPredMode & PRED_L1) - 1) >> 1;
140 COPYTHECONTEXT("sub_mb_type", u1_subMbPredMode);
141 }
142 /* Storing collocated Mb and SubMb mode information */
143 *pu1_col_info++ = ((PRED_8x8) << 6)
144 | ((pu1_sub_mb_mc_mode[ui_sub_mb_mode] << 4));
145 if(ui_sub_mb_mode != B_DIRECT_8x8)
146 {
147 if(ui_sub_mb_mode > B_BI_8x8)
148 {
149 ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag = 0;
150 }
151 }
152 else if(!ps_dec->s_high_profile.u1_direct_8x8_inference_flag)
153 {
154 ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag = 0;
155 }
156 }
157 }
158 else
159 {
160 UWORD8 u1_mb_pred_mode_idx = 5 + u1_mb_type;
161 UWORD8 u1_mb_pred_mode_part0 = pu1_mb_pred_modes[0][u1_mb_pred_mode_idx];
162 UWORD8 u1_mb_pred_mode_part1 = pu1_mb_pred_modes[1][u1_mb_pred_mode_idx];
163 u1_mb_mc_mode = ps_cur_mb_info->u1_mb_mc_mode;
164 u1_num_mb_part = pu1_num_mb_part[u1_mb_mc_mode];
165
166 pi1_ref_idx[0][0] = ((u1_mb_pred_mode_part0 & PRED_L0) - 1) >> 1;
167 pi1_ref_idx[1][0] = ((u1_mb_pred_mode_part0 & PRED_L1) - 1) >> 1;
168 pi1_ref_idx[0][1] = ((u1_mb_pred_mode_part1 & PRED_L0) - 1) >> 1;
169 pi1_ref_idx[1][1] = ((u1_mb_pred_mode_part1 & PRED_L1) - 1) >> 1;
170
171 u4_mb_pred_mode = (u1_mb_pred_mode_part0 << 8) | u1_mb_pred_mode_part1;
172 u4_mb_mc_mode = u1_mb_mc_mode | (u1_mb_mc_mode << 8);
173 u4_mb_mc_mode <<= 16;
174 u4_mb_pred_mode <<= 16;
175
176 /* Storing collocated Mb and SubMb mode information */
177 *pu1_col_info++ = (u1_mb_mc_mode << 6);
178 if(u1_mb_mc_mode)
179 *pu1_col_info++ = (u1_mb_mc_mode << 6);
180 }
181
182 {
183 UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
184 UWORD8 uc_field = ps_cur_mb_info->u1_mb_field_decodingflag;
185 UWORD8 *pu1_num_ref_idx_lx_active =
186 ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active;
187 const UWORD8 u1_mbaff_field = (u1_mbaff & uc_field);
188 UWORD8 u4_num_ref_idx_lx_active;
189
190 u4_num_ref_idx_lx_active = (pu1_num_ref_idx_lx_active[0]
191 << u1_mbaff_field) - 1;
192
193 if(u4_num_ref_idx_lx_active)
194 {
195 if(1 == u4_num_ref_idx_lx_active)
196 ih264d_parse_bmb_ref_index_cavlc_range1(
197 u1_num_mb_part, ps_bitstrm, pi1_ref_idx[0],
198 u4_num_ref_idx_lx_active);
199 else
200 {
201 ret = ih264d_parse_bmb_ref_index_cavlc(u1_num_mb_part, ps_bitstrm,
202 pi1_ref_idx[0],
203 u4_num_ref_idx_lx_active);
204 if(ret != OK)
205 return ret;
206 }
207 }
208
209 u4_num_ref_idx_lx_active = (pu1_num_ref_idx_lx_active[1]
210 << u1_mbaff_field) - 1;
211
212 if(u4_num_ref_idx_lx_active)
213 {
214 if(1 == u4_num_ref_idx_lx_active)
215 ih264d_parse_bmb_ref_index_cavlc_range1(
216 u1_num_mb_part, ps_bitstrm, pi1_ref_idx[1],
217 u4_num_ref_idx_lx_active);
218 else
219 {
220 ret = ih264d_parse_bmb_ref_index_cavlc(u1_num_mb_part, ps_bitstrm,
221 pi1_ref_idx[1],
222 u4_num_ref_idx_lx_active);
223 if(ret != OK)
224 return ret;
225 }
226 }
227 }
228
229 /* Read MotionVectors */
230 {
231 const UWORD8 * pu1_top_left_sub_mb_indx;
232
233 const UWORD8 * pu1_sub_mb_indx_mod =
234 (const UWORD8 *)(gau1_ih264d_submb_indx_mod)
235 + (u1_sub_mb * 6);
236 const UWORD8 * pu1_sub_mb_partw = (const UWORD8 *)gau1_ih264d_submb_partw;
237 const UWORD8 * pu1_sub_mb_parth = (const UWORD8 *)gau1_ih264d_submb_parth;
238 const UWORD8 * pu1_num_sub_mb_part =
239 (const UWORD8 *)gau1_ih264d_num_submb_part;
240 const UWORD8 * pu1_mb_partw = (const UWORD8 *)gau1_ih264d_mb_partw;
241 const UWORD8 * pu1_mb_parth = (const UWORD8 *)gau1_ih264d_mb_parth;
242 UWORD8 u1_p_idx = 0, u1_num_submb_part, uc_lx;
243 parse_part_params_t * ps_part;
244 mv_pred_t *ps_mv_start = ps_dec->ps_mv_cur + (u1_mb_num << 4);
245 UWORD8 u1_mb_part_wd, u1_mb_part_ht;
246
247 /* Initialisations */
248 ps_part = ps_dec->ps_part;
249 /* Default Initialization for Non subMb Case Mode */
250 u1_mb_part_wd = pu1_mb_partw[u1_mb_mc_mode];
251 u1_mb_part_ht = pu1_mb_parth[u1_mb_mc_mode];
252 u1_num_submb_part = 1;
253
254 /* Decoding the MV for the subMB */
255 for(uc_lx = 0; uc_lx < 2; uc_lx++)
256 {
257 UWORD8 u1_sub_mb_num = 0, u1_pred_mode, uc_i;
258 UWORD32 u4_mb_mc_mode_tmp = u4_mb_mc_mode;
259 UWORD32 u4_mb_pred_mode_tmp = u4_mb_pred_mode;
260 UWORD16 u2_sub_mb_num = 0x028A; // for sub mb case
261 UWORD8 u1_b2 = uc_lx << 1;
262 u1_pred_mode = (uc_lx) ? PRED_L1 : PRED_L0;
263 pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_mb_mc_mode << 1);
264
265 for(uc_i = 0; uc_i < u1_num_mb_part; uc_i++)
266 {
267 UWORD8 u1_mb_mc_mode, uc_j;
268 UWORD8 i1_pred = u4_mb_pred_mode_tmp >> 24;
269 u1_mb_mc_mode = u4_mb_mc_mode_tmp >> 24;
270 u4_mb_pred_mode_tmp <<= 8;
271 u4_mb_mc_mode_tmp <<= 8;
272 /* subMb prediction mode */
273 if(u1_sub_mb)
274 {
275
276 u1_mb_part_wd = pu1_sub_mb_partw[u1_mb_mc_mode];
277 u1_mb_part_ht = pu1_sub_mb_parth[u1_mb_mc_mode];
278 u1_sub_mb_num = u2_sub_mb_num >> 12;
279 u1_num_submb_part = pu1_num_sub_mb_part[u1_mb_mc_mode];
280 pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod
281 + (u1_mb_mc_mode << 1);
282 u2_sub_mb_num <<= 4;
283 }
284 for(uc_j = 0; uc_j < u1_num_submb_part;
285 uc_j++, pu1_top_left_sub_mb_indx++)
286 {
287 mv_pred_t * ps_mv;
288 u1_sub_mb_num = u1_sub_mb_num + *pu1_top_left_sub_mb_indx;
289 ps_mv = ps_mv_start + u1_sub_mb_num;
290
291 /* Storing Info for partitions, writing only once */
292 if(uc_lx)
293 {
294 ps_part->u1_is_direct = (!i1_pred);
295 ps_part->u1_pred_mode = i1_pred;
296 ps_part->u1_sub_mb_num = u1_sub_mb_num;
297 ps_part->u1_partheight = u1_mb_part_ht;
298 ps_part->u1_partwidth = u1_mb_part_wd;
299 /* Increment partition Index */
300 u1_p_idx++;
301 ps_part++;
302 }
303
304 if(i1_pred & u1_pred_mode)
305 {
306 WORD16 i2_mvx, i2_mvy;
307
308//inlining ih264d_sev
309 {
310 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
311 UWORD32 u4_word, u4_ldz, u4_abs_val;
312
313 /***************************************************************/
314 /* Find leading zeros in next 32 bits */
315 /***************************************************************/
316 NEXTBITS_32(u4_word, u4_bitstream_offset,
317 pu4_bitstrm_buf);
318 u4_ldz = CLZ(u4_word);
319
320 /* Flush the ps_bitstrm */
321 u4_bitstream_offset += (u4_ldz + 1);
322
323 /* Read the suffix from the ps_bitstrm */
324 u4_word = 0;
325 if(u4_ldz)
326 GETBITS(u4_word, u4_bitstream_offset,
327 pu4_bitstrm_buf, u4_ldz);
328
329 *pu4_bitstrm_ofst = u4_bitstream_offset;
330 u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
331
332 if(u4_word & 0x1)
333 i2_mvx = (-(WORD32)u4_abs_val);
334 else
335 i2_mvx = (u4_abs_val);
336 }
337//inlinined ih264d_sev
338
339//inlining ih264d_sev
340 {
341 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
342 UWORD32 u4_word, u4_ldz, u4_abs_val;
343
344 /***************************************************************/
345 /* Find leading zeros in next 32 bits */
346 /***************************************************************/
347 NEXTBITS_32(u4_word, u4_bitstream_offset,
348 pu4_bitstrm_buf);
349 u4_ldz = CLZ(u4_word);
350
351 /* Flush the ps_bitstrm */
352 u4_bitstream_offset += (u4_ldz + 1);
353
354 /* Read the suffix from the ps_bitstrm */
355 u4_word = 0;
356 if(u4_ldz)
357 GETBITS(u4_word, u4_bitstream_offset,
358 pu4_bitstrm_buf, u4_ldz);
359
360 *pu4_bitstrm_ofst = u4_bitstream_offset;
361 u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
362
363 if(u4_word & 0x1)
364 i2_mvy = (-(WORD32)u4_abs_val);
365 else
366 i2_mvy = (u4_abs_val);
367 }
368//inlinined ih264d_sev
369
370 /* Storing Mv residuals */
371 ps_mv->i2_mv[u1_b2] = i2_mvx;
372 ps_mv->i2_mv[u1_b2 + 1] = i2_mvy;
373 }
374 }
375 }
376 }
377 /* write back to the scratch partition info */
378 ps_dec->ps_part = ps_part;
379 ps_parse_mb_data->u1_num_part = u1_sub_mb ? u1_p_idx : u1_num_mb_part;
380
381 }
382 return OK;
383}
384
385/*!
386 **************************************************************************
387 * \if Function name : ParseMb_SubMb_PredBCab\endif
388 *
389 * \brief
390 * Implements sub_mb_pred() of 7.3.5.2. & mb_pred() of 7.3.5.1
391 *
392 * \return
393 * None.
394 *
395 **************************************************************************
396 */
397
398WORD32 ih264d_parse_bmb_non_direct_cabac(dec_struct_t * ps_dec,
399 dec_mb_info_t * ps_cur_mb_info,
400 UWORD8 u1_mb_num,
401 UWORD8 u1_num_mbsNby2)
402{
403 /* Loads from ps_dec */
404 decoding_envirnoment_t * ps_cab_env = &ps_dec->s_cab_dec_env;
405 dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
406 ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
407 parse_pmbarams_t * ps_parse_mb_data = ps_dec->ps_parse_mb_data
408 + u1_num_mbsNby2;
409
410 /* table pointer loads */
411 const UWORD8 * pu1_sub_mb_pred_modes = (UWORD8 *)(gau1_ih264d_submb_pred_modes)
412 + 4;
413 const UWORD8 (*pu1_mb_pred_modes)[32] =
414 (const UWORD8 (*)[32])gau1_ih264d_mb_pred_modes;
415 const UWORD8 *pu1_num_mb_part = (const UWORD8 *)gau1_ih264d_num_mb_part;
416 const UWORD8 *pu1_sub_mb_mc_mode = (UWORD8 *)(gau1_ih264d_submb_mc_mode) + 4;
417
418 const UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
419 UWORD8 * pu1_col_info = ps_parse_mb_data->u1_col_info;
420 WORD8 *pi1_ref_idx_l0 = &ps_parse_mb_data->i1_ref_idx[0][0];
421 WORD8 *pi1_ref_idx_l1 = &ps_parse_mb_data->i1_ref_idx[1][0];
422 UWORD8 u1_dec_ref_l0, u1_dec_ref_l1;
423
424 UWORD8 u1_num_mb_part, u1_mb_mc_mode, u1_sub_mb, u1_mbpred_mode = 5
425 + u1_mb_type;
426 UWORD32 u4_mb_mc_mode = 0, u4_mb_pred_mode = 0;
427 WORD32 ret;
428
429 p_curr_ctxt->u1_mb_type = CAB_NON_BD16x16;
430 u1_sub_mb = !(u1_mb_type ^ B_8x8);
431
432 {
433 UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
434 UWORD8 *pu1_num_ref_idx_lx_active =
435 ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active;
436 UWORD8 uc_field = ps_cur_mb_info->u1_mb_field_decodingflag;
437 UWORD8 u1_mbaff_field = (u1_mbaff & uc_field);
438 u1_dec_ref_l0 = (pu1_num_ref_idx_lx_active[0] << u1_mbaff_field) - 1;
439 u1_dec_ref_l1 = (pu1_num_ref_idx_lx_active[1] << u1_mbaff_field) - 1;
440 }
441
442 if(u1_sub_mb)
443 {
444 const UWORD8 u1_colz = ((PRED_8x8) << 6);
445 UWORD8 uc_i;
446 u1_mb_mc_mode = 0;
447 u1_num_mb_part = 4;
448 /* Reading the subMB type */
449 for(uc_i = 0; uc_i < 4; uc_i++)
450 {
451 UWORD8 u1_sub_mb_mode, u1_subMbPredModes;
452 u1_sub_mb_mode = ih264d_parse_submb_type_cabac(
453 1, ps_cab_env, ps_bitstrm,
454 ps_dec->p_sub_mb_type_t);
455
456 if(u1_sub_mb_mode > 12)
457 return ERROR_SUB_MB_TYPE;
458
459 u1_subMbPredModes = pu1_sub_mb_pred_modes[u1_sub_mb_mode];
460 u4_mb_mc_mode = (u4_mb_mc_mode << 8) | pu1_sub_mb_mc_mode[u1_sub_mb_mode];
461 u4_mb_pred_mode = (u4_mb_pred_mode << 8) | u1_subMbPredModes;
462 *pi1_ref_idx_l0++ =
463 (u1_subMbPredModes & PRED_L0) ? u1_dec_ref_l0 : -1;
464 *pi1_ref_idx_l1++ =
465 (u1_subMbPredModes & PRED_L1) ? u1_dec_ref_l1 : -1;
466 COPYTHECONTEXT("sub_mb_type", u1_sub_mb_mode);
467 /* Storing collocated Mb and SubMb mode information */
468 *pu1_col_info++ =
469 (u1_colz | (pu1_sub_mb_mc_mode[u1_sub_mb_mode] << 4));
470 if(u1_sub_mb_mode != B_DIRECT_8x8)
471 {
472 if(u1_sub_mb_mode > B_BI_8x8)
473 {
474 ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag = 0;
475 }
476 }
477 else if(!ps_dec->s_high_profile.u1_direct_8x8_inference_flag)
478 {
479 ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag = 0;
480 }
481 }
482 pi1_ref_idx_l0 -= 4;
483 pi1_ref_idx_l1 -= 4;
484 }
485 else
486 {
487 UWORD8 u1_mb_pred_mode_part0 = pu1_mb_pred_modes[0][u1_mbpred_mode];
488 UWORD8 u1_mb_pred_mode_part1 = pu1_mb_pred_modes[1][u1_mbpred_mode];
489 u1_mb_mc_mode = ps_cur_mb_info->u1_mb_mc_mode;
490 u1_num_mb_part = pu1_num_mb_part[u1_mb_mc_mode];
491 /* Storing collocated Mb and SubMb mode information */
492 *pu1_col_info++ = (u1_mb_mc_mode << 6);
493 if(u1_mb_mc_mode)
494 *pu1_col_info++ = (u1_mb_mc_mode << 6);
495 u4_mb_mc_mode = u1_mb_mc_mode | (u1_mb_mc_mode << 8);
496 u4_mb_mc_mode <<= 16;
497 u4_mb_pred_mode = ((u1_mb_pred_mode_part0 << 8) | u1_mb_pred_mode_part1) << 16;
498
499 *pi1_ref_idx_l0++ = (u1_mb_pred_mode_part0 & PRED_L0) ? u1_dec_ref_l0 : -1;
500 *pi1_ref_idx_l0-- = (u1_mb_pred_mode_part1 & PRED_L0) ? u1_dec_ref_l0 : -1;
501 *pi1_ref_idx_l1++ = (u1_mb_pred_mode_part0 & PRED_L1) ? u1_dec_ref_l1 : -1;
502 *pi1_ref_idx_l1-- = (u1_mb_pred_mode_part1 & PRED_L1) ? u1_dec_ref_l1 : -1;
503 }
504 {
505 WORD8 *pi1_lft_cxt = ps_dec->pi1_left_ref_idx_ctxt_inc;
506 WORD8 *pi1_top_cxt = p_curr_ctxt->i1_ref_idx;
507
508 ret = ih264d_parse_ref_idx_cabac(u1_num_mb_part, 0, u1_dec_ref_l0,
509 u1_mb_mc_mode, pi1_ref_idx_l0, pi1_lft_cxt,
510 pi1_top_cxt, ps_cab_env, ps_bitstrm,
511 ps_dec->p_ref_idx_t);
512 if(ret != OK)
513 return ret;
514
515 ret = ih264d_parse_ref_idx_cabac(u1_num_mb_part, 2, u1_dec_ref_l1,
516 u1_mb_mc_mode, pi1_ref_idx_l1, pi1_lft_cxt,
517 pi1_top_cxt, ps_cab_env, ps_bitstrm,
518 ps_dec->p_ref_idx_t);
519 if(ret != OK)
520 return ret;
521 }
522 /* Read MotionVectors */
523 {
524 const UWORD8 *pu1_top_left_sub_mb_indx;
525 UWORD8 uc_j, uc_lx;
526 UWORD8 u1_mb_part_wd, u1_mb_part_ht;
527
528 const UWORD8 *pu1_sub_mb_indx_mod =
529 (const UWORD8 *)gau1_ih264d_submb_indx_mod
530 + (u1_sub_mb * 6);
531 const UWORD8 *pu1_sub_mb_partw = (const UWORD8 *)gau1_ih264d_submb_partw;
532 const UWORD8 *pu1_sub_mb_parth = (const UWORD8 *)gau1_ih264d_submb_parth;
533 const UWORD8 *pu1_num_sub_mb_part =
534 (const UWORD8 *)gau1_ih264d_num_submb_part;
535 const UWORD8 *pu1_mb_partw = (const UWORD8 *)gau1_ih264d_mb_partw;
536 const UWORD8 *pu1_mb_parth = (const UWORD8 *)gau1_ih264d_mb_parth;
537
538 UWORD8 u1_p_idx = 0;
539 UWORD8 u1_num_submb_part;
540 parse_part_params_t *ps_part;
541 /* Initialisations */
542 mv_pred_t *ps_mv_start = ps_dec->ps_mv_cur + (u1_mb_num << 4);
543 ps_part = ps_dec->ps_part;
544
545 /* Default initialization for non subMb case */
546 u1_mb_part_wd = pu1_mb_partw[u1_mb_mc_mode];
547 u1_mb_part_ht = pu1_mb_parth[u1_mb_mc_mode];
548 u1_num_submb_part = 1;
549
550 /* Decoding the MV for the subMB */
551 for(uc_lx = 0; uc_lx < 2; uc_lx++)
552 {
553 UWORD8 u1_sub_mb_num = 0;
554 UWORD32 u4_mb_pred_mode_tmp = u4_mb_pred_mode;
555 UWORD32 u4_mb_mc_mode_tmp = u4_mb_mc_mode;
556 UWORD8 u1_mb_mc_mode_1, u1_pred_mode, uc_i;
557 UWORD16 u2_sub_mb_num = 0x028A;
558 UWORD8 u1_b2 = uc_lx << 1;
559 u1_pred_mode = (uc_lx) ? PRED_L1 : PRED_L0;
560 /* Default for Cabac */
561 pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_mb_mc_mode << 1);
562 for(uc_i = 0; uc_i < u1_num_mb_part; uc_i++)
563 {
564
565 WORD8 i1_pred = (UWORD8)(u4_mb_pred_mode_tmp >> 24);
566 u1_mb_mc_mode_1 = (UWORD8)(u4_mb_mc_mode_tmp >> 24);
567 u4_mb_pred_mode_tmp <<= 8;
568 u4_mb_mc_mode_tmp <<= 8;
569
570 /* subMb prediction mode */
571 if(u1_sub_mb)
572 {
573 u1_mb_part_wd = pu1_sub_mb_partw[u1_mb_mc_mode_1];
574 u1_mb_part_ht = pu1_sub_mb_parth[u1_mb_mc_mode_1];
575 u1_sub_mb_num = u2_sub_mb_num >> 12;
576 pu1_top_left_sub_mb_indx = pu1_sub_mb_indx_mod + (u1_mb_mc_mode_1 << 1);
577 u1_num_submb_part = pu1_num_sub_mb_part[u1_mb_mc_mode_1];
578 u2_sub_mb_num = u2_sub_mb_num << 4;
579 }
580
581 for(uc_j = 0; uc_j < u1_num_submb_part;
582 uc_j++, pu1_top_left_sub_mb_indx++)
583 {
584 mv_pred_t *ps_mv;
585 u1_sub_mb_num = u1_sub_mb_num + *pu1_top_left_sub_mb_indx;
586 ps_mv = ps_mv_start + u1_sub_mb_num;
587
588 /* Storing Info for partitions, writing only once */
589 if(uc_lx)
590 {
591 ps_part->u1_is_direct = (!i1_pred);
592 ps_part->u1_pred_mode = i1_pred;
593 ps_part->u1_sub_mb_num = u1_sub_mb_num;
594 ps_part->u1_partheight = u1_mb_part_ht;
595 ps_part->u1_partwidth = u1_mb_part_wd;
596
597 /* Increment partition Index */
598 u1_p_idx++;
599 ps_part++;
600 }
601
602 ih264d_get_mvd_cabac(u1_sub_mb_num, u1_b2, u1_mb_part_wd,
603 u1_mb_part_ht,
604 (UWORD8)(i1_pred & u1_pred_mode), ps_dec,
605 ps_mv);
606 }
607 }
608 }
609 /* write back to the scratch partition info */
610
611 ps_dec->ps_part = ps_part;
612 ps_parse_mb_data->u1_num_part = u1_sub_mb ? u1_p_idx : u1_num_mb_part;
613
614 }
615
616 return OK;
617}
618
619/*!
620 **************************************************************************
621 * \if Function name : ih264d_parse_bmb_cabac \endif
622 *
623 * \brief
624 * This function parses CABAC syntax of a B MB.
625 *
626 * \return
627 * 0 on Success and Error code otherwise
628 **************************************************************************
629 */
630WORD32 ih264d_parse_bmb_cabac(dec_struct_t * ps_dec,
631 dec_mb_info_t * ps_cur_mb_info,
632 UWORD8 u1_mb_num,
633 UWORD8 u1_num_mbsNby2)
634{
635 UWORD8 u1_cbp;
636 deblk_mb_t * ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_mb_num;
637 const UWORD8 *puc_mb_mc_mode = (const UWORD8 *)gau1_ih264d_mb_mc_mode;
638 UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
639 ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
640
641 WORD32 ret;
642 UWORD8 u1_Bdirect_tranform_read = 1;
643 ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag = 1;
644
645 ps_cur_mb_info->u1_mb_mc_mode = puc_mb_mc_mode[5 + u1_mb_type];
646
647 ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
648
649 ps_cur_deblk_mb->u1_mb_type |= D_B_SLICE;
650 if(u1_mb_type != B_DIRECT)
651 {
652 ret = ih264d_parse_bmb_non_direct_cabac(ps_dec, ps_cur_mb_info, u1_mb_num,
653 u1_num_mbsNby2);
654 if(ret != OK)
655 return ret;
656 }
657 else
658 {
659
660 /************ STORING PARTITION INFO ***********/
661 parse_part_params_t * ps_part_info;
662 ps_part_info = ps_dec->ps_part;
663 ps_part_info->u1_is_direct = PART_DIRECT_16x16;
664 ps_part_info->u1_sub_mb_num = 0;
665 ps_dec->ps_part++;
666 p_curr_ctxt->u1_mb_type = CAB_BD16x16;
667
668 MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0);
669 memset(ps_dec->pi1_left_ref_idx_ctxt_inc, 0, 4);
670 MEMSET_16BYTES(p_curr_ctxt->u1_mv, 0);
671 memset(p_curr_ctxt->i1_ref_idx, 0, 4);
672
673 /* check whether transform8x8 u4_flag to be read or not */
674 u1_Bdirect_tranform_read =
675 ps_dec->s_high_profile.u1_direct_8x8_inference_flag;
676 }
677
678 /* Read the Coded block pattern */
679 u1_cbp = (WORD8)ih264d_parse_ctx_cbp_cabac(ps_dec);
680 p_curr_ctxt->u1_cbp = u1_cbp;
681 ps_cur_mb_info->u1_cbp = u1_cbp;
682
683 if(u1_cbp > 47)
684 return ERROR_CBP;
685
686 COPYTHECONTEXT("coded_block_pattern", u1_cbp);
687
688 ps_cur_mb_info->u1_tran_form8x8 = 0;
689 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
690
691 if((ps_dec->s_high_profile.u1_transform8x8_present) && (u1_cbp & (0xf))
692 && (ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag)
693 && (u1_Bdirect_tranform_read))
694 {
695 ps_cur_mb_info->u1_tran_form8x8 = ih264d_parse_transform8x8flag_cabac(
696 ps_dec, ps_cur_mb_info);
697 COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
698
699 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
700 p_curr_ctxt->u1_transform8x8_ctxt = ps_cur_mb_info->u1_tran_form8x8;
701 }
702 else
703 {
704 p_curr_ctxt->u1_transform8x8_ctxt = 0;
705 }
706
707 p_curr_ctxt->u1_intra_chroma_pred_mode = 0;
708 p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE;
709 ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x6;
710
711 /* Read mb_qp_delta */
712 if(u1_cbp)
713 {
714 WORD8 c_temp;
715 ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &c_temp);
716 if(ret != OK)
717 return ret;
718 COPYTHECONTEXT("mb_qp_delta", c_temp);
719 if(c_temp)
720 {
721 ret = ih264d_update_qp(ps_dec, c_temp);
722 if(ret != OK)
723 return ret;
724 }
725 }
726 else
727 ps_dec->i1_prev_mb_qp_delta = 0;
728
729 ih264d_parse_residual4x4_cabac(ps_dec, ps_cur_mb_info, 0);
730 if(EXCEED_OFFSET(ps_dec->ps_bitstrm))
731 return ERROR_EOB_TERMINATE_T;
732 return OK;
733}
734/*!
735 **************************************************************************
736 * \if Function name : ih264d_parse_bmb_cavlc \endif
737 *
738 * \brief
739 * This function parses CAVLC syntax of a B MB.
740 *
741 * \return
742 * 0 on Success and Error code otherwise
743 **************************************************************************
744 */
745WORD32 ih264d_parse_bmb_cavlc(dec_struct_t * ps_dec,
746 dec_mb_info_t * ps_cur_mb_info,
747 UWORD8 u1_mb_num,
748 UWORD8 u1_num_mbsNby2)
749{
750 UWORD32 u4_cbp;
751 deblk_mb_t * ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u1_mb_num;
752 dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
753 UWORD32 * pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
754 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
755 const UWORD8 *puc_mb_mc_mode = (const UWORD8 *)gau1_ih264d_mb_mc_mode;
756 UWORD8 u1_mb_type = ps_cur_mb_info->u1_mb_type;
757
758 WORD32 ret;
759 UWORD8 u1_Bdirect_tranform_read = 1;
760 ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag = 1;
761 ps_cur_mb_info->u1_tran_form8x8 = 0;
762 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
763
764 ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
765
766 ps_cur_mb_info->u1_mb_mc_mode = puc_mb_mc_mode[5 + u1_mb_type];
767
768 ps_cur_deblk_mb->u1_mb_type |= D_B_SLICE;
769 if(u1_mb_type != B_DIRECT)
770 {
771 ret = ih264d_parse_bmb_non_direct_cavlc(ps_dec, ps_cur_mb_info, u1_mb_num,
772 u1_num_mbsNby2);
773 if(ret != OK)
774 return ret;
775 }
776 else
777 {
778 /************ STORING PARTITION INFO ***********/
779 parse_part_params_t * ps_part_info;
780 ps_part_info = ps_dec->ps_part;
781 ps_part_info->u1_is_direct = PART_DIRECT_16x16;
782 ps_part_info->u1_sub_mb_num = 0;
783 ps_dec->ps_part++;
784 /* check whether transform8x8 u4_flag to be read or not */
785 u1_Bdirect_tranform_read =
786 ps_dec->s_high_profile.u1_direct_8x8_inference_flag;
787 }
788
789 /* Read the Coded block pattern */
790 {
791 const UWORD8 * puc_CbpInter = gau1_ih264d_cbp_inter;
792//Inlined ih264d_uev
793 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
794 UWORD32 u4_word, u4_ldz;
795
796 /***************************************************************/
797 /* Find leading zeros in next 32 bits */
798 /***************************************************************/
799 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
800 u4_ldz = CLZ(u4_word);
801 /* Flush the ps_bitstrm */
802 u4_bitstream_offset += (u4_ldz + 1);
803 /* Read the suffix from the ps_bitstrm */
804 u4_word = 0;
805 if(u4_ldz)
806 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
807 *pu4_bitstrm_ofst = u4_bitstream_offset;
808 u4_cbp = ((1 << u4_ldz) + u4_word - 1);
809//Inlined ih264d_uev
810 if(u4_cbp > 47)
811 return ERROR_CBP;
812 u4_cbp = puc_CbpInter[u4_cbp];
813
814 if((ps_dec->s_high_profile.u1_transform8x8_present) && (u4_cbp & (0xf))
815 && (ps_dec->s_high_profile.u1_no_submb_part_size_lt8x8_flag)
816 && (u1_Bdirect_tranform_read))
817 {
818 ps_cur_mb_info->u1_tran_form8x8 = ih264d_get_bit_h264(ps_bitstrm);
819 COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
820 ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
821 }
822
823 }
824
825 COPYTHECONTEXT("coded_block_pattern", u4_cbp);
826 ps_cur_mb_info->u1_cbp = u4_cbp;
827
828 /* Read mb_qp_delta */
829 if(u4_cbp)
830 {
831 WORD32 i_temp;
832//inlining ih264d_sev
833
834 UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
835 UWORD32 u4_word, u4_ldz, u4_abs_val;
836
837 /***************************************************************/
838 /* Find leading zeros in next 32 bits */
839 /***************************************************************/
840 NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
841 u4_ldz = CLZ(u4_word);
842
843 /* Flush the ps_bitstrm */
844 u4_bitstream_offset += (u4_ldz + 1);
845
846 /* Read the suffix from the ps_bitstrm */
847 u4_word = 0;
848 if(u4_ldz)
849 GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf, u4_ldz);
850
851 *pu4_bitstrm_ofst = u4_bitstream_offset;
852 u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
853
854 if(u4_word & 0x1)
855 i_temp = (-(WORD32)u4_abs_val);
856 else
857 i_temp = (u4_abs_val);
858
859 if(i_temp < -26 || i_temp > 25)
860 return ERROR_INV_RANGE_QP_T;
861//inlinined ih264d_sev
862 COPYTHECONTEXT("mb_qp_delta", i_temp);
863 if(i_temp)
864 {
865 ret = ih264d_update_qp(ps_dec, (WORD8)i_temp);
866 if(ret != OK)
867 return ret;
868 }
869
870 ret = ih264d_parse_residual4x4_cavlc(ps_dec, ps_cur_mb_info, 0);
871 if(ret != OK)
872 return ret;
873 if(EXCEED_OFFSET(ps_bitstrm))
874 return ERROR_EOB_TERMINATE_T;
875 }
876 else
877 {
878 ps_dec->i1_prev_mb_qp_delta = 0;
879 ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CAVLC);
880 }
881
882 return OK;
883}
884
885WORD32 ih264d_mv_pred_ref_tfr_nby2_bmb(dec_struct_t * ps_dec,
886 UWORD8 u1_mb_idx,
887 UWORD8 u1_num_mbs)
888{
889 parse_pmbarams_t * ps_mb_part_info;
890 parse_part_params_t * ps_part;
891 mv_pred_t *ps_mv_nmb, *ps_mv_nmb_start, *ps_mv_ntop, *ps_mv_ntop_start;
892 pic_buffer_t * ps_ref_frame;
893 UWORD8 u1_direct_mode_width;
894 UWORD8 i, j;
895 dec_mb_info_t * ps_cur_mb_info;
896 const UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
897 UWORD8 u1_field;
898 WORD32 ret = 0;
899
900 ps_dec->i4_submb_ofst -= (u1_num_mbs - u1_mb_idx) << 4;
901 ps_mb_part_info = ps_dec->ps_parse_mb_data;
902 ps_part = ps_dec->ps_parse_part_params;
903
904 /* N/2 Mb MvPred and Transfer Setup Loop */
905 for(i = u1_mb_idx; i < u1_num_mbs; i++, ps_mb_part_info++)
906 {
907 UWORD8 u1_colz = 0;
908 ps_dec->i4_submb_ofst += SUB_BLK_SIZE;
909 /* Restore the slice scratch MbX and MbY context */
910 ps_cur_mb_info = ps_dec->ps_nmb_info + i;
Harish Mahendrakar251b0072015-08-04 09:55:15 +0530911
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530912
913 u1_field = ps_cur_mb_info->u1_mb_field_decodingflag;
914
915 ps_mv_nmb_start = ps_dec->ps_mv_cur + (i << 4);
916 ps_dec->u2_mbx = ps_cur_mb_info->u2_mbx;
917 ps_dec->u2_mby = ps_cur_mb_info->u2_mby;
918 ps_dec->u1_currB_type = 0;
919 ps_dec->u2_mv_2mb[i & 0x1] = 0;
920
921 /* Look for MV Prediction and Reference Transfer in Non-I Mbs */
922 if(!ps_mb_part_info->u1_isI_mb)
923 {
924 UWORD8 u1_blk_no;
925 WORD16 i1_ref_idx, i1_ref_idx1;
926 UWORD8 u1_pred_mode;
927 UWORD8 u1_sub_mb_x, u1_sub_mb_y, u1_sub_mb_num;
928 UWORD8 u1_lx, u1_lx_start, u1_lxend, u1_tmp_lx;
929 UWORD8 u1_num_part, u1_num_ref, u1_wd, u1_ht;
930 UWORD32 *pu4_wt_offst;
931 UWORD8 u1_scale_ref, u4_bot_mb;
932 deblk_mb_t * ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + i;
933 WORD8 (*pi1_ref_idx)[MAX_REFIDX_INFO_PER_MB] =
934 ps_mb_part_info->i1_ref_idx;
935 WORD8 *pi1_ref_idx0 = pi1_ref_idx[0],
936 *pi1_ref_idx1 = pi1_ref_idx[1];
937 UWORD32 **ppu4_wt_ofst = ps_mb_part_info->pu4_wt_offst;
938
939 /* MB Level initialisations */
940 ps_dec->u4_num_pmbair = i >> u1_mbaff;
941 ps_dec->u1_mb_idx_mv = i;
942
943 /* CHANGED CODE */
944 ps_mv_ntop_start = ps_mv_nmb_start
945 - (ps_dec->u2_frm_wd_in_mbs << (4 + u1_mbaff)) + 12;
946
947 u1_num_part = ps_mb_part_info->u1_num_part;
948 ps_cur_deblk_mb->u1_mb_type |= (u1_num_part > 1) << 1;
949 u1_direct_mode_width = (1 == ps_mb_part_info->u1_num_part) ? 16 : 8;
950
951
952 ps_cur_mb_info->u4_pred_info_pkd_idx = ps_dec->u4_pred_info_pkd_idx;
953 ps_cur_mb_info->u1_num_pred_parts = 0;
954
955 /****************************************************/
956 /* weighted u4_ofst pointer calculations, this loop */
957 /* runs maximum 4 times, even in direct cases */
958 /****************************************************/
959 u1_scale_ref = u1_mbaff & ps_cur_mb_info->u1_mb_field_decodingflag;
960 u4_bot_mb = 1 - ps_cur_mb_info->u1_topmb;
961 if(ps_dec->ps_cur_pps->u1_wted_bipred_idc)
962 {
963 u1_num_ref = MIN(u1_num_part, 4);
964 if(PART_DIRECT_16x16 != ps_part->u1_is_direct)
965 {
966 for(u1_blk_no = 0; u1_blk_no < u1_num_ref; u1_blk_no++)
967 {
968 i1_ref_idx = MAX(pi1_ref_idx0[u1_blk_no], 0);
969 if(u1_scale_ref)
970 i1_ref_idx >>= 1;
971 i1_ref_idx *=
972 ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1];
973 if(u1_scale_ref)
974 i1_ref_idx +=
975 (MAX(pi1_ref_idx1[u1_blk_no], 0)
976 >> 1);
977 else
978 i1_ref_idx += MAX(pi1_ref_idx1[u1_blk_no], 0);
979 pu4_wt_offst = (UWORD32*)&ps_dec->pu4_wt_ofsts[2
980 * X3(i1_ref_idx)];
981
982 if(pi1_ref_idx0[u1_blk_no] < 0)
983 pu4_wt_offst += 1;
984
985 ppu4_wt_ofst[u1_blk_no] = pu4_wt_offst;
986 if(u1_scale_ref
987 && (ps_dec->ps_cur_pps->u1_wted_bipred_idc
988 == 2))
989 {
990 i1_ref_idx = MAX(pi1_ref_idx0[u1_blk_no], 0);
991 i1_ref_idx *=
992 (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1]
993 << 1);
994 i1_ref_idx += MAX(pi1_ref_idx1[u1_blk_no], 0);
995 if(u4_bot_mb)
996 {
997 i1_ref_idx +=
998 (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0]
999 << 1)
1000 * (ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1]
1001 << 1);
1002 }
1003 pu4_wt_offst = (UWORD32*)&ps_dec->pu4_mbaff_wt_mat[2
1004 * X3(i1_ref_idx)];
1005 ppu4_wt_ofst[u1_blk_no] = pu4_wt_offst;
1006 }
1007 }
1008 }
1009 }
1010
1011 /**************************************************/
1012 /* Loop on Partitions */
1013 /* direct mode is reflected as a single partition */
1014 /**************************************************/
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301015 for(j = 0; j < u1_num_part; j++, ps_part++)
1016 {
1017 u1_sub_mb_num = ps_part->u1_sub_mb_num;
1018 ps_dec->u1_sub_mb_num = u1_sub_mb_num;
1019
1020 if(PART_NOT_DIRECT != ps_part->u1_is_direct)
1021 {
1022 /**************************************************/
1023 /* Direct Mode, Call DecodeSpatial/TemporalDirect */
1024 /* only (those will in turn call FormMbPartInfo) */
1025 /**************************************************/
1026 ret = ps_dec->ps_cur_slice->pf_decodeDirect(ps_dec,
1027 u1_direct_mode_width,
1028 ps_cur_mb_info, i);
1029 if(ret != OK)
1030 return ret;
1031 ps_cur_deblk_mb->u1_mb_type |= (ps_dec->u1_currB_type << 1);
1032
1033 }
1034 else
1035 {
1036 mv_pred_t s_mvPred;
1037 /**************************************************/
1038 /* Non Direct Mode, Call Motion Vector Predictor */
1039 /* and FormMbpartInfo */
1040 /**************************************************/
1041 u1_sub_mb_x = u1_sub_mb_num & 0x03;
1042 u1_sub_mb_y = u1_sub_mb_num >> 2;
1043 u1_blk_no =
1044 (u1_num_part < 4) ?
1045 j :
1046 (((u1_sub_mb_y >> 1) << 1)
1047 + (u1_sub_mb_x
1048 >> 1));
1049
1050 ps_mv_ntop = ps_mv_ntop_start + u1_sub_mb_x;
1051 ps_mv_nmb = ps_mv_nmb_start + u1_sub_mb_num;
1052
1053 u1_pred_mode = ps_part->u1_pred_mode;
1054 u1_wd = ps_part->u1_partwidth;
1055 u1_ht = ps_part->u1_partheight;
1056
1057 u1_lx_start = 0;
1058 u1_lxend = 2;
1059 if( PRED_L0 == u1_pred_mode)
1060 {
1061 s_mvPred.i2_mv[2] = 0;
1062 s_mvPred.i2_mv[3] = 0;
1063 u1_lxend = 1;
1064 }
1065 if( PRED_L1 == u1_pred_mode)
1066 {
1067 s_mvPred.i2_mv[0] = 0;
1068 s_mvPred.i2_mv[1] = 0;
1069 u1_lx_start = 1;
1070 }
1071
1072 /* Populate the colpic info and reference frames */
1073 s_mvPred.i1_ref_frame[0] = pi1_ref_idx0[u1_blk_no];
1074 s_mvPred.i1_ref_frame[1] = pi1_ref_idx1[u1_blk_no];
1075
1076 ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb, ps_mv_ntop,
1077 &s_mvPred, u1_sub_mb_num, u1_wd,
1078 u1_lx_start, u1_lxend,
1079 ps_cur_mb_info->u1_mb_mc_mode);
1080
1081 /**********************************************************/
1082 /* Loop on number of predictors, 1 Each for Forw Backw */
1083 /* Loop 2 times for BiDirect mode */
1084 /**********************************************************/
1085 for(u1_lx = u1_lx_start; u1_lx < u1_lxend; u1_lx++)
1086 {
1087 WORD16 i2_mv_x, i2_mv_y;
1088
1089 /********************************************************/
1090 /* Predict Mv */
1091 /* Add Mv Residuals and store back */
1092 /********************************************************/
1093 i1_ref_idx = s_mvPred.i1_ref_frame[u1_lx];
1094 u1_tmp_lx = (u1_lx << 1);
1095
1096 i2_mv_x = ps_mv_nmb->i2_mv[u1_tmp_lx];
1097 i2_mv_y = ps_mv_nmb->i2_mv[u1_tmp_lx + 1];
1098
1099 i2_mv_x += s_mvPred.i2_mv[u1_tmp_lx];
1100 i2_mv_y += s_mvPred.i2_mv[u1_tmp_lx + 1];
1101 s_mvPred.i2_mv[u1_tmp_lx] = i2_mv_x;
1102 s_mvPred.i2_mv[u1_tmp_lx + 1] = i2_mv_y;
1103
1104 /********************************************************/
1105 /* Transfer setup call */
1106 /* convert RefIdx if it is MbAff */
1107 /* Pass Weight Offset and refFrame */
1108 /********************************************************/
1109 i1_ref_idx1 = i1_ref_idx >> u1_scale_ref;
1110 if(u1_scale_ref && ((i1_ref_idx & 0x01) != u4_bot_mb))
1111 i1_ref_idx1 += MAX_REF_BUFS;
1112 ps_ref_frame =
1113 ps_dec->ps_ref_pic_buf_lx[u1_lx][i1_ref_idx1];
1114
1115 /* Storing Colocated-Zero u4_flag */
1116 if(u1_lx == u1_lx_start)
1117 {
1118 /* Fill colocated info in MvPred structure */
1119 s_mvPred.u1_col_ref_pic_idx =
1120 ps_ref_frame->u1_mv_buf_id;
1121 s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
1122
1123 /* Calculating colocated zero information */
1124 u1_colz =
1125 (u1_field << 1)
1126 | ((i1_ref_idx == 0)
1127 && (ABS(i2_mv_x)
1128 <= 1)
1129 && (ABS(i2_mv_y)
1130 <= 1));
1131 u1_colz |= ps_mb_part_info->u1_col_info[u1_blk_no];
1132 }
1133
1134 pu4_wt_offst = ppu4_wt_ofst[u1_blk_no];
1135 {
1136 pred_info_pkd_t *ps_pred_pkd;
1137 WORD16 i2_mv[2];
1138
1139 i2_mv[0] = i2_mv_x;
1140 i2_mv[1] = i2_mv_y;
1141
1142 ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
1143 ih264d_fill_pred_info(i2_mv,u1_wd,u1_ht,u1_sub_mb_num,u1_pred_mode,
1144 ps_pred_pkd,ps_ref_frame->u1_pic_buf_id,i1_ref_idx,pu4_wt_offst,
1145 ps_ref_frame->u1_pic_type);
1146 ps_dec->u4_pred_info_pkd_idx++;
1147 ps_cur_mb_info->u1_num_pred_parts++;
1148
1149
1150 }
1151
1152 }
1153 ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb,
1154 u1_sub_mb_num, u1_colz, u1_ht,
1155 u1_wd);
1156 }
1157 }
1158
1159 }
1160 else
1161 {
1162 /* Set zero values in case of Intra Mbs */
1163 mv_pred_t s_mvPred =
1164 {
1165 { 0, 0, 0, 0 },
1166 { -1, -1 }, 0, 0};
1167 /* Storing colocated zero information */
1168 ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
1169 (UWORD8)(u1_field << 1), 4, 4);
1170 }
1171
1172 /*if num _cores is set to 3 ,compute bs will be done in another thread*/
1173 if(ps_dec->u4_num_cores < 3)
1174 {
1175 if(ps_dec->u4_app_disable_deblk_frm == 0)
1176 ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
1177 (UWORD16)(i >> u1_mbaff));
1178 }
1179 }
1180 return OK;
1181}
1182/*!
1183 **************************************************************************
1184 * \if Function name : ih264d_get_implicit_weights \endif
1185 *
1186 * \brief
1187 * Calculates Implicit Weights.
1188 *
1189 * \return
1190 * None
1191 *
1192 **************************************************************************
1193 */
1194void ih264d_get_implicit_weights(dec_struct_t *ps_dec)
1195{
1196 UWORD32 *pu4_iwt_ofst;
1197 UWORD8 i, j;
1198 struct pic_buffer_t *ps_pic_buff0, *ps_pic_buff1;
1199 WORD16 i2_dist_scale_factor;
1200 WORD16 i16_tb, i16_td, i16_tx;
Hamsalekha S3eb692d2017-09-08 13:52:05 +05301201 WORD32 i4_tb, i4_td;
1202 WORD32 i4_poc0, i4_poc1;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301203 UWORD32 ui_temp0, ui_temp1;
1204 UWORD8 uc_num_ref_idx_l0_active, uc_num_ref_idx_l1_active;
1205
1206 pu4_iwt_ofst = ps_dec->pu4_wts_ofsts_mat;
1207 uc_num_ref_idx_l0_active =
1208 ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0];
1209 uc_num_ref_idx_l1_active =
1210 ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1];
1211
1212 for(i = 0; i < uc_num_ref_idx_l0_active; i++)
1213 {
1214 ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][i];
Hamsalekha S3eb692d2017-09-08 13:52:05 +05301215 i4_poc0 = ps_pic_buff0->i4_avg_poc;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301216 for(j = 0; j < uc_num_ref_idx_l1_active; j++)
1217 {
1218 ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][j];
Hamsalekha S3eb692d2017-09-08 13:52:05 +05301219 i4_poc1 = ps_pic_buff1->i4_avg_poc;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301220
Hamsalekha S3eb692d2017-09-08 13:52:05 +05301221 if(i4_poc1 != i4_poc0)
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301222 {
Hamsalekha S3eb692d2017-09-08 13:52:05 +05301223 i4_tb = ps_dec->ps_cur_pic->i4_poc - i4_poc0;
Isha Shrikant Kulkarnifc7139a2019-01-11 12:13:14 +05301224 i16_tb = CLIP_S8(i4_tb);
Hamsalekha S3eb692d2017-09-08 13:52:05 +05301225 i4_td = i4_poc1 - i4_poc0;
Isha Shrikant Kulkarnifc7139a2019-01-11 12:13:14 +05301226 i16_td = CLIP_S8(i4_td);
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301227 i16_tx = (16384 + ABS(SIGN_POW2_DIV(i16_td, 1))) / i16_td;
Isha Shrikant Kulkarnifc7139a2019-01-11 12:13:14 +05301228 i2_dist_scale_factor = CLIP_S11(
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301229 (((i16_tb * i16_tx) + 32) >> 6));
1230
1231 if(/*((u4_poc1 - u4_poc0) == 0) ||*/
1232 (!(ps_pic_buff1->u1_is_short && ps_pic_buff0->u1_is_short))
1233 || ((i2_dist_scale_factor >> 2) < -64)
1234 || ((i2_dist_scale_factor >> 2) > 128))
1235 {
1236 /* same for forward and backward, wt=32 and Offset = 0 */
1237 ui_temp0 = 0x00000020;
1238 ui_temp1 = 0x00000020;
1239 }
1240 else
1241 {
1242 ui_temp0 = 64 - (i2_dist_scale_factor >> 2);
1243 ui_temp1 = (i2_dist_scale_factor >> 2);
1244 }
1245 }
1246 else
1247 {
1248 ui_temp0 = 0x00000020;
1249 ui_temp1 = 0x00000020;
1250 }
1251 pu4_iwt_ofst[0] = pu4_iwt_ofst[2] = pu4_iwt_ofst[4] = ui_temp0;
1252 pu4_iwt_ofst[1] = pu4_iwt_ofst[3] = pu4_iwt_ofst[5] = ui_temp1;
1253 pu4_iwt_ofst += 6;
1254 }
1255 }
1256 if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1257 {
1258 UWORD8 k;
1259 WORD32 i4_cur_poc = ps_dec->ps_cur_pic->i4_top_field_order_cnt;
1260 UWORD32* pu4_wt_mat = ps_dec->pu4_mbaff_wt_mat;
1261 /* Form the Implicit Weighted prediction matrix for field MBs also */
1262 for(k = 0; k < 2; k++)
1263 {
1264 for(i = 0; i < (uc_num_ref_idx_l0_active << 1); i++)
1265 {
1266 UWORD16 u2_l0_idx;
1267
1268 /*u2_l0_idx = (i >= uc_num_ref_idx_l0_active)
1269 ?(MAX_REF_BUFS + i - uc_num_ref_idx_l0_active) : (i) ;*/
1270
1271 u2_l0_idx = i >> 1;
1272 if((i & 0x01) != k)
1273 {
1274 u2_l0_idx += MAX_REF_BUFS;
1275 }
1276 ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][u2_l0_idx];
Hamsalekha S3eb692d2017-09-08 13:52:05 +05301277 i4_poc0 = ps_pic_buff0->i4_poc;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301278 for(j = 0; j < (uc_num_ref_idx_l1_active << 1); j++)
1279 {
1280 UWORD16 u2_l1_idx;
1281 /*u2_l1_idx = (j >= uc_num_ref_idx_l1_active)
1282 ? (MAX_REF_BUFS + j - uc_num_ref_idx_l1_active ) : (j) ;*/
1283
1284 u2_l1_idx = j >> 1;
1285 if((j & 0x01) != k)
1286 {
1287 u2_l1_idx += MAX_REF_BUFS;
1288 }
1289 ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][u2_l1_idx];
Hamsalekha S3eb692d2017-09-08 13:52:05 +05301290 i4_poc1 = ps_pic_buff1->i4_poc;
1291 if(i4_poc1 != i4_poc0)
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301292 {
Hamsalekha S3eb692d2017-09-08 13:52:05 +05301293 i4_tb = i4_cur_poc - i4_poc0;
Isha Shrikant Kulkarnifc7139a2019-01-11 12:13:14 +05301294 i16_tb = CLIP_S8(i4_tb);
Hamsalekha S3eb692d2017-09-08 13:52:05 +05301295 i4_td = i4_poc1 - i4_poc0;
Isha Shrikant Kulkarnifc7139a2019-01-11 12:13:14 +05301296 i16_td = CLIP_S8(i4_td);
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301297 i16_tx = (16384 + ABS(SIGN_POW2_DIV(i16_td, 1)))
1298 / i16_td;
Isha Shrikant Kulkarnifc7139a2019-01-11 12:13:14 +05301299 i2_dist_scale_factor = CLIP_S11(
1300 (((i16_tb * i16_tx) + 32) >> 6));
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301301
1302 if(/*((u4_poc1 - u4_poc0) == 0) ||*/
1303 (!(ps_pic_buff1->u1_is_short && ps_pic_buff0->u1_is_short))
1304 || ((i2_dist_scale_factor >> 2) < -64)
1305 || ((i2_dist_scale_factor >> 2) > 128))
1306 {
1307 /* same for forward and backward, wt=32 and Offset = 0 */
1308 ui_temp0 = 0x00000020;
1309 ui_temp1 = 0x00000020;
1310 }
1311 else
1312 {
1313 ui_temp0 = 64 - (i2_dist_scale_factor >> 2);
1314 ui_temp1 = (i2_dist_scale_factor >> 2);
1315 }
1316 }
1317 else
1318 {
1319 ui_temp0 = 0x00000020;
1320 ui_temp1 = 0x00000020;
1321 }
1322 /* Store in the weight matrix */
1323 *pu4_wt_mat++ = ui_temp0;
1324 *pu4_wt_mat++ = ui_temp1;
1325 *pu4_wt_mat++ = ui_temp0;
1326 *pu4_wt_mat++ = ui_temp1;
1327 *pu4_wt_mat++ = ui_temp0;
1328 *pu4_wt_mat++ = ui_temp1;
1329
1330 }
1331 }
1332 i4_cur_poc = ps_dec->ps_cur_pic->i4_bottom_field_order_cnt;
1333 }
1334 }
1335}
1336
1337/*!
1338 **************************************************************************
1339 * \if Function name : ih264d_decode_bslice \endif
1340 *
1341 * \brief
1342 * Decodes a B Slice
1343 *
1344 *
1345 * \return
1346 * 0 on Success and Error code otherwise
1347 **************************************************************************
1348 */
1349WORD32 ih264d_parse_bslice(dec_struct_t * ps_dec, UWORD16 u2_first_mb_in_slice)
1350{
1351 dec_pic_params_t * ps_pps = ps_dec->ps_cur_pps;
1352 dec_slice_params_t * ps_slice = ps_dec->ps_cur_slice;
1353 dec_bit_stream_t * ps_bitstrm = ps_dec->ps_bitstrm;
1354 UWORD8 u1_ref_idx_re_flag_lx;
1355 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
1356 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
1357
1358 UWORD32 u4_temp, ui_temp1;
1359 WORD32 i_temp;
1360 WORD32 ret;
1361
1362 /*--------------------------------------------------------------------*/
1363 /* Read remaining contents of the slice header */
1364 /*--------------------------------------------------------------------*/
1365 {
1366 WORD8 *pi1_buf;
1367 WORD16 *pi2_mv = ps_dec->s_default_mv_pred.i2_mv;
1368 WORD32 *pi4_mv = (WORD32*)pi2_mv;
1369 WORD16 *pi16_refFrame;
1370 pi1_buf = ps_dec->s_default_mv_pred.i1_ref_frame;
1371 pi16_refFrame = (WORD16*)pi1_buf;
1372 *pi4_mv = 0;
1373 *(pi4_mv + 1) = 0;
1374 *pi16_refFrame = OUT_OF_RANGE_REF;
1375 ps_dec->s_default_mv_pred.u1_col_ref_pic_idx = (UWORD8)-1;
1376 ps_dec->s_default_mv_pred.u1_pic_type = (UWORD8)-1;
1377 }
1378
1379 ps_slice->u1_num_ref_idx_active_override_flag = ih264d_get_bit_h264(
1380 ps_bitstrm);
1381 COPYTHECONTEXT("SH: num_ref_idx_override_flag",
1382 ps_slice->u1_num_ref_idx_active_override_flag);
1383
1384 u4_temp = ps_dec->ps_cur_pps->u1_num_ref_idx_lx_active[0];
1385 ui_temp1 = ps_dec->ps_cur_pps->u1_num_ref_idx_lx_active[1];
1386 if(ps_slice->u1_num_ref_idx_active_override_flag)
1387 {
1388 u4_temp = 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1389 COPYTHECONTEXT("SH: num_ref_idx_l0_active_minus1",
1390 u4_temp - 1);
1391 ui_temp1 = 1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1392 COPYTHECONTEXT("SH: num_ref_idx_l1_active_minus1",
1393 ui_temp1 - 1);
1394 }
1395
1396 {
1397 UWORD8 u1_max_ref_idx = MAX_FRAMES;
1398 if(ps_slice->u1_field_pic_flag)
1399 {
1400 u1_max_ref_idx = MAX_FRAMES << 1;
1401 }
Hamsalekha S208c74d2017-09-08 14:22:22 +05301402 if((u4_temp > u1_max_ref_idx) || (ui_temp1 > u1_max_ref_idx)
1403 || (u4_temp < 1) || (ui_temp1 < 1))
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301404 {
1405 return ERROR_NUM_REF;
1406 }
1407 ps_slice->u1_num_ref_idx_lx_active[0] = u4_temp;
1408 ps_slice->u1_num_ref_idx_lx_active[1] = ui_temp1;
1409 }
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301410
Hamsalekha Sf9d3f9a2017-05-23 11:53:52 +05301411
1412 ih264d_init_ref_idx_lx_b(ps_dec);
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301413 /* Store the value for future slices in the same picture */
1414 ps_dec->u1_num_ref_idx_lx_active_prev =
1415 ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0];
1416
1417 u1_ref_idx_re_flag_lx = ih264d_get_bit_h264(ps_bitstrm);
1418 COPYTHECONTEXT("SH: ref_pic_list_reordering_flag_l0",u1_ref_idx_re_flag_lx);
1419
1420 /* Modified temporarily */
1421 if(u1_ref_idx_re_flag_lx)
1422 {
1423 WORD8 ret;
1424 ps_dec->ps_ref_pic_buf_lx[0] = ps_dec->ps_dpb_mgr->ps_mod_dpb[0];
1425 ret = ih264d_ref_idx_reordering(ps_dec, 0);
1426 if(ret == -1)
1427 return ERROR_REFIDX_ORDER_T;
1428 }
1429 else
1430 ps_dec->ps_ref_pic_buf_lx[0] = ps_dec->ps_dpb_mgr->ps_init_dpb[0];
1431
1432 u1_ref_idx_re_flag_lx = ih264d_get_bit_h264(ps_bitstrm);
1433 COPYTHECONTEXT("SH: ref_pic_list_reordering_flag_l1",u1_ref_idx_re_flag_lx);
1434
1435 /* Modified temporarily */
1436 if(u1_ref_idx_re_flag_lx)
1437 {
1438 WORD8 ret;
1439 ps_dec->ps_ref_pic_buf_lx[1] = ps_dec->ps_dpb_mgr->ps_mod_dpb[1];
1440 ret = ih264d_ref_idx_reordering(ps_dec, 1);
1441 if(ret == -1)
1442 return ERROR_REFIDX_ORDER_T;
1443 }
1444 else
1445 ps_dec->ps_ref_pic_buf_lx[1] = ps_dec->ps_dpb_mgr->ps_init_dpb[1];
1446
1447 /* Create refIdx to POC mapping */
1448 {
1449 void **ppv_map_ref_idx_to_poc_lx;
1450 WORD8 idx;
1451 struct pic_buffer_t *ps_pic;
1452
1453 ppv_map_ref_idx_to_poc_lx = ps_dec->ppv_map_ref_idx_to_poc + FRM_LIST_L0;
1454 ppv_map_ref_idx_to_poc_lx[0] = 0;
1455 ppv_map_ref_idx_to_poc_lx++;
1456 for(idx = 0; idx < ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0];
1457 idx++)
1458 {
1459 ps_pic = ps_dec->ps_ref_pic_buf_lx[0][idx];
1460 ppv_map_ref_idx_to_poc_lx[idx] = (ps_pic->pu1_buf1);
1461 }
1462
1463 ppv_map_ref_idx_to_poc_lx = ps_dec->ppv_map_ref_idx_to_poc + FRM_LIST_L1;
1464
1465 ppv_map_ref_idx_to_poc_lx[0] = 0;
1466 ppv_map_ref_idx_to_poc_lx++;
1467 for(idx = 0; idx < ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1];
1468 idx++)
1469 {
1470 ps_pic = ps_dec->ps_ref_pic_buf_lx[1][idx];
1471 ppv_map_ref_idx_to_poc_lx[idx] = (ps_pic->pu1_buf1);
1472 }
1473
1474 if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1475 {
1476 void **ppv_map_ref_idx_to_poc_lx_t, **ppv_map_ref_idx_to_poc_lx_b;
1477
1478 ppv_map_ref_idx_to_poc_lx_t = ps_dec->ppv_map_ref_idx_to_poc
1479 + TOP_LIST_FLD_L0;
1480 ppv_map_ref_idx_to_poc_lx_b = ps_dec->ppv_map_ref_idx_to_poc
1481 + BOT_LIST_FLD_L0;
1482
1483 ppv_map_ref_idx_to_poc_lx_t[0] = 0;
1484 ppv_map_ref_idx_to_poc_lx_t++;
1485 ppv_map_ref_idx_to_poc_lx_b[0] = 0;
1486 ppv_map_ref_idx_to_poc_lx_b++;
1487 for(idx = 0; idx < ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[0];
1488 idx++)
1489 {
1490 ps_pic = ps_dec->ps_ref_pic_buf_lx[0][idx];
1491 ppv_map_ref_idx_to_poc_lx_t[0] = (ps_pic->pu1_buf1);
1492 ppv_map_ref_idx_to_poc_lx_b[1] = (ps_pic->pu1_buf1);
1493
1494 ppv_map_ref_idx_to_poc_lx_b[0] = (ps_pic->pu1_buf1) + 1;
1495 ppv_map_ref_idx_to_poc_lx_t[1] = (ps_pic->pu1_buf1) + 1;
1496
1497 ppv_map_ref_idx_to_poc_lx_t += 2;
1498 ppv_map_ref_idx_to_poc_lx_b += 2;
1499 }
1500
1501 ppv_map_ref_idx_to_poc_lx_t = ps_dec->ppv_map_ref_idx_to_poc
1502 + TOP_LIST_FLD_L1;
1503 ppv_map_ref_idx_to_poc_lx_b = ps_dec->ppv_map_ref_idx_to_poc
1504 + BOT_LIST_FLD_L1;
1505
1506 ppv_map_ref_idx_to_poc_lx_t[0] = 0;
1507 ppv_map_ref_idx_to_poc_lx_t++;
1508 ppv_map_ref_idx_to_poc_lx_b[0] = 0;
1509 ppv_map_ref_idx_to_poc_lx_b++;
1510 for(idx = 0; idx < ps_dec->ps_cur_slice->u1_num_ref_idx_lx_active[1];
1511 idx++)
1512 {
1513 UWORD8 u1_tmp_idx = idx << 1;
1514 ps_pic = ps_dec->ps_ref_pic_buf_lx[1][idx];
1515 ppv_map_ref_idx_to_poc_lx_t[u1_tmp_idx] = (ps_pic->pu1_buf1);
1516 ppv_map_ref_idx_to_poc_lx_b[u1_tmp_idx + 1] = (ps_pic->pu1_buf1);
1517
1518 ppv_map_ref_idx_to_poc_lx_b[u1_tmp_idx] = (ps_pic->pu1_buf1) + 1;
1519 ppv_map_ref_idx_to_poc_lx_t[u1_tmp_idx + 1] = (ps_pic->pu1_buf1) + 1;
1520
1521 }
1522 }
1523
1524 if(ps_dec->u4_num_cores >= 3)
1525 {
1526 WORD32 num_entries;
1527 WORD32 size;
Harish Mahendrakar251b0072015-08-04 09:55:15 +05301528 num_entries = MAX_FRAMES;
1529 if((1 >= ps_dec->ps_cur_sps->u1_num_ref_frames) &&
1530 (0 == ps_dec->i4_display_delay))
1531 {
1532 num_entries = 1;
1533 }
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301534
Harish Mahendrakar251b0072015-08-04 09:55:15 +05301535 num_entries = ((2 * num_entries) + 1);
Hamsalekha Sa925a6b2017-04-21 11:01:52 +05301536 num_entries *= 2;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301537
1538 size = num_entries * sizeof(void *);
1539 size += PAD_MAP_IDX_POC * sizeof(void *);
1540
1541 memcpy((void *)ps_dec->ps_parse_cur_slice->ppv_map_ref_idx_to_poc,
1542 ps_dec->ppv_map_ref_idx_to_poc,
1543 size);
1544 }
1545
1546 }
1547
1548 if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag
1549 && (ps_dec->ps_cur_slice->u1_field_pic_flag == 0))
1550 {
1551 ih264d_convert_frm_mbaff_list(ps_dec);
1552 }
1553
1554 if(ps_pps->u1_wted_bipred_idc == 1)
1555 {
1556 ret = ih264d_parse_pred_weight_table(ps_slice, ps_bitstrm);
1557 if(ret != OK)
1558 return ret;
1559 ih264d_form_pred_weight_matrix(ps_dec);
1560 ps_dec->pu4_wt_ofsts = ps_dec->pu4_wts_ofsts_mat;
1561 }
1562 else if(ps_pps->u1_wted_bipred_idc == 2)
1563 {
1564 /* Implicit Weighted prediction */
1565 ps_slice->u2_log2Y_crwd = 0x0505;
1566 ps_dec->pu4_wt_ofsts = ps_dec->pu4_wts_ofsts_mat;
1567 ih264d_get_implicit_weights(ps_dec);
1568 }
1569 else
1570 ps_dec->ps_cur_slice->u2_log2Y_crwd = 0;
1571
1572 ps_dec->ps_parse_cur_slice->u2_log2Y_crwd =
1573 ps_dec->ps_cur_slice->u2_log2Y_crwd;
1574
1575 /* G050 */
1576 if(ps_slice->u1_nal_ref_idc != 0)
1577 {
1578 if(!ps_dec->ps_dpb_cmds->u1_dpb_commands_read)
Naveen Kumar Ponnusamy943323f2015-12-04 16:51:43 +05301579 {
1580 i_temp = ih264d_read_mmco_commands(ps_dec);
1581 if (i_temp < 0)
1582 {
1583 return ERROR_DBP_MANAGER_T;
1584 }
1585 ps_dec->u4_bitoffset = i_temp;
1586 }
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301587 else
1588 ps_bitstrm->u4_ofst += ps_dec->u4_bitoffset;
1589 }
1590 /* G050 */
1591
1592 if(ps_pps->u1_entropy_coding_mode == CABAC)
1593 {
1594 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1595 if(u4_temp > MAX_CABAC_INIT_IDC)
1596 {
1597 return ERROR_INV_SLICE_HDR_T;
1598 }
1599 ps_slice->u1_cabac_init_idc = u4_temp;
1600 COPYTHECONTEXT("SH: cabac_init_idc",ps_slice->u1_cabac_init_idc);
1601 }
1602
1603 /* Read slice_qp_delta */
Harish Mahendrakar08b77b22019-07-02 15:28:05 -07001604 WORD64 i8_temp = (WORD64)ps_pps->u1_pic_init_qp
1605 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1606 if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP))
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301607 {
1608 return ERROR_INV_RANGE_QP_T;
1609 }
Harish Mahendrakar08b77b22019-07-02 15:28:05 -07001610 ps_slice->u1_slice_qp = i8_temp;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301611 COPYTHECONTEXT("SH: slice_qp_delta",
1612 (WORD8)(ps_slice->u1_slice_qp - ps_pps->u1_pic_init_qp));
1613
1614 if(ps_pps->u1_deblocking_filter_parameters_present_flag == 1)
1615 {
1616 u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1617 if(u4_temp > SLICE_BOUNDARY_DBLK_DISABLED)
1618 {
1619 return ERROR_INV_SLICE_HDR_T;
1620 } COPYTHECONTEXT("SH: disable_deblocking_filter_idc", u4_temp);
1621 ps_slice->u1_disable_dblk_filter_idc = u4_temp;
1622 if(u4_temp != 1)
1623 {
1624 i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
1625 << 1;
1626 if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
1627 {
1628 return ERROR_INV_SLICE_HDR_T;
1629 }
1630 ps_slice->i1_slice_alpha_c0_offset = i_temp;
1631 COPYTHECONTEXT("SH: slice_alpha_c0_offset_div2",
1632 ps_slice->i1_slice_alpha_c0_offset >> 1);
1633
1634 i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
1635 << 1;
1636 if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
1637 {
1638 return ERROR_INV_SLICE_HDR_T;
1639 }
1640 ps_slice->i1_slice_beta_offset = i_temp;
1641 COPYTHECONTEXT("SH: slice_beta_offset_div2",
1642 ps_slice->i1_slice_beta_offset >> 1);
1643
1644 }
1645 else
1646 {
1647 ps_slice->i1_slice_alpha_c0_offset = 0;
1648 ps_slice->i1_slice_beta_offset = 0;
1649 }
1650 }
1651 else
1652 {
1653 ps_slice->u1_disable_dblk_filter_idc = 0;
1654 ps_slice->i1_slice_alpha_c0_offset = 0;
1655 ps_slice->i1_slice_beta_offset = 0;
1656 }
1657
Marco Nelissen8ef4c3f2015-06-03 07:26:32 -07001658 ps_dec->u1_slice_header_done = 2;
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301659
1660 if(ps_pps->u1_entropy_coding_mode)
1661 {
1662 SWITCHOFFTRACE; SWITCHONTRACECABAC;
1663 ps_dec->pf_parse_inter_slice = ih264d_parse_inter_slice_data_cabac;
1664 ps_dec->pf_parse_inter_mb = ih264d_parse_bmb_cabac;
1665 ih264d_init_cabac_contexts(B_SLICE, ps_dec);
1666
1667 if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1668 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_mbaff;
1669 else
1670 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_nonmbaff;
1671 }
1672 else
1673 {
1674 SWITCHONTRACE; SWITCHOFFTRACECABAC;
1675 ps_dec->pf_parse_inter_slice = ih264d_parse_inter_slice_data_cavlc;
1676 ps_dec->pf_parse_inter_mb = ih264d_parse_bmb_cavlc;
1677 if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1678 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_mbaff;
1679 else
1680 ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_nonmbaff;
1681 }
1682
1683 ret = ih264d_cal_col_pic(ps_dec);
1684 if(ret != OK)
1685 return ret;
1686 ps_dec->u1_B = 1;
1687 ps_dec->pf_mvpred_ref_tfr_nby2mb = ih264d_mv_pred_ref_tfr_nby2_bmb;
1688 ret = ps_dec->pf_parse_inter_slice(ps_dec, ps_slice, u2_first_mb_in_slice);
1689 if(ret != OK)
1690 return ret;
1691 return OK;
1692}
1693