Coverage Report

Created: 2025-07-09 06:20

/src/libhevc/encoder/ihevce_hle_q_func.c
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2018 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*!
22
******************************************************************************
23
* \file ihevce_hle_que_func.c
24
*
25
* \brief
26
*    This file contains Que finction of Hehg level encoder
27
*
28
* \date
29
*    18/09/2012
30
*
31
* \author
32
*    Ittiam
33
*
34
* List of Functions
35
*    <TODO: TO BE ADDED>
36
*
37
******************************************************************************
38
*/
39
40
/*****************************************************************************/
41
/* File Includes                                                             */
42
/*****************************************************************************/
43
/* System include files */
44
#include <stdio.h>
45
#include <string.h>
46
#include <stdlib.h>
47
#include <assert.h>
48
#include <stdarg.h>
49
#include <math.h>
50
51
/* User include files */
52
#include "ihevc_typedefs.h"
53
#include "itt_video_api.h"
54
#include "ihevce_api.h"
55
56
#include "rc_cntrl_param.h"
57
#include "rc_frame_info_collector.h"
58
#include "rc_look_ahead_params.h"
59
60
#include "ihevc_defs.h"
61
#include "ihevc_macros.h"
62
#include "ihevc_debug.h"
63
#include "ihevc_structs.h"
64
#include "ihevc_platform_macros.h"
65
#include "ihevc_deblk.h"
66
#include "ihevc_itrans_recon.h"
67
#include "ihevc_chroma_itrans_recon.h"
68
#include "ihevc_chroma_intra_pred.h"
69
#include "ihevc_intra_pred.h"
70
#include "ihevc_inter_pred.h"
71
#include "ihevc_mem_fns.h"
72
#include "ihevc_padding.h"
73
#include "ihevc_weighted_pred.h"
74
#include "ihevc_sao.h"
75
#include "ihevc_resi_trans.h"
76
#include "ihevc_quant_iquant_ssd.h"
77
#include "ihevc_cabac_tables.h"
78
#include "ihevc_trans_tables.h"
79
#include "ihevc_trans_macros.h"
80
81
#include "ihevce_defs.h"
82
#include "ihevce_hle_interface.h"
83
#include "ihevce_hle_q_func.h"
84
#include "ihevce_buffer_que_interface.h"
85
#include "ihevce_lap_enc_structs.h"
86
#include "ihevce_multi_thrd_structs.h"
87
#include "ihevce_multi_thrd_funcs.h"
88
#include "ihevce_me_common_defs.h"
89
#include "ihevce_had_satd.h"
90
#include "ihevce_error_codes.h"
91
#include "ihevce_error_checks.h"
92
#include "ihevce_bitstream.h"
93
#include "ihevce_cabac.h"
94
#include "ihevce_rdoq_macros.h"
95
#include "ihevce_function_selector.h"
96
#include "ihevce_enc_structs.h"
97
98
#include "cast_types.h"
99
#include "osal.h"
100
#include "osal_defaults.h"
101
102
/*****************************************************************************/
103
/* Function Definitions                                                      */
104
/*****************************************************************************/
105
106
/*!
107
******************************************************************************
108
* \if Function name : ihevce_q_get_free_buff \endif
109
*
110
* \brief
111
*    Gets a free buffer from the que requested
112
*
113
* \param[in] high level encoder context pointer
114
* \param[in] Que id of the buffer
115
* \param[in] pointer to return the buffer id
116
*
117
* \return
118
*    None
119
*
120
* \author
121
*  Ittiam
122
*
123
*****************************************************************************
124
*/
125
void *ihevce_q_get_free_buff(
126
    void *pv_enc_ctxt, WORD32 i4_q_id, WORD32 *pi4_buff_id, WORD32 i4_blocking_mode)
127
1.07M
{
128
    /* local varaibles */
129
1.07M
    WORD32 end_flag = 0;
130
1.07M
    void *pv_buff = NULL;
131
1.07M
    WORD32 i4_mres_single_out;
132
1.07M
    enc_ctxt_t *ps_enc_ctxt = (enc_ctxt_t *)pv_enc_ctxt;
133
1.07M
    i4_mres_single_out = ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_mres_single_out;
134
135
2.24M
    while(1 != end_flag)
136
1.16M
    {
137
        /* acquire mutex lock */
138
1.16M
        osal_mutex_lock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);
139
140
        /* call the buffer api function */
141
1.16M
        pv_buff =
142
1.16M
            ihevce_buff_que_get_free_buf(ps_enc_ctxt->s_enc_ques.apv_q_hdl[i4_q_id], pi4_buff_id);
143
144
        /* release mutex lock */
145
1.16M
        osal_mutex_unlock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);
146
147
        /* if no free buffer is available */
148
1.16M
        if(NULL == pv_buff)
149
85.6k
        {
150
            /* check if the mode is blocking */
151
85.6k
            if(BUFF_QUE_BLOCKING_MODE == i4_blocking_mode)
152
85.6k
            {
153
                /* ------------------------------------------------- */
154
                /* Get free buffers are called by producers          */
155
                /* these producers threads will be put in pend state */
156
                /* ------------------------------------------------- */
157
158
                /* choose the semaphore based on Que Id */
159
85.6k
                void *pv_sem_handle = NULL;
160
161
                /* input data Que : application's input data processing */
162
                /* thread is put to pend state                          */
163
85.6k
                if(IHEVCE_INPUT_DATA_CTRL_Q == i4_q_id)
164
0
                {
165
0
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_data_sem_handle;
166
0
                }
167
168
                /* input ctrl Que : application's input ctrl processing */
169
                /* thread is put to pend state                          */
170
85.6k
                if(IHEVCE_INPUT_ASYNCH_CTRL_Q == i4_q_id)
171
0
                {
172
0
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_ctrl_sem_handle;
173
0
                }
174
175
85.6k
                if(IHEVCE_ENC_INPUT_Q == i4_q_id)
176
0
                {
177
0
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_inp_data_sem_hdl;
178
0
                }
179
180
                /* Output data Que : Output thread is put to pend state */
181
85.6k
                if(IHEVCE_OUTPUT_DATA_Q == i4_q_id)
182
0
                {
183
0
                    if(1 == i4_mres_single_out)
184
0
                    {
185
0
                        pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_common_mres_sem_hdl;
186
0
                    }
187
0
                    else
188
0
                    {
189
0
                        pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_strm_sem_handle[0];
190
0
                    }
191
0
                }
192
                /* Recon data Que : Recon thread is put to pend state */
193
85.6k
                if(IHEVCE_RECON_DATA_Q == i4_q_id)
194
0
                {
195
0
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_recon_sem_handle[0];
196
0
                }
197
                /* frm prs ent cod data Que : frame process is put to pend state */
198
85.6k
                if(IHEVCE_FRM_PRS_ENT_COD_Q == i4_q_id)
199
2.37k
                {
200
2.37k
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle;
201
2.37k
                }
202
                /* Pre encode/ encode data Que : pre enocde is put to pend state */
203
85.6k
                if(IHEVCE_PRE_ENC_ME_Q == i4_q_id)
204
0
                {
205
0
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle;
206
0
                }
207
                /* ME/ENC Que : enc frame proc is put to pend state */
208
85.6k
                if(IHEVCE_ME_ENC_RDOPT_Q == i4_q_id)
209
0
                {
210
0
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle;
211
0
                }
212
85.6k
                if(IHEVCE_L0_IPE_ENC_Q == i4_q_id)
213
83.2k
                {
214
83.2k
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle;
215
83.2k
                }
216
                /* output status queue should be used by both LAP and Frame
217
                   process in non blocking mode */
218
85.6k
                if(IHEVCE_OUTPUT_STATUS_Q == i4_q_id)
219
0
                {
220
0
                    ASSERT(0);
221
0
                }
222
223
                /* go the pend state */
224
85.6k
                osal_sem_wait(pv_sem_handle);
225
85.6k
            }
226
            /* if non blocking then return NULL and break from loop */
227
0
            else
228
0
            {
229
0
                end_flag = 1;
230
0
            }
231
85.6k
        }
232
        /* if valid free buffer is available then break from loop */
233
1.07M
        else
234
1.07M
        {
235
1.07M
            end_flag = 1;
236
1.07M
        }
237
1.16M
    }
238
239
1.07M
    return (pv_buff);
240
1.07M
}
241
242
/*!
243
******************************************************************************
244
* \if Function name : ihevce_q_set_buff_prod \endif
245
*
246
* \brief
247
*    Sets the buffer as produced in the que requested
248
*
249
* \param[in] high level encoder context pointer
250
* \param[in] Que id of the buffer
251
* \param[in] buffer id which needs to be set as produced
252
*
253
* \return
254
*    None
255
*
256
* \author
257
*  Ittiam
258
*
259
*****************************************************************************
260
*/
261
IV_API_CALL_STATUS_T ihevce_q_set_buff_prod(void *pv_enc_ctxt, WORD32 i4_q_id, WORD32 i4_buff_id)
262
1.07M
{
263
    /* local varaibles */
264
265
1.07M
    WORD32 i4_num_users = 0;
266
1.07M
    WORD32 i4_mres_single_out;
267
1.07M
    enc_ctxt_t *ps_enc_ctxt = (enc_ctxt_t *)pv_enc_ctxt;
268
1.07M
    i4_mres_single_out = ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_mres_single_out;
269
270
    /* acquire mutex lock */
271
1.07M
    osal_mutex_lock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);
272
273
    /* call the buffer api function */
274
1.07M
    ihevce_buff_que_set_buf_prod(
275
1.07M
        ps_enc_ctxt->s_enc_ques.apv_q_hdl[i4_q_id], i4_buff_id, i4_num_users);
276
277
    /* release mutex lock */
278
1.07M
    osal_mutex_unlock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);
279
280
    /* ------------------------------------------------------------- */
281
    /* after setting the buffer the consumers thread needs to be     */
282
    /* posted in case if that thread is in wait state                */
283
    /* currently this post is done unconditionally                   */
284
    /* ------------------------------------------------------------- */
285
286
    /* input command que : LAP & Frame process threads needs to posted */
287
1.07M
    if(IHEVCE_INPUT_ASYNCH_CTRL_Q == i4_q_id)
288
5.68k
    {
289
5.68k
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle);
290
5.68k
    }
291
292
    /* input data que : LAP thread needs to posted */
293
1.07M
    if(IHEVCE_INPUT_DATA_CTRL_Q == i4_q_id)
294
177k
    {
295
177k
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle);
296
177k
    }
297
298
    /* output stream data que :  Entropy processing thread needs to posted */
299
1.07M
    if(IHEVCE_OUTPUT_DATA_Q == i4_q_id)
300
186k
    {
301
186k
        WORD32 i4_entropy_thrd_id;
302
186k
        WORD32 i4_bufque_id;
303
304
186k
        i4_bufque_id = (i4_q_id - IHEVCE_OUTPUT_DATA_Q);
305
186k
        i4_entropy_thrd_id = i4_bufque_id;
306
307
186k
        if(i4_bufque_id == 0)
308
186k
        {
309
186k
            i4_entropy_thrd_id = ps_enc_ctxt->i4_ref_mbr_id;
310
186k
        }
311
0
        else if(i4_bufque_id == ps_enc_ctxt->i4_ref_mbr_id)
312
0
        {
313
0
            i4_entropy_thrd_id = 0;
314
0
        }
315
316
186k
        if(IHEVCE_OUTPUT_DATA_Q == i4_q_id)
317
186k
        {
318
186k
            if(1 == i4_mres_single_out)
319
0
            {
320
0
                osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_ent_common_mres_sem_hdl);
321
0
            }
322
186k
            else
323
186k
            {
324
186k
                osal_sem_post(
325
186k
                    ps_enc_ctxt->s_thrd_sem_ctxt.apv_ent_cod_sem_handle[i4_entropy_thrd_id]);
326
186k
            }
327
186k
        }
328
186k
    }
329
330
    /* output recon data que :  app's output data processing thread needs to posted */
331
1.07M
    if(IHEVCE_RECON_DATA_Q == i4_q_id)
332
0
    {
333
0
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle);
334
0
    }
335
    /* output control que :  app's output processing thread needs to posted */
336
1.07M
    if(IHEVCE_OUTPUT_STATUS_Q == i4_q_id)
337
0
    {
338
0
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_ctrl_sem_handle);
339
0
    }
340
341
    /* frm process entropy que :  entropy thread needs to posted */
342
1.07M
    if(IHEVCE_FRM_PRS_ENT_COD_Q == i4_q_id)
343
177k
    {
344
177k
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.apv_ent_cod_sem_handle[0]);
345
177k
    }
346
    /* pre-encode/encode que :  encode frame proc thread needs to posted */
347
1.07M
    if(IHEVCE_PRE_ENC_ME_Q == i4_q_id)
348
177k
    {
349
177k
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle);
350
177k
    }
351
    /* ME/ENC Que : enc frame proc needs to be posted */
352
1.07M
    if(IHEVCE_ME_ENC_RDOPT_Q == i4_q_id)
353
177k
    {
354
177k
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle);
355
177k
    }
356
1.07M
    if(IHEVCE_L0_IPE_ENC_Q == i4_q_id)
357
177k
    {
358
177k
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle);
359
177k
    }
360
361
1.07M
    if(IHEVCE_ENC_INPUT_Q == i4_q_id)
362
0
    {
363
0
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_preenc_inp_data_sem_hdl);
364
0
    }
365
366
1.07M
    return (IV_SUCCESS);
367
1.07M
}
368
369
/*!
370
******************************************************************************
371
* \if Function name : ihevce_q_get_filled_buff \endif
372
*
373
* \brief
374
*    Gets a next filled buffer from the que requested
375
*
376
* \param[in] high level encoder context pointer
377
* \param[in] Que id of the buffer
378
* \param[in] pointer to return the buffer id
379
*
380
* \return
381
*    None
382
*
383
* \author
384
*  Ittiam
385
*
386
*****************************************************************************
387
*/
388
void *ihevce_q_get_filled_buff(
389
    void *pv_enc_ctxt, WORD32 i4_q_id, WORD32 *pi4_buff_id, WORD32 i4_blocking_mode)
390
1.25M
{
391
    /* local varaibles */
392
1.25M
    WORD32 end_flag = 0;
393
1.25M
    void *pv_buff = NULL;
394
1.25M
    WORD32 i4_mres_single_out;
395
1.25M
    enc_ctxt_t *ps_enc_ctxt = (enc_ctxt_t *)pv_enc_ctxt;
396
1.25M
    i4_mres_single_out = ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_mres_single_out;
397
398
3.93M
    while(1 != end_flag)
399
2.67M
    {
400
        /* acquire mutex lock */
401
2.67M
        osal_mutex_lock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);
402
403
        /* call the buffer api function */
404
2.67M
        pv_buff =
405
2.67M
            ihevce_buff_que_get_next_buf(ps_enc_ctxt->s_enc_ques.apv_q_hdl[i4_q_id], pi4_buff_id);
406
407
        /* release mutex lock */
408
2.67M
        osal_mutex_unlock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);
409
410
        /* if no free buffer is available */
411
2.67M
        if(NULL == pv_buff)
412
1.60M
        {
413
            /* check if the mode is blocking */
414
1.60M
            if(BUFF_QUE_BLOCKING_MODE == i4_blocking_mode)
415
1.42M
            {
416
                /* ------------------------------------------------- */
417
                /* Get filled buffers are called by consumers        */
418
                /* these consumer threads will be put in pend state */
419
                /* ------------------------------------------------- */
420
421
                /* choose the semaphore based on Que Id */
422
1.42M
                void *pv_sem_handle = NULL;
423
424
                /* input data Que : LAP thread is put to pend state */
425
1.42M
                if(IHEVCE_INPUT_DATA_CTRL_Q == i4_q_id)
426
189k
                {
427
189k
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle;
428
189k
                }
429
430
                /* input ctrl Que : LAP thread is put to pend state */
431
1.42M
                if(IHEVCE_INPUT_ASYNCH_CTRL_Q == i4_q_id)
432
0
                {
433
0
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle;
434
0
                }
435
436
                /* Output Stream data Que : Entropy processing */
437
                /* thread is put to pend state                              */
438
1.42M
                if(IHEVCE_OUTPUT_DATA_Q == i4_q_id)
439
0
                {
440
0
                    WORD32 i4_entropy_thrd_id;
441
0
                    WORD32 i4_bufque_id;
442
443
0
                    i4_bufque_id = (i4_q_id - IHEVCE_OUTPUT_DATA_Q);
444
0
                    i4_entropy_thrd_id = i4_bufque_id;
445
446
0
                    if(i4_bufque_id == 0)
447
0
                    {
448
0
                        i4_entropy_thrd_id = ps_enc_ctxt->i4_ref_mbr_id;
449
0
                    }
450
0
                    else if(i4_bufque_id == ps_enc_ctxt->i4_ref_mbr_id)
451
0
                    {
452
0
                        i4_entropy_thrd_id = 0;
453
0
                    }
454
455
0
                    if(IHEVCE_OUTPUT_DATA_Q == i4_q_id)
456
0
                    {
457
0
                        if(1 == i4_mres_single_out)
458
0
                        {
459
0
                            pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_ent_common_mres_sem_hdl;
460
0
                        }
461
0
                        else
462
0
                        {
463
0
                            pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt
464
0
                                                .apv_ent_cod_sem_handle[i4_entropy_thrd_id];
465
0
                        }
466
0
                    }
467
0
                }
468
469
                /* Output Recon data Que : Frame processing */
470
                /* thread is put to pend state                       */
471
1.42M
                if(IHEVCE_RECON_DATA_Q == i4_q_id)
472
0
                {
473
0
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle;
474
0
                }
475
                /* frm prs ent cod data Que : entropy thread is put to pend state */
476
1.42M
                if(IHEVCE_FRM_PRS_ENT_COD_Q == i4_q_id)
477
372k
                {
478
372k
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.apv_ent_cod_sem_handle[0];
479
372k
                }
480
                /* Output status Que : application's output processing */
481
                /* thread is put to pend state                         */
482
1.42M
                if(IHEVCE_OUTPUT_STATUS_Q == i4_q_id)
483
0
                {
484
0
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_ctrl_sem_handle;
485
0
                }
486
487
                /* pre-encode/encode Que : encode frame proc thread  */
488
1.42M
                if(IHEVCE_PRE_ENC_ME_Q == i4_q_id)
489
858k
                {
490
858k
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle;
491
858k
                }
492
                /* ME/ENC Que : enc frame proc is put to pend state */
493
1.42M
                if(IHEVCE_ME_ENC_RDOPT_Q == i4_q_id)
494
0
                {
495
0
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle;
496
0
                }
497
1.42M
                if(IHEVCE_L0_IPE_ENC_Q == i4_q_id)
498
89
                {
499
89
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle;
500
89
                }
501
                /* This call will be made from pre-enc enc thread, hence when input is not available the caller thread should go to pend */
502
1.42M
                if(IHEVCE_ENC_INPUT_Q == i4_q_id)
503
0
                {
504
0
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_preenc_inp_data_sem_hdl;
505
0
                }
506
507
                /* go the pend state */
508
1.42M
                osal_sem_wait(pv_sem_handle);
509
1.42M
            }
510
            /* if non blocking then return NULL and break from loop */
511
180k
            else
512
180k
            {
513
180k
                end_flag = 1;
514
180k
            }
515
1.60M
        }
516
        /* if valid filled buffer is available then break from loop */
517
1.07M
        else
518
1.07M
        {
519
1.07M
            end_flag = 1;
520
1.07M
        }
521
2.67M
    }
522
523
1.25M
    return (pv_buff);
524
1.25M
}
525
526
/*!
527
******************************************************************************
528
* \if Function name : ihevce_q_rel_buf \endif
529
*
530
* \brief
531
*    Frees the buffer as in the que requested
532
*
533
* \param[in] high level encoder context pointer
534
* \param[in] Que id of the buffer
535
* \param[in] buffer id which needs to be freed
536
*
537
* \return
538
*    None
539
*
540
* \author
541
*  Ittiam
542
*
543
*****************************************************************************
544
*/
545
IV_API_CALL_STATUS_T ihevce_q_rel_buf(void *pv_enc_ctxt, WORD32 i4_q_id, WORD32 i4_buff_id)
546
1.08M
{
547
    /* local varaibles */
548
1.08M
    WORD32 i4_mres_single_out;
549
1.08M
    enc_ctxt_t *ps_enc_ctxt = (enc_ctxt_t *)pv_enc_ctxt;
550
1.08M
    i4_mres_single_out = ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_mres_single_out;
551
    /* acquire mutex lock */
552
1.08M
    osal_mutex_lock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);
553
554
    /* call the buffer api function */
555
1.08M
    ihevce_buff_que_rel_buf(ps_enc_ctxt->s_enc_ques.apv_q_hdl[i4_q_id], i4_buff_id);
556
557
    /* release mutex lock */
558
1.08M
    osal_mutex_unlock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);
559
560
    /* ------------------------------------------------------------- */
561
    /* after releasing the buffer the producer thread needs to be    */
562
    /* posted in case if that thread is in wait state                */
563
    /* currently this post is done unconditionally                   */
564
    /* ------------------------------------------------------------- */
565
566
    /* input data que :  app's input data producing thread needs to posted */
567
1.08M
    if(IHEVCE_INPUT_DATA_CTRL_Q == i4_q_id)
568
177k
    {
569
177k
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_data_sem_handle);
570
177k
    }
571
572
    /* input data control que :  app's command que producing thread needs to posted */
573
1.08M
    if(IHEVCE_INPUT_ASYNCH_CTRL_Q == i4_q_id)
574
5.68k
    {
575
5.68k
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_ctrl_sem_handle);
576
5.68k
    }
577
    /*multiple input queue*/
578
1.08M
    if(IHEVCE_ENC_INPUT_Q == i4_q_id)
579
0
    {
580
0
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_inp_data_sem_hdl);
581
0
    }
582
583
    /* output data que: Output thread needs to posted */
584
1.08M
    if(IHEVCE_OUTPUT_DATA_Q == i4_q_id)
585
186k
    {
586
186k
        if(1 == i4_mres_single_out)
587
0
        {
588
0
            osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_common_mres_sem_hdl);
589
0
        }
590
186k
        else
591
186k
        {
592
186k
            osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_strm_sem_handle[0]);
593
186k
        }
594
186k
    }
595
    /* Recon data que: Recon thread needs to posted */
596
1.08M
    if(IHEVCE_RECON_DATA_Q == i4_q_id)
597
0
    {
598
0
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_recon_sem_handle[0]);
599
0
    }
600
    /* output status que: LAP & Frame process threads needs to posted */
601
1.08M
    if(IHEVCE_OUTPUT_STATUS_Q == i4_q_id)
602
0
    {
603
0
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle);
604
0
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle);
605
0
    }
606
607
    /* frm process entropy que :  Frame process needs to posted */
608
1.08M
    if(IHEVCE_FRM_PRS_ENT_COD_Q == i4_q_id)
609
177k
    {
610
177k
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle);
611
177k
    }
612
    /* pre-encode/encode Que : pre-encode frame proc needs to be posted */
613
1.08M
    if(IHEVCE_PRE_ENC_ME_Q == i4_q_id)
614
186k
    {
615
186k
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle);
616
186k
    }
617
    /* ME/ENC Que : enc frame proc needs to be posted */
618
1.08M
    if(IHEVCE_ME_ENC_RDOPT_Q == i4_q_id)
619
177k
    {
620
177k
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle);
621
177k
    }
622
1.08M
    if(IHEVCE_L0_IPE_ENC_Q == i4_q_id)
623
177k
    {
624
177k
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle);
625
177k
    }
626
1.08M
    return (IV_SUCCESS);
627
1.08M
}
628
629
/*!
630
******************************************************************************
631
* \if Function name : ihevce_force_end \endif
632
*
633
* \brief
634
*    Sets force end flag in enc_ctxt for all resolutions
635
*
636
* \param[in] high level encoder context pointer
637
*
638
* \return
639
*    None
640
*
641
* \author
642
*  Ittiam
643
*
644
*****************************************************************************
645
*/
646
void ihevce_force_end(ihevce_hle_ctxt_t *ps_hle_ctxt)
647
0
{
648
0
    enc_ctxt_t *ps_enc_ctxt;
649
0
    WORD32 i4_resolution_id = 0;
650
0
    WORD32 i4_num_res_layers = 0;
651
0
    ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[0];
652
653
0
    i4_num_res_layers = ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_num_res_layers;
654
0
    for(i4_resolution_id = 0; i4_resolution_id < i4_num_res_layers; i4_resolution_id++)
655
0
    {
656
0
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[i4_resolution_id];
657
0
        ps_enc_ctxt->s_multi_thrd.i4_force_end_flag = 1;
658
0
    }
659
0
}