Coverage Report

Created: 2025-11-24 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libhevc/encoder/ihevce_memory_init.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2018 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
******************************************************************************
23
* \file ihevce_memory_init.c
24
*
25
* \brief
26
*    This file contains functions which perform memory requirement gathering
27
*    and freeing of memories of encoder at the end
28
*
29
* \date
30
*    18/09/2012
31
*
32
* \author
33
*    Ittiam
34
*
35
* List of Functions
36
*    <TODO: TO BE ADDED>
37
*
38
******************************************************************************
39
*/
40
41
/*****************************************************************************/
42
/* File Includes                                                             */
43
/*****************************************************************************/
44
/* System include files */
45
#include <stdio.h>
46
#include <string.h>
47
#include <stdlib.h>
48
#include <assert.h>
49
#include <stdarg.h>
50
#include <math.h>
51
52
/* User include files */
53
#include "ihevc_typedefs.h"
54
#include "itt_video_api.h"
55
#include "ihevce_api.h"
56
57
#include "rc_cntrl_param.h"
58
#include "rc_frame_info_collector.h"
59
#include "rc_look_ahead_params.h"
60
61
#include "ihevc_defs.h"
62
#include "ihevc_macros.h"
63
#include "ihevc_debug.h"
64
#include "ihevc_structs.h"
65
#include "ihevc_platform_macros.h"
66
#include "ihevc_deblk.h"
67
#include "ihevc_itrans_recon.h"
68
#include "ihevc_chroma_itrans_recon.h"
69
#include "ihevc_chroma_intra_pred.h"
70
#include "ihevc_intra_pred.h"
71
#include "ihevc_inter_pred.h"
72
#include "ihevc_mem_fns.h"
73
#include "ihevc_padding.h"
74
#include "ihevc_weighted_pred.h"
75
#include "ihevc_sao.h"
76
#include "ihevc_resi_trans.h"
77
#include "ihevc_quant_iquant_ssd.h"
78
#include "ihevc_cabac_tables.h"
79
#include "ihevc_common_tables.h"
80
81
#include "ihevce_defs.h"
82
#include "ihevce_hle_interface.h"
83
#include "ihevce_lap_enc_structs.h"
84
#include "ihevce_lap_interface.h"
85
#include "ihevce_multi_thrd_structs.h"
86
#include "ihevce_multi_thrd_funcs.h"
87
#include "ihevce_me_common_defs.h"
88
#include "ihevce_had_satd.h"
89
#include "ihevce_error_codes.h"
90
#include "ihevce_bitstream.h"
91
#include "ihevce_cabac.h"
92
#include "ihevce_rdoq_macros.h"
93
#include "ihevce_function_selector.h"
94
#include "ihevce_enc_structs.h"
95
#include "ihevce_entropy_structs.h"
96
#include "ihevce_cmn_utils_instr_set_router.h"
97
#include "ihevce_ipe_instr_set_router.h"
98
#include "ihevce_decomp_pre_intra_structs.h"
99
#include "ihevce_decomp_pre_intra_pass.h"
100
#include "ihevce_enc_loop_structs.h"
101
#include "ihevce_nbr_avail.h"
102
#include "ihevce_enc_loop_utils.h"
103
#include "ihevce_sub_pic_rc.h"
104
#include "ihevce_global_tables.h"
105
#include "ihevce_bs_compute_ctb.h"
106
#include "ihevce_cabac_rdo.h"
107
#include "ihevce_deblk.h"
108
#include "ihevce_entropy_interface.h"
109
#include "ihevce_frame_process.h"
110
#include "ihevce_ipe_pass.h"
111
#include "ihevce_rc_enc_structs.h"
112
#include "ihevce_rc_interface.h"
113
#include "hme_datatype.h"
114
#include "hme_interface.h"
115
#include "hme_common_defs.h"
116
#include "hme_defs.h"
117
#include "ihevce_me_instr_set_router.h"
118
#include "ihevce_enc_subpel_gen.h"
119
#include "ihevce_inter_pred.h"
120
#include "ihevce_mv_pred.h"
121
#include "ihevce_mv_pred_merge.h"
122
#include "ihevce_enc_loop_inter_mode_sifter.h"
123
#include "ihevce_me_pass.h"
124
#include "ihevce_coarse_me_pass.h"
125
#include "ihevce_enc_cu_recursion.h"
126
#include "ihevce_enc_loop_pass.h"
127
#include "ihevce_common_utils.h"
128
#include "ihevce_buffer_que_interface.h"
129
#include "ihevce_dep_mngr_interface.h"
130
#include "ihevce_sao.h"
131
#include "ihevce_tile_interface.h"
132
133
#include "cast_types.h"
134
#include "osal.h"
135
#include "osal_defaults.h"
136
137
/*****************************************************************************/
138
/* Function Definitions                                                      */
139
/*****************************************************************************/
140
141
/*!
142
******************************************************************************
143
* \if Function name : ihevce_mem_manager_init \endif
144
*
145
* \brief
146
*    Encoder Memory init function
147
*
148
* \param[in] Processing interface context pointer
149
*
150
* \return
151
*    None
152
*
153
* \author
154
*  Ittiam
155
*
156
*****************************************************************************
157
*/
158
46.1k
#define MAX_QUEUE 40
159
void ihevce_mem_manager_init(enc_ctxt_t *ps_enc_ctxt, ihevce_hle_ctxt_t *ps_intrf_ctxt)
160
6.81k
{
161
    /* local variables */
162
6.81k
    WORD32 total_memtabs_req = 0;
163
6.81k
    WORD32 total_memtabs_used = 0;
164
6.81k
    WORD32 total_system_memtabs = 0;
165
6.81k
    WORD32 ctr;
166
6.81k
    WORD32 buf_size;
167
6.81k
    WORD32 num_ctb_horz;
168
6.81k
    WORD32 num_ctb_vert;
169
6.81k
    WORD32 num_cu_in_ctb;
170
6.81k
    WORD32 num_pu_in_ctb;
171
6.81k
    WORD32 num_tu_in_ctb;
172
6.81k
    WORD32 ctb_size;
173
6.81k
    WORD32 min_cu_size;
174
6.81k
    WORD32 max_num_ref_pics;
175
6.81k
    WORD32 mem_alloc_ctrl_flag;
176
6.81k
    WORD32 space_for_mem_in_enc_grp = 0;
177
6.81k
    WORD32 space_for_mem_in_pre_enc_grp = 0;
178
6.81k
    WORD32 mv_bank_size;
179
6.81k
    WORD32 ref_idx_bank_size;
180
6.81k
    WORD32 a_wd[MAX_NUM_HME_LAYERS], a_ht[MAX_NUM_HME_LAYERS];
181
6.81k
    WORD32 a_disp_wd[MAX_NUM_HME_LAYERS], a_disp_ht[MAX_NUM_HME_LAYERS];
182
6.81k
    WORD32 a_ctb_align_wd[MAX_NUM_HME_LAYERS], a_ctb_align_ht[MAX_NUM_HME_LAYERS];
183
6.81k
    WORD32 n_enc_layers = 1, n_tot_layers;
184
6.81k
    WORD32 num_bufs_preenc_me_que, num_bufs_L0_ipe_enc, max_delay_preenc_l0_que;
185
6.81k
    WORD32 i, i4_resolution_id = ps_enc_ctxt->i4_resolution_id;  //counter
186
6.81k
    WORD32 i4_num_bitrate_inst;
187
6.81k
    iv_mem_rec_t *ps_memtab;
188
6.81k
    WORD32 i4_field_pic, i4_total_queues = 0;
189
190
6.81k
    recon_pic_buf_t **pps_pre_enc_pic_bufs;
191
6.81k
    frm_proc_ent_cod_ctxt_t **pps_frm_proc_ent_cod_bufs[IHEVCE_MAX_NUM_BITRATES];
192
6.81k
    pre_enc_me_ctxt_t **pps_pre_enc_bufs;
193
6.81k
    me_enc_rdopt_ctxt_t **pps_me_enc_bufs;
194
6.81k
    pre_enc_L0_ipe_encloop_ctxt_t **pps_L0_ipe_enc_bufs;
195
    /*get number of input buffer required based on requirement from each stage*/
196
6.81k
    ihevce_lap_enc_buf_t **pps_lap_enc_input_bufs;
197
6.81k
    WORD32 i4_num_enc_loop_frm_pllel;
198
6.81k
    WORD32 i4_num_me_frm_pllel;
199
    /*msr: These are parameters required to allocate input buffer,
200
    encoder needs to be initilized before getting requirements hence filled once static params are initilized*/
201
6.81k
    WORD32 num_input_buf_per_queue, i4_yuv_min_size, i4_luma_min_size;
202
203
6.81k
    i4_num_bitrate_inst = ps_enc_ctxt->i4_num_bitrates;
204
6.81k
    i4_field_pic = ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_field_pic;
205
6.81k
    ps_intrf_ctxt->i4_gpu_mem_size = 0;
206
207
    /*Initialize the thrd id flag and all deafult values for sub pic rc */
208
6.81k
    {
209
6.81k
        WORD32 i, j, k;
210
211
13.6k
        for(i = 0; i < MAX_NUM_ENC_LOOP_PARALLEL; i++)
212
6.81k
        {
213
13.6k
            for(j = 0; j < IHEVCE_MAX_NUM_BITRATES; j++)
214
6.81k
            {
215
6.81k
                ps_enc_ctxt->s_multi_thrd.ai4_acc_ctb_ctr[i][j] = 0;
216
6.81k
                ps_enc_ctxt->s_multi_thrd.ai4_ctb_ctr[i][j] = 0;
217
218
6.81k
                ps_enc_ctxt->s_multi_thrd.ai4_threshold_reached[i][j] = 0;
219
220
6.81k
                ps_enc_ctxt->s_multi_thrd.ai4_curr_qp_acc[i][j] = 0;
221
222
6.81k
                ps_enc_ctxt->s_multi_thrd.af_acc_hdr_bits_scale_err[i][j] = 0;
223
224
61.3k
                for(k = 0; k < MAX_NUM_FRM_PROC_THRDS_ENC; k++)
225
54.4k
                {
226
54.4k
                    ps_enc_ctxt->s_multi_thrd.ai4_thrd_id_valid_flag[i][j][k] = -1;
227
54.4k
                }
228
6.81k
            }
229
6.81k
        }
230
6.81k
    }
231
232
6.81k
#define ENABLE_FRM_PARALLEL
233
6.81k
#ifdef ENABLE_FRM_PARALLEL
234
6.81k
    i4_num_enc_loop_frm_pllel = MAX_NUM_ENC_LOOP_PARALLEL;
235
6.81k
    i4_num_me_frm_pllel = MAX_NUM_ME_PARALLEL;
236
#else
237
    i4_num_enc_loop_frm_pllel = 1;
238
    i4_num_me_frm_pllel = 1;
239
#endif
240
241
6.81k
    ps_enc_ctxt->s_multi_thrd.i4_num_enc_loop_frm_pllel = i4_num_enc_loop_frm_pllel;
242
6.81k
    ps_enc_ctxt->i4_max_fr_enc_loop_parallel_rc = i4_num_enc_loop_frm_pllel;
243
6.81k
    ps_enc_ctxt->s_multi_thrd.i4_num_me_frm_pllel = i4_num_me_frm_pllel;
244
6.81k
    ps_enc_ctxt->s_multi_thrd.i4_force_end_flag = 0;
245
246
6.81k
    ps_enc_ctxt->i4_ref_mbr_id = 0;
247
    /* get the ctb size from max cu size */
248
6.81k
    ctb_size = ps_enc_ctxt->ps_stat_prms->s_config_prms.i4_max_log2_cu_size;
249
250
    /* get the min cu size from config params */
251
6.81k
    min_cu_size = ps_enc_ctxt->ps_stat_prms->s_config_prms.i4_min_log2_cu_size;
252
253
    /* convert to actual width */
254
6.81k
    ctb_size = 1 << ctb_size;
255
6.81k
    min_cu_size = 1 << min_cu_size;
256
257
    /* Get the width and heights of different decomp layers */
258
6.81k
    *a_wd =
259
6.81k
        ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[ps_enc_ctxt->i4_resolution_id]
260
6.81k
            .i4_width +
261
6.81k
        SET_CTB_ALIGN(
262
6.81k
            ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[ps_enc_ctxt->i4_resolution_id]
263
6.81k
                .i4_width,
264
6.81k
            min_cu_size);
265
6.81k
    *a_ht =
266
6.81k
        ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[ps_enc_ctxt->i4_resolution_id]
267
6.81k
            .i4_height +
268
6.81k
        SET_CTB_ALIGN(
269
6.81k
            ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[ps_enc_ctxt->i4_resolution_id]
270
6.81k
                .i4_height,
271
6.81k
            min_cu_size);
272
273
6.81k
    n_tot_layers = hme_derive_num_layers(n_enc_layers, a_wd, a_ht, a_disp_wd, a_disp_ht);
274
6.81k
    hme_coarse_get_layer1_mv_bank_ref_idx_size(
275
6.81k
        n_tot_layers,
276
6.81k
        a_wd,
277
6.81k
        a_ht,
278
6.81k
        ((ps_enc_ctxt->ps_stat_prms->s_coding_tools_prms.i4_max_reference_frames == -1)
279
6.81k
             ? ((DEFAULT_MAX_REFERENCE_PICS) << i4_field_pic)
280
6.81k
             : ps_enc_ctxt->ps_stat_prms->s_coding_tools_prms.i4_max_reference_frames),
281
6.81k
        (S32 *)(&mv_bank_size),
282
6.81k
        (S32 *)(&ref_idx_bank_size));
283
6.81k
    if(n_tot_layers < 3)
284
0
    {
285
0
        WORD32 error_code;
286
0
        error_code = IHEVCE_NUM_DECOMP_LYRS_NOT_SUPPORTED;
287
0
        ps_intrf_ctxt->i4_error_code = IHEVCE_SETUNSUPPORTEDINPUT(error_code);
288
0
        return;
289
0
    }
290
291
    /* calculate num cu,pu,tu in ctb */
292
6.81k
    num_cu_in_ctb = ctb_size / MIN_CU_SIZE;
293
6.81k
    num_cu_in_ctb *= num_cu_in_ctb;
294
295
6.81k
    num_pu_in_ctb = ctb_size / MIN_PU_SIZE;
296
6.81k
    num_pu_in_ctb *= num_pu_in_ctb;
297
298
6.81k
    num_tu_in_ctb = ctb_size / MIN_PU_SIZE;
299
6.81k
    num_tu_in_ctb *= num_tu_in_ctb;
300
301
    /* calcuate the number of ctb horizontally*/
302
6.81k
    num_ctb_horz =
303
6.81k
        ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[ps_enc_ctxt->i4_resolution_id]
304
6.81k
            .i4_width +
305
6.81k
        SET_CTB_ALIGN(
306
6.81k
            ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[ps_enc_ctxt->i4_resolution_id]
307
6.81k
                .i4_width,
308
6.81k
            ctb_size);
309
6.81k
    num_ctb_horz = num_ctb_horz / ctb_size;
310
311
    /* calcuate the number of ctb vertically*/
312
6.81k
    num_ctb_vert =
313
6.81k
        ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[ps_enc_ctxt->i4_resolution_id]
314
6.81k
            .i4_height +
315
6.81k
        SET_CTB_ALIGN(
316
6.81k
            ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[ps_enc_ctxt->i4_resolution_id]
317
6.81k
                .i4_height,
318
6.81k
            ctb_size);
319
6.81k
    num_ctb_vert = num_ctb_vert / ctb_size;
320
321
    /* align all the decomp layer dimensions to CTB alignment */
322
28.0k
    for(ctr = 0; ctr < n_tot_layers; ctr++)
323
21.2k
    {
324
21.2k
        a_ctb_align_wd[ctr] = a_wd[ctr] + SET_CTB_ALIGN(a_wd[ctr], ctb_size);
325
326
21.2k
        a_ctb_align_ht[ctr] = a_ht[ctr] + SET_CTB_ALIGN(a_ht[ctr], ctb_size);
327
21.2k
    }
328
329
    /* SEI related parametert initialization */
330
331
6.81k
    ps_enc_ctxt->u4_cur_pic_encode_cnt = 0;
332
333
    /* store the frame level ctb parameters which will be constant for the session */
334
6.81k
    ps_enc_ctxt->s_frm_ctb_prms.i4_ctb_size = ctb_size;
335
6.81k
    ps_enc_ctxt->s_frm_ctb_prms.i4_min_cu_size = min_cu_size;
336
6.81k
    ps_enc_ctxt->s_frm_ctb_prms.i4_num_cus_in_ctb = num_cu_in_ctb;
337
6.81k
    ps_enc_ctxt->s_frm_ctb_prms.i4_num_pus_in_ctb = num_pu_in_ctb;
338
6.81k
    ps_enc_ctxt->s_frm_ctb_prms.i4_num_tus_in_ctb = num_tu_in_ctb;
339
340
    /* intialize cra poc to default value */
341
6.81k
    ps_enc_ctxt->i4_cra_poc = 0;
342
343
    /* initialise the memory alloc control flag */
344
6.81k
    mem_alloc_ctrl_flag = ps_enc_ctxt->ps_stat_prms->s_multi_thrd_prms.i4_memory_alloc_ctrl_flag;
345
346
    /* decide the memory space for enc_grp and pre_enc_grp based on control flag */
347
6.81k
    if(0 == mem_alloc_ctrl_flag)
348
6.81k
    {
349
        /* normal memory */
350
6.81k
        space_for_mem_in_enc_grp = IV_EXT_CACHEABLE_NORMAL_MEM;
351
6.81k
        space_for_mem_in_pre_enc_grp = IV_EXT_CACHEABLE_NORMAL_MEM;
352
6.81k
    }
353
0
    else if(1 == mem_alloc_ctrl_flag)
354
0
    {
355
        /* only NUMA Node 0 memory allocation */
356
0
        space_for_mem_in_enc_grp = IV_EXT_CACHEABLE_NUMA_NODE0_MEM;
357
0
        space_for_mem_in_pre_enc_grp = IV_EXT_CACHEABLE_NUMA_NODE0_MEM;
358
0
    }
359
0
    else if(2 == mem_alloc_ctrl_flag)
360
0
    {
361
        /* Both NUMA Node 0 & Node 1 memory allocation */
362
0
        space_for_mem_in_enc_grp = IV_EXT_CACHEABLE_NUMA_NODE0_MEM;
363
0
        space_for_mem_in_pre_enc_grp = IV_EXT_CACHEABLE_NUMA_NODE1_MEM;
364
0
    }
365
0
    else
366
0
    {
367
        /* should not enter here */
368
0
        ASSERT(0);
369
0
    }
370
371
6.81k
    {
372
6.81k
        if(ps_enc_ctxt->s_multi_thrd.i4_num_enc_loop_frm_pllel > 1)
373
0
        {
374
0
            num_bufs_preenc_me_que = MIN_L1_L0_STAGGER_NON_SEQ +
375
0
                                     ps_enc_ctxt->ps_stat_prms->s_lap_prms.i4_rc_look_ahead_pics +
376
0
                                     (MAX_L0_IPE_ENC_STAGGER - 1) + NUM_BUFS_DECOMP_HME;
377
0
        }
378
6.81k
        else
379
6.81k
        {
380
6.81k
            num_bufs_preenc_me_que = MIN_L1_L0_STAGGER_NON_SEQ +
381
6.81k
                                     ps_enc_ctxt->ps_stat_prms->s_lap_prms.i4_rc_look_ahead_pics +
382
6.81k
                                     (MIN_L0_IPE_ENC_STAGGER - 1) + NUM_BUFS_DECOMP_HME;
383
6.81k
        }
384
385
        /*The number of buffers to support stagger between L0 IPE, ME and enc loop. This is a separate queue to store L0 IPE
386
        output to save memory since this is not used in L1 stage*/
387
6.81k
        if(ps_enc_ctxt->s_multi_thrd.i4_num_enc_loop_frm_pllel > 1)
388
0
        {
389
0
            num_bufs_L0_ipe_enc = MAX_L0_IPE_ENC_STAGGER;
390
0
        }
391
6.81k
        else
392
6.81k
        {
393
6.81k
            num_bufs_L0_ipe_enc = MIN_L0_IPE_ENC_STAGGER;
394
6.81k
        }
395
396
6.81k
        max_delay_preenc_l0_que = MIN_L1_L0_STAGGER_NON_SEQ +
397
6.81k
                                  ps_enc_ctxt->ps_stat_prms->s_lap_prms.i4_rc_look_ahead_pics + 1;
398
6.81k
    }
399
400
    /* ------------ popluate the lap static parameters ------------- */
401
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_max_closed_gop_period =
402
6.81k
        ps_enc_ctxt->ps_stat_prms->s_coding_tools_prms.i4_max_closed_gop_period;
403
404
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_min_closed_gop_period =
405
6.81k
        ps_enc_ctxt->ps_stat_prms->s_coding_tools_prms.i4_min_closed_gop_period;
406
407
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_max_cra_open_gop_period =
408
6.81k
        ps_enc_ctxt->ps_stat_prms->s_coding_tools_prms.i4_max_cra_open_gop_period;
409
410
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_max_i_open_gop_period =
411
6.81k
        ps_enc_ctxt->ps_stat_prms->s_coding_tools_prms.i4_max_i_open_gop_period;
412
413
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_max_reference_frames =
414
6.81k
        ps_enc_ctxt->ps_stat_prms->s_coding_tools_prms.i4_max_reference_frames;
415
416
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_max_temporal_layers =
417
6.81k
        ps_enc_ctxt->ps_stat_prms->s_coding_tools_prms.i4_max_temporal_layers;
418
419
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_width = ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_width;
420
421
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_height = ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_height;
422
423
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_enable_logo = ps_enc_ctxt->ps_stat_prms->i4_enable_logo;
424
425
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_src_interlace_field =
426
6.81k
        ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_field_pic;
427
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_frame_rate =
428
6.81k
        ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_frm_rate_num /
429
6.81k
        ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_frm_rate_denom;
430
431
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_blu_ray_spec = ps_enc_ctxt->i4_blu_ray_spec;
432
433
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_internal_bit_depth =
434
6.81k
        ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_internal_bit_depth;
435
436
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_input_bit_depth =
437
6.81k
        ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_input_bit_depth;
438
439
6.81k
    ps_enc_ctxt->s_lap_stat_prms.u1_chroma_array_type =
440
6.81k
        (ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_chr_format == IV_YUV_422SP_UV) ? 2 : 1;
441
442
6.81k
    ps_enc_ctxt->s_lap_stat_prms.i4_rc_pass_num = ps_enc_ctxt->ps_stat_prms->s_pass_prms.i4_pass;
443
444
6.81k
    if(0 == i4_resolution_id)
445
6.81k
    {
446
13.6k
        for(ctr = 0; ctr < ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_num_res_layers; ctr++)
447
6.81k
        {
448
6.81k
            ps_enc_ctxt->s_lap_stat_prms.ai4_quality_preset[ctr] =
449
6.81k
                ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[ctr].i4_quality_preset;
450
451
6.81k
            if(ps_enc_ctxt->s_lap_stat_prms.ai4_quality_preset[ctr] == IHEVCE_QUALITY_P7)
452
378
            {
453
378
                ps_enc_ctxt->s_lap_stat_prms.ai4_quality_preset[ctr] = IHEVCE_QUALITY_P6;
454
378
            }
455
6.81k
        }
456
6.81k
    }
457
6.81k
    memcpy(
458
6.81k
        &ps_enc_ctxt->s_lap_stat_prms.s_lap_params,
459
6.81k
        &ps_enc_ctxt->ps_stat_prms->s_lap_prms,
460
6.81k
        sizeof(ihevce_lap_params_t));
461
462
    /* copy the create prms as runtime prms */
463
6.81k
    memcpy(
464
6.81k
        &ps_enc_ctxt->s_runtime_src_prms,
465
6.81k
        &ps_enc_ctxt->ps_stat_prms->s_src_prms,
466
6.81k
        sizeof(ihevce_src_params_t));
467
    /*Copy the target params*/
468
6.81k
    memcpy(
469
6.81k
        &ps_enc_ctxt->s_runtime_tgt_params,
470
6.81k
        &ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id],
471
6.81k
        sizeof(ihevce_tgt_params_t));
472
6.81k
    ps_enc_ctxt->s_lap_stat_prms.e_arch_type = ps_enc_ctxt->ps_stat_prms->e_arch_type;
473
6.81k
    ps_enc_ctxt->s_lap_stat_prms.u1_is_popcnt_available = ps_enc_ctxt->u1_is_popcnt_available;
474
475
    /* copy the create prms as runtime prms */
476
6.81k
    memcpy(
477
6.81k
        &ps_enc_ctxt->s_runtime_src_prms,
478
6.81k
        &ps_enc_ctxt->ps_stat_prms->s_src_prms,
479
6.81k
        sizeof(ihevce_src_params_t));
480
    /*Copy the target params*/
481
6.81k
    memcpy(
482
6.81k
        &ps_enc_ctxt->s_runtime_tgt_params,
483
6.81k
        &ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id],
484
6.81k
        sizeof(ihevce_tgt_params_t));
485
486
    /* copy the run time coding parameters */
487
6.81k
    memcpy(
488
6.81k
        &ps_enc_ctxt->s_runtime_coding_prms,
489
6.81k
        &ps_enc_ctxt->ps_stat_prms->s_coding_tools_prms,
490
6.81k
        sizeof(ihevce_coding_params_t));
491
    /*change in run time parameter*/
492
6.81k
    if(ps_enc_ctxt->ps_stat_prms->s_coding_tools_prms.i4_max_reference_frames == -1)
493
6.81k
    {
494
6.81k
        ps_enc_ctxt->s_runtime_coding_prms.i4_max_reference_frames = (DEFAULT_MAX_REFERENCE_PICS)
495
6.81k
                                                                     << i4_field_pic;
496
6.81k
        ps_enc_ctxt->s_lap_stat_prms.i4_max_reference_frames =
497
6.81k
            ps_enc_ctxt->s_runtime_coding_prms.i4_max_reference_frames;
498
6.81k
    }
499
6.81k
    ASSERT(i4_num_enc_loop_frm_pllel == i4_num_me_frm_pllel);
500
501
6.81k
    if((1 == i4_num_enc_loop_frm_pllel) && (1 == i4_num_me_frm_pllel))
502
6.81k
    {
503
6.81k
        max_num_ref_pics = ps_enc_ctxt->s_runtime_coding_prms.i4_max_reference_frames;
504
6.81k
    }
505
0
    else
506
0
    {
507
0
        max_num_ref_pics =
508
0
            ps_enc_ctxt->s_runtime_coding_prms.i4_max_reference_frames * i4_num_enc_loop_frm_pllel;
509
0
    }
510
    /* --------------------------------------------------------------------- */
511
    /* --------------  Collating the number of memtabs required ------------ */
512
    /* --------------------------------------------------------------------- */
513
514
    /* Memtabs for syntactical tiles */
515
6.81k
    total_memtabs_req += ihevce_tiles_get_num_mem_recs();
516
517
    /* ---------- Enc loop Memtabs --------- */
518
6.81k
    total_memtabs_req +=
519
6.81k
        ihevce_enc_loop_get_num_mem_recs(i4_num_bitrate_inst, i4_num_enc_loop_frm_pllel);
520
    /* ---------- ME Memtabs --------------- */
521
6.81k
    total_memtabs_req += ihevce_me_get_num_mem_recs(i4_num_me_frm_pllel);
522
523
    /* ---------- Coarse ME Memtabs --------------- */
524
6.81k
    total_memtabs_req += ihevce_coarse_me_get_num_mem_recs();
525
    /* ---------- IPE Memtabs -------------- */
526
6.81k
    total_memtabs_req += ihevce_ipe_get_num_mem_recs();
527
528
    /* ---------- ECD Memtabs -------------- */
529
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
530
6.81k
    {
531
6.81k
        total_memtabs_req += ihevce_entropy_get_num_mem_recs();
532
6.81k
    }
533
6.81k
    if(0 == ps_enc_ctxt->i4_resolution_id)
534
6.81k
    {
535
        /* ---------- LAP Memtabs--------------- */
536
6.81k
        total_memtabs_req += ihevce_lap_get_num_mem_recs();
537
6.81k
    }
538
    /* ---------- Decomp Pre Intra Memtabs--------------- */
539
6.81k
    total_memtabs_req += ihevce_decomp_pre_intra_get_num_mem_recs();
540
541
    /* ---------- RC memtabs --------------- */
542
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
543
6.81k
    {
544
6.81k
        total_memtabs_req += ihevce_rc_get_num_mem_recs(); /*HEVC_RC*/
545
6.81k
    }
546
547
    /* ---------- System Memtabs ----------- */
548
6.81k
    total_memtabs_req += TOTAL_SYSTEM_MEM_RECS;  //increment this based on final requirement
549
550
    /* -----Frameproc Entcod Que Memtabs --- */
551
    /* one queue for each bit-rate is used */
552
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
553
6.81k
    {
554
6.81k
        total_memtabs_req += ihevce_buff_que_get_num_mem_recs();
555
6.81k
    }
556
    /* mrs:memtab for one queue for encoder owned input queue, This is only request for memtab, currently more than
557
    required memtabs are allocated. Hence my change of using memtab for yuv buffers is surviving. Only memtab
558
    usage and initialization needs to be exact sync*/
559
6.81k
    total_memtabs_req += ihevce_buff_que_get_num_mem_recs();
560
561
    /* ---Pre-encode Encode Que Mem requests -- */
562
6.81k
    total_memtabs_req += ihevce_buff_que_get_num_mem_recs();
563
564
    /* -----ME / Enc-RD opt Que Mem requests --- */
565
6.81k
    total_memtabs_req += ihevce_buff_que_get_num_mem_recs();
566
567
    /* ----Pre-encode L0 IPE to enc Que Mem requests -- */
568
6.81k
    total_memtabs_req += ihevce_buff_que_get_num_mem_recs();
569
570
    /* --- ME-EncLoop Dep Mngr Row-Row Mem requests -- */
571
6.81k
    total_memtabs_req += NUM_ME_ENC_BUFS * ihevce_dmgr_get_num_mem_recs();
572
573
    /* --- Prev. frame EncLoop Done Dep Mngr Frm-Frm Mem requests -- */
574
6.81k
    total_memtabs_req += i4_num_enc_loop_frm_pllel * ihevce_dmgr_get_num_mem_recs();
575
576
    /* --- Prev. frame EncLoop Done for re-encode Dep Mngr Frm-Frm Mem requests -- */
577
6.81k
    total_memtabs_req += ihevce_dmgr_get_num_mem_recs();
578
579
    /* --- Prev. frame ME Done Dep Mngr Frm-Frm Mem requests -- */
580
6.81k
    total_memtabs_req += i4_num_me_frm_pllel * ihevce_dmgr_get_num_mem_recs();
581
582
    /* --- Prev. frame PreEnc L1 Done Dep Mngr Frm-Frm Mem requests -- */
583
6.81k
    total_memtabs_req += ihevce_dmgr_get_num_mem_recs();
584
585
    /* --- Prev. frame PreEnc HME Done Dep Mngr Frm-Frm Mem requests -- */
586
6.81k
    total_memtabs_req += ihevce_dmgr_get_num_mem_recs();
587
588
    /* --- Prev. frame PreEnc L0 Done Dep Mngr Frm-Frm Mem requests -- */
589
6.81k
    total_memtabs_req += ihevce_dmgr_get_num_mem_recs();
590
591
    /* --- ME-Prev Recon Dep Mngr Row-Frm Mem requests -- */
592
6.81k
    total_memtabs_req +=
593
6.81k
        (max_num_ref_pics + 1 + NUM_EXTRA_RECON_BUFS) * ihevce_dmgr_get_num_mem_recs();
594
595
    /* ----- allocate memomry for memtabs --- */
596
6.81k
    {
597
6.81k
        iv_mem_rec_t s_memtab;
598
599
6.81k
        s_memtab.i4_size = sizeof(iv_mem_rec_t);
600
6.81k
        s_memtab.i4_mem_size = total_memtabs_req * sizeof(iv_mem_rec_t);
601
6.81k
        s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
602
6.81k
        s_memtab.i4_mem_alignment = 4;
603
604
6.81k
        ps_intrf_ctxt->ihevce_mem_alloc(
605
6.81k
            ps_intrf_ctxt->pv_mem_mgr_hdl, &ps_enc_ctxt->ps_stat_prms->s_sys_api, &s_memtab);
606
6.81k
        if(s_memtab.pv_base == NULL)
607
0
        {
608
0
            ps_intrf_ctxt->i4_error_code = IHEVCE_CANNOT_ALLOCATE_MEMORY;
609
0
            return;
610
0
        }
611
612
6.81k
        ps_memtab = (iv_mem_rec_t *)s_memtab.pv_base;
613
6.81k
    }
614
615
    /* --------------------------------------------------------------------- */
616
    /* ------------------  Collating memory requirements ------------------- */
617
    /* --------------------------------------------------------------------- */
618
619
    /* ----------- Tiles mem requests -------------*/
620
0
    total_memtabs_used += ihevce_tiles_get_mem_recs(
621
6.81k
        &ps_memtab[total_memtabs_used],
622
6.81k
        ps_enc_ctxt->ps_stat_prms,
623
6.81k
        &ps_enc_ctxt->s_frm_ctb_prms,
624
6.81k
        i4_resolution_id,
625
6.81k
        space_for_mem_in_enc_grp);
626
627
    /* ---------- Enc loop Mem requests --------- */
628
6.81k
    total_memtabs_used += ihevce_enc_loop_get_mem_recs(
629
6.81k
        &ps_memtab[total_memtabs_used],
630
6.81k
        ps_enc_ctxt->ps_stat_prms,
631
6.81k
        ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
632
6.81k
        i4_num_bitrate_inst,
633
6.81k
        i4_num_enc_loop_frm_pllel,
634
6.81k
        space_for_mem_in_enc_grp,
635
6.81k
        i4_resolution_id);
636
    /* ---------- ME Mem requests --------------- */
637
6.81k
    total_memtabs_used += ihevce_me_get_mem_recs(
638
6.81k
        &ps_memtab[total_memtabs_used],
639
6.81k
        ps_enc_ctxt->ps_stat_prms,
640
6.81k
        ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
641
6.81k
        space_for_mem_in_enc_grp,
642
6.81k
        i4_resolution_id,
643
6.81k
        i4_num_me_frm_pllel);
644
645
    /* ---------- Coarse ME Mem requests --------------- */
646
6.81k
    total_memtabs_used += ihevce_coarse_me_get_mem_recs(
647
6.81k
        &ps_memtab[total_memtabs_used],
648
6.81k
        ps_enc_ctxt->ps_stat_prms,
649
6.81k
        ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds,
650
6.81k
        space_for_mem_in_pre_enc_grp,
651
6.81k
        i4_resolution_id);
652
    /* ---------- IPE Mem requests -------------- */
653
6.81k
    total_memtabs_used += ihevce_ipe_get_mem_recs(
654
6.81k
        &ps_memtab[total_memtabs_used],
655
6.81k
        ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds,
656
6.81k
        space_for_mem_in_pre_enc_grp);
657
    /* ---------- ECD Mem requests -------------- */
658
6.81k
    i4_num_bitrate_inst = ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id]
659
6.81k
                              .i4_num_bitrate_instances;
660
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
661
6.81k
    {
662
6.81k
        total_memtabs_used += ihevce_entropy_get_mem_recs(
663
6.81k
            &ps_memtab[total_memtabs_used],
664
6.81k
            ps_enc_ctxt->ps_stat_prms,
665
6.81k
            space_for_mem_in_pre_enc_grp,
666
6.81k
            i4_resolution_id);
667
6.81k
    }
668
669
6.81k
    if(0 == i4_resolution_id)
670
6.81k
    {
671
        /* ---------- LAP Mem requests--------------- */
672
6.81k
        total_memtabs_used +=
673
6.81k
            ihevce_lap_get_mem_recs(&ps_memtab[total_memtabs_used], space_for_mem_in_pre_enc_grp);
674
6.81k
    }
675
676
    /* -------- DECOMPOSITION PRE INTRA Mem requests-------- */
677
6.81k
    total_memtabs_used += ihevce_decomp_pre_intra_get_mem_recs(
678
6.81k
        &ps_memtab[total_memtabs_used],
679
6.81k
        ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds,
680
6.81k
        space_for_mem_in_pre_enc_grp);
681
682
    /* ---------- RC Mem requests --------------- */
683
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
684
6.81k
    {
685
6.81k
        total_memtabs_used += ihevce_rc_get_mem_recs(
686
6.81k
            &ps_memtab[total_memtabs_used],
687
6.81k
            ps_enc_ctxt->ps_stat_prms,
688
6.81k
            space_for_mem_in_pre_enc_grp,
689
6.81k
            &ps_enc_ctxt->ps_stat_prms->s_sys_api);
690
6.81k
    }
691
692
    /* ---------- System Mem requests ----------- */
693
694
    /* allocate memory for pps tile */
695
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
696
697
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
698
699
6.81k
    if(1 == ps_enc_ctxt->ps_stat_prms->s_app_tile_params.i4_tiles_enabled_flag)
700
0
    {
701
0
        ps_memtab[total_memtabs_used].i4_mem_size =
702
0
            (ps_enc_ctxt->ps_stat_prms->s_app_tile_params.i4_num_tile_cols *
703
0
             ps_enc_ctxt->ps_stat_prms->s_app_tile_params.i4_num_tile_rows) *
704
0
            (sizeof(tile_t));
705
0
    }
706
6.81k
    else
707
6.81k
    {
708
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size = sizeof(tile_t);
709
6.81k
    }
710
711
    /* increment the memtab counter */
712
6.81k
    total_memtabs_used++;
713
6.81k
    total_system_memtabs++;
714
715
    /* recon picture buffer pointer array */
716
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
717
6.81k
    {
718
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
719
720
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
721
722
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
723
6.81k
            (max_num_ref_pics + 1 + NUM_EXTRA_RECON_BUFS) * (sizeof(recon_pic_buf_t *));
724
725
        /* increment the memtab counter */
726
6.81k
        total_memtabs_used++;
727
6.81k
        total_system_memtabs++;
728
6.81k
    }
729
730
    /* recon picture buffers structures */
731
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
732
6.81k
    {
733
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
734
735
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
736
737
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
738
6.81k
            (max_num_ref_pics + 1 + NUM_EXTRA_RECON_BUFS) * (sizeof(recon_pic_buf_t));
739
740
        /* increment the memtab counter */
741
6.81k
        total_memtabs_used++;
742
6.81k
        total_system_memtabs++;
743
6.81k
    }
744
745
    /* reference/recon picture buffers */
746
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
747
6.81k
    {
748
6.81k
        WORD32 i4_chroma_buf_size_shift =
749
6.81k
            -(ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_internal_bit_depth <= 8) +
750
6.81k
            (ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_chr_format == IV_YUV_422SP_UV);
751
752
6.81k
        buf_size = ((num_ctb_horz * ctb_size) + (PAD_HORZ << 1));
753
6.81k
        buf_size = buf_size * ((num_ctb_vert * ctb_size) + (PAD_VERT << 1));
754
6.81k
        buf_size = buf_size * (max_num_ref_pics + 1 + NUM_EXTRA_RECON_BUFS);
755
756
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
757
758
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
759
760
        /* If HBD, both 8bit and 16 bit luma buffers are required, whereas only 16bit chroma buffers are required */
761
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
762
            /* Luma */
763
6.81k
            (buf_size * ((ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_internal_bit_depth > 8)
764
6.81k
                             ? BUFFER_SIZE_MULTIPLIER_IF_HBD
765
6.81k
                             : 1)) +
766
            /* Chroma */
767
6.81k
            (SHL_NEG(buf_size, i4_chroma_buf_size_shift));
768
769
        /* increment the memtab counter */
770
6.81k
        total_memtabs_used++;
771
6.81k
        total_system_memtabs++;
772
6.81k
    }
773
    /* reference/recon picture subpel planes */
774
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
775
776
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
777
778
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size =
779
6.81k
        buf_size * (3 + L0ME_IN_OPENLOOP_MODE); /* 3 planes */
780
781
    /* increment the memtab counter */
782
6.81k
    total_memtabs_used++;
783
6.81k
    total_system_memtabs++;
784
    /* reference colocated MV bank */
785
    /* Keep memory for an extra CTB at the right and bottom of frame.
786
    This extra space is needed by dist-encoding and unused in non-dist-encoding */
787
6.81k
    buf_size = (num_ctb_horz + 1) * (num_ctb_vert + 1) * num_pu_in_ctb;
788
6.81k
    buf_size = buf_size * sizeof(pu_col_mv_t) * (max_num_ref_pics + 1 + NUM_EXTRA_RECON_BUFS) *
789
6.81k
               i4_num_bitrate_inst;
790
791
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
792
793
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
794
795
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
796
797
    /* increment the memtab counter */
798
6.81k
    total_memtabs_used++;
799
6.81k
    total_system_memtabs++;
800
801
    /* reference colocated MV bank map */
802
    /* Keep memory for an extra CTB at the right and bottom of frame.
803
    This extra space is needed by dist-encoding and unused in non-dist-encoding */
804
6.81k
    buf_size = (num_ctb_horz + 1) * (num_ctb_vert + 1) * num_pu_in_ctb;
805
6.81k
    buf_size = buf_size * sizeof(UWORD8) * (max_num_ref_pics + 1 + NUM_EXTRA_RECON_BUFS) *
806
6.81k
               i4_num_bitrate_inst;
807
808
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
809
810
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
811
812
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
813
814
    /* increment the memtab counter */
815
6.81k
    total_memtabs_used++;
816
6.81k
    total_system_memtabs++;
817
818
    /* reference collocated MV bank map offsets map */
819
6.81k
    buf_size = num_ctb_horz * num_ctb_vert;
820
6.81k
    buf_size = buf_size * sizeof(UWORD16) * (max_num_ref_pics + 1 + NUM_EXTRA_RECON_BUFS) *
821
6.81k
               i4_num_bitrate_inst;
822
823
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
824
825
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
826
827
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
828
829
    /* increment the memtab counter */
830
6.81k
    total_memtabs_used++;
831
6.81k
    total_system_memtabs++;
832
833
    /* reference colocated MV bank ctb offset */
834
6.81k
    buf_size = num_ctb_horz;
835
6.81k
    buf_size = buf_size * num_ctb_vert;
836
6.81k
    buf_size = buf_size * sizeof(UWORD32) * (max_num_ref_pics + 1 + NUM_EXTRA_RECON_BUFS) *
837
6.81k
               i4_num_bitrate_inst;
838
839
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
840
841
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
842
843
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
844
845
    /* increment the memtab counter */
846
6.81k
    total_memtabs_used++;
847
6.81k
    total_system_memtabs++;
848
849
    /* recon picture buffer pointer array for pre enc group */
850
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
851
852
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
853
854
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size =
855
6.81k
        (max_num_ref_pics + 1) * (sizeof(recon_pic_buf_t *));
856
857
    /* increment the memtab counter */
858
6.81k
    total_memtabs_used++;
859
6.81k
    total_system_memtabs++;
860
861
    /* recon picture buffers structures for pre enc group */
862
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
863
864
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
865
866
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = (max_num_ref_pics + 1) * (sizeof(recon_pic_buf_t));
867
868
    /* increment the memtab counter */
869
6.81k
    total_memtabs_used++;
870
6.81k
    total_system_memtabs++;
871
6.81k
    {
872
6.81k
        num_input_buf_per_queue = ihevce_lap_get_num_ip_bufs(&ps_enc_ctxt->s_lap_stat_prms);
873
6.81k
        {
874
6.81k
            WORD32 i4_count_temp = 0, i4_last_queue_length;
875
876
            /*First allocate the memory for the buffer based on resolution*/
877
6.81k
            WORD32 ctb_align_pic_wd = ps_enc_ctxt->s_runtime_tgt_params.i4_width +
878
6.81k
                                      SET_CTB_ALIGN(
879
6.81k
                                          ps_enc_ctxt->s_runtime_tgt_params.i4_width,
880
6.81k
                                          ps_enc_ctxt->s_frm_ctb_prms.i4_ctb_size);
881
882
6.81k
            WORD32 ctb_align_pic_ht = ps_enc_ctxt->s_runtime_tgt_params.i4_height +
883
6.81k
                                      SET_CTB_ALIGN(
884
6.81k
                                          ps_enc_ctxt->s_runtime_tgt_params.i4_height,
885
6.81k
                                          ps_enc_ctxt->s_frm_ctb_prms.i4_ctb_size);
886
887
6.81k
            i4_last_queue_length = (num_input_buf_per_queue % MAX_QUEUE);
888
889
6.81k
            if((num_input_buf_per_queue % MAX_QUEUE) == 0)
890
0
                i4_last_queue_length = MAX_QUEUE;
891
892
6.81k
            ps_enc_ctxt->i4_num_input_buf_per_queue = num_input_buf_per_queue;
893
6.81k
            i4_yuv_min_size =
894
6.81k
                (ctb_align_pic_wd * ctb_align_pic_ht) +
895
6.81k
                ((ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_chr_format == IV_YUV_422SP_UV)
896
6.81k
                     ? (ctb_align_pic_wd * ctb_align_pic_ht)
897
6.81k
                     : ((ctb_align_pic_wd * ctb_align_pic_ht) >> 1));
898
6.81k
            i4_luma_min_size = (ctb_align_pic_wd * ctb_align_pic_ht);
899
900
            /*Inorder to allocate memory for the large buffer sizes overflowing WORD32 we are splitting the memtabs using i4_total_hbd_queues and MAX_HBD_QUEUE*/
901
6.81k
            i4_total_queues = num_input_buf_per_queue / MAX_QUEUE;
902
903
6.81k
            if((num_input_buf_per_queue % MAX_QUEUE) != 0)
904
6.81k
            {
905
6.81k
                i4_total_queues++;
906
6.81k
            }
907
908
6.81k
            ASSERT(i4_total_queues < 5);
909
910
13.6k
            for(i4_count_temp = 0; i4_count_temp < i4_total_queues; i4_count_temp++)
911
6.81k
            {
912
6.81k
                ps_memtab[total_memtabs_used].i4_mem_alignment = 32;
913
914
6.81k
                ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
915
                /*Memory size for yuv buffer of one frame * num of input required to stored in the queue*/
916
6.81k
                if((i4_count_temp < (i4_total_queues - 1)))
917
0
                    ps_memtab[total_memtabs_used].i4_mem_size = i4_yuv_min_size * MAX_QUEUE;
918
6.81k
                else
919
6.81k
                    ps_memtab[total_memtabs_used].i4_mem_size =
920
6.81k
                        (i4_yuv_min_size)*i4_last_queue_length;
921
922
                /* increment the memtab counter */
923
6.81k
                total_memtabs_used++;
924
6.81k
                total_system_memtabs++;
925
6.81k
            }
926
6.81k
        }
927
        /*memory for input buffer structure*/
928
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
929
930
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
931
932
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
933
6.81k
            (num_input_buf_per_queue) * (sizeof(ihevce_lap_enc_buf_t *));
934
935
        /* increment the memtab counter */
936
6.81k
        total_memtabs_used++;
937
6.81k
        total_system_memtabs++;
938
939
        /* frame process/entropy coding buffer structures */
940
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
941
942
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
943
944
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
945
6.81k
            (num_input_buf_per_queue) * (sizeof(ihevce_lap_enc_buf_t));
946
        /* increment the memtab counter */
947
6.81k
        total_memtabs_used++;
948
6.81k
        total_system_memtabs++;
949
950
        /*input synch ctrl command*/
951
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
952
953
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
954
955
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
956
6.81k
            (num_input_buf_per_queue) * (ENC_COMMAND_BUFF_SIZE);
957
958
6.81k
        total_memtabs_used++;
959
6.81k
        total_system_memtabs++;
960
6.81k
    }
961
962
    /* Pre-encode/encode coding buffer pointer array */
963
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
964
965
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
966
967
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size =
968
6.81k
        (num_bufs_preenc_me_que) * (sizeof(pre_enc_me_ctxt_t *));
969
970
    /* increment the memtab counter */
971
6.81k
    total_memtabs_used++;
972
6.81k
    total_system_memtabs++;
973
974
    /* frame process/entropy coding buffer structures */
975
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
976
977
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
978
979
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size =
980
6.81k
        (num_bufs_preenc_me_que) * (sizeof(pre_enc_me_ctxt_t));
981
982
    /* increment the memtab counter */
983
6.81k
    total_memtabs_used++;
984
6.81k
    total_system_memtabs++;
985
986
    /* Pre-encode L0 IPE output to ME buffer pointer*/
987
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
988
989
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
990
991
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size =
992
6.81k
        (num_bufs_L0_ipe_enc) * (sizeof(pre_enc_L0_ipe_encloop_ctxt_t *));
993
994
    /* increment the memtab counter */
995
6.81k
    total_memtabs_used++;
996
6.81k
    total_system_memtabs++;
997
998
    /* Pre-encode L0 IPE output to ME buffer */
999
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1000
1001
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1002
1003
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size =
1004
6.81k
        (num_bufs_L0_ipe_enc) * (sizeof(pre_enc_L0_ipe_encloop_ctxt_t));
1005
1006
    /* increment the memtab counter */
1007
6.81k
    total_memtabs_used++;
1008
6.81k
    total_system_memtabs++;
1009
1010
    /* CTB analyse Frame level  */
1011
6.81k
    buf_size = num_ctb_horz;
1012
6.81k
    buf_size = buf_size * num_ctb_vert;
1013
6.81k
    buf_size = buf_size * sizeof(ctb_analyse_t) * num_bufs_preenc_me_que;
1014
1015
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1016
1017
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1018
1019
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1020
1021
    /* increment the memtab counter */
1022
6.81k
    total_memtabs_used++;
1023
6.81k
    total_system_memtabs++;
1024
1025
    /* ME layer ctxt pointer */
1026
6.81k
    buf_size = sizeof(layer_ctxt_t) * num_bufs_preenc_me_que;
1027
1028
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1029
1030
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1031
1032
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1033
1034
    /* increment the memtab counter */
1035
6.81k
    total_memtabs_used++;
1036
6.81k
    total_system_memtabs++;
1037
1038
    /* ME layer MV bank ctxt pointer */
1039
6.81k
    buf_size = sizeof(layer_mv_t) * num_bufs_preenc_me_que;
1040
1041
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1042
1043
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1044
1045
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1046
1047
    /* increment the memtab counter */
1048
6.81k
    total_memtabs_used++;
1049
6.81k
    total_system_memtabs++;
1050
1051
    /* ME layer MV bank pointer */
1052
6.81k
    buf_size = mv_bank_size * num_bufs_preenc_me_que;
1053
1054
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1055
1056
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1057
1058
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1059
1060
    /* increment the memtab counter */
1061
6.81k
    total_memtabs_used++;
1062
6.81k
    total_system_memtabs++;
1063
1064
    /* ME layer ref idx bank pointer */
1065
6.81k
    buf_size = ref_idx_bank_size * num_bufs_preenc_me_que;
1066
1067
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1068
1069
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1070
1071
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1072
1073
    /* increment the memtab counter */
1074
6.81k
    total_memtabs_used++;
1075
6.81k
    total_system_memtabs++;
1076
    /* Frame level array to store 8x8 intra cost */
1077
6.81k
    buf_size = (num_ctb_horz * ctb_size) >> 3;
1078
6.81k
    buf_size *= ((num_ctb_vert * ctb_size) >> 3);
1079
6.81k
    buf_size *= sizeof(double) * num_bufs_preenc_me_que;
1080
1081
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1082
1083
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1084
1085
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1086
1087
    /* increment the memtab counter */
1088
6.81k
    total_memtabs_used++;
1089
6.81k
    total_system_memtabs++;
1090
1091
    /* Frame level array to store ctb intra cost and modes */
1092
6.81k
    buf_size = (num_ctb_horz * num_ctb_vert);
1093
6.81k
    buf_size *= sizeof(ipe_l0_ctb_analyse_for_me_t) * num_bufs_L0_ipe_enc;
1094
1095
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1096
1097
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1098
1099
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1100
1101
    /* increment the memtab counter */
1102
6.81k
    total_memtabs_used++;
1103
6.81k
    total_system_memtabs++;
1104
1105
    /*
1106
    * Layer early decision buffer L1 buf.Since the pre intra analysis always
1107
    * expects memory for ihevce_ed_blk_t for complete ctbs, align the width and
1108
    * height in layer to mutiple of 32.
1109
    */
1110
6.81k
    buf_size = (a_ctb_align_wd[1] >> 5) * (a_ctb_align_ht[1] >> 5) * sizeof(ihevce_ed_ctb_l1_t) *
1111
6.81k
               num_bufs_preenc_me_que;
1112
1113
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1114
1115
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_pre_enc_grp;
1116
1117
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1118
1119
    /* increment the memtab counter */
1120
6.81k
    total_memtabs_used++;
1121
6.81k
    total_system_memtabs++;
1122
1123
    /*
1124
    * Layer early decision buffer L1 buf.Since the pre intra analysis always
1125
    * expects memory for ihevce_ed_blk_t for complete ctbs, align the width and
1126
    * height in layer to mutiple of 32.
1127
    */
1128
6.81k
    buf_size = (a_ctb_align_wd[1] >> 2) * (a_ctb_align_ht[1] >> 2) * sizeof(ihevce_ed_blk_t) *
1129
6.81k
               num_bufs_preenc_me_que;
1130
1131
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1132
1133
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_pre_enc_grp;
1134
1135
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1136
1137
    /* increment the memtab counter */
1138
6.81k
    total_memtabs_used++;
1139
6.81k
    total_system_memtabs++;
1140
1141
    /*
1142
    * Layer early decision buffer L2 buf.Since the pre intra analysis always
1143
    * expects memory for ihevce_ed_blk_t for complete ctbs, align the width and
1144
    * height in layer to mutiple of 16.
1145
    */
1146
6.81k
    buf_size = (a_ctb_align_wd[2] >> 2) * (a_ctb_align_ht[2] >> 2) * sizeof(ihevce_ed_blk_t) *
1147
6.81k
               num_bufs_preenc_me_que;
1148
1149
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1150
1151
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_pre_enc_grp;
1152
1153
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1154
1155
    /* increment the memtab counter */
1156
6.81k
    total_memtabs_used++;
1157
6.81k
    total_system_memtabs++;
1158
1159
    /* following is the buffer requirement of
1160
    que between me and enc*/
1161
1162
    /* me/enc que buffer pointer array */
1163
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1164
1165
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1166
1167
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = (NUM_ME_ENC_BUFS) * (sizeof(me_enc_rdopt_ctxt_t *));
1168
1169
    /* increment the memtab counter */
1170
6.81k
    total_memtabs_used++;
1171
6.81k
    total_system_memtabs++;
1172
1173
    /* fme/enc que buffer structures */
1174
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1175
1176
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1177
1178
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = (NUM_ME_ENC_BUFS) * (sizeof(me_enc_rdopt_ctxt_t));
1179
1180
    /* increment the memtab counter */
1181
6.81k
    total_memtabs_used++;
1182
6.81k
    total_system_memtabs++;
1183
1184
    /* Job Queue related memory                            */
1185
    /* max num ctb rows is doubled to take care worst case */
1186
    /* requirements because of HME layers                  */
1187
6.81k
    buf_size = (MAX_NUM_VERT_UNITS_FRM) * (NUM_ENC_JOBS_QUES)*NUM_ME_ENC_BUFS;  //PING_PONG_BUF;
1188
    /* In tile case, based on the number of column tiles,
1189
    we will have  separate jobQ per column tile        */
1190
6.81k
    if(1 == ps_enc_ctxt->ps_stat_prms->s_app_tile_params.i4_tiles_enabled_flag)
1191
0
    {
1192
0
        buf_size *= ps_enc_ctxt->ps_stat_prms->s_app_tile_params.i4_num_tile_cols;
1193
0
    }
1194
6.81k
    buf_size *= sizeof(job_queue_t);
1195
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1196
1197
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1198
1199
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1200
1201
    /* increment the memtab counter */
1202
6.81k
    total_memtabs_used++;
1203
6.81k
    total_system_memtabs++;
1204
1205
    /* cur_ctb_cu_tree_t Frame level  */
1206
6.81k
    buf_size = num_ctb_horz * MAX_NUM_NODES_CU_TREE;
1207
6.81k
    buf_size = buf_size * num_ctb_vert;
1208
1209
    /* ps_cu_analyse_inter buffer is used to popualte outputs form ME after using cu analyse form IPE */
1210
6.81k
    buf_size = buf_size * sizeof(cur_ctb_cu_tree_t) * NUM_ME_ENC_BUFS;
1211
1212
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1213
1214
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1215
1216
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1217
1218
    /* increment the memtab counter */
1219
6.81k
    total_memtabs_used++;
1220
6.81k
    total_system_memtabs++;
1221
1222
    /* me_ctb_data_t Frame level  */
1223
6.81k
    buf_size = num_ctb_horz * num_ctb_vert;
1224
1225
    /* This buffer is used to */
1226
6.81k
    buf_size = buf_size * sizeof(me_ctb_data_t) * NUM_ME_ENC_BUFS;
1227
1228
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1229
1230
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1231
1232
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1233
1234
    /* increment the memtab counter */
1235
6.81k
    total_memtabs_used++;
1236
6.81k
    total_system_memtabs++;
1237
1238
    /* following is for each bit-rate */
1239
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
1240
6.81k
    {
1241
        /* frame process/entropy coding buffer pointer array */
1242
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1243
1244
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1245
1246
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
1247
6.81k
            (NUM_FRMPROC_ENTCOD_BUFS) * (sizeof(frm_proc_ent_cod_ctxt_t *));
1248
1249
        /* increment the memtab counter */
1250
6.81k
        total_memtabs_used++;
1251
6.81k
        total_system_memtabs++;
1252
1253
        /* frame process/entropy coding buffer structures */
1254
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1255
1256
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1257
1258
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
1259
6.81k
            (NUM_FRMPROC_ENTCOD_BUFS) * (sizeof(frm_proc_ent_cod_ctxt_t));
1260
1261
        /* increment the memtab counter */
1262
6.81k
        total_memtabs_used++;
1263
6.81k
        total_system_memtabs++;
1264
1265
        /* CTB enc loop Frame level  */
1266
6.81k
        buf_size = num_ctb_horz;
1267
6.81k
        buf_size = buf_size * num_ctb_vert;
1268
6.81k
        buf_size = buf_size * sizeof(ctb_enc_loop_out_t) * NUM_FRMPROC_ENTCOD_BUFS;
1269
1270
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1271
1272
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1273
1274
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1275
1276
        /* increment the memtab counter */
1277
6.81k
        total_memtabs_used++;
1278
6.81k
        total_system_memtabs++;
1279
1280
        /* CU enc loop Frame level  */
1281
6.81k
        buf_size = num_ctb_horz * num_cu_in_ctb;
1282
6.81k
        buf_size = buf_size * num_ctb_vert;
1283
6.81k
        buf_size = buf_size * sizeof(cu_enc_loop_out_t) * NUM_FRMPROC_ENTCOD_BUFS;
1284
1285
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1286
1287
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1288
1289
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1290
1291
        /* increment the memtab counter */
1292
6.81k
        total_memtabs_used++;
1293
6.81k
        total_system_memtabs++;
1294
1295
        /* TU enc loop Frame level  */
1296
6.81k
        buf_size = num_ctb_horz * num_tu_in_ctb;
1297
6.81k
        buf_size = buf_size * num_ctb_vert;
1298
6.81k
        buf_size = buf_size * sizeof(tu_enc_loop_out_t) * NUM_FRMPROC_ENTCOD_BUFS;
1299
1300
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1301
1302
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1303
1304
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1305
1306
        /* increment the memtab counter */
1307
6.81k
        total_memtabs_used++;
1308
6.81k
        total_system_memtabs++;
1309
1310
        /* PU enc loop Frame level  */
1311
6.81k
        buf_size = num_ctb_horz * num_pu_in_ctb;
1312
6.81k
        buf_size = buf_size * num_ctb_vert;
1313
6.81k
        buf_size = buf_size * sizeof(pu_t) * NUM_FRMPROC_ENTCOD_BUFS;
1314
1315
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1316
1317
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1318
1319
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1320
1321
        /* increment the memtab counter */
1322
6.81k
        total_memtabs_used++;
1323
6.81k
        total_system_memtabs++;
1324
1325
        /* Coeffs Frame level  */
1326
6.81k
        buf_size =
1327
6.81k
            num_ctb_horz * ((ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_chr_format == IV_YUV_422SP_UV)
1328
6.81k
                                ? (num_tu_in_ctb << 1)
1329
6.81k
                                : ((num_tu_in_ctb * 3) >> 1));
1330
6.81k
        buf_size = buf_size * num_ctb_vert;
1331
6.81k
        buf_size = buf_size * sizeof(UWORD8) * MAX_SCAN_COEFFS_BYTES_4x4 * NUM_FRMPROC_ENTCOD_BUFS;
1332
1333
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1334
1335
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1336
1337
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1338
1339
        /* increment the memtab counter */
1340
6.81k
        total_memtabs_used++;
1341
6.81k
        total_system_memtabs++;
1342
1343
6.81k
#ifndef DISABLE_SEI
1344
        /* SEI Payload Data */
1345
6.81k
        buf_size = sizeof(UWORD8) * MAX_NUMBER_OF_SEI_PAYLOAD * MAX_SEI_PAYLOAD_PER_TLV *
1346
6.81k
                   NUM_FRMPROC_ENTCOD_BUFS;
1347
1348
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1349
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1350
1351
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1352
1353
        /* increment the memtab counter */
1354
6.81k
        total_memtabs_used++;
1355
6.81k
        total_system_memtabs++;
1356
6.81k
#endif
1357
6.81k
    }
1358
1359
    /* ------ Working mem frame level -------*/
1360
6.81k
    buf_size = ((num_ctb_horz * ctb_size) + 16);
1361
6.81k
    buf_size *= ((num_ctb_vert * ctb_size) + 23);
1362
6.81k
    buf_size *= sizeof(WORD16);
1363
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1364
1365
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1366
1367
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1368
1369
    /* increment the memtab counter */
1370
6.81k
    total_memtabs_used++;
1371
6.81k
    total_system_memtabs++;
1372
    /* Job Queue related memory                            */
1373
    /* max num ctb rows is doubled to take care worst case */
1374
    /* requirements because of HME layers                  */
1375
6.81k
    buf_size = (MAX_NUM_VERT_UNITS_FRM) * (NUM_PRE_ENC_JOBS_QUES) * (max_delay_preenc_l0_que);
1376
6.81k
    buf_size *= sizeof(job_queue_t);
1377
1378
6.81k
    ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
1379
1380
6.81k
    ps_memtab[total_memtabs_used].e_mem_type = (IV_MEM_TYPE_T)space_for_mem_in_enc_grp;
1381
1382
6.81k
    ps_memtab[total_memtabs_used].i4_mem_size = buf_size;
1383
1384
    /* increment the memtab counter */
1385
6.81k
    total_memtabs_used++;
1386
6.81k
    total_system_memtabs++;
1387
1388
    /* check on the system memtabs */
1389
6.81k
    ASSERT(total_system_memtabs <= TOTAL_SYSTEM_MEM_RECS);
1390
1391
    /* -----Frameproc Entcod Que Mem requests --- */
1392
    /*  derive for each bit-rate */
1393
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
1394
6.81k
    {
1395
6.81k
        total_memtabs_used += ihevce_buff_que_get_mem_recs(
1396
6.81k
            &ps_memtab[total_memtabs_used], NUM_FRMPROC_ENTCOD_BUFS, space_for_mem_in_enc_grp);
1397
6.81k
    }
1398
    /*mrs: Request memory for the input yuv queue*/
1399
6.81k
    total_memtabs_used += ihevce_buff_que_get_mem_recs(
1400
6.81k
        &ps_memtab[total_memtabs_used], num_input_buf_per_queue, space_for_mem_in_enc_grp);
1401
    /*------ The encoder owned input buffer queue*/
1402
    /* -----Pre-encode Encode Que Mem requests --- */
1403
6.81k
    total_memtabs_used += ihevce_buff_que_get_mem_recs(
1404
6.81k
        &ps_memtab[total_memtabs_used], num_bufs_preenc_me_que, space_for_mem_in_enc_grp);
1405
1406
    /* -----ME / Enc-RD opt Que Mem requests --- */
1407
6.81k
    total_memtabs_used += ihevce_buff_que_get_mem_recs(
1408
6.81k
        &ps_memtab[total_memtabs_used], NUM_ME_ENC_BUFS, space_for_mem_in_enc_grp);
1409
1410
    /* -----Pre-encode L0 IPE to enc Que Mem requests --- */
1411
6.81k
    total_memtabs_used += ihevce_buff_que_get_mem_recs(
1412
6.81k
        &ps_memtab[total_memtabs_used], num_bufs_L0_ipe_enc, space_for_mem_in_enc_grp);
1413
1414
    /* ---------- Dependency Manager allocations -------- */
1415
6.81k
    {
1416
        /* --- ME-EncLoop Dep Mngr Row-Row Mem requests -- */
1417
13.6k
        for(ctr = 0; ctr < NUM_ME_ENC_BUFS; ctr++)
1418
6.81k
        {
1419
6.81k
            total_memtabs_used += ihevce_dmgr_get_mem_recs(
1420
6.81k
                &ps_memtab[total_memtabs_used],
1421
6.81k
                DEP_MNGR_ROW_ROW_SYNC,
1422
6.81k
                (a_ctb_align_ht[0] / ctb_size),
1423
6.81k
                ps_enc_ctxt->ps_stat_prms->s_app_tile_params
1424
6.81k
                    .i4_num_tile_cols, /* Number of Col Tiles */
1425
6.81k
                ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
1426
6.81k
                space_for_mem_in_enc_grp);
1427
6.81k
        }
1428
1429
13.6k
        for(ctr = 0; ctr < i4_num_enc_loop_frm_pllel; ctr++)
1430
6.81k
        {
1431
            /* --- Prev. frame EncLoop Done Dep Mngr Frm-Frm Mem requests -- */
1432
6.81k
            total_memtabs_used += ihevce_dmgr_get_mem_recs(
1433
6.81k
                &ps_memtab[total_memtabs_used],
1434
6.81k
                DEP_MNGR_FRM_FRM_SYNC,
1435
6.81k
                (a_ctb_align_ht[0] / ctb_size),
1436
6.81k
                1, /* Number of Col Tiles : Don't care for FRM_FRM */
1437
6.81k
                ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
1438
6.81k
                space_for_mem_in_enc_grp);
1439
6.81k
        }
1440
        /* --- Prev. frame EncLoop Done for re-encode Dep Mngr Frm-Frm Mem requests -- */
1441
6.81k
        total_memtabs_used += ihevce_dmgr_get_mem_recs(
1442
6.81k
            &ps_memtab[total_memtabs_used],
1443
6.81k
            DEP_MNGR_FRM_FRM_SYNC,
1444
6.81k
            (a_ctb_align_ht[0] / ctb_size),
1445
6.81k
            1, /* Number of Col Tiles : Don't care for FRM_FRM */
1446
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
1447
6.81k
            space_for_mem_in_enc_grp);
1448
13.6k
        for(ctr = 0; ctr < i4_num_me_frm_pllel; ctr++)
1449
6.81k
        {
1450
            /* --- Prev. frame ME Done Dep Mngr Frm-Frm Mem requests -- */
1451
6.81k
            total_memtabs_used += ihevce_dmgr_get_mem_recs(
1452
6.81k
                &ps_memtab[total_memtabs_used],
1453
6.81k
                DEP_MNGR_FRM_FRM_SYNC,
1454
6.81k
                (a_ctb_align_ht[0] / ctb_size),
1455
6.81k
                1, /* Number of Col Tiles : Don't care for FRM_FRM */
1456
6.81k
                ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
1457
6.81k
                space_for_mem_in_enc_grp);
1458
6.81k
        }
1459
1460
        /* --- Prev. frame PreEnc L1 Done Dep Mngr Frm-Frm Mem requests -- */
1461
6.81k
        total_memtabs_used += ihevce_dmgr_get_mem_recs(
1462
6.81k
            &ps_memtab[total_memtabs_used],
1463
6.81k
            DEP_MNGR_FRM_FRM_SYNC,
1464
6.81k
            (a_ctb_align_ht[0] / ctb_size),
1465
6.81k
            1, /* Number of Col Tiles : Don't care for FRM_FRM */
1466
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds,
1467
6.81k
            space_for_mem_in_enc_grp);
1468
1469
        /* --- Prev. frame PreEnc HME Done Dep Mngr Frm-Frm Mem requests -- */
1470
6.81k
        total_memtabs_used += ihevce_dmgr_get_mem_recs(
1471
6.81k
            &ps_memtab[total_memtabs_used],
1472
6.81k
            DEP_MNGR_FRM_FRM_SYNC,
1473
6.81k
            (a_ctb_align_ht[0] / ctb_size),
1474
6.81k
            1, /* Number of Col Tiles : Don't care for FRM_FRM */
1475
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds,
1476
6.81k
            space_for_mem_in_enc_grp);
1477
1478
        /* --- Prev. frame PreEnc L0 Done Dep Mngr Frm-Frm Mem requests -- */
1479
6.81k
        total_memtabs_used += ihevce_dmgr_get_mem_recs(
1480
6.81k
            &ps_memtab[total_memtabs_used],
1481
6.81k
            DEP_MNGR_FRM_FRM_SYNC,
1482
6.81k
            (a_ctb_align_ht[0] / ctb_size),
1483
6.81k
            1, /* Number of Col Tiles : Don't care for FRM_FRM */
1484
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds,
1485
6.81k
            space_for_mem_in_enc_grp);
1486
1487
        /* --- ME-Prev Recon Dep Mngr Row-Frm Mem requests -- */
1488
40.8k
        for(ctr = 0; ctr < (max_num_ref_pics + 1 + NUM_EXTRA_RECON_BUFS); ctr++)
1489
34.0k
        {
1490
34.0k
            WORD32 i4_num_units = num_ctb_horz * num_ctb_vert;
1491
1492
34.0k
            total_memtabs_used += ihevce_dmgr_map_get_mem_recs(
1493
34.0k
                &ps_memtab[total_memtabs_used],
1494
34.0k
                i4_num_units,
1495
34.0k
                ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
1496
34.0k
                space_for_mem_in_enc_grp);
1497
34.0k
        }
1498
6.81k
    }
1499
1500
    /* ----- allocate memory as per requests ---- */
1501
1502
    /* check on memtabs requested v/s memtabs used */
1503
    //ittiam : should put an assert
1504
1505
    //ASSERT(total_memtabs_used == total_memtabs_req);
1506
1507
6.00M
    for(ctr = 0; ctr < total_memtabs_used; ctr++)
1508
5.99M
    {
1509
5.99M
        UWORD8 *pu1_mem = NULL;
1510
5.99M
        ps_intrf_ctxt->ihevce_mem_alloc(
1511
5.99M
            ps_intrf_ctxt->pv_mem_mgr_hdl, &ps_enc_ctxt->ps_stat_prms->s_sys_api, &ps_memtab[ctr]);
1512
1513
5.99M
        pu1_mem = (UWORD8 *)ps_memtab[ctr].pv_base;
1514
1515
5.99M
        if(NULL == pu1_mem)
1516
0
        {
1517
0
            ps_intrf_ctxt->i4_error_code = IHEVCE_CANNOT_ALLOCATE_MEMORY;
1518
0
            return;
1519
0
        }
1520
5.99M
    }
1521
1522
    /* --------------------------------------------------------------------- */
1523
    /* --------- Initialisation of Modules & System memory ----------------- */
1524
    /* --------------------------------------------------------------------- */
1525
1526
    /* store the final allocated memtabs */
1527
6.81k
    ps_enc_ctxt->s_mem_mngr.i4_num_create_memtabs = total_memtabs_used;
1528
6.81k
    ps_enc_ctxt->s_mem_mngr.ps_create_memtab = ps_memtab;
1529
1530
    /* ---------- Tiles Mem init --------- */
1531
6.81k
    ps_enc_ctxt->ps_tile_params_base = (ihevce_tile_params_t *)ihevce_tiles_mem_init(
1532
6.81k
        ps_memtab, ps_enc_ctxt->ps_stat_prms, ps_enc_ctxt, i4_resolution_id);
1533
1534
6.81k
    ps_memtab += ihevce_tiles_get_num_mem_recs();
1535
1536
    /* ---------- Enc loop Mem init --------- */
1537
6.81k
    ps_enc_ctxt->s_module_ctxt.pv_enc_loop_ctxt = ihevce_enc_loop_init(
1538
6.81k
        ps_memtab,
1539
6.81k
        ps_enc_ctxt->ps_stat_prms,
1540
6.81k
        ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
1541
6.81k
        ps_intrf_ctxt->pv_osal_handle,
1542
6.81k
        &ps_enc_ctxt->s_func_selector,
1543
6.81k
        &ps_enc_ctxt->s_rc_quant,
1544
6.81k
        ps_enc_ctxt->ps_tile_params_base,
1545
6.81k
        i4_resolution_id,
1546
6.81k
        i4_num_enc_loop_frm_pllel,
1547
6.81k
        ps_enc_ctxt->u1_is_popcnt_available);
1548
1549
6.81k
    ps_memtab += ihevce_enc_loop_get_num_mem_recs(i4_num_bitrate_inst, i4_num_enc_loop_frm_pllel);
1550
    /* ---------- ME Mem init --------------- */
1551
6.81k
    ps_enc_ctxt->s_module_ctxt.pv_me_ctxt = ihevce_me_init(
1552
6.81k
        ps_memtab,
1553
6.81k
        ps_enc_ctxt->ps_stat_prms,
1554
6.81k
        ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
1555
6.81k
        ps_intrf_ctxt->pv_osal_handle,
1556
6.81k
        &ps_enc_ctxt->s_rc_quant,
1557
6.81k
        (void *)ps_enc_ctxt->ps_tile_params_base,
1558
6.81k
        i4_resolution_id,
1559
6.81k
        i4_num_me_frm_pllel,
1560
6.81k
        ps_enc_ctxt->u1_is_popcnt_available);
1561
1562
6.81k
    ps_memtab += ihevce_me_get_num_mem_recs(i4_num_me_frm_pllel);
1563
1564
    /* ---------- Coarse ME Mem init --------------- */
1565
6.81k
    ps_enc_ctxt->s_module_ctxt.pv_coarse_me_ctxt = ihevce_coarse_me_init(
1566
6.81k
        ps_memtab,
1567
6.81k
        ps_enc_ctxt->ps_stat_prms,
1568
6.81k
        ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds,
1569
6.81k
        ps_intrf_ctxt->pv_osal_handle,
1570
6.81k
        i4_resolution_id,
1571
6.81k
        ps_enc_ctxt->u1_is_popcnt_available);
1572
1573
6.81k
    ps_memtab += ihevce_coarse_me_get_num_mem_recs();
1574
    /* ---------- IPE Mem init -------------- */
1575
6.81k
    ps_enc_ctxt->s_module_ctxt.pv_ipe_ctxt = ihevce_ipe_init(
1576
6.81k
        ps_memtab,
1577
6.81k
        ps_enc_ctxt->ps_stat_prms,
1578
6.81k
        ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds,
1579
6.81k
        ps_enc_ctxt->i4_ref_mbr_id,
1580
6.81k
        &ps_enc_ctxt->s_func_selector,
1581
6.81k
        &ps_enc_ctxt->s_rc_quant,
1582
6.81k
        i4_resolution_id,
1583
6.81k
        ps_enc_ctxt->u1_is_popcnt_available);
1584
1585
6.81k
    ps_memtab += ihevce_ipe_get_num_mem_recs();
1586
1587
6.81k
    ps_enc_ctxt->s_rc_quant.i2_max_qp = 51;
1588
6.81k
    ps_enc_ctxt->s_rc_quant.i2_min_qp = 0;
1589
6.81k
    ps_enc_ctxt->s_rc_quant.i1_qp_offset = 0;
1590
6.81k
    ps_enc_ctxt->s_rc_quant.i2_max_qscale =
1591
6.81k
        228 << 3;  // Q3 format is mantained for accuarate calc at lower qp
1592
6.81k
    ps_enc_ctxt->s_rc_quant.i2_min_qscale = 1;
1593
1594
    /* ---------- ECD Mem init -------------- */
1595
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
1596
6.81k
    {
1597
6.81k
        ps_enc_ctxt->s_module_ctxt.apv_ent_cod_ctxt[i] = ihevce_entropy_init(
1598
6.81k
            ps_memtab,
1599
6.81k
            ps_enc_ctxt->ps_stat_prms,
1600
6.81k
            (void *)ps_enc_ctxt->ps_tile_params_base,
1601
6.81k
            i4_resolution_id);
1602
1603
6.81k
        ps_memtab += ihevce_entropy_get_num_mem_recs();
1604
6.81k
    }
1605
1606
    /* ---------- LAP Mem init--------------- */
1607
6.81k
    if(i4_resolution_id == 0)
1608
6.81k
    {
1609
6.81k
        ps_enc_ctxt->s_module_ctxt.pv_lap_ctxt =
1610
6.81k
            ihevce_lap_init(ps_memtab, &ps_enc_ctxt->s_lap_stat_prms, ps_enc_ctxt->ps_stat_prms);
1611
1612
6.81k
        ps_memtab += ihevce_lap_get_num_mem_recs();
1613
6.81k
    }
1614
    /*-----------DECOMPOSITION PRE INTRA init----*/
1615
6.81k
    ps_enc_ctxt->s_module_ctxt.pv_decomp_pre_intra_ctxt = ihevce_decomp_pre_intra_init(
1616
6.81k
        ps_memtab,
1617
6.81k
        ps_enc_ctxt->ps_stat_prms,
1618
6.81k
        ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds,
1619
6.81k
        &ps_enc_ctxt->s_func_selector,
1620
6.81k
        i4_resolution_id,
1621
6.81k
        ps_enc_ctxt->u1_is_popcnt_available);
1622
1623
6.81k
    ps_memtab += ihevce_decomp_pre_intra_get_num_mem_recs();
1624
1625
    /* ---------- RC Mem init --------------- */
1626
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
1627
6.81k
    {
1628
        /*swaping of buf_id for 0th and reference bitrate location, as encoder
1629
        assumes always 0th loc for reference bitrate and app must receive in
1630
        the configured order*/
1631
6.81k
        if(i == 0)
1632
6.81k
        {
1633
6.81k
            ps_enc_ctxt->s_module_ctxt.apv_rc_ctxt[i] = ihevce_rc_mem_init(
1634
6.81k
                ps_memtab,
1635
6.81k
                ps_enc_ctxt->ps_stat_prms,
1636
6.81k
                ps_enc_ctxt->i4_ref_mbr_id,
1637
6.81k
                &ps_enc_ctxt->s_rc_quant,
1638
6.81k
                ps_enc_ctxt->i4_resolution_id,
1639
6.81k
                ps_enc_ctxt->i4_look_ahead_frames_in_first_pass);
1640
6.81k
        }
1641
0
        else if(i == ps_enc_ctxt->i4_ref_mbr_id)
1642
0
        {
1643
0
            ps_enc_ctxt->s_module_ctxt.apv_rc_ctxt[i] = ihevce_rc_mem_init(
1644
0
                ps_memtab,
1645
0
                ps_enc_ctxt->ps_stat_prms,
1646
0
                0,
1647
0
                &ps_enc_ctxt->s_rc_quant,
1648
0
                ps_enc_ctxt->i4_resolution_id,
1649
0
                ps_enc_ctxt->i4_look_ahead_frames_in_first_pass);
1650
0
        }
1651
0
        else
1652
0
        {
1653
0
            ps_enc_ctxt->s_module_ctxt.apv_rc_ctxt[i] = ihevce_rc_mem_init(
1654
0
                ps_memtab,
1655
0
                ps_enc_ctxt->ps_stat_prms,
1656
0
                i,
1657
0
                &ps_enc_ctxt->s_rc_quant,
1658
0
                ps_enc_ctxt->i4_resolution_id,
1659
0
                ps_enc_ctxt->i4_look_ahead_frames_in_first_pass);
1660
0
        }
1661
6.81k
        ps_memtab += ihevce_rc_get_num_mem_recs();
1662
6.81k
    }
1663
1664
    /* ---------- System Mem init ----------- */
1665
6.81k
    {
1666
6.81k
        recon_pic_buf_t **pps_pic_bufs[IHEVCE_MAX_NUM_BITRATES];
1667
6.81k
        recon_pic_buf_t *ps_pic_bufs[IHEVCE_MAX_NUM_BITRATES];
1668
6.81k
        void *pv_recon_buf[IHEVCE_MAX_NUM_BITRATES];
1669
6.81k
#if(SRC_PADDING_FOR_TRAQO || ENABLE_SSD_CALC_RC)
1670
6.81k
        void *pv_recon_buf_source[IHEVCE_MAX_NUM_BITRATES] = { NULL };
1671
6.81k
#endif
1672
6.81k
        void *pv_uv_recon_buf[IHEVCE_MAX_NUM_BITRATES];
1673
6.81k
        UWORD8 *pu1_subpel_buf;
1674
6.81k
        pu_col_mv_t *ps_col_mv;
1675
6.81k
        UWORD8 *pu1_col_mv_map;
1676
6.81k
        UWORD16 *pu2_col_num_pu_map;
1677
6.81k
        UWORD32 *pu4_col_mv_off;
1678
6.81k
        WORD32 luma_frm_size;
1679
6.81k
        WORD32 recon_stride; /* stride for Y and UV(interleave) */
1680
6.81k
        WORD32 luma_frm_height; /* including padding    */
1681
6.81k
        WORD32 num_pu_in_frm;
1682
1683
        /* pps tile memory */
1684
13.6k
        for(i = 0; i < i4_num_bitrate_inst; i++)
1685
6.81k
        {
1686
6.81k
            ps_enc_ctxt->as_pps[i].ps_tile = (tile_t *)ps_memtab->pv_base;
1687
6.81k
        }
1688
1689
6.81k
        ps_memtab++; /* increment the memtabs */
1690
1691
        /* recon picture buffer pointer array */
1692
13.6k
        for(i = 0; i < i4_num_bitrate_inst; i++)
1693
6.81k
        {
1694
6.81k
            pps_pic_bufs[i] = (recon_pic_buf_t **)ps_memtab->pv_base;
1695
6.81k
            ps_memtab++; /* increment the memtabs */
1696
6.81k
        }
1697
1698
        /* recon picture buffers structures */
1699
13.6k
        for(i = 0; i < i4_num_bitrate_inst; i++)
1700
6.81k
        {
1701
6.81k
            ps_pic_bufs[i] = (recon_pic_buf_t *)ps_memtab->pv_base;
1702
6.81k
            ps_memtab++; /* increment the memtabs */
1703
6.81k
        }
1704
1705
        /* reference/recon picture buffers */
1706
13.6k
        for(i = 0; i < i4_num_bitrate_inst; i++)
1707
6.81k
        {
1708
6.81k
            pv_recon_buf[i] = ps_memtab->pv_base;
1709
6.81k
            ps_memtab++; /* increment the memtabs */
1710
6.81k
        }
1711
        /* reference/recon picture subpel planes */
1712
6.81k
        pu1_subpel_buf = (UWORD8 *)ps_memtab->pv_base;
1713
        /* increment the memtabs */
1714
6.81k
        ps_memtab++;
1715
        /* reference colocated MV bank */
1716
6.81k
        ps_col_mv = (pu_col_mv_t *)ps_memtab->pv_base;
1717
        /* increment the memtabs */
1718
6.81k
        ps_memtab++;
1719
1720
        /* reference colocated MV bank map */
1721
6.81k
        pu1_col_mv_map = (UWORD8 *)ps_memtab->pv_base;
1722
        /* increment the memtabs */
1723
6.81k
        ps_memtab++;
1724
1725
        /* reference collocated MV bank map offsets map */
1726
6.81k
        pu2_col_num_pu_map = (UWORD16 *)ps_memtab->pv_base;
1727
        /* increment the memtabs */
1728
6.81k
        ps_memtab++;
1729
1730
        /* reference colocated MV bank ctb offset */
1731
6.81k
        pu4_col_mv_off = (UWORD32 *)ps_memtab->pv_base;
1732
        /* increment the memtabs */
1733
6.81k
        ps_memtab++;
1734
1735
        /* compute the stride and frame height after accounting for padding */
1736
6.81k
        recon_stride = ((num_ctb_horz * ctb_size) + (PAD_HORZ << 1));
1737
6.81k
        luma_frm_height = ((num_ctb_vert * ctb_size) + (PAD_VERT << 1));
1738
6.81k
        luma_frm_size = recon_stride * luma_frm_height;
1739
        /* The subpel buffer is also incremented to take care of padding */
1740
        /* Both luma and subpel buffer use same stride                   */
1741
6.81k
        pu1_subpel_buf += (recon_stride * PAD_VERT);
1742
6.81k
        pu1_subpel_buf += PAD_HORZ;
1743
1744
        /* Keep memory for an extra CTB at the right and bottom of frame.
1745
        This extra space is needed by dist-encoding and unused in non-dist-encoding */
1746
6.81k
        num_pu_in_frm = (num_ctb_horz + 1) * num_pu_in_ctb * (num_ctb_vert + 1);
1747
1748
13.6k
        for(i = 0; i < i4_num_bitrate_inst; i++)
1749
6.81k
        {
1750
6.81k
            pv_uv_recon_buf[i] = pv_recon_buf[i];
1751
1752
            /* increment the recon buffer to take care of padding */
1753
6.81k
            pv_recon_buf[i] = (UWORD8 *)pv_recon_buf[i] + (recon_stride * PAD_VERT) + PAD_HORZ;
1754
1755
            /* chroma buffer starts at the end of luma buffer */
1756
6.81k
            pv_uv_recon_buf[i] = (UWORD8 *)pv_uv_recon_buf[i] + luma_frm_size;
1757
6.81k
            if(ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_internal_bit_depth == 8)
1758
6.81k
            {
1759
                /* increment the chroma recon buffer to take care of padding    */
1760
                /* vert padding halved but horiz is same due to uv interleave   */
1761
6.81k
                pv_uv_recon_buf[i] =
1762
6.81k
                    (UWORD8 *)pv_uv_recon_buf[i] + (recon_stride * (PAD_VERT >> 1)) +
1763
6.81k
                    ((ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_chr_format == IV_YUV_422SP_UV)
1764
6.81k
                         ? (recon_stride * (PAD_VERT >> 1))
1765
6.81k
                         : 0);
1766
6.81k
                pv_uv_recon_buf[i] = (UWORD8 *)pv_uv_recon_buf[i] + PAD_HORZ;
1767
6.81k
            }
1768
1769
            /* loop to initialise all the memories */
1770
            /* initialize recon buffers */
1771
            /* only YUV buffers are allocated for each bit-rate instnaces.
1772
            Subpel buffers and col buffers are made NULL for auxiliary bit-rate instances,
1773
            since ME and IPE happens only for reference bit-rate instnace */
1774
40.8k
            for(ctr = 0; ctr < (max_num_ref_pics + 1 + NUM_EXTRA_RECON_BUFS); ctr++)
1775
34.0k
            {
1776
34.0k
                pps_pic_bufs[i][ctr] =
1777
34.0k
                    ps_pic_bufs[i];  //check the index of pps [i] should be first or last index?!!
1778
1779
34.0k
                ps_pic_bufs[i]->s_yuv_buf_desc.i4_size = sizeof(iv_enc_yuv_buf_t);
1780
34.0k
                ps_pic_bufs[i]->s_yuv_buf_desc.pv_y_buf = pv_recon_buf[i];
1781
34.0k
                ps_pic_bufs[i]->s_yuv_buf_desc.pv_v_buf = NULL;
1782
34.0k
                {
1783
34.0k
                    ps_pic_bufs[i]->s_yuv_buf_desc.pv_u_buf = pv_uv_recon_buf[i];
1784
34.0k
                }
1785
34.0k
                ps_pic_bufs[i]->apu1_y_sub_pel_planes[0] = ((i == 0) ? pu1_subpel_buf : NULL);
1786
34.0k
                ps_pic_bufs[i]->apu1_y_sub_pel_planes[1] =
1787
34.0k
                    ((i == 0) ? (pu1_subpel_buf + luma_frm_size) : NULL);
1788
34.0k
                ps_pic_bufs[i]->apu1_y_sub_pel_planes[2] =
1789
34.0k
                    ((i == 0) ? (pu1_subpel_buf + (luma_frm_size * 2)) : NULL);
1790
34.0k
                ps_pic_bufs[i]->ps_frm_col_mv = ps_col_mv;
1791
34.0k
                ps_pic_bufs[i]->pu1_frm_pu_map = pu1_col_mv_map;
1792
34.0k
                ps_pic_bufs[i]->pu2_num_pu_map = pu2_col_num_pu_map;
1793
34.0k
                ps_pic_bufs[i]->pu4_pu_off = pu4_col_mv_off;
1794
34.0k
                ps_pic_bufs[i]->i4_is_free = 1;
1795
34.0k
                ps_pic_bufs[i]->i4_poc = -1;
1796
34.0k
                ps_pic_bufs[i]->i4_display_num = -1;
1797
34.0k
                ps_pic_bufs[i]->i4_buf_id = ctr;
1798
1799
                /* frame level buff increments */
1800
34.0k
                ps_col_mv += num_pu_in_frm;
1801
34.0k
                pu1_col_mv_map += num_pu_in_frm;
1802
34.0k
                pu2_col_num_pu_map += (num_ctb_horz * num_ctb_vert);
1803
34.0k
                pu4_col_mv_off += (num_ctb_horz * num_ctb_vert);
1804
1805
34.0k
                if(ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_chr_format == IV_YUV_422SP_UV)
1806
0
                {
1807
0
                    pv_recon_buf[i] = (UWORD8 *)pv_recon_buf[i] + (luma_frm_size << 1);
1808
0
                    pv_uv_recon_buf[i] = (UWORD8 *)pv_uv_recon_buf[i] + (luma_frm_size << 1);
1809
0
                }
1810
34.0k
                else
1811
34.0k
                {
1812
34.0k
                    pv_recon_buf[i] = (UWORD8 *)pv_recon_buf[i] + ((3 * luma_frm_size) >> 1);
1813
34.0k
                    pv_uv_recon_buf[i] = (UWORD8 *)pv_uv_recon_buf[i] + ((3 * luma_frm_size) >> 1);
1814
34.0k
                }
1815
34.0k
                pu1_subpel_buf += ((3 + L0ME_IN_OPENLOOP_MODE) * luma_frm_size); /* 3 planes */
1816
34.0k
                ps_pic_bufs[i]++;
1817
34.0k
            }  //ctr ends
1818
1819
            /* store the queue pointer and num buffs to context */
1820
6.81k
            ps_enc_ctxt->pps_recon_buf_q[i] = pps_pic_bufs[i];
1821
6.81k
            ps_enc_ctxt->ai4_num_buf_recon_q[i] = (max_num_ref_pics + 1 + NUM_EXTRA_RECON_BUFS);
1822
1823
6.81k
        }  //bitrate ctr ends
1824
1825
6.81k
    }  //end of system memory init
1826
1827
    /* Pre encode group recon buffer  containier NO Buffers will be allocated / used */
1828
6.81k
    {
1829
6.81k
        recon_pic_buf_t *ps_pic_bufs;
1830
1831
        /* recon picture buffer pointer array */
1832
6.81k
        pps_pre_enc_pic_bufs = (recon_pic_buf_t **)ps_memtab->pv_base;
1833
        /* increment the memtabs */
1834
6.81k
        ps_memtab++;
1835
1836
        /* recon picture buffers structures */
1837
6.81k
        ps_pic_bufs = (recon_pic_buf_t *)ps_memtab->pv_base;
1838
        /* increment the memtabs */
1839
6.81k
        ps_memtab++;
1840
1841
        /* loop to initialise all the memories */
1842
40.8k
        for(ctr = 0; ctr < (max_num_ref_pics + 1); ctr++)
1843
34.0k
        {
1844
34.0k
            pps_pre_enc_pic_bufs[ctr] = ps_pic_bufs;
1845
1846
34.0k
            ps_pic_bufs->s_yuv_buf_desc.i4_size = sizeof(iv_enc_yuv_buf_t);
1847
34.0k
            ps_pic_bufs->s_yuv_buf_desc.pv_y_buf = NULL;
1848
34.0k
            ps_pic_bufs->s_yuv_buf_desc.pv_u_buf = NULL;
1849
34.0k
            ps_pic_bufs->s_yuv_buf_desc.pv_v_buf = NULL;
1850
34.0k
            ps_pic_bufs->apu1_y_sub_pel_planes[0] = NULL;
1851
34.0k
            ps_pic_bufs->apu1_y_sub_pel_planes[1] = NULL;
1852
34.0k
            ps_pic_bufs->apu1_y_sub_pel_planes[2] = NULL;
1853
34.0k
            ps_pic_bufs->ps_frm_col_mv = NULL;
1854
34.0k
            ps_pic_bufs->pu1_frm_pu_map = NULL;
1855
34.0k
            ps_pic_bufs->pu2_num_pu_map = NULL;
1856
34.0k
            ps_pic_bufs->pu4_pu_off = NULL;
1857
34.0k
            ps_pic_bufs->i4_is_free = 1;
1858
34.0k
            ps_pic_bufs->i4_poc = -1;
1859
34.0k
            ps_pic_bufs->i4_buf_id = ctr;
1860
1861
            /* frame level buff increments */
1862
34.0k
            ps_pic_bufs++;
1863
34.0k
        }
1864
1865
        /* store the queue pointer and num buffs to context */
1866
6.81k
        ps_enc_ctxt->pps_pre_enc_recon_buf_q = pps_pre_enc_pic_bufs;
1867
6.81k
        ps_enc_ctxt->i4_pre_enc_num_buf_recon_q = (max_num_ref_pics + 1);
1868
6.81k
    }
1869
1870
    /* Frame level buffers and Que between pre-encode & encode */
1871
6.81k
    {
1872
6.81k
        pre_enc_me_ctxt_t *ps_pre_enc_bufs;
1873
6.81k
        pre_enc_L0_ipe_encloop_ctxt_t *ps_L0_ipe_enc_bufs;
1874
6.81k
        ihevce_lap_enc_buf_t *ps_lap_enc_input_buf;
1875
6.81k
        ctb_analyse_t *ps_ctb_analyse;
1876
6.81k
        UWORD8 *pu1_me_lyr_ctxt;
1877
6.81k
        UWORD8 *pu1_me_lyr_bank_ctxt;
1878
6.81k
        UWORD8 *pu1_mv_bank;
1879
6.81k
        UWORD8 *pu1_ref_idx_bank;
1880
6.81k
        double *plf_intra_8x8_cost;
1881
6.81k
        ipe_l0_ctb_analyse_for_me_t *ps_ipe_analyse_ctb;
1882
6.81k
        ihevce_ed_ctb_l1_t *ps_ed_ctb_l1;
1883
6.81k
        ihevce_ed_blk_t *ps_layer1_buf;
1884
6.81k
        ihevce_ed_blk_t *ps_layer2_buf;
1885
6.81k
        UWORD8 *pu1_lap_input_yuv_buf[4];
1886
6.81k
        UWORD8 *pu1_input_synch_ctrl_cmd;
1887
6.81k
        WORD32 i4_count = 0;
1888
        /*initialize the memory for input buffer*/
1889
6.81k
        {
1890
13.6k
            for(i4_count = 0; i4_count < i4_total_queues; i4_count++)
1891
6.81k
            {
1892
6.81k
                pu1_lap_input_yuv_buf[i4_count] = (UWORD8 *)ps_memtab->pv_base;
1893
                /* increment the memtabs */
1894
6.81k
                ps_memtab++;
1895
6.81k
            }
1896
6.81k
            pps_lap_enc_input_bufs = (ihevce_lap_enc_buf_t **)ps_memtab->pv_base;
1897
            /* increment the memtabs */
1898
6.81k
            ps_memtab++;
1899
1900
            /*memory for the input buffer structure*/
1901
6.81k
            ps_lap_enc_input_buf = (ihevce_lap_enc_buf_t *)ps_memtab->pv_base;
1902
6.81k
            ps_memtab++;
1903
1904
6.81k
            pu1_input_synch_ctrl_cmd = (UWORD8 *)ps_memtab->pv_base;
1905
6.81k
            ps_memtab++;
1906
6.81k
        }
1907
        /* pre encode /encode coding buffer pointer array */
1908
6.81k
        pps_pre_enc_bufs = (pre_enc_me_ctxt_t **)ps_memtab->pv_base;
1909
        /* increment the memtabs */
1910
6.81k
        ps_memtab++;
1911
1912
        /* pre encode /encode buffer structure */
1913
6.81k
        ps_pre_enc_bufs = (pre_enc_me_ctxt_t *)ps_memtab->pv_base;
1914
        /* increment the memtabs */
1915
6.81k
        ps_memtab++;
1916
1917
        /*  Pre-encode L0 IPE output to ME buffer pointer */
1918
6.81k
        pps_L0_ipe_enc_bufs = (pre_enc_L0_ipe_encloop_ctxt_t **)ps_memtab->pv_base;
1919
        /* increment the memtabs */
1920
6.81k
        ps_memtab++;
1921
1922
        /* Pre-encode L0 IPE output to ME buffer */
1923
6.81k
        ps_L0_ipe_enc_bufs = (pre_enc_L0_ipe_encloop_ctxt_t *)ps_memtab->pv_base;
1924
        /* increment the memtabs */
1925
6.81k
        ps_memtab++;
1926
1927
        /* CTB analyse Frame level  */
1928
6.81k
        ps_ctb_analyse = (ctb_analyse_t *)ps_memtab->pv_base;
1929
        /* increment the memtabs */
1930
6.81k
        ps_memtab++;
1931
1932
        /* ME layer ctxt Frame level  */
1933
6.81k
        pu1_me_lyr_ctxt = (UWORD8 *)ps_memtab->pv_base;
1934
        /* increment the memtabs */
1935
6.81k
        ps_memtab++;
1936
1937
        /* ME layer bank ctxt Frame level  */
1938
6.81k
        pu1_me_lyr_bank_ctxt = (UWORD8 *)ps_memtab->pv_base;
1939
        /* increment the memtabs */
1940
6.81k
        ps_memtab++;
1941
1942
        /* ME layer MV bank Frame level  */
1943
6.81k
        pu1_mv_bank = (UWORD8 *)ps_memtab->pv_base;
1944
        /* increment the memtabs */
1945
6.81k
        ps_memtab++;
1946
1947
        /* ME layer ref idx bank Frame level  */
1948
6.81k
        pu1_ref_idx_bank = (UWORD8 *)ps_memtab->pv_base;
1949
        /* increment the memtabs */
1950
6.81k
        ps_memtab++;
1951
        /* 8x8 intra costs for entire frame */
1952
6.81k
        plf_intra_8x8_cost = (double *)ps_memtab->pv_base;
1953
6.81k
        ps_memtab++;
1954
1955
        /* ctb intra costs and modes for entire frame */
1956
6.81k
        ps_ipe_analyse_ctb = (ipe_l0_ctb_analyse_for_me_t *)ps_memtab->pv_base;
1957
6.81k
        ps_memtab++;
1958
1959
        /*Contains ctb level information at pre-intra stage */
1960
6.81k
        ps_ed_ctb_l1 = (ihevce_ed_ctb_l1_t *)ps_memtab->pv_base;
1961
6.81k
        ps_memtab++;
1962
1963
        /* Layer L1 buf */
1964
6.81k
        ps_layer1_buf = (ihevce_ed_blk_t *)ps_memtab->pv_base;
1965
        /* increment the memtabs */
1966
6.81k
        ps_memtab++;
1967
1968
        /* Layer2 buf */
1969
6.81k
        ps_layer2_buf = (ihevce_ed_blk_t *)ps_memtab->pv_base;
1970
        /* increment the memtabs */
1971
6.81k
        ps_memtab++;
1972
1973
        /* loop to initialise all the memories*/
1974
        /*mrs: assign individual input yuv frame pointers here*/
1975
1976
6.81k
        i4_count = 0;
1977
        /* loop to initialise the buffer pointer */
1978
25.7k
        for(ctr = 0; ctr < num_input_buf_per_queue; ctr++)
1979
18.9k
        {
1980
18.9k
            pps_lap_enc_input_bufs[ctr] = &ps_lap_enc_input_buf[ctr];
1981
1982
18.9k
            pps_lap_enc_input_bufs[ctr]->s_input_buf.i4_size = sizeof(iv_input_data_ctrl_buffs_t);
1983
1984
18.9k
            pps_lap_enc_input_bufs[ctr]->s_input_buf.pv_synch_ctrl_bufs = pu1_input_synch_ctrl_cmd;
1985
1986
18.9k
            pps_lap_enc_input_bufs[ctr]->s_input_buf.s_input_buf.i4_size = sizeof(iv_yuv_buf_t);
1987
1988
18.9k
            pu1_input_synch_ctrl_cmd += ENC_COMMAND_BUFF_SIZE;
1989
            /*pointer to i/p buf initialised to null in case of run time allocation*/
1990
1991
18.9k
            {
1992
18.9k
                pps_lap_enc_input_bufs[ctr]->s_lap_out.s_input_buf.pv_y_buf =
1993
18.9k
                    pu1_lap_input_yuv_buf[i4_count];
1994
1995
18.9k
                pps_lap_enc_input_bufs[ctr]->s_lap_out.s_input_buf.pv_u_buf =
1996
18.9k
                    pu1_lap_input_yuv_buf[i4_count] + i4_luma_min_size;
1997
1998
18.9k
                pps_lap_enc_input_bufs[ctr]->s_lap_out.s_input_buf.pv_v_buf =
1999
18.9k
                    NULL; /*since yuv 420 format*/
2000
2001
18.9k
                pu1_lap_input_yuv_buf[i4_count] += i4_yuv_min_size;
2002
2003
18.9k
                if(((ctr + 1) % MAX_QUEUE) == 0)
2004
0
                    i4_count++;
2005
18.9k
            }
2006
18.9k
        }
2007
20.4k
        for(ctr = 0; ctr < num_bufs_preenc_me_que; ctr++)
2008
13.6k
        {
2009
13.6k
            pps_pre_enc_bufs[ctr] = ps_pre_enc_bufs;
2010
2011
13.6k
            ps_pre_enc_bufs->ps_ctb_analyse = ps_ctb_analyse;
2012
13.6k
            ps_pre_enc_bufs->pv_me_lyr_ctxt = (void *)pu1_me_lyr_ctxt;
2013
13.6k
            ps_pre_enc_bufs->pv_me_lyr_bnk_ctxt = (void *)pu1_me_lyr_bank_ctxt;
2014
13.6k
            ps_pre_enc_bufs->pv_me_mv_bank = (void *)pu1_mv_bank;
2015
13.6k
            ps_pre_enc_bufs->pv_me_ref_idx = (void *)pu1_ref_idx_bank;
2016
13.6k
            ps_pre_enc_bufs->ps_layer1_buf = ps_layer1_buf;
2017
13.6k
            ps_pre_enc_bufs->ps_layer2_buf = ps_layer2_buf;
2018
13.6k
            ps_pre_enc_bufs->ps_ed_ctb_l1 = ps_ed_ctb_l1;
2019
13.6k
            ps_pre_enc_bufs->plf_intra_8x8_cost = plf_intra_8x8_cost;
2020
2021
13.6k
            ps_ctb_analyse += num_ctb_horz * num_ctb_vert;
2022
13.6k
            pu1_me_lyr_ctxt += sizeof(layer_ctxt_t);
2023
13.6k
            pu1_me_lyr_bank_ctxt += sizeof(layer_mv_t);
2024
13.6k
            pu1_mv_bank += mv_bank_size;
2025
13.6k
            pu1_ref_idx_bank += ref_idx_bank_size;
2026
13.6k
            plf_intra_8x8_cost +=
2027
13.6k
                (((num_ctb_horz * ctb_size) >> 3) * ((num_ctb_vert * ctb_size) >> 3));
2028
13.6k
            ps_ed_ctb_l1 += (a_ctb_align_wd[1] >> 5) * (a_ctb_align_ht[1] >> 5);
2029
13.6k
            ps_layer1_buf += (a_ctb_align_wd[1] >> 2) * (a_ctb_align_ht[1] >> 2);
2030
13.6k
            ps_layer2_buf += (a_ctb_align_wd[2] >> 2) * (a_ctb_align_ht[2] >> 2);
2031
13.6k
            ps_pre_enc_bufs++;
2032
13.6k
        }
2033
2034
13.6k
        for(ctr = 0; ctr < num_bufs_L0_ipe_enc; ctr++)
2035
6.81k
        {
2036
6.81k
            pps_L0_ipe_enc_bufs[ctr] = ps_L0_ipe_enc_bufs;
2037
6.81k
            ps_L0_ipe_enc_bufs->ps_ipe_analyse_ctb = ps_ipe_analyse_ctb;
2038
6.81k
            ps_ipe_analyse_ctb += num_ctb_horz * num_ctb_vert;
2039
6.81k
            ps_L0_ipe_enc_bufs++;
2040
6.81k
        }
2041
6.81k
    }
2042
2043
    /* Frame level que between ME and Enc rd-opt */
2044
6.81k
    {
2045
6.81k
        me_enc_rdopt_ctxt_t *ps_me_enc_bufs;
2046
6.81k
        job_queue_t *ps_job_q_enc;
2047
6.81k
        me_ctb_data_t *ps_cur_ctb_me_data;
2048
6.81k
        cur_ctb_cu_tree_t *ps_cur_ctb_cu_tree;
2049
2050
        /* pre encode /encode coding buffer pointer array */
2051
6.81k
        pps_me_enc_bufs = (me_enc_rdopt_ctxt_t **)ps_memtab->pv_base;
2052
        /* increment the memtabs */
2053
6.81k
        ps_memtab++;
2054
2055
        /* pre encode /encode buffer structure */
2056
6.81k
        ps_me_enc_bufs = (me_enc_rdopt_ctxt_t *)ps_memtab->pv_base;
2057
        /* increment the memtabs */
2058
6.81k
        ps_memtab++;
2059
2060
        /*me and enc job queue memory */
2061
6.81k
        ps_job_q_enc = (job_queue_t *)ps_memtab->pv_base;
2062
        /* increment the memtabs */
2063
6.81k
        ps_memtab++;
2064
2065
        /*ctb me data memory*/
2066
6.81k
        ps_cur_ctb_cu_tree = (cur_ctb_cu_tree_t *)ps_memtab->pv_base;
2067
        /* increment the memtabs */
2068
6.81k
        ps_memtab++;
2069
2070
        /*ctb me data memory*/
2071
6.81k
        ps_cur_ctb_me_data = (me_ctb_data_t *)ps_memtab->pv_base;
2072
        /* increment the memtabs */
2073
6.81k
        ps_memtab++;
2074
2075
        /* loop to initialise all the memories */
2076
13.6k
        for(ctr = 0; ctr < NUM_ME_ENC_BUFS; ctr++)
2077
6.81k
        {
2078
6.81k
            pps_me_enc_bufs[ctr] = ps_me_enc_bufs;
2079
2080
6.81k
            ps_me_enc_bufs->ps_job_q_enc = ps_job_q_enc;
2081
6.81k
            ps_me_enc_bufs->ps_cur_ctb_cu_tree = ps_cur_ctb_cu_tree;
2082
6.81k
            ps_me_enc_bufs->ps_cur_ctb_me_data = ps_cur_ctb_me_data;
2083
2084
6.81k
            ps_job_q_enc += (MAX_NUM_VERT_UNITS_FRM * NUM_ENC_JOBS_QUES);
2085
            /* In tile case, based on the number of column tiles,
2086
            increment jobQ per column tile        */
2087
6.81k
            if(1 == ps_enc_ctxt->ps_stat_prms->s_app_tile_params.i4_tiles_enabled_flag)
2088
0
            {
2089
0
                WORD32 col_tile_ctr;
2090
0
                for(col_tile_ctr = 1;
2091
0
                    col_tile_ctr < ps_enc_ctxt->ps_stat_prms->s_app_tile_params.i4_num_tile_cols;
2092
0
                    col_tile_ctr++)
2093
0
                {
2094
0
                    ps_job_q_enc += (MAX_NUM_VERT_UNITS_FRM * NUM_ENC_JOBS_QUES);
2095
0
                }
2096
0
            }
2097
2098
6.81k
            ps_cur_ctb_cu_tree += (num_ctb_horz * MAX_NUM_NODES_CU_TREE * num_ctb_vert);
2099
6.81k
            ps_cur_ctb_me_data += (num_ctb_horz * num_ctb_vert);
2100
2101
6.81k
            ps_me_enc_bufs++;
2102
6.81k
        }
2103
6.81k
    }
2104
    /* Frame level Que between frame process & entropy */
2105
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
2106
6.81k
    {
2107
6.81k
        frm_proc_ent_cod_ctxt_t *ps_frmp_ent_bufs;
2108
6.81k
        ctb_enc_loop_out_t *ps_ctb;
2109
6.81k
        cu_enc_loop_out_t *ps_cu;
2110
6.81k
        tu_enc_loop_out_t *ps_tu;
2111
6.81k
        pu_t *ps_pu;
2112
6.81k
        UWORD8 *pu1_coeffs;
2113
6.81k
        WORD32 num_ctb_in_frm;
2114
6.81k
        WORD32 coeff_size;
2115
2116
        /* frame process/entropy coding buffer pointer array */
2117
6.81k
        pps_frm_proc_ent_cod_bufs[i] = (frm_proc_ent_cod_ctxt_t **)ps_memtab->pv_base;
2118
        /* increment the memtabs */
2119
6.81k
        ps_memtab++;
2120
2121
        /* frame process/entropy coding buffer structure */
2122
6.81k
        ps_frmp_ent_bufs = (frm_proc_ent_cod_ctxt_t *)ps_memtab->pv_base;
2123
        /* increment the memtabs */
2124
6.81k
        ps_memtab++;
2125
2126
        /* CTB enc loop Frame level  */
2127
6.81k
        ps_ctb = (ctb_enc_loop_out_t *)ps_memtab->pv_base;
2128
        /* increment the memtabs */
2129
6.81k
        ps_memtab++;
2130
2131
        /* CU enc loop Frame level  */
2132
6.81k
        ps_cu = (cu_enc_loop_out_t *)ps_memtab->pv_base;
2133
        /* increment the memtabs */
2134
6.81k
        ps_memtab++;
2135
2136
        /* TU enc loop Frame level  */
2137
6.81k
        ps_tu = (tu_enc_loop_out_t *)ps_memtab->pv_base;
2138
        /* increment the memtabs */
2139
6.81k
        ps_memtab++;
2140
2141
        /* PU enc loop Frame level  */
2142
6.81k
        ps_pu = (pu_t *)ps_memtab->pv_base;
2143
        /* increment the memtabs */
2144
6.81k
        ps_memtab++;
2145
2146
        /* Coeffs Frame level  */
2147
6.81k
        pu1_coeffs = (UWORD8 *)ps_memtab->pv_base;
2148
        /* increment the memtabs */
2149
6.81k
        ps_memtab++;
2150
2151
6.81k
#ifndef DISABLE_SEI
2152
        /* CC User Data  */
2153
6.81k
        UWORD8 *pu1_sei_payload;
2154
6.81k
        pu1_sei_payload = (UWORD8 *)ps_memtab->pv_base;
2155
6.81k
        ps_memtab++;
2156
6.81k
#endif
2157
2158
6.81k
        num_ctb_in_frm = num_ctb_horz * num_ctb_vert;
2159
2160
        /* calculate the coeff size */
2161
6.81k
        coeff_size =
2162
6.81k
            num_ctb_horz * ((ps_enc_ctxt->ps_stat_prms->s_src_prms.i4_chr_format == IV_YUV_422SP_UV)
2163
6.81k
                                ? (num_tu_in_ctb << 1)
2164
6.81k
                                : ((num_tu_in_ctb * 3) >> 1));
2165
6.81k
        coeff_size = coeff_size * num_ctb_vert * MAX_SCAN_COEFFS_BYTES_4x4;
2166
        /* loop to initialise all the memories */
2167
13.6k
        for(ctr = 0; ctr < NUM_FRMPROC_ENTCOD_BUFS; ctr++)
2168
6.81k
        {
2169
6.81k
            pps_frm_proc_ent_cod_bufs[i][ctr] = ps_frmp_ent_bufs;
2170
2171
6.81k
            ps_frmp_ent_bufs->ps_frm_ctb_data = ps_ctb;
2172
6.81k
            ps_frmp_ent_bufs->ps_frm_cu_data = ps_cu;
2173
6.81k
            ps_frmp_ent_bufs->ps_frm_pu_data = ps_pu;
2174
6.81k
            ps_frmp_ent_bufs->ps_frm_tu_data = ps_tu;
2175
6.81k
            ps_frmp_ent_bufs->pv_coeff_data = pu1_coeffs;
2176
2177
            /* memset the slice headers and buffer to keep track */
2178
6.81k
            memset(&ps_frmp_ent_bufs->s_slice_hdr, 0, sizeof(slice_header_t));
2179
2180
            /*PIC_INFO*/
2181
6.81k
            memset(&ps_frmp_ent_bufs->s_pic_level_info, 0, sizeof(s_pic_level_acc_info_t));
2182
2183
6.81k
            ps_ctb += num_ctb_in_frm;
2184
6.81k
            ps_cu += num_ctb_in_frm * num_cu_in_ctb;
2185
6.81k
            ps_pu += num_ctb_in_frm * num_pu_in_ctb;
2186
6.81k
            ps_tu += num_ctb_in_frm * num_tu_in_ctb;
2187
2188
6.81k
            pu1_coeffs += coeff_size;
2189
2190
6.81k
#ifndef DISABLE_SEI
2191
74.9k
            for(WORD32 num_sei = 0; num_sei < MAX_NUMBER_OF_SEI_PAYLOAD; num_sei++)
2192
68.1k
            {
2193
68.1k
                ps_frmp_ent_bufs->as_sei_payload[num_sei].pu1_sei_payload = pu1_sei_payload;
2194
68.1k
                ps_frmp_ent_bufs->as_sei_payload[num_sei].u4_payload_type = 0;
2195
68.1k
                ps_frmp_ent_bufs->as_sei_payload[num_sei].u4_payload_length = 0;
2196
68.1k
                pu1_sei_payload += MAX_SEI_PAYLOAD_PER_TLV;
2197
68.1k
            }
2198
2199
6.81k
#endif
2200
6.81k
            ps_frmp_ent_bufs++;
2201
6.81k
        }
2202
6.81k
    }
2203
2204
    /* Working memory for encoder */
2205
6.81k
    ps_enc_ctxt->pu1_frm_lvl_wkg_mem = (UWORD8 *)ps_memtab->pv_base;
2206
6.81k
    ps_memtab++;
2207
2208
    /* Job Que memory */
2209
    /* Job que memory distribution is as follows                                                 _______
2210
    enc_group_ping -> MAX_NUM_VERT_UNITS_FRM for all the passes (NUM_ENC_JOBS_QUES)------------>|_______|
2211
    enc_group_pong -> MAX_NUM_VERT_UNITS_FRM for all the passes (NUM_ENC_JOBS_QUES)------------>|_______|
2212
    pre_enc_group_ping -> MAX_NUM_VERT_UNITS_FRM for all the passes (NUM_PRE_ENC_JOBS_QUES)---->|_______|
2213
    pre_enc_group_ping -> MAX_NUM_VERT_UNITS_FRM for all the passes (NUM_PRE_ENC_JOBS_QUES)---->|_______|
2214
    */
2215
2216
6.81k
    ps_enc_ctxt->s_multi_thrd.aps_job_q_pre_enc[0] = (job_queue_t *)ps_memtab->pv_base;
2217
13.6k
    for(ctr = 1; ctr < max_delay_preenc_l0_que; ctr++)
2218
6.81k
    {
2219
6.81k
        ps_enc_ctxt->s_multi_thrd.aps_job_q_pre_enc[ctr] =
2220
6.81k
            ps_enc_ctxt->s_multi_thrd.aps_job_q_pre_enc[0] +
2221
6.81k
            (MAX_NUM_VERT_UNITS_FRM * NUM_PRE_ENC_JOBS_QUES * ctr);
2222
6.81k
    }
2223
6.81k
    ps_memtab++;
2224
2225
    /* -----Frameproc Entcod Que mem_init --- */
2226
    /* init ptrs for each bit-rate */
2227
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
2228
6.81k
    {
2229
6.81k
        ps_enc_ctxt->s_enc_ques.apv_q_hdl[IHEVCE_FRM_PRS_ENT_COD_Q + i] = ihevce_buff_que_init(
2230
6.81k
            ps_memtab, NUM_FRMPROC_ENTCOD_BUFS, (void **)pps_frm_proc_ent_cod_bufs[i]);
2231
6.81k
        ps_memtab += ihevce_buff_que_get_num_mem_recs();
2232
6.81k
    }
2233
    /*mrs*/
2234
    /* ----Encoder owned input buffer queue init----*/
2235
6.81k
    ps_enc_ctxt->s_enc_ques.apv_q_hdl[IHEVCE_ENC_INPUT_Q] =
2236
6.81k
        ihevce_buff_que_init(ps_memtab, num_input_buf_per_queue, (void **)pps_lap_enc_input_bufs);
2237
6.81k
    ps_memtab += ihevce_buff_que_get_num_mem_recs();
2238
2239
    /* -----Pre-Encode / Encode Que mem_init --- */
2240
6.81k
    ps_enc_ctxt->s_enc_ques.apv_q_hdl[IHEVCE_PRE_ENC_ME_Q] =
2241
6.81k
        ihevce_buff_que_init(ps_memtab, num_bufs_preenc_me_que, (void **)pps_pre_enc_bufs);
2242
2243
6.81k
    ps_memtab += ihevce_buff_que_get_num_mem_recs();
2244
2245
    /* -----ME / Enc-RD opt Que mem_init --- */
2246
6.81k
    ps_enc_ctxt->s_enc_ques.apv_q_hdl[IHEVCE_ME_ENC_RDOPT_Q] =
2247
6.81k
        ihevce_buff_que_init(ps_memtab, NUM_ME_ENC_BUFS, (void **)pps_me_enc_bufs);
2248
2249
6.81k
    ps_memtab += ihevce_buff_que_get_num_mem_recs();
2250
2251
    /* -----Pre-Encode L0 IPE to enc queue --- */
2252
6.81k
    ps_enc_ctxt->s_enc_ques.apv_q_hdl[IHEVCE_L0_IPE_ENC_Q] =
2253
6.81k
        ihevce_buff_que_init(ps_memtab, num_bufs_L0_ipe_enc, (void **)pps_L0_ipe_enc_bufs);
2254
2255
6.81k
    ps_memtab += ihevce_buff_que_get_num_mem_recs();
2256
2257
    /* ---------- Dependency Manager allocations -------- */
2258
6.81k
    {
2259
6.81k
        osal_sem_attr_t attr = OSAL_DEFAULT_SEM_ATTR;
2260
6.81k
        WORD32 i1_is_sem_enabled;
2261
2262
6.81k
        if(ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id]
2263
6.81k
               .i4_quality_preset >= IHEVCE_QUALITY_P4)
2264
1.88k
        {
2265
1.88k
            i1_is_sem_enabled = 0;
2266
1.88k
        }
2267
4.92k
        else
2268
4.92k
        {
2269
4.92k
            i1_is_sem_enabled = 1;
2270
4.92k
        }
2271
2272
        /* allocate semaphores for all the threads in pre-enc and enc */
2273
13.6k
        for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds; ctr++)
2274
6.81k
        {
2275
6.81k
            ps_enc_ctxt->s_multi_thrd.apv_enc_thrd_sem_handle[ctr] =
2276
6.81k
                osal_sem_create(ps_intrf_ctxt->pv_osal_handle, &attr);
2277
6.81k
            if(NULL == ps_enc_ctxt->s_multi_thrd.apv_enc_thrd_sem_handle[ctr])
2278
0
            {
2279
0
                ps_intrf_ctxt->i4_error_code = IHEVCE_CANNOT_ALLOCATE_MEMORY;
2280
0
                return;
2281
0
            }
2282
6.81k
        }
2283
2284
13.6k
        for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds; ctr++)
2285
6.81k
        {
2286
6.81k
            ps_enc_ctxt->s_multi_thrd.apv_pre_enc_thrd_sem_handle[ctr] =
2287
6.81k
                osal_sem_create(ps_intrf_ctxt->pv_osal_handle, &attr);
2288
6.81k
            if(NULL == ps_enc_ctxt->s_multi_thrd.apv_pre_enc_thrd_sem_handle[ctr])
2289
0
            {
2290
0
                ps_intrf_ctxt->i4_error_code = IHEVCE_CANNOT_ALLOCATE_MEMORY;
2291
0
                return;
2292
0
            }
2293
6.81k
        }
2294
2295
        /* --- ME-EncLoop Dep Mngr Row-Row Init -- */
2296
13.6k
        for(ctr = 0; ctr < NUM_ME_ENC_BUFS; ctr++)
2297
6.81k
        {
2298
6.81k
            me_enc_rdopt_ctxt_t *ps_me_enc_bufs = pps_me_enc_bufs[ctr];
2299
2300
6.81k
            ps_me_enc_bufs->pv_dep_mngr_encloop_dep_me = ihevce_dmgr_init(
2301
6.81k
                ps_memtab,
2302
6.81k
                ps_intrf_ctxt->pv_osal_handle,
2303
6.81k
                DEP_MNGR_ROW_ROW_SYNC,
2304
6.81k
                (a_ctb_align_ht[0] / ctb_size),
2305
6.81k
                (a_ctb_align_wd[0] / ctb_size),
2306
6.81k
                ps_enc_ctxt->ps_tile_params_base->i4_num_tile_cols, /* Number of Col Tiles */
2307
6.81k
                ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
2308
6.81k
                i1_is_sem_enabled /*Sem Disabled/Enabled*/
2309
6.81k
            );
2310
6.81k
            ps_memtab += ihevce_dmgr_get_num_mem_recs();
2311
2312
            /* Register Enc group semaphore handles */
2313
6.81k
            ihevce_dmgr_reg_sem_hdls(
2314
6.81k
                ps_me_enc_bufs->pv_dep_mngr_encloop_dep_me,
2315
6.81k
                ps_enc_ctxt->s_multi_thrd.apv_enc_thrd_sem_handle,
2316
6.81k
                ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds);
2317
2318
            /* Register the handle in multithread ctxt also for free purpose */
2319
6.81k
            ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_encloop_dep_me[ctr] =
2320
6.81k
                ps_me_enc_bufs->pv_dep_mngr_encloop_dep_me;
2321
6.81k
        }
2322
2323
13.6k
        for(ctr = 0; ctr < i4_num_enc_loop_frm_pllel; ctr++)
2324
6.81k
        {
2325
            /* --- Prev. frame EncLoop Done Dep Mngr Frm-Frm Mem Init -- */
2326
6.81k
            ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_prev_frame_done[ctr] = ihevce_dmgr_init(
2327
6.81k
                ps_memtab,
2328
6.81k
                ps_intrf_ctxt->pv_osal_handle,
2329
6.81k
                DEP_MNGR_FRM_FRM_SYNC,
2330
6.81k
                (a_ctb_align_ht[0] / ctb_size),
2331
6.81k
                (a_ctb_align_wd[0] / ctb_size),
2332
6.81k
                1, /* Number of Col Tiles : Don't care for FRM_FRM */
2333
6.81k
                ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
2334
6.81k
                1 /*Sem Enabled*/
2335
6.81k
            );
2336
6.81k
            ps_memtab += ihevce_dmgr_get_num_mem_recs();
2337
2338
            /* Register Enc group semaphore handles */
2339
6.81k
            ihevce_dmgr_reg_sem_hdls(
2340
6.81k
                ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_prev_frame_done[ctr],
2341
6.81k
                ps_enc_ctxt->s_multi_thrd.apv_enc_thrd_sem_handle,
2342
6.81k
                ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds);
2343
6.81k
        }
2344
        /* --- Prev. frame EncLoop Done Dep Mngr  for re-encode  Frm-Frm Mem Init -- */
2345
6.81k
        ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_enc_done_for_reenc = ihevce_dmgr_init(
2346
6.81k
            ps_memtab,
2347
6.81k
            ps_intrf_ctxt->pv_osal_handle,
2348
6.81k
            DEP_MNGR_FRM_FRM_SYNC,
2349
6.81k
            (a_ctb_align_ht[0] / ctb_size),
2350
6.81k
            (a_ctb_align_wd[0] / ctb_size),
2351
6.81k
            1, /* Number of Col Tiles : Don't care for FRM_FRM */
2352
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
2353
6.81k
            1 /*Sem Enabled*/
2354
6.81k
        );
2355
6.81k
        ps_memtab += ihevce_dmgr_get_num_mem_recs();
2356
2357
        /* Register Enc group semaphore handles */
2358
6.81k
        ihevce_dmgr_reg_sem_hdls(
2359
6.81k
            ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_enc_done_for_reenc,
2360
6.81k
            ps_enc_ctxt->s_multi_thrd.apv_enc_thrd_sem_handle,
2361
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds);
2362
13.6k
        for(ctr = 0; ctr < i4_num_me_frm_pllel; ctr++)
2363
6.81k
        {
2364
            /* --- Prev. frame ME Done Dep Mngr Frm-Frm Mem Init -- */
2365
6.81k
            ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_prev_frame_me_done[ctr] = ihevce_dmgr_init(
2366
6.81k
                ps_memtab,
2367
6.81k
                ps_intrf_ctxt->pv_osal_handle,
2368
6.81k
                DEP_MNGR_FRM_FRM_SYNC,
2369
6.81k
                (a_ctb_align_ht[0] / ctb_size),
2370
6.81k
                (a_ctb_align_wd[0] / ctb_size),
2371
6.81k
                1, /* Number of Col Tiles : Don't care for FRM_FRM */
2372
6.81k
                ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
2373
6.81k
                1 /*Sem Enabled*/
2374
6.81k
            );
2375
6.81k
            ps_memtab += ihevce_dmgr_get_num_mem_recs();
2376
2377
            /* Register Enc group semaphore handles */
2378
6.81k
            ihevce_dmgr_reg_sem_hdls(
2379
6.81k
                ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_prev_frame_me_done[ctr],
2380
6.81k
                ps_enc_ctxt->s_multi_thrd.apv_enc_thrd_sem_handle,
2381
6.81k
                ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds);
2382
6.81k
        }
2383
        /* --- Prev. frame PreEnc L1 Done Dep Mngr Frm-Frm Mem Init -- */
2384
6.81k
        ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_l1 = ihevce_dmgr_init(
2385
6.81k
            ps_memtab,
2386
6.81k
            ps_intrf_ctxt->pv_osal_handle,
2387
6.81k
            DEP_MNGR_FRM_FRM_SYNC,
2388
6.81k
            (a_ctb_align_ht[0] / ctb_size),
2389
6.81k
            (a_ctb_align_wd[0] / ctb_size),
2390
6.81k
            1, /* Number of Col Tiles : Don't care for FRM_FRM */
2391
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds,
2392
6.81k
            1 /*Sem Enabled*/
2393
6.81k
        );
2394
6.81k
        ps_memtab += ihevce_dmgr_get_num_mem_recs();
2395
2396
        /* Register Pre-Enc group semaphore handles */
2397
6.81k
        ihevce_dmgr_reg_sem_hdls(
2398
6.81k
            ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_l1,
2399
6.81k
            ps_enc_ctxt->s_multi_thrd.apv_pre_enc_thrd_sem_handle,
2400
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds);
2401
2402
        /* --- Prev. frame PreEnc HME Done Dep Mngr Frm-Frm Mem Init -- */
2403
6.81k
        ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_coarse_me = ihevce_dmgr_init(
2404
6.81k
            ps_memtab,
2405
6.81k
            ps_intrf_ctxt->pv_osal_handle,
2406
6.81k
            DEP_MNGR_FRM_FRM_SYNC,
2407
6.81k
            (a_ctb_align_ht[0] / ctb_size),
2408
6.81k
            (a_ctb_align_wd[0] / ctb_size),
2409
6.81k
            1, /* Number of Col Tiles : Don't care for FRM_FRM */
2410
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds,
2411
6.81k
            1 /*Sem Enabled*/
2412
6.81k
        );
2413
6.81k
        ps_memtab += ihevce_dmgr_get_num_mem_recs();
2414
2415
        /* Register Pre-Enc group semaphore handles */
2416
6.81k
        ihevce_dmgr_reg_sem_hdls(
2417
6.81k
            ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_coarse_me,
2418
6.81k
            ps_enc_ctxt->s_multi_thrd.apv_pre_enc_thrd_sem_handle,
2419
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds);
2420
2421
        /* --- Prev. frame PreEnc L0 Done Dep Mngr Frm-Frm Mem Init -- */
2422
6.81k
        ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_l0 = ihevce_dmgr_init(
2423
6.81k
            ps_memtab,
2424
6.81k
            ps_intrf_ctxt->pv_osal_handle,
2425
6.81k
            DEP_MNGR_FRM_FRM_SYNC,
2426
6.81k
            (a_ctb_align_ht[0] / ctb_size),
2427
6.81k
            (a_ctb_align_wd[0] / ctb_size),
2428
6.81k
            1, /* Number of Col Tiles : Don't care for FRM_FRM */
2429
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds,
2430
6.81k
            1 /*Sem Enabled*/
2431
6.81k
        );
2432
6.81k
        ps_memtab += ihevce_dmgr_get_num_mem_recs();
2433
2434
        /* Register Pre-Enc group semaphore handles */
2435
6.81k
        ihevce_dmgr_reg_sem_hdls(
2436
6.81k
            ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_l0,
2437
6.81k
            ps_enc_ctxt->s_multi_thrd.apv_pre_enc_thrd_sem_handle,
2438
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds);
2439
2440
        /* --- ME-Prev Recon Dep Mngr Row-Frm Mem init -- */
2441
40.8k
        for(ctr = 0; ctr < (max_num_ref_pics + 1 + NUM_EXTRA_RECON_BUFS); ctr++)
2442
34.0k
        {
2443
34.0k
            WORD32 ai4_tile_xtra_ctb[4] = { 0 };
2444
2445
34.0k
            ps_enc_ctxt->pps_recon_buf_q[0][ctr]->pv_dep_mngr_recon = ihevce_dmgr_map_init(
2446
34.0k
                ps_memtab,
2447
34.0k
                num_ctb_vert,
2448
34.0k
                num_ctb_horz,
2449
34.0k
                i1_is_sem_enabled, /*Sem Disabled/Enabled*/
2450
34.0k
                ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds,
2451
34.0k
                ai4_tile_xtra_ctb);
2452
2453
34.0k
            ps_memtab += ihevce_dmgr_get_num_mem_recs();
2454
2455
            /* Register Enc group semaphore handles */
2456
34.0k
            ihevce_dmgr_reg_sem_hdls(
2457
34.0k
                ps_enc_ctxt->pps_recon_buf_q[0][ctr]->pv_dep_mngr_recon,
2458
34.0k
                ps_enc_ctxt->s_multi_thrd.apv_enc_thrd_sem_handle,
2459
34.0k
                ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds);
2460
34.0k
        }
2461
2462
        /* ------ Module level register semaphores -------- */
2463
6.81k
        ihevce_coarse_me_reg_thrds_sem(
2464
6.81k
            ps_enc_ctxt->s_module_ctxt.pv_coarse_me_ctxt,
2465
6.81k
            ps_enc_ctxt->s_multi_thrd.apv_pre_enc_thrd_sem_handle,
2466
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds);
2467
2468
6.81k
        ihevce_enc_loop_reg_sem_hdls(
2469
6.81k
            ps_enc_ctxt->s_module_ctxt.pv_enc_loop_ctxt,
2470
6.81k
            ps_enc_ctxt->s_multi_thrd.apv_enc_thrd_sem_handle,
2471
6.81k
            ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds);
2472
6.81k
    }
2473
2474
    /* copy the run time source parameters from create time prms */
2475
0
    memcpy(
2476
6.81k
        &ps_enc_ctxt->s_runtime_src_prms,
2477
6.81k
        &ps_enc_ctxt->ps_stat_prms->s_src_prms,
2478
6.81k
        sizeof(ihevce_src_params_t));
2479
2480
6.81k
    memcpy(
2481
6.81k
        &ps_enc_ctxt->s_runtime_tgt_params,
2482
6.81k
        &ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[i4_resolution_id],
2483
6.81k
        sizeof(ihevce_tgt_params_t));
2484
2485
    /* copy the run time coding parameters from create time prms */
2486
6.81k
    memcpy(
2487
6.81k
        &ps_enc_ctxt->s_runtime_coding_prms,
2488
6.81k
        &ps_enc_ctxt->ps_stat_prms->s_coding_tools_prms,
2489
6.81k
        sizeof(ihevce_coding_params_t));
2490
2491
    /*change in run time parameter*/
2492
6.81k
    if(ps_enc_ctxt->ps_stat_prms->s_coding_tools_prms.i4_max_reference_frames == -1)
2493
6.81k
    {
2494
6.81k
        ps_enc_ctxt->s_runtime_coding_prms.i4_max_reference_frames = (DEFAULT_MAX_REFERENCE_PICS)
2495
6.81k
                                                                     << i4_field_pic;
2496
2497
6.81k
        ps_enc_ctxt->s_lap_stat_prms.i4_max_reference_frames =
2498
6.81k
            ps_enc_ctxt->s_runtime_coding_prms.i4_max_reference_frames;
2499
6.81k
    }
2500
2501
    /* populate the frame level ctb parameters based on run time params */
2502
6.81k
    ihevce_set_pre_enc_prms(ps_enc_ctxt);
2503
2504
6.81k
    return;
2505
6.81k
}
2506
2507
/*!
2508
******************************************************************************
2509
* \if Function name : ihevce_mem_manager_que_init \endif
2510
*
2511
* \brief
2512
*    Encoder Que memory init function
2513
*
2514
* \param[in] Encoder context pointer
2515
* \param[in] High level Encoder context pointer
2516
* \param[in] Buffer descriptors
2517
*
2518
* \return
2519
*    None
2520
*
2521
* \author
2522
*  Ittiam
2523
*
2524
*****************************************************************************
2525
*/
2526
void ihevce_mem_manager_que_init(
2527
    enc_ctxt_t *ps_enc_ctxt,
2528
    ihevce_hle_ctxt_t *ps_hle_ctxt,
2529
    iv_input_data_ctrl_buffs_desc_t *ps_input_data_ctrl_buffs_desc,
2530
    iv_input_asynch_ctrl_buffs_desc_t *ps_input_asynch_ctrl_buffs_desc,
2531
    iv_output_data_buffs_desc_t *ps_output_data_buffs_desc,
2532
    iv_recon_data_buffs_desc_t *ps_recon_data_buffs_desc)
2533
6.81k
{
2534
    /* local variables */
2535
6.81k
    WORD32 total_memtabs_req = 0;
2536
6.81k
    WORD32 total_memtabs_used = 0;
2537
6.81k
    WORD32 ctr;
2538
6.81k
    iv_mem_rec_t *ps_memtab;
2539
6.81k
    WORD32 i;  //counter variable
2540
6.81k
    iv_output_data_buffs_desc_t *ps_out_desc;
2541
6.81k
    iv_recon_data_buffs_desc_t *ps_rec_desc;
2542
6.81k
    WORD32 i4_num_bitrate_inst;  //number of bit-rate instance
2543
    /* storing 0th instance's pointer. This will be used for assigning buffer queue handles for input/output queues */
2544
6.81k
    enc_ctxt_t *ps_enc_ctxt_base = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[0];
2545
2546
6.81k
    i4_num_bitrate_inst = ps_enc_ctxt->i4_num_bitrates;
2547
    //ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[0].i4_num_bitrate_instances;
2548
2549
    /* --------------------------------------------------------------------- */
2550
    /* --------------  Collating the number of memtabs required ------------ */
2551
    /* --------------------------------------------------------------------- */
2552
2553
    /* ------ Input Data Que Memtab -------- */
2554
6.81k
    if(0 == ps_enc_ctxt->i4_resolution_id)
2555
6.81k
    {
2556
        /* array of pointers for input */
2557
6.81k
        total_memtabs_req++;
2558
2559
        /* pointers for input desc */
2560
6.81k
        total_memtabs_req++;
2561
2562
        /* que manager buffer requirements */
2563
6.81k
        total_memtabs_req += ihevce_buff_que_get_num_mem_recs();
2564
2565
        /* ------ Input Control Que memtab ----- */
2566
        /* array of pointers for input control */
2567
6.81k
        total_memtabs_req++;
2568
2569
        /* pointers for input control desc */
2570
6.81k
        total_memtabs_req++;
2571
2572
        /* que manager buffer requirements */
2573
6.81k
        total_memtabs_req += ihevce_buff_que_get_num_mem_recs();
2574
6.81k
    }
2575
2576
    /* ------ Output Data Que Memtab -------- */
2577
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
2578
6.81k
    {
2579
        /* array of pointers for output */
2580
6.81k
        total_memtabs_req++;
2581
2582
        /* pointers for output desc */
2583
6.81k
        total_memtabs_req++;
2584
2585
        /* que manager buffer requirements */
2586
6.81k
        total_memtabs_req += ihevce_buff_que_get_num_mem_recs();
2587
6.81k
    }
2588
2589
    /* ------ Recon Data Que Memtab -------- */
2590
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
2591
6.81k
    {
2592
6.81k
        if(ps_hle_ctxt->ps_static_cfg_prms->i4_save_recon)
2593
0
        {
2594
            /* array of pointers for input */
2595
0
            total_memtabs_req++;
2596
2597
            /* pointers for input desc */
2598
0
            total_memtabs_req++;
2599
2600
            /* que manager buffer requirements */
2601
0
            total_memtabs_req += ihevce_buff_que_get_num_mem_recs();
2602
0
        }
2603
6.81k
    }
2604
2605
    /* ----- allocate memomry for memtabs --- */
2606
6.81k
    {
2607
6.81k
        iv_mem_rec_t s_memtab;
2608
2609
6.81k
        s_memtab.i4_size = sizeof(iv_mem_rec_t);
2610
6.81k
        s_memtab.i4_mem_size = total_memtabs_req * sizeof(iv_mem_rec_t);
2611
6.81k
        s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
2612
6.81k
        s_memtab.i4_mem_alignment = 4;
2613
2614
6.81k
        ps_hle_ctxt->ihevce_mem_alloc(
2615
6.81k
            ps_hle_ctxt->pv_mem_mgr_hdl, &ps_hle_ctxt->ps_static_cfg_prms->s_sys_api, &s_memtab);
2616
6.81k
        if(s_memtab.pv_base == NULL)
2617
0
        {
2618
0
            ps_hle_ctxt->i4_error_code = IHEVCE_CANNOT_ALLOCATE_MEMORY;
2619
0
            return;
2620
0
        }
2621
6.81k
        ps_memtab = (iv_mem_rec_t *)s_memtab.pv_base;
2622
6.81k
    }
2623
2624
    /* --------------------------------------------------------------------- */
2625
    /* ------------------  Collating memory requirements ------------------- */
2626
    /* --------------------------------------------------------------------- */
2627
6.81k
    if(0 == ps_enc_ctxt->i4_resolution_id)
2628
6.81k
    {
2629
        /* ------ Input Data Que memory requests -------- */
2630
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
2631
2632
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
2633
2634
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
2635
6.81k
            ((ps_input_data_ctrl_buffs_desc->i4_num_yuv_bufs) * (sizeof(ihevce_lap_enc_buf_t *)));
2636
2637
        /* increment the memtab counter */
2638
6.81k
        total_memtabs_used++;
2639
2640
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
2641
2642
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
2643
2644
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
2645
6.81k
            ((ps_input_data_ctrl_buffs_desc->i4_num_yuv_bufs) * (sizeof(ihevce_lap_enc_buf_t)));
2646
2647
        /* increment the memtab counter */
2648
6.81k
        total_memtabs_used++;
2649
2650
        /* call the Que manager get mem recs */
2651
6.81k
        total_memtabs_used += ihevce_buff_que_get_mem_recs(
2652
6.81k
            &ps_memtab[total_memtabs_used],
2653
6.81k
            ps_input_data_ctrl_buffs_desc->i4_num_yuv_bufs,
2654
6.81k
            IV_EXT_CACHEABLE_NORMAL_MEM);
2655
2656
        /* ------ Input Control Que memory requests -------- */
2657
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
2658
2659
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
2660
2661
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
2662
6.81k
            ((ps_input_asynch_ctrl_buffs_desc->i4_num_asynch_ctrl_bufs) *
2663
6.81k
             (sizeof(iv_input_ctrl_buffs_t *)));
2664
2665
        /* increment the memtab counter */
2666
6.81k
        total_memtabs_used++;
2667
2668
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
2669
2670
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
2671
2672
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
2673
6.81k
            ((ps_input_asynch_ctrl_buffs_desc->i4_num_asynch_ctrl_bufs) *
2674
6.81k
             (sizeof(iv_input_ctrl_buffs_t)));
2675
2676
        /* increment the memtab counter */
2677
6.81k
        total_memtabs_used++;
2678
2679
        /* call the Que manager get mem recs */
2680
6.81k
        total_memtabs_used += ihevce_buff_que_get_mem_recs(
2681
6.81k
            &ps_memtab[total_memtabs_used],
2682
6.81k
            ps_input_asynch_ctrl_buffs_desc->i4_num_asynch_ctrl_bufs,
2683
6.81k
            IV_EXT_CACHEABLE_NORMAL_MEM);
2684
6.81k
    }
2685
2686
    /* ------ Output data Que memory requests -------- */
2687
6.81k
    ps_out_desc = ps_output_data_buffs_desc;
2688
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
2689
6.81k
    {
2690
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
2691
2692
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
2693
2694
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
2695
6.81k
            ((ps_out_desc->i4_num_bitstream_bufs) * (sizeof(iv_output_data_buffs_t *)));
2696
2697
        /* increment the memtab counter */
2698
6.81k
        total_memtabs_used++;
2699
2700
6.81k
        ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
2701
2702
6.81k
        ps_memtab[total_memtabs_used].e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
2703
2704
6.81k
        ps_memtab[total_memtabs_used].i4_mem_size =
2705
6.81k
            ((ps_out_desc->i4_num_bitstream_bufs) * (sizeof(iv_output_data_buffs_t)));
2706
2707
        /* increment the memtab counter */
2708
6.81k
        total_memtabs_used++;
2709
2710
        /* call the Que manager get mem recs */
2711
6.81k
        total_memtabs_used += ihevce_buff_que_get_mem_recs(
2712
6.81k
            &ps_memtab[total_memtabs_used],
2713
6.81k
            ps_out_desc->i4_num_bitstream_bufs,
2714
6.81k
            IV_EXT_CACHEABLE_NORMAL_MEM);
2715
6.81k
        ps_out_desc++;
2716
6.81k
    }
2717
2718
    //recon_dump
2719
    /* ------ Recon Data Que memory requests -------- */
2720
6.81k
    ps_rec_desc = ps_recon_data_buffs_desc;
2721
6.81k
    if(ps_hle_ctxt->ps_static_cfg_prms->i4_save_recon)
2722
0
    {
2723
0
        for(i = 0; i < i4_num_bitrate_inst; i++)
2724
0
        {
2725
0
            ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
2726
2727
0
            ps_memtab[total_memtabs_used].e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
2728
2729
0
            ps_memtab[total_memtabs_used].i4_mem_size =
2730
0
                ((ps_rec_desc->i4_num_recon_bufs) * (sizeof(iv_enc_recon_data_buffs_t *)));
2731
2732
            /* increment the memtab counter */
2733
0
            total_memtabs_used++;
2734
2735
0
            ps_memtab[total_memtabs_used].i4_mem_alignment = 8;
2736
2737
0
            ps_memtab[total_memtabs_used].e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
2738
2739
0
            ps_memtab[total_memtabs_used].i4_mem_size =
2740
0
                ((ps_rec_desc->i4_num_recon_bufs) * (sizeof(iv_enc_recon_data_buffs_t)));
2741
2742
            /* increment the memtab counter */
2743
0
            total_memtabs_used++;
2744
2745
            /* call the Que manager get mem recs */
2746
0
            total_memtabs_used += ihevce_buff_que_get_mem_recs(
2747
0
                &ps_memtab[total_memtabs_used],
2748
0
                ps_rec_desc->i4_num_recon_bufs,
2749
0
                IV_EXT_CACHEABLE_NORMAL_MEM);
2750
2751
0
            ps_rec_desc++;
2752
0
        }
2753
0
    }
2754
2755
    /* ----- allocate memory as per requests ---- */
2756
2757
    /* check on memtabs requested v/s memtabs used */
2758
    //ittiam : should put an assert
2759
6.81k
    ASSERT(total_memtabs_req == total_memtabs_used);
2760
149k
    for(ctr = 0; ctr < total_memtabs_used; ctr++)
2761
143k
    {
2762
143k
        UWORD8 *pu1_mem = NULL;
2763
143k
        ps_hle_ctxt->ihevce_mem_alloc(
2764
143k
            ps_hle_ctxt->pv_mem_mgr_hdl,
2765
143k
            &ps_hle_ctxt->ps_static_cfg_prms->s_sys_api,
2766
143k
            &ps_memtab[ctr]);
2767
2768
143k
        pu1_mem = (UWORD8 *)ps_memtab[ctr].pv_base;
2769
2770
143k
        if(NULL == pu1_mem)
2771
0
        {
2772
0
            ps_hle_ctxt->i4_error_code = IHEVCE_CANNOT_ALLOCATE_MEMORY;
2773
0
            return;
2774
0
        }
2775
143k
    }
2776
2777
    /* store the final allocated memtabs */
2778
6.81k
    ps_enc_ctxt->s_mem_mngr.i4_num_q_memtabs = total_memtabs_used;
2779
6.81k
    ps_enc_ctxt->s_mem_mngr.ps_q_memtab = ps_memtab;
2780
2781
    /* --------------------------------------------------------------------- */
2782
    /* -------------- Initialisation of Queues memory ---------------------- */
2783
    /* --------------------------------------------------------------------- */
2784
2785
    /* ---------- Input Data Que Mem init --------------- */
2786
6.81k
    if(0 == ps_enc_ctxt->i4_resolution_id)
2787
6.81k
    {
2788
6.81k
        ihevce_lap_enc_buf_t **pps_inp_bufs;
2789
6.81k
        ihevce_lap_enc_buf_t *ps_inp_bufs;
2790
2791
6.81k
        pps_inp_bufs = (ihevce_lap_enc_buf_t **)ps_memtab->pv_base;
2792
6.81k
        ps_memtab++;
2793
2794
6.81k
        ps_inp_bufs = (ihevce_lap_enc_buf_t *)ps_memtab->pv_base;
2795
6.81k
        ps_memtab++;
2796
2797
        /* loop to initialise the buffer pointer */
2798
25.7k
        for(ctr = 0; ctr < ps_input_data_ctrl_buffs_desc->i4_num_yuv_bufs; ctr++)
2799
18.9k
        {
2800
18.9k
            pps_inp_bufs[ctr] = &ps_inp_bufs[ctr];
2801
2802
18.9k
            pps_inp_bufs[ctr]->s_input_buf.i4_size = sizeof(iv_input_data_ctrl_buffs_t);
2803
2804
18.9k
            pps_inp_bufs[ctr]->s_input_buf.s_input_buf.i4_size = sizeof(iv_yuv_buf_t);
2805
2806
            /*pointer to i/p buf initialised to null in case of run time allocation*/
2807
18.9k
            if(ps_hle_ctxt->i4_create_time_input_allocation == 1)
2808
18.9k
            {
2809
18.9k
                pps_inp_bufs[ctr]->s_input_buf.pv_synch_ctrl_bufs =
2810
18.9k
                    ps_input_data_ctrl_buffs_desc->ppv_synch_ctrl_bufs[ctr];
2811
2812
18.9k
                pps_inp_bufs[ctr]->s_input_buf.s_input_buf.pv_y_buf =
2813
18.9k
                    ps_input_data_ctrl_buffs_desc->ppv_y_buf[ctr];
2814
2815
18.9k
                pps_inp_bufs[ctr]->s_input_buf.s_input_buf.pv_u_buf =
2816
18.9k
                    ps_input_data_ctrl_buffs_desc->ppv_u_buf[ctr];
2817
2818
18.9k
                pps_inp_bufs[ctr]->s_input_buf.s_input_buf.pv_v_buf =
2819
18.9k
                    ps_input_data_ctrl_buffs_desc->ppv_v_buf[ctr];
2820
18.9k
            }
2821
0
            else
2822
0
            {
2823
0
                pps_inp_bufs[ctr]->s_input_buf.pv_synch_ctrl_bufs = NULL;
2824
2825
0
                pps_inp_bufs[ctr]->s_input_buf.s_input_buf.pv_y_buf = NULL;
2826
2827
0
                pps_inp_bufs[ctr]->s_input_buf.s_input_buf.pv_u_buf = NULL;
2828
2829
0
                pps_inp_bufs[ctr]->s_input_buf.s_input_buf.pv_v_buf = NULL;
2830
0
            }
2831
18.9k
        }
2832
2833
        /* Get the input data buffer Q handle */
2834
6.81k
        ps_enc_ctxt->s_enc_ques.apv_q_hdl[IHEVCE_INPUT_DATA_CTRL_Q] = ihevce_buff_que_init(
2835
6.81k
            ps_memtab, ps_input_data_ctrl_buffs_desc->i4_num_yuv_bufs, (void **)pps_inp_bufs);
2836
2837
        /* increment the memtab pointer */
2838
6.81k
        ps_memtab += ihevce_buff_que_get_num_mem_recs();
2839
6.81k
    }
2840
0
    else
2841
0
    {
2842
        /* Get the input data buffer Q handle from 0th instance */
2843
0
        ps_enc_ctxt->s_enc_ques.apv_q_hdl[IHEVCE_INPUT_DATA_CTRL_Q] =
2844
0
            ps_enc_ctxt_base->s_enc_ques.apv_q_hdl[IHEVCE_INPUT_DATA_CTRL_Q];
2845
0
    }
2846
2847
    /* ---------- Input control Que Mem init --------------- */
2848
6.81k
    if(0 == ps_enc_ctxt->i4_resolution_id)
2849
6.81k
    {
2850
6.81k
        iv_input_ctrl_buffs_t **pps_inp_bufs;
2851
6.81k
        iv_input_ctrl_buffs_t *ps_inp_bufs;
2852
2853
6.81k
        pps_inp_bufs = (iv_input_ctrl_buffs_t **)ps_memtab->pv_base;
2854
6.81k
        ps_memtab++;
2855
2856
6.81k
        ps_inp_bufs = (iv_input_ctrl_buffs_t *)ps_memtab->pv_base;
2857
6.81k
        ps_memtab++;
2858
2859
        /* loop to initialise the buffer pointer */
2860
34.0k
        for(ctr = 0; ctr < ps_input_asynch_ctrl_buffs_desc->i4_num_asynch_ctrl_bufs; ctr++)
2861
27.2k
        {
2862
27.2k
            pps_inp_bufs[ctr] = &ps_inp_bufs[ctr];
2863
2864
27.2k
            pps_inp_bufs[ctr]->i4_size = sizeof(iv_input_ctrl_buffs_t);
2865
2866
27.2k
            pps_inp_bufs[ctr]->pv_asynch_ctrl_bufs =
2867
27.2k
                ps_input_asynch_ctrl_buffs_desc->ppv_asynch_ctrl_bufs[ctr];
2868
27.2k
        }
2869
2870
        /* Get the input control buffer Q handle */
2871
6.81k
        ps_enc_ctxt->s_enc_ques.apv_q_hdl[IHEVCE_INPUT_ASYNCH_CTRL_Q] = ihevce_buff_que_init(
2872
6.81k
            ps_memtab,
2873
6.81k
            ps_input_asynch_ctrl_buffs_desc->i4_num_asynch_ctrl_bufs,
2874
6.81k
            (void **)pps_inp_bufs);
2875
2876
        /* increment the memtab pointer */
2877
6.81k
        ps_memtab += ihevce_buff_que_get_num_mem_recs();
2878
6.81k
    }
2879
0
    else
2880
0
    {
2881
        /* Get the input control buffer Q handle from 0th instance */
2882
0
        ps_enc_ctxt->s_enc_ques.apv_q_hdl[IHEVCE_INPUT_ASYNCH_CTRL_Q] =
2883
0
            ps_enc_ctxt_base->s_enc_ques.apv_q_hdl[IHEVCE_INPUT_ASYNCH_CTRL_Q];
2884
0
    }
2885
2886
    /* ---------- Output data Que Mem init --------------- */
2887
6.81k
    ps_out_desc = ps_output_data_buffs_desc;
2888
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
2889
6.81k
    {
2890
6.81k
        iv_output_data_buffs_t **pps_out_bufs;
2891
6.81k
        iv_output_data_buffs_t *ps_out_bufs;
2892
2893
6.81k
        pps_out_bufs = (iv_output_data_buffs_t **)ps_memtab->pv_base;
2894
6.81k
        ps_memtab++;
2895
2896
6.81k
        ps_out_bufs = (iv_output_data_buffs_t *)ps_memtab->pv_base;
2897
6.81k
        ps_memtab++;
2898
2899
        /* loop to initialise the buffer pointer */
2900
34.0k
        for(ctr = 0; ctr < ps_out_desc->i4_num_bitstream_bufs; ctr++)
2901
27.2k
        {
2902
27.2k
            pps_out_bufs[ctr] = &ps_out_bufs[ctr];
2903
2904
27.2k
            pps_out_bufs[ctr]->i4_size = sizeof(iv_output_data_buffs_t);
2905
2906
27.2k
            pps_out_bufs[ctr]->i4_bitstream_buf_size = ps_out_desc->i4_size_bitstream_buf;
2907
2908
            /*pointer to o/p buf initialised to null in case of run time allocation*/
2909
27.2k
            if(ps_hle_ctxt->i4_create_time_output_allocation == 1)
2910
0
            {
2911
0
                pps_out_bufs[ctr]->pv_bitstream_bufs = ps_out_desc->ppv_bitstream_bufs[ctr];
2912
0
            }
2913
27.2k
            else
2914
27.2k
            {
2915
27.2k
                pps_out_bufs[ctr]->pv_bitstream_bufs = NULL;
2916
27.2k
            }
2917
27.2k
        }
2918
2919
        /* Get the output data buffer Q handle */
2920
6.81k
        ps_enc_ctxt->s_enc_ques.apv_q_hdl[IHEVCE_OUTPUT_DATA_Q + i] = ihevce_buff_que_init(
2921
6.81k
            ps_memtab, ps_out_desc->i4_num_bitstream_bufs, (void **)pps_out_bufs);
2922
2923
        /* increment the memtab pointer */
2924
6.81k
        ps_memtab += ihevce_buff_que_get_num_mem_recs();
2925
2926
6.81k
        ps_out_desc++;
2927
6.81k
    }
2928
2929
    /* ----------Recon data Que Mem init --------------- */
2930
6.81k
    ps_rec_desc = ps_recon_data_buffs_desc;
2931
13.6k
    for(i = 0; i < i4_num_bitrate_inst; i++)
2932
6.81k
    {
2933
6.81k
        if(ps_hle_ctxt->ps_static_cfg_prms->i4_save_recon)
2934
0
        {
2935
0
            iv_enc_recon_data_buffs_t **pps_recon_bufs;
2936
0
            iv_enc_recon_data_buffs_t *ps_recon_bufs;
2937
2938
0
            pps_recon_bufs = (iv_enc_recon_data_buffs_t **)ps_memtab->pv_base;
2939
0
            ps_memtab++;
2940
2941
0
            ps_recon_bufs = (iv_enc_recon_data_buffs_t *)ps_memtab->pv_base;
2942
0
            ps_memtab++;
2943
2944
            /* loop to initialise the buffer pointer */
2945
0
            for(ctr = 0; ctr < ps_rec_desc->i4_num_recon_bufs; ctr++)
2946
0
            {
2947
0
                pps_recon_bufs[ctr] = &ps_recon_bufs[ctr];
2948
2949
0
                pps_recon_bufs[ctr]->i4_size = sizeof(iv_enc_recon_data_buffs_t);
2950
2951
0
                pps_recon_bufs[ctr]->pv_y_buf = ps_rec_desc->ppv_y_buf[ctr];
2952
2953
0
                pps_recon_bufs[ctr]->pv_cb_buf = ps_rec_desc->ppv_u_buf[ctr];
2954
2955
0
                pps_recon_bufs[ctr]->pv_cr_buf = ps_rec_desc->ppv_v_buf[ctr];
2956
0
            }
2957
2958
            /* Get the output data buffer Q handle */
2959
0
            ps_enc_ctxt->s_enc_ques.apv_q_hdl[IHEVCE_RECON_DATA_Q + i] = ihevce_buff_que_init(
2960
0
                ps_memtab, ps_rec_desc->i4_num_recon_bufs, (void **)pps_recon_bufs);
2961
2962
            /* increment the memtab pointer */
2963
0
            ps_memtab += ihevce_buff_que_get_num_mem_recs();
2964
2965
0
            ps_rec_desc++;
2966
0
        }
2967
6.81k
        else
2968
6.81k
        {
2969
6.81k
            ps_enc_ctxt->s_enc_ques.apv_q_hdl[IHEVCE_RECON_DATA_Q + i] = NULL;
2970
6.81k
        }
2971
6.81k
    }
2972
2973
6.81k
    return;
2974
6.81k
}
2975
2976
/*!
2977
******************************************************************************
2978
* \if Function name : ihevce_mem_manager_free \endif
2979
*
2980
* \brief
2981
*    Encoder memory free function
2982
*
2983
* \param[in] Processing interface context pointer
2984
*
2985
* \return
2986
*    None
2987
*
2988
* \author
2989
*  Ittiam
2990
*
2991
*****************************************************************************
2992
*/
2993
void ihevce_mem_manager_free(enc_ctxt_t *ps_enc_ctxt, ihevce_hle_ctxt_t *ps_intrf_ctxt)
2994
6.81k
{
2995
6.81k
    WORD32 ctr;
2996
2997
    /* run a loop to free all the memory allocated create time */
2998
6.00M
    for(ctr = 0; ctr < ps_enc_ctxt->s_mem_mngr.i4_num_create_memtabs; ctr++)
2999
5.99M
    {
3000
5.99M
        ps_intrf_ctxt->ihevce_mem_free(
3001
5.99M
            ps_intrf_ctxt->pv_mem_mgr_hdl, &ps_enc_ctxt->s_mem_mngr.ps_create_memtab[ctr]);
3002
5.99M
    }
3003
3004
    /* free the memtab memory */
3005
6.81k
    {
3006
6.81k
        iv_mem_rec_t s_memtab;
3007
3008
6.81k
        s_memtab.i4_size = sizeof(iv_mem_rec_t);
3009
6.81k
        s_memtab.i4_mem_size = ps_enc_ctxt->s_mem_mngr.i4_num_create_memtabs * sizeof(iv_mem_rec_t);
3010
6.81k
        s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
3011
6.81k
        s_memtab.i4_mem_alignment = 4;
3012
6.81k
        s_memtab.pv_base = (void *)ps_enc_ctxt->s_mem_mngr.ps_create_memtab;
3013
3014
6.81k
        ps_intrf_ctxt->ihevce_mem_free(ps_intrf_ctxt->pv_mem_mgr_hdl, &s_memtab);
3015
6.81k
    }
3016
3017
6.81k
    if(1 == ps_enc_ctxt->i4_io_queues_created)
3018
6.81k
    {
3019
        /* run a loop to free all the memory allocated durign que creation */
3020
149k
        for(ctr = 0; ctr < ps_enc_ctxt->s_mem_mngr.i4_num_q_memtabs; ctr++)
3021
143k
        {
3022
143k
            ps_intrf_ctxt->ihevce_mem_free(
3023
143k
                ps_intrf_ctxt->pv_mem_mgr_hdl, &ps_enc_ctxt->s_mem_mngr.ps_q_memtab[ctr]);
3024
143k
        }
3025
3026
        /* free the  memtab memory */
3027
6.81k
        {
3028
6.81k
            iv_mem_rec_t s_memtab;
3029
3030
6.81k
            s_memtab.i4_size = sizeof(iv_mem_rec_t);
3031
6.81k
            s_memtab.i4_mem_size = ps_enc_ctxt->s_mem_mngr.i4_num_q_memtabs * sizeof(iv_mem_rec_t);
3032
6.81k
            s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
3033
6.81k
            s_memtab.i4_mem_alignment = 4;
3034
6.81k
            s_memtab.pv_base = (void *)ps_enc_ctxt->s_mem_mngr.ps_q_memtab;
3035
3036
6.81k
            ps_intrf_ctxt->ihevce_mem_free(ps_intrf_ctxt->pv_mem_mgr_hdl, &s_memtab);
3037
6.81k
        }
3038
6.81k
    }
3039
6.81k
    return;
3040
6.81k
}