Coverage Report

Created: 2026-09-01 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmpeg2/decoder/impeg2d_pic_proc.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
#include <stdio.h>
21
#include <string.h>
22
23
#include "iv_datatypedef.h"
24
#include "iv.h"
25
26
#include "impeg2_buf_mgr.h"
27
#include "impeg2_disp_mgr.h"
28
#include "impeg2_defs.h"
29
#include "impeg2_platform_macros.h"
30
#include "impeg2_inter_pred.h"
31
#include "impeg2_idct.h"
32
#include "impeg2_globals.h"
33
#include "impeg2_format_conv.h"
34
#include "impeg2_macros.h"
35
36
#include "ivd.h"
37
#include "impeg2d.h"
38
#include "impeg2d_bitstream.h"
39
#include "impeg2d_structs.h"
40
#include "impeg2d_globals.h"
41
#include "impeg2d_vld_tables.h"
42
#include "impeg2d_vld.h"
43
#include "impeg2d_pic_proc.h"
44
#include "impeg2d_debug.h"
45
46
void impeg2d_init_function_ptr(void *pv_codec);
47
void impeg2d_format_convert(dec_state_t *ps_dec,
48
                            pic_buf_t *ps_src_pic,
49
                            iv_yuv_buf_t    *ps_disp_frm_buf,
50
                            UWORD32 u4_start_row, UWORD32 u4_num_rows)
51
239k
{
52
239k
    UWORD8  *pu1_src_y,*pu1_src_u,*pu1_src_v;
53
239k
    UWORD8  *pu1_dst_y,*pu1_dst_u,*pu1_dst_v;
54
55
56
57
239k
    if((NULL == ps_src_pic) || (NULL == ps_src_pic->pu1_y) || (0 == u4_num_rows))
58
0
            return;
59
60
239k
    pu1_src_y   = ps_src_pic->pu1_y + (u4_start_row * ps_dec->u2_frame_width);
61
239k
    pu1_src_u   = ps_src_pic->pu1_u + ((u4_start_row >> 1) * (ps_dec->u2_frame_width >> 1));
62
239k
    pu1_src_v   = ps_src_pic->pu1_v + ((u4_start_row >> 1) *(ps_dec->u2_frame_width >> 1));
63
64
239k
    pu1_dst_y  =  (UWORD8 *)ps_disp_frm_buf->pv_y_buf + (u4_start_row *  ps_dec->u4_frm_buf_stride);
65
239k
    pu1_dst_u =   (UWORD8 *)ps_disp_frm_buf->pv_u_buf +((u4_start_row >> 1)*(ps_dec->u4_frm_buf_stride >> 1));
66
239k
    pu1_dst_v =   (UWORD8 *)ps_disp_frm_buf->pv_v_buf +((u4_start_row >> 1)*(ps_dec->u4_frm_buf_stride >> 1));
67
68
239k
    if (IV_YUV_420P == ps_dec->i4_chromaFormat)
69
96.8k
    {
70
96.8k
        ps_dec->pf_copy_yuv420p_buf(pu1_src_y, pu1_src_u, pu1_src_v, pu1_dst_y,
71
96.8k
                                    pu1_dst_u, pu1_dst_v,
72
96.8k
                                    ps_dec->u2_horizontal_size,
73
96.8k
                                    u4_num_rows,
74
96.8k
                                    ps_dec->u2_frame_width,
75
96.8k
                                    (ps_dec->u2_frame_width >> 1),
76
96.8k
                                    (ps_dec->u2_frame_width >> 1),
77
96.8k
                                    ps_dec->u4_frm_buf_stride,
78
96.8k
                                    (ps_dec->u4_frm_buf_stride >> 1),
79
96.8k
                                    (ps_dec->u4_frm_buf_stride >> 1));
80
96.8k
    }
81
142k
    else if (IV_YUV_422ILE == ps_dec->i4_chromaFormat)
82
0
    {
83
0
        void    *pv_yuv422i;
84
0
        UWORD32 u2_height,u2_width,u2_stride_y,u2_stride_u,u2_stride_v;
85
0
        UWORD32 u2_stride_yuv422i;
86
87
88
0
        pv_yuv422i          = (UWORD8 *)ps_disp_frm_buf->pv_y_buf + ((ps_dec->u2_vertical_size)*(ps_dec->u4_frm_buf_stride));
89
0
        u2_height           = u4_num_rows;
90
0
        u2_width            = ps_dec->u2_horizontal_size;
91
0
        u2_stride_y         = ps_dec->u2_frame_width;
92
0
        u2_stride_u         = u2_stride_y >> 1;
93
0
        u2_stride_v         = u2_stride_u;
94
0
        u2_stride_yuv422i   = (0 == ps_dec->u4_frm_buf_stride) ? ps_dec->u2_horizontal_size : ps_dec->u4_frm_buf_stride;
95
96
0
        ps_dec->pf_fmt_conv_yuv420p_to_yuv422ile(pu1_src_y,
97
0
            pu1_src_u,
98
0
            pu1_src_v,
99
0
            pv_yuv422i,
100
0
            u2_width,
101
0
            u2_height,
102
0
            u2_stride_y,
103
0
            u2_stride_u,
104
0
            u2_stride_v,
105
0
            u2_stride_yuv422i);
106
107
0
    }
108
142k
    else if((ps_dec->i4_chromaFormat == IV_YUV_420SP_UV) ||
109
58.2k
            (ps_dec->i4_chromaFormat == IV_YUV_420SP_VU))
110
142k
    {
111
112
142k
        UWORD32 dest_inc_Y=0,dest_inc_UV=0;
113
142k
        WORD32 convert_uv_only;
114
115
142k
        pu1_dst_u =   (UWORD8 *)ps_disp_frm_buf->pv_u_buf +((u4_start_row >> 1)*(ps_dec->u4_frm_buf_stride));
116
142k
        dest_inc_Y =    ps_dec->u4_frm_buf_stride;
117
142k
        dest_inc_UV =   ((ps_dec->u4_frm_buf_stride + 1) >> 1) << 1;
118
142k
        convert_uv_only = 0;
119
120
142k
        if(1 == ps_dec->u4_share_disp_buf)
121
0
            convert_uv_only = 1;
122
123
142k
        if(ps_src_pic->pu1_y == ps_disp_frm_buf->pv_y_buf)
124
58.4k
            convert_uv_only = 1;
125
126
142k
        if(ps_dec->i4_chromaFormat == IV_YUV_420SP_UV)
127
84.5k
        {
128
84.5k
            ps_dec->pf_fmt_conv_yuv420p_to_yuv420sp_uv(pu1_src_y,
129
84.5k
                pu1_src_u,
130
84.5k
                pu1_src_v,
131
84.5k
                pu1_dst_y,
132
84.5k
                pu1_dst_u,
133
84.5k
                u4_num_rows,
134
84.5k
                ps_dec->u2_horizontal_size,
135
84.5k
                ps_dec->u2_frame_width,
136
84.5k
                ps_dec->u2_frame_width >> 1,
137
84.5k
                ps_dec->u2_frame_width >> 1,
138
84.5k
                dest_inc_Y,
139
84.5k
                dest_inc_UV,
140
84.5k
                convert_uv_only);
141
84.5k
        }
142
58.2k
        else
143
58.2k
        {
144
58.2k
            ps_dec->pf_fmt_conv_yuv420p_to_yuv420sp_vu(pu1_src_y,
145
58.2k
                    pu1_src_u,
146
58.2k
                    pu1_src_v,
147
58.2k
                    pu1_dst_y,
148
58.2k
                    pu1_dst_u,
149
58.2k
                    u4_num_rows,
150
58.2k
                    ps_dec->u2_horizontal_size,
151
58.2k
                    ps_dec->u2_frame_width,
152
58.2k
                    ps_dec->u2_frame_width >> 1,
153
58.2k
                    ps_dec->u2_frame_width >> 1,
154
58.2k
                    dest_inc_Y,
155
58.2k
                    dest_inc_UV,
156
58.2k
                    convert_uv_only);
157
58.2k
        }
158
159
160
161
142k
    }
162
163
239k
}
164
165
166
/*******************************************************************************
167
*
168
*  Function Name   : impeg2d_get_frm_buf
169
*
170
*  Description     : Gets YUV component buffers for the frame
171
*
172
*  Arguments       :
173
*  frm_buf         : YUV buffer
174
*  frm             : Reference frame
175
*  width           : Width of the frame
176
*  Height          : Height of the frame
177
*
178
*  Values Returned : None
179
*******************************************************************************/
180
void impeg2d_get_frm_buf(yuv_buf_t *ps_frm_buf,UWORD8 *pu1_frm,UWORD32 u4_width,UWORD32 u4_height)
181
0
{
182
0
   UWORD32 u4_luma_size = u4_width * u4_height;
183
0
   UWORD32 u4_chroma_size = (u4_width * u4_height)>>2;
184
185
0
   ps_frm_buf->pu1_y = pu1_frm;
186
0
   ps_frm_buf->pu1_u = pu1_frm + u4_luma_size;
187
0
   ps_frm_buf->pu1_v = pu1_frm + u4_luma_size + u4_chroma_size;
188
189
0
}
190
/*******************************************************************************
191
*
192
*  Function Name   : impeg2d_get_bottom_field_buf
193
*
194
*  Description     : Gets YUV component buffers for bottom field of the frame
195
*
196
*  Arguments       :
197
*  frm_buf         : YUV buffer
198
*  frm             : Reference frame
199
*  width           : Width of the frame
200
*  Height          : Height of the frame
201
*
202
*  Values Returned : None
203
*******************************************************************************/
204
void impeg2d_get_bottom_field_buf(yuv_buf_t *ps_src_buf,yuv_buf_t *ps_dst_buf,
205
                      UWORD32 u4_width)
206
19.7k
{
207
19.7k
   ps_dst_buf->pu1_y = ps_src_buf->pu1_y + u4_width;
208
19.7k
   ps_dst_buf->pu1_u = ps_src_buf->pu1_u + (u4_width>>1);
209
19.7k
   ps_dst_buf->pu1_v = ps_src_buf->pu1_v + (u4_width>>1);
210
211
19.7k
}
212
/*******************************************************************************
213
*  Function Name   : impeg2d_get_mb_addr_incr
214
*
215
*  Description     : Decodes the Macroblock address increment
216
*
217
*  Arguments       :
218
*  stream          : Bitstream
219
*
220
*  Values Returned : Macroblock address increment
221
*******************************************************************************/
222
UWORD16 impeg2d_get_mb_addr_incr(stream_t *ps_stream)
223
997k
{
224
997k
    UWORD16 u2_mb_addr_incr = 0;
225
1.07M
    while (impeg2d_bit_stream_nxt(ps_stream,MB_ESCAPE_CODE_LEN) == MB_ESCAPE_CODE &&
226
75.9k
            ps_stream->u4_offset < ps_stream->u4_max_offset)
227
75.3k
    {
228
75.3k
        impeg2d_bit_stream_flush(ps_stream,MB_ESCAPE_CODE_LEN);
229
75.3k
        u2_mb_addr_incr += 33;
230
75.3k
    }
231
997k
    u2_mb_addr_incr += impeg2d_dec_vld_symbol(ps_stream,gai2_impeg2d_mb_addr_incr,MB_ADDR_INCR_LEN) +
232
997k
        MB_ADDR_INCR_OFFSET;
233
997k
    return(u2_mb_addr_incr);
234
997k
}
235
236
/*******************************************************************************
237
*
238
*  Function Name   : impeg2d_init_video_state
239
*
240
*  Description     : Initializes the Video decoder state
241
*
242
*  Arguments       :
243
*  dec             : Decoder context
244
*  videoType       : MPEG_2_Video / MPEG_1_Video
245
*
246
*  Values Returned : None
247
*******************************************************************************/
248
IMPEG2D_ERROR_CODES_T impeg2d_init_video_state(dec_state_t *ps_dec, e_video_type_t e_video_type)
249
8.16k
{
250
    /*-----------------------------------------------------------------------*/
251
    /* Bit Stream  that conforms to MPEG-1 <ISO/IEC 11172-2> standard        */
252
    /*-----------------------------------------------------------------------*/
253
8.16k
    if(e_video_type == MPEG_1_VIDEO)
254
5.04k
    {
255
5.04k
        ps_dec->u2_is_mpeg2 = 0;
256
257
        /*-------------------------------------------------------------------*/
258
        /* force MPEG-1 parameters for proper decoder behavior               */
259
        /* see ISO/IEC 13818-2 section D.9.14                                */
260
        /*-------------------------------------------------------------------*/
261
5.04k
        ps_dec->u2_progressive_sequence         = 1;
262
5.04k
        ps_dec->u2_intra_dc_precision           = 0;
263
5.04k
        ps_dec->u2_picture_structure            = FRAME_PICTURE;
264
5.04k
        ps_dec->u2_frame_pred_frame_dct         = 1;
265
5.04k
        ps_dec->u2_concealment_motion_vectors   = 0;
266
5.04k
        ps_dec->u2_q_scale_type                 = 0;
267
5.04k
        ps_dec->u2_intra_vlc_format             = 0;
268
5.04k
        ps_dec->u2_alternate_scan               = 0;
269
5.04k
        ps_dec->u2_repeat_first_field           = 0;
270
5.04k
        ps_dec->u2_progressive_frame            = 1;
271
5.04k
        ps_dec->u2_frame_rate_extension_n       = 0;
272
5.04k
        ps_dec->u2_frame_rate_extension_d       = 0;
273
5.04k
        ps_dec->u2_forw_f_code                  = 7;
274
5.04k
        ps_dec->u2_back_f_code                  = 7;
275
276
5.04k
        ps_dec->pf_vld_inv_quant                  = impeg2d_vld_inv_quant_mpeg1;
277
        /*-------------------------------------------------------------------*/
278
        /* Setting of parameters other than those mentioned in MPEG2 standard*/
279
        /* but used in decoding process.                                     */
280
        /*-------------------------------------------------------------------*/
281
5.04k
    }
282
    /*-----------------------------------------------------------------------*/
283
    /* Bit Stream  that conforms to MPEG-2                                   */
284
    /*-----------------------------------------------------------------------*/
285
3.12k
    else
286
3.12k
    {
287
3.12k
        ps_dec->u2_is_mpeg2                  = 1;
288
3.12k
        ps_dec->u2_full_pel_forw_vector   = 0;
289
3.12k
        ps_dec->u2_forw_f_code            = 7;
290
3.12k
        ps_dec->u2_full_pel_back_vector   = 0;
291
3.12k
        ps_dec->u2_back_f_code            = 7;
292
3.12k
        ps_dec->pf_vld_inv_quant       = impeg2d_vld_inv_quant_mpeg2;
293
294
295
3.12k
    }
296
297
298
8.16k
    impeg2d_init_function_ptr(ps_dec);
299
300
    /* Set the frame Width and frame Height */
301
8.16k
    ps_dec->u2_frame_height        = ALIGN16(ps_dec->u2_vertical_size);
302
8.16k
    ps_dec->u2_frame_width         = ALIGN16(ps_dec->u2_horizontal_size);
303
8.16k
    ps_dec->u2_num_horiz_mb         = (ps_dec->u2_horizontal_size + 15) >> 4;
304
   // dec->u4_frm_buf_stride    = dec->frameWidth;
305
8.16k
    if (ps_dec->u2_frame_height > ps_dec->u2_create_max_height || ps_dec->u2_frame_width > ps_dec->u2_create_max_width)
306
0
    {
307
0
        return IMPEG2D_PIC_SIZE_NOT_SUPPORTED;
308
0
    }
309
310
8.16k
    ps_dec->u2_num_flds_decoded = 0;
311
312
    /* Calculate the frame period */
313
8.16k
    {
314
8.16k
        UWORD32 numer;
315
8.16k
        UWORD32 denom;
316
8.16k
        numer = (UWORD32)gau2_impeg2_frm_rate_code[ps_dec->u2_frame_rate_code][1] *
317
8.16k
                                (UWORD32)(ps_dec->u2_frame_rate_extension_d + 1);
318
319
8.16k
        denom = (UWORD32)gau2_impeg2_frm_rate_code[ps_dec->u2_frame_rate_code][0] *
320
8.16k
                                (UWORD32)(ps_dec->u2_frame_rate_extension_n + 1);
321
8.16k
        ps_dec->u2_framePeriod =  (numer * 1000 * 100) / denom;
322
8.16k
    }
323
324
325
8.16k
   if(VERTICAL_SCAN == ps_dec->u2_alternate_scan)
326
466
   {
327
466
    ps_dec->pu1_inv_scan_matrix = (UWORD8 *)gau1_impeg2_inv_scan_vertical;
328
466
   }
329
7.69k
   else
330
7.69k
   {
331
7.69k
    ps_dec->pu1_inv_scan_matrix = (UWORD8 *)gau1_impeg2_inv_scan_zig_zag;
332
7.69k
   }
333
8.16k
   return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
334
8.16k
}
335
/*******************************************************************************
336
*
337
*  Function Name   : impeg2d_pre_pic_dec_proc
338
*
339
*  Description     : Does the processing neccessary before picture decoding
340
*
341
*  Arguments       :
342
*  dec             : Decoder context
343
*
344
*  Values Returned : None
345
*******************************************************************************/
346
IMPEG2D_ERROR_CODES_T impeg2d_pre_pic_dec_proc(dec_state_t *ps_dec)
347
29.3k
{
348
29.3k
    WORD32 u4_get_disp;
349
29.3k
    pic_buf_t *ps_disp_pic;
350
29.3k
    IMPEG2D_ERROR_CODES_T e_error = (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
351
352
29.3k
    u4_get_disp = 0;
353
29.3k
    ps_disp_pic = NULL;
354
355
    /* Field Picture */
356
29.3k
    if(ps_dec->u2_picture_structure != FRAME_PICTURE)
357
5.95k
    {
358
5.95k
        ps_dec->u2_num_vert_mb       = (ps_dec->u2_vertical_size + 31) >> 5;
359
360
5.95k
        if(ps_dec->u2_num_flds_decoded == 0)
361
3.72k
        {
362
3.72k
            pic_buf_t *ps_pic_buf;
363
3.72k
            u4_get_disp = 1;
364
365
3.72k
            ps_pic_buf = impeg2_buf_mgr_get_next_free(ps_dec->pv_pic_buf_mg, &ps_dec->i4_cur_buf_id);
366
367
3.72k
            if (NULL == ps_pic_buf)
368
397
            {
369
397
                return IMPEG2D_NO_FREE_BUF_ERR;
370
397
            }
371
372
3.32k
            impeg2_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mg, ps_dec->i4_cur_buf_id, BUF_MGR_DISP);
373
3.32k
            impeg2_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mg, ps_dec->i4_cur_buf_id, BUF_MGR_REF);
374
3.32k
            if(ps_dec->u4_deinterlace)
375
3.32k
                impeg2_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mg, ps_dec->i4_cur_buf_id, MPEG2_BUF_MGR_DEINT);
376
377
3.32k
            ps_pic_buf->e_pic_type = ps_dec->e_pic_type;
378
3.32k
            ps_dec->ps_cur_pic = ps_pic_buf;
379
3.32k
            ps_dec->s_cur_frm_buf.pu1_y = ps_pic_buf->pu1_y;
380
3.32k
            ps_dec->s_cur_frm_buf.pu1_u = ps_pic_buf->pu1_u;
381
3.32k
            ps_dec->s_cur_frm_buf.pu1_v = ps_pic_buf->pu1_v;
382
3.32k
        }
383
2.23k
        else
384
2.23k
        {
385
            /* Timestamp associated with second field is associated with the current picture */
386
2.23k
            ps_dec->ps_cur_pic->u4_ts = ps_dec->u4_inp_ts;
387
2.23k
        }
388
389
5.56k
        if(ps_dec->u2_picture_structure == TOP_FIELD)
390
4.18k
        {
391
4.18k
            ps_dec->u2_fld_parity = TOP;
392
4.18k
        }
393
1.37k
        else
394
1.37k
        {
395
1.37k
            ps_dec->u2_fld_parity = BOTTOM;
396
1.37k
        }
397
5.56k
        ps_dec->u2_field_dct           = 0;
398
5.56k
        ps_dec->u2_read_dct_type        = 0;
399
5.56k
        ps_dec->u2_read_motion_type     = 1;
400
5.56k
        ps_dec->u2_fld_pic             = 1;
401
5.56k
        ps_dec->u2_frm_pic             = 0;
402
5.56k
        ps_dec->ps_func_forw_or_back     = gas_impeg2d_func_fld_fw_or_bk;
403
5.56k
        ps_dec->ps_func_bi_direct       = gas_impeg2d_func_fld_bi_direct;
404
5.56k
   }
405
    /* Frame Picture */
406
23.4k
    else
407
23.4k
    {
408
23.4k
        pic_buf_t *ps_pic_buf;
409
410
411
23.4k
        ps_dec->u2_num_vert_mb       = (ps_dec->u2_vertical_size + 15) >> 4;
412
23.4k
        u4_get_disp = 1;
413
23.4k
        ps_pic_buf = impeg2_buf_mgr_get_next_free(ps_dec->pv_pic_buf_mg, &ps_dec->i4_cur_buf_id);
414
415
23.4k
        if (NULL == ps_pic_buf)
416
522
        {
417
522
            return IMPEG2D_NO_FREE_BUF_ERR;
418
522
        }
419
22.8k
        impeg2_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mg, ps_dec->i4_cur_buf_id, BUF_MGR_DISP);
420
22.8k
        impeg2_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mg, ps_dec->i4_cur_buf_id, BUF_MGR_REF);
421
22.8k
        if(ps_dec->u4_deinterlace)
422
22.8k
            impeg2_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mg, ps_dec->i4_cur_buf_id, MPEG2_BUF_MGR_DEINT);
423
424
22.8k
        ps_pic_buf->u4_ts = ps_dec->u4_inp_ts;
425
22.8k
        ps_pic_buf->e_pic_type = ps_dec->e_pic_type;
426
22.8k
        ps_dec->ps_cur_pic = ps_pic_buf;
427
22.8k
        ps_dec->s_cur_frm_buf.pu1_y = ps_pic_buf->pu1_y;
428
22.8k
        ps_dec->s_cur_frm_buf.pu1_u = ps_pic_buf->pu1_u;
429
22.8k
        ps_dec->s_cur_frm_buf.pu1_v = ps_pic_buf->pu1_v;
430
431
432
22.8k
        if(ps_dec->u2_frame_pred_frame_dct == 0)
433
4.65k
        {
434
4.65k
            ps_dec->u2_read_dct_type    = 1;
435
4.65k
            ps_dec->u2_read_motion_type = 1;
436
4.65k
        }
437
18.2k
        else
438
18.2k
        {
439
18.2k
            ps_dec->u2_read_dct_type    = 0;
440
18.2k
            ps_dec->u2_read_motion_type = 0;
441
18.2k
            ps_dec->u2_motion_type     = 2;
442
18.2k
            ps_dec->u2_field_dct       = 0;
443
18.2k
        }
444
445
22.8k
        ps_dec->u2_fld_parity          = TOP;
446
22.8k
        ps_dec->u2_fld_pic             = 0;
447
22.8k
        ps_dec->u2_frm_pic             = 1;
448
22.8k
        ps_dec->ps_func_forw_or_back     = gas_impeg2d_func_frm_fw_or_bk;
449
22.8k
        ps_dec->ps_func_bi_direct       = gas_impeg2d_func_frm_bi_direct;
450
22.8k
   }
451
28.4k
    ps_dec->u2_def_dc_pred[Y_LUMA]   = 128 << ps_dec->u2_intra_dc_precision;
452
28.4k
    ps_dec->u2_def_dc_pred[U_CHROMA]   = 128 << ps_dec->u2_intra_dc_precision;
453
28.4k
    ps_dec->u2_def_dc_pred[V_CHROMA]   = 128 << ps_dec->u2_intra_dc_precision;
454
28.4k
    ps_dec->u2_num_mbs_left  = ps_dec->u2_num_horiz_mb * ps_dec->u2_num_vert_mb;
455
28.4k
    if(u4_get_disp)
456
26.2k
    {
457
26.2k
        if(ps_dec->u4_num_frames_decoded > 1)
458
21.2k
        {
459
21.2k
            ps_disp_pic = impeg2_disp_mgr_get(&ps_dec->s_disp_mgr, &ps_dec->i4_disp_buf_id);
460
21.2k
        }
461
26.2k
        ps_dec->ps_disp_pic = ps_disp_pic;
462
26.2k
        if(ps_disp_pic)
463
17.6k
        {
464
17.6k
            if(1 == ps_dec->u4_share_disp_buf)
465
0
            {
466
0
                ps_dec->ps_disp_frm_buf->pv_y_buf  = ps_disp_pic->pu1_y;
467
0
                if(IV_YUV_420P == ps_dec->i4_chromaFormat)
468
0
                {
469
0
                    ps_dec->ps_disp_frm_buf->pv_u_buf  = ps_disp_pic->pu1_u;
470
0
                    ps_dec->ps_disp_frm_buf->pv_v_buf  = ps_disp_pic->pu1_v;
471
0
                }
472
0
                else
473
0
                {
474
0
                    UWORD8 *pu1_buf;
475
476
0
                    pu1_buf = ps_dec->as_disp_buffers[ps_disp_pic->i4_buf_id].pu1_bufs[1];
477
0
                    ps_dec->ps_disp_frm_buf->pv_u_buf  = pu1_buf;
478
479
0
                    pu1_buf = ps_dec->as_disp_buffers[ps_disp_pic->i4_buf_id].pu1_bufs[2];
480
0
                    ps_dec->ps_disp_frm_buf->pv_v_buf  = pu1_buf;
481
0
                }
482
0
            }
483
17.6k
        }
484
26.2k
    }
485
486
487
28.4k
    switch(ps_dec->e_pic_type)
488
28.4k
    {
489
7.64k
    case I_PIC:
490
7.64k
        {
491
7.64k
            ps_dec->pf_decode_slice = impeg2d_dec_i_slice;
492
7.64k
            break;
493
0
        }
494
8.64k
    case D_PIC:
495
8.64k
        {
496
8.64k
            ps_dec->pf_decode_slice = impeg2d_dec_d_slice;
497
8.64k
            break;
498
0
        }
499
5.47k
    case P_PIC:
500
5.47k
        {
501
5.47k
            ps_dec->pf_decode_slice = impeg2d_dec_p_b_slice;
502
5.47k
            ps_dec->pu2_mb_type       = gau2_impeg2d_p_mb_type;
503
5.47k
            break;
504
0
        }
505
6.68k
    case B_PIC:
506
6.68k
        {
507
6.68k
            ps_dec->pf_decode_slice = impeg2d_dec_p_b_slice;
508
6.68k
            ps_dec->pu2_mb_type       = gau2_impeg2d_b_mb_type;
509
6.68k
            break;
510
0
        }
511
0
    default:
512
0
        return IMPEG2D_INVALID_PIC_TYPE;
513
28.4k
    }
514
515
    /*************************************************************************/
516
    /* Set the reference pictures                                            */
517
    /*************************************************************************/
518
519
    /* Error resilience: If forward and backward pictures are going to be NULL*/
520
    /* then assign both to the current                                        */
521
    /* if one of them NULL then we will assign the non null to the NULL one   */
522
523
28.4k
    if(ps_dec->e_pic_type == P_PIC)
524
5.47k
    {
525
5.47k
        if (NULL == ps_dec->as_recent_fld[1][0].pu1_y)
526
768
        {
527
768
            ps_dec->as_recent_fld[1][0] = ps_dec->s_cur_frm_buf;
528
768
        }
529
5.47k
        if (NULL == ps_dec->as_recent_fld[1][1].pu1_y)
530
770
        {
531
770
            impeg2d_get_bottom_field_buf(&ps_dec->s_cur_frm_buf, &ps_dec->as_recent_fld[1][1],
532
770
                ps_dec->u2_frame_width);
533
770
        }
534
535
5.47k
        ps_dec->as_ref_buf[FORW][TOP]    = ps_dec->as_recent_fld[1][0];
536
5.47k
        ps_dec->as_ref_buf[FORW][BOTTOM] = ps_dec->as_recent_fld[1][1];
537
538
539
5.47k
    }
540
22.9k
    else if(ps_dec->e_pic_type == B_PIC)
541
6.68k
    {
542
6.68k
        if((NULL == ps_dec->as_recent_fld[1][0].pu1_y) && (NULL == ps_dec->as_recent_fld[0][0].pu1_y))
543
760
        {
544
            // assign the current picture to both
545
760
            ps_dec->as_recent_fld[1][0] = ps_dec->s_cur_frm_buf;
546
760
            impeg2d_get_bottom_field_buf(&ps_dec->s_cur_frm_buf, &ps_dec->as_recent_fld[1][1],
547
760
                ps_dec->u2_frame_width);
548
760
            ps_dec->as_recent_fld[0][0] = ps_dec->s_cur_frm_buf;
549
760
            ps_dec->as_recent_fld[0][1] = ps_dec->as_recent_fld[1][1];
550
760
        }
551
        //Assign the non-null picture to the null picture
552
5.92k
        else if ((NULL != ps_dec->as_recent_fld[1][0].pu1_y) && (NULL == ps_dec->as_recent_fld[0][0].pu1_y))
553
148
        {
554
148
            ps_dec->as_recent_fld[0][0] = ps_dec->as_recent_fld[1][0];
555
148
            ps_dec->as_recent_fld[0][1] = ps_dec->as_recent_fld[1][1];
556
148
        }
557
5.77k
        else if ((NULL == ps_dec->as_recent_fld[1][0].pu1_y) && (NULL != ps_dec->as_recent_fld[0][0].pu1_y))
558
0
        {
559
0
            ps_dec->as_recent_fld[1][0] = ps_dec->as_recent_fld[0][0];
560
0
            ps_dec->as_recent_fld[1][1] = ps_dec->as_recent_fld[0][1];
561
0
        }
562
563
        /* Error resilience: If forward and backward pictures are going to be NULL*/
564
        /* then assign both to the current                                        */
565
        /* if one of them NULL then we will assign the non null to the NULL one   */
566
567
6.68k
        if((NULL == ps_dec->as_recent_fld[0][1].pu1_y) && (NULL == ps_dec->as_recent_fld[1][1].pu1_y))
568
26
        {
569
            // assign the current picture to both
570
26
            ps_dec->as_recent_fld[1][0] = ps_dec->s_cur_frm_buf;
571
26
            impeg2d_get_bottom_field_buf(&ps_dec->s_cur_frm_buf, &ps_dec->as_recent_fld[1][1],
572
26
                                         ps_dec->u2_frame_width);
573
26
            ps_dec->as_recent_fld[0][0] = ps_dec->s_cur_frm_buf;
574
26
            ps_dec->as_recent_fld[0][1] = ps_dec->as_recent_fld[1][1];
575
26
        }
576
        //Assign the non-null picture to the null picture
577
578
6.66k
        else if((NULL == ps_dec->as_recent_fld[0][1].pu1_y) && (NULL != ps_dec->as_recent_fld[1][1].pu1_y))
579
9
        {
580
9
            ps_dec->as_recent_fld[0][0] = ps_dec->as_recent_fld[1][0];
581
9
            ps_dec->as_recent_fld[0][1] = ps_dec->as_recent_fld[1][1];
582
9
        }
583
584
6.65k
        else if((NULL == ps_dec->as_recent_fld[1][1].pu1_y) && (NULL != ps_dec->as_recent_fld[0][1].pu1_y))
585
0
        {
586
0
            ps_dec->as_recent_fld[1][0] = ps_dec->as_recent_fld[0][0];
587
0
            ps_dec->as_recent_fld[1][1] = ps_dec->as_recent_fld[0][1];
588
0
        }
589
6.68k
        ps_dec->as_ref_buf[FORW][TOP]    = ps_dec->as_recent_fld[0][0];
590
6.68k
        ps_dec->as_ref_buf[FORW][BOTTOM] = ps_dec->as_recent_fld[0][1];
591
6.68k
        ps_dec->as_ref_buf[BACK][TOP]    = ps_dec->as_recent_fld[1][0];
592
6.68k
        ps_dec->as_ref_buf[BACK][BOTTOM] = ps_dec->as_recent_fld[1][1];
593
594
595
6.68k
    }
596
597
28.4k
    return e_error;
598
28.4k
}
599
600
/*******************************************************************************
601
*
602
*  Function Name   : impeg2d_post_pic_dec_proc
603
*
604
*  Description     : Performs processing that is needed at the end of picture
605
*                    decode
606
*
607
*  Arguments       :
608
*  dec             : Decoder context
609
*
610
*  Values Returned : None
611
*******************************************************************************/
612
void impeg2d_post_pic_dec_proc(dec_state_t *ps_dec)
613
28.4k
{
614
615
28.4k
   WORD32 u4_update_pic_buf = 0;
616
    /*************************************************************************/
617
    /* Processing at the end of picture                                      */
618
    /*************************************************************************/
619
28.4k
    if(ps_dec->u2_picture_structure != FRAME_PICTURE)
620
5.56k
    {
621
5.56k
        ps_dec->u2_num_vert_mb       = (ps_dec->u2_vertical_size + 31) >> 5;
622
623
5.56k
        if(ps_dec->u2_num_flds_decoded == 1)
624
2.23k
        {
625
2.23k
            ps_dec->u2_num_flds_decoded = 0;
626
2.23k
            u4_update_pic_buf = 1;
627
2.23k
        }
628
3.32k
        else
629
3.32k
        {
630
3.32k
            ps_dec->u2_num_flds_decoded = 1;
631
3.32k
        }
632
5.56k
    }
633
22.8k
    else
634
22.8k
    {
635
22.8k
        u4_update_pic_buf = 1;
636
22.8k
    }
637
638
28.4k
    if(u4_update_pic_buf)
639
25.1k
    {
640
25.1k
        ps_dec->i4_frame_decoded = 1;
641
25.1k
        if(ps_dec->e_pic_type != B_PIC)
642
19.1k
        {
643
            /* In any sequence first two pictures have to be reference pictures */
644
            /* Adding of first picture in the sequence */
645
19.1k
            if(ps_dec->aps_ref_pics[0] == NULL)
646
4.97k
            {
647
4.97k
                ps_dec->aps_ref_pics[0] = ps_dec->ps_cur_pic;
648
4.97k
            }
649
650
            /* Adding of second picture in the sequence */
651
14.2k
            else if(ps_dec->aps_ref_pics[1] == NULL)
652
1.64k
            {
653
1.64k
                ps_dec->aps_ref_pics[1] = ps_dec->ps_cur_pic;
654
1.64k
                impeg2_disp_mgr_add(&ps_dec->s_disp_mgr, ps_dec->aps_ref_pics[0], ps_dec->aps_ref_pics[0]->i4_buf_id);
655
1.64k
            }
656
12.5k
            else
657
12.5k
            {
658
659
12.5k
                impeg2_disp_mgr_add(&ps_dec->s_disp_mgr, ps_dec->aps_ref_pics[1], ps_dec->aps_ref_pics[1]->i4_buf_id);
660
12.5k
                impeg2_buf_mgr_release(ps_dec->pv_pic_buf_mg, ps_dec->aps_ref_pics[0]->i4_buf_id, BUF_MGR_REF);
661
12.5k
                ps_dec->aps_ref_pics[0] = ps_dec->aps_ref_pics[1];
662
12.5k
                ps_dec->aps_ref_pics[1] = ps_dec->ps_cur_pic;
663
664
12.5k
            }
665
19.1k
        }
666
5.94k
        else
667
5.94k
        {
668
5.94k
            impeg2_disp_mgr_add(&ps_dec->s_disp_mgr, ps_dec->ps_cur_pic, ps_dec->ps_cur_pic->i4_buf_id);
669
670
5.94k
            impeg2_buf_mgr_release(ps_dec->pv_pic_buf_mg, ps_dec->ps_cur_pic->i4_buf_id, BUF_MGR_REF);
671
5.94k
        }
672
673
25.1k
    }
674
    /*************************************************************************/
675
    /* Update the list of recent reference pictures                          */
676
    /*************************************************************************/
677
28.4k
    if(ps_dec->e_pic_type != B_PIC)
678
21.7k
    {
679
21.7k
        switch(ps_dec->u2_picture_structure)
680
21.7k
        {
681
17.3k
        case FRAME_PICTURE:
682
17.3k
            {
683
17.3k
                ps_dec->as_recent_fld[0][0] = ps_dec->as_recent_fld[1][0];
684
17.3k
                ps_dec->as_recent_fld[0][1] = ps_dec->as_recent_fld[1][1];
685
686
17.3k
                ps_dec->as_recent_fld[1][0] = ps_dec->s_cur_frm_buf;
687
17.3k
                impeg2d_get_bottom_field_buf(&ps_dec->s_cur_frm_buf, &ps_dec->as_recent_fld[1][1],
688
17.3k
                ps_dec->u2_frame_width);
689
17.3k
                break;
690
0
            }
691
3.53k
        case TOP_FIELD:
692
3.53k
            {
693
3.53k
                ps_dec->as_recent_fld[0][0] = ps_dec->as_recent_fld[1][0];
694
3.53k
                ps_dec->as_recent_fld[1][0] = ps_dec->s_cur_frm_buf;
695
3.53k
                break;
696
0
            }
697
905
        case BOTTOM_FIELD:
698
905
            {
699
905
                ps_dec->as_recent_fld[0][1] = ps_dec->as_recent_fld[1][1];
700
905
                impeg2d_get_bottom_field_buf(&ps_dec->s_cur_frm_buf, &ps_dec->as_recent_fld[1][1],
701
905
                ps_dec->u2_frame_width);
702
905
                break;
703
0
            }
704
21.7k
        }
705
21.7k
    }
706
28.4k
}