Home | History | Annotate | Download | only in test
      1 
      2 /*
      3  *  Copyright 2001-2008 Texas Instruments - http://www.ti.com/
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 /* =============================================================================
     18 *             Texas Instruments OMAP(TM) Platform Software
     19 *  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
     20 *
     21 *  Use of this software is controlled by the terms and conditions found
     22 *  in the license agreement under which this software has been supplied.
     23 * =========================================================================== */
     24 /**
     25 * @file VideoEncTest.c
     26 *
     27 * This file implements OMX Component for MPEG-4 encoder that
     28 * is fully compliant with the OMX specification 1.5.
     29 *
     30 * @path  $(CSLPATH)\src
     31 *
     32 * @rev  0.1
     33 */
     34 /* -------------------------------------------------------------------------- */
     35 /* =============================================================================
     36 *!
     37 *! Revision History
     38 *! ===================================
     39 *!
     40 *! 02-Feb-2006 mf: Revisions appear in reverse chronological order;
     41 *! that is, newest first.  The date format is dd-Mon-yyyy.
     42 * =========================================================================== */
     43 #define _XOPEN_SOURCE 600
     44 
     45 #include <signal.h>
     46 #include <stdio.h>
     47 #include <stdlib.h>
     48 #include <stdarg.h>
     49 #include <string.h>
     50 #include <sched.h>
     51 #include <unistd.h>
     52 #include <sys/types.h>
     53 #include <sys/select.h>
     54 #include <time.h>
     55 #include <OMX_Component.h>
     56 #include <getopt.h>
     57 #include <sys/types.h>
     58 
     59 #define DSP_MMU_FAULT_HANDLING
     60 
     61 #ifdef DSP_MMU_FAULT_HANDLING
     62 #include <dbapi.h>
     63 #include <DSPManager.h>
     64 #include <DSPProcessor.h>
     65 #include <DSPProcessor_OEM.h>
     66 #endif
     67 
     68 /* For debug printing
     69    Add -DAPP_DEBUG to CFLAGS in test Makefile */
     70 #define KHRONOS_1_2
     71 #if VIDENCTEST_DEBUG
     72     #define VIDENCTEST_MAX_TIME_OUTS 1000000
     73     #define __VIDENCTEST_PRINT__
     74     #define __VIDENCTEST_DPRINT__
     75     #define __VIDENCTEST_MTRACE__
     76 #else
     77     #define VIDENCTEST_MAX_TIME_OUTS 1000000
     78 #endif
     79 #define VIDENCTEST_UNUSED_ARG(arg) (void)(arg)
     80 #if 0
     81     #define VIDENCTEST_COLOR
     82     #define VIDENCTEST_PRINT_PARAMS
     83 #endif
     84 
     85 #define VIDENCTEST_USE_DEFAULT_VALUE (OMX_U32)-1
     86 #define VIDENCTEST_USE_DEFAULT_VALUE_UI (unsigned int)-1
     87 
     88 #define VIDENCTEST_MALLOC(_p_, _s_, _c_, _h_)                           \
     89     _p_ = (_c_*)malloc(_s_);                                            \
     90     if (_p_ == NULL) {                                                  \
     91         VIDENCTEST_MTRACE("malloc() error.\n");                         \
     92         eError = OMX_ErrorInsufficientResources;                        \
     93     }                                                                   \
     94     else {                                                              \
     95         VIDENCTEST_MTRACE(": %d :malloc() -> %p\n", __LINE__, _p_);     \
     96         memset((_p_), 0x0, _s_);                                        \
     97         if ((_p_) == NULL) {                                            \
     98             VIDENCTEST_MTRACE("memset() error.\n");                     \
     99             eError = OMX_ErrorUndefined;                                \
    100         }                                                               \
    101         else{                                                           \
    102             eError = VIDENCTEST_ListAdd(_h_, _p_);                      \
    103             if (eError == OMX_ErrorInsufficientResources) {             \
    104                 VIDENCTEST_MTRACE("malloc() error.\n");                 \
    105             }                                                           \
    106         }                                                               \
    107     }                                                                   \
    108 
    109 
    110 #define VIDENCTEST_FREE(_p_, _h_)                           \
    111     VIDENCTEST_ListRemove(_h_, _p_);                        \
    112     _p_ = NULL;                                             \
    113 
    114 #define VIDENCTEST_CHECK_ERROR(_e_, _s_)                    \
    115     if (_e_ != OMX_ErrorNone){                              \
    116         printf("\n------VIDENCTEST FATAL ERROR-------\n %x : %s \n", _e_, _s_);  \
    117         VIDENCTEST_HandleError(pAppData, _e_);               \
    118         goto EXIT;                                          \
    119     }                                                       \
    120 
    121 #define VIDENCTEST_CHECK_EXIT(_e_, _s_)                     \
    122     if (_e_ != OMX_ErrorNone){                              \
    123         printf("\n------VIDENCTEST ERROR-------\n %x : %s \n", _e_, _s_);  \
    124         goto EXIT;                                          \
    125     }
    126 
    127 #if 1
    128     #define CALC_TIME
    129 #endif
    130 
    131 #define MAX_UNRESPONSIVE_COUNT 50
    132 #define NUM_OF_IN_BUFFERS 4
    133 #define NUM_OF_OUT_BUFFERS 4
    134 #define MAX_NUM_OF_PORTS 16
    135 #define MAX_EVENTS 256
    136 /*
    137  *  ANSI escape sequences for outputing text in various colors
    138  */
    139 #ifdef APP_COLOR
    140     #define DBG_TEXT_WHITE   "\x1b[1;37;40m"
    141     #define DBG_TEXT_YELLOW  "\x1b[1;33;40m"
    142     #define DBG_TEXT_MAGENTA "\x1b[1;35;40m"
    143     #define DBG_TEXT_GREEN   "\x1b[1;32;40m"
    144     #define DBG_TEXT_CYAN    "\x1b[1;36;40m"
    145     #define DBG_TEXT_RED     "\x1b[1;31;40m"
    146 #else
    147     #define DBG_TEXT_WHITE ""
    148     #define DBG_TEXT_YELLOW ""
    149     #define DBG_TEXT_MAGENTA ""
    150     #define DBG_TEXT_GREEN ""
    151     #define DBG_TEXT_CYAN ""
    152     #define DBG_TEXT_RED ""
    153 #endif
    154 
    155 #define APP_CONVERT_STATE(_s_, _p_)        \
    156     if (_p_ == 0) {                        \
    157         _s_ = "OMX_StateInvalid";          \
    158     }                                      \
    159     else if (_p_ == 1) {                   \
    160         _s_ = "OMX_StateLoaded";           \
    161     }                                      \
    162     else if (_p_ == 2) {                   \
    163         _s_ = "OMX_StateIdle";             \
    164     }                                      \
    165     else if (_p_ == 3) {                   \
    166         _s_ = "OMX_StateExecuting";        \
    167     }                                      \
    168     else if (_p_ == 4) {                   \
    169         _s_ = "OMX_StatePause";            \
    170     }                                      \
    171     else if (_p_ == 5) {                   \
    172         _s_ = "OMX_StateWaitForResources"; \
    173     }                                      \
    174     else {                                 \
    175         _s_ = "UnsupportedCommand";        \
    176     }
    177 
    178 
    179 /*static const int iQ16_Const = 1 << 16;*/
    180 static const float fQ16_Const = (float)(1 << 16);
    181 
    182 /*static float Q16Tof(int nQ16)
    183 {
    184     return nQ16 / fQ16_Const;
    185 }*/
    186 
    187 static int fToQ16(float f)
    188 {
    189     return (int)(f*fQ16_Const);
    190 }
    191 
    192 #ifdef DSP_MMU_FAULT_HANDLING
    193 static int bInvalid_state;
    194 int LoadBaseImage();
    195 #endif
    196 
    197 void VIDENCTEST_Log(const char *szFileName, int iLineNum, const char *szFunctionName, const char *strFormat, ...)
    198 {
    199     va_list list;
    200     VIDENCTEST_UNUSED_ARG(szFileName);
    201     VIDENCTEST_UNUSED_ARG(iLineNum);
    202     fprintf(stdout, "%s():", szFunctionName);
    203     va_start(list, strFormat);
    204     vfprintf(stdout, strFormat, list);
    205     va_end(list);
    206 }
    207 
    208 #ifdef __VIDENCTEST_DPRINT__
    209     #define VIDENCTEST_DPRINT(STR, ARG...) VIDENCTEST_Log(__FILE__, __LINE__, __FUNCTION__, STR, ##ARG)
    210 #else
    211     #define VIDENCTEST_DPRINT(...)
    212 #endif
    213 
    214 #ifdef __VIDENCTEST_MTRACE__
    215     #define VIDENCTEST_MTRACE(STR, ARG...) VIDENCTEST_Log(__FILE__, __LINE__, __FUNCTION__, STR, ##ARG)
    216 #else
    217     #define VIDENCTEST_MTRACE(...)
    218 #endif
    219 
    220 #ifdef __VIDENCTEST_PRINT__
    221     #define VIDENCTEST_PRINT(...) fprintf(stdout, __VA_ARGS__)
    222 #else
    223     #define VIDENCTEST_PRINT(...)
    224 #endif
    225 
    226 OMX_STRING StrVideoEncoder= "OMX.TI.Video.encoder";
    227 
    228 typedef enum VIDEOENC_PORT_INDEX {
    229     VIDENC_INPUT_PORT = 0x0,
    230     VIDENC_OUTPUT_PORT
    231 } VIDEOENC_PORT_INDEX;
    232 
    233 typedef enum VIDENCTEST_STATE {
    234     VIDENCTEST_StateLoaded = 0x0,
    235     VIDENCTEST_StateUnLoad,
    236     VIDENCTEST_StateReady,
    237     VIDENCTEST_StateStarting,
    238     VIDENCTEST_StateEncoding,
    239     VIDENCTEST_StateStopping,
    240     VIDENCTEST_StateConfirm,
    241     VIDENCTEST_StateWaitEvent,
    242     VIDENCTEST_StatePause,
    243     VIDENCTEST_StateStop,
    244     VIDENCTEST_StateError
    245 } VIDENCTEST_STATE;
    246 
    247 typedef enum VIDENCTEST_TEST_TYPE {
    248     VIDENCTEST_FullRecord = 0x0,
    249     VIDENCTEST_PartialRecord,
    250     VIDENCTEST_PauseResume,
    251     VIDENCTEST_StopRestart
    252 } VIDENCTEST_TEST_TYPE;
    253 
    254 typedef enum VIDENC_TEST_NAL_FORMAT {
    255     VIDENC_TEST_NAL_UNIT = 0,
    256     VIDENC_TEST_NAL_SLICE,
    257     VIDENC_TEST_NAL_FRAME
    258 }VIDENC_TEST_NAL_FORMAT;
    259 
    260 #ifndef KHRONOS_1_2
    261 typedef enum OMX_EXTRADATATYPE {
    262     OMX_ExtraDataNone = 0,
    263     OMX_ExtraDataQuantization
    264 } OMX_EXTRADATATYPE;
    265 #endif
    266 
    267 typedef struct OMX_OTHER_EXTRADATATYPE_1_1_2 {
    268     OMX_U32 nSize;
    269     OMX_VERSIONTYPE nVersion;
    270     OMX_U32 nPortIndex;
    271     OMX_EXTRADATATYPE eType;
    272     OMX_U32 nDataSize;
    273     OMX_U8 data[1];
    274 } OMX_OTHER_EXTRADATATYPE_1_1_2;
    275 
    276 typedef struct APP_TIME{
    277     time_t rawTime;
    278     struct tm* pTimeInfo;
    279     int nHrs;
    280     int nMin;
    281     int nSec;
    282     OMX_BOOL bInitTime;
    283     int nTotalTime;
    284 } APP_TIME;
    285 
    286 /* Structure used for the Memory List (Link-List)*/
    287 typedef struct VIDENCTEST_NODE {
    288     OMX_PTR pData;
    289     struct VIDENCTEST_NODE* pNext;
    290 }VIDENCTEST_NODE;
    291 
    292 typedef struct MYBUFFER_DATA{
    293     time_t rawTime;
    294     struct tm* pTimeInfo;
    295 } MYBUFFER_DATA;
    296 
    297 typedef struct MYDATATYPE {
    298     OMX_HANDLETYPE pHandle;
    299     char* szInFile;
    300     char* szOutFile;
    301     char* szOutFileNal;
    302     int nWidth;
    303     int nHeight;
    304     OMX_U8 eColorFormat;
    305     OMX_U32 nBitrate;
    306     OMX_U8 nFramerate;
    307     OMX_U8 eCompressionFormat;
    308     OMX_U8 eLevel;
    309     OMX_U32 nOutBuffSize;
    310     OMX_STATETYPE eState;
    311     OMX_PORT_PARAM_TYPE* pVideoInit;
    312     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef[MAX_NUM_OF_PORTS];
    313     OMX_PARAM_PORTDEFINITIONTYPE* pInPortDef;
    314     OMX_PARAM_PORTDEFINITIONTYPE* pOutPortDef;
    315     OMX_VIDEO_PARAM_AVCTYPE* pH264;
    316     OMX_VIDEO_AVCLEVELTYPE eLevelH264;
    317     OMX_VIDEO_PARAM_H263TYPE* pH263;
    318     OMX_VIDEO_H263LEVELTYPE eLevelH63;
    319     OMX_VIDEO_PARAM_MPEG4TYPE* pMpeg4;
    320     OMX_VIDEO_MPEG4LEVELTYPE eLevelMpeg4;
    321     int IpBuf_Pipe[2];
    322     int OpBuf_Pipe[2];
    323     int eventPipe[2];
    324     int fdmax;
    325     FILE* fIn;
    326     FILE* fOut;
    327     FILE* fNalnd;
    328     OMX_U32 nCurrentFrameIn;
    329     OMX_U32 nCurrentFrameOut;
    330     OMX_S32 nRetVal;
    331     OMX_CALLBACKTYPE* pCb;
    332     OMX_COMPONENTTYPE* pComponent;
    333     OMX_BUFFERHEADERTYPE* pInBuff[NUM_OF_IN_BUFFERS];
    334     OMX_BUFFERHEADERTYPE* pOutBuff[NUM_OF_OUT_BUFFERS];
    335     OMX_U8* pIBuffer[NUM_OF_IN_BUFFERS];
    336     OMX_U8* pOBuffer[NUM_OF_OUT_BUFFERS];
    337     OMX_VIDEO_PARAM_BITRATETYPE* pVidParamBitrate;
    338     OMX_VIDEO_CONTROLRATETYPE eControlRate;
    339     OMX_VIDEO_PARAM_QUANTIZATIONTYPE* pQuantization;
    340     OMX_U32 nQpI;
    341     OMX_BOOL bAllocateIBuf;
    342     OMX_BOOL bAllocateOBuf;
    343     OMX_INDEXTYPE nVideoEncodeCustomParamIndex;
    344     OMX_U32 nVBVSize;
    345     OMX_BOOL bDeblockFilter;
    346     OMX_BOOL bForceIFrame;
    347     OMX_U32 nIntraFrameInterval;
    348     OMX_U32 nGOBHeaderInterval;
    349     OMX_U32 nTargetFrameRate;
    350     OMX_U32 nAIRRate;
    351     OMX_U32 nTargetBitRate;
    352     OMX_U32 nStartPortNumber;
    353     OMX_U32 nPorts;
    354     OMX_U8 nInBufferCount;
    355     OMX_U8 nOutBufferCount;
    356     void* pEventArray[MAX_EVENTS];
    357     OMX_U8 nEventCount;
    358     OMX_BOOL bStop;
    359     OMX_BOOL bExit;
    360     OMX_U32 nSizeIn;
    361     OMX_U32 nSizeOut;
    362 
    363     OMX_U32 nReferenceFrame;
    364     OMX_U32 nNumberOfTimesTodo;
    365     OMX_U32 nNumberOfTimesDone;
    366     OMX_U32 nUnresponsiveCount;
    367     VIDENCTEST_NODE*  pMemoryListHead; /* Used in Memory List (Link-List) */
    368     VIDENCTEST_STATE eCurrentState;
    369     VIDENCTEST_TEST_TYPE eTypeOfTest;
    370     OMX_U32 nMIRRate;
    371     OMX_U32 nResynchMarkerSpacing;
    372     unsigned int nEncodingPreset;
    373     OMX_U8 nUnrestrictedMV;
    374     OMX_U8 NalFormat;
    375     OMX_U8 bLastOutBuffer;
    376     OMX_U32  nQPIoF;
    377 } MYDATATYPE;
    378 
    379 typedef struct EVENT_PRIVATE {
    380     OMX_EVENTTYPE eEvent;
    381     OMX_U32 nData1;
    382     OMX_U32 nData2;
    383     MYDATATYPE* pAppData;
    384     OMX_PTR pEventData;
    385 } EVENT_PRIVATE;
    386 
    387 /* safe routine to get the maximum of 2 integers */
    388 /* inline int maxint(int a, int b) */
    389 int maxint(int a, int b)
    390 {
    391     return(a>b) ? a : b;
    392 }
    393 
    394 /*-----------------------------------------------------------------------------*/
    395 /**
    396   * ListCreate()
    397   *
    398   * Creates the List Head of the Component Memory List.
    399   *
    400   * @param pListHead VIDENCTEST_NODE double pointer with the List Header of the Memory List.
    401   *
    402   * @retval OMX_ErrorNone
    403   *               OMX_ErrorInsufficientResources if the malloc fails
    404   *
    405   **/
    406 /*-----------------------------------------------------------------------------*/
    407 OMX_ERRORTYPE VIDENCTEST_ListCreate(struct VIDENCTEST_NODE** pListHead)
    408 {
    409     OMX_ERRORTYPE eError = OMX_ErrorNone;
    410 
    411     *pListHead = (VIDENCTEST_NODE*)malloc(sizeof(VIDENCTEST_NODE)); /* need to malloc!!! */
    412     if (*pListHead == NULL) {
    413         VIDENCTEST_DPRINT("malloc() error.\n");
    414         eError = OMX_ErrorInsufficientResources;
    415         goto EXIT;
    416     }
    417 
    418     VIDENCTEST_DPRINT("Create MemoryListHeader[%p]\n", *pListHead);
    419     memset(*pListHead, 0x0, sizeof(VIDENCTEST_NODE));
    420 
    421 EXIT:
    422     return eError;
    423 }
    424 
    425 /*-----------------------------------------------------------------------------*/
    426 /**
    427   * ListAdd()
    428   *
    429   * Add a new node to Component Memory List
    430   *
    431   * @param pListHead VIDENCTEST_NODE Points List Header of the Memory List.
    432   *                pData OMX_PTR points to the new allocated data.
    433   * @retval OMX_ErrorNone
    434   *               OMX_ErrorInsufficientResources if the malloc fails
    435   *
    436   **/
    437 /*-----------------------------------------------------------------------------*/
    438 
    439 OMX_ERRORTYPE VIDENCTEST_ListAdd(struct VIDENCTEST_NODE* pListHead, OMX_PTR pData)
    440 {
    441     OMX_ERRORTYPE eError = OMX_ErrorNone;
    442     VIDENCTEST_NODE* pTmp = NULL;
    443     VIDENCTEST_NODE* pNewNode = NULL;
    444 
    445     pNewNode = (VIDENCTEST_NODE*)malloc(sizeof(VIDENCTEST_NODE)); /* need to malloc!!! */
    446     if (pNewNode == NULL) {
    447         VIDENCTEST_DPRINT("malloc() error.\n");
    448         eError = OMX_ErrorInsufficientResources;
    449         goto EXIT;
    450     }
    451 
    452     memset(pNewNode, 0x0, sizeof(VIDENCTEST_NODE));
    453     pNewNode->pData = pData;
    454     pNewNode->pNext = NULL;
    455     VIDENCTEST_DPRINT("Add MemoryNode[%p] -> [%p]\n", pNewNode, pNewNode->pData);
    456 
    457     pTmp = pListHead;
    458 
    459     while (pTmp->pNext != NULL) {
    460         pTmp = pTmp->pNext;
    461     }
    462     pTmp->pNext = pNewNode;
    463 
    464 EXIT:
    465     return eError;
    466 }
    467 
    468 /*-----------------------------------------------------------------------------*/
    469 /**
    470   * ListRemove()
    471   *
    472   * Called inside VIDENC_FREE Macro remove  node from Component Memory List and free the memory pointed by the node.
    473   *
    474   * @param pListHead VIDENCTEST_NODE Points List Header of the Memory List.
    475   *                pData OMX_PTR points to the new allocated data.
    476   * @retval OMX_ErrorNone
    477   *
    478   *
    479   **/
    480 /*-----------------------------------------------------------------------------*/
    481 
    482 OMX_ERRORTYPE VIDENCTEST_ListRemove(struct VIDENCTEST_NODE* pListHead, OMX_PTR pData)
    483 {
    484     OMX_ERRORTYPE eError = OMX_ErrorNone;
    485     VIDENCTEST_NODE* pNode = NULL;
    486     VIDENCTEST_NODE* pTmp = NULL;
    487 
    488     pNode = pListHead;
    489 
    490     while (pNode->pNext != NULL) {
    491         if (pNode->pNext->pData == pData) {
    492             pTmp = pNode->pNext;
    493             pNode->pNext = pTmp->pNext;
    494             VIDENCTEST_DPRINT("Remove MemoryNode[%p] -> [%p]\n", pTmp, pTmp->pData);
    495             free(pTmp->pData);
    496             free(pTmp);
    497             pTmp = NULL;
    498             break;
    499             /* VIDENC_ListPrint2(pListHead); */
    500         }
    501         pNode = pNode->pNext;
    502     }
    503     return eError;
    504 }
    505 
    506 /*-----------------------------------------------------------------------------*/
    507 /**
    508   * ListDestroy()
    509   *
    510   * Called inside OMX_ComponentDeInit()  Remove all nodes and free all the memory in the Component Memory List.
    511   *
    512   * @param pListHead VIDENCTEST_NODE Points List Header of the Memory List.
    513   *
    514   * @retval OMX_ErrorNone
    515   *
    516   *
    517   **/
    518 /*-----------------------------------------------------------------------------*/
    519 
    520 OMX_ERRORTYPE VIDENCTEST_ListDestroy(struct VIDENCTEST_NODE* pListHead)
    521 {
    522     OMX_ERRORTYPE eError = OMX_ErrorNone;
    523     VIDENCTEST_NODE* pTmp = NULL;
    524     VIDENCTEST_NODE* pNode = NULL;
    525     pNode = pListHead;
    526 
    527     while (pNode->pNext != NULL) {
    528         pTmp = pNode->pNext;
    529         if (pTmp->pData != NULL) {
    530             VIDENCTEST_FREE(pTmp->pData, pListHead);
    531         }
    532         pNode->pNext = pTmp->pNext;
    533         VIDENCTEST_FREE(pTmp, pListHead);
    534     }
    535 
    536     VIDENCTEST_DPRINT("Destroy MemoryListHeader[%p]\n", pListHead);
    537     free(pListHead);
    538     return eError;
    539 }
    540 
    541 /*-----------------------------------------------------------------------------*/
    542 /**
    543   * EventHandler(  )
    544   *
    545   * Called inside OMX_ComponentDeInit()  Remove all nodes and free all the memory in the Component Memory List.
    546   *
    547   * @param pListHead VIDENCTEST_NODE Points List Header of the Memory List.
    548   *
    549   * @retval OMX_ErrorNone
    550   *
    551   *
    552   **/
    553 /*-----------------------------------------------------------------------------*/
    554 void VIDENCTEST_EventHandler(OMX_HANDLETYPE hComponent, MYDATATYPE* pAppData, OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2, OMX_PTR pEventData)
    555 {
    556     EVENT_PRIVATE* pEventPrivate = NULL;
    557     OMX_ERRORTYPE eError = OMX_ErrorNone;
    558     OMX_HANDLETYPE pHandle;
    559     VIDENCTEST_NODE* pListHead;
    560 
    561     pHandle= pAppData->pHandle;
    562     pListHead = pAppData->pMemoryListHead;
    563     VIDENCTEST_UNUSED_ARG(hComponent);
    564     VIDENCTEST_MALLOC(pEventPrivate, sizeof(EVENT_PRIVATE), EVENT_PRIVATE, pListHead);
    565 
    566     /* TODO: Optimize using a linked list */
    567     pAppData->pEventArray[pAppData->nEventCount] = pEventPrivate;
    568     pAppData->nEventCount++;
    569     if(eError != OMX_ErrorNone)
    570         VIDENCTEST_DPRINT("Erro in function VIDENCTEST_EventHandler\n");
    571     else{
    572     pEventPrivate->pAppData = pAppData;
    573     pEventPrivate->eEvent = eEvent;
    574     pEventPrivate->nData1 = nData1;
    575     pEventPrivate->nData2 = nData2;
    576     pEventPrivate->pEventData = pEventData;
    577 
    578     write(pAppData->eventPipe[1], &pEventPrivate, sizeof(pEventPrivate));
    579     }
    580 }
    581 
    582 /*-----------------------------------------------------------------------------*/
    583 /**
    584   * FillBufferDone()
    585   *
    586   * Callback function when output buffer is done fill with h.264/mpeg4/h.263 data
    587   *
    588   * @param
    589   *
    590   * @retval OMX_ErrorNone
    591   *
    592   *
    593   **/
    594 /*-----------------------------------------------------------------------------*/
    595 void VIDENCTEST_FillBufferDone(OMX_HANDLETYPE hComponent, MYDATATYPE* pAppData, OMX_BUFFERHEADERTYPE* pBuffer)
    596 {
    597     VIDENCTEST_UNUSED_ARG(hComponent);
    598     VIDENCTEST_DPRINT("FillBufferDone :: %p \n", pBuffer);
    599     write(pAppData->OpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
    600 }
    601 
    602 /*-----------------------------------------------------------------------------*/
    603 /**
    604   * EmptyBufferDone()
    605   *
    606   * Callback function when and input buffer has been encoded. Returns an Empty Buffer.
    607   *
    608   * @param
    609   *
    610   * @retval OMX_ErrorNone
    611   *
    612   *
    613   **/
    614 /*-----------------------------------------------------------------------------*/
    615 void VIDENCTEST_EmptyBufferDone(OMX_HANDLETYPE hComponent, MYDATATYPE* pAppData, OMX_BUFFERHEADERTYPE* pBuffer)
    616 {
    617     VIDENCTEST_UNUSED_ARG(hComponent);
    618     VIDENCTEST_DPRINT("EmptyBufferDone :: %p \n", pBuffer);
    619     write(pAppData->IpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
    620 }
    621 
    622 /*-----------------------------------------------------------------------------*/
    623 /**
    624   * fill_data()
    625   *
    626   * Fill buffer with data from the input file (YUV data 420/422 little endian/ 422 big endian).
    627   *
    628   * @param
    629   *
    630   * @retval OMX_ErrorNone
    631   *
    632   *
    633   **/
    634 /*-----------------------------------------------------------------------------*/
    635 int VIDENCTEST_fill_data(OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn, int buffersize)
    636 {
    637     int nRead = -1;
    638     int nError = 0;
    639 
    640     /* Input video frame format: YUV422 interleaved (1) or YUV420 (0) */
    641     nRead = fread(pBuf->pBuffer,1, buffersize, fIn);
    642     if (nRead == -1) {
    643         VIDENCTEST_DPRINT("Error Reading File!\n");
    644     }
    645     nError = ferror(fIn);
    646     if (nError != 0) {
    647         VIDENCTEST_DPRINT("ERROR: reading file\n");
    648     }
    649     nError = feof(fIn);
    650     if (nError != 0 ) {
    651         VIDENCTEST_DPRINT("EOS reached...\n");
    652     }
    653 
    654     pBuf->nFilledLen = nRead;
    655     if (feof(fIn)) {
    656         VIDENCTEST_DPRINT("Setting OMX_BUFFERFLAGE_EOS -> %p\n", pBuf);
    657         pBuf->nFlags = OMX_BUFFERFLAG_EOS;
    658     }
    659     return nRead;
    660 }
    661 
    662 /*-----------------------------------------------------------------------------*/
    663 /**
    664   * HandleError()
    665   *
    666   * Function call when an error ocurrs. The function un-load and free all the resource
    667   * depending the eError recieved.
    668   * @param pHandle Handle of MYDATATYPE structure
    669   * @param eError Error ocurred.
    670  *
    671   * @retval OMX_ErrorNone
    672   *
    673   *
    674   **/
    675 /*-----------------------------------------------------------------------------*/
    676 
    677 OMX_ERRORTYPE VIDENCTEST_HandleError(MYDATATYPE* pAppData, OMX_ERRORTYPE eError)
    678 {
    679     OMX_ERRORTYPE eErrorHandleError = OMX_ErrorNone;
    680     OMX_HANDLETYPE pHandle = pAppData->pHandle;
    681     OMX_U32 nCounter;
    682     VIDENCTEST_NODE* pListHead;
    683     OMX_ERRORTYPE eErr = OMX_ErrorNone;
    684 
    685     VIDENCTEST_DPRINT ("Enters to HandleError\n");
    686     pListHead = pAppData->pMemoryListHead;
    687 
    688     switch (pAppData->eCurrentState) {
    689         case VIDENCTEST_StateReady:
    690         case VIDENCTEST_StateStarting:
    691         case VIDENCTEST_StateEncoding:
    692         case VIDENCTEST_StateStopping:
    693         case VIDENCTEST_StateConfirm:
    694         case VIDENCTEST_StatePause:
    695         case VIDENCTEST_StateStop:
    696         case VIDENCTEST_StateWaitEvent:
    697          VIDENCTEST_DPRINT ("Free buffers\n");
    698             if (pAppData->bAllocateOBuf == OMX_TRUE) {
    699                 for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
    700                     pAppData->pOBuffer[nCounter] -= 128;
    701                     pAppData->pOBuffer[nCounter] = (unsigned char*)pAppData->pOBuffer[nCounter];
    702                     VIDENCTEST_FREE(pAppData->pOBuffer[nCounter], pListHead);
    703                     pAppData->pOBuffer[nCounter] = NULL;
    704                 }
    705             }
    706             for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
    707                 eError = OMX_FreeBuffer(pHandle, pAppData->pOutPortDef->nPortIndex, pAppData->pOutBuff[nCounter]);
    708             }
    709             if (pAppData->bAllocateIBuf == OMX_TRUE) {
    710                 for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
    711                     pAppData->pIBuffer[nCounter] -= 128;
    712                     pAppData->pIBuffer[nCounter] = (unsigned char*)pAppData->pIBuffer[nCounter];
    713                     VIDENCTEST_FREE(pAppData->pIBuffer[nCounter], pListHead);
    714                     pAppData->pIBuffer[nCounter] = NULL;
    715                 }
    716             }
    717             for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
    718                 eError = OMX_FreeBuffer(pHandle, pAppData->pInPortDef->nPortIndex, pAppData->pInBuff[nCounter]);
    719             }
    720         case VIDENCTEST_StateLoaded:
    721             VIDENCTEST_DPRINT ("DeInit Component\n");
    722             eErrorHandleError = TIOMX_FreeHandle(pHandle);
    723             VIDENCTEST_CHECK_EXIT(eErrorHandleError, "Error at TIOMX_FreeHandle function");
    724             eErrorHandleError = TIOMX_Deinit();
    725             VIDENCTEST_CHECK_EXIT(eErrorHandleError, "Error at TIOMX_Deinit function");
    726             fclose(pAppData->fIn);
    727             fclose(pAppData->fOut);
    728             if(pAppData->NalFormat == VIDENC_TEST_NAL_FRAME || pAppData->NalFormat == VIDENC_TEST_NAL_SLICE) {
    729                 fclose(pAppData->fNalnd);
    730             }
    731 
    732             eErr = close(pAppData->IpBuf_Pipe[0]);
    733             if (0 != eErr && OMX_ErrorNone == eError) {
    734                 eError = OMX_ErrorHardware;
    735                 VIDENCTEST_DPRINT ("Error while closing data pipe\n");
    736             }
    737 
    738             eErr = close(pAppData->OpBuf_Pipe[0]);
    739             if (0 != eErr && OMX_ErrorNone == eError) {
    740                 eError = OMX_ErrorHardware;
    741                 VIDENCTEST_DPRINT ("Error while closing data pipe\n");
    742             }
    743 
    744             eErr = close(pAppData->eventPipe[0]);
    745             if (0 != eErr && OMX_ErrorNone == eError) {
    746                 eError = OMX_ErrorHardware;
    747                 VIDENCTEST_DPRINT ("Error while closing data pipe\n");
    748             }
    749 
    750             eErr = close(pAppData->IpBuf_Pipe[1]);
    751             if (0 != eErr && OMX_ErrorNone == eError) {
    752                 eError = OMX_ErrorHardware;
    753                 VIDENCTEST_DPRINT ("Error while closing data pipe\n");
    754             }
    755 
    756             eErr = close(pAppData->OpBuf_Pipe[1]);
    757             if (0 != eErr && OMX_ErrorNone == eError) {
    758                 eError = OMX_ErrorHardware;
    759                 VIDENCTEST_DPRINT ("Error while closing data pipe\n");
    760             }
    761 
    762             eErr = close(pAppData->eventPipe[1]);
    763             if (0 != eErr && OMX_ErrorNone == eError) {
    764                 eError = OMX_ErrorHardware;
    765                 VIDENCTEST_DPRINT ("Error while closing data pipe\n");
    766             }
    767             pAppData->fIn = NULL;
    768             pAppData->fOut = NULL;
    769             pAppData->fNalnd = NULL;
    770         case VIDENCTEST_StateUnLoad:
    771             VIDENCTEST_DPRINT ("Free Resources\n");
    772             VIDENCTEST_ListDestroy(pListHead);
    773         default:
    774             ;
    775     }
    776 
    777 #ifdef DSP_MMU_FAULT_HANDLING
    778     if(bInvalid_state == OMX_TRUE)
    779     {
    780         LoadBaseImage();
    781     }
    782 #endif
    783 
    784 EXIT:
    785     return eErrorHandleError;
    786 }
    787 
    788 /*-----------------------------------------------------------------------------*/
    789 /**
    790   * SetH264Parameter()
    791   *
    792   * Initialize H264 Parameters.
    793   *
    794   * @param pAppData
    795   *
    796   * @retval OMX_ErrorNone
    797   *
    798   *
    799   **/
    800 /*-----------------------------------------------------------------------------*/
    801 OMX_ERRORTYPE VIDENCTEST_SetH264Parameter(MYDATATYPE* pAppData)
    802 {
    803     OMX_ERRORTYPE eError = OMX_ErrorNone;
    804     OMX_HANDLETYPE pHandle = pAppData->pHandle;
    805 
    806     /* Set the component's OMX_PARAM_PORTDEFINITIONTYPE structure (input) */
    807     /**********************************************************************/
    808     pAppData->pInPortDef->nBufferCountActual = NUM_OF_IN_BUFFERS;
    809     pAppData->pInPortDef->nBufferCountMin = 1;
    810     pAppData->pInPortDef->bEnabled = OMX_TRUE;
    811     pAppData->pInPortDef->bPopulated = OMX_FALSE;
    812     pAppData->pInPortDef->eDomain = OMX_PortDomainVideo;
    813 
    814     /* OMX_VIDEO_PORTDEFINITION values for input port */
    815     pAppData->pInPortDef->format.video.cMIMEType = "yuv";
    816     pAppData->pInPortDef->format.video.pNativeRender = NULL;
    817     pAppData->pInPortDef->format.video.nStride = -1;
    818     pAppData->pInPortDef->format.video.nSliceHeight = -1;
    819     pAppData->pInPortDef->format.video.xFramerate = fToQ16(pAppData->nFramerate);
    820     pAppData->pInPortDef->format.video.bFlagErrorConcealment = OMX_FALSE;
    821     pAppData->pInPortDef->format.video.eColorFormat = pAppData->eColorFormat;
    822     pAppData->pInPortDef->format.video.nFrameWidth = pAppData->nWidth;
    823     pAppData->pInPortDef->format.video.nFrameHeight = pAppData->nHeight;
    824 
    825 
    826 
    827     eError = OMX_SetParameter(pHandle, OMX_IndexParamPortDefinition, pAppData->pInPortDef);
    828     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
    829 
    830     /* To get nBufferSize */
    831     eError = OMX_GetParameter(pHandle, OMX_IndexParamPortDefinition, pAppData->pInPortDef);
    832     VIDENCTEST_CHECK_EXIT(eError, "Error at GetParameter");
    833 
    834     pAppData->nSizeIn = pAppData->pInPortDef->nBufferSize;
    835 
    836     /* Set the component's OMX_VIDEO_PARAM_AVCTYPE structure (output) */
    837     /*************************************************************/
    838     memset(pAppData->pH264, 0x0, sizeof(OMX_VIDEO_PARAM_AVCTYPE));
    839     pAppData->pH264->nSize = sizeof(OMX_VIDEO_PARAM_AVCTYPE);
    840     pAppData->pH264->nVersion.s.nVersionMajor = 0x1;
    841     pAppData->pH264->nVersion.s.nVersionMinor = 0x0;
    842     pAppData->pH264->nVersion.s.nRevision = 0x0;
    843     pAppData->pH264->nVersion.s.nStep = 0x0;
    844     pAppData->pH264->nPortIndex = VIDENC_OUTPUT_PORT;
    845     pAppData->pH264->nSliceHeaderSpacing = 0;
    846     pAppData->pH264->nPFrames = -1;
    847     pAppData->pH264->nBFrames = -1;
    848     pAppData->pH264->bUseHadamard = 0;
    849     pAppData->pH264->nRefFrames = -1;
    850     pAppData->pH264->nRefIdx10ActiveMinus1 = -1;
    851     pAppData->pH264->nRefIdx11ActiveMinus1 = -1;
    852     pAppData->pH264->bEnableUEP = OMX_FALSE;
    853     pAppData->pH264->bEnableFMO = OMX_FALSE;
    854     pAppData->pH264->bEnableASO = OMX_FALSE;
    855     pAppData->pH264->bEnableRS = OMX_FALSE;
    856     pAppData->pH264->eProfile = OMX_VIDEO_AVCProfileBaseline;
    857     pAppData->pH264->nAllowedPictureTypes = -1;
    858     pAppData->pH264->bFrameMBsOnly = OMX_FALSE;
    859     pAppData->pH264->bMBAFF = OMX_FALSE;
    860     pAppData->pH264->bEntropyCodingCABAC = OMX_FALSE;
    861     pAppData->pH264->bWeightedPPrediction = OMX_FALSE;
    862     pAppData->pH264->nWeightedBipredicitonMode = -1;
    863     pAppData->pH264->bconstIpred = OMX_FALSE;
    864     pAppData->pH264->bDirect8x8Inference = OMX_FALSE;
    865     pAppData->pH264->bDirectSpatialTemporal = OMX_FALSE;
    866     pAppData->pH264->nCabacInitIdc = -1;
    867     pAppData->pH264->eLoopFilterMode = OMX_VIDEO_AVCLoopFilterDisable;
    868     pAppData->pH264->eLevel = pAppData->eLevelH264;
    869 
    870     eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoAvc, pAppData->pH264);
    871     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
    872 
    873     /* Set the component's OMX_PARAM_PORTDEFINITIONTYPE structure (output) */
    874     /***********************************************************************/
    875     /*memset(pAppData->pOutPortDef, 0x1, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
    876     pAppData->pOutPortDef->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
    877     pAppData->pOutPortDef->nVersion.s.nVersionMajor = 0x1;
    878     pAppData->pOutPortDef->nVersion.s.nVersionMinor = 0x0;
    879     pAppData->pOutPortDef->nVersion.s.nRevision = 0x0;
    880     pAppData->pOutPortDef->nVersion.s.nStep = 0x0;
    881     pAppData->pOutPortDef->nPortIndex = VIDENC_OUTPUT_PORT;
    882     pAppData->pOutPortDef->eDir = OMX_DirOutput;*/
    883     pAppData->pOutPortDef->nBufferCountActual = NUM_OF_OUT_BUFFERS;
    884     pAppData->pOutPortDef->nBufferCountMin = 1;
    885     /*pAppData->pOutPortDef->nBufferSize = pAppData->nOutBuffSize;*/
    886     pAppData->pOutPortDef->bEnabled = OMX_TRUE;
    887     pAppData->pOutPortDef->bPopulated = OMX_FALSE;
    888     pAppData->pOutPortDef->eDomain = OMX_PortDomainVideo;
    889 
    890     /* OMX_VIDEO_PORTDEFINITION values for input port */
    891     pAppData->pOutPortDef->format.video.cMIMEType = "264";
    892     pAppData->pOutPortDef->format.video.pNativeRender = NULL;
    893     pAppData->pOutPortDef->format.video.nFrameWidth = pAppData->nWidth;
    894     pAppData->pOutPortDef->format.video.nFrameHeight = pAppData->nHeight;
    895     pAppData->pOutPortDef->format.video.nStride = 0;
    896     pAppData->pOutPortDef->format.video.nSliceHeight = 0;
    897     pAppData->pOutPortDef->format.video.nBitrate = pAppData->nBitrate;
    898     pAppData->pOutPortDef->format.video.xFramerate = 0;
    899     pAppData->pOutPortDef->format.video.bFlagErrorConcealment = OMX_FALSE;
    900     pAppData->pOutPortDef->format.video.eCompressionFormat = pAppData->eCompressionFormat;
    901 
    902     eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pAppData->pOutPortDef);
    903     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
    904 
    905     /* Retreive nBufferSize */
    906     eError = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, pAppData->pOutPortDef);
    907     VIDENCTEST_CHECK_EXIT(eError, "Error at GetParameter");
    908 
    909     pAppData->nSizeOut = pAppData->pOutPortDef->nBufferSize;
    910 
    911     /* Set the component's OMX_VIDEO_PARAM_BITRATETYPE structure (output) */
    912     /*************************************************************/
    913     pAppData->pVidParamBitrate->nSize = sizeof(OMX_VIDEO_PARAM_BITRATETYPE);
    914     pAppData->pVidParamBitrate->nVersion.s.nVersionMajor = 0x1;
    915     pAppData->pVidParamBitrate->nVersion.s.nVersionMinor = 0x0;
    916     pAppData->pVidParamBitrate->nVersion.s.nRevision = 0x0;
    917     pAppData->pVidParamBitrate->nVersion.s.nStep = 0x0;
    918     pAppData->pVidParamBitrate->nPortIndex = VIDENC_OUTPUT_PORT;
    919     pAppData->pVidParamBitrate->eControlRate = pAppData->eControlRate;
    920     pAppData->pVidParamBitrate->nTargetBitrate = pAppData->pOutPortDef->format.video.nBitrate;
    921 
    922     /* TODO: need to convert what value DSP is expecting to equivalent OMX value */
    923     eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoBitrate, pAppData->pVidParamBitrate);
    924     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
    925 
    926     /* Set the component's OMX_VIDEO_PARAM_QUANTIZATIONTYPE structure (output) */
    927     /*************************************************************/
    928     pAppData->pQuantization->nSize = sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE);
    929     pAppData->pQuantization->nVersion.s.nVersionMajor = 0x1;
    930     pAppData->pQuantization->nVersion.s.nVersionMinor = 0x0;
    931     pAppData->pQuantization->nVersion.s.nRevision = 0x0;
    932     pAppData->pQuantization->nVersion.s.nStep = 0x0;
    933     pAppData->pQuantization->nPortIndex = VIDENC_OUTPUT_PORT;
    934     pAppData->pQuantization->nQpI = pAppData->nQpI;
    935 
    936     eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoQuantization, pAppData->pQuantization);
    937     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
    938 
    939     /* SR12020: Set H.264 encode Deblocking Filter using the custom OMX index */
    940     eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Param.DeblockFilter", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
    941     VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
    942 
    943     eError = OMX_SetParameter(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->bDeblockFilter));
    944     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
    945 
    946     if(pAppData->nEncodingPreset!=VIDENCTEST_USE_DEFAULT_VALUE_UI && pAppData->nEncodingPreset<=4){
    947         printf("EncodingPreset %d selected\n", pAppData->nEncodingPreset);
    948         eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.EncodingPreset", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
    949         VIDENCTEST_CHECK_EXIT(eError, "OMX_GetExtensionIndex function");
    950         eError = OMX_SetParameter(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nEncodingPreset));
    951         VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for nEncodingPreset");
    952     }
    953 
    954     if(pAppData->nUnrestrictedMV != (OMX_U8)VIDENCTEST_USE_DEFAULT_VALUE_UI){
    955         printf("nUnrestrictedMV %d selected\n", pAppData->nUnrestrictedMV);
    956         eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.UnrestrictedMV", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
    957         VIDENCTEST_CHECK_EXIT(eError, "OMX_GetExtensionIndex function");
    958         eError = OMX_SetParameter(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nUnrestrictedMV));
    959         VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for nUnrestrictedMV");
    960     }
    961 
    962     eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.NALFormat", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
    963     VIDENCTEST_CHECK_EXIT(eError, "OMX_GetExtensionIndex function");
    964     eError = OMX_SetParameter(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->NalFormat));
    965     VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for NalFormat");
    966 
    967 EXIT:
    968     return eError;
    969 }
    970 
    971 /*-----------------------------------------------------------------------------*/
    972 /**
    973   * SetMpeg4Parameter()
    974   *
    975   * Intialize Mpeg4 structures.
    976   *
    977   * @param pAppData
    978   *
    979   * @retval OMX_ErrorNone
    980   *
    981   *
    982   **/
    983 /*-----------------------------------------------------------------------------*/
    984 OMX_ERRORTYPE VIDENCTEST_SetMpeg4Parameter(MYDATATYPE* pAppData)
    985 {
    986     OMX_ERRORTYPE eError = OMX_ErrorNone;
    987     OMX_HANDLETYPE pHandle = pAppData->pHandle;
    988 
    989     /* Set the component's OMX_PARAM_PORTDEFINITIONTYPE structure (input) */
    990     /**********************************************************************/
    991     pAppData->pInPortDef->nBufferCountActual = NUM_OF_IN_BUFFERS;
    992     pAppData->pInPortDef->nBufferCountMin = 2;
    993     pAppData->pInPortDef->bEnabled = OMX_TRUE;
    994     pAppData->pInPortDef->bPopulated = OMX_FALSE;
    995     pAppData->pInPortDef->eDomain = OMX_PortDomainVideo;
    996 
    997     /* OMX_VIDEO_PORTDEFINITION values for input port */
    998     pAppData->pInPortDef->format.video.cMIMEType = "yuv";
    999     pAppData->pInPortDef->format.video.pNativeRender = NULL;
   1000     pAppData->pInPortDef->format.video.nStride = -1;
   1001     pAppData->pInPortDef->format.video.nSliceHeight = -1;
   1002     pAppData->pInPortDef->format.video.xFramerate = fToQ16(pAppData->nFramerate);
   1003     pAppData->pInPortDef->format.video.bFlagErrorConcealment = OMX_FALSE;
   1004     pAppData->pInPortDef->format.video.eColorFormat = pAppData->eColorFormat;
   1005     pAppData->pInPortDef->format.video.nFrameWidth = pAppData->nWidth;
   1006     pAppData->pInPortDef->format.video.nFrameHeight = pAppData->nHeight;
   1007 
   1008     eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pAppData->pInPortDef);
   1009     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
   1010 
   1011     /* To get nBufferSize */
   1012     eError = OMX_GetParameter(pHandle, OMX_IndexParamPortDefinition, pAppData->pInPortDef);
   1013     VIDENCTEST_CHECK_EXIT(eError, "Error at GetParameter");
   1014 
   1015     pAppData->nSizeIn = pAppData->pInPortDef->nBufferSize;
   1016 
   1017     /* Set the component's OMX_PARAM_PORTDEFINITIONTYPE structure (output) */
   1018     /*************************************************************/
   1019     pAppData->pOutPortDef->nBufferCountActual = NUM_OF_OUT_BUFFERS;
   1020     pAppData->pOutPortDef->nBufferCountMin = 1;
   1021     pAppData->pOutPortDef->bEnabled = OMX_TRUE;
   1022     pAppData->pOutPortDef->bPopulated = OMX_FALSE;
   1023     pAppData->pOutPortDef->eDomain = OMX_PortDomainVideo;
   1024 
   1025     /* OMX_VIDEO_PORTDEFINITION values for input port */
   1026     pAppData->pOutPortDef->format.video.cMIMEType = "mp4";
   1027     pAppData->pOutPortDef->format.video.pNativeRender = NULL;
   1028     pAppData->pOutPortDef->format.video.nFrameWidth = pAppData->nWidth;
   1029     pAppData->pOutPortDef->format.video.nFrameHeight = pAppData->nHeight;
   1030     pAppData->pOutPortDef->format.video.nStride = 0;
   1031     pAppData->pOutPortDef->format.video.nSliceHeight = 0;
   1032     pAppData->pOutPortDef->format.video.nBitrate = pAppData->nBitrate;
   1033     pAppData->pOutPortDef->format.video.xFramerate = 0;
   1034     pAppData->pOutPortDef->format.video.bFlagErrorConcealment = OMX_FALSE;
   1035     pAppData->pOutPortDef->format.video.eCompressionFormat = pAppData->eCompressionFormat;
   1036 
   1037     eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pAppData->pOutPortDef);
   1038     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
   1039 
   1040     /* Retreive nBufferSize */
   1041     eError = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, pAppData->pOutPortDef);
   1042     VIDENCTEST_CHECK_EXIT(eError, "Error at GetParameter");
   1043 
   1044     pAppData->nSizeOut = pAppData->pOutPortDef->nBufferSize;
   1045 
   1046     /* Set the component's OMX_VIDEO_PARAM_BITRATETYPE structure (output) */
   1047     /*************************************************************/
   1048     pAppData->pVidParamBitrate->nSize = sizeof(OMX_VIDEO_PARAM_BITRATETYPE);
   1049     pAppData->pVidParamBitrate->nVersion.s.nVersionMajor = 0x1;
   1050     pAppData->pVidParamBitrate->nVersion.s.nVersionMinor = 0x0;
   1051     pAppData->pVidParamBitrate->nVersion.s.nRevision = 0x0;
   1052     pAppData->pVidParamBitrate->nVersion.s.nStep = 0x0;
   1053     pAppData->pVidParamBitrate->nPortIndex = VIDENC_OUTPUT_PORT;
   1054     pAppData->pVidParamBitrate->eControlRate = pAppData->eControlRate;
   1055     pAppData->pVidParamBitrate->nTargetBitrate = pAppData->pOutPortDef->format.video.nBitrate;
   1056 
   1057     /* TODO: need to convert what value DSP is expecting to equivalent OMX value */
   1058 
   1059     eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoBitrate, pAppData->pVidParamBitrate);
   1060     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
   1061 
   1062     /* Set the component's OMX_VIDEO_PARAM_H263TYPE structure (output) */
   1063     /*************************************************************/
   1064     if (pAppData->eCompressionFormat == OMX_VIDEO_CodingH263) {
   1065         pAppData->pH263->nSize = sizeof(OMX_VIDEO_PARAM_H263TYPE);
   1066         pAppData->pH263->nVersion.s.nVersionMajor = 0x1;
   1067         pAppData->pH263->nVersion.s.nVersionMinor = 0x0;
   1068         pAppData->pH263->nVersion.s.nRevision = 0x0;
   1069         pAppData->pH263->nVersion.s.nStep = 0x0;
   1070         pAppData->pH263->nPortIndex = VIDENC_OUTPUT_PORT;
   1071         pAppData->pH263->eLevel = pAppData->eLevelH63;
   1072         pAppData->pH263->nGOBHeaderInterval = pAppData->nGOBHeaderInterval;
   1073 
   1074         eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoH263, pAppData->pH263);
   1075         VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
   1076     }
   1077 
   1078     /* Set the component's OMX_VIDEO_PARAM_QUANTIZATIONTYPE structure (output) */
   1079     /*************************************************************/
   1080     pAppData->pQuantization->nSize = sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE);
   1081     pAppData->pQuantization->nVersion.s.nVersionMajor = 0x1;
   1082     pAppData->pQuantization->nVersion.s.nVersionMinor = 0x0;
   1083     pAppData->pQuantization->nVersion.s.nRevision = 0x0;
   1084     pAppData->pQuantization->nVersion.s.nStep = 0x0;
   1085     pAppData->pQuantization->nPortIndex = VIDENC_OUTPUT_PORT;
   1086     pAppData->pQuantization->nQpI = pAppData->nQpI;
   1087 
   1088     eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoQuantization, pAppData->pQuantization);
   1089     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
   1090 
   1091     /* Set the component's OMX_VIDEO_PARAM_MPEG4TYPE structure (output) */
   1092     /*************************************************************/
   1093     if (pAppData->eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
   1094         pAppData->pMpeg4->nSize = sizeof(OMX_VIDEO_PARAM_MPEG4TYPE);
   1095         pAppData->pMpeg4->nVersion.s.nVersionMajor = 0x1;
   1096         pAppData->pMpeg4->nVersion.s.nVersionMinor = 0x0;
   1097         pAppData->pMpeg4->nVersion.s.nRevision = 0x0;
   1098         pAppData->pMpeg4->nVersion.s.nStep = 0x0;
   1099         pAppData->pMpeg4->nPortIndex = VIDENC_OUTPUT_PORT;
   1100         pAppData->pMpeg4->eLevel = pAppData->eLevelMpeg4;
   1101 
   1102         eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoMpeg4, pAppData->pMpeg4);
   1103         VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
   1104     }
   1105 
   1106     /* SR10527: Set MPEG4/H263 encode VBV Size using the custom OMX index */
   1107     eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Param.VBVSize", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
   1108     VIDENCTEST_CHECK_EXIT(eError, "OMX_GetExtensionIndex function");
   1109 
   1110     eError = OMX_SetParameter(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nVBVSize));
   1111     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
   1112 
   1113     if(pAppData->nMIRRate != VIDENCTEST_USE_DEFAULT_VALUE){
   1114         printf("MIRRate selected\n");
   1115         eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.MIRRate", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
   1116         VIDENCTEST_CHECK_EXIT(eError, "OMX_GetExtensionIndex function");
   1117         eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nMIRRate));
   1118         VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for nMIRRate");
   1119     }
   1120 
   1121     if(pAppData->nResynchMarkerSpacing != VIDENCTEST_USE_DEFAULT_VALUE){
   1122         printf("ResynchMarkerSpacing selected\n");
   1123         OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE ErrorCorrectionType;
   1124         ErrorCorrectionType.nSize = sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE);
   1125         ErrorCorrectionType.nVersion.s.nVersionMajor = 0x1;
   1126         ErrorCorrectionType.nVersion.s.nVersionMinor = 0x0;
   1127         ErrorCorrectionType.nVersion.s.nRevision     = 0x0;
   1128         ErrorCorrectionType.nVersion.s.nStep         = 0x0;
   1129         ErrorCorrectionType.nPortIndex= VIDENC_OUTPUT_PORT;
   1130         ErrorCorrectionType.bEnableHEC= OMX_TRUE;
   1131         ErrorCorrectionType.bEnableResync = OMX_TRUE;
   1132         ErrorCorrectionType.bEnableDataPartitioning= OMX_FALSE;
   1133         ErrorCorrectionType.bEnableRVLC= OMX_FALSE;
   1134         ErrorCorrectionType.nResynchMarkerSpacing = pAppData->nResynchMarkerSpacing;
   1135 
   1136         eError = OMX_SetConfig(pHandle, OMX_IndexParamVideoErrorCorrection, &ErrorCorrectionType);
   1137         VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for ErrorCorrection");
   1138     }
   1139     if(pAppData->nUnrestrictedMV != (OMX_U8)VIDENCTEST_USE_DEFAULT_VALUE_UI){
   1140         printf("nUnrestrictedMV %d selected\n", pAppData->nUnrestrictedMV);
   1141         eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.UnrestrictedMV", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
   1142         VIDENCTEST_CHECK_EXIT(eError, "OMX_GetExtensionIndex function");
   1143         eError = OMX_SetParameter(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nUnrestrictedMV));
   1144         VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for nUnrestrictedMV");
   1145     }
   1146 EXIT:
   1147     return eError;
   1148 }
   1149 
   1150 /*-----------------------------------------------------------------------------*/
   1151 /**
   1152   * AllocateResources()
   1153   *
   1154   * Allocate necesary resources.
   1155   *
   1156   * @param pAppData
   1157   *
   1158   * @retval OMX_ErrorNone
   1159   *
   1160   *
   1161   **/
   1162 /*-----------------------------------------------------------------------------*/
   1163 OMX_ERRORTYPE VIDENCTEST_AllocateResources(MYDATATYPE* pAppData)
   1164 {
   1165     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1166     int retval = 0;
   1167     VIDENCTEST_NODE* pListHead;
   1168 
   1169     pListHead = pAppData->pMemoryListHead;
   1170 
   1171     VIDENCTEST_MALLOC(pAppData->pCb, sizeof(OMX_CALLBACKTYPE), OMX_CALLBACKTYPE, pListHead);
   1172     VIDENCTEST_MALLOC(pAppData->pInPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE), OMX_PARAM_PORTDEFINITIONTYPE, pListHead);
   1173     VIDENCTEST_MALLOC(pAppData->pOutPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE), OMX_PARAM_PORTDEFINITIONTYPE, pListHead);
   1174 
   1175     if (pAppData->eCompressionFormat == OMX_VIDEO_CodingH263) {
   1176         VIDENCTEST_MALLOC(pAppData->pVidParamBitrate, sizeof(OMX_VIDEO_PARAM_BITRATETYPE), OMX_VIDEO_PARAM_BITRATETYPE, pListHead);
   1177         VIDENCTEST_MALLOC(pAppData->pH263, sizeof(OMX_VIDEO_PARAM_H263TYPE), OMX_VIDEO_PARAM_H263TYPE, pListHead);
   1178     }
   1179     else if (pAppData->eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
   1180         VIDENCTEST_MALLOC(pAppData->pVidParamBitrate, sizeof(OMX_VIDEO_PARAM_BITRATETYPE), OMX_VIDEO_PARAM_BITRATETYPE, pListHead);
   1181         VIDENCTEST_MALLOC(pAppData->pMpeg4, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE), OMX_VIDEO_PARAM_MPEG4TYPE, pListHead);
   1182     }
   1183     else if (pAppData->eCompressionFormat == OMX_VIDEO_CodingAVC) {
   1184         VIDENCTEST_MALLOC(pAppData->pVidParamBitrate, sizeof(OMX_VIDEO_PARAM_BITRATETYPE), OMX_VIDEO_PARAM_BITRATETYPE, pListHead);
   1185         VIDENCTEST_MALLOC(pAppData->pH264, sizeof(OMX_VIDEO_PARAM_AVCTYPE), OMX_VIDEO_PARAM_AVCTYPE, pListHead);
   1186     }
   1187     else {
   1188         VIDENCTEST_DPRINT("Invalid compression format value.\n");
   1189         eError = OMX_ErrorUnsupportedSetting;
   1190         goto EXIT;
   1191     }
   1192     VIDENCTEST_MALLOC(pAppData->pQuantization, sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE), OMX_VIDEO_PARAM_QUANTIZATIONTYPE, pListHead);
   1193 
   1194     /* Create a pipe used to queue data from the callback. */
   1195     retval = pipe(pAppData->IpBuf_Pipe);
   1196     if (retval != 0) {
   1197         VIDENCTEST_DPRINT("Error: Fill Data Pipe failed to open\n");
   1198         goto EXIT;
   1199     }
   1200     retval = pipe(pAppData->OpBuf_Pipe);
   1201     if (retval != 0) {
   1202         VIDENCTEST_DPRINT("Error: Empty Data Pipe failed to open\n");
   1203         goto EXIT;
   1204     }
   1205     retval = pipe(pAppData->eventPipe);
   1206     if (retval != 0) {
   1207         VIDENCTEST_DPRINT("Error: Empty Data Pipe failed to open\n");
   1208         goto EXIT;
   1209     }
   1210 
   1211 EXIT:
   1212     return eError;
   1213 }
   1214 
   1215 /*-----------------------------------------------------------------------------*/
   1216 /**
   1217   * AllocateBuffers()
   1218   *
   1219   * Allocate necesary resources.
   1220   *
   1221   * @param pAppData
   1222   *
   1223   * @retval OMX_ErrorNone
   1224   *
   1225   *
   1226   **/
   1227 /*-----------------------------------------------------------------------------*/
   1228 OMX_ERRORTYPE VIDENCTEST_AllocateBuffers(MYDATATYPE* pAppData)
   1229 {
   1230     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1231     OMX_U8 nCounter = 0;
   1232     VIDENCTEST_NODE* pListHead;
   1233 
   1234     pListHead = pAppData->pMemoryListHead;
   1235 
   1236     for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
   1237         if (pAppData->bAllocateIBuf == OMX_TRUE) {
   1238             VIDENCTEST_MALLOC(pAppData->pIBuffer[nCounter], pAppData->nSizeIn + 256, OMX_U8, pListHead);
   1239             pAppData->pIBuffer[nCounter] += 128;
   1240             pAppData->pIBuffer[nCounter] = (unsigned char*)pAppData->pIBuffer[nCounter];
   1241         }
   1242     }
   1243     for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
   1244         if (pAppData->bAllocateOBuf == OMX_TRUE) {
   1245             VIDENCTEST_MALLOC(pAppData->pOBuffer[nCounter], pAppData->nSizeOut + 256, OMX_U8, pListHead);
   1246             pAppData->pOBuffer[nCounter] += 128;
   1247             pAppData->pOBuffer[nCounter] = (unsigned char*)pAppData->pOBuffer[nCounter];
   1248             }
   1249     }
   1250 
   1251     return eError;
   1252 }
   1253 
   1254 /*-----------------------------------------------------------------------------*/
   1255 /**
   1256   * FreeResources()
   1257   *
   1258   * Free all allocated memory.
   1259   *
   1260   * @param pAppData
   1261   *
   1262   * @retval OMX_ErrorNone
   1263   *
   1264   *
   1265   **/
   1266 /*-----------------------------------------------------------------------------*/
   1267 OMX_ERRORTYPE VIDENCTEST_FreeResources(MYDATATYPE* pAppData)
   1268 {
   1269     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1270     OMX_U32 i = 0;
   1271     VIDENCTEST_NODE* pListHead;
   1272 
   1273     pListHead = pAppData->pMemoryListHead;
   1274 
   1275     VIDENCTEST_FREE(pAppData->pCb, pListHead);
   1276     VIDENCTEST_FREE(pAppData->pInPortDef, pListHead);
   1277     VIDENCTEST_FREE(pAppData->pOutPortDef, pListHead);
   1278 
   1279     if((pAppData->NalFormat == VIDENC_TEST_NAL_FRAME || pAppData->NalFormat == VIDENC_TEST_NAL_SLICE)
   1280         && pAppData->szOutFileNal) {
   1281         VIDENCTEST_FREE(pAppData->szOutFileNal, pListHead);
   1282     }
   1283 
   1284     if (pAppData->pH264 != NULL) {
   1285         VIDENCTEST_FREE(pAppData->pH264, pListHead);
   1286     }
   1287 
   1288     VIDENCTEST_FREE(pAppData->pVidParamBitrate, pListHead);
   1289 
   1290     if (pAppData->pH263 != NULL) {
   1291         VIDENCTEST_FREE(pAppData->pH263, pListHead);
   1292     }
   1293 
   1294     VIDENCTEST_FREE(pAppData->pQuantization, pListHead);
   1295 
   1296     if (pAppData->pMpeg4 != NULL) {
   1297         VIDENCTEST_FREE(pAppData->pMpeg4, pListHead);
   1298     }
   1299 
   1300     for (i = 0; i < pAppData->nEventCount; i++) {
   1301         VIDENCTEST_FREE(pAppData->pEventArray[i], pListHead);
   1302     }
   1303 
   1304     return eError;
   1305 }
   1306 
   1307 /*-----------------------------------------------------------------------------*/
   1308 /**
   1309   * PrintCorrectArgs()
   1310   *
   1311   * Print the description of the input arguments. Also Prints a sample line.
   1312   *
   1313   * @param bPrintH264. IF set will print the H264 argument description.
   1314   * @param bPrintMpeg4. If set will print the Mpeg4/H263  argument description.
   1315   *
   1316   * @retval OMX_ErrorNone
   1317   *
   1318   *
   1319   **/
   1320 /*-----------------------------------------------------------------------------*/
   1321 OMX_ERRORTYPE VIDENCTEST_PrintCorrectArgs(OMX_BOOL bPrintH264, OMX_BOOL bPrintMpeg4)
   1322 {
   1323     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1324 
   1325     if (bPrintMpeg4 == OMX_TRUE) {
   1326         printf("MPEG4/H.263 Encode Usage: ./VideoEncTest <arg01> <arg02> <arg03> ...");
   1327         printf("\narg01 : <input.yuv>");
   1328         printf("\narg02 : <output.mp4>");
   1329         printf("\narg03 : <width>");
   1330         printf("\narg04 : <height>");
   1331         printf("\narg05 : <19:420/25:422-BE/26:422-LE>");
   1332         printf("\narg06 : <bitrate>");
   1333         printf("\narg07 : <framerate>");
   1334         printf("\narg08 : <3:H263/4:MPEG4/7:H264>");
   1335         printf("\narg09 : <rateCtrl/1:var/2:const>");
   1336         printf("\narg10 : <GOB> --H.263 only--");
   1337         printf("\narg11 : <QPI>");
   1338         printf("\narg12 : <level>");
   1339         printf("\narg13 : <allocateBufFlag>");
   1340         printf("\narg14 : <VBVsize>");
   1341         printf("\narg15 : <0:full-rec/1:partial-rec->stop/2:rec->pause->resume/3:rec->stop->restart>");
   1342         printf("\narg16 : <stop/pause frame/iteration> -- use zero if arg15 = 0:full-rec <or> use a valid frame # if arg15 = 1, 2, 3 --\n");
   1343         printf("\narg17 : <Number of Repetitions of test>");
   1344         printf("\nSample OMX MPEG4 Encode test:\n");
   1345         printf("/omx/VideoEncTest /omx/patterns/carphone_qcif_420p_short.yuv /omx/patterns/carphone_qcif_420p_short.mp4 176 144 19 64000 15 4 1 0 12 0 1 120 0 0 1\n");
   1346         printf("\nSample OMX H.263 Encode test:\n");
   1347         printf("/omx/VideoEncTest /omx/patterns/carphone_qcif_420p_short.yuv /omx/patterns/carphone_qcif_420p_short.263 176 144 19 64000 15 3 2 0 12 10 1 120 0 0 1\n\n");
   1348     }
   1349     if (bPrintH264 == OMX_TRUE) {
   1350         printf("H.264 Encode Usage: ./VideoEncTest <arg01> <arg02> <arg03> ...");
   1351         printf("\narg01 :: <input.yuv>");
   1352         printf("\narg02 :: <output.H264>");
   1353         printf("\narg03 :: <width>");
   1354         printf("\narg04 :: <height>");
   1355         printf("\narg05 :: <19:420/25:422-BE/26:422-LE>");
   1356         printf("\narg06 :: <bitrate>");
   1357         printf("\narg07 :: <framerate>");
   1358         printf("\narg08 :: <3:H263/4:MPEG4/7:H264>");
   1359         printf("\narg09 :: <level>");
   1360         printf("\narg10 :: <out_buff_size>");
   1361         printf("\narg11 :: <allocateBufFlag>");
   1362         printf("\narg12 :: <deblockFilter>");
   1363         printf("\narg13 :: <rateCtrl/0:none/1:var/2:const>");
   1364         printf("\narg14 :: <QPI> --set rate control to zero--");
   1365         printf("\narg15 :: <0:full-rec/1:partial-rec->stop/2:rec->pause->resume/3:rec->stop->restart>");
   1366         printf("\narg16 :: <stop/pause frame/iteration> -- use zero if arg15 = 0:full-rec <or> use a valid frame # if arg15 = 1, 2, 3 --\n");
   1367         printf("\narg17 :: <Number of Repetitions of test>");
   1368         printf("\nSample OMX H.264 Encode test:\n");
   1369         printf("/omx/VideoEncTest /omx/patterns/carphone_qcif_420p_short.yuv /omx/patterns/carphone_qcif_420p_short.264 176 144 19 64000 15 7 10 26250 1 1 1 0 0 0 1\n\n");
   1370     }
   1371     return eError;
   1372 }
   1373 
   1374 /*-----------------------------------------------------------------------------*/
   1375 /**
   1376   * Init()
   1377   *
   1378   *Initialize all the parameters for the VideoEncoder Structures
   1379   *
   1380   * @param  pAppData MYDATA handle
   1381   *
   1382   * @retval OMX_ErrorNone
   1383   *
   1384   *
   1385   **/
   1386 /*-----------------------------------------------------------------------------*/
   1387 OMX_ERRORTYPE VIDENCTEST_PassToLoaded(MYDATATYPE* pAppData)
   1388 {
   1389     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1390     OMX_HANDLETYPE pHandle;
   1391     VIDENCTEST_NODE* pListHead;
   1392     OMX_U32 i;
   1393     OMX_CALLBACKTYPE sCb = {(void*)VIDENCTEST_EventHandler, (void*)VIDENCTEST_EmptyBufferDone, (void*)VIDENCTEST_FillBufferDone};
   1394 
   1395     pListHead = pAppData->pMemoryListHead;
   1396 
   1397     eError = VIDENCTEST_AllocateResources(pAppData);
   1398 
   1399 
   1400     VIDENCTEST_CHECK_EXIT(eError, "Error at Allocation of Resources");
   1401 
   1402     pAppData->fdmax = maxint(pAppData->IpBuf_Pipe[0], pAppData->eventPipe[0]);
   1403 
   1404     pAppData->fdmax = maxint(pAppData->OpBuf_Pipe[0], pAppData->fdmax);
   1405 
   1406 
   1407 
   1408     /* Initialize OMX Core */
   1409 
   1410     eError = TIOMX_Init();
   1411     VIDENCTEST_CHECK_EXIT(eError, "Error returned by TIOMX_Init()");
   1412 
   1413     *pAppData->pCb = sCb;
   1414     /* Get VideoEncoder Component Handle */
   1415     eError = TIOMX_GetHandle(&pHandle, StrVideoEncoder, pAppData, pAppData->pCb);
   1416     VIDENCTEST_CHECK_EXIT(eError, "Error returned by TIOMX_Init()");
   1417     if (pHandle == NULL) {
   1418         VIDENCTEST_DPRINT("Error GetHandle() return Null Pointer\n");
   1419         eError = OMX_ErrorUndefined;
   1420         goto EXIT;
   1421     }
   1422 
   1423     pAppData->pHandle = pHandle;
   1424 
   1425     /* Get starting port number and the number of ports */
   1426     VIDENCTEST_MALLOC(pAppData->pVideoInit, sizeof(OMX_PORT_PARAM_TYPE), OMX_PORT_PARAM_TYPE, pListHead);
   1427 
   1428     eError = OMX_GetParameter(pHandle, OMX_IndexParamVideoInit, pAppData->pVideoInit);
   1429     VIDENCTEST_CHECK_EXIT(eError, "Error returned from GetParameter()");
   1430 
   1431     pAppData->nStartPortNumber = pAppData->pVideoInit->nStartPortNumber;
   1432     pAppData->nPorts           = pAppData->pVideoInit->nPorts;
   1433 
   1434     VIDENCTEST_FREE(pAppData->pVideoInit, pListHead);
   1435 
   1436     /* TODO: Optimize - We should use a linked list instead of an array */
   1437     for (i = pAppData->nStartPortNumber; i < pAppData->nPorts; i++) {
   1438         VIDENCTEST_MALLOC(pAppData->pPortDef[i], sizeof(OMX_PARAM_PORTDEFINITIONTYPE), OMX_PARAM_PORTDEFINITIONTYPE, pListHead);
   1439 
   1440         pAppData->pPortDef[i]->nPortIndex = i;
   1441         eError = OMX_GetParameter(pHandle, OMX_IndexParamPortDefinition, pAppData->pPortDef[i]);
   1442         VIDENCTEST_CHECK_EXIT(eError, "Error returned from GetParameter()");
   1443 
   1444         if (pAppData->pPortDef[i]->eDir == OMX_DirInput) {
   1445             memcpy(pAppData->pInPortDef, pAppData->pPortDef[i], sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
   1446         }
   1447         else {
   1448             memcpy(pAppData->pOutPortDef, pAppData->pPortDef[i], sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
   1449         }
   1450         VIDENCTEST_FREE(pAppData->pPortDef[i], pListHead);
   1451     }
   1452 
   1453     switch (pAppData->eCompressionFormat) {
   1454         case OMX_VIDEO_CodingH263:
   1455             eError = VIDENCTEST_SetMpeg4Parameter(pAppData);
   1456             VIDENCTEST_CHECK_EXIT(eError, "Error returned from SetMpeg4Parameter()");
   1457             break;
   1458         case OMX_VIDEO_CodingMPEG4:
   1459             eError = VIDENCTEST_SetMpeg4Parameter(pAppData);
   1460             VIDENCTEST_CHECK_EXIT(eError, "Error returned from SetMpeg4Parameter()");
   1461             break;
   1462         case OMX_VIDEO_CodingAVC:
   1463             eError = VIDENCTEST_SetH264Parameter(pAppData);
   1464             VIDENCTEST_CHECK_EXIT(eError, "Error returned from SetH264Parameter()");
   1465             break;
   1466         default:
   1467             VIDENCTEST_DPRINT("Invalid compression format value.\n");
   1468             eError = OMX_ErrorUnsupportedSetting;
   1469             goto EXIT;
   1470     }
   1471 
   1472     VIDENCTEST_AllocateBuffers(pAppData);
   1473     VIDENCTEST_CHECK_EXIT(eError, "Error at Allocation of Resources");
   1474 
   1475     pAppData->eCurrentState = VIDENCTEST_StateLoaded;
   1476 
   1477  EXIT:
   1478     return eError;
   1479 
   1480 }
   1481 
   1482 /*-----------------------------------------------------------------------------*/
   1483 /**
   1484   * PassToReady()
   1485   *
   1486   *Pass the Component to Idle and allocate the buffers
   1487   *
   1488   * @param  pAppData MYDATA handle
   1489   *
   1490   * @retval OMX_ErrorNone
   1491   *
   1492   *
   1493   **/
   1494 /*-----------------------------------------------------------------------------*/
   1495 OMX_ERRORTYPE VIDENCTEST_PassToReady(MYDATATYPE* pAppData)
   1496 {
   1497     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1498     OMX_HANDLETYPE pHandle;
   1499     OMX_U32 nCounter;
   1500 
   1501     pHandle = pAppData->pHandle;
   1502 
   1503     eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
   1504     VIDENCTEST_CHECK_EXIT(eError, "Error from SendCommand-Idle(Init) State function");
   1505 
   1506     for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
   1507        if (pAppData->bAllocateIBuf == OMX_TRUE) {
   1508             eError = OMX_UseBuffer(pHandle,
   1509                                   &pAppData->pInBuff[nCounter],
   1510                                   pAppData->pInPortDef->nPortIndex,
   1511                                   pAppData,
   1512                                   pAppData->pInPortDef->nBufferSize,
   1513                                   pAppData->pIBuffer[nCounter]);
   1514             VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_UseBuffer function");
   1515        }
   1516        else {
   1517             eError = OMX_AllocateBuffer(pHandle,
   1518                                        &pAppData->pInBuff[nCounter],
   1519                                        pAppData->pInPortDef->nPortIndex,
   1520                                        pAppData,
   1521                                        pAppData->pInPortDef->nBufferSize);
   1522             VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_AllocateBuffer State function");
   1523        }
   1524     }
   1525 
   1526     pAppData->nInBufferCount = NUM_OF_IN_BUFFERS;
   1527 
   1528     for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
   1529         if (pAppData->bAllocateOBuf == OMX_TRUE) {
   1530             eError = OMX_UseBuffer(pHandle,
   1531                                    &pAppData->pOutBuff[nCounter],
   1532                                    pAppData->pOutPortDef->nPortIndex,
   1533                                    pAppData,
   1534                                    pAppData->pOutPortDef->nBufferSize,
   1535                                    pAppData->pOBuffer[nCounter]);
   1536             VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_UseBuffer function");
   1537         }
   1538         else {
   1539             eError = OMX_AllocateBuffer(pHandle,
   1540                                         &pAppData->pOutBuff[nCounter],
   1541                                         pAppData->pOutPortDef->nPortIndex,
   1542                                         pAppData,
   1543                                         pAppData->pOutPortDef->nBufferSize);
   1544             VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_AllocateBuffer function");
   1545         }
   1546     }
   1547 
   1548     pAppData->nOutBufferCount = NUM_OF_OUT_BUFFERS;
   1549 
   1550     pAppData->bLastOutBuffer = 0;
   1551 
   1552 
   1553 EXIT:
   1554     return eError;
   1555 
   1556 }
   1557 
   1558 /*-----------------------------------------------------------------------------*/
   1559 /**
   1560   * PassToExecuting()
   1561   *
   1562   *Pass the component to executing  and fill the first 4 buffers.
   1563   *
   1564   * @param  pAppData MYDATA handle
   1565   *
   1566   * @retval OMX_ErrorNone
   1567   *
   1568   *
   1569   **/
   1570 /*-----------------------------------------------------------------------------*/
   1571 OMX_ERRORTYPE VIDENCTEST_Starting(MYDATATYPE* pAppData)
   1572 {
   1573     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1574     OMX_HANDLETYPE pHandle;
   1575     OMX_U32 nCounter = 0;
   1576     OMX_U32 nBuffersToSend;
   1577 
   1578     pHandle = pAppData->pHandle;
   1579     pAppData->pComponent = (OMX_COMPONENTTYPE*)pHandle;
   1580 
   1581     /* SR10519/17735: Set the interval for the insertion of intra frames at run-time using a custom OMX index */
   1582     eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.IntraFrameInterval", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
   1583     VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
   1584 
   1585    /* MPEG4/H263 DSP socket node default value */
   1586     if(pAppData->nIntraFrameInterval == VIDENCTEST_USE_DEFAULT_VALUE){
   1587             pAppData->nIntraFrameInterval = 30;
   1588     }
   1589     eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nIntraFrameInterval));
   1590     VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_SetConfig function");
   1591 
   1592     /* This test only applies to MPEG4/H.263 encoding */
   1593     if (pAppData->eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
   1594         pAppData->eCompressionFormat == OMX_VIDEO_CodingH263) {
   1595         /* SR10540: Set the Target Frame Rate at run-time using a custom OMX index */
   1596         eError = OMX_GetExtensionIndex(pHandle,
   1597                                        "OMX.TI.VideoEncode.Config.TargetFrameRate",
   1598                                        (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
   1599         VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
   1600 
   1601         pAppData->nTargetFrameRate = pAppData->nFramerate; /* Refer to DSP socket node interface guide for usage */
   1602         eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nTargetFrameRate));
   1603         VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_SetConfig function");
   1604     }
   1605 
   1606     /* SR10523: Set the AIRRate at run-time using a custom OMX index */
   1607     eError = OMX_GetExtensionIndex(pHandle,
   1608                                    "OMX.TI.VideoEncode.Config.AIRRate",
   1609                                    (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
   1610     VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
   1611     pAppData->nAIRRate = 0; /* Refer to DSP socket node interface guide for usage */
   1612     eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nAIRRate));
   1613     VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_SetConfig function");
   1614 
   1615     /* SR12005: Set the Target Bit Rate at run-time using a custom OMX index */
   1616     eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.TargetBitRate", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
   1617     VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
   1618 
   1619     pAppData->nTargetBitRate = pAppData->nBitrate; /* Refer to DSP socket node interface guide for usage */
   1620     eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nTargetBitRate));
   1621     VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_SetConfig function");
   1622 
   1623     /*Initialize Frame Counter */
   1624     pAppData->nCurrentFrameIn = 0;
   1625     pAppData->nCurrentFrameOut = 0;
   1626 
   1627 
   1628     /*Validation of stopframe in cases of Pause->Resume and Stop->Restart test cases*/
   1629     if ( pAppData->eTypeOfTest == VIDENCTEST_StopRestart || pAppData->eTypeOfTest == VIDENCTEST_PauseResume) {
   1630         if (pAppData->nReferenceFrame <= 1 ){
   1631             nBuffersToSend = 1;
   1632         }
   1633         else if (pAppData->nReferenceFrame < NUM_OF_IN_BUFFERS){
   1634             nBuffersToSend = pAppData->nReferenceFrame;
   1635         }
   1636         else {
   1637             nBuffersToSend = NUM_OF_IN_BUFFERS;
   1638         }
   1639     }
   1640     else {
   1641         nBuffersToSend = NUM_OF_IN_BUFFERS;
   1642     }
   1643         /* Send FillThisBuffertoOMXVideoEncoder */
   1644 
   1645         if (pAppData->eTypeOfTest == VIDENCTEST_PartialRecord && pAppData->nReferenceFrame < NUM_OF_IN_BUFFERS) {
   1646             nBuffersToSend = pAppData->nReferenceFrame;
   1647             }
   1648 
   1649 
   1650 
   1651     for (nCounter = 0; nCounter < nBuffersToSend; nCounter++) {
   1652         pAppData->pOutBuff[nCounter]->nFilledLen = 0;
   1653         eError = pAppData->pComponent->FillThisBuffer(pHandle, pAppData->pOutBuff[nCounter]);
   1654         VIDENCTEST_CHECK_EXIT(eError, "Error in FillThisBuffer");
   1655         pAppData->nOutBufferCount--;
   1656     }
   1657 
   1658     /* Send EmptyThisBuffer to OMX Video Encoder */
   1659     for (nCounter = 0; nCounter < nBuffersToSend; nCounter++) {
   1660         pAppData->pInBuff[nCounter]->nFilledLen = VIDENCTEST_fill_data(pAppData->pInBuff[nCounter], pAppData->fIn , pAppData->pInPortDef->nBufferSize);
   1661 
   1662         if (pAppData->pInBuff[nCounter]->nFlags == OMX_BUFFERFLAG_EOS && pAppData->pInBuff[nCounter]->nFilledLen == 0) {
   1663             pAppData->eCurrentState = VIDENCTEST_StateStopping;
   1664             eError = pAppData->pComponent->EmptyThisBuffer(pHandle, pAppData->pInBuff[nCounter]);
   1665             VIDENCTEST_CHECK_ERROR(eError, "Error at EmptyThisBuffer function");
   1666             pAppData->nInBufferCount--;
   1667             goto EXIT;
   1668         }
   1669         else {
   1670             pAppData->pComponent->EmptyThisBuffer(pHandle, pAppData->pInBuff[nCounter]);
   1671             pAppData->nInBufferCount--;
   1672             pAppData->nCurrentFrameIn++;
   1673         }
   1674     }
   1675 
   1676     pAppData->eCurrentState = VIDENCTEST_StateEncoding;
   1677 
   1678 EXIT:
   1679     return eError;
   1680 }
   1681 
   1682 /*-----------------------------------------------------------------------------*/
   1683 /**
   1684   * DeInit()
   1685   *
   1686   *Pass the component to executing  and fill the first 4 buffers.
   1687   *
   1688   * @param  pAppData MYDATA handle
   1689   *
   1690   * @retval OMX_ErrorNone
   1691   *
   1692   *
   1693   **/
   1694 /*-----------------------------------------------------------------------------*/
   1695  OMX_ERRORTYPE VIDENCTEST_DeInit(MYDATATYPE* pAppData)
   1696  {
   1697     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1698     OMX_ERRORTYPE eErr = OMX_ErrorNone;
   1699     VIDENCTEST_NODE* pListHead;
   1700     OMX_HANDLETYPE pHandle = pAppData->pHandle;
   1701     pListHead = pAppData->pMemoryListHead;
   1702 
   1703     /* Free Component Handle */
   1704     eError = TIOMX_FreeHandle(pHandle);
   1705     VIDENCTEST_CHECK_EXIT(eError, "Error in TIOMX_FreeHandle");
   1706 
   1707     /* De-Initialize OMX Core */
   1708     eError = TIOMX_Deinit();
   1709     VIDENCTEST_CHECK_EXIT(eError, "Error in TIOMX_Deinit");
   1710 
   1711     /* shutdown */
   1712     fclose(pAppData->fIn);
   1713     fclose(pAppData->fOut);
   1714     if(pAppData->NalFormat == VIDENC_TEST_NAL_FRAME || pAppData->NalFormat == VIDENC_TEST_NAL_SLICE) {
   1715         fclose(pAppData->fNalnd);
   1716     }
   1717 
   1718     eErr = close(pAppData->IpBuf_Pipe[0]);
   1719     if (0 != eErr && OMX_ErrorNone == eError) {
   1720         eError = OMX_ErrorHardware;
   1721         VIDENCTEST_DPRINT ("Error while closing data pipe\n");
   1722     }
   1723 
   1724     eErr = close(pAppData->OpBuf_Pipe[0]);
   1725     if (0 != eErr && OMX_ErrorNone == eError) {
   1726         eError = OMX_ErrorHardware;
   1727         VIDENCTEST_DPRINT ("Error while closing data pipe\n");
   1728     }
   1729 
   1730     eErr = close(pAppData->eventPipe[0]);
   1731     if (0 != eErr && OMX_ErrorNone == eError) {
   1732         eError = OMX_ErrorHardware;
   1733         VIDENCTEST_DPRINT ("Error while closing data pipe\n");
   1734     }
   1735 
   1736     eErr = close(pAppData->IpBuf_Pipe[1]);
   1737     if (0 != eErr && OMX_ErrorNone == eError) {
   1738         eError = OMX_ErrorHardware;
   1739         VIDENCTEST_DPRINT ("Error while closing data pipe\n");
   1740     }
   1741 
   1742     eErr = close(pAppData->OpBuf_Pipe[1]);
   1743     if (0 != eErr && OMX_ErrorNone == eError) {
   1744         eError = OMX_ErrorHardware;
   1745         VIDENCTEST_DPRINT ("Error while closing data pipe\n");
   1746     }
   1747 
   1748     eErr = close(pAppData->eventPipe[1]);
   1749     if (0 != eErr && OMX_ErrorNone == eError) {
   1750         eError = OMX_ErrorHardware;
   1751         VIDENCTEST_DPRINT ("Error while closing data pipe\n");
   1752     }
   1753 
   1754     pAppData->fIn = NULL;
   1755     pAppData->fOut = NULL;
   1756     pAppData->fNalnd = NULL;
   1757 
   1758     VIDENCTEST_FreeResources(pAppData);
   1759     VIDENCTEST_CHECK_EXIT(eError, "Error in FillThisBuffer");
   1760 
   1761     VIDENCTEST_FREE(pAppData, pListHead);
   1762     VIDENCTEST_ListDestroy(pListHead);
   1763     pAppData = NULL;
   1764 
   1765 EXIT:
   1766     return eError;
   1767 
   1768 }
   1769 
   1770 /*-----------------------------------------------------------------------------*/
   1771 /**
   1772   * HandleState()
   1773   *
   1774   *StateTransitions Driven.
   1775   *
   1776   * @param  pAppData
   1777   * @param  nData2 - State that has been set.
   1778   *
   1779   * @retval OMX_ErrorNone
   1780   *
   1781   *
   1782   **/
   1783 /*-----------------------------------------------------------------------------*/
   1784 OMX_ERRORTYPE VIDENCTEST_HandleState(MYDATATYPE* pAppData, OMX_U32 eState)
   1785 {
   1786     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1787     OMX_HANDLETYPE pHandle = pAppData->pHandle;
   1788     OMX_U32 nCounter = 0;
   1789     VIDENCTEST_NODE* pListHead;
   1790 
   1791     pListHead = pAppData->pMemoryListHead;
   1792 
   1793     switch (eState) {
   1794         case OMX_StateLoaded:
   1795             VIDENCTEST_PRINT("Component in OMX_StateLoaded\n");
   1796             if(pAppData->eCurrentState == VIDENCTEST_StateLoaded) {
   1797                 pAppData->eCurrentState = VIDENCTEST_StateUnLoad;
   1798             }
   1799             break;
   1800         case OMX_StateIdle:
   1801             VIDENCTEST_PRINT("Component in OMX_StateIdle\n");
   1802             if (pAppData->eCurrentState == VIDENCTEST_StateLoaded) {
   1803                 pAppData->eCurrentState = VIDENCTEST_StateReady;
   1804                 VIDENCTEST_PRINT("Send Component to OMX_StateExecuting\n");
   1805                 eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
   1806                 VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_SendCommand function\n");
   1807             }
   1808             else if(pAppData->eCurrentState == VIDENCTEST_StateWaitEvent){
   1809                 if(pAppData->bStop == OMX_TRUE){
   1810                     int count;
   1811                     VIDENCTEST_PRINT("Component in OMX_StateStop\n");
   1812                     pAppData->eCurrentState = VIDENCTEST_StateStop;
   1813                     /*printf("Press any key to resume...");*/
   1814                     /*getchar();*/
   1815                     for(count = 5; count >= 0; count--) {
   1816                         printf("App stopped: restart in %d seconds\n", count);
   1817                         sleep(1);
   1818                     }
   1819                     pAppData->bStop = OMX_FALSE;
   1820                 }
   1821 
   1822                 VIDENCTEST_PRINT("Disable Input Port\n");
   1823                 eError = OMX_SendCommand(pHandle, OMX_CommandPortDisable, VIDENC_INPUT_PORT, NULL);
   1824                 VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_SendCommand function\n");
   1825 
   1826                 if (pAppData->bAllocateIBuf == OMX_TRUE) {
   1827                     for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
   1828                         pAppData->pIBuffer[nCounter] -= 128;
   1829                         pAppData->pIBuffer[nCounter] = (unsigned char*)pAppData->pIBuffer[nCounter];
   1830                         VIDENCTEST_FREE(pAppData->pIBuffer[nCounter], pListHead);
   1831                         pAppData->pIBuffer[nCounter] = NULL;
   1832                     }
   1833                 }
   1834                 for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
   1835                     eError = OMX_FreeBuffer(pHandle, pAppData->pInPortDef->nPortIndex, pAppData->pInBuff[nCounter]);
   1836                 }
   1837             }
   1838             break;
   1839         case OMX_StateExecuting:
   1840         VIDENCTEST_PRINT("Component in OMX_StateExecuting\n");
   1841                 pAppData->eCurrentState = VIDENCTEST_StateStarting;
   1842                 eError = VIDENCTEST_Starting(pAppData);
   1843             break;
   1844         case OMX_StatePause:
   1845             VIDENCTEST_PRINT("Component in OMX_StatePause\n");
   1846             pAppData->eCurrentState = VIDENCTEST_StatePause;
   1847             /*printf("Press any key to resume...");*/
   1848             /*getchar();*/
   1849             int count;
   1850             for(count = 5; count >= 0; count--) {
   1851                 printf("App paused: resume in %d seconds\n", count);
   1852                 sleep(1);
   1853             }
   1854             pAppData->bStop = OMX_FALSE;
   1855             eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
   1856             break;
   1857         case OMX_StateWaitForResources:
   1858         VIDENCTEST_PRINT("Component in OMX_StateWaitForResources\n");
   1859             break;
   1860         case OMX_StateInvalid:
   1861         VIDENCTEST_PRINT("Component in OMX_StateInvalid\n");
   1862              eError = OMX_ErrorInvalidState;
   1863         }
   1864 
   1865 EXIT:
   1866     return eError;
   1867 }
   1868 
   1869 /*-----------------------------------------------------------------------------*/
   1870 /**
   1871   * CheckArgs_H263()
   1872   *
   1873   *Validates h.263 input parameters
   1874   *
   1875   * @param  pAppData
   1876   * @param  argv
   1877   *
   1878   * @retval OMX_ErrorNone
   1879   *
   1880   *
   1881   **/
   1882 /*-----------------------------------------------------------------------------*/
   1883 OMX_ERRORTYPE VIDENCTEST_CheckArgs_H263(MYDATATYPE* pAppData, char** argv)
   1884 {
   1885     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1886 
   1887     switch (atoi(argv[9])) {
   1888         case 0:
   1889             pAppData->eControlRate = OMX_Video_ControlRateDisable;
   1890             break;
   1891         case 1:
   1892             pAppData->eControlRate = OMX_Video_ControlRateVariable;
   1893             break;
   1894         case 2:
   1895             pAppData->eControlRate = OMX_Video_ControlRateConstant;
   1896             break;
   1897         default:
   1898             eError = OMX_ErrorBadParameter;
   1899             printf("*Error: Input Argument CONTROL RATE is not valid");
   1900             goto EXIT;
   1901     }
   1902 
   1903     pAppData->nGOBHeaderInterval = atoi(argv[10]);
   1904     pAppData->nQpI = atoi(argv[11]);
   1905 
   1906     switch (atoi(argv[12])) {
   1907         case 10:
   1908             pAppData->eLevelH63 = OMX_VIDEO_H263Level10;
   1909             break;
   1910         case 20:
   1911             pAppData->eLevelH63 = OMX_VIDEO_H263Level20;
   1912             break;
   1913         case 30:
   1914             pAppData->eLevelH63 = OMX_VIDEO_H263Level30;
   1915             break;
   1916         case 40:
   1917             pAppData->eLevelH63 = OMX_VIDEO_H263Level40;
   1918             break;
   1919         case 45:
   1920             pAppData->eLevelH63 = OMX_VIDEO_H263Level45;
   1921             break;
   1922         case 50:
   1923             pAppData->eLevelH63 = OMX_VIDEO_H263Level50;
   1924             break;
   1925         case 60:
   1926             pAppData->eLevelH63 = OMX_VIDEO_H263Level60;
   1927             break;
   1928         case 70:
   1929             pAppData->eLevelH63 = OMX_VIDEO_H263Level70;
   1930             break;
   1931         default:
   1932             eError = OMX_ErrorBadParameter;
   1933             printf("*Error: Input Argument LEVEL is not valid");
   1934             goto EXIT;
   1935     }
   1936 
   1937     if (atoi(argv[13]) == 0) {
   1938         pAppData->bAllocateIBuf = OMX_FALSE;
   1939         pAppData->bAllocateOBuf = OMX_FALSE;
   1940     }
   1941     else {
   1942         pAppData->bAllocateIBuf = OMX_TRUE;
   1943         pAppData->bAllocateOBuf = OMX_TRUE;
   1944     }
   1945 
   1946     pAppData->nVBVSize = atoi(argv[14]);
   1947 
   1948 
   1949 EXIT:
   1950     return eError;
   1951 }
   1952 
   1953 /*-----------------------------------------------------------------------------*/
   1954 /**
   1955   * CheckArgs_Mpeg4()
   1956   *
   1957   *Validates Mpeg4 input parameters
   1958   *
   1959   * @param  pAppData
   1960   * @param  argv
   1961   *
   1962   * @retval OMX_ErrorNone
   1963   *
   1964   *
   1965   **/
   1966 /*-----------------------------------------------------------------------------*/
   1967 OMX_ERRORTYPE VIDENCTEST_CheckArgs_Mpeg4(MYDATATYPE* pAppData, char** argv)
   1968 {
   1969     OMX_ERRORTYPE eError = OMX_ErrorNone;
   1970 
   1971     switch (atoi(argv[9])) {
   1972         case 0:
   1973             pAppData->eControlRate = OMX_Video_ControlRateDisable;
   1974             break;
   1975         case 1:
   1976             pAppData->eControlRate = OMX_Video_ControlRateVariable;
   1977             break;
   1978         case 2:
   1979             pAppData->eControlRate = OMX_Video_ControlRateConstant;
   1980             break;
   1981         default:
   1982             eError = OMX_ErrorBadParameter;
   1983             printf("*Error: Input Argument CONTROL RATE is not valid");
   1984             goto EXIT;
   1985     }
   1986 
   1987     pAppData->nQpI = atoi(argv[11]);
   1988 
   1989 #if 0
   1990    pAppData->eLevelMpeg4 = atoi(argv[12]);
   1991 
   1992 #else
   1993     switch (atoi(argv[12])) {
   1994         case 0:
   1995             pAppData->eLevelMpeg4 = OMX_VIDEO_MPEG4Level0;
   1996             break;
   1997         case 1:
   1998             pAppData->eLevelMpeg4 = OMX_VIDEO_MPEG4Level1;
   1999             break;
   2000         case 2:
   2001             pAppData->eLevelMpeg4 = OMX_VIDEO_MPEG4Level2;
   2002             break;
   2003         case 3:
   2004             pAppData->eLevelMpeg4 = OMX_VIDEO_MPEG4Level3;
   2005             break;
   2006         case 4:
   2007             pAppData->eLevelMpeg4 = OMX_VIDEO_MPEG4Level4;
   2008             break;
   2009         case 5:
   2010             pAppData->eLevelMpeg4 = OMX_VIDEO_MPEG4Level5;
   2011             break;
   2012         case 100:
   2013             pAppData->eLevelMpeg4 = OMX_VIDEO_MPEG4Level0b;
   2014             break;
   2015         default:
   2016             eError = OMX_ErrorBadParameter;
   2017             printf("*Error: Input Argument LEVEL is not valid");
   2018             goto EXIT;
   2019         }
   2020 #endif
   2021 
   2022 
   2023     if (atoi(argv[13]) == 0) {
   2024         pAppData->bAllocateIBuf = OMX_FALSE;
   2025         pAppData->bAllocateOBuf = OMX_FALSE;
   2026     }
   2027     else {
   2028         pAppData->bAllocateIBuf = OMX_TRUE;
   2029         pAppData->bAllocateOBuf = OMX_TRUE;
   2030     }
   2031 
   2032     pAppData->nVBVSize = atoi(argv[14]);
   2033 
   2034 
   2035 EXIT:
   2036     return eError;
   2037 }
   2038 
   2039 /*-----------------------------------------------------------------------------*/
   2040 /**
   2041   * CheckArgs_AVC()
   2042   *
   2043   *Validates Mpeg4 input parameters
   2044   *
   2045   * @param  pAppData
   2046   * @param  argv
   2047   *
   2048   * @retval OMX_ErrorNone
   2049   *
   2050   *
   2051   **/
   2052 /*-----------------------------------------------------------------------------*/
   2053 OMX_ERRORTYPE VIDENCTEST_CheckArgs_AVC(MYDATATYPE* pAppData, char** argv)
   2054 {
   2055     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2056 
   2057     switch (atoi(argv[9])) {
   2058         case 10:
   2059             pAppData->eLevelH264 = OMX_VIDEO_AVCLevel1;
   2060             break;
   2061         case 11:
   2062             pAppData->eLevelH264 = OMX_VIDEO_AVCLevel11;
   2063             break;
   2064         case 12:
   2065             pAppData->eLevelH264 = OMX_VIDEO_AVCLevel12;
   2066             break;
   2067         case 13:
   2068             pAppData->eLevelH264 = OMX_VIDEO_AVCLevel13;
   2069             break;
   2070         case 20:
   2071             pAppData->eLevelH264 = OMX_VIDEO_AVCLevel2;
   2072             break;
   2073         case 21:
   2074             pAppData->eLevelH264 = OMX_VIDEO_AVCLevel21;
   2075             break;
   2076         case 22:
   2077             pAppData->eLevelH264 = OMX_VIDEO_AVCLevel22;
   2078             break;
   2079         case 30:
   2080             pAppData->eLevelH264 = OMX_VIDEO_AVCLevel3;
   2081             break;
   2082         case 9:
   2083             pAppData->eLevelH264 = OMX_VIDEO_AVCLevel1b;
   2084             break;
   2085         default:
   2086             eError = OMX_ErrorBadParameter;
   2087             printf("*Error: Input Argument CONTROL RATE is not valid");
   2088             goto EXIT;
   2089     }
   2090 
   2091     pAppData->nOutBuffSize  = atoi(argv[10]);
   2092 
   2093     if (atoi(argv[11]) == 0) {
   2094         pAppData->bAllocateIBuf = OMX_FALSE;
   2095         pAppData->bAllocateOBuf = OMX_FALSE;
   2096     }
   2097     else {
   2098         pAppData->bAllocateIBuf = OMX_TRUE;
   2099         pAppData->bAllocateOBuf = OMX_TRUE;
   2100     }
   2101 
   2102     if (atoi(argv[12]) == 0) {
   2103             pAppData->bDeblockFilter = OMX_FALSE;
   2104     }
   2105     else if (atoi(argv[12]) == 1) {
   2106         pAppData->bDeblockFilter = OMX_TRUE;
   2107     }
   2108     else {
   2109         eError = OMX_ErrorBadParameter;
   2110         printf("*Error: Input Argument DEBLOCK FILTER is not valid");
   2111         goto EXIT;
   2112     }
   2113 
   2114 
   2115     switch (atoi(argv[13])) {
   2116         case 0:
   2117             pAppData->eControlRate = OMX_Video_ControlRateDisable;
   2118             break;
   2119         case 1:
   2120             pAppData->eControlRate = OMX_Video_ControlRateVariable;
   2121             break;
   2122         case 2:
   2123             pAppData->eControlRate = OMX_Video_ControlRateConstant;
   2124             break;
   2125         default:
   2126             ;
   2127     }
   2128 
   2129     pAppData->nQpI = atoi(argv[14]);
   2130 
   2131 EXIT:
   2132     return eError;
   2133 }
   2134 
   2135 /*-----------------------------------------------------------------------------*/
   2136 /**
   2137   * VIDENCTEST_CheckOptionalArgs()
   2138   *
   2139   *Validates input argument from user.
   2140   *
   2141   * @param  argc
   2142   * @param  argv
   2143   *
   2144   * @retval OMX_ErrorNone
   2145   *
   2146   *
   2147   **/
   2148 /*-----------------------------------------------------------------------------*/
   2149 
   2150 
   2151 OMX_ERRORTYPE VIDENCTEST_CheckOptionalArgs(MYDATATYPE* pAppData, int argc, char* argv []){
   2152     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2153     int next_option;
   2154     const char* const short_options = "m:r:i:p:e:n";
   2155     const struct option long_options[] = {
   2156         {"nMIRRate",    1, NULL, 'm'},
   2157         {"nResyncMarker",   1, NULL, 'r'},
   2158         {"nIntraFrameInterval",   1, NULL, 'i'},
   2159         {"nEncodingPreset",   1, NULL, 'p'},
   2160         {"nRrker",   1, NULL, 'e'},
   2161         {"NALFormat",   1, NULL, 'n'},
   2162         {"nQPIoF", 1, NULL, 'q'},
   2163         {"nUnrestrictedMV", 1, NULL, 'u'},
   2164         {NULL,          0, NULL,   0}
   2165     };
   2166 
   2167     VIDENCTEST_PRINT("checking for optional args\n");
   2168     do
   2169         {
   2170         next_option = getopt_long(argc, argv, short_options, long_options, NULL);
   2171         switch (next_option)
   2172             {
   2173             case 'm':
   2174                 printf("%d MIRRate found, Value= %s\n",next_option,optarg);
   2175                 pAppData->nMIRRate=atoi(optarg);
   2176                 break;
   2177             case 'r':
   2178                 printf("%d ResyncMarker found, Value= %s\n",next_option,optarg);
   2179                 pAppData->nResynchMarkerSpacing=atoi(optarg);
   2180                 break;
   2181             case 'i':
   2182                 printf("%d IntraFrameInterval found, Value= %s\n",next_option,optarg);
   2183                 pAppData->nIntraFrameInterval=atoi(optarg);
   2184                 break;
   2185             case 'p':
   2186                 if(pAppData->eCompressionFormat == OMX_VIDEO_CodingAVC){
   2187                     printf("%d EncodingPreset found, Value= %s\n",next_option,optarg);
   2188                     pAppData->nEncodingPreset=atoi(optarg);
   2189                     }
   2190                 else
   2191                     printf("** Warning: EncodingPreset valid only for H264. Proceeding with test.\n");
   2192                 break;
   2193             case 'n':
   2194                 printf("%d Nal Format found, Value= %s\n",next_option,optarg);
   2195                 pAppData->NalFormat=atoi(optarg);
   2196                 break;
   2197             case 'q':
   2198                 printf("%d QPI value changed each %d frames\n",next_option,atoi(optarg));
   2199                 pAppData->nQPIoF=atoi(optarg);
   2200             case 'u':
   2201                 printf("%d nUnrestrictedMV found, Value= %s\n",next_option,optarg);
   2202                 pAppData->nUnrestrictedMV=atoi(optarg);
   2203                 break;
   2204             case -1:
   2205                 break;
   2206             default:
   2207                 printf("** Warning: %d No valid param found. Proceeding with test. optarg= %s\n",next_option,optarg);
   2208 
   2209             }
   2210 
   2211     }
   2212     while(next_option != -1);
   2213 
   2214     return eError;
   2215 
   2216 }
   2217 
   2218 /*-----------------------------------------------------------------------------*/
   2219 /**
   2220   * CheckArgs()
   2221   *
   2222   *Validates input argument from user.
   2223   *
   2224   * @param  argc
   2225   * @param  argv
   2226   * @param pAppDataTmp
   2227   *
   2228   * @retval OMX_ErrorNone
   2229   *
   2230   *
   2231   **/
   2232 /*-----------------------------------------------------------------------------*/
   2233 OMX_ERRORTYPE VIDENCTEST_CheckArgs(int argc, char** argv, MYDATATYPE** pAppDataTmp)
   2234 {
   2235     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2236     VIDENCTEST_NODE*  pMemoryListHead;
   2237     MYDATATYPE* pAppData;
   2238 
   2239     eError = VIDENCTEST_ListCreate(&pMemoryListHead);
   2240     VIDENCTEST_CHECK_EXIT(eError, "Error at Creating Memory List");
   2241 
   2242     VIDENCTEST_MALLOC(pAppData, sizeof(MYDATATYPE), MYDATATYPE, pMemoryListHead);
   2243     VIDENCTEST_CHECK_EXIT(eError, "Error at Allocating MYDATATYPE structure");
   2244     *pAppDataTmp = pAppData;
   2245     pAppData->pMemoryListHead = pMemoryListHead;
   2246     pAppData->eCurrentState = VIDENCTEST_StateUnLoad;
   2247     pAppData->nMIRRate=VIDENCTEST_USE_DEFAULT_VALUE;
   2248     pAppData->nResynchMarkerSpacing=VIDENCTEST_USE_DEFAULT_VALUE;
   2249     pAppData->nIntraFrameInterval=VIDENCTEST_USE_DEFAULT_VALUE;
   2250     pAppData->nEncodingPreset=VIDENCTEST_USE_DEFAULT_VALUE_UI;
   2251     pAppData->nUnrestrictedMV=(OMX_U8)VIDENCTEST_USE_DEFAULT_VALUE_UI;
   2252     pAppData->NalFormat = 0;
   2253     pAppData->nQPIoF = 0;
   2254     pAppData->bForceIFrame = 0;
   2255 
   2256 
   2257     if (argc < 15){
   2258         printf("*Error: Input argument COLOR FORMAT is not valid");
   2259         VIDENCTEST_PrintCorrectArgs(OMX_TRUE, OMX_TRUE);
   2260         eError = OMX_ErrorBadParameter;
   2261         goto EXIT;
   2262     }
   2263     else {
   2264 
   2265         pAppData->szInFile = argv[1];
   2266         pAppData->fIn = fopen(pAppData->szInFile, "r");
   2267         if (!pAppData->fIn) {
   2268             printf("Error: failed to open the file <%s>", pAppData->szInFile);
   2269             eError = OMX_ErrorBadParameter;
   2270             goto EXIT;
   2271         }
   2272 
   2273         pAppData->szOutFile = argv[2];
   2274         pAppData->fOut = fopen(pAppData->szOutFile, "w");
   2275         if (!pAppData->fOut) {
   2276             VIDENCTEST_DPRINT("Error: failed to open the file <%s>", pAppData->szOutFile);
   2277             eError = OMX_ErrorBadParameter;
   2278             goto EXIT;
   2279         }
   2280 
   2281         pAppData->nWidth = atoi(argv[3]);
   2282         if (pAppData->nWidth & 15) {
   2283             printf("**Warning: Input Argument WIDTH is not multiple of 16. \n");
   2284         }
   2285 
   2286         pAppData->nHeight = atoi(argv[4]);
   2287         if (pAppData->nHeight & 15) {
   2288             printf("**Warning: Input Argument HEIGHT is not multiple of 16. \n");
   2289         }
   2290 
   2291         switch (atoi(argv[5])) {
   2292             case 19:
   2293                 pAppData->eColorFormat = OMX_COLOR_FormatYUV420Planar;/*420*/
   2294                 break;
   2295             case 25:
   2296                 pAppData->eColorFormat = OMX_COLOR_FormatYCbYCr;/*422-BE*/
   2297                 break;
   2298             case 26:
   2299                 pAppData->eColorFormat = OMX_COLOR_FormatCbYCrY;/*422-LE*/
   2300                 break;
   2301             default:
   2302                 printf("*Error: Input Argument COLOR FORMAT is not valid");
   2303                 VIDENCTEST_PrintCorrectArgs(OMX_TRUE, OMX_TRUE);
   2304                 eError = OMX_ErrorBadParameter;
   2305                 goto EXIT;
   2306         }
   2307 
   2308         pAppData->nBitrate = atoi(argv[6]);
   2309         if(pAppData->nBitrate > 10000000) {
   2310             printf("**Warning: Input argument BITRATE outside of tested range, behavior of component unknown.\n");
   2311         }
   2312 
   2313         pAppData->nFramerate = atoi(argv[7]);
   2314         if(pAppData->nFramerate < 7 || pAppData->nFramerate > 30) {
   2315             printf("**Warning: Input argument FRAMERATE outside of tested range, behavior of component unknown.\n");
   2316         }
   2317 
   2318         switch (atoi(argv[8])) {
   2319             case 3:
   2320                 pAppData->eCompressionFormat = OMX_VIDEO_CodingH263;
   2321                 eError = VIDENCTEST_CheckArgs_H263(pAppData, argv);
   2322                 VIDENCTEST_CHECK_EXIT(eError, "Error at Checking arguments for H263");
   2323                 break;
   2324             case 4:
   2325                 pAppData->eCompressionFormat = OMX_VIDEO_CodingMPEG4;
   2326                 eError = VIDENCTEST_CheckArgs_Mpeg4(pAppData, argv);
   2327                 VIDENCTEST_CHECK_EXIT(eError, "Error at Checking arguments for MPEG4");
   2328                 break;
   2329             case 7:
   2330                 pAppData->eCompressionFormat = OMX_VIDEO_CodingAVC;
   2331                 eError = VIDENCTEST_CheckArgs_AVC(pAppData, argv);
   2332                 VIDENCTEST_CHECK_EXIT(eError, "Error at Checking arguments for H264");
   2333                 break;
   2334             default:
   2335                 printf("*Error: Input argument COLOR FORMAT is not valid");
   2336                 VIDENCTEST_PrintCorrectArgs(OMX_TRUE, OMX_TRUE);
   2337                 eError = OMX_ErrorBadParameter;
   2338                 goto EXIT;
   2339         }
   2340     }
   2341 
   2342     if (argc < 16) {
   2343         pAppData->eTypeOfTest = VIDENCTEST_FullRecord;
   2344         printf("**Warning: Input Arguments TYPE OF TEST is not include input. Using Default value VIDENCTEST_FullRecord.\n");
   2345     }
   2346     else {
   2347         switch (atoi(argv[15])){
   2348             case 0:
   2349                 pAppData->eTypeOfTest = VIDENCTEST_FullRecord;
   2350                 pAppData->bStop = OMX_FALSE;
   2351                 break;
   2352             case 1:
   2353                 pAppData->eTypeOfTest = VIDENCTEST_PartialRecord;
   2354                 pAppData->bStop = OMX_FALSE;
   2355                 break;
   2356             case 2:
   2357                 pAppData->eTypeOfTest = VIDENCTEST_PauseResume;
   2358                 pAppData->bStop = OMX_TRUE;
   2359                 break;
   2360             case 3:
   2361                 pAppData->eTypeOfTest = VIDENCTEST_StopRestart;
   2362                 pAppData->bStop = OMX_TRUE;
   2363                 break;
   2364             default:
   2365                 pAppData->eTypeOfTest = VIDENCTEST_FullRecord;
   2366                 printf("**Warning: Input Argument TYPE OF TEST is out of range. Using Default value VIDENCTEST_FullRecord.\n");
   2367         }
   2368     }
   2369 
   2370     if (argc < 17) {
   2371         pAppData->nReferenceFrame = 0;
   2372         printf("**Warning: Input Arguments nReferenceFrame has not been specified. Using Default value 0.\n");
   2373     }
   2374     else{
   2375         pAppData->nReferenceFrame = atoi(argv[16]);
   2376     }
   2377 
   2378     if (argc < 18) {
   2379         pAppData->nNumberOfTimesTodo = 1;
   2380     }
   2381     else{
   2382         if(argv[17][0]<'0' || argv[17][0] > '9'){
   2383             pAppData->nNumberOfTimesTodo = 1;
   2384         }
   2385         else{
   2386             pAppData->nNumberOfTimesTodo  = atoi(argv[17]);
   2387             VIDENCTEST_PRINT("nNumberOfTimesTodo %lu \n", pAppData->nNumberOfTimesTodo);
   2388         }
   2389     }
   2390 
   2391     VIDENCTEST_CheckOptionalArgs(pAppData, argc, argv);
   2392 
   2393     if(pAppData->NalFormat == VIDENC_TEST_NAL_FRAME || pAppData->NalFormat == VIDENC_TEST_NAL_SLICE) {
   2394         VIDENCTEST_MALLOC(pAppData->szOutFileNal, strlen(pAppData->szOutFile)+3, char, pMemoryListHead);
   2395         strcpy(pAppData->szOutFileNal, pAppData->szOutFile);
   2396         strcat(pAppData->szOutFileNal, "nd");
   2397         pAppData->fNalnd = fopen(pAppData->szOutFileNal, "w");
   2398         if (!pAppData->szOutFileNal) {
   2399             VIDENCTEST_DPRINT("Error: failed to open the file <%s>", pAppData->szOutFileNal);
   2400             eError = OMX_ErrorBadParameter;
   2401             goto EXIT;
   2402         }
   2403     }
   2404 
   2405 EXIT:
   2406     return eError;
   2407 }
   2408 
   2409 /*-----------------------------------------------------------------------------*/
   2410 /**
   2411   * Confirm()
   2412   *
   2413   *Check what type of test, repetions to be done and takes certain path.
   2414   *
   2415   * @param  argc
   2416   * @param  argv
   2417   * @param pAppDataTmp
   2418   *
   2419   * @retval OMX_ErrorNone
   2420   *
   2421   *
   2422   **/
   2423 /*-----------------------------------------------------------------------------*/
   2424 OMX_ERRORTYPE VIDENCTEST_Confirm(MYDATATYPE* pAppData)
   2425 {
   2426     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2427     OMX_HANDLETYPE pHandle = pAppData->pHandle;
   2428 
   2429     switch (pAppData->eTypeOfTest){
   2430         case VIDENCTEST_FullRecord:
   2431         case VIDENCTEST_PartialRecord:
   2432             pAppData->nNumberOfTimesDone++;
   2433             if(pAppData->nNumberOfTimesTodo == pAppData->nNumberOfTimesDone) {
   2434                 pAppData->bExit = OMX_TRUE;
   2435             }
   2436             else {
   2437                 pAppData->bExit = OMX_FALSE;
   2438                 VIDENCTEST_PRINT("\nTimes Done: %i of %i \n", pAppData->nNumberOfTimesDone, pAppData->nNumberOfTimesTodo);
   2439                 pAppData->fOut = fopen(pAppData->szOutFile, "w");
   2440                 if(pAppData->NalFormat == VIDENC_TEST_NAL_FRAME || pAppData->NalFormat == VIDENC_TEST_NAL_SLICE) {
   2441                     pAppData->fNalnd = fopen(pAppData->szOutFileNal, "w");
   2442                 }
   2443                 if (!pAppData->fIn){
   2444                     VIDENCTEST_CHECK_EXIT(OMX_ErrorUndefined, "Error at fopen function");
   2445                 }
   2446                 rewind(pAppData->fIn);
   2447             }
   2448             eError = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
   2449             VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_SendCommand function");
   2450             break;
   2451         case VIDENCTEST_PauseResume:
   2452         case VIDENCTEST_StopRestart:
   2453             if (pAppData->bStop == OMX_TRUE) {
   2454                 if(pAppData->eTypeOfTest == VIDENCTEST_StopRestart) {
   2455                     rewind(pAppData->fIn);
   2456                     eError = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
   2457                     VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_SendCommand function");
   2458                 }
   2459                 else if (pAppData->eTypeOfTest == VIDENCTEST_PauseResume) {
   2460                     eError = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StatePause, NULL);
   2461                     VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_SendCommand function");
   2462                 }
   2463             }
   2464             else {
   2465                 pAppData->nNumberOfTimesDone++;
   2466                 if(pAppData->nNumberOfTimesTodo == pAppData->nNumberOfTimesDone) {
   2467                     pAppData->bExit = OMX_TRUE;
   2468                 }
   2469                 else {
   2470                     pAppData->bExit = OMX_FALSE;
   2471                     fprintf(stdout, "\nTimes Done: %lx of %lx \n", pAppData->nNumberOfTimesDone, pAppData->nNumberOfTimesTodo);
   2472                     if(pAppData->eTypeOfTest == VIDENCTEST_StopRestart || pAppData->eTypeOfTest == VIDENCTEST_PauseResume) {
   2473                         pAppData->bStop = OMX_TRUE;
   2474                     }
   2475                     else{
   2476                         pAppData->bStop = OMX_FALSE;
   2477                     }
   2478 
   2479                     pAppData->fOut = fopen(pAppData->szOutFile, "w");
   2480                     if (!pAppData->fOut){
   2481                         VIDENCTEST_CHECK_EXIT(OMX_ErrorUndefined, "Error at fopen function");
   2482                     }
   2483                     if(pAppData->NalFormat == VIDENC_TEST_NAL_FRAME || pAppData->NalFormat == VIDENC_TEST_NAL_SLICE) {
   2484                         pAppData->fNalnd = fopen(pAppData->szOutFileNal, "w");
   2485                         if (!pAppData->fNalnd){
   2486                             VIDENCTEST_CHECK_EXIT(OMX_ErrorUndefined, "Error at fopen function");
   2487                         }
   2488                     }
   2489                     rewind(pAppData->fIn);
   2490                 }
   2491                 eError = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
   2492                 VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_SendCommand function");
   2493             }
   2494         }
   2495 
   2496         pAppData->eCurrentState = VIDENCTEST_StateWaitEvent;
   2497 
   2498 EXIT:
   2499     return eError;
   2500 }
   2501 
   2502 /*-----------------------------------------------------------------------------*/
   2503 /**
   2504   * HandlePortDisable()
   2505   *
   2506   *Handles PortDisable Event
   2507   *
   2508   * @param  argc
   2509   * @param  argv
   2510   * @param pAppDataTmp
   2511   *
   2512   * @retval OMX_ErrorNone
   2513   *
   2514   *
   2515   **/
   2516 /*-----------------------------------------------------------------------------*/
   2517 OMX_ERRORTYPE VIDENCTEST_HandlePortDisable(MYDATATYPE* pAppData, OMX_U32 ePort)
   2518 {
   2519     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2520     OMX_HANDLETYPE pHandle = pAppData->pHandle;
   2521     OMX_U32 nCounter;
   2522     VIDENCTEST_NODE* pListHead;
   2523 
   2524     pAppData->nUnresponsiveCount = 0;
   2525     pListHead = pAppData->pMemoryListHead;
   2526 
   2527     if (ePort == VIDENC_INPUT_PORT){
   2528         eError = OMX_SendCommand(pHandle, OMX_CommandPortDisable, VIDENC_OUTPUT_PORT, NULL);
   2529         VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_SendCommand function");
   2530 
   2531         if (pAppData->bAllocateOBuf == OMX_TRUE) {
   2532             for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
   2533                 pAppData->pOBuffer[nCounter] -= 128;
   2534                 pAppData->pOBuffer[nCounter] = (unsigned char*)pAppData->pOBuffer[nCounter];
   2535                 VIDENCTEST_FREE(pAppData->pOBuffer[nCounter], pListHead);
   2536                 pAppData->pOBuffer[nCounter] = NULL;
   2537             }
   2538         }
   2539         for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
   2540             eError = OMX_FreeBuffer(pHandle, pAppData->pOutPortDef->nPortIndex, pAppData->pOutBuff[nCounter]);
   2541             VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_FreeBuffer function");
   2542         }
   2543     }
   2544     else if(ePort == VIDENC_OUTPUT_PORT) {
   2545         if (pAppData->bExit == OMX_TRUE) {
   2546             eError = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
   2547             VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_SendCommand function");
   2548             pAppData->eCurrentState = VIDENCTEST_StateLoaded;
   2549         }
   2550         else {
   2551             eError = OMX_SendCommand(pHandle, OMX_CommandPortEnable, VIDENC_INPUT_PORT, NULL);
   2552             VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_SendCommand function");
   2553 
   2554             for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
   2555                 if (pAppData->bAllocateIBuf == OMX_TRUE) {
   2556                     VIDENCTEST_MALLOC(pAppData->pIBuffer[nCounter], pAppData->nSizeIn + 256, OMX_U8, pListHead);
   2557                     pAppData->pIBuffer[nCounter] += 128;
   2558                     pAppData->pIBuffer[nCounter] = (unsigned char*)pAppData->pIBuffer[nCounter];
   2559                 }
   2560             }
   2561 
   2562             for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
   2563                 if (pAppData->bAllocateIBuf == OMX_TRUE) {
   2564                 eError = OMX_UseBuffer(pHandle,
   2565                                         &pAppData->pInBuff[nCounter],
   2566                                         pAppData->pInPortDef->nPortIndex,
   2567                                         pAppData,
   2568                                         pAppData->pInPortDef->nBufferSize,
   2569                                         pAppData->pIBuffer[nCounter]);
   2570                 VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_UseBuffer function");
   2571                 }
   2572                 else {
   2573                     eError = OMX_AllocateBuffer(pHandle,
   2574                                                 &pAppData->pInBuff[nCounter],
   2575                                                 pAppData->pInPortDef->nPortIndex,
   2576                                                 pAppData,
   2577                                                 pAppData->pInPortDef->nBufferSize);
   2578                     VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_AllocateBuffer function");
   2579                 }
   2580             }
   2581         }
   2582     }
   2583 
   2584 
   2585 EXIT:
   2586     return eError;
   2587 }
   2588 
   2589 /*-----------------------------------------------------------------------------*/
   2590 /**
   2591   * HandlePortEnable()
   2592   *
   2593   *Handles PortEnable Event
   2594   *
   2595   * @param  pAppData
   2596   * @param  nPort
   2597   *
   2598   * @retval OMX_ErrorNone
   2599   *
   2600   *
   2601   **/
   2602 /*-----------------------------------------------------------------------------*/
   2603 OMX_ERRORTYPE VIDENCTEST_HandlePortEnable(MYDATATYPE* pAppData, OMX_U32 ePort)
   2604 {
   2605     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2606     OMX_HANDLETYPE pHandle = pAppData->pHandle;
   2607     OMX_U32 nCounter;
   2608     VIDENCTEST_NODE* pListHead;
   2609 
   2610     pAppData->nUnresponsiveCount = 0;
   2611     pListHead = pAppData->pMemoryListHead;
   2612 
   2613     if (ePort == VIDENC_INPUT_PORT){
   2614         eError = OMX_SendCommand(pHandle, OMX_CommandPortEnable, VIDENC_OUTPUT_PORT, NULL);
   2615         VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_SendCommand function");
   2616 
   2617         for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
   2618             if (pAppData->bAllocateOBuf == OMX_TRUE) {
   2619                 VIDENCTEST_MALLOC(pAppData->pOBuffer[nCounter], pAppData->nSizeOut + 256, OMX_U8, pListHead);
   2620                 pAppData->pOBuffer[nCounter] += 128;
   2621                 pAppData->pOBuffer[nCounter] = (unsigned char*)pAppData->pOBuffer[nCounter];
   2622             }
   2623         }
   2624 
   2625         for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
   2626             if (pAppData->bAllocateOBuf == OMX_TRUE) {
   2627                 eError = OMX_UseBuffer(pHandle,
   2628                                         &pAppData->pOutBuff[nCounter],
   2629                                         pAppData->pOutPortDef->nPortIndex,
   2630                                         pAppData,
   2631                                         pAppData->pOutPortDef->nBufferSize,
   2632                                         pAppData->pOBuffer[nCounter]);
   2633                 VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_UseBuffer function");
   2634             }
   2635             else {
   2636                 eError = OMX_AllocateBuffer(pHandle,
   2637                                             &pAppData->pOutBuff[nCounter],
   2638                                             pAppData->pOutPortDef->nPortIndex,
   2639                                             pAppData,
   2640                                             pAppData->pOutPortDef->nBufferSize);
   2641                 VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_AllocateBuffer function");
   2642             }
   2643         }
   2644     }
   2645     else if(ePort == VIDENC_OUTPUT_PORT){
   2646         eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
   2647         VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_SendCommand function");
   2648     }
   2649 
   2650 EXIT:
   2651     return eError;
   2652 }
   2653 
   2654 /*-----------------------------------------------------------------------------*/
   2655 /**
   2656   * HandlePortEnable()
   2657   *
   2658   *Handles PortEnable Event
   2659   *
   2660   * @param  pAppData
   2661   * @param  nPort
   2662   *
   2663   * @retval OMX_ErrorNone
   2664   *
   2665   *
   2666   **/
   2667 /*-----------------------------------------------------------------------------*/
   2668 OMX_ERRORTYPE VIDENCTEST_HandleEventError(MYDATATYPE* pAppData, OMX_U32 eErr, OMX_U32 nData2)
   2669 {
   2670     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2671     VIDENCTEST_UNUSED_ARG(nData2);
   2672     VIDENCTEST_PRINT("\n------VIDENCTEST ERROR-------\nOMX_EventError\n");
   2673     VIDENCTEST_PRINT("eErr : %x \n", eErr);
   2674     VIDENCTEST_PRINT("nData2 : %x \n", nData2);
   2675 
   2676     switch (eErr){
   2677      case OMX_ErrorNone:
   2678         break;
   2679      case OMX_ErrorInsufficientResources:
   2680      case OMX_ErrorUndefined:
   2681      case OMX_ErrorInvalidComponentName:
   2682      case OMX_ErrorComponentNotFound:
   2683      case OMX_ErrorInvalidComponent:
   2684         eError = eErr;
   2685         break;
   2686      case OMX_ErrorBadParameter:
   2687      case OMX_ErrorNotImplemented:
   2688      case OMX_ErrorUnderflow:
   2689      case OMX_ErrorOverflow:
   2690         break;
   2691      case OMX_ErrorInvalidState:
   2692 #ifdef DSP_MMU_FAULT_HANDLING
   2693         bInvalid_state = OMX_TRUE;
   2694 #endif
   2695      case OMX_ErrorHardware:
   2696      case OMX_ErrorStreamCorrupt:
   2697      case OMX_ErrorPortsNotCompatible:
   2698      case OMX_ErrorResourcesLost:
   2699      case OMX_ErrorNoMore:
   2700      case OMX_ErrorVersionMismatch:
   2701      case OMX_ErrorNotReady:
   2702      case OMX_ErrorTimeout:
   2703      case OMX_ErrorSameState:
   2704      case OMX_ErrorResourcesPreempted:
   2705         eError = eErr;
   2706         break;
   2707      case OMX_ErrorPortUnresponsiveDuringAllocation:
   2708      case OMX_ErrorPortUnresponsiveDuringDeallocation:
   2709      case OMX_ErrorPortUnresponsiveDuringStop:
   2710         if(pAppData->nUnresponsiveCount++ > MAX_UNRESPONSIVE_COUNT){
   2711             eError = eErr;
   2712         }
   2713         break;
   2714      case OMX_ErrorIncorrectStateTransition:
   2715      case OMX_ErrorIncorrectStateOperation:
   2716      case OMX_ErrorUnsupportedSetting:
   2717      case OMX_ErrorUnsupportedIndex:
   2718      case OMX_ErrorBadPortIndex:
   2719      case OMX_ErrorMax:
   2720      default:
   2721         ;
   2722     }
   2723 
   2724     return eError;
   2725  }
   2726 
   2727 
   2728 /*-----------------------------------------------------------------------------*/
   2729 /**
   2730   * Main()
   2731   *
   2732   *Control flow of the Stand Alone Test Application
   2733   *
   2734   * @param  argc
   2735   * @param argv
   2736   *
   2737   * @retval OMX_ErrorNone
   2738   *
   2739   *
   2740   **/
   2741 /*-----------------------------------------------------------------------------*/
   2742 int main(int argc, char** argv)
   2743 {
   2744     OMX_ERRORTYPE eError = OMX_ErrorNone;
   2745     OMX_HANDLETYPE pHandle;
   2746     OMX_BUFFERHEADERTYPE* pBuffer;
   2747     OMX_U32 nError;
   2748     OMX_U32 nTimeCount;
   2749     MYDATATYPE* pAppData;
   2750     fd_set rfds;
   2751     VIDENCTEST_NODE* pListHead;
   2752     sigset_t set;
   2753 
   2754     nTimeCount = 0;
   2755 #ifdef DSP_MMU_FAULT_HANDLING
   2756     bInvalid_state = OMX_FALSE;
   2757 #endif
   2758     OMX_OTHER_EXTRADATATYPE_1_1_2 *pExtraDataType;
   2759     OMX_U8* pTemp;
   2760     OMX_U32* pIndexNal;
   2761     OMX_U32 nNalSlices;
   2762 
   2763 
   2764     VIDENCTEST_PRINT("Enter to CheckArgs\n");
   2765 
   2766     eError = VIDENCTEST_CheckArgs(argc, argv, &pAppData);
   2767 
   2768     VIDENCTEST_CHECK_ERROR(eError, "Invalid Arguments");
   2769     VIDENCTEST_PRINT("Exit to CheckArgs\n");
   2770 
   2771     VIDENCTEST_PRINT("Enter to PassToLoaded\n");
   2772     eError = VIDENCTEST_PassToLoaded(pAppData);
   2773     VIDENCTEST_CHECK_ERROR(eError, "Error at Initialization of Component");
   2774     VIDENCTEST_PRINT("Exit to PassToLoaded\n");
   2775 
   2776     pListHead = pAppData->pMemoryListHead;
   2777     pHandle = pAppData->pHandle;
   2778 
   2779     VIDENCTEST_PRINT("Enter to PassToReady\n");
   2780     eError = VIDENCTEST_PassToReady(pAppData);
   2781     VIDENCTEST_CHECK_ERROR(eError, "Error at Passing to ComponentReady State");
   2782     VIDENCTEST_PRINT("Exit to PassToReady\n");
   2783 
   2784     while(1){
   2785         FD_ZERO(&rfds);
   2786         FD_SET(pAppData->IpBuf_Pipe[0], &rfds);
   2787         FD_SET(pAppData->OpBuf_Pipe[0], &rfds);
   2788         FD_SET(pAppData->eventPipe[0], &rfds);
   2789 
   2790         sigemptyset(&set);
   2791         sigaddset(&set,SIGALRM);
   2792         pAppData->nRetVal = pselect(pAppData->fdmax+1, &rfds, NULL, NULL, NULL,&set);
   2793 
   2794         if (pAppData->nRetVal == -1) {
   2795             perror("pselect()");
   2796             VIDENCTEST_DPRINT("Error\n");
   2797             break;
   2798         }
   2799 
   2800         if (pAppData->nRetVal == 0) {
   2801             if (nTimeCount++ > VIDENCTEST_MAX_TIME_OUTS) {
   2802                 VIDENCTEST_DPRINT("Application: Timeout!!!\n");
   2803                 printf("\n------VIDENCTEST FATAL ERROR-------\n Component Unresponsive \n");
   2804                 VIDENCTEST_HandleError(pAppData, OMX_ErrorUndefined);
   2805                 goto EXIT;
   2806             }
   2807             sched_yield();
   2808         }
   2809         else{
   2810             nTimeCount = 0;
   2811         }
   2812 
   2813         if (FD_ISSET(pAppData->eventPipe[0], &rfds)) {
   2814             EVENT_PRIVATE* pEventPrivate = NULL;
   2815             OMX_EVENTTYPE eEvent = -1;
   2816             OMX_U32 nData1 = 0;
   2817             OMX_U32 nData2 = 0;
   2818 
   2819             read(pAppData->eventPipe[0], &pEventPrivate, sizeof(pEventPrivate));
   2820             eEvent = pEventPrivate->eEvent;
   2821             nData1 = pEventPrivate->nData1;
   2822             nData2 = pEventPrivate->nData2;
   2823 
   2824             switch (eEvent) {
   2825                 case OMX_EventCmdComplete:
   2826                     switch (nData1){
   2827                         case OMX_CommandStateSet:
   2828                             VIDENCTEST_PRINT("Enter to HandleState\n");
   2829                             eError = VIDENCTEST_HandleState(pAppData, nData2);
   2830                             VIDENCTEST_CHECK_ERROR(eError, "Error at HandleState function");
   2831                             VIDENCTEST_PRINT("Exit to HandleState\n");
   2832                             break;
   2833                         case OMX_CommandFlush:
   2834                             break;
   2835                         case OMX_CommandPortDisable:
   2836                             VIDENCTEST_PRINT("Enter to HandlePortDisable\n");
   2837                             eError = VIDENCTEST_HandlePortDisable(pAppData, nData2);
   2838                             VIDENCTEST_CHECK_ERROR(eError, "Error at HandlePortDisable function");
   2839                             VIDENCTEST_PRINT("Exits to HandlePortDisable\n");
   2840                             break;
   2841                         case OMX_CommandPortEnable:
   2842                             VIDENCTEST_PRINT("Enter to HandlePortEnable\n");
   2843                             eError = VIDENCTEST_HandlePortEnable(pAppData, nData2);
   2844                             VIDENCTEST_CHECK_ERROR(eError, "Error at PortPortEnable function");
   2845                             VIDENCTEST_PRINT("Exits to HandlePortEnable\n");
   2846                             break;
   2847                         case OMX_CommandMarkBuffer:
   2848                             ;
   2849                     }
   2850                     break;
   2851                 case OMX_EventError:
   2852                     eError = VIDENCTEST_HandleEventError(pAppData, nData1, nData2);
   2853                     VIDENCTEST_CHECK_ERROR(eError, "Fatal EventError");
   2854                     break;
   2855                 case OMX_EventMax:
   2856                     VIDENCTEST_PRINT("OMX_EventMax recived, nothing to do\n");
   2857                     break;
   2858                 case OMX_EventMark:
   2859                     VIDENCTEST_PRINT("OMX_EventMark recived, nothing to do\n");
   2860                     break;
   2861                 case OMX_EventPortSettingsChanged:
   2862                     VIDENCTEST_PRINT("OMX_EventPortSettingsChanged recived, nothing to do\n");
   2863                     break;
   2864                 case OMX_EventBufferFlag:
   2865                     VIDENCTEST_PRINT("OMX_EventBufferFlag recived, nothing to do\n");
   2866                     break;
   2867                 case OMX_EventResourcesAcquired:
   2868                     VIDENCTEST_PRINT("OMX_EventResourcesAcquired recived, nothing to do\n");
   2869                     break;
   2870                 case OMX_EventComponentResumed:
   2871                     VIDENCTEST_PRINT("OMX_EventComponentResumed recived, nothing to do\n");
   2872                     break;
   2873                 case OMX_EventDynamicResourcesAvailable:
   2874                     VIDENCTEST_PRINT("OMX_EventDynamicResourcesAvailable recived, nothing to do\n");
   2875                     break;
   2876                 case OMX_EventPortFormatDetected:
   2877                     VIDENCTEST_PRINT("OMX_EventPortFormatDetected recived, nothing to do\n");
   2878                     break;
   2879                 case OMX_EventKhronosExtensions:
   2880                     VIDENCTEST_PRINT("OMX_EventKhronosExtensions recived, nothing to do\n");
   2881                     break;
   2882                 case OMX_EventVendorStartUnused:
   2883                     VIDENCTEST_PRINT("OMX_EventVendorStartUnused recived, nothing to do\n");
   2884                     break;
   2885                 default:
   2886                     VIDENCTEST_CHECK_ERROR(OMX_ErrorUndefined, "Error at EmptyThisBuffer function");
   2887                     break;
   2888             }
   2889 
   2890             VIDENCTEST_FREE(pEventPrivate, pListHead);
   2891         }
   2892 
   2893         if(FD_ISSET(pAppData->IpBuf_Pipe[0], &rfds)){
   2894             VIDENCTEST_PRINT("Input Pipe event receive\n");
   2895             read(pAppData->IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   2896             pAppData->nInBufferCount++;
   2897 
   2898             if(pAppData->eCurrentState == VIDENCTEST_StateEncoding) {
   2899                 pBuffer->nFilledLen = VIDENCTEST_fill_data(pBuffer, pAppData->fIn , pAppData->pInPortDef->nBufferSize);
   2900 
   2901                 if (pBuffer->nFlags == OMX_BUFFERFLAG_EOS && pBuffer->nFilledLen == 0) {
   2902                     pAppData->eCurrentState = VIDENCTEST_StateStopping;
   2903                     eError = pAppData->pComponent->EmptyThisBuffer(pHandle, pBuffer);
   2904                     VIDENCTEST_CHECK_ERROR(eError, "Error at EmptyThisBuffer function");
   2905                     pAppData->nInBufferCount--;
   2906                 }
   2907 
   2908                 if(pAppData->eTypeOfTest != VIDENCTEST_FullRecord){
   2909                     if(pAppData->nCurrentFrameIn == pAppData->nReferenceFrame){
   2910                         pAppData->eCurrentState = VIDENCTEST_StateStopping;
   2911                         if(pAppData->eTypeOfTest == VIDENCTEST_PauseResume) {
   2912                             eError = pAppData->pComponent->EmptyThisBuffer(pHandle, pBuffer);
   2913                             VIDENCTEST_CHECK_ERROR(eError, "Error at EmptyThisBuffer function");
   2914                             pAppData->nInBufferCount--;
   2915                             pAppData->nCurrentFrameIn++;
   2916                         }
   2917                     }
   2918                 }
   2919 
   2920                 if(pAppData->eCurrentState == VIDENCTEST_StateEncoding){
   2921                     if(pAppData->nQPIoF > 0) {
   2922                         if(!(pAppData->nCurrentFrameIn % pAppData->nQPIoF)) {
   2923                             pAppData->bForceIFrame = OMX_TRUE;
   2924 
   2925                             eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.ForceIFrame", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
   2926                             VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
   2927                             eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->bForceIFrame));
   2928                             VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for bForceIFrame");
   2929                             eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.QPI", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
   2930                             VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
   2931                             eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nQpI));
   2932                             VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for bForceIFrame");
   2933                         }
   2934                         else {
   2935                             pAppData->bForceIFrame = OMX_FALSE;
   2936                             eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.ForceIFrame", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
   2937                             VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
   2938                             eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->bForceIFrame));
   2939                             VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for bForceIFrame");
   2940                         }
   2941                     }
   2942                     eError = pAppData->pComponent->EmptyThisBuffer(pHandle, pBuffer);
   2943                     VIDENCTEST_CHECK_ERROR(eError, "Error at EmptyThisBuffer function");
   2944                     pAppData->nInBufferCount--;
   2945                     pAppData->nCurrentFrameIn++;
   2946                 }
   2947             }
   2948 
   2949             if(pAppData->eCurrentState == VIDENCTEST_StateStopping) {
   2950                 if(pAppData->nInBufferCount == NUM_OF_IN_BUFFERS){
   2951                     pAppData->eCurrentState = VIDENCTEST_StateConfirm;
   2952                 }
   2953             }
   2954         }
   2955 
   2956         if(FD_ISSET(pAppData->OpBuf_Pipe[0], &rfds)){
   2957             VIDENCTEST_PRINT("Output Pipe event receive\n");
   2958             read(pAppData->OpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
   2959             pAppData->nOutBufferCount++;
   2960 
   2961 
   2962             /* check is it is the last buffer */
   2963             if((pBuffer->nFlags & OMX_BUFFERFLAG_EOS) ||
   2964                 (pAppData->eTypeOfTest != VIDENCTEST_FullRecord &&
   2965                 pAppData->nCurrentFrameIn == pAppData->nReferenceFrame)) {
   2966                 pAppData->bLastOutBuffer = 1;
   2967             }
   2968 
   2969             /*App sends last buffer as null buffer, so buffer with EOS contains only garbage*/
   2970             if(pBuffer->nFilledLen) {
   2971                 pAppData->nCurrentFrameOut++;
   2972                 fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, pAppData->fOut);
   2973                 nError = ferror(pAppData->fOut);
   2974                 if (nError != 0) {
   2975                     VIDENCTEST_DPRINT("ERROR: writing to file\n");
   2976                 }
   2977                 nError = fflush(pAppData->fOut);
   2978                 if (nError != 0) {
   2979                     VIDENCTEST_DPRINT("ERROR: flushing file\n");
   2980                 }
   2981 
   2982                 if(pAppData->NalFormat == VIDENC_TEST_NAL_SLICE){
   2983                     nNalSlices = 1;
   2984                     fwrite(&nNalSlices, 1, sizeof(OMX_U32), pAppData->fNalnd);
   2985                     fwrite(&(pBuffer->nFilledLen), 1, sizeof(OMX_U32), pAppData->fNalnd);
   2986                     nError = ferror(pAppData->fNalnd);
   2987                     if (nError != 0) {
   2988                         VIDENCTEST_DPRINT("ERROR: writing to file\n");
   2989                     }
   2990                     nError = fflush(pAppData->fNalnd);
   2991                     if (nError != 0) {
   2992                         VIDENCTEST_DPRINT("ERROR: flushing file\n");
   2993                     }
   2994                 }
   2995                 /* Check if it is Nal format and if it has extra data*/
   2996                 if((pAppData->NalFormat == VIDENC_TEST_NAL_FRAME) &&
   2997                     (pBuffer->nFlags & OMX_BUFFERFLAG_EXTRADATA)){
   2998 
   2999                     pTemp = pBuffer->pBuffer + pBuffer->nOffset + pBuffer->nFilledLen + 3;
   3000                     pExtraDataType = (OMX_OTHER_EXTRADATATYPE_1_1_2*) (((OMX_U32) pTemp) & ~3);
   3001                     pIndexNal = (OMX_U32*)(pExtraDataType->data);
   3002 
   3003                     nNalSlices = *pIndexNal;
   3004                     fwrite(pIndexNal, 1, sizeof(OMX_U32), pAppData->fNalnd);
   3005 
   3006                     while(nNalSlices--) {
   3007                         pIndexNal++;
   3008                         fwrite(pIndexNal, 1, sizeof(OMX_U32), pAppData->fNalnd);
   3009                         nError = ferror(pAppData->fNalnd);
   3010                         if (nError != 0) {
   3011                             VIDENCTEST_DPRINT("ERROR: writing to file\n");
   3012                         }
   3013                         nError = fflush(pAppData->fNalnd);
   3014                         if (nError != 0) {
   3015                             VIDENCTEST_DPRINT("ERROR: flushing file\n");
   3016                         }
   3017                     }
   3018                 }
   3019             }
   3020 
   3021             if(pAppData->eCurrentState == VIDENCTEST_StateEncoding ||
   3022                 pAppData->eCurrentState == VIDENCTEST_StateStopping) {
   3023                 pBuffer->nFilledLen = 0;
   3024                 eError = pAppData->pComponent->FillThisBuffer(pHandle, pBuffer);
   3025                 VIDENCTEST_CHECK_ERROR(eError, "Error at FillThisBuffer function");
   3026                 pAppData->nOutBufferCount--;
   3027             }
   3028         }
   3029 
   3030         if (pAppData->eCurrentState == VIDENCTEST_StateConfirm ) {
   3031             if (pAppData->bLastOutBuffer){
   3032                 VIDENCTEST_PRINT("Number of Input  Buffer at Client Side : %i\n", pAppData->nInBufferCount);
   3033                 VIDENCTEST_PRINT("Number of Output Buffer at Client Side : %i\n", pAppData->nOutBufferCount);
   3034                 VIDENCTEST_PRINT("Frames Out: %i\n", pAppData->nCurrentFrameOut);
   3035                 VIDENCTEST_PRINT("Enter to Confirm Function\n");
   3036                 eError = VIDENCTEST_Confirm(pAppData);
   3037                 VIDENCTEST_CHECK_ERROR(eError, "Error at VIDENCTEST_Confirm function");
   3038                 VIDENCTEST_PRINT("Exits to Confirm Function\n");
   3039             }
   3040         }
   3041 
   3042         if (pAppData->eCurrentState == VIDENCTEST_StateUnLoad) {
   3043             VIDENCTEST_PRINT("Exiting while\n");
   3044             break;
   3045         }
   3046         sched_yield();
   3047     }
   3048     if(pAppData->nCurrentFrameIn != pAppData->nCurrentFrameOut)
   3049     {
   3050         printf("App: Warning!!! FrameIn: %d FrameOut: %d\n", (int)pAppData->nCurrentFrameIn, (int)pAppData->nCurrentFrameOut);
   3051     }
   3052 
   3053     eError = VIDENCTEST_DeInit(pAppData);
   3054 
   3055 EXIT:
   3056     return eError;
   3057 }
   3058 
   3059 #ifdef DSP_MMU_FAULT_HANDLING
   3060 int LoadBaseImage()
   3061 {
   3062     unsigned int uProcId = 0;   /* default proc ID is 0. */
   3063     unsigned int index = 0;
   3064 
   3065     struct DSP_PROCESSORINFO dspInfo;
   3066     DSP_HPROCESSOR hProc;
   3067     DSP_STATUS status = DSP_SOK;
   3068     unsigned int numProcs;
   3069     char* argv[2];
   3070 
   3071     argv[0] = "/lib/dsp/baseimage.dof";
   3072 
   3073     status = (DBAPI)DspManager_Open(0, NULL);
   3074     if (DSP_FAILED(status)) {
   3075         printf("DSPManager_Open failed \n");
   3076         return -1;
   3077     }
   3078     while (DSP_SUCCEEDED(DSPManager_EnumProcessorInfo(index,&dspInfo,
   3079         (unsigned int)sizeof(struct DSP_PROCESSORINFO),&numProcs))) {
   3080         if ((dspInfo.uProcessorType == DSPTYPE_55) ||
   3081             (dspInfo.uProcessorType == DSPTYPE_64)) {
   3082             uProcId = index;
   3083             status = DSP_SOK;
   3084             break;
   3085         }
   3086         index++;
   3087     }
   3088     status = DSPProcessor_Attach(uProcId, NULL, &hProc);
   3089     if (DSP_SUCCEEDED(status)) {
   3090         status = DSPProcessor_Stop(hProc);
   3091         if (DSP_SUCCEEDED(status)) {
   3092             status = DSPProcessor_Load(hProc,1,(const char **)argv,NULL);
   3093             if (DSP_SUCCEEDED(status)) {
   3094                 status = DSPProcessor_Start(hProc);
   3095                 if (DSP_SUCCEEDED(status)) {
   3096                     fprintf(stderr,"Baseimage Loaded\n");
   3097                 }
   3098                 else {
   3099                     fprintf(stderr,"APP: Baseimage start error!\n");
   3100                 }
   3101             }
   3102             else {
   3103                 fprintf(stderr,"APP: Baseimage load error!\n");
   3104             }
   3105             DSPProcessor_Detach(hProc);
   3106         }
   3107         else {
   3108             fprintf(stderr,"APP: Baseimage stop error!\n");
   3109         }
   3110     }
   3111     else {
   3112         fprintf(stderr,"APP: Baseimage attach error!\n");
   3113     }
   3114 
   3115     return 0;
   3116 }
   3117 #endif
   3118 
   3119 
   3120