Coverage Report

Created: 2026-02-26 07:09

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