Home | History | Annotate | Download | only in src
      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_VideoEnc_Utils.c
     30 *
     31 * This file implements OMX Component for MPEG-4 encoder that
     32 * is fully compliant with the OMX specification 1.5.
     33 *
     34 * @path  $(CSLPATH)\src
     35 *
     36 * @rev  0.1
     37 */
     38 /* ---------------------------------------------------------------------------*/
     39 /* =============================================================================
     40 *!
     41 *! Revision History
     42 *! =============================================================================
     43 *!
     44 *! 02-Feb-2006 mf: Revisions appear in reverse chronological order;
     45 *! that is, newest first.  The date format is dd-Mon-yyyy.
     46 * ============================================================================*/
     47 
     48 /* ------compilation control switches ----------------------------------------*/
     49 /******************************************************************************
     50 *  INCLUDE FILES
     51 *******************************************************************************/
     52 /* ----- system and platform files -------------------------------------------*/
     53 #ifdef UNDER_CE
     54     #include <windows.h>
     55     #include <omx_core.h>
     56     #include <stdlib.h>
     57     #include <pthread.h>
     58 #else
     59     #include <wchar.h>
     60     #include <unistd.h>
     61     #include <sys/types.h>
     62     #include <sys/wait.h>
     63     #include <sys/types.h>
     64     #include <sys/select.h>
     65     #include <sys/stat.h>
     66     #include <dlfcn.h>
     67     #include <malloc.h>
     68     #include <memory.h>
     69     #include <fcntl.h>
     70 #endif
     71 
     72 #include <dbapi.h>
     73 #include <string.h>
     74 #include <stdlib.h>
     75 #include <stdio.h>
     76 
     77 /*------- Program Header Files -----------------------------------------------*/
     78 #include "OMX_VideoEnc_Utils.h"
     79 #include "OMX_VideoEnc_Thread.h"
     80 #include "OMX_VideoEnc_DSP.h"
     81 
     82 #define DSP_MMU_FAULT_HANDLING
     83 
     84 // We cannot request the same MHz for all resolutions.
     85 // we have to change this implementation once we modify
     86 // opencore to request the correct level based on resolution/bitrate/etc
     87 #define VIDEO_ENCODER_MHZ (400 - 45 + 2)
     88 
     89 /* H264 Specific */
     90 #define SPS_CODE_PREFIX 0x07
     91 #define PPS_CODE_PREFIX 0x08
     92 
     93 #ifdef UNDER_CE
     94     HINSTANCE g_hLcmlDllHandle = NULL;
     95 #endif
     96 #ifdef UNDER_CE
     97 void sleep(DWORD Duration)
     98 {
     99     Sleep(Duration);
    100 }
    101 #endif
    102 /*******************************************************************************
    103 *  EXTERNAL REFERENCES NOTE : only use if not found in header file
    104 *******************************************************************************/
    105 /*--------data declarations --------------------------------------------------*/
    106 /*--------function prototypes ------------------------------------------------*/
    107 
    108 /*******************************************************************************
    109 *  PUBLIC DECLARATIONS Defined here, used elsewhere
    110 *******************************************************************************/
    111 /*--------data declarations --------------------------------------------------*/
    112 
    113 
    114 /*--------function prototypes ------------------------------------------------*/
    115 
    116 /*******************************************************************************
    117 *  PRIVATE DECLARATIONS Defined here, used only here
    118 *******************************************************************************/
    119 /*--------data declarations --------------------------------------------------*/
    120 struct DSP_UUID H264VESOCKET_TI_UUID = {
    121     0x63A3581A, 0x09D7, 0x4AD0, 0x80, 0xB8, {
    122     0x5F, 0x2C, 0x4D, 0x4D, 0x59, 0xC9
    123     }
    124 };
    125 
    126 struct DSP_UUID MP4VESOCKET_TI_UUID = {
    127     0x98c2e8d8, 0x4644, 0x11d6, 0x81, 0x18, {
    128         0x00, 0xb0, 0xd0, 0x8d, 0x72, 0x9f
    129     }
    130 };
    131 
    132 struct DSP_UUID USN_UUID = {
    133     0x79A3C8B3, 0x95F2, 0x403F, 0x9A, 0x4B, {
    134         0xCF, 0x80, 0x57, 0x73, 0x05, 0x41
    135     }
    136 };
    137 
    138 OMX_U32 VIDENC_STRUCT_H264DEFBITRATE [VIDENC_MAXBITRATES][2] = {
    139 /*1*/    {176 * 144, 128000},     /*128KBps*/
    140 /*2*/    {320 * 240, 400000},     /*400KBps*/
    141 /*3*/    {352 * 288, 500000},     /*500kBps*/
    142 /*4*/    {640 * 480, 1500000},    /*1.5MBps*/
    143 /*5*/    {720 * 480, 2000000},    /*2MBps*/
    144 /*6*/    {720 * 576, 3000000},    /*3MBps*/
    145 /*7*/    {1280 * 720, 3000000},   /*3MBps*/
    146 };
    147 
    148 OMX_U32 VIDENC_STRUCT_MPEG4DEFBITRATE [VIDENC_MAXBITRATES][2] = {
    149 /*1*/    {176 * 144, 128000},     /*128KBps*/
    150 /*2*/    {320 * 240, 400000},     /*400KBps*/
    151 /*3*/    {352 * 288, 500000},     /*500kBps*/
    152 /*4*/    {640 * 480, 1500000},    /*1.5MBps*/
    153 /*5*/    {720 * 480, 2000000},    /*2MBps*/
    154 /*6*/    {720 * 576, 3000000},    /*3MBps*/
    155 /*7*/    {1280 * 720, 3000000},   /*3MBps*/
    156 };
    157 
    158 OMX_U32 VIDENC_STRUCT_H263DEFBITRATE [VIDENC_MAXBITRATES][2] = {
    159 /*1*/    {176 * 144, 128000},     /*128KBps*/
    160 /*2*/    {320 * 240, 400000},     /*400KBps*/
    161 /*3*/    {352 * 288, 500000},     /*500kBps*/
    162 /*4*/    {640 * 480, 1500000},    /*1.5MBps*/
    163 /*5*/    {720 * 480, 2000000},    /*2MBps*/
    164 /*6*/    {720 * 576, 3000000},    /*3MBps*/
    165 /*7*/    {1280 * 720, 3000000},   /*3MBps*/
    166 };
    167 /*--------macro definitions ---------------------------------------------------*/
    168 
    169 static const int iQ16_Const = 1 << 16;
    170 static const float fQ16_Const = (float)(1 << 16);
    171 
    172 static float Q16Tof(int nQ16)
    173 {
    174     return nQ16 / fQ16_Const;
    175 }
    176 
    177 
    178 
    179 /*-----------------------------------------------------------------------------*/
    180 /**
    181   * ListCreate()
    182   *
    183   * Function call in OMX_ComponentInit(). Creates the List Head of the Component Memory List.
    184   *
    185   * @param pListHead VIDENC_NODE double pointer with the List Header of the Memory List.
    186   *
    187   * @retval OMX_ErrorNone
    188   *               OMX_ErrorInsufficientResources if the malloc fails
    189   *
    190   **/
    191 /*-----------------------------------------------------------------------------*/
    192 OMX_ERRORTYPE OMX_VIDENC_ListCreate(struct OMX_TI_Debug *dbg, struct VIDENC_NODE** pListHead)
    193 {
    194     OMX_ERRORTYPE eError = OMX_ErrorNone;
    195 
    196     *pListHead = (VIDENC_NODE*)malloc(sizeof(VIDENC_NODE)); /* need to malloc!!! */
    197     if (*pListHead == NULL)
    198     {
    199         OMX_TRACE4(*dbg, "malloc() out of memory error\n");
    200         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
    201     }
    202 
    203     OMX_TRACE1(*dbg, "Create MemoryListHeader[%p]\n", *pListHead);
    204     memset(*pListHead, 0x0, sizeof(VIDENC_NODE));
    205 
    206 OMX_CONF_CMD_BAIL:
    207     return eError;
    208 }
    209 
    210 /*-----------------------------------------------------------------------------*/
    211 /**
    212   * ListAdd()
    213   *
    214   * Called inside VIDENC_MALLOC Macro to add a new node to Component Memory List
    215   *
    216   * @param pListHead VIDENC_NODE Points List Header of the Memory List.
    217   *                pData OMX_PTR points to the new allocated data.
    218   * @retval OMX_ErrorNone
    219   *               OMX_ErrorInsufficientResources if the malloc fails
    220   *
    221   **/
    222 /*-----------------------------------------------------------------------------*/
    223 
    224 OMX_ERRORTYPE OMX_VIDENC_ListAdd(struct OMX_TI_Debug *dbg, struct VIDENC_NODE* pListHead, OMX_PTR pData)
    225 {
    226     OMX_ERRORTYPE eError = OMX_ErrorNone;
    227     VIDENC_NODE* pTmp = NULL;
    228     VIDENC_NODE* pNewNode = NULL;
    229     pNewNode = (VIDENC_NODE*)malloc(sizeof(VIDENC_NODE)); /* need to malloc!!! */
    230     if (pNewNode == NULL)
    231     {
    232         OMX_TRACE4(*dbg, "malloc() out of memory error\n");
    233         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
    234     }
    235     memset(pNewNode, 0x0, sizeof(VIDENC_NODE));
    236     pNewNode->pData = pData;
    237     pNewNode->pNext = NULL;
    238     OMX_TRACE1(*dbg, "Add MemoryNode[%p] -> [%p]\n", pNewNode, pNewNode->pData);
    239     pTmp = pListHead;
    240 
    241     while (pTmp->pNext != NULL)
    242     {
    243         pTmp = pTmp->pNext;
    244     }
    245     pTmp->pNext = pNewNode;
    246 
    247 OMX_CONF_CMD_BAIL:
    248     return eError;
    249 }
    250 
    251 /*-----------------------------------------------------------------------------*/
    252 /**
    253   * ListRemove()
    254   *
    255   * Called inside VIDENC_FREE Macro remove  node from Component Memory List and free the memory pointed by the node.
    256   *
    257   * @param pListHead VIDENC_NODE Points List Header of the Memory List.
    258   *                pData OMX_PTR points to the new allocated data.
    259   * @retval OMX_ErrorNone
    260   *
    261   *
    262   **/
    263 /*-----------------------------------------------------------------------------*/
    264 
    265 OMX_ERRORTYPE OMX_VIDENC_ListRemove(struct OMX_TI_Debug *dbg, struct VIDENC_NODE* pListHead,
    266                                     OMX_PTR pData)
    267 {
    268     OMX_ERRORTYPE eError = OMX_ErrorNone;
    269     VIDENC_NODE* pNode = NULL;
    270     VIDENC_NODE* pTmp = NULL;
    271 
    272     pNode = pListHead;
    273 
    274     while (pNode->pNext != NULL)
    275     {
    276         if (pNode->pNext->pData == pData)
    277         {
    278             pTmp = pNode->pNext;
    279             pNode->pNext = pTmp->pNext;
    280             OMX_TRACE1(*dbg, "Remove MemoryNode[%p] -> [%p]\n", pTmp, pTmp->pData);
    281             free(pTmp->pData);
    282             free(pTmp);
    283             pTmp = NULL;
    284             break;
    285             /* VIDENC_ListPrint2(pListHead); */
    286         }
    287         pNode = pNode->pNext;
    288     }
    289     return eError;
    290 }
    291 
    292 /*-----------------------------------------------------------------------------*/
    293 /**
    294   * ListDestroy()
    295   *
    296   * Called inside OMX_ComponentDeInit()  Remove all nodes and free all the memory in the Component Memory List.
    297   *
    298   * @param pListHead VIDENC_NODE Points List Header of the Memory List.
    299   *
    300   * @retval OMX_ErrorNone
    301   *
    302   *
    303   **/
    304 /*-----------------------------------------------------------------------------*/
    305 
    306 OMX_ERRORTYPE OMX_VIDENC_ListDestroy(struct OMX_TI_Debug *dbg, struct VIDENC_NODE* pListHead)
    307 {
    308     OMX_ERRORTYPE eError = OMX_ErrorNone;
    309     VIDENC_NODE* pTmp = NULL;
    310     VIDENC_NODE* pNode = NULL;
    311     pNode = pListHead;
    312 
    313     while (pNode->pNext != NULL)
    314     {
    315         pTmp = pNode->pNext;
    316         pNode->pNext=pTmp->pNext;
    317         if (pTmp->pData != NULL)
    318         {
    319             OMX_TRACE0(*dbg, "Remove MemoryNode[%p] -> [%p]\n", pTmp, pTmp->pData);
    320             free(pTmp->pData);
    321             pTmp->pData = NULL;
    322         }
    323         free(pTmp);
    324         pTmp = NULL;
    325     }
    326 
    327     OMX_TRACE1(*dbg, "Destroy MemoryListHeader[%p]\n", pListHead);
    328     free(pListHead);
    329     return eError;
    330 }
    331 
    332 
    333 
    334 /*---------------------------------------------------------------------------------------*/
    335 /**
    336   *  OMX_VIDENC_EmptyDataPipes Wait until all buffers are processed
    337   *
    338   * @param pComponentPrivate pointer to the private video encoder structure
    339   *
    340   * @return None
    341   *
    342  **/
    343 /*---------------------------------------------------------------------------------------*/
    344 void OMX_VIDENC_EmptyDataPipes (VIDENC_COMPONENT_PRIVATE *pComponentPrivate)
    345 {
    346     pthread_mutex_lock(&bufferReturned_mutex);
    347     while (pComponentPrivate->EmptythisbufferCount != pComponentPrivate->EmptybufferdoneCount ||
    348            pComponentPrivate->FillthisbufferCount  != pComponentPrivate->FillbufferdoneCount) {
    349         pthread_cond_wait(&bufferReturned_condition, &bufferReturned_mutex);
    350     }
    351     pthread_mutex_unlock(&bufferReturned_mutex);
    352     LOGI("Video encoder has returned all buffers");
    353 }
    354 
    355 void OMX_VIDENC_IncrementBufferCountByOne(OMX_U32 *count)
    356 {
    357     pthread_mutex_lock(&bufferReturned_mutex);
    358     (*count)++;
    359     pthread_mutex_unlock(&bufferReturned_mutex);
    360 }
    361 
    362 void OMX_VIDENC_SignalIfAllBuffersAreReturned(VIDENC_COMPONENT_PRIVATE *pComponentPrivate)
    363 {
    364     pthread_mutex_lock(&bufferReturned_mutex);
    365     if ((pComponentPrivate->EmptythisbufferCount == pComponentPrivate->EmptybufferdoneCount) &&
    366         (pComponentPrivate->FillthisbufferCount  == pComponentPrivate->FillbufferdoneCount)) {
    367         pthread_cond_broadcast(&bufferReturned_condition);
    368         LOGI("Sending pthread signal that video encoder has returned all buffers to app");
    369     }
    370     pthread_mutex_unlock(&bufferReturned_mutex);
    371 }
    372 
    373 /*---------------------------------------------------------------------------------------*/
    374 /**
    375   *  OMX_VIDENC_HandleError() will handle the error and pass the component to Invalid
    376   *  State, and send the event to the client.
    377   * @param eError - OMX_ERRORTYPE that occur.
    378   *
    379   * @retval OMX_NoError              Success, ready to roll
    380   *         OMX_Error_BadParameter   The input parameter pointer is null
    381  **/
    382 /*---------------------------------------------------------------------------------------*/
    383 OMX_ERRORTYPE OMX_VIDENC_HandleError(VIDENC_COMPONENT_PRIVATE* pComponentPrivate,
    384                                      OMX_ERRORTYPE eErrorCmp)
    385 {
    386     OMX_ERRORTYPE eError = OMX_ErrorNone;
    387     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
    388 
    389     pComponentPrivate->bHandlingFatalError = OMX_TRUE;
    390 
    391     OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    392                              OMX_EventError,
    393                              eErrorCmp,
    394                              OMX_TI_ErrorSevere,
    395                              NULL);
    396 
    397     switch (eErrorCmp)
    398     {
    399         case OMX_ErrorBadParameter:
    400         case OMX_ErrorPortUnresponsiveDuringAllocation:
    401         case OMX_ErrorUnsupportedIndex:
    402         case OMX_ErrorInsufficientResources:
    403             goto OMX_CONF_CMD_BAIL;
    404         default:
    405             ;
    406     }
    407 
    408     pComponentPrivate->bHideEvents = OMX_TRUE;
    409 
    410     eError = eErrorCmp;
    411     pComponentPrivate->eState = OMX_StateInvalid;
    412 
    413     OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    414                              OMX_EventError,
    415                              OMX_ErrorInvalidState,
    416                              OMX_TI_ErrorCritical,
    417                              NULL);
    418 
    419 OMX_CONF_CMD_BAIL:
    420     if (pComponentPrivate)
    421         pComponentPrivate->bHandlingFatalError = OMX_FALSE;
    422     return eError;
    423 }
    424 
    425 /*---------------------------------------------------------------------------------------*/
    426 /**
    427   *  OMX_VIDENC_HandleLcmlEvent() will handle the event from the LCML
    428  *  thread.
    429   * @param eError - OMX_ERRORTYPE that occur.
    430   *
    431   * @retval OMX_NoError              Success, ready to roll
    432   *         OMX_Error_BadParameter   The input parameter pointer is null
    433  **/
    434 /*---------------------------------------------------------------------------------------*/
    435 OMX_ERRORTYPE OMX_VIDENC_HandleLcmlEvent(VIDENC_COMPONENT_PRIVATE* pComponentPrivate,
    436                                          TUsnCodecEvent eEvent, void* argsCb [])
    437 {
    438     OMX_ERRORTYPE eError = OMX_ErrorNone;
    439 
    440     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
    441 
    442     switch(eEvent)
    443     {
    444     case EMMCodecDspMessageRecieved:
    445         OMX_PRDSP1(pComponentPrivate->dbg, "EMMCodecDspMessageRecieved\n");
    446         break;
    447     case EMMCodecBufferProcessed:
    448         OMX_PRDSP1(pComponentPrivate->dbg, "EMMCodecBufferProcessed\n");
    449         break;
    450     case EMMCodecProcessingStarted:
    451         OMX_PRDSP1(pComponentPrivate->dbg, "EMMCodecProcessingStarted\n");
    452         break;
    453     case EMMCodecProcessingPaused:
    454         OMX_PRDSP1(pComponentPrivate->dbg, "EMMCodecProcessingPaused\n");
    455         break;
    456     case EMMCodecProcessingStoped:
    457         OMX_PRDSP1(pComponentPrivate->dbg, "EMMCodecProcessingStoped\n");
    458         break;
    459     case EMMCodecProcessingEof:
    460         OMX_PRDSP1(pComponentPrivate->dbg, "EMMCodecProcessingEof\n");
    461         break;
    462     case EMMCodecBufferNotProcessed:
    463         OMX_PRDSP1(pComponentPrivate->dbg, "EMMCodecBufferNotProcessed\n");
    464         break;
    465     case EMMCodecAlgCtrlAck:
    466         OMX_PRDSP1(pComponentPrivate->dbg, "EMMCodecAlgCtrlAck\n");
    467         break;
    468     case EMMCodecStrmCtrlAck:
    469         OMX_PRDSP1(pComponentPrivate->dbg, "EMMCodecStrmCtrlAck\n");
    470         break;
    471     case EMMCodecInternalError:
    472         OMX_PRDSP2(pComponentPrivate->dbg, "EMMCodecInternalError\n");
    473 #ifdef DSP_MMU_FAULT_HANDLING
    474         if((argsCb[4] == (void *)USN_ERR_UNKNOWN_MSG) && (argsCb[5] == (void*)NULL))
    475         {
    476             OMX_VIDENC_SET_ERROR_BAIL(eError, OMX_ErrorInvalidState, pComponentPrivate);
    477         }
    478         else
    479         {
    480            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    481                                    OMX_EventError,
    482                                    OMX_ErrorHardware,
    483                                    OMX_TI_ErrorCritical,
    484                                    "Error Hardware\n");
    485             eError = OMX_ErrorHardware;
    486         }
    487 #else
    488            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    489                                    OMX_EventError,
    490                                    OMX_ErrorHardware,
    491                                    OMX_TI_ErrorCritical,
    492                                    "Error Hardware\n");
    493            eError = OMX_ErrorHardware;
    494 #endif
    495         break;
    496     case EMMCodecInitError:
    497         OMX_PRDSP2(pComponentPrivate->dbg, "EMMCodecInitError\n");
    498 #ifdef DSP_MMU_FAULT_HANDLING
    499         if((argsCb[4] == (void *)USN_ERR_UNKNOWN_MSG) && (argsCb[5] == (void*)NULL))
    500         {
    501             OMX_VIDENC_SET_ERROR_BAIL(eError, OMX_ErrorInvalidState, pComponentPrivate);
    502         }
    503         else
    504         {
    505            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    506                                    OMX_EventError,
    507                                    OMX_ErrorHardware,
    508                                    OMX_TI_ErrorCritical,
    509                                    "Error Hardware\n");
    510             eError = OMX_ErrorHardware;
    511         }
    512 #else
    513        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    514                                    OMX_EventError,
    515                                    OMX_ErrorHardware,
    516                                    OMX_TI_ErrorCritical,
    517                                    "Error Hardware\n");
    518         eError = OMX_ErrorHardware;
    519 #endif
    520         break;
    521     case EMMCodecDspError:
    522         OMX_PRDSP2(pComponentPrivate->dbg, "EMMCodecDspError\n");
    523 #ifdef DSP_MMU_FAULT_HANDLING
    524         if((argsCb[4] == (void *)NULL) && (argsCb[5] == (void*)NULL))
    525         {
    526             OMX_VIDENC_SET_ERROR_BAIL(eError, OMX_ErrorInvalidState, pComponentPrivate);
    527         }
    528         else
    529         {
    530        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    531                                    OMX_EventError,
    532                                    OMX_ErrorHardware,
    533                                    OMX_TI_ErrorCritical,
    534                                    "Error Hardware\n");
    535             eError = OMX_ErrorHardware;
    536         }
    537 #else
    538        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    539                                    OMX_EventError,
    540                                    OMX_ErrorHardware,
    541                                    OMX_TI_ErrorCritical,
    542                                    "Error Hardware\n");
    543         eError = OMX_ErrorHardware;
    544 #endif
    545         break;
    546     }
    547 
    548 OMX_CONF_CMD_BAIL:
    549     return eError;
    550 }
    551 
    552 /*-----------------------------------------------------------------------------*/
    553 /**
    554   * Disable Port()
    555   *
    556   * Called by component thread, handles commands sent by the app.
    557   *
    558   * @param
    559   *
    560   * @retval OMX_ErrorNone                  success, ready to roll
    561   *
    562   **/
    563 /*-----------------------------------------------------------------------------*/
    564 OMX_ERRORTYPE OMX_VIDENC_HandleCommandDisablePort (VIDENC_COMPONENT_PRIVATE* pComponentPrivate,
    565                                                    OMX_U32 nParam1)
    566 {
    567     OMX_U8 i = 0;
    568     OMX_BOOL bFlushFlag;
    569     OMX_COMPONENTTYPE* pHandle = NULL;
    570     VIDENC_NODE* pMemoryListHead = NULL;
    571     OMX_ERRORTYPE eError = OMX_ErrorNone;
    572     VIDEOENC_PORT_TYPE* pCompPortIn = NULL;
    573     VIDEOENC_PORT_TYPE* pCompPortOut = NULL;
    574     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
    575     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
    576 
    577     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
    578 
    579     pHandle         = (OMX_COMPONENTTYPE*)pComponentPrivate->pHandle;
    580     pCompPortIn     = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT];
    581     pCompPortOut    = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
    582     pPortDefIn      = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
    583     pPortDefOut     = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
    584     pMemoryListHead = pComponentPrivate->pMemoryListHead;
    585 
    586     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pHandle, pPortDefIn, pPortDefOut);
    587 
    588     if (nParam1 == VIDENC_INPUT_PORT || nParam1 == (OMX_U32)-1)
    589     {
    590         /* Flush the DSP side before sending buffers back to the client */
    591         bFlushFlag = OMX_FALSE;
    592         for (i = 0; i < pPortDefIn->nBufferCountActual; i++)
    593         {
    594             if(pCompPortIn->pBufferPrivate[i]->eBufferOwner != VIDENC_BUFFER_WITH_CLIENT)
    595             {
    596                 bFlushFlag = OMX_TRUE;
    597             }
    598         }
    599 
    600         if(bFlushFlag == OMX_TRUE)
    601         {
    602             eError = OMX_VIDENC_HandleCommandFlush(pComponentPrivate, VIDENC_INPUT_PORT, OMX_TRUE);
    603             OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRBUFFER3,
    604                                   "Flush command failed (%x)\n", eError);
    605             bFlushFlag = OMX_FALSE;
    606         }
    607 
    608         /*Return buffer to client*/
    609         if (pCompPortIn->hTunnelComponent == NULL)
    610         {
    611             for (i = 0; i < pPortDefIn->nBufferCountActual; i++)
    612             {
    613                 if (pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT ||
    614                     pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_DSP)
    615                 {
    616                     pCompPortIn->pBufferPrivate[i]->eBufferOwner = VIDENC_BUFFER_WITH_CLIENT;
    617 #ifdef __PERF_INSTRUMENTATION__
    618                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
    619                                       PREF(pCompPortIn->pBufferPrivate[i]->pBufferHdr, pBuffer),
    620                                       0,
    621                                       PERF_ModuleHLMM);
    622 #endif
    623                     pComponentPrivate->sCbData.EmptyBufferDone(pComponentPrivate->pHandle,
    624                                                                pComponentPrivate->pHandle->pApplicationPrivate,
    625                                                                pCompPortIn->pBufferPrivate[i]->pBufferHdr);
    626                     OMX_VIDENC_IncrementBufferCountByOne(&pComponentPrivate->EmptybufferdoneCount);
    627                     OMX_VIDENC_SignalIfAllBuffersAreReturned(pComponentPrivate);
    628                 }
    629             }
    630         }
    631         else
    632         {
    633             for (i = 0; i < pPortDefIn->nBufferCountActual; i++)
    634             {
    635                 if (pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT ||
    636                     pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_DSP)
    637                 {
    638                     pCompPortIn->pBufferPrivate[i]->eBufferOwner = VIDENC_BUFFER_WITH_TUNNELEDCOMP;
    639 #ifdef __PERF_INSTRUMENTATION__
    640                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
    641                                       PREF(pCompPortIn->pBufferPrivate[i]->pBufferHdr, pBuffer),
    642                                       0,
    643                                       PERF_ModuleLLMM);
    644 #endif
    645                     eError = OMX_FillThisBuffer(pCompPortIn->hTunnelComponent,
    646                                                 pCompPortIn->pBufferPrivate[i]->pBufferHdr);
    647                     OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRBUFFER4,
    648                                           "FillThisBuffer failed (%x)\n", eError);
    649                 }
    650             }
    651         }
    652     }
    653     if (nParam1 == VIDENC_OUTPUT_PORT || nParam1 == (OMX_U32)-1)
    654     {
    655         /* Flush the DSP side before sending buffers back to the client */
    656         bFlushFlag = OMX_FALSE;
    657         for (i = 0; i < pPortDefOut->nBufferCountActual; i++)
    658         {
    659             if(pCompPortOut->pBufferPrivate[i]->eBufferOwner != VIDENC_BUFFER_WITH_CLIENT)
    660             {
    661                 bFlushFlag = OMX_TRUE;
    662             }
    663         }
    664 
    665         if(bFlushFlag == OMX_TRUE)
    666         {
    667             eError = OMX_VIDENC_HandleCommandFlush(pComponentPrivate, VIDENC_OUTPUT_PORT, OMX_TRUE);
    668             OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRBUFFER3,
    669                                   "Flush command failed (%x)\n", eError);
    670             bFlushFlag = OMX_FALSE;
    671         }
    672 
    673         /*Return buffer to client*/
    674         if (pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->hTunnelComponent == NULL)
    675         {
    676             for (i = 0; i < pPortDefOut->nBufferCountActual; i++)
    677             {
    678                 if (pCompPortOut->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT ||
    679                     pCompPortOut->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_DSP)
    680                 {
    681 
    682                     pCompPortOut->pBufferPrivate[i]->eBufferOwner = VIDENC_BUFFER_WITH_CLIENT;
    683 #ifdef __PERF_INSTRUMENTATION__
    684                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
    685                                       pCompPortOut->pBufferPrivate[i]->pBufferHdr ?
    686                                       pCompPortOut->pBufferPrivate[i]->pBufferHdr->pBuffer :
    687                                       NULL,
    688                                       pCompPortOut->pBufferPrivate[i]->pBufferHdr ?
    689                                       pCompPortOut->pBufferPrivate[i]->pBufferHdr->nFilledLen :
    690                                       0,
    691                                       PERF_ModuleHLMM);
    692 #endif
    693                     OMX_CONF_CIRCULAR_BUFFER_MOVE_HEAD(pCompPortOut->pBufferPrivate[i]->pBufferHdr,
    694                                                        pComponentPrivate->sCircularBuffer,
    695                                                        pComponentPrivate);
    696                     /* trigger event handler if we are supposed to */
    697                     if (pCompPortOut->pBufferPrivate[i]->pBufferHdr->hMarkTargetComponent == pComponentPrivate->pHandle &&
    698                         pCompPortOut->pBufferPrivate[i]->pBufferHdr->pMarkData)
    699                     {
    700                         OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    701                                                  OMX_EventMark,
    702                                                  0x0,
    703                                                  0x0,
    704                                                  pCompPortOut->pBufferPrivate[i]->pBufferHdr->pMarkData);
    705                     }
    706                     pComponentPrivate->sCbData.FillBufferDone(pComponentPrivate->pHandle,
    707                                                               pComponentPrivate->pHandle->pApplicationPrivate,
    708                                                               pCompPortOut->pBufferPrivate[i]->pBufferHdr);
    709                     OMX_VIDENC_IncrementBufferCountByOne(&pComponentPrivate->FillbufferdoneCount);
    710                     OMX_VIDENC_SignalIfAllBuffersAreReturned(pComponentPrivate);
    711                 }
    712             }
    713         }
    714         else
    715         {
    716          /* If tunneled with VPP  - NOT Implemented*/
    717 #ifdef __PERF_INSTRUMENTATION__
    718                 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
    719                                   PREF(pCompPortOut->pBufferPrivate[i]->pBufferHdr,pBuffer),
    720                                   PREF(pCompPortOut->pBufferPrivate[i]->pBufferHdr,nFilledLen),
    721                                   PERF_ModuleLLMM);
    722 #endif
    723         }
    724     }
    725 
    726     OMX_PRBUFFER2(pComponentPrivate->dbg, "Flushing Pipes!\n");
    727     OMX_VIDENC_EmptyDataPipes (pComponentPrivate);
    728 
    729     /*while (1)
    730     {*/
    731 
    732         if (nParam1 == VIDENC_INPUT_PORT)
    733         {
    734             while ((pPortDefIn->bPopulated))
    735             {
    736                 /*Send event*/
    737 #ifndef UNDER_CE
    738     pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
    739     pthread_cond_wait(&pComponentPrivate->unpopulate_cond, &pComponentPrivate->videoe_mutex_app);
    740     pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
    741 #else
    742         OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
    743 #endif
    744         break;
    745                 }
    746                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    747                              OMX_EventCmdComplete,
    748                              OMX_CommandPortDisable,
    749                              VIDENC_INPUT_PORT,
    750                              NULL);
    751 
    752             }
    753 
    754         else if (nParam1 == VIDENC_OUTPUT_PORT)
    755         {
    756             while ((pPortDefOut->bPopulated))
    757             {
    758                 /*Send event*/
    759 #ifndef UNDER_CE
    760     pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
    761     pthread_cond_wait(&pComponentPrivate->unpopulate_cond, &pComponentPrivate->videoe_mutex_app);
    762     pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
    763 #else
    764         OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
    765 #endif
    766         break;
    767                 }
    768         OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    769                              OMX_EventCmdComplete,
    770                              OMX_CommandPortDisable,
    771                              VIDENC_OUTPUT_PORT,
    772                              NULL);
    773 
    774             }
    775 
    776         else if (nParam1 == (OMX_U32)-1)
    777         {
    778             while ((pPortDefIn->bPopulated) || (pPortDefOut->bPopulated))
    779             {
    780         /*Send events*/
    781 #ifndef UNDER_CE
    782     pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
    783     pthread_cond_wait(&pComponentPrivate->unpopulate_cond, &pComponentPrivate->videoe_mutex_app);
    784     pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
    785 #else
    786         OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
    787 #endif
    788         break;
    789                 }
    790         OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    791                              OMX_EventCmdComplete,
    792                              OMX_CommandPortDisable,
    793                              VIDENC_INPUT_PORT,
    794                              NULL);
    795                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    796                              OMX_EventCmdComplete,
    797                              OMX_CommandPortDisable,
    798                              VIDENC_OUTPUT_PORT,
    799                              NULL);
    800 
    801 
    802         }
    803 
    804 
    805 OMX_CONF_CMD_BAIL:
    806     return eError;
    807 }
    808 
    809 /*-----------------------------------------------------------------------------*/
    810 /**
    811   * Enable Port()
    812   *
    813   * Called by component thread, handles commands sent by the app.
    814   *
    815   * @param
    816   *
    817   * @retval OMX_ErrorNone                  success, ready to roll
    818   *
    819   **/
    820 /*-----------------------------------------------------------------------------*/
    821 
    822 OMX_ERRORTYPE OMX_VIDENC_HandleCommandEnablePort (VIDENC_COMPONENT_PRIVATE* pComponentPrivate,
    823                                                   OMX_U32 nParam1)
    824 {
    825     OMX_U32 nTimeout = 0x0;
    826     OMX_COMPONENTTYPE* pHandle = NULL;
    827     VIDENC_NODE* pMemoryListHead = NULL;
    828     OMX_ERRORTYPE eError = OMX_ErrorNone;
    829     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
    830     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
    831 
    832     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
    833 
    834     pHandle = (OMX_COMPONENTTYPE*)pComponentPrivate->pHandle;
    835     pPortDefIn      = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
    836     pPortDefOut     = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
    837     pMemoryListHead = pComponentPrivate->pMemoryListHead;
    838 
    839     nTimeout = 0x0;
    840     /*while(1)
    841     {*/
    842         if(nParam1 == VIDENC_INPUT_PORT)
    843         {
    844         if (pComponentPrivate->eState != OMX_StateLoaded)
    845         {
    846         pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
    847             while (!pPortDefIn->bPopulated)
    848                {
    849 #ifndef UNDER_CE
    850         pthread_cond_wait(&pComponentPrivate->populate_cond, &pComponentPrivate->videoe_mutex_app);
    851 #else
    852         OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
    853 #endif
    854 
    855                 }
    856     }
    857     pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
    858         OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    859                                              OMX_EventCmdComplete,
    860                                              OMX_CommandPortEnable,
    861                                              VIDENC_INPUT_PORT,
    862                                              NULL);
    863 
    864 
    865         }
    866         else if(nParam1 == VIDENC_OUTPUT_PORT)
    867         {
    868         if (pComponentPrivate->eState != OMX_StateLoaded)
    869         {
    870             pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
    871             while(!pPortDefOut->bPopulated)
    872             {
    873 #ifndef UNDER_CE
    874         pthread_cond_wait(&pComponentPrivate->populate_cond, &pComponentPrivate->videoe_mutex_app);
    875 #else
    876         OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
    877 #endif
    878 
    879                 }
    880         }
    881             pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
    882                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    883                                          OMX_EventCmdComplete,
    884                                          OMX_CommandPortEnable,
    885                                          VIDENC_OUTPUT_PORT,
    886                                          NULL);
    887 
    888 
    889         }
    890         else if(nParam1 == (OMX_U32)-1)
    891         {
    892         if (pComponentPrivate->eState != OMX_StateLoaded)
    893         {
    894             pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
    895             while(!pPortDefOut->bPopulated && !pPortDefIn->bPopulated)
    896             {
    897 #ifndef UNDER_CE
    898             pthread_cond_wait(&pComponentPrivate->populate_cond, &pComponentPrivate->videoe_mutex_app);
    899 #else
    900         OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
    901 #endif
    902       break;
    903                 }
    904         }
    905             pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
    906                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    907                                          OMX_EventCmdComplete,
    908                                          OMX_CommandPortEnable,
    909                                          VIDENC_INPUT_PORT,
    910                                          NULL);
    911                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
    912                                         OMX_EventCmdComplete,
    913                                         OMX_CommandPortEnable,
    914                                         VIDENC_OUTPUT_PORT,
    915                                         NULL);
    916 
    917 
    918         }
    919 
    920 
    921 OMX_CONF_CMD_BAIL:
    922     return eError;
    923 }
    924 
    925 /*----------------------------------------------------------------------------*/
    926 /**
    927   * OMX_OMX_VIDENC_HandleCommandFlush()
    928   *
    929   * Called by component thread, handles commands sent by the app.
    930   *
    931   * @param phandle LCML_DSP_INTERFACE handle for this instance of the component
    932   *
    933   * @retval OMX_ErrorNone                  success, ready to roll
    934   *         OMX_ErrorInsufficientResources if the malloc fails
    935   **/
    936 /*----------------------------------------------------------------------------*/
    937 
    938 OMX_ERRORTYPE OMX_VIDENC_HandleCommandFlush(VIDENC_COMPONENT_PRIVATE* pComponentPrivate,
    939                                             OMX_U32 nParam1,
    940                                             OMX_BOOL bInternalFlush)
    941 {
    942     OMX_U16 i = 0;
    943     OMX_U32 aParam[3] = {0};
    944     OMX_COMPONENTTYPE* pHandle = NULL;
    945     VIDENC_NODE* pMemoryListHead = NULL;
    946     OMX_ERRORTYPE eError = OMX_ErrorNone;
    947     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
    948     VIDEOENC_PORT_TYPE* pCompPortIn = NULL;
    949     VIDEOENC_PORT_TYPE* pCompPortOut = NULL;
    950     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
    951     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
    952 
    953     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
    954 
    955     pLcmlHandle     = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
    956     pCompPortIn     = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT];
    957     pCompPortOut    = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
    958     pPortDefIn      = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
    959     pPortDefOut     = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
    960     pHandle         = (OMX_COMPONENTTYPE*)pComponentPrivate->pHandle;
    961     pMemoryListHead = pComponentPrivate->pMemoryListHead;
    962 
    963     if (nParam1 == VIDENC_INPUT_PORT || nParam1 == (OMX_U32)-1)
    964     {
    965         aParam[0] = USN_STRMCMD_FLUSH;
    966         aParam[1] = VIDENC_INPUT_PORT;
    967         aParam[2] = 0x0;
    968 
    969         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
    970                                     EMMCodecControlStrmCtrl,
    971                                     (void*)aParam);
    972         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
    973                               "DSP Input flush failed (%x).\n", eError);
    974 
    975 #ifndef UNDER_CE
    976         pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
    977         while (pComponentPrivate->bFlushComplete == OMX_FALSE)
    978         {
    979             pthread_cond_wait(&pComponentPrivate->flush_cond, &pComponentPrivate->videoe_mutex_app);
    980         }
    981         pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
    982 #else
    983         while (pComponentPrivate->bFlushComplete == OMX_FALSE)
    984         {
    985             sched_yield();
    986         }
    987 #endif
    988 
    989         pComponentPrivate->bFlushComplete = OMX_FALSE;
    990 
    991         if (pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->hTunnelComponent == NULL)
    992         {
    993             for (i = 0; i < pPortDefIn->nBufferCountActual; i++)
    994             {
    995                 if (pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT ||
    996                     pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_DSP)
    997                 {
    998 
    999                     pCompPortIn->pBufferPrivate[i]->eBufferOwner = VIDENC_BUFFER_WITH_CLIENT;
   1000 #ifdef __PERF_INSTRUMENTATION__
   1001                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1002                                       PREF(pCompPortIn->pBufferPrivate[i]->pBufferHdr,pBuffer),
   1003                                       0,
   1004                                       PERF_ModuleHLMM);
   1005 #endif
   1006                     pComponentPrivate->sCbData.EmptyBufferDone(pComponentPrivate->pHandle,
   1007                                                                pComponentPrivate->pHandle->pApplicationPrivate,
   1008                                                                pCompPortIn->pBufferPrivate[i]->pBufferHdr);
   1009                     OMX_VIDENC_IncrementBufferCountByOne(&pComponentPrivate->EmptybufferdoneCount);
   1010                     OMX_VIDENC_SignalIfAllBuffersAreReturned(pComponentPrivate);
   1011                 }
   1012             }
   1013         }
   1014         else
   1015         {
   1016             for (i = 0; i < pPortDefIn->nBufferCountActual; i++)
   1017             {
   1018                 if (pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT ||
   1019                     pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_DSP)
   1020                 {
   1021 
   1022                     pCompPortIn->pBufferPrivate[i]->eBufferOwner = VIDENC_BUFFER_WITH_TUNNELEDCOMP;
   1023 #ifdef __PERF_INSTRUMENTATION__
   1024                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1025                                       PREF(pCompPortOut->pBufferPrivate[i]->pBufferHdr,pBuffer),
   1026                                       0,
   1027                                       PERF_ModuleLLMM);
   1028 #endif
   1029                     eError = OMX_FillThisBuffer(pCompPortIn->hTunnelComponent,
   1030                                                 pCompPortIn->pBufferPrivate[i]->pBufferHdr);
   1031                     OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRBUFFER4,
   1032                                           "FillThisBuffer failed (%x)\n", eError);
   1033                 }
   1034             }
   1035         }
   1036         if (bInternalFlush == OMX_FALSE)
   1037         {
   1038             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1039                                      OMX_EventCmdComplete,
   1040                                      OMX_CommandFlush,
   1041                                      VIDENC_INPUT_PORT,
   1042                                      NULL);
   1043         }
   1044     }
   1045     if (nParam1 == VIDENC_OUTPUT_PORT || nParam1 == (OMX_U32)-1)
   1046     {
   1047         aParam[0] = USN_STRMCMD_FLUSH;
   1048         aParam[1] = VIDENC_OUTPUT_PORT;
   1049         aParam[2] = 0x0;
   1050 
   1051         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1052                                    EMMCodecControlStrmCtrl,
   1053                                    (void*)aParam);
   1054         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
   1055                               "DSP Output flush failed (%x).\n", eError);
   1056 #ifndef UNDER_CE
   1057         pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
   1058         while (pComponentPrivate->bFlushComplete == OMX_FALSE)
   1059         {
   1060             pthread_cond_wait(&pComponentPrivate->flush_cond, &pComponentPrivate->videoe_mutex_app);
   1061         }
   1062         pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
   1063 #else
   1064         while (pComponentPrivate->bFlushComplete == OMX_FALSE)
   1065         {
   1066             sched_yield();
   1067         }
   1068 #endif
   1069 
   1070         pComponentPrivate->bFlushComplete = OMX_FALSE;
   1071 
   1072         if (pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->hTunnelComponent == NULL)
   1073         {
   1074             for (i = 0; i < pPortDefOut->nBufferCountActual; i++)
   1075             {
   1076                 if (pCompPortOut->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT ||
   1077                     pCompPortOut->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_DSP)
   1078                 {
   1079 
   1080                     pCompPortOut->pBufferPrivate[i]->eBufferOwner = VIDENC_BUFFER_WITH_CLIENT;
   1081 #ifdef __PERF_INSTRUMENTATION__
   1082                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1083                                       PREF(pCompPortOut->pBufferPrivate[i]->pBufferHdr,pBuffer),
   1084                                       PREF(pCompPortOut->pBufferPrivate[i]->pBufferHdr,nFilledLen),
   1085                                       PERF_ModuleHLMM);
   1086 #endif
   1087                     /*Copy Buffer Data to be propagated*/
   1088                     OMX_CONF_CIRCULAR_BUFFER_MOVE_HEAD(pCompPortOut->pBufferPrivate[i]->pBufferHdr,
   1089                                                        pComponentPrivate->sCircularBuffer,
   1090                                                        pComponentPrivate);
   1091                      /* trigger event handler if we are supposed to */
   1092                     if (pCompPortOut->pBufferPrivate[i]->pBufferHdr->hMarkTargetComponent == pComponentPrivate->pHandle &&
   1093                         pCompPortOut->pBufferPrivate[i]->pBufferHdr->pMarkData)
   1094                     {
   1095                         OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1096                                                  OMX_EventMark,
   1097                                                  0x0,
   1098                                                  0x0,
   1099                                                  pCompPortOut->pBufferPrivate[i]->pBufferHdr->pMarkData);
   1100                     }
   1101                     pComponentPrivate->sCbData.FillBufferDone(pComponentPrivate->pHandle,
   1102                                                               pComponentPrivate->pHandle->pApplicationPrivate,
   1103                                                               pCompPortOut->pBufferPrivate[i]->pBufferHdr);
   1104                     OMX_VIDENC_IncrementBufferCountByOne(&pComponentPrivate->FillbufferdoneCount);
   1105                     OMX_VIDENC_SignalIfAllBuffersAreReturned(pComponentPrivate);
   1106                 }
   1107             }
   1108         }
   1109         else
   1110         {
   1111             /* If tunneled with VPP  - NOT Implemented*/
   1112         }
   1113         if (bInternalFlush == OMX_FALSE)
   1114         {
   1115             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1116                                      OMX_EventCmdComplete,
   1117                                      OMX_CommandFlush,
   1118                                      VIDENC_OUTPUT_PORT,
   1119                                      NULL);
   1120         }
   1121     }
   1122 
   1123 OMX_CONF_CMD_BAIL:
   1124     return eError;
   1125 }
   1126 
   1127 /*----------------------------------------------------------------------------*/
   1128 /**
   1129   * OMX_VIDENC_HandleCommand()
   1130   *
   1131   * Called by component thread, handles commands sent by the app.
   1132   *
   1133   * @param phandle LCML_DSP_INTERFACE handle for this instance of the component
   1134   *
   1135   * @retval OMX_ErrorNone                  success, ready to roll
   1136   *         OMX_ErrorInsufficientResources if the malloc fails
   1137   **/
   1138 /*----------------------------------------------------------------------------*/
   1139 OMX_ERRORTYPE OMX_VIDENC_HandleCommandStateSet (VIDENC_COMPONENT_PRIVATE* pComponentPrivate,
   1140                                                 OMX_U32 nParam1)
   1141 {
   1142     VIDENC_NODE* pMemoryListHead = NULL;
   1143     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1144     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
   1145     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   1146 
   1147     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   1148 
   1149     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
   1150     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
   1151     pMemoryListHead = pComponentPrivate->pMemoryListHead;
   1152 
   1153     switch (nParam1)
   1154     {
   1155     case OMX_StateIdle:
   1156         eError = OMX_VIDENC_HandleCommandStateSetIdle (pComponentPrivate);
   1157         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRSTATE3,
   1158                               "Failed to move to Idle state (%x).\n", eError);
   1159         break;
   1160     case OMX_StateExecuting:
   1161         eError = OMX_VIDENC_HandleCommandStateSetExecuting (pComponentPrivate);
   1162         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRSTATE3,
   1163                               "Failed to move to Execute state (%x).\n", eError);
   1164         break;
   1165     case OMX_StateLoaded:
   1166         eError = OMX_VIDENC_HandleCommandStateSetLoaded (pComponentPrivate);
   1167         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRSTATE3,
   1168                               "Failed to move to Loaded state (%x).\n", eError);
   1169         break;
   1170     case OMX_StatePause:
   1171         eError = OMX_VIDENC_HandleCommandStateSetPause (pComponentPrivate);
   1172         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRSTATE3,
   1173                               "Failed to move to Pause state (%x).\n", eError);
   1174         break;
   1175     case OMX_StateInvalid:
   1176             if (pComponentPrivate->eState == OMX_StateInvalid)
   1177             {
   1178                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1179                                          OMX_EventError,
   1180                                          OMX_ErrorSameState,
   1181                                          OMX_TI_ErrorSevere,
   1182                                          NULL);
   1183             }
   1184             else
   1185             {
   1186                 pComponentPrivate->eState = OMX_StateInvalid;
   1187                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1188                                          OMX_EventError,
   1189                                          OMX_ErrorInvalidState,
   1190                                          OMX_TI_ErrorSevere,
   1191                                          NULL);
   1192                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1193                                          OMX_EventCmdComplete,
   1194                                          OMX_CommandStateSet,
   1195                                          OMX_StateInvalid,
   1196                                          NULL);
   1197             }
   1198             break;
   1199         case OMX_StateWaitForResources:
   1200             if (pComponentPrivate->eState == OMX_StateWaitForResources)
   1201             {
   1202                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1203                                          OMX_EventError,
   1204                                          OMX_ErrorSameState,
   1205                                          OMX_TI_ErrorMinor,
   1206                                          NULL);
   1207             }
   1208             else if (pComponentPrivate->eState == OMX_StateLoaded)
   1209             {
   1210                 pComponentPrivate->eState = OMX_StateWaitForResources;
   1211                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1212                                          OMX_EventCmdComplete,
   1213                                          OMX_CommandStateSet,
   1214                                          OMX_StateWaitForResources,
   1215                                          NULL);
   1216             }
   1217             else
   1218             {
   1219                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1220                                          OMX_EventError,
   1221                                          OMX_ErrorIncorrectStateTransition,
   1222                                          OMX_TI_ErrorMinor,
   1223                                          NULL);
   1224             }
   1225             break;
   1226         case OMX_StateMax:
   1227             break;
   1228     } /* End of Switch */
   1229 
   1230 OMX_CONF_CMD_BAIL:
   1231     return eError;
   1232 }
   1233 
   1234 /*----------------------------------------------------------------------------*/
   1235 /**
   1236   * OMX_VIDENC_HandleCommandStateSet()
   1237   *
   1238   * Called by component thread, handles commands sent by the app.
   1239   *
   1240   * @param phandle LCML_DSP_INTERFACE handle for this instance of the component
   1241   *
   1242   * @retval OMX_ErrorNone                  success, ready to roll
   1243   *         OMX_ErrorInsufficientResources if the malloc fails
   1244   **/
   1245 /*----------------------------------------------------------------------------*/
   1246 OMX_ERRORTYPE OMX_VIDENC_HandleCommandStateSetIdle(VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
   1247 {
   1248     OMX_U8 nCount = 0;
   1249     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1250     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
   1251     VIDEOENC_PORT_TYPE* pCompPortIn = NULL;
   1252     VIDEOENC_PORT_TYPE* pCompPortOut = NULL;
   1253     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
   1254     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   1255 
   1256 
   1257     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   1258 
   1259     pCompPortIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT];
   1260     pCompPortOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
   1261     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
   1262     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
   1263 
   1264 
   1265     switch (pComponentPrivate->eState)
   1266     {
   1267         case OMX_StateIdle:
   1268             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1269                                      OMX_EventError,
   1270                                      OMX_ErrorSameState,
   1271                                      OMX_TI_ErrorMinor,
   1272                                      NULL);
   1273             break;
   1274         case OMX_StateInvalid:
   1275             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1276                                      OMX_EventError,
   1277                                      OMX_ErrorIncorrectStateTransition,
   1278                                      OMX_TI_ErrorMajor,
   1279                                      NULL);
   1280             break;
   1281         case OMX_StateLoaded:
   1282         case OMX_StateWaitForResources:
   1283 #ifdef __PERF_INSTRUMENTATION__
   1284                 PERF_Boundary(pComponentPrivate->pPERFcomp,
   1285                               PERF_BoundaryStart | PERF_BoundarySetup);
   1286 #endif
   1287         if ( pPortDefIn->bEnabled == OMX_TRUE || pPortDefOut->bEnabled == OMX_TRUE )
   1288         {
   1289             pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
   1290             while ( (!pPortDefIn->bPopulated) || (!pPortDefOut->bPopulated))
   1291             {
   1292 #ifndef UNDER_CE
   1293                 pthread_cond_wait(&pComponentPrivate->populate_cond, &pComponentPrivate->videoe_mutex_app);
   1294 #else
   1295             OMX_WaitForEvent(&(pComponentPrivate->InLoaded_event));
   1296 #endif
   1297             }
   1298             pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
   1299         }
   1300             /* Make sure the DSP node has been deleted first to cover
   1301                    any idle->loaded->idle or idle->wfr->idle combinations
   1302                    */
   1303             if (pComponentPrivate->bCodecStarted == OMX_TRUE ||
   1304                 pComponentPrivate->bCodecLoaded == OMX_TRUE)
   1305             {
   1306             OMX_PRDSP2(pComponentPrivate->dbg, "Attempting to destroy the node...\n");
   1307                 pLcmlHandle = NULL;
   1308                 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   1309                 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1310                                            EMMCodecControlDestroy,
   1311                                            NULL);
   1312             OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP3,
   1313                                   "Failed to destroy socket node (%x).\n", eError);
   1314 
   1315 
   1316                 /*Unload LCML */
   1317                 if(pComponentPrivate->pModLcml != NULL)
   1318                 {
   1319 #ifndef UNDER_CE
   1320                     dlclose(pComponentPrivate->pModLcml);
   1321 #else
   1322                     FreeLibrary(pComponentPrivate->pModLcml);
   1323                 FreeLibrary(g_hLcmlDllHandle);
   1324                 g_hLcmlDllHandle = NULL;
   1325 
   1326 #endif
   1327                    pComponentPrivate->pModLcml = NULL;
   1328                    pComponentPrivate->pLCML = NULL;
   1329                 }
   1330 
   1331                 pComponentPrivate->bCodecStarted = OMX_FALSE;
   1332                 pComponentPrivate->bCodecLoaded = OMX_FALSE;
   1333             }
   1334 
   1335             eError = OMX_VIDENC_InitLCML(pComponentPrivate);
   1336         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
   1337                               "Failed to initialize LCML (%x).\n", eError);
   1338 
   1339 #ifdef __PERF_INSTRUMENTATION__
   1340             pComponentPrivate->nLcml_nCntIp = 0;
   1341             pComponentPrivate->nLcml_nCntOpReceived = 0;
   1342 #endif
   1343             if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
   1344             {
   1345                 eError = OMX_VIDENC_InitDSP_H264Enc(pComponentPrivate);
   1346             OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
   1347                                   "Failed to initialize H264 SN (%x).\n", eError);
   1348             }
   1349             else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   1350                      pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
   1351             {
   1352                 eError = OMX_VIDENC_InitDSP_Mpeg4Enc(pComponentPrivate);
   1353             OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
   1354                                   "Failed to initialize MPEG4 SN (%x).\n", eError);
   1355             }
   1356             else
   1357             {
   1358             OMX_PRSTATE4(pComponentPrivate->dbg, "Unsupported compression format (%d)\n",
   1359                          pPortDefOut->format.video.eCompressionFormat);
   1360                 OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
   1361             }
   1362 
   1363 #ifdef RESOURCE_MANAGER_ENABLED
   1364 
   1365         OMX_PRMGR2(pComponentPrivate->dbg, "Setting CallBack In Video Encoder component\n");
   1366              pComponentPrivate->cRMCallBack.RMPROXY_Callback = (void*)OMX_VIDENC_ResourceManagerCallBack;
   1367             switch (pPortDefOut->format.video.eCompressionFormat)
   1368             {
   1369                 case OMX_VIDEO_CodingAVC:
   1370                      switch(pComponentPrivate->pH264->eLevel)
   1371                      {
   1372                         case OMX_VIDEO_AVCLevel1:
   1373                         case OMX_VIDEO_AVCLevel1b:
   1374                             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1375                                                          RMProxy_RequestResource,
   1376                                                          OMX_H264_Encode_COMPONENT,
   1377                                                          VIDEO_ENCODER_MHZ,
   1378                                                          3456,
   1379                                                          &(pComponentPrivate->cRMCallBack));
   1380 
   1381                             break;
   1382                         case OMX_VIDEO_AVCLevel11:
   1383                         case OMX_VIDEO_AVCLevel12:
   1384                             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1385                                                          RMProxy_RequestResource,
   1386                                                          OMX_H264_Encode_COMPONENT,
   1387                                                          VIDEO_ENCODER_MHZ,
   1388                                                          3456,
   1389                                                          &(pComponentPrivate->cRMCallBack));
   1390                             break;
   1391                         case OMX_VIDEO_AVCLevel13:
   1392                         case OMX_VIDEO_AVCLevel2:
   1393                         case OMX_VIDEO_AVCLevel21:
   1394                         case OMX_VIDEO_AVCLevel22:
   1395                         case OMX_VIDEO_AVCLevel3:
   1396                          default:
   1397                             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1398                                                             RMProxy_RequestResource,
   1399                                                             OMX_H264_Encode_COMPONENT,
   1400                                                             VIDEO_ENCODER_MHZ,
   1401                                                             3456,
   1402                                                             &(pComponentPrivate->cRMCallBack));
   1403                     }
   1404                     break;
   1405                 case OMX_VIDEO_CodingMPEG4:
   1406                     switch(pComponentPrivate->pMpeg4->eLevel)
   1407                     {
   1408                         case 0:
   1409                         case 1:
   1410                         case 100:
   1411                             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1412                                                          RMProxy_RequestResource,
   1413                                                          OMX_MPEG4_Encode_COMPONENT,
   1414                                                          VIDEO_ENCODER_MHZ,
   1415                                                          3456,
   1416                                                          &(pComponentPrivate->cRMCallBack));
   1417                             break;
   1418                         case 2:
   1419                         case 3:
   1420                             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1421                                                          RMProxy_RequestResource,
   1422                                                          OMX_MPEG4_Encode_COMPONENT,
   1423                                                          VIDEO_ENCODER_MHZ,
   1424                                                          3456,
   1425                                                          &(pComponentPrivate->cRMCallBack));
   1426                             break;
   1427                         case 4:
   1428                         default:
   1429                             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1430                                                          RMProxy_RequestResource,
   1431                                                          OMX_MPEG4_Encode_COMPONENT,
   1432                                                          VIDEO_ENCODER_MHZ,
   1433                                                          3456,
   1434                                                          &(pComponentPrivate->cRMCallBack));
   1435                     }
   1436                     break;
   1437                 case OMX_VIDEO_CodingH263:
   1438                     switch(pComponentPrivate->pH263->eLevel)
   1439                     {
   1440                         case OMX_VIDEO_H263Level10:
   1441                         case OMX_VIDEO_H263Level40:
   1442                             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1443                                                          RMProxy_RequestResource,
   1444                                                          OMX_H263_Encode_COMPONENT,
   1445                                                          VIDEO_ENCODER_MHZ,
   1446                                                          3456,
   1447                                                          &(pComponentPrivate->cRMCallBack));
   1448                             break;
   1449                         case OMX_VIDEO_H263Level20:
   1450                         case OMX_VIDEO_H263Level30:
   1451                         default:
   1452                             eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1453                                                          RMProxy_RequestResource,
   1454                                                          OMX_H263_Encode_COMPONENT,
   1455                                                          VIDEO_ENCODER_MHZ,
   1456                                                          3456,
   1457                                                          &(pComponentPrivate->cRMCallBack));
   1458                     }
   1459                     break;
   1460                 default:
   1461                 OMX_PRSTATE4(pComponentPrivate->dbg, "Unsupported compression format (%d)\n",
   1462                              pPortDefOut->format.video.eCompressionFormat);
   1463                     OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
   1464             }
   1465 
   1466             /* Resource Manager Proxy Calls */
   1467                 if (pCompPortOut->pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
   1468                 {
   1469                     /* TODO: Disable RM Send for now */
   1470                     /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H264_Encode_COMPONENT, 0); */
   1471             OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Idle from Loaded\n");
   1472                     eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1473                                                  RMProxy_StateSet,
   1474                                                  OMX_H264_Encode_COMPONENT,
   1475                                                  OMX_StateIdle,
   1476                                                  3456,
   1477                                                  NULL);
   1478                 }
   1479                 else if (pCompPortOut->pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
   1480                 {
   1481                     /* TODO: Disable RM Send for now */
   1482                     /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_MPEG4_Encode_COMPONENT, 0); */
   1483             OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Idle from Loaded\n");
   1484                     eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1485                                                  RMProxy_StateSet,
   1486                                                  OMX_MPEG4_Encode_COMPONENT,
   1487                                                  OMX_StateIdle,
   1488                                                  3456,
   1489                                                  NULL);
   1490                 }
   1491                 else if (pCompPortOut->pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
   1492                 {
   1493                     /* TODO: Disable RM Send for now */
   1494                     /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H263_Encode_COMPONENT, 0); */
   1495             OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Idle from Loaded\n");
   1496                     eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1497                                                  RMProxy_StateSet,
   1498                                                  OMX_H263_Encode_COMPONENT,
   1499                                                  OMX_StateIdle,
   1500                                                  3456,
   1501                                                  NULL);
   1502                 }
   1503         if (eError != OMX_ErrorNone)
   1504         {
   1505                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1506                                              OMX_EventError,
   1507                                              OMX_ErrorHardware,
   1508                                              OMX_TI_ErrorSevere,
   1509                                              NULL);
   1510                 }
   1511 
   1512            if (eError == OMX_ErrorNone) {
   1513 
   1514                pComponentPrivate->eState = OMX_StateIdle;
   1515 #ifdef __PERF_INSTRUMENTATION__
   1516                 PERF_Boundary(pComponentPrivate->pPERFcomp,
   1517                             PERF_BoundaryComplete | PERF_BoundarySetup);
   1518 #endif
   1519 
   1520                /* Decrement reference count with signal enabled */
   1521                if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
   1522                      return OMX_ErrorUndefined;
   1523                }
   1524 
   1525                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1526                                          OMX_EventCmdComplete,
   1527                                          OMX_CommandStateSet,
   1528                                          OMX_StateIdle,
   1529                                          NULL);
   1530             }
   1531             else if (eError == OMX_ErrorInsufficientResources)
   1532             {
   1533                 pComponentPrivate->eState = OMX_StateWaitForResources;
   1534                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1535                                          OMX_EventError,
   1536                                          OMX_ErrorInsufficientResources,
   1537                                          OMX_TI_ErrorMajor,
   1538                                          NULL);
   1539             }
   1540 #else /* WinCE MM will not use Linux RM, so do this... */
   1541             pComponentPrivate->eState = OMX_StateIdle;
   1542 #ifdef __PERF_INSTRUMENTATION__
   1543             PERF_Boundary(pComponentPrivate->pPERFcomp,
   1544                           PERF_BoundaryComplete | PERF_BoundarySetup);
   1545 #endif
   1546 
   1547             /* Decrement reference count with signal enabled */
   1548             if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
   1549                 return OMX_ErrorUndefined;
   1550             }
   1551 
   1552             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1553                                      OMX_EventCmdComplete,
   1554                                      OMX_CommandStateSet,
   1555                                      OMX_StateIdle,
   1556                                      NULL);
   1557 #endif
   1558             break;
   1559         case OMX_StateExecuting:
   1560         case OMX_StatePause:
   1561             pLcmlHandle = NULL;
   1562 #ifdef __PERF_INSTRUMENTATION__
   1563             PERF_Boundary(pComponentPrivate->pPERF,
   1564                           PERF_BoundaryComplete | PERF_BoundarySteadyState);
   1565 #endif
   1566 
   1567             pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   1568             eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1569                                        MMCodecControlStop,
   1570                                        NULL);
   1571         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP3,
   1572                               "Failed to stop socket node (%x).\n", eError);
   1573             pComponentPrivate->bCodecStarted = OMX_FALSE;
   1574         OMX_PRDSP2(pComponentPrivate->dbg, "MMCodecControlStop called...\n");
   1575 
   1576 #ifndef UNDER_CE
   1577             pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
   1578         while (pComponentPrivate->bDSPStopAck == OMX_FALSE)
   1579         {
   1580                 pthread_cond_wait(&pComponentPrivate->stop_cond, &pComponentPrivate->videoe_mutex_app);
   1581             }
   1582             pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
   1583 #else
   1584         while (pComponentPrivate->bDSPStopAck == OMX_FALSE)
   1585         {
   1586                 sched_yield();
   1587             }
   1588 #endif
   1589             pComponentPrivate->bDSPStopAck = OMX_FALSE;
   1590 
   1591             for (nCount = 0; nCount < pPortDefIn->nBufferCountActual; nCount++)
   1592             {
   1593                 OMX_PRBUFFER2(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [OWNER = %d]\n",
   1594                               nCount,
   1595                               VIDENC_INPUT_PORT,
   1596                               pCompPortIn->pBufferPrivate[nCount]->pBufferHdr,
   1597                               pCompPortIn->pBufferPrivate[nCount]->eBufferOwner);
   1598 
   1599                 if (pCompPortIn->pBufferPrivate[nCount]->eBufferOwner == VIDENC_BUFFER_WITH_DSP ||
   1600                     pCompPortIn->pBufferPrivate[nCount]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT)
   1601                 {
   1602                     OMX_PRBUFFER1(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [SEND BACK TO SUPPLIER]\n",
   1603                                   nCount,
   1604                                   VIDENC_INPUT_PORT,
   1605                                   pCompPortIn->pBufferPrivate[nCount]->pBufferHdr);
   1606 
   1607                     if (pCompPortIn->hTunnelComponent == NULL)
   1608                     {
   1609 
   1610                         pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->nFilledLen = 0;
   1611                         OMX_PRBUFFER1(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [memset %lu bytes]\n",
   1612                                       nCount,
   1613                                       VIDENC_INPUT_PORT,
   1614                                       pCompPortIn->pBufferPrivate[nCount]->pBufferHdr,
   1615                                       pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->nAllocLen);
   1616 
   1617                         memset(pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->pBuffer,
   1618                                0x0,
   1619                                pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->nAllocLen);
   1620 
   1621                         pCompPortIn->pBufferPrivate[nCount]->eBufferOwner = VIDENC_BUFFER_WITH_CLIENT;
   1622 #ifdef __PERF_INSTRUMENTATION__
   1623                         PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1624                                           pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->pBuffer,
   1625                                           0,
   1626                                           PERF_ModuleHLMM);
   1627 #endif
   1628                         pComponentPrivate->sCbData.EmptyBufferDone(pComponentPrivate->pHandle,
   1629                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   1630                                                                    pCompPortIn->pBufferPrivate[nCount]->pBufferHdr);
   1631                         OMX_VIDENC_IncrementBufferCountByOne(&pComponentPrivate->EmptybufferdoneCount);
   1632                         OMX_VIDENC_SignalIfAllBuffersAreReturned(pComponentPrivate);
   1633                     }
   1634                     else
   1635                     {
   1636                         pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->nFilledLen = 0;
   1637                         pCompPortIn->pBufferPrivate[nCount]->eBufferOwner = VIDENC_BUFFER_WITH_TUNNELEDCOMP;
   1638 #ifdef __PERF_INSTRUMENTATION__
   1639                         PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1640                                           pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->pBuffer,
   1641                                           0,
   1642                                           PERF_ModuleLLMM);
   1643 #endif
   1644                         eError = OMX_FillThisBuffer(pCompPortIn->hTunnelComponent,
   1645                                                     pCompPortIn->pBufferPrivate[nCount]->pBufferHdr);
   1646                     OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRBUFFER4,
   1647                                           "FillThisBuffer failed (%x).\n", eError);
   1648                     }
   1649                 }
   1650             }
   1651 
   1652             for (nCount = 0; nCount < pPortDefOut->nBufferCountActual; nCount++)
   1653             {
   1654                 OMX_PRBUFFER2(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [OWNER = %d]\n",
   1655                               nCount,
   1656                               VIDENC_OUTPUT_PORT,
   1657                               pCompPortOut->pBufferPrivate[nCount]->pBufferHdr,
   1658                               pCompPortOut->pBufferPrivate[nCount]->eBufferOwner);
   1659 
   1660                 if (pCompPortOut->pBufferPrivate[nCount]->eBufferOwner == VIDENC_BUFFER_WITH_DSP ||
   1661                     pCompPortOut->pBufferPrivate[nCount]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT)
   1662                 {
   1663 
   1664                     if (pCompPortOut->hTunnelComponent == NULL)
   1665                     {
   1666                         OMX_PRBUFFER1(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [memset %lu bytes]\n",
   1667                                       nCount,
   1668                                       VIDENC_OUTPUT_PORT,
   1669                                       pCompPortOut->pBufferPrivate[nCount]->pBufferHdr,
   1670                                       pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->nAllocLen);
   1671 
   1672                         memset(pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->pBuffer,
   1673                                0x0,
   1674                                pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->nAllocLen);
   1675                     }
   1676 
   1677                     OMX_PRBUFFER1(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [SEND BACK TO SUPPLIER]\n", nCount,
   1678                                   VIDENC_OUTPUT_PORT,
   1679                                   pCompPortOut->pBufferPrivate[nCount]->pBufferHdr);
   1680 
   1681                     pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->nFilledLen = 0;
   1682                     pCompPortOut->pBufferPrivate[nCount]->eBufferOwner = VIDENC_BUFFER_WITH_CLIENT;
   1683 #ifdef __PERF_INSTRUMENTATION__
   1684                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   1685                                       pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->pBuffer,
   1686                                       pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->nFilledLen,
   1687                                       PERF_ModuleHLMM);
   1688 #endif
   1689                     /*Propagate pBufferHeader Data*/
   1690                     OMX_CONF_CIRCULAR_BUFFER_MOVE_HEAD(pCompPortOut->pBufferPrivate[nCount]->pBufferHdr,
   1691                                                    pComponentPrivate->sCircularBuffer,
   1692                                                    pComponentPrivate);
   1693                     /* trigger event handler if we are supposed to */
   1694                     if (pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->hMarkTargetComponent == pComponentPrivate->pHandle &&
   1695                         pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->pMarkData)
   1696                     {
   1697                         OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1698                                                  OMX_EventMark,
   1699                                                  0x0,
   1700                                                  0x0,
   1701                                                  pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->pMarkData);
   1702                     }
   1703                     pComponentPrivate->sCbData.FillBufferDone(pComponentPrivate->pHandle,
   1704                                                               pComponentPrivate->pHandle->pApplicationPrivate,
   1705                                                               pCompPortOut->pBufferPrivate[nCount]->pBufferHdr);
   1706                     OMX_VIDENC_IncrementBufferCountByOne(&pComponentPrivate->FillbufferdoneCount);
   1707                     OMX_VIDENC_SignalIfAllBuffersAreReturned(pComponentPrivate);
   1708                 }
   1709             }
   1710 
   1711 #ifdef RESOURCE_MANAGER_ENABLED /* Resource Manager Proxy Calls */
   1712                 if (pCompPortOut->pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
   1713                 {
   1714                     /* TODO: Disable RM Send for now */
   1715                     /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H264_Encode_COMPONENT, 0); */
   1716                     eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1717                                                  RMProxy_StateSet,
   1718                                                  OMX_H264_Encode_COMPONENT,
   1719                                                  OMX_StateIdle,
   1720                                                  3456,
   1721                                                  NULL);
   1722                 }
   1723                 else if (pCompPortOut->pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
   1724                 {
   1725                     /* TODO: Disable RM Send for now */
   1726                     /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_MPEG4_Encode_COMPONENT, 0); */
   1727                     eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1728                                                  RMProxy_StateSet,
   1729                                                  OMX_MPEG4_Encode_COMPONENT,
   1730                                                  OMX_StateIdle,
   1731                                                  3456,
   1732                                                  NULL);
   1733                 }
   1734                 else if (pCompPortOut->pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
   1735                 {
   1736                     /* TODO: Disable RM Send for now */
   1737                     /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H263_Encode_COMPONENT, 0); */
   1738             OMX_PRMGR2(pComponentPrivate->dbg, "Setting Idle state from Executing to RMProxy\n");
   1739                     eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1740                                                  RMProxy_StateSet,
   1741                                                  OMX_H263_Encode_COMPONENT,
   1742                                                  OMX_StateIdle,
   1743                                                  3456,
   1744                                                  NULL);
   1745                 }
   1746         if (eError != OMX_ErrorNone)
   1747         {
   1748                     OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1749                                              OMX_EventError,
   1750                                              OMX_ErrorHardware,
   1751                                              OMX_TI_ErrorMajor,
   1752                                              NULL);
   1753                 }
   1754 
   1755 #endif
   1756         OMX_PRBUFFER2(pComponentPrivate->dbg, "Flushing Pipes!\n");
   1757         OMX_VIDENC_EmptyDataPipes (pComponentPrivate);
   1758 
   1759         pComponentPrivate->eState = OMX_StateIdle;
   1760 
   1761         /* Decrement reference count with signal enabled */
   1762         if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
   1763              return OMX_ErrorUndefined;
   1764         }
   1765 
   1766         OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1767                                  OMX_EventCmdComplete,
   1768                                  OMX_CommandStateSet,
   1769                                  OMX_StateIdle,
   1770                                  NULL);
   1771         break;
   1772         default:
   1773             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1774                                      OMX_EventError,
   1775                                      OMX_ErrorIncorrectStateTransition,
   1776                                      OMX_TI_ErrorMinor,
   1777                                      NULL);
   1778     }
   1779 OMX_CONF_CMD_BAIL:
   1780     return eError;
   1781 }
   1782 
   1783 /*----------------------------------------------------------------------------*/
   1784 /**
   1785   * OMX_VIDENC_HandleCommandStateSet()
   1786   *
   1787   * Called by component thread, handles commands sent by the app.
   1788   *
   1789   * @param phandle LCML_DSP_INTERFACE handle for this instance of the component
   1790   *
   1791   * @retval OMX_ErrorNone                  success, ready to roll
   1792   *         OMX_ErrorInsufficientResources if the malloc fails
   1793   **/
   1794 /*----------------------------------------------------------------------------*/
   1795 OMX_ERRORTYPE OMX_VIDENC_HandleCommandStateSetExecuting(VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
   1796 {
   1797     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1798     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
   1799     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
   1800     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   1801 
   1802     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   1803 
   1804     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
   1805     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
   1806 
   1807     switch (pComponentPrivate->eState)
   1808     {
   1809         case OMX_StateExecuting:
   1810             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, OMX_EventError, OMX_ErrorSameState, OMX_TI_ErrorMinor, NULL);
   1811             break;
   1812         case OMX_StateIdle:
   1813             OMX_CONF_CIRCULAR_BUFFER_RESTART(pComponentPrivate->sCircularBuffer);
   1814         case OMX_StatePause:
   1815             if (pComponentPrivate->bCodecStarted == OMX_FALSE)
   1816             {
   1817                 pLcmlHandle = NULL;
   1818                 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   1819                 pLcmlHandle->pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)pComponentPrivate;
   1820 
   1821             OMX_PRDSP2(pComponentPrivate->dbg, "Starting the codec...\n");
   1822                 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1823                                            EMMCodecControlStart,
   1824                                            NULL);
   1825             OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
   1826                                   "Failed to start socket node (%x).\n", eError);
   1827 
   1828                 pComponentPrivate->bCodecStarted = OMX_TRUE;
   1829             }
   1830 
   1831 #ifdef RESOURCE_MANAGER_ENABLED /* Resource Manager Proxy Calls */
   1832             if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
   1833             {
   1834                 /* TODO: Disable RM Send for now */
   1835             OMX_PRMGR2(pComponentPrivate->dbg, "Setting executing state to RMProxy\n");
   1836                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H264_Encode_COMPONENT, 0); */
   1837                 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1838                                              RMProxy_StateSet,
   1839                                              OMX_H264_Encode_COMPONENT,
   1840                                              OMX_StateExecuting,
   1841                                              3456,
   1842                                              NULL);
   1843             }
   1844             else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
   1845             {
   1846                 /* TODO: Disable RM Send for now */
   1847             OMX_PRMGR2(pComponentPrivate->dbg, "Setting executing state to RMProxy\n");
   1848                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_MPEG4_Encode_COMPONENT, 0); */
   1849                 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1850                                              RMProxy_StateSet,
   1851                                              OMX_MPEG4_Encode_COMPONENT,
   1852                                              OMX_StateExecuting,
   1853                                              3456,
   1854                                              NULL);
   1855 
   1856             }
   1857             else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
   1858             {
   1859                 /* TODO: Disable RM Send for now */
   1860                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H263_Encode_COMPONENT, 0); */
   1861             OMX_PRMGR2(pComponentPrivate->dbg, "Setting executing state to RMProxy\n");
   1862                 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   1863                                              RMProxy_StateSet,
   1864                                              OMX_H263_Encode_COMPONENT,
   1865                                              OMX_StateExecuting,
   1866                                              3456,
   1867                                              NULL);
   1868             }
   1869             if (eError != OMX_ErrorNone)
   1870             {
   1871                 pComponentPrivate->eState = OMX_StateWaitForResources;
   1872                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1873                                          OMX_EventError,
   1874                                          OMX_ErrorHardware,
   1875                                          OMX_TI_ErrorMajor,
   1876                                          NULL);
   1877             }
   1878 #endif
   1879             pComponentPrivate->eState = OMX_StateExecuting;
   1880 #ifdef __PERF_INSTRUMENTATION__
   1881             PERF_Boundary(pComponentPrivate->pPERFcomp,
   1882                           PERF_BoundaryStart | PERF_BoundarySteadyState);
   1883 #endif
   1884 
   1885             /* Decrement reference count with signal enabled */
   1886             if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
   1887                  return OMX_ErrorUndefined;
   1888             }
   1889 
   1890             /*Send state change notificaiton to Application*/
   1891             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1892                                      OMX_EventCmdComplete,
   1893                                      OMX_CommandStateSet,
   1894                                      OMX_StateExecuting,
   1895                                      NULL);
   1896             break;
   1897         default:
   1898             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1899                                      OMX_EventError,
   1900                                      OMX_ErrorIncorrectStateTransition,
   1901                                      OMX_TI_ErrorMinor,
   1902                                      NULL);
   1903     }
   1904 OMX_CONF_CMD_BAIL:
   1905     return eError;
   1906 }
   1907 
   1908 /*----------------------------------------------------------------------------*/
   1909 /**
   1910   * OMX_VIDENC_HandleCommandStateSetPause()
   1911   *
   1912   * Called by component thread, handles commands sent by the app.
   1913   *
   1914   * @param phandle LCML_DSP_INTERFACE handle for this instance of the component
   1915   *
   1916   * @retval OMX_ErrorNone                  success, ready to roll
   1917   *         OMX_ErrorInsufficientResources if the malloc fails
   1918   **/
   1919 /*----------------------------------------------------------------------------*/
   1920 OMX_ERRORTYPE OMX_VIDENC_HandleCommandStateSetPause (VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
   1921 {
   1922     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1923     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
   1924     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   1925     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
   1926 
   1927     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   1928 
   1929     pLcmlHandle     = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   1930     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
   1931     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
   1932 
   1933 
   1934     switch (pComponentPrivate->eState)
   1935     {
   1936         case OMX_StatePause:
   1937             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1938                                      OMX_EventError,
   1939                                      OMX_ErrorSameState,
   1940                                      OMX_TI_ErrorMinor,
   1941                                      NULL);
   1942             break;
   1943         case OMX_StateIdle:
   1944         case OMX_StateExecuting:
   1945             pLcmlHandle = NULL;
   1946 #ifdef __PERF_INSTRUMENTATION__
   1947             PERF_Boundary(pComponentPrivate->pPERFcomp,
   1948                           PERF_BoundaryComplete | PERF_BoundarySteadyState);
   1949 #endif
   1950             pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   1951             eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   1952                                        EMMCodecControlPause,
   1953                                    NULL);
   1954         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
   1955                               "Failed to pause socket node (%x).\n", eError);
   1956 
   1957 
   1958         pComponentPrivate->bCodecStarted = OMX_FALSE;
   1959         OMX_PRDSP2(pComponentPrivate->dbg, "MMCodecControlPaused called...\n");
   1960 
   1961 
   1962 #ifndef UNDER_CE
   1963             pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
   1964         while (pComponentPrivate->bDSPStopAck == OMX_FALSE)
   1965         {
   1966                 pthread_cond_wait(&pComponentPrivate->stop_cond, &pComponentPrivate->videoe_mutex_app);
   1967             }
   1968             pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
   1969 #else
   1970         while (pComponentPrivate->bDSPStopAck == OMX_FALSE)
   1971         {
   1972                 sched_yield();
   1973             }
   1974 #endif
   1975 
   1976             pComponentPrivate->bDSPStopAck = OMX_FALSE;
   1977 
   1978             pComponentPrivate->eState = OMX_StatePause;
   1979 
   1980             /* Decrement reference count with signal enabled */
   1981             if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
   1982                  return OMX_ErrorUndefined;
   1983             }
   1984 
   1985             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1986                                      OMX_EventCmdComplete,
   1987                                      OMX_CommandStateSet,
   1988                                      OMX_StatePause,
   1989                                      NULL);
   1990             break;
   1991         default:
   1992             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   1993                                      OMX_EventError,
   1994                                      OMX_ErrorIncorrectStateTransition,
   1995                                      OMX_TI_ErrorMinor,
   1996                                      NULL);
   1997     }
   1998 
   1999 OMX_CONF_CMD_BAIL:
   2000     return eError;
   2001 }
   2002 
   2003 /*----------------------------------------------------------------------------*/
   2004 /**
   2005   * OMX_VIDENC_HandleCommandStateSetLoaded()
   2006   *
   2007   * Called by component thread, handles commands sent by the app.
   2008   *
   2009   * @param phandle LCML_DSP_INTERFACE handle for this instance of the component
   2010   *
   2011   * @retval OMX_ErrorNone                  success, ready to roll
   2012   *         OMX_ErrorInsufficientResources if the malloc fails
   2013   **/
   2014 /*----------------------------------------------------------------------------*/
   2015 OMX_ERRORTYPE OMX_VIDENC_HandleCommandStateSetLoaded (VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
   2016 {
   2017     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2018     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
   2019     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
   2020     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   2021 
   2022     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   2023 
   2024     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
   2025     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
   2026 
   2027     switch (pComponentPrivate->eState)
   2028     {
   2029         case OMX_StateLoaded:
   2030             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   2031                                      OMX_EventError,
   2032                                      OMX_ErrorSameState,
   2033                                      OMX_TI_ErrorMinor,
   2034                                      NULL);
   2035             break;
   2036         case OMX_StateWaitForResources:
   2037         OMX_PRSTATE2(pComponentPrivate->dbg, "Transitioning from WFR to Loaded\n");
   2038 #ifdef RESOURCE_MANAGER_ENABLED
   2039             if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
   2040             {
   2041                 /* TODO: Disable RM Send for now */
   2042                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H264_Encode_COMPONENT, 0); */
   2043             OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Loaded from WFR\n");
   2044                 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   2045                                              RMProxy_StateSet,
   2046                                              OMX_H264_Encode_COMPONENT,
   2047                                              OMX_StateLoaded,
   2048                                              3456,
   2049                                              NULL);
   2050             }
   2051             else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
   2052             {
   2053                 /* TODO: Disable RM Send for now */
   2054                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_MPEG4_Encode_COMPONENT, 0); */
   2055             OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Loaded from WFR\n");
   2056                 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   2057                                              RMProxy_StateSet,
   2058                                              OMX_MPEG4_Encode_COMPONENT,
   2059                                              OMX_StateLoaded,
   2060                                              3456,
   2061                                              NULL);
   2062             }
   2063             else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
   2064             {
   2065                 /* TODO: Disable RM Send for now */
   2066                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H263_Encode_COMPONENT, 0); */
   2067             OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Loaded from WFR\n");
   2068                 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   2069                                              RMProxy_StateSet,
   2070                                              OMX_H263_Encode_COMPONENT,
   2071                                              OMX_StateLoaded,
   2072                                              3456,
   2073                                              NULL);
   2074             }
   2075             if (eError != OMX_ErrorNone)
   2076             {
   2077                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   2078                                          OMX_EventError,
   2079                                          OMX_ErrorHardware,
   2080                                          OMX_TI_ErrorMajor,
   2081                                          NULL);
   2082                 break;
   2083             }
   2084 #endif
   2085             pComponentPrivate->eState = OMX_StateLoaded;
   2086             /* Decrement reference count with signal enabled */
   2087             if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
   2088                 return OMX_ErrorUndefined;
   2089             }
   2090 
   2091             #ifdef __PERF_INSTRUMENTATION__
   2092                 PERF_Boundary(pComponentPrivate->pPERFcomp,
   2093                               PERF_BoundaryComplete | PERF_BoundaryCleanup);
   2094             #endif
   2095             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   2096                                      OMX_EventCmdComplete,
   2097                                      OMX_CommandStateSet,
   2098                                      OMX_StateLoaded,
   2099                                      NULL);
   2100             break;
   2101         case OMX_StateIdle:
   2102             OMX_PRSTATE2(pComponentPrivate->dbg, "Transitioning from Idle to Loaded\n");
   2103             pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   2104     #ifdef __PERF_INSTRUMENTATION__
   2105             PERF_Boundary(pComponentPrivate->pPERFcomp,
   2106                           PERF_BoundaryStart | PERF_BoundaryCleanup);
   2107     #endif
   2108             pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
   2109             while ( (pPortDefIn->bPopulated) || (pPortDefOut->bPopulated))
   2110             {
   2111     #ifndef UNDER_CE
   2112                     pthread_cond_wait(&pComponentPrivate->unpopulate_cond, &pComponentPrivate->videoe_mutex_app);
   2113     #else
   2114                     OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
   2115     #endif
   2116             }
   2117             pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
   2118 
   2119     #ifdef RESOURCE_MANAGER_ENABLED /* Resource Manager Proxy Calls */
   2120             if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
   2121             {
   2122                 /* TODO: Disable RM Send for now */
   2123                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H264_Encode_COMPONENT, 0); */
   2124                 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   2125                                              RMProxy_FreeResource,
   2126                                              OMX_H264_Encode_COMPONENT,
   2127                                              0,
   2128                                              3456,
   2129                                              NULL);
   2130             }
   2131             else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
   2132             {
   2133                 /* TODO: Disable RM Send for now */
   2134                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_MPEG4_Encode_COMPONENT, 0); */
   2135                 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   2136                                              RMProxy_FreeResource,
   2137                                              OMX_MPEG4_Encode_COMPONENT,
   2138                                              0,
   2139                                              3456,
   2140                                              NULL);
   2141             }
   2142             else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
   2143             {
   2144                 /* TODO: Disable RM Send for now */
   2145                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H263_Encode_COMPONENT, 0); */
   2146                 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
   2147                                              RMProxy_FreeResource,
   2148                                              OMX_H263_Encode_COMPONENT,
   2149                                              0,
   2150                                              3456,
   2151                                              NULL);
   2152             }
   2153             if (eError != OMX_ErrorNone)
   2154             {
   2155                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   2156                                          OMX_EventError,
   2157                                          OMX_ErrorHardware,
   2158                                          OMX_TI_ErrorMajor,
   2159                                          NULL);
   2160             }
   2161     #endif
   2162              /* Make sure the DSP node has been deleted */
   2163              if (pComponentPrivate->bCodecStarted == OMX_TRUE || pComponentPrivate->bCodecLoaded == OMX_TRUE)
   2164              {
   2165                  OMX_TRACE2(pComponentPrivate->dbg, "LCML_ControlCodec EMMCodecControlDestroy\n");
   2166                  eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   2167                                              EMMCodecControlDestroy,
   2168                                              NULL);
   2169                  OMX_CONF_BAIL_IF_ERROR(eError);
   2170                  OMX_TRACE2(pComponentPrivate->dbg,"Atempting to Unload LCML");
   2171                  /*Unload LCML */
   2172                  if(pComponentPrivate->pModLcml != NULL)
   2173                  {
   2174                      OMX_TRACE2(pComponentPrivate->dbg,"Unloading LCML");
   2175                      dlclose(pComponentPrivate->pModLcml);
   2176                      pComponentPrivate->pModLcml = NULL;
   2177                      pComponentPrivate->pLCML = NULL;
   2178                  }
   2179 
   2180                  pComponentPrivate->bCodecStarted = OMX_FALSE;
   2181                  pComponentPrivate->bCodecLoaded = OMX_FALSE;
   2182              }
   2183 
   2184              OMX_CONF_BAIL_IF_ERROR(eError);
   2185 
   2186 #ifdef __KHRONOS_CONF__
   2187             pComponentPrivate->bPassingIdleToLoaded = OMX_FALSE;
   2188 #endif
   2189             pComponentPrivate->eState = OMX_StateLoaded;
   2190 
   2191 #ifdef __PERF_INSTRUMENTATION__
   2192                 PERF_Boundary(pComponentPrivate->pPERFcomp,
   2193                               PERF_BoundaryComplete | PERF_BoundaryCleanup);
   2194 #endif
   2195 
   2196             /* Decrement reference count with signal enabled */
   2197             if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
   2198                  return OMX_ErrorUndefined;
   2199             }
   2200 
   2201             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   2202                                      OMX_EventCmdComplete,
   2203                                      OMX_CommandStateSet,
   2204                                      OMX_StateLoaded,
   2205                                      NULL);
   2206             break;
   2207         default:
   2208             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   2209                                      OMX_EventError,
   2210                                      OMX_ErrorIncorrectStateTransition,
   2211                                      OMX_TI_ErrorMinor,
   2212                                      NULL);
   2213     }
   2214 OMX_CONF_CMD_BAIL:
   2215     return eError;
   2216 }
   2217 
   2218 
   2219 /*---------------------------------------------------------------------------------------*/
   2220 /**
   2221   * OMX_OMX_VIDENC_Process_FreeOutBuf()
   2222   *
   2223   * Called by component thread, handles free output buffers from app.
   2224   *
   2225   * @param pComponentPrivate private component structure for this instance of the component
   2226   *
   2227   * @param phandle LCML_DSP_INTERFACE handle for this instance of the component
   2228   *
   2229   * @retval OMX_ErrorNone                  success, ready to roll
   2230   *         OMX_ErrorInsufficientResources if the malloc fails
   2231   **/
   2232 /*---------------------------------------------------------------------------------------*/
   2233 
   2234 OMX_ERRORTYPE OMX_VIDENC_Process_FreeOutBuf(VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
   2235 {
   2236     int nRet = -1;
   2237     void *pUalgOutParams = NULL;
   2238     VIDENC_NODE* pMemoryListHead = NULL;
   2239     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2240     OMX_BUFFERHEADERTYPE* pBufHead = NULL;
   2241     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
   2242      VIDENC_BUFFER_PRIVATE* pBufferPrivate = NULL;
   2243     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   2244 
   2245     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   2246 
   2247     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
   2248     pLcmlHandle = (LCML_DSP_INTERFACE*)(((VIDENC_COMPONENT_PRIVATE*)pComponentPrivate)->pLCML);
   2249     pMemoryListHead = pComponentPrivate->pMemoryListHead;
   2250 
   2251 #ifndef UNDER_CE
   2252     if (pthread_mutex_lock(&(pComponentPrivate->mVideoEncodeBufferMutex)) != 0)
   2253     {
   2254         OMX_TRACE4(pComponentPrivate->dbg, "pthread_mutex_lock() failed.\n");
   2255         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
   2256     }
   2257     nRet = read(pComponentPrivate->nFree_oPipe[0], &pBufHead, sizeof(pBufHead));
   2258     if ((nRet == -1) || !pBufHead || !pBufHead->pOutputPortPrivate)
   2259     {
   2260         pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex));
   2261         OMX_ERROR4(pComponentPrivate->dbg, "Error while reading from the pipe\n");
   2262         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
   2263     }
   2264 
   2265     pBufferPrivate = pBufHead->pOutputPortPrivate;
   2266 
   2267     pBufferPrivate->bReadFromPipe = OMX_TRUE;
   2268     if (pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex)) != 0)
   2269     {
   2270         OMX_TRACE4(pComponentPrivate->dbg, "pthread_mutex_unlock() failed.\n");
   2271         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
   2272     }
   2273 #else
   2274     nRet = read(pComponentPrivate->nFree_oPipe[0], &pBufHead, sizeof(pBufHead));
   2275     if ((nRet == -1) || (pBufHead == NULL) || (pBufHead->pOutputPortPrivate == NULL))
   2276     {
   2277         OMX_ERROR4(pComponentPrivate->dbg, "Error while reading from the pipe\n");
   2278         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
   2279     }
   2280     if (pBufHead != NULL)
   2281     {
   2282         pBufferPrivate = pBufHead->pOutputPortPrivate;
   2283     }
   2284     pBufferPrivate->bReadFromPipe = OMX_TRUE;
   2285 #endif
   2286 
   2287 #ifdef __PERF_INSTRUMENTATION__
   2288     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   2289                       PREF(pBufHead,pBuffer),
   2290                       0,
   2291                       PERF_ModuleCommonLayer);
   2292 #endif
   2293 
   2294 if (pBufferPrivate->eBufferOwner == VIDENC_BUFFER_WITH_DSP ||
   2295         pBufferPrivate->eBufferOwner == VIDENC_BUFFER_WITH_CLIENT)
   2296     {
   2297 goto EXIT;
   2298 
   2299 }
   2300 
   2301     if(!pBufferPrivate || !pLcmlHandle || !pPortDefOut)
   2302         goto EXIT;
   2303 
   2304     if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
   2305     {
   2306             pUalgOutParams =(H264VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam;
   2307         OMX_PRBUFFER1(pComponentPrivate->dbg, " %p \n", (void*)pBufHead);
   2308             pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_DSP;
   2309             eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   2310                                       EMMCodecOuputBuffer,
   2311                                       pBufHead->pBuffer,
   2312                                       pBufHead->nAllocLen,
   2313                                       0,
   2314                                       (OMX_U8*)pUalgOutParams,
   2315                                       sizeof(H264VE_GPP_SN_UALGOutputParams),
   2316                                       (void*)pBufHead);
   2317             if (eError != OMX_ErrorNone)
   2318         {
   2319             OMX_PRDSP4(pComponentPrivate->dbg, "LCML QueueBuffer failed: %x\n", eError);
   2320             OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
   2321         }
   2322 
   2323     }
   2324     else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   2325              pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
   2326     {
   2327         pUalgOutParams = (MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam;
   2328         OMX_PRBUFFER1(pComponentPrivate->dbg, " %p\n", (void*)pBufHead);
   2329         pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_DSP;
   2330         eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   2331                                   EMMCodecOuputBuffer,
   2332                                   pBufHead->pBuffer,
   2333                                   pBufHead->nAllocLen,
   2334                                   0,
   2335                                   (OMX_U8*)pUalgOutParams,
   2336                                   sizeof(MP4VE_GPP_SN_UALGOutputParams),
   2337                                   (void*)pBufHead);
   2338         if (eError != OMX_ErrorNone)
   2339         {
   2340             OMX_PRDSP4(pComponentPrivate->dbg, "LCML QueueBuffer failed: %x\n", eError);
   2341             OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
   2342         }
   2343     }
   2344     else
   2345     {
   2346         OMX_PRBUFFER4(pComponentPrivate->dbg, "Unsupported compression format (%d)\n",
   2347                       pPortDefOut->format.video.eCompressionFormat);
   2348         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
   2349     }
   2350     EXIT:
   2351 OMX_CONF_CMD_BAIL:
   2352     return eError;
   2353 }
   2354 
   2355 /*---------------------------------------------------------------------------------------*/
   2356 /**
   2357   * OMX_VIDENC_Process_FilledInBuf()
   2358   *
   2359   * Called by component thread, handles filled input buffers from app.
   2360   *
   2361   * @param pComponentPrivate private component structure for this instance of the component
   2362   *
   2363   * @param phandle LCML_DSP_INTERFACE handle for this instance of the component
   2364   *
   2365   * @retval OMX_ErrorNone                  success, ready to roll
   2366   *         OMX_ErrorInsufficientResources if the malloc fails
   2367   **/
   2368 /*---------------------------------------------------------------------------------------*/
   2369 
   2370 OMX_ERRORTYPE OMX_VIDENC_Process_FilledInBuf(VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
   2371 {
   2372     OMX_U8 i = 0;
   2373     int nRet = -1;
   2374     void* pUalgInpParams = NULL;
   2375     VIDENC_NODE* pMemoryListHead = NULL;
   2376     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2377     OMX_BUFFERHEADERTYPE* pBufHead = NULL;
   2378     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
   2379     VIDENC_BUFFER_PRIVATE* pBufferPrivate = NULL;
   2380     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
   2381     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   2382     VIDEOENC_PORT_TYPE* pCompPortOut            = NULL;
   2383 
   2384     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   2385 
   2386     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
   2387     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
   2388     pCompPortOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
   2389     pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   2390     pMemoryListHead = pComponentPrivate->pMemoryListHead;
   2391 
   2392     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pLcmlHandle, pPortDefIn, 1);
   2393 
   2394 #ifndef UNDER_CE
   2395     if (pthread_mutex_lock(&(pComponentPrivate->mVideoEncodeBufferMutex)) != 0)
   2396     {
   2397         OMX_TRACE4(pComponentPrivate->dbg, "pthread_mutex_lock() failed.\n");
   2398         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
   2399     }
   2400     nRet = read(pComponentPrivate->nFilled_iPipe[0], &(pBufHead), sizeof(pBufHead));
   2401     if ((nRet == -1) || !pBufHead || !pBufHead->pInputPortPrivate)
   2402     {
   2403         pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex));
   2404         OMX_TRACE4(pComponentPrivate->dbg, "Error while reading from the pipe\n");
   2405         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
   2406     }
   2407 
   2408     if (pBufHead != NULL)
   2409     {
   2410     pBufferPrivate = (VIDENC_BUFFER_PRIVATE*)pBufHead->pInputPortPrivate;
   2411    	}
   2412     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pBufHead, pBufferPrivate, 1);
   2413     pBufferPrivate->bReadFromPipe = OMX_TRUE;
   2414 
   2415     if (pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex)) != 0)
   2416     {
   2417         OMX_TRACE4(pComponentPrivate->dbg, "pthread_mutex_unlock() failed.\n");
   2418         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
   2419     }
   2420 #else
   2421     nRet = read(pComponentPrivate->nFilled_iPipe[0], &(pBufHead), sizeof(pBufHead));
   2422     if (nRet == -1)
   2423     {
   2424         OMX_TRACE4(pComponentPrivate->dbg, "Error while reading from the pipe\n");
   2425         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
   2426     }
   2427     pBufferPrivate = (VIDENC_BUFFER_PRIVATE*)pBufHead->pInputPortPrivate;
   2428     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pBufHead, pBufferPrivate, 1);
   2429     pBufferPrivate->bReadFromPipe = OMX_TRUE;
   2430 #endif
   2431 
   2432 #ifdef __PERF_INSTRUMENTATION__
   2433     /*For Steady State Instumentation*/
   2434     #if 0
   2435     if ((pComponentPrivate->nLcml_nCntIp == 1))
   2436     {
   2437         PERF_Boundary(pComponentPrivate->pPERFcomp,
   2438                       PERF_BoundaryStart | PERF_BoundarySteadyState);
   2439     }
   2440     #endif
   2441     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   2442                       PREF(pBufHead,pBuffer),
   2443                       pPortDefIn->nBufferSize,
   2444                       PERF_ModuleCommonLayer);
   2445 #endif
   2446 
   2447     if (pBufferPrivate->eBufferOwner == VIDENC_BUFFER_WITH_DSP ||
   2448         pBufferPrivate->eBufferOwner == VIDENC_BUFFER_WITH_CLIENT)
   2449     {
   2450         goto EXIT;
   2451     }
   2452 
   2453 
   2454 
   2455     if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
   2456     {
   2457 
   2458         pUalgInpParams = (H264VE_GPP_SN_UALGInputParams*)pBufferPrivate->pUalgParam;
   2459         OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pUalgInpParams, 1, 1);
   2460 
   2461         /*< must be followed for all video encoders*/
   2462         /*  size of this structure             */
   2463         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.size = sizeof(H264VE_GPP_SN_UALGInputParams);
   2464         /*  Input frame height                 */
   2465         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.inputHeight = pPortDefIn->format.video.nFrameHeight;
   2466         /*  Input frame width                  */
   2467         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.inputWidth  = pPortDefIn->format.video.nFrameWidth;
   2468         /*  Reference or input frame rate*1000 */
   2469         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.refFrameRate = (OMX_U32)(Q16Tof(pPortDefIn->format.video.xFramerate)*1000.0);
   2470         /*  Target frame rate * 1000           */
   2471         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.targetFrameRate = pComponentPrivate->nTargetFrameRate;
   2472         /*  Target bit rate in bits per second */
   2473         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.targetBitRate = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig->nEncodeBitrate;
   2474         /*  I frame interval e.g. 30           */
   2475         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.intraFrameInterval = pComponentPrivate->nIntraFrameInterval;
   2476         /*  XDM_ENCODE_AU, XDM_GENERATE_HEADER */
   2477         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.generateHeader = 0;
   2478         /*  DEFAULT(0): use imagewidth as pitch
   2479         *  else use given capture width for
   2480         *  pitch provided it is greater than
   2481         *  image width.*/
   2482         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.captureWidth = 0;
   2483         /*  Force given frame as I or IDR (in H.264)  frame    */
   2484         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.forceIFrame = pComponentPrivate->bForceIFrame;
   2485 
   2486 
   2487 
   2488         /*< initial QP of I frames Range[-1,51]. -1 is for auto initialization.*/
   2489         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.qpIntra = 0x0000001c;
   2490         /*< initial QP of P frames Range[-1,51]. -1 is for auto initialization.*/
   2491         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.qpInter = 0x0000001c;
   2492         /*< Maximum QP to be used  Range[0,51]*/
   2493         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.qpMax = 0x00000033;
   2494         /*< Minimum QP to be used  Range[0,51]*/
   2495         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.qpMin = 0x00000000;
   2496         /*< Controls enable/disable loop filter, See IH264VENC_LoopFilterParams for more details*/
   2497         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.lfDisableIdc = 0x00000000;
   2498         /*< enable/disable Quarter Pel Interpolation*/
   2499         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.quartPelDisable = 0x00000000;
   2500         /*< Adaptive Intra Refesh MB Period: Period at which intra macro blocks should be insterted in a frame*/
   2501         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.airMbPeriod = pComponentPrivate->nAIRRate;
   2502         /*< Maximum number of macro block in a slice <minimum value is 8>*/
   2503         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.maxMBsPerSlice = 0;
   2504         /*< Maximum number of bytes in a slice */
   2505         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.maxBytesPerSlice = 0;
   2506         /*< Row number from which slice needs to be intra coded*/
   2507         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sliceRefreshRowStartNumber = 0;
   2508         /*< Number of rows to be coded as intra slice*/
   2509         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sliceRefreshRowNumber = 0;
   2510         /*< alpha offset for loop filter [-12, 12] even number*/
   2511         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.filterOffsetA = 0;
   2512         /*< beta offset for loop filter [-12, 12] even number*/
   2513         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.filterOffsetB = 0 ;
   2514         /*< Limits the maximum frame number in the bit-stream to (1<< (log2MaxFNumMinus4 + 4)) Range[0,12]*/
   2515         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.log2MaxFNumMinus4 = 0;
   2516         /*< Specifies offset to be added to luma QP for addressing QPC values table for chroma components. Valid value is between -12 and 12, (inclusive)*/
   2517         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.chromaQPIndexOffset = 0;
   2518         /*< Controls the intra macroblock coding in P slices [0,1]*/
   2519         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.constrainedIntraPredEnable = 0;
   2520         /*< Picture Order count type Valid values 0, 2*/
   2521         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.picOrderCountType = 0;
   2522         /*< enable/Disable Multiple Motion vector per MB, valid values are [1, 4] [For DM6446, allowed value is only 1]*/
   2523         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.maxMVperMB = pComponentPrivate->maxMVperMB;
   2524         /*< See IH264VENC_Intra4x4Params for more details*/
   2525         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.intra4x4EnableIdc = pComponentPrivate->intra4x4EnableIdc;
   2526         /*< enable/Disable Motion vector access*/
   2527         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.mvDataEnable = 0;
   2528         /*< Enable/Disable Hierarchical P Frame (non-reference P frame) Coding. [Not useful for DM6446]*/
   2529         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.hierCodingEnable = 0; /* should be 1; */
   2530         /*< Signals the type of stream generated with Call-back*/
   2531         if (pComponentPrivate->AVCNALFormat == VIDENC_AVC_NAL_UNIT)
   2532         {
   2533             ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.streamFormat = IH264_BYTE_STREAM;
   2534         }
   2535         else
   2536         {
   2537            ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.streamFormat = IH264_NALU_STREAM;
   2538         }
   2539         /*< Mechanism to do intra Refresh, see IH264VENC_IntraRefreshMethods for valid values*/
   2540         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.intraRefreshMethod = IH264_INTRAREFRESH_NONE;
   2541         /* Enable Perceptual Quantization a.k.a. Perceptual Rate Control*/
   2542         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.perceptualQuant = 0;
   2543         /* Enable Scene Change Detection*/
   2544         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sceneChangeDet = 0;
   2545         /*< Function pointer of the call-back function to be used by Encoder*/
   2546         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.pfNalUnitCallBack = NULL;
   2547 
   2548         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.pContext = NULL;
   2549 
   2550         /*< Following Parameter are related to Arbitrary Slice Ordering (ASO)*/
   2551         /*< Number of valid enteries in asoSliceOrder array valid range is [0,8],
   2552         //!< where 0 and 1 doesn't have any effect*/
   2553         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.numSliceASO = pComponentPrivate->numSliceASO;
   2554         /*!< Array containing the order of slices in which they should
   2555         //!< be present in bit-stream. vaild enteries are [0, any entry lesser than numSlicesASO]*/
   2556         for( i=0; i<MAXNUMSLCGPS;i++)
   2557             ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.asoSliceOrder[i] = pComponentPrivate->asoSliceOrder[i];
   2558 
   2559         /*< Following Parameter are related to Flexible macro block ordering (FMO)*/
   2560         /*< Total Number of slice groups, valid enteries are [0,8]*/
   2561         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.numSliceGroups = pComponentPrivate->numSliceGroups;
   2562         /*< Slice GroupMapType : For Valid enteries see IH264VENC_SliceGroupMapType*/
   2563         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sliceGroupMapType = pComponentPrivate->sliceGroupMapType;
   2564         /*< Slice Group Change Direction Flag: Only valid when sliceGroupMapType
   2565         //!< is equal to IH264_RASTER_SCAN_SLICE_GRP.
   2566         //!< For valid values refer IH264VENC_SliceGroupChangeDirection*/
   2567         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sliceGroupChangeDirectionFlag = pComponentPrivate->sliceGroupChangeDirectionFlag;
   2568         /*< Slice Group Change Rate: Only valid when sliceGroupMapType
   2569         //!< is equal to IH264_RASTER_SCAN_SLICE_GRP.
   2570         //!< valid values are : [0, factor of number of Mbs in a row]*/
   2571         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sliceGroupChangeRate = pComponentPrivate->sliceGroupChangeRate;
   2572         /*< Slice Group Change Cycle: Only valid when sliceGroupMapType
   2573         //!< is equal to IH264_RASTER_SCAN_SLICE_GRP.
   2574         //!< Valid values can be 0 to numMbsRowsInPicture, also constrained
   2575         //!< by sliceGroupChangeRate*sliceGroupChangeCycle < totalMbsInFrame*/
   2576         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sliceGroupChangeCycle = pComponentPrivate->sliceGroupChangeCycle;
   2577         /*< This field is useful in case of sliceGroupMapType equal to either
   2578         //!< IH264_INTERLEAVED_SLICE_GRP or IH264_FOREGRND_WITH_LEFTOVER_SLICE_GRP
   2579         //!< In both cases it has different meaning:
   2580         //!< In case of IH264_INTERLEAVED_SLICE_GRP:
   2581         //!< The i-th entery in this array is used to specify the number of consecutive
   2582         //!< slice group macroblocks to be assigned to the i-th slice group in
   2583         //!< raster scan order of slice group macroblock units.
   2584         //!< Valid values are 0 to totalMbsInFrame again constrained by sum of all the elements
   2585         //!< shouldn't exceed totalMbsInFrame
   2586         //!< In case of IH264_FOREGRND_WITH_LEFTOVER_SLICE_GRP:
   2587         //!< First entry in the array specify the start position of foreground region in terms
   2588         //!< of macroblock number, valid values are [0, totalMbsInFrame-1]
   2589         //!< Second entry in the array specify the end position of foreground region in terms
   2590         //!< of macroblock number, valid values are [0, totalMbsInFrame-1] with following constrains:
   2591         //!< endPos > startPos && endPos%mbsInOneRow > startPos%mbsInOneRow*/
   2592         for( i=0; i<MAXNUMSLCGPS;i++)
   2593         {
   2594             ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sliceGroupParams[i] = pComponentPrivate->sliceGroupParams[i];
   2595         }
   2596 
   2597         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulFrameIndex = pComponentPrivate->nFrameCnt;
   2598 
   2599         pComponentPrivate->bForceIFrame = 0;
   2600         ++pComponentPrivate->nFrameCnt;
   2601 
   2602         printH264UAlgInParam(pUalgInpParams, 0, &pComponentPrivate->dbg);
   2603         OMX_CONF_CIRCULAR_BUFFER_MOVE_TAIL(pBufHead,
   2604                                            pComponentPrivate->sCircularBuffer,
   2605                                            pComponentPrivate);
   2606 
   2607        /*Send Buffer to LCML*/
   2608         OMX_PRBUFFER1(pComponentPrivate->dbg, " %p\n", (void*)pBufHead);
   2609         pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_DSP;
   2610         eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
   2611                                   EMMCodecInputBuffer,
   2612                                   pBufHead->pBuffer,
   2613                                   pBufHead->nAllocLen,
   2614                                   pBufHead->nFilledLen,
   2615                                   (OMX_U8*)pUalgInpParams,
   2616                                   sizeof(H264VE_GPP_SN_UALGInputParams),
   2617                                   (OMX_U8*)pBufHead);
   2618         if (eError != OMX_ErrorNone)
   2619         {
   2620             OMX_PRDSP4(pComponentPrivate->dbg, "LCML QueueBuffer failed: %x\n", eError);
   2621             OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
   2622         }
   2623 
   2624     }
   2625     else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   2626              pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
   2627     {
   2628         eError = OMX_VIDENC_Queue_Mpeg4_Buffer(pComponentPrivate, pBufHead);
   2629     }
   2630     else
   2631     {
   2632         OMX_PRBUFFER4(pComponentPrivate->dbg, "Unsupported compression format (%d)\n",
   2633                       pPortDefOut->format.video.eCompressionFormat);
   2634         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
   2635     }
   2636 OMX_CONF_CMD_BAIL:
   2637 EXIT:
   2638     return eError;
   2639 }
   2640 
   2641 OMX_ERRORTYPE OMX_VIDENC_Queue_Mpeg4_Buffer(VIDENC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BUFFERHEADERTYPE* pBufHead)
   2642 {
   2643     MP4VE_GPP_SN_UALGInputParams* pUalgInpParams = NULL;
   2644     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2645     VIDENC_BUFFER_PRIVATE* pBufferPrivate;
   2646     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
   2647     VIDEOENC_PORT_TYPE* pCompPortOut = NULL;
   2648     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   2649 
   2650     pBufferPrivate = (VIDENC_BUFFER_PRIVATE*)pBufHead->pInputPortPrivate;
   2651     pCompPortOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
   2652     pPortDefOut = pCompPortOut->pPortDef;
   2653     pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   2654 
   2655     pUalgInpParams = (MP4VE_GPP_SN_UALGInputParams*)pBufferPrivate->pUalgParam;
   2656     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pUalgInpParams, 1, 1);
   2657 
   2658     pUalgInpParams->ulFrameIndex         = pComponentPrivate->nFrameCnt;
   2659     pUalgInpParams->ulTargetFrameRate    = pComponentPrivate->nTargetFrameRate;
   2660     pUalgInpParams->ulTargetBitRate      = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig->nEncodeBitrate;
   2661     pUalgInpParams->ulGenerateHeader     = 0;
   2662     pUalgInpParams->ulForceIFrame        = pComponentPrivate->bForceIFrame;
   2663     pUalgInpParams->ulResyncInterval     = pCompPortOut->pErrorCorrectionType->nResynchMarkerSpacing;
   2664     if(pCompPortOut->pErrorCorrectionType->bEnableHEC)
   2665         pUalgInpParams->ulHecInterval    = 3;
   2666     else
   2667     pUalgInpParams->ulHecInterval        = 0;
   2668     pUalgInpParams->ulAIRRate            = pCompPortOut->pIntraRefreshType->nAirRef;
   2669     pUalgInpParams->ulMIRRate            = pComponentPrivate->nMIRRate;
   2670     pUalgInpParams->ulfCode              = 5;
   2671     pUalgInpParams->ulHalfPel            = 1;
   2672     pUalgInpParams->ul4MV                = 0;
   2673     pUalgInpParams->ulIntraFrameInterval = pComponentPrivate->nIntraFrameInterval;
   2674 
   2675     /*Set nQPI Value*/
   2676     if (pUalgInpParams->ulForceIFrame == OMX_TRUE)
   2677     {
   2678         pUalgInpParams->ulQPIntra = pComponentPrivate->nQPI;
   2679     }
   2680     else
   2681     {
   2682         pUalgInpParams->ulQPIntra    = 0;
   2683     }
   2684 
   2685     /*Set segment mode params*/
   2686     if (pComponentPrivate->bMVDataEnable)
   2687     {
   2688         pUalgInpParams->ul4MV                 =1;
   2689         pUalgInpParams->uluseUMV              =1;
   2690         pUalgInpParams->ulMVDataEnable        =1;
   2691     }
   2692     else
   2693     {
   2694         pUalgInpParams->ul4MV                 =0;
   2695         pUalgInpParams->uluseUMV              =0;
   2696         pUalgInpParams->ulMVDataEnable        =0;
   2697     }
   2698     if (pComponentPrivate->bResyncDataEnable)
   2699         pUalgInpParams->ulResyncDataEnable    =1;
   2700     else
   2701         pUalgInpParams->ulResyncDataEnable    =0;
   2702     /* Reset bForceMPEG4IFrame to zero */
   2703     pComponentPrivate->bForceIFrame = OMX_FALSE;
   2704 
   2705     /*Set ulACPred Value*/
   2706     if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
   2707     {
   2708         pUalgInpParams->ulACPred         = pComponentPrivate->pMpeg4->bACPred;
   2709     }
   2710     else
   2711     {
   2712         pUalgInpParams->ulACPred        = 0;
   2713     }
   2714     pUalgInpParams->ulQPInter           = 8;
   2715     pUalgInpParams->ulLastFrame         = 0;
   2716     pUalgInpParams->ulcapturewidth      = 0;
   2717     pUalgInpParams->ulQpMax             = 31;
   2718     pUalgInpParams->ulQpMin             = 2;
   2719     ++pComponentPrivate->nFrameCnt;
   2720 
   2721     if(pComponentPrivate->bRequestVOLHeader == OMX_TRUE)
   2722     {
   2723         /*In the case of Mpeg4 we have to send an extra Buffer to LCML requesting for VOL Header*/
   2724         memcpy(pComponentPrivate->pTempUalgInpParams,pUalgInpParams,sizeof(MP4VE_GPP_SN_UALGInputParams));
   2725         pComponentPrivate->pTempUalgInpParams->ulGenerateHeader = 1;
   2726         pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_DSP;
   2727         eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
   2728                                   EMMCodecInputBuffer,
   2729                                   pComponentPrivate->pTempUalgInpParams,/*send any buffer*/
   2730                                   1,
   2731                                   0,
   2732                                   pComponentPrivate->pTempUalgInpParams,
   2733                                   sizeof(MP4VE_GPP_SN_UALGInputParams),
   2734                                   (OMX_U8*)pBufHead);
   2735         if (eError != OMX_ErrorNone)
   2736         {
   2737             OMX_PRDSP2(pComponentPrivate->dbg, "LCML QueueBuffer failed: %x\n", eError);
   2738         }
   2739         pComponentPrivate->bRequestVOLHeader = OMX_FALSE;
   2740     }
   2741 
   2742     OMX_PRDSP1(pComponentPrivate->dbg,
   2743                "TargetFrameRate -> %d\n\
   2744                TargetBitRate   -> %d\n\
   2745                QPI             -> %d\n", pComponentPrivate->nTargetFrameRate,
   2746                (int)pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig->nEncodeBitrate,
   2747                pComponentPrivate->nQPI);
   2748 
   2749     printMpeg4UAlgInParam(pUalgInpParams, 0, &pComponentPrivate->dbg);
   2750     OMX_CONF_CIRCULAR_BUFFER_MOVE_TAIL(pBufHead,
   2751                                            pComponentPrivate->sCircularBuffer,
   2752                                            pComponentPrivate);
   2753 
   2754         /*Send Buffer to LCML*/
   2755         OMX_PRBUFFER1(pComponentPrivate->dbg, " %p\n", (void*)pBufHead);
   2756         pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_DSP;
   2757         eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
   2758                                   EMMCodecInputBuffer,
   2759                                   pBufHead->pBuffer,
   2760                                   pBufHead->nAllocLen,
   2761                                   pBufHead->nFilledLen,
   2762                                   (OMX_U8*)pUalgInpParams,
   2763                                   sizeof(MP4VE_GPP_SN_UALGInputParams),
   2764                                   (OMX_U8*)pBufHead);
   2765     if (eError != OMX_ErrorNone)
   2766     {
   2767         OMX_PRDSP4(pComponentPrivate->dbg, "LCML QueueBuffer failed: %x\n", eError);
   2768     }
   2769 
   2770 OMX_CONF_CMD_BAIL:
   2771 
   2772     return eError;
   2773 }
   2774 
   2775 
   2776 /*---------------------------------------------------------------------------------------*/
   2777 /**
   2778   * OMX_VIDENC_Process_FilledOutBuf()
   2779   *
   2780   * Called by component thread, handles filled output buffers from DSP.
   2781   *
   2782   * @param pComponentPrivate private component structure for this instance of the component
   2783   *
   2784   * @retval OMX_ErrorNone                  success, ready to roll
   2785   *         OMX_ErrorInsufficientResources if the malloc fails
   2786   **/
   2787 /*---------------------------------------------------------------------------------------*/
   2788 
   2789 OMX_ERRORTYPE OMX_VIDENC_Process_FilledOutBuf(VIDENC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BUFFERHEADERTYPE* pBufHead)
   2790 {
   2791     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2792     VIDENC_BUFFER_PRIVATE* pBufferPrivate = NULL;
   2793     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   2794     OMX_OTHER_EXTRADATATYPE_1_1_2* pExtraDataType;
   2795     H264VE_GPP_SN_UALGOutputParams* pSNPrivateParams;
   2796     OMX_U8* pTemp;
   2797     OMX_U32* pIndexNal;
   2798 
   2799     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   2800 
   2801     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
   2802 
   2803    if (pComponentPrivate->bCodecStarted == OMX_TRUE)
   2804     {
   2805 
   2806         pBufferPrivate = pBufHead->pOutputPortPrivate;
   2807         pSNPrivateParams = (H264VE_GPP_SN_UALGOutputParams*)(pBufferPrivate->pUalgParam);
   2808         pBufHead->nFilledLen = ((H264VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->ulBitstreamSize;
   2809 
   2810         if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
   2811         {
   2812         /*Copy Buffer Data to be propagated*/
   2813         if((pComponentPrivate->AVCNALFormat == VIDENC_AVC_NAL_SLICE) &&
   2814                 (pSNPrivateParams->ulNALUnitsPerFrame != (pSNPrivateParams->ulNALUnitIndex+1)) &&
   2815                 (pSNPrivateParams->ulNALUnitsPerFrame != 0))
   2816         {
   2817 
   2818             pBufHead->pMarkData = NULL;
   2819             pBufHead->hMarkTargetComponent = NULL;
   2820             pBufHead->nTickCount = pComponentPrivate->sCircularBuffer.pHead->nTickCount;
   2821             pBufHead->nTimeStamp = pComponentPrivate->sCircularBuffer.pHead->nTimeStamp;
   2822             pBufHead->nFlags = 0;
   2823         }
   2824             else
   2825             {
   2826                 OMX_CONF_CIRCULAR_BUFFER_MOVE_HEAD(pBufHead, pComponentPrivate->sCircularBuffer,
   2827                                                    pComponentPrivate);
   2828             pBufHead->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
   2829         }
   2830 
   2831             /* Set lFrameType*/
   2832             if (((H264VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->lFrameType == OMX_LFRAMETYPE_H264 ||
   2833                  ((H264VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->lFrameType == OMX_LFRAMETYPE_IDR_H264)
   2834             {
   2835                 /* IDR Frame */
   2836                 OMX_S32 nalType = pBufHead->pBuffer[0] & 0x1F;
   2837                 if (nalType == SPS_CODE_PREFIX || nalType == PPS_CODE_PREFIX) {
   2838                     /* Need to drop subsequent SPS or PPS NAL unit since opencore does not
   2839                      * correctly handle storage */
   2840                     if (!pComponentPrivate->bSentFirstSpsPps) {
   2841                         /* we can assume here that PPS always comes second */
   2842                         if (nalType == PPS_CODE_PREFIX)
   2843                             pComponentPrivate->bSentFirstSpsPps = OMX_TRUE;
   2844                     } else {
   2845                         pBufHead->nFilledLen = 0;
   2846                     }
   2847                 }
   2848 
   2849                 pBufHead->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;
   2850             }
   2851 
   2852             /* if NAL frame mode */
   2853             if (pComponentPrivate->AVCNALFormat == VIDENC_AVC_NAL_FRAME)
   2854             {
   2855 
   2856                 /*H264VE_GPP_SN_UALGOutputParams* pSNPrivateParams;*/
   2857                 int nNalSlices;
   2858 
   2859                 pBufHead->nFlags |= OMX_BUFFERFLAG_EXTRADATA;
   2860 
   2861                 pTemp = pBufHead->pBuffer + pBufHead->nOffset + pBufHead->nFilledLen + 3;
   2862                 pExtraDataType = (OMX_OTHER_EXTRADATATYPE_1_1_2*) (((OMX_U32) pTemp) & ~3);
   2863                 pIndexNal = (OMX_U32*)(pExtraDataType->data);
   2864                 /*pSNPrivateParams = (H264VE_GPP_SN_UALGOutputParams*)(pBufferPrivate->pUalgParam);*/
   2865 
   2866                 pExtraDataType->nVersion.s.nVersionMajor = 1;
   2867                 pExtraDataType->nVersion.s.nVersionMinor = 1;
   2868                 pExtraDataType->nVersion.s.nRevision = 2;
   2869                 pExtraDataType->nPortIndex = VIDENC_OUTPUT_PORT;
   2870                 pExtraDataType->eType = OMX_ExtraDataQuantization;
   2871                 pExtraDataType->nDataSize = (1+pSNPrivateParams->ulNALUnitsPerFrame)*sizeof(OMX_U32);
   2872 
   2873                 *pIndexNal = pSNPrivateParams->ulNALUnitsPerFrame;
   2874                 pIndexNal++;
   2875                 for (nNalSlices = 0; (OMX_U32)nNalSlices < pSNPrivateParams->ulNALUnitsPerFrame; nNalSlices++, pIndexNal++)
   2876                 {
   2877 
   2878                     *pIndexNal = (OMX_U32)(pSNPrivateParams->ulNALUnitsSizes[nNalSlices]);
   2879                 }
   2880 
   2881                 pTemp = (OMX_U8*)((((OMX_U32)pIndexNal)+3) & ~3);
   2882                 pExtraDataType->nSize = (OMX_U32)pTemp-(OMX_U32)pExtraDataType;
   2883 
   2884                 pExtraDataType = (OMX_OTHER_EXTRADATATYPE_1_1_2*) pTemp;
   2885                 pExtraDataType->nSize = (sizeof(OMX_OTHER_EXTRADATATYPE_1_1_2)+3) & ~3;
   2886                 pExtraDataType->nVersion.s.nVersionMajor = 1;
   2887                 pExtraDataType->nVersion.s.nVersionMinor = 1;
   2888                 pExtraDataType->nVersion.s.nRevision = 2;
   2889                 pExtraDataType->nPortIndex = VIDENC_OUTPUT_PORT;
   2890                 pExtraDataType->eType = OMX_ExtraDataNone;
   2891                 pExtraDataType->nDataSize = 0;
   2892             }
   2893         }
   2894         else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   2895                  pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
   2896         {
   2897             /*We ignore the first Mpeg4 buffer which contains VOL Header since we did not add it to the circular list*/
   2898             if(pComponentPrivate->bWaitingForVOLHeaderBuffer == OMX_FALSE)
   2899             {
   2900                 OMX_CONF_CIRCULAR_BUFFER_MOVE_HEAD(pBufHead, pComponentPrivate->sCircularBuffer,
   2901                                                    pComponentPrivate);
   2902             }
   2903             else
   2904             {
   2905                 pComponentPrivate->bWaitingForVOLHeaderBuffer = OMX_FALSE;
   2906             }
   2907 
   2908             pBufHead->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
   2909 
   2910             /* Set cFrameType*/
   2911             if (((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->cFrameType == OMX_CFRAMETYPE_MPEG4)
   2912             {
   2913                 /* I-VOP Frame */
   2914                 pBufHead->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;
   2915             }
   2916             VIDENC_MPEG4_SEGMENTMODE_METADATA* pMetaData;
   2917             /*copy MPEG4 segment mode meta data */
   2918             pMetaData=(VIDENC_MPEG4_SEGMENTMODE_METADATA*)pBufferPrivate->pMetaData;
   2919             if (pComponentPrivate->bMVDataEnable==OMX_TRUE)
   2920             {
   2921                pMetaData->mvDataSize=((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->mvDataSize;
   2922                pMetaData->pMVData=((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->MVData;
   2923             }
   2924             if (pComponentPrivate->bResyncDataEnable==OMX_TRUE)
   2925             {
   2926                pMetaData->pResyncData=((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->ResyncData;
   2927                pMetaData->numPackets=((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->numPackets;
   2928             }
   2929         }
   2930         else
   2931         {
   2932             OMX_PRBUFFER4(pComponentPrivate->dbg, "Unsupported compression format (%d)\n",
   2933                           pPortDefOut->format.video.eCompressionFormat);
   2934             OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
   2935         }
   2936 
   2937         if (pBufHead->nFlags & OMX_BUFFERFLAG_EOS)
   2938         {
   2939             /* trigger event handler */
   2940             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,  OMX_EventBufferFlag, 0x1, pBufHead->nFlags, NULL);
   2941             /* clear flag */
   2942             pComponentPrivate->nFlags = 0;
   2943         }
   2944 
   2945         if (pBufHead->pMarkData != NULL)
   2946         {
   2947             /* trigger event handler if we are supposed to */
   2948             if (pBufHead->hMarkTargetComponent == pComponentPrivate->pHandle &&
   2949                 pBufHead->pMarkData)
   2950             {
   2951                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,  OMX_EventMark, 0x0, 0x0,
   2952                                         pBufHead->pMarkData);
   2953             }
   2954         }
   2955         pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_CLIENT;
   2956 #ifdef __PERF_INSTRUMENTATION__
   2957         PERF_SendingBuffer(pComponentPrivate->pPERFcomp,
   2958                            pBufHead->pBuffer,
   2959                            pBufHead->nFilledLen,
   2960                            PERF_ModuleHLMM);
   2961 #endif
   2962         pComponentPrivate->sCbData.FillBufferDone(pComponentPrivate->pHandle,
   2963                                                   pComponentPrivate->pHandle->pApplicationPrivate,
   2964                                                   pBufHead);
   2965         OMX_VIDENC_IncrementBufferCountByOne(&pComponentPrivate->FillbufferdoneCount);
   2966         OMX_VIDENC_SignalIfAllBuffersAreReturned(pComponentPrivate);
   2967     }
   2968 OMX_CONF_CMD_BAIL:
   2969     return eError;
   2970 }
   2971 
   2972 /*---------------------------------------------------------------------------------------*/
   2973 /**
   2974   * OMX_VIDENC_Process_FreeInBuf()
   2975   *
   2976   * Called by component thread, handles free input buffers from DSP.
   2977   *
   2978   * @param pComponentPrivate private component structure for this instance of the component
   2979   *
   2980   * @retval OMX_ErrorNone                  success, ready to roll
   2981   *         OMX_ErrorInsufficientResources if the malloc fails
   2982   **/
   2983 /*---------------------------------------------------------------------------------------*/
   2984 
   2985 OMX_ERRORTYPE OMX_VIDENC_Process_FreeInBuf(VIDENC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BUFFERHEADERTYPE* pBufHead)
   2986 {
   2987     VIDENC_NODE* pMemoryListHead = NULL;
   2988     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2989     OMX_HANDLETYPE hTunnelComponent = NULL;
   2990     VIDENC_BUFFER_PRIVATE* pBufferPrivate = NULL;
   2991 
   2992     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   2993 
   2994     hTunnelComponent = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->hTunnelComponent;
   2995     pMemoryListHead = pComponentPrivate->pMemoryListHead;
   2996 
   2997     /*pBufHead is checked for NULL*/
   2998     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pBufHead, 1, 1);
   2999     pBufferPrivate = pBufHead->pInputPortPrivate;
   3000 
   3001     if (hTunnelComponent != NULL)
   3002     {
   3003         pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_TUNNELEDCOMP;
   3004 #ifdef __PERF_INSTRUMENTATION__
   3005         PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   3006                           PREF(pBufHead,pBuffer),
   3007                           pBufHead->nFilledLen,
   3008                           PERF_ModuleLLMM);
   3009 #endif
   3010 
   3011         eError = OMX_FillThisBuffer(hTunnelComponent, pBufHead);
   3012         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg,
   3013                               OMX_PRBUFFER4, "FillThisBuffer failed (%x)", eError);
   3014     }
   3015     else
   3016     {
   3017         pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_CLIENT;
   3018 #ifdef __PERF_INSTRUMENTATION__
   3019         PERF_SendingFrame(pComponentPrivate->pPERFcomp,
   3020                           PREF(pBufHead,pBuffer),
   3021                           0,
   3022                           PERF_ModuleHLMM);
   3023 #endif
   3024         pComponentPrivate->sCbData.EmptyBufferDone(pComponentPrivate->pHandle,
   3025                                                    pComponentPrivate->pHandle->pApplicationPrivate,
   3026                                                    pBufHead);
   3027         OMX_VIDENC_IncrementBufferCountByOne(&pComponentPrivate->EmptybufferdoneCount);
   3028         OMX_VIDENC_SignalIfAllBuffersAreReturned(pComponentPrivate);
   3029    }
   3030 
   3031 OMX_CONF_CMD_BAIL:
   3032     return eError;
   3033 }
   3034 /*---------------------------------------------------------------------------------------*/
   3035 /**
   3036   *  Function to initialize LCML
   3037   *
   3038   *
   3039   *
   3040   * @retval OMX_NoError              Success, ready to roll
   3041   *
   3042   **/
   3043 /*---------------------------------------------------------------------------------------*/
   3044 
   3045 OMX_ERRORTYPE OMX_VIDENC_InitLCML(VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
   3046 {
   3047     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3048     OMX_HANDLETYPE hLCML = NULL;
   3049     VIDENC_NODE* pMemoryListHead = NULL;
   3050 #ifdef UNDER_CE
   3051     typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE);
   3052     LPFNDLLFUNC1 fpGetHandle1;
   3053 #else
   3054     void* pMyLCML = NULL;
   3055     fpo   fpGetHandle = NULL;
   3056     char* error = NULL;
   3057 #endif
   3058 
   3059     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   3060 
   3061 #ifndef UNDER_CE
   3062     pMyLCML = dlopen("libLCML.so", RTLD_LAZY);
   3063     pComponentPrivate->pModLcml = pMyLCML;
   3064     if (!pMyLCML)
   3065     {
   3066         OMX_ERROR5(pComponentPrivate->dbg, "Could not open LCML library\n");
   3067         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined);
   3068     }
   3069 
   3070     fpGetHandle = dlsym(pMyLCML, "GetHandle");
   3071     if ((error = dlerror()) != NULL)
   3072     {
   3073         OMX_ERROR4(pComponentPrivate->dbg, "No GetHandle in LCML library\n");
   3074         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined);
   3075     }
   3076 
   3077     eError = (*fpGetHandle)(&hLCML);
   3078     if (eError != OMX_ErrorNone)
   3079     {
   3080         OMX_ERROR5(pComponentPrivate->dbg, "Error While Getting LCML Handle (%x)...\n", eError);
   3081        OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined);
   3082     }
   3083 
   3084     pComponentPrivate->pLCML = (LCML_DSP_INTERFACE*)hLCML;
   3085     pMemoryListHead = pComponentPrivate->pMemoryListHead;
   3086     pComponentPrivate->pLCML->pComponentPrivate = (VIDENC_COMPONENT_PRIVATE *)pComponentPrivate;
   3087 
   3088 #else
   3089     g_hLcmlDllHandle = LoadLibraryEx(TEXT("oaf_bml.dll"), NULL, 0);
   3090     if (g_hLcmlDllHandle == NULL)
   3091     {
   3092         OMX_ERROR5(pComponentPrivate->dbg, "BML Load Failed!!!, %d\n", GetLastError());
   3093         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined);
   3094     }
   3095     fpGetHandle1 = (LPFNDLLFUNC1)GetProcAddress(g_hLcmlDllHandle,TEXT("GetHandle"));
   3096     if (!fpGetHandle1)
   3097     {
   3098         FreeLibrary(g_hLcmlDllHandle);
   3099         g_hLcmlDllHandle = NULL;
   3100         OMX_ERROR4(pComponentPrivate->dbg, "No GetHandle in BML\n");
   3101         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined);
   3102     }
   3103     eError = fpGetHandle1(&hLCML);
   3104     if (eError != OMX_ErrorNone)
   3105     {
   3106         FreeLibrary(g_hLcmlDllHandle);
   3107         g_hLcmlDllHandle = NULL;
   3108         OMX_ERROR5(pComponentPrivate->dbg, "Error While Getting LCML Handle (%x)...\n", eError);
   3109         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined);
   3110     }
   3111     (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML = (LCML_DSP_INTERFACE*)hLCML;
   3112     pComponentPrivate->pLCML->pComponentPrivate = (VIDENC_COMPONENT_PRIVATE *)pComponentPrivate;
   3113 #endif
   3114 OMX_CONF_CMD_BAIL:
   3115     return eError;
   3116 }
   3117 
   3118 /*---------------------------------------------------------------------------------------*/
   3119 /**
   3120   *  Function to fill DSP structures via LCML
   3121   *
   3122   *
   3123   *
   3124   * @retval OMX_NoError              Success, ready to roll
   3125   *
   3126   **/
   3127 /*---------------------------------------------------------------------------------------*/
   3128 
   3129 OMX_ERRORTYPE OMX_VIDENC_InitDSP_H264Enc(VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
   3130 {
   3131     OMX_U16 nArr[100];
   3132     OMX_U32* pTmp = NULL;
   3133     LCML_CALLBACKTYPE sCb;
   3134     LCML_DSP* pLcmlDSP = NULL;
   3135     VIDENC_NODE* pMemoryListHead = NULL;
   3136     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3137     OMX_VIDEO_PARAM_AVCTYPE* pH264 = NULL;
   3138     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
   3139     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
   3140     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   3141     OMX_VIDEO_PARAM_BITRATETYPE* pVidParamBitrate = NULL;
   3142     OMX_VIDEO_PARAM_QUANTIZATIONTYPE* pQuantization = NULL;
   3143     H264VE_GPP_SN_Obj_CreatePhase* pCreatePhaseArgs = NULL;
   3144     /* OMX_VIDEO_CONFIG_AVCINTRAPERIOD* pH264IntraPeriod = NULL; */
   3145     OMX_VIDEO_PARAM_MOTIONVECTORTYPE* pMotionVector = NULL;
   3146     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   3147 
   3148     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
   3149     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
   3150     pH264 = pComponentPrivate->pH264;
   3151     pVidParamBitrate = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateType;
   3152     pQuantization = pComponentPrivate->pQuantization;
   3153     pMemoryListHead = pComponentPrivate->pMemoryListHead;
   3154     /* pH264IntraPeriod = pComponentPrivate->pH264IntraPeriod; */
   3155     pMotionVector = pComponentPrivate->pMotionVector;
   3156     pComponentPrivate->bErrorLcmlHandle = OMX_FALSE;
   3157 
   3158     pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   3159     pLcmlDSP = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
   3160     pLcmlDSP = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
   3161 
   3162     pLcmlDSP->In_BufInfo.nBuffers           = pPortDefIn->nBufferCountActual;
   3163     pLcmlDSP->In_BufInfo.nSize              = pComponentPrivate->nInBufferSize;
   3164     pLcmlDSP->In_BufInfo.DataTrMethod       = DMM_METHOD;
   3165 
   3166     pLcmlDSP->Out_BufInfo.nBuffers          = pPortDefOut->nBufferCountActual;
   3167     pLcmlDSP->Out_BufInfo.nSize             = pComponentPrivate->nOutBufferSize;
   3168     pLcmlDSP->Out_BufInfo.DataTrMethod      = DMM_METHOD;
   3169 
   3170     pLcmlDSP->NodeInfo.nNumOfDLLs           = OMX_H264ENC_NUM_DLLS;
   3171     pLcmlDSP->NodeInfo.AllUUIDs[0].uuid     = &H264VESOCKET_TI_UUID;
   3172     strcpy ((char *)pLcmlDSP->NodeInfo.AllUUIDs[0].DllName,H264_ENC_NODE_DLL);
   3173     pLcmlDSP->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT;
   3174 
   3175     pLcmlDSP->NodeInfo.AllUUIDs[1].uuid     = &H264VESOCKET_TI_UUID;
   3176     strcpy ((char *)pLcmlDSP->NodeInfo.AllUUIDs[1].DllName,H264_ENC_NODE_DLL);
   3177     pLcmlDSP->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT;
   3178 
   3179     pLcmlDSP->NodeInfo.AllUUIDs[2].uuid     = &USN_UUID;
   3180     strcpy ((char *)pLcmlDSP->NodeInfo.AllUUIDs[2].DllName,USN_DLL);
   3181     pLcmlDSP->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT;
   3182 
   3183     pLcmlDSP->SegID                         = 0;
   3184     pLcmlDSP->Timeout                       = -1;
   3185     pLcmlDSP->Alignment                     = 0;
   3186     pLcmlDSP->Priority                      = 5;
   3187 
   3188     #ifdef GPP_PRIVATE_NODE_HEAP
   3189         if ((pPortDefIn->format.video.nFrameWidth <= 176) &&
   3190             (pPortDefIn->format.video.nFrameHeight <= 144))
   3191         {
   3192             pLcmlDSP->ProfileID = 0;
   3193         }
   3194         else if ((pPortDefIn->format.video.nFrameWidth <= 352) &&
   3195                  (pPortDefIn->format.video.nFrameHeight <= 288))
   3196         {
   3197             pLcmlDSP->ProfileID = 1;
   3198         }
   3199         else
   3200         {
   3201             pLcmlDSP->ProfileID = 2;
   3202         }
   3203     #else
   3204         pLcmlDSP->ProfileID = 0xff; /* Use DSP node heap */
   3205     #endif
   3206 
   3207     /* pLcmlDSP->buffindx                      = 999; */
   3208 
   3209     VIDENC_MALLOC(pCreatePhaseArgs,
   3210                   sizeof(H264VE_GPP_SN_Obj_CreatePhase),
   3211                   H264VE_GPP_SN_Obj_CreatePhase,
   3212                   pMemoryListHead,
   3213                   pComponentPrivate->dbg);
   3214 
   3215     pCreatePhaseArgs->usNumStreams            = 2;
   3216     pCreatePhaseArgs->usStreamId              = VIDENC_INPUT_PORT;
   3217     pCreatePhaseArgs->usBuffTypeInStream      = 0;
   3218     pCreatePhaseArgs->usMaxBuffsInStream      = (OMX_U16)pPortDefIn->nBufferCountActual;
   3219     pCreatePhaseArgs->usStreamId2             = VIDENC_OUTPUT_PORT;
   3220     pCreatePhaseArgs->usBuffTypeInStream2     = 0;
   3221     pCreatePhaseArgs->usMaxBuffsInStream2     = (OMX_U16)pPortDefOut->nBufferCountActual;
   3222 
   3223     pCreatePhaseArgs->ulWidth                 = pPortDefIn->format.video.nFrameWidth;
   3224     pCreatePhaseArgs->ulHeight                = pPortDefIn->format.video.nFrameHeight;
   3225     pCreatePhaseArgs->ulTargetBitRate         = pPortDefOut->format.video.nBitrate;
   3226     pCreatePhaseArgs->ulBitstreamBuffSize     = pComponentPrivate->nOutBufferSize;
   3227     pCreatePhaseArgs->ulFrameRate             = (unsigned int)(Q16Tof(pPortDefIn->format.video.xFramerate)*1000.0);
   3228 
   3229     /* set run-time frame and bit rates to create-time values */
   3230     pComponentPrivate->nTargetFrameRate       = pCreatePhaseArgs->ulFrameRate;
   3231     pComponentPrivate->nPrevTargetFrameRate   = 0;
   3232     pComponentPrivate->bSentFirstSpsPps       = OMX_FALSE;
   3233 
   3234     if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar)
   3235     {
   3236         pCreatePhaseArgs->ucYUVFormat         = 0;
   3237     }
   3238     else if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatCbYCrY) /*422 LE UYVY*/
   3239     {
   3240         pCreatePhaseArgs->ucYUVFormat         = 2;
   3241     }
   3242     else if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatYCbYCr) /*422 BE YUYV */
   3243     {
   3244         pCreatePhaseArgs->ucYUVFormat         = 1;
   3245     }
   3246     else
   3247     {
   3248         OMX_PRDSP2(pComponentPrivate->dbg, "Unsupported YUV format.\n");
   3249         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
   3250     }
   3251 
   3252     pCreatePhaseArgs->ucUnrestrictedMV        = pComponentPrivate->ucUnrestrictedMV;
   3253     pCreatePhaseArgs->ucNumRefFrames          = 1;
   3254 
   3255     if (pVidParamBitrate->eControlRate == OMX_Video_ControlRateVariable)
   3256     {
   3257         pCreatePhaseArgs->ucRateControlAlgorithm  = 0;
   3258     }
   3259     else if (pVidParamBitrate->eControlRate == OMX_Video_ControlRateConstant)
   3260     {
   3261         pCreatePhaseArgs->ucRateControlAlgorithm  = 1;
   3262     }
   3263     else if (pVidParamBitrate->eControlRate == OMX_Video_ControlRateDisable)
   3264     {
   3265         pCreatePhaseArgs->ucRateControlAlgorithm  = 2;
   3266     }
   3267     else
   3268     {
   3269         OMX_PRDSP2(pComponentPrivate->dbg, "Unsupported rate control algorithm.\n");
   3270         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
   3271     }
   3272 
   3273     pCreatePhaseArgs->ucIDREnable             = 1;
   3274 
   3275     if (pComponentPrivate->bDeblockFilter == OMX_FALSE)
   3276     {
   3277         pCreatePhaseArgs->ucDeblockingEnable  = 0;
   3278     }
   3279     else if (pComponentPrivate->bDeblockFilter == OMX_TRUE)
   3280     {
   3281         pCreatePhaseArgs->ucDeblockingEnable  = 1;
   3282     }
   3283     else
   3284     {
   3285         OMX_PRDSP2(pComponentPrivate->dbg, "Unsupported deblocking setting.\n");
   3286         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter);
   3287     }
   3288 
   3289     pCreatePhaseArgs->ucMVRange               = (pMotionVector->sXSearchRange > pMotionVector->sYSearchRange ? pMotionVector->sXSearchRange : pMotionVector->sYSearchRange);
   3290     pCreatePhaseArgs->ucQPIFrame              = 28;
   3291     pCreatePhaseArgs->ucProfile               = 66;
   3292     pCreatePhaseArgs->ulIntraFramePeriod      = pCreatePhaseArgs->ulFrameRate > 15000 ? 29 : 14;
   3293 
   3294     if (pH264->eLevel == OMX_VIDEO_AVCLevel1b)
   3295     {
   3296         pCreatePhaseArgs->ucLevel = 9;
   3297     }
   3298     else if (pH264->eLevel == OMX_VIDEO_AVCLevel1)
   3299     {
   3300         pCreatePhaseArgs->ucLevel = 10;
   3301     }
   3302     else if (pH264->eLevel == OMX_VIDEO_AVCLevel11)
   3303     {
   3304         pCreatePhaseArgs->ucLevel = 11;
   3305     }
   3306     else if (pH264->eLevel == OMX_VIDEO_AVCLevel12)
   3307     {
   3308         pCreatePhaseArgs->ucLevel = 12;
   3309     }
   3310     else if (pH264->eLevel == OMX_VIDEO_AVCLevel13)
   3311     {
   3312         pCreatePhaseArgs->ucLevel = 13;
   3313     }
   3314     else if (pH264->eLevel == OMX_VIDEO_AVCLevel2)
   3315     {
   3316         pCreatePhaseArgs->ucLevel = 20;
   3317     }
   3318     else if (pH264->eLevel == OMX_VIDEO_AVCLevel21)
   3319     {
   3320         pCreatePhaseArgs->ucLevel = 21;
   3321     }
   3322     else if (pH264->eLevel == OMX_VIDEO_AVCLevel22)
   3323     {
   3324         pCreatePhaseArgs->ucLevel = 22;
   3325     }
   3326     else if (pH264->eLevel == OMX_VIDEO_AVCLevel3)
   3327     {
   3328         pCreatePhaseArgs->ucLevel = 30;
   3329         if ((pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar) &&
   3330             (pPortDefIn->format.video.nFrameWidth == 320) &&
   3331             (pPortDefIn->format.video.nFrameHeight == 240))
   3332         {
   3333             pCreatePhaseArgs->ucQPIFrame = 0;
   3334         }
   3335     }
   3336     else
   3337     {
   3338         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting,
   3339                                pComponentPrivate->dbg, OMX_PRDSP2,
   3340                                "Unsupported level.\n");
   3341     }
   3342 
   3343     /* override parameters for VGA & D1 encoding */
   3344     if ((pPortDefIn->format.video.nFrameWidth >= 640 ||
   3345         pPortDefIn->format.video.nFrameHeight >= 480) &&
   3346         pCreatePhaseArgs->ulFrameRate > 15000)
   3347     {
   3348         pComponentPrivate->maxMVperMB = 1;
   3349         pComponentPrivate->intra4x4EnableIdc = INTRA4x4_ISLICES;
   3350         pComponentPrivate->nIntraFrameInterval = 30;
   3351         pComponentPrivate->nAIRRate = 0;
   3352         /* Encoding preset = 4 enables DSP side optimizations for high resolutions */
   3353         pComponentPrivate->nEncodingPreset = 4;
   3354         pCreatePhaseArgs->ulIntraFramePeriod = 0;
   3355         /* Constant bit rate control enabled */
   3356         pCreatePhaseArgs->ucRateControlAlgorithm = 1;
   3357         pCreatePhaseArgs->ucLevel = 30;
   3358     }
   3359     /* Ensure frame rate update interval, which forces IDR frames, is same as I-Slice interval */
   3360     pComponentPrivate->nFrameRateUpdateInterval = pComponentPrivate->nIntraFrameInterval;
   3361     pCreatePhaseArgs->usNalCallback = pComponentPrivate->AVCNALFormat;
   3362     pCreatePhaseArgs->ulEncodingPreset = pComponentPrivate->nEncodingPreset;
   3363     pCreatePhaseArgs->ulRcAlgo = 0;
   3364     pCreatePhaseArgs->endArgs = END_OF_CR_PHASE_ARGS;
   3365     printH264CreateParams(pCreatePhaseArgs, &pComponentPrivate->dbg);
   3366 
   3367     pTmp = memcpy (nArr, pCreatePhaseArgs, sizeof(H264VE_GPP_SN_Obj_CreatePhase));
   3368     if (pTmp == NULL)
   3369     {
   3370         OMX_TRACE4(pComponentPrivate->dbg, "memcpy() out of memory error.\n");
   3371         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
   3372     }
   3373     pLcmlDSP->pCrPhArgs = nArr;
   3374     sCb.LCML_Callback = (void *)OMX_VIDENC_LCML_Callback;
   3375 
   3376     eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   3377                               NULL,
   3378                               &pLcmlHandle,
   3379                               NULL,
   3380                               &sCb);
   3381     if (eError != OMX_ErrorNone)
   3382     {
   3383         OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...\n");
   3384         /*TODO: Validate eError from LCML_InitMMCodec for ResourceExhaustionTest */
   3385         pComponentPrivate->bErrorLcmlHandle = OMX_TRUE;
   3386         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
   3387     }
   3388     pComponentPrivate->bCodecLoaded = OMX_TRUE;
   3389     VIDENC_FREE(pCreatePhaseArgs, pMemoryListHead,
   3390                 pComponentPrivate->dbg);
   3391 OMX_CONF_CMD_BAIL:
   3392     return eError;
   3393 }
   3394 
   3395 /*---------------------------------------------------------------------------------------*/
   3396 /**
   3397   *  Function to fill DSP structures via LCML
   3398   *
   3399   *
   3400   *
   3401   * @retval OMX_NoError              Success, ready to roll
   3402   *
   3403   **/
   3404 /*---------------------------------------------------------------------------------------*/
   3405 
   3406 OMX_ERRORTYPE OMX_VIDENC_InitDSP_Mpeg4Enc(VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
   3407 {
   3408     OMX_U16 nArr[100];
   3409     OMX_U32* pTmp = NULL;
   3410     LCML_CALLBACKTYPE sCb;
   3411     LCML_DSP* pLcmlDSP = NULL;
   3412     VIDENC_NODE* pMemoryListHead = NULL;
   3413     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3414     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
   3415     OMX_VIDEO_PARAM_H263TYPE* pH263 = NULL;
   3416     OMX_VIDEO_PARAM_MPEG4TYPE* pMpeg4 = NULL;
   3417     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
   3418     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   3419     MP4VE_GPP_SN_Obj_CreatePhase* pCreatePhaseArgs = NULL;
   3420     OMX_VIDEO_PARAM_BITRATETYPE* pVidParamBitrate = NULL;
   3421     OMX_VIDEO_PARAM_QUANTIZATIONTYPE* pQuantization = NULL;
   3422     VIDEOENC_PORT_TYPE* pCompPortOut            = NULL;
   3423 
   3424     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   3425 
   3426     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
   3427     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
   3428     pCompPortOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
   3429     pVidParamBitrate = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateType;
   3430     pQuantization = pComponentPrivate->pQuantization;
   3431     pH263 = pComponentPrivate->pH263;
   3432     pMpeg4 = pComponentPrivate->pMpeg4;
   3433     pMemoryListHead = pComponentPrivate->pMemoryListHead;
   3434 
   3435     pComponentPrivate->bErrorLcmlHandle = OMX_FALSE;
   3436 
   3437     pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
   3438     pLcmlDSP    = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
   3439 
   3440     pLcmlDSP->In_BufInfo.nBuffers           = pPortDefIn->nBufferCountActual;
   3441     pLcmlDSP->In_BufInfo.nSize              = pComponentPrivate->nInBufferSize;
   3442     pLcmlDSP->In_BufInfo.DataTrMethod       = DMM_METHOD;
   3443 
   3444     pLcmlDSP->Out_BufInfo.nBuffers          = pPortDefOut->nBufferCountActual;
   3445     pLcmlDSP->Out_BufInfo.nSize             = pComponentPrivate->nOutBufferSize;
   3446     pLcmlDSP->Out_BufInfo.DataTrMethod      = DMM_METHOD;
   3447 
   3448     pLcmlDSP->NodeInfo.nNumOfDLLs           = OMX_MP4ENC_NUM_DLLS;
   3449     pLcmlDSP->NodeInfo.AllUUIDs[0].uuid     = &MP4VESOCKET_TI_UUID;
   3450     strcpy ((char *)pLcmlDSP->NodeInfo.AllUUIDs[0].DllName,MP4_ENC_NODE_DLL);
   3451     pLcmlDSP->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT;
   3452 
   3453     pLcmlDSP->NodeInfo.AllUUIDs[1].uuid     = &MP4VESOCKET_TI_UUID;
   3454     strcpy ((char *)pLcmlDSP->NodeInfo.AllUUIDs[1].DllName,MP4_ENC_NODE_DLL);
   3455     pLcmlDSP->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT;
   3456 
   3457     pLcmlDSP->NodeInfo.AllUUIDs[2].uuid     = &USN_UUID;
   3458     strcpy ((char *)pLcmlDSP->NodeInfo.AllUUIDs[2].DllName,USN_DLL);
   3459     pLcmlDSP->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT;
   3460 
   3461     pLcmlDSP->SegID     = 0;
   3462     pLcmlDSP->Timeout   = -1;
   3463     pLcmlDSP->Alignment = 0;
   3464     pLcmlDSP->Priority  = 5;
   3465 
   3466     #ifdef GPP_PRIVATE_NODE_HEAP
   3467         if ((pPortDefIn->format.video.nFrameWidth <= 176) &&
   3468             (pPortDefIn->format.video.nFrameHeight <= 144))
   3469         {
   3470             pLcmlDSP->ProfileID = 0;
   3471         }
   3472         else if ((pPortDefIn->format.video.nFrameWidth <= 352) &&
   3473                  (pPortDefIn->format.video.nFrameHeight <= 288))
   3474         {
   3475             pLcmlDSP->ProfileID = 1;
   3476         }
   3477         else if ((pPortDefIn->format.video.nFrameWidth <= 640) &&
   3478                  (pPortDefIn->format.video.nFrameHeight <= 480))
   3479         {
   3480             pLcmlDSP->ProfileID = 2;
   3481         }
   3482         else if ((pPortDefIn->format.video.nFrameWidth <= 720) &&
   3483                  (pPortDefIn->format.video.nFrameHeight <= 480))
   3484         {
   3485             pLcmlDSP->ProfileID = 3;
   3486         }
   3487         else if ((pPortDefIn->format.video.nFrameWidth <= 720) &&
   3488                  (pPortDefIn->format.video.nFrameHeight <= 576))
   3489         {
   3490             pLcmlDSP->ProfileID = 4;
   3491         }
   3492         else
   3493         {
   3494             pLcmlDSP->ProfileID = 4;
   3495         }
   3496     #else
   3497         pLcmlDSP->ProfileID = 0xff; /* Use DSP node heap */
   3498     #endif
   3499 
   3500     /* pLcmlDSP->buffindx = 999; */
   3501 
   3502     VIDENC_MALLOC(pCreatePhaseArgs,
   3503                   sizeof(MP4VE_GPP_SN_Obj_CreatePhase),
   3504                   MP4VE_GPP_SN_Obj_CreatePhase,
   3505                   pMemoryListHead,
   3506                   pComponentPrivate->dbg);
   3507 
   3508     pCreatePhaseArgs->ucUnrestrictedMV        = pComponentPrivate->ucUnrestrictedMV;
   3509     pCreatePhaseArgs->ucProfile               = 1;
   3510 
   3511     pCreatePhaseArgs->usNumStreams            = 2;
   3512     pCreatePhaseArgs->usStreamId              = 0;
   3513     pCreatePhaseArgs->usBuffTypeInStream      = 0;
   3514     pCreatePhaseArgs->usMaxBuffsInStream      = (OMX_U16)pPortDefIn->nBufferCountActual;
   3515     pCreatePhaseArgs->usStreamId2             = 1;
   3516     pCreatePhaseArgs->usBuffTypeInStream2     = 0;
   3517     pCreatePhaseArgs->usMaxBuffsInStream2     = (OMX_U16)pPortDefOut->nBufferCountActual;
   3518 
   3519     pCreatePhaseArgs->ulWidth                 = pPortDefIn->format.video.nFrameWidth;
   3520     pCreatePhaseArgs->ulHeight                = pPortDefIn->format.video.nFrameHeight;
   3521     pCreatePhaseArgs->ulTargetBitRate         = pPortDefOut->format.video.nBitrate;
   3522     pCreatePhaseArgs->ulVBVSize               = pComponentPrivate->nVBVSize;
   3523 
   3524     if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
   3525     {
   3526         pCreatePhaseArgs->ulGOBHeadersInterval    = pH263->nGOBHeaderInterval;
   3527     }
   3528     else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
   3529     {
   3530         pCreatePhaseArgs->ulGOBHeadersInterval    = 0;
   3531     }
   3532 
   3533     if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
   3534     {
   3535         pCreatePhaseArgs->ucIsMPEG4 = 0;
   3536     }
   3537     else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
   3538     {
   3539         pCreatePhaseArgs->ucIsMPEG4 = 1;
   3540         /*Initialize variables for the generation of VOL Header*/
   3541         pComponentPrivate->bRequestVOLHeader = OMX_TRUE;
   3542         pComponentPrivate->bWaitingForVOLHeaderBuffer = OMX_TRUE;
   3543         pComponentPrivate->bWaitingVOLHeaderCallback = OMX_TRUE;
   3544     }
   3545     else
   3546     {
   3547         OMX_PRDSP4(pComponentPrivate->dbg, "Unsupported video format (%d).\n",
   3548                    pPortDefOut->format.video.eCompressionFormat);
   3549         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
   3550     }
   3551 
   3552     if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar)
   3553     {
   3554         pCreatePhaseArgs->ucYUVFormat         = 0;
   3555     }
   3556     else if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatCbYCrY) /*422 LE UYVY*/
   3557     {
   3558         pCreatePhaseArgs->ucYUVFormat         = 2;
   3559     }
   3560     else if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatYCbYCr) /*422 BE YUYV */
   3561     {
   3562         pCreatePhaseArgs->ucYUVFormat         = 1;
   3563     }
   3564     else
   3565     {
   3566             OMX_PRDSP2(pComponentPrivate->dbg, "Unsupported YUV format.\n");
   3567         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
   3568     }
   3569     if(pCompPortOut->pErrorCorrectionType->bEnableHEC)
   3570         pCreatePhaseArgs->ucHEC                   = 1;
   3571     else
   3572         pCreatePhaseArgs->ucHEC                   = 0;/**/
   3573 
   3574     if(pCompPortOut->pErrorCorrectionType->bEnableResync)
   3575         pCreatePhaseArgs->ucResyncMarker          = 1;
   3576     else
   3577         pCreatePhaseArgs->ucResyncMarker          = 0;/**/
   3578 
   3579     if(pCompPortOut->pErrorCorrectionType->bEnableDataPartitioning)
   3580         pCreatePhaseArgs->ucDataPartitioning      = 1;
   3581     else
   3582         pCreatePhaseArgs->ucDataPartitioning      = 0;/**/
   3583 
   3584     if(pCompPortOut->pErrorCorrectionType->bEnableRVLC)
   3585         pCreatePhaseArgs->ucReversibleVLC      = 1;
   3586     else
   3587         pCreatePhaseArgs->ucReversibleVLC         = 0;/**/
   3588 
   3589     pCreatePhaseArgs->ucFrameRate             = (OMX_U8) Q16Tof(pPortDefIn->format.video.xFramerate);
   3590 
   3591    /* set run-time frame and bit rates to create-time values */
   3592     pComponentPrivate->nTargetFrameRate       = pCreatePhaseArgs->ucFrameRate;
   3593     pComponentPrivate->nPrevTargetFrameRate   = 0;
   3594     pComponentPrivate->nTargetBitRate         = pCreatePhaseArgs->ulTargetBitRate;
   3595 
   3596      if (pVidParamBitrate->eControlRate == OMX_Video_ControlRateConstant)
   3597     {
   3598         pCreatePhaseArgs->ucRateControlAlgorithm  = IVIDEO_LOW_DELAY;
   3599     }
   3600     else if (pVidParamBitrate->eControlRate == OMX_Video_ControlRateVariable)
   3601     {
   3602         pCreatePhaseArgs->ucRateControlAlgorithm  = IVIDEO_STORAGE;
   3603     }
   3604     else if (pVidParamBitrate->eControlRate == OMX_Video_ControlRateDisable)
   3605     {
   3606         pCreatePhaseArgs->ucRateControlAlgorithm  = IVIDEO_NONE;
   3607     }
   3608     else
   3609     {
   3610         OMX_PRDSP2(pComponentPrivate->dbg, "Unsupported rate control algorithm.\n");
   3611     OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
   3612     }
   3613 
   3614     pCreatePhaseArgs->ucQPFirstIFrame         = (OMX_U8)pQuantization->nQpI;
   3615 
   3616     if (pCreatePhaseArgs->ucIsMPEG4 == 1)
   3617     {
   3618 #ifdef __KHRONOS_CONF_1_1__
   3619         if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level0)
   3620         {
   3621             pCreatePhaseArgs->ucLevel = 0;
   3622         }
   3623         else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level1)
   3624         {
   3625             pCreatePhaseArgs->ucLevel = 1;
   3626         }
   3627         else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level2)
   3628         {
   3629             pCreatePhaseArgs->ucLevel = 2;
   3630         }
   3631         else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level3)
   3632         {
   3633             pCreatePhaseArgs->ucLevel = 3;
   3634         }
   3635         else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level4a ||
   3636                  pMpeg4->eLevel == OMX_VIDEO_MPEG4Level4)
   3637         {
   3638             pCreatePhaseArgs->ucLevel = 4;
   3639         }
   3640         else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level5)
   3641         {
   3642             pCreatePhaseArgs->ucLevel = 5;
   3643         }
   3644         else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level0b)
   3645         {
   3646             pCreatePhaseArgs->ucLevel = 100;
   3647         }
   3648         else
   3649         {
   3650                 OMX_PRDSP2(pComponentPrivate->dbg, "Unsupported level.\n");
   3651             OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
   3652         }
   3653 #else
   3654         pCreatePhaseArgs->ucLevel = pMpeg4->eLevel;
   3655 #endif
   3656         pCreatePhaseArgs->enableH263AnnexI  = 0;
   3657         pCreatePhaseArgs->enableH263AnnexJ  = 0;
   3658         pCreatePhaseArgs->enableH263AnnexT  = 0;
   3659 
   3660     }
   3661     else
   3662     {
   3663         if (pH263->eLevel == OMX_VIDEO_H263Level10)
   3664         {
   3665             pCreatePhaseArgs->ucLevel = 10;
   3666         }
   3667         else if (pH263->eLevel == OMX_VIDEO_H263Level20)
   3668         {
   3669             pCreatePhaseArgs->ucLevel = 20;
   3670         }
   3671         else if (pH263->eLevel == OMX_VIDEO_H263Level30)
   3672         {
   3673             pCreatePhaseArgs->ucLevel = 30;
   3674         }
   3675         else if (pH263->eLevel == OMX_VIDEO_H263Level40)
   3676         {
   3677             pCreatePhaseArgs->ucLevel = 40;
   3678         }
   3679         else if (pH263->eLevel == OMX_VIDEO_H263Level45)
   3680         {
   3681             pCreatePhaseArgs->ucLevel = 45;
   3682         }
   3683         else if (pH263->eLevel == OMX_VIDEO_H263Level50)
   3684         {
   3685             pCreatePhaseArgs->ucLevel = 50;
   3686         }
   3687         else if (pH263->eLevel == OMX_VIDEO_H263Level60)
   3688         {
   3689             pCreatePhaseArgs->ucLevel = 60;
   3690         }
   3691         else if (pH263->eLevel == OMX_VIDEO_H263Level70)
   3692         {
   3693             pCreatePhaseArgs->ucLevel = 70;
   3694         }
   3695         else
   3696         {
   3697             OMX_PRDSP2(pComponentPrivate->dbg, "Unsupported level.\n");
   3698             OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
   3699         }
   3700 
   3701         pCreatePhaseArgs->enableH263AnnexI  = 0;
   3702         pCreatePhaseArgs->enableH263AnnexJ  = 0;
   3703         pCreatePhaseArgs->enableH263AnnexT  = 0;
   3704     }
   3705     pCreatePhaseArgs->ulMaxDelay              = 300;
   3706     #ifndef MODE_3410
   3707     pCreatePhaseArgs->ulVbvParamEnable        = 0;
   3708     pCreatePhaseArgs->ulH263SliceMode         = 0;
   3709     #endif
   3710     pCreatePhaseArgs->ulUseGOV                = 0;
   3711     if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
   3712         pCreatePhaseArgs->ulUseVOS            = 1;//needed to generate VOL Header
   3713     else
   3714         pCreatePhaseArgs->ulUseVOS            = 0;
   3715     pCreatePhaseArgs->endArgs                 = END_OF_CR_PHASE_ARGS;
   3716     pTmp = memcpy(nArr, pCreatePhaseArgs, sizeof(MP4VE_GPP_SN_Obj_CreatePhase));
   3717     if (pTmp == NULL)
   3718     {
   3719         OMX_TRACE4(pComponentPrivate->dbg, "memcpy() out of memory error.\n");
   3720         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
   3721     }
   3722 
   3723     pLcmlDSP->pCrPhArgs = nArr;
   3724     printMpeg4Params(pCreatePhaseArgs, &pComponentPrivate->dbg);
   3725 
   3726     sCb.LCML_Callback = (void *)OMX_VIDENC_LCML_Callback;
   3727     eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
   3728                               NULL,
   3729                               &pLcmlHandle,
   3730                               NULL,
   3731                               &sCb);
   3732 
   3733     if (eError != OMX_ErrorNone)
   3734     {
   3735         OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...\n");
   3736         /*TODO: Validate eError from LCML_InitMMCodec for ResourceExhaustionTest */
   3737         pComponentPrivate->bErrorLcmlHandle = OMX_TRUE;
   3738         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
   3739     }
   3740     pComponentPrivate->bCodecLoaded = OMX_TRUE;
   3741     VIDENC_FREE(pCreatePhaseArgs, pMemoryListHead,
   3742                 pComponentPrivate->dbg);
   3743 
   3744 OMX_CONF_CMD_BAIL:
   3745     return eError;
   3746 }
   3747 /*----------------------------------------------------------------------------*/
   3748 /**
   3749   *  OMX_VIDENC_Allocate_DSPResources()
   3750   *
   3751   *
   3752   *
   3753   *
   3754   * @param
   3755   * @param
   3756   * @param
   3757   *
   3758   * @retval OMX_NoError              Success, ready to roll
   3759   *         OMX_Error_BadParameter   The input parameter pointer is null
   3760   **/
   3761 /*----------------------------------------------------------------------------*/
   3762 
   3763 OMX_ERRORTYPE OMX_VIDENC_Allocate_DSPResources(VIDENC_COMPONENT_PRIVATE* pComponentPrivate,
   3764                                                OMX_IN OMX_U32 nPortIndex)
   3765 {
   3766     char* pTemp = NULL;
   3767     OMX_U32 nBufferCnt = -1;
   3768     VIDENC_NODE* pMemoryListHead = NULL;
   3769     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3770     VIDEOENC_PORT_TYPE* pCompPort = NULL;
   3771     OMX_VIDEO_CODINGTYPE eCompressionFormat = -1;
   3772     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
   3773 
   3774     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
   3775 
   3776     pMemoryListHead = pComponentPrivate->pMemoryListHead;
   3777     pCompPort = pComponentPrivate->pCompPort[nPortIndex];
   3778     nBufferCnt = pComponentPrivate->pCompPort[nPortIndex]->nBufferCnt;
   3779     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
   3780     eCompressionFormat = pPortDefOut->format.video.eCompressionFormat;
   3781 
   3782     if (nPortIndex == VIDENC_INPUT_PORT)
   3783     {
   3784         if (eCompressionFormat == OMX_VIDEO_CodingAVC)
   3785         {
   3786             H264VE_GPP_SN_UALGInputParams* pUalgParam;
   3787 
   3788             VIDENC_MALLOC(pUalgParam,
   3789                           sizeof(H264VE_GPP_SN_UALGInputParams) + 256,
   3790                           H264VE_GPP_SN_UALGInputParams,
   3791                           pMemoryListHead,
   3792                           pComponentPrivate->dbg);
   3793 
   3794             pTemp = (char*)pUalgParam;
   3795             pTemp += 128;
   3796             pUalgParam = (H264VE_GPP_SN_UALGInputParams*)pTemp;
   3797             pCompPort->pBufferPrivate[nBufferCnt]->pUalgParam = pUalgParam;
   3798         }
   3799         else if (eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   3800                  eCompressionFormat == OMX_VIDEO_CodingH263)
   3801         {
   3802             MP4VE_GPP_SN_UALGInputParams* pUalgParam;
   3803 
   3804             VIDENC_MALLOC(pUalgParam,
   3805                           sizeof(MP4VE_GPP_SN_UALGInputParams) + 256,
   3806                           MP4VE_GPP_SN_UALGInputParams,
   3807                           pMemoryListHead,
   3808                           pComponentPrivate->dbg);
   3809             pTemp = (char*)pUalgParam;
   3810             pTemp += 128;
   3811             pUalgParam = (MP4VE_GPP_SN_UALGInputParams*)pTemp;
   3812             pCompPort->pBufferPrivate[nBufferCnt]->pUalgParam = pUalgParam;
   3813             if(eCompressionFormat == OMX_VIDEO_CodingMPEG4)
   3814             {/*Structure needed to send the request for VOLHeader to SN*/
   3815                 VIDENC_MALLOC(pComponentPrivate->pTempUalgInpParams,
   3816                               sizeof(MP4VE_GPP_SN_UALGInputParams) + 256,
   3817                               MP4VE_GPP_SN_UALGInputParams,
   3818                               pMemoryListHead,
   3819                               pComponentPrivate->dbg);
   3820                 pTemp = (char*)pComponentPrivate->pTempUalgInpParams;
   3821                 pTemp += 128;
   3822                 pComponentPrivate->pTempUalgInpParams = (MP4VE_GPP_SN_UALGInputParams*)pTemp;
   3823             }
   3824         }
   3825     }
   3826     else if (nPortIndex == VIDENC_OUTPUT_PORT)
   3827     {
   3828         if (eCompressionFormat == OMX_VIDEO_CodingAVC)
   3829         {
   3830             H264VE_GPP_SN_UALGOutputParams* pUalgParam;
   3831 
   3832             VIDENC_MALLOC(pUalgParam,
   3833                           sizeof(H264VE_GPP_SN_UALGOutputParams) + 256,
   3834                           H264VE_GPP_SN_UALGOutputParams,
   3835                           pMemoryListHead,
   3836                           pComponentPrivate->dbg);
   3837             pTemp = (char*)pUalgParam;
   3838             pTemp += 128;
   3839             pUalgParam = (H264VE_GPP_SN_UALGOutputParams*)pTemp;
   3840             pCompPort->pBufferPrivate[nBufferCnt]->pUalgParam = pUalgParam;
   3841         }
   3842         else if (eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   3843                  eCompressionFormat == OMX_VIDEO_CodingH263)
   3844         {
   3845             MP4VE_GPP_SN_UALGOutputParams* pUalgParam;
   3846 
   3847             VIDENC_MALLOC(pUalgParam,
   3848                           sizeof(MP4VE_GPP_SN_UALGOutputParams) + 256,
   3849                           MP4VE_GPP_SN_UALGOutputParams,
   3850                           pMemoryListHead,
   3851                           pComponentPrivate->dbg);
   3852             pTemp = (char*)pUalgParam;
   3853             pTemp += 128;
   3854             pUalgParam = (MP4VE_GPP_SN_UALGOutputParams*)pTemp;
   3855             pCompPort->pBufferPrivate[nBufferCnt]->pUalgParam = pUalgParam;
   3856         }
   3857     }
   3858 OMX_CONF_CMD_BAIL:
   3859     return eError;
   3860 }
   3861 
   3862 /*---------------------------------------------------------------------------------------*/
   3863 /**
   3864   *  Callback() function will be called LCML component to write the msg
   3865   *
   3866   * @param msgBuffer                 This buffer will be returned by the LCML
   3867   *
   3868   * @retval OMX_NoError              Success, ready to roll
   3869   *         OMX_Error_BadParameter   The input parameter pointer is null
   3870  **/
   3871 /*---------------------------------------------------------------------------------------*/
   3872 OMX_ERRORTYPE OMX_VIDENC_LCML_Callback(TUsnCodecEvent event,void* argsCb [10])
   3873 {
   3874     int nRet = -1;
   3875     OMX_COMPONENTTYPE* pHandle = NULL;
   3876     OMX_ERRORTYPE eError = OMX_ErrorNone;
   3877     OMX_BUFFERHEADERTYPE* pBufHead = NULL;
   3878     VIDENC_BUFFER_PRIVATE* pBufferPrivate = NULL;
   3879     LCML_DSP_INTERFACE* pLcmlDspInterface = NULL;
   3880     TUsnCodecEvent eEvent = (TUsnCodecEvent)event;
   3881     VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
   3882 
   3883     OMX_CONF_CHECK_CMD(argsCb, 1, 1);
   3884 
   3885     if (argsCb[6])
   3886     {
   3887         pLcmlDspInterface = (LCML_DSP_INTERFACE*)argsCb[6];
   3888         pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)pLcmlDspInterface->pComponentPrivate;
   3889         pHandle = (OMX_COMPONENTTYPE *)pComponentPrivate->pHandle;
   3890     }
   3891     else
   3892     {
   3893         OMXDBG_PRINT(stderr, DSP, 5, 0, "No LCML handle\n");
   3894         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter);
   3895     }
   3896 
   3897 
   3898     if (eEvent == EMMCodecBufferProcessed)
   3899     {
   3900         if (((OMX_S32)argsCb[0]) == EMMCodecOuputBuffer)
   3901         {
   3902             pBufHead = (OMX_BUFFERHEADERTYPE*)argsCb[7];
   3903             pBufferPrivate = (VIDENC_BUFFER_PRIVATE*)pBufHead->pOutputPortPrivate;
   3904 #ifdef __PERF_INSTRUMENTATION__
   3905             PERF_ReceivedFrame(pComponentPrivate->pPERFcomp,
   3906                                PREF(pBufHead,pBuffer),
   3907                                PREF(pBufHead,nFilledLen),
   3908                                PERF_ModuleCommonLayer);
   3909 
   3910             pComponentPrivate->nLcml_nCntOpReceived++;
   3911 
   3912             if ((pComponentPrivate->nLcml_nCntIp >= 1) &&
   3913                 (pComponentPrivate->nLcml_nCntOpReceived == 1))
   3914             {
   3915                 PERF_Boundary(pComponentPrivate->pPERFcomp,
   3916                               PERF_BoundaryStart | PERF_BoundarySteadyState);
   3917             }
   3918 #endif
   3919             OMX_PRDSP1(pComponentPrivate->dbg, " [OUT] -> %p\n", pBufHead);
   3920             if(pBufHead->nFilledLen > pBufHead->nAllocLen) {
   3921                 LOGD("VE Warning!!! Output buffer overflow.");
   3922             }
   3923             pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_COMPONENT;
   3924             if (pComponentPrivate->bCodecStarted == OMX_TRUE)
   3925             {
   3926                 OMX_PRDSP1(pComponentPrivate->dbg, "Enters OMX_VIDENC_Process_FilledOutBuf\n");
   3927               eError = OMX_VIDENC_Process_FilledOutBuf(pComponentPrivate, pBufHead);
   3928               if (eError != OMX_ErrorNone)
   3929               {
   3930                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   3931                            OMX_EventError,
   3932                            OMX_ErrorUndefined,
   3933                            OMX_TI_ErrorCritical,
   3934                            NULL);
   3935                 OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
   3936               }
   3937             }
   3938         }
   3939         if ((int)argsCb [0] == EMMCodecInputBuffer)
   3940         {
   3941             pBufHead = (OMX_BUFFERHEADERTYPE*)argsCb[7];
   3942             pBufferPrivate = (VIDENC_BUFFER_PRIVATE*)pBufHead->pInputPortPrivate;
   3943 
   3944 #ifdef __PERF_INSTRUMENTATION__
   3945             PERF_ReceivedFrame(pComponentPrivate->pPERFcomp,
   3946                                PREF(pBufHead,pBuffer),
   3947                                0,
   3948                                PERF_ModuleCommonLayer);
   3949 #endif
   3950 
   3951             OMX_PRDSP1(pComponentPrivate->dbg, " [IN] -> %p\n", pBufHead);
   3952             pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_COMPONENT;
   3953             /*we should ignore the callback asociated to the VOL Header request*/
   3954             if (pComponentPrivate->bCodecStarted == OMX_TRUE && pComponentPrivate->bWaitingVOLHeaderCallback == OMX_FALSE)
   3955             {
   3956                 OMX_PRDSP1(pComponentPrivate->dbg, "Enters OMX_VIDENC_Process_FreeInBuf\n");
   3957                eError = OMX_VIDENC_Process_FreeInBuf(pComponentPrivate, pBufHead);
   3958                if (eError != OMX_ErrorNone)
   3959                {
   3960                  OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
   3961                             OMX_EventError,
   3962                             OMX_ErrorUndefined,
   3963                             OMX_TI_ErrorCritical,
   3964                             NULL);
   3965                  OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
   3966                }
   3967                 OMX_PRDSP1(pComponentPrivate->dbg, "Exits OMX_VIDENC_Process_FreeInBuf\n");
   3968             }
   3969             else if(pComponentPrivate->bWaitingVOLHeaderCallback == OMX_TRUE)
   3970             {
   3971                 pComponentPrivate->bWaitingVOLHeaderCallback = OMX_FALSE;
   3972             }
   3973         }
   3974     }
   3975 
   3976     if(eEvent == EMMCodecProcessingPaused ||
   3977        eEvent == EMMCodecProcessingStoped)
   3978     {
   3979         if (pComponentPrivate != NULL)
   3980         {
   3981             pComponentPrivate->bDSPStopAck = OMX_TRUE;
   3982             #ifndef UNDER_CE
   3983                 pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
   3984                 pthread_cond_signal(&pComponentPrivate->stop_cond);
   3985                 pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
   3986             #endif
   3987         }
   3988     }
   3989 
   3990     if(eEvent == EMMCodecStrmCtrlAck)
   3991     {
   3992         if ((int)argsCb [0] == USN_ERR_NONE)
   3993         {
   3994             pComponentPrivate->bFlushComplete = OMX_TRUE;
   3995             #ifndef UNDER_CE
   3996                 pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
   3997                 pthread_cond_signal(&pComponentPrivate->flush_cond);
   3998                 pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
   3999             #endif
   4000         }
   4001     }
   4002    nRet = OMX_VIDENC_HandleLcmlEvent(pComponentPrivate, eEvent, argsCb);
   4003     if (nRet == -1)
   4004     {
   4005         OMX_ERROR4(pComponentPrivate->dbg, "LCML Event Handler failed.\n");
   4006         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined);
   4007     }
   4008 
   4009 OMX_CONF_CMD_BAIL:
   4010     return eError;
   4011 }
   4012 
   4013 
   4014 #ifdef UNDER_CE
   4015 /* ================================================================================= */
   4016 /**
   4017 * @fns Sleep replace for WIN CE
   4018 */
   4019 /* ================================================================================ */
   4020 int OMX_CreateEvent(OMX_Event *event){
   4021     int ret = OMX_ErrorNone;
   4022     HANDLE createdEvent = NULL;
   4023     if (event == NULL)
   4024     {
   4025         ret = OMX_ErrorBadParameter;
   4026         goto EXIT;
   4027     }
   4028     event->event  = CreateEvent(NULL, TRUE, FALSE, NULL);
   4029     if(event->event == NULL)
   4030         ret = (int)GetLastError();
   4031 EXIT:
   4032     return ret;
   4033 }
   4034 
   4035 int OMX_SignalEvent(OMX_Event *event){
   4036      int ret = OMX_ErrorNone;
   4037     if (event == NULL)
   4038     {
   4039         ret = OMX_ErrorBadParameter;
   4040         goto EXIT;
   4041      }
   4042      SetEvent(event->event);
   4043      ret = (int)GetLastError();
   4044 EXIT:
   4045     return ret;
   4046 }
   4047 
   4048 int OMX_WaitForEvent(OMX_Event *event) {
   4049      int ret = OMX_ErrorNone;
   4050     if (event == NULL)
   4051     {
   4052         ret = OMX_ErrorBadParameter;
   4053         goto EXIT;
   4054      }
   4055      WaitForSingleObject(event->event, INFINITE);
   4056      ret = (int)GetLastError();
   4057 EXIT:
   4058      return ret;
   4059 }
   4060 
   4061 int OMX_DestroyEvent(OMX_Event *event) {
   4062      int ret = OMX_ErrorNone;
   4063     if (event == NULL)
   4064     {
   4065         ret = OMX_ErrorBadParameter;
   4066         goto EXIT;
   4067      }
   4068      CloseHandle(event->event);
   4069 EXIT:
   4070      return ret;
   4071 }
   4072 #endif
   4073 
   4074 #ifdef RESOURCE_MANAGER_ENABLED
   4075 /*-----------------------------------------------------------------------------*/
   4076 /**
   4077   * OMX_VIDENC_ResourceManagerCallBack()
   4078   *
   4079   * Called from Resource Manager()
   4080   *
   4081  *
   4082   *
   4083   **/
   4084 /*-----------------------------------------------------------------------------*/
   4085 void OMX_VIDENC_ResourceManagerCallBack(RMPROXY_COMMANDDATATYPE cbData)
   4086 {
   4087     OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
   4088     OMX_STATETYPE state = OMX_StateIdle;
   4089     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
   4090     VIDENC_COMPONENT_PRIVATE *pCompPrivate = NULL;
   4091 
   4092     pCompPrivate = (VIDENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
   4093     OMX_PRMGR2(pCompPrivate->dbg, "OMX_VIDENC_ResourceManagerCallBack\n");
   4094     OMX_PRMGR2(pCompPrivate->dbg, "Arguments:\ncbData.RM_Error = %dcbData.RM_Cmd = %d\n", *(cbData.RM_Error), cbData.RM_Cmd);
   4095     if (*(cbData.RM_Error) == OMX_ErrorResourcesPreempted)
   4096     {
   4097         if (pCompPrivate->eState== OMX_StateExecuting ||
   4098             pCompPrivate->eState == OMX_StatePause)
   4099         {
   4100 
   4101         pCompPrivate->sCbData.EventHandler (
   4102                             pHandle, pHandle->pApplicationPrivate,
   4103                             OMX_EventError,
   4104                            OMX_ErrorResourcesPreempted,OMX_TI_ErrorMinor,
   4105                             "Componentn Preempted\n");
   4106 
   4107             OMX_PRSTATE2(pCompPrivate->dbg, "Send command to Idle from RM CallBack\n");
   4108         OMX_SendCommand(pHandle, Cmd, state, NULL);
   4109         pCompPrivate->bPreempted = 1;
   4110 
   4111         }
   4112     }
   4113     else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired)
   4114     {
   4115         pCompPrivate->sCbData.EventHandler (
   4116                             pHandle, pHandle->pApplicationPrivate,
   4117                             OMX_EventResourcesAcquired, 0,0,
   4118                             NULL);
   4119         OMX_PRSTATE2(pCompPrivate->dbg, "Send command to Executing from RM CallBack\n");
   4120         OMX_SendCommand(pHandle, Cmd, OMX_StateExecuting, NULL);
   4121     }
   4122 }
   4123 #endif
   4124 
   4125 void CalculateBufferSize(OMX_PARAM_PORTDEFINITIONTYPE* pCompPort, VIDENC_COMPONENT_PRIVATE* pCompPrivate)
   4126 {
   4127 
   4128     if(pCompPort->nPortIndex == VIDENC_INPUT_PORT) {
   4129         if (pCompPort->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar)
   4130         {
   4131             pCompPort->nBufferSize = pCompPort->format.video.nFrameWidth *
   4132                                     pCompPort->format.video.nFrameHeight * 1.5;
   4133         }
   4134         else
   4135         {
   4136             pCompPort->nBufferSize = pCompPort->format.video.nFrameWidth *
   4137                                     pCompPort->format.video.nFrameHeight * 2;
   4138         }
   4139     }
   4140     else {
   4141         if (pCompPort->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
   4142         {
   4143             pCompPort->nBufferSize = GetMaxAVCBufferSize(pCompPort->format.video.nFrameWidth, pCompPort->format.video.nFrameHeight);
   4144         }
   4145         else
   4146         {/*coding Mpeg4 or H263*/
   4147             pCompPort->nBufferSize = pCompPort->format.video.nFrameWidth *
   4148                                     pCompPort->format.video.nFrameHeight / 2;
   4149         }
   4150         pCompPort->nBufferSize += 256;
   4151     }
   4152 }
   4153 
   4154 OMX_U32 GetMaxAVCBufferSize(OMX_U32 width, OMX_U32 height)
   4155 {
   4156     OMX_U32 MaxCPB;
   4157     OMX_U32 nMacroBlocks;
   4158 
   4159     /* Calculate output buffer size based on max possible CPB for the resolution
   4160        Output bitrate may not be set yet, so only resolution is taken into account */
   4161 
   4162     nMacroBlocks = (width * height) / 256;
   4163 
   4164     /* Following values are set based on Annex A of AVC Standard */
   4165     if(nMacroBlocks <= 99) {
   4166         MaxCPB = 500;
   4167     }
   4168     else if(nMacroBlocks <= 396) {
   4169         MaxCPB = 2000;
   4170     }
   4171     else if(nMacroBlocks <= 792) {
   4172         MaxCPB = 4000;
   4173     }
   4174     else if(nMacroBlocks <= 1620) {
   4175         /* Note - Max bitrate in this case is assumed to max 4 Mbps to limit the buffer size
   4176            If bitrate in this particular case could be higher than 4 Mbps, increase MxCPB value */
   4177         MaxCPB = 4000;
   4178     }
   4179     else
   4180         MaxCPB = 14000;
   4181 
   4182     /* MaxCPB are in units of 1200 bits i.e. 150 bytes */
   4183     /* Return  buffer size in bytes*/
   4184     /*Last patch to improve the performance*/
   4185     /*return (150 * MaxCPB);*/
   4186     return (width * height) / 2;
   4187 }
   4188 OMX_U32 OMX_VIDENC_GetDefaultBitRate(VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
   4189 {
   4190     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef;
   4191     OMX_U32 bitrate;
   4192     int nCount;
   4193 
   4194     pPortDef = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
   4195     for ( nCount = 0; nCount < VIDENC_MAXBITRATES; nCount++ ) {
   4196         if (pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
   4197             bitrate = VIDENC_STRUCT_H264DEFBITRATE [nCount][1];
   4198             if ((pPortDef->format.video.nFrameWidth * pPortDef->format.video.nFrameHeight)
   4199                 <= VIDENC_STRUCT_H264DEFBITRATE[nCount][0]) {
   4200                 break;
   4201             }
   4202         }
   4203         else if (pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
   4204             bitrate = VIDENC_STRUCT_MPEG4DEFBITRATE [nCount][1];
   4205             if ((pPortDef->format.video.nFrameWidth * pPortDef->format.video.nFrameHeight)
   4206                 <= VIDENC_STRUCT_MPEG4DEFBITRATE[nCount][0]) {
   4207                 break;
   4208             }
   4209         }
   4210         else {
   4211             bitrate = VIDENC_STRUCT_H263DEFBITRATE [nCount][1];
   4212             if ((pPortDef->format.video.nFrameWidth * pPortDef->format.video.nFrameHeight)
   4213                 <= VIDENC_STRUCT_H263DEFBITRATE[nCount][0]) {
   4214                 break;
   4215             }
   4216         }
   4217     }
   4218 
   4219     return bitrate;
   4220 }
   4221 
   4222 
   4223 void printMpeg4Params(MP4VE_GPP_SN_Obj_CreatePhase* pCreatePhaseArgs,
   4224                       struct OMX_TI_Debug *dbg)
   4225 {
   4226     OMX_PRDSP2(*dbg, "\nusNumStreams = %d\n", pCreatePhaseArgs->usNumStreams);
   4227     OMX_PRDSP2(*dbg, "usStreamId = %d\n", pCreatePhaseArgs->usStreamId);
   4228     OMX_PRDSP2(*dbg, "usBuffTypeInStream = %d\n", pCreatePhaseArgs->usBuffTypeInStream);
   4229     OMX_PRDSP2(*dbg, "usMaxBuffsInStream = %d\n", pCreatePhaseArgs->usMaxBuffsInStream);
   4230     OMX_PRDSP2(*dbg, "usStreamId2 = %d\n", pCreatePhaseArgs->usStreamId2);
   4231     OMX_PRDSP2(*dbg, "usBuffTypeInStream2 = %d\n", pCreatePhaseArgs->usBuffTypeInStream2);
   4232     OMX_PRDSP2(*dbg, "usMaxBuffsInStream2 = %d\n", pCreatePhaseArgs->usMaxBuffsInStream2);
   4233 
   4234     OMX_PRDSP2(*dbg, "ulWidth = %d\n", pCreatePhaseArgs->ulWidth);
   4235     OMX_PRDSP2(*dbg, "ulHeight = %d\n", pCreatePhaseArgs->ulHeight);
   4236     OMX_PRDSP2(*dbg, "ulTargetBitRate = %d\n", pCreatePhaseArgs->ulTargetBitRate);
   4237     OMX_PRDSP2(*dbg, "ulVBVSize = %d\n", pCreatePhaseArgs->ulVBVSize);
   4238     OMX_PRDSP2(*dbg, "ulGOBHeadersInterval = %d\n", pCreatePhaseArgs->ulGOBHeadersInterval);
   4239 
   4240     OMX_PRDSP2(*dbg, "ucIsMPEG4 = %d\n", pCreatePhaseArgs->ucIsMPEG4);
   4241     OMX_PRDSP2(*dbg, "ucYUVFormat = %d\n", pCreatePhaseArgs->ucYUVFormat);
   4242     OMX_PRDSP2(*dbg, "ucHEC = %d\n", pCreatePhaseArgs->ucHEC);
   4243     OMX_PRDSP2(*dbg, "ucResyncMarker = %d\n", pCreatePhaseArgs->ucResyncMarker);
   4244     OMX_PRDSP2(*dbg, "ucDataPartitioning = %d\n", pCreatePhaseArgs->ucDataPartitioning);
   4245     OMX_PRDSP2(*dbg, "ucReversibleVLC = %d\n", pCreatePhaseArgs->ucReversibleVLC);
   4246     OMX_PRDSP2(*dbg, "ucUnrestrictedMV = %d\n", pCreatePhaseArgs->ucUnrestrictedMV);
   4247     OMX_PRDSP2(*dbg, "ucFrameRate = %d\n", pCreatePhaseArgs->ucFrameRate);
   4248     OMX_PRDSP2(*dbg, "ucRateControlAlgorithm = %d\n", pCreatePhaseArgs->ucRateControlAlgorithm);
   4249     OMX_PRDSP2(*dbg, "ucQPFirstIFrame = %d\n", pCreatePhaseArgs->ucQPFirstIFrame);
   4250     OMX_PRDSP2(*dbg, "ucProfile = %d\n", pCreatePhaseArgs->ucProfile);
   4251     OMX_PRDSP2(*dbg, "ucLevel = %d\n", pCreatePhaseArgs->ucLevel);
   4252     OMX_PRDSP2(*dbg, "ulMaxDelay = %d\n", pCreatePhaseArgs->ulMaxDelay);
   4253     /*
   4254     OMX_PRDSP2(*dbg, "ulVbvParamEnable = %d\n", pCreatePhaseArgs->ulVbvParamEnable);
   4255     OMX_PRDSP2(*dbg, "ulH263SliceMode = %d\n", pCreatePhaseArgs->ulH263SliceMode);
   4256     */
   4257     OMX_PRDSP2(*dbg, "ulUseGOV = %d\n", pCreatePhaseArgs->ulUseGOV);
   4258     OMX_PRDSP2(*dbg, "ulUseVOS = %d\n", pCreatePhaseArgs->ulUseVOS);
   4259     OMX_PRDSP2(*dbg, "enableH263AnnexI = %d\n", pCreatePhaseArgs->enableH263AnnexI);
   4260     OMX_PRDSP2(*dbg, "enableH263AnnexJ = %d\n", pCreatePhaseArgs->enableH263AnnexJ);
   4261     OMX_PRDSP2(*dbg, "enableH263AnnexT = %d\n", pCreatePhaseArgs->enableH263AnnexT);
   4262 }
   4263 void printH264CreateParams(H264VE_GPP_SN_Obj_CreatePhase* pCreatePhaseArgs, struct OMX_TI_Debug *dbg)
   4264 {
   4265     OMX_PRDSP2(*dbg, "\nusNumStreams = %d\n", pCreatePhaseArgs->usNumStreams);
   4266     OMX_PRDSP2(*dbg, "usStreamId = %d\n", pCreatePhaseArgs->usStreamId);
   4267     OMX_PRDSP2(*dbg, "usBuffTypeInStream = %d\n", pCreatePhaseArgs->usBuffTypeInStream);
   4268     OMX_PRDSP2(*dbg, "usMaxBuffsInStream = %d\n", pCreatePhaseArgs->usMaxBuffsInStream);
   4269     OMX_PRDSP2(*dbg, "usStreamId2 = %d\n", pCreatePhaseArgs->usStreamId2);
   4270     OMX_PRDSP2(*dbg, "usBuffTypeInStream2 = %d\n", pCreatePhaseArgs->usBuffTypeInStream2);
   4271     OMX_PRDSP2(*dbg, "usMaxBuffsInStream2 = %d\n", pCreatePhaseArgs->usMaxBuffsInStream2);
   4272 
   4273     OMX_PRDSP2(*dbg, "ulWidth = %d\n", pCreatePhaseArgs->ulWidth);
   4274     OMX_PRDSP2(*dbg, "ulHeight = %d\n", pCreatePhaseArgs->ulHeight);
   4275     OMX_PRDSP2(*dbg, "ulTargetBitRate = %d\n", pCreatePhaseArgs->ulTargetBitRate);
   4276     OMX_PRDSP2(*dbg, "ulBitstreamBuffSize = %d\n", pCreatePhaseArgs->ulBitstreamBuffSize);
   4277     OMX_PRDSP2(*dbg, "ulIntraFramePeriod = %d\n", pCreatePhaseArgs->ulIntraFramePeriod);
   4278     OMX_PRDSP2(*dbg, "ulFrameRate = %d\n", pCreatePhaseArgs->ulFrameRate);
   4279 
   4280     OMX_PRDSP2(*dbg, "ucYUVFormat = %d\n", pCreatePhaseArgs->ucYUVFormat);
   4281     OMX_PRDSP2(*dbg, "ucUnrestrictedMV = %d\n", pCreatePhaseArgs->ucUnrestrictedMV);
   4282     OMX_PRDSP2(*dbg, "ucNumRefFrames = %d\n", pCreatePhaseArgs->ucNumRefFrames);
   4283     OMX_PRDSP2(*dbg, "ucRateControlAlgorithm = %d\n", pCreatePhaseArgs->ucRateControlAlgorithm);
   4284     OMX_PRDSP2(*dbg, "ucIDREnable = %d\n", pCreatePhaseArgs->ucIDREnable);
   4285     OMX_PRDSP2(*dbg, "ucDeblockingEnable = %d\n", pCreatePhaseArgs->ucDeblockingEnable);
   4286     OMX_PRDSP2(*dbg, "ucMVRange = %d\n", pCreatePhaseArgs->ucMVRange);
   4287     OMX_PRDSP2(*dbg, "ucQPIFrame = %d\n", pCreatePhaseArgs->ucQPIFrame);
   4288     OMX_PRDSP2(*dbg, "ucProfile = %d\n", pCreatePhaseArgs->ucProfile);
   4289     OMX_PRDSP2(*dbg, "ucLevel = %d\n", pCreatePhaseArgs->ucLevel);
   4290 
   4291     OMX_PRDSP2(*dbg, "usNalCallback = %d\n", pCreatePhaseArgs->usNalCallback);
   4292     OMX_PRDSP2(*dbg, "ulEncodingPreset = %d\n", pCreatePhaseArgs->ulEncodingPreset);
   4293     OMX_PRDSP2(*dbg, "ulRcAlgo = %d\n", pCreatePhaseArgs->ulRcAlgo);
   4294 }
   4295 
   4296 void printMpeg4UAlgInParam(MP4VE_GPP_SN_UALGInputParams* pUalgInpParams, int printAlways, struct OMX_TI_Debug *dbg)
   4297 {
   4298     static int printed=0;
   4299 
   4300     if(printAlways || !printed)
   4301     {
   4302         printed++;
   4303         OMX_PRDSP2(*dbg, "\nulFrameIndex = %u\n", pUalgInpParams->ulFrameIndex);
   4304         OMX_PRDSP2(*dbg, "ulTargetFrameRate = %u\n", pUalgInpParams->ulTargetFrameRate);
   4305         OMX_PRDSP2(*dbg, "ulTargetBitRate = %u\n", pUalgInpParams->ulTargetBitRate);
   4306         OMX_PRDSP2(*dbg, "ulIntraFrameInterval = %u\n", pUalgInpParams->ulIntraFrameInterval);
   4307         OMX_PRDSP2(*dbg, "ulGenerateHeader = %u\n", pUalgInpParams->ulGenerateHeader);
   4308         OMX_PRDSP2(*dbg, "ulForceIFrame = %u\n", pUalgInpParams->ulForceIFrame);
   4309         OMX_PRDSP2(*dbg, "ulResyncInterval = %u\n", pUalgInpParams->ulResyncInterval);
   4310         OMX_PRDSP2(*dbg, "ulHecInterval = %u\n", pUalgInpParams->ulHecInterval);
   4311         OMX_PRDSP2(*dbg, "ulAIRRate = %u\n", pUalgInpParams->ulAIRRate);
   4312         OMX_PRDSP2(*dbg, "ulMIRRate = %u\n", pUalgInpParams->ulMIRRate);
   4313         OMX_PRDSP2(*dbg, "ulQPIntra = %u\n", pUalgInpParams->ulQPIntra);
   4314         OMX_PRDSP2(*dbg, "ulfCode = %u\n", pUalgInpParams->ulfCode);
   4315         OMX_PRDSP2(*dbg, "ulHalfPel = %u\n", pUalgInpParams->ulHalfPel);
   4316         OMX_PRDSP2(*dbg, "ulACPred = %u\n", pUalgInpParams->ulACPred);
   4317         OMX_PRDSP2(*dbg, "ul4MV = %u\n", pUalgInpParams->ul4MV);
   4318         OMX_PRDSP2(*dbg, "uluseUMV = %u\n", pUalgInpParams->uluseUMV);
   4319         OMX_PRDSP2(*dbg, "ulMVDataEnable = %u\n", pUalgInpParams->ulMVDataEnable);
   4320         OMX_PRDSP2(*dbg, "ulResyncDataEnable = %u\n", pUalgInpParams->ulResyncDataEnable);
   4321         OMX_PRDSP2(*dbg, "ulQPInter = %u\n", pUalgInpParams->ulQPInter);
   4322         OMX_PRDSP2(*dbg, "ulLastFrame = %u\n", pUalgInpParams->ulLastFrame);
   4323         OMX_PRDSP2(*dbg, "ulcapturewidth = %u\n", pUalgInpParams->ulcapturewidth);
   4324         OMX_PRDSP2(*dbg, "ulQpMax = %u\n", pUalgInpParams->ulQpMax);
   4325         OMX_PRDSP2(*dbg, "ulQpMin = %u\n", pUalgInpParams->ulQpMin);
   4326     }
   4327 }
   4328 
   4329 
   4330 void printH264UAlgInParam(H264VE_GPP_SN_UALGInputParams* pUalgInpParams, int printAlways, struct OMX_TI_Debug *dbg)
   4331 {
   4332     static int printed=0;
   4333 
   4334     if(printAlways || !printed)
   4335     {
   4336         printed++;
   4337         OMX_PRDSP2(*dbg, "\nqpIntra = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.qpIntra);
   4338         OMX_PRDSP2(*dbg, "qpInter = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.qpInter);
   4339         OMX_PRDSP2(*dbg, "qpMax = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.qpMax);
   4340         OMX_PRDSP2(*dbg, "qpMin = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.qpMin);
   4341         OMX_PRDSP2(*dbg, "lfDisableIdc = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.lfDisableIdc);
   4342         OMX_PRDSP2(*dbg, "quartPelDisable = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.quartPelDisable);
   4343         OMX_PRDSP2(*dbg, "airMbPeriod = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.airMbPeriod);
   4344         OMX_PRDSP2(*dbg, "maxMBsPerSlice = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.maxMBsPerSlice);
   4345         OMX_PRDSP2(*dbg, "maxBytesPerSlice = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.maxBytesPerSlice);
   4346         OMX_PRDSP2(*dbg, "sliceRefreshRowStartNumber = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sliceRefreshRowStartNumber);
   4347         OMX_PRDSP2(*dbg, "sliceRefreshRowNumber = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sliceRefreshRowNumber);
   4348         OMX_PRDSP2(*dbg, "filterOffsetA = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.filterOffsetA);
   4349         OMX_PRDSP2(*dbg, "filterOffsetB = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.filterOffsetB);
   4350         OMX_PRDSP2(*dbg, "log2MaxFNumMinus4 = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.log2MaxFNumMinus4);
   4351         OMX_PRDSP2(*dbg, "chromaQPIndexOffset = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.chromaQPIndexOffset);
   4352         OMX_PRDSP2(*dbg, "constrainedIntraPredEnable = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.constrainedIntraPredEnable);
   4353         OMX_PRDSP2(*dbg, "picOrderCountType = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.picOrderCountType);
   4354         OMX_PRDSP2(*dbg, "maxMVperMB = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.maxMVperMB);
   4355         OMX_PRDSP2(*dbg, "intra4x4EnableIdc = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.intra4x4EnableIdc);
   4356         OMX_PRDSP2(*dbg, "mvDataEnable = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.mvDataEnable);
   4357         OMX_PRDSP2(*dbg, "hierCodingEnable = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.hierCodingEnable);
   4358         OMX_PRDSP2(*dbg, "streamFormat = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.streamFormat);
   4359         OMX_PRDSP2(*dbg, "intraRefreshMethod = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.intraRefreshMethod);
   4360         OMX_PRDSP2(*dbg, "perceptualQuant = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.perceptualQuant);
   4361         OMX_PRDSP2(*dbg, "sceneChangeDet = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sceneChangeDet);
   4362         OMX_PRDSP2(*dbg, "numSliceASO = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.numSliceASO);
   4363         OMX_PRDSP2(*dbg, "numSliceGroups = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.numSliceGroups);
   4364         OMX_PRDSP2(*dbg, "sliceGroupMapType = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sliceGroupMapType);
   4365         OMX_PRDSP2(*dbg, "sliceGroupChangeDirectionFlag = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sliceGroupChangeDirectionFlag);
   4366         OMX_PRDSP2(*dbg, "sliceGroupChangeRate = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sliceGroupChangeRate);
   4367         OMX_PRDSP2(*dbg, "sliceGroupChangeCycle = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sliceGroupChangeCycle);
   4368         OMX_PRDSP2(*dbg, "ulFrameIndex = %lu\n", pUalgInpParams->ulFrameIndex);
   4369     }
   4370 }
   4371 
   4372 OMX_ERRORTYPE IsResolutionPlayable (OMX_U32 width, OMX_U32 height)
   4373 {
   4374     if (width  > WVGA_MAX_WIDTH || height > WVGA_MAX_HEIGHT)
   4375     {
   4376         return OMX_ErrorBadParameter;
   4377     }
   4378     return OMX_ErrorNone;
   4379 
   4380 }
   4381 
   4382 OMX_ERRORTYPE AddStateTransition(VIDENC_COMPONENT_PRIVATE* pComponentPrivate) {
   4383 
   4384     OMX_ERRORTYPE eError = OMX_ErrorNone;
   4385 
   4386     if(pthread_mutex_lock(&pComponentPrivate->mutexStateChangeRequest)) {
   4387        return OMX_ErrorUndefined;
   4388     }
   4389 
   4390     /* Increment state change request reference count */
   4391     pComponentPrivate->nPendingStateChangeRequests++;
   4392 
   4393     if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
   4394        return OMX_ErrorUndefined;
   4395     }
   4396 
   4397     return eError;
   4398 }
   4399 
   4400 OMX_ERRORTYPE RemoveStateTransition(VIDENC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BOOL bEnableSignal) {
   4401     OMX_ERRORTYPE eError = OMX_ErrorNone;
   4402 
   4403      /* Decrement state change request reference count*/
   4404     if(pthread_mutex_lock(&pComponentPrivate->mutexStateChangeRequest)) {
   4405        return OMX_ErrorUndefined;
   4406     }
   4407 
   4408     pComponentPrivate->nPendingStateChangeRequests--;
   4409 
   4410    /* If there are no more pending requests, signal the thread waiting on this*/
   4411     if(!pComponentPrivate->nPendingStateChangeRequests && bEnableSignal) {
   4412        pthread_cond_signal(&(pComponentPrivate->StateChangeCondition));
   4413     }
   4414 
   4415     if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
   4416        return OMX_ErrorUndefined;
   4417     }
   4418 
   4419     return eError;
   4420 }
   4421