Home | History | Annotate | Download | only in inc
      1 
      2 /*
      3  * Copyright (C) Texas Instruments - http://www.ti.com/
      4  *
      5  * This library is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU Lesser General Public
      7  * License as published by the Free Software Foundation; either
      8  * version 2.1 of the License, or (at your option) any later version.
      9  *
     10  *
     11  * This library is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Lesser General Public License for more details.
     15  *
     16  *
     17  * You should have received a copy of the GNU Lesser General Public
     18  * License along with this library; if not, write to the Free Software
     19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
     20  */
     21 /* =============================================================================
     22 *             Texas Instruments OMAP(TM) Platform Software
     23 *  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
     24 *
     25 *  Use of this software is controlled by the terms and conditions found
     26 *  in the license agreement under which this software has been supplied.
     27 * ============================================================================ */
     28 /**
     29 * @file OMX_Mp3Dec_Utils.h
     30 *
     31 * This is an header file for an audio MP3 decoder that is fully
     32 * compliant with the OMX Audio specification.
     33 * This the file is used internally by the component
     34 * in its code.
     35 *
     36 * @path  $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\mp3_dec\inc\
     37 *
     38 * @rev 1.0
     39 */
     40 /* --------------------------------------------------------------------------- */
     41 #ifndef OMX_MP3DEC_UTILS__H
     42 #define OMX_MP3DEC_UTILS__H
     43 
     44 #include <OMX_Component.h>
     45 #include "OMX_TI_Common.h"
     46 #include <OMX_TI_Debug.h>
     47 #include "LCML_DspCodec.h"
     48 
     49 #ifdef UNDER_CE
     50 #include <windows.h>
     51 #include <oaf_osal.h>
     52 #include <omx_core.h>
     53 #include <stdlib.h>
     54 #else
     55 #include <pthread.h>
     56 #endif
     57 
     58 #ifndef UNDER_CE
     59 
     60 #ifdef RESOURCE_MANAGER_ENABLED
     61 #include <ResourceManagerProxyAPI.h>
     62 #endif
     63 
     64 
     65 #define _ERROR_PROPAGATION__
     66 #ifdef __PERF_INSTRUMENTATION__
     67     #include "perf.h"
     68 #endif
     69 
     70 #ifndef ANDROID
     71     #define ANDROID
     72 #endif
     73 
     74 #ifdef ANDROID
     75     /* Log for Android system*/
     76     #include <utils/Log.h>
     77     #undef LOG_TAG
     78     #define LOG_TAG "OMX_MP3"
     79 
     80     /* PV opencore capability custom parameter index */
     81     #define PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX 0xFF7A347
     82 #endif
     83 
     84 #endif
     85 
     86 #define MP3DEC_MAJOR_VER 0x1/* Major number of the component */
     87 #define MP3DEC_MINOR_VER 0x1 /* Mnor number of the component */
     88 #define NOT_USED 10 /* Value not used */
     89 #define NORMAL_BUFFER 0 /* Marks a buffer as normal buffer */
     90 #define OMX_MP3DEC_DEFAULT_SEGMENT (0) /* default segment ID of the component */
     91 #define OMX_MP3DEC_SN_TIMEOUT (-1) /* tomeout value keep waiting until get the message */
     92 #define OMX_MP3DEC_SN_PRIORITY (10) /* SN priority value */
     93 
     94 #define MP3DEC_BUFHEADER_VERSION 0x0 /* Buffer Header structure version number */
     95 #define MP3D_TIMEOUT (1000) /* default timeout in millisecs */
     96 #define MP3_CPU 25
     97 
     98 /* #define DSP_RENDERING_ON*/ /* Enable to use DASF functionality */
     99 /* #define MP3DEC_MEMDEBUG */ /* Enable memory leaks debuf info */
    100 //#define MP3DEC_DEBUG    /* See all debug statement of the component */
    101 /* #define MP3DEC_MEMDETAILS */  /* See memory details of the component */
    102 /* #define MP3DEC_BUFDETAILS */  /* See buffers details of the component */
    103 // #define MP3DEC_STATEDETAILS /* See all state transitions of the component*/
    104 
    105 #define MP3_APP_ID  100 /* Defines MP3 Dec App ID, App must use this value */
    106 #define MP3D_MAX_NUM_OF_BUFS 10 /* Max number of buffers used */
    107 #define MP3D_NUM_INPUT_BUFFERS 4  /* Default number of input buffers */
    108 #define MP3D_NUM_OUTPUT_BUFFERS 4 /* Default number of output buffers */
    109 
    110 #define MP3D_INPUT_BUFFER_SIZE  2000*4 /* Default size of input buffer */
    111 #define MP3D_OUTPUT_BUFFER_SIZE 8192 /* Default size of output buffer */
    112 #define MP3D_DEFAULT_FREQUENCY 44100 /* Default sample frequency*/
    113 
    114 #define OUTPUT_PORT_MP3DEC 1
    115 #define INPUT_PORT_MP3DEC 0
    116 
    117 #define MP3D_MONO_STREAM  1 /* Mono stream index */
    118 #define MP3D_STEREO_INTERLEAVED_STREAM  2 /* Stereo Interleaved stream index */
    119 #define MP3D_STEREO_NONINTERLEAVED_STREAM  3 /* Stereo Non-Interleaved stream index */
    120 
    121 #define MP3D_STEREO_STREAM  2
    122 
    123 #define NUM_OF_PORTS 0x2 /* Number of ports of component */
    124 
    125 #ifdef UNDER_CE
    126 #define MP3DEC_USN_DLL_NAME "\\windows\\usn.dll64P"
    127 #else
    128 #define MP3DEC_USN_DLL_NAME "usn.dll64P"
    129 #endif
    130 
    131 #ifdef UNDER_CE
    132 #define MP3DEC_DLL_NAME "\\windows\\mp3dec_sn.dll64P"
    133 #else
    134 #define MP3DEC_DLL_NAME "mp3dec_sn.dll64P"
    135 #endif
    136 
    137 #define DONT_CARE 0
    138 
    139 #define EXIT_COMPONENT_THRD  10
    140 
    141 #ifdef UNDER_CE /* For Windows */
    142 
    143 #ifdef  MP3DEC_DEBUG
    144  #define MP3DEC_DPRINT(STR, ARG...) printf()
    145 #else
    146 #endif
    147 
    148 #ifdef  MP3DEC_DEBUG
    149  #define MP3DEC_EPRINT(STR, ARG...) printf()
    150 #else
    151 #endif
    152 
    153 
    154 #ifdef MP3DEC_MEMCHECK
    155         #define MP3DEC_MEMPRINT(STR, ARG...) printf()
    156 #else
    157 #endif
    158 
    159 #ifdef MP3DEC_STATEDETAILS
    160         #define MP3DEC_STATEPRINT(STR, ARG...) printf()
    161 #else
    162 #endif
    163 
    164 
    165 #ifdef MP3DEC_BUFDETAILS
    166         #define MP3DEC_BUFPRINT(STR, ARG...) printf()
    167 #else
    168 #endif
    169 
    170 #ifdef MP3DEC_MEMDETAILS
    171         #define MP3DEC_MEMPRINT(STR, ARG...) printf()
    172 #else
    173 #endif
    174 
    175 
    176 #ifdef DEBUG
    177         #define MP3DEC_DPRINT   printf
    178         #define MP3DEC_EPRINT   printf
    179         #define MP3DEC_MEMPRINT   printf
    180         #define MP3DEC_STATEPRINT   printf
    181         #define MP3DEC_BUFPRINT   printf
    182 #else
    183         #define MP3DEC_DPRINT
    184         #define MP3DEC_EPRINT printf
    185         #define MP3DEC_MEMPRINT
    186         #define MP3DEC_STATEPRINT
    187         #define MP3DEC_BUFPRINT
    188 #endif
    189 
    190 #else /* for Linux */
    191 #ifdef  MP3DEC_DEBUG
    192 
    193   #ifdef ANDROID
    194     #define MP3DEC_DPRINT  ALOGW
    195     #define MP3DEC_BUFPRINT ALOGW
    196     #define MP3DEC_MEMPRINT ALOGW
    197     #define MP3DEC_STATEPRINT ALOGW
    198   #else
    199     #define MP3DEC_DPRINT  printf
    200     #define MP3DEC_BUFPRINT printf
    201     #define MP3DEC_MEMPRINT printf
    202     #define MP3DEC_STATEPRINT printf
    203   #endif
    204 
    205 #else
    206     #define MP3DEC_DPRINT(...)
    207 
    208     #ifdef MP3DEC_STATEDETAILS
    209         #define MP3DEC_STATEPRINT printf
    210     #else
    211         #define MP3DEC_STATEPRINT(...)
    212     #endif
    213 
    214     #ifdef MP3DEC_BUFDETAILS
    215         #define MP3DEC_BUFPRINT printf
    216     #else
    217         #define MP3DEC_BUFPRINT(...)
    218     #endif
    219 
    220     #ifdef MP3DEC_MEMDETAILS
    221         #define MP3DEC_MEMPRINT printf
    222     #else
    223         #define MP3DEC_MEMPRINT(...)
    224     #endif
    225 
    226 #endif
    227 
    228 #ifdef ANDROID
    229   #define MP3DEC_EPRINT ALOGE
    230 #else
    231   #define MP3DEC_EPRINT printf
    232 #endif
    233 
    234 #endif
    235 
    236 #define MP3D_OMX_ERROR_EXIT(_e_, _c_, _s_)\
    237     _e_ = _c_;\
    238     OMXDBG_PRINT(stderr, ERROR, 4, 0, "\n**************** OMX ERROR ************************\n");\
    239     OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d : Error Name: %s : Error Num = %x",__LINE__, _s_, _e_);\
    240     OMXDBG_PRINT(stderr, ERROR, 4, 0, "\n**************** OMX ERROR ************************\n");\
    241     goto EXIT;
    242 
    243 
    244 #define MP3D_OMX_CONF_CHECK_CMD(_ptr1, _ptr2, _ptr3) \
    245 {                                               \
    246     if(!_ptr1 || !_ptr2 || !_ptr3){             \
    247         eError = OMX_ErrorBadParameter;         \
    248         goto EXIT;                 \
    249     }                                           \
    250 }
    251 
    252 #define OMX_CONF_INIT_STRUCT(_s_, _name_)       \
    253     memset((_s_), 0x0, sizeof(_name_)); \
    254     (_s_)->nSize = sizeof(_name_);              \
    255     (_s_)->nVersion.s.nVersionMajor = 0x1;      \
    256     (_s_)->nVersion.s.nVersionMinor = 0x1;      \
    257     (_s_)->nVersion.s.nRevision = 0x1;          \
    258     (_s_)->nVersion.s.nStep = 0x0
    259 
    260 /* ======================================================================= */
    261 /** PV_OMXComponentCapabilityFlagsType: this communicates capabilities to opencore client
    262 *
    263 */
    264 /* ==================================================================== */
    265 typedef struct PV_OMXComponentCapabilityFlagsType
    266 {
    267         ////////////////// OMX COMPONENT CAPABILITY RELATED MEMBERS (for opencore compatability)
    268         OMX_BOOL iIsOMXComponentMultiThreaded;
    269         OMX_BOOL iOMXComponentSupportsExternalOutputBufferAlloc;
    270         OMX_BOOL iOMXComponentSupportsExternalInputBufferAlloc;
    271         OMX_BOOL iOMXComponentSupportsMovableInputBuffers;
    272         OMX_BOOL iOMXComponentSupportsPartialFrames;
    273         OMX_BOOL iOMXComponentNeedsNALStartCode;
    274         OMX_BOOL iOMXComponentCanHandleIncompleteFrames;
    275 } PV_OMXComponentCapabilityFlagsType;
    276 /* ======================================================================= */
    277 /** MP3D_COMP_PORT_TYPE: This enum is used by the OMX Component.
    278 *
    279 * @param MP3D_INPUT_PORT: Specifies Input port.
    280 *
    281 * @param MP3D_OUTPUT_PORT: Specifies Output port.
    282 */
    283 /* ==================================================================== */
    284 typedef enum MP3D_COMP_PORT_TYPE {
    285     MP3D_INPUT_PORT = 0,
    286     MP3D_OUTPUT_PORT
    287 }MP3D_COMP_PORT_TYPE;
    288 
    289 /* ======================================================================= */
    290 /**
    291  * pthread variable to indicate OMX returned all buffers to app
    292  */
    293 /* ======================================================================= */
    294     pthread_mutex_t bufferReturned_mutex;
    295     pthread_cond_t bufferReturned_condition;
    296 
    297 /* ======================================================================= */
    298 /** OMX_INDEXAUDIOTYPE: This enum is used by the TI OMX Component.
    299 *
    300 * @param :
    301 *
    302 * @param :
    303 */
    304 /* ==================================================================== */
    305 
    306 typedef enum OMX_INDEXAUDIOTYPE {
    307     MP3D_OMX_IndexCustomMode16_24bit = 0xFF000001,
    308     MP3D_OMX_IndexCustomModeDasfConfig,
    309     OMX_IndexCustomMp3DecHeaderInfoConfig,
    310     OMX_IndexCustomMp3DecStreamInfoConfig,
    311     OMX_IndexCustomMp3DecDataPath,
    312     OMX_IndexCustomDebug
    313 }OMX_INDEXAUDIOTYPE;
    314 /* ======================================================================= */
    315 /** MP3DEC_BUFDATA
    316 *
    317 * @param nFrames: Specifies the number of frames received by the SN.
    318 *
    319 */
    320 /* ==================================================================== */
    321 typedef struct MP3DEC_BUFDATA {
    322    OMX_U8 nFrames;
    323 }MP3DEC_BUFDATA;
    324 
    325 /* ======================================================================= */
    326 /** IAUDIO_PcmFormat: This value is used by DSP.
    327 *
    328 * @param IAUDIO_BLOCK: It is used in DASF mode.
    329 *
    330 * @param IAUDIO_INTERLEAVED: It specifies interleaved format of SN.
    331 */
    332 /* ==================================================================== */
    333 typedef enum {
    334     IAUDIO_BLOCK=0,
    335     IAUDIO_INTERLEAVED
    336 } IAUDIO_PcmFormat;
    337 
    338 
    339 /* ======================================================================= */
    340 /** MP3DEC_UALGParams
    341  *
    342  * @param lOutputFormat - To set interleaved/Block format:Refer to IAUDIO_Mp3Format.
    343  * @param DownSampleSbr -
    344  */
    345 /* ==================================================================== */
    346 typedef struct {
    347   OMX_U32 size;
    348   unsigned long      lOutputFormat;
    349   unsigned long    lMonoToStereoCopy;
    350   unsigned long    lStereoToMonoCopy;
    351 } MP3DEC_UALGParams;
    352 
    353 
    354 /* ======================================================================= */
    355 /** MP3D_IUALG_Cmd: This enum type describes the standard set of commands that
    356 * will be passed to iualg control API at DSP. This enum is taken as it is from
    357 * DSP side USN source code.
    358 *
    359 * @param IUALG_CMD_STOP: This command indicates that higher layer framework
    360 * has received a stop command and no more process API will be called for the
    361 * current data stream. The iualg layer is expected to ensure that all processed
    362 * output as is put in the output IUALG_Buf buffers and the state of all buffers
    363 * changed as to free or DISPATCH after this function call.
    364 *
    365 * @param IUALG_CMD_PAUSE: This command indicates that higher layer framework
    366 * has received a PAUSE command on the current data stream. The iualg layer
    367 * can change the state of some of its output IUALG_Bufs to DISPATCH to enable
    368 * high level framework to use the processed data until the command was received.
    369 *
    370 * @param IUALG_CMD_GETSTATUS: This command indicates that some algo specific
    371 * status needs to be returned to the framework. The pointer to the status
    372 * structure will be in IALG_status * variable passed to the control API.
    373 * The interpretation of the content of this pointer is left to IUALG layer.
    374 *
    375 * @param IUALG_CMD_SETSTATUS: This command indicates that some algo specific
    376 * status needs to be set. The pointer to the status structure will be in
    377 * IALG_status * variable passed to the control API. The interpretation of the
    378 * content of this pointer is left to IUALG layer.
    379 *
    380 * @param IUALG_CMD_USERCMDSTART: The algorithm specific control commands can
    381 * have the enum type set from this number.
    382 */
    383 /* ==================================================================== */
    384 typedef enum {
    385     IUALG_CMD_STOP          = 0,
    386     IUALG_CMD_PAUSE         = 1,
    387     IUALG_CMD_GETSTATUS     = 2,
    388     IUALG_CMD_SETSTATUS     = 3,
    389     IUALG_CMD_USERCMDSTART  = 100
    390 }IUALG_Cmd;
    391 
    392 #ifdef UNDER_CE
    393     #ifndef _OMX_EVENT_
    394         #define _OMX_EVENT_
    395         typedef struct OMX_Event {
    396             HANDLE event;
    397         } OMX_Event;
    398     #endif
    399     int OMX_CreateEvent(OMX_Event *event);
    400     int OMX_SignalEvent(OMX_Event *event);
    401     int OMX_WaitForEvent(OMX_Event *event);
    402     int OMX_DestroyEvent(OMX_Event *event);
    403 #endif
    404 
    405 /* ======================================================================= */
    406 /** IUALG_MP3DCmd: This enum specifies the command to DSP.
    407 *
    408 * @param IULAG_CMD_SETSTREAMTYPE: Specifies the stream type to be sent to DSP.
    409 */
    410 /* ==================================================================== */
    411 typedef enum {
    412     IULAG_CMD_SETSTREAMTYPE = IUALG_CMD_USERCMDSTART
    413 }IUALG_MP3DCmd;
    414 
    415 /* ======================================================================= */
    416 /** MP3DEC_UAlgInBufParamStruct: This struct is passed with input buffers that
    417  * are sent to DSP.
    418 */
    419 /* ==================================================================== */
    420 typedef struct {
    421     /* Set to 1 if buffer is last buffer */
    422     unsigned long bLastBuffer;
    423 }MP3DEC_UAlgInBufParamStruct;
    424 
    425 /* ======================================================================= */
    426 /** MP3D_USN_AudioCodecParams: This contains the information which does to Codec
    427  * on DSP
    428  * are sent to DSP.
    429 */
    430 /* ==================================================================== */
    431 typedef struct USN_AudioCodecParams{
    432     /* Specifies the sample frequency */
    433     unsigned long ulSamplingFreq;
    434     /* Specifies the UUID */
    435     unsigned long unUUID;
    436     /* Specifies the audio format */
    437     unsigned short unAudioFormat;
    438 }USN_AudioCodecParams;
    439 
    440 /* ======================================================================= */
    441 /** MP3DEC_UAlgOutBufParamStruct: This is passed with output buffer to DSP.
    442 */
    443 /* ==================================================================== */
    444 typedef struct {
    445     /* Number of frames in a buffer */
    446     unsigned long ulFrameCount;
    447     unsigned long ulIsLastBuffer;
    448 }MP3DEC_UAlgOutBufParamStruct;
    449 
    450 /* ======================================================================= */
    451 /** MP3D_LCML_BUFHEADERTYPE: This is LCML buffer header which is sent to LCML
    452  * for both input and output buffers.
    453 */
    454 /* ==================================================================== */
    455 typedef struct MP3D_LCML_BUFHEADERTYPE {
    456     /* Direction whether input or output buffer */
    457     OMX_DIRTYPE eDir;
    458     /* Pointer to OMX Buffer Header */
    459     OMX_BUFFERHEADERTYPE *pBufHdr;
    460     /* Other parameters, may be useful for enhancements */
    461     void *pOtherParams[10];
    462     /* Input Parameter Information structure */
    463     MP3DEC_UAlgInBufParamStruct *pIpParam;
    464     /* Output Parameter Information structure */
    465     MP3DEC_UAlgOutBufParamStruct *pOpParam;
    466 }MP3D_LCML_BUFHEADERTYPE;
    467 
    468 /* Component Port Context */
    469 typedef struct MP3D_AUDIODEC_PORT_TYPE {
    470     /* Used in tunneling, this is handle of tunneled component */
    471     OMX_HANDLETYPE hTunnelComponent;
    472     /* Port which has to be tunneled */
    473     OMX_U32 nTunnelPort;
    474     /* Buffer Supplier Information */
    475     OMX_BUFFERSUPPLIERTYPE eSupplierSetting;
    476     /* Number of buffers */
    477     OMX_U8 nBufferCnt;
    478     /* Port format information */
    479     OMX_AUDIO_PARAM_PORTFORMATTYPE* pPortFormat;
    480 } MP3D_AUDIODEC_PORT_TYPE;
    481 
    482 
    483 /* ======================================================================= */
    484 /** _MP3D_BUFFERLIST: This contains information about a buffer's owner whether
    485  * it is application or component, number of buffers owned etc.
    486 *
    487 * @see OMX_BUFFERHEADERTYPE
    488 */
    489 /* ==================================================================== */
    490 struct _MP3D_BUFFERLIST{
    491     /* Array of pointer to OMX buffer headers */
    492     OMX_BUFFERHEADERTYPE *pBufHdr[MP3D_MAX_NUM_OF_BUFS];
    493     /* Array that tells about owner of each buffer */
    494     OMX_U32 bufferOwner[MP3D_MAX_NUM_OF_BUFS];
    495     /* Tracks pending buffers */
    496     OMX_U32 bBufferPending[MP3D_MAX_NUM_OF_BUFS];
    497     /* Number of buffers  */
    498     OMX_U32 numBuffers;
    499 };
    500 
    501 typedef struct _MP3D_BUFFERLIST MP3D_BUFFERLIST;
    502 
    503 typedef struct StreamData{
    504     OMX_U32 nSyncWord;
    505     OMX_U32 nMpegVersion;
    506     OMX_U32 nLayer;
    507     OMX_U32 nBitRate;
    508     OMX_U32 nFrequency;
    509     OMX_U32 nChannelMode;
    510 }StreamData;
    511 
    512 
    513 /* ======================================================================= */
    514 /** MP3DEC_COMPONENT_PRIVATE: This is the major and main structure of the
    515  * component which contains all type of information of buffers, ports etc
    516  * contained in the component.
    517 *
    518 * @see OMX_BUFFERHEADERTYPE
    519 * @see OMX_AUDIO_PARAM_PORTFORMATTYPE
    520 * @see OMX_PARAM_PORTDEFINITIONTYPE
    521 * @see MP3D_LCML_BUFHEADERTYPE
    522 * @see OMX_PORT_PARAM_TYPE
    523 * @see OMX_PRIORITYMGMTTYPE
    524 * @see MP3D_AUDIODEC_PORT_TYPE
    525 * @see MP3D_BUFFERLIST
    526 * @see MP3D_AUDIODEC_PORT_TYPE
    527 * @see LCML_STRMATTR
    528 * @see
    529 */
    530 /* ==================================================================== */
    531 typedef struct MP3DEC_COMPONENT_PRIVATE
    532 {
    533     /** Handle for use with async callbacks */
    534     OMX_CALLBACKTYPE cbInfo;
    535     /** Handle for use with async callbacks */
    536 
    537     /** Number of input buffers at runtime */
    538     OMX_U32 nRuntimeInputBuffers;
    539     /** Number of output buffers at runtime */
    540     OMX_U32 nRuntimeOutputBuffers;
    541     /** Parameters being passed to the SN */
    542     USN_AudioCodecParams *pParams;
    543     /**Dynamic parameters*/
    544     MP3DEC_UALGParams *ptAlgDynParams;
    545 
    546     OMX_PORT_PARAM_TYPE* sPortParam;
    547     /* Input port information */
    548     OMX_AUDIO_PARAM_PORTFORMATTYPE sInPortFormat;
    549     /* Output port information */
    550     OMX_AUDIO_PARAM_PORTFORMATTYPE sOutPortFormat;
    551     /* Buffer owner information */
    552     OMX_U32 bIsBufferOwned[NUM_OF_PORTS];
    553 
    554     /** This will contain info like how many buffers
    555         are there for input/output ports, their size etc, but not
    556         BUFFERHEADERTYPE POINTERS. */
    557     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef[NUM_OF_PORTS];
    558     /* Contains information that come from application */
    559     OMX_AUDIO_PARAM_MP3TYPE* mp3Params;
    560     OMX_AUDIO_PARAM_PCMMODETYPE* pcmParams;
    561     /** This is component handle */
    562     OMX_COMPONENTTYPE* pHandle;
    563 
    564     /** Needed to free LCML lib dll **/
    565     void* ptrLibLCML;
    566 
    567     /** Current state of this component */
    568     OMX_STATETYPE curState;
    569 
    570     /** The component thread handle */
    571     pthread_t ComponentThread;
    572 
    573     /** The pipes for sending buffers to the thread */
    574     int dataPipe[2];
    575 
    576     /** The pipes for sending buffers to the thread */
    577     int cmdPipe[2];
    578 
    579     /** The pipes for sending command data to the thread */
    580     int cmdDataPipe[2];
    581 
    582     /** Set to indicate component is stopping */
    583     OMX_U32 bIsEOFSent;
    584 
    585     /** Count of number of buffers outstanding with bridge */
    586     OMX_U32 lcml_nIpBuf;
    587 
    588     /** Count of number of buffers outstanding with bridge */
    589     OMX_U32 lcml_nOpBuf;
    590 
    591     /** Counts of number of input buffers sent to LCML */
    592     OMX_U32 lcml_nCntIp;
    593     /** Counts of number of input buffers received from LCML */
    594     OMX_U32 lcml_nCntIpRes;
    595     /** Counts of number of output buffers sent to LCML */
    596     OMX_U32 lcml_nCntOp;
    597     /** Counts of number of output buffers received from LCML */
    598     OMX_U32 lcml_nCntOpReceived;
    599     /** Counts of number of buffers sent to App  */
    600     OMX_U32 lcml_nCntApp;
    601     /** Counts of number of buffers received from App  */
    602     OMX_U32 app_nBuf;
    603 
    604 #ifdef __PERF_INSTRUMENTATION__
    605     PERF_OBJHANDLE pPERF, pPERFcomp;
    606     OMX_U32 nLcml_nCntIp;
    607     OMX_U32 nLcml_nCntOpReceived;
    608 #endif
    609 
    610     /** Counts of number of output buffers reclaimed from lcml  */
    611     OMX_U32 num_Reclaimed_Op_Buff;
    612     /** Counts of number of input buffers sent to lcml  */
    613     OMX_U32 num_Sent_Ip_Buff;
    614     /** Counts of number of output buffers sent to lcml  */
    615     OMX_U32 num_Op_Issued;
    616     /** Holds the value of dasf mode, 1: DASF mode or 0: File Mode  */
    617     OMX_U32 dasfmode;
    618     /** Holds the value of frame mode, 1: frame mode or 0: non Frame Mode  */
    619     OMX_U32 frameMode;
    620 
    621     /** This is LCML handle  */
    622     OMX_HANDLETYPE pLcmlHandle;
    623 
    624     /** Contains pointers to LCML Buffer Headers */
    625     MP3D_LCML_BUFHEADERTYPE *pLcmlBufHeader[2];
    626     OMX_U32 bBufferIsAllocated;
    627 
    628     /** Tells whether buffers on ports have been allocated */
    629     OMX_U32 bPortDefsAllocated;
    630     /** Tells whether component thread has started */
    631     OMX_U32 bCompThreadStarted;
    632     /** Marks the buffer data  */
    633     OMX_PTR pMarkData;
    634     /** Marks the buffer */
    635     OMX_MARKTYPE *pMarkBuf;
    636     /** Marks the target component */
    637     OMX_HANDLETYPE hMarkTargetComponent;
    638     /** Flag to track when input buffer's filled length is 0 */
    639     OMX_U32 bBypassDSP;
    640     /** Input port enable flag */
    641     int ipPortEnableFlag;
    642     /** Input port disble flag */
    643     int ipPortDisableFlag;
    644     /** Pointer to port parameter structure */
    645     OMX_PORT_PARAM_TYPE* pPortParamType;
    646     /** Pointer to port priority management structure */
    647     OMX_PRIORITYMGMTTYPE* pPriorityMgmt;
    648 
    649 #ifdef RESOURCE_MANAGER_ENABLED
    650     RMPROXY_CALLBACKTYPE rmproxyCallback;
    651 #endif
    652     OMX_BOOL bPreempted;
    653 
    654     /** Contains the port related info of both the ports */
    655     MP3D_AUDIODEC_PORT_TYPE *pCompPort[NUM_OF_PORTS];
    656     /* Checks whether or not buffer were allocated by appliction */
    657     int bufAlloced;
    658     /** Flag to check about execution of component thread */
    659     OMX_U16 bExitCompThrd;
    660     /** Pointer to list of input buffers */
    661     MP3D_BUFFERLIST *pInputBufferList;
    662     /** Pointer to list of output buffers */
    663     MP3D_BUFFERLIST *pOutputBufferList;
    664     /** it is used for component's create phase arguments */
    665     LCML_STRMATTR  *strmAttr;
    666     /** Contains the version information */
    667     OMX_U32 nVersion;
    668 
    669     /** Audio Stream ID */
    670     OMX_U32 streamID;
    671     OMX_BOOL bIsInvalidState;
    672     OMX_STRING* sDeviceString;
    673     /** MPEG 1 Layer 2 custom flag **/
    674     OMX_BOOL mpeg1_layer2;
    675 
    676     int nOpBit;
    677     int bLcmlHandleOpened;
    678     OMX_U32 nFillThisBufferCount;
    679     /** Counts number of FillBufferDone calls*/
    680     OMX_U32 nFillBufferDoneCount;
    681     /** Counts number of EmptyThisBuffer calls*/
    682     OMX_U32 nEmptyThisBufferCount;
    683     /** Counts number of EmptyBufferDone calls*/
    684     OMX_U32 nEmptyBufferDoneCount;
    685     /** Checks if component Init Params have been initialized */
    686     OMX_U32 bInitParamsInitialized;
    687     MP3D_BUFFERLIST *pInputBufferListQueue;
    688     MP3D_BUFFERLIST *pOutputBufferListQueue;
    689     OMX_BUFFERHEADERTYPE *pInputBufHdrPending[MP3D_MAX_NUM_OF_BUFS];
    690     OMX_U32 nNumInputBufPending;
    691     OMX_BUFFERHEADERTYPE *pOutputBufHdrPending[MP3D_MAX_NUM_OF_BUFS];
    692     OMX_U32 nNumOutputBufPending;
    693 
    694     /** Store buffers received while paused **/
    695     OMX_BUFFERHEADERTYPE *pOutputBufHdrPause[MP3D_MAX_NUM_OF_BUFS];
    696     OMX_U32 nNumOutputBufPause;
    697     /** Flags to control port disable command **/
    698     OMX_U32 bDisableCommandPending;
    699     OMX_U32 bDisableCommandParam;
    700     /** Flags to control port enable command **/
    701     OMX_U32 bEnableCommandPending;
    702     OMX_U32 bEnableCommandParam;
    703 
    704     OMX_U32 nInvalidFrameCount;
    705     OMX_U32 numPendingBuffers;
    706     OMX_U32 bNoIdleOnStop;
    707     OMX_U32 bDspStoppedWhileExecuting;
    708     OMX_BOOL bLoadedCommandPending;
    709 
    710     /** Counts number of buffers received from client */
    711     OMX_U32 nHandledFillThisBuffers;
    712     /** Count number of buffers recieved from client */
    713     OMX_U32 nHandledEmptyThisBuffers;
    714     OMX_BOOL bFlushOutputPortCommandPending;
    715     OMX_BOOL bFlushInputPortCommandPending;
    716 
    717 #ifndef UNDER_CE
    718     pthread_mutex_t AlloBuf_mutex;
    719     pthread_cond_t AlloBuf_threshold;
    720     OMX_U8 AlloBuf_waitingsignal;
    721 
    722     pthread_mutex_t codecStop_mutex;
    723     pthread_cond_t codecStop_threshold;
    724     OMX_U8 codecStop_waitingsignal;
    725 
    726     pthread_mutex_t codecFlush_mutex;
    727     pthread_cond_t codecFlush_threshold;
    728     OMX_U8 codecFlush_waitingsignal;
    729 
    730     pthread_mutex_t InLoaded_mutex;
    731     pthread_cond_t InLoaded_threshold;
    732     OMX_U8 InLoaded_readytoidle;
    733 
    734     pthread_mutex_t InIdle_mutex;
    735     pthread_cond_t InIdle_threshold;
    736     OMX_U8 InIdle_goingtoloaded;
    737 
    738 #else
    739     OMX_Event AlloBuf_event;
    740     OMX_U8 AlloBuf_waitingsignal;
    741 
    742     OMX_Event InLoaded_event;
    743     OMX_U8 InLoaded_readytoidle;
    744 
    745     OMX_Event InIdle_event;
    746     OMX_U8 InIdle_goingtoloaded;
    747 #endif
    748 
    749     OMX_PARAM_COMPONENTROLETYPE componentRole;
    750 
    751     /** Keep buffer timestamps **/
    752     OMX_S64 arrBufIndex[MP3D_MAX_NUM_OF_BUFS];
    753 	/**Keep buffer tickcounts*/
    754     OMX_U32 arrBufIndexTick[MP3D_MAX_NUM_OF_BUFS];
    755 
    756     /** Index to arrBufIndex[] and arrBufIndexTick[], used for input buffer timestamps */
    757     OMX_U8 IpBufindex;
    758     /** Index to arrBufIndex[] and arrBufIndexTick[], used for output buffer timestamps */
    759     OMX_U8 OpBufindex;
    760 
    761     OMX_U8 SendAfterEOS;
    762 
    763     /** Flag to mark the first buffer sent **/
    764     OMX_U8 first_buff;
    765 
    766     /** First Time Stamp sent **/
    767     OMX_S64 first_TS;
    768     /** Temp Time Stamp to store intermediate values **/
    769     OMX_S64 temp_TS;
    770     /** Last buffer received usind in PV-Android context **/
    771     OMX_BUFFERHEADERTYPE *lastout;
    772 
    773     PV_OMXComponentCapabilityFlagsType iPVCapabilityFlags;
    774     OMX_BOOL reconfigInputPort;
    775     OMX_BOOL reconfigOutputPort;
    776     OMX_BOOL bConfigData;
    777 
    778     StreamData pStreamData;
    779 
    780     struct OMX_TI_Debug dbg;
    781 
    782 } MP3DEC_COMPONENT_PRIVATE;
    783 
    784 
    785 /* ================================================================================= * */
    786 /**
    787 * OMX_ComponentInit() function is called by OMX Core to initialize the component
    788 * with default values of the component. Before calling this function OMX_Init
    789 * must have been called.
    790 *
    791 * @param *hComp This is component handle allocated by the OMX core.
    792 *
    793 * @pre          OMX_Init should be called by application.
    794 *
    795 * @post         Component has initialzed with default values.
    796 *
    797 *  @return      OMX_ErrorNone = Successful Inirialization of the component\n
    798 *               OMX_ErrorInsufficientResources = Not enough memory
    799 *
    800 *  @see          Mp3Dec_StartCompThread()
    801 */
    802 /* ================================================================================ * */
    803 #ifndef UNDER_CE
    804 OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp);
    805 #else
    806 /*  WinCE Implicit Export Syntax */
    807 #define OMX_EXPORT __declspec(dllexport)
    808 OMX_EXPORT OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp);
    809 #endif
    810 
    811 
    812 /* ================================================================================= * */
    813 /**
    814 * Mp3Dec_StartCompThread() starts the component thread. This is internal
    815 * function of the component.
    816 *
    817 * @param pHandle This is component handle allocated by the OMX core.
    818 *
    819 * @pre          None
    820 *
    821 * @post         None
    822 *
    823 *  @return      OMX_ErrorNone = Successful Inirialization of the component\n
    824 *               OMX_ErrorInsufficientResources = Not enough memory
    825 *
    826 *  @see         None
    827 */
    828 /* ================================================================================ * */
    829 OMX_ERRORTYPE Mp3Dec_StartCompThread(OMX_HANDLETYPE pHandle);
    830 
    831 
    832 /* ================================================================================= * */
    833 /**
    834 * MP3DEC_Fill_LCMLInitParams() fills the LCML initialization structure.
    835 *
    836 * @param pHandle This is component handle allocated by the OMX core.
    837 *
    838 * @param plcml_Init This structure is filled and sent to LCML.
    839 *
    840 * @pre          None
    841 *
    842 * @post         None
    843 *
    844 *  @return      OMX_ErrorNone = Successful Inirialization of the LCML struct.
    845 *               OMX_ErrorInsufficientResources = Not enough memory
    846 *
    847 *  @see         None
    848 */
    849 /* ================================================================================ * */
    850 OMX_ERRORTYPE MP3DEC_Fill_LCMLInitParams(OMX_HANDLETYPE pHandle, LCML_DSP *plcml_Init, OMX_U16 arr[]);
    851 
    852 
    853 /* ================================================================================= * */
    854 /**
    855 * MP3DEC_GetBufferDirection() function determines whether it is input buffer or
    856 * output buffer.
    857 *
    858 * @param *pBufHeader This is pointer to buffer header whose direction needs to
    859 *                    be determined.
    860 *
    861 * @param *eDir  This is output argument which stores the direction of buffer.
    862 *
    863 * @pre          None
    864 *
    865 * @post         None
    866 *
    867 *  @return      OMX_ErrorNone = Successful processing.
    868 *               OMX_ErrorBadParameter = In case of invalid buffer
    869 *
    870 *  @see         None
    871 */
    872 /* ================================================================================ * */
    873 OMX_ERRORTYPE MP3DEC_GetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader, OMX_DIRTYPE *eDir);
    874 
    875 /* ================================================================================= * */
    876 /**
    877 * MP3DEC_LCML_Callback() function is callback which is called by LCML whenever
    878 * there is an even generated for the component.
    879 *
    880 * @param event  This is event that was generated.
    881 *
    882 * @param arg    This has other needed arguments supplied by LCML like handles
    883 *               etc.
    884 *
    885 * @pre          None
    886 *
    887 * @post         None
    888 *
    889 *  @return      OMX_ErrorNone = Successful processing.
    890 *               OMX_ErrorInsufficientResources = Not enough memory
    891 *
    892 *  @see         None
    893 */
    894 /* ================================================================================ * */
    895 OMX_ERRORTYPE MP3DEC_LCML_Callback (TUsnCodecEvent event,void * args [10]);
    896 
    897 /* ================================================================================= * */
    898 /**
    899 * MP3DEC_HandleCommand() function handles the command sent by the application.
    900 * All the state transitions, except from nothing to loaded state, of the
    901 * component are done by this function.
    902 *
    903 * @param pComponentPrivate  This is component's private date structure.
    904 *
    905 * @pre          None
    906 *
    907 * @post         None
    908 *
    909 *  @return      OMX_ErrorNone = Successful processing.
    910 *               OMX_ErrorInsufficientResources = Not enough memory
    911 *               OMX_ErrorHardware = Hardware error has occured lile LCML failed
    912 *               to do any said operartion.
    913 *
    914 *  @see         None
    915 */
    916 /* ================================================================================ * */
    917 OMX_U32 MP3DEC_HandleCommand (MP3DEC_COMPONENT_PRIVATE *pComponentPrivate);
    918 
    919 /* ================================================================================= * */
    920 /**
    921 * MP3DEC_HandleDataBuf_FromApp() function handles the input and output buffers
    922 * that come from the application. It is not direct function wich gets called by
    923 * the application rather, it gets called eventually.
    924 *
    925 * @param *pBufHeader This is the buffer header that needs to be processed.
    926 *
    927 * @param *pComponentPrivate  This is component's private date structure.
    928 *
    929 * @pre          None
    930 *
    931 * @post         None
    932 *
    933 *  @return      OMX_ErrorNone = Successful processing.
    934 *               OMX_ErrorInsufficientResources = Not enough memory
    935 *               OMX_ErrorHardware = Hardware error has occured lile LCML failed
    936 *               to do any said operartion.
    937 *
    938 *  @see         None
    939 */
    940 /* ================================================================================ * */
    941 OMX_ERRORTYPE MP3DEC_HandleDataBuf_FromApp(OMX_BUFFERHEADERTYPE *pBufHeader, MP3DEC_COMPONENT_PRIVATE *pComponentPrivate);
    942 
    943 /* ================================================================================= * */
    944 /**
    945 * MP3DEC_GetLCMLHandle() function gets the LCML handle and interacts with LCML
    946 * by using this LCML Handle.
    947 *
    948 * @param *pBufHeader This is the buffer header that needs to be processed.
    949 *
    950 * @param *pComponentPrivate  This is component's private date structure.
    951 *
    952 * @pre          None
    953 *
    954 * @post         None
    955 *
    956 *  @return      OMX_HANDLETYPE = Successful loading of LCML library.
    957 *               OMX_ErrorHardware = Hardware error has occured.
    958 *
    959 *  @see         None
    960 */
    961 /* ================================================================================ * */
    962 OMX_HANDLETYPE MP3DEC_GetLCMLHandle(MP3DEC_COMPONENT_PRIVATE* pComponentPrivate);
    963 
    964 /* ================================================================================= * */
    965 /**
    966 * MP3DEC_GetCorresponding_LCMLHeader() function gets the corresponding LCML
    967 * header from the actual data buffer for required processing.
    968 *
    969 * @param *pBuffer This is the data buffer pointer.
    970 *
    971 * @param eDir   This is direction of buffer. Input/Output.
    972 *
    973 * @param *MP3D_LCML_BUFHEADERTYPE  This is pointer to LCML Buffer Header.
    974 *
    975 * @pre          None
    976 *
    977 * @post         None
    978 *
    979 *  @return      OMX_ErrorNone = Successful Inirialization of the component\n
    980 *               OMX_ErrorHardware = Hardware error has occured.
    981 *
    982 *  @see         None
    983 */
    984 /* ================================================================================ * */
    985 OMX_ERRORTYPE MP3DEC_GetCorresponding_LCMLHeader(MP3DEC_COMPONENT_PRIVATE* pComponentPrivate,
    986                                                                                 OMX_U8 *pBuffer,
    987                                         OMX_DIRTYPE eDir,
    988                                         MP3D_LCML_BUFHEADERTYPE **ppLcmlHdr);
    989 /* ================================================================================= * */
    990 /**
    991 * MP3DEC_FreeCompResources() function frees the component resources.
    992 *
    993 * @param pComponent This is the component handle.
    994 *
    995 * @pre          None
    996 *
    997 * @post         None
    998 *
    999 *  @return      OMX_ErrorNone = Successful Inirialization of the component\n
   1000 *               OMX_ErrorHardware = Hardware error has occured.
   1001 *
   1002 *  @see         None
   1003 */
   1004 /* ================================================================================ * */
   1005 OMX_ERRORTYPE MP3DEC_FreeCompResources(OMX_HANDLETYPE pComponent);
   1006 
   1007 
   1008 /* ================================================================================= * */
   1009 /**
   1010 * MP3DEC_CleanupInitParams() function frees only the initialization time
   1011 * memories allocated. For example, it will not close pipes, it will not free the
   1012 * memory allocated to the buffers etc. But it does free the memory of buffers
   1013 * utilized by the LCML etc. It is basically subset of MP3DEC_FreeResources()
   1014 * function.
   1015 *
   1016 * @param pComponent This is the component handle.
   1017 *
   1018 * @pre          None
   1019 *
   1020 * @post         None
   1021 *
   1022 *  @return      OMX_ErrorNone = Successful Inirialization of the component\n
   1023 *
   1024 *  @see         None
   1025 */
   1026 /* ================================================================================ * */
   1027 void MP3DEC_CleanupInitParams(OMX_HANDLETYPE pComponent);
   1028 /* ================================================================================= * */
   1029 /**
   1030 * MP3DEC_CleanupInitParamsEx() function frees only the initialization time
   1031 * memories allocated. For example, it will not close pipes, it will not free the
   1032 * memory allocated to the buffers etc. But it does free the memory of buffers
   1033 * utilized by the LCML etc. It is basically subset of MP3DEC_FreeResources()
   1034 * function. Called while port disable when port reconfiguration takes place.
   1035 *
   1036 * @param pComponent This is the component handle.
   1037 *
   1038 * @pre          None
   1039 *
   1040 * @post         None
   1041 *
   1042 *  @return      OMX_ErrorNone = Successful Inirialization of the component\n
   1043 *
   1044 *  @see         None
   1045 */
   1046 /* ================================================================================ * */
   1047 void MP3DEC_CleanupInitParamsEx(OMX_HANDLETYPE pComponent,OMX_U32 indexport);
   1048 
   1049 #ifdef RESOURCE_MANAGER_ENABLED
   1050 /* =================================================================================== */
   1051 /**
   1052 *  MP3_ResourceManagerCallback() Callback from Resource Manager
   1053 *
   1054 *  @param cbData	RM Proxy command data
   1055 *
   1056 *  @return None
   1057 */
   1058 /* =================================================================================== */
   1059 void MP3_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
   1060 #endif
   1061 
   1062 OMX_ERRORTYPE MP3DECFill_LCMLInitParamsEx(OMX_HANDLETYPE pComponent,OMX_U32 indexport);
   1063 void MP3DEC_SetPending(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber);
   1064 void MP3DEC_ClearPending(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber) ;
   1065 OMX_U32 MP3DEC_IsPending(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir);
   1066 OMX_U32 MP3DEC_IsValid(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U8 *pBuffer, OMX_DIRTYPE eDir) ;
   1067 void* MP3DEC_ComponentThread (void* pThreadData);
   1068 
   1069 /*  =========================================================================*/
   1070 /*  func    GetBits                                                          */
   1071 /*                                                                           */
   1072 /*  desc    Gets aBits number of bits from position aPosition of one buffer  */
   1073 /*            and returns the value in a TUint value.                        */
   1074 /*  =========================================================================*/
   1075 OMX_U32 MP3DEC_GetBits(OMX_U32* nPosition, OMX_U8 nBits, OMX_U8* pBuffer, OMX_BOOL bIcreasePosition);
   1076 
   1077 /*=======================================================================*/
   1078 /*! @fn SignalIfAllBuffersAreReturned
   1079 
   1080  * @brief Sends pthread signal to indicate OMX has returned all buffers to app
   1081 
   1082  * @param  none
   1083 
   1084  * @Return void
   1085 
   1086  */
   1087 /*=======================================================================*/
   1088 void SignalIfAllBuffersAreReturned(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate);
   1089 
   1090 /*  =========================================================================*/
   1091 /*  func    MP3DEC_HandleUSNError
   1092 /*
   1093 /*  desc    Handles error messages returned by the dsp
   1094 /*
   1095 /*@return n/a
   1096 /*
   1097 /*  =========================================================================*/
   1098 void MP3DEC_HandleUSNError (MP3DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg);
   1099 
   1100 #endif
   1101