1 /*--------------------------------------------------------------------------
2 Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6     * Redistributions of source code must retain the above copyright
7       notice, this list of conditions and the following disclaimer.
8     * Redistributions in binary form must reproduce the above copyright
9       notice, this list of conditions and the following disclaimer in the
10       documentation and/or other materials provided with the distribution.
11     * Neither the name of The Linux Foundation nor
12       the names of its contributors may be used to endorse or promote
13       products derived from this software without specific prior written
14       permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 --------------------------------------------------------------------------*/
28 #ifndef _AAC_ENC_H_
29 #define _AAC_ENC_H_
30 /*============================================================================
31                     Audio Encoder
32 
33 @file omx_aac_aenc.h
34 This module contains the class definition for openMAX encoder component.
35 
36 
37 
38 ============================================================================*/
39 
40 //////////////////////////////////////////////////////////////////////////////
41 //                             Include Files
42 //////////////////////////////////////////////////////////////////////////////
43 
44 /* Uncomment out below line #define LOG_NDEBUG 0 if we want to see
45  *  all DEBUG_PRINT or LOGV messaging */
46 #include<stdlib.h>
47 #include <stdio.h>
48 #include <pthread.h>
49 #include <time.h>
50 #include <inttypes.h>
51 #include <unistd.h>
52 #include "QOMX_AudioExtensions.h"
53 #include "QOMX_AudioIndexExtensions.h"
54 #include "OMX_Core.h"
55 #include "OMX_Audio.h"
56 #include "aenc_svr.h"
57 #include "qc_omx_component.h"
58 #include "Map.h"
59 #include <semaphore.h>
60 #include <linux/msm_audio.h>
61 #include <linux/msm_audio_aac.h>
62 extern "C" {
63     void * get_omx_component_factory_fn(void);
64 }
65 
66 
67 //////////////////////////////////////////////////////////////////////////////
68 //                       Module specific globals
69 //////////////////////////////////////////////////////////////////////////////
70 
71 
72 
73 #define OMX_SPEC_VERSION  0x00000101
74 #define min(x,y) (((x) < (y)) ? (x) : (y))
75 #define MAX(x,y) (x >= y?x:y)
76 
77 //////////////////////////////////////////////////////////////////////////////
78 //               Macros
79 //////////////////////////////////////////////////////////////////////////////
80 //
81 
82 
83 #define PrintFrameHdr(i,bufHdr) \
84                            DEBUG_PRINT("i=%d OMX bufHdr[%p]buf[%p]size[%d]TS[%lld]nFlags[0x%x]\n",\
85                            i,\
86                            bufHdr,                                     \
87                            ((OMX_BUFFERHEADERTYPE *)bufHdr)->pBuffer,   \
88                            (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nFilledLen,\
89                            ((OMX_BUFFERHEADERTYPE *)bufHdr)->nTimeStamp, \
90                            (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nFlags)
91 
92 
93 // BitMask Management logic
94 #define BITS_PER_BYTE 8
95 #define BITMASK_SIZE(mIndex) \
96             (((mIndex) + BITS_PER_BYTE - 1)/BITS_PER_BYTE)
97 #define BITMASK_OFFSET(mIndex)\
98             ((mIndex)/BITS_PER_BYTE)
99 #define BITMASK_FLAG(mIndex) \
100             (1 << ((mIndex) % BITS_PER_BYTE))
101 #define BITMASK_CLEAR(mArray,mIndex)\
102             (mArray)[BITMASK_OFFSET(mIndex)] &=  ~(BITMASK_FLAG(mIndex))
103 #define BITMASK_SET(mArray,mIndex)\
104             (mArray)[BITMASK_OFFSET(mIndex)] |=  BITMASK_FLAG(mIndex)
105 #define BITMASK_PRESENT(mArray,mIndex)\
106             ((mArray)[BITMASK_OFFSET(mIndex)] & BITMASK_FLAG(mIndex))
107 #define BITMASK_ABSENT(mArray,mIndex)\
108             (((mArray)[BITMASK_OFFSET(mIndex)] & \
109             BITMASK_FLAG(mIndex)) == 0x0)
110 
111 #define OMX_CORE_NUM_INPUT_BUFFERS    2
112 #define OMX_CORE_NUM_OUTPUT_BUFFERS   16
113 
114 #define OMX_CORE_INPUT_BUFFER_SIZE    8192
115 #define OMX_CORE_CONTROL_CMDQ_SIZE   100
116 #define OMX_AENC_VOLUME_STEP         0x147
117 #define OMX_AENC_MIN                 0
118 #define OMX_AENC_MAX                 100
119 #define NON_TUNNEL                   1
120 #define TUNNEL                       0
121 #define IP_PORT_BITMASK                 0x02
122 #define OP_PORT_BITMASK                 0x01
123 #define IP_OP_PORT_BITMASK              0x03
124 
125 #define DEFAULT_SF            44100
126 #define DEFAULT_CH_CFG        2
127 #define DEFAULT_BITRATE       64000
128 #define OMX_AAC_DEFAULT_VOL         25
129 // 14 bytes for input meta data
130 #define OMX_AENC_SIZEOF_META_BUF     (OMX_CORE_INPUT_BUFFER_SIZE+14)
131 
132 #define TRUE 1
133 #define FALSE 0
134 
135 
136 #define NUMOFFRAMES                   1
137 #define MAXFRAMELENGTH                1536
138 #define OMX_AAC_OUTPUT_BUFFER_SIZE    ((NUMOFFRAMES * (sizeof(ENC_META_OUT)+ MAXFRAMELENGTH + 1)\
139                                           + 1023) & (~1023))
140 //Raw Header
141 #define AUDAAC_MAX_MP4FF_HEADER_LENGTH  2
142 
143 #define AUDAAC_MP4FF_OBJ_TYPE           5
144 #define AUDAAC_MP4FF_FREQ_IDX           4
145 #define AUDAAC_MP4FF_CH_CONFIG          4
146 
147 //ADIF Header
148 #define AUDAAC_MAX_ADIF_HEADER_LENGTH 17
149 
150 #define AAC_COPYRIGHT_PRESENT_SIZE    1
151 #define AAC_ORIGINAL_COPY_SIZE        1
152 #define AAC_HOME_SIZE                 1
153 #define AAC_BITSTREAM_TYPE_SIZE               1
154 #define AAC_BITRATE_SIZE                     23
155 #define AAC_NUM_PFE_SIZE                      4
156 #define AAC_BUFFER_FULLNESS_SIZE             20
157 #define AAC_ELEMENT_INSTANCE_TAG_SIZE         4
158 #define AAC_NUM_FRONT_CHANNEL_ELEMENTS_SIZE   4
159 #define AAC_NUM_SIDE_CHANNEL_ELEMENTS_SIZE    4
160 #define AAC_NUM_BACK_CHANNEL_ELEMENTS_SIZE    4
161 #define AAC_NUM_LFE_CHANNEL_ELEMENTS_SIZE     2
162 #define AAC_NUM_ASSOC_DATA_ELEMENTS_SIZE      3
163 #define AAC_NUM_VALID_CC_ELEMENTS_SIZE        4
164 #define AAC_MONO_MIXDOWN_PRESENT_SIZE         1
165 #define AAC_MONO_MIXDOWN_ELEMENT_SIZE         4
166 #define AAC_STEREO_MIXDOWN_PRESENT_SIZE       1
167 #define AAC_STEREO_MIXDOWN_ELEMENT_SIZE       4
168 #define AAC_MATRIX_MIXDOWN_PRESENT_SIZE       1
169 #define AAC_MATRIX_MIXDOWN_SIZE               3
170 #define AAC_FCE_SIZE                          5
171 #define AAC_SCE_SIZE                          5
172 #define AAC_BCE_SIZE                          5
173 #define AAC_LFE_SIZE                          4
174 #define AAC_ADE_SIZE                          4
175 #define AAC_VCE_SIZE                          5
176 #define AAC_COMMENT_FIELD_BYTES_SIZE          8
177 #define AAC_COMMENT_FIELD_DATA_SIZE           8
178 #define AAC_SAMPLING_FREQ_INDEX_SIZE          4
179 #define AAC_PROFILE_SIZE                      2
180 
181 
182 
183 //Raw Header
184 #define AUDAAC_MAX_RAW_HEADER_LENGTH  8
185 
186 #define AUDAAC_RAW_OBJ_TYPE          8
187 #define AUDAAC_RAW_FREQ_IDX          8
188 #define AUDAAC_RAW_CH_CONFIG         8
189 #define AUDAAC_RAW_SBR_PRESENT       8
190 #define AUDAAC_RAW_SBR_PS_PRESENT    8
191 #define AUDAAC_RAW_EXT_OBJ_TYPE      8
192 #define AUDAAC_RAW_EXT_FREQ_IDX      8
193 #define AUDAAC_RAW_EXT_CH_CONFIG     8
194 
195 struct sample_rate_idx {
196     OMX_U32 sample_rate;
197     OMX_U32 sample_rate_idx;
198 };
199 static struct sample_rate_idx sample_idx_tbl[10] = {
200     {8000, 0x0b},
201     {11025, 0x0a},
202     {12000, 0x09},
203     {16000, 0x08},
204     {22050, 0x07},
205     {24000, 0x06},
206     {32000, 0x05},
207     {44100, 0x04},
208     {48000, 0x03},
209     {64000, 0x02},
210 };
211 class omx_aac_aenc;
212 
213 // OMX AAC audio encoder class
214 class omx_aac_aenc: public qc_omx_component
215 {
216 public:
217     omx_aac_aenc();                             // constructor
218     virtual ~omx_aac_aenc();                    // destructor
219 
220     OMX_ERRORTYPE allocate_buffer(OMX_HANDLETYPE             hComp,
221                                   OMX_BUFFERHEADERTYPE **bufferHdr,
222                                   OMX_U32                     port,
223                                   OMX_PTR                  appData,
224                                   OMX_U32                    bytes);
225 
226 
227     OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp);
228 
229     OMX_ERRORTYPE component_init(OMX_STRING role);
230 
231     OMX_ERRORTYPE component_role_enum(OMX_HANDLETYPE hComp,
232                                       OMX_U8         *role,
233                                       OMX_U32        index);
234 
235     OMX_ERRORTYPE component_tunnel_request(OMX_HANDLETYPE             hComp,
236                                            OMX_U32                     port,
237                                            OMX_HANDLETYPE     peerComponent,
238                                            OMX_U32                 peerPort,
239                                            OMX_TUNNELSETUPTYPE *tunnelSetup);
240 
241     OMX_ERRORTYPE empty_this_buffer(OMX_HANDLETYPE         hComp,
242                                     OMX_BUFFERHEADERTYPE *buffer);
243 
244 
245     OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE         hComp,
246                                           OMX_BUFFERHEADERTYPE *buffer);
247 
248 
249     OMX_ERRORTYPE fill_this_buffer(OMX_HANDLETYPE         hComp,
250                                    OMX_BUFFERHEADERTYPE *buffer);
251 
252 
253     OMX_ERRORTYPE free_buffer(OMX_HANDLETYPE         hComp,
254                               OMX_U32                 port,
255                               OMX_BUFFERHEADERTYPE *buffer);
256 
257     OMX_ERRORTYPE get_component_version(OMX_HANDLETYPE              hComp,
258                                         OMX_STRING          componentName,
259                                         OMX_VERSIONTYPE *componentVersion,
260                                         OMX_VERSIONTYPE *     specVersion,
261                                         OMX_UUIDTYPE       *componentUUID);
262 
263     OMX_ERRORTYPE get_config(OMX_HANDLETYPE      hComp,
264                              OMX_INDEXTYPE configIndex,
265                              OMX_PTR        configData);
266 
267     OMX_ERRORTYPE get_extension_index(OMX_HANDLETYPE     hComp,
268                                       OMX_STRING     paramName,
269                                       OMX_INDEXTYPE *indexType);
270 
271     OMX_ERRORTYPE get_parameter(OMX_HANDLETYPE hComp,
272                                 OMX_INDEXTYPE paramIndex,
273                                 OMX_PTR paramData);
274 
275     OMX_ERRORTYPE get_state(OMX_HANDLETYPE hComp,
276                             OMX_STATETYPE *state);
277 
278     static void process_in_port_msg(void          *client_data,
279                                     unsigned char id);
280 
281     static void process_out_port_msg(void          *client_data,
282                                      unsigned char id);
283 
284     static void process_command_msg(void          *client_data,
285                                     unsigned char id);
286 
287     static void process_event_cb(void          *client_data,
288                                    unsigned char id);
289 
290 
291     OMX_ERRORTYPE set_callbacks(OMX_HANDLETYPE hComp,
292                                 OMX_CALLBACKTYPE *callbacks,
293                                 OMX_PTR appData);
294 
295     OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp,
296                              OMX_INDEXTYPE configIndex,
297                              OMX_PTR configData);
298 
299     OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp,
300                                 OMX_INDEXTYPE paramIndex,
301                                 OMX_PTR paramData);
302 
303     OMX_ERRORTYPE use_buffer(OMX_HANDLETYPE             hComp,
304                              OMX_BUFFERHEADERTYPE **bufferHdr,
305                              OMX_U32                     port,
306                              OMX_PTR                  appData,
307                              OMX_U32                    bytes,
308                              OMX_U8                  *buffer);
309 
310     OMX_ERRORTYPE use_EGL_image(OMX_HANDLETYPE             hComp,
311                                 OMX_BUFFERHEADERTYPE **bufferHdr,
312                                 OMX_U32                     port,
313                                 OMX_PTR                  appData,
314                                 void *                  eglImage);
315 
316     bool post_command(unsigned int p1, unsigned int p2,
317         unsigned char id);
318 
319     // Deferred callback identifiers
320     enum
321     {
322         //Event Callbacks from the component thread context
323         OMX_COMPONENT_GENERATE_EVENT       = 0x1,
324         //Buffer Done callbacks from component thread context
325         OMX_COMPONENT_GENERATE_BUFFER_DONE = 0x2,
326         OMX_COMPONENT_GENERATE_ETB         = 0x3,
327         //Command
328         OMX_COMPONENT_GENERATE_COMMAND     = 0x4,
329         OMX_COMPONENT_GENERATE_FRAME_DONE  = 0x05,
330         OMX_COMPONENT_GENERATE_FTB         = 0x06,
331         OMX_COMPONENT_GENERATE_EOS         = 0x07,
332         OMX_COMPONENT_PORTSETTINGS_CHANGED = 0x08,
333         OMX_COMPONENT_SUSPEND              = 0x09,
334         OMX_COMPONENT_RESUME               = 0x0a
335     };
336 private:
337 
338     ///////////////////////////////////////////////////////////
339     // Type definitions
340     ///////////////////////////////////////////////////////////
341     // Bit Positions
342     enum flags_bit_positions
343     {
344         // Defer transition to IDLE
345         OMX_COMPONENT_IDLE_PENDING            =0x1,
346         // Defer transition to LOADING
347         OMX_COMPONENT_LOADING_PENDING         =0x2,
348 
349         OMX_COMPONENT_MUTED                   =0x3,
350 
351         // Defer transition to Enable
352         OMX_COMPONENT_INPUT_ENABLE_PENDING    =0x4,
353         // Defer transition to Enable
354         OMX_COMPONENT_OUTPUT_ENABLE_PENDING   =0x5,
355         // Defer transition to Disable
356         OMX_COMPONENT_INPUT_DISABLE_PENDING   =0x6,
357         // Defer transition to Disable
358         OMX_COMPONENT_OUTPUT_DISABLE_PENDING  =0x7
359     };
360 
361     #define MIN_BITRATE 24000
362     #define MAX_BITRATE 192000
363     #define MAX_BITRATE_MULFACTOR 12
364     #define BITRATE_DIVFACTOR 2
365     typedef Map<OMX_BUFFERHEADERTYPE*, OMX_BUFFERHEADERTYPE*>
366     input_buffer_map;
367 
368     typedef Map<OMX_BUFFERHEADERTYPE*, OMX_BUFFERHEADERTYPE*>
369     output_buffer_map;
370 
371     enum port_indexes
372     {
373         OMX_CORE_INPUT_PORT_INDEX        =0,
374         OMX_CORE_OUTPUT_PORT_INDEX       =1
375     };
376 
377     struct omx_event
378     {
379         unsigned long param1;
380         unsigned long param2;
381         unsigned char id;
382     };
383 
384     struct omx_cmd_queue
385     {
386         omx_event m_q[OMX_CORE_CONTROL_CMDQ_SIZE];
387         unsigned m_read;
388         unsigned m_write;
389         unsigned m_size;
390 
391         omx_cmd_queue();
392         ~omx_cmd_queue();
393         bool insert_entry(unsigned long p1, unsigned long p2, unsigned char id);
394         bool pop_entry(unsigned long *p1,unsigned long *p2, unsigned char *id);
395         bool get_msg_id(unsigned char *id);
396         bool get_msg_with_id(unsigned *p1,unsigned *p2, unsigned id);
397     };
398 
399     typedef struct TIMESTAMP
400     {
401         unsigned int LowPart;
402         unsigned int HighPart;
403     }__attribute__((packed)) TIMESTAMP;
404 
405     typedef struct metadata_input
406     {
407         unsigned short offsetVal;
408         TIMESTAMP      nTimeStamp;
409         unsigned int   nFlags;
410     }__attribute__((packed)) META_IN;
411 
412     typedef struct enc_meta_out
413     {
414         unsigned int offset_to_frame;
415         unsigned int frame_size;
416         unsigned int encoded_pcm_samples;
417         unsigned int msw_ts;
418         unsigned int lsw_ts;
419         unsigned int nflags;
420     } __attribute__ ((packed))ENC_META_OUT;
421 
422     typedef struct
423     {
424         OMX_U32 tot_in_buf_len;
425         OMX_U32 tot_out_buf_len;
426         OMX_TICKS tot_pb_time;
427         OMX_U32 fbd_cnt;
428         OMX_U32 ftb_cnt;
429         OMX_U32 etb_cnt;
430         OMX_U32 ebd_cnt;
431     }AAC_PB_STATS;
432 
433     ///////////////////////////////////////////////////////////
434     // Member variables
435     ///////////////////////////////////////////////////////////
436     OMX_U8                         *m_tmp_meta_buf;
437     OMX_U8                         *m_tmp_out_meta_buf;
438     OMX_U8                         m_flush_cnt ;
439     OMX_U8                         m_comp_deinit;
440 
441     // the below var doesnt hold good if combo of use and alloc bufs are used
442     OMX_U8                         m_eos_bm;
443     OMX_S32                        m_volume;//Unit to be determined
444     OMX_U8                         audaac_header_adif[AUDAAC_MAX_ADIF_HEADER_LENGTH];
445     OMX_U8                         audaac_header_mp4ff[AUDAAC_MAX_MP4FF_HEADER_LENGTH];
446     OMX_U16                        audaac_hdr_bit_index;
447     OMX_S32                        sample_idx;
448     OMX_S32                        adif_flag;
449     OMX_S32                        mp4ff_flag;
450     OMX_PTR                        m_app_data;// Application data
451     int                            nNumInputBuf;
452     int                            nNumOutputBuf;
453     int                            m_drv_fd;   // Kernel device node file handle
454     bool                           bFlushinprogress;
455     bool                           is_in_th_sleep;
456     bool                           is_out_th_sleep;
457     unsigned int                   m_flags;      //encapsulate the waiting states.
458     OMX_U64                        nTimestamp;
459     OMX_U64                        ts;
460     uint32_t                       m_frame_count;
461     unsigned int                   frameduration;
462     unsigned int                   pcm_input; //tunnel or non-tunnel
463     unsigned int                   m_inp_act_buf_count;    // Num of Input Buffers
464     unsigned int                   m_out_act_buf_count;    // Numb of Output Buffers
465     unsigned int                   m_inp_current_buf_count;    // Num of Input Buffers
466     unsigned int                   m_out_current_buf_count;    // Numb of Output Buffers
467     unsigned int                   output_buffer_size;
468     unsigned int                   input_buffer_size;
469     unsigned short                 m_session_id;
470     // store I/P PORT state
471     OMX_BOOL                       m_inp_bEnabled;
472     // store O/P PORT state
473     OMX_BOOL                       m_out_bEnabled;
474     //Input port Populated
475     OMX_BOOL                       m_inp_bPopulated;
476     //Output port Populated
477     OMX_BOOL                       m_out_bPopulated;
478     sem_t                          sem_States;
479     sem_t                          sem_read_msg;
480     sem_t                          sem_write_msg;
481 
482     volatile int                   m_is_event_done;
483     volatile int                   m_is_in_th_sleep;
484     volatile int                   m_is_out_th_sleep;
485     input_buffer_map               m_input_buf_hdrs;
486     output_buffer_map              m_output_buf_hdrs;
487     omx_cmd_queue                  m_input_q;
488     omx_cmd_queue                  m_input_ctrl_cmd_q;
489     omx_cmd_queue                  m_input_ctrl_ebd_q;
490     omx_cmd_queue                  m_command_q;
491     omx_cmd_queue                  m_output_q;
492     omx_cmd_queue                  m_output_ctrl_cmd_q;
493     omx_cmd_queue                  m_output_ctrl_fbd_q;
494     pthread_mutexattr_t            m_outputlock_attr;
495     pthread_mutexattr_t            m_commandlock_attr;
496     pthread_mutexattr_t            m_lock_attr;
497     pthread_mutexattr_t            m_state_attr;
498     pthread_mutexattr_t            m_flush_attr;
499     pthread_mutexattr_t            m_in_th_attr_1;
500     pthread_mutexattr_t            m_out_th_attr_1;
501     pthread_mutexattr_t            m_event_attr;
502     pthread_mutexattr_t            m_in_th_attr;
503     pthread_mutexattr_t            m_out_th_attr;
504     pthread_mutexattr_t            out_buf_count_lock_attr;
505     pthread_mutexattr_t            in_buf_count_lock_attr;
506     pthread_cond_t                 cond;
507     pthread_cond_t                 in_cond;
508     pthread_cond_t                 out_cond;
509     pthread_mutex_t                m_lock;
510     pthread_mutex_t                m_commandlock;
511     pthread_mutex_t                m_outputlock;
512     // Mutexes for state change
513     pthread_mutex_t                m_state_lock;
514     // Mutexes for  flush acks from input and output threads
515     pthread_mutex_t                m_flush_lock;
516     pthread_mutex_t                m_event_lock;
517     pthread_mutex_t                m_in_th_lock;
518     pthread_mutex_t                m_out_th_lock;
519     pthread_mutex_t                m_in_th_lock_1;
520     pthread_mutex_t                m_out_th_lock_1;
521     pthread_mutex_t                out_buf_count_lock;
522     pthread_mutex_t                in_buf_count_lock;
523 
524     OMX_STATETYPE                  m_state;      // OMX State
525     OMX_STATETYPE                  nState;
526     OMX_CALLBACKTYPE               m_cb;         // Application callbacks
527     AAC_PB_STATS                  m_aac_pb_stats;
528     struct aac_ipc_info           *m_ipc_to_in_th;    // for input thread
529     struct aac_ipc_info           *m_ipc_to_out_th;    // for output thread
530     struct aac_ipc_info           *m_ipc_to_cmd_th;    // for command thread
531     OMX_PRIORITYMGMTTYPE           m_priority_mgm ;
532     OMX_AUDIO_PARAM_AACPROFILETYPE m_aac_param; // Cache AAC encoder parameter
533     OMX_AUDIO_PARAM_PCMMODETYPE    m_pcm_param;  // Cache pcm  parameter
534     OMX_PARAM_COMPONENTROLETYPE    component_Role;
535     OMX_PARAM_BUFFERSUPPLIERTYPE   m_buffer_supplier;
536 
537     ///////////////////////////////////////////////////////////
538     // Private methods
539     ///////////////////////////////////////////////////////////
540     OMX_ERRORTYPE allocate_output_buffer(OMX_HANDLETYPE       hComp,
541                                          OMX_BUFFERHEADERTYPE **bufferHdr,
542                                          OMX_U32 port,OMX_PTR appData,
543                                          OMX_U32              bytes);
544 
545     OMX_ERRORTYPE allocate_input_buffer(OMX_HANDLETYPE       hComp,
546                                         OMX_BUFFERHEADERTYPE **bufferHdr,
547                                         OMX_U32              port,
548                                         OMX_PTR              appData,
549                                         OMX_U32              bytes);
550 
551     OMX_ERRORTYPE use_input_buffer(OMX_IN OMX_HANDLETYPE          hComp,
552                                    OMX_INOUT OMX_BUFFERHEADERTYPE **bufHdr,
553                                    OMX_IN OMX_U32                 port,
554                                    OMX_IN OMX_PTR                 appData,
555                                    OMX_IN OMX_U32                 bytes,
556                                    OMX_IN OMX_U8*                 buffer);
557 
558     OMX_ERRORTYPE use_output_buffer(OMX_IN OMX_HANDLETYPE          hComp,
559                                     OMX_INOUT OMX_BUFFERHEADERTYPE **bufHdr,
560                                     OMX_IN OMX_U32                 port,
561                                     OMX_IN OMX_PTR                 appData,
562                                     OMX_IN OMX_U32                 bytes,
563                                     OMX_IN OMX_U8*                 buffer);
564 
565     OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE       hComp,
566                                          OMX_BUFFERHEADERTYPE *buffer);
567 
568     OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE  hComp,
569                                      OMX_COMMANDTYPE cmd,
570                                      OMX_U32         param1,
571                                      OMX_PTR         cmdData);
572 
573     OMX_ERRORTYPE send_command(OMX_HANDLETYPE hComp,
574                                OMX_COMMANDTYPE  cmd,
575                                OMX_U32       param1,
576                                OMX_PTR      cmdData);
577 
578     bool allocate_done(void);
579 
580     bool release_done(OMX_U32         param1);
581 
582     bool execute_omx_flush(OMX_IN OMX_U32 param1, bool cmd_cmpl=true);
583 
584     bool execute_input_omx_flush(void);
585 
586     bool execute_output_omx_flush(void);
587 
588     bool search_input_bufhdr(OMX_BUFFERHEADERTYPE *buffer);
589 
590     bool search_output_bufhdr(OMX_BUFFERHEADERTYPE *buffer);
591 
592     bool post_input(unsigned long p1, unsigned long p2,
593                     unsigned char id);
594 
595     bool post_output(unsigned long p1, unsigned long p2,
596                      unsigned char id);
597 
598     void process_events(omx_aac_aenc *client_data);
599 
600     void buffer_done_cb(OMX_BUFFERHEADERTYPE *bufHdr);
601 
602     void frame_done_cb(OMX_BUFFERHEADERTYPE *bufHdr);
603 
604     void wait_for_event();
605 
606     void event_complete();
607 
608     void in_th_goto_sleep();
609 
610     void in_th_wakeup();
611 
612     void out_th_goto_sleep();
613 
614     void out_th_wakeup();
615 
616     void flush_ack();
617     void deinit_encoder();
618     void audaac_rec_install_adif_header_variable (OMX_U16  byte_num,
619                         OMX_U32 sample_index, OMX_U8 channel_config);
620     void  audaac_rec_install_mp4ff_header_variable (OMX_U16  byte_num,
621                         OMX_U32 sample_index,OMX_U8 channel_config);
622     void audaac_rec_install_bits(OMX_U8 *input,
623                 OMX_U8 num_bits_reqd,
624                 OMX_U32  value,
625                 OMX_U16 *hdr_bit_index);
626     int get_updated_bit_rate(int bitrate);
627 
628 };
629 #endif
630