Coverage Report

Created: 2026-05-30 06:23

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