Coverage Report

Created: 2026-10-17 07:28

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