Coverage Report

Created: 2025-11-11 06:42

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
205k
{
93
205k
    WORD32 i4_delta_qp;
94
205k
    UWORD32 u4_temp;
95
205k
    UWORD32 ui_is_top_mb_available;
96
205k
    UWORD32 ui_is_left_mb_available;
97
205k
    UWORD32 u4_cbp;
98
205k
    UWORD32 u4_offset;
99
205k
    UWORD32 *pu4_bitstrm_buf;
100
205k
    WORD32 ret;
101
102
205k
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
103
205k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
104
205k
    UNUSED(u4_mb_num);
105
205k
    ps_cur_mb_info->u1_tran_form8x8 = 0;
106
205k
    ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
107
108
205k
    ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
109
110
205k
    u4_temp = ps_dec->u1_mb_ngbr_availablity;
111
205k
    ui_is_top_mb_available = BOOLEAN(u4_temp & TOP_MB_AVAILABLE_MASK);
112
205k
    ui_is_left_mb_available = BOOLEAN(u4_temp & LEFT_MB_AVAILABLE_MASK);
113
114
205k
    pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
115
116
205k
    if(u1_mb_type == I_4x4_MB)
117
57.8k
    {
118
57.8k
        ps_cur_mb_info->ps_curmb->u1_mb_type = I_4x4_MB;
119
57.8k
        u4_offset = 0;
120
121
        /*--------------------------------------------------------------------*/
122
        /* Read transform_size_8x8_flag if present                            */
123
        /*--------------------------------------------------------------------*/
124
57.8k
        if(ps_dec->s_high_profile.u1_transform8x8_present)
125
34.0k
        {
126
34.0k
            ps_cur_mb_info->u1_tran_form8x8 = ih264d_get_bit_h264(ps_bitstrm);
127
34.0k
            COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
128
34.0k
            ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
129
34.0k
        }
130
131
        /*--------------------------------------------------------------------*/
132
        /* Read the IntraPrediction modes for LUMA                            */
133
        /*--------------------------------------------------------------------*/
134
57.8k
        if (!ps_cur_mb_info->u1_tran_form8x8)
135
26.9k
        {
136
26.9k
            UWORD8 *pu1_temp;
137
26.9k
            ih264d_read_intra_pred_modes(ps_dec,
138
26.9k
                                          ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
139
26.9k
                                          ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+16),
140
26.9k
                                          ps_cur_mb_info->u1_tran_form8x8);
141
26.9k
            pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
142
26.9k
            pu1_temp += 32;
143
26.9k
            ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
144
26.9k
        }
145
30.9k
        else
146
30.9k
        {
147
30.9k
            UWORD8 *pu1_temp;
148
30.9k
            ih264d_read_intra_pred_modes(ps_dec,
149
30.9k
                                          ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
150
30.9k
                                          ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+4),
151
30.9k
                                          ps_cur_mb_info->u1_tran_form8x8);
152
30.9k
            pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
153
30.9k
            pu1_temp += 8;
154
30.9k
            ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
155
30.9k
        }
156
        /*--------------------------------------------------------------------*/
157
        /* Read the IntraPrediction mode for CHROMA                           */
158
        /*--------------------------------------------------------------------*/
159
//Inlined ih264d_uev
160
57.8k
        {
161
57.8k
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
162
57.8k
            UWORD32 u4_word, u4_ldz, u4_temp;
163
164
            /***************************************************************/
165
            /* Find leading zeros in next 32 bits                          */
166
            /***************************************************************/
167
57.8k
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
168
57.8k
            u4_ldz = CLZ(u4_word);
169
            /* Flush the ps_bitstrm */
170
57.8k
            u4_bitstream_offset += (u4_ldz + 1);
171
            /* Read the suffix from the ps_bitstrm */
172
57.8k
            u4_word = 0;
173
57.8k
            if(u4_ldz)
174
11.2k
            {
175
11.2k
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
176
11.2k
                        u4_ldz);
177
11.2k
            }
178
57.8k
            *pu4_bitstrm_ofst = u4_bitstream_offset;
179
57.8k
            u4_temp = ((1 << u4_ldz) + u4_word - 1);
180
57.8k
            if(u4_temp > 3)
181
1.23k
            {
182
1.23k
                return ERROR_CHROMA_PRED_MODE;
183
1.23k
            }
184
56.6k
            ps_cur_mb_info->u1_chroma_pred_mode = u4_temp;
185
56.6k
            COPYTHECONTEXT("intra_chroma_pred_mode", ps_cur_mb_info->u1_chroma_pred_mode);
186
56.6k
        }
187
        /*--------------------------------------------------------------------*/
188
        /* Read the Coded block pattern                                       */
189
        /*--------------------------------------------------------------------*/
190
0
        {
191
56.6k
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
192
56.6k
            UWORD32 u4_word, u4_ldz;
193
194
            /***************************************************************/
195
            /* Find leading zeros in next 32 bits                          */
196
            /***************************************************************/
197
56.6k
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
198
56.6k
            u4_ldz = CLZ(u4_word);
199
            /* Flush the ps_bitstrm */
200
56.6k
            u4_bitstream_offset += (u4_ldz + 1);
201
            /* Read the suffix from the ps_bitstrm */
202
56.6k
            u4_word = 0;
203
56.6k
            if(u4_ldz)
204
18.0k
            {
205
18.0k
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
206
18.0k
                        u4_ldz);
207
18.0k
            }
208
56.6k
            *pu4_bitstrm_ofst = u4_bitstream_offset;
209
56.6k
            u4_cbp = ((1 << u4_ldz) + u4_word - 1);
210
56.6k
        }
211
56.6k
        if(u4_cbp > 47)
212
200
        {
213
200
            return ERROR_CBP;
214
200
        }
215
216
56.4k
        u4_cbp = gau1_ih264d_cbp_table[u4_cbp][0];
217
56.4k
        COPYTHECONTEXT("coded_block_pattern", u1_cbp);
218
56.4k
        ps_cur_mb_info->u1_cbp = u4_cbp;
219
220
        /*--------------------------------------------------------------------*/
221
        /* Read mb_qp_delta                                                   */
222
        /*--------------------------------------------------------------------*/
223
56.4k
        if(ps_cur_mb_info->u1_cbp)
224
53.3k
        {
225
53.3k
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
226
53.3k
            UWORD32 u4_word, u4_ldz, u4_abs_val;
227
228
            /***************************************************************/
229
            /* Find leading zeros in next 32 bits                          */
230
            /***************************************************************/
231
53.3k
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
232
53.3k
            u4_ldz = CLZ(u4_word);
233
234
            /* Flush the ps_bitstrm */
235
53.3k
            u4_bitstream_offset += (u4_ldz + 1);
236
237
            /* Read the suffix from the ps_bitstrm */
238
53.3k
            u4_word = 0;
239
53.3k
            if(u4_ldz)
240
13.2k
            {
241
13.2k
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
242
13.2k
                        u4_ldz);
243
13.2k
            }
244
245
53.3k
            *pu4_bitstrm_ofst = u4_bitstream_offset;
246
53.3k
            u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
247
248
53.3k
            if(u4_word & 0x1)
249
8.64k
            {
250
8.64k
                i4_delta_qp = (-(WORD32)u4_abs_val);
251
8.64k
            }
252
44.7k
            else
253
44.7k
            {
254
44.7k
                i4_delta_qp = (u4_abs_val);
255
44.7k
            }
256
257
53.3k
            if((i4_delta_qp < -26) || (i4_delta_qp > 25))
258
366
            {
259
366
                return ERROR_INV_RANGE_QP_T;
260
366
            }
261
262
52.9k
            COPYTHECONTEXT("mb_qp_delta", i1_delta_qp);
263
52.9k
            if(i4_delta_qp != 0)
264
12.8k
            {
265
12.8k
                ret = ih264d_update_qp(ps_dec, (WORD8)i4_delta_qp);
266
12.8k
                if(ret != OK)
267
0
                    return ret;
268
12.8k
            }
269
52.9k
        }
270
271
56.4k
    }
272
147k
    else
273
147k
    {
274
147k
        u4_offset = 1;
275
147k
        ps_cur_mb_info->ps_curmb->u1_mb_type = I_16x16_MB;
276
        /*-------------------------------------------------------------------*/
277
        /* Read the IntraPrediction mode for CHROMA                          */
278
        /*-------------------------------------------------------------------*/
279
147k
        {
280
147k
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
281
147k
            UWORD32 u4_word, u4_ldz;
282
283
            /***************************************************************/
284
            /* Find leading zeros in next 32 bits                          */
285
            /***************************************************************/
286
147k
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
287
147k
            u4_ldz = CLZ(u4_word);
288
            /* Flush the ps_bitstrm */
289
147k
            u4_bitstream_offset += (u4_ldz + 1);
290
            /* Read the suffix from the ps_bitstrm */
291
147k
            u4_word = 0;
292
147k
            if(u4_ldz)
293
34.1k
            {
294
34.1k
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
295
34.1k
                        u4_ldz);
296
34.1k
            }
297
147k
            *pu4_bitstrm_ofst = u4_bitstream_offset;
298
147k
            u4_temp = ((1 << u4_ldz) + u4_word - 1);
299
300
//Inlined ih264d_uev
301
302
147k
            if(u4_temp > 3)
303
927
            {
304
927
                return ERROR_CHROMA_PRED_MODE;
305
927
            }
306
146k
            ps_cur_mb_info->u1_chroma_pred_mode = u4_temp;
307
146k
            COPYTHECONTEXT("intra_chroma_pred_mode", ps_cur_mb_info->u1_chroma_pred_mode);
308
146k
        }
309
        /*-------------------------------------------------------------------*/
310
        /* Read the Coded block pattern                                      */
311
        /*-------------------------------------------------------------------*/
312
0
        u4_cbp = gau1_ih264d_cbp_tab[(u1_mb_type - 1) >> 2];
313
146k
        ps_cur_mb_info->u1_cbp = u4_cbp;
314
315
        /*-------------------------------------------------------------------*/
316
        /* Read mb_qp_delta                                                  */
317
        /*-------------------------------------------------------------------*/
318
146k
        {
319
146k
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
320
146k
            UWORD32 u4_word, u4_ldz, u4_abs_val;
321
322
            /***************************************************************/
323
            /* Find leading zeros in next 32 bits                          */
324
            /***************************************************************/
325
146k
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
326
146k
            u4_ldz = CLZ(u4_word);
327
328
            /* Flush the ps_bitstrm */
329
146k
            u4_bitstream_offset += (u4_ldz + 1);
330
331
            /* Read the suffix from the ps_bitstrm */
332
146k
            u4_word = 0;
333
146k
            if(u4_ldz)
334
79.5k
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
335
146k
                        u4_ldz);
336
337
146k
            *pu4_bitstrm_ofst = u4_bitstream_offset;
338
146k
            u4_abs_val = ((1 << u4_ldz) + u4_word) >> 1;
339
340
146k
            if(u4_word & 0x1)
341
46.8k
                i4_delta_qp = (-(WORD32)u4_abs_val);
342
99.8k
            else
343
99.8k
                i4_delta_qp = (u4_abs_val);
344
345
146k
            if((i4_delta_qp < -26) || (i4_delta_qp > 25))
346
346
                return ERROR_INV_RANGE_QP_T;
347
348
146k
        }
349
//inlinined ih264d_sev
350
146k
        COPYTHECONTEXT("Delta quant", i1_delta_qp);
351
352
146k
        if(i4_delta_qp != 0)
353
79.2k
        {
354
79.2k
            ret = ih264d_update_qp(ps_dec, (WORD8)i4_delta_qp);
355
79.2k
            if(ret != OK)
356
0
                return ret;
357
79.2k
        }
358
359
146k
        {
360
146k
            WORD16 i_scaleFactor;
361
146k
            UWORD32 ui_N = 0;
362
146k
            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
146k
            if(ps_dec->s_high_profile.u1_scaling_present)
368
7.98k
            {
369
7.98k
                pi2_scale_matrix_ptr =
370
7.98k
                                ps_dec->s_high_profile.i2_scalinglist4x4[0];
371
7.98k
            }
372
138k
            else
373
138k
            {
374
138k
                i_scaleFactor = 16;
375
138k
                pi2_scale_matrix_ptr = &i_scaleFactor;
376
138k
            }
377
378
            /*---------------------------------------------------------------*/
379
            /* Decode DC coefficients                                        */
380
            /*---------------------------------------------------------------*/
381
            /*---------------------------------------------------------------*/
382
            /* Calculation of N                                              */
383
            /*---------------------------------------------------------------*/
384
146k
            if(ui_is_left_mb_available)
385
83.5k
            {
386
387
83.5k
                if(ui_is_top_mb_available)
388
64.1k
                {
389
64.1k
                    ui_N = ((ps_cur_mb_info->ps_top_mb->pu1_nnz_y[0]
390
64.1k
                                    + ps_dec->pu1_left_nnz_y[0] + 1) >> 1);
391
64.1k
                }
392
19.4k
                else
393
19.4k
                {
394
19.4k
                    ui_N = ps_dec->pu1_left_nnz_y[0];
395
19.4k
                }
396
83.5k
            }
397
62.8k
            else if(ui_is_top_mb_available)
398
29.8k
            {
399
29.8k
                ui_N = ps_cur_mb_info->ps_top_mb->pu1_nnz_y[0];
400
29.8k
            }
401
402
146k
            {
403
146k
                WORD16 pi2_dc_coef[16];
404
146k
                WORD32 pi4_tmp[16];
405
146k
                tu_sblk4x4_coeff_data_t *ps_tu_4x4 =
406
146k
                                (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
407
146k
                WORD16 *pi2_coeff_block =
408
146k
                                (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
409
146k
                UWORD32 u4_num_coeff;
410
146k
                ps_tu_4x4->u2_sig_coeff_map = 0;
411
412
146k
                ret = ps_dec->pf_cavlc_parse4x4coeff[(ui_N > 7)](pi2_dc_coef, 0, ui_N,
413
146k
                                                                 ps_dec, &u4_num_coeff);
414
146k
                if(ret != OK)
415
249
                    return ret;
416
417
146k
                if(EXCEED_OFFSET(ps_bitstrm))
418
373
                    return ERROR_EOB_TERMINATE_T;
419
145k
                if(ps_tu_4x4->u2_sig_coeff_map)
420
28.5k
                {
421
28.5k
                    memset(pi2_dc_coef,0,sizeof(pi2_dc_coef));
422
28.5k
                    ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
423
28.5k
                                                     pi2_dc_coef,
424
28.5k
                                                     ps_dec->pu1_inv_scan);
425
426
28.5k
                    PROFILE_DISABLE_IQ_IT_RECON()
427
28.5k
                    ps_dec->pf_ihadamard_scaling_4x4(pi2_dc_coef,
428
28.5k
                                                     pi2_coeff_block,
429
28.5k
                                                     ps_dec->pu2_quant_scale_y,
430
28.5k
                                                     (UWORD16 *)pi2_scale_matrix_ptr,
431
28.5k
                                                     ps_dec->u1_qp_y_div6,
432
28.5k
                                                     pi4_tmp);
433
28.5k
                    pi2_coeff_block += 16;
434
28.5k
                    ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_block;
435
28.5k
                    SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,0);
436
28.5k
                }
437
438
145k
            }
439
145k
        }
440
145k
    }
441
442
443
201k
    if(u4_cbp)
444
85.6k
    {
445
446
85.6k
        ret = ih264d_parse_residual4x4_cavlc(ps_dec, ps_cur_mb_info,
447
85.6k
                                       (UWORD8)u4_offset);
448
85.6k
        if(ret != OK)
449
2.92k
            return ret;
450
82.7k
        if(EXCEED_OFFSET(ps_bitstrm))
451
1.20k
            return ERROR_EOB_TERMINATE_T;
452
453
        /* Store Left Mb NNZ and TOP chroma NNZ */
454
82.7k
    }
455
116k
    else
456
116k
    {
457
116k
        ps_cur_mb_info->u1_qp_div6 = ps_dec->u1_qp_y_div6;
458
116k
        ps_cur_mb_info->u1_qpc_div6 = ps_dec->u1_qp_u_div6;
459
116k
        ps_cur_mb_info->u1_qpcr_div6 = ps_dec->u1_qp_v_div6;
460
116k
        ps_cur_mb_info->u1_qp_rem6 = ps_dec->u1_qp_y_rem6;
461
116k
        ps_cur_mb_info->u1_qpc_rem6 = ps_dec->u1_qp_u_rem6;
462
116k
        ps_cur_mb_info->u1_qpcr_rem6 = ps_dec->u1_qp_v_rem6;
463
116k
        ih264d_update_nnz_for_skipmb(ps_dec, ps_cur_mb_info, CAVLC);
464
116k
    }
465
466
197k
    return OK;
467
201k
}
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.29M
{
486
1.29M
    WORD8 i1_delta_qp;
487
1.29M
    UWORD8 u1_cbp;
488
1.29M
    UWORD8 u1_offset;
489
    /* Variables for handling Cabac contexts */
490
1.29M
    ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
491
1.29M
    ctxt_inc_mb_info_t *ps_left_ctxt = ps_dec->p_left_ctxt_mb_info;
492
1.29M
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
493
1.29M
    bin_ctxt_model_t *p_bin_ctxt;
494
495
1.29M
    UWORD8 u1_intra_chrom_pred_mode;
496
1.29M
    UWORD8 u1_dc_block_flag = 0;
497
1.29M
    WORD32 ret;
498
499
1.29M
    ps_cur_mb_info->u1_yuv_dc_block_flag = 0;
500
501
1.29M
    if(ps_left_ctxt == ps_dec->ps_def_ctxt_mb_info)
502
61.1k
    {
503
61.1k
        ps_dec->pu1_left_yuv_dc_csbp[0] = 0xf;
504
61.1k
    }
505
506
1.29M
    if(ps_dec->ps_cur_slice->u1_slice_type != I_SLICE)
507
34.4k
    {
508
34.4k
        WORD32 *pi4_buf;
509
34.4k
        WORD8 *pi1_buf;
510
34.4k
        MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0);
511
34.4k
        *((UWORD32 *)ps_dec->pi1_left_ref_idx_ctxt_inc) = 0;
512
34.4k
        MEMSET_16BYTES(p_curr_ctxt->u1_mv, 0);
513
34.4k
        memset(p_curr_ctxt->i1_ref_idx, 0, 4);
514
34.4k
    }
515
516
1.29M
    if(u1_mb_type == I_4x4_MB)
517
448k
    {
518
448k
        ps_cur_mb_info->ps_curmb->u1_mb_type = I_4x4_MB;
519
448k
        p_curr_ctxt->u1_mb_type = CAB_I4x4;
520
448k
        u1_offset = 0;
521
522
448k
        ps_cur_mb_info->u1_tran_form8x8 = 0;
523
448k
        ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
524
525
        /*--------------------------------------------------------------------*/
526
        /* Read transform_size_8x8_flag if present                            */
527
        /*--------------------------------------------------------------------*/
528
448k
        if(ps_dec->s_high_profile.u1_transform8x8_present)
529
70.0k
        {
530
70.0k
            ps_cur_mb_info->u1_tran_form8x8 = ih264d_parse_transform8x8flag_cabac(
531
70.0k
                            ps_dec, ps_cur_mb_info);
532
70.0k
            COPYTHECONTEXT("transform_size_8x8_flag", ps_cur_mb_info->u1_tran_form8x8);
533
70.0k
            p_curr_ctxt->u1_transform8x8_ctxt = ps_cur_mb_info->u1_tran_form8x8;
534
70.0k
            ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = ps_cur_mb_info->u1_tran_form8x8;
535
70.0k
        }
536
378k
        else
537
378k
        {
538
378k
            p_curr_ctxt->u1_transform8x8_ctxt = 0;
539
378k
        }
540
541
        /*--------------------------------------------------------------------*/
542
        /* Read the IntraPrediction modes for LUMA                            */
543
        /*--------------------------------------------------------------------*/
544
448k
        if (!ps_cur_mb_info->u1_tran_form8x8)
545
391k
        {
546
391k
            UWORD8 *pu1_temp;
547
391k
            ih264d_read_intra_pred_modes_cabac(
548
391k
                            ps_dec,
549
391k
                            ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
550
391k
                            ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+16),
551
391k
                            ps_cur_mb_info->u1_tran_form8x8);
552
391k
            pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
553
391k
            pu1_temp += 32;
554
391k
            ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
555
391k
        }
556
56.8k
        else
557
56.8k
        {
558
56.8k
            UWORD8 *pu1_temp;
559
56.8k
            ih264d_read_intra_pred_modes_cabac(
560
56.8k
                            ps_dec,
561
56.8k
                            ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data),
562
56.8k
                            ((UWORD8 *)ps_dec->pv_parse_tu_coeff_data+4),
563
56.8k
                            ps_cur_mb_info->u1_tran_form8x8);
564
56.8k
            pu1_temp = (UWORD8 *)ps_dec->pv_parse_tu_coeff_data;
565
56.8k
            pu1_temp += 8;
566
56.8k
            ps_dec->pv_parse_tu_coeff_data = (void *)pu1_temp;
567
56.8k
        }
568
        /*--------------------------------------------------------------------*/
569
        /* Read the IntraPrediction mode for CHROMA                           */
570
        /*--------------------------------------------------------------------*/
571
448k
        u1_intra_chrom_pred_mode = ih264d_parse_chroma_pred_mode_cabac(ps_dec);
572
448k
        COPYTHECONTEXT("intra_chroma_pred_mode", u1_intra_chrom_pred_mode);
573
448k
        p_curr_ctxt->u1_intra_chroma_pred_mode = ps_cur_mb_info->u1_chroma_pred_mode =
574
448k
                        u1_intra_chrom_pred_mode;
575
576
        /*--------------------------------------------------------------------*/
577
        /* Read the Coded block pattern                                       */
578
        /*--------------------------------------------------------------------*/
579
448k
        u1_cbp = ih264d_parse_ctx_cbp_cabac(ps_dec);
580
448k
        COPYTHECONTEXT("coded_block_pattern", u1_cbp);
581
448k
        ps_cur_mb_info->u1_cbp = u1_cbp;
582
448k
        p_curr_ctxt->u1_cbp = u1_cbp;
583
584
        /*--------------------------------------------------------------------*/
585
        /* Read mb_qp_delta                                                   */
586
        /*--------------------------------------------------------------------*/
587
448k
        if(ps_cur_mb_info->u1_cbp)
588
298k
        {
589
298k
            ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &i1_delta_qp);
590
298k
            if(ret != OK)
591
123
                return ret;
592
298k
            COPYTHECONTEXT("mb_qp_delta", i1_delta_qp);
593
298k
            if(i1_delta_qp != 0)
594
39.3k
            {
595
39.3k
                ret = ih264d_update_qp(ps_dec, i1_delta_qp);
596
39.3k
                if(ret != OK)
597
0
                    return ret;
598
39.3k
            }
599
298k
        }
600
149k
        else
601
149k
            ps_dec->i1_prev_mb_qp_delta = 0;
602
448k
        p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE;
603
448k
    }
604
843k
    else
605
843k
    {
606
843k
        u1_offset = 1;
607
843k
        ps_cur_mb_info->ps_curmb->u1_mb_type = I_16x16_MB;
608
843k
        p_curr_ctxt->u1_mb_type = CAB_I16x16;
609
843k
        ps_cur_mb_info->u1_tran_form8x8 = 0;
610
843k
        p_curr_ctxt->u1_transform8x8_ctxt = 0;
611
843k
        ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
612
        /*--------------------------------------------------------------------*/
613
        /* Read the IntraPrediction mode for CHROMA                           */
614
        /*--------------------------------------------------------------------*/
615
843k
        u1_intra_chrom_pred_mode = ih264d_parse_chroma_pred_mode_cabac(ps_dec);
616
843k
        if(u1_intra_chrom_pred_mode > 3)
617
0
            return ERROR_CHROMA_PRED_MODE;
618
619
843k
        COPYTHECONTEXT("Chroma intra_chroma_pred_mode pred mode", u1_intra_chrom_pred_mode);
620
843k
        p_curr_ctxt->u1_intra_chroma_pred_mode = ps_cur_mb_info->u1_chroma_pred_mode =
621
843k
                        u1_intra_chrom_pred_mode;
622
623
        /*--------------------------------------------------------------------*/
624
        /* Read the Coded block pattern                                       */
625
        /*--------------------------------------------------------------------*/
626
843k
        u1_cbp = gau1_ih264d_cbp_tab[(u1_mb_type - 1) >> 2];
627
843k
        ps_cur_mb_info->u1_cbp = u1_cbp;
628
843k
        p_curr_ctxt->u1_cbp = u1_cbp;
629
630
        /*--------------------------------------------------------------------*/
631
        /* Read mb_qp_delta                                                   */
632
        /*--------------------------------------------------------------------*/
633
843k
        ret = ih264d_parse_mb_qp_delta_cabac(ps_dec, &i1_delta_qp);
634
843k
        if(ret != OK)
635
105
            return ret;
636
843k
        COPYTHECONTEXT("mb_qp_delta", i1_delta_qp);
637
843k
        if(i1_delta_qp != 0)
638
224k
        {
639
224k
            ret = ih264d_update_qp(ps_dec, i1_delta_qp);
640
224k
            if(ret != OK)
641
0
                return ret;
642
224k
        }
643
644
843k
        {
645
843k
            WORD16 i_scaleFactor;
646
843k
            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
843k
            if(ps_dec->s_high_profile.u1_scaling_present)
652
6.41k
            {
653
6.41k
                pi2_scale_matrix_ptr =
654
6.41k
                                ps_dec->s_high_profile.i2_scalinglist4x4[0];
655
656
6.41k
            }
657
837k
            else
658
837k
            {
659
837k
                i_scaleFactor = 16;
660
837k
                pi2_scale_matrix_ptr = &i_scaleFactor;
661
837k
            }
662
843k
            {
663
843k
                ctxt_inc_mb_info_t *ps_top_ctxt = ps_dec->p_top_ctxt_mb_info;
664
843k
                UWORD8 uc_a, uc_b;
665
843k
                UWORD32 u4_ctx_inc;
666
667
843k
                INC_SYM_COUNT(&(ps_dec->s_cab_dec_env));
668
669
                /* if MbAddrN not available then CondTermN = 1 */
670
843k
                uc_b = ((ps_top_ctxt->u1_yuv_dc_csbp) & 0x01);
671
672
                /* if MbAddrN not available then CondTermN = 1 */
673
843k
                uc_a = ((ps_dec->pu1_left_yuv_dc_csbp[0]) & 0x01);
674
675
843k
                u4_ctx_inc = (uc_a + (uc_b << 1));
676
677
843k
                {
678
843k
                    WORD16 pi2_dc_coef[16];
679
843k
                    tu_sblk4x4_coeff_data_t *ps_tu_4x4 =
680
843k
                                    (tu_sblk4x4_coeff_data_t *)ps_dec->pv_parse_tu_coeff_data;
681
843k
                    WORD16 *pi2_coeff_block =
682
843k
                                    (WORD16 *)ps_dec->pv_parse_tu_coeff_data;
683
684
843k
                    p_bin_ctxt = (ps_dec->p_cbf_t[LUMA_DC_CTXCAT]) + u4_ctx_inc;
685
686
843k
                    u1_dc_block_flag =
687
843k
                                    ih264d_read_coeff4x4_cabac(ps_bitstrm,
688
843k
                                                    LUMA_DC_CTXCAT,
689
843k
                                                    ps_dec->p_significant_coeff_flag_t[LUMA_DC_CTXCAT],
690
843k
                                                    ps_dec, p_bin_ctxt);
691
692
                    /* Store coded_block_flag */
693
843k
                    p_curr_ctxt->u1_yuv_dc_csbp &= 0xFE;
694
843k
                    p_curr_ctxt->u1_yuv_dc_csbp |= u1_dc_block_flag;
695
843k
                    if(u1_dc_block_flag)
696
88.3k
                    {
697
88.3k
                        WORD32 pi4_tmp[16];
698
88.3k
                        memset(pi2_dc_coef,0,sizeof(pi2_dc_coef));
699
88.3k
                        ih264d_unpack_coeff4x4_dc_4x4blk(ps_tu_4x4,
700
88.3k
                                                         pi2_dc_coef,
701
88.3k
                                                         ps_dec->pu1_inv_scan);
702
703
88.3k
                        PROFILE_DISABLE_IQ_IT_RECON()
704
88.3k
                        ps_dec->pf_ihadamard_scaling_4x4(pi2_dc_coef,
705
88.3k
                                                         pi2_coeff_block,
706
88.3k
                                                         ps_dec->pu2_quant_scale_y,
707
88.3k
                                                         (UWORD16 *)pi2_scale_matrix_ptr,
708
88.3k
                                                         ps_dec->u1_qp_y_div6,
709
88.3k
                                                         pi4_tmp);
710
88.3k
                        pi2_coeff_block += 16;
711
88.3k
                        ps_dec->pv_parse_tu_coeff_data = (void *)pi2_coeff_block;
712
88.3k
                        SET_BIT(ps_cur_mb_info->u1_yuv_dc_block_flag,0);
713
88.3k
                    }
714
715
843k
                }
716
717
843k
            }
718
843k
        }
719
843k
    }
720
721
1.29M
    ps_dec->pu1_left_yuv_dc_csbp[0] &= 0x6;
722
1.29M
    ps_dec->pu1_left_yuv_dc_csbp[0] |= u1_dc_block_flag;
723
724
1.29M
    ih264d_parse_residual4x4_cabac(ps_dec, ps_cur_mb_info, u1_offset);
725
1.29M
    if(EXCEED_OFFSET(ps_bitstrm))
726
4.74k
        return ERROR_EOB_TERMINATE_T;
727
1.28M
    return OK;
728
1.29M
}
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
37.1k
{
758
37.1k
    UWORD8 uc_more_data_flag;
759
37.1k
    UWORD32 u4_num_mbs, u4_mb_idx;
760
37.1k
    dec_mb_info_t *ps_cur_mb_info;
761
37.1k
    deblk_mb_t *ps_cur_deblk_mb;
762
37.1k
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
763
37.1k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
764
37.1k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
765
37.1k
    UWORD16 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
766
37.1k
    WORD32 i4_cur_mb_addr;
767
37.1k
    UWORD8 u1_mbaff;
768
37.1k
    UWORD32 u4_num_mbs_next, u4_end_of_row, u4_tfr_n_mb;
769
37.1k
    WORD32 ret = OK;
770
771
37.1k
    ps_dec->u1_qp = ps_slice->u1_slice_qp;
772
37.1k
    ih264d_update_qp(ps_dec, 0);
773
37.1k
    u1_mbaff = ps_slice->u1_mbaff_frame_flag;
774
775
    /* initializations */
776
37.1k
    u4_mb_idx = ps_dec->u4_mb_idx;
777
37.1k
    u4_num_mbs = u4_mb_idx;
778
779
37.1k
    uc_more_data_flag = 1;
780
37.1k
    i4_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff;
781
782
37.1k
    do
783
165k
    {
784
165k
        UWORD8 u1_mb_type;
785
786
165k
        ps_dec->pv_prev_mb_parse_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
787
788
165k
        if(i4_cur_mb_addr > ps_dec->ps_cur_sps->u4_max_mb_addr)
789
28.9k
        {
790
28.9k
            break;
791
28.9k
        }
792
793
136k
        ps_cur_mb_info = ps_dec->ps_nmb_info + u4_num_mbs;
794
136k
        ps_dec->u4_num_mbs_cur_nmb = u4_num_mbs;
795
136k
        ps_dec->u4_num_pmbair = (u4_num_mbs >> u1_mbaff);
796
797
136k
        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
136k
        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
136k
        ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + u4_num_mbs;
809
810
136k
        if(ps_dec->u4_app_disable_deblk_frm == 0)
811
136k
            ih264d_set_deblocking_parameters(ps_cur_deblk_mb, ps_slice,
812
136k
                                             ps_dec->u1_mb_ngbr_availablity,
813
136k
                                             ps_dec->u1_cur_mb_fld_dec_flag);
814
815
136k
        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
136k
        {
822
136k
            UWORD32 u4_bitstream_offset = *pu4_bitstrm_ofst;
823
136k
            UWORD32 u4_word, u4_ldz, u4_temp;
824
825
            /***************************************************************/
826
            /* Find leading zeros in next 32 bits                          */
827
            /***************************************************************/
828
136k
            NEXTBITS_32(u4_word, u4_bitstream_offset, pu4_bitstrm_buf);
829
136k
            u4_ldz = CLZ(u4_word);
830
            /* Flush the ps_bitstrm */
831
136k
            u4_bitstream_offset += (u4_ldz + 1);
832
            /* Read the suffix from the ps_bitstrm */
833
136k
            u4_word = 0;
834
136k
            if(u4_ldz)
835
102k
                GETBITS(u4_word, u4_bitstream_offset, pu4_bitstrm_buf,
836
136k
                        u4_ldz);
837
136k
            *pu4_bitstrm_ofst = u4_bitstream_offset;
838
136k
            u4_temp = ((1 << u4_ldz) + u4_word - 1);
839
136k
            if(u4_temp > 25)
840
130
                return ERROR_MB_TYPE;
841
136k
            u1_mb_type = u4_temp;
842
843
136k
        }
844
//Inlined ih264d_uev
845
0
        ps_cur_mb_info->u1_mb_type = u1_mb_type;
846
136k
        COPYTHECONTEXT("u1_mb_type", u1_mb_type);
847
848
        /**************************************************************/
849
        /* Parse Macroblock data                                      */
850
        /**************************************************************/
851
136k
        if(25 == u1_mb_type)
852
2.85k
        {
853
            /* I_PCM_MB */
854
2.85k
            ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB;
855
2.85k
            ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u4_num_mbs);
856
2.85k
            if(ret != OK)
857
0
                return ret;
858
2.85k
            ps_cur_deblk_mb->u1_mb_qp = 0;
859
2.85k
        }
860
133k
        else
861
133k
        {
862
133k
            ret = ih264d_parse_imb_cavlc(ps_dec, ps_cur_mb_info, u4_num_mbs, u1_mb_type);
863
133k
            if(ret != OK)
864
2.64k
                return ret;
865
131k
            ps_cur_deblk_mb->u1_mb_qp = ps_dec->u1_qp;
866
131k
        }
867
868
134k
        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
134k
        uc_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
875
876
134k
        if(u1_mbaff)
877
4.10k
        {
878
4.10k
            ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
879
4.10k
            if(!uc_more_data_flag && (0 == (i4_cur_mb_addr & 1)))
880
1
            {
881
1
                return ERROR_EOB_FLUSHBITS_T;
882
1
            }
883
4.10k
        }
884
        /**************************************************************/
885
        /* Get next Macroblock address                                */
886
        /**************************************************************/
887
888
134k
        i4_cur_mb_addr++;
889
890
891
        /* Store the colocated information */
892
134k
        {
893
134k
            mv_pred_t *ps_mv_nmb_start = ps_dec->ps_mv_cur + (u4_num_mbs << 4);
894
895
134k
            mv_pred_t s_mvPred =
896
134k
                {
897
134k
                    { 0, 0, 0, 0 },
898
134k
                      { -1, -1 }, 0, 0};
899
134k
            ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
900
134k
                               (UWORD8)(ps_dec->u1_cur_mb_fld_dec_flag << 1), 4,
901
134k
                               4);
902
134k
        }
903
904
        /*if num _cores is set to 3,compute bs will be done in another thread*/
905
134k
        if(ps_dec->u4_num_cores < 3)
906
92.8k
        {
907
92.8k
            if(ps_dec->u4_app_disable_deblk_frm == 0)
908
92.8k
                ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
909
92.8k
                                     (UWORD16)(u4_num_mbs >> u1_mbaff));
910
92.8k
        }
911
134k
        u4_num_mbs++;
912
913
        /****************************************************************/
914
        /* Check for End Of Row                                         */
915
        /****************************************************************/
916
134k
        u4_num_mbs_next = i2_pic_wdin_mbs - ps_dec->u2_mbx - 1;
917
134k
        u4_end_of_row = (!u4_num_mbs_next) && (!(u1_mbaff && (u4_num_mbs & 0x01)));
918
134k
        u4_tfr_n_mb = (u4_num_mbs == ps_dec->u4_recon_mb_grp) || u4_end_of_row
919
73.6k
                        || (!uc_more_data_flag);
920
134k
        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
134k
        if(u4_tfr_n_mb || (!uc_more_data_flag))
927
61.0k
        {
928
929
61.0k
            if(ps_dec->u1_separate_parse)
930
39.6k
            {
931
39.6k
                ih264d_parse_tfr_nmb(ps_dec, u4_mb_idx, u4_num_mbs,
932
39.6k
                                     u4_num_mbs_next, u4_tfr_n_mb, u4_end_of_row);
933
39.6k
                ps_dec->ps_nmb_info +=  u4_num_mbs;
934
39.6k
            }
935
21.3k
            else
936
21.3k
            {
937
21.3k
                ih264d_decode_recon_tfr_nmb(ps_dec, u4_mb_idx, u4_num_mbs,
938
21.3k
                                            u4_num_mbs_next, u4_tfr_n_mb,
939
21.3k
                                            u4_end_of_row);
940
21.3k
            }
941
61.0k
            ps_dec->u4_total_mbs_coded += u4_num_mbs;
942
61.0k
            if(u4_tfr_n_mb)
943
61.0k
                u4_num_mbs = 0;
944
61.0k
            u4_mb_idx = u4_num_mbs;
945
61.0k
            ps_dec->u4_mb_idx = u4_num_mbs;
946
947
61.0k
        }
948
134k
    }
949
134k
    while(uc_more_data_flag);
950
951
34.3k
    ps_dec->u4_num_mbs_cur_nmb = 0;
952
34.3k
    ps_dec->ps_cur_slice->u4_mbs_in_slice = i4_cur_mb_addr
953
954
34.3k
                        - (u2_first_mb_in_slice << u1_mbaff);
955
956
34.3k
    return ret;
957
37.1k
}
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
11.0k
{
987
11.0k
    UWORD8 uc_more_data_flag;
988
11.0k
    UWORD32 u4_num_mbs, u4_mb_idx;
989
11.0k
    dec_mb_info_t *ps_cur_mb_info;
990
11.0k
    deblk_mb_t *ps_cur_deblk_mb;
991
992
11.0k
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
993
11.0k
    UWORD16 i2_pic_wdin_mbs = ps_dec->u2_frm_wd_in_mbs;
994
11.0k
    WORD32 i4_cur_mb_addr;
995
11.0k
    UWORD8 u1_mbaff;
996
11.0k
    UWORD32 u4_num_mbs_next, u4_end_of_row, u4_tfr_n_mb;
997
11.0k
    WORD32 ret = OK;
998
999
11.0k
    ps_dec->u1_qp = ps_slice->u1_slice_qp;
1000
11.0k
    ih264d_update_qp(ps_dec, 0);
1001
11.0k
    u1_mbaff = ps_slice->u1_mbaff_frame_flag;
1002
1003
11.0k
    if(ps_bitstrm->u4_ofst & 0x07)
1004
8.62k
    {
1005
8.62k
        ps_bitstrm->u4_ofst += 8;
1006
8.62k
        ps_bitstrm->u4_ofst &= 0xFFFFFFF8;
1007
8.62k
    }
1008
11.0k
    ret = ih264d_init_cabac_dec_envirnoment(&(ps_dec->s_cab_dec_env), ps_bitstrm);
1009
11.0k
    if(ret != OK)
1010
63
        return ret;
1011
11.0k
    ih264d_init_cabac_contexts(I_SLICE, ps_dec);
1012
1013
11.0k
    ps_dec->i1_prev_mb_qp_delta = 0;
1014
1015
    /* initializations */
1016
11.0k
    u4_mb_idx = ps_dec->u4_mb_idx;
1017
11.0k
    u4_num_mbs = u4_mb_idx;
1018
1019
11.0k
    uc_more_data_flag = 1;
1020
11.0k
    i4_cur_mb_addr = u2_first_mb_in_slice << u1_mbaff;
1021
11.0k
    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.35k
        {
1029
6.35k
            break;
1030
6.35k
        }
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
475
            {
1078
                /* I_PCM_MB */
1079
475
                ps_cur_mb_info->ps_curmb->u1_mb_type = I_PCM_MB;
1080
475
                ret = ih264d_parse_ipcm_mb(ps_dec, ps_cur_mb_info, u4_num_mbs);
1081
475
                if(ret != OK)
1082
99
                    return ret;
1083
376
                ps_cur_deblk_mb->u1_mb_qp = 0;
1084
376
            }
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
1.82k
                    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
7.95k
            {
1101
7.95k
                ih264d_update_mbaff_left_nnz(ps_dec, ps_cur_mb_info);
1102
7.95k
            }
1103
1104
1105
1.18M
            if(ps_cur_mb_info->u1_topmb && u1_mbaff)
1106
4.00k
                uc_more_data_flag = 1;
1107
1.17M
            else
1108
1.17M
            {
1109
1.17M
                uc_more_data_flag = ih264d_decode_terminate(&ps_dec->s_cab_dec_env,
1110
1.17M
                                                          ps_bitstrm);
1111
1.17M
                uc_more_data_flag = !uc_more_data_flag;
1112
1.17M
                COPYTHECONTEXT("Decode Sliceterm",!uc_more_data_flag);
1113
1.17M
            }
1114
1115
1.18M
            if(u1_mbaff)
1116
7.95k
            {
1117
7.95k
                if(!uc_more_data_flag && (0 == (i4_cur_mb_addr & 1)))
1118
0
                {
1119
0
                    return ERROR_EOB_FLUSHBITS_T;
1120
0
                }
1121
7.95k
            }
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
914k
            {
1140
914k
                if(ps_dec->u4_app_disable_deblk_frm == 0)
1141
914k
                    ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
1142
914k
                                         (UWORD16)(u4_num_mbs >> u1_mbaff));
1143
914k
            }
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
37.9k
        {
1159
1160
1161
37.9k
            if(ps_dec->u1_separate_parse)
1162
23.2k
            {
1163
23.2k
                ih264d_parse_tfr_nmb(ps_dec, u4_mb_idx, u4_num_mbs,
1164
23.2k
                                     u4_num_mbs_next, u4_tfr_n_mb, u4_end_of_row);
1165
23.2k
                ps_dec->ps_nmb_info +=  u4_num_mbs;
1166
23.2k
            }
1167
14.7k
            else
1168
14.7k
            {
1169
14.7k
                ih264d_decode_recon_tfr_nmb(ps_dec, u4_mb_idx, u4_num_mbs,
1170
14.7k
                                            u4_num_mbs_next, u4_tfr_n_mb,
1171
14.7k
                                            u4_end_of_row);
1172
14.7k
            }
1173
37.9k
            ps_dec->u4_total_mbs_coded += u4_num_mbs;
1174
37.9k
            if(u4_tfr_n_mb)
1175
37.9k
                u4_num_mbs = 0;
1176
37.9k
            u4_mb_idx = u4_num_mbs;
1177
37.9k
            ps_dec->u4_mb_idx = u4_num_mbs;
1178
1179
37.9k
        }
1180
1.18M
    }
1181
1.18M
    while(uc_more_data_flag);
1182
1183
9.10k
    ps_dec->u4_num_mbs_cur_nmb = 0;
1184
9.10k
    ps_dec->ps_cur_slice->u4_mbs_in_slice = i4_cur_mb_addr
1185
1186
9.10k
                        - (u2_first_mb_in_slice << u1_mbaff);
1187
1188
9.10k
    return ret;
1189
11.0k
}
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
7.77k
{
1216
7.77k
    dec_bit_stream_t * const ps_bitstrm = ps_dec->ps_bitstrm;
1217
7.77k
    UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
1218
7.77k
    UWORD8 *pu1_y, *pu1_u, *pu1_v;
1219
7.77k
    WORD32 ret;
1220
1221
7.77k
    UWORD32 u4_rec_width_y, u4_rec_width_uv;
1222
7.77k
    UWORD32 u1_num_mb_pair;
1223
7.77k
    UWORD8 u1_x, u1_y;
1224
    /* CHANGED CODE */
1225
7.77k
    tfr_ctxt_t *ps_frame_buf;
1226
7.77k
    UWORD8 u1_mb_field_decoding_flag;
1227
7.77k
    UWORD32 *pu4_buf;
1228
7.77k
    UWORD8 *pu1_buf;
1229
    /* CHANGED CODE */
1230
1231
7.77k
    if(ps_dec->u1_separate_parse)
1232
3.32k
    {
1233
3.32k
        ps_frame_buf = &ps_dec->s_tran_addrecon_parse;
1234
3.32k
    }
1235
4.45k
    else
1236
4.45k
    {
1237
4.45k
        ps_frame_buf = &ps_dec->s_tran_addrecon;
1238
4.45k
    }
1239
    /* align bistream to byte boundary. */
1240
    /* pcm_alignment_zero_bit discarded */
1241
    /* For XX GotoByteBoundary */
1242
7.77k
    if(ps_bitstrm->u4_ofst & 0x07)
1243
4.59k
    {
1244
4.59k
        ps_bitstrm->u4_ofst += 8;
1245
4.59k
        ps_bitstrm->u4_ofst &= 0xFFFFFFF8;
1246
4.59k
    }
1247
1248
    /*  Store left Nnz as 16 for each 4x4 blk */
1249
1250
7.77k
    pu1_buf = ps_dec->pu1_left_nnz_y;
1251
7.77k
    pu4_buf = (UWORD32 *)pu1_buf;
1252
7.77k
    *pu4_buf = 0x10101010;
1253
7.77k
    pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
1254
7.77k
    pu4_buf = (UWORD32 *)pu1_buf;
1255
7.77k
    *pu4_buf = 0x10101010;
1256
7.77k
    pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
1257
7.77k
    pu4_buf = (UWORD32 *)pu1_buf;
1258
7.77k
    *pu4_buf = 0x10101010;
1259
7.77k
    pu1_buf = ps_dec->pu1_left_nnz_uv;
1260
7.77k
    pu4_buf = (UWORD32 *)pu1_buf;
1261
7.77k
    *pu4_buf = 0x10101010;
1262
7.77k
    ps_cur_mb_info->u1_cbp = 0xff;
1263
1264
7.77k
    ps_dec->i1_prev_mb_qp_delta = 0;
1265
    /* Get neighbour MB's */
1266
7.77k
    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
7.77k
    u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
1273
7.77k
    pu1_y = ps_frame_buf->pu1_dest_y + (u1_num_mb_pair << 4);
1274
7.77k
    pu1_u = ps_frame_buf->pu1_dest_u + (u1_num_mb_pair << 4);
1275
7.77k
    pu1_v = pu1_u + 1;
1276
1277
7.77k
    u4_rec_width_y = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag;
1278
7.77k
    u4_rec_width_uv = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag;
1279
    /* CHANGED CODE  */
1280
1281
7.77k
    if(u1_mbaff)
1282
133
    {
1283
133
        UWORD8 u1_top_mb;
1284
1285
133
        u1_top_mb = ps_cur_mb_info->u1_topmb;
1286
1287
133
        if(u1_top_mb == 0)
1288
89
        {
1289
89
            pu1_y += (u1_mb_field_decoding_flag ?
1290
78
                            (u4_rec_width_y >> 1) : (u4_rec_width_y << 4));
1291
89
            pu1_u += (u1_mb_field_decoding_flag ?
1292
78
                            (u4_rec_width_uv) : (u4_rec_width_uv << 4));
1293
89
            pu1_v = pu1_u + 1;
1294
89
        }
1295
133
    }
1296
1297
    /* Read Luma samples */
1298
132k
    for(u1_y = 0; u1_y < 16; u1_y++)
1299
124k
    {
1300
2.11M
        for(u1_x = 0; u1_x < 16; u1_x++)
1301
1.99M
            pu1_y[u1_x] = ih264d_get_bits_h264(ps_bitstrm, 8);
1302
1303
124k
        pu1_y += u4_rec_width_y;
1304
124k
    }
1305
1306
    /* Read Chroma samples */
1307
69.9k
    for(u1_y = 0; u1_y < 8; u1_y++)
1308
62.1k
    {
1309
559k
        for(u1_x = 0; u1_x < 8; u1_x++)
1310
497k
            pu1_u[u1_x * YUV420SP_FACTOR] = ih264d_get_bits_h264(ps_bitstrm, 8);
1311
1312
62.1k
        pu1_u += u4_rec_width_uv;
1313
62.1k
    }
1314
1315
69.9k
    for(u1_y = 0; u1_y < 8; u1_y++)
1316
62.1k
    {
1317
559k
        for(u1_x = 0; u1_x < 8; u1_x++)
1318
497k
            pu1_v[u1_x * YUV420SP_FACTOR] = ih264d_get_bits_h264(ps_bitstrm, 8);
1319
1320
62.1k
        pu1_v += u4_rec_width_uv;
1321
62.1k
    }
1322
1323
7.77k
    if(CABAC == ps_dec->ps_cur_pps->u1_entropy_coding_mode)
1324
2.44k
    {
1325
2.44k
        UWORD32 *pu4_buf;
1326
2.44k
        UWORD8 *pu1_buf;
1327
2.44k
        ctxt_inc_mb_info_t *p_curr_ctxt = ps_dec->ps_curr_ctxt_mb_info;
1328
        /* Re-initialize the cabac decoding engine. */
1329
2.44k
        ret = ih264d_init_cabac_dec_envirnoment(&(ps_dec->s_cab_dec_env), ps_bitstrm);
1330
2.44k
        if(ret != OK)
1331
1.05k
            return ret;
1332
        /* update the cabac contetxs */
1333
1.39k
        p_curr_ctxt->u1_mb_type = CAB_I_PCM;
1334
1.39k
        p_curr_ctxt->u1_cbp = 47;
1335
1.39k
        p_curr_ctxt->u1_intra_chroma_pred_mode = 0;
1336
1.39k
        p_curr_ctxt->u1_transform8x8_ctxt = 0;
1337
1.39k
        ps_cur_mb_info->ps_curmb->u1_tran_form8x8 = 0;
1338
1339
1.39k
        pu1_buf = ps_dec->pu1_left_nnz_y;
1340
1.39k
        pu4_buf = (UWORD32 *)pu1_buf;
1341
1.39k
        *pu4_buf = 0x01010101;
1342
1343
1.39k
        pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_y;
1344
1.39k
        pu4_buf = (UWORD32 *)pu1_buf;
1345
1.39k
        *pu4_buf = 0x01010101;
1346
1347
1.39k
        pu1_buf = ps_cur_mb_info->ps_curmb->pu1_nnz_uv;
1348
1.39k
        pu4_buf = (UWORD32 *)pu1_buf;
1349
1.39k
        *pu4_buf = 0x01010101;
1350
1351
1.39k
        pu1_buf = ps_dec->pu1_left_nnz_uv;
1352
1.39k
        pu4_buf = (UWORD32 *)pu1_buf;
1353
1.39k
        *pu4_buf = 0x01010101;
1354
1355
1.39k
        p_curr_ctxt->u1_yuv_dc_csbp = 0x7;
1356
1.39k
        ps_dec->pu1_left_yuv_dc_csbp[0] = 0x7;
1357
1.39k
        if(ps_dec->ps_cur_slice->u1_slice_type != I_SLICE)
1358
571
        {
1359
1360
571
            MEMSET_16BYTES(&ps_dec->pu1_left_mv_ctxt_inc[0][0], 0);
1361
571
            memset(ps_dec->pi1_left_ref_idx_ctxt_inc, 0, 4);
1362
571
            MEMSET_16BYTES(p_curr_ctxt->u1_mv, 0);
1363
571
            memset(p_curr_ctxt->i1_ref_idx, 0, 4);
1364
1365
571
        }
1366
1.39k
    }
1367
6.72k
    return OK;
1368
7.77k
}
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
48.7k
{
1385
48.7k
    dec_pic_params_t * ps_pps = ps_dec->ps_cur_pps;
1386
48.7k
    dec_slice_params_t * ps_slice = ps_dec->ps_cur_slice;
1387
48.7k
    UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer;
1388
48.7k
    UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst;
1389
48.7k
    UWORD32 u4_temp;
1390
48.7k
    WORD32 i_temp;
1391
48.7k
    WORD64 i8_temp;
1392
48.7k
    WORD32 ret;
1393
1394
    /*--------------------------------------------------------------------*/
1395
    /* Read remaining contents of the slice header                        */
1396
    /*--------------------------------------------------------------------*/
1397
    /* dec_ref_pic_marking function */
1398
    /* G050 */
1399
48.7k
    if(ps_slice->u1_nal_ref_idc != 0)
1400
36.6k
    {
1401
36.6k
        if(!ps_dec->ps_dpb_cmds->u1_dpb_commands_read)
1402
33.9k
        {
1403
33.9k
            i_temp = ih264d_read_mmco_commands(ps_dec);
1404
33.9k
            if (i_temp < 0)
1405
8
            {
1406
8
                return ERROR_DBP_MANAGER_T;
1407
8
            }
1408
33.9k
            ps_dec->u4_bitoffset = i_temp;
1409
33.9k
        }
1410
2.65k
        else
1411
2.65k
            ps_dec->ps_bitstrm->u4_ofst += ps_dec->u4_bitoffset;
1412
36.6k
    }
1413
    /* G050 */
1414
1415
    /* Read slice_qp_delta */
1416
48.7k
    i8_temp = (WORD64)ps_pps->u1_pic_init_qp
1417
48.7k
                        + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1418
48.7k
    if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP))
1419
232
        return ERROR_INV_RANGE_QP_T;
1420
48.4k
    ps_slice->u1_slice_qp = i8_temp;
1421
48.4k
    COPYTHECONTEXT("SH: slice_qp_delta",
1422
48.4k
                    ps_slice->u1_slice_qp - ps_pps->u1_pic_init_qp);
1423
1424
48.4k
    if(ps_pps->u1_deblocking_filter_parameters_present_flag == 1)
1425
9.29k
    {
1426
9.29k
        u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
1427
9.29k
        COPYTHECONTEXT("SH: disable_deblocking_filter_idc", u4_temp);
1428
1429
9.29k
        if(u4_temp > SLICE_BOUNDARY_DBLK_DISABLED)
1430
94
        {
1431
94
            return ERROR_INV_SLICE_HDR_T;
1432
94
        }
1433
9.19k
        ps_slice->u1_disable_dblk_filter_idc = u4_temp;
1434
9.19k
        if(u4_temp != 1)
1435
8.25k
        {
1436
8.25k
            i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
1437
8.25k
                            << 1;
1438
8.25k
            if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
1439
66
            {
1440
66
                return ERROR_INV_SLICE_HDR_T;
1441
66
            }
1442
8.18k
            ps_slice->i1_slice_alpha_c0_offset = i_temp;
1443
8.18k
            COPYTHECONTEXT("SH: slice_alpha_c0_offset_div2",
1444
8.18k
                            ps_slice->i1_slice_alpha_c0_offset >> 1);
1445
1446
8.18k
            i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf)
1447
8.18k
                            << 1;
1448
8.18k
            if((MIN_DBLK_FIL_OFF > i_temp) || (i_temp > MAX_DBLK_FIL_OFF))
1449
76
            {
1450
76
                return ERROR_INV_SLICE_HDR_T;
1451
76
            }
1452
8.11k
            ps_slice->i1_slice_beta_offset = i_temp;
1453
8.11k
            COPYTHECONTEXT("SH: slice_beta_offset_div2",
1454
8.11k
                            ps_slice->i1_slice_beta_offset >> 1);
1455
1456
8.11k
        }
1457
942
        else
1458
942
        {
1459
942
            ps_slice->i1_slice_alpha_c0_offset = 0;
1460
942
            ps_slice->i1_slice_beta_offset = 0;
1461
942
        }
1462
9.19k
    }
1463
39.2k
    else
1464
39.2k
    {
1465
39.2k
        ps_slice->u1_disable_dblk_filter_idc = 0;
1466
39.2k
        ps_slice->i1_slice_alpha_c0_offset = 0;
1467
39.2k
        ps_slice->i1_slice_beta_offset = 0;
1468
39.2k
    }
1469
1470
    /* Initialization to check if number of motion vector per 2 Mbs */
1471
    /* are exceeding the range or not */
1472
48.2k
    ps_dec->u2_mv_2mb[0] = 0;
1473
48.2k
    ps_dec->u2_mv_2mb[1] = 0;
1474
1475
1476
    /*set slice header cone to 2 ,to indicate  correct header*/
1477
48.2k
    ps_dec->u1_slice_header_done = 2;
1478
1479
48.2k
    if(ps_pps->u1_entropy_coding_mode)
1480
11.0k
    {
1481
11.0k
        SWITCHOFFTRACE; SWITCHONTRACECABAC;
1482
11.0k
        if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1483
190
        {
1484
190
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_mbaff;
1485
190
        }
1486
10.9k
        else
1487
10.9k
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cabac_nonmbaff;
1488
1489
11.0k
        ret = ih264d_parse_islice_data_cabac(ps_dec, ps_slice,
1490
11.0k
                                             u2_first_mb_in_slice);
1491
11.0k
        if(ret != OK)
1492
1.98k
            return ret;
1493
9.10k
        SWITCHONTRACE; SWITCHOFFTRACECABAC;
1494
9.10k
    }
1495
37.1k
    else
1496
37.1k
    {
1497
37.1k
        if(ps_dec->ps_cur_slice->u1_mbaff_frame_flag)
1498
186
        {
1499
186
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_mbaff;
1500
186
        }
1501
36.9k
        else
1502
36.9k
            ps_dec->pf_get_mb_info = ih264d_get_mb_info_cavlc_nonmbaff;
1503
37.1k
        ret = ih264d_parse_islice_data_cavlc(ps_dec, ps_slice,
1504
37.1k
                                       u2_first_mb_in_slice);
1505
37.1k
        if(ret != OK)
1506
2.77k
            return ret;
1507
37.1k
    }
1508
1509
43.4k
    return OK;
1510
48.2k
}