Coverage Report

Created: 2026-09-03 07:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/decoder/svc/isvcd_utils.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2022 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
23
 *  isvcd_utils.c
24
 *
25
 * @brief
26
 *  Contains routines that handle of start and end of pic processing
27
 *
28
 * @author
29
 *  Kishore
30
 *
31
 * @remarks
32
 *  None
33
 *
34
 *******************************************************************************
35
 */
36
37
#include <string.h>
38
#include "ih264_typedefs.h"
39
#include "ithread.h"
40
#include "ih264d_deblocking.h"
41
#include "ih264d_parse_slice.h"
42
#include "ih264d_parse_cavlc.h"
43
#include "ih264d_dpb_manager.h"
44
#include "ih264d_defs.h"
45
#include "isvcd_structs.h"
46
#include "ih264d_mem_request.h"
47
#include "ih264_typedefs.h"
48
#include "ih264_macros.h"
49
#include "ih264_platform_macros.h"
50
#include "ih264d_tables.h"
51
#include "ih264d_debug.h"
52
#include "ih264d_mb_utils.h"
53
#include "ih264d_error_handler.h"
54
#include "ih264d_dpb_manager.h"
55
#include "ih264d_utils.h"
56
#include "ih264d_defs.h"
57
#include "ih264d_tables.h"
58
#include "ih264d_inter_pred.h"
59
#include "ih264d_dpb_manager.h"
60
#include "iv.h"
61
#include "ivd.h"
62
#include "ih264d_format_conv.h"
63
#include "ih264_error.h"
64
#include "ih264_disp_mgr.h"
65
#include "ih264_buf_mgr.h"
66
#include "ih264d_utils.h"
67
68
WORD32 ih264d_init_dec_mb_grp(dec_struct_t *ps_dec);
69
/*!
70
**************************************************************************
71
* \if Function name : isvcd_free_dynamic_bufs \endif
72
*
73
* \brief
74
*    This function frees dynamic memory allocated by Decoder.
75
*
76
* \param ps_dec: Pointer to dec_struct_t.
77
*
78
* \return
79
*    Returns i4_status as returned by MemManager.
80
*
81
**************************************************************************
82
*/
83
WORD16 isvcd_free_dynamic_bufs(svc_dec_lyr_struct_t *ps_svc_lyr_dec)
84
147k
{
85
147k
    WORD32 i;
86
147k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
87
    /* Free any avc dynamic buffers that are allocated */
88
147k
    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->pu1_bits_buf_dynamic);
89
147k
    ih264d_free_dynamic_bufs(ps_dec);
90
147k
    PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->pu1_crop_wnd_flag);
91
147k
    PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->ps_inter_lyr_mb_prms_base);
92
147k
    PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->ps_il_pred_mv_bank_buf_base);
93
147k
    PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->pi2_il_residual_resample_luma_base);
94
147k
    PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->pi2_il_residual_resample_chroma_base);
95
147k
    PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->ps_svc_frm_mb_info);
96
147k
    PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->pu2_frm_res_luma_csbp);
97
147k
    PS_DEC_ALIGNED_FREE(ps_dec, ps_svc_lyr_dec->pu1_svc_base_mode_flag);
98
99
147k
    memset(ps_dec->ps_pic_buf_base, 0, sizeof(struct pic_buffer_t) * (H264_MAX_REF_PICS * 2));
100
9.57M
    for(i = 0; i < MAX_DISP_BUFS_NEW; i++)
101
9.42M
    {
102
9.42M
        ps_dec->apv_buf_id_pic_buf_map[i] = NULL;
103
9.42M
    }
104
147k
    return 0;
105
147k
}
106
107
/*!
108
**************************************************************************
109
* \if Function name : isvcd_allocate_dynamic_bufs \endif
110
*
111
* \brief
112
*    This function allocates memory required by Decoder.
113
*
114
* \param ps_dec: Pointer to dec_struct_t.
115
*
116
* \return
117
*    Returns i4_status as returned by MemManager.
118
*
119
**************************************************************************
120
*/
121
122
WORD16 isvcd_allocate_dynamic_bufs(svc_dec_lyr_struct_t *ps_svc_lyr_dec)
123
23.8k
{
124
23.8k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
125
23.8k
    WORD16 i16_status = 0;
126
23.8k
    UWORD8 uc_frmOrFld = (1 - ps_dec->ps_cur_sps->u1_frame_mbs_only_flag);
127
23.8k
    dec_seq_params_t *ps_sps = ps_dec->ps_cur_sps;
128
23.8k
    UWORD32 u4_total_mbs = ps_sps->u4_total_num_of_mbs << uc_frmOrFld;
129
23.8k
    WORD32 size;
130
23.8k
    void *pv_buf;
131
23.8k
    void *pv_mem_ctxt = ps_dec->pv_mem_ctxt;
132
23.8k
    size = u4_total_mbs;
133
134
23.8k
    i16_status = ih264d_allocate_dynamic_bufs(ps_dec);
135
136
23.8k
    if(i16_status != OK)
137
0
    {
138
        /* Free any dynamic buffers that are allocated */
139
0
        ih264d_free_dynamic_bufs(ps_dec);
140
0
        ps_dec->i4_error_code = IVD_MEM_ALLOC_FAILED;
141
0
        return IVD_MEM_ALLOC_FAILED;
142
0
    }
143
23.8k
    if(u4_total_mbs == 0)
144
0
    {
145
0
        return IVD_MEM_ALLOC_FAILED;
146
0
    }
147
148
    /* Allocate frame level mb info */
149
23.8k
    size = sizeof(dec_svc_mb_info_t) * u4_total_mbs;
150
23.8k
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
151
23.8k
    RETURN_IF((NULL == pv_buf), IV_FAIL);
152
23.8k
    ps_svc_lyr_dec->ps_svc_frm_mb_info = pv_buf;
153
23.8k
    memset(ps_svc_lyr_dec->ps_svc_frm_mb_info, 0, size);
154
155
    /* Allocate frame level residual luma csbp info */
156
23.8k
    size = sizeof(UWORD16) * u4_total_mbs;
157
23.8k
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
158
23.8k
    RETURN_IF((NULL == pv_buf), IV_FAIL);
159
23.8k
    ps_svc_lyr_dec->pu2_frm_res_luma_csbp = pv_buf;
160
23.8k
    memset(ps_svc_lyr_dec->pu2_frm_res_luma_csbp, 0, size);
161
23.8k
    ps_svc_lyr_dec->i4_frm_res_luma_csbp_stride = ps_dec->u2_frm_wd_in_mbs;
162
163
    /* Allocate frame level residual luma csbp info */
164
23.8k
    size = sizeof(UWORD8) * u4_total_mbs;
165
23.8k
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
166
23.8k
    RETURN_IF((NULL == pv_buf), IV_FAIL);
167
23.8k
    ps_svc_lyr_dec->pu1_svc_base_mode_flag = pv_buf;
168
23.8k
    memset(ps_svc_lyr_dec->pu1_svc_base_mode_flag, 0, size);
169
23.8k
    ps_svc_lyr_dec->i4_frm_svc_base_mode_cabac_stride = ps_dec->u2_frm_wd_in_mbs;
170
23.8k
    ps_svc_lyr_dec->i4_frm_svc_base_mode_cabac_size = u4_total_mbs;
171
172
    /* Allocate frame level crop windows flags */
173
23.8k
    size = sizeof(UWORD8) * u4_total_mbs;
174
23.8k
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
175
23.8k
    RETURN_IF((NULL == pv_buf), IV_FAIL);
176
23.8k
    ps_svc_lyr_dec->pu1_crop_wnd_flag = pv_buf;
177
23.8k
    memset(ps_svc_lyr_dec->pu1_crop_wnd_flag, 0, size);
178
179
    /**********************************/
180
    /*Creation of Inter layer buffers */
181
    /**********************************/
182
183
    /* MB type buffer : one element per MB */
184
23.8k
    size = (ps_dec->u2_frm_wd_in_mbs + 2) * (ps_dec->u2_frm_ht_in_mbs + 2) *
185
23.8k
           sizeof(inter_lyr_mb_prms_t);
186
23.8k
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
187
23.8k
    RETURN_IF((NULL == pv_buf), IV_FAIL);
188
23.8k
    memset(pv_buf, -1, size);
189
23.8k
    ps_svc_lyr_dec->ps_inter_lyr_mb_prms_base = pv_buf;
190
23.8k
    ps_svc_lyr_dec->u2_inter_lyr_mb_prms_stride = ps_dec->u2_frm_wd_in_mbs + 2;
191
23.8k
    ps_svc_lyr_dec->ps_inter_lyr_mb_prms_frm_start =
192
23.8k
        ps_svc_lyr_dec->ps_inter_lyr_mb_prms_base + 1 + ps_svc_lyr_dec->u2_inter_lyr_mb_prms_stride;
193
194
23.8k
    ps_svc_lyr_dec->u4_inter_lyr_mb_prms_size = (ps_dec->u2_frm_wd_in_mbs + 2) *
195
23.8k
                                                (ps_dec->u2_frm_ht_in_mbs + 2) *
196
23.8k
                                                sizeof(inter_lyr_mb_prms_t);
197
198
    /* Luma Residual data at each layer : dafault 0*/
199
23.8k
    size = ((ps_dec->u2_pic_wd + 4) * (ps_dec->u2_pic_ht + 4)) * sizeof(WORD16);
200
23.8k
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
201
23.8k
    RETURN_IF((NULL == pv_buf), IV_FAIL);
202
23.8k
    memset(pv_buf, 0, size);
203
23.8k
    ps_svc_lyr_dec->pi2_il_residual_resample_luma_base = pv_buf;
204
23.8k
    ps_svc_lyr_dec->u2_residual_resample_luma_stride = (ps_dec->u2_pic_wd + 4);
205
23.8k
    ps_svc_lyr_dec->pi2_il_residual_resample_mb_luma_frm_start =
206
23.8k
        ps_svc_lyr_dec->pi2_il_residual_resample_luma_base + 2 +
207
23.8k
        (2 * ps_svc_lyr_dec->u2_residual_resample_luma_stride);
208
23.8k
    ps_svc_lyr_dec->u4_residual_resample_luma_size =
209
23.8k
        ((ps_dec->u2_pic_wd + 4) * (ps_dec->u2_pic_ht + 4)) * sizeof(WORD16);
210
211
    /* Chroma Residual data at each layer : dafault 0*/
212
23.8k
    size = (((4 + ps_dec->u2_pic_wd) * ((4 + ps_dec->u2_pic_ht) >> 1)) * sizeof(WORD16));
213
23.8k
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
214
23.8k
    RETURN_IF((NULL == pv_buf), IV_FAIL);
215
23.8k
    memset(pv_buf, 0, size);
216
23.8k
    ps_svc_lyr_dec->pi2_il_residual_resample_chroma_base = pv_buf;
217
23.8k
    ps_svc_lyr_dec->u2_residual_resample_chroma_stride = (ps_dec->u2_pic_wd + 4);
218
23.8k
    ps_svc_lyr_dec->pi2_il_residual_resample_mb_chroma_frm_start =
219
23.8k
        ps_svc_lyr_dec->pi2_il_residual_resample_chroma_base + 2 +
220
23.8k
        ps_svc_lyr_dec->u2_residual_resample_chroma_stride;
221
23.8k
    ps_svc_lyr_dec->u4_residual_resample_chroma_size =
222
23.8k
        (((4 + ps_dec->u2_pic_wd) * ((4 + ps_dec->u2_pic_ht) >> 1)) * sizeof(WORD16));
223
224
    /* mv bank buffer : 16 elements per MB: each at 4x4 block level */
225
23.8k
    size = ((ps_dec->u2_pic_wd) * (ps_dec->u2_pic_ht >> 4)) * sizeof(mv_pred_t);
226
23.8k
    pv_buf = ps_dec->pf_aligned_alloc(pv_mem_ctxt, 128, size);
227
23.8k
    RETURN_IF((NULL == pv_buf), IV_FAIL);
228
23.8k
    memset(pv_buf, 0, size);
229
23.8k
    ps_svc_lyr_dec->ps_il_pred_mv_bank_buf_base = pv_buf;
230
231
    /*syntax for SVC related bin ctxt tables*/
232
23.8k
    {
233
23.8k
        bin_ctxt_model_t *const p_cabac_ctxt_table_t = ps_dec->p_cabac_ctxt_table_t;
234
235
23.8k
        ps_svc_lyr_dec->ps_base_mode_flag = p_cabac_ctxt_table_t + CABAC_BASE_MODE_FLAG;
236
23.8k
        ps_svc_lyr_dec->ps_motion_prediction_flag_l0 = p_cabac_ctxt_table_t + CABAC_MOT_PRED_FLAG0;
237
23.8k
        ps_svc_lyr_dec->ps_motion_prediction_flag_l1 = p_cabac_ctxt_table_t + CABAC_MOT_PRED_FLAG1;
238
23.8k
        ps_svc_lyr_dec->ps_residual_prediction_flag = p_cabac_ctxt_table_t + CABAC_RES_PRED_FLAG;
239
23.8k
    }
240
23.8k
    return (i16_status);
241
23.8k
}
242
243
/*!
244
**************************************************************************
245
* \if Function name : isvcd_decode_pic_order_cnt \endif
246
*
247
* \brief
248
*    Calculates picture order count of picture.
249
*
250
* \return
251
*    Returns the pic order count of the picture to which current
252
*    Slice belongs.
253
*
254
**************************************************************************
255
*/
256
WORD32 isvcd_decode_pic_order_cnt(
257
    UWORD8 u1_is_idr_slice, UWORD32 u2_frame_num, pocstruct_t *ps_prev_poc, pocstruct_t *ps_cur_poc,
258
    dec_slice_params_t *ps_cur_slice, /*!< Pointer to current slice Params*/
259
    dec_pic_params_t *ps_pps, UWORD8 u1_nal_ref_idc, UWORD8 u1_bottom_field_flag,
260
    UWORD8 u1_field_pic_flag, WORD32 *pi4_poc, dec_struct_t *ps_dec)
261
142k
{
262
142k
    WORD64 i8_pic_msb;
263
142k
    WORD32 i4_top_field_order_cnt = 0, i4_bottom_field_order_cnt = 0;
264
142k
    dec_seq_params_t *ps_seq = ps_dec->ps_cur_sps;
265
142k
    WORD32 i4_prev_frame_num_ofst;
266
267
142k
    switch(ps_seq->u1_pic_order_cnt_type)
268
142k
    {
269
111k
        case 0:
270
            /* POC TYPE 0 */
271
111k
            if(u1_is_idr_slice)
272
100k
            {
273
100k
                ps_prev_poc->i4_pic_order_cnt_msb = 0;
274
100k
                ps_prev_poc->i4_pic_order_cnt_lsb = 0;
275
100k
            }
276
111k
            if(ps_prev_poc->u1_mmco_equalto5)
277
1.07k
            {
278
1.07k
                if(ps_prev_poc->u1_bot_field != 1)
279
1.07k
                {
280
1.07k
                    ps_prev_poc->i4_pic_order_cnt_msb = 0;
281
1.07k
                    ps_prev_poc->i4_pic_order_cnt_lsb = ps_prev_poc->i4_top_field_order_count;
282
1.07k
                }
283
0
                else
284
0
                {
285
0
                    ps_prev_poc->i4_pic_order_cnt_msb = 0;
286
0
                    ps_prev_poc->i4_pic_order_cnt_lsb = 0;
287
0
                }
288
1.07k
            }
289
290
111k
            if((ps_cur_poc->i4_pic_order_cnt_lsb < ps_prev_poc->i4_pic_order_cnt_lsb) &&
291
3.96k
               ((ps_prev_poc->i4_pic_order_cnt_lsb - ps_cur_poc->i4_pic_order_cnt_lsb) >=
292
3.96k
                (ps_seq->i4_max_pic_order_cntLsb >> 1)))
293
2.66k
            {
294
2.66k
                i8_pic_msb =
295
2.66k
                    (WORD64) ps_prev_poc->i4_pic_order_cnt_msb + ps_seq->i4_max_pic_order_cntLsb;
296
2.66k
            }
297
109k
            else if((ps_cur_poc->i4_pic_order_cnt_lsb > ps_prev_poc->i4_pic_order_cnt_lsb) &&
298
81.5k
                    ((ps_cur_poc->i4_pic_order_cnt_lsb - ps_prev_poc->i4_pic_order_cnt_lsb) >=
299
81.5k
                     (ps_seq->i4_max_pic_order_cntLsb >> 1)))
300
47.4k
            {
301
47.4k
                i8_pic_msb =
302
47.4k
                    (WORD64) ps_prev_poc->i4_pic_order_cnt_msb - ps_seq->i4_max_pic_order_cntLsb;
303
47.4k
            }
304
61.7k
            else
305
61.7k
            {
306
61.7k
                i8_pic_msb = ps_prev_poc->i4_pic_order_cnt_msb;
307
61.7k
            }
308
309
111k
            if(!u1_field_pic_flag || !u1_bottom_field_flag)
310
111k
            {
311
111k
                WORD64 i8_result = i8_pic_msb + ps_cur_poc->i4_pic_order_cnt_lsb;
312
111k
                if(IS_OUT_OF_RANGE_S32(i8_result))
313
0
                {
314
0
                    return ERROR_INV_POC;
315
0
                }
316
111k
                i4_top_field_order_cnt = (WORD32) i8_result;
317
111k
            }
318
319
111k
            if(!u1_field_pic_flag)
320
111k
            {
321
111k
                WORD64 i8_result =
322
111k
                    (WORD64) i4_top_field_order_cnt + ps_cur_poc->i4_delta_pic_order_cnt_bottom;
323
111k
                if(IS_OUT_OF_RANGE_S32(i8_result))
324
142
                {
325
142
                    return ERROR_INV_POC;
326
142
                }
327
111k
                i4_bottom_field_order_cnt = (WORD32) i8_result;
328
111k
            }
329
0
            else if(u1_bottom_field_flag)
330
0
            {
331
0
                WORD64 i8_result = i8_pic_msb + ps_cur_poc->i4_pic_order_cnt_lsb;
332
0
                if(IS_OUT_OF_RANGE_S32(i8_result))
333
0
                {
334
0
                    return ERROR_INV_POC;
335
0
                }
336
0
                i4_bottom_field_order_cnt = (WORD32) i8_result;
337
0
            }
338
339
111k
            if(IS_OUT_OF_RANGE_S32(i8_pic_msb))
340
0
            {
341
0
                return ERROR_INV_POC;
342
0
            }
343
111k
            ps_cur_poc->i4_pic_order_cnt_msb = (WORD32) i8_pic_msb;
344
111k
            break;
345
346
26.7k
        case 1:
347
26.7k
        {
348
            /* POC TYPE 1 */
349
26.7k
            UWORD8 i;
350
26.7k
            WORD32 prev_frame_num;
351
26.7k
            WORD32 frame_num_ofst;
352
26.7k
            WORD32 abs_frm_num;
353
26.7k
            WORD32 poc_cycle_cnt, frame_num_in_poc_cycle;
354
26.7k
            WORD64 i8_expected_delta_poc_cycle;
355
26.7k
            WORD32 expected_poc;
356
26.7k
            WORD64 i8_result;
357
358
26.7k
            prev_frame_num = (WORD32) ps_cur_slice->u2_frame_num;
359
26.7k
            if(!u1_is_idr_slice)
360
11.8k
            {
361
11.8k
                if(ps_cur_slice->u1_mmco_equalto5)
362
1.09k
                {
363
1.09k
                    prev_frame_num = 0;
364
1.09k
                    i4_prev_frame_num_ofst = 0;
365
1.09k
                }
366
10.7k
                else
367
10.7k
                {
368
10.7k
                    i4_prev_frame_num_ofst = ps_prev_poc->i4_prev_frame_num_ofst;
369
10.7k
                }
370
11.8k
            }
371
14.9k
            else
372
14.9k
                i4_prev_frame_num_ofst = 0;
373
374
            /* 1. Derivation for FrameNumOffset */
375
26.7k
            if(u1_is_idr_slice)
376
14.9k
            {
377
14.9k
                frame_num_ofst = 0;
378
14.9k
                ps_cur_poc->i4_delta_pic_order_cnt[0] = 0;
379
14.9k
                ps_cur_poc->i4_delta_pic_order_cnt[1] = 0;
380
14.9k
            }
381
11.8k
            else if(prev_frame_num > ((WORD32) u2_frame_num))
382
4.93k
            {
383
4.93k
                WORD64 i8_result =
384
4.93k
                    i4_prev_frame_num_ofst + (WORD64) ps_seq->u2_u4_max_pic_num_minus1 + 1;
385
4.93k
                if(IS_OUT_OF_RANGE_S32(i8_result))
386
75
                {
387
75
                    return ERROR_INV_FRAME_NUM;
388
75
                }
389
4.85k
                frame_num_ofst = (WORD32) i8_result;
390
4.85k
            }
391
6.87k
            else
392
6.87k
                frame_num_ofst = i4_prev_frame_num_ofst;
393
394
            /* 2. Derivation for absFrameNum */
395
26.6k
            if(0 != ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle)
396
16.3k
            {
397
16.3k
                WORD64 i8_result = frame_num_ofst + (WORD64) u2_frame_num;
398
16.3k
                if(IS_OUT_OF_RANGE_S32(i8_result))
399
0
                {
400
0
                    return ERROR_INV_FRAME_NUM;
401
0
                }
402
16.3k
                abs_frm_num = (WORD32) i8_result;
403
16.3k
            }
404
10.2k
            else
405
10.2k
                abs_frm_num = 0;
406
26.6k
            if((u1_nal_ref_idc == 0) && (abs_frm_num > 0)) abs_frm_num = abs_frm_num - 1;
407
408
            /* 4. expectedDeltaPerPicOrderCntCycle is derived as */
409
26.6k
            i8_expected_delta_poc_cycle = 0;
410
141k
            for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle; i++)
411
115k
            {
412
115k
                i8_expected_delta_poc_cycle += ps_seq->i4_ofst_for_ref_frame[i];
413
115k
            }
414
415
            /* 3. When absFrameNum > 0, picOrderCntCycleCnt and
416
            frame_num_in_poc_cycle are derived as : */
417
            /* 5. expectedPicOrderCnt is derived as : */
418
26.6k
            if(abs_frm_num > 0)
419
16.2k
            {
420
16.2k
                poc_cycle_cnt =
421
16.2k
                    DIV((abs_frm_num - 1), ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
422
16.2k
                frame_num_in_poc_cycle =
423
16.2k
                    MOD((abs_frm_num - 1), ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
424
425
16.2k
                i8_result = poc_cycle_cnt * i8_expected_delta_poc_cycle;
426
427
79.2k
                for(i = 0; i <= frame_num_in_poc_cycle; i++)
428
62.9k
                {
429
62.9k
                    i8_result = i8_result + ps_seq->i4_ofst_for_ref_frame[i];
430
62.9k
                }
431
432
16.2k
                if(IS_OUT_OF_RANGE_S32(i8_result)) return ERROR_INV_POC;
433
434
15.9k
                expected_poc = (WORD32) i8_result;
435
15.9k
            }
436
10.3k
            else
437
10.3k
                expected_poc = 0;
438
439
26.3k
            if(u1_nal_ref_idc == 0)
440
3.72k
            {
441
3.72k
                i8_result = (WORD64) expected_poc + ps_seq->i4_ofst_for_non_ref_pic;
442
443
3.72k
                if(IS_OUT_OF_RANGE_S32(i8_result)) return ERROR_INV_POC;
444
445
3.52k
                expected_poc = (WORD32) i8_result;
446
3.52k
            }
447
448
            /* 6. TopFieldOrderCnt or BottomFieldOrderCnt are derived as */
449
26.1k
            if(!u1_field_pic_flag)
450
26.1k
            {
451
26.1k
                i8_result = (WORD64) expected_poc + ps_cur_poc->i4_delta_pic_order_cnt[0];
452
453
26.1k
                if(IS_OUT_OF_RANGE_S32(i8_result)) return ERROR_INV_POC;
454
25.9k
                i4_top_field_order_cnt = (WORD32) i8_result;
455
456
25.9k
                i8_result = (WORD64) i4_top_field_order_cnt +
457
25.9k
                            ps_seq->i4_ofst_for_top_to_bottom_field +
458
25.9k
                            ps_cur_poc->i4_delta_pic_order_cnt[1];
459
460
25.9k
                if(IS_OUT_OF_RANGE_S32(i8_result)) return ERROR_INV_POC;
461
25.7k
                i4_bottom_field_order_cnt = (WORD32) i8_result;
462
25.7k
            }
463
0
            else if(!u1_bottom_field_flag)
464
0
            {
465
0
                i8_result = (WORD64) expected_poc + ps_cur_poc->i4_delta_pic_order_cnt[0];
466
467
0
                if(IS_OUT_OF_RANGE_S32(i8_result)) return ERROR_INV_POC;
468
0
                i4_top_field_order_cnt = (WORD32) i8_result;
469
0
            }
470
0
            else
471
0
            {
472
0
                i8_result = (WORD64) expected_poc + ps_seq->i4_ofst_for_top_to_bottom_field +
473
0
                            ps_cur_poc->i4_delta_pic_order_cnt[0];
474
475
0
                if(IS_OUT_OF_RANGE_S32(i8_result)) return ERROR_INV_POC;
476
0
                i4_bottom_field_order_cnt = (WORD32) i8_result;
477
0
            }
478
            /* Copy the current POC info into Previous POC structure */
479
25.7k
            ps_cur_poc->i4_prev_frame_num_ofst = frame_num_ofst;
480
25.7k
        }
481
482
0
        break;
483
3.68k
        case 2:
484
3.68k
        {
485
            /* POC TYPE 2 */
486
3.68k
            WORD32 prev_frame_num;
487
3.68k
            WORD32 frame_num_ofst;
488
3.68k
            WORD32 tmp_poc;
489
490
3.68k
            prev_frame_num = (WORD32) ps_cur_slice->u2_frame_num;
491
3.68k
            if(!u1_is_idr_slice)
492
1.65k
            {
493
1.65k
                if(ps_cur_slice->u1_mmco_equalto5)
494
451
                {
495
451
                    prev_frame_num = 0;
496
451
                    i4_prev_frame_num_ofst = 0;
497
451
                }
498
1.20k
                else
499
1.20k
                    i4_prev_frame_num_ofst = ps_prev_poc->i4_prev_frame_num_ofst;
500
1.65k
            }
501
2.03k
            else
502
2.03k
                i4_prev_frame_num_ofst = 0;
503
504
            /* 1. Derivation for FrameNumOffset */
505
3.68k
            if(u1_is_idr_slice)
506
2.03k
            {
507
2.03k
                frame_num_ofst = 0;
508
2.03k
                ps_cur_poc->i4_delta_pic_order_cnt[0] = 0;
509
2.03k
                ps_cur_poc->i4_delta_pic_order_cnt[1] = 0;
510
2.03k
            }
511
1.65k
            else if(prev_frame_num > ((WORD32) u2_frame_num))
512
569
            {
513
569
                WORD64 i8_result =
514
569
                    i4_prev_frame_num_ofst + (WORD64) ps_seq->u2_u4_max_pic_num_minus1 + 1;
515
569
                if(IS_OUT_OF_RANGE_S32(i8_result))
516
85
                {
517
85
                    return ERROR_INV_FRAME_NUM;
518
85
                }
519
484
                frame_num_ofst = (WORD32) i8_result;
520
484
            }
521
1.08k
            else
522
1.08k
                frame_num_ofst = i4_prev_frame_num_ofst;
523
524
            /* 2. Derivation for tempPicOrderCnt */
525
3.60k
            if(u1_is_idr_slice)
526
2.03k
                tmp_poc = 0;
527
1.57k
            else if(u1_nal_ref_idc == 0)
528
428
            {
529
428
                WORD64 i8_result = ((frame_num_ofst + (WORD64) u2_frame_num) << 1) - 1;
530
428
                if(IS_OUT_OF_RANGE_S32(i8_result))
531
0
                {
532
0
                    return ERROR_INV_POC;
533
0
                }
534
428
                tmp_poc = (WORD32) i8_result;
535
428
            }
536
1.14k
            else
537
1.14k
            {
538
1.14k
                WORD64 i8_result = (frame_num_ofst + (WORD64) u2_frame_num) << 1;
539
1.14k
                if(IS_OUT_OF_RANGE_S32(i8_result))
540
0
                {
541
0
                    return ERROR_INV_POC;
542
0
                }
543
1.14k
                tmp_poc = (WORD32) i8_result;
544
1.14k
            }
545
546
            /* 6. TopFieldOrderCnt or BottomFieldOrderCnt are derived as */
547
3.60k
            if(!u1_field_pic_flag)
548
3.60k
            {
549
3.60k
                i4_top_field_order_cnt = tmp_poc;
550
3.60k
                i4_bottom_field_order_cnt = tmp_poc;
551
3.60k
            }
552
0
            else if(!u1_bottom_field_flag)
553
0
                i4_top_field_order_cnt = tmp_poc;
554
0
            else
555
0
                i4_bottom_field_order_cnt = tmp_poc;
556
557
            /* Copy the current POC info into Previous POC structure */
558
3.60k
            ps_prev_poc->i4_prev_frame_num_ofst = frame_num_ofst;
559
3.60k
            ps_cur_poc->i4_prev_frame_num_ofst = frame_num_ofst;
560
3.60k
        }
561
0
        break;
562
0
        default:
563
0
            return ERROR_INV_POC_TYPE_T;
564
0
            break;
565
142k
    }
566
567
141k
    if(!u1_field_pic_flag)  // or a complementary field pair
568
141k
    {
569
141k
        *pi4_poc = MIN(i4_top_field_order_cnt, i4_bottom_field_order_cnt);
570
141k
        ps_pps->i4_top_field_order_cnt = i4_top_field_order_cnt;
571
141k
        ps_pps->i4_bottom_field_order_cnt = i4_bottom_field_order_cnt;
572
141k
    }
573
0
    else if(!u1_bottom_field_flag)
574
0
    {
575
0
        *pi4_poc = i4_top_field_order_cnt;
576
0
        ps_pps->i4_top_field_order_cnt = i4_top_field_order_cnt;
577
0
    }
578
0
    else
579
0
    {
580
0
        *pi4_poc = i4_bottom_field_order_cnt;
581
0
        ps_pps->i4_bottom_field_order_cnt = i4_bottom_field_order_cnt;
582
0
    }
583
584
141k
    ps_pps->i4_avg_poc = *pi4_poc;
585
586
141k
    return OK;
587
142k
}
588
589
/*****************************************************************************/
590
/*                                                                           */
591
/*  Function Name : isvcd_decode_gaps_in_frame_num */
592
/*                                                                           */
593
/*  Description   : This function decodes gaps in frame number               */
594
/*                                                                           */
595
/*  Inputs        : ps_dec          Decoder parameters                       */
596
/*                  u2_frame_num   current frame number                     */
597
/*                                                                           */
598
/*  Globals       : None                                                     */
599
/*  Processing    : This functionality needs to be implemented               */
600
/*  Outputs       : None                                                     */
601
/*  Returns       : None                                                     */
602
/*                                                                           */
603
/*  Issues        : Not implemented                                          */
604
/*                                                                           */
605
/*  Revision History:                                                        */
606
/*                                                                           */
607
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
608
/*         06 05 2002   NS              Draft                                */
609
/*                                                                           */
610
/*****************************************************************************/
611
WORD32 isvcd_decode_gaps_in_frame_num(dec_struct_t *ps_dec, UWORD16 u2_frame_num)
612
0
{
613
0
    UWORD32 u4_next_frm_num, u4_start_frm_num;
614
0
    UWORD32 u4_max_frm_num;
615
0
    pocstruct_t s_tmp_poc;
616
0
    WORD32 i4_poc;
617
0
    dec_slice_params_t *ps_cur_slice;
618
619
0
    dec_pic_params_t *ps_pic_params;
620
0
    WORD8 i1_gap_idx;
621
0
    WORD32 *i4_gaps_start_frm_num;
622
0
    dpb_manager_t *ps_dpb_mgr;
623
0
    WORD8 *pi1_gaps_per_seq;
624
0
    WORD32 ret;
625
626
0
    ps_cur_slice = ps_dec->ps_cur_slice;
627
0
    if(ps_cur_slice->u1_field_pic_flag)
628
0
    {
629
0
        if(ps_dec->u2_prev_ref_frame_num == u2_frame_num) return 0;
630
0
    }
631
632
0
    u4_next_frm_num = ps_dec->u2_prev_ref_frame_num + 1;
633
0
    u4_max_frm_num = ps_dec->ps_cur_sps->u2_u4_max_pic_num_minus1 + 1;
634
635
0
    if(u4_next_frm_num >= u4_max_frm_num)
636
0
    {
637
0
        u4_next_frm_num -= u4_max_frm_num;
638
0
    }
639
640
0
    if(u4_next_frm_num == u2_frame_num)
641
0
    {
642
0
        return (0);
643
0
    }
644
645
0
    if((ps_dec->u1_nal_unit_type == IDR_SLICE_NAL) && (u4_next_frm_num >= u2_frame_num))
646
0
    {
647
0
        return (0);
648
0
    }
649
0
    u4_start_frm_num = u4_next_frm_num;
650
651
0
    s_tmp_poc.i4_pic_order_cnt_lsb = 0;
652
0
    s_tmp_poc.i4_delta_pic_order_cnt_bottom = 0;
653
0
    s_tmp_poc.i4_pic_order_cnt_lsb = 0;
654
0
    s_tmp_poc.i4_delta_pic_order_cnt_bottom = 0;
655
0
    s_tmp_poc.i4_delta_pic_order_cnt[0] = 0;
656
0
    s_tmp_poc.i4_delta_pic_order_cnt[1] = 0;
657
658
0
    ps_cur_slice = ps_dec->ps_cur_slice;
659
0
    ps_pic_params = ps_dec->ps_cur_pps;
660
661
0
    ps_dpb_mgr = ps_dec->ps_dpb_mgr;
662
663
    /* Find a empty slot to store gap seqn info */
664
0
    i4_gaps_start_frm_num = ps_dpb_mgr->ai4_gaps_start_frm_num;
665
0
    for(i1_gap_idx = 0; i1_gap_idx < MAX_FRAMES; i1_gap_idx++)
666
0
    {
667
0
        if(INVALID_FRAME_NUM == i4_gaps_start_frm_num[i1_gap_idx]) break;
668
0
    }
669
0
    if(MAX_FRAMES == i1_gap_idx)
670
0
    {
671
0
        UWORD32 i4_error_code;
672
0
        i4_error_code = ERROR_DBP_MANAGER_T;
673
0
        return i4_error_code;
674
0
    }
675
676
0
    i4_poc = 0;
677
0
    i4_gaps_start_frm_num[i1_gap_idx] = u4_start_frm_num;
678
0
    ps_dpb_mgr->ai4_gaps_end_frm_num[i1_gap_idx] = u2_frame_num - 1;
679
0
    pi1_gaps_per_seq = ps_dpb_mgr->ai1_gaps_per_seq;
680
0
    pi1_gaps_per_seq[i1_gap_idx] = 0;
681
0
    while(u4_next_frm_num != u2_frame_num)
682
0
    {
683
0
        ih264d_delete_nonref_nondisplay_pics(ps_dpb_mgr);
684
0
        if(ps_pic_params->ps_sps->u1_pic_order_cnt_type)
685
0
        {
686
            /* allocate a picture buffer and insert it as ST node */
687
0
            ret =
688
0
                isvcd_decode_pic_order_cnt(0, u4_next_frm_num, &ps_dec->s_prev_pic_poc, &s_tmp_poc,
689
0
                                           ps_cur_slice, ps_pic_params, 1, 0, 0, &i4_poc, ps_dec);
690
0
            if(ret != OK) return ret;
691
692
            /* Display seq no calculations */
693
0
            if(i4_poc >= ps_dec->i4_max_poc) ps_dec->i4_max_poc = i4_poc;
694
            /* IDR Picture or POC wrap around */
695
0
            if(i4_poc == 0)
696
0
            {
697
0
                WORD64 i8_temp;
698
0
                i8_temp = (WORD64) ps_dec->i4_prev_max_display_seq + ps_dec->i4_max_poc +
699
0
                          ps_dec->u1_max_dec_frame_buffering + 1;
700
                /*If i4_prev_max_display_seq overflows integer range, reset it */
701
0
                ps_dec->i4_prev_max_display_seq =
702
0
                    IS_OUT_OF_RANGE_S32(i8_temp) ? 0 : (WORD32) i8_temp;
703
0
                ps_dec->i4_max_poc = 0;
704
0
            }
705
706
0
            ps_cur_slice->u1_mmco_equalto5 = 0;
707
0
            ps_cur_slice->u2_frame_num = u4_next_frm_num;
708
0
        }
709
710
0
        if(ps_dpb_mgr->i1_poc_buf_id_entries >= ps_dec->u1_max_dec_frame_buffering)
711
0
        {
712
0
            ret = ih264d_assign_display_seq(ps_dec);
713
0
            if(ret != OK) return ret;
714
0
        }
715
716
0
        {
717
0
            WORD64 i8_display_poc;
718
0
            i8_display_poc = (WORD64) ps_dec->i4_prev_max_display_seq + i4_poc;
719
0
            if(IS_OUT_OF_RANGE_S32(i8_display_poc))
720
0
            {
721
0
                ps_dec->i4_prev_max_display_seq = 0;
722
0
            }
723
0
        }
724
0
        ret = ih264d_insert_pic_in_display_list(ps_dec->ps_dpb_mgr, (WORD8) DO_NOT_DISP,
725
0
                                                (WORD32) (ps_dec->i4_prev_max_display_seq + i4_poc),
726
0
                                                u4_next_frm_num);
727
0
        if(ret != OK) return ret;
728
729
0
        pi1_gaps_per_seq[i1_gap_idx]++;
730
0
        ret = ih264d_do_mmco_for_gaps(ps_dpb_mgr, ps_dec->ps_cur_sps->u1_num_ref_frames);
731
0
        if(ret != OK) return ret;
732
733
0
        ih264d_delete_nonref_nondisplay_pics(ps_dpb_mgr);
734
735
0
        u4_next_frm_num++;
736
0
        if(u4_next_frm_num >= u4_max_frm_num)
737
0
        {
738
0
            u4_next_frm_num -= u4_max_frm_num;
739
0
        }
740
0
    }
741
742
0
    return OK;
743
0
}
744
745
/*!
746
****************************************************************************
747
*                                                                           
748
*  \if Function name : isvcd_init_dpb_ref_bufs \endif
749
*
750
*  \brief
751
*    Initializes the reference buffers
752
*
753
*  \return
754
*    None
755
*
756
*  \note
757
*    This function is called to initialize the reference buffers.
758
****************************************************************************
759
*/
760
761
void isvcd_init_dpb_ref_bufs(dec_struct_t *ps_dec)
762
105k
{
763
105k
    UWORD8 i;
764
105k
    struct pic_buffer_t *ps_init_dpb;
765
105k
    ps_init_dpb = ps_dec->ps_dpb_mgr->ps_init_dpb[0][0];
766
6.84M
    for(i = 0; i < 2 * MAX_REF_BUFS; i++)
767
6.74M
    {
768
6.74M
        memset(ps_init_dpb, 0, sizeof(struct pic_buffer_t));
769
6.74M
        ps_init_dpb->pu1_buf1 = NULL;
770
6.74M
        ps_init_dpb->u1_long_term_frm_idx = MAX_REF_BUFS + 1;
771
6.74M
        ps_dec->ps_dpb_mgr->ps_init_dpb[0][i] = ps_init_dpb;
772
6.74M
        ps_dec->ps_dpb_mgr->ps_mod_dpb[0][i] = ps_init_dpb;
773
6.74M
        ps_init_dpb++;
774
6.74M
    }
775
776
105k
    ps_init_dpb = ps_dec->ps_dpb_mgr->ps_init_dpb[1][0];
777
6.84M
    for(i = 0; i < 2 * MAX_REF_BUFS; i++)
778
6.74M
    {
779
6.74M
        memset(ps_init_dpb, 0, sizeof(struct pic_buffer_t));
780
6.74M
        ps_init_dpb->pu1_buf1 = NULL;
781
6.74M
        ps_init_dpb->u1_long_term_frm_idx = MAX_REF_BUFS + 1;
782
6.74M
        ps_dec->ps_dpb_mgr->ps_init_dpb[1][i] = ps_init_dpb;
783
6.74M
        ps_dec->ps_dpb_mgr->ps_mod_dpb[1][i] = ps_init_dpb;
784
6.74M
        ps_init_dpb++;
785
6.74M
    }
786
105k
}
787
788
/*!
789
**************************************************************************
790
* \if Function name : isvcd_init_pic \endif
791
*
792
* \brief
793
*    Initializes the picture.
794
*
795
* \return
796
*    0 on Success and Error code otherwise
797
*
798
* \note
799
*    This function is called when first slice of the
800
*    NON -IDR picture is encountered.
801
**************************************************************************
802
*/
803
WORD32 isvcd_init_pic(svc_dec_lyr_struct_t *ps_svc_lyr_dec, UWORD16 u2_frame_num, WORD32 i4_poc,
804
                      dec_pic_params_t *ps_pps)
805
138k
{
806
138k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
807
138k
    dec_seq_params_t *ps_seq = ps_dec->ps_cur_sps;
808
138k
    prev_seq_params_t *ps_prev_seq_params = &ps_dec->s_prev_seq_params;
809
138k
    WORD32 ret;
810
811
138k
    ps_dec->ps_cur_slice->u2_frame_num = u2_frame_num;
812
138k
    ps_dec->ps_cur_slice->i4_poc = i4_poc;
813
138k
    ps_dec->ps_cur_pps = ps_pps;
814
138k
    ps_dec->ps_cur_pps->pv_codec_handle = ps_dec;
815
816
138k
    ps_dec->ps_dpb_mgr->i4_max_frm_num = ps_seq->u2_u4_max_pic_num_minus1 + 1;
817
818
138k
    ps_dec->ps_dpb_mgr->u2_pic_ht = ps_dec->u2_pic_ht;
819
138k
    ps_dec->ps_dpb_mgr->u2_pic_wd = ps_dec->u2_pic_wd;
820
138k
    ps_dec->i4_pic_type = NA_SLICE;
821
138k
    ps_dec->i4_frametype = IV_NA_FRAME;
822
138k
    ps_dec->i4_content_type = IV_CONTENTTYPE_NA;
823
824
    /*--------------------------------------------------------------------*/
825
    /* Get the value of MaxMbAddress and frmheight in Mbs                 */
826
    /*--------------------------------------------------------------------*/
827
138k
    ps_seq->u4_max_mb_addr =
828
138k
        ((UWORD32)ps_seq->u2_frm_wd_in_mbs *
829
138k
         ((UWORD32)ps_dec->u2_pic_ht >> (4 + ps_dec->ps_cur_slice->u1_field_pic_flag))) -
830
138k
        1;
831
138k
    ps_dec->u2_frm_ht_in_mbs = (ps_dec->u2_pic_ht >> (4 + ps_dec->ps_cur_slice->u1_field_pic_flag));
832
833
    /***************************************************************************/
834
    /* If change in Level or the required PicBuffers i4_size is more than the  */
835
    /* current one FREE the current PicBuffers and allocate affresh            */
836
    /***************************************************************************/
837
138k
    if(!ps_dec->u1_init_dec_flag)
838
23.8k
    {
839
23.8k
        ps_dec->u1_max_dec_frame_buffering = ih264d_get_dpb_size(ps_seq);
840
841
23.8k
        ps_dec->i4_display_delay = ps_dec->u1_max_dec_frame_buffering;
842
23.8k
        if((1 == ps_seq->u1_vui_parameters_present_flag) &&
843
1.95k
           (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
844
173
        {
845
173
            if(ps_seq->u1_frame_mbs_only_flag == 1)
846
173
                ps_dec->i4_display_delay = ps_seq->s_vui.u4_num_reorder_frames + 1;
847
0
            else
848
0
                ps_dec->i4_display_delay = ps_seq->s_vui.u4_num_reorder_frames * 2 + 2;
849
173
        }
850
851
23.8k
        if(IVD_DECODE_FRAME_OUT == ps_dec->e_frm_out_mode) ps_dec->i4_display_delay = 0;
852
853
23.8k
        if(ps_dec->u4_share_disp_buf == 0)
854
23.8k
        {
855
23.8k
            if(ps_seq->u1_frame_mbs_only_flag == 1)
856
23.8k
                ps_dec->u1_pic_bufs = ps_dec->i4_display_delay + ps_seq->u1_num_ref_frames + 1;
857
0
            else
858
0
                ps_dec->u1_pic_bufs = ps_dec->i4_display_delay + ps_seq->u1_num_ref_frames * 2 + 2;
859
23.8k
        }
860
0
        else
861
0
        {
862
0
            ps_dec->u1_pic_bufs = (WORD32) ps_dec->u4_num_disp_bufs;
863
0
        }
864
865
        /* Ensure at least two buffers are allocated */
866
23.8k
        ps_dec->u1_pic_bufs = MAX(ps_dec->u1_pic_bufs, 2);
867
868
23.8k
        if(ps_dec->u4_share_disp_buf == 0)
869
23.8k
            ps_dec->u1_pic_bufs = MIN(ps_dec->u1_pic_bufs, (H264_MAX_REF_PICS * 2));
870
871
23.8k
        ps_dec->u1_max_dec_frame_buffering =
872
23.8k
            MIN(ps_dec->u1_max_dec_frame_buffering, ps_dec->u1_pic_bufs);
873
874
        /* Temporary hack to run Tractor Cav/Cab/MbAff Profiler streams  also for
875
         * CAFI1_SVA_C.264 in conformance*/
876
23.8k
        if(ps_dec->u1_init_dec_flag)
877
0
        {
878
0
            ih264d_release_pics_in_dpb((void *) ps_dec, ps_dec->u1_pic_bufs);
879
0
            ih264d_release_display_bufs(ps_dec);
880
0
            ih264d_reset_ref_bufs(ps_dec->ps_dpb_mgr);
881
0
        }
882
883
        /*********************************************************************/
884
        /* Configuring decoder parameters based on level and then            */
885
        /* fresh pointer initialisation in decoder scratch and state buffers */
886
        /*********************************************************************/
887
23.8k
        if(!ps_dec->u1_init_dec_flag || ((ps_seq->u1_level_idc < H264_LEVEL_3_0) ^
888
0
                                         (ps_prev_seq_params->u1_level_idc < H264_LEVEL_3_0)))
889
23.8k
        {
890
23.8k
            ret = ih264d_init_dec_mb_grp(ps_dec);
891
23.8k
            if(ret != OK) return ret;
892
23.8k
        }
893
894
23.8k
        ret = isvcd_allocate_dynamic_bufs(ps_svc_lyr_dec);
895
896
23.8k
        if(ret != OK)
897
0
        {
898
            /* Free any dynamic buffers that are allocated */
899
0
            isvcd_free_dynamic_bufs(ps_svc_lyr_dec);
900
0
            ps_dec->i4_error_code = IVD_MEM_ALLOC_FAILED;
901
0
            return IVD_MEM_ALLOC_FAILED;
902
0
        }
903
904
23.8k
        ih264d_init_ref_bufs((dpb_manager_t *)ps_dec->ps_dpb_mgr);
905
23.8k
        isvcd_init_dpb_ref_bufs(ps_dec);
906
907
23.8k
        ret = ih264d_create_pic_buffers(ps_dec->u1_pic_bufs, ps_dec);
908
23.8k
        if(ret != OK) return ret;
909
910
23.8k
        ret = ih264d_create_mv_bank(ps_dec, ps_dec->u2_pic_wd, ps_dec->u2_pic_ht);
911
23.8k
        if(ret != OK) return ret;
912
913
        /* In shared mode, set all of them as used by display */
914
23.8k
        if(ps_dec->u4_share_disp_buf == 1)
915
0
        {
916
0
            WORD32 i;
917
918
0
            for(i = 0; i < ps_dec->u1_pic_bufs; i++)
919
0
            {
920
0
                ih264_buf_mgr_set_status((buf_mgr_t *) ps_dec->pv_pic_buf_mgr, i, BUF_MGR_IO);
921
0
            }
922
0
        }
923
924
23.8k
        ps_dec->u1_init_dec_flag = 1;
925
23.8k
        ps_prev_seq_params->u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs;
926
23.8k
        ps_prev_seq_params->u1_level_idc = ps_seq->u1_level_idc;
927
23.8k
        ps_prev_seq_params->u1_profile_idc = ps_seq->u1_profile_idc;
928
23.8k
        ps_prev_seq_params->u2_frm_ht_in_mbs = ps_seq->u2_frm_ht_in_mbs;
929
23.8k
        ps_prev_seq_params->u1_frame_mbs_only_flag = ps_seq->u1_frame_mbs_only_flag;
930
23.8k
        ps_prev_seq_params->u1_direct_8x8_inference_flag = ps_seq->u1_direct_8x8_inference_flag;
931
932
23.8k
        ps_dec->i4_cur_display_seq = 0;
933
23.8k
        ps_dec->i4_prev_max_display_seq = 0;
934
23.8k
        ps_dec->i4_max_poc = 0;
935
936
23.8k
        {
937
            /* 0th entry of CtxtIncMbMap will be always be containing default values
938
            for CABAC context representing MB not available */
939
23.8k
            ctxt_inc_mb_info_t *p_DefCtxt = ps_dec->p_ctxt_inc_mb_map - 1;
940
23.8k
            UWORD8 *pu1_temp;
941
23.8k
            WORD8 i;
942
23.8k
            p_DefCtxt->u1_mb_type = CAB_SKIP;
943
944
23.8k
            p_DefCtxt->u1_cbp = 0x0f;
945
23.8k
            p_DefCtxt->u1_intra_chroma_pred_mode = 0;
946
947
23.8k
            p_DefCtxt->u1_yuv_dc_csbp = 0x7;
948
949
23.8k
            p_DefCtxt->u1_transform8x8_ctxt = 0;
950
951
23.8k
            pu1_temp = (UWORD8 *) p_DefCtxt->i1_ref_idx;
952
119k
            for(i = 0; i < 4; i++, pu1_temp++) (*pu1_temp) = 0;
953
23.8k
            pu1_temp = (UWORD8 *) p_DefCtxt->u1_mv;
954
405k
            for(i = 0; i < 16; i++, pu1_temp++) (*pu1_temp) = 0;
955
23.8k
            ps_dec->ps_def_ctxt_mb_info = p_DefCtxt;
956
23.8k
        }
957
23.8k
    }
958
    /* reset DBP commands read u4_flag */
959
138k
    ps_dec->ps_dpb_cmds->u1_dpb_commands_read = 0;
960
961
138k
    return OK;
962
138k
}