/src/libhevc/encoder/ihevce_hle_interface.c
Line | Count | Source (jump to first uncovered line) |
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 | 8.85k | { |
145 | 8.85k | ps_enc_ctxt->i4_end_flag = 0; |
146 | | |
147 | | /* set the queue related pointer and buffer to default value */ |
148 | 8.85k | ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl = NULL; |
149 | | |
150 | | /* Reset the i/o queues created status to 0 */ |
151 | 8.85k | ps_enc_ctxt->i4_io_queues_created = 0; |
152 | | |
153 | | /* reset the frame limit flag to 0 */ |
154 | 8.85k | ps_enc_ctxt->i4_frame_limit_reached = 0; |
155 | | |
156 | 8.85k | return; |
157 | 8.85k | } |
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 | 8.88k | { |
178 | | /* local variables */ |
179 | 8.88k | enc_ctxt_t *ps_enc_ctxt; |
180 | 8.88k | iv_mem_rec_t s_memtab; |
181 | 8.88k | ihevce_static_cfg_params_t *ps_enc_static_cfg_params; |
182 | 8.88k | WORD32 i4_num_resolutions = ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_num_res_layers; |
183 | 8.88k | WORD32 i4_look_ahead_frames_in_first_pass = -1; |
184 | 8.88k | WORD32 i4_total_cores = 0, ctr, i4_mres_flag = 0; |
185 | 8.88k | ihevce_sys_api_t *ps_sys_api = &ps_hle_ctxt->ps_static_cfg_prms->s_sys_api; |
186 | | |
187 | 8.88k | WORD32 status = 0; |
188 | 8.88k | WORD32 i; |
189 | 8.88k | WORD32 *pi4_active_res_id = NULL; |
190 | | |
191 | | /* OSAL Init */ |
192 | 8.88k | status = ihevce_osal_init((void *)ps_hle_ctxt); |
193 | | |
194 | 8.88k | if(status != 0) |
195 | 0 | return (IV_FAIL); |
196 | | |
197 | | /* --------------------------------------------------------------------- */ |
198 | | /* High Level Encoder Init */ |
199 | | /* --------------------------------------------------------------------- */ |
200 | | |
201 | 8.88k | if(i4_num_resolutions > 1) |
202 | 0 | i4_mres_flag = 1; |
203 | | /* set no error in the output */ |
204 | 8.88k | ps_hle_ctxt->i4_error_code = 0; |
205 | | |
206 | | /* Error checks on the static parameters passed */ |
207 | 8.88k | 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 | 8.88k | s_memtab.i4_size = sizeof(iv_mem_rec_t); |
212 | 8.88k | s_memtab.i4_mem_alignment = 4; |
213 | 8.88k | s_memtab.i4_mem_size = sizeof(ihevce_static_cfg_params_t); |
214 | 8.88k | s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM; |
215 | | |
216 | 8.88k | ps_hle_ctxt->ihevce_mem_alloc( |
217 | 8.88k | ps_hle_ctxt->pv_mem_mgr_hdl, &ps_hle_ctxt->ps_static_cfg_prms->s_sys_api, &s_memtab); |
218 | 8.88k | if(s_memtab.pv_base == NULL) |
219 | 0 | { |
220 | 0 | return (IV_FAIL); |
221 | 0 | } |
222 | 8.88k | ps_enc_static_cfg_params = (ihevce_static_cfg_params_t *)s_memtab.pv_base; |
223 | 8.88k | memcpy( |
224 | 8.88k | ps_enc_static_cfg_params, |
225 | 8.88k | ps_hle_ctxt->ps_static_cfg_prms, |
226 | 8.88k | (sizeof(ihevce_static_cfg_params_t))); |
227 | | |
228 | 8.88k | 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 | 8.88k | if((ps_enc_static_cfg_params->s_multi_thrd_prms.i4_memory_alloc_ctrl_flag > 2) || |
232 | 8.88k | (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 | 8.88k | if((i4_mres_flag == 1) && |
238 | 8.88k | (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 | 8.88k | if((ps_enc_static_cfg_params->s_tgt_lyr_prms.as_tgt_params[0].i4_quality_preset == |
246 | 8.88k | IHEVCE_QUALITY_P6) && |
247 | 8.88k | (ps_enc_static_cfg_params->s_config_prms.i4_cu_level_rc)) |
248 | 321 | { |
249 | 321 | ps_sys_api->ihevce_printf( |
250 | 321 | ps_sys_api->pv_cb_handle, |
251 | 321 | "\nIHEVCE WARNING: Disabling CU level QP modulation for P6 preset\n"); |
252 | 321 | ps_enc_static_cfg_params->s_config_prms.i4_cu_level_rc = 0; |
253 | 321 | } |
254 | 8.88k | if((ps_enc_static_cfg_params->s_tgt_lyr_prms.as_tgt_params[0].i4_quality_preset == |
255 | 8.88k | IHEVCE_QUALITY_P7) && |
256 | 8.88k | (ps_enc_static_cfg_params->s_config_prms.i4_cu_level_rc)) |
257 | 103 | { |
258 | 103 | ps_sys_api->ihevce_printf( |
259 | 103 | ps_sys_api->pv_cb_handle, |
260 | 103 | "\nIHEVCE WARNING: Disabling CU level QP modulation for P7 preset\n"); |
261 | 103 | ps_enc_static_cfg_params->s_config_prms.i4_cu_level_rc = 0; |
262 | 103 | } |
263 | | |
264 | 8.88k | if(0 != ps_hle_ctxt->i4_error_code) |
265 | 27 | { |
266 | 27 | ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab); |
267 | 27 | return (IV_FAIL); |
268 | 27 | } |
269 | 8.85k | ps_hle_ctxt->ai4_num_core_per_res[0] = i4_total_cores; |
270 | | |
271 | 8.85k | 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 | 17.7k | for(ctr = 0; ctr < i4_num_resolutions; ctr++) |
292 | 8.85k | { |
293 | 8.85k | WORD32 i4_br_id; |
294 | 8.85k | s_memtab.i4_size = sizeof(iv_mem_rec_t); |
295 | 8.85k | s_memtab.i4_mem_alignment = 4; |
296 | 8.85k | s_memtab.i4_mem_size = sizeof(enc_ctxt_t); |
297 | 8.85k | s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM; |
298 | | |
299 | 8.85k | ps_hle_ctxt->ihevce_mem_alloc( |
300 | 8.85k | ps_hle_ctxt->pv_mem_mgr_hdl, &ps_enc_static_cfg_params->s_sys_api, &s_memtab); |
301 | 8.85k | if(s_memtab.pv_base == NULL) |
302 | 0 | { |
303 | 0 | return (IV_FAIL); |
304 | 0 | } |
305 | | |
306 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)s_memtab.pv_base; |
307 | | |
308 | 8.85k | 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 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_all_thrds_active_flag = 1; |
312 | | |
313 | 8.85k | 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 | 8.85k | ps_enc_ctxt->i4_num_bitrates = |
321 | 8.85k | ps_enc_static_cfg_params->s_tgt_lyr_prms.as_tgt_params[ctr].i4_num_bitrate_instances; |
322 | 8.85k | 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 | 8.85k | else |
327 | 8.85k | { |
328 | 8.85k | ps_enc_ctxt->i4_blu_ray_spec = 0; |
329 | 8.85k | } |
330 | | |
331 | | /* if all threads are required to be active */ |
332 | 8.85k | if(1 == ps_enc_ctxt->s_multi_thrd.i4_all_thrds_active_flag) |
333 | 8.85k | { |
334 | | /* store the number of threads to be created as passed by app with HT flag */ |
335 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds = |
336 | 8.85k | ps_hle_ctxt->ai4_num_core_per_res[ctr]; |
337 | | |
338 | | /* pre enc threads are doubled if HT is ON */ |
339 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds = |
340 | 8.85k | ps_hle_ctxt->ai4_num_core_per_res[ctr]; |
341 | 8.85k | } |
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 | 8.85k | ps_enc_ctxt->i4_resolution_id = ctr; |
349 | | /* store hle ctxt in enc ctxt */ |
350 | 8.85k | ps_enc_ctxt->pv_hle_ctxt = (void *)ps_hle_ctxt; |
351 | 8.85k | ps_enc_ctxt->pv_rc_mutex_lock_hdl = NULL; |
352 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_mutex_lock_hdl = NULL; |
353 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_for_qp_update_mutex_lock_hdl = NULL; |
354 | 8.85k | ps_enc_ctxt->i4_look_ahead_frames_in_first_pass = i4_look_ahead_frames_in_first_pass; |
355 | | |
356 | 8.85k | ps_enc_ctxt->ai4_is_past_pic_complex[0] = 0; |
357 | 8.85k | ps_enc_ctxt->ai4_is_past_pic_complex[1] = 0; |
358 | 8.85k | ps_enc_ctxt->i4_is_I_reset_done = 1; |
359 | 8.85k | ps_enc_ctxt->i4_past_RC_reset_count = 0; |
360 | 8.85k | ps_enc_ctxt->i4_future_RC_reset = 0; |
361 | 8.85k | ps_enc_ctxt->i4_past_RC_scd_reset_count = 0; |
362 | 8.85k | ps_enc_ctxt->i4_future_RC_scd_reset = 0; |
363 | 8.85k | ps_enc_ctxt->i4_active_scene_num = -1; |
364 | 17.7k | for(i = 0; i < IHEVCE_MAX_NUM_BITRATES; i++) |
365 | 8.85k | { |
366 | 8.85k | ps_enc_ctxt->ai4_rc_query[i] = 0; |
367 | 8.85k | } |
368 | 8.85k | ps_enc_ctxt->i4_active_enc_frame_id = 0; |
369 | 8.85k | ps_enc_ctxt->u1_is_popcnt_available = 1; |
370 | | |
371 | 8.85k | #ifndef ARM |
372 | 8.85k | ps_enc_ctxt->e_arch_type = ARCH_X86_GENERIC; |
373 | 8.85k | 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 | 8.85k | { |
383 | 8.85k | ps_enc_static_cfg_params->e_arch_type = ps_enc_ctxt->e_arch_type; |
384 | | |
385 | 8.85k | ihevce_init_function_ptr(ps_enc_ctxt, ps_enc_ctxt->e_arch_type); |
386 | 8.85k | } |
387 | | |
388 | 8.85k | ihevce_mem_manager_init(ps_enc_ctxt, ps_hle_ctxt); |
389 | | |
390 | 8.85k | 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 | 8.85k | ps_enc_ctxt->pv_rc_mutex_lock_hdl = osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
397 | 8.85k | 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 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_mutex_lock_hdl = |
404 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
405 | 8.85k | 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 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_for_qp_update_mutex_lock_hdl = |
411 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
412 | 8.85k | 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 | 8.85k | ihevce_context_reset(ps_enc_ctxt); |
419 | | |
420 | | /* register the Encoder context in HLE interface ctxt */ |
421 | 8.85k | ps_hle_ctxt->apv_enc_hdl[ctr] = ps_enc_ctxt; |
422 | 8.85k | } |
423 | | /* init profile */ |
424 | 8.85k | PROFILE_INIT(&ps_hle_ctxt->profile_hle); |
425 | 17.7k | for(ctr = 0; ctr < i4_num_resolutions; ctr++) |
426 | 8.85k | { |
427 | 8.85k | WORD32 i4_br_id; |
428 | | |
429 | 8.85k | PROFILE_INIT(&ps_hle_ctxt->profile_enc_me[ctr]); |
430 | 8.85k | PROFILE_INIT(&ps_hle_ctxt->profile_pre_enc_l1l2[ctr]); |
431 | 8.85k | PROFILE_INIT(&ps_hle_ctxt->profile_pre_enc_l0ipe[ctr]); |
432 | 17.7k | for(i4_br_id = 0; i4_br_id < ps_enc_ctxt->i4_num_bitrates; i4_br_id++) |
433 | 8.85k | { |
434 | 8.85k | PROFILE_INIT(&ps_hle_ctxt->profile_enc[ctr][i4_br_id]); |
435 | 8.85k | PROFILE_INIT(&ps_hle_ctxt->profile_entropy[ctr][i4_br_id]); |
436 | 8.85k | } |
437 | 8.85k | } |
438 | 8.85k | 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 | 8.85k | return (IV_SUCCESS); |
442 | 8.85k | } |
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 | 8.85k | { |
469 | | /* local variables */ |
470 | 8.85k | enc_ctxt_t *ps_enc_ctxt; |
471 | 8.85k | ihevce_src_params_t *ps_src_prms; |
472 | 8.85k | WORD32 ctb_align_pic_wd; |
473 | 8.85k | WORD32 ctb_align_pic_ht, i4_resolution_id = 0, i4_num_resolutions, i4_num_bitrate_instances; |
474 | 8.85k | WORD32 i4_resolution_id_ctr, br_ctr; |
475 | | |
476 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[i4_resolution_id]; |
477 | 8.85k | ps_src_prms = &ps_hle_ctxt->ps_static_cfg_prms->s_src_prms; |
478 | 8.85k | 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 | 8.85k | ps_hle_ctxt->i4_error_code = 0; |
481 | | |
482 | | /* ------- populate the Input buffer requirements -------- */ |
483 | | /* get the number of buffers required for LAP */ |
484 | 8.85k | ps_input_bufs_req->i4_min_num_yuv_bufs = |
485 | 8.85k | ihevce_lap_get_num_ip_bufs(&ps_enc_ctxt->s_lap_stat_prms); |
486 | | |
487 | 8.85k | ps_input_bufs_req->i4_min_num_synch_ctrl_bufs = ps_input_bufs_req->i4_min_num_yuv_bufs; |
488 | | |
489 | 8.85k | 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 | 8.85k | ctb_align_pic_wd = |
493 | 8.85k | ps_src_prms->i4_width + |
494 | 8.85k | SET_CTB_ALIGN(ps_src_prms->i4_width, ps_enc_ctxt->s_frm_ctb_prms.i4_ctb_size); |
495 | | |
496 | 8.85k | ctb_align_pic_ht = |
497 | 8.85k | ps_src_prms->i4_height + |
498 | 8.85k | SET_CTB_ALIGN(ps_src_prms->i4_height, ps_enc_ctxt->s_frm_ctb_prms.i4_ctb_size); |
499 | | |
500 | 8.85k | 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 | 8.85k | else |
507 | 8.85k | { |
508 | 8.85k | ps_input_bufs_req->i4_min_size_y_buf = ctb_align_pic_wd * ctb_align_pic_ht; |
509 | | |
510 | 8.85k | ps_input_bufs_req->i4_min_size_uv_buf = (ctb_align_pic_wd * ctb_align_pic_ht) >> 1; |
511 | 8.85k | } |
512 | | |
513 | 8.85k | ps_input_bufs_req->i4_min_size_uv_buf <<= |
514 | 8.85k | ((ps_src_prms->i4_chr_format == IV_YUV_422SP_UV) ? 1 : 0); |
515 | | |
516 | 8.85k | ps_input_bufs_req->i4_yuv_format = ps_src_prms->i4_chr_format; |
517 | | |
518 | 8.85k | #ifndef DISABLE_SEI |
519 | 8.85k | ps_input_bufs_req->i4_min_size_synch_ctrl_bufs = |
520 | 8.85k | ((MAX_SEI_PAYLOAD_PER_TLV + 16) * MAX_NUMBER_OF_SEI_PAYLOAD) + 16; |
521 | | |
522 | 8.85k | ps_input_bufs_req->i4_min_size_asynch_ctrl_bufs = |
523 | 8.85k | ((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 | 17.7k | for(i4_resolution_id_ctr = 0; i4_resolution_id_ctr < i4_num_resolutions; i4_resolution_id_ctr++) |
530 | 8.85k | { |
531 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[i4_resolution_id_ctr]; |
532 | | |
533 | 8.85k | 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 | 8.85k | ctb_align_pic_wd = ps_enc_ctxt->s_runtime_tgt_params.i4_width + |
537 | 8.85k | SET_CTB_ALIGN( |
538 | 8.85k | ps_enc_ctxt->s_runtime_tgt_params.i4_width, |
539 | 8.85k | ps_enc_ctxt->s_frm_ctb_prms.i4_ctb_size); |
540 | | |
541 | 8.85k | ctb_align_pic_ht = ps_enc_ctxt->s_runtime_tgt_params.i4_height + |
542 | 8.85k | SET_CTB_ALIGN( |
543 | 8.85k | ps_enc_ctxt->s_runtime_tgt_params.i4_height, |
544 | 8.85k | ps_enc_ctxt->s_frm_ctb_prms.i4_ctb_size); |
545 | | |
546 | 17.7k | for(br_ctr = 0; br_ctr < i4_num_bitrate_instances; br_ctr++) |
547 | 8.85k | { |
548 | | /* ------- populate the Output buffer requirements -------- */ |
549 | 8.85k | ps_res_layer_output_bufs_req->s_output_buf_req[i4_resolution_id_ctr][br_ctr] |
550 | 8.85k | .i4_min_num_out_bufs = NUM_OUTPUT_BUFS; |
551 | | |
552 | 8.85k | ps_res_layer_output_bufs_req->s_output_buf_req[i4_resolution_id_ctr][br_ctr] |
553 | 8.85k | .i4_min_size_bitstream_buf = (ctb_align_pic_wd * ctb_align_pic_ht); |
554 | | |
555 | 8.85k | if((ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_internal_bit_depth == 12) || |
556 | 8.85k | ((ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_internal_bit_depth > 8) && |
557 | 8.85k | (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 | 8.85k | if((ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_internal_bit_depth == 10) && |
564 | 8.85k | (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 | 8.85k | if(ps_enc_ctxt->ps_stat_prms->i4_save_recon == 0) |
575 | 8.85k | { |
576 | 8.85k | ps_res_layer_recon_bufs_req->s_recon_buf_req[i4_resolution_id_ctr][br_ctr] |
577 | 8.85k | .i4_min_num_recon_bufs = 0; |
578 | | |
579 | 8.85k | ps_res_layer_recon_bufs_req->s_recon_buf_req[i4_resolution_id_ctr][br_ctr] |
580 | 8.85k | .i4_min_size_y_buf = 0; |
581 | | |
582 | 8.85k | ps_res_layer_recon_bufs_req->s_recon_buf_req[i4_resolution_id_ctr][br_ctr] |
583 | 8.85k | .i4_min_size_uv_buf = 0; |
584 | 8.85k | } |
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 | 8.85k | } |
607 | 8.85k | } |
608 | | |
609 | 8.85k | return (IV_SUCCESS); |
610 | 8.85k | } |
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 | 8.85k | { |
644 | | /* local varaibles */ |
645 | 8.85k | enc_ctxt_t *ps_enc_ctxt; |
646 | 8.85k | WORD32 res_ctr, |
647 | 8.85k | i4_num_resolutions = ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_num_res_layers; |
648 | 8.85k | void *pv_q_mutex_hdl = NULL; |
649 | | |
650 | | /* set no error in the output */ |
651 | 8.85k | ps_hle_ctxt->i4_error_code = 0; |
652 | | |
653 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++) |
654 | 8.85k | { |
655 | 8.85k | 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 | 8.85k | ihevce_mem_manager_que_init( |
660 | 8.85k | ps_enc_ctxt, |
661 | 8.85k | ps_hle_ctxt, |
662 | 8.85k | ps_input_data_ctrl_buffs_desc, |
663 | 8.85k | ps_input_asynch_ctrl_buffs_desc, |
664 | 8.85k | &ps_mres_output_data_buffs_desc->s_output_data_buffs[res_ctr][0], |
665 | 8.85k | &ps_mres_recon_data_buffs_desc->s_recon_data_buffs[res_ctr][0]); |
666 | | |
667 | | /* set the number of Queues */ |
668 | 8.85k | 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 | 8.85k | if(0 == res_ctr) |
674 | 8.85k | { |
675 | 8.85k | 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 | 8.85k | pv_q_mutex_hdl = ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl; |
678 | 8.85k | if(NULL == pv_q_mutex_hdl) |
679 | 0 | { |
680 | 0 | return IV_FAIL; |
681 | 0 | } |
682 | 8.85k | } |
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 | 8.85k | ps_enc_ctxt->i4_io_queues_created = 1; |
690 | 8.85k | } |
691 | 8.85k | return (IV_SUCCESS); |
692 | 8.85k | } |
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 | 8.85k | { |
713 | | /* local variables */ |
714 | 8.85k | WORD32 ctr, res_ctr; |
715 | 8.85k | ihevce_hle_ctxt_t *ps_hle_ctxt; |
716 | 8.85k | enc_ctxt_t *ps_enc_ctxt; |
717 | | /* enc ctxt to store 0th instance's params which are required by all instances */ |
718 | 8.85k | enc_ctxt_t *ps_enc_ctxt_base; |
719 | 8.85k | void *pv_lap_sem_hdl; |
720 | 8.85k | void *pv_enc_frame_process_sem_hdl; |
721 | 8.85k | void *pv_pre_enc_frame_process_sem_hdl; |
722 | 8.85k | void *apv_ent_coding_sem_hdl[IHEVCE_MAX_NUM_BITRATES]; |
723 | 8.85k | void *pv_ent_common_mres_sem_hdl = NULL; |
724 | 8.85k | void *pv_out_common_mres_sem_hdl = NULL; |
725 | | |
726 | 8.85k | void *pv_inp_data_sem_hdl; |
727 | 8.85k | void *pv_lap_inp_data_sem_hdl; |
728 | 8.85k | void *pv_preenc_inp_data_sem_hdl; |
729 | 8.85k | void *pv_inp_ctrl_sem_hdl; |
730 | 8.85k | void *apv_out_stream_sem_hdl[IHEVCE_MAX_NUM_BITRATES]; |
731 | 8.85k | void *apv_out_recon_sem_hdl[IHEVCE_MAX_NUM_BITRATES]; |
732 | 8.85k | void *pv_out_ctrl_sts_sem_hdl; |
733 | | |
734 | 8.85k | lap_intface_t *ps_lap_interface_ctxt; |
735 | 8.85k | iv_mem_rec_t s_memtab; |
736 | 8.85k | WORD32 i4_num_bit_rate_instances[IHEVCE_MAX_NUM_RESOLUTIONS], i4_num_resolutions; |
737 | 8.85k | WORD32 i; //loop variable |
738 | 8.85k | WORD32 ai4_proc_count[MAX_NUMBER_PROC_GRPS] = { 0 }, i4_proc_grp_count; |
739 | 8.85k | WORD32 i4_acc_proc_num = 0; |
740 | | |
741 | | /* Frame Encode processing threads & semaphores */ |
742 | 8.85k | void *apv_enc_frm_proc_hdls[IHEVCE_MAX_NUM_RESOLUTIONS][MAX_NUM_FRM_PROC_THRDS_ENC]; |
743 | 8.85k | frm_proc_thrd_ctxt_t |
744 | 8.85k | *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 | 8.85k | void *apv_pre_enc_frm_proc_hdls[IHEVCE_MAX_NUM_RESOLUTIONS][MAX_NUM_FRM_PROC_THRDS_PRE_ENC]; |
748 | 8.85k | frm_proc_thrd_ctxt_t |
749 | 8.85k | *aps_pre_enc_frm_proc_thrd_ctxt[IHEVCE_MAX_NUM_RESOLUTIONS][MAX_NUM_FRM_PROC_THRDS_PRE_ENC]; |
750 | | |
751 | 8.85k | void *apv_entropy_thrd_hdls[IHEVCE_MAX_NUM_RESOLUTIONS][NUM_ENTROPY_THREADS]; |
752 | 8.85k | frm_proc_thrd_ctxt_t *aps_entropy_thrd_ctxt[IHEVCE_MAX_NUM_RESOLUTIONS][NUM_ENTROPY_THREADS]; |
753 | | |
754 | 8.85k | ps_hle_ctxt = (ihevce_hle_ctxt_t *)pv_proc_intf_ctxt; |
755 | 8.85k | ps_enc_ctxt_base = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[0]; |
756 | | /* profile start */ |
757 | 8.85k | PROFILE_START(&ps_hle_ctxt->profile_hle); |
758 | | /* store default values of mem tab */ |
759 | 8.85k | s_memtab.i4_size = sizeof(iv_mem_rec_t); |
760 | 8.85k | s_memtab.i4_mem_alignment = 4; |
761 | | |
762 | 8.85k | i4_num_resolutions = ps_enc_ctxt_base->ps_stat_prms->s_tgt_lyr_prms.i4_num_res_layers; |
763 | 8.85k | memset( |
764 | 8.85k | apv_entropy_thrd_hdls, |
765 | 8.85k | 0, |
766 | 8.85k | IHEVCE_MAX_NUM_RESOLUTIONS * NUM_ENTROPY_THREADS * sizeof(void *)); |
767 | 8.85k | memset( |
768 | 8.85k | apv_entropy_thrd_hdls, |
769 | 8.85k | 0, |
770 | 8.85k | IHEVCE_MAX_NUM_RESOLUTIONS * NUM_ENTROPY_THREADS * sizeof(void *)); |
771 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++) |
772 | 8.85k | { |
773 | 8.85k | i4_num_bit_rate_instances[res_ctr] = |
774 | 8.85k | ps_enc_ctxt_base->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[res_ctr] |
775 | 8.85k | .i4_num_bitrate_instances; |
776 | 8.85k | } |
777 | | /* --------------------------------------------------------------------- */ |
778 | | /* Init number of threads for each stage */ |
779 | | /* --------------------------------------------------------------------- */ |
780 | | |
781 | 8.85k | { |
782 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++) |
783 | 8.85k | { |
784 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr]; |
785 | | /* all the threads created will be made active */ |
786 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_num_active_enc_thrds = |
787 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds; |
788 | | |
789 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_num_active_pre_enc_thrds = |
790 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds; |
791 | 8.85k | } |
792 | 8.85k | } |
793 | | |
794 | | /* --------------------------------------------------------------------- */ |
795 | | /* Multiple processing Threads Semaphores init */ |
796 | | /* --------------------------------------------------------------------- */ |
797 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++) |
798 | 8.85k | { |
799 | 8.85k | osal_sem_attr_t attr = OSAL_DEFAULT_SEM_ATTR; |
800 | | |
801 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr]; |
802 | | |
803 | 8.85k | attr.value = SEM_START_VALUE; |
804 | | |
805 | | /* Create Semaphore handle for LAP thread */ |
806 | 8.85k | if(0 == ps_enc_ctxt->i4_resolution_id) |
807 | 8.85k | { |
808 | 8.85k | pv_lap_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr); |
809 | 8.85k | if(NULL == pv_lap_sem_hdl) |
810 | 0 | { |
811 | 0 | return IV_FAIL; |
812 | 0 | } |
813 | 8.85k | } |
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 | 8.85k | pv_enc_frame_process_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr); |
821 | 8.85k | 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 | 8.85k | pv_pre_enc_frame_process_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr); |
828 | 8.85k | 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 | 8.85k | if(0 == ps_enc_ctxt->i4_resolution_id) |
835 | 8.85k | { |
836 | 8.85k | pv_inp_data_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr); |
837 | 8.85k | if(NULL == pv_inp_data_sem_hdl) |
838 | 0 | { |
839 | 0 | return IV_FAIL; |
840 | 0 | } |
841 | 8.85k | } |
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 | 8.85k | pv_lap_inp_data_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr); |
850 | 8.85k | 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 | 8.85k | pv_preenc_inp_data_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr); |
857 | 8.85k | 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 | 8.85k | if(0 == ps_enc_ctxt->i4_resolution_id) |
864 | 8.85k | { |
865 | 8.85k | pv_inp_ctrl_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr); |
866 | 8.85k | if(NULL == pv_inp_ctrl_sem_hdl) |
867 | 0 | { |
868 | 0 | return IV_FAIL; |
869 | 0 | } |
870 | 8.85k | } |
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 | 8.85k | pv_out_ctrl_sts_sem_hdl = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr); |
878 | 8.85k | 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 | 8.85k | 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 | 17.7k | for(i = 0; i < i4_num_bit_rate_instances[res_ctr]; i++) |
911 | 8.85k | { |
912 | | /* Create Semaphore for enropy coding thread */ |
913 | 8.85k | apv_ent_coding_sem_hdl[i] = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr); |
914 | 8.85k | 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 | 8.85k | apv_out_stream_sem_hdl[i] = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr); |
921 | 8.85k | 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 | 8.85k | apv_out_recon_sem_hdl[i] = osal_sem_create(ps_hle_ctxt->pv_osal_handle, &attr); |
928 | 8.85k | if(NULL == apv_out_recon_sem_hdl[i]) |
929 | 0 | { |
930 | 0 | return IV_FAIL; |
931 | 0 | } |
932 | 8.85k | } |
933 | | |
934 | | /* update the semaphore handles and the thread creates status */ |
935 | | |
936 | 8.85k | ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle = pv_enc_frame_process_sem_hdl; |
937 | 8.85k | ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle = |
938 | 8.85k | pv_pre_enc_frame_process_sem_hdl; |
939 | 8.85k | ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle = pv_lap_sem_hdl; |
940 | 8.85k | ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_data_sem_handle = pv_inp_data_sem_hdl; |
941 | 8.85k | ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_inp_data_sem_hdl = pv_lap_inp_data_sem_hdl; |
942 | 8.85k | ps_enc_ctxt->s_thrd_sem_ctxt.pv_preenc_inp_data_sem_hdl = pv_preenc_inp_data_sem_hdl; |
943 | 8.85k | ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_ctrl_sem_handle = pv_inp_ctrl_sem_hdl; |
944 | 8.85k | ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_ctrl_sem_handle = pv_out_ctrl_sts_sem_hdl; |
945 | 17.7k | for(i = 0; i < i4_num_bit_rate_instances[res_ctr]; i++) |
946 | 8.85k | { |
947 | 8.85k | ps_enc_ctxt->s_thrd_sem_ctxt.apv_ent_cod_sem_handle[i] = apv_ent_coding_sem_hdl[i]; |
948 | 8.85k | ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_strm_sem_handle[i] = apv_out_stream_sem_hdl[i]; |
949 | 8.85k | ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_recon_sem_handle[i] = apv_out_recon_sem_hdl[i]; |
950 | 8.85k | } |
951 | 8.85k | } |
952 | | |
953 | | /* --------------------------------------------------------------------- */ |
954 | | /* Multiple processing Threads Mutex init */ |
955 | | /* --------------------------------------------------------------------- */ |
956 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++) |
957 | 8.85k | { |
958 | 8.85k | 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 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_enc_grp_me = |
962 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
963 | 8.85k | 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 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_enc_grp_enc_loop = |
970 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
971 | 8.85k | 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 | 17.7k | for(i = 0; i < MAX_NUM_ME_PARALLEL; i++) |
978 | 8.85k | { |
979 | 8.85k | ps_enc_ctxt->s_multi_thrd.apv_mutex_handle[i] = |
980 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
981 | 8.85k | if(NULL == ps_enc_ctxt->s_multi_thrd.apv_mutex_handle[i]) |
982 | 0 | { |
983 | 0 | return IV_FAIL; |
984 | 0 | } |
985 | | |
986 | 8.85k | ps_enc_ctxt->s_multi_thrd.apv_mutex_handle_me_end[i] = |
987 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
988 | 8.85k | if(NULL == ps_enc_ctxt->s_multi_thrd.apv_mutex_handle_me_end[i]) |
989 | 0 | { |
990 | 0 | return IV_FAIL; |
991 | 0 | } |
992 | 8.85k | } |
993 | | |
994 | 17.7k | for(i = 0; i < MAX_NUM_ENC_LOOP_PARALLEL; i++) |
995 | 8.85k | { |
996 | 8.85k | ps_enc_ctxt->s_multi_thrd.apv_post_enc_mutex_handle[i] = |
997 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
998 | 8.85k | 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 | 8.85k | ps_enc_ctxt->s_multi_thrd.apv_mutex_handle_frame_init[i] = |
1004 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
1005 | 8.85k | if(NULL == ps_enc_ctxt->s_multi_thrd.apv_mutex_handle_frame_init[i]) |
1006 | 0 | { |
1007 | 0 | return IV_FAIL; |
1008 | 0 | } |
1009 | 8.85k | } |
1010 | | |
1011 | | /*initialize mutex for pre-enc group */ |
1012 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_init = |
1013 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
1014 | | |
1015 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_decomp_deinit = |
1016 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
1017 | | |
1018 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_hme_init = |
1019 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
1020 | | |
1021 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_hme_deinit = |
1022 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
1023 | | |
1024 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_deinit = |
1025 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
1026 | | |
1027 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_l0_ipe_init = |
1028 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
1029 | | |
1030 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_decomp = |
1031 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
1032 | | |
1033 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_hme = |
1034 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
1035 | | |
1036 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_l0ipe = |
1037 | 8.85k | osal_mutex_create(ps_hle_ctxt->pv_osal_handle); |
1038 | | |
1039 | 8.85k | if(NULL == ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_init || |
1040 | 8.85k | NULL == ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_decomp_deinit || |
1041 | 8.85k | NULL == ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_hme_init || |
1042 | 8.85k | NULL == ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_hme_deinit || |
1043 | 8.85k | NULL == ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_deinit || |
1044 | 8.85k | NULL == ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_l0_ipe_init || |
1045 | 8.85k | NULL == ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_decomp || |
1046 | 8.85k | NULL == ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_hme || |
1047 | 8.85k | 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 | 8.85k | } |
1052 | | |
1053 | | /* --------------------------------------------------------------------- */ |
1054 | | /* Multiple processing Threads Context init */ |
1055 | | /* --------------------------------------------------------------------- */ |
1056 | | |
1057 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++) |
1058 | 8.85k | { |
1059 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr]; |
1060 | 8.85k | ps_enc_ctxt_base = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[0]; |
1061 | | |
1062 | | /*initialize multi-thread context for enc group*/ |
1063 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_is_recon_free_done = 0; |
1064 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_idx_dvsr_p = 0; |
1065 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_last_inp_buf = 0; |
1066 | | |
1067 | 8.85k | { |
1068 | | /* For all the ME frames in Parallel */ |
1069 | 8.85k | WORD32 i4_frm_idx; |
1070 | | |
1071 | 17.7k | for(i4_frm_idx = 0; i4_frm_idx < MAX_NUM_ME_PARALLEL; i4_frm_idx++) |
1072 | 8.85k | { |
1073 | 8.85k | ps_enc_ctxt->s_multi_thrd.me_num_thrds_exited[i4_frm_idx] = 0; |
1074 | 8.85k | ps_enc_ctxt->s_multi_thrd.ai4_me_master_done_flag[i4_frm_idx] = 0; |
1075 | 8.85k | ps_enc_ctxt->s_multi_thrd.ai4_me_enc_buff_prod_flag[i4_frm_idx] = 0; |
1076 | 8.85k | } |
1077 | 8.85k | } |
1078 | | |
1079 | 8.85k | { |
1080 | 8.85k | WORD32 i4_frm_idx; |
1081 | 8.85k | ps_enc_ctxt->s_multi_thrd.num_thrds_done = 0; |
1082 | 8.85k | ps_enc_ctxt->s_multi_thrd.num_thrds_exited_for_reenc = 0; |
1083 | 17.7k | for(i4_frm_idx = 0; i4_frm_idx < MAX_NUM_ENC_LOOP_PARALLEL; i4_frm_idx++) |
1084 | 8.85k | { |
1085 | 8.85k | ps_enc_ctxt->s_multi_thrd.num_thrds_exited[i4_frm_idx] = 0; |
1086 | | |
1087 | 8.85k | ps_enc_ctxt->s_multi_thrd.enc_master_done_frame_init[i4_frm_idx] = 0; |
1088 | | |
1089 | 17.7k | for(i = 0; i < i4_num_bit_rate_instances[res_ctr]; i++) |
1090 | 8.85k | { |
1091 | | /*reset the entropy buffer produced status */ |
1092 | 8.85k | ps_enc_ctxt->s_multi_thrd.ai4_produce_outbuf[i4_frm_idx][i] = 1; |
1093 | 8.85k | ps_enc_ctxt->s_multi_thrd.ps_frm_recon[i4_frm_idx][i] = NULL; |
1094 | | |
1095 | 8.85k | ps_enc_ctxt->s_multi_thrd.ps_curr_out_enc_grp[i4_frm_idx][i] = NULL; |
1096 | 8.85k | } |
1097 | 8.85k | } |
1098 | 8.85k | } |
1099 | 8.85k | 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 | 17.7k | for(i = 0; i < ps_enc_ctxt->s_multi_thrd.i4_num_enc_loop_frm_pllel; i++) |
1103 | 8.85k | { |
1104 | 8.85k | ihevce_dmgr_set_done_frm_frm_sync( |
1105 | 8.85k | ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_prev_frame_done[i]); |
1106 | 8.85k | } |
1107 | | /* Set prev_frame_done = 1 to indicate that all the threads are in same frame*/ |
1108 | 8.85k | ihevce_dmgr_set_done_frm_frm_sync( |
1109 | 8.85k | 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 | 8.85k | ihevce_dmgr_set_prev_done_frm_frm_sync( |
1112 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_enc_done_for_reenc); |
1113 | 17.7k | for(i = 0; i < ps_enc_ctxt->s_multi_thrd.i4_num_me_frm_pllel; i++) |
1114 | 8.85k | { |
1115 | 8.85k | ihevce_dmgr_set_done_frm_frm_sync( |
1116 | 8.85k | ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_prev_frame_me_done[i]); |
1117 | 8.85k | } |
1118 | | |
1119 | | /* initialize multi-thread context for pre enc group */ |
1120 | | |
1121 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_ctrl_blocking_mode = BUFF_QUE_BLOCKING_MODE; |
1122 | | |
1123 | 256k | for(ctr = 0; ctr < MAX_PRE_ENC_STAGGER + NUM_BUFS_DECOMP_HME; ctr++) |
1124 | 247k | { |
1125 | 247k | ps_enc_ctxt->s_multi_thrd.ai4_pre_enc_init_done[ctr] = 0; |
1126 | 247k | ps_enc_ctxt->s_multi_thrd.ai4_pre_enc_hme_init_done[ctr] = 0; |
1127 | 247k | ps_enc_ctxt->s_multi_thrd.ai4_pre_enc_deinit_done[ctr] = 1; |
1128 | 247k | ps_enc_ctxt->s_multi_thrd.ai4_num_thrds_processed_decomp[ctr] = 0; |
1129 | 247k | ps_enc_ctxt->s_multi_thrd.ai4_num_thrds_processed_coarse_me[ctr] = 0; |
1130 | 247k | ps_enc_ctxt->s_multi_thrd.ai4_num_thrds_processed_pre_enc[ctr] = 0; |
1131 | | |
1132 | 247k | ps_enc_ctxt->s_multi_thrd.ai4_num_thrds_processed_L0_ipe_qp_init[ctr] = 0; |
1133 | 247k | ps_enc_ctxt->s_multi_thrd.ai4_decomp_coarse_me_complete_flag[ctr] = 1; |
1134 | 247k | ps_enc_ctxt->s_multi_thrd.ai4_end_flag_pre_enc[ctr] = 0; |
1135 | 247k | } |
1136 | | |
1137 | | /* Set prev_frame_done = 1 to indicate that all the threads are in same frame*/ |
1138 | 8.85k | ihevce_dmgr_set_done_frm_frm_sync( |
1139 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_l1); |
1140 | | |
1141 | 8.85k | ihevce_dmgr_set_done_frm_frm_sync( |
1142 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_coarse_me); |
1143 | | |
1144 | 8.85k | ihevce_dmgr_set_done_frm_frm_sync( |
1145 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_dep_mngr_prev_frame_pre_enc_l0); |
1146 | | |
1147 | 8.85k | { |
1148 | | /**init idx for handling delay between pre-me and l0-ipe*/ |
1149 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_delay_pre_me_btw_l0_ipe = 0; |
1150 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_max_delay_pre_me_btw_l0_ipe = |
1151 | 8.85k | MIN_L1_L0_STAGGER_NON_SEQ + |
1152 | 8.85k | ps_enc_ctxt->s_lap_stat_prms.s_lap_params.i4_rc_look_ahead_pics + 1; |
1153 | 8.85k | 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 | 8.85k | ps_enc_ctxt->s_multi_thrd.i4_qp_update_l0_ipe = -1; |
1160 | 8.85k | } |
1161 | 8.85k | } |
1162 | | |
1163 | | /** Get Number of Processor Groups **/ |
1164 | 8.85k | 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 | 8.85k | ASSERT(i4_proc_grp_count <= MAX_NUMBER_PROC_GRPS); |
1167 | | /** Get Number of logical processors in Each Group **/ |
1168 | 17.7k | for(ctr = 0; ctr < i4_proc_grp_count; ctr++) |
1169 | 8.85k | { |
1170 | 8.85k | ai4_proc_count[ctr] = |
1171 | 8.85k | ps_enc_ctxt_base->ps_stat_prms->s_multi_thrd_prms.ai4_num_cores_per_grp[ctr]; |
1172 | 8.85k | } |
1173 | | |
1174 | | /* --------------------------------------------------------------------- */ |
1175 | | /* Create a LAP thread */ |
1176 | | /* --------------------------------------------------------------------- */ |
1177 | | /* LAP thread will run on 0th resolution instance context */ |
1178 | 8.85k | { |
1179 | 8.85k | s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM; |
1180 | 8.85k | s_memtab.i4_mem_size = sizeof(lap_intface_t); |
1181 | | |
1182 | | /* initialise the interface strucure parameters */ |
1183 | 8.85k | ps_hle_ctxt->ihevce_mem_alloc( |
1184 | 8.85k | ps_hle_ctxt->pv_mem_mgr_hdl, &ps_enc_ctxt_base->ps_stat_prms->s_sys_api, &s_memtab); |
1185 | 8.85k | if(s_memtab.pv_base == NULL) |
1186 | 0 | { |
1187 | 0 | return (IV_FAIL); |
1188 | 0 | } |
1189 | | |
1190 | 8.85k | ps_lap_interface_ctxt = (lap_intface_t *)s_memtab.pv_base; |
1191 | | |
1192 | | /* populate the params */ |
1193 | 8.85k | ps_lap_interface_ctxt->pv_hle_ctxt = ps_hle_ctxt; |
1194 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[0]; |
1195 | 8.85k | ps_lap_interface_ctxt->pv_lap_module_ctxt = ps_enc_ctxt->s_module_ctxt.pv_lap_ctxt; |
1196 | 8.85k | ps_lap_interface_ctxt->i4_ctrl_in_que_id = IHEVCE_INPUT_ASYNCH_CTRL_Q; |
1197 | 8.85k | ps_lap_interface_ctxt->i4_ctrl_out_que_id = IHEVCE_OUTPUT_STATUS_Q; |
1198 | 8.85k | ps_lap_interface_ctxt->i4_ctrl_cmd_buf_size = ENC_COMMAND_BUFF_SIZE; |
1199 | 8.85k | ps_lap_interface_ctxt->i4_ctrl_in_que_blocking_mode = BUFF_QUE_BLOCKING_MODE; |
1200 | 8.85k | ps_lap_interface_ctxt->ps_sys_api = &ps_enc_ctxt_base->ps_stat_prms->s_sys_api; |
1201 | 8.85k | ps_enc_ctxt_base->pv_lap_interface_ctxt = (void *)ps_lap_interface_ctxt; |
1202 | 8.85k | ps_lap_interface_ctxt->ihevce_dyn_bitrate_cb = ihevce_dyn_bitrate; |
1203 | 8.85k | } |
1204 | | |
1205 | | /* --------------------------------------------------------------------- */ |
1206 | | /* Create Entropy Coding threads */ |
1207 | | /* --------------------------------------------------------------------- */ |
1208 | | /*Create entropy thread for each encoder instance*/ |
1209 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++) |
1210 | 8.85k | { |
1211 | 8.85k | osal_thread_attr_t s_thread_attr = OSAL_DEFAULT_THREAD_ATTR; |
1212 | 8.85k | WORD32 i4_num_entropy_threads; |
1213 | | |
1214 | | /* derive encoder ctxt from hle handle */ |
1215 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr]; |
1216 | | |
1217 | 8.85k | i4_num_entropy_threads = |
1218 | 8.85k | ps_enc_ctxt_base->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[res_ctr] |
1219 | 8.85k | .i4_num_bitrate_instances; |
1220 | | |
1221 | | /* initialise the interface strucure parameters */ |
1222 | 17.7k | for(ctr = 0; ctr < i4_num_entropy_threads; ctr++) |
1223 | 8.85k | { |
1224 | 8.85k | s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM; |
1225 | 8.85k | s_memtab.i4_mem_size = sizeof(frm_proc_thrd_ctxt_t); |
1226 | | |
1227 | 8.85k | ps_hle_ctxt->ihevce_mem_alloc( |
1228 | 8.85k | ps_hle_ctxt->pv_mem_mgr_hdl, &ps_enc_ctxt_base->ps_stat_prms->s_sys_api, &s_memtab); |
1229 | 8.85k | if(s_memtab.pv_base == NULL) |
1230 | 0 | { |
1231 | 0 | return (IV_FAIL); |
1232 | 0 | } |
1233 | | |
1234 | 8.85k | aps_entropy_thrd_ctxt[res_ctr][ctr] = (frm_proc_thrd_ctxt_t *)s_memtab.pv_base; |
1235 | | |
1236 | | /* initialise the interface strucure parameters */ |
1237 | 8.85k | aps_entropy_thrd_ctxt[res_ctr][ctr]->i4_thrd_id = ctr; |
1238 | 8.85k | aps_entropy_thrd_ctxt[res_ctr][ctr]->ps_hle_ctxt = ps_hle_ctxt; |
1239 | 8.85k | aps_entropy_thrd_ctxt[res_ctr][ctr]->pv_enc_ctxt = (void *)ps_enc_ctxt; |
1240 | | |
1241 | | /* Initialize application thread attributes */ |
1242 | 8.85k | s_thread_attr.exit_code = 0; |
1243 | 8.85k | s_thread_attr.name = 0; |
1244 | 8.85k | s_thread_attr.priority_map_flag = 1; |
1245 | 8.85k | s_thread_attr.priority = OSAL_PRIORITY_DEFAULT; |
1246 | 8.85k | s_thread_attr.stack_addr = 0; |
1247 | 8.85k | s_thread_attr.stack_size = THREAD_STACK_SIZE; |
1248 | 8.85k | s_thread_attr.thread_func = ihevce_ent_coding_thrd; |
1249 | 8.85k | s_thread_attr.thread_param = |
1250 | 8.85k | (void *)(aps_entropy_thrd_ctxt[res_ctr] |
1251 | 8.85k | [ctr]); //encioder and hle context are derived from this |
1252 | 8.85k | s_thread_attr.core_affinity_mask = 0; |
1253 | 8.85k | 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 | 8.85k | else |
1260 | 8.85k | { |
1261 | 8.85k | s_thread_attr.group_num = 0; |
1262 | 8.85k | } |
1263 | | |
1264 | | /* Create entropy coding thread */ |
1265 | 8.85k | apv_entropy_thrd_hdls[res_ctr][ctr] = |
1266 | 8.85k | osal_thread_create(ps_hle_ctxt->pv_osal_handle, &s_thread_attr); |
1267 | 8.85k | if(NULL == apv_entropy_thrd_hdls[res_ctr][ctr]) |
1268 | 0 | { |
1269 | 0 | return IV_FAIL; |
1270 | 0 | } |
1271 | 8.85k | } |
1272 | 8.85k | } |
1273 | | |
1274 | | /* --------------------------------------------------------------------- */ |
1275 | | /* Create all Slave Encode Frame processing threads */ |
1276 | | /* - -------------------------------------------------------------------- */ |
1277 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++) |
1278 | 8.85k | { |
1279 | 8.85k | WORD32 enc_ctr = 0; |
1280 | 8.85k | WORD32 i4_loop_count; |
1281 | 8.85k | WORD32 i4_curr_grp_num = 0; |
1282 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr]; |
1283 | | |
1284 | 8.85k | i4_acc_proc_num = 0; |
1285 | | /* Calculate the start core number of enc threads for current resolution */ |
1286 | 8.85k | 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 | 8.85k | 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 | 17.7k | for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds; ctr++) |
1313 | 8.85k | { |
1314 | 8.85k | osal_thread_attr_t s_thread_attr = OSAL_DEFAULT_THREAD_ATTR; |
1315 | | |
1316 | 8.85k | s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM; |
1317 | 8.85k | s_memtab.i4_mem_size = sizeof(frm_proc_thrd_ctxt_t); |
1318 | | |
1319 | 8.85k | ps_hle_ctxt->ihevce_mem_alloc( |
1320 | 8.85k | ps_hle_ctxt->pv_mem_mgr_hdl, &ps_enc_ctxt_base->ps_stat_prms->s_sys_api, &s_memtab); |
1321 | 8.85k | if(s_memtab.pv_base == NULL) |
1322 | 0 | { |
1323 | 0 | return (IV_FAIL); |
1324 | 0 | } |
1325 | | |
1326 | 8.85k | 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 | 8.85k | aps_enc_frm_proc_thrd_ctxt[res_ctr][ctr]->i4_thrd_id = ctr; |
1330 | | |
1331 | 8.85k | aps_enc_frm_proc_thrd_ctxt[res_ctr][ctr]->ps_hle_ctxt = ps_hle_ctxt; |
1332 | | |
1333 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr]; |
1334 | | |
1335 | 8.85k | aps_enc_frm_proc_thrd_ctxt[res_ctr][ctr]->pv_enc_ctxt = (void *)ps_enc_ctxt; |
1336 | | |
1337 | | /* Initialize application thread attributes */ |
1338 | 8.85k | s_thread_attr.exit_code = 0; |
1339 | 8.85k | s_thread_attr.name = 0; |
1340 | 8.85k | s_thread_attr.priority_map_flag = 1; |
1341 | 8.85k | s_thread_attr.priority = OSAL_PRIORITY_DEFAULT; |
1342 | 8.85k | s_thread_attr.stack_addr = 0; |
1343 | 8.85k | s_thread_attr.stack_size = THREAD_STACK_SIZE; |
1344 | 8.85k | s_thread_attr.thread_func = ihevce_enc_frm_proc_slave_thrd; |
1345 | 8.85k | s_thread_attr.thread_param = (void *)(aps_enc_frm_proc_thrd_ctxt[res_ctr][ctr]); |
1346 | 8.85k | s_thread_attr.group_num = i4_curr_grp_num; |
1347 | 8.85k | 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 | 8.85k | else |
1364 | 8.85k | { |
1365 | 8.85k | s_thread_attr.core_affinity_mask = 0; |
1366 | 8.85k | if((enc_ctr >= i4_acc_proc_num) && |
1367 | 8.85k | (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 | 8.85k | } |
1376 | | |
1377 | | /* Create frame processing thread */ |
1378 | 8.85k | apv_enc_frm_proc_hdls[res_ctr][ctr] = |
1379 | 8.85k | osal_thread_create(ps_hle_ctxt->pv_osal_handle, &s_thread_attr); |
1380 | 8.85k | if(NULL == apv_enc_frm_proc_hdls[res_ctr][ctr]) |
1381 | 0 | { |
1382 | 0 | return IV_FAIL; |
1383 | 0 | } |
1384 | 8.85k | enc_ctr++; |
1385 | 8.85k | } |
1386 | 8.85k | } |
1387 | | |
1388 | | /* --------------------------------------------------------------------- */ |
1389 | | /* Create all Pre - Encode Frame processing threads */ |
1390 | | /* --------------------------------------------------------------------- */ |
1391 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++) |
1392 | 8.85k | { |
1393 | 8.85k | WORD32 pre_enc_ctr = 0; |
1394 | 8.85k | WORD32 i4_loop_count; |
1395 | 8.85k | WORD32 i4_curr_grp_num = 0; |
1396 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr]; |
1397 | | |
1398 | 8.85k | i4_acc_proc_num = 0; |
1399 | | |
1400 | 8.85k | 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 | 8.85k | if(ps_enc_ctxt->s_multi_thrd.i4_all_thrds_active_flag) |
1403 | 8.85k | { |
1404 | | /* If its sequential mode of operation enc and pre-enc threads to be given same core affinity mask */ |
1405 | 8.85k | pre_enc_ctr -= ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds; |
1406 | 8.85k | } |
1407 | | |
1408 | 8.85k | 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 | 17.7k | for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds; ctr++) |
1431 | 8.85k | { |
1432 | 8.85k | osal_thread_attr_t s_thread_attr = OSAL_DEFAULT_THREAD_ATTR; |
1433 | | |
1434 | 8.85k | s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM; |
1435 | 8.85k | s_memtab.i4_mem_size = sizeof(frm_proc_thrd_ctxt_t); |
1436 | | |
1437 | 8.85k | ps_hle_ctxt->ihevce_mem_alloc( |
1438 | 8.85k | ps_hle_ctxt->pv_mem_mgr_hdl, &ps_enc_ctxt_base->ps_stat_prms->s_sys_api, &s_memtab); |
1439 | 8.85k | if(s_memtab.pv_base == NULL) |
1440 | 0 | { |
1441 | 0 | return (IV_FAIL); |
1442 | 0 | } |
1443 | | |
1444 | 8.85k | 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 | 8.85k | aps_pre_enc_frm_proc_thrd_ctxt[res_ctr][ctr]->i4_thrd_id = ctr; |
1448 | | |
1449 | 8.85k | aps_pre_enc_frm_proc_thrd_ctxt[res_ctr][ctr]->ps_hle_ctxt = ps_hle_ctxt; |
1450 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr]; |
1451 | 8.85k | aps_pre_enc_frm_proc_thrd_ctxt[res_ctr][ctr]->pv_enc_ctxt = (void *)ps_enc_ctxt; |
1452 | | |
1453 | | /* Initialize application thread attributes */ |
1454 | 8.85k | s_thread_attr.exit_code = 0; |
1455 | 8.85k | s_thread_attr.name = 0; |
1456 | 8.85k | s_thread_attr.priority_map_flag = 1; |
1457 | 8.85k | s_thread_attr.priority = OSAL_PRIORITY_DEFAULT; |
1458 | 8.85k | s_thread_attr.stack_addr = 0; |
1459 | 8.85k | s_thread_attr.stack_size = THREAD_STACK_SIZE; |
1460 | 8.85k | s_thread_attr.thread_func = ihevce_pre_enc_process_frame_thrd; |
1461 | 8.85k | s_thread_attr.thread_param = (void *)(aps_pre_enc_frm_proc_thrd_ctxt[res_ctr][ctr]); |
1462 | 8.85k | s_thread_attr.group_num = i4_curr_grp_num; |
1463 | | |
1464 | 8.85k | 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 | 8.85k | else |
1484 | 8.85k | { |
1485 | 8.85k | s_thread_attr.core_affinity_mask = 0; |
1486 | | |
1487 | 8.85k | if(((pre_enc_ctr + ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds) >= |
1488 | 8.85k | i4_acc_proc_num) && |
1489 | 8.85k | (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 | 8.85k | } |
1498 | | |
1499 | | /* Create frame processing thread */ |
1500 | 8.85k | apv_pre_enc_frm_proc_hdls[res_ctr][ctr] = |
1501 | 8.85k | osal_thread_create(ps_hle_ctxt->pv_osal_handle, &s_thread_attr); |
1502 | 8.85k | if(NULL == apv_pre_enc_frm_proc_hdls[res_ctr][ctr]) |
1503 | 0 | { |
1504 | 0 | return IV_FAIL; |
1505 | 0 | } |
1506 | 8.85k | pre_enc_ctr++; |
1507 | 8.85k | } |
1508 | 8.85k | } |
1509 | | |
1510 | | /* Set the threads init done Flag */ |
1511 | 8.85k | 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 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++) |
1521 | 8.85k | { |
1522 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr]; |
1523 | | |
1524 | 17.7k | for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds; ctr++) |
1525 | 8.85k | { |
1526 | | /* Wait for thread to complete */ |
1527 | 8.85k | osal_thread_wait(apv_pre_enc_frm_proc_hdls[res_ctr][ctr]); |
1528 | | |
1529 | | /* Destroy thread */ |
1530 | 8.85k | osal_thread_destroy(apv_pre_enc_frm_proc_hdls[res_ctr][ctr]); |
1531 | | |
1532 | 8.85k | s_memtab.i4_mem_size = sizeof(frm_proc_thrd_ctxt_t); |
1533 | 8.85k | s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM; |
1534 | 8.85k | s_memtab.pv_base = (void *)aps_pre_enc_frm_proc_thrd_ctxt[res_ctr][ctr]; |
1535 | | |
1536 | | /* free the ctxt memory */ |
1537 | 8.85k | ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab); |
1538 | 8.85k | } |
1539 | 8.85k | } |
1540 | | |
1541 | | /* --------------------------------------------------------------------- */ |
1542 | | /* Frame process Encode slave threads destroy */ |
1543 | | /* --------------------------------------------------------------------- */ |
1544 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++) |
1545 | 8.85k | { |
1546 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr]; |
1547 | | |
1548 | 17.7k | for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds; ctr++) |
1549 | 8.85k | { |
1550 | | /* Wait for thread to complete */ |
1551 | 8.85k | osal_thread_wait(apv_enc_frm_proc_hdls[res_ctr][ctr]); |
1552 | | |
1553 | | /* Destroy thread */ |
1554 | 8.85k | osal_thread_destroy(apv_enc_frm_proc_hdls[res_ctr][ctr]); |
1555 | | |
1556 | 8.85k | s_memtab.i4_mem_size = sizeof(frm_proc_thrd_ctxt_t); |
1557 | 8.85k | s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM; |
1558 | 8.85k | s_memtab.pv_base = (void *)aps_enc_frm_proc_thrd_ctxt[res_ctr][ctr]; |
1559 | | |
1560 | | /* free the ctxt memory */ |
1561 | 8.85k | ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab); |
1562 | 8.85k | } |
1563 | 8.85k | } |
1564 | | |
1565 | | /* --------------------------------------------------------------------- */ |
1566 | | /* Entropy threads destroy */ |
1567 | | /* --------------------------------------------------------------------- */ |
1568 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++) |
1569 | 8.85k | { |
1570 | 8.85k | WORD32 i4_num_bitrates = |
1571 | 8.85k | ps_enc_ctxt_base->ps_stat_prms->s_tgt_lyr_prms.as_tgt_params[res_ctr] |
1572 | 8.85k | .i4_num_bitrate_instances; |
1573 | | |
1574 | 17.7k | for(ctr = 0; ctr < i4_num_bitrates; ctr++) |
1575 | 8.85k | { |
1576 | | /* Wait for Entropy Coding thread to complete */ |
1577 | 8.85k | osal_thread_wait(apv_entropy_thrd_hdls[res_ctr][ctr]); |
1578 | | |
1579 | | /* Destroy Entropy Coding thread */ |
1580 | 8.85k | osal_thread_destroy(apv_entropy_thrd_hdls[res_ctr][ctr]); |
1581 | | |
1582 | | //semaphore will come here |
1583 | | |
1584 | 8.85k | s_memtab.i4_mem_size = sizeof(frm_proc_thrd_ctxt_t); |
1585 | 8.85k | s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM; |
1586 | 8.85k | s_memtab.pv_base = (void *)aps_entropy_thrd_ctxt[res_ctr][ctr]; |
1587 | | |
1588 | | /* free the ctxt memory */ |
1589 | 8.85k | ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab); |
1590 | 8.85k | } |
1591 | 8.85k | } |
1592 | | |
1593 | 8.85k | s_memtab.i4_mem_size = sizeof(lap_intface_t); |
1594 | 8.85k | s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM; |
1595 | 8.85k | s_memtab.pv_base = (void *)ps_lap_interface_ctxt; |
1596 | 8.85k | ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab); |
1597 | | /* profile stop */ |
1598 | 8.85k | PROFILE_STOP(&ps_hle_ctxt->profile_hle, NULL); |
1599 | 8.85k | return (0); |
1600 | 8.85k | } |
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 | 165k | { |
1624 | 165k | void *pv_ptr; |
1625 | 165k | enc_ctxt_t *ps_enc_ctxt; |
1626 | 165k | WORD32 i4_resolution_id = 0; |
1627 | | |
1628 | 165k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[i4_resolution_id]; |
1629 | 165k | 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 | 165k | pv_ptr = ihevce_q_get_free_buff( |
1635 | 165k | ps_hle_ctxt->apv_enc_hdl[0], IHEVCE_INPUT_DATA_CTRL_Q, pi4_buff_id, i4_blocking_mode); |
1636 | | |
1637 | 165k | return (pv_ptr); |
1638 | 165k | } |
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 | 5.76k | { |
1662 | 5.76k | void *pv_ptr; |
1663 | | |
1664 | | /*Input buffer is same for all enc handles*/ |
1665 | 5.76k | pv_ptr = ihevce_q_get_free_buff( |
1666 | 5.76k | ps_hle_ctxt->apv_enc_hdl[0], IHEVCE_INPUT_ASYNCH_CTRL_Q, pi4_buff_id, i4_blocking_mode); |
1667 | | |
1668 | 5.76k | return (pv_ptr); |
1669 | 5.76k | } |
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 | 174k | { |
1697 | 174k | void *pv_ptr; |
1698 | | |
1699 | 174k | pv_ptr = ihevce_q_get_free_buff( |
1700 | 174k | ps_hle_ctxt->apv_enc_hdl[i4_res_instance], |
1701 | 174k | (IHEVCE_OUTPUT_DATA_Q + i4_bitrate_instance), |
1702 | 174k | pi4_buff_id, |
1703 | 174k | i4_blocking_mode); |
1704 | 174k | return (pv_ptr); |
1705 | 174k | } |
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 | 165k | { |
1764 | 165k | IV_API_CALL_STATUS_T ret_status; |
1765 | | |
1766 | 165k | ret_status = |
1767 | 165k | ihevce_q_set_buff_prod(ps_hle_ctxt->apv_enc_hdl[0], IHEVCE_INPUT_DATA_CTRL_Q, i4_buff_id); |
1768 | | |
1769 | 165k | return (ret_status); |
1770 | 165k | } |
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 | 5.76k | { |
1794 | 5.76k | IV_API_CALL_STATUS_T ret_status; |
1795 | | |
1796 | 5.76k | ret_status = |
1797 | 5.76k | ihevce_q_set_buff_prod(ps_hle_ctxt->apv_enc_hdl[0], IHEVCE_INPUT_ASYNCH_CTRL_Q, i4_buff_id); |
1798 | | |
1799 | 5.76k | return (ret_status); |
1800 | 5.76k | } |
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 | 174k | { |
1826 | 174k | IV_API_CALL_STATUS_T ret_status; |
1827 | | |
1828 | 174k | ret_status = ihevce_q_set_buff_prod( |
1829 | 174k | ps_hle_ctxt->apv_enc_hdl[i4_resolution_id], |
1830 | 174k | (IHEVCE_OUTPUT_DATA_Q + i4_bitrate_instance_id), |
1831 | 174k | i4_buff_id); |
1832 | | |
1833 | 174k | return (ret_status); |
1834 | 174k | } |
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 | 8.88k | { |
2018 | | /* local varaibles */ |
2019 | 8.88k | enc_ctxt_t *ps_enc_ctxt; |
2020 | 8.88k | iv_mem_rec_t s_memtab; |
2021 | 8.88k | WORD32 ctr = 0, i, res_ctr, i4_num_resolutions; |
2022 | 8.88k | WORD32 ai4_num_bitrate_instances[IHEVCE_MAX_NUM_RESOLUTIONS] = { 1 }; |
2023 | | |
2024 | 8.88k | i4_num_resolutions = ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_num_res_layers; |
2025 | 17.7k | for(ctr = 0; ctr < i4_num_resolutions; ctr++) |
2026 | 8.88k | { |
2027 | 8.88k | ai4_num_bitrate_instances[ctr] = |
2028 | 8.88k | ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[ctr] |
2029 | 8.88k | .i4_num_bitrate_instances; |
2030 | 8.88k | } |
2031 | | |
2032 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions && ps_hle_ctxt->apv_enc_hdl[res_ctr]; res_ctr++) |
2033 | 8.85k | { |
2034 | 8.85k | ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[res_ctr]; |
2035 | | |
2036 | 8.85k | if(res_ctr == 0) |
2037 | 8.85k | { |
2038 | 8.85k | osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle); |
2039 | 8.85k | osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_data_sem_handle); |
2040 | 8.85k | osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_ctrl_sem_handle); |
2041 | 8.85k | 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 | 8.85k | } |
2047 | | |
2048 | 8.85k | osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_inp_data_sem_hdl); |
2049 | 8.85k | osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_preenc_inp_data_sem_hdl); |
2050 | | |
2051 | 8.85k | osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle); |
2052 | 8.85k | osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle); |
2053 | | |
2054 | 8.85k | osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_ctrl_sem_handle); |
2055 | | |
2056 | 17.7k | for(i = 0; i < ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[res_ctr] |
2057 | 17.7k | .i4_num_bitrate_instances; |
2058 | 8.85k | i++) |
2059 | 8.85k | { |
2060 | 8.85k | osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.apv_ent_cod_sem_handle[i]); |
2061 | 8.85k | osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_strm_sem_handle[i]); |
2062 | 8.85k | osal_sem_destroy(ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_recon_sem_handle[i]); |
2063 | 8.85k | } |
2064 | | |
2065 | | /* destroy the mutex allocated for job queue usage encode group */ |
2066 | 8.85k | 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 | 8.85k | 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 | 17.7k | for(i = 0; i < MAX_NUM_ME_PARALLEL; i++) |
2073 | 8.85k | { |
2074 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.apv_mutex_handle[i]); |
2075 | | |
2076 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.apv_mutex_handle_me_end[i]); |
2077 | 8.85k | } |
2078 | | |
2079 | 17.7k | for(i = 0; i < MAX_NUM_ENC_LOOP_PARALLEL; i++) |
2080 | 8.85k | { |
2081 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.apv_mutex_handle_frame_init[i]); |
2082 | | |
2083 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.apv_post_enc_mutex_handle[i]); |
2084 | 8.85k | } |
2085 | | |
2086 | | /* destroy the mutex allocated for job queue, init and de-init |
2087 | | usage pre enocde group */ |
2088 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_decomp); |
2089 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_hme); |
2090 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_job_q_mutex_hdl_pre_enc_l0ipe); |
2091 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_init); |
2092 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_decomp_deinit); |
2093 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_hme_init); |
2094 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_pre_enc_hme_deinit); |
2095 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_mutex_hdl_l0_ipe_init); |
2096 | 8.85k | 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 | 8.85k | 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 | 8.85k | ihevce_coarse_me_delete( |
2107 | 8.85k | ps_enc_ctxt->s_module_ctxt.pv_coarse_me_ctxt, |
2108 | 8.85k | ps_hle_ctxt->ps_static_cfg_prms, |
2109 | 8.85k | ps_enc_ctxt->i4_resolution_id); |
2110 | | /* destroy semaphores for all the threads in pre-enc and enc */ |
2111 | 17.7k | for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_enc_proc_thrds; ctr++) |
2112 | 8.85k | { |
2113 | 8.85k | osal_sem_destroy(ps_enc_ctxt->s_multi_thrd.apv_enc_thrd_sem_handle[ctr]); |
2114 | 8.85k | } |
2115 | | |
2116 | 17.7k | for(ctr = 0; ctr < ps_enc_ctxt->s_multi_thrd.i4_num_pre_enc_proc_thrds; ctr++) |
2117 | 8.85k | { |
2118 | 8.85k | osal_sem_destroy(ps_enc_ctxt->s_multi_thrd.apv_pre_enc_thrd_sem_handle[ctr]); |
2119 | 8.85k | } |
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 | 17.7k | for(ctr = 0; ctr < NUM_ME_ENC_BUFS; ctr++) |
2125 | 8.85k | { |
2126 | 8.85k | ihevce_dmgr_del(ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_encloop_dep_me[ctr]); |
2127 | 8.85k | } |
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 | 17.7k | for(i = 0; i < ps_enc_ctxt->s_multi_thrd.i4_num_enc_loop_frm_pllel; i++) |
2132 | 8.85k | { |
2133 | 8.85k | ihevce_dmgr_del(ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_prev_frame_done[i]); |
2134 | 8.85k | } |
2135 | | /* destroy the Prev. frame EncLoop Done for re-encode Dep Mngr */ |
2136 | 8.85k | 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 | 17.7k | for(i = 0; i < ps_enc_ctxt->s_multi_thrd.i4_num_me_frm_pllel; i++) |
2142 | 8.85k | { |
2143 | 8.85k | ihevce_dmgr_del(ps_enc_ctxt->s_multi_thrd.apv_dep_mngr_prev_frame_me_done[i]); |
2144 | 8.85k | } |
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 | 8.85k | 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 | 8.85k | 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 | 8.85k | 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 | 53.1k | for(ctr = 0; ctr < ps_enc_ctxt->ai4_num_buf_recon_q[0]; ctr++) |
2165 | 44.2k | { |
2166 | 44.2k | ihevce_dmgr_del(ps_enc_ctxt->pps_recon_buf_q[0][ctr]->pv_dep_mngr_recon); |
2167 | 44.2k | } |
2168 | | |
2169 | | /* destroy all the mutex created */ |
2170 | 8.85k | if(res_ctr == 0) |
2171 | 8.85k | { |
2172 | 8.85k | if(NULL != ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl) |
2173 | 8.85k | { |
2174 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl); |
2175 | 8.85k | } |
2176 | 8.85k | } |
2177 | | |
2178 | 8.85k | if(NULL != ps_enc_ctxt->pv_rc_mutex_lock_hdl) |
2179 | 8.85k | { |
2180 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->pv_rc_mutex_lock_hdl); |
2181 | 8.85k | } |
2182 | | |
2183 | 8.85k | if(NULL != ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_mutex_lock_hdl) |
2184 | 8.85k | { |
2185 | 8.85k | osal_mutex_destroy(ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_mutex_lock_hdl); |
2186 | 8.85k | } |
2187 | | |
2188 | 8.85k | if(NULL != ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_for_qp_update_mutex_lock_hdl) |
2189 | 8.85k | { |
2190 | 8.85k | osal_mutex_destroy( |
2191 | 8.85k | ps_enc_ctxt->s_multi_thrd.pv_sub_pic_rc_for_qp_update_mutex_lock_hdl); |
2192 | 8.85k | } |
2193 | | |
2194 | | /* call the memrory free function */ |
2195 | 8.85k | ihevce_mem_manager_free(ps_enc_ctxt, ps_hle_ctxt); |
2196 | 8.85k | if((1 == ps_hle_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_mres_single_out) && |
2197 | 8.85k | (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 | 8.85k | if(res_ctr == (i4_num_resolutions - 1)) |
2208 | 8.85k | { |
2209 | 8.85k | s_memtab.i4_mem_size = sizeof(ihevce_static_cfg_params_t); |
2210 | 8.85k | s_memtab.i4_mem_alignment = 4; |
2211 | 8.85k | s_memtab.i4_size = sizeof(iv_mem_rec_t); |
2212 | 8.85k | s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM; |
2213 | 8.85k | s_memtab.pv_base = ps_enc_ctxt->ps_stat_prms; |
2214 | | |
2215 | | /* free the encoder context pointer */ |
2216 | 8.85k | ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab); |
2217 | 8.85k | } |
2218 | 8.85k | s_memtab.i4_mem_size = sizeof(enc_ctxt_t); |
2219 | 8.85k | s_memtab.i4_mem_alignment = 4; |
2220 | 8.85k | s_memtab.i4_size = sizeof(iv_mem_rec_t); |
2221 | 8.85k | s_memtab.e_mem_type = IV_EXT_CACHEABLE_NORMAL_MEM; |
2222 | 8.85k | s_memtab.pv_base = ps_enc_ctxt; |
2223 | | |
2224 | | /* free the encoder context pointer */ |
2225 | 8.85k | ps_hle_ctxt->ihevce_mem_free(ps_hle_ctxt->pv_mem_mgr_hdl, &s_memtab); |
2226 | | |
2227 | | /* reset the encoder handle to NULL */ |
2228 | 8.85k | ps_hle_ctxt->apv_enc_hdl[res_ctr] = NULL; |
2229 | 8.85k | } |
2230 | | /* profile end */ |
2231 | 8.88k | PROFILE_END(&ps_hle_ctxt->profile_hle, "hle interface thread active time"); |
2232 | 17.7k | for(res_ctr = 0; res_ctr < i4_num_resolutions; res_ctr++) |
2233 | 8.88k | { |
2234 | 8.88k | WORD32 i4_br_id; |
2235 | | |
2236 | 8.88k | PROFILE_END(&ps_hle_ctxt->profile_pre_enc_l1l2[res_ctr], "pre enc l1l2 process"); |
2237 | 8.88k | PROFILE_END(&ps_hle_ctxt->profile_pre_enc_l0ipe[res_ctr], "pre enc l0 ipe process"); |
2238 | 8.88k | PROFILE_END(&ps_hle_ctxt->profile_enc_me[res_ctr], "enc me process"); |
2239 | 17.7k | for(i4_br_id = 0; i4_br_id < ai4_num_bitrate_instances[res_ctr]; i4_br_id++) |
2240 | 8.88k | { |
2241 | 8.88k | PROFILE_END(&ps_hle_ctxt->profile_enc[res_ctr][i4_br_id], "enc loop process"); |
2242 | 8.88k | PROFILE_END(&ps_hle_ctxt->profile_entropy[res_ctr][i4_br_id], "entropy process"); |
2243 | 8.88k | } |
2244 | 8.88k | } |
2245 | | |
2246 | | /* OSAL Delete */ |
2247 | 8.88k | ihevce_osal_delete((void *)ps_hle_ctxt); |
2248 | | |
2249 | 8.88k | return (IV_SUCCESS); |
2250 | 8.88k | } |