aboutsummaryrefslogtreecommitdiff
path: root/encoder/ihevce_hle_q_func.c
blob: eab3350a7c2a704ad62de29566aae9c6517b863c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
/******************************************************************************
 *
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/

/*!
******************************************************************************
* \file ihevce_hle_que_func.c
*
* \brief
*    This file contains Que finction of Hehg level encoder
*
* \date
*    18/09/2012
*
* \author
*    Ittiam
*
* List of Functions
*    <TODO: TO BE ADDED>
*
******************************************************************************
*/

/*****************************************************************************/
/* File Includes                                                             */
/*****************************************************************************/
/* System include files */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdarg.h>
#include <math.h>

/* User include files */
#include "ihevc_typedefs.h"
#include "itt_video_api.h"
#include "ihevce_api.h"

#include "rc_cntrl_param.h"
#include "rc_frame_info_collector.h"
#include "rc_look_ahead_params.h"

#include "ihevc_defs.h"
#include "ihevc_macros.h"
#include "ihevc_debug.h"
#include "ihevc_structs.h"
#include "ihevc_platform_macros.h"
#include "ihevc_deblk.h"
#include "ihevc_itrans_recon.h"
#include "ihevc_chroma_itrans_recon.h"
#include "ihevc_chroma_intra_pred.h"
#include "ihevc_intra_pred.h"
#include "ihevc_inter_pred.h"
#include "ihevc_mem_fns.h"
#include "ihevc_padding.h"
#include "ihevc_weighted_pred.h"
#include "ihevc_sao.h"
#include "ihevc_resi_trans.h"
#include "ihevc_quant_iquant_ssd.h"
#include "ihevc_cabac_tables.h"
#include "ihevc_trans_tables.h"
#include "ihevc_trans_macros.h"

#include "ihevce_defs.h"
#include "ihevce_hle_interface.h"
#include "ihevce_hle_q_func.h"
#include "ihevce_buffer_que_interface.h"
#include "ihevce_lap_enc_structs.h"
#include "ihevce_multi_thrd_structs.h"
#include "ihevce_multi_thrd_funcs.h"
#include "ihevce_me_common_defs.h"
#include "ihevce_had_satd.h"
#include "ihevce_error_codes.h"
#include "ihevce_error_checks.h"
#include "ihevce_bitstream.h"
#include "ihevce_cabac.h"
#include "ihevce_rdoq_macros.h"
#include "ihevce_function_selector.h"
#include "ihevce_enc_structs.h"

#include "cast_types.h"
#include "osal.h"
#include "osal_defaults.h"

/*****************************************************************************/
/* Function Definitions                                                      */
/*****************************************************************************/

/*!
******************************************************************************
* \if Function name : ihevce_q_get_free_buff \endif
*
* \brief
*    Gets a free buffer from the que requested
*
* \param[in] high level encoder context pointer
* \param[in] Que id of the buffer
* \param[in] pointer to return the buffer id
*
* \return
*    None
*
* \author
*  Ittiam
*
*****************************************************************************
*/
void *ihevce_q_get_free_buff(
    void *pv_enc_ctxt, WORD32 i4_q_id, WORD32 *pi4_buff_id, WORD32 i4_blocking_mode)
{
    /* local varaibles */
    WORD32 end_flag = 0;
    void *pv_buff = NULL;
    WORD32 i4_mres_single_out;
    enc_ctxt_t *ps_enc_ctxt = (enc_ctxt_t *)pv_enc_ctxt;
    i4_mres_single_out = ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_mres_single_out;

    while(1 != end_flag)
    {
        /* acquire mutex lock */
        osal_mutex_lock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);

        /* call the buffer api function */
        pv_buff =
            ihevce_buff_que_get_free_buf(ps_enc_ctxt->s_enc_ques.apv_q_hdl[i4_q_id], pi4_buff_id);

        /* release mutex lock */
        osal_mutex_unlock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);

        /* if no free buffer is available */
        if(NULL == pv_buff)
        {
            /* check if the mode is blocking */
            if(BUFF_QUE_BLOCKING_MODE == i4_blocking_mode)
            {
                /* ------------------------------------------------- */
                /* Get free buffers are called by producers          */
                /* these producers threads will be put in pend state */
                /* ------------------------------------------------- */

                /* choose the semaphore based on Que Id */
                void *pv_sem_handle = NULL;

                /* input data Que : application's input data processing */
                /* thread is put to pend state                          */
                if(IHEVCE_INPUT_DATA_CTRL_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_data_sem_handle;
                }

                /* input ctrl Que : application's input ctrl processing */
                /* thread is put to pend state                          */
                if(IHEVCE_INPUT_ASYNCH_CTRL_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_ctrl_sem_handle;
                }

                if(IHEVCE_ENC_INPUT_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_inp_data_sem_hdl;
                }

                /* Output data Que : Output thread is put to pend state */
                if(IHEVCE_OUTPUT_DATA_Q == i4_q_id)
                {
                    if(1 == i4_mres_single_out)
                    {
                        pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_common_mres_sem_hdl;
                    }
                    else
                    {
                        pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_strm_sem_handle[0];
                    }
                }
                /* Recon data Que : Recon thread is put to pend state */
                if(IHEVCE_RECON_DATA_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_recon_sem_handle[0];
                }
                /* frm prs ent cod data Que : frame process is put to pend state */
                if(IHEVCE_FRM_PRS_ENT_COD_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle;
                }
                /* Pre encode/ encode data Que : pre enocde is put to pend state */
                if(IHEVCE_PRE_ENC_ME_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle;
                }
                /* ME/ENC Que : enc frame proc is put to pend state */
                if(IHEVCE_ME_ENC_RDOPT_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle;
                }
                if(IHEVCE_L0_IPE_ENC_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle;
                }
                /* output status queue should be used by both LAP and Frame
                   process in non blocking mode */
                if(IHEVCE_OUTPUT_STATUS_Q == i4_q_id)
                {
                    ASSERT(0);
                }

                /* go the pend state */
                osal_sem_wait(pv_sem_handle);
            }
            /* if non blocking then return NULL and break from loop */
            else
            {
                end_flag = 1;
            }
        }
        /* if valid free buffer is available then break from loop */
        else
        {
            end_flag = 1;
        }
    }

    return (pv_buff);
}

/*!
******************************************************************************
* \if Function name : ihevce_q_set_buff_prod \endif
*
* \brief
*    Sets the buffer as produced in the que requested
*
* \param[in] high level encoder context pointer
* \param[in] Que id of the buffer
* \param[in] buffer id which needs to be set as produced
*
* \return
*    None
*
* \author
*  Ittiam
*
*****************************************************************************
*/
IV_API_CALL_STATUS_T ihevce_q_set_buff_prod(void *pv_enc_ctxt, WORD32 i4_q_id, WORD32 i4_buff_id)
{
    /* local varaibles */

    WORD32 i4_num_users = 0;
    WORD32 i4_mres_single_out;
    enc_ctxt_t *ps_enc_ctxt = (enc_ctxt_t *)pv_enc_ctxt;
    i4_mres_single_out = ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_mres_single_out;

    /* acquire mutex lock */
    osal_mutex_lock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);

    /* call the buffer api function */
    ihevce_buff_que_set_buf_prod(
        ps_enc_ctxt->s_enc_ques.apv_q_hdl[i4_q_id], i4_buff_id, i4_num_users);

    /* release mutex lock */
    osal_mutex_unlock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);

    /* ------------------------------------------------------------- */
    /* after setting the buffer the consumers thread needs to be     */
    /* posted in case if that thread is in wait state                */
    /* currently this post is done unconditionally                   */
    /* ------------------------------------------------------------- */

    /* input command que : LAP & Frame process threads needs to posted */
    if(IHEVCE_INPUT_ASYNCH_CTRL_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle);
    }

    /* input data que : LAP thread needs to posted */
    if(IHEVCE_INPUT_DATA_CTRL_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle);
    }

    /* output stream data que :  Entropy processing thread needs to posted */
    if(IHEVCE_OUTPUT_DATA_Q == i4_q_id)
    {
        WORD32 i4_entropy_thrd_id;
        WORD32 i4_bufque_id;

        i4_bufque_id = (i4_q_id - IHEVCE_OUTPUT_DATA_Q);
        i4_entropy_thrd_id = i4_bufque_id;

        if(i4_bufque_id == 0)
        {
            i4_entropy_thrd_id = ps_enc_ctxt->i4_ref_mbr_id;
        }
        else if(i4_bufque_id == ps_enc_ctxt->i4_ref_mbr_id)
        {
            i4_entropy_thrd_id = 0;
        }

        if(IHEVCE_OUTPUT_DATA_Q == i4_q_id)
        {
            if(1 == i4_mres_single_out)
            {
                osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_ent_common_mres_sem_hdl);
            }
            else
            {
                osal_sem_post(
                    ps_enc_ctxt->s_thrd_sem_ctxt.apv_ent_cod_sem_handle[i4_entropy_thrd_id]);
            }
        }
    }

    /* output recon data que :  app's output data processing thread needs to posted */
    if(IHEVCE_RECON_DATA_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle);
    }
    /* output control que :  app's output processing thread needs to posted */
    if(IHEVCE_OUTPUT_STATUS_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_ctrl_sem_handle);
    }

    /* frm process entropy que :  entropy thread needs to posted */
    if(IHEVCE_FRM_PRS_ENT_COD_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.apv_ent_cod_sem_handle[0]);
    }
    /* pre-encode/encode que :  encode frame proc thread needs to posted */
    if(IHEVCE_PRE_ENC_ME_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle);
    }
    /* ME/ENC Que : enc frame proc needs to be posted */
    if(IHEVCE_ME_ENC_RDOPT_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle);
    }
    if(IHEVCE_L0_IPE_ENC_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle);
    }

    if(IHEVCE_ENC_INPUT_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_preenc_inp_data_sem_hdl);
    }

    return (IV_SUCCESS);
}

/*!
******************************************************************************
* \if Function name : ihevce_q_get_filled_buff \endif
*
* \brief
*    Gets a next filled buffer from the que requested
*
* \param[in] high level encoder context pointer
* \param[in] Que id of the buffer
* \param[in] pointer to return the buffer id
*
* \return
*    None
*
* \author
*  Ittiam
*
*****************************************************************************
*/
void *ihevce_q_get_filled_buff(
    void *pv_enc_ctxt, WORD32 i4_q_id, WORD32 *pi4_buff_id, WORD32 i4_blocking_mode)
{
    /* local varaibles */
    WORD32 end_flag = 0;
    void *pv_buff = NULL;
    WORD32 i4_mres_single_out;
    enc_ctxt_t *ps_enc_ctxt = (enc_ctxt_t *)pv_enc_ctxt;
    i4_mres_single_out = ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_mres_single_out;

    while(1 != end_flag)
    {
        /* acquire mutex lock */
        osal_mutex_lock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);

        /* call the buffer api function */
        pv_buff =
            ihevce_buff_que_get_next_buf(ps_enc_ctxt->s_enc_ques.apv_q_hdl[i4_q_id], pi4_buff_id);

        /* release mutex lock */
        osal_mutex_unlock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);

        /* if no free buffer is available */
        if(NULL == pv_buff)
        {
            /* check if the mode is blocking */
            if(BUFF_QUE_BLOCKING_MODE == i4_blocking_mode)
            {
                /* ------------------------------------------------- */
                /* Get filled buffers are called by consumers        */
                /* these consumer threads will be put in pend state */
                /* ------------------------------------------------- */

                /* choose the semaphore based on Que Id */
                void *pv_sem_handle = NULL;

                /* input data Que : LAP thread is put to pend state */
                if(IHEVCE_INPUT_DATA_CTRL_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle;
                }

                /* input ctrl Que : LAP thread is put to pend state */
                if(IHEVCE_INPUT_ASYNCH_CTRL_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle;
                }

                /* Output Stream data Que : Entropy processing */
                /* thread is put to pend state                              */
                if(IHEVCE_OUTPUT_DATA_Q == i4_q_id)
                {
                    WORD32 i4_entropy_thrd_id;
                    WORD32 i4_bufque_id;

                    i4_bufque_id = (i4_q_id - IHEVCE_OUTPUT_DATA_Q);
                    i4_entropy_thrd_id = i4_bufque_id;

                    if(i4_bufque_id == 0)
                    {
                        i4_entropy_thrd_id = ps_enc_ctxt->i4_ref_mbr_id;
                    }
                    else if(i4_bufque_id == ps_enc_ctxt->i4_ref_mbr_id)
                    {
                        i4_entropy_thrd_id = 0;
                    }

                    if(IHEVCE_OUTPUT_DATA_Q == i4_q_id)
                    {
                        if(1 == i4_mres_single_out)
                        {
                            pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_ent_common_mres_sem_hdl;
                        }
                        else
                        {
                            pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt
                                                .apv_ent_cod_sem_handle[i4_entropy_thrd_id];
                        }
                    }
                }

                /* Output Recon data Que : Frame processing */
                /* thread is put to pend state                       */
                if(IHEVCE_RECON_DATA_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle;
                }
                /* frm prs ent cod data Que : entropy thread is put to pend state */
                if(IHEVCE_FRM_PRS_ENT_COD_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.apv_ent_cod_sem_handle[0];
                }
                /* Output status Que : application's output processing */
                /* thread is put to pend state                         */
                if(IHEVCE_OUTPUT_STATUS_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_ctrl_sem_handle;
                }

                /* pre-encode/encode Que : encode frame proc thread  */
                if(IHEVCE_PRE_ENC_ME_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle;
                }
                /* ME/ENC Que : enc frame proc is put to pend state */
                if(IHEVCE_ME_ENC_RDOPT_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle;
                }
                if(IHEVCE_L0_IPE_ENC_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle;
                }
                /* This call will be made from pre-enc enc thread, hence when input is not available the caller thread should go to pend */
                if(IHEVCE_ENC_INPUT_Q == i4_q_id)
                {
                    pv_sem_handle = ps_enc_ctxt->s_thrd_sem_ctxt.pv_preenc_inp_data_sem_hdl;
                }

                /* go the pend state */
                osal_sem_wait(pv_sem_handle);
            }
            /* if non blocking then return NULL and break from loop */
            else
            {
                end_flag = 1;
            }
        }
        /* if valid filled buffer is available then break from loop */
        else
        {
            end_flag = 1;
        }
    }

    return (pv_buff);
}

/*!
******************************************************************************
* \if Function name : ihevce_q_rel_buf \endif
*
* \brief
*    Frees the buffer as in the que requested
*
* \param[in] high level encoder context pointer
* \param[in] Que id of the buffer
* \param[in] buffer id which needs to be freed
*
* \return
*    None
*
* \author
*  Ittiam
*
*****************************************************************************
*/
IV_API_CALL_STATUS_T ihevce_q_rel_buf(void *pv_enc_ctxt, WORD32 i4_q_id, WORD32 i4_buff_id)
{
    /* local varaibles */
    WORD32 i4_mres_single_out;
    enc_ctxt_t *ps_enc_ctxt = (enc_ctxt_t *)pv_enc_ctxt;
    i4_mres_single_out = ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_mres_single_out;
    /* acquire mutex lock */
    osal_mutex_lock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);

    /* call the buffer api function */
    ihevce_buff_que_rel_buf(ps_enc_ctxt->s_enc_ques.apv_q_hdl[i4_q_id], i4_buff_id);

    /* release mutex lock */
    osal_mutex_unlock(ps_enc_ctxt->s_enc_ques.pv_q_mutex_hdl);

    /* ------------------------------------------------------------- */
    /* after releasing the buffer the producer thread needs to be    */
    /* posted in case if that thread is in wait state                */
    /* currently this post is done unconditionally                   */
    /* ------------------------------------------------------------- */

    /* input data que :  app's input data producing thread needs to posted */
    if(IHEVCE_INPUT_DATA_CTRL_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_data_sem_handle);
    }

    /* input data control que :  app's command que producing thread needs to posted */
    if(IHEVCE_INPUT_ASYNCH_CTRL_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_inp_ctrl_sem_handle);
    }
    /*multiple input queue*/
    if(IHEVCE_ENC_INPUT_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_inp_data_sem_hdl);
    }

    /* output data que: Output thread needs to posted */
    if(IHEVCE_OUTPUT_DATA_Q == i4_q_id)
    {
        if(1 == i4_mres_single_out)
        {
            osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_out_common_mres_sem_hdl);
        }
        else
        {
            osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_strm_sem_handle[0]);
        }
    }
    /* Recon data que: Recon thread needs to posted */
    if(IHEVCE_RECON_DATA_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.apv_out_recon_sem_handle[0]);
    }
    /* output status que: LAP & Frame process threads needs to posted */
    if(IHEVCE_OUTPUT_STATUS_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_lap_sem_handle);
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle);
    }

    /* frm process entropy que :  Frame process needs to posted */
    if(IHEVCE_FRM_PRS_ENT_COD_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle);
    }
    /* pre-encode/encode Que : pre-encode frame proc needs to be posted */
    if(IHEVCE_PRE_ENC_ME_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle);
    }
    /* ME/ENC Que : enc frame proc needs to be posted */
    if(IHEVCE_ME_ENC_RDOPT_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_enc_frm_proc_sem_handle);
    }
    if(IHEVCE_L0_IPE_ENC_Q == i4_q_id)
    {
        osal_sem_post(ps_enc_ctxt->s_thrd_sem_ctxt.pv_pre_enc_frm_proc_sem_handle);
    }
    return (IV_SUCCESS);
}

/*!
******************************************************************************
* \if Function name : ihevce_force_end \endif
*
* \brief
*    Sets force end flag in enc_ctxt for all resolutions
*
* \param[in] high level encoder context pointer
*
* \return
*    None
*
* \author
*  Ittiam
*
*****************************************************************************
*/
void ihevce_force_end(ihevce_hle_ctxt_t *ps_hle_ctxt)
{
    enc_ctxt_t *ps_enc_ctxt;
    WORD32 i4_resolution_id = 0;
    WORD32 i4_num_res_layers = 0;
    ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[0];

    i4_num_res_layers = ps_enc_ctxt->ps_stat_prms->s_tgt_lyr_prms.i4_num_res_layers;
    for(i4_resolution_id = 0; i4_resolution_id < i4_num_res_layers; i4_resolution_id++)
    {
        ps_enc_ctxt = (enc_ctxt_t *)ps_hle_ctxt->apv_enc_hdl[i4_resolution_id];
        ps_enc_ctxt->s_multi_thrd.i4_force_end_flag = 1;
    }
}