Coverage Report

Created: 2025-11-12 06:11

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
196k
{
67
196k
    *ps_ref_pic_buf_lx = *ps_pic;
68
196k
}
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.27M
{
74
1.27M
    parse_pmbarams_t * ps_mb_part_info;
75
1.27M
    parse_part_params_t * ps_part;
76
1.27M
    mv_pred_t *ps_mv_nmb, *ps_mv_nmb_start, *ps_mv_ntop, *ps_mv_ntop_start;
77
1.27M
    UWORD32 i, j;
78
1.27M
    const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
79
1.27M
    dec_mb_info_t * ps_cur_mb_info;
80
1.27M
    WORD32 i2_mv_x, i2_mv_y;
81
1.27M
    WORD32 ret;
82
83
1.27M
    ps_dec->i4_submb_ofst -= (WORD32)(u4_num_mbs - u4_mb_idx) << 4;
84
1.27M
    ps_mb_part_info = ps_dec->ps_parse_mb_data; // + u4_mb_idx;
85
1.27M
    ps_part = ps_dec->ps_parse_part_params; // + u4_mb_idx;
86
87
    /* N/2 Mb MvPred and Transfer Setup Loop */
88
19.4M
    for(i = u4_mb_idx; i < u4_num_mbs; i++, ps_mb_part_info++)
89
18.1M
    {
90
18.1M
        UWORD32 u1_colz;
91
18.1M
        UWORD32 u1_field;
92
18.1M
        mv_pred_t s_mvPred;
93
18.1M
        mv_pred_t *ps_mv_pred = &s_mvPred;
94
95
96
97
18.1M
        *ps_mv_pred = ps_dec->s_default_mv_pred;
98
99
18.1M
        ps_dec->i4_submb_ofst += SUB_BLK_SIZE;
100
101
        /* Restore the slice scratch MbX and MbY context */
102
18.1M
        ps_cur_mb_info = ps_dec->ps_nmb_info + i;
103
18.1M
        u1_field = ps_cur_mb_info->u1_mb_field_decodingflag;
104
105
106
107
18.1M
        ps_mv_nmb_start = ps_dec->ps_mv_cur + (i << 4);
108
18.1M
        ps_dec->u2_mbx = ps_cur_mb_info->u2_mbx;
109
18.1M
        ps_dec->u2_mby = ps_cur_mb_info->u2_mby;
110
18.1M
        ps_dec->u2_mv_2mb[i & 0x1] = 0;
111
112
        /* Look for MV Prediction and Reference Transfer in Non-I Mbs */
113
18.1M
        if(!ps_mb_part_info->u4_isI_mb)
114
18.0M
        {
115
18.0M
            UWORD32 u1_blk_no;
116
18.0M
            WORD32 i1_ref_idx, i1_ref_idx1;
117
18.0M
            UWORD32 u1_sub_mb_x, u1_sub_mb_y, u1_sub_mb_num;
118
18.0M
            UWORD32 u1_num_part, u1_num_ref, u1_wd, u1_ht;
119
18.0M
            UWORD32 *pu4_wt_offst, **ppu4_wt_ofst;
120
18.0M
            UWORD32 u1_scale_ref, u4_bot_mb;
121
18.0M
            WORD8 *pi1_ref_idx = ps_mb_part_info->i1_ref_idx[0];
122
18.0M
            pic_buffer_t *ps_ref_frame, **pps_ref_frame;
123
18.0M
            deblk_mb_t * ps_cur_deblk_mb = ps_dec->ps_deblk_mbn + i;
124
125
            /* MB Level initialisations */
126
18.0M
            ps_dec->u4_num_pmbair = i >> u1_mbaff;
127
18.0M
            ps_dec->u4_mb_idx_mv = i;
128
18.0M
            ppu4_wt_ofst = ps_mb_part_info->pu4_wt_offst;
129
18.0M
            pps_ref_frame = ps_dec->ps_ref_pic_buf_lx[0];
130
            /* CHANGED CODE */
131
18.0M
            ps_mv_ntop_start = ps_mv_nmb_start
132
18.0M
                            - (ps_dec->u2_frm_wd_in_mbs << (4 + u1_mbaff)) + 12;
133
134
18.0M
            u1_num_part = ps_mb_part_info->u1_num_part;
135
18.0M
            ps_cur_deblk_mb->u1_mb_type |= (u1_num_part > 1) << 1;
136
18.0M
            ps_cur_mb_info->u4_pred_info_pkd_idx = ps_dec->u4_pred_info_pkd_idx;
137
18.0M
            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
18.0M
            u1_scale_ref = u1_mbaff & u1_field;
145
146
18.0M
            u4_bot_mb = 1 - ps_cur_mb_info->u1_topmb;
147
18.0M
            if(ps_dec->ps_cur_pps->u1_wted_pred_flag)
148
10.7M
            {
149
10.7M
                u1_num_ref = MIN(u1_num_part, 4);
150
21.5M
                for(u1_blk_no = 0; u1_blk_no < u1_num_ref; u1_blk_no++)
151
10.8M
                {
152
10.8M
                    i1_ref_idx = pi1_ref_idx[u1_blk_no];
153
10.8M
                    if(u1_scale_ref)
154
3.22k
                        i1_ref_idx >>= 1;
155
10.8M
                    pu4_wt_offst = (UWORD32*)&ps_dec->pu4_wt_ofsts[2
156
10.8M
                                    * X3(i1_ref_idx)];
157
10.8M
                    ppu4_wt_ofst[u1_blk_no] = pu4_wt_offst;
158
10.8M
                }
159
10.7M
            }
160
7.35M
            else
161
7.35M
            {
162
7.35M
                ppu4_wt_ofst[0] = NULL;
163
7.35M
                ppu4_wt_ofst[1] = NULL;
164
7.35M
                ppu4_wt_ofst[2] = NULL;
165
7.35M
                ppu4_wt_ofst[3] = NULL;
166
7.35M
            }
167
168
            /**************************************************/
169
            /* Loop on Partitions                             */
170
            /**************************************************/
171
36.5M
            for(j = 0; j < u1_num_part; j++, ps_part++)
172
18.4M
            {
173
174
18.4M
                u1_sub_mb_num = ps_part->u1_sub_mb_num;
175
18.4M
                ps_dec->u1_sub_mb_num = u1_sub_mb_num;
176
177
18.4M
                if(PART_NOT_DIRECT != ps_part->u1_is_direct)
178
17.7M
                {
179
                    /* Mb Skip Mode */
180
                    /* Setting the default and other members of MvPred Structure */
181
17.7M
                    s_mvPred.i2_mv[2] = -1;
182
17.7M
                    s_mvPred.i2_mv[3] = -1;
183
17.7M
                    s_mvPred.i1_ref_frame[0] = 0;
184
17.7M
                    i1_ref_idx = (u1_scale_ref && u4_bot_mb) ? MAX_REF_BUFS : 0;
185
17.7M
                    ps_ref_frame = pps_ref_frame[i1_ref_idx];
186
17.7M
                    s_mvPred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id;
187
17.7M
                    s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
188
17.7M
                    pu4_wt_offst = (UWORD32*)&ps_dec->pu4_wt_ofsts[0];
189
190
17.7M
                    ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb_start,
191
17.7M
                                      ps_mv_ntop_start, &s_mvPred, 0, 4, 0, 1,
192
17.7M
                                      MB_SKIP);
193
194
195
196
197
198
199
17.7M
                    {
200
17.7M
                        pred_info_pkd_t *ps_pred_pkd;
201
17.7M
                        ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
202
17.7M
                    ih264d_fill_pred_info (s_mvPred.i2_mv,4,4,0,PRED_L0,ps_pred_pkd,ps_ref_frame->u1_pic_buf_id,
203
17.7M
                                           (i1_ref_idx >> u1_scale_ref),pu4_wt_offst,
204
17.7M
                                           ps_ref_frame->u1_pic_type);
205
206
207
17.7M
                    ps_dec->u4_pred_info_pkd_idx++;
208
17.7M
                    ps_cur_mb_info->u1_num_pred_parts++;
209
17.7M
                    }
210
211
212
213
                    /* Storing colocated zero information */
214
17.7M
                    u1_colz = ((ABS(s_mvPred.i2_mv[0]) <= 1)
215
17.7M
                                    && (ABS(s_mvPred.i2_mv[1]) <= 1))
216
17.7M
                                    + (u1_field << 1);
217
218
17.7M
                    ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
219
17.7M
                                       u1_colz, 4, 4);
220
17.7M
                }
221
654k
                else
222
654k
                {
223
654k
                    u1_sub_mb_x = u1_sub_mb_num & 0x03;
224
654k
                    u1_sub_mb_y = u1_sub_mb_num >> 2;
225
654k
                    u1_blk_no =
226
654k
                                    (u1_num_part < 4) ?
227
356k
                                                    j :
228
654k
                                                    (((u1_sub_mb_y >> 1) << 1)
229
298k
                                                                    + (u1_sub_mb_x
230
298k
                                                                                    >> 1));
231
232
654k
                    ps_mv_ntop = ps_mv_ntop_start + u1_sub_mb_x;
233
654k
                    ps_mv_nmb = ps_mv_nmb_start + u1_sub_mb_num;
234
235
654k
                    u1_wd = ps_part->u1_partwidth;
236
654k
                    u1_ht = ps_part->u1_partheight;
237
238
                    /* Populate the colpic info and reference frames */
239
654k
                    i1_ref_idx = pi1_ref_idx[u1_blk_no];
240
654k
                    s_mvPred.i1_ref_frame[0] = i1_ref_idx;
241
242
                    /********************************************************/
243
                    /* Predict Mv                                           */
244
                    /* Add Mv Residuals and store back                      */
245
                    /********************************************************/
246
654k
                    ps_dec->pf_mvpred(ps_dec, ps_cur_mb_info, ps_mv_nmb, ps_mv_ntop,
247
654k
                                      &s_mvPred, u1_sub_mb_num, u1_wd, 0, 1,
248
654k
                                      ps_cur_mb_info->u1_mb_mc_mode);
249
654k
                    i2_mv_x = ps_mv_nmb->i2_mv[0];
250
654k
                    i2_mv_y = ps_mv_nmb->i2_mv[1];
251
654k
                    i2_mv_x += s_mvPred.i2_mv[0];
252
654k
                    i2_mv_y += s_mvPred.i2_mv[1];
253
654k
                    s_mvPred.i2_mv[0] = i2_mv_x;
254
654k
                    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
654k
                    i1_ref_idx1 = i1_ref_idx >> u1_scale_ref;
262
654k
                    if(u1_scale_ref && ((i1_ref_idx & 0x01) != u4_bot_mb))
263
16.5k
                        i1_ref_idx1 += MAX_REF_BUFS;
264
654k
                    ps_ref_frame = pps_ref_frame[i1_ref_idx1];
265
654k
                    pu4_wt_offst = ppu4_wt_ofst[u1_blk_no];
266
267
268
269
270
271
272
654k
                    {
273
654k
                    pred_info_pkd_t *ps_pred_pkd;
274
654k
                    ps_pred_pkd = ps_dec->ps_pred_pkd + ps_dec->u4_pred_info_pkd_idx;
275
654k
                    ih264d_fill_pred_info (s_mvPred.i2_mv,u1_wd,u1_ht,u1_sub_mb_num,PRED_L0,ps_pred_pkd,
276
654k
                                           ps_ref_frame->u1_pic_buf_id,(i1_ref_idx >> u1_scale_ref),pu4_wt_offst,
277
654k
                                           ps_ref_frame->u1_pic_type);
278
279
654k
                    ps_dec->u4_pred_info_pkd_idx++;
280
654k
                    ps_cur_mb_info->u1_num_pred_parts++;
281
654k
                    }
282
283
284
285
                    /* Fill colocated info in MvPred structure */
286
654k
                    s_mvPred.u1_col_ref_pic_idx = ps_ref_frame->u1_mv_buf_id;
287
654k
                    s_mvPred.u1_pic_type = ps_ref_frame->u1_pic_type;
288
289
                    /* Calculating colocated zero information */
290
654k
                    u1_colz =
291
654k
                                    (u1_field << 1)
292
654k
                                                    | ((i1_ref_idx == 0)
293
454k
                                                                    && (ABS(i2_mv_x)
294
454k
                                                                                    <= 1)
295
215k
                                                                    && (ABS(i2_mv_y)
296
215k
                                                                                    <= 1));
297
654k
                    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
654k
                    ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb,
303
654k
                                       u1_sub_mb_num, u1_colz, u1_ht,
304
654k
                                       u1_wd);
305
654k
                }
306
18.4M
            }
307
308
18.0M
        }
309
60.6k
        else
310
60.6k
        {
311
            /* Storing colocated zero information */
312
60.6k
            ih264d_rep_mv_colz(ps_dec, &s_mvPred, ps_mv_nmb_start, 0,
313
60.6k
                               (UWORD8)(u1_field << 1), 4, 4);
314
315
60.6k
        }
316
        /*if num _cores is set to 3,compute bs will be done in another thread*/
317
18.1M
        if(ps_dec->u4_num_cores < 3)
318
10.9M
        {
319
320
10.9M
            if(ps_dec->u4_app_disable_deblk_frm == 0)
321
10.9M
                ps_dec->pf_compute_bs(ps_dec, ps_cur_mb_info,
322
10.9M
                                     (UWORD16)(i >> u1_mbaff));
323
10.9M
        }
324
18.1M
    }
325
326
327
328
1.27M
    return OK;
329
1.27M
}
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.17M
{
339
1.17M
    WORD32 i,j;
340
1.17M
    UWORD32 u1_end_of_row_next;
341
1.17M
    dec_mb_info_t * ps_cur_mb_info;
342
1.17M
    UWORD32 u4_update_mbaff = 0;
343
1.17M
    WORD32 ret;
344
1.17M
    const UWORD32 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
345
1.17M
    const UWORD32 u1_slice_type = ps_dec->ps_cur_slice->u1_slice_type;
346
1.17M
    const WORD32 u1_skip_th = (
347
1.17M
                    (u1_slice_type != I_SLICE) ?
348
1.13M
                                    (ps_dec->u1_B ? B_8x8 : PRED_8x8R0) : -1);
349
1.17M
    const UWORD32 u1_ipcm_th = (
350
1.17M
                    (u1_slice_type != I_SLICE) ? (ps_dec->u1_B ? 23 : 5) : 0);
351
352
353
354
355
356
    /* N Mb MC Loop */
357
11.1M
    for(i = u4_mb_idx; i < u4_num_mbs; i++)
358
9.94M
    {
359
9.94M
        ps_cur_mb_info = ps_dec->ps_nmb_info + i;
360
9.94M
        ps_dec->u4_dma_buf_idx = 0;
361
9.94M
        ps_dec->u4_pred_info_idx = 0;
362
363
9.94M
        if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
364
219k
        {
365
219k
            {
366
219k
                WORD32 pred_cnt = 0;
367
219k
                pred_info_pkd_t *ps_pred_pkd;
368
219k
                UWORD32 u4_pred_info_pkd_idx;
369
219k
                WORD8 i1_pred;
370
371
219k
                u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
372
373
817k
                while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
374
597k
                {
375
376
597k
                    ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
377
378
597k
                     ps_dec->p_form_mb_part_info(ps_pred_pkd,ps_dec,
379
597k
                                               ps_cur_mb_info->u2_mbx,ps_cur_mb_info->u2_mby,(i >> u1_mbaff),
380
597k
                                         ps_cur_mb_info);
381
597k
                    u4_pred_info_pkd_idx++;
382
597k
                    pred_cnt++;
383
597k
                }
384
219k
            }
385
386
219k
            ps_dec->p_motion_compensate(ps_dec, ps_cur_mb_info);
387
388
219k
        }
389
9.72M
        else if(ps_cur_mb_info->u1_mb_type == MB_SKIP)
390
8.94M
        {
391
8.94M
            {
392
8.94M
                WORD32 pred_cnt = 0;
393
8.94M
                pred_info_pkd_t *ps_pred_pkd;
394
8.94M
                UWORD32 u4_pred_info_pkd_idx;
395
8.94M
                WORD8 i1_pred;
396
397
8.94M
                u4_pred_info_pkd_idx = ps_cur_mb_info->u4_pred_info_pkd_idx;
398
399
18.3M
                while(pred_cnt < ps_cur_mb_info->u1_num_pred_parts)
400
9.36M
                {
401
402
9.36M
                    ps_pred_pkd = ps_dec->ps_pred_pkd + u4_pred_info_pkd_idx;
403
404
9.36M
                    ps_dec->p_form_mb_part_info(ps_pred_pkd,ps_dec,
405
9.36M
                                               ps_cur_mb_info->u2_mbx,ps_cur_mb_info->u2_mby,(i >> u1_mbaff),
406
9.36M
                                         ps_cur_mb_info);
407
408
9.36M
                    u4_pred_info_pkd_idx++;
409
9.36M
                    pred_cnt++;
410
9.36M
                }
411
8.94M
            }
412
            /* Decode MB skip */
413
8.94M
            ps_dec->p_motion_compensate(ps_dec, ps_cur_mb_info);
414
415
8.94M
        }
416
417
9.94M
     }
418
419
420
    /* N Mb IQ IT RECON  Loop */
421
11.1M
    for(j = u4_mb_idx; j < i; j++)
422
9.94M
    {
423
9.94M
        ps_cur_mb_info = ps_dec->ps_nmb_info + j;
424
425
9.94M
        if(ps_cur_mb_info->u1_mb_type <= u1_skip_th)
426
219k
        {
427
219k
            ih264d_process_inter_mb(ps_dec, ps_cur_mb_info, j);
428
429
219k
        }
430
9.72M
        else if(ps_cur_mb_info->u1_mb_type != MB_SKIP)
431
780k
        {
432
780k
            if((u1_ipcm_th + 25) != ps_cur_mb_info->u1_mb_type)
433
777k
            {
434
777k
                ps_cur_mb_info->u1_mb_type -= (u1_skip_th + 1);
435
777k
                ih264d_process_intra_mb(ps_dec, ps_cur_mb_info, j);
436
777k
            }
437
780k
        }
438
439
440
9.94M
        if(ps_dec->u4_use_intrapred_line_copy)
441
8.58M
        {
442
8.58M
            ih264d_copy_intra_pred_line(ps_dec, ps_cur_mb_info, j);
443
8.58M
        }
444
445
9.94M
    }
446
447
    /*N MB deblocking*/
448
1.17M
    if(ps_dec->u4_nmb_deblk == 1)
449
1.13M
    {
450
451
1.13M
        UWORD32 u4_cur_mb, u4_right_mb;
452
1.13M
        UWORD32 u4_mb_x, u4_mb_y;
453
1.13M
        UWORD32 u4_wd_y, u4_wd_uv;
454
1.13M
        tfr_ctxt_t *ps_tfr_cxt = &(ps_dec->s_tran_addrecon);
455
1.13M
        UWORD8 u1_field_pic_flag = ps_dec->ps_cur_slice->u1_field_pic_flag;
456
1.13M
        const WORD32 i4_cb_qp_idx_ofst =
457
1.13M
                       ps_dec->ps_cur_pps->i1_chroma_qp_index_offset;
458
1.13M
        const WORD32 i4_cr_qp_idx_ofst =
459
1.13M
                       ps_dec->ps_cur_pps->i1_second_chroma_qp_index_offset;
460
461
1.13M
        u4_wd_y = ps_dec->u2_frm_wd_y << u1_field_pic_flag;
462
1.13M
        u4_wd_uv = ps_dec->u2_frm_wd_uv << u1_field_pic_flag;
463
464
465
1.13M
        ps_cur_mb_info = ps_dec->ps_nmb_info + u4_mb_idx;
466
467
1.13M
        ps_dec->u4_deblk_mb_x = ps_cur_mb_info->u2_mbx;
468
1.13M
        ps_dec->u4_deblk_mb_y = ps_cur_mb_info->u2_mby;
469
470
9.71M
        for(j = u4_mb_idx; j < i; j++)
471
8.58M
        {
472
473
8.58M
            ih264d_deblock_mb_nonmbaff(ps_dec, ps_tfr_cxt,
474
8.58M
                                       i4_cb_qp_idx_ofst, i4_cr_qp_idx_ofst,
475
8.58M
                                        u4_wd_y, u4_wd_uv);
476
477
478
8.58M
        }
479
480
481
482
1.13M
    }
483
484
485
486
1.17M
    if(u4_tfr_n_mb)
487
1.17M
    {
488
        /****************************************************************/
489
        /* Check for End Of Row in Next iteration                       */
490
        /****************************************************************/
491
1.17M
        u1_end_of_row_next =
492
1.17M
                        u4_num_mbs_next
493
14.1k
                                        && (u4_num_mbs_next
494
14.1k
                                                        <= (ps_dec->u4_recon_mb_grp
495
14.1k
                                                                        >> 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.17M
        ih264d_transfer_mb_group_data(ps_dec, u4_num_mbs, u4_end_of_row,
506
1.17M
                                      u1_end_of_row_next);
507
1.17M
        ps_dec->u4_num_mbs_prev_nmb = u4_num_mbs;
508
509
1.17M
        ps_dec->u4_pred_info_idx = 0;
510
1.17M
        ps_dec->u4_dma_buf_idx = 0;
511
512
513
1.17M
    }
514
1.17M
    return OK;
515
1.17M
}
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
630k
{
533
    /* CHANGED CODE */
534
630k
    UWORD8 *pu1_rec_y, *pu1_rec_u, *pu1_rec_v;
535
536
    /*CHANGED CODE */
537
630k
    UWORD32 ui_rec_width, u4_recwidth_cr;
538
630k
    WORD16 *pi2_y_coeff;
539
630k
    UWORD32 u1_mb_field_decoding_flag;
540
630k
    const UWORD8 u1_mbaff = ps_dec->ps_cur_slice->u1_mbaff_frame_flag;
541
630k
    UWORD32 uc_botMb;
542
630k
    UWORD32 u4_num_pmbair;
543
    /* CHANGED CODE */
544
630k
    tfr_ctxt_t *ps_frame_buf = ps_dec->ps_frame_buf_ip_recon;
545
630k
    UWORD32 u4_luma_dc_only_csbp = 0;
546
630k
    UWORD32 u4_luma_dc_only_cbp = 0;
547
    /* CHANGED CODE */
548
549
630k
    uc_botMb = 1 - ps_cur_mb_info->u1_topmb;
550
630k
    u4_num_pmbair = (u4_mb_num >> u1_mbaff);
551
630k
    u1_mb_field_decoding_flag = ps_cur_mb_info->u1_mb_field_decodingflag;
552
553
554
    /* CHANGED CODE */
555
630k
    pu1_rec_y = ps_frame_buf->pu1_dest_y + (u4_num_pmbair << 4);
556
630k
    pu1_rec_u =
557
630k
                    ps_frame_buf->pu1_dest_u
558
630k
                                    + (u4_num_pmbair << 3) * YUV420SP_FACTOR;
559
630k
    pu1_rec_v = ps_frame_buf->pu1_dest_v + (u4_num_pmbair << 3);
560
630k
    ui_rec_width = ps_dec->u2_frm_wd_y << u1_mb_field_decoding_flag;
561
630k
    u4_recwidth_cr = ps_dec->u2_frm_wd_uv << u1_mb_field_decoding_flag;
562
563
    /* CHANGED CODE */
564
565
630k
    if(u1_mbaff)
566
44.3k
    {
567
44.3k
        if(uc_botMb)
568
21.6k
        {
569
21.6k
            pu1_rec_y += (u1_mb_field_decoding_flag ?
570
12.9k
                            (ui_rec_width >> 1) : (ui_rec_width << 4));
571
21.6k
            pu1_rec_u += (u1_mb_field_decoding_flag ?
572
12.9k
                            (u4_recwidth_cr >> 1) : (u4_recwidth_cr << 3));
573
21.6k
            pu1_rec_v += (u1_mb_field_decoding_flag ?
574
12.9k
                            (u4_recwidth_cr >> 1) : (u4_recwidth_cr << 3));
575
21.6k
        }
576
44.3k
    }
577
578
630k
    if(!ps_cur_mb_info->u1_tran_form8x8)
579
599k
    {
580
599k
        u4_luma_dc_only_csbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
581
599k
                                       ps_cur_mb_info,
582
599k
                                       0);
583
599k
    }
584
31.8k
    else
585
31.8k
    {
586
31.8k
        if(!ps_dec->ps_cur_pps->u1_entropy_coding_mode)
587
7.48k
        {
588
7.48k
            u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff4x4_mb(ps_dec,
589
7.48k
                                           ps_cur_mb_info,
590
7.48k
                                           0);
591
7.48k
        }
592
24.3k
        else
593
24.3k
        {
594
24.3k
            u4_luma_dc_only_cbp = ih264d_unpack_luma_coeff8x8_mb(ps_dec,
595
24.3k
                                           ps_cur_mb_info);
596
24.3k
        }
597
31.8k
    }
598
599
630k
    pi2_y_coeff = ps_dec->pi2_coeff_data;
600
    /* Inverse Transform and Reconstruction */
601
630k
    if(ps_cur_mb_info->u1_cbp & 0x0f)
602
124k
    {
603
        /* CHANGED CODE */
604
124k
        if(!ps_cur_mb_info->u1_tran_form8x8)
605
93.1k
        {
606
93.1k
            UWORD32 i;
607
93.1k
            WORD16 ai2_tmp[16];
608
1.58M
            for(i = 0; i < 16; i++)
609
1.49M
            {
610
1.49M
                if(CHECKBIT(ps_cur_mb_info->u2_luma_csbp, i))
611
346k
                {
612
346k
                    WORD16 *pi2_level = pi2_y_coeff + (i << 4);
613
346k
                    UWORD8 *pu1_pred_sblk = pu1_rec_y + ((i & 0x3) * BLK_SIZE)
614
346k
                                    + (i >> 2) * (ui_rec_width << 2);
615
346k
                    PROFILE_DISABLE_IQ_IT_RECON()
616
346k
                    {
617
346k
                        if(CHECKBIT(u4_luma_dc_only_csbp, i))
618
60.2k
                        {
619
60.2k
                            ps_dec->pf_iquant_itrans_recon_luma_4x4_dc(
620
60.2k
                                            pi2_level,
621
60.2k
                                            pu1_pred_sblk,
622
60.2k
                                            pu1_pred_sblk,
623
60.2k
                                            ui_rec_width,
624
60.2k
                                            ui_rec_width,
625
60.2k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
626
60.2k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[3],
627
60.2k
                                            ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
628
60.2k
                                            NULL);
629
60.2k
                        }
630
286k
                        else
631
286k
                        {
632
286k
                            ps_dec->pf_iquant_itrans_recon_luma_4x4(
633
286k
                                            pi2_level,
634
286k
                                            pu1_pred_sblk,
635
286k
                                            pu1_pred_sblk,
636
286k
                                            ui_rec_width,
637
286k
                                            ui_rec_width,
638
286k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qp_rem6],
639
286k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[3],
640
286k
                                            ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
641
286k
                                            NULL);
642
286k
                        }
643
346k
                    }
644
346k
                }
645
1.49M
            }
646
93.1k
        }
647
31.8k
        else
648
31.8k
        {
649
31.8k
            WORD16 *pi2_scale_matrix_ptr;
650
31.8k
            WORD32 i;
651
652
31.8k
            pi2_scale_matrix_ptr =
653
31.8k
                            ps_dec->s_high_profile.i2_scalinglist8x8[1];
654
655
159k
            for(i = 0; i < 4; i++)
656
127k
            {
657
127k
                WORD16 ai2_tmp[64];
658
127k
                WORD16 *pi16_levelBlock = pi2_y_coeff + (i << 6); /* move to the next 8x8 adding 64 */
659
660
127k
                UWORD8 *pu1_pred_sblk = pu1_rec_y + ((i & 0x1) * BLK8x8SIZE)
661
127k
                                + (i >> 1) * (ui_rec_width << 3);
662
127k
                if(CHECKBIT(ps_cur_mb_info->u1_cbp, i))
663
66.4k
                {
664
66.4k
                    PROFILE_DISABLE_IQ_IT_RECON()
665
66.4k
                    {
666
66.4k
                        if(CHECKBIT(u4_luma_dc_only_cbp, i))
667
1.61k
                        {
668
1.61k
                            ps_dec->pf_iquant_itrans_recon_luma_8x8_dc(
669
1.61k
                                            pi16_levelBlock,
670
1.61k
                                            pu1_pred_sblk,
671
1.61k
                                            pu1_pred_sblk,
672
1.61k
                                            ui_rec_width,
673
1.61k
                                            ui_rec_width,
674
1.61k
                                            gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
675
1.61k
                                            (UWORD16 *)pi2_scale_matrix_ptr,
676
1.61k
                                            ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
677
1.61k
                                            NULL);
678
1.61k
                        }
679
64.8k
                        else
680
64.8k
                        {
681
64.8k
                            ps_dec->pf_iquant_itrans_recon_luma_8x8(
682
64.8k
                                            pi16_levelBlock,
683
64.8k
                                            pu1_pred_sblk,
684
64.8k
                                            pu1_pred_sblk,
685
64.8k
                                            ui_rec_width,
686
64.8k
                                            ui_rec_width,
687
64.8k
                                            gau1_ih264d_dequant8x8_cavlc[ps_cur_mb_info->u1_qp_rem6],
688
64.8k
                                            (UWORD16 *)pi2_scale_matrix_ptr,
689
64.8k
                                            ps_cur_mb_info->u1_qp_div6, ai2_tmp, 0,
690
64.8k
                                            NULL);
691
64.8k
                        }
692
66.4k
                    }
693
66.4k
                }
694
127k
            }
695
696
31.8k
        }
697
124k
    }
698
699
    /* Decode Chroma Block */
700
630k
    ih264d_unpack_chroma_coeff4x4_mb(ps_dec,
701
630k
                                     ps_cur_mb_info);
702
    /*--------------------------------------------------------------------*/
703
    /* Chroma Blocks decoding                                             */
704
    /*--------------------------------------------------------------------*/
705
630k
    {
706
630k
        UWORD8 u1_chroma_cbp = (UWORD8)(ps_cur_mb_info->u1_cbp >> 4);
707
708
630k
        if(u1_chroma_cbp != CBPC_ALLZERO)
709
71.7k
        {
710
71.7k
            UWORD32 u4_scale_u = ps_cur_mb_info->u1_qpc_div6;
711
71.7k
            UWORD32 u4_scale_v = ps_cur_mb_info->u1_qpcr_div6;
712
71.7k
            UWORD16 u2_chroma_csbp = ps_cur_mb_info->u2_chroma_csbp;
713
714
71.7k
            pi2_y_coeff = ps_dec->pi2_coeff_data;
715
716
71.7k
            {
717
71.7k
                UWORD32 i;
718
71.7k
                WORD16 ai2_tmp[16];
719
358k
                for(i = 0; i < 4; i++)
720
286k
                {
721
286k
                    WORD16 *pi2_level = pi2_y_coeff + (i << 4);
722
286k
                    UWORD8 *pu1_pred_sblk = pu1_rec_u
723
286k
                                    + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
724
286k
                                    + (i >> 1) * (u4_recwidth_cr << 2);
725
286k
                    PROFILE_DISABLE_IQ_IT_RECON()
726
286k
                    {
727
286k
                        if(CHECKBIT(u2_chroma_csbp, i))
728
18.0k
                        {
729
18.0k
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4(
730
18.0k
                                            pi2_level,
731
18.0k
                                            pu1_pred_sblk,
732
18.0k
                                            pu1_pred_sblk,
733
18.0k
                                            u4_recwidth_cr,
734
18.0k
                                            u4_recwidth_cr,
735
18.0k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
736
18.0k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[4],
737
18.0k
                                            u4_scale_u, ai2_tmp, pi2_level);
738
18.0k
                        }
739
268k
                        else if(pi2_level[0] != 0)
740
129k
                        {
741
129k
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
742
129k
                                            pi2_level,
743
129k
                                            pu1_pred_sblk,
744
129k
                                            pu1_pred_sblk,
745
129k
                                            u4_recwidth_cr,
746
129k
                                            u4_recwidth_cr,
747
129k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpc_rem6],
748
129k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[4],
749
129k
                                            u4_scale_u, ai2_tmp, pi2_level);
750
129k
                        }
751
286k
                    }
752
286k
                }
753
71.7k
            }
754
755
71.7k
            pi2_y_coeff += MB_CHROM_SIZE;
756
71.7k
            u2_chroma_csbp >>= 4;
757
758
71.7k
            {
759
71.7k
                UWORD32 i;
760
71.7k
                WORD16 ai2_tmp[16];
761
358k
                for(i = 0; i < 4; i++)
762
286k
                {
763
286k
                    WORD16 *pi2_level = pi2_y_coeff + (i << 4);
764
286k
                    UWORD8 *pu1_pred_sblk = pu1_rec_u + 1
765
286k
                                    + ((i & 0x1) * BLK_SIZE * YUV420SP_FACTOR)
766
286k
                                    + (i >> 1) * (u4_recwidth_cr << 2);
767
286k
                    PROFILE_DISABLE_IQ_IT_RECON()
768
286k
                    {
769
286k
                        if(CHECKBIT(u2_chroma_csbp, i))
770
20.1k
                        {
771
20.1k
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4(
772
20.1k
                                            pi2_level,
773
20.1k
                                            pu1_pred_sblk,
774
20.1k
                                            pu1_pred_sblk,
775
20.1k
                                            u4_recwidth_cr,
776
20.1k
                                            u4_recwidth_cr,
777
20.1k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
778
20.1k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[5],
779
20.1k
                                            u4_scale_v, ai2_tmp, pi2_level);
780
20.1k
                        }
781
266k
                        else if(pi2_level[0] != 0)
782
139k
                        {
783
139k
                            ps_dec->pf_iquant_itrans_recon_chroma_4x4_dc(
784
139k
                                            pi2_level,
785
139k
                                            pu1_pred_sblk,
786
139k
                                            pu1_pred_sblk,
787
139k
                                            u4_recwidth_cr,
788
139k
                                            u4_recwidth_cr,
789
139k
                                            gau2_ih264_iquant_scale_4x4[ps_cur_mb_info->u1_qpcr_rem6],
790
139k
                                            (UWORD16 *)ps_dec->s_high_profile.i2_scalinglist4x4[5],
791
139k
                                            u4_scale_v, ai2_tmp, pi2_level);
792
139k
                        }
793
286k
                    }
794
286k
                }
795
71.7k
            }
796
71.7k
        }
797
630k
    }
798
630k
    return (0);
799
630k
}
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
6.90k
    {
834
6.90k
        return ERROR_PRED_WEIGHT_TABLE_T;
835
6.90k
    }
836
33.6k
    uc_luma_log2_weight_denom = u4_temp;
837
33.6k
    COPYTHECONTEXT("SH: luma_log2_weight_denom",uc_luma_log2_weight_denom);
838
33.6k
    ui32_y_def_weight_ofst = (1 << uc_luma_log2_weight_denom);
839
840
33.6k
    u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
841
33.6k
    if(u4_temp > MAX_LOG2_WEIGHT_DENOM)
842
1.82k
    {
843
1.82k
        return ERROR_PRED_WEIGHT_TABLE_T;
844
1.82k
    }
845
31.8k
    uc_chroma_log2_weight_denom = u4_temp;
846
31.8k
    COPYTHECONTEXT("SH: chroma_log2_weight_denom",uc_chroma_log2_weight_denom);
847
31.8k
    ui32_cr_def_weight_ofst = (1 << uc_chroma_log2_weight_denom);
848
849
31.8k
    ps_cur_slice->u2_log2Y_crwd = uc_luma_log2_weight_denom
850
31.8k
                    | (uc_chroma_log2_weight_denom << 8);
851
852
31.8k
    cont = (ps_cur_slice->u1_slice_type == B_SLICE);
853
31.8k
    lx = 0;
854
31.8k
    do
855
34.8k
    {
856
89.6k
        for(i = 0; i < ps_cur_slice->u1_num_ref_idx_lx_active[lx]; i++)
857
57.2k
        {
858
57.2k
            pui32_weight_offset_lx = ps_cur_slice->u4_wt_ofst_lx[lx][i];
859
860
57.2k
            uc_weight_flag = ih264d_get_bit_h264(ps_bitstrm);
861
57.2k
            pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
862
57.2k
            COPYTHECONTEXT("SH: luma_weight_l0_flag",uc_weight_flag);
863
57.2k
            if(uc_weight_flag)
864
26.1k
            {
865
26.1k
                i_temp = ih264d_sev(pu4_bitstrm_ofst,
866
26.1k
                                    pu4_bitstrm_buf);
867
26.1k
                if((i_temp < PRED_WEIGHT_MIN) || (i_temp > PRED_WEIGHT_MAX))
868
356
                    return ERROR_PRED_WEIGHT_TABLE_T;
869
25.7k
                c_weight = i_temp;
870
25.7k
                COPYTHECONTEXT("SH: luma_weight_l0",c_weight);
871
872
25.7k
                i_temp = ih264d_sev(pu4_bitstrm_ofst,
873
25.7k
                                    pu4_bitstrm_buf);
874
25.7k
                if((i_temp < PRED_WEIGHT_MIN) || (i_temp > PRED_WEIGHT_MAX))
875
619
                    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
31.1k
            else
883
31.1k
            {
884
885
31.1k
                pui32_weight_offset_lx[0] = ui32_y_def_weight_ofst;
886
31.1k
            }
887
888
56.2k
            {
889
56.2k
                WORD8 c_weightCb, c_weightCr, c_offsetCb, c_offsetCr;
890
56.2k
                uc_weight_flag = ih264d_get_bit_h264(ps_bitstrm);
891
56.2k
                pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
892
56.2k
                COPYTHECONTEXT("SH: chroma_weight_l0_flag",uc_weight_flag);
893
56.2k
                if(uc_weight_flag)
894
23.1k
                {
895
23.1k
                    i_temp = ih264d_sev(pu4_bitstrm_ofst,
896
23.1k
                                        pu4_bitstrm_buf);
897
23.1k
                    if((i_temp < PRED_WEIGHT_MIN) || (i_temp > PRED_WEIGHT_MAX))
898
360
                        return ERROR_PRED_WEIGHT_TABLE_T;
899
22.7k
                    c_weightCb = i_temp;
900
22.7k
                    COPYTHECONTEXT("SH: chroma_weight_l0",c_weightCb);
901
902
22.7k
                    i_temp = ih264d_sev(pu4_bitstrm_ofst,
903
22.7k
                                        pu4_bitstrm_buf);
904
22.7k
                    if((i_temp < PRED_WEIGHT_MIN) || (i_temp > PRED_WEIGHT_MAX))
905
348
                        return ERROR_PRED_WEIGHT_TABLE_T;
906
22.4k
                    c_offsetCb = i_temp;
907
22.4k
                    COPYTHECONTEXT("SH: chroma_weight_l0",c_offsetCb);
908
909
22.4k
                    ui32_temp = (c_offsetCb << 16) | (c_weightCb & 0xFFFF);
910
22.4k
                    pui32_weight_offset_lx[1] = ui32_temp;
911
912
22.4k
                    i_temp = ih264d_sev(pu4_bitstrm_ofst,
913
22.4k
                                        pu4_bitstrm_buf);
914
22.4k
                    if((i_temp < PRED_WEIGHT_MIN) || (i_temp > PRED_WEIGHT_MAX))
915
417
                        return ERROR_PRED_WEIGHT_TABLE_T;
916
21.9k
                    c_weightCr = i_temp;
917
21.9k
                    COPYTHECONTEXT("SH: chroma_weight_l0",c_weightCr);
918
919
21.9k
                    i_temp = ih264d_sev(pu4_bitstrm_ofst,
920
21.9k
                                        pu4_bitstrm_buf);
921
21.9k
                    if((i_temp < PRED_WEIGHT_MIN) || (i_temp > PRED_WEIGHT_MAX))
922
370
                        return ERROR_PRED_WEIGHT_TABLE_T;
923
21.6k
                    c_offsetCr = i_temp;
924
21.6k
                    COPYTHECONTEXT("SH: chroma_weight_l0",c_offsetCr);
925
926
21.6k
                    ui32_temp = (c_offsetCr << 16) | (c_weightCr & 0xFFFF);
927
21.6k
                    pui32_weight_offset_lx[2] = ui32_temp;
928
21.6k
                }
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.2k
            }
935
56.2k
        }
936
32.3k
        lx++;
937
32.3k
    }
938
32.3k
    while(cont--);
939
940
29.3k
    return OK;
941
31.8k
}
942
943
static int pic_num_compare(const void *pv_pic1, const void *pv_pic2)
944
9.03k
{
945
9.03k
    struct pic_buffer_t *ps_pic1 = *(struct pic_buffer_t **) pv_pic1;
946
9.03k
    struct pic_buffer_t *ps_pic2 = *(struct pic_buffer_t **) pv_pic2;
947
9.03k
    if (ps_pic1->i4_pic_num < ps_pic2->i4_pic_num)
948
1.98k
    {
949
1.98k
        return -1;
950
1.98k
    }
951
7.05k
    else if (ps_pic1->i4_pic_num > ps_pic2->i4_pic_num)
952
4.39k
    {
953
4.39k
        return 1;
954
4.39k
    }
955
2.66k
    else
956
2.66k
    {
957
2.66k
        return 0;
958
2.66k
    }
959
9.03k
}
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.3k
{
986
82.3k
    struct pic_buffer_t *ps_ref_pic_buf_lx;
987
82.3k
    dpb_manager_t *ps_dpb_mgr;
988
82.3k
    struct dpb_info_t *ps_next_dpb;
989
82.3k
    WORD8 i, j;
990
82.3k
    UWORD8 u1_max_lt_index, u1_min_lt_index;
991
82.3k
    UWORD32 u4_lt_index;
992
82.3k
    UWORD8 u1_field_pic_flag;
993
82.3k
    dec_slice_params_t *ps_cur_slice;
994
82.3k
    UWORD8 u1_L0;
995
82.3k
    WORD32 i4_cur_pic_num, i4_min_st_pic_num;
996
82.3k
    WORD32 i4_temp_pic_num, i4_ref_pic_num;
997
82.3k
    UWORD8 u1_num_short_term_bufs;
998
82.3k
    UWORD8 u1_max_ref_idx_l0;
999
82.3k
    struct pic_buffer_t *aps_st_pic_bufs[2 * MAX_REF_BUFS] = {NULL};
1000
1001
82.3k
    ps_cur_slice = ps_dec->ps_cur_slice;
1002
82.3k
    u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag;
1003
82.3k
    u1_max_ref_idx_l0 = ps_cur_slice->u1_num_ref_idx_lx_active[0]
1004
82.3k
                    << u1_field_pic_flag;
1005
1006
82.3k
    ps_dpb_mgr = ps_dec->ps_dpb_mgr;
1007
    /* Get the current frame number */
1008
82.3k
    i4_cur_pic_num = ps_dec->ps_cur_pic->i4_pic_num;
1009
1010
    /* Get Min pic_num,MinLt */
1011
82.3k
    i4_min_st_pic_num = i4_cur_pic_num;
1012
82.3k
    u1_max_lt_index = MAX_REF_BUFS + 1;
1013
82.3k
    u1_min_lt_index = MAX_REF_BUFS + 1;
1014
1015
    /* Start from ST head */
1016
82.3k
    ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1017
140k
    for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
1018
58.1k
    {
1019
58.1k
        i4_ref_pic_num = ps_next_dpb->ps_pic_buf->i4_pic_num;
1020
58.1k
        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.1k
        ps_next_dpb = ps_next_dpb->ps_prev_short;
1028
58.1k
    }
1029
1030
    /* Sort ST ref pocs in ascending order */
1031
82.3k
    ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
1032
140k
    for (j = 0; j < ps_dpb_mgr->u1_num_st_ref_bufs; j++)
1033
58.1k
    {
1034
58.1k
        aps_st_pic_bufs[j] = ps_next_dpb->ps_pic_buf;
1035
58.1k
        ps_next_dpb = ps_next_dpb->ps_prev_short;
1036
58.1k
    }
1037
82.3k
    qsort(aps_st_pic_bufs, ps_dpb_mgr->u1_num_st_ref_bufs,
1038
82.3k
        sizeof(aps_st_pic_bufs[0]), pic_num_compare);
1039
1040
    /* Start from LT head */
1041
82.3k
    ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
1042
82.3k
    if(ps_next_dpb)
1043
10.3k
    {
1044
10.3k
        u1_max_lt_index = ps_next_dpb->u1_lt_idx;
1045
10.3k
        u1_min_lt_index = ps_next_dpb->u1_lt_idx;
1046
1047
22.0k
        for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
1048
11.7k
        {
1049
11.7k
            u4_lt_index = ps_next_dpb->u1_lt_idx;
1050
11.7k
            u1_max_lt_index = (UWORD8)(MAX(u1_max_lt_index, u4_lt_index));
1051
11.7k
            u1_min_lt_index = (UWORD8)(MIN(u1_min_lt_index, u4_lt_index));
1052
1053
            /* Chase the next link */
1054
11.7k
            ps_next_dpb = ps_next_dpb->ps_prev_long;
1055
11.7k
        }
1056
10.3k
    }
1057
    /* 1. Initialize refIdxL0 */
1058
82.3k
    u1_L0 = 0;
1059
82.3k
    if(u1_field_pic_flag)
1060
442
    {
1061
442
        ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0];
1062
442
        ps_ref_pic_buf_lx += MAX_REF_BUFS;
1063
442
        i4_temp_pic_num = i4_cur_pic_num;
1064
442
    }
1065
81.9k
    else
1066
81.9k
    {
1067
81.9k
        ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0];
1068
81.9k
        i4_temp_pic_num = i4_cur_pic_num;
1069
81.9k
    }
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
140k
    for(j = ps_dpb_mgr->u1_num_st_ref_bufs - 1; j >= 0; j--)
1074
58.1k
    {
1075
58.1k
        if(aps_st_pic_bufs[j])
1076
58.1k
        {
1077
            /* Copy info in pic buffer */
1078
58.1k
            ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
1079
58.1k
                                               aps_st_pic_bufs[j]);
1080
58.1k
            ps_ref_pic_buf_lx++;
1081
58.1k
            u1_L0++;
1082
58.1k
        }
1083
58.1k
    }
1084
1085
    /* Arrange all Long term buffers in ascending order, in LongtermIndex */
1086
    /* Start from LT head */
1087
82.3k
    u1_num_short_term_bufs = u1_L0;
1088
170k
    for(u4_lt_index = u1_min_lt_index; u4_lt_index <= u1_max_lt_index;
1089
88.2k
                    u4_lt_index++)
1090
88.2k
    {
1091
88.2k
        ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
1092
101k
        for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
1093
25.0k
        {
1094
25.0k
            if(ps_next_dpb->u1_lt_idx == u4_lt_index)
1095
11.7k
            {
1096
11.7k
                ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
1097
11.7k
                                                   ps_next_dpb->ps_pic_buf);
1098
1099
11.7k
                ps_ref_pic_buf_lx->u1_long_term_pic_num =
1100
11.7k
                                ps_ref_pic_buf_lx->u1_long_term_frm_idx;
1101
11.7k
                ps_ref_pic_buf_lx++;
1102
11.7k
                u1_L0++;
1103
11.7k
                break;
1104
11.7k
            }
1105
13.2k
            ps_next_dpb = ps_next_dpb->ps_prev_long;
1106
13.2k
        }
1107
88.2k
    }
1108
1109
82.3k
    if(u1_field_pic_flag)
1110
442
    {
1111
        /* Initialize the rest of the entries in the */
1112
        /* reference list to handle of errors        */
1113
442
        {
1114
442
            UWORD8 u1_i;
1115
442
            pic_buffer_t ref_pic;
1116
1117
442
            ref_pic = *(ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS);
1118
1119
442
            if(NULL == ref_pic.pu1_buf1)
1120
0
            {
1121
0
                ref_pic = *ps_dec->ps_cur_pic;
1122
0
            }
1123
2.50k
            for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
1124
2.06k
            {
1125
2.06k
                *ps_ref_pic_buf_lx = ref_pic;
1126
2.06k
                ps_ref_pic_buf_lx++;
1127
2.06k
            }
1128
442
        }
1129
1130
442
        ih264d_convert_frm_to_fld_list(
1131
442
                        ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS, &u1_L0,
1132
442
                        ps_dec, u1_num_short_term_bufs);
1133
1134
442
        ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0] + u1_L0;
1135
442
    }
1136
1137
    /* Initialize the rest of the entries in the */
1138
    /* reference list to handle of errors        */
1139
82.3k
    {
1140
82.3k
        UWORD8 u1_i;
1141
82.3k
        pic_buffer_t ref_pic;
1142
1143
82.3k
        ref_pic = *(ps_dpb_mgr->ps_init_dpb[0][0]);
1144
1145
82.3k
        if(NULL == ref_pic.pu1_buf1)
1146
0
        {
1147
0
            ref_pic = *ps_dec->ps_cur_pic;
1148
0
        }
1149
190k
        for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
1150
107k
        {
1151
107k
            *ps_ref_pic_buf_lx = ref_pic;
1152
107k
            ps_ref_pic_buf_lx++;
1153
107k
        }
1154
82.3k
    }
1155
82.3k
    ps_dec->ps_cur_slice->u1_initial_list_size[0] = u1_L0;
1156
82.3k
}
1157