Coverage Report

Created: 2025-11-24 06:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/decoder/ih264d_process_pslice.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
 * \file ih264d_process_pslice.c
23
 *
24
 * \brief
25
 *    Contains routines that decode a I slice type
26
 *
27
 * Detailed_description
28
 *
29
 * \date
30
 *    21/12/2002
31
 *
32
 * \author  NS
33
 **************************************************************************
34
 */
35
#include "ih264_typedefs.h"
36
#include "ih264_macros.h"
37
#include "ih264_platform_macros.h"
38
39
#include <string.h>
40
#include "ih264d_bitstrm.h"
41
#include "ih264d_defs.h"
42
#include "ih264d_debug.h"
43
#include "ih264d_structs.h"
44
#include "ih264d_defs.h"
45
#include "ih264d_parse_cavlc.h"
46
#include "ih264d_mb_utils.h"
47
#include "ih264d_deblocking.h"
48
#include "ih264d_dpb_manager.h"
49
#include "ih264d_mvpred.h"
50
#include "ih264d_inter_pred.h"
51
#include "ih264d_process_pslice.h"
52
#include "ih264d_error_handler.h"
53
#include "ih264d_cabac.h"
54
#include "ih264d_debug.h"
55
#include "ih264d_tables.h"
56
#include "ih264d_parse_slice.h"
57
#include "ih264d_utils.h"
58
#include "ih264d_parse_islice.h"
59
#include "ih264d_process_bslice.h"
60
#include "ih264d_process_intra_mb.h"
61
62
void ih264d_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t * ps_dec);
63
64
void ih264d_insert_pic_in_ref_pic_listx(struct pic_buffer_t *ps_ref_pic_buf_lx,
65
                                        struct pic_buffer_t *ps_pic)
66
198k
{
67
198k
    *ps_ref_pic_buf_lx = *ps_pic;
68
198k
}
69
70
WORD32 ih264d_mv_pred_ref_tfr_nby2_pmb(dec_struct_t * ps_dec,
71
                                     UWORD32 u4_mb_idx,
72
                                     UWORD32 u4_num_mbs)
73
1.31M
{
74
1.31M
    parse_pmbarams_t * ps_mb_part_info;
75
1.31M
    parse_part_params_t * ps_part;
76
1.31M
    mv_pred_t *ps_mv_nmb, *ps_mv_nmb_start, *ps_mv_ntop, *ps_mv_ntop_start;
77
1.31M
    UWORD32 i, j;
78
1.31M
    const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
79
1.31M
    dec_mb_info_t * ps_cur_mb_info;
80
1.31M
    WORD32 i2_mv_x, i2_mv_y;
81
1.31M
    WORD32 ret;
82
83
1.31M
    ps_dec->i4_submb_ofst -= (WORD32)(u4_num_mbs - u4_mb_idx) << 4;
84
1.31M
    ps_mb_part_info = ps_dec->ps_parse_mb_data; // + u4_mb_idx;
85
1.31M
    ps_part = ps_dec->ps_parse_part_params; // + u4_mb_idx;
86
87
    /* N/2 Mb MvPred and Transfer Setup Loop */
88
23.4M
    for(i = u4_mb_idx; i < u4_num_mbs; i++, ps_mb_part_info++)
89
22.1M
    {
90
22.1M
        UWORD32 u1_colz;
91
22.1M
        UWORD32 u1_field;
92
22.1M
        mv_pred_t s_mvPred;
93
22.1M
        mv_pred_t *ps_mv_pred = &s_mvPred;
94
95
96
97
22.1M
        *ps_mv_pred = ps_dec->s_default_mv_pred;
98
99
22.1M
        ps_dec->i4_submb_ofst += SUB_BLK_SIZE;
100
101
        /* Restore the slice scratch MbX and MbY context */
102
22.1M
        ps_cur_mb_info = ps_dec->ps_nmb_info + i;
103
22.1M
        u1_field = ps_cur_mb_info->u1_mb_field_decodingflag;
104
105
106
107
22.1M
        ps_mv_nmb_start = ps_dec->ps_mv_cur + (i << 4);
108
22.1M
        ps_dec->u2_mbx = ps_cur_mb_info->u2_mbx;
109
22.1M
        ps_dec->u2_mby = ps_cur_mb_info->u2_mby;
110
22.1M
        ps_dec->u2_mv_2mb[i & 0x1] = 0;
111
112
        /* Look for MV Prediction and Reference Transfer in Non-I Mbs */
113
22.1M
        if(!ps_mb_part_info->u4_isI_mb)
114
22.1M
        {
115
22.1M
            UWORD32 u1_blk_no;
116
22.1M
            WORD32 i1_ref_idx, i1_ref_idx1;
117
22.1M
            UWORD32 u1_sub_mb_x, u1_sub_mb_y, u1_sub_mb_num;
118
22.1M
            UWORD32 u1_num_part, u1_num_ref, u1_wd, u1_ht;
119
22.1M
            UWORD32 *pu4_wt_offst, **ppu4_wt_ofst;
120
22.1M
            UWORD32 u1_scale_ref, u4_bot_mb;
121
22.1M
            WORD8 *pi1_ref_idx = ps_mb_part_info->i1_ref_idx[0];
122
22.1M
            pic_buffer_t *ps_ref_frame, **pps_ref_frame;
123
22.1M
            deblk_mb_t * ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + i;
124
125
            /* MB Level initialisations */
126
22.1M
            ps_dec->u4_num_pmbair = i >> u1_mbaff;
127
22.1M
            ps_dec->u4_mb_idx_mv = i;
128
22.1M
            ppu4_wt_ofst = ps_mb_part_info->pu4_wt_offst;
129
22.1M
            pps_ref_frame = ps_dec->ps_ref_pic_buf_lx[0];
130
            /* CHANGED CODE */
131
22.1M
            ps_mv_ntop_start = ps_mv_nmb_start
132
22.1M
                            - (ps_dec->u2_frm_wd_in_mbs << (4 + u1_mbaff)) + 12;
133
134
22.1M
            u1_num_part = ps_mb_part_info->u1_num_part;
135
22.1M
            ps_cur_deblk_mb->u1_mb_type |= (u1_num_part > 1) << 1;
136
22.1M
            ps_cur_mb_info->u4_pred_info_pkd_idx = ps_dec->u4_pred_info_pkd_idx;
137
22.1M
            ps_cur_mb_info->u1_num_pred_parts = 0;
138
139
140
            /****************************************************/
141
            /* weighted u4_ofst pointer calculations, this loop  */
142
            /* runs maximum 4 times, even in direct cases       */
143
            /****************************************************/
144
22.1M
            u1_scale_ref = u1_mbaff & u1_field;
145
146
22.1M
            u4_bot_mb = 1 - ps_cur_mb_info->u1_topmb;
147
22.1M
            if(ps_dec->ps_cur_pps->u1_wted_pred_flag)
148
13.3M
            {
149
13.3M
                u1_num_ref = MIN(u1_num_part, 4);
150
26.8M
                for(u1_blk_no = 0; u1_blk_no < u1_num_ref; u1_blk_no++)
151
13.4M
                {
152
13.4M
                    i1_ref_idx = pi1_ref_idx[u1_blk_no];
153
13.4M
                    if(u1_scale_ref)
154
2.43k
                        i1_ref_idx >>= 1;
155
13.4M
                    pu4_wt_offst = (UWORD32*)&ps_dec->pu4_wt_ofsts[2
156
13.4M
                                    * X3(i1_ref_idx)];
157
13.4M
                    ppu4_wt_ofst[u1_blk_no] = pu4_wt_offst;
158
13.4M
                }
159
13.3M
            }
160
8.75M
            else
161
8.75M
            {
162
8.75M
                ppu4_wt_ofst[0] = NULL;
163
8.75M
                ppu4_wt_ofst[1] = NULL;
164
8.75M
                ppu4_wt_ofst[2] = NULL;
165
8.75M
                ppu4_wt_ofst[3] = NULL;
166
8.75M
            }
167
168
            /**************************************************/
169
            /* Loop on Partitions                             */
170
            /**************************************************/
171
44.5M
            for(j = 0; j < u1_num_part; j++, ps_part++)
172
22.4M
            {
173
174
22.4M
                u1_sub_mb_num = ps_part->u1_sub_mb_num;
175
22.4M
                ps_dec->u1_sub_mb_num = u1_sub_mb_num;
176
177
22.4M
                if(PART_NOT_DIRECT != ps_part->u1_is_direct)
178
21.8M
                {
179
                    /* Mb Skip Mode */
180
                    /* Setting the default and other members of MvPred Structure */
181
21.8M
                    s_mvPred.i2_mv[2] = -1;
182
21.8M
                    s_mvPred.i2_mv[3] = -1;
183
21.8M
                    s_mvPred.i1_ref_frame[0] = 0;
184
21.8M
                    i1_ref_idx = (u1_scale_ref && u4_bot_mb) ? MAX_REF_BUFS : 0;
185
21.8M
                    ps_ref_frame = pps_ref_frame[i1_ref_idx];
186
21.8M
                    s_mvPred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id;
187
21.8M
                    s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
188
21.8M
                    pu4_wt_offst = (UWORD32*)&ps_dec->pu4_wt_ofsts[0];
189
190
21.8M
                    ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb_start,
191
21.8M
                                      ps_mv_ntop_start, &s_mvPred, 0, 4, 0, 1,
192
21.8M
                                      MB_SKIP);
193
194
195
196
197
198
199
21.8M
                    {
200
21.8M
                        pred_info_pkd_t *ps_pred_pkd;
201
21.8M
                        ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
202
21.8M
                    ih264d_fill_pred_info (s_mvPred.i2_mv,4,4,0,PRED_L0,ps_pred_pkd,ps_ref_frame->u1_pic_buf_id,
203
21.8M
                                           (i1_ref_idx >> u1_scale_ref),pu4_wt_offst,
204
21.8M
                                           ps_ref_frame->u1_pic_type);
205
206
207
21.8M
                    ps_dec->u4_pred_info_pkd_idx++;
208
21.8M
                    ps_cur_mb_info->u1_num_pred_parts++;
209
21.8M
                    }
210
211
212
213
                    /* Storing colocated zero information */
214
21.8M
                    u1_colz = ((ABS(s_mvPred.i2_mv[0]) <= 1)
215
21.7M
                                    && (ABS(s_mvPred.i2_mv[1]) <= 1))
216
21.8M
                                    + (u1_field << 1);
217
218
21.8M
                    ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
219
21.8M
                                       u1_colz, 4, 4);
220
21.8M
                }
221
677k
                else
222
677k
                {
223
677k
                    u1_sub_mb_x = u1_sub_mb_num & 0x03;
224
677k
                    u1_sub_mb_y = u1_sub_mb_num >> 2;
225
677k
                    u1_blk_no =
226
677k
                                    (u1_num_part < 4) ?
227
379k
                                                    j :
228
677k
                                                    (((u1_sub_mb_y >> 1) << 1)
229
297k
                                                                    + (u1_sub_mb_x
230
297k
                                                                                    >> 1));
231
232
677k
                    ps_mv_ntop = ps_mv_ntop_start + u1_sub_mb_x;
233
677k
                    ps_mv_nmb = ps_mv_nmb_start + u1_sub_mb_num;
234
235
677k
                    u1_wd = ps_part->u1_partwidth;
236
677k
                    u1_ht = ps_part->u1_partheight;
237
238
                    /* Populate the colpic info and reference frames */
239
677k
                    i1_ref_idx = pi1_ref_idx[u1_blk_no];
240
677k
                    s_mvPred.i1_ref_frame[0] = i1_ref_idx;
241
242
                    /********************************************************/
243
                    /* Predict Mv                                           */
244
                    /* Add Mv Residuals and store back                      */
245
                    /********************************************************/
246
677k
                    ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb, ps_mv_ntop,
247
677k
                                      &s_mvPred, u1_sub_mb_num, u1_wd, 0, 1,
248
677k
                                      ps_cur_mb_info->u1_mb_mc_mode);
249
677k
                    i2_mv_x = ps_mv_nmb->i2_mv[0];
250
677k
                    i2_mv_y = ps_mv_nmb->i2_mv[1];
251
677k
                    i2_mv_x += s_mvPred.i2_mv[0];
252
677k
                    i2_mv_y += s_mvPred.i2_mv[1];
253
677k
                    s_mvPred.i2_mv[0] = i2_mv_x;
254
677k
                    s_mvPred.i2_mv[1] = i2_mv_y;
255
256
                    /********************************************************/
257
                    /* Transfer setup call                                  */
258
                    /* convert RefIdx if it is MbAff                        */
259
                    /* Pass Weight Offset and refFrame                      */
260
                    /********************************************************/
261
677k
                    i1_ref_idx1 = i1_ref_idx >> u1_scale_ref;
262
677k
                    if(u1_scale_ref && ((i1_ref_idx & 0x01) != u4_bot_mb))
263
18.3k
                        i1_ref_idx1 += MAX_REF_BUFS;
264
677k
                    ps_ref_frame = pps_ref_frame[i1_ref_idx1];
265
677k
                    pu4_wt_offst = ppu4_wt_ofst[u1_blk_no];
266
267
268
269
270
271
272
677k
                    {
273
677k
                    pred_info_pkd_t *ps_pred_pkd;
274
677k
                    ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
275
677k
                    ih264d_fill_pred_info (s_mvPred.i2_mv,u1_wd,u1_ht,u1_sub_mb_num,PRED_L0,ps_pred_pkd,
276
677k
                                           ps_ref_frame->u1_pic_buf_id,(i1_ref_idx >> u1_scale_ref),pu4_wt_offst,
277
677k
                                           ps_ref_frame->u1_pic_type);
278
279
677k
                    ps_dec->u4_pred_info_pkd_idx++;
280
677k
                    ps_cur_mb_info->u1_num_pred_parts++;
281
677k
                    }
282
283
284
285
                    /* Fill colocated info in MvPred structure */
286
677k
                    s_mvPred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id;
287
677k
                    s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
288
289
                    /* Calculating colocated zero information */
290
677k
                    u1_colz =
291
677k
                                    (u1_field << 1)
292
677k
                                                    | ((i1_ref_idx == 0)
293
476k
                                                                    && (ABS(i2_mv_x)
294
476k
                                                                                    <= 1)
295
223k
                                                                    && (ABS(i2_mv_y)
296
223k
                                                                                    <= 1));
297
677k
                    u1_colz |= ps_mb_part_info->u1_col_info[u1_blk_no];
298
299
                    /* Replicate the motion vectors and colzero u4_flag  */
300
                    /* for all sub-partitions                         */
301
302
677k
                    ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb,
303
677k
                                       u1_sub_mb_num, u1_colz, u1_ht,
304
677k
                                       u1_wd);
305
677k
                }
306
22.4M
            }
307
308
22.1M
        }
309
73.5k
        else
310
73.5k
        {
311
            /* Storing colocated zero information */
312
73.5k
            ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
313
73.5k
                               (UWORD8)(u1_field << 1), 4, 4);
314
315
73.5k
        }
316
        /*if num _cores is set to 3,compute bs will be done in another thread*/
317
22.1M
        if(ps_dec->u4_num_cores < 3)
318
12.7M
        {
319
320
12.7M
            if(ps_dec->u4_app_disable_deblk_frm == 0)
321
12.7M
                ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
322
12.7M
                                     (UWORD16)(i >> u1_mbaff));
323
12.7M
        }
324
22.1M
    }
325
326
327
328
1.31M
    return OK;
329
1.31M
}
330
331
332
WORD32 ih264d_decode_recon_tfr_nmb(dec_struct_t * ps_dec,
333
                                   UWORD32 u4_mb_idx,
334
                                   UWORD32 u4_num_mbs,
335
                                   UWORD32 u4_num_mbs_next,
336
                                   UWORD32 u4_tfr_n_mb,
337
                                   UWORD32 u4_end_of_row)
338
1.24M
{
339
1.24M
    WORD32 i,j;
340
1.24M
    UWORD32 u1_end_of_row_next;
341
1.24M
    dec_mb_info_t * ps_cur_mb_info;
342
1.24M
    UWORD32 u4_update_mbaff = 0;
343
1.24M
    WORD32 ret;
344
1.24M
    const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
345
1.24M
    const UWORD32 u1_slice_type = ps_dec->ps_cur_slice->u1_slice_type;
346
1.24M
    const WORD32 u1_skip_th = (
347
1.24M
                    (u1_slice_type != I_SLICE) ?
348
1.20M
                                    (ps_dec->u1_B ? B_8x8 : PRED_8x8R0) : -1);
349
1.24M
    const UWORD32 u1_ipcm_th = (
350
1.24M
                    (u1_slice_type != I_SLICE) ? (ps_dec->u1_B ? 23 : 5) : 0);
351
352
353
354
355
356
    /* N Mb MC Loop */
357
12.8M
    for(i = u4_mb_idx; i < u4_num_mbs; i++)
358
11.6M
    {
359
11.6M
        ps_cur_mb_info = ps_dec->ps_nmb_info + i;
360
11.6M
        ps_dec->u4_dma_buf_idx = 0;
361
11.6M
        ps_dec->u4_pred_info_idx = 0;
362
363
11.6M
        if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
364
246k
        {
365
246k
            {
366
246k
                WORD32 pred_cnt = 0;
367
246k
                pred_info_pkd_t *ps_pred_pkd;
368
246k
                UWORD32 u4_pred_info_pkd_idx;
369
246k
                WORD8 i1_pred;
370
371
246k
                u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
372
373
903k
                while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
374
657k
                {
375
376
657k
                    ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
377
378
657k
                     ps_dec->p_form_mb_part_info(ps_pred_pkd,ps_dec,
379
657k
                                               ps_cur_mb_info->u2_mbx,ps_cur_mb_info->u2_mby,(i >> u1_mbaff),
380
657k
                                         ps_cur_mb_info);
381
657k
                    u4_pred_info_pkd_idx++;
382
657k
                    pred_cnt++;
383
657k
                }
384
246k
            }
385
386
246k
            ps_dec->p_motion_compensate(ps_dec, ps_cur_mb_info);
387
388
246k
        }
389
11.3M
        else if(ps_cur_mb_info->u1_mb_type == MB_SKIP)
390
10.5M
        {
391
10.5M
            {
392
10.5M
                WORD32 pred_cnt = 0;
393
10.5M
                pred_info_pkd_t *ps_pred_pkd;
394
10.5M
                UWORD32 u4_pred_info_pkd_idx;
395
10.5M
                WORD8 i1_pred;
396
397
10.5M
                u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
398
399
21.6M
                while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
400
11.0M
                {
401
402
11.0M
                    ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
403
404
11.0M
                    ps_dec->p_form_mb_part_info(ps_pred_pkd,ps_dec,
405
11.0M
                                               ps_cur_mb_info->u2_mbx,ps_cur_mb_info->u2_mby,(i >> u1_mbaff),
406
11.0M
                                         ps_cur_mb_info);
407
408
11.0M
                    u4_pred_info_pkd_idx++;
409
11.0M
                    pred_cnt++;
410
11.0M
                }
411
10.5M
            }
412
            /* Decode MB skip */
413
10.5M
            ps_dec->p_motion_compensate(ps_dec, ps_cur_mb_info);
414
415
10.5M
        }
416
417
11.6M
     }
418
419
420
    /* N Mb IQ IT RECON  Loop */
421
12.8M
    for(j = u4_mb_idx; j < i; j++)
422
11.6M
    {
423
11.6M
        ps_cur_mb_info = ps_dec->ps_nmb_info + j;
424
425
11.6M
        if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
426
246k
        {
427
246k
            ih264d_process_inter_mb(ps_dec, ps_cur_mb_info, j);
428
429
246k
        }
430
11.3M
        else if(ps_cur_mb_info->u1_mb_type != MB_SKIP)
431
827k
        {
432
827k
            if((u1_ipcm_th + 25) != ps_cur_mb_info->u1_mb_type)
433
824k
            {
434
824k
                ps_cur_mb_info->u1_mb_type -= (u1_skip_th + 1);
435
824k
                ih264d_process_intra_mb(ps_dec, ps_cur_mb_info, j);
436
824k
            }
437
827k
        }
438
439
440
11.6M
        if(ps_dec->u4_use_intrapred_line_copy)
441
10.2M
        {
442
10.2M
            ih264d_copy_intra_pred_line(ps_dec, ps_cur_mb_info, j);
443
10.2M
        }
444
445
11.6M
    }
446
447
    /*N MB deblocking*/
448
1.24M
    if(ps_dec->u4_nmb_deblk == 1)
449
1.20M
    {
450
451
1.20M
        UWORD32 u4_cur_mb, u4_right_mb;
452
1.20M
        UWORD32 u4_mb_x, u4_mb_y;
453
1.20M
        UWORD32 u4_wd_y, u4_wd_uv;
454
1.20M
        tfr_ctxt_t *ps_tfr_cxt = &(ps_dec->s_tran_addrecon);
455
1.20M
        UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
456
1.20M
        const WORD32 i4_cb_qp_idx_ofst =
457
1.20M
                       ps_dec->ps_cur_pps->i1_chroma_qp_index_offset;
458
1.20M
        const WORD32 i4_cr_qp_idx_ofst =
459
1.20M
                       ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset;
460
461
1.20M
        u4_wd_y = ps_dec->u2_frm_wd_y << u1_field_pic_flag;
462
1.20M
        u4_wd_uv = ps_dec->u2_frm_wd_uv << u1_field_pic_flag;
463
464
465
1.20M
        ps_cur_mb_info = ps_dec->ps_nmb_info + u4_mb_idx;
466
467
1.20M
        ps_dec->u4_deblk_mb_x = ps_cur_mb_info->u2_mbx;
468
1.20M
        ps_dec->u4_deblk_mb_y = ps_cur_mb_info->u2_mby;
469
470
11.4M
        for(j = u4_mb_idx; j < i; j++)
471
10.2M
        {
472
473
10.2M
            ih264d_deblock_mb_nonmbaff(ps_dec, ps_tfr_cxt,
474
10.2M
                                       i4_cb_qp_idx_ofst, i4_cr_qp_idx_ofst,
475
10.2M
                                        u4_wd_y, u4_wd_uv);
476
477
478
10.2M
        }
479
480
481
482
1.20M
    }
483
484
485
486
1.24M
    if(u4_tfr_n_mb)
487
1.24M
    {
488
        /****************************************************************/
489
        /* Check for End Of Row in Next iteration                       */
490
        /****************************************************************/
491
1.24M
        u1_end_of_row_next =
492
1.24M
                        u4_num_mbs_next
493
13.3k
                                        && (u4_num_mbs_next
494
13.3k
                                                        <= (ps_dec->u4_recon_mb_grp
495
13.3k
                                                                        >> u1_mbaff));
496
497
        /****************************************************************/
498
        /* Transfer the Following things                                */
499
        /* N-Mb DeblkParams Data    ( To Ext DeblkParams Buffer )       */
500
        /* N-Mb Recon Data          ( To Ext Frame Buffer )             */
501
        /* N-Mb Intrapredline Data  ( Updated Internally)               */
502
        /* N-Mb MV Data             ( To Ext MV Buffer )                */
503
        /* N-Mb MVTop/TopRight Data ( To Int MV Top Scratch Buffers)    */
504
        /****************************************************************/
505
1.24M
        ih264d_transfer_mb_group_data(ps_dec, u4_num_mbs, u4_end_of_row,
506
1.24M
                                      u1_end_of_row_next);
507
1.24M
        ps_dec->u4_num_mbs_prev_nmb = u4_num_mbs;
508
509
1.24M
        ps_dec->u4_pred_info_idx = 0;
510
1.24M
        ps_dec->u4_dma_buf_idx = 0;
511
512
513
1.24M
    }
514
1.24M
    return OK;
515
1.24M
}
516
517
/*!
518
 **************************************************************************
519
 * \if Function name : ih264d_process_inter_mb \endif
520
 *
521
 * \brief
522
 *    This function decodes an Inter MB.
523
 *
524
 *
525
 * \return
526
 *    0 on Success and Error code otherwise
527
 **************************************************************************
528
 */
529
WORD32 ih264d_process_inter_mb(dec_struct_t * ps_dec,
530
                               dec_mb_info_t * ps_cur_mb_info,
531
                               UWORD32 u4_mb_num)
532
719k
{
533
    /* CHANGED CODE */
534
719k
    UWORD8 *pu1_rec_y, *pu1_rec_u, *pu1_rec_v;
535
536
    /*CHANGED CODE */
537
719k
    UWORD32 ui_rec_width, u4_recwidth_cr;
538
719k
    WORD16 *pi2_y_coeff;
539
719k
    UWORD32 u1_mb_field_decoding_flag;
540
719k
    const UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
541
719k
    UWORD32 uc_botMb;
542
719k
    UWORD32 u4_num_pmbair;
543
    /* CHANGED CODE */
544
719k
    tfr_ctxt_t *ps_frame_buf = ps_dec->ps_frame_buf_ip_recon;
545
719k
    UWORD32 u4_luma_dc_only_csbp = 0;
546
719k
    UWORD32 u4_luma_dc_only_cbp = 0;
547
    /* CHANGED CODE */
548
549
719k
    uc_botMb = 1 - ps_cur_mb_info->u1_topmb;
550
719k
    u4_num_pmbair = (u4_mb_num >> u1_mbaff);
551
719k
    u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
552
553
554
    /* CHANGED CODE */
555
719k
    pu1_rec_y = ps_frame_buf->pu1_dest_y + (u4_num_pmbair << 4);
556
719k
    pu1_rec_u =
557
719k
                    ps_frame_buf->pu1_dest_u
558
719k
                                    + (u4_num_pmbair << 3) * YUV420SP_FACTOR;
559
719k
    pu1_rec_v = ps_frame_buf->pu1_dest_v + (u4_num_pmbair << 3);
560
719k
    ui_rec_width = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag;
561
719k
    u4_recwidth_cr = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag;
562
563
    /* CHANGED CODE */
564
565
719k
    if(u1_mbaff)
566
60.4k
    {
567
60.4k
        if(uc_botMb)
568
29.2k
        {
569
29.2k
            pu1_rec_y += (u1_mb_field_decoding_flag ?
570
15.4k
                            (ui_rec_width >> 1) : (ui_rec_width << 4));
571
29.2k
            pu1_rec_u += (u1_mb_field_decoding_flag ?
572
15.4k
                            (u4_recwidth_cr >> 1) : (u4_recwidth_cr << 3));
573
29.2k
            pu1_rec_v += (u1_mb_field_decoding_flag ?
574
15.4k
                            (u4_recwidth_cr >> 1) : (u4_recwidth_cr << 3));
575
29.2k
        }
576
60.4k
    }
577
578
719k
    if(!ps_cur_mb_info->u1_tran_form8x8)
579
687k
    {
580
687k
        u4_luma_dc_only_csbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
581
687k
                                       ps_cur_mb_info,
582
687k
                                       0);
583
687k
    }
584
32.6k
    else
585
32.6k
    {
586
32.6k
        if(!ps_dec->ps_cur_pps->u1_entropy_coding_mode)
587
7.61k
        {
588
7.61k
            u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
589
7.61k
                                           ps_cur_mb_info,
590
7.61k
                                           0);
591
7.61k
        }
592
25.0k
        else
593
25.0k
        {
594
25.0k
            u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff8x8_mb(ps_dec,
595
25.0k
                                           ps_cur_mb_info);
596
25.0k
        }
597
32.6k
    }
598
599
719k
    pi2_y_coeff = ps_dec->pi2_coeff_data;
600
    /* Inverse Transform and Reconstruction */
601
719k
    if(ps_cur_mb_info->u1_cbp & 0x0f)
602
146k
    {
603
        /* CHANGED CODE */
604
146k
        if(!ps_cur_mb_info->u1_tran_form8x8)
605
113k
        {
606
113k
            UWORD32 i;
607
113k
            WORD16 ai2_tmp[16];
608
1.92M
            for(i = 0; i < 16; i++)
609
1.81M
            {
610
1.81M
                if(CHECKBIT(ps_cur_mb_info->u2_luma_csbp, i))
611
439k
                {
612
439k
                    WORD16 *pi2_level = pi2_y_coeff + (i << 4);
613
439k
                    UWORD8 *pu1_pred_sblk = pu1_rec_y + ((i & 0x3) * BLK_SIZE)
614
439k
                                    + (i >> 2) * (ui_rec_width << 2);
615
439k
                    PROFILE_DISABLE_IQ_IT_RECON()
616
439k
                    {
617
439k
                        if(CHECKBIT(u4_luma_dc_only_csbp, i))
618
63.6k
                        {
619
63.6k
                            ps_dec->pf_iquant_itrans_recon_luma_4x4_dc(
620
63.6k
                                            pi2_level,
621
63.6k
                                            pu1_pred_sblk,
622
63.6k
                                            pu1_pred_sblk,
623
63.6k
                                            ui_rec_width,
624
63.6k
                                            ui_rec_width,
625
63.6k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
626
63.6k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[3],
627
63.6k
                                            ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
628
63.6k
                                            NULL);
629
63.6k
                        }
630
375k
                        else
631
375k
                        {
632
375k
                            ps_dec->pf_iquant_itrans_recon_luma_4x4(
633
375k
                                            pi2_level,
634
375k
                                            pu1_pred_sblk,
635
375k
                                            pu1_pred_sblk,
636
375k
                                            ui_rec_width,
637
375k
                                            ui_rec_width,
638
375k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
639
375k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[3],
640
375k
                                            ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
641
375k
                                            NULL);
642
375k
                        }
643
439k
                    }
644
439k
                }
645
1.81M
            }
646
113k
        }
647
32.6k
        else
648
32.6k
        {
649
32.6k
            WORD16 *pi2_scale_matrix_ptr;
650
32.6k
            WORD32 i;
651
652
32.6k
            pi2_scale_matrix_ptr =
653
32.6k
                            ps_dec->s_high_profile.i2_scalinglist8x8[1];
654
655
163k
            for(i = 0; i < 4; i++)
656
130k
            {
657
130k
                WORD16 ai2_tmp[64];
658
130k
                WORD16 *pi16_levelBlock = pi2_y_coeff + (i << 6); /* move to the next 8x8 adding 64 */
659
660
130k
                UWORD8 *pu1_pred_sblk = pu1_rec_y + ((i & 0x1) * BLK8x8SIZE)
661
130k
                                + (i >> 1) * (ui_rec_width << 3);
662
130k
                if(CHECKBIT(ps_cur_mb_info->u1_cbp, i))
663
66.8k
                {
664
66.8k
                    PROFILE_DISABLE_IQ_IT_RECON()
665
66.8k
                    {
666
66.8k
                        if(CHECKBIT(u4_luma_dc_only_cbp, i))
667
2.51k
                        {
668
2.51k
                            ps_dec->pf_iquant_itrans_recon_luma_8x8_dc(
669
2.51k
                                            pi16_levelBlock,
670
2.51k
                                            pu1_pred_sblk,
671
2.51k
                                            pu1_pred_sblk,
672
2.51k
                                            ui_rec_width,
673
2.51k
                                            ui_rec_width,
674
2.51k
                                            gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
675
2.51k
                                            (UWORD16 *)pi2_scale_matrix_ptr,
676
2.51k
                                            ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
677
2.51k
                                            NULL);
678
2.51k
                        }
679
64.3k
                        else
680
64.3k
                        {
681
64.3k
                            ps_dec->pf_iquant_itrans_recon_luma_8x8(
682
64.3k
                                            pi16_levelBlock,
683
64.3k
                                            pu1_pred_sblk,
684
64.3k
                                            pu1_pred_sblk,
685
64.3k
                                            ui_rec_width,
686
64.3k
                                            ui_rec_width,
687
64.3k
                                            gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
688
64.3k
                                            (UWORD16 *)pi2_scale_matrix_ptr,
689
64.3k
                                            ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
690
64.3k
                                            NULL);
691
64.3k
                        }
692
66.8k
                    }
693
66.8k
                }
694
130k
            }
695
696
32.6k
        }
697
146k
    }
698
699
    /* Decode Chroma Block */
700
719k
    ih264d_unpack_chroma_coeff4x4_mb(ps_dec,
701
719k
                                     ps_cur_mb_info);
702
    /*--------------------------------------------------------------------*/
703
    /* Chroma Blocks decoding                                             */
704
    /*--------------------------------------------------------------------*/
705
719k
    {
706
719k
        UWORD8 u1_chroma_cbp = (UWORD8)(ps_cur_mb_info->u1_cbp >> 4);
707
708
719k
        if(u1_chroma_cbp != CBPC_ALLZERO)
709
80.3k
        {
710
80.3k
            UWORD32 u4_scale_u = ps_cur_mb_info->u1_qpc_div6;
711
80.3k
            UWORD32 u4_scale_v = ps_cur_mb_info->u1_qpcr_div6;
712
80.3k
            UWORD16 u2_chroma_csbp = ps_cur_mb_info->u2_chroma_csbp;
713
714
80.3k
            pi2_y_coeff = ps_dec->pi2_coeff_data;
715
716
80.3k
            {
717
80.3k
                UWORD32 i;
718
80.3k
                WORD16 ai2_tmp[16];
719
401k
                for(i = 0; i < 4; i++)
720
321k
                {
721
321k
                    WORD16 *pi2_level = pi2_y_coeff + (i << 4);
722
321k
                    UWORD8 *pu1_pred_sblk = pu1_rec_u
723
321k
                                    + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
724
321k
                                    + (i >> 1) * (u4_recwidth_cr << 2);
725
321k
                    PROFILE_DISABLE_IQ_IT_RECON()
726
321k
                    {
727
321k
                        if(CHECKBIT(u2_chroma_csbp, i))
728
21.8k
                        {
729
21.8k
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4(
730
21.8k
                                            pi2_level,
731
21.8k
                                            pu1_pred_sblk,
732
21.8k
                                            pu1_pred_sblk,
733
21.8k
                                            u4_recwidth_cr,
734
21.8k
                                            u4_recwidth_cr,
735
21.8k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
736
21.8k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[4],
737
21.8k
                                            u4_scale_u, ai2_tmp, pi2_level);
738
21.8k
                        }
739
299k
                        else if(pi2_level[0] != 0)
740
143k
                        {
741
143k
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
742
143k
                                            pi2_level,
743
143k
                                            pu1_pred_sblk,
744
143k
                                            pu1_pred_sblk,
745
143k
                                            u4_recwidth_cr,
746
143k
                                            u4_recwidth_cr,
747
143k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
748
143k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[4],
749
143k
                                            u4_scale_u, ai2_tmp, pi2_level);
750
143k
                        }
751
321k
                    }
752
321k
                }
753
80.3k
            }
754
755
80.3k
            pi2_y_coeff += MB_CHROM_SIZE;
756
80.3k
            u2_chroma_csbp >>= 4;
757
758
80.3k
            {
759
80.3k
                UWORD32 i;
760
80.3k
                WORD16 ai2_tmp[16];
761
401k
                for(i = 0; i < 4; i++)
762
321k
                {
763
321k
                    WORD16 *pi2_level = pi2_y_coeff + (i << 4);
764
321k
                    UWORD8 *pu1_pred_sblk = pu1_rec_u + 1
765
321k
                                    + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
766
321k
                                    + (i >> 1) * (u4_recwidth_cr << 2);
767
321k
                    PROFILE_DISABLE_IQ_IT_RECON()
768
321k
                    {
769
321k
                        if(CHECKBIT(u2_chroma_csbp, i))
770
24.9k
                        {
771
24.9k
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4(
772
24.9k
                                            pi2_level,
773
24.9k
                                            pu1_pred_sblk,
774
24.9k
                                            pu1_pred_sblk,
775
24.9k
                                            u4_recwidth_cr,
776
24.9k
                                            u4_recwidth_cr,
777
24.9k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
778
24.9k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[5],
779
24.9k
                                            u4_scale_v, ai2_tmp, pi2_level);
780
24.9k
                        }
781
296k
                        else if(pi2_level[0] != 0)
782
149k
                        {
783
149k
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
784
149k
                                            pi2_level,
785
149k
                                            pu1_pred_sblk,
786
149k
                                            pu1_pred_sblk,
787
149k
                                            u4_recwidth_cr,
788
149k
                                            u4_recwidth_cr,
789
149k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
790
149k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[5],
791
149k
                                            u4_scale_v, ai2_tmp, pi2_level);
792
149k
                        }
793
321k
                    }
794
321k
                }
795
80.3k
            }
796
80.3k
        }
797
719k
    }
798
719k
    return (0);
799
719k
}
800
801
/*!
802
 **************************************************************************
803
 * \if Function name : ih264d_parse_pred_weight_table \endif
804
 *
805
 * \brief
806
 *    Implements pred_weight_table() of 7.3.3.2.
807
 *
808
 * \return
809
 *    None
810
 *
811
 **************************************************************************
812
 */
813
WORD32 ih264d_parse_pred_weight_table(dec_slice_params_t * ps_cur_slice,
814
                                      dec_bit_stream_t * ps_bitstrm)
815
40.5k
{
816
40.5k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
817
40.5k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
818
40.5k
    WORD8 i, cont, lx;
819
40.5k
    UWORD8 uc_weight_flag;
820
40.5k
    UWORD32 *pui32_weight_offset_lx;
821
40.5k
    WORD16 c_weight, c_offset;
822
40.5k
    UWORD32 ui32_y_def_weight_ofst, ui32_cr_def_weight_ofst;
823
40.5k
    UWORD32 ui32_temp;
824
40.5k
    UWORD8 uc_luma_log2_weight_denom;
825
40.5k
    UWORD8 uc_chroma_log2_weight_denom;
826
827
    /* Variables for error resilience checks */
828
40.5k
    UWORD32 u4_temp;
829
40.5k
    WORD32 i_temp;
830
831
40.5k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
832
40.5k
    if(u4_temp > MAX_LOG2_WEIGHT_DENOM)
833
7.00k
    {
834
7.00k
        return ERROR_PRED_WEIGHT_TABLE_T;
835
7.00k
    }
836
33.5k
    uc_luma_log2_weight_denom = u4_temp;
837
33.5k
    COPYTHECONTEXT("SH: luma_log2_weight_denom",uc_luma_log2_weight_denom);
838
33.5k
    ui32_y_def_weight_ofst = (1 << uc_luma_log2_weight_denom);
839
840
33.5k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
841
33.5k
    if(u4_temp > MAX_LOG2_WEIGHT_DENOM)
842
2.11k
    {
843
2.11k
        return ERROR_PRED_WEIGHT_TABLE_T;
844
2.11k
    }
845
31.4k
    uc_chroma_log2_weight_denom = u4_temp;
846
31.4k
    COPYTHECONTEXT("SH: chroma_log2_weight_denom",uc_chroma_log2_weight_denom);
847
31.4k
    ui32_cr_def_weight_ofst = (1 << uc_chroma_log2_weight_denom);
848
849
31.4k
    ps_cur_slice->u2_log2Y_crwd = uc_luma_log2_weight_denom
850
31.4k
                    | (uc_chroma_log2_weight_denom << 8);
851
852
31.4k
    cont = (ps_cur_slice->u1_slice_type == B_SLICE);
853
31.4k
    lx = 0;
854
31.4k
    do
855
34.6k
    {
856
89.1k
        for(i = 0; i < ps_cur_slice->u1_num_ref_idx_lx_active[lx]; i++)
857
56.9k
        {
858
56.9k
            pui32_weight_offset_lx = ps_cur_slice->u4_wt_ofst_lx[lx][i];
859
860
56.9k
            uc_weight_flag = ih264d_get_bit_h264(ps_bitstrm);
861
56.9k
            pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
862
56.9k
            COPYTHECONTEXT("SH: luma_weight_l0_flag",uc_weight_flag);
863
56.9k
            if(uc_weight_flag)
864
26.0k
            {
865
26.0k
                i_temp = ih264d_sev(pu4_bitstrm_ofst,
866
26.0k
                                    pu4_bitstrm_buf);
867
26.0k
                if((i_temp < PRED_WEIGHT_MIN) || (i_temp > PRED_WEIGHT_MAX))
868
355
                    return ERROR_PRED_WEIGHT_TABLE_T;
869
25.6k
                c_weight = i_temp;
870
25.6k
                COPYTHECONTEXT("SH: luma_weight_l0",c_weight);
871
872
25.6k
                i_temp = ih264d_sev(pu4_bitstrm_ofst,
873
25.6k
                                    pu4_bitstrm_buf);
874
25.6k
                if((i_temp < PRED_WEIGHT_MIN) || (i_temp > PRED_WEIGHT_MAX))
875
528
                    return ERROR_PRED_WEIGHT_TABLE_T;
876
25.1k
                c_offset = i_temp;
877
25.1k
                COPYTHECONTEXT("SH: luma_offset_l0",c_offset);
878
879
25.1k
                ui32_temp = (c_offset << 16) | (c_weight & 0xFFFF);
880
25.1k
                pui32_weight_offset_lx[0] = ui32_temp;
881
25.1k
            }
882
30.9k
            else
883
30.9k
            {
884
885
30.9k
                pui32_weight_offset_lx[0] = ui32_y_def_weight_ofst;
886
30.9k
            }
887
888
56.0k
            {
889
56.0k
                WORD8 c_weightCb, c_weightCr, c_offsetCb, c_offsetCr;
890
56.0k
                uc_weight_flag = ih264d_get_bit_h264(ps_bitstrm);
891
56.0k
                pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
892
56.0k
                COPYTHECONTEXT("SH: chroma_weight_l0_flag",uc_weight_flag);
893
56.0k
                if(uc_weight_flag)
894
22.9k
                {
895
22.9k
                    i_temp = ih264d_sev(pu4_bitstrm_ofst,
896
22.9k
                                        pu4_bitstrm_buf);
897
22.9k
                    if((i_temp < PRED_WEIGHT_MIN) || (i_temp > PRED_WEIGHT_MAX))
898
302
                        return ERROR_PRED_WEIGHT_TABLE_T;
899
22.6k
                    c_weightCb = i_temp;
900
22.6k
                    COPYTHECONTEXT("SH: chroma_weight_l0",c_weightCb);
901
902
22.6k
                    i_temp = ih264d_sev(pu4_bitstrm_ofst,
903
22.6k
                                        pu4_bitstrm_buf);
904
22.6k
                    if((i_temp < PRED_WEIGHT_MIN) || (i_temp > PRED_WEIGHT_MAX))
905
394
                        return ERROR_PRED_WEIGHT_TABLE_T;
906
22.2k
                    c_offsetCb = i_temp;
907
22.2k
                    COPYTHECONTEXT("SH: chroma_weight_l0",c_offsetCb);
908
909
22.2k
                    ui32_temp = (c_offsetCb << 16) | (c_weightCb & 0xFFFF);
910
22.2k
                    pui32_weight_offset_lx[1] = ui32_temp;
911
912
22.2k
                    i_temp = ih264d_sev(pu4_bitstrm_ofst,
913
22.2k
                                        pu4_bitstrm_buf);
914
22.2k
                    if((i_temp < PRED_WEIGHT_MIN) || (i_temp > PRED_WEIGHT_MAX))
915
491
                        return ERROR_PRED_WEIGHT_TABLE_T;
916
21.7k
                    c_weightCr = i_temp;
917
21.7k
                    COPYTHECONTEXT("SH: chroma_weight_l0",c_weightCr);
918
919
21.7k
                    i_temp = ih264d_sev(pu4_bitstrm_ofst,
920
21.7k
                                        pu4_bitstrm_buf);
921
21.7k
                    if((i_temp < PRED_WEIGHT_MIN) || (i_temp > PRED_WEIGHT_MAX))
922
404
                        return ERROR_PRED_WEIGHT_TABLE_T;
923
21.3k
                    c_offsetCr = i_temp;
924
21.3k
                    COPYTHECONTEXT("SH: chroma_weight_l0",c_offsetCr);
925
926
21.3k
                    ui32_temp = (c_offsetCr << 16) | (c_weightCr & 0xFFFF);
927
21.3k
                    pui32_weight_offset_lx[2] = ui32_temp;
928
21.3k
                }
929
33.1k
                else
930
33.1k
                {
931
33.1k
                    pui32_weight_offset_lx[1] = ui32_cr_def_weight_ofst;
932
33.1k
                    pui32_weight_offset_lx[2] = ui32_cr_def_weight_ofst;
933
33.1k
                }
934
56.0k
            }
935
56.0k
        }
936
32.1k
        lx++;
937
32.1k
    }
938
32.1k
    while(cont--);
939
940
28.9k
    return OK;
941
31.4k
}
942
943
static int pic_num_compare(const void *pv_pic1, const void *pv_pic2)
944
8.85k
{
945
8.85k
    struct pic_buffer_t *ps_pic1 = *(struct pic_buffer_t **) pv_pic1;
946
8.85k
    struct pic_buffer_t *ps_pic2 = *(struct pic_buffer_t **) pv_pic2;
947
8.85k
    if (ps_pic1->i4_pic_num < ps_pic2->i4_pic_num)
948
2.02k
    {
949
2.02k
        return -1;
950
2.02k
    }
951
6.82k
    else if (ps_pic1->i4_pic_num > ps_pic2->i4_pic_num)
952
4.18k
    {
953
4.18k
        return 1;
954
4.18k
    }
955
2.64k
    else
956
2.64k
    {
957
2.64k
        return 0;
958
2.64k
    }
959
8.85k
}
960
/*****************************************************************************/
961
/*                                                                           */
962
/*  Function Name : ih264d_init_ref_idx_lx_p                                        */
963
/*                                                                           */
964
/*  Description   : This function initializes the reference picture L0 list  */
965
/*                  for P slices as per section 8.2.4.2.1 and 8.2.4.2.2.     */
966
/*                                                                           */
967
/*  Inputs        : pointer to ps_dec struture                               */
968
/*  Globals       : NO                                                       */
969
/*  Processing    : arranges all the short term pictures according to        */
970
/*                  pic_num in descending order starting from curr pic_num.  */
971
/*                  and inserts it in L0 list followed by all Long term      */
972
/*                  pictures in ascending order.                             */
973
/*                                                                           */
974
/*  Returns       : void                                                     */
975
/*                                                                           */
976
/*  Issues        : <List any issues or problems with this function>         */
977
/*                                                                           */
978
/*  Revision History:                                                        */
979
/*                                                                           */
980
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
981
/*         13 07 2002   Jay             Draft                                */
982
/*                                                                           */
983
/*****************************************************************************/
984
void ih264d_init_ref_idx_lx_p(dec_struct_t *ps_dec)
985
82.6k
{
986
82.6k
    struct pic_buffer_t *ps_ref_pic_buf_lx;
987
82.6k
    dpb_manager_t *ps_dpb_mgr;
988
82.6k
    struct dpb_info_t *ps_next_dpb;
989
82.6k
    WORD8 i, j;
990
82.6k
    UWORD8 u1_max_lt_index, u1_min_lt_index;
991
82.6k
    UWORD32 u4_lt_index;
992
82.6k
    UWORD8 u1_field_pic_flag;
993
82.6k
    dec_slice_params_t *ps_cur_slice;
994
82.6k
    UWORD8 u1_L0;
995
82.6k
    WORD32 i4_cur_pic_num, i4_min_st_pic_num;
996
82.6k
    WORD32 i4_temp_pic_num, i4_ref_pic_num;
997
82.6k
    UWORD8 u1_num_short_term_bufs;
998
82.6k
    UWORD8 u1_max_ref_idx_l0;
999
82.6k
    struct pic_buffer_t *aps_st_pic_bufs[2 * MAX_REF_BUFS] = {NULL};
1000
1001
82.6k
    ps_cur_slice = ps_dec->ps_cur_slice;
1002
82.6k
    u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag;
1003
82.6k
    u1_max_ref_idx_l0 = ps_cur_slice->u1_num_ref_idx_lx_active[0]
1004
82.6k
                    << u1_field_pic_flag;
1005
1006
82.6k
    ps_dpb_mgr = ps_dec->ps_dpb_mgr;
1007
    /* Get the current frame number */
1008
82.6k
    i4_cur_pic_num = ps_dec->ps_cur_pic->i4_pic_num;
1009
1010
    /* Get Min pic_num,MinLt */
1011
82.6k
    i4_min_st_pic_num = i4_cur_pic_num;
1012
82.6k
    u1_max_lt_index = MAX_REF_BUFS + 1;
1013
82.6k
    u1_min_lt_index = MAX_REF_BUFS + 1;
1014
1015
    /* Start from ST head */
1016
82.6k
    ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1017
141k
    for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
1018
58.4k
    {
1019
58.4k
        i4_ref_pic_num = ps_next_dpb->ps_pic_buf->i4_pic_num;
1020
58.4k
        if(i4_ref_pic_num < i4_cur_pic_num)
1021
21.9k
        {
1022
            /* RefPic Buf pic_num is before Current pic_num in decode order */
1023
21.9k
            i4_min_st_pic_num = MIN(i4_min_st_pic_num, i4_ref_pic_num);
1024
21.9k
        }
1025
1026
        /* Chase the next link */
1027
58.4k
        ps_next_dpb = ps_next_dpb->ps_prev_short;
1028
58.4k
    }
1029
1030
    /* Sort ST ref pocs in ascending order */
1031
82.6k
    ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1032
141k
    for (j = 0; j < ps_dpb_mgr->u1_num_st_ref_bufs; j++)
1033
58.4k
    {
1034
58.4k
        aps_st_pic_bufs[j] = ps_next_dpb->ps_pic_buf;
1035
58.4k
        ps_next_dpb = ps_next_dpb->ps_prev_short;
1036
58.4k
    }
1037
82.6k
    qsort(aps_st_pic_bufs, ps_dpb_mgr->u1_num_st_ref_bufs,
1038
82.6k
        sizeof(aps_st_pic_bufs[0]), pic_num_compare);
1039
1040
    /* Start from LT head */
1041
82.6k
    ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
1042
82.6k
    if(ps_next_dpb)
1043
9.73k
    {
1044
9.73k
        u1_max_lt_index = ps_next_dpb->u1_lt_idx;
1045
9.73k
        u1_min_lt_index = ps_next_dpb->u1_lt_idx;
1046
1047
20.8k
        for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
1048
11.1k
        {
1049
11.1k
            u4_lt_index = ps_next_dpb->u1_lt_idx;
1050
11.1k
            u1_max_lt_index = (UWORD8)(MAX(u1_max_lt_index, u4_lt_index));
1051
11.1k
            u1_min_lt_index = (UWORD8)(MIN(u1_min_lt_index, u4_lt_index));
1052
1053
            /* Chase the next link */
1054
11.1k
            ps_next_dpb = ps_next_dpb->ps_prev_long;
1055
11.1k
        }
1056
9.73k
    }
1057
    /* 1. Initialize refIdxL0 */
1058
82.6k
    u1_L0 = 0;
1059
82.6k
    if(u1_field_pic_flag)
1060
519
    {
1061
519
        ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0];
1062
519
        ps_ref_pic_buf_lx += MAX_REF_BUFS;
1063
519
        i4_temp_pic_num = i4_cur_pic_num;
1064
519
    }
1065
82.1k
    else
1066
82.1k
    {
1067
82.1k
        ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0];
1068
82.1k
        i4_temp_pic_num = i4_cur_pic_num;
1069
82.1k
    }
1070
    /* Arrange all short term buffers in output order as given by pic_num */
1071
    /* Arrange pic_num's less than Curr pic_num in the descending pic_num */
1072
    /* order starting from (Curr pic_num - 1)                             */
1073
141k
    for(j = ps_dpb_mgr->u1_num_st_ref_bufs - 1; j >= 0; j--)
1074
58.4k
    {
1075
58.4k
        if(aps_st_pic_bufs[j])
1076
58.4k
        {
1077
            /* Copy info in pic buffer */
1078
58.4k
            ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
1079
58.4k
                                               aps_st_pic_bufs[j]);
1080
58.4k
            ps_ref_pic_buf_lx++;
1081
58.4k
            u1_L0++;
1082
58.4k
        }
1083
58.4k
    }
1084
1085
    /* Arrange all Long term buffers in ascending order, in LongtermIndex */
1086
    /* Start from LT head */
1087
82.6k
    u1_num_short_term_bufs = u1_L0;
1088
169k
    for(u4_lt_index = u1_min_lt_index; u4_lt_index <= u1_max_lt_index;
1089
87.2k
                    u4_lt_index++)
1090
87.2k
    {
1091
87.2k
        ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
1092
98.0k
        for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
1093
21.9k
        {
1094
21.9k
            if(ps_next_dpb->u1_lt_idx == u4_lt_index)
1095
11.1k
            {
1096
11.1k
                ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
1097
11.1k
                                                   ps_next_dpb->ps_pic_buf);
1098
1099
11.1k
                ps_ref_pic_buf_lx->u1_long_term_pic_num =
1100
11.1k
                                ps_ref_pic_buf_lx->u1_long_term_frm_idx;
1101
11.1k
                ps_ref_pic_buf_lx++;
1102
11.1k
                u1_L0++;
1103
11.1k
                break;
1104
11.1k
            }
1105
10.8k
            ps_next_dpb = ps_next_dpb->ps_prev_long;
1106
10.8k
        }
1107
87.2k
    }
1108
1109
82.6k
    if(u1_field_pic_flag)
1110
519
    {
1111
        /* Initialize the rest of the entries in the */
1112
        /* reference list to handle of errors        */
1113
519
        {
1114
519
            UWORD8 u1_i;
1115
519
            pic_buffer_t ref_pic;
1116
1117
519
            ref_pic = *(ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS);
1118
1119
519
            if(NULL == ref_pic.pu1_buf1)
1120
0
            {
1121
0
                ref_pic = *ps_dec->ps_cur_pic;
1122
0
            }
1123
2.45k
            for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
1124
1.93k
            {
1125
1.93k
                *ps_ref_pic_buf_lx = ref_pic;
1126
1.93k
                ps_ref_pic_buf_lx++;
1127
1.93k
            }
1128
519
        }
1129
1130
519
        ih264d_convert_frm_to_fld_list(
1131
519
                        ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS, &u1_L0,
1132
519
                        ps_dec, u1_num_short_term_bufs);
1133
1134
519
        ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0] + u1_L0;
1135
519
    }
1136
1137
    /* Initialize the rest of the entries in the */
1138
    /* reference list to handle of errors        */
1139
82.6k
    {
1140
82.6k
        UWORD8 u1_i;
1141
82.6k
        pic_buffer_t ref_pic;
1142
1143
82.6k
        ref_pic = *(ps_dpb_mgr->ps_init_dpb[0][0]);
1144
1145
82.6k
        if(NULL == ref_pic.pu1_buf1)
1146
0
        {
1147
0
            ref_pic = *ps_dec->ps_cur_pic;
1148
0
        }
1149
191k
        for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
1150
108k
        {
1151
108k
            *ps_ref_pic_buf_lx = ref_pic;
1152
108k
            ps_ref_pic_buf_lx++;
1153
108k
        }
1154
82.6k
    }
1155
82.6k
    ps_dec->ps_cur_slice->u1_initial_list_size[0] = u1_L0;
1156
82.6k
}
1157