Coverage Report

Created: 2026-02-26 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libhevc/encoder/ihevce_hle_interface.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_hle_interface.c
24
*
25
* \brief
26
*    This file contains all the functions related High level encoder
27
*    Interface layer
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
#include <time.h>
52
53
/* User include files */
54
#include "ihevc_typedefs.h"
55
#include "itt_video_api.h"
56
#include "ihevce_api.h"
57
58
#include "rc_cntrl_param.h"
59
#include "rc_frame_info_collector.h"
60
#include "rc_look_ahead_params.h"
61
62
#include "ihevc_defs.h"
63
#include "ihevc_macros.h"
64
#include "ihevc_debug.h"
65
#include "ihevc_structs.h"
66
#include "ihevc_platform_macros.h"
67
#include "ihevc_deblk.h"
68
#include "ihevc_itrans_recon.h"
69
#include "ihevc_chroma_itrans_recon.h"
70
#include "ihevc_chroma_intra_pred.h"
71
#include "ihevc_intra_pred.h"
72
#include "ihevc_inter_pred.h"
73
#include "ihevc_mem_fns.h"
74
#include "ihevc_padding.h"
75
#include "ihevc_weighted_pred.h"
76
#include "ihevc_sao.h"
77
#include "ihevc_resi_trans.h"
78
#include "ihevc_quant_iquant_ssd.h"
79
#include "ihevc_cabac_tables.h"
80
#include "ihevc_trans_tables.h"
81
#include "ihevc_trans_macros.h"
82
83
#include "ihevce_defs.h"
84
#include "ihevce_hle_interface.h"
85
#include "ihevce_hle_q_func.h"
86
#include "ihevce_buffer_que_interface.h"
87
#include "ihevce_lap_enc_structs.h"
88
#include "ihevce_multi_thrd_structs.h"
89
#include "ihevce_multi_thrd_funcs.h"
90
#include "ihevce_me_common_defs.h"
91
#include "ihevce_had_satd.h"
92
#include "ihevce_error_codes.h"
93
#include "ihevce_error_checks.h"
94
#include "ihevce_bitstream.h"
95
#include "ihevce_cabac.h"
96
#include "ihevce_rdoq_macros.h"
97
#include "ihevce_function_selector.h"
98
#include "ihevce_enc_structs.h"
99
#include "ihevce_cmn_utils_instr_set_router.h"
100
#include "ihevce_memory_init.h"
101
#include "ihevce_lap_interface.h"
102
#include "ihevce_entropy_cod.h"
103
#include "ihevce_entropy_structs.h"
104
#include "ihevce_frame_process_utils.h"
105
#include "ihevce_frame_process.h"
106
#include "ihevce_profile.h"
107
#include "ihevce_global_tables.h"
108
#include "ihevce_dep_mngr_interface.h"
109
#include "ihevce_common_utils.h"
110
#include "hme_datatype.h"
111
#include "hme_interface.h"
112
#include "hme_common_defs.h"
113
#include "hme_defs.h"
114
#include "ihevce_coarse_me_pass.h"
115
#include "ihevce_me_pass.h"
116
#include "ihevce_enc_loop_structs.h"
117
#include "ihevce_enc_loop_pass.h"
118
119
#include "cast_types.h"
120
#include "osal.h"
121
#include "osal_defaults.h"
122
123
/*****************************************************************************/
124
/* Function Definitions                                                      */
125
/*****************************************************************************/
126
/*!
127
******************************************************************************
128
* \if Function name : ihevce_context_reset \endif
129
*
130
* \brief
131
*    Encoder reset function
132
*
133
* \param[in] Encoder context pointer
134
*
135
* \return
136
*    None
137
*
138
* \author
139
*  Ittiam
140
*
141
*****************************************************************************
142
*/
143
void ihevce_context_reset(enc_ctxt_t *ps_enc_ctxt)
144
238
{
145
238
    ps_enc_ctxt->i4_end_flag = 0;
146
147
    /* set the queue related pointer and buffer to default value */
148
238
    ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl = NULL;
149
150
    /* Reset the i/o queues created status to 0 */
151
238
    ps_enc_ctxt->i4_io_queues_created = 0;
152
153
    /* reset the frame limit flag to 0 */
154
238
    ps_enc_ctxt->i4_frame_limit_reached = 0;
155
156
238
    return;
157
238
}
158
159
/*!
160
******************************************************************************
161
* \if Function name : ihevce_hle_interface_create \endif
162
*
163
* \brief
164
*    High level Encoder create function
165
*
166
* \param[in]  High level encoder interface context pointer
167
*
168
* \return
169
*    success or fail
170
*
171
* \author
172
*  Ittiam
173
*
174
*****************************************************************************
175
*/
176
IV_API_CALL_STATUS_T ihevce_hle_interface_create(ihevce_hle_ctxt_t *ps_hle_ctxt)
177
238
{
178
    /* local variables */
179
238
    enc_ctxt_t *ps_enc_ctxt;
180
238
    iv_mem_rec_t s_memtab;
181
238
    ihevce_static_cfg_params_t *ps_enc_static_cfg_params;
182
238
    WORD32 i4_num_resolutions = ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_num_res_layers;
183
238
    WORD32 i4_look_ahead_frames_in_first_pass = -1;
184
238
    WORD32 i4_total_cores = 0, ctr, i4_mres_flag = 0;
185
238
    ihevce_sys_api_t *ps_sys_api = &ps_hle_ctxt->ps_static_cfg_prms->s_sys_api;
186
187
238
    WORD32 status = 0;
188
238
    WORD32 i;
189
238
    WORD32 *pi4_active_res_id = NULL;
190
191
    /* OSAL Init */
192
238
    status = ihevce_osal_init((void *)ps_hle_ctxt);
193
194
238
    if(status != 0)
195
0
        return (IV_FAIL);
196
197
    /* --------------------------------------------------------------------- */
198
    /*              High Level Encoder Init                                  */
199
    /* --------------------------------------------------------------------- */
200
201
238
    if(i4_num_resolutions > 1)
202
0
        i4_mres_flag = 1;
203
    /* set no error in the output */
204
238
    ps_hle_ctxt->i4_error_code = 0;
205
206
    /* Error checks on the static parameters passed */
207
238
    ps_hle_ctxt->i4_error_code = ihevce_hle_validate_static_params(ps_hle_ctxt->ps_static_cfg_prms);
208
209
    /*memory for static cfg params for encoder, which can be overwritten if encoder wants
210
        encoder should use this for all its usage*/
211
238
    s_memtab.i4_size = sizeof(iv_mem_rec_t);
212
238
    s_memtab.i4_mem_alignment = 4;
213
238
    s_memtab.i4_mem_size = sizeof(ihevce_static_cfg_params_t);
214
238
    s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
215
216
238
    ps_hle_ctxt->ihevce_mem_alloc(
217
238
        ps_hle_ctxt->pv_mem_mgr_hdl, &ps_hle_ctxt->ps_static_cfg_prms->s_sys_api, &s_memtab);
218
238
    if(s_memtab.pv_base == NULL)
219
0
    {
220
0
        return (IV_FAIL);
221
0
    }
222
238
    ps_enc_static_cfg_params = (ihevce_static_cfg_params_t *)s_memtab.pv_base;
223
238
    memcpy(
224
238
        ps_enc_static_cfg_params,
225
238
        ps_hle_ctxt->ps_static_cfg_prms,
226
238
        (sizeof(ihevce_static_cfg_params_t)));
227
228
238
    i4_total_cores = ps_enc_static_cfg_params->s_multi_thrd_prms.i4_max_num_cores;
229
230
    /* check for validity of memory control flag (only 0,1,2 modes are allowed) */
231
238
    if((ps_enc_static_cfg_params->s_multi_thrd_prms.i4_memory_alloc_ctrl_flag > 2) ||
232
238
       (ps_enc_static_cfg_params->s_multi_thrd_prms.i4_memory_alloc_ctrl_flag < 0))
233
0
    {
234
0
        ps_hle_ctxt->i4_error_code = IHEVCE_INVALID_MEM_CTRL_FLAG;
235
0
    }
236
237
238
    if((i4_mres_flag == 1) &&
238
0
       (ps_enc_static_cfg_params->s_multi_thrd_prms.i4_use_thrd_affinity == 1))
239
0
    {
240
0
        ps_sys_api->ihevce_printf(
241
0
            ps_sys_api->pv_cb_handle,
242
0
            "\nIHEVCE WARNING: Enabling thread affinity in multiresolution encoding will affect "
243
0
            "performance\n");
244
0
    }
245
238
    if((ps_enc_static_cfg_params->s_tgt_lyr_prms.as_tgt_params[0].i4_quality_preset ==
246
238
        IHEVCE_QUALITY_P6) &&
247
8
       (ps_enc_static_cfg_params->s_config_prms.i4_cu_level_rc))
248
0
    {
249
0
        ps_sys_api->ihevce_printf(
250
0
            ps_sys_api->pv_cb_handle,
251
0
            "\nIHEVCE WARNING: Disabling CU level QP modulation for P6 preset\n");
252
0
        ps_enc_static_cfg_params->s_config_prms.i4_cu_level_rc = 0;
253
0
    }
254
238
    if((ps_enc_static_cfg_params->s_tgt_lyr_prms.as_tgt_params[0].i4_quality_preset ==
255
238
        IHEVCE_QUALITY_P7) &&
256
31
       (ps_enc_static_cfg_params->s_config_prms.i4_cu_level_rc))
257
0
    {
258
0
        ps_sys_api->ihevce_printf(
259
0
            ps_sys_api->pv_cb_handle,
260
0
            "\nIHEVCE WARNING: Disabling CU level QP modulation for P7 preset\n");
261
0
        ps_enc_static_cfg_params->s_config_prms.i4_cu_level_rc = 0;
262
0
    }
263
264
238
    if(0 != ps_hle_ctxt->i4_error_code)
265
0
    {
266
0
        ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab);
267
0
        return (IV_FAIL);
268
0
    }
269
238
    ps_hle_ctxt->ai4_num_core_per_res[0] = i4_total_cores;
270
271
238
    if(1 == ps_enc_static_cfg_params->s_tgt_lyr_prms.i4_mres_single_out)
272
0
    {
273
        /*    Memory Allocation of pi4_active_res_id */
274
0
        s_memtab.i4_size = sizeof(iv_mem_rec_t);
275
0
        s_memtab.i4_mem_alignment = 4;
276
0
        s_memtab.i4_mem_size = sizeof(WORD32) * (IHEVCE_MAX_NUM_RESOLUTIONS + 1);
277
0
        s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
278
279
0
        ps_hle_ctxt->ihevce_mem_alloc(
280
0
            ps_hle_ctxt->pv_mem_mgr_hdl, &ps_enc_static_cfg_params->s_sys_api, &s_memtab);
281
0
        if(s_memtab.pv_base == NULL)
282
0
        {
283
0
            return (IV_FAIL);
284
0
        }
285
286
0
        pi4_active_res_id = (WORD32 *)s_memtab.pv_base;
287
0
    }
288
    /* --------------------------------------------------------------------- */
289
    /*    Context and Memory Initialization of Encoder ctxt                  */
290
    /* --------------------------------------------------------------------- */
291
476
    for(ctr = 0; ctr < i4_num_resolutions; ctr++)
292
238
    {
293
238
        WORD32 i4_br_id;
294
238
        s_memtab.i4_size = sizeof(iv_mem_rec_t);
295
238
        s_memtab.i4_mem_alignment = 4;
296
238
        s_memtab.i4_mem_size = sizeof(enc_ctxt_t);
297
238
        s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
298
299
238
        ps_hle_ctxt->ihevce_mem_alloc(
300
238
            ps_hle_ctxt->pv_mem_mgr_hdl, &ps_enc_static_cfg_params->s_sys_api, &s_memtab);
301
238
        if(s_memtab.pv_base == NULL)
302
0
        {
303
0
            return (IV_FAIL);
304
0
        }
305
306
238
        ps_enc_ctxt = (enc_ctxt_t *)s_memtab.pv_base;
307
308
238
        ps_enc_ctxt->ps_stat_prms = ps_enc_static_cfg_params;
309
310
        /* check of number of cores to decide the num threads active */
311
238
        ps_enc_ctxt->s_multi_thrd.i4_all_thrds_active_flag = 1;
312
313
238
        if(1 == ps_enc_static_cfg_params->s_tgt_lyr_prms.i4_mres_single_out)
314
0
        {
315
0
            pi4_active_res_id[ctr] = 0;
316
0
            ps_enc_ctxt->s_multi_thrd.pi4_active_res_id = pi4_active_res_id;
317
0
        }
318
319
        /*store num bit-rate instances in the encoder context */
320
238
        ps_enc_ctxt->i4_num_bitrates =
321
238
            ps_enc_static_cfg_params->s_tgt_lyr_prms.as_tgt_params[ctr].i4_num_bitrate_instances;
322
238
        if(BLU_RAY_SUPPORT == ps_enc_static_cfg_params->s_out_strm_prms.i4_interop_flags)
323
0
        {
324
0
            ps_enc_ctxt->i4_blu_ray_spec = 1;
325
0
        }
326
238
        else
327
238
        {
328
238
            ps_enc_ctxt->i4_blu_ray_spec = 0;
329
238
        }
330
331
        /* if all threads are required to be active */
332
238
        if(1 == ps_enc_ctxt->s_multi_thrd.i4_all_thrds_active_flag)
333
238
        {
334
            /* store the number of threads to be created as passed by app with HT flag */
335
238
            ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds =
336
238
                ps_hle_ctxt->ai4_num_core_per_res[ctr];
337
338
            /* pre enc threads are doubled if HT is ON */
339
238
            ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds =
340
238
                ps_hle_ctxt->ai4_num_core_per_res[ctr];
341
238
        }
342
0
        else
343
0
        {
344
            // TODO: distribute threads across stages
345
0
        }
346
347
        /*Keep track of resolution id, this is used to differentiate from other encoder instance*/
348
238
        ps_enc_ctxt->i4_resolution_id = ctr;
349
        /* store hle ctxt in enc ctxt */
350
238
        ps_enc_ctxt->pv_hle_ctxt = (void *)ps_hle_ctxt;
351
238
        ps_enc_ctxt->pv_rc_mutex_lock_hdl = NULL;
352
238
        ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_mutex_lock_hdl = NULL;
353
238
        ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_for_qp_update_mutex_lock_hdl = NULL;
354
238
        ps_enc_ctxt->i4_look_ahead_frames_in_first_pass = i4_look_ahead_frames_in_first_pass;
355
356
238
        ps_enc_ctxt->ai4_is_past_pic_complex[0] = 0;
357
238
        ps_enc_ctxt->ai4_is_past_pic_complex[1] = 0;
358
238
        ps_enc_ctxt->i4_is_I_reset_done = 1;
359
238
        ps_enc_ctxt->i4_past_RC_reset_count = 0;
360
238
        ps_enc_ctxt->i4_future_RC_reset = 0;
361
238
        ps_enc_ctxt->i4_past_RC_scd_reset_count = 0;
362
238
        ps_enc_ctxt->i4_future_RC_scd_reset = 0;
363
238
        ps_enc_ctxt->i4_active_scene_num = -1;
364
476
        for(i = 0; i < IHEVCE_MAX_NUM_BITRATES; i++)
365
238
        {
366
238
            ps_enc_ctxt->ai4_rc_query[i] = 0;
367
238
        }
368
238
        ps_enc_ctxt->i4_active_enc_frame_id = 0;
369
238
        ps_enc_ctxt->u1_is_popcnt_available = 1;
370
371
238
#ifndef ARM
372
238
        ps_enc_ctxt->e_arch_type = ARCH_X86_GENERIC;
373
238
        ps_enc_ctxt->u1_is_popcnt_available = 0;
374
#else
375
        if(ps_enc_static_cfg_params->e_arch_type == ARCH_NA)
376
            ps_enc_ctxt->e_arch_type = ihevce_default_arch();
377
        else
378
            ps_enc_ctxt->e_arch_type = ps_enc_static_cfg_params->e_arch_type;
379
        ps_enc_ctxt->u1_is_popcnt_available = 0;
380
#endif
381
382
238
        {
383
238
            ps_enc_static_cfg_params->e_arch_type = ps_enc_ctxt->e_arch_type;
384
385
238
            ihevce_init_function_ptr(ps_enc_ctxt, ps_enc_ctxt->e_arch_type);
386
238
        }
387
388
238
        ihevce_mem_manager_init(ps_enc_ctxt, ps_hle_ctxt);
389
390
238
        if(0 != ps_hle_ctxt->i4_error_code)
391
0
        {
392
0
            return (IV_FAIL);
393
0
        }
394
395
        /* mutex lock for RC calls */
396
238
        ps_enc_ctxt->pv_rc_mutex_lock_hdl = osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
397
238
        if(NULL == ps_enc_ctxt->pv_rc_mutex_lock_hdl)
398
0
        {
399
0
            return IV_FAIL;
400
0
        }
401
402
        /* mutex lock for Sub pic RC calls */
403
238
        ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_mutex_lock_hdl =
404
238
            osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
405
238
        if(NULL == ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_mutex_lock_hdl)
406
0
        {
407
0
            return IV_FAIL;
408
0
        }
409
410
238
        ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_for_qp_update_mutex_lock_hdl =
411
238
            osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
412
238
        if(NULL == ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_for_qp_update_mutex_lock_hdl)
413
0
        {
414
0
            return IV_FAIL;
415
0
        }
416
417
        /* reset the encoder context */
418
238
        ihevce_context_reset(ps_enc_ctxt);
419
420
        /* register the Encoder context in HLE interface ctxt */
421
238
        ps_hle_ctxt->apv_enc_hdl[ctr] = ps_enc_ctxt;
422
238
    }
423
    /* init profile */
424
238
    PROFILE_INIT(&ps_hle_ctxt->profile_hle);
425
476
    for(ctr = 0; ctr < i4_num_resolutions; ctr++)
426
238
    {
427
238
        WORD32 i4_br_id;
428
429
238
        PROFILE_INIT(&ps_hle_ctxt->profile_enc_me[ctr]);
430
238
        PROFILE_INIT(&ps_hle_ctxt->profile_pre_enc_l1l2[ctr]);
431
238
        PROFILE_INIT(&ps_hle_ctxt->profile_pre_enc_l0ipe[ctr]);
432
476
        for(i4_br_id = 0; i4_br_id < ps_enc_ctxt->i4_num_bitrates; i4_br_id++)
433
238
        {
434
238
            PROFILE_INIT(&ps_hle_ctxt->profile_enc[ctr][i4_br_id]);
435
238
            PROFILE_INIT(&ps_hle_ctxt->profile_entropy[ctr][i4_br_id]);
436
238
        }
437
238
    }
438
238
    if(1 == ps_enc_static_cfg_params->s_tgt_lyr_prms.i4_mres_single_out)
439
0
        pi4_active_res_id[i4_num_resolutions] = 0;
440
441
238
    return (IV_SUCCESS);
442
238
}
443
444
/*!
445
******************************************************************************
446
* \if Function name : ihevce_query_io_buf_req \endif
447
*
448
* \brief
449
*    High level Encoder IO buffers query function
450
*
451
* \param[in] High level encoder interface context pointer
452
* \param[out] Input buffer requirment stucture pointer.
453
* \param[out] Output buffer requirment stucture pointer.
454
*
455
* \return
456
*    success or fail
457
*
458
* \author
459
*  Ittiam
460
*
461
*****************************************************************************
462
*/
463
IV_API_CALL_STATUS_T ihevce_query_io_buf_req(
464
    ihevce_hle_ctxt_t *ps_hle_ctxt,
465
    iv_input_bufs_req_t *ps_input_bufs_req,
466
    iv_res_layer_output_bufs_req_t *ps_res_layer_output_bufs_req,
467
    iv_res_layer_recon_bufs_req_t *ps_res_layer_recon_bufs_req)
468
238
{
469
    /* local variables */
470
238
    enc_ctxt_t *ps_enc_ctxt;
471
238
    ihevce_src_params_t *ps_src_prms;
472
238
    WORD32 ctb_align_pic_wd;
473
238
    WORD32 ctb_align_pic_ht, i4_resolution_id = 0, i4_num_resolutions, i4_num_bitrate_instances;
474
238
    WORD32 i4_resolution_id_ctr, br_ctr;
475
476
238
    ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[i4_resolution_id];
477
238
    ps_src_prms = &ps_hle_ctxt->ps_static_cfg_prms->s_src_prms;
478
238
    i4_num_resolutions = ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_num_res_layers;
479
    /* set no error in the output */
480
238
    ps_hle_ctxt->i4_error_code = 0;
481
482
    /* ------- populate the Input buffer requirements -------- */
483
    /* get the number of buffers required for LAP */
484
238
    ps_input_bufs_req->i4_min_num_yuv_bufs =
485
238
        ihevce_lap_get_num_ip_bufs(&ps_enc_ctxt->s_lap_stat_prms);
486
487
238
    ps_input_bufs_req->i4_min_num_synch_ctrl_bufs = ps_input_bufs_req->i4_min_num_yuv_bufs;
488
489
238
    ps_input_bufs_req->i4_min_num_asynch_ctrl_bufs = NUM_AYSNC_CMD_BUFS;
490
491
    /* buffer sizes are populated based on create time parameters */
492
238
    ctb_align_pic_wd =
493
238
        ps_src_prms->i4_width +
494
238
        SET_CTB_ALIGN(ps_src_prms->i4_width, ps_enc_ctxt->s_frm_ctb_prms.i4_ctb_size);
495
496
238
    ctb_align_pic_ht =
497
238
        ps_src_prms->i4_height +
498
238
        SET_CTB_ALIGN(ps_src_prms->i4_height, ps_enc_ctxt->s_frm_ctb_prms.i4_ctb_size);
499
500
238
    if(ps_src_prms->i4_input_bit_depth > 8)
501
0
    {
502
0
        ps_input_bufs_req->i4_min_size_y_buf = ctb_align_pic_wd * ctb_align_pic_ht * 2;
503
504
0
        ps_input_bufs_req->i4_min_size_uv_buf = ps_input_bufs_req->i4_min_size_y_buf >> 1;
505
0
    }
506
238
    else
507
238
    {
508
238
        ps_input_bufs_req->i4_min_size_y_buf = ctb_align_pic_wd * ctb_align_pic_ht;
509
510
238
        ps_input_bufs_req->i4_min_size_uv_buf = (ctb_align_pic_wd * ctb_align_pic_ht) >> 1;
511
238
    }
512
513
238
    ps_input_bufs_req->i4_min_size_uv_buf <<=
514
238
        ((ps_src_prms->i4_chr_format == IV_YUV_422SP_UV) ? 1 : 0);
515
516
238
    ps_input_bufs_req->i4_yuv_format = ps_src_prms->i4_chr_format;
517
518
238
#ifndef DISABLE_SEI
519
238
    ps_input_bufs_req->i4_min_size_synch_ctrl_bufs =
520
238
        ((MAX_SEI_PAYLOAD_PER_TLV + 16) * MAX_NUMBER_OF_SEI_PAYLOAD) + 16;
521
522
238
    ps_input_bufs_req->i4_min_size_asynch_ctrl_bufs =
523
238
        ((MAX_SEI_PAYLOAD_PER_TLV + 16) * (MAX_NUMBER_OF_SEI_PAYLOAD - 6)) + 16;
524
#else
525
    ps_input_bufs_req->i4_min_size_synch_ctrl_bufs = 16;
526
    ps_input_bufs_req->i4_min_size_asynch_ctrl_bufs = 16;
527
#endif
528
529
476
    for(i4_resolution_id_ctr = 0; i4_resolution_id_ctr < i4_num_resolutions; i4_resolution_id_ctr++)
530
238
    {
531
238
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[i4_resolution_id_ctr];
532
533
238
        i4_num_bitrate_instances = ps_enc_ctxt->s_runtime_tgt_params.i4_num_bitrate_instances;
534
535
        /* buffer sizes are populated based on create time parameters */
536
238
        ctb_align_pic_wd = ps_enc_ctxt->s_runtime_tgt_params.i4_width +
537
238
                           SET_CTB_ALIGN(
538
238
                               ps_enc_ctxt->s_runtime_tgt_params.i4_width,
539
238
                               ps_enc_ctxt->s_frm_ctb_prms.i4_ctb_size);
540
541
238
        ctb_align_pic_ht = ps_enc_ctxt->s_runtime_tgt_params.i4_height +
542
238
                           SET_CTB_ALIGN(
543
238
                               ps_enc_ctxt->s_runtime_tgt_params.i4_height,
544
238
                               ps_enc_ctxt->s_frm_ctb_prms.i4_ctb_size);
545
546
476
        for(br_ctr = 0; br_ctr < i4_num_bitrate_instances; br_ctr++)
547
238
        {
548
            /* ------- populate the Output buffer requirements -------- */
549
238
            ps_res_layer_output_bufs_req->s_output_buf_req[i4_resolution_id_ctr][br_ctr]
550
238
                .i4_min_num_out_bufs = NUM_OUTPUT_BUFS;
551
552
238
            ps_res_layer_output_bufs_req->s_output_buf_req[i4_resolution_id_ctr][br_ctr]
553
238
                .i4_min_size_bitstream_buf = (ctb_align_pic_wd * ctb_align_pic_ht);
554
555
238
            if((ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_internal_bit_depth == 12) ||
556
238
               ((ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_internal_bit_depth > 8) &&
557
0
                (ps_src_prms->i4_chr_format == IV_YUV_422SP_UV)))
558
0
            {
559
0
                ps_res_layer_output_bufs_req->s_output_buf_req[i4_resolution_id_ctr][br_ctr]
560
0
                    .i4_min_size_bitstream_buf *= 2;
561
0
            }
562
563
238
            if((ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_internal_bit_depth == 10) &&
564
0
               (ps_src_prms->i4_chr_format == IV_YUV_420SP_UV))
565
0
            {
566
0
                ps_res_layer_output_bufs_req->s_output_buf_req[i4_resolution_id_ctr][br_ctr]
567
0
                    .i4_min_size_bitstream_buf *= 3;
568
0
                ps_res_layer_output_bufs_req->s_output_buf_req[i4_resolution_id_ctr][br_ctr]
569
0
                    .i4_min_size_bitstream_buf >>= 1;
570
0
            }
571
572
            //recon_dump
573
            /* ------- populate the Recon buffer requirements -------- */
574
238
            if(ps_enc_ctxt->ps_stat_prms->i4_save_recon == 0)
575
238
            {
576
238
                ps_res_layer_recon_bufs_req->s_recon_buf_req[i4_resolution_id_ctr][br_ctr]
577
238
                    .i4_min_num_recon_bufs = 0;
578
579
238
                ps_res_layer_recon_bufs_req->s_recon_buf_req[i4_resolution_id_ctr][br_ctr]
580
238
                    .i4_min_size_y_buf = 0;
581
582
238
                ps_res_layer_recon_bufs_req->s_recon_buf_req[i4_resolution_id_ctr][br_ctr]
583
238
                    .i4_min_size_uv_buf = 0;
584
238
            }
585
0
            else
586
0
            {
587
0
                ps_res_layer_recon_bufs_req->s_recon_buf_req[i4_resolution_id_ctr][br_ctr]
588
0
                    .i4_min_num_recon_bufs = 2 * HEVCE_MAX_REF_PICS + 1;
589
590
0
                ps_res_layer_recon_bufs_req->s_recon_buf_req[i4_resolution_id_ctr][br_ctr]
591
0
                    .i4_min_size_y_buf =
592
0
                    ctb_align_pic_wd * ctb_align_pic_ht *
593
0
                    ((ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_internal_bit_depth > 8)
594
0
                         ? 2
595
0
                         : 1);
596
597
0
                ps_res_layer_recon_bufs_req->s_recon_buf_req[i4_resolution_id_ctr][br_ctr]
598
0
                    .i4_min_size_uv_buf =
599
0
                    (ps_res_layer_recon_bufs_req->s_recon_buf_req[i4_resolution_id_ctr][br_ctr]
600
0
                         .i4_min_size_y_buf >>
601
0
                     1);
602
0
                ps_res_layer_recon_bufs_req->s_recon_buf_req[i4_resolution_id_ctr][br_ctr]
603
0
                    .i4_min_size_uv_buf <<=
604
0
                    ((ps_src_prms->i4_chr_format == IV_YUV_422SP_UV) ? 1 : 0);
605
0
            }
606
238
        }
607
238
    }
608
609
238
    return (IV_SUCCESS);
610
238
}
611
612
/*!
613
******************************************************************************
614
* \if Function name : ihevce_create_ports \endif
615
*
616
* \brief
617
*    High level Encoder IO ports Create function
618
*
619
* \param[in] High level encoder interface context pointer
620
* \param[in] Input data buffer descriptor
621
* \param[in] Input control buffer descriptor
622
* \param[in] Output data buffer descriptor
623
* \param[in] Output control status buffer descriptor
624
* \param[out] Pointer to store the ID for Input data Que
625
* \param[out] Pointer to store the ID for Input control Que
626
* \param[out] Pointer to store the ID for Output data Que
627
* \param[out] Pointer to store the ID for Output control status Que
628
*
629
* \return
630
*  success or fail
631
*
632
* \author
633
*  Ittiam
634
*
635
*****************************************************************************
636
*/
637
IV_API_CALL_STATUS_T ihevce_create_ports(
638
    ihevce_hle_ctxt_t *ps_hle_ctxt,
639
    iv_input_data_ctrl_buffs_desc_t *ps_input_data_ctrl_buffs_desc,
640
    iv_input_asynch_ctrl_buffs_desc_t *ps_input_asynch_ctrl_buffs_desc,
641
    iv_res_layer_output_data_buffs_desc_t *ps_mres_output_data_buffs_desc,
642
    iv_res_layer_recon_data_buffs_desc_t *ps_mres_recon_data_buffs_desc)
643
238
{
644
    /* local varaibles */
645
238
    enc_ctxt_t *ps_enc_ctxt;
646
238
    WORD32 res_ctr,
647
238
        i4_num_resolutions = ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_num_res_layers;
648
238
    void *pv_q_mutex_hdl = NULL;
649
650
    /* set no error in the output */
651
238
    ps_hle_ctxt->i4_error_code = 0;
652
653
476
    for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++)
654
238
    {
655
238
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr];
656
        /* check on buffer sizes provided by applciation needs to be checked */
657
658
        /* call the memory manager que init function , pass the op data , status, recon for the first bitrate, internally we will increment*/
659
238
        ihevce_mem_manager_que_init(
660
238
            ps_enc_ctxt,
661
238
            ps_hle_ctxt,
662
238
            ps_input_data_ctrl_buffs_desc,
663
238
            ps_input_asynch_ctrl_buffs_desc,
664
238
            &ps_mres_output_data_buffs_desc->s_output_data_buffs[res_ctr][0],
665
238
            &ps_mres_recon_data_buffs_desc->s_recon_data_buffs[res_ctr][0]);
666
667
        /* set the number of Queues */
668
238
        ps_enc_ctxt->s_enc_ques.i4_num_queues = IHEVCE_MAX_NUM_QUEUES;
669
670
        /* allocate a mutex to take care of handling multiple threads accesing Queues */
671
        /*my understanding, this is common semaphore for all the queue. Since main input is still
672
        common across all instance fo encoder. Hence common semaphore is a must*/
673
238
        if(0 == res_ctr)
674
238
        {
675
238
            ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl = osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
676
            /* store it in local variable for allocating it to other instances */
677
238
            pv_q_mutex_hdl = ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl;
678
238
            if(NULL == pv_q_mutex_hdl)
679
0
            {
680
0
                return IV_FAIL;
681
0
            }
682
238
        }
683
0
        else
684
0
        {
685
0
            ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl = pv_q_mutex_hdl;
686
0
        }
687
688
        /* Set the i/o queues created status to 1 */
689
238
        ps_enc_ctxt->i4_io_queues_created = 1;
690
238
    }
691
238
    return (IV_SUCCESS);
692
238
}
693
694
/*!
695
******************************************************************************
696
* \if Function name : ihevce_hle_interface_thrd \endif
697
*
698
* \brief
699
*    High level encoder thread interface function
700
*
701
* \param[in] High level interface context pointer
702
*
703
* \return
704
*    None
705
*
706
* \author
707
*  Ittiam
708
*
709
*****************************************************************************
710
*/
711
WORD32 ihevce_hle_interface_thrd(void *pv_proc_intf_ctxt)
712
238
{
713
    /* local variables */
714
238
    WORD32 ctr, res_ctr;
715
238
    ihevce_hle_ctxt_t *ps_hle_ctxt;
716
238
    enc_ctxt_t *ps_enc_ctxt;
717
    /* enc ctxt to store 0th instance's params which are required by all instances */
718
238
    enc_ctxt_t *ps_enc_ctxt_base;
719
238
    void *pv_lap_sem_hdl;
720
238
    void *pv_enc_frame_process_sem_hdl;
721
238
    void *pv_pre_enc_frame_process_sem_hdl;
722
238
    void *apv_ent_coding_sem_hdl[IHEVCE_MAX_NUM_BITRATES];
723
238
    void *pv_ent_common_mres_sem_hdl = NULL;
724
238
    void *pv_out_common_mres_sem_hdl = NULL;
725
726
238
    void *pv_inp_data_sem_hdl;
727
238
    void *pv_lap_inp_data_sem_hdl;
728
238
    void *pv_preenc_inp_data_sem_hdl;
729
238
    void *pv_inp_ctrl_sem_hdl;
730
238
    void *apv_out_stream_sem_hdl[IHEVCE_MAX_NUM_BITRATES];
731
238
    void *apv_out_recon_sem_hdl[IHEVCE_MAX_NUM_BITRATES];
732
238
    void *pv_out_ctrl_sts_sem_hdl;
733
734
238
    lap_intface_t *ps_lap_interface_ctxt;
735
238
    iv_mem_rec_t s_memtab;
736
238
    WORD32 i4_num_bit_rate_instances[IHEVCE_MAX_NUM_RESOLUTIONS], i4_num_resolutions;
737
238
    WORD32 i;  //loop variable
738
238
    WORD32 ai4_proc_count[MAX_NUMBER_PROC_GRPS] = { 0 }, i4_proc_grp_count;
739
238
    WORD32 i4_acc_proc_num = 0;
740
741
    /* Frame Encode processing threads & semaphores */
742
238
    void *apv_enc_frm_proc_hdls[IHEVCE_MAX_NUM_RESOLUTIONS][MAX_NUM_FRM_PROC_THRDS_ENC];
743
238
    frm_proc_thrd_ctxt_t
744
238
        *aps_enc_frm_proc_thrd_ctxt[IHEVCE_MAX_NUM_RESOLUTIONS][MAX_NUM_FRM_PROC_THRDS_ENC];
745
746
    /* Pre Frame Encode processing threads & semaphores */
747
238
    void *apv_pre_enc_frm_proc_hdls[IHEVCE_MAX_NUM_RESOLUTIONS][MAX_NUM_FRM_PROC_THRDS_PRE_ENC];
748
238
    frm_proc_thrd_ctxt_t
749
238
        *aps_pre_enc_frm_proc_thrd_ctxt[IHEVCE_MAX_NUM_RESOLUTIONS][MAX_NUM_FRM_PROC_THRDS_PRE_ENC];
750
751
238
    void *apv_entropy_thrd_hdls[IHEVCE_MAX_NUM_RESOLUTIONS][NUM_ENTROPY_THREADS];
752
238
    frm_proc_thrd_ctxt_t *aps_entropy_thrd_ctxt[IHEVCE_MAX_NUM_RESOLUTIONS][NUM_ENTROPY_THREADS];
753
754
238
    ps_hle_ctxt = (ihevce_hle_ctxt_t *)pv_proc_intf_ctxt;
755
238
    ps_enc_ctxt_base = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[0];
756
    /* profile start */
757
238
    PROFILE_START(&ps_hle_ctxt->profile_hle);
758
    /* store default values of mem tab */
759
238
    s_memtab.i4_size = sizeof(iv_mem_rec_t);
760
238
    s_memtab.i4_mem_alignment = 4;
761
762
238
    i4_num_resolutions = ps_enc_ctxt_base->ps_stat_prms->s_tgt_lyr_prms.i4_num_res_layers;
763
238
    memset(
764
238
        apv_entropy_thrd_hdls,
765
238
        0,
766
238
        IHEVCE_MAX_NUM_RESOLUTIONS * NUM_ENTROPY_THREADS * sizeof(void *));
767
238
    memset(
768
238
        apv_entropy_thrd_hdls,
769
238
        0,
770
238
        IHEVCE_MAX_NUM_RESOLUTIONS * NUM_ENTROPY_THREADS * sizeof(void *));
771
476
    for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++)
772
238
    {
773
238
        i4_num_bit_rate_instances[res_ctr] =
774
238
            ps_enc_ctxt_base->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[res_ctr]
775
238
                .i4_num_bitrate_instances;
776
238
    }
777
    /* --------------------------------------------------------------------- */
778
    /*        Init number of threads for each stage                          */
779
    /* --------------------------------------------------------------------- */
780
781
238
    {
782
476
        for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++)
783
238
        {
784
238
            ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr];
785
            /* all the threads created will be made active */
786
238
            ps_enc_ctxt->s_multi_thrd.i4_num_active_enc_thrds =
787
238
                ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds;
788
789
238
            ps_enc_ctxt->s_multi_thrd.i4_num_active_pre_enc_thrds =
790
238
                ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds;
791
238
        }
792
238
    }
793
794
    /* --------------------------------------------------------------------- */
795
    /*            Multiple processing Threads Semaphores init                */
796
    /* --------------------------------------------------------------------- */
797
476
    for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++)
798
238
    {
799
238
        osal_sem_attr_t attr = OSAL_DEFAULT_SEM_ATTR;
800
801
238
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr];
802
803
238
        attr.value = SEM_START_VALUE;
804
805
        /* Create Semaphore handle for LAP thread   */
806
238
        if(0 == ps_enc_ctxt->i4_resolution_id)
807
238
        {
808
238
            pv_lap_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr);
809
238
            if(NULL == pv_lap_sem_hdl)
810
0
            {
811
0
                return IV_FAIL;
812
0
            }
813
238
        }
814
0
        else
815
0
        {
816
            /*NOTE: Tile workspace assigned this to null. Confirm this*/
817
0
            pv_lap_sem_hdl = ps_enc_ctxt_base->s_thrd_sem_ctxt.pv_lap_sem_handle;
818
0
        }
819
        /* Create Semaphore for encode frame process thread */
820
238
        pv_enc_frame_process_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr);
821
238
        if(NULL == pv_enc_frame_process_sem_hdl)
822
0
        {
823
0
            return IV_FAIL;
824
0
        }
825
826
        /* Create Semaphore for pre_encode frame process thread */
827
238
        pv_pre_enc_frame_process_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr);
828
238
        if(NULL == pv_pre_enc_frame_process_sem_hdl)
829
0
        {
830
0
            return IV_FAIL;
831
0
        }
832
833
        /* Create Semaphore for input frame data q function */
834
238
        if(0 == ps_enc_ctxt->i4_resolution_id)
835
238
        {
836
238
            pv_inp_data_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr);
837
238
            if(NULL == pv_inp_data_sem_hdl)
838
0
            {
839
0
                return IV_FAIL;
840
0
            }
841
238
        }
842
0
        else
843
0
        {
844
0
            pv_inp_data_sem_hdl = ps_enc_ctxt_base->s_thrd_sem_ctxt.pv_inp_data_sem_handle;
845
0
        }
846
847
        /*creating new input queue owned by encoder*/
848
        /* Create Semaphore for input frame data q function */
849
238
        pv_lap_inp_data_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr);
850
238
        if(NULL == pv_lap_inp_data_sem_hdl)
851
0
        {
852
0
            return IV_FAIL;
853
0
        }
854
855
        /* Create Semaphore for input frame data q function */
856
238
        pv_preenc_inp_data_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr);
857
238
        if(NULL == pv_preenc_inp_data_sem_hdl)
858
0
        {
859
0
            return IV_FAIL;
860
0
        }
861
862
        /* Create Semaphore for input conrol data q function */
863
238
        if(0 == ps_enc_ctxt->i4_resolution_id)
864
238
        {
865
238
            pv_inp_ctrl_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr);
866
238
            if(NULL == pv_inp_ctrl_sem_hdl)
867
0
            {
868
0
                return IV_FAIL;
869
0
            }
870
238
        }
871
0
        else
872
0
        { /*Inp ctrl queue is same for all resolutions between app and lap*/
873
0
            pv_inp_ctrl_sem_hdl = ps_enc_ctxt_base->s_thrd_sem_ctxt.pv_inp_ctrl_sem_handle;
874
0
        }
875
876
        /* Create Semaphore for output control status data q function */
877
238
        pv_out_ctrl_sts_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr);
878
238
        if(NULL == pv_out_ctrl_sts_sem_hdl)
879
0
        {
880
0
            return IV_FAIL;
881
0
        }
882
883
        /* Multi res single output case singel output queue is used for all output resolutions */
884
238
        if(1 == ps_enc_ctxt_base->ps_stat_prms->s_tgt_lyr_prms.i4_mres_single_out)
885
0
        {
886
0
            ps_enc_ctxt->s_enc_ques.apv_q_hdl[IHEVCE_OUTPUT_DATA_Q] =
887
0
                ps_enc_ctxt_base->s_enc_ques.apv_q_hdl[IHEVCE_OUTPUT_DATA_Q];
888
0
            if(0 == ps_enc_ctxt->i4_resolution_id)
889
0
            {
890
                /* Create Semaphore for enropy coding thread   */
891
0
                pv_ent_common_mres_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr);
892
0
                if(NULL == pv_ent_common_mres_sem_hdl)
893
0
                {
894
0
                    return IV_FAIL;
895
0
                }
896
897
                /* Create Semaphore for output stream data q function */
898
0
                pv_out_common_mres_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr);
899
0
                if(NULL == pv_out_common_mres_sem_hdl)
900
0
                {
901
0
                    return IV_FAIL;
902
0
                }
903
0
            }
904
0
            ps_enc_ctxt->s_thrd_sem_ctxt.pv_ent_common_mres_sem_hdl = pv_ent_common_mres_sem_hdl;
905
0
            ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_common_mres_sem_hdl = pv_out_common_mres_sem_hdl;
906
0
        }
907
908
        /*create entropy and output semaphores for each thread.
909
        Each thread will correspond to each bit-rate instance running */
910
476
        for(i = 0; i < i4_num_bit_rate_instances[res_ctr]; i++)
911
238
        {
912
            /* Create Semaphore for enropy coding thread   */
913
238
            apv_ent_coding_sem_hdl[i] = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr);
914
238
            if(NULL == apv_ent_coding_sem_hdl[i])
915
0
            {
916
0
                return IV_FAIL;
917
0
            }
918
919
            /* Create Semaphore for output stream data q function */
920
238
            apv_out_stream_sem_hdl[i] = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr);
921
238
            if(NULL == apv_out_stream_sem_hdl[i])
922
0
            {
923
0
                return IV_FAIL;
924
0
            }
925
926
            /* Create Semaphore for output recon data q function */
927
238
            apv_out_recon_sem_hdl[i] = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr);
928
238
            if(NULL == apv_out_recon_sem_hdl[i])
929
0
            {
930
0
                return IV_FAIL;
931
0
            }
932
238
        }
933
934
        /* update the semaphore handles and the thread creates status */
935
936
238
        ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle = pv_enc_frame_process_sem_hdl;
937
238
        ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle =
938
238
            pv_pre_enc_frame_process_sem_hdl;
939
238
        ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle = pv_lap_sem_hdl;
940
238
        ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_data_sem_handle = pv_inp_data_sem_hdl;
941
238
        ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_inp_data_sem_hdl = pv_lap_inp_data_sem_hdl;
942
238
        ps_enc_ctxt->s_thrd_sem_ctxt.pv_preenc_inp_data_sem_hdl = pv_preenc_inp_data_sem_hdl;
943
238
        ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_ctrl_sem_handle = pv_inp_ctrl_sem_hdl;
944
238
        ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_ctrl_sem_handle = pv_out_ctrl_sts_sem_hdl;
945
476
        for(i = 0; i < i4_num_bit_rate_instances[res_ctr]; i++)
946
238
        {
947
238
            ps_enc_ctxt->s_thrd_sem_ctxt.apv_ent_cod_sem_handle[i] = apv_ent_coding_sem_hdl[i];
948
238
            ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_strm_sem_handle[i] = apv_out_stream_sem_hdl[i];
949
238
            ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_recon_sem_handle[i] = apv_out_recon_sem_hdl[i];
950
238
        }
951
238
    }
952
953
    /* --------------------------------------------------------------------- */
954
    /*            Multiple processing Threads Mutex init                     */
955
    /* --------------------------------------------------------------------- */
956
476
    for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++)
957
238
    {
958
238
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr];
959
960
        /* create a mutex lock for Job Queue access accross slave threads of encode frame processing */
961
238
        ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_enc_grp_me =
962
238
            osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
963
238
        if(NULL == ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_enc_grp_me)
964
0
        {
965
0
            return IV_FAIL;
966
0
        }
967
968
        /* create a mutex lock for Job Queue access accross slave threads of encode frame processing */
969
238
        ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_enc_grp_enc_loop =
970
238
            osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
971
238
        if(NULL == ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_enc_grp_enc_loop)
972
0
        {
973
0
            return IV_FAIL;
974
0
        }
975
976
        /* create mutex for enc thread group */
977
476
        for(i = 0; i < MAX_NUM_ME_PARALLEL; i++)
978
238
        {
979
238
            ps_enc_ctxt->s_multi_thrd.apv_mutex_handle[i] =
980
238
                osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
981
238
            if(NULL == ps_enc_ctxt->s_multi_thrd.apv_mutex_handle[i])
982
0
            {
983
0
                return IV_FAIL;
984
0
            }
985
986
238
            ps_enc_ctxt->s_multi_thrd.apv_mutex_handle_me_end[i] =
987
238
                osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
988
238
            if(NULL == ps_enc_ctxt->s_multi_thrd.apv_mutex_handle_me_end[i])
989
0
            {
990
0
                return IV_FAIL;
991
0
            }
992
238
        }
993
994
476
        for(i = 0; i < MAX_NUM_ENC_LOOP_PARALLEL; i++)
995
238
        {
996
238
            ps_enc_ctxt->s_multi_thrd.apv_post_enc_mutex_handle[i] =
997
238
                osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
998
238
            if(NULL == ps_enc_ctxt->s_multi_thrd.apv_post_enc_mutex_handle[i])
999
0
            {
1000
0
                return IV_FAIL;
1001
0
            }
1002
1003
238
            ps_enc_ctxt->s_multi_thrd.apv_mutex_handle_frame_init[i] =
1004
238
                osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
1005
238
            if(NULL == ps_enc_ctxt->s_multi_thrd.apv_mutex_handle_frame_init[i])
1006
0
            {
1007
0
                return IV_FAIL;
1008
0
            }
1009
238
        }
1010
1011
        /*initialize mutex for pre-enc group */
1012
238
        ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_init =
1013
238
            osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
1014
1015
238
        ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_decomp_deinit =
1016
238
            osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
1017
1018
238
        ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_hme_init =
1019
238
            osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
1020
1021
238
        ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_hme_deinit =
1022
238
            osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
1023
1024
238
        ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_deinit =
1025
238
            osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
1026
1027
238
        ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_l0_ipe_init =
1028
238
            osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
1029
1030
238
        ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_decomp =
1031
238
            osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
1032
1033
238
        ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_hme =
1034
238
            osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
1035
1036
238
        ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_l0ipe =
1037
238
            osal_mutex_create(ps_hle_ctxt->pv_osal_handle);
1038
1039
238
        if(NULL == ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_init ||
1040
238
           NULL == ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_decomp_deinit ||
1041
238
           NULL == ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_hme_init ||
1042
238
           NULL == ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_hme_deinit ||
1043
238
           NULL == ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_deinit ||
1044
238
           NULL == ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_l0_ipe_init ||
1045
238
           NULL == ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_decomp ||
1046
238
           NULL == ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_hme ||
1047
238
           NULL == ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_l0ipe)
1048
0
        {
1049
0
            return IV_FAIL;
1050
0
        }
1051
238
    }
1052
1053
    /* --------------------------------------------------------------------- */
1054
    /*            Multiple processing Threads Context init                   */
1055
    /* --------------------------------------------------------------------- */
1056
1057
476
    for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++)
1058
238
    {
1059
238
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr];
1060
238
        ps_enc_ctxt_base = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[0];
1061
1062
        /*initialize multi-thread context for enc group*/
1063
238
        ps_enc_ctxt->s_multi_thrd.i4_is_recon_free_done = 0;
1064
238
        ps_enc_ctxt->s_multi_thrd.i4_idx_dvsr_p = 0;
1065
238
        ps_enc_ctxt->s_multi_thrd.i4_last_inp_buf = 0;
1066
1067
238
        {
1068
            /* For all the ME frames in Parallel */
1069
238
            WORD32 i4_frm_idx;
1070
1071
476
            for(i4_frm_idx = 0; i4_frm_idx < MAX_NUM_ME_PARALLEL; i4_frm_idx++)
1072
238
            {
1073
238
                ps_enc_ctxt->s_multi_thrd.me_num_thrds_exited[i4_frm_idx] = 0;
1074
238
                ps_enc_ctxt->s_multi_thrd.ai4_me_master_done_flag[i4_frm_idx] = 0;
1075
238
                ps_enc_ctxt->s_multi_thrd.ai4_me_enc_buff_prod_flag[i4_frm_idx] = 0;
1076
238
            }
1077
238
        }
1078
1079
238
        {
1080
238
            WORD32 i4_frm_idx;
1081
238
            ps_enc_ctxt->s_multi_thrd.num_thrds_done = 0;
1082
238
            ps_enc_ctxt->s_multi_thrd.num_thrds_exited_for_reenc = 0;
1083
476
            for(i4_frm_idx = 0; i4_frm_idx < MAX_NUM_ENC_LOOP_PARALLEL; i4_frm_idx++)
1084
238
            {
1085
238
                ps_enc_ctxt->s_multi_thrd.num_thrds_exited[i4_frm_idx] = 0;
1086
1087
238
                ps_enc_ctxt->s_multi_thrd.enc_master_done_frame_init[i4_frm_idx] = 0;
1088
1089
476
                for(i = 0; i < i4_num_bit_rate_instances[res_ctr]; i++)
1090
238
                {
1091
                    /*reset the entropy buffer produced status */
1092
238
                    ps_enc_ctxt->s_multi_thrd.ai4_produce_outbuf[i4_frm_idx][i] = 1;
1093
238
                    ps_enc_ctxt->s_multi_thrd.ps_frm_recon[i4_frm_idx][i] = NULL;
1094
1095
238
                    ps_enc_ctxt->s_multi_thrd.ps_curr_out_enc_grp[i4_frm_idx][i] = NULL;
1096
238
                }
1097
238
            }
1098
238
        }
1099
238
        ps_enc_ctxt->s_multi_thrd.i4_seq_mode_enabled_flag = 0;
1100
1101
        /* Set prev_frame_done = 1 to indicate that all the threads are in same frame*/
1102
476
        for(i = 0; i < ps_enc_ctxt->s_multi_thrd.i4_num_enc_loop_frm_pllel; i++)
1103
238
        {
1104
238
            ihevce_dmgr_set_done_frm_frm_sync(
1105
238
                ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_prev_frame_done[i]);
1106
238
        }
1107
        /* Set prev_frame_done = 1 to indicate that all the threads are in same frame*/
1108
238
        ihevce_dmgr_set_done_frm_frm_sync(
1109
238
            ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_enc_done_for_reenc);
1110
        /*to enable the dependency manager to wait when first reached*/
1111
238
        ihevce_dmgr_set_prev_done_frm_frm_sync(
1112
238
            ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_enc_done_for_reenc);
1113
476
        for(i = 0; i < ps_enc_ctxt->s_multi_thrd.i4_num_me_frm_pllel; i++)
1114
238
        {
1115
238
            ihevce_dmgr_set_done_frm_frm_sync(
1116
238
                ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_prev_frame_me_done[i]);
1117
238
        }
1118
1119
        /* initialize multi-thread context for pre enc group */
1120
1121
238
        ps_enc_ctxt->s_multi_thrd.i4_ctrl_blocking_mode = BUFF_QUE_BLOCKING_MODE;
1122
1123
6.90k
        for(ctr = 0; ctr < MAX_PRE_ENC_STAGGER + NUM_BUFS_DECOMP_HME; ctr++)
1124
6.66k
        {
1125
6.66k
            ps_enc_ctxt->s_multi_thrd.ai4_pre_enc_init_done[ctr] = 0;
1126
6.66k
            ps_enc_ctxt->s_multi_thrd.ai4_pre_enc_hme_init_done[ctr] = 0;
1127
6.66k
            ps_enc_ctxt->s_multi_thrd.ai4_pre_enc_deinit_done[ctr] = 1;
1128
6.66k
            ps_enc_ctxt->s_multi_thrd.ai4_num_thrds_processed_decomp[ctr] = 0;
1129
6.66k
            ps_enc_ctxt->s_multi_thrd.ai4_num_thrds_processed_coarse_me[ctr] = 0;
1130
6.66k
            ps_enc_ctxt->s_multi_thrd.ai4_num_thrds_processed_pre_enc[ctr] = 0;
1131
1132
6.66k
            ps_enc_ctxt->s_multi_thrd.ai4_num_thrds_processed_L0_ipe_qp_init[ctr] = 0;
1133
6.66k
            ps_enc_ctxt->s_multi_thrd.ai4_decomp_coarse_me_complete_flag[ctr] = 1;
1134
6.66k
            ps_enc_ctxt->s_multi_thrd.ai4_end_flag_pre_enc[ctr] = 0;
1135
6.66k
        }
1136
1137
        /* Set prev_frame_done = 1 to indicate that all the threads are in same frame*/
1138
238
        ihevce_dmgr_set_done_frm_frm_sync(
1139
238
            ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_l1);
1140
1141
238
        ihevce_dmgr_set_done_frm_frm_sync(
1142
238
            ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_coarse_me);
1143
1144
238
        ihevce_dmgr_set_done_frm_frm_sync(
1145
238
            ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_l0);
1146
1147
238
        {
1148
            /**init idx for handling delay between pre-me and l0-ipe*/
1149
238
            ps_enc_ctxt->s_multi_thrd.i4_delay_pre_me_btw_l0_ipe = 0;
1150
238
            ps_enc_ctxt->s_multi_thrd.i4_max_delay_pre_me_btw_l0_ipe =
1151
238
                MIN_L1_L0_STAGGER_NON_SEQ +
1152
238
                ps_enc_ctxt->s_lap_stat_prms.s_lap_params.i4_rc_look_ahead_pics + 1;
1153
238
            if(ps_enc_ctxt->s_lap_stat_prms.s_lap_params.i4_rc_look_ahead_pics)
1154
0
            {
1155
0
                ps_enc_ctxt->s_multi_thrd.i4_delay_pre_me_btw_l0_ipe =
1156
0
                    MIN_L1_L0_STAGGER_NON_SEQ +
1157
0
                    ps_enc_ctxt->s_lap_stat_prms.s_lap_params.i4_rc_look_ahead_pics;
1158
0
            }
1159
238
            ps_enc_ctxt->s_multi_thrd.i4_qp_update_l0_ipe = -1;
1160
238
        }
1161
238
    }
1162
1163
    /** Get Number of Processor Groups **/
1164
238
    i4_proc_grp_count = ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.i4_num_proc_groups;
1165
    /*** Enc threads are allocated based on the assumption that there can be only 2 processor groups **/
1166
238
    ASSERT(i4_proc_grp_count <= MAX_NUMBER_PROC_GRPS);
1167
    /** Get Number of logical processors in Each Group **/
1168
476
    for(ctr = 0; ctr < i4_proc_grp_count; ctr++)
1169
238
    {
1170
238
        ai4_proc_count[ctr] =
1171
238
            ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.ai4_num_cores_per_grp[ctr];
1172
238
    }
1173
1174
    /* --------------------------------------------------------------------- */
1175
    /*            Create a LAP thread                                        */
1176
    /* --------------------------------------------------------------------- */
1177
    /* LAP thread will run on  0th resolution instance context */
1178
238
    {
1179
238
        s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
1180
238
        s_memtab.i4_mem_size = sizeof(lap_intface_t);
1181
1182
        /* initialise the interface strucure parameters */
1183
238
        ps_hle_ctxt->ihevce_mem_alloc(
1184
238
            ps_hle_ctxt->pv_mem_mgr_hdl, &ps_enc_ctxt_base->ps_stat_prms->s_sys_api, &s_memtab);
1185
238
        if(s_memtab.pv_base == NULL)
1186
0
        {
1187
0
            return (IV_FAIL);
1188
0
        }
1189
1190
238
        ps_lap_interface_ctxt = (lap_intface_t *)s_memtab.pv_base;
1191
1192
        /* populate the params */
1193
238
        ps_lap_interface_ctxt->pv_hle_ctxt = ps_hle_ctxt;
1194
238
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[0];
1195
238
        ps_lap_interface_ctxt->pv_lap_module_ctxt = ps_enc_ctxt->s_module_ctxt.pv_lap_ctxt;
1196
238
        ps_lap_interface_ctxt->i4_ctrl_in_que_id = IHEVCE_INPUT_ASYNCH_CTRL_Q;
1197
238
        ps_lap_interface_ctxt->i4_ctrl_out_que_id = IHEVCE_OUTPUT_STATUS_Q;
1198
238
        ps_lap_interface_ctxt->i4_ctrl_cmd_buf_size = ENC_COMMAND_BUFF_SIZE;
1199
238
        ps_lap_interface_ctxt->i4_ctrl_in_que_blocking_mode = BUFF_QUE_BLOCKING_MODE;
1200
238
        ps_lap_interface_ctxt->ps_sys_api = &ps_enc_ctxt_base->ps_stat_prms->s_sys_api;
1201
238
        ps_enc_ctxt_base->pv_lap_interface_ctxt = (void *)ps_lap_interface_ctxt;
1202
238
        ps_lap_interface_ctxt->ihevce_dyn_bitrate_cb = ihevce_dyn_bitrate;
1203
238
    }
1204
1205
    /* --------------------------------------------------------------------- */
1206
    /*          Create Entropy Coding threads                             */
1207
    /* --------------------------------------------------------------------- */
1208
    /*Create entropy thread for each encoder instance*/
1209
476
    for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++)
1210
238
    {
1211
238
        osal_thread_attr_t s_thread_attr = OSAL_DEFAULT_THREAD_ATTR;
1212
238
        WORD32 i4_num_entropy_threads;
1213
1214
        /* derive encoder ctxt from hle handle */
1215
238
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr];
1216
1217
238
        i4_num_entropy_threads =
1218
238
            ps_enc_ctxt_base->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[res_ctr]
1219
238
                .i4_num_bitrate_instances;
1220
1221
        /* initialise the interface strucure parameters */
1222
476
        for(ctr = 0; ctr < i4_num_entropy_threads; ctr++)
1223
238
        {
1224
238
            s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
1225
238
            s_memtab.i4_mem_size = sizeof(frm_proc_thrd_ctxt_t);
1226
1227
238
            ps_hle_ctxt->ihevce_mem_alloc(
1228
238
                ps_hle_ctxt->pv_mem_mgr_hdl, &ps_enc_ctxt_base->ps_stat_prms->s_sys_api, &s_memtab);
1229
238
            if(s_memtab.pv_base == NULL)
1230
0
            {
1231
0
                return (IV_FAIL);
1232
0
            }
1233
1234
238
            aps_entropy_thrd_ctxt[res_ctr][ctr] = (frm_proc_thrd_ctxt_t *)s_memtab.pv_base;
1235
1236
            /* initialise the interface strucure parameters */
1237
238
            aps_entropy_thrd_ctxt[res_ctr][ctr]->i4_thrd_id = ctr;
1238
238
            aps_entropy_thrd_ctxt[res_ctr][ctr]->ps_hle_ctxt = ps_hle_ctxt;
1239
238
            aps_entropy_thrd_ctxt[res_ctr][ctr]->pv_enc_ctxt = (void *)ps_enc_ctxt;
1240
1241
            /* Initialize application thread attributes */
1242
238
            s_thread_attr.exit_code = 0;
1243
238
            s_thread_attr.name = 0;
1244
238
            s_thread_attr.priority_map_flag = 1;
1245
238
            s_thread_attr.priority = OSAL_PRIORITY_DEFAULT;
1246
238
            s_thread_attr.stack_addr = 0;
1247
238
            s_thread_attr.stack_size = THREAD_STACK_SIZE;
1248
238
            s_thread_attr.thread_func = ihevce_ent_coding_thrd;
1249
238
            s_thread_attr.thread_param =
1250
238
                (void *)(aps_entropy_thrd_ctxt[res_ctr]
1251
238
                                              [ctr]);  //encioder and hle context are derived from this
1252
238
            s_thread_attr.core_affinity_mask = 0;
1253
238
            if(ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.i4_num_proc_groups > 1)
1254
0
            {
1255
                /* Run ENTROPY thread on last group if there are more than one processor group */
1256
0
                s_thread_attr.group_num =
1257
0
                    ps_hle_ctxt->ps_static_cfg_prms->s_multi_thrd_prms.i4_num_proc_groups - 1;
1258
0
            }
1259
238
            else
1260
238
            {
1261
238
                s_thread_attr.group_num = 0;
1262
238
            }
1263
1264
            /* Create entropy coding thread */
1265
238
            apv_entropy_thrd_hdls[res_ctr][ctr] =
1266
238
                osal_thread_create(ps_hle_ctxt->pv_osal_handle, &s_thread_attr);
1267
238
            if(NULL == apv_entropy_thrd_hdls[res_ctr][ctr])
1268
0
            {
1269
0
                return IV_FAIL;
1270
0
            }
1271
238
        }
1272
238
    }
1273
1274
    /* --------------------------------------------------------------------- */
1275
    /*     Create all Slave Encode Frame processing threads                  */
1276
    /* - -------------------------------------------------------------------- */
1277
476
    for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++)
1278
238
    {
1279
238
        WORD32 enc_ctr = 0;
1280
238
        WORD32 i4_loop_count;
1281
238
        WORD32 i4_curr_grp_num = 0;
1282
238
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr];
1283
1284
238
        i4_acc_proc_num = 0;
1285
        /* Calculate the start core number of enc threads for current resolution */
1286
238
        for(i4_loop_count = 0; i4_loop_count < res_ctr; i4_loop_count++)
1287
0
        {
1288
            /* Add number of cores taken by each resolution till the curr resolution */
1289
0
            enc_ctr += ps_hle_ctxt->ai4_num_core_per_res[i4_loop_count];
1290
0
        }
1291
238
        if(ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.i4_num_proc_groups > 1)
1292
0
        {
1293
            /* Select the group number for each res based on processors present in each group */
1294
0
            for(i4_loop_count = 0;
1295
0
                i4_loop_count <
1296
0
                ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.i4_num_proc_groups;
1297
0
                i4_loop_count++)
1298
0
            {
1299
0
                i4_acc_proc_num += ai4_proc_count[i4_loop_count];
1300
0
                if(enc_ctr >= i4_acc_proc_num)
1301
0
                {
1302
                    /* if enc_ctr is greater than proc count for first group,
1303
                    then increment group count.This group number will be starting grp num for
1304
                    that resolution */
1305
0
                    i4_curr_grp_num++;
1306
0
                }
1307
0
                else
1308
0
                    break;
1309
0
            }
1310
0
        }
1311
1312
476
        for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds; ctr++)
1313
238
        {
1314
238
            osal_thread_attr_t s_thread_attr = OSAL_DEFAULT_THREAD_ATTR;
1315
1316
238
            s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
1317
238
            s_memtab.i4_mem_size = sizeof(frm_proc_thrd_ctxt_t);
1318
1319
238
            ps_hle_ctxt->ihevce_mem_alloc(
1320
238
                ps_hle_ctxt->pv_mem_mgr_hdl, &ps_enc_ctxt_base->ps_stat_prms->s_sys_api, &s_memtab);
1321
238
            if(s_memtab.pv_base == NULL)
1322
0
            {
1323
0
                return (IV_FAIL);
1324
0
            }
1325
1326
238
            aps_enc_frm_proc_thrd_ctxt[res_ctr][ctr] = (frm_proc_thrd_ctxt_t *)s_memtab.pv_base;
1327
1328
            /* initialise the interface strucure parameters */
1329
238
            aps_enc_frm_proc_thrd_ctxt[res_ctr][ctr]->i4_thrd_id = ctr;
1330
1331
238
            aps_enc_frm_proc_thrd_ctxt[res_ctr][ctr]->ps_hle_ctxt = ps_hle_ctxt;
1332
1333
238
            ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr];
1334
1335
238
            aps_enc_frm_proc_thrd_ctxt[res_ctr][ctr]->pv_enc_ctxt = (void *)ps_enc_ctxt;
1336
1337
            /* Initialize application thread attributes */
1338
238
            s_thread_attr.exit_code = 0;
1339
238
            s_thread_attr.name = 0;
1340
238
            s_thread_attr.priority_map_flag = 1;
1341
238
            s_thread_attr.priority = OSAL_PRIORITY_DEFAULT;
1342
238
            s_thread_attr.stack_addr = 0;
1343
238
            s_thread_attr.stack_size = THREAD_STACK_SIZE;
1344
238
            s_thread_attr.thread_func = ihevce_enc_frm_proc_slave_thrd;
1345
238
            s_thread_attr.thread_param = (void *)(aps_enc_frm_proc_thrd_ctxt[res_ctr][ctr]);
1346
238
            s_thread_attr.group_num = i4_curr_grp_num;
1347
238
            if(1 == ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.i4_use_thrd_affinity)
1348
0
            {
1349
0
                ihevce_static_multi_thread_params_t *ps_multi_thrd_prms =
1350
0
                    &ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms;
1351
1352
0
                s_thread_attr.core_affinity_mask = ps_multi_thrd_prms->au8_core_aff_mask[enc_ctr];
1353
0
                if((enc_ctr >= i4_acc_proc_num) &&
1354
0
                   (ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.i4_num_proc_groups > 1))
1355
0
                {
1356
                    /*** When the cores in the Group0 is exhausted start enc threads in the next Processor Group ***/
1357
0
                    s_thread_attr.group_num++;
1358
0
                    i4_curr_grp_num++;
1359
                    /* This takes care of the condition that differnt proc groups can have diff number of cores */
1360
0
                    i4_acc_proc_num += ai4_proc_count[i4_curr_grp_num];
1361
0
                }
1362
0
            }
1363
238
            else
1364
238
            {
1365
238
                s_thread_attr.core_affinity_mask = 0;
1366
238
                if((enc_ctr >= i4_acc_proc_num) &&
1367
238
                   (ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.i4_num_proc_groups > 1))
1368
0
                {
1369
                    /*** When the cores in the Group0 is exhausted start enc threads in the next Processor Group ***/
1370
0
                    s_thread_attr.group_num++;
1371
0
                    i4_curr_grp_num++;
1372
                    /* This takes care of the condition that differnt proc groups can have diff number of cores */
1373
0
                    i4_acc_proc_num += ai4_proc_count[i4_curr_grp_num];
1374
0
                }
1375
238
            }
1376
1377
            /* Create frame processing thread */
1378
238
            apv_enc_frm_proc_hdls[res_ctr][ctr] =
1379
238
                osal_thread_create(ps_hle_ctxt->pv_osal_handle, &s_thread_attr);
1380
238
            if(NULL == apv_enc_frm_proc_hdls[res_ctr][ctr])
1381
0
            {
1382
0
                return IV_FAIL;
1383
0
            }
1384
238
            enc_ctr++;
1385
238
        }
1386
238
    }
1387
1388
    /* --------------------------------------------------------------------- */
1389
    /*     Create all Pre - Encode Frame processing threads                  */
1390
    /* --------------------------------------------------------------------- */
1391
476
    for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++)
1392
238
    {
1393
238
        WORD32 pre_enc_ctr = 0;
1394
238
        WORD32 i4_loop_count;
1395
238
        WORD32 i4_curr_grp_num = 0;
1396
238
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr];
1397
1398
238
        i4_acc_proc_num = 0;
1399
1400
238
        for(i4_loop_count = 0; i4_loop_count < res_ctr; i4_loop_count++)
1401
0
            pre_enc_ctr += ps_hle_ctxt->ai4_num_core_per_res[i4_loop_count];
1402
238
        if(ps_enc_ctxt->s_multi_thrd.i4_all_thrds_active_flag)
1403
238
        {
1404
            /* If its sequential mode of operation enc and pre-enc threads to be given same core affinity mask */
1405
238
            pre_enc_ctr -= ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds;
1406
238
        }
1407
1408
238
        if(ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.i4_num_proc_groups > 1)
1409
0
        {
1410
            /* Select the group number for each res based on processors present in each group */
1411
0
            for(i4_loop_count = 0;
1412
0
                i4_loop_count <
1413
0
                ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.i4_num_proc_groups;
1414
0
                i4_loop_count++)
1415
0
            {
1416
0
                i4_acc_proc_num += ai4_proc_count[i4_loop_count];
1417
0
                if((pre_enc_ctr + ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds) >=
1418
0
                   i4_acc_proc_num)
1419
0
                {
1420
                    /* if pre_enc_ctr is greater than proc count for first group,
1421
                    then increment group count.This group number will be starting grp num for
1422
                    that resolution */
1423
0
                    i4_curr_grp_num++;
1424
0
                }
1425
0
                else
1426
0
                    break;
1427
0
            }
1428
0
        }
1429
1430
476
        for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds; ctr++)
1431
238
        {
1432
238
            osal_thread_attr_t s_thread_attr = OSAL_DEFAULT_THREAD_ATTR;
1433
1434
238
            s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
1435
238
            s_memtab.i4_mem_size = sizeof(frm_proc_thrd_ctxt_t);
1436
1437
238
            ps_hle_ctxt->ihevce_mem_alloc(
1438
238
                ps_hle_ctxt->pv_mem_mgr_hdl, &ps_enc_ctxt_base->ps_stat_prms->s_sys_api, &s_memtab);
1439
238
            if(s_memtab.pv_base == NULL)
1440
0
            {
1441
0
                return (IV_FAIL);
1442
0
            }
1443
1444
238
            aps_pre_enc_frm_proc_thrd_ctxt[res_ctr][ctr] = (frm_proc_thrd_ctxt_t *)s_memtab.pv_base;
1445
1446
            /* initialise the interface strucure parameters */
1447
238
            aps_pre_enc_frm_proc_thrd_ctxt[res_ctr][ctr]->i4_thrd_id = ctr;
1448
1449
238
            aps_pre_enc_frm_proc_thrd_ctxt[res_ctr][ctr]->ps_hle_ctxt = ps_hle_ctxt;
1450
238
            ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr];
1451
238
            aps_pre_enc_frm_proc_thrd_ctxt[res_ctr][ctr]->pv_enc_ctxt = (void *)ps_enc_ctxt;
1452
1453
            /* Initialize application thread attributes */
1454
238
            s_thread_attr.exit_code = 0;
1455
238
            s_thread_attr.name = 0;
1456
238
            s_thread_attr.priority_map_flag = 1;
1457
238
            s_thread_attr.priority = OSAL_PRIORITY_DEFAULT;
1458
238
            s_thread_attr.stack_addr = 0;
1459
238
            s_thread_attr.stack_size = THREAD_STACK_SIZE;
1460
238
            s_thread_attr.thread_func = ihevce_pre_enc_process_frame_thrd;
1461
238
            s_thread_attr.thread_param = (void *)(aps_pre_enc_frm_proc_thrd_ctxt[res_ctr][ctr]);
1462
238
            s_thread_attr.group_num = i4_curr_grp_num;
1463
1464
238
            if(1 == ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.i4_use_thrd_affinity)
1465
0
            {
1466
0
                ihevce_static_multi_thread_params_t *ps_multi_thrd_prms =
1467
0
                    &ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms;
1468
1469
0
                s_thread_attr.core_affinity_mask =
1470
0
                    ps_multi_thrd_prms->au8_core_aff_mask
1471
0
                        [pre_enc_ctr + ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds];
1472
0
                if(((pre_enc_ctr + ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds) >=
1473
0
                    i4_acc_proc_num) &&
1474
0
                   (ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.i4_num_proc_groups > 1))
1475
0
                {
1476
                    /*** When the cores in the Group0 is exhausted start enc threads in the next Processor Group ***/
1477
0
                    s_thread_attr.group_num++;
1478
0
                    i4_curr_grp_num++;
1479
                    /* This takes care of the condition that differnt proc groups can have diff number of cores */
1480
0
                    i4_acc_proc_num += ai4_proc_count[i4_curr_grp_num];
1481
0
                }
1482
0
            }
1483
238
            else
1484
238
            {
1485
238
                s_thread_attr.core_affinity_mask = 0;
1486
1487
238
                if(((pre_enc_ctr + ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds) >=
1488
238
                    i4_acc_proc_num) &&
1489
238
                   (ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.i4_num_proc_groups > 1))
1490
0
                {
1491
                    /*** When the cores in the Group0 is exhausted start enc threads in the next Processor Group ***/
1492
0
                    s_thread_attr.group_num++;
1493
0
                    i4_curr_grp_num++;
1494
                    /* This takes care of the condition that differnt proc groups can have diff number of cores */
1495
0
                    i4_acc_proc_num += ai4_proc_count[i4_curr_grp_num];
1496
0
                }
1497
238
            }
1498
1499
            /* Create frame processing thread */
1500
238
            apv_pre_enc_frm_proc_hdls[res_ctr][ctr] =
1501
238
                osal_thread_create(ps_hle_ctxt->pv_osal_handle, &s_thread_attr);
1502
238
            if(NULL == apv_pre_enc_frm_proc_hdls[res_ctr][ctr])
1503
0
            {
1504
0
                return IV_FAIL;
1505
0
            }
1506
238
            pre_enc_ctr++;
1507
238
        }
1508
238
    }
1509
1510
    /* Set the threads init done Flag */
1511
238
    ps_hle_ctxt->i4_hle_init_done = 1;
1512
1513
    /* --------------------------------------------------------------------- */
1514
    /*            Wait and destroy Processing threads                        */
1515
    /* --------------------------------------------------------------------- */
1516
1517
    /* --------------------------------------------------------------------- */
1518
    /*           Frame process Pre - Encode threads destroy                  */
1519
    /* --------------------------------------------------------------------- */
1520
476
    for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++)
1521
238
    {
1522
238
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr];
1523
1524
476
        for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds; ctr++)
1525
238
        {
1526
            /* Wait for thread to complete */
1527
238
            osal_thread_wait(apv_pre_enc_frm_proc_hdls[res_ctr][ctr]);
1528
1529
            /* Destroy thread */
1530
238
            osal_thread_destroy(apv_pre_enc_frm_proc_hdls[res_ctr][ctr]);
1531
1532
238
            s_memtab.i4_mem_size = sizeof(frm_proc_thrd_ctxt_t);
1533
238
            s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
1534
238
            s_memtab.pv_base = (void *)aps_pre_enc_frm_proc_thrd_ctxt[res_ctr][ctr];
1535
1536
            /* free the ctxt memory */
1537
238
            ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab);
1538
238
        }
1539
238
    }
1540
1541
    /* --------------------------------------------------------------------- */
1542
    /*           Frame process Encode slave threads destroy                  */
1543
    /* --------------------------------------------------------------------- */
1544
476
    for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++)
1545
238
    {
1546
238
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr];
1547
1548
476
        for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds; ctr++)
1549
238
        {
1550
            /* Wait for thread to complete */
1551
238
            osal_thread_wait(apv_enc_frm_proc_hdls[res_ctr][ctr]);
1552
1553
            /* Destroy thread */
1554
238
            osal_thread_destroy(apv_enc_frm_proc_hdls[res_ctr][ctr]);
1555
1556
238
            s_memtab.i4_mem_size = sizeof(frm_proc_thrd_ctxt_t);
1557
238
            s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
1558
238
            s_memtab.pv_base = (void *)aps_enc_frm_proc_thrd_ctxt[res_ctr][ctr];
1559
1560
            /* free the ctxt memory */
1561
238
            ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab);
1562
238
        }
1563
238
    }
1564
1565
    /* --------------------------------------------------------------------- */
1566
    /*           Entropy threads destroy                                     */
1567
    /* --------------------------------------------------------------------- */
1568
476
    for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++)
1569
238
    {
1570
238
        WORD32 i4_num_bitrates =
1571
238
            ps_enc_ctxt_base->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[res_ctr]
1572
238
                .i4_num_bitrate_instances;
1573
1574
476
        for(ctr = 0; ctr < i4_num_bitrates; ctr++)
1575
238
        {
1576
            /* Wait for Entropy Coding thread to complete */
1577
238
            osal_thread_wait(apv_entropy_thrd_hdls[res_ctr][ctr]);
1578
1579
            /* Destroy Entropy Coding thread */
1580
238
            osal_thread_destroy(apv_entropy_thrd_hdls[res_ctr][ctr]);
1581
1582
            //semaphore will come here
1583
1584
238
            s_memtab.i4_mem_size = sizeof(frm_proc_thrd_ctxt_t);
1585
238
            s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
1586
238
            s_memtab.pv_base = (void *)aps_entropy_thrd_ctxt[res_ctr][ctr];
1587
1588
            /* free the ctxt memory */
1589
238
            ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab);
1590
238
        }
1591
238
    }
1592
1593
238
    s_memtab.i4_mem_size = sizeof(lap_intface_t);
1594
238
    s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
1595
238
    s_memtab.pv_base = (void *)ps_lap_interface_ctxt;
1596
238
    ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab);
1597
    /* profile stop */
1598
238
    PROFILE_STOP(&ps_hle_ctxt->profile_hle, NULL);
1599
238
    return (0);
1600
238
}
1601
1602
/*!
1603
******************************************************************************
1604
* \if Function name : ihevce_q_get_free_inp_data_buff \endif
1605
*
1606
* \brief
1607
*    Gets a free buffer from the que requested
1608
*
1609
* \param[in] high level encoder context pointer
1610
* \param[in] pointer to return the buffer id
1611
* \param[in] blocking mode / non blocking mode
1612
*
1613
* \return
1614
*    None
1615
*
1616
* \author
1617
*  Ittiam
1618
*
1619
*****************************************************************************
1620
*/
1621
void *ihevce_q_get_free_inp_data_buff(
1622
    ihevce_hle_ctxt_t *ps_hle_ctxt, WORD32 *pi4_buff_id, WORD32 i4_blocking_mode)
1623
3.96k
{
1624
3.96k
    void *pv_ptr;
1625
3.96k
    enc_ctxt_t *ps_enc_ctxt;
1626
3.96k
    WORD32 i4_resolution_id = 0;
1627
1628
3.96k
    ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[i4_resolution_id];
1629
3.96k
    if(ps_enc_ctxt->i4_frame_limit_reached == 1)
1630
0
    {
1631
0
        return (NULL);
1632
0
    }
1633
    /*Input buffer is same for all enc handles*/
1634
3.96k
    pv_ptr = ihevce_q_get_free_buff(
1635
3.96k
        ps_hle_ctxt->apv_enc_hdl[0], IHEVCE_INPUT_DATA_CTRL_Q, pi4_buff_id, i4_blocking_mode);
1636
1637
3.96k
    return (pv_ptr);
1638
3.96k
}
1639
1640
/*!
1641
******************************************************************************
1642
* \if Function name : ihevce_q_get_free_inp_ctrl_buff \endif
1643
*
1644
* \brief
1645
*    Gets a free buffer from the que requested
1646
*
1647
* \param[in] high level encoder context pointer
1648
* \param[in] pointer to return the buffer id
1649
* \param[in] blocking mode / non blocking mode
1650
*
1651
* \return
1652
*    None
1653
*
1654
* \author
1655
*  Ittiam
1656
*
1657
*****************************************************************************
1658
*/
1659
void *ihevce_q_get_free_inp_ctrl_buff(
1660
    ihevce_hle_ctxt_t *ps_hle_ctxt, WORD32 *pi4_buff_id, WORD32 i4_blocking_mode)
1661
205
{
1662
205
    void *pv_ptr;
1663
1664
    /*Input buffer is same for all enc handles*/
1665
205
    pv_ptr = ihevce_q_get_free_buff(
1666
205
        ps_hle_ctxt->apv_enc_hdl[0], IHEVCE_INPUT_ASYNCH_CTRL_Q, pi4_buff_id, i4_blocking_mode);
1667
1668
205
    return (pv_ptr);
1669
205
}
1670
1671
/*!
1672
******************************************************************************
1673
* \if Function name : ihevce_q_get_free_out_strm_buff \endif
1674
*
1675
* \brief
1676
*    Gets a free buffer from the que requested
1677
*
1678
* \param[in] high level encoder context pointer
1679
* \param[in] pointer to return the buffer id
1680
* \param[in] blocking mode / non blocking mode
1681
*
1682
* \return
1683
*    None
1684
*
1685
* \author
1686
*  Ittiam
1687
*
1688
*****************************************************************************
1689
*/
1690
void *ihevce_q_get_free_out_strm_buff(
1691
    ihevce_hle_ctxt_t *ps_hle_ctxt,
1692
    WORD32 *pi4_buff_id,
1693
    WORD32 i4_blocking_mode,
1694
    WORD32 i4_bitrate_instance,
1695
    WORD32 i4_res_instance)
1696
4.20k
{
1697
4.20k
    void *pv_ptr;
1698
1699
4.20k
    pv_ptr = ihevce_q_get_free_buff(
1700
4.20k
        ps_hle_ctxt->apv_enc_hdl[i4_res_instance],
1701
4.20k
        (IHEVCE_OUTPUT_DATA_Q + i4_bitrate_instance),
1702
4.20k
        pi4_buff_id,
1703
4.20k
        i4_blocking_mode);
1704
4.20k
    return (pv_ptr);
1705
4.20k
}
1706
1707
/*!
1708
******************************************************************************
1709
* \if Function name : ihevce_q_get_free_out_recon_buff \endif
1710
*
1711
* \brief
1712
*    Gets a free buffer from the que requested
1713
*
1714
* \param[in] high level encoder context pointer
1715
* \param[in] pointer to return the buffer id
1716
* \param[in] blocking mode / non blocking mode
1717
*
1718
* \return
1719
*    None
1720
*
1721
* \author
1722
*  Ittiam
1723
*
1724
*****************************************************************************
1725
*/
1726
void *ihevce_q_get_free_out_recon_buff(
1727
    ihevce_hle_ctxt_t *ps_hle_ctxt,
1728
    WORD32 *pi4_buff_id,
1729
    WORD32 i4_blocking_mode,
1730
    WORD32 i4_bitrate_instance,
1731
    WORD32 i4_res_instance)
1732
0
{
1733
0
    void *pv_ptr;
1734
1735
0
    pv_ptr = ihevce_q_get_free_buff(
1736
0
        ps_hle_ctxt->apv_enc_hdl[i4_res_instance],
1737
0
        (IHEVCE_RECON_DATA_Q + i4_bitrate_instance),
1738
0
        pi4_buff_id,
1739
0
        i4_blocking_mode);
1740
0
    return (pv_ptr);
1741
0
}
1742
1743
/*!
1744
******************************************************************************
1745
* \if Function name : ihevce_q_set_inp_data_buff_prod \endif
1746
*
1747
* \brief
1748
*    Sets the input data buffer as produced in the que requested
1749
*
1750
* \param[in] high level encoder context pointer
1751
* \param[in] buffer id which needs to be set as produced
1752
*
1753
* \return
1754
*    None
1755
*
1756
* \author
1757
*  Ittiam
1758
*
1759
*****************************************************************************
1760
*/
1761
IV_API_CALL_STATUS_T
1762
    ihevce_q_set_inp_data_buff_prod(ihevce_hle_ctxt_t *ps_hle_ctxt, WORD32 i4_buff_id)
1763
3.96k
{
1764
3.96k
    IV_API_CALL_STATUS_T ret_status;
1765
1766
3.96k
    ret_status =
1767
3.96k
        ihevce_q_set_buff_prod(ps_hle_ctxt->apv_enc_hdl[0], IHEVCE_INPUT_DATA_CTRL_Q, i4_buff_id);
1768
1769
3.96k
    return (ret_status);
1770
3.96k
}
1771
1772
/*!
1773
******************************************************************************
1774
* \if Function name : ihevce_q_set_inp_ctrl_buff_prod \endif
1775
*
1776
* \brief
1777
*    Sets the input data buffer as produced in the que requested
1778
*
1779
* \param[in] high level encoder context pointer
1780
* \param[in] buffer id which needs to be set as produced
1781
*
1782
* \return
1783
*    None
1784
*
1785
* \author
1786
*  Ittiam
1787
*
1788
*****************************************************************************
1789
*/
1790
IV_API_CALL_STATUS_T
1791
    ihevce_q_set_inp_ctrl_buff_prod(ihevce_hle_ctxt_t *ps_hle_ctxt, WORD32 i4_buff_id)
1792
1793
205
{
1794
205
    IV_API_CALL_STATUS_T ret_status;
1795
1796
205
    ret_status =
1797
205
        ihevce_q_set_buff_prod(ps_hle_ctxt->apv_enc_hdl[0], IHEVCE_INPUT_ASYNCH_CTRL_Q, i4_buff_id);
1798
1799
205
    return (ret_status);
1800
205
}
1801
1802
/*!
1803
******************************************************************************
1804
* \if Function name : ihevce_q_set_out_strm_buff_prod \endif
1805
*
1806
* \brief
1807
*    Sets the Output stream buffer as produced in the que requested
1808
*
1809
* \param[in] high level encoder context pointer
1810
* \param[in] buffer id which needs to be set as produced
1811
*
1812
* \return
1813
*    None
1814
*
1815
* \author
1816
*  Ittiam
1817
*
1818
*****************************************************************************
1819
*/
1820
IV_API_CALL_STATUS_T ihevce_q_set_out_strm_buff_prod(
1821
    ihevce_hle_ctxt_t *ps_hle_ctxt,
1822
    WORD32 i4_buff_id,
1823
    WORD32 i4_bitrate_instance_id,
1824
    WORD32 i4_resolution_id)
1825
4.20k
{
1826
4.20k
    IV_API_CALL_STATUS_T ret_status;
1827
1828
4.20k
    ret_status = ihevce_q_set_buff_prod(
1829
4.20k
        ps_hle_ctxt->apv_enc_hdl[i4_resolution_id],
1830
4.20k
        (IHEVCE_OUTPUT_DATA_Q + i4_bitrate_instance_id),
1831
4.20k
        i4_buff_id);
1832
1833
4.20k
    return (ret_status);
1834
4.20k
}
1835
1836
/*!
1837
******************************************************************************
1838
* \if Function name : ihevce_q_set_out_recon_buff_prod \endif
1839
*
1840
* \brief
1841
*    Sets the Output recon buffer as produced in the que requested
1842
*
1843
* \param[in] high level encoder context pointer
1844
* \param[in] buffer id which needs to be set as produced
1845
*
1846
* \return
1847
*    None
1848
*
1849
* \author
1850
*  Ittiam
1851
*
1852
*****************************************************************************
1853
*/
1854
IV_API_CALL_STATUS_T ihevce_q_set_out_recon_buff_prod(
1855
    ihevce_hle_ctxt_t *ps_hle_ctxt,
1856
    WORD32 i4_buff_id,
1857
    WORD32 i4_bitrate_instance_id,
1858
    WORD32 i4_resolution_id)
1859
0
{
1860
0
    IV_API_CALL_STATUS_T ret_status;
1861
1862
0
    ret_status = ihevce_q_set_buff_prod(
1863
0
        ps_hle_ctxt->apv_enc_hdl[i4_resolution_id],
1864
0
        (IHEVCE_RECON_DATA_Q + i4_bitrate_instance_id),
1865
0
        i4_buff_id);
1866
1867
0
    return (ret_status);
1868
0
}
1869
1870
//recon_dump
1871
/*!
1872
******************************************************************************
1873
* \if Function name : ihevce_q_get_filled_recon_buff \endif
1874
*
1875
* \brief
1876
*    Gets a next filled recon buffer from the que requested
1877
*
1878
* \param[in] high level encoder context pointer
1879
* \param[in] pointer to return the buffer id
1880
* \param[in] blocking mode / non blocking mode
1881
*
1882
* \return
1883
*    None
1884
*
1885
* \author
1886
*  Ittiam
1887
*
1888
*****************************************************************************
1889
*/
1890
void *ihevce_q_get_filled_recon_buff(
1891
    ihevce_hle_ctxt_t *ps_hle_ctxt,
1892
    WORD32 *pi4_buff_id,
1893
    WORD32 i4_blocking_mode,
1894
    WORD32 i4_bitrate_instance_id,
1895
    WORD32 i4_resolution_id)
1896
0
{
1897
0
    void *pv_ptr;
1898
1899
0
    pv_ptr = ihevce_q_get_filled_buff(
1900
0
        ps_hle_ctxt->apv_enc_hdl[i4_resolution_id],
1901
0
        IHEVCE_RECON_DATA_Q + i4_bitrate_instance_id,
1902
0
        pi4_buff_id,
1903
0
        i4_blocking_mode);
1904
1905
0
    return (pv_ptr);
1906
0
}
1907
1908
/*!
1909
******************************************************************************
1910
* \if Function name : ihevce_q_get_filled_ctrl_sts_buff \endif
1911
*
1912
* \brief
1913
*    Gets a next filled control status buffer from the que requested
1914
*
1915
* \param[in] high level encoder context pointer
1916
* \param[in] pointer to return the buffer id
1917
* \param[in] blocking mode / non blocking mode
1918
*
1919
* \return
1920
*    None
1921
*
1922
* \author
1923
*  Ittiam
1924
*
1925
*****************************************************************************
1926
*/
1927
void *ihevce_q_get_filled_ctrl_sts_buff(
1928
    ihevce_hle_ctxt_t *ps_hle_ctxt, WORD32 *pi4_buff_id, WORD32 i4_blocking_mode)
1929
0
{
1930
0
    void *pv_ptr;
1931
0
    pv_ptr = ihevce_q_get_filled_buff(
1932
0
        ps_hle_ctxt->apv_enc_hdl[0], IHEVCE_OUTPUT_STATUS_Q, pi4_buff_id, i4_blocking_mode);
1933
1934
0
    return (pv_ptr);
1935
0
}
1936
1937
//recon_dump
1938
/*!
1939
******************************************************************************
1940
* \if Function name : ihevce_q_rel_recon_buf \endif
1941
*
1942
* \brief
1943
*    Frees the recon buffer in the recon buffer que
1944
*
1945
* \param[in] high level encoder context pointer
1946
* \param[in] buffer id which needs to be freed
1947
*
1948
* \return
1949
*    None
1950
*
1951
* \author
1952
*  Ittiam
1953
*
1954
*****************************************************************************
1955
*/
1956
IV_API_CALL_STATUS_T ihevce_q_rel_recon_buf(
1957
    ihevce_hle_ctxt_t *ps_hle_ctxt,
1958
    WORD32 i4_buff_id,
1959
    WORD32 i4_bitrate_instance_id,
1960
    WORD32 i4_resolution_id)
1961
0
{
1962
0
    IV_API_CALL_STATUS_T ret_status;
1963
1964
0
    ret_status = ihevce_q_rel_buf(
1965
0
        ps_hle_ctxt->apv_enc_hdl[i4_resolution_id],
1966
0
        IHEVCE_RECON_DATA_Q + i4_bitrate_instance_id,
1967
0
        i4_buff_id);
1968
1969
0
    return (ret_status);
1970
0
}
1971
1972
/*!
1973
******************************************************************************
1974
* \if Function name : ihevce_q_rel_ctrl_sts_buf \endif
1975
*
1976
* \brief
1977
*    Frees the output control sttus buffer in buffer que
1978
*
1979
* \param[in] high level encoder context pointer
1980
* \param[in] buffer id which needs to be freed
1981
*
1982
* \return
1983
*    None
1984
*
1985
* \author
1986
*  Ittiam
1987
*
1988
*****************************************************************************
1989
*/
1990
IV_API_CALL_STATUS_T ihevce_q_rel_ctrl_sts_buf(ihevce_hle_ctxt_t *ps_hle_ctxt, WORD32 i4_buff_id)
1991
0
{
1992
0
    IV_API_CALL_STATUS_T ret_status;
1993
1994
0
    ret_status = ihevce_q_rel_buf(ps_hle_ctxt->apv_enc_hdl[0], IHEVCE_OUTPUT_STATUS_Q, i4_buff_id);
1995
1996
0
    return (ret_status);
1997
0
}
1998
1999
/*!
2000
******************************************************************************
2001
* \if Function name : ihevce_hle_interface_delete \endif
2002
*
2003
* \brief
2004
*    High leve encoder delete interface
2005
*
2006
* \param[in] high level encoder interface context pointer
2007
*
2008
* \return
2009
*    None
2010
*
2011
* \author
2012
*  Ittiam
2013
*
2014
*****************************************************************************
2015
*/
2016
IV_API_CALL_STATUS_T ihevce_hle_interface_delete(ihevce_hle_ctxt_t *ps_hle_ctxt)
2017
238
{
2018
    /* local varaibles */
2019
238
    enc_ctxt_t *ps_enc_ctxt;
2020
238
    iv_mem_rec_t s_memtab;
2021
238
    WORD32 ctr = 0, i, res_ctr, i4_num_resolutions;
2022
238
    WORD32 ai4_num_bitrate_instances[IHEVCE_MAX_NUM_RESOLUTIONS] = { 1 };
2023
2024
238
    i4_num_resolutions = ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_num_res_layers;
2025
476
    for(ctr = 0; ctr < i4_num_resolutions; ctr++)
2026
238
    {
2027
238
        ai4_num_bitrate_instances[ctr] =
2028
238
            ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[ctr]
2029
238
                .i4_num_bitrate_instances;
2030
238
    }
2031
2032
476
    for(res_ctr = 0; res_ctr < i4_num_resolutions && ps_hle_ctxt->apv_enc_hdl[res_ctr]; res_ctr++)
2033
238
    {
2034
238
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr];
2035
2036
238
        if(res_ctr == 0)
2037
238
        {
2038
238
            osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle);
2039
238
            osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_data_sem_handle);
2040
238
            osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_ctrl_sem_handle);
2041
238
            if(1 == ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_mres_single_out)
2042
0
            {
2043
0
                osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_ent_common_mres_sem_hdl);
2044
0
                osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_common_mres_sem_hdl);
2045
0
            }
2046
238
        }
2047
2048
238
        osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_inp_data_sem_hdl);
2049
238
        osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_preenc_inp_data_sem_hdl);
2050
2051
238
        osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle);
2052
238
        osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle);
2053
2054
238
        osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_ctrl_sem_handle);
2055
2056
476
        for(i = 0; i < ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[res_ctr]
2057
476
                           .i4_num_bitrate_instances;
2058
238
            i++)
2059
238
        {
2060
238
            osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.apv_ent_cod_sem_handle[i]);
2061
238
            osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_strm_sem_handle[i]);
2062
238
            osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_recon_sem_handle[i]);
2063
238
        }
2064
2065
        /* destroy the mutex  allocated for job queue usage encode group */
2066
238
        osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_enc_grp_me);
2067
2068
        /* destroy the mutex  allocated for job queue usage encode group */
2069
238
        osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_enc_grp_enc_loop);
2070
2071
        /* destroy the mutexes allocated for enc thread group */
2072
476
        for(i = 0; i < MAX_NUM_ME_PARALLEL; i++)
2073
238
        {
2074
238
            osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.apv_mutex_handle[i]);
2075
2076
238
            osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.apv_mutex_handle_me_end[i]);
2077
238
        }
2078
2079
476
        for(i = 0; i < MAX_NUM_ENC_LOOP_PARALLEL; i++)
2080
238
        {
2081
238
            osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.apv_mutex_handle_frame_init[i]);
2082
2083
238
            osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.apv_post_enc_mutex_handle[i]);
2084
238
        }
2085
2086
        /* destroy the mutex  allocated for job queue, init and de-init
2087
        usage pre enocde group */
2088
238
        osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_decomp);
2089
238
        osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_hme);
2090
238
        osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_l0ipe);
2091
238
        osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_init);
2092
238
        osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_decomp_deinit);
2093
238
        osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_hme_init);
2094
238
        osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_hme_deinit);
2095
238
        osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_l0_ipe_init);
2096
238
        osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_deinit);
2097
2098
        /* destroy the EncLoop Module */
2099
        /* Note : Only Destroys the resources allocated in the module like */
2100
        /* semaphore,etc. Memory free is done separately using memtabs     */
2101
238
        ihevce_enc_loop_delete(ps_enc_ctxt->s_module_ctxt.pv_enc_loop_ctxt);
2102
2103
        /* destroy the Coarse ME Module */
2104
        /* Note : Only Destroys the resources allocated in the module like */
2105
        /* semaphore,etc. Memory free is done separately using memtabs     */
2106
238
        ihevce_coarse_me_delete(
2107
238
            ps_enc_ctxt->s_module_ctxt.pv_coarse_me_ctxt,
2108
238
            ps_hle_ctxt->ps_static_cfg_prms,
2109
238
            ps_enc_ctxt->i4_resolution_id);
2110
        /* destroy semaphores for all the threads in pre-enc and enc */
2111
476
        for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds; ctr++)
2112
238
        {
2113
238
            osal_sem_destroy(ps_enc_ctxt->s_multi_thrd.apv_enc_thrd_sem_handle[ctr]);
2114
238
        }
2115
2116
476
        for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds; ctr++)
2117
238
        {
2118
238
            osal_sem_destroy(ps_enc_ctxt->s_multi_thrd.apv_pre_enc_thrd_sem_handle[ctr]);
2119
238
        }
2120
2121
        /* destroy the ME-EncLoop Dep Mngr */
2122
        /* Note : Only Destroys the resources allocated in the module like */
2123
        /* semaphore,etc. Memory free is done separately using memtabs     */
2124
476
        for(ctr = 0; ctr < NUM_ME_ENC_BUFS; ctr++)
2125
238
        {
2126
238
            ihevce_dmgr_del(ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_encloop_dep_me[ctr]);
2127
238
        }
2128
        /* destroy the Prev. frame EncLoop Done Dep Mngr */
2129
        /* Note : Only Destroys the resources allocated in the module like */
2130
        /* semaphore,etc. Memory free is done separately using memtabs     */
2131
476
        for(i = 0; i < ps_enc_ctxt->s_multi_thrd.i4_num_enc_loop_frm_pllel; i++)
2132
238
        {
2133
238
            ihevce_dmgr_del(ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_prev_frame_done[i]);
2134
238
        }
2135
        /* destroy the Prev. frame EncLoop Done for re-encode Dep Mngr */
2136
238
        ihevce_dmgr_del(ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_enc_done_for_reenc);
2137
2138
        /* destroy the Prev. frame ME Done Dep Mngr */
2139
        /* Note : Only Destroys the resources allocated in the module like */
2140
        /* semaphore,etc. Memory free is done separately using memtabs     */
2141
476
        for(i = 0; i < ps_enc_ctxt->s_multi_thrd.i4_num_me_frm_pllel; i++)
2142
238
        {
2143
238
            ihevce_dmgr_del(ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_prev_frame_me_done[i]);
2144
238
        }
2145
2146
        /* destroy the Prev. frame PreEnc L1 Done Dep Mngr */
2147
        /* Note : Only Destroys the resources allocated in the module like */
2148
        /* semaphore,etc. Memory free is done separately using memtabs     */
2149
238
        ihevce_dmgr_del(ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_l1);
2150
2151
        /* destroy the Prev. frame PreEnc HME Done Dep Mngr */
2152
        /* Note : Only Destroys the resources allocated in the module like */
2153
        /* semaphore,etc. Memory free is done separately using memtabs     */
2154
238
        ihevce_dmgr_del(ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_coarse_me);
2155
2156
        /* destroy the Prev. frame PreEnc L0 Done Dep Mngr */
2157
        /* Note : Only Destroys the resources allocated in the module like */
2158
        /* semaphore,etc. Memory free is done separately using memtabs     */
2159
238
        ihevce_dmgr_del(ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_l0);
2160
2161
        /* destroy the ME-Prev Recon  Dep Mngr    */
2162
        /* Note : Only Destroys the resources allocated in the module like */
2163
        /* semaphore,etc. Memory free is done separately using memtabs     */
2164
1.42k
        for(ctr = 0; ctr < ps_enc_ctxt->ai4_num_buf_recon_q[0]; ctr++)
2165
1.19k
        {
2166
1.19k
            ihevce_dmgr_del(ps_enc_ctxt->pps_recon_buf_q[0][ctr]->pv_dep_mngr_recon);
2167
1.19k
        }
2168
2169
        /* destroy all the mutex created */
2170
238
        if(res_ctr == 0)
2171
238
        {
2172
238
            if(NULL != ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl)
2173
238
            {
2174
238
                osal_mutex_destroy(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);
2175
238
            }
2176
238
        }
2177
2178
238
        if(NULL != ps_enc_ctxt->pv_rc_mutex_lock_hdl)
2179
238
        {
2180
238
            osal_mutex_destroy(ps_enc_ctxt->pv_rc_mutex_lock_hdl);
2181
238
        }
2182
2183
238
        if(NULL != ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_mutex_lock_hdl)
2184
238
        {
2185
238
            osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_mutex_lock_hdl);
2186
238
        }
2187
2188
238
        if(NULL != ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_for_qp_update_mutex_lock_hdl)
2189
238
        {
2190
238
            osal_mutex_destroy(
2191
238
                ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_for_qp_update_mutex_lock_hdl);
2192
238
        }
2193
2194
        /* call the memrory free function */
2195
238
        ihevce_mem_manager_free(ps_enc_ctxt, ps_hle_ctxt);
2196
238
        if((1 == ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_mres_single_out) &&
2197
0
           (res_ctr == 0))
2198
0
        {
2199
0
            s_memtab.i4_mem_size = sizeof(WORD32) * IHEVCE_MAX_NUM_RESOLUTIONS;
2200
0
            s_memtab.i4_mem_alignment = 4;
2201
0
            s_memtab.i4_size = sizeof(iv_mem_rec_t);
2202
0
            s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
2203
0
            s_memtab.pv_base = ps_enc_ctxt->s_multi_thrd.pi4_active_res_id;
2204
            /* free active_res_id memory */
2205
0
            ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab);
2206
0
        }
2207
238
        if(res_ctr == (i4_num_resolutions - 1))
2208
238
        {
2209
238
            s_memtab.i4_mem_size = sizeof(ihevce_static_cfg_params_t);
2210
238
            s_memtab.i4_mem_alignment = 4;
2211
238
            s_memtab.i4_size = sizeof(iv_mem_rec_t);
2212
238
            s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
2213
238
            s_memtab.pv_base = ps_enc_ctxt->ps_stat_prms;
2214
2215
            /* free the encoder context pointer */
2216
238
            ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab);
2217
238
        }
2218
238
        s_memtab.i4_mem_size = sizeof(enc_ctxt_t);
2219
238
        s_memtab.i4_mem_alignment = 4;
2220
238
        s_memtab.i4_size = sizeof(iv_mem_rec_t);
2221
238
        s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM;
2222
238
        s_memtab.pv_base = ps_enc_ctxt;
2223
2224
        /* free the encoder context pointer */
2225
238
        ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab);
2226
2227
        /* reset the encoder handle to NULL */
2228
238
        ps_hle_ctxt->apv_enc_hdl[res_ctr] = NULL;
2229
238
    }
2230
    /* profile end */
2231
238
    PROFILE_END(&ps_hle_ctxt->profile_hle, "hle interface thread active time");
2232
476
    for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++)
2233
238
    {
2234
238
        WORD32 i4_br_id;
2235
2236
238
        PROFILE_END(&ps_hle_ctxt->profile_pre_enc_l1l2[res_ctr], "pre enc l1l2 process");
2237
238
        PROFILE_END(&ps_hle_ctxt->profile_pre_enc_l0ipe[res_ctr], "pre enc l0 ipe process");
2238
238
        PROFILE_END(&ps_hle_ctxt->profile_enc_me[res_ctr], "enc me process");
2239
476
        for(i4_br_id = 0; i4_br_id < ai4_num_bitrate_instances[res_ctr]; i4_br_id++)
2240
238
        {
2241
238
            PROFILE_END(&ps_hle_ctxt->profile_enc[res_ctr][i4_br_id], "enc loop process");
2242
238
            PROFILE_END(&ps_hle_ctxt->profile_entropy[res_ctr][i4_br_id], "entropy process");
2243
238
        }
2244
238
    }
2245
2246
    /* OSAL Delete */
2247
238
    ihevce_osal_delete((void *)ps_hle_ctxt);
2248
2249
238
    return (IV_SUCCESS);
2250
238
}