/src/libhevc/encoder/ihevce_plugin.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 | | * \file ihevce_plugin.c |
23 | | * |
24 | | * \brief |
25 | | * This file contains wrapper utilities to use hevc encoder library |
26 | | * |
27 | | * \date |
28 | | * 15/04/2014 |
29 | | * |
30 | | * \author |
31 | | * Ittiam |
32 | | * |
33 | | * List of Functions |
34 | | * |
35 | | * |
36 | | ****************************************************************************** |
37 | | */ |
38 | | |
39 | | /*****************************************************************************/ |
40 | | /* File Includes */ |
41 | | /*****************************************************************************/ |
42 | | /* System include files */ |
43 | | #include <stdio.h> |
44 | | #include <string.h> |
45 | | #include <stdlib.h> |
46 | | #include <assert.h> |
47 | | #include <stdarg.h> |
48 | | |
49 | | /* User include files */ |
50 | | #include "ihevc_typedefs.h" |
51 | | #include "itt_video_api.h" |
52 | | #include "ihevce_api.h" |
53 | | |
54 | | #include "rc_cntrl_param.h" |
55 | | #include "rc_frame_info_collector.h" |
56 | | #include "rc_look_ahead_params.h" |
57 | | |
58 | | #include "ihevc_defs.h" |
59 | | #include "ihevc_macros.h" |
60 | | #include "ihevc_debug.h" |
61 | | #include "ihevc_structs.h" |
62 | | #include "ihevc_platform_macros.h" |
63 | | #include "ihevc_deblk.h" |
64 | | #include "ihevc_itrans_recon.h" |
65 | | #include "ihevc_chroma_itrans_recon.h" |
66 | | #include "ihevc_chroma_intra_pred.h" |
67 | | #include "ihevc_intra_pred.h" |
68 | | #include "ihevc_inter_pred.h" |
69 | | #include "ihevc_mem_fns.h" |
70 | | #include "ihevc_padding.h" |
71 | | #include "ihevc_weighted_pred.h" |
72 | | #include "ihevc_sao.h" |
73 | | #include "ihevc_resi_trans.h" |
74 | | #include "ihevc_quant_iquant_ssd.h" |
75 | | |
76 | | #include "ihevce_defs.h" |
77 | | #include "ihevce_lap_enc_structs.h" |
78 | | #include "ihevce_plugin.h" |
79 | | #include "ihevce_plugin_priv.h" |
80 | | #include "ihevce_hle_interface.h" |
81 | | #include "ihevce_multi_thrd_structs.h" |
82 | | #include "ihevce_me_common_defs.h" |
83 | | #include "ihevce_error_codes.h" |
84 | | #include "ihevce_error_checks.h" |
85 | | #include "ihevce_function_selector.h" |
86 | | #include "ihevce_enc_structs.h" |
87 | | #include "ihevce_global_tables.h" |
88 | | |
89 | | #include "cast_types.h" |
90 | | #include "osal.h" |
91 | | #include "osal_defaults.h" |
92 | | |
93 | | /*****************************************************************************/ |
94 | | /* Constant Macros */ |
95 | | /*****************************************************************************/ |
96 | 8.26k | #define CREATE_TIME_ALLOCATION_INPUT 1 |
97 | 8.26k | #define CREATE_TIME_ALLOCATION_OUTPUT 0 |
98 | | |
99 | | #define MAX_NUM_FRM_IN_GOP 600 |
100 | | |
101 | | /*****************************************************************************/ |
102 | | /* Extern variables */ |
103 | | /*****************************************************************************/ |
104 | | |
105 | | /*****************************************************************************/ |
106 | | /* Function Definitions */ |
107 | | /*****************************************************************************/ |
108 | | |
109 | | /*! |
110 | | ****************************************************************************** |
111 | | * \if Function name : mem_mngr_alloc \endif |
112 | | * |
113 | | * \brief |
114 | | * Memory manager specific alloc function |
115 | | * it expects to reset the allocated memory and provide the zero initialised |
116 | | * memory whenever this function getting called |
117 | | * |
118 | | * \param[in] pv_handle : handle to memory manager |
119 | | * (currently not required can be set to null) |
120 | | * \param[in] ps_memtab : memory descriptor pointer |
121 | | * |
122 | | * \return |
123 | | * Memory pointer |
124 | | * |
125 | | * \author |
126 | | * Ittiam |
127 | | * |
128 | | ***************************************************************************** |
129 | | */ |
130 | | void mem_mngr_alloc(void *pv_handle, ihevce_sys_api_t *ps_sys_api, iv_mem_rec_t *ps_memtab) |
131 | 7.79M | { |
132 | 7.79M | #ifndef X86_MINGW |
133 | 7.79M | WORD32 error, mem_alignment; |
134 | 7.79M | #endif |
135 | | |
136 | 7.79M | (void)pv_handle; |
137 | | |
138 | | #ifdef X86_MINGW |
139 | | ps_memtab->pv_base = _aligned_malloc(ps_memtab->i4_mem_size, ps_memtab->i4_mem_alignment); |
140 | | #else |
141 | 7.79M | mem_alignment = ps_memtab->i4_mem_alignment; |
142 | 7.79M | mem_alignment = (mem_alignment >> 3) << 3; |
143 | 7.79M | if(mem_alignment == 0) |
144 | 5.10M | { |
145 | 5.10M | error = posix_memalign(&ps_memtab->pv_base, sizeof(void *), ps_memtab->i4_mem_size); |
146 | 5.10M | } |
147 | 2.69M | else |
148 | 2.69M | { |
149 | 2.69M | error = posix_memalign(&ps_memtab->pv_base, mem_alignment, ps_memtab->i4_mem_size); |
150 | 2.69M | } |
151 | 7.79M | if(error != 0) |
152 | 0 | { |
153 | 0 | ps_sys_api->ihevce_printf(ps_sys_api->pv_cb_handle, "posix_memalign error %d\n", error); |
154 | 0 | } |
155 | 7.79M | #endif |
156 | | |
157 | 7.79M | if(ps_memtab->pv_base == NULL) |
158 | 0 | { |
159 | 0 | ps_sys_api->ihevce_printf( |
160 | 0 | ps_sys_api->pv_cb_handle, "IHEVCE ERROR: Unable to allocate memory\n"); |
161 | 0 | ASSERT(0); |
162 | 0 | } |
163 | 7.79M | else |
164 | 7.79M | { |
165 | 7.79M | memset(ps_memtab->pv_base, 0, ps_memtab->i4_mem_size); |
166 | 7.79M | } |
167 | 7.79M | return; |
168 | 7.79M | } |
169 | | |
170 | | /*! |
171 | | ****************************************************************************** |
172 | | * \if Function name : memory_alloc \endif |
173 | | * |
174 | | * \brief |
175 | | * common memory allocate function should be used across all threads |
176 | | * it expects to reset the allocated memory and return the zero initialised |
177 | | * memory pointer whenever this function getting called |
178 | | * |
179 | | * \param[in] pv_handle : handle to memory manager |
180 | | * (currently not required can be set to null) |
181 | | * \param[in] u4_size : size of memory required |
182 | | * |
183 | | * \return |
184 | | * Memory pointer |
185 | | * |
186 | | * \author |
187 | | * Ittiam |
188 | | * |
189 | | ***************************************************************************** |
190 | | */ |
191 | | void *memory_alloc(void *pv_handle, UWORD32 u4_size) |
192 | 65.9k | { |
193 | 65.9k | (void)pv_handle; |
194 | 65.9k | void *pv_buf = malloc(u4_size); |
195 | 65.9k | if(pv_buf) |
196 | 65.9k | { |
197 | 65.9k | memset(pv_buf, 0, u4_size); |
198 | 65.9k | } |
199 | 65.9k | return (pv_buf); |
200 | 65.9k | } |
201 | | |
202 | | /*! |
203 | | ****************************************************************************** |
204 | | * \if Function name : mem_mngr_free \endif |
205 | | * |
206 | | * \brief |
207 | | * Memory manager specific free function |
208 | | * |
209 | | * \param[in] pv_handle : handle to memory manager |
210 | | * (currently not required can be set to null) |
211 | | * \param[in] ps_memtab : memory descriptor pointer |
212 | | * |
213 | | * \return |
214 | | * Memory pointer |
215 | | * |
216 | | * \author |
217 | | * Ittiam |
218 | | * |
219 | | ***************************************************************************** |
220 | | */ |
221 | | void mem_mngr_free(void *pv_handle, iv_mem_rec_t *ps_memtab) |
222 | 7.79M | { |
223 | 7.79M | (void)pv_handle; |
224 | | #ifdef X86_MINGW |
225 | | _aligned_free(ps_memtab->pv_base); |
226 | | #else |
227 | 7.79M | free(ps_memtab->pv_base); |
228 | 7.79M | #endif |
229 | 7.79M | return; |
230 | 7.79M | } |
231 | | |
232 | | /*! |
233 | | ****************************************************************************** |
234 | | * \if Function name : memory_free \endif |
235 | | * |
236 | | * \brief |
237 | | * common memory free function should be used across all threads |
238 | | * |
239 | | * \param[in] pv_handle : handle to memory manager |
240 | | * (currently not required can be set to null) |
241 | | * \param[in] pv_mem : memory to be freed |
242 | | * |
243 | | * \return |
244 | | * Memory pointer |
245 | | * |
246 | | * \author |
247 | | * Ittiam |
248 | | * |
249 | | ***************************************************************************** |
250 | | */ |
251 | | void memory_free(void *pv_handle, void *pv_mem) |
252 | 74.1k | { |
253 | 74.1k | (void)pv_handle; |
254 | 74.1k | free(pv_mem); |
255 | 74.1k | return; |
256 | 74.1k | } |
257 | | |
258 | | /*! |
259 | | ****************************************************************************** |
260 | | * \if Function name : ihevce_set_def_params \endif |
261 | | * |
262 | | * \brief |
263 | | * Set default values |
264 | | * |
265 | | * \param[in] Static params pointer |
266 | | * |
267 | | * \return |
268 | | * status |
269 | | * |
270 | | * \author |
271 | | * Ittiam |
272 | | * |
273 | | ***************************************************************************** |
274 | | */ |
275 | | IHEVCE_PLUGIN_STATUS_T ihevce_set_def_params(ihevce_static_cfg_params_t *ps_params) |
276 | 8.26k | { |
277 | 8.26k | WORD32 i, j; |
278 | | /* sanity checks */ |
279 | 8.26k | if(NULL == ps_params) |
280 | 0 | return (IHEVCE_EFAIL); |
281 | | |
282 | 8.26k | memset(ps_params, 0, sizeof(*ps_params)); |
283 | | |
284 | | /* initialsie all the parameters to default values */ |
285 | 8.26k | ps_params->i4_size = sizeof(ihevce_static_cfg_params_t); |
286 | 8.26k | ps_params->i4_save_recon = 0; |
287 | 8.26k | ps_params->i4_log_dump_level = 0; |
288 | 8.26k | ps_params->i4_enable_logo = 0; |
289 | 8.26k | ps_params->i4_enable_csv_dump = 0; |
290 | | |
291 | | /* Control to free the entropy output buffers */ |
292 | | /* 1 for non_blocking mode */ |
293 | | /* and 0 for blocking mode */ |
294 | 8.26k | ps_params->i4_outbuf_buf_free_control = 1; |
295 | | |
296 | | /* coding tools parameters */ |
297 | 8.26k | ps_params->s_coding_tools_prms.i4_size = sizeof(ihevce_coding_params_t); |
298 | 8.26k | ps_params->s_coding_tools_prms.i4_cropping_mode = 1; |
299 | 8.26k | ps_params->s_coding_tools_prms.i4_deblocking_type = 0; |
300 | 8.26k | ps_params->s_coding_tools_prms.i4_enable_entropy_sync = 0; |
301 | | // New IDR/CDR Params |
302 | 8.26k | ps_params->s_coding_tools_prms.i4_max_closed_gop_period = 0; |
303 | 8.26k | ps_params->s_coding_tools_prms.i4_min_closed_gop_period = 0; |
304 | 8.26k | ps_params->s_coding_tools_prms.i4_max_cra_open_gop_period = 60; |
305 | 8.26k | ps_params->s_coding_tools_prms.i4_max_i_open_gop_period = 0; |
306 | 8.26k | ps_params->s_coding_tools_prms.i4_max_reference_frames = -1; |
307 | 8.26k | ps_params->s_coding_tools_prms.i4_max_temporal_layers = 0; |
308 | 8.26k | ps_params->s_coding_tools_prms.i4_slice_type = 0; |
309 | 8.26k | ps_params->s_coding_tools_prms.i4_use_default_sc_mtx = 0; |
310 | 8.26k | ps_params->s_coding_tools_prms.i4_weighted_pred_enable = 0; |
311 | 8.26k | ps_params->s_coding_tools_prms.i4_vqet = 0; |
312 | | |
313 | 8.26k | ps_params->e_arch_type = ARCH_NA; |
314 | | |
315 | | /* config parameters */ |
316 | 8.26k | ps_params->s_config_prms.i4_size = sizeof(ihevce_config_prms_t); |
317 | 8.26k | ps_params->s_config_prms.i4_cu_level_rc = 1; |
318 | 8.26k | ps_params->s_config_prms.i4_init_vbv_fullness = 0; |
319 | 8.26k | ps_params->s_config_prms.i4_max_frame_qp = 51; |
320 | 8.26k | ps_params->s_config_prms.i4_max_log2_cu_size = 6; |
321 | 8.26k | ps_params->s_config_prms.i4_max_log2_tu_size = 5; |
322 | 8.26k | ps_params->s_config_prms.i4_max_search_range_horz = 512; |
323 | 8.26k | ps_params->s_config_prms.i4_max_search_range_vert = 256; |
324 | 8.26k | ps_params->s_config_prms.i4_max_tr_tree_depth_I = 1; |
325 | 8.26k | ps_params->s_config_prms.i4_max_tr_tree_depth_nI = 3; |
326 | 8.26k | ps_params->s_config_prms.i4_min_frame_qp = 1; |
327 | 8.26k | ps_params->s_config_prms.i4_min_log2_cu_size = 3; |
328 | 8.26k | ps_params->s_config_prms.i4_min_log2_tu_size = 2; |
329 | 8.26k | ps_params->s_config_prms.i4_num_frms_to_encode = -1; |
330 | 8.26k | ps_params->s_config_prms.i4_rate_control_mode = 2; |
331 | 8.26k | ps_params->s_config_prms.i4_stuffing_enable = 0; |
332 | 8.26k | ps_params->s_config_prms.i4_vbr_max_peak_rate_dur = 2000; |
333 | | |
334 | | /* LAP parameters */ |
335 | 8.26k | ps_params->s_lap_prms.i4_size = sizeof(ihevce_lap_params_t); |
336 | 8.26k | ps_params->s_lap_prms.i4_deinterlacer_enable = 0; |
337 | 8.26k | ps_params->s_lap_prms.i4_denoise_enable = 0; |
338 | 8.26k | ps_params->s_lap_prms.i4_enable_wts_ofsts = 1; |
339 | 8.26k | ps_params->s_lap_prms.i4_rc_look_ahead_pics = 0; |
340 | | |
341 | | /* Multi Thread parameters */ |
342 | 8.26k | ps_params->s_multi_thrd_prms.i4_size = sizeof(ihevce_static_multi_thread_params_t); |
343 | 8.26k | ps_params->s_multi_thrd_prms.i4_max_num_cores = 1; |
344 | 8.26k | ps_params->s_multi_thrd_prms.i4_memory_alloc_ctrl_flag = 0; |
345 | 8.26k | ps_params->s_multi_thrd_prms.i4_num_proc_groups = 1; |
346 | 8.26k | ps_params->s_multi_thrd_prms.ai4_num_cores_per_grp[0] = -1; |
347 | 8.26k | ps_params->s_multi_thrd_prms.i4_use_thrd_affinity = -1; //0; |
348 | 8.26k | memset(&ps_params->s_multi_thrd_prms.au8_core_aff_mask[0], 0, sizeof(ULWORD64) * MAX_NUM_CORES); |
349 | | |
350 | | /* Output Streams parameters */ |
351 | 8.26k | ps_params->s_out_strm_prms.i4_size = sizeof(ihevce_out_strm_params_t); |
352 | 8.26k | ps_params->s_out_strm_prms.i4_aud_enable_flags = 0; |
353 | 8.26k | ps_params->s_out_strm_prms.i4_eos_enable_flags = 0; |
354 | 8.26k | ps_params->s_out_strm_prms.i4_codec_profile = 1; |
355 | 8.26k | ps_params->s_out_strm_prms.i4_codec_tier = 0; |
356 | 8.26k | ps_params->s_out_strm_prms.i4_codec_type = 0; |
357 | 8.26k | #ifndef DISABLE_SEI |
358 | 8.26k | ps_params->s_out_strm_prms.i4_sei_buffer_period_flags = 0; |
359 | 8.26k | ps_params->s_out_strm_prms.i4_sei_enable_flag = 0; |
360 | 8.26k | ps_params->s_out_strm_prms.i4_sei_payload_enable_flag = 0; |
361 | 8.26k | ps_params->s_out_strm_prms.i4_sei_pic_timing_flags = 0; |
362 | 8.26k | ps_params->s_out_strm_prms.i4_sei_cll_enable = 0; |
363 | 8.26k | ps_params->s_out_strm_prms.u2_sei_avg_cll = 0; |
364 | 8.26k | ps_params->s_out_strm_prms.u2_sei_max_cll = 0; |
365 | 8.26k | ps_params->s_out_strm_prms.i4_sei_recovery_point_flags = 0; |
366 | 8.26k | ps_params->s_out_strm_prms.i4_sei_mastering_disp_colour_vol_flags = 0; |
367 | 8.26k | ps_params->s_out_strm_prms.i4_decoded_pic_hash_sei_flag = 0; |
368 | 8.26k | #endif |
369 | 8.26k | ps_params->s_out_strm_prms.i4_sps_at_cdr_enable = 1; |
370 | 8.26k | ps_params->s_out_strm_prms.i4_vui_enable = 0; |
371 | | /*Set the interoperability flag to 0*/ |
372 | 8.26k | ps_params->s_out_strm_prms.i4_interop_flags = 0; |
373 | | |
374 | | /* Source parameters */ |
375 | 8.26k | ps_params->s_src_prms.i4_size = sizeof(ihevce_src_params_t); |
376 | 8.26k | ps_params->s_src_prms.inp_chr_format = 1; |
377 | 8.26k | ps_params->s_src_prms.i4_chr_format = 11; |
378 | 8.26k | ps_params->s_src_prms.i4_field_pic = 0; |
379 | 8.26k | ps_params->s_src_prms.i4_frm_rate_denom = 1000; |
380 | 8.26k | ps_params->s_src_prms.i4_frm_rate_num = 30000; |
381 | 8.26k | ps_params->s_src_prms.i4_height = 0; //1080; |
382 | 8.26k | ps_params->s_src_prms.i4_input_bit_depth = 8; |
383 | 8.26k | ps_params->s_src_prms.i4_topfield_first = 1; |
384 | 8.26k | ps_params->s_src_prms.i4_width = 0; //1920; |
385 | 8.26k | ps_params->s_src_prms.i4_orig_width = 0; |
386 | 8.26k | ps_params->s_src_prms.i4_orig_height = 0; |
387 | | |
388 | | /* Target layer parameters */ |
389 | 8.26k | ps_params->s_tgt_lyr_prms.i4_size = sizeof(ihevce_tgt_layer_params_t); |
390 | 8.26k | ps_params->s_tgt_lyr_prms.i4_enable_temporal_scalability = 0; |
391 | 8.26k | ps_params->s_tgt_lyr_prms.i4_internal_bit_depth = 8; |
392 | 8.26k | ps_params->s_tgt_lyr_prms.i4_mbr_quality_setting = IHEVCE_MBR_HIGH_QUALITY; |
393 | 8.26k | ps_params->s_tgt_lyr_prms.i4_multi_res_layer_reuse = 0; |
394 | 8.26k | ps_params->s_tgt_lyr_prms.i4_num_res_layers = 1; |
395 | 8.26k | ps_params->s_tgt_lyr_prms.i4_mres_single_out = 0; |
396 | 8.26k | ps_params->s_tgt_lyr_prms.i4_start_res_id = 0; |
397 | 8.26k | ps_params->s_tgt_lyr_prms.pf_scale_chroma = NULL; |
398 | 8.26k | ps_params->s_tgt_lyr_prms.pf_scale_luma = NULL; |
399 | 8.26k | ps_params->s_tgt_lyr_prms.pv_scaler_handle = NULL; |
400 | | |
401 | | /* target parameters */ |
402 | 16.5k | for(i = 0; i < IHEVCE_MAX_NUM_RESOLUTIONS; i++) |
403 | 8.26k | { |
404 | 8.26k | ps_params->s_tgt_lyr_prms.as_tgt_params[i].i4_size = sizeof(ihevce_tgt_params_t); |
405 | 16.5k | for(j = 0; j < IHEVCE_MAX_NUM_BITRATES; j++) |
406 | 8.26k | { |
407 | 8.26k | ps_params->s_tgt_lyr_prms.as_tgt_params[i].ai4_frame_qp[j] = 32; |
408 | 8.26k | ps_params->s_tgt_lyr_prms.as_tgt_params[i].ai4_tgt_bitrate[j] = 5000000; |
409 | 8.26k | ps_params->s_tgt_lyr_prms.as_tgt_params[i].ai4_peak_bitrate[j] = 10000000; |
410 | 8.26k | ps_params->s_tgt_lyr_prms.as_tgt_params[i].ai4_max_vbv_buffer_size[j] = -1; |
411 | 8.26k | } |
412 | 8.26k | ps_params->s_tgt_lyr_prms.as_tgt_params[i].i4_codec_level = 156; |
413 | 8.26k | ps_params->s_tgt_lyr_prms.as_tgt_params[i].i4_frm_rate_scale_factor = 1; |
414 | 8.26k | ps_params->s_tgt_lyr_prms.as_tgt_params[i].i4_height = 0; |
415 | 8.26k | ps_params->s_tgt_lyr_prms.as_tgt_params[i].i4_num_bitrate_instances = 1; |
416 | 8.26k | ps_params->s_tgt_lyr_prms.as_tgt_params[i].i4_quality_preset = IHEVCE_QUALITY_P5; |
417 | 8.26k | ps_params->s_tgt_lyr_prms.as_tgt_params[i].i4_width = 0; |
418 | 8.26k | } |
419 | | |
420 | | /* SEI VUI parameters */ |
421 | 8.26k | ps_params->s_vui_sei_prms.u1_aspect_ratio_info_present_flag = 0; |
422 | 8.26k | ps_params->s_vui_sei_prms.au1_aspect_ratio_idc[0] = 255; |
423 | 8.26k | ps_params->s_vui_sei_prms.au2_sar_width[0] = 4; |
424 | 8.26k | ps_params->s_vui_sei_prms.au2_sar_height[0] = 3; |
425 | 8.26k | ps_params->s_vui_sei_prms.u1_overscan_info_present_flag = 0; |
426 | 8.26k | ps_params->s_vui_sei_prms.u1_overscan_appropriate_flag = 0; |
427 | 8.26k | ps_params->s_vui_sei_prms.u1_video_signal_type_present_flag = 1; |
428 | 8.26k | ps_params->s_vui_sei_prms.u1_video_format = 5; |
429 | 8.26k | ps_params->s_vui_sei_prms.u1_video_full_range_flag = 1; |
430 | 8.26k | ps_params->s_vui_sei_prms.u1_colour_description_present_flag = 0; |
431 | 8.26k | ps_params->s_vui_sei_prms.u1_colour_primaries = 2; |
432 | 8.26k | ps_params->s_vui_sei_prms.u1_transfer_characteristics = 2; |
433 | 8.26k | ps_params->s_vui_sei_prms.u1_matrix_coefficients = 2; |
434 | 8.26k | ps_params->s_vui_sei_prms.u1_chroma_loc_info_present_flag = 0; |
435 | 8.26k | ps_params->s_vui_sei_prms.u1_chroma_sample_loc_type_top_field = 0; |
436 | 8.26k | ps_params->s_vui_sei_prms.u1_chroma_sample_loc_type_bottom_field = 0; |
437 | 8.26k | ps_params->s_vui_sei_prms.u1_vui_hrd_parameters_present_flag = 0; |
438 | 8.26k | ps_params->s_vui_sei_prms.u1_timing_info_present_flag = 0; |
439 | 8.26k | ps_params->s_vui_sei_prms.u1_nal_hrd_parameters_present_flag = 0; |
440 | | |
441 | | /* Setting sysAPIs to NULL */ |
442 | 8.26k | memset(&ps_params->s_sys_api, 0, sizeof(ihevce_sys_api_t)); |
443 | | |
444 | | /* Multi pass parameters */ |
445 | 8.26k | memset(&ps_params->s_pass_prms, 0, sizeof(ihevce_pass_prms_t)); |
446 | 8.26k | ps_params->s_pass_prms.i4_size = sizeof(ihevce_pass_prms_t); |
447 | | |
448 | | /* Tile parameters */ |
449 | 8.26k | ps_params->s_app_tile_params.i4_size = sizeof(ihevce_app_tile_params_t); |
450 | 8.26k | ps_params->s_app_tile_params.i4_tiles_enabled_flag = 0; |
451 | 8.26k | ps_params->s_app_tile_params.i4_uniform_spacing_flag = 1; |
452 | 8.26k | ps_params->s_app_tile_params.i4_num_tile_cols = 1; |
453 | 8.26k | ps_params->s_app_tile_params.i4_num_tile_rows = 1; |
454 | | |
455 | 8.26k | ps_params->s_slice_params.i4_slice_segment_mode = 0; |
456 | 8.26k | ps_params->s_slice_params.i4_slice_segment_argument = 1300; |
457 | | |
458 | 8.26k | return (IHEVCE_EOK); |
459 | 8.26k | } |
460 | | |
461 | | /*! |
462 | | ****************************************************************************** |
463 | | * \if Function name : ihevce_cmds_error_report \endif |
464 | | * |
465 | | * \brief |
466 | | * Call back from encoder to report errors |
467 | | * |
468 | | * \param[in] pv_error_handling_cb_handle |
469 | | * \param[in] i4_error_code |
470 | | * \param[in] i4_cmd_type |
471 | | * \param[in] i4_id |
472 | | * |
473 | | * \return |
474 | | * None |
475 | | * |
476 | | * \author |
477 | | * Ittiam |
478 | | * |
479 | | ***************************************************************************** |
480 | | */ |
481 | | IV_API_CALL_STATUS_T ihevce_cmds_error_report( |
482 | | void *pv_cb_handle, WORD32 i4_error_code, WORD32 i4_cmd_type, WORD32 i4_buf_id) |
483 | 0 | { |
484 | | /*local variables*/ |
485 | 0 | plugin_ctxt_t *plugin_ctxt = (plugin_ctxt_t *)pv_cb_handle; |
486 | 0 | ihevce_static_cfg_params_t *ps_static_cfg_params = |
487 | 0 | ((ihevce_hle_ctxt_t *)plugin_ctxt->pv_hle_interface_ctxt)->ps_static_cfg_prms; |
488 | |
|
489 | 0 | if(i4_cmd_type == 0) |
490 | 0 | ps_static_cfg_params->s_sys_api.ihevce_printf( |
491 | 0 | ps_static_cfg_params->s_sys_api.pv_cb_handle, |
492 | 0 | "PLUGIN ERROR: Asynchronous Buffer Error %d in Buffer Id %d", |
493 | 0 | i4_error_code, |
494 | 0 | i4_buf_id); |
495 | 0 | else |
496 | 0 | ps_static_cfg_params->s_sys_api.ihevce_printf( |
497 | 0 | ps_static_cfg_params->s_sys_api.pv_cb_handle, |
498 | 0 | "PLUGIN ERROR: Synchronous Buffer Error %d in Buffer Id %d", |
499 | 0 | i4_error_code, |
500 | 0 | i4_buf_id); |
501 | |
|
502 | 0 | return (IV_SUCCESS); |
503 | 0 | } |
504 | | |
505 | | /*! |
506 | | ****************************************************************************** |
507 | | * \if Function name : ihevce_strm_fill_done \endif |
508 | | * |
509 | | * \brief |
510 | | * Call back from encoder when Bitstream is ready to consume |
511 | | * |
512 | | * \param[in] |
513 | | * \param[in] |
514 | | * \param[in] |
515 | | * |
516 | | * \return |
517 | | * None |
518 | | * |
519 | | * \author |
520 | | * Ittiam |
521 | | * |
522 | | ***************************************************************************** |
523 | | */ |
524 | | IV_API_CALL_STATUS_T |
525 | | ihevce_strm_fill_done(void *pv_ctxt, void *pv_curr_out, WORD32 i4_br_id, WORD32 i4_res_id) |
526 | 166k | { |
527 | | /* local variables */ |
528 | 166k | plugin_ctxt_t *ps_ctxt = (plugin_ctxt_t *)pv_ctxt; |
529 | 166k | app_ctxt_t *ps_app_ctxt = &ps_ctxt->s_app_ctxt; |
530 | 166k | out_strm_prms_t *ps_out_strm_prms = &ps_app_ctxt->as_out_strm_prms[i4_res_id][i4_br_id]; |
531 | 166k | void *pv_app_out_strm_buf_mutex_hdl = ps_out_strm_prms->pv_app_out_strm_buf_mutex_hdl; |
532 | 166k | void *pv_app_out_strm_buf_cond_var_hdl = ps_out_strm_prms->pv_app_out_strm_buf_cond_var_hdl; |
533 | 166k | iv_output_data_buffs_t *ps_curr_out = (iv_output_data_buffs_t *)pv_curr_out; |
534 | 166k | WORD32 end_flag = ps_curr_out->i4_end_flag; |
535 | 166k | WORD32 osal_result; |
536 | | |
537 | | /* ------ output dump stream -- */ |
538 | 166k | if((WORD32)IV_FAIL != ps_curr_out->i4_process_ret_sts) |
539 | 166k | { |
540 | 166k | if(0 != ps_curr_out->i4_bytes_generated) |
541 | 157k | { |
542 | | /* accumulate the total bits generated */ |
543 | 157k | (ps_out_strm_prms->u8_total_bits) += ps_curr_out->i4_bytes_generated * 8; |
544 | 157k | (ps_out_strm_prms->u4_num_frms_enc)++; |
545 | 157k | } |
546 | 166k | } |
547 | | |
548 | | /****** Lock the critical section ******/ |
549 | 166k | osal_result = osal_mutex_lock(pv_app_out_strm_buf_mutex_hdl); |
550 | 166k | if(OSAL_SUCCESS != osal_result) |
551 | 0 | return (IV_FAIL); |
552 | | |
553 | | /* Update the end flag to communicate with the o/p thread */ |
554 | 166k | ps_app_ctxt->ai4_out_strm_end_flag[i4_res_id][i4_br_id] = end_flag; |
555 | | |
556 | | /* set the produced status of the buffer */ |
557 | 166k | { |
558 | 166k | WORD32 idx = ps_curr_out->i4_cb_buf_id; |
559 | | |
560 | 166k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][idx].i4_timestamp_low = |
561 | 166k | ps_curr_out->i4_out_timestamp_low; |
562 | 166k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][idx].i4_timestamp_high = |
563 | 166k | ps_curr_out->i4_out_timestamp_high; |
564 | 166k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][idx].i4_bytes_gen = |
565 | 166k | ps_curr_out->i4_bytes_generated; |
566 | 166k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][idx].i4_is_key_frame = 0; |
567 | 166k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][idx].i4_end_flag = end_flag; |
568 | | |
569 | 166k | if((IV_IDR_FRAME == ps_curr_out->i4_encoded_frame_type) || |
570 | 166k | (IV_I_FRAME == ps_curr_out->i4_encoded_frame_type)) |
571 | 41.2k | { |
572 | 41.2k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][idx].i4_is_key_frame = 1; |
573 | 41.2k | } |
574 | | |
575 | | /* set the buffer as produced */ |
576 | 166k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][idx].i4_is_prod = 1; |
577 | 166k | } |
578 | | |
579 | | /****** Wake ******/ |
580 | 166k | osal_cond_var_signal(pv_app_out_strm_buf_cond_var_hdl); |
581 | | |
582 | | /****** Unlock the critical section ******/ |
583 | 166k | osal_result = osal_mutex_unlock(pv_app_out_strm_buf_mutex_hdl); |
584 | 166k | if(OSAL_SUCCESS != osal_result) |
585 | 0 | return (IV_FAIL); |
586 | | |
587 | 166k | return (IV_SUCCESS); |
588 | 166k | } |
589 | | |
590 | | /*! |
591 | | ****************************************************************************** |
592 | | * \if Function name : ihevce_plugin_init \endif |
593 | | * |
594 | | * \brief |
595 | | * Initialises the encoder context and threads |
596 | | * |
597 | | * \param[in] Static params pointer |
598 | | * |
599 | | * \return |
600 | | * status |
601 | | * |
602 | | * \author |
603 | | * Ittiam |
604 | | * |
605 | | ***************************************************************************** |
606 | | */ |
607 | | IHEVCE_PLUGIN_STATUS_T ihevce_init(ihevce_static_cfg_params_t *ps_params, void **ppv_ihevce_hdl) |
608 | 8.26k | { |
609 | | /* local variables */ |
610 | 8.26k | plugin_ctxt_t *ps_ctxt; |
611 | 8.26k | app_ctxt_t *ps_app_ctxt; |
612 | 8.26k | ihevce_hle_ctxt_t *ps_interface_ctxt; |
613 | 8.26k | ihevce_sys_api_t *ps_sys_api; |
614 | 8.26k | osal_cb_funcs_t s_cb_funcs; |
615 | 8.26k | WORD32 status = 0; |
616 | | |
617 | | /* sanity checks */ |
618 | 8.26k | if(NULL == ps_params) |
619 | 0 | return (IHEVCE_EFAIL); |
620 | | |
621 | 8.26k | if(NULL == ppv_ihevce_hdl) |
622 | 0 | return (IHEVCE_EFAIL); |
623 | | |
624 | | /* set the handle to null by default */ |
625 | 8.26k | *ppv_ihevce_hdl = NULL; |
626 | | |
627 | | /* Initiallizing system apis */ |
628 | 8.26k | ps_sys_api = &ps_params->s_sys_api; |
629 | 8.26k | ihevce_init_sys_api(NULL, ps_sys_api); |
630 | | |
631 | | /* --------------------------------------------------------------------- */ |
632 | | /* Query and print Encoder version */ |
633 | | /* --------------------------------------------------------------------- */ |
634 | 8.26k | ps_sys_api->ihevce_printf( |
635 | 8.26k | ps_sys_api->pv_cb_handle, "Encoder version %s\n\n", ihevce_get_encoder_version()); |
636 | | |
637 | | /* --------------------------------------------------------------------- */ |
638 | | /* Plugin Handle create */ |
639 | | /* --------------------------------------------------------------------- */ |
640 | 8.26k | ps_ctxt = (plugin_ctxt_t *)memory_alloc(NULL, sizeof(plugin_ctxt_t)); |
641 | 8.26k | if(NULL == ps_ctxt) |
642 | 0 | { |
643 | 0 | ps_sys_api->ihevce_printf( |
644 | 0 | ps_sys_api->pv_cb_handle, "IHEVCE ERROR: Error in Plugin initialization\n"); |
645 | 0 | return (IHEVCE_EFAIL); |
646 | 0 | } |
647 | | |
648 | | /* initialise memory call backs */ |
649 | 8.26k | ps_ctxt->ihevce_mem_alloc = memory_alloc; |
650 | 8.26k | ps_ctxt->ihevce_mem_free = memory_free; |
651 | | |
652 | 8.26k | ps_ctxt->u8_num_frames_encoded = 0; |
653 | | |
654 | 8.26k | if((0 == ps_params->i4_res_id) && (0 == ps_params->i4_br_id)) |
655 | 8.26k | { |
656 | | /* --------------------------------------------------------------------- */ |
657 | | /* OSAL Handle create */ |
658 | | /* --------------------------------------------------------------------- */ |
659 | 8.26k | ps_ctxt->pv_osal_handle = memory_alloc(NULL, OSAL_HANDLE_SIZE); |
660 | | |
661 | | /* Initialize OSAL call back functions */ |
662 | 8.26k | s_cb_funcs.mmr_handle = NULL; |
663 | 8.26k | s_cb_funcs.osal_alloc = memory_alloc; |
664 | 8.26k | s_cb_funcs.osal_free = memory_free; |
665 | | |
666 | 8.26k | status = osal_init(ps_ctxt->pv_osal_handle); |
667 | 8.26k | if(OSAL_SUCCESS != status) |
668 | 0 | { |
669 | 0 | ps_sys_api->ihevce_printf( |
670 | 0 | ps_sys_api->pv_cb_handle, "IHEVCE ERROR: Error in OSAL initialization\n"); |
671 | 0 | return (IHEVCE_EFAIL); |
672 | 0 | } |
673 | | |
674 | 8.26k | status = osal_register_callbacks(ps_ctxt->pv_osal_handle, &s_cb_funcs); |
675 | 8.26k | if(OSAL_SUCCESS != status) |
676 | 0 | { |
677 | 0 | ps_sys_api->ihevce_printf( |
678 | 0 | ps_sys_api->pv_cb_handle, "IHEVCE ERROR: Error in OSAL call back registration\n"); |
679 | 0 | return (IHEVCE_EFAIL); |
680 | 0 | } |
681 | | |
682 | | /* --------------------------------------------------------------------- */ |
683 | | /* Thread affinity Initialization */ |
684 | | /* --------------------------------------------------------------------- */ |
685 | 8.26k | if(ps_params->s_multi_thrd_prms.i4_use_thrd_affinity) |
686 | 8.26k | { |
687 | 8.26k | WORD32 i4_ctr; |
688 | | |
689 | | /* loop over all the cores */ |
690 | 16.5k | for(i4_ctr = 0; i4_ctr < ps_params->s_multi_thrd_prms.i4_max_num_cores; i4_ctr++) |
691 | 8.26k | { |
692 | | /* All cores are logical cores */ |
693 | 8.26k | ps_params->s_multi_thrd_prms.au8_core_aff_mask[i4_ctr] = ((ULWORD64)1 << i4_ctr); |
694 | 8.26k | } |
695 | 8.26k | } |
696 | | |
697 | | /* --------------------------------------------------------------------- */ |
698 | | /* Context Initialization */ |
699 | | /* --------------------------------------------------------------------- */ |
700 | 8.26k | ps_app_ctxt = &ps_ctxt->s_app_ctxt; |
701 | | |
702 | 8.26k | ps_ctxt->ps_static_cfg_prms = (ihevce_static_cfg_params_t *)ps_ctxt->ihevce_mem_alloc( |
703 | 8.26k | NULL, sizeof(ihevce_static_cfg_params_t)); |
704 | 8.26k | if(NULL == ps_ctxt->ps_static_cfg_prms) |
705 | 0 | { |
706 | 0 | ps_sys_api->ihevce_printf( |
707 | 0 | ps_sys_api->pv_cb_handle, "IHEVCE ERROR: Error in Plugin memory initialization\n"); |
708 | 0 | return (IHEVCE_EFAIL); |
709 | 0 | } |
710 | | |
711 | 8.26k | ps_params->apF_csv_file[0][0] = NULL; |
712 | | |
713 | | /* set the memory manager handle to NULL */ |
714 | 8.26k | ps_app_ctxt->pv_mem_mngr_handle = NULL; |
715 | | |
716 | | /* --------------------------------------------------------------------- */ |
717 | | /* Back up the static params passed by caller */ |
718 | | /* --------------------------------------------------------------------- */ |
719 | 8.26k | memcpy(ps_ctxt->ps_static_cfg_prms, ps_params, sizeof(ihevce_static_cfg_params_t)); |
720 | | |
721 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_orig_width = |
722 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_width; |
723 | 8.26k | if(HEVCE_MIN_WIDTH > ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_width) |
724 | 5.84k | { |
725 | 5.84k | ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_width = HEVCE_MIN_WIDTH; |
726 | 5.84k | } |
727 | | |
728 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_orig_height = |
729 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_height; |
730 | 8.26k | if(HEVCE_MIN_HEIGHT > ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_height) |
731 | 6.39k | { |
732 | 6.39k | ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_height = HEVCE_MIN_HEIGHT; |
733 | 6.39k | } |
734 | | |
735 | | /* setting tgt width and height same as src width and height */ |
736 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[0].i4_width = |
737 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_width; |
738 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[0].i4_height = |
739 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_height; |
740 | | |
741 | | /* setting key frame interval */ |
742 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period = |
743 | 8.26k | MIN(MAX_NUM_FRM_IN_GOP, |
744 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_coding_tools_prms.i4_max_closed_gop_period); |
745 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_coding_tools_prms.i4_max_cra_open_gop_period = |
746 | 8.26k | MIN(MAX_NUM_FRM_IN_GOP, |
747 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_coding_tools_prms.i4_max_cra_open_gop_period); |
748 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_coding_tools_prms.i4_max_i_open_gop_period = |
749 | 8.26k | MIN(MAX_NUM_FRM_IN_GOP, |
750 | 8.26k | ps_ctxt->ps_static_cfg_prms->s_coding_tools_prms.i4_max_i_open_gop_period); |
751 | | |
752 | | /* entropy sync is disabled if there is only one CTB row */ |
753 | 8.26k | if(ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_height <= |
754 | 8.26k | (1 << ps_ctxt->ps_static_cfg_prms->s_config_prms.i4_max_log2_cu_size)) |
755 | 6.46k | { |
756 | 6.46k | ps_ctxt->ps_static_cfg_prms->s_coding_tools_prms.i4_enable_entropy_sync = 0; |
757 | 6.46k | } |
758 | | |
759 | | /* --------------------------------------------------------------------- */ |
760 | | /* High Level Encoder context init */ |
761 | | /* --------------------------------------------------------------------- */ |
762 | 8.26k | ps_interface_ctxt = |
763 | 8.26k | (ihevce_hle_ctxt_t *)ps_ctxt->ihevce_mem_alloc(NULL, sizeof(ihevce_hle_ctxt_t)); |
764 | 8.26k | if(NULL == ps_interface_ctxt) |
765 | 0 | { |
766 | 0 | ps_sys_api->ihevce_printf( |
767 | 0 | ps_sys_api->pv_cb_handle, |
768 | 0 | "IHEVCE ERROR: Error in Plugin HLE memory initialization\n"); |
769 | 0 | return (IHEVCE_EFAIL); |
770 | 0 | } |
771 | 8.26k | ps_interface_ctxt->i4_size = sizeof(ihevce_hle_ctxt_t); |
772 | | |
773 | 8.26k | ps_ctxt->pv_hle_interface_ctxt = ps_interface_ctxt; |
774 | | |
775 | | /* store the static config parameters pointer */ |
776 | 8.26k | ps_interface_ctxt->ps_static_cfg_prms = ps_ctxt->ps_static_cfg_prms; |
777 | | |
778 | | /* initialise the interface strucure parameters */ |
779 | 8.26k | ps_interface_ctxt->pv_inp_cb_handle = (void *)ps_ctxt; |
780 | 8.26k | ps_interface_ctxt->pv_out_cb_handle = (void *)ps_ctxt; |
781 | 8.26k | ps_interface_ctxt->pv_recon_cb_handle = (void *)ps_ctxt; |
782 | | |
783 | 8.26k | ps_interface_ctxt->pv_osal_handle = ps_ctxt->pv_osal_handle; |
784 | 8.26k | ps_interface_ctxt->ihevce_mem_alloc = mem_mngr_alloc; |
785 | 8.26k | ps_interface_ctxt->ihevce_mem_free = mem_mngr_free; |
786 | 8.26k | ps_interface_ctxt->i4_hle_init_done = 0; |
787 | 8.26k | ps_interface_ctxt->pv_mem_mgr_hdl = ps_app_ctxt->pv_mem_mngr_handle; |
788 | | |
789 | | /* reigter the callbacks */ |
790 | 8.26k | ps_interface_ctxt->ihevce_output_strm_fill_done = ihevce_strm_fill_done; |
791 | 8.26k | ps_interface_ctxt->ihevce_output_recon_fill_done = NULL; |
792 | 8.26k | ps_interface_ctxt->ihevce_set_free_input_buff = NULL; |
793 | | |
794 | | /*Added for run time or create time creation*/ |
795 | 8.26k | ps_interface_ctxt->i4_create_time_input_allocation = (WORD32)CREATE_TIME_ALLOCATION_INPUT; |
796 | 8.26k | ps_interface_ctxt->i4_create_time_output_allocation = (WORD32)CREATE_TIME_ALLOCATION_OUTPUT; |
797 | | |
798 | 8.26k | ps_interface_ctxt->ihevce_cmds_error_report = ihevce_cmds_error_report; |
799 | 8.26k | ps_interface_ctxt->pv_cmd_err_cb_handle = (void *)ps_ctxt; |
800 | | |
801 | | /* --------------------------------------------------------------------- */ |
802 | | /* High Level Encoder Instance Creation */ |
803 | | /* --------------------------------------------------------------------- */ |
804 | 8.26k | status = ihevce_hle_interface_create(ps_interface_ctxt); |
805 | 8.26k | if((WORD32)IV_FAIL == status) |
806 | 39 | { |
807 | 39 | ihevce_hle_interface_delete(ps_interface_ctxt); |
808 | | |
809 | 39 | memory_free(NULL, ps_interface_ctxt); |
810 | | |
811 | | /* free static config memory */ |
812 | 39 | ps_ctxt->ihevce_mem_free(NULL, ps_ctxt->ps_static_cfg_prms); |
813 | | |
814 | | /* free osal handle */ |
815 | 39 | memory_free(NULL, ps_ctxt->pv_osal_handle); |
816 | | |
817 | | /* free plugin ctxt memory */ |
818 | 39 | memory_free(NULL, ps_ctxt); |
819 | | |
820 | 39 | ps_sys_api->ihevce_printf( |
821 | 39 | ps_sys_api->pv_cb_handle, "IHEVCE ERROR: Error in Plugin HLE create failed\n"); |
822 | 39 | return (IHEVCE_EFAIL); |
823 | 39 | } |
824 | | |
825 | | /* --------------------------------------------------------------------- */ |
826 | | /* Input Output and Command buffer allocation */ |
827 | | /* --------------------------------------------------------------------- */ |
828 | 8.22k | { |
829 | 8.22k | WORD32 ctr; |
830 | 8.22k | WORD32 buf_size; |
831 | 8.22k | UWORD8 *pu1_tmp_buf; |
832 | 8.22k | WORD32 i4_res_id; |
833 | 8.22k | WORD32 i4_br_id; |
834 | 8.22k | WORD32 i4_num_resolutions; |
835 | 8.22k | WORD32 ai4_num_bitrate_instances[IHEVCE_MAX_NUM_RESOLUTIONS] = { 1 }; |
836 | 8.22k | iv_input_bufs_req_t s_input_bufs_req; |
837 | 8.22k | iv_res_layer_output_bufs_req_t s_res_layer_output_bufs_req; |
838 | 8.22k | iv_res_layer_recon_bufs_req_t s_res_layer_recon_bufs_req; |
839 | | |
840 | | /* local array of pointers */ |
841 | 8.22k | void *apv_inp_luma_bufs[MAX_NUM_INP_DATA_BUFS]; |
842 | 8.22k | void *apv_inp_cb_bufs[MAX_NUM_INP_DATA_BUFS]; |
843 | 8.22k | void *apv_inp_cr_bufs[MAX_NUM_INP_DATA_BUFS]; |
844 | 8.22k | void *apv_inp_sync_bufs[MAX_NUM_INP_CTRL_SYNC_BUFS]; |
845 | 8.22k | void *apv_inp_async_bufs[MAX_NUM_INP_CTRL_ASYNC_BUFS]; |
846 | 8.22k | void *apv_out_data_bufs[IHEVCE_MAX_NUM_RESOLUTIONS][IHEVCE_MAX_NUM_BITRATES] |
847 | 8.22k | [MAX_NUM_OUT_DATA_BUFS]; |
848 | | |
849 | | /* get the number of resolutions */ |
850 | 8.22k | i4_num_resolutions = ps_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_num_res_layers; |
851 | | |
852 | | /* set the size of the structure */ |
853 | 8.22k | s_input_bufs_req.i4_size = sizeof(iv_input_bufs_req_t); |
854 | 8.22k | s_res_layer_output_bufs_req.i4_size = sizeof(iv_res_layer_output_bufs_req_t); |
855 | 8.22k | s_res_layer_recon_bufs_req.i4_size = sizeof(iv_res_layer_recon_bufs_req_t); |
856 | | |
857 | | /* loop over num resolutions */ |
858 | 16.4k | for(i4_res_id = 0; i4_res_id < i4_num_resolutions; i4_res_id++) |
859 | 8.22k | { |
860 | | /* store the number of bitrates */ |
861 | 8.22k | ai4_num_bitrate_instances[i4_res_id] = |
862 | 8.22k | ps_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_res_id] |
863 | 8.22k | .i4_num_bitrate_instances; |
864 | | |
865 | | /* loop over num bitrates */ |
866 | 16.4k | for(i4_br_id = 0; i4_br_id < ai4_num_bitrate_instances[i4_res_id]; i4_br_id++) |
867 | 8.22k | { |
868 | 8.22k | s_res_layer_output_bufs_req.s_output_buf_req[i4_res_id][i4_br_id].i4_size = |
869 | 8.22k | sizeof(iv_output_bufs_req_t); |
870 | 8.22k | } |
871 | 8.22k | } |
872 | | |
873 | | /* call Query I/O buffer */ |
874 | 8.22k | status = ihevce_query_io_buf_req( |
875 | 8.22k | ps_interface_ctxt, |
876 | 8.22k | &s_input_bufs_req, |
877 | 8.22k | &s_res_layer_output_bufs_req, |
878 | 8.22k | &s_res_layer_recon_bufs_req); |
879 | | |
880 | | /* check on the requirements against the MAX of application */ |
881 | | /* should be present only for debug purpose */ |
882 | | |
883 | | /* --------------- Input data buffers init ---------------------- */ |
884 | | /* allocate memory for input buffers */ |
885 | 8.22k | if(ps_interface_ctxt->i4_create_time_input_allocation == 1) |
886 | 8.22k | { |
887 | 8.22k | buf_size = s_input_bufs_req.i4_min_size_uv_buf + s_input_bufs_req.i4_min_size_y_buf; |
888 | 8.22k | ps_ctxt->s_memtab_inp_data_buf.i4_size = sizeof(iv_mem_rec_t); |
889 | 8.22k | ps_ctxt->s_memtab_inp_data_buf.i4_mem_alignment = 4; |
890 | 8.22k | ps_ctxt->s_memtab_inp_data_buf.i4_mem_size = |
891 | 8.22k | (s_input_bufs_req.i4_min_num_yuv_bufs + XTRA_INP_DATA_BUFS) * buf_size; |
892 | 8.22k | ps_ctxt->s_memtab_inp_data_buf.e_mem_type = IV_EXT_CACHEABLE_NUMA_NODE0_MEM; |
893 | | |
894 | 8.22k | mem_mngr_alloc( |
895 | 8.22k | ps_app_ctxt->pv_mem_mngr_handle, ps_sys_api, &ps_ctxt->s_memtab_inp_data_buf); |
896 | | |
897 | 8.22k | pu1_tmp_buf = (UWORD8 *)ps_ctxt->s_memtab_inp_data_buf.pv_base; |
898 | | |
899 | 8.22k | if(NULL == pu1_tmp_buf) |
900 | 0 | { |
901 | 0 | ps_sys_api->ihevce_printf( |
902 | 0 | ps_sys_api->pv_cb_handle, "IHEVCE ERROR: Error in allocate memory\n"); |
903 | 0 | return (IHEVCE_EFAIL); |
904 | 0 | } |
905 | | |
906 | | /* loop to initialise the buffer pointer */ |
907 | 31.0k | for(ctr = 0; ctr < s_input_bufs_req.i4_min_num_yuv_bufs + XTRA_INP_DATA_BUFS; ctr++) |
908 | 22.7k | { |
909 | 22.7k | apv_inp_luma_bufs[ctr] = pu1_tmp_buf; |
910 | 22.7k | apv_inp_cb_bufs[ctr] = pu1_tmp_buf + s_input_bufs_req.i4_min_size_y_buf; |
911 | 22.7k | apv_inp_cr_bufs[ctr] = NULL; /* 420SP case */ |
912 | | |
913 | | /* increment the input buffer pointer to next buffer */ |
914 | 22.7k | pu1_tmp_buf += buf_size; |
915 | 22.7k | } |
916 | 8.22k | } |
917 | | |
918 | | /* --------------- Output data buffers init ---------------------- */ |
919 | | |
920 | | /* loop over num resolutions */ |
921 | 16.4k | for(i4_res_id = 0; i4_res_id < i4_num_resolutions; i4_res_id++) |
922 | 8.22k | { |
923 | 16.4k | for(i4_br_id = 0; i4_br_id < ai4_num_bitrate_instances[i4_res_id]; i4_br_id++) |
924 | 8.22k | { |
925 | 8.22k | buf_size = s_res_layer_output_bufs_req.s_output_buf_req[i4_res_id][i4_br_id] |
926 | 8.22k | .i4_min_size_bitstream_buf; |
927 | | |
928 | 8.22k | ps_ctxt->as_memtab_out_data_buf[i4_res_id][i4_br_id].i4_size = |
929 | 8.22k | sizeof(iv_mem_rec_t); |
930 | 8.22k | ps_ctxt->as_memtab_out_data_buf[i4_res_id][i4_br_id].i4_mem_alignment = 4; |
931 | | |
932 | 8.22k | if(!ps_interface_ctxt->i4_create_time_output_allocation) |
933 | 8.22k | { |
934 | 8.22k | ps_ctxt->as_memtab_out_data_buf[i4_res_id][i4_br_id].i4_mem_size = |
935 | 8.22k | (s_res_layer_output_bufs_req.s_output_buf_req[i4_res_id][i4_br_id] |
936 | 8.22k | .i4_min_num_out_bufs + |
937 | 8.22k | XTRA_OUT_DATA_BUFS) * |
938 | 8.22k | buf_size; |
939 | 8.22k | } |
940 | 0 | else |
941 | 0 | { |
942 | 0 | ps_ctxt->as_memtab_out_data_buf[i4_res_id][i4_br_id].i4_mem_size = |
943 | 0 | (s_res_layer_output_bufs_req.s_output_buf_req[i4_res_id][i4_br_id] |
944 | 0 | .i4_min_num_out_bufs) * |
945 | 0 | buf_size; |
946 | 0 | } |
947 | 8.22k | ps_ctxt->as_memtab_out_data_buf[i4_res_id][i4_br_id].e_mem_type = |
948 | 8.22k | IV_EXT_CACHEABLE_NUMA_NODE1_MEM; |
949 | | |
950 | 8.22k | mem_mngr_alloc( |
951 | 8.22k | ps_app_ctxt->pv_mem_mngr_handle, |
952 | 8.22k | ps_sys_api, |
953 | 8.22k | &ps_ctxt->as_memtab_out_data_buf[i4_res_id][i4_br_id]); |
954 | | |
955 | 8.22k | pu1_tmp_buf = |
956 | 8.22k | (UWORD8 *)ps_ctxt->as_memtab_out_data_buf[i4_res_id][i4_br_id].pv_base; |
957 | 8.22k | if(NULL == pu1_tmp_buf) |
958 | 0 | { |
959 | 0 | ps_sys_api->ihevce_printf( |
960 | 0 | ps_sys_api->pv_cb_handle, "IHEVCE ERROR: Error in allocate memory\n"); |
961 | 0 | return (IHEVCE_EFAIL); |
962 | 0 | } |
963 | | |
964 | 8.22k | if(ps_interface_ctxt->i4_create_time_output_allocation == 1) |
965 | 0 | { |
966 | | /* loop to initialise the buffer pointer */ |
967 | 0 | for(ctr = 0; |
968 | 0 | ctr < s_res_layer_output_bufs_req.s_output_buf_req[i4_res_id][i4_br_id] |
969 | 0 | .i4_min_num_out_bufs; |
970 | 0 | ctr++) |
971 | 0 | { |
972 | 0 | apv_out_data_bufs[i4_res_id][i4_br_id][ctr] = pu1_tmp_buf; |
973 | 0 | pu1_tmp_buf += buf_size; |
974 | 0 | } |
975 | 0 | } |
976 | 8.22k | else |
977 | 8.22k | { |
978 | 8.22k | WORD32 i4_num_out_bufs = |
979 | 8.22k | s_res_layer_output_bufs_req.s_output_buf_req[i4_res_id][i4_br_id] |
980 | 8.22k | .i4_min_num_out_bufs + |
981 | 8.22k | XTRA_OUT_DATA_BUFS; |
982 | 8.22k | ps_ctxt->i4_num_out_bufs = i4_num_out_bufs; |
983 | 8.22k | ps_ctxt->ai4_free_out_buf_idx[i4_res_id][i4_br_id] = 0; |
984 | 8.22k | ps_ctxt->i4_prod_out_buf_idx = 0; |
985 | | |
986 | | /* Assert to make sure ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][] array |
987 | | has more bufs than ps_ctxt->i4_num_out_bufs. Needed to identify |
988 | | wrap-around case */ |
989 | 8.22k | ASSERT(ps_ctxt->i4_num_out_bufs <= MAX_NUM_OUT_DATA_BUFS); |
990 | | |
991 | | /* loop to initialise the buffer pointer */ |
992 | 41.1k | for(ctr = 0; ctr < i4_num_out_bufs; ctr++) |
993 | 32.9k | { |
994 | 32.9k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][ctr].i4_idx = ctr; |
995 | 32.9k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][ctr].i4_is_free = 1; |
996 | 32.9k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][ctr].i4_is_prod = 0; |
997 | 32.9k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][ctr].i4_bytes_gen = 0; |
998 | 32.9k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][ctr].pu1_buf = pu1_tmp_buf; |
999 | 32.9k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][ctr].i4_buf_size = buf_size; |
1000 | 32.9k | pu1_tmp_buf += buf_size; |
1001 | 32.9k | } |
1002 | 8.22k | } |
1003 | | |
1004 | | /* create mutex for controlling the out strm buf b/w appln and encoder */ |
1005 | 8.22k | ps_app_ctxt->as_out_strm_prms[i4_res_id][i4_br_id] |
1006 | 8.22k | .pv_app_out_strm_buf_mutex_hdl = osal_mutex_create(ps_ctxt->pv_osal_handle); |
1007 | 8.22k | if(NULL == ps_app_ctxt->as_out_strm_prms[i4_res_id][i4_br_id] |
1008 | 8.22k | .pv_app_out_strm_buf_mutex_hdl) |
1009 | 0 | { |
1010 | 0 | ps_sys_api->ihevce_printf( |
1011 | 0 | ps_sys_api->pv_cb_handle, |
1012 | 0 | "IHEVCE ERROR: Error in Plugin initialization\n"); |
1013 | 0 | return (IHEVCE_EFAIL); |
1014 | 0 | } |
1015 | | |
1016 | | /* create mutex for controlling the out strm buf b/w appln and encoder */ |
1017 | 8.22k | ps_app_ctxt->as_out_strm_prms[i4_res_id][i4_br_id] |
1018 | 8.22k | .pv_app_out_strm_buf_cond_var_hdl = |
1019 | 8.22k | osal_cond_var_create(ps_ctxt->pv_osal_handle); |
1020 | 8.22k | if(NULL == ps_app_ctxt->as_out_strm_prms[i4_res_id][i4_br_id] |
1021 | 8.22k | .pv_app_out_strm_buf_cond_var_hdl) |
1022 | 0 | { |
1023 | 0 | ps_sys_api->ihevce_printf( |
1024 | 0 | ps_sys_api->pv_cb_handle, |
1025 | 0 | "IHEVCE ERROR: Error in Plugin initialization\n"); |
1026 | 0 | return (IHEVCE_EFAIL); |
1027 | 0 | } |
1028 | 8.22k | } |
1029 | 8.22k | } |
1030 | | |
1031 | 8.22k | if(ps_interface_ctxt->i4_create_time_input_allocation == 1) |
1032 | 8.22k | { |
1033 | | /* ------------- Input sync command buffers init -------------------- */ |
1034 | 8.22k | buf_size = s_input_bufs_req.i4_min_size_synch_ctrl_bufs; |
1035 | | |
1036 | 8.22k | ps_ctxt->s_memtab_inp_sync_ctrl_buf.i4_size = sizeof(iv_mem_rec_t); |
1037 | 8.22k | ps_ctxt->s_memtab_inp_sync_ctrl_buf.i4_mem_alignment = 4; |
1038 | 8.22k | ps_ctxt->s_memtab_inp_sync_ctrl_buf.i4_mem_size = |
1039 | 8.22k | (s_input_bufs_req.i4_min_num_yuv_bufs + XTRA_INP_DATA_BUFS) * buf_size; |
1040 | 8.22k | ps_ctxt->s_memtab_inp_sync_ctrl_buf.e_mem_type = IV_EXT_CACHEABLE_NUMA_NODE0_MEM; |
1041 | | |
1042 | 8.22k | mem_mngr_alloc( |
1043 | 8.22k | ps_app_ctxt->pv_mem_mngr_handle, |
1044 | 8.22k | ps_sys_api, |
1045 | 8.22k | &ps_ctxt->s_memtab_inp_sync_ctrl_buf); |
1046 | | |
1047 | 8.22k | pu1_tmp_buf = (UWORD8 *)ps_ctxt->s_memtab_inp_sync_ctrl_buf.pv_base; |
1048 | | |
1049 | 8.22k | if(NULL == pu1_tmp_buf) |
1050 | 0 | { |
1051 | 0 | ps_sys_api->ihevce_printf( |
1052 | 0 | ps_sys_api->pv_cb_handle, "IHEVCE ERROR: Error in allocate memory\n"); |
1053 | 0 | return (IHEVCE_EFAIL); |
1054 | 0 | } |
1055 | | |
1056 | | /* loop to initialise the buffer pointer */ |
1057 | 31.0k | for(ctr = 0; ctr < s_input_bufs_req.i4_min_num_yuv_bufs + XTRA_INP_DATA_BUFS; ctr++) |
1058 | 22.7k | { |
1059 | 22.7k | apv_inp_sync_bufs[ctr] = pu1_tmp_buf; |
1060 | 22.7k | pu1_tmp_buf += buf_size; |
1061 | 22.7k | } |
1062 | 8.22k | } |
1063 | | |
1064 | | /* ------------- Input async command buffers init -------------------- */ |
1065 | 8.22k | buf_size = s_input_bufs_req.i4_min_size_asynch_ctrl_bufs; |
1066 | | |
1067 | | /* allocate memory for output status buffer */ |
1068 | 8.22k | ps_ctxt->pu1_inp_async_ctrl_buf = (UWORD8 *)ps_ctxt->ihevce_mem_alloc( |
1069 | 8.22k | NULL, s_input_bufs_req.i4_min_num_asynch_ctrl_bufs * buf_size); |
1070 | 8.22k | if(ps_ctxt->pu1_inp_async_ctrl_buf == NULL) |
1071 | 0 | { |
1072 | 0 | ps_sys_api->ihevce_printf( |
1073 | 0 | ps_sys_api->pv_cb_handle, |
1074 | 0 | "IHEVCE ERROR: Error in Plugin memory initialization\n"); |
1075 | 0 | return (IHEVCE_EFAIL); |
1076 | 0 | } |
1077 | | |
1078 | 8.22k | pu1_tmp_buf = ps_ctxt->pu1_inp_async_ctrl_buf; |
1079 | | |
1080 | | /* loop to initialise the buffer pointer */ |
1081 | 41.1k | for(ctr = 0; ctr < s_input_bufs_req.i4_min_num_asynch_ctrl_bufs; ctr++) |
1082 | 32.9k | { |
1083 | 32.9k | apv_inp_async_bufs[ctr] = pu1_tmp_buf; |
1084 | 32.9k | pu1_tmp_buf += buf_size; |
1085 | 32.9k | } |
1086 | | |
1087 | | /* Create IO ports for the buffer allocated */ |
1088 | 8.22k | { |
1089 | 8.22k | iv_input_data_ctrl_buffs_desc_t s_inp_desc; |
1090 | 8.22k | iv_input_asynch_ctrl_buffs_desc_t s_inp_ctrl_desc; |
1091 | 8.22k | iv_res_layer_output_data_buffs_desc_t s_mres_out_desc; |
1092 | 8.22k | iv_res_layer_recon_data_buffs_desc_t s_mres_recon_desc; |
1093 | | |
1094 | | /* set the parameters of the input data control desc */ |
1095 | 8.22k | s_inp_desc.i4_size = sizeof(iv_input_data_ctrl_buffs_desc_t); |
1096 | 8.22k | s_inp_desc.i4_num_synch_ctrl_bufs = s_input_bufs_req.i4_min_num_synch_ctrl_bufs; |
1097 | 8.22k | s_inp_desc.i4_num_yuv_bufs = |
1098 | 8.22k | s_input_bufs_req.i4_min_num_yuv_bufs + XTRA_INP_DATA_BUFS; |
1099 | 8.22k | s_inp_desc.i4_size_y_buf = s_input_bufs_req.i4_min_size_y_buf; |
1100 | 8.22k | s_inp_desc.i4_size_uv_buf = s_input_bufs_req.i4_min_size_uv_buf; |
1101 | 8.22k | s_inp_desc.i4_size_synch_ctrl_bufs = s_input_bufs_req.i4_min_size_synch_ctrl_bufs; |
1102 | 8.22k | s_inp_desc.ppv_synch_ctrl_bufs = &apv_inp_sync_bufs[0]; |
1103 | 8.22k | s_inp_desc.ppv_y_buf = &apv_inp_luma_bufs[0]; |
1104 | 8.22k | s_inp_desc.ppv_u_buf = &apv_inp_cb_bufs[0]; |
1105 | 8.22k | s_inp_desc.ppv_v_buf = &apv_inp_cr_bufs[0]; |
1106 | | |
1107 | | /* set the parameters of the input async control desc */ |
1108 | 8.22k | s_inp_ctrl_desc.i4_size = sizeof(iv_input_asynch_ctrl_buffs_desc_t); |
1109 | 8.22k | s_inp_ctrl_desc.i4_num_asynch_ctrl_bufs = |
1110 | 8.22k | s_input_bufs_req.i4_min_num_asynch_ctrl_bufs; |
1111 | 8.22k | s_inp_ctrl_desc.i4_size_asynch_ctrl_bufs = |
1112 | 8.22k | s_input_bufs_req.i4_min_size_asynch_ctrl_bufs; |
1113 | 8.22k | s_inp_ctrl_desc.ppv_asynch_ctrl_bufs = &apv_inp_async_bufs[0]; |
1114 | | |
1115 | 16.4k | for(i4_res_id = 0; i4_res_id < i4_num_resolutions; i4_res_id++) |
1116 | 8.22k | { |
1117 | | /* set the parameters of the output data desc */ |
1118 | 16.4k | for(i4_br_id = 0; i4_br_id < ai4_num_bitrate_instances[i4_res_id]; i4_br_id++) |
1119 | 8.22k | { |
1120 | 8.22k | s_mres_out_desc.s_output_data_buffs[i4_res_id][i4_br_id].i4_size = |
1121 | 8.22k | sizeof(iv_output_data_buffs_desc_t); |
1122 | | |
1123 | 8.22k | if(!ps_interface_ctxt->i4_create_time_output_allocation) |
1124 | 8.22k | { |
1125 | 8.22k | s_mres_out_desc.s_output_data_buffs[i4_res_id][i4_br_id] |
1126 | 8.22k | .i4_num_bitstream_bufs = |
1127 | 8.22k | s_res_layer_output_bufs_req.s_output_buf_req[i4_res_id][i4_br_id] |
1128 | 8.22k | .i4_min_num_out_bufs + |
1129 | 8.22k | XTRA_OUT_DATA_BUFS; |
1130 | 8.22k | } |
1131 | 0 | else |
1132 | 0 | { |
1133 | 0 | s_mres_out_desc.s_output_data_buffs[i4_res_id][i4_br_id] |
1134 | 0 | .i4_num_bitstream_bufs = |
1135 | 0 | s_res_layer_output_bufs_req.s_output_buf_req[i4_res_id][i4_br_id] |
1136 | 0 | .i4_min_num_out_bufs; |
1137 | 0 | } |
1138 | | |
1139 | 8.22k | s_mres_out_desc.s_output_data_buffs[i4_res_id][i4_br_id] |
1140 | 8.22k | .i4_size_bitstream_buf = |
1141 | 8.22k | s_res_layer_output_bufs_req.s_output_buf_req[i4_res_id][i4_br_id] |
1142 | 8.22k | .i4_min_size_bitstream_buf; |
1143 | 8.22k | s_mres_out_desc.s_output_data_buffs[i4_res_id][i4_br_id].ppv_bitstream_bufs = |
1144 | 8.22k | &apv_out_data_bufs[i4_res_id][i4_br_id][0]; |
1145 | 8.22k | } |
1146 | 8.22k | } |
1147 | | |
1148 | 8.22k | s_mres_recon_desc.i4_size = sizeof(iv_res_layer_recon_data_buffs_desc_t); |
1149 | | /* call create I/O ports */ |
1150 | 8.22k | status = ihevce_create_ports( |
1151 | 8.22k | ps_interface_ctxt, |
1152 | 8.22k | &s_inp_desc, |
1153 | 8.22k | &s_inp_ctrl_desc, |
1154 | 8.22k | &s_mres_out_desc, |
1155 | 8.22k | &s_mres_recon_desc); |
1156 | 8.22k | } |
1157 | 8.22k | } |
1158 | | |
1159 | | /* --------------------------------------------------------------------- */ |
1160 | | /* Create a High level encoder thread */ |
1161 | | /* --------------------------------------------------------------------- */ |
1162 | 0 | { |
1163 | 8.22k | osal_thread_attr_t s_thread_attr = OSAL_DEFAULT_THREAD_ATTR; |
1164 | | |
1165 | | /* Initialize application thread attributes */ |
1166 | 8.22k | s_thread_attr.exit_code = 0; |
1167 | 8.22k | s_thread_attr.name = 0; |
1168 | 8.22k | s_thread_attr.priority_map_flag = 1; |
1169 | 8.22k | s_thread_attr.priority = OSAL_PRIORITY_DEFAULT; |
1170 | 8.22k | s_thread_attr.stack_addr = 0; |
1171 | 8.22k | s_thread_attr.stack_size = THREAD_STACK_SIZE; |
1172 | 8.22k | s_thread_attr.thread_func = ihevce_hle_interface_thrd; |
1173 | 8.22k | s_thread_attr.thread_param = (void *)(ps_interface_ctxt); |
1174 | 8.22k | s_thread_attr.core_affinity_mask = 0; |
1175 | 8.22k | s_thread_attr.group_num = 0; |
1176 | | |
1177 | | /* Create High level encoder thread */ |
1178 | 8.22k | ps_ctxt->pv_hle_thread_hdl = |
1179 | 8.22k | osal_thread_create(ps_ctxt->pv_osal_handle, &s_thread_attr); |
1180 | 8.22k | if(NULL == ps_ctxt->pv_hle_thread_hdl) |
1181 | 0 | { |
1182 | 0 | return IHEVCE_EFAIL; |
1183 | 0 | } |
1184 | 8.22k | } |
1185 | | |
1186 | | /* --------------------------------------------------------------------- */ |
1187 | | /* Wait until HLE init is done */ |
1188 | | /* --------------------------------------------------------------------- */ |
1189 | 8.22k | { |
1190 | 8.22k | volatile WORD32 hle_init_done; |
1191 | 8.22k | volatile WORD32 *pi4_hle_init_done; |
1192 | | |
1193 | 8.22k | pi4_hle_init_done = (volatile WORD32 *)&ps_interface_ctxt->i4_hle_init_done; |
1194 | | |
1195 | 8.22k | do |
1196 | 1.55G | { |
1197 | 1.55G | hle_init_done = *pi4_hle_init_done; |
1198 | | |
1199 | 1.55G | } while(0 == hle_init_done); |
1200 | 8.22k | } |
1201 | | |
1202 | | /* reset flush mode */ |
1203 | 8.22k | ps_ctxt->i4_flush_mode_on = 0; |
1204 | | |
1205 | 8.22k | { |
1206 | 8.22k | WORD32 i4_res_id; |
1207 | 8.22k | WORD32 i4_br_id; |
1208 | 16.4k | for(i4_res_id = 0; i4_res_id < IHEVCE_MAX_NUM_RESOLUTIONS; i4_res_id++) |
1209 | 8.22k | { |
1210 | 16.4k | for(i4_br_id = 0; i4_br_id < IHEVCE_MAX_NUM_BITRATES; i4_br_id++) |
1211 | 8.22k | { |
1212 | | /* reset out end flag */ |
1213 | 8.22k | ps_ctxt->ai4_out_end_flag[i4_res_id][i4_br_id] = 0; |
1214 | 8.22k | } |
1215 | 8.22k | } |
1216 | 8.22k | } |
1217 | | |
1218 | | /* reset the field id */ |
1219 | 8.22k | ps_ctxt->i4_field_id = 0; |
1220 | | |
1221 | | /* based on number of B pics set the DTS value */ |
1222 | 8.22k | ps_ctxt->i8_dts = -1; |
1223 | | |
1224 | 8.22k | if(0 != ps_ctxt->ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers) |
1225 | 2.11k | { |
1226 | 2.11k | ps_ctxt->i8_dts = |
1227 | 2.11k | (-1) * |
1228 | 2.11k | (1 << ps_ctxt->ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers); |
1229 | 2.11k | } |
1230 | | |
1231 | | /* initialsie the buffer stride */ |
1232 | 8.22k | { |
1233 | 8.22k | WORD32 max_cu_size; |
1234 | | |
1235 | 8.22k | max_cu_size = (1 << ps_ctxt->ps_static_cfg_prms->s_config_prms.i4_max_log2_cu_size); |
1236 | 8.22k | ps_ctxt->i4_frm_stride = |
1237 | 8.22k | ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_width + |
1238 | 8.22k | SET_CTB_ALIGN(ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_width, max_cu_size); |
1239 | 8.22k | } |
1240 | 8.22k | } |
1241 | 0 | else |
1242 | 0 | { |
1243 | | /* free plugin ctxt memory */ |
1244 | 0 | memory_free(NULL, ps_ctxt); |
1245 | |
|
1246 | 0 | return (IHEVCE_EFAIL); |
1247 | 0 | } |
1248 | | |
1249 | | /* reset the place holders of old bitrate */ |
1250 | 8.22k | memset(&ps_ctxt->ai4_old_bitrate[0][0], 0, sizeof(ps_ctxt->ai4_old_bitrate)); |
1251 | | |
1252 | 8.22k | ps_ctxt->ai4_old_bitrate[0][0] = ps_params->s_tgt_lyr_prms.as_tgt_params[0].ai4_tgt_bitrate[0]; |
1253 | | |
1254 | | /* store the plugin handle before returning */ |
1255 | 8.22k | *ppv_ihevce_hdl = (void *)ps_ctxt; |
1256 | | |
1257 | 8.22k | return (IHEVCE_EOK); |
1258 | 8.26k | } |
1259 | | |
1260 | | static IHEVCE_PLUGIN_STATUS_T |
1261 | | ihevce_receive_out_buffer(plugin_ctxt_t *ps_ctxt, ihevce_out_buf_t *ps_out) |
1262 | 153k | { |
1263 | 153k | app_ctxt_t *ps_app_ctxt = &ps_ctxt->s_app_ctxt; |
1264 | 153k | WORD32 i4_res_id, i4_br_id; |
1265 | 153k | WORD32 i4_num_resolutions; |
1266 | 153k | WORD32 ai4_num_bitrate_instances[IHEVCE_MAX_NUM_RESOLUTIONS] = { 1 }; |
1267 | | |
1268 | 153k | i4_num_resolutions = ps_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_num_res_layers; |
1269 | 306k | for(i4_res_id = 0; i4_res_id < i4_num_resolutions; i4_res_id++) |
1270 | 153k | { |
1271 | 153k | ai4_num_bitrate_instances[i4_res_id] = |
1272 | 153k | ps_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_res_id] |
1273 | 153k | .i4_num_bitrate_instances; |
1274 | 153k | } |
1275 | | /* default init */ |
1276 | 153k | ps_out->pu1_output_buf = NULL; |
1277 | 153k | ps_out->i4_bytes_generated = 0; |
1278 | | |
1279 | | /* ---------------- if any output buffer is available return the buffer back ------------- */ |
1280 | 153k | while(1) |
1281 | 153k | { |
1282 | 153k | WORD32 osal_result; |
1283 | 153k | WORD32 buf_present = 0; |
1284 | 153k | WORD32 i4_is_prod = 1; |
1285 | 153k | WORD32 i4_atleast_one_br_prod = 0; |
1286 | | /****** Lock the critical section ******/ |
1287 | 153k | osal_result = |
1288 | 153k | osal_mutex_lock(ps_app_ctxt->as_out_strm_prms[0][0].pv_app_out_strm_buf_mutex_hdl); |
1289 | | |
1290 | 153k | if(OSAL_SUCCESS != osal_result) |
1291 | 0 | return IHEVCE_EFAIL; |
1292 | | |
1293 | | /* wait until entropy sends an output */ |
1294 | 298k | while(1) |
1295 | 298k | { |
1296 | 298k | i4_is_prod = 1; |
1297 | 596k | for(i4_res_id = 0; i4_res_id < i4_num_resolutions; i4_res_id++) |
1298 | 298k | { |
1299 | 596k | for(i4_br_id = 0; i4_br_id < ai4_num_bitrate_instances[i4_res_id]; i4_br_id++) |
1300 | 298k | { |
1301 | 298k | i4_is_prod &= |
1302 | 298k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][ps_ctxt->i4_prod_out_buf_idx] |
1303 | 298k | .i4_is_prod; |
1304 | 298k | i4_atleast_one_br_prod |= |
1305 | 298k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][ps_ctxt->i4_prod_out_buf_idx] |
1306 | 298k | .i4_is_prod; |
1307 | 298k | } |
1308 | 298k | } |
1309 | 298k | if(!i4_is_prod) |
1310 | 145k | { |
1311 | 290k | for(i4_res_id = 0; i4_res_id < i4_num_resolutions; i4_res_id++) |
1312 | 145k | { |
1313 | 290k | for(i4_br_id = 0; i4_br_id < ai4_num_bitrate_instances[i4_res_id]; i4_br_id++) |
1314 | 145k | { |
1315 | 145k | osal_cond_var_wait( |
1316 | 145k | ps_app_ctxt->as_out_strm_prms[i4_res_id][i4_br_id] |
1317 | 145k | .pv_app_out_strm_buf_cond_var_hdl, |
1318 | 145k | ps_app_ctxt->as_out_strm_prms[i4_res_id][i4_br_id] |
1319 | 145k | .pv_app_out_strm_buf_mutex_hdl); |
1320 | 145k | } |
1321 | 145k | } |
1322 | 145k | } |
1323 | 153k | else |
1324 | 153k | { |
1325 | 153k | break; |
1326 | 153k | } |
1327 | 298k | } |
1328 | | |
1329 | 153k | ASSERT(i4_is_prod == 1); |
1330 | | |
1331 | | /* check if the current buffer for all bitrates and resolutions have been produced */ |
1332 | 153k | if(1 == i4_is_prod) |
1333 | 153k | { |
1334 | 153k | buf_present = 1; |
1335 | | |
1336 | 306k | for(i4_res_id = 0; i4_res_id < i4_num_resolutions; i4_res_id++) |
1337 | 153k | { |
1338 | 306k | for(i4_br_id = 0; i4_br_id < ai4_num_bitrate_instances[i4_res_id]; i4_br_id++) |
1339 | 153k | { |
1340 | | /* set the buffer to free status */ |
1341 | 153k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][ps_ctxt->i4_prod_out_buf_idx] |
1342 | 153k | .i4_is_free = 1; |
1343 | 153k | if((0 == i4_res_id) && (0 == i4_br_id)) |
1344 | 153k | { |
1345 | 153k | ps_out->i4_bytes_generated = |
1346 | 153k | ps_ctxt->aaas_out_bufs[0][0][ps_ctxt->i4_prod_out_buf_idx].i4_bytes_gen; |
1347 | 153k | ps_out->pu1_output_buf = |
1348 | 153k | ps_ctxt->aaas_out_bufs[0][0][ps_ctxt->i4_prod_out_buf_idx].pu1_buf; |
1349 | 153k | } |
1350 | 153k | } |
1351 | 153k | } |
1352 | | |
1353 | | /* copy the contents to output buffer */ |
1354 | 153k | ps_out->i4_is_key_frame = |
1355 | 153k | ps_ctxt->aaas_out_bufs[0][0][ps_ctxt->i4_prod_out_buf_idx].i4_is_key_frame; |
1356 | 153k | ps_out->u8_pts = |
1357 | 153k | ps_ctxt->aaas_out_bufs[0][0][ps_ctxt->i4_prod_out_buf_idx].i4_timestamp_low; |
1358 | 153k | ps_out->u8_pts = |
1359 | 153k | ps_out->u8_pts | |
1360 | 153k | ((ULWORD64)( |
1361 | 153k | ps_ctxt->aaas_out_bufs[0][0][ps_ctxt->i4_prod_out_buf_idx].i4_timestamp_high) |
1362 | 153k | << 32); |
1363 | 153k | ps_out->i4_end_flag = |
1364 | 153k | ps_ctxt->aaas_out_bufs[0][0][ps_ctxt->i4_prod_out_buf_idx].i4_end_flag; |
1365 | 153k | ps_out->i8_dts = ps_ctxt->i8_dts; |
1366 | | |
1367 | | /* increment the DTS */ |
1368 | 153k | ps_ctxt->i8_dts++; |
1369 | 153k | } |
1370 | | |
1371 | | /* check for buffer present */ |
1372 | 153k | if(1 == buf_present) |
1373 | 153k | { |
1374 | 153k | ps_ctxt->i4_prod_out_buf_idx++; |
1375 | | |
1376 | | /* wrap around case */ |
1377 | 153k | if(ps_ctxt->i4_prod_out_buf_idx == ps_ctxt->i4_num_out_bufs) |
1378 | 34.8k | { |
1379 | 34.8k | ps_ctxt->i4_prod_out_buf_idx = 0; |
1380 | 34.8k | } |
1381 | | |
1382 | | /****** Unlock the critical section ******/ |
1383 | 153k | osal_result = osal_mutex_unlock( |
1384 | 153k | ps_app_ctxt->as_out_strm_prms[0][0].pv_app_out_strm_buf_mutex_hdl); |
1385 | 153k | if(OSAL_SUCCESS != osal_result) |
1386 | 0 | return IHEVCE_EFAIL; |
1387 | | |
1388 | | /* break while 1 loop */ |
1389 | 153k | break; |
1390 | 153k | } |
1391 | 0 | else |
1392 | 0 | { |
1393 | | /* in steady state*/ |
1394 | 0 | if(0 == ps_ctxt->i4_flush_mode_on) |
1395 | 0 | { |
1396 | | /****** Unlock the critical section ******/ |
1397 | 0 | osal_result = osal_mutex_unlock( |
1398 | 0 | ps_app_ctxt->as_out_strm_prms[0][0].pv_app_out_strm_buf_mutex_hdl); |
1399 | 0 | if(OSAL_SUCCESS != osal_result) |
1400 | 0 | return IHEVCE_EFAIL; |
1401 | 0 | if(!i4_atleast_one_br_prod) /*** If atleast one bitrate is produced do not break from loop **/ |
1402 | 0 | { /*** Continue in while loop and Wait for next bitrate ***/ |
1403 | | /* break while 1 loop */ |
1404 | 0 | break; |
1405 | 0 | } |
1406 | 0 | } |
1407 | 0 | else |
1408 | 0 | { |
1409 | | /* In flush mode is ON then this function must return output |
1410 | | buffers. Otherwise assume that encoding is over and return fail */ |
1411 | | /****** Unlock the critical section ******/ |
1412 | 0 | osal_result = osal_mutex_unlock( |
1413 | 0 | ps_app_ctxt->as_out_strm_prms[0][0].pv_app_out_strm_buf_mutex_hdl); |
1414 | 0 | if(OSAL_SUCCESS != osal_result) |
1415 | 0 | return IHEVCE_EFAIL; |
1416 | 0 | } |
1417 | 0 | } |
1418 | 153k | } |
1419 | | |
1420 | 153k | return IHEVCE_EOK; |
1421 | 153k | } |
1422 | | |
1423 | | static IHEVCE_PLUGIN_STATUS_T |
1424 | | ihevce_queue_out_buffer(plugin_ctxt_t *ps_ctxt, WORD32 i4_res_id, WORD32 i4_br_id) |
1425 | 166k | { |
1426 | 166k | app_ctxt_t *ps_app_ctxt = &ps_ctxt->s_app_ctxt; |
1427 | 166k | ihevce_hle_ctxt_t *ps_interface_ctxt = (ihevce_hle_ctxt_t *)ps_ctxt->pv_hle_interface_ctxt; |
1428 | | |
1429 | | /* --------------------------------------------------------------------- */ |
1430 | | /* Free Output buffer Queuing */ |
1431 | | /* --------------------------------------------------------------------- */ |
1432 | | /* ------- Que in free output buffer if end flag is not set ------ */ |
1433 | 166k | if(0 == ps_ctxt->ai4_out_end_flag[i4_res_id][i4_br_id]) |
1434 | 166k | { |
1435 | 166k | WORD32 osal_result; |
1436 | 166k | iv_output_data_buffs_t *ps_curr_out; |
1437 | 166k | WORD32 buf_id_strm; |
1438 | 166k | WORD32 free_idx; |
1439 | | |
1440 | 166k | free_idx = ps_ctxt->ai4_free_out_buf_idx[i4_res_id][i4_br_id]; |
1441 | | |
1442 | 166k | if(1 == ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][free_idx].i4_is_free) |
1443 | 166k | { |
1444 | | /* ---------- get a free desc. from output Q ------ */ |
1445 | 166k | ps_curr_out = (iv_output_data_buffs_t *)ihevce_q_get_free_out_strm_buff( |
1446 | 166k | ps_interface_ctxt, &buf_id_strm, BUFF_QUE_NON_BLOCKING_MODE, i4_br_id, i4_res_id); |
1447 | | |
1448 | | /* if a free buffer is available */ |
1449 | 166k | if(NULL != ps_curr_out) |
1450 | 166k | { |
1451 | | /****** Lock the critical section ******/ |
1452 | 166k | osal_result = osal_mutex_lock(ps_app_ctxt->as_out_strm_prms[i4_res_id][i4_br_id] |
1453 | 166k | .pv_app_out_strm_buf_mutex_hdl); |
1454 | | |
1455 | 166k | if(OSAL_SUCCESS != osal_result) |
1456 | 0 | return IHEVCE_EFAIL; |
1457 | | |
1458 | 166k | if(1 == ps_app_ctxt->ai4_out_strm_end_flag[i4_res_id][i4_br_id]) |
1459 | 0 | { |
1460 | 0 | ps_curr_out->i4_is_last_buf = 1; |
1461 | 0 | ps_ctxt->ai4_out_end_flag[i4_res_id][i4_br_id] = 1; |
1462 | 0 | } |
1463 | 166k | else |
1464 | 166k | { |
1465 | 166k | ps_curr_out->i4_is_last_buf = 0; |
1466 | 166k | } |
1467 | 166k | ASSERT(ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][free_idx].i4_is_free == 1); |
1468 | 166k | ASSERT(free_idx == ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][free_idx].i4_idx); |
1469 | | |
1470 | 166k | ps_curr_out->pv_bitstream_bufs = |
1471 | 166k | (void *)ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][free_idx].pu1_buf; |
1472 | 166k | ps_curr_out->i4_cb_buf_id = |
1473 | 166k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][free_idx].i4_idx; |
1474 | 166k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][free_idx].i4_is_free = 0; |
1475 | 166k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][free_idx].i4_is_prod = 0; |
1476 | 166k | ps_ctxt->aaas_out_bufs[i4_res_id][i4_br_id][free_idx].i4_bytes_gen = 0; |
1477 | | |
1478 | 166k | ps_ctxt->ai4_free_out_buf_idx[i4_res_id][i4_br_id]++; |
1479 | | |
1480 | | /* wrap around case */ |
1481 | 166k | if(ps_ctxt->ai4_free_out_buf_idx[i4_res_id][i4_br_id] == ps_ctxt->i4_num_out_bufs) |
1482 | 37.8k | { |
1483 | 37.8k | ps_ctxt->ai4_free_out_buf_idx[i4_res_id][i4_br_id] = 0; |
1484 | 37.8k | } |
1485 | | |
1486 | | /****** Unlock the critical section ******/ |
1487 | 166k | osal_result = osal_mutex_unlock(ps_app_ctxt->as_out_strm_prms[i4_res_id][i4_br_id] |
1488 | 166k | .pv_app_out_strm_buf_mutex_hdl); |
1489 | 166k | if(OSAL_SUCCESS != osal_result) |
1490 | 0 | return IHEVCE_EFAIL; |
1491 | | |
1492 | | /* ---------- set the buffer as produced ---------- */ |
1493 | 166k | ihevce_q_set_out_strm_buff_prod( |
1494 | 166k | ps_interface_ctxt, buf_id_strm, i4_br_id, i4_res_id); |
1495 | 166k | } |
1496 | 166k | } |
1497 | 166k | } |
1498 | 166k | return IHEVCE_EOK; |
1499 | 166k | } |
1500 | | |
1501 | | /*! |
1502 | | ****************************************************************************** |
1503 | | * \if Function name : ihevce_close \endif |
1504 | | * |
1505 | | * \brief |
1506 | | * De-Initialises the encoder context and threads |
1507 | | * |
1508 | | * \param[in] Static params pointer |
1509 | | * |
1510 | | * \return |
1511 | | * status |
1512 | | * |
1513 | | * \author |
1514 | | * Ittiam |
1515 | | * |
1516 | | ***************************************************************************** |
1517 | | */ |
1518 | | IHEVCE_PLUGIN_STATUS_T ihevce_close(void *pv_ihevce_hdl) |
1519 | 8.22k | { |
1520 | | /* local variables */ |
1521 | 8.22k | plugin_ctxt_t *ps_ctxt; |
1522 | 8.22k | app_ctxt_t *ps_app_ctxt; |
1523 | 8.22k | ihevce_hle_ctxt_t *ps_interface_ctxt; |
1524 | 8.22k | WORD32 i4_num_resolutions; |
1525 | 8.22k | WORD32 i4_res_id; |
1526 | 8.22k | WORD32 i4_br_id; |
1527 | 8.22k | WORD32 ai4_num_bitrate_instances[IHEVCE_MAX_NUM_RESOLUTIONS] = { 1 }; |
1528 | 8.22k | ihevce_sys_api_t *ps_sys_api; |
1529 | | |
1530 | | /* sanity checks */ |
1531 | 8.22k | if(NULL == pv_ihevce_hdl) |
1532 | 0 | return (IHEVCE_EFAIL); |
1533 | | |
1534 | | /* derive local variables */ |
1535 | 8.22k | ps_ctxt = (plugin_ctxt_t *)pv_ihevce_hdl; |
1536 | | |
1537 | 8.22k | ps_sys_api = &ps_ctxt->ps_static_cfg_prms->s_sys_api; |
1538 | | |
1539 | 8.22k | if((0 == ps_ctxt->ps_static_cfg_prms->i4_res_id) && |
1540 | 8.22k | (0 == ps_ctxt->ps_static_cfg_prms->i4_br_id)) |
1541 | 8.22k | { |
1542 | 8.22k | ps_interface_ctxt = (ihevce_hle_ctxt_t *)ps_ctxt->pv_hle_interface_ctxt; |
1543 | 8.22k | ps_app_ctxt = &ps_ctxt->s_app_ctxt; |
1544 | 8.22k | i4_num_resolutions = ps_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_num_res_layers; |
1545 | | |
1546 | 8.22k | if(1 != ps_ctxt->i4_flush_mode_on) |
1547 | 8.22k | { |
1548 | 16.4k | for(i4_res_id = 0; i4_res_id < i4_num_resolutions; i4_res_id++) |
1549 | 8.22k | { |
1550 | 8.22k | ai4_num_bitrate_instances[i4_res_id] = |
1551 | 8.22k | ps_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_res_id] |
1552 | 8.22k | .i4_num_bitrate_instances; |
1553 | 16.4k | for(i4_br_id = 0; i4_br_id < ai4_num_bitrate_instances[i4_res_id]; i4_br_id++) |
1554 | 8.22k | { |
1555 | | /* ------- Que in free output buffer if end flag is not set ------ */ |
1556 | 8.22k | ihevce_queue_out_buffer(ps_ctxt, i4_res_id, i4_br_id); |
1557 | 8.22k | } |
1558 | 8.22k | } |
1559 | | /* --------------------------------------------------------------------- */ |
1560 | | /* Input Processing */ |
1561 | | /* --------------------------------------------------------------------- */ |
1562 | 8.22k | { |
1563 | 8.22k | WORD32 buf_id; |
1564 | | |
1565 | 8.22k | iv_input_data_ctrl_buffs_t *ps_curr_inp; |
1566 | 8.22k | WORD32 *pi4_ctrl_ptr; |
1567 | | |
1568 | | /* ---------- get a free buffer from input Q ------ */ |
1569 | 8.22k | ps_curr_inp = (iv_input_data_ctrl_buffs_t *)ihevce_q_get_free_inp_data_buff( |
1570 | 8.22k | ps_interface_ctxt, &buf_id, BUFF_QUE_BLOCKING_MODE); |
1571 | | |
1572 | 8.22k | if(NULL != ps_curr_inp) |
1573 | 8.22k | { |
1574 | | /* flush mode command */ |
1575 | | |
1576 | 8.22k | ps_curr_inp->i4_buf_id = buf_id; |
1577 | | |
1578 | | /* set the input status to invalid flag */ |
1579 | 8.22k | ps_curr_inp->i4_inp_frm_data_valid_flag = 0; |
1580 | | |
1581 | 8.22k | pi4_ctrl_ptr = (WORD32 *)ps_curr_inp->pv_synch_ctrl_bufs; |
1582 | | |
1583 | 8.22k | *pi4_ctrl_ptr = IHEVCE_SYNCH_API_FLUSH_TAG; |
1584 | 8.22k | *(pi4_ctrl_ptr + 1) = 0; |
1585 | 8.22k | *(pi4_ctrl_ptr + 2) = IHEVCE_SYNCH_API_END_TAG; |
1586 | | |
1587 | 8.22k | ps_curr_inp->i4_cmd_buf_size = 4 * 3; /* 4 bytes */ |
1588 | | |
1589 | | /* ---------- set the buffer as produced ---------- */ |
1590 | 8.22k | ihevce_q_set_inp_data_buff_prod(ps_interface_ctxt, buf_id); |
1591 | 8.22k | } |
1592 | 0 | else |
1593 | 0 | { |
1594 | | /* Enable flush-mode and internal-flush once limit according to |
1595 | | Eval-version is reached */ |
1596 | 0 | ps_ctxt->i4_flush_mode_on = 1; |
1597 | 0 | } |
1598 | 8.22k | } |
1599 | 8.22k | } |
1600 | | |
1601 | | /* --------------------------------------------------------------------- */ |
1602 | | /* Wait and destroy Processing threads */ |
1603 | | /* --------------------------------------------------------------------- */ |
1604 | | |
1605 | | /* Wait for High level encoder thread to complete */ |
1606 | 8.22k | osal_thread_wait(ps_ctxt->pv_hle_thread_hdl); |
1607 | | |
1608 | | /* Destroy Hle thread */ |
1609 | 8.22k | osal_thread_destroy(ps_ctxt->pv_hle_thread_hdl); |
1610 | | |
1611 | | /* --------------------------------------------------------------------- */ |
1612 | | /* Input Output and Command buffers free */ |
1613 | | /* --------------------------------------------------------------------- */ |
1614 | | |
1615 | | /* free output data and control buffer */ |
1616 | | |
1617 | 16.4k | for(i4_res_id = 0; i4_res_id < i4_num_resolutions; i4_res_id++) |
1618 | 8.22k | { |
1619 | 8.22k | ai4_num_bitrate_instances[i4_res_id] = |
1620 | 8.22k | ps_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_res_id] |
1621 | 8.22k | .i4_num_bitrate_instances; |
1622 | | |
1623 | 16.4k | for(i4_br_id = 0; i4_br_id < ai4_num_bitrate_instances[i4_res_id]; i4_br_id++) |
1624 | 8.22k | { |
1625 | 8.22k | mem_mngr_free( |
1626 | 8.22k | ps_app_ctxt->pv_mem_mngr_handle, |
1627 | 8.22k | &ps_ctxt->as_memtab_out_data_buf[i4_res_id][i4_br_id]); |
1628 | | |
1629 | | /* free mutex of out strm buf b/w appln and encoder */ |
1630 | 8.22k | osal_mutex_destroy(ps_app_ctxt->as_out_strm_prms[i4_res_id][i4_br_id] |
1631 | 8.22k | .pv_app_out_strm_buf_mutex_hdl); |
1632 | | |
1633 | 8.22k | osal_cond_var_destroy(ps_app_ctxt->as_out_strm_prms[i4_res_id][i4_br_id] |
1634 | 8.22k | .pv_app_out_strm_buf_cond_var_hdl); |
1635 | 8.22k | } |
1636 | 8.22k | } |
1637 | | |
1638 | 8.22k | ps_ctxt->ihevce_mem_free(NULL, ps_ctxt->pu1_out_ctrl_buf); |
1639 | 8.22k | ps_ctxt->ihevce_mem_free(NULL, ps_ctxt->pu1_inp_async_ctrl_buf); |
1640 | | |
1641 | | /* free input data and control buffer */ |
1642 | 8.22k | if(ps_interface_ctxt->i4_create_time_input_allocation == 1) |
1643 | 8.22k | { |
1644 | 8.22k | mem_mngr_free(ps_app_ctxt->pv_mem_mngr_handle, &ps_ctxt->s_memtab_inp_data_buf); |
1645 | 8.22k | mem_mngr_free(ps_app_ctxt->pv_mem_mngr_handle, &ps_ctxt->s_memtab_inp_sync_ctrl_buf); |
1646 | 8.22k | } |
1647 | | |
1648 | | /* --------------------------------------------------------------------- */ |
1649 | | /* Encoder Instance Deletion */ |
1650 | | /* --------------------------------------------------------------------- */ |
1651 | 8.22k | ihevce_hle_interface_delete(ps_interface_ctxt); |
1652 | | |
1653 | | /* free the high level encoder context memory */ |
1654 | 8.22k | ps_ctxt->ihevce_mem_free(NULL, ps_ctxt->pv_hle_interface_ctxt); |
1655 | | |
1656 | 8.22k | if(ps_ctxt->ps_static_cfg_prms->i4_enable_csv_dump) |
1657 | 0 | { |
1658 | 0 | ps_sys_api->s_file_io_api.ihevce_fclose( |
1659 | 0 | (void *)ps_sys_api->pv_cb_handle, ps_ctxt->ps_static_cfg_prms->apF_csv_file[0][0]); |
1660 | 0 | } |
1661 | | |
1662 | | /* free static config memory */ |
1663 | 8.22k | ps_ctxt->ihevce_mem_free(NULL, ps_ctxt->ps_static_cfg_prms); |
1664 | | |
1665 | | /* free osal handle */ |
1666 | 8.22k | memory_free(NULL, ps_ctxt->pv_osal_handle); |
1667 | | |
1668 | | /* free plugin ctxt memory */ |
1669 | 8.22k | memory_free(NULL, pv_ihevce_hdl); |
1670 | 8.22k | } |
1671 | 0 | else |
1672 | 0 | { |
1673 | 0 | return (IHEVCE_EFAIL); |
1674 | 0 | } |
1675 | | |
1676 | 8.22k | return (IHEVCE_EOK); |
1677 | 8.22k | } |
1678 | | |
1679 | | /*! |
1680 | | ****************************************************************************** |
1681 | | * \if Function name : ihevce_copy_inp_8bit \endif |
1682 | | * |
1683 | | * \brief |
1684 | | * Input copy function for 8 bit input |
1685 | | * |
1686 | | * \param[in] Source and desdtination buffer descriptors |
1687 | | * |
1688 | | * \return |
1689 | | * None |
1690 | | * |
1691 | | * \author |
1692 | | * Ittiam |
1693 | | * |
1694 | | ***************************************************************************** |
1695 | | */ |
1696 | | IV_API_CALL_STATUS_T ihevce_copy_inp_8bit( |
1697 | | iv_input_data_ctrl_buffs_t *ps_curr_inp, |
1698 | | ihevce_inp_buf_t *ps_inp, |
1699 | | WORD32 chroma_format, |
1700 | | WORD32 i4_orig_wd, |
1701 | | WORD32 i4_orig_ht) |
1702 | 149k | { |
1703 | 149k | UWORD8 *pu1_src, *pu1_dst; |
1704 | 149k | WORD32 src_strd, dst_strd; |
1705 | 149k | WORD32 frm_height = i4_orig_ht; |
1706 | 149k | WORD32 frm_width = i4_orig_wd; |
1707 | 149k | WORD32 buf_height = ps_curr_inp->s_input_buf.i4_y_ht; |
1708 | 149k | WORD32 buf_width = ps_curr_inp->s_input_buf.i4_y_wd; |
1709 | 149k | WORD32 rows, cols; |
1710 | | |
1711 | 149k | pu1_src = (UWORD8 *)ps_inp->apv_inp_planes[0]; |
1712 | 149k | src_strd = ps_inp->ai4_inp_strd[0]; |
1713 | 149k | pu1_dst = (UWORD8 *)ps_curr_inp->s_input_buf.pv_y_buf; |
1714 | 149k | dst_strd = ps_curr_inp->s_input_buf.i4_y_strd; |
1715 | | |
1716 | 149k | if((ps_inp->ai4_inp_size[0] < (src_strd * frm_height)) || (ps_inp->ai4_inp_size[0] <= 0) || |
1717 | 149k | (ps_inp->apv_inp_planes[0] == NULL)) |
1718 | 0 | { |
1719 | 0 | return (IV_FAIL); |
1720 | 0 | } |
1721 | | /* copy the input luma data into internal buffer */ |
1722 | 2.34M | for(rows = 0; rows < frm_height; rows++) |
1723 | 2.19M | { |
1724 | 2.19M | memcpy(pu1_dst, pu1_src, frm_width); |
1725 | 2.19M | if(buf_width > frm_width) |
1726 | 1.70M | { |
1727 | 1.70M | memset(pu1_dst + frm_width, 0x0, buf_width - frm_width); |
1728 | 1.70M | } |
1729 | 2.19M | pu1_src += src_strd; |
1730 | 2.19M | pu1_dst += dst_strd; |
1731 | 2.19M | } |
1732 | 8.53M | while(rows < buf_height) |
1733 | 8.38M | { |
1734 | 8.38M | memset(pu1_dst, 0x0, buf_width); |
1735 | 8.38M | pu1_dst += dst_strd; |
1736 | 8.38M | rows++; |
1737 | 8.38M | } |
1738 | | |
1739 | 149k | if(IV_YUV_420P == chroma_format) |
1740 | 149k | { |
1741 | 149k | UWORD8 *pu1_src_u, *pu1_src_v; |
1742 | 149k | WORD32 src_strd_u, src_strd_v; |
1743 | | |
1744 | 149k | pu1_src_u = (UWORD8 *)ps_inp->apv_inp_planes[1]; |
1745 | 149k | src_strd_u = ps_inp->ai4_inp_strd[1]; |
1746 | 149k | pu1_src_v = (UWORD8 *)ps_inp->apv_inp_planes[2]; |
1747 | 149k | src_strd_v = ps_inp->ai4_inp_strd[2]; |
1748 | 149k | pu1_dst = (UWORD8 *)ps_curr_inp->s_input_buf.pv_u_buf; |
1749 | 149k | dst_strd = ps_curr_inp->s_input_buf.i4_uv_strd; |
1750 | | |
1751 | 149k | frm_width = i4_orig_wd >> 1; |
1752 | 149k | frm_height = i4_orig_ht >> 1; |
1753 | 149k | buf_width = ps_curr_inp->s_input_buf.i4_uv_wd; |
1754 | 149k | buf_height = ps_curr_inp->s_input_buf.i4_uv_ht; |
1755 | | |
1756 | 149k | if((ps_inp->ai4_inp_size[1] < (ps_inp->ai4_inp_strd[1] * frm_height)) || |
1757 | 149k | (ps_inp->ai4_inp_size[1] <= 0) || (pu1_src_u == NULL)) |
1758 | 0 | { |
1759 | 0 | return (IV_FAIL); |
1760 | 0 | } |
1761 | 149k | if((ps_inp->ai4_inp_size[2] < (ps_inp->ai4_inp_strd[2] * frm_height)) || |
1762 | 149k | (ps_inp->ai4_inp_size[2] <= 0) || (pu1_src_v == NULL)) |
1763 | 0 | { |
1764 | 0 | return (IV_FAIL); |
1765 | 0 | } |
1766 | | |
1767 | | /* copy the input chroma data in pixel interleaved format */ |
1768 | 1.24M | for(rows = 0; rows < frm_height; rows++) |
1769 | 1.09M | { |
1770 | 85.7M | for(cols = 0; cols < frm_width; cols++) |
1771 | 84.6M | { |
1772 | | /* U V alternate */ |
1773 | 84.6M | pu1_dst[(cols << 1)] = pu1_src_u[cols]; |
1774 | 84.6M | pu1_dst[(cols << 1) + 1] = pu1_src_v[cols]; |
1775 | 84.6M | } |
1776 | 1.09M | if(buf_width > (cols << 1)) |
1777 | 850k | { |
1778 | 850k | memset(&pu1_dst[(cols << 1)], 0x80, buf_width - (cols << 1)); |
1779 | 850k | } |
1780 | | |
1781 | 1.09M | pu1_src_u += src_strd_u; |
1782 | 1.09M | pu1_src_v += src_strd_v; |
1783 | 1.09M | pu1_dst += dst_strd; |
1784 | 1.09M | } |
1785 | 4.34M | while(rows < buf_height) |
1786 | 4.19M | { |
1787 | 4.19M | memset(pu1_dst, 0x80, buf_width); |
1788 | | |
1789 | 4.19M | pu1_dst += dst_strd; |
1790 | 4.19M | rows++; |
1791 | 4.19M | } |
1792 | 149k | } |
1793 | 0 | else if(IV_YUV_420SP_UV == chroma_format) |
1794 | 0 | { |
1795 | 0 | pu1_src = (UWORD8 *)ps_inp->apv_inp_planes[1]; |
1796 | 0 | src_strd = ps_inp->ai4_inp_strd[1]; |
1797 | 0 | pu1_dst = (UWORD8 *)ps_curr_inp->s_input_buf.pv_u_buf; |
1798 | 0 | dst_strd = ps_curr_inp->s_input_buf.i4_uv_strd; |
1799 | |
|
1800 | 0 | frm_width = i4_orig_wd; |
1801 | 0 | frm_height = i4_orig_ht >> 1; |
1802 | 0 | buf_width = ps_curr_inp->s_input_buf.i4_uv_wd; |
1803 | 0 | buf_height = ps_curr_inp->s_input_buf.i4_uv_ht; |
1804 | |
|
1805 | 0 | if((ps_inp->ai4_inp_size[1] < (ps_inp->ai4_inp_strd[1] * frm_height)) || |
1806 | 0 | (ps_inp->ai4_inp_size[1] <= 0) || (pu1_src == NULL)) |
1807 | 0 | { |
1808 | 0 | return (IV_FAIL); |
1809 | 0 | } |
1810 | | |
1811 | | /* copy the input luma data into internal buffer */ |
1812 | 0 | for(rows = 0; rows < frm_height; rows++) |
1813 | 0 | { |
1814 | 0 | memcpy(pu1_dst, pu1_src, frm_width); |
1815 | 0 | if(buf_width > frm_width) |
1816 | 0 | { |
1817 | 0 | memset(pu1_dst + frm_width, 0x80, buf_width - frm_width); |
1818 | 0 | } |
1819 | 0 | pu1_src += src_strd; |
1820 | 0 | pu1_dst += dst_strd; |
1821 | 0 | } |
1822 | 0 | while(rows < buf_height) |
1823 | 0 | { |
1824 | 0 | memset(pu1_dst, 0x80, buf_width); |
1825 | 0 | pu1_dst += dst_strd; |
1826 | 0 | rows++; |
1827 | 0 | } |
1828 | 0 | } |
1829 | 149k | return (IV_SUCCESS); |
1830 | 149k | } |
1831 | | |
1832 | | /*! |
1833 | | ****************************************************************************** |
1834 | | * \if Function name : ihevce_encode_header \endif |
1835 | | * |
1836 | | * \brief |
1837 | | * Receive sps, pps and vps of the encoded sequence |
1838 | | * |
1839 | | * \param[in] Plugin handle, Output buffer |
1840 | | * |
1841 | | * \return |
1842 | | * Success or Failure |
1843 | | * |
1844 | | * \author |
1845 | | * Ittiam |
1846 | | * |
1847 | | ***************************************************************************** |
1848 | | */ |
1849 | | IHEVCE_PLUGIN_STATUS_T ihevce_encode_header(void *pv_ihevce_hdl, ihevce_out_buf_t *ps_out) |
1850 | 8.22k | { |
1851 | 8.22k | plugin_ctxt_t *ps_ctxt = (plugin_ctxt_t *)pv_ihevce_hdl; |
1852 | 8.22k | ihevce_hle_ctxt_t *ps_interface_ctxt; |
1853 | | |
1854 | | /* sanity checks */ |
1855 | 8.22k | if(NULL == pv_ihevce_hdl) |
1856 | 0 | return (IHEVCE_EFAIL); |
1857 | | |
1858 | 8.22k | if(NULL == ps_out) |
1859 | 0 | return (IHEVCE_EFAIL); |
1860 | | |
1861 | 8.22k | if((0 == ps_ctxt->ps_static_cfg_prms->i4_res_id) && |
1862 | 8.22k | (0 == ps_ctxt->ps_static_cfg_prms->i4_br_id)) |
1863 | 8.22k | { |
1864 | 8.22k | WORD32 status; |
1865 | | |
1866 | | /* ------- Que in free output buffer if end flag is not set ------ */ |
1867 | 8.22k | ihevce_queue_out_buffer(ps_ctxt, 0, 0); |
1868 | | |
1869 | | /* ------- API call to encoder header ------- */ |
1870 | 8.22k | ps_interface_ctxt = (ihevce_hle_ctxt_t *)ps_ctxt->pv_hle_interface_ctxt; |
1871 | 8.22k | status = ihevce_entropy_encode_header(ps_interface_ctxt, 0, 0); |
1872 | 8.22k | if(status) |
1873 | 0 | return IHEVCE_EFAIL; |
1874 | | |
1875 | | /* ------- receive header ------- */ |
1876 | 8.22k | ihevce_receive_out_buffer(ps_ctxt, ps_out); |
1877 | 8.22k | } |
1878 | 0 | else |
1879 | 0 | { |
1880 | 0 | return (IHEVCE_EFAIL); |
1881 | 0 | } |
1882 | | |
1883 | 8.22k | return (IHEVCE_EOK); |
1884 | 8.22k | } |
1885 | | |
1886 | | /*! |
1887 | | ****************************************************************************** |
1888 | | * \if Function name : ihevce_encode \endif |
1889 | | * |
1890 | | * \brief |
1891 | | * Frame level processing function |
1892 | | * |
1893 | | * \param[in] Plugin handle, Input buffer, Output buffer |
1894 | | * |
1895 | | * \return |
1896 | | * Success or Failure |
1897 | | * |
1898 | | * \author |
1899 | | * Ittiam |
1900 | | * |
1901 | | ***************************************************************************** |
1902 | | */ |
1903 | | IHEVCE_PLUGIN_STATUS_T |
1904 | | ihevce_encode(void *pv_ihevce_hdl, ihevce_inp_buf_t *ps_inp, ihevce_out_buf_t *ps_out) |
1905 | 149k | { |
1906 | | /* local variables */ |
1907 | 149k | plugin_ctxt_t *ps_ctxt; |
1908 | 149k | app_ctxt_t *ps_app_ctxt; |
1909 | 149k | ihevce_hle_ctxt_t *ps_interface_ctxt; |
1910 | | |
1911 | 149k | WORD32 i4_res_id, i4_br_id; |
1912 | 149k | WORD32 i4_num_resolutions; |
1913 | 149k | WORD32 ai4_num_bitrate_instances[IHEVCE_MAX_NUM_RESOLUTIONS] = { 1 }; |
1914 | 149k | UWORD32 u4_latency = 0; |
1915 | | |
1916 | | /* sanity checks */ |
1917 | 149k | if(NULL == pv_ihevce_hdl) |
1918 | 0 | return (IHEVCE_EFAIL); |
1919 | | |
1920 | 149k | if(NULL == ps_out) |
1921 | 0 | return (IHEVCE_EFAIL); |
1922 | | |
1923 | | /* derive local variables */ |
1924 | 149k | ps_ctxt = (plugin_ctxt_t *)pv_ihevce_hdl; |
1925 | 149k | if((0 == ps_ctxt->ps_static_cfg_prms->i4_res_id) && |
1926 | 149k | (0 == ps_ctxt->ps_static_cfg_prms->i4_br_id)) |
1927 | 149k | { |
1928 | 149k | ps_interface_ctxt = (ihevce_hle_ctxt_t *)ps_ctxt->pv_hle_interface_ctxt; |
1929 | 149k | ps_app_ctxt = &ps_ctxt->s_app_ctxt; |
1930 | 149k | i4_num_resolutions = ps_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.i4_num_res_layers; |
1931 | | |
1932 | 149k | if(ps_ctxt->ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers) |
1933 | 36.7k | { |
1934 | 36.7k | u4_latency += |
1935 | 36.7k | (1 << ps_ctxt->ps_static_cfg_prms->s_coding_tools_prms.i4_max_temporal_layers) - 1; |
1936 | 36.7k | } |
1937 | | |
1938 | 149k | u4_latency += ps_ctxt->ps_static_cfg_prms->s_lap_prms.i4_rc_look_ahead_pics; |
1939 | | |
1940 | | /* Once the internal-flush-flag has been set and codec has issued |
1941 | | end flag, exit encoding by returning IHEVCE_EFAIL */ |
1942 | 149k | if(ps_ctxt->i4_internal_flush) |
1943 | 0 | { |
1944 | 0 | if(1 == ps_app_ctxt->ai4_out_strm_end_flag[0][0]) |
1945 | 0 | return (IHEVCE_EFAIL); |
1946 | 0 | } |
1947 | | |
1948 | 299k | for(i4_res_id = 0; i4_res_id < i4_num_resolutions; i4_res_id++) |
1949 | 149k | { |
1950 | 149k | ai4_num_bitrate_instances[i4_res_id] = |
1951 | 149k | ps_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[i4_res_id] |
1952 | 149k | .i4_num_bitrate_instances; |
1953 | 299k | for(i4_br_id = 0; i4_br_id < ai4_num_bitrate_instances[i4_res_id]; i4_br_id++) |
1954 | 149k | { |
1955 | | /* ------- Que in free output buffer if end flag is not set ------ */ |
1956 | 149k | ihevce_queue_out_buffer(ps_ctxt, i4_res_id, i4_br_id); |
1957 | 149k | } |
1958 | 149k | } |
1959 | | |
1960 | | /* --------------------------------------------------------------------- */ |
1961 | | /* Input Processing */ |
1962 | | /* --------------------------------------------------------------------- */ |
1963 | 149k | if(0 == ps_ctxt->i4_flush_mode_on) |
1964 | 149k | { |
1965 | 149k | WORD32 frm_stride; |
1966 | 149k | WORD32 frm_width; |
1967 | 149k | WORD32 frm_height; |
1968 | 149k | WORD32 buf_id; |
1969 | | |
1970 | 149k | iv_input_data_ctrl_buffs_t *ps_curr_inp; |
1971 | 149k | WORD32 *pi4_ctrl_ptr; |
1972 | | |
1973 | 149k | frm_width = ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_width; |
1974 | 149k | frm_height = ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_height; |
1975 | 149k | frm_stride = ps_ctxt->i4_frm_stride; |
1976 | | |
1977 | | /* ---------- get a free buffer from input Q ------ */ |
1978 | 149k | ps_curr_inp = (iv_input_data_ctrl_buffs_t *)ihevce_q_get_free_inp_data_buff( |
1979 | 149k | ps_interface_ctxt, &buf_id, BUFF_QUE_BLOCKING_MODE); |
1980 | | |
1981 | 149k | if(NULL != ps_curr_inp) |
1982 | 149k | { |
1983 | | /* if input buffer is not NULL */ |
1984 | 149k | if(NULL != ps_inp) |
1985 | 149k | { |
1986 | 149k | WORD32 result; |
1987 | | |
1988 | 149k | pi4_ctrl_ptr = (WORD32 *)ps_curr_inp->pv_synch_ctrl_bufs; |
1989 | | |
1990 | | /* ---------- set ip params ---------- */ |
1991 | 149k | ps_curr_inp->s_input_buf.i4_size = sizeof(iv_yuv_buf_t); |
1992 | 149k | ps_curr_inp->s_input_buf.i4_y_wd = frm_width; |
1993 | 149k | ps_curr_inp->s_input_buf.i4_y_ht = frm_height; |
1994 | 149k | ps_curr_inp->s_input_buf.i4_y_strd = frm_stride; |
1995 | 149k | ps_curr_inp->s_input_buf.i4_uv_wd = frm_width; |
1996 | 149k | ps_curr_inp->s_input_buf.i4_uv_ht = |
1997 | 149k | frm_height >> |
1998 | 149k | ((ps_ctxt->ps_static_cfg_prms->s_src_prms.inp_chr_format == 13) ? 0 : 1); |
1999 | 149k | ps_curr_inp->s_input_buf.i4_uv_strd = frm_stride; |
2000 | | |
2001 | 149k | ps_curr_inp->i4_buf_id = buf_id; |
2002 | 149k | ps_curr_inp->i4_inp_frm_data_valid_flag = 1; |
2003 | 149k | ps_curr_inp->i4_topfield_first = 1; /* set to default */ |
2004 | 149k | ps_curr_inp->i4_bottom_field = ps_ctxt->i4_field_id; |
2005 | 149k | ps_curr_inp->i4_inp_timestamp_low = (WORD32)(ps_inp->u8_pts & 0xFFFFFFFF); |
2006 | 149k | ps_curr_inp->i4_inp_timestamp_high = (WORD32)(ps_inp->u8_pts >> 32); |
2007 | | |
2008 | | /* toggle field id */ |
2009 | 149k | ps_ctxt->i4_field_id = !ps_ctxt->i4_field_id; |
2010 | | |
2011 | | /* ---------- Introduction of Force IDR locs ---------- */ |
2012 | 149k | if(ps_inp->i4_force_idr_flag) |
2013 | 1.34k | { |
2014 | 1.34k | *pi4_ctrl_ptr = IHEVCE_SYNCH_API_FORCE_IDR_TAG; |
2015 | 1.34k | *(pi4_ctrl_ptr + 1) = 0; |
2016 | 1.34k | pi4_ctrl_ptr += 2; |
2017 | | |
2018 | | /* set the cmd to NA */ |
2019 | 1.34k | *pi4_ctrl_ptr = IHEVCE_SYNCH_API_END_TAG; |
2020 | | |
2021 | 1.34k | ps_curr_inp->i4_cmd_buf_size = 4 * 3; /* 12 bytes */ |
2022 | 1.34k | } |
2023 | 148k | else |
2024 | 148k | { |
2025 | | /* set the cmd to NA */ |
2026 | 148k | *pi4_ctrl_ptr = IHEVCE_SYNCH_API_END_TAG; |
2027 | | |
2028 | 148k | ps_curr_inp->i4_cmd_buf_size = 4; /* 4 bytes */ |
2029 | 148k | } |
2030 | | /* call the input copy function */ |
2031 | 149k | result = ihevce_copy_inp_8bit( |
2032 | 149k | ps_curr_inp, |
2033 | 149k | ps_inp, |
2034 | 149k | ps_ctxt->ps_static_cfg_prms->s_src_prms.inp_chr_format, |
2035 | 149k | ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_orig_width, |
2036 | 149k | ps_ctxt->ps_static_cfg_prms->s_src_prms.i4_orig_height); |
2037 | | |
2038 | 149k | if(IV_SUCCESS != result) |
2039 | 0 | return (IHEVCE_EFAIL); |
2040 | | |
2041 | 149k | if(3 != ps_ctxt->ps_static_cfg_prms->s_config_prms.i4_rate_control_mode) |
2042 | 98.0k | { |
2043 | | /* Dynamic Change in bitrate not supported for multi res/MBR */ |
2044 | | /*** Check for change in bitrate command ***/ |
2045 | 98.0k | if(ps_ctxt->ai4_old_bitrate[0][0] != ps_inp->i4_curr_bitrate) |
2046 | 5.28k | { |
2047 | 5.28k | WORD32 buf_id; |
2048 | 5.28k | WORD32 *pi4_cmd_buf; |
2049 | 5.28k | iv_input_ctrl_buffs_t *ps_ctrl_buf; |
2050 | 5.28k | ihevce_dyn_config_prms_t *ps_dyn_br; |
2051 | 5.28k | WORD32 codec_level_index = ihevce_get_level_index( |
2052 | 5.28k | ps_ctxt->ps_static_cfg_prms->s_tgt_lyr_prms.as_tgt_params[0] |
2053 | 5.28k | .i4_codec_level); |
2054 | 5.28k | WORD32 max_bitrate = |
2055 | 5.28k | g_as_level_data[codec_level_index].i4_max_bit_rate |
2056 | 5.28k | [ps_ctxt->ps_static_cfg_prms->s_out_strm_prms.i4_codec_tier] * |
2057 | 5.28k | 1000; |
2058 | | |
2059 | | /* ---------- get a free buffer from command Q ------ */ |
2060 | 5.28k | ps_ctrl_buf = (iv_input_ctrl_buffs_t *)ihevce_q_get_free_inp_ctrl_buff( |
2061 | 5.28k | ps_interface_ctxt, &buf_id, BUFF_QUE_BLOCKING_MODE); |
2062 | | /* store the buffer id */ |
2063 | 5.28k | ps_ctrl_buf->i4_buf_id = buf_id; |
2064 | | |
2065 | | /* get the buffer pointer */ |
2066 | 5.28k | pi4_cmd_buf = (WORD32 *)ps_ctrl_buf->pv_asynch_ctrl_bufs; |
2067 | | |
2068 | | /* store the set default command, encoder should use create time prms */ |
2069 | 5.28k | *pi4_cmd_buf = IHEVCE_ASYNCH_API_SETBITRATE_TAG; |
2070 | 5.28k | *(pi4_cmd_buf + 1) = sizeof(ihevce_dyn_config_prms_t); |
2071 | | |
2072 | 5.28k | ps_dyn_br = (ihevce_dyn_config_prms_t *)(pi4_cmd_buf + 2); |
2073 | 5.28k | ps_dyn_br->i4_size = sizeof(ihevce_dyn_config_prms_t); |
2074 | 5.28k | ps_dyn_br->i4_tgt_br_id = 0; |
2075 | 5.28k | ps_dyn_br->i4_tgt_res_id = 0; |
2076 | 5.28k | ps_dyn_br->i4_new_tgt_bitrate = |
2077 | 5.28k | MIN(ps_inp->i4_curr_bitrate, max_bitrate); |
2078 | 5.28k | ps_dyn_br->i4_new_tgt_bitrate = |
2079 | 5.28k | MAX(ps_dyn_br->i4_new_tgt_bitrate, MIN_BITRATE); |
2080 | 5.28k | ps_dyn_br->i4_new_peak_bitrate = |
2081 | 5.28k | MIN((ps_dyn_br->i4_new_tgt_bitrate << 1), max_bitrate); |
2082 | 5.28k | pi4_cmd_buf += 2; |
2083 | 5.28k | pi4_cmd_buf += (sizeof(ihevce_dyn_config_prms_t) >> 2); |
2084 | | |
2085 | 5.28k | *(pi4_cmd_buf) = IHEVCE_ASYNCH_API_END_TAG; |
2086 | | |
2087 | 5.28k | ps_ctrl_buf->i4_cmd_buf_size = 12 + sizeof(ihevce_dyn_config_prms_t); |
2088 | | |
2089 | | /* ---------- set the buffer as produced ---------- */ |
2090 | 5.28k | ihevce_q_set_inp_ctrl_buff_prod(ps_interface_ctxt, buf_id); |
2091 | | |
2092 | 5.28k | ps_ctxt->ai4_old_bitrate[0][0] = ps_dyn_br->i4_new_tgt_bitrate; |
2093 | 5.28k | } |
2094 | 98.0k | } |
2095 | | |
2096 | 149k | ps_ctxt->u8_num_frames_queued++; |
2097 | 149k | } |
2098 | 0 | else |
2099 | 0 | { /* flush mode command */ |
2100 | |
|
2101 | 0 | ps_curr_inp->i4_buf_id = buf_id; |
2102 | | |
2103 | | /* set the input status to invalid flag */ |
2104 | 0 | ps_curr_inp->i4_inp_frm_data_valid_flag = 0; |
2105 | |
|
2106 | 0 | pi4_ctrl_ptr = (WORD32 *)ps_curr_inp->pv_synch_ctrl_bufs; |
2107 | |
|
2108 | 0 | *pi4_ctrl_ptr = IHEVCE_SYNCH_API_FLUSH_TAG; |
2109 | 0 | *(pi4_ctrl_ptr + 1) = 0; |
2110 | 0 | *(pi4_ctrl_ptr + 2) = IHEVCE_SYNCH_API_END_TAG; |
2111 | |
|
2112 | 0 | ps_curr_inp->i4_cmd_buf_size = 4 * 3; /* 4 bytes */ |
2113 | 0 | } |
2114 | | |
2115 | | /* ---------- set the buffer as produced ---------- */ |
2116 | 149k | ihevce_q_set_inp_data_buff_prod(ps_interface_ctxt, buf_id); |
2117 | 149k | ps_ctxt->u8_num_frames_encoded++; |
2118 | 149k | } |
2119 | 0 | else |
2120 | 0 | { |
2121 | | /* Enable flush-mode and internal-flush once limit according to |
2122 | | Eval-version is reached */ |
2123 | 0 | ps_ctxt->i4_flush_mode_on = 1; |
2124 | 0 | ps_ctxt->i4_internal_flush = 1; |
2125 | 0 | } |
2126 | 149k | } |
2127 | | |
2128 | | /* set encoder in flush mode if input buffer is NULL */ |
2129 | 149k | if(0 == ps_ctxt->i4_flush_mode_on) |
2130 | 149k | { |
2131 | 149k | if(NULL == ps_inp) |
2132 | 0 | { |
2133 | 0 | ps_ctxt->i4_flush_mode_on = 1; |
2134 | 0 | } |
2135 | 149k | } |
2136 | | |
2137 | 149k | if((u4_latency < ps_ctxt->u8_num_frames_queued) || (1 == ps_ctxt->i4_flush_mode_on)) |
2138 | 145k | { |
2139 | | /* --------------------------------------------------------------------- */ |
2140 | | /* Output Processing */ |
2141 | | /* --------------------------------------------------------------------- */ |
2142 | 145k | ihevce_receive_out_buffer(ps_ctxt, ps_out); |
2143 | 145k | } |
2144 | 149k | } |
2145 | 0 | else //Other bitrate and resolution instances |
2146 | 0 | { |
2147 | 0 | return IHEVCE_EFAIL; |
2148 | 0 | } |
2149 | 149k | return (IHEVCE_EOK); |
2150 | 149k | } |
2151 | | |