This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to run VENC on DM814x to support multi-channel encode?

HI,

I am using DM81x SDK 05_02_00_48 to encode frames. I am trying to make 2 encode components running simultaneously but it doesn't successfully encode the video.


I have been able to create a handle for both components, setup all the parameters, allocate all the buffers,
and move both components into the execute state. However, when I actually send video frames to the second handle,
the EmptyBufferDone callback is executed but the FillBufferDone callback never gets called.
The first encoder takes frames and encodes them just fine without problem.

Can you please suggest how to run multiple encoders in parallel?

Can you suggest how to do? and provide example code if you have already?

Thanks
Prakash

  • Hi Prakash,

    Refer this post http://e2e.ti.com/support/embedded/multimedia_software_codecs/f/356/p/366322/1291033.aspx#1291033  it also has code attached.

    Regards,

    --Prabhakar Lad

  • Dear Prabhakar

    Thanks for your quick reply. I referred earlier to same thread and example source provided to create 2 Encoder instances. It is working fine, in the sense when I use each client separately to encode frames it works fine. But When I run both components parallel and call OMX_FillThisBuffer and OMX_EmptyThisBUffer() functions to both clients alternately then there is IL_ClientCbFillBufferDone() called for the 1st Client, But there is no IL_ClientCbFillBufferDone callback returned from component for the 2nd Client.

    In your example code there is no OMX_FillThisBUffer() and OMX_EmptyThisBUffer() calls to 2nd Handle created. Can you please check?

    Thanks

    Prakash

  • Hi Prakash,

    I am able to execute two encoder instances . 

    Here I am using same input yuv file for both instances and generating two outputs.

    But there is some issue with second instance EOS. the file sizes are not matching.

    Can you exectue encode executible with the attached ilclient files?

    Ram

    1754.ilclient.c
    /*
     *  Copyright (c) 2010-2011, Texas Instruments Incorporated
     *
     *  Redistribution and use in source and binary forms, with or without
     *  modification, are permitted provided that the following conditions
     *  are met:
     *
     *  *  Redistributions of source code must retain the above copyright
     *     notice, this list of conditions and the following disclaimer.
     *
     *  *  Redistributions in binary form must reproduce the above copyright
     *     notice, this list of conditions and the following disclaimer in the
     *     documentation and/or other materials provided with the distribution.
     *
     *  *  Neither the name of Texas Instruments Incorporated nor the names of
     *     its contributors may be used to endorse or promote products derived
     *     from this software without specific prior written permission.
     *
     *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *  Contact information for paper mail:
     *  Texas Instruments
     *  Post Office Box 655303
     *  Dallas, Texas 75265
     *  Contact information:
     *  http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
     *  DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
     *  ============================================================================
     *
     */
    
    /**
     *******************************************************************************
     *  @file  encode_test.c
     *  @brief This file contains all Functions related to Test Application
     *
     *         This is the example IL Client support to create, configure & chaining
     *         of multi channel omx-components using proprietary tunneling 
     *         mode
     *
     *  @rev 1.0
     *******************************************************************************
     */
    
    /*******************************************************************************
    *                             Compilation Control Switches
    *******************************************************************************/
    /* None */
    
    /*******************************************************************************
    *                             INCLUDE FILES
    *******************************************************************************/
    
    /*--------------------- system and platform files ----------------------------*/
    #include <stdint.h>
    #include <string.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <pthread.h>
    #include <unistd.h>
    #include <xdc/std.h>
    #include <xdc/runtime/Assert.h>
    #include <xdc/runtime/Timestamp.h>
    #include "timm_osal_trace.h"
    /*-------------------------program files -------------------------------------*/
    #include "ti/omx/interfaces/openMaxv11/OMX_Core.h"
    #include "ti/omx/interfaces/openMaxv11/OMX_Component.h"
    #include "ilclient.h"
    #include "ilclient_utils.h"
    #include "OMX_TI_Common.h"
    #include "OMX_TI_Index.h"
    #include "OMX_TI_Video.h"
    #include "timm_osal_interfaces.h"
    #include "omx_venc.h"
    
    OMX_BOOL gILClientExit = OMX_FALSE;
    OMX_BOOL gILClientExitRead = OMX_FALSE;
    
    typedef void *(*ILC_StartFcnPtr) (void *);
    /* ========================================================================== */
    /**
    * IL_ClientCbEventHandler() : This method is the event handler implementation to 
    * handle events from the OMX Derived component
    *
    * @param hComponent        : Handle to the component
    * @param ptrAppData        : 
    * @param eEvent            :
    * @param nData1            :
    * @param nData2            :
    * @param pEventData        :
    *
    *  @return      
    *  OMX_ErrorNone = Successful 
    *
    *  Other_value = Failed (Error code is returned)
    *
    */
    /* ========================================================================== */
    OMX_ERRORTYPE IL_ClientCbEventHandler (OMX_HANDLETYPE hComponent,
                                                  OMX_PTR ptrAppData,
                                                  OMX_EVENTTYPE eEvent,
                                                  OMX_U32 nData1, OMX_U32 nData2,
                                                  OMX_PTR pEventData)
    {
      IL_CLIENT_COMP_PRIVATE *comp;
    
      comp = ptrAppData;
    
      printf ("got event");
      if (eEvent == OMX_EventCmdComplete)
      {
        if (nData1 == OMX_CommandStateSet)
        {
          printf ("State changed to: ");
          switch ((int) nData2)
          {
            case OMX_StateInvalid:
              printf ("OMX_StateInvalid \n");
              break;
            case OMX_StateLoaded:
              printf ("OMX_StateLoaded \n");
              break;
            case OMX_StateIdle:
              printf ("OMX_StateIdle \n");
              break;
            case OMX_StateExecuting:
              printf ("OMX_StateExecuting \n");
              break;
            case OMX_StatePause:
              printf ("OMX_StatePause\n");
              break;
            case OMX_StateWaitForResources:
              printf ("OMX_StateWaitForResources\n");
              break;
          }
          /* post an semaphore, so that in IL Client we can confirm the state
             change */
          semp_post (comp->done_sem);
        }
        else if (OMX_CommandFlush == nData1) {
         printf(" OMX_CommandFlush completed \n");
          semp_post (comp->done_sem);
         }
        
        else if (OMX_CommandPortEnable || OMX_CommandPortDisable)
        {
          printf ("Enable/Disable Event \n");
          semp_post (comp->port_sem);
        }
      }
      else if (eEvent == OMX_EventBufferFlag)
      {
        printf ("OMX_EventBufferFlag \n");
        if ((int) nData2 == OMX_BUFFERFLAG_EOS)
        {
          printf ("got EOS event \n");
          semp_post (comp->eos);
        }
      }
      else if (eEvent == OMX_EventError)
      {
        printf ("*** unrecoverable error: %s (0x%lx) \n",
                IL_ClientErrorToStr (nData1), nData1);
        printf ("Press a key to proceed\n");
      }
      else
      {
        printf ("unhandled event, param1 = %i, param2 = %i \n", (int) nData1,
                (int) nData2);
      }
    
      return OMX_ErrorNone;
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientCbEmptyBufferDone() : This method is the callback implementation to 
    * handle EBD events from the OMX Derived component
    *
    * @param hComponent        : Handle to the component
    * @param ptrAppData        : app pointer, which was passed during the getHandle
    * @param pBuffer           : buffer header, for the buffer which is consumed
    *
    *  @return      
    *  OMX_ErrorNone = Successful 
    *
    *  Other_value = Failed (Error code is returned)
    *
    */
    /* ========================================================================== */
    
    OMX_ERRORTYPE IL_ClientCbEmptyBufferDone (OMX_HANDLETYPE hComponent,
                                              OMX_PTR ptrAppData,
                                              OMX_BUFFERHEADERTYPE *pBuffer)
    {
      IL_CLIENT_COMP_PRIVATE *thisComp = (IL_CLIENT_COMP_PRIVATE *) ptrAppData;
      IL_CLIENT_INPORT_PARAMS *inPortParamsPtr;
      IL_CLIENT_PIPE_MSG localPipeMsg;
    
      OMX_ERRORTYPE eError = OMX_ErrorNone;
      int retVal = 0;
    
      inPortParamsPtr = thisComp->inPortParams + pBuffer->nInputPortIndex;
    
      /* if the buffer is from file i/o, write the free buffer header into ipbuf
         pipe, else keep it in its local pipe. From local pipe It would be given to 
         remote component as "consumed buffer " */
    
      if (inPortParamsPtr->connInfo.remotePipe[0] == NULL)
      {
        /* write the empty buffer pointer to input pipe */
        retVal = write (inPortParamsPtr->ipBufPipe[1], &pBuffer, sizeof (pBuffer));
    
        if (sizeof (pBuffer) != retVal)
        {
          printf ("Error writing into Input buffer i/p Pipe!\n");
          eError = OMX_ErrorNotReady;
          return eError;
        }
      }
      else
      {
        /* Create a message that EBD is done and this buffer is ready to be
           recycled. This message will be read in buffer processing thread and
           remote component will be indicated about its status */
        localPipeMsg.cmd = IL_CLIENT_PIPE_CMD_EBD;
        localPipeMsg.pbufHeader = pBuffer;
        retVal = write (thisComp->localPipe[1],
                        &localPipeMsg, sizeof (IL_CLIENT_PIPE_MSG));
        if (sizeof (IL_CLIENT_PIPE_MSG) != retVal)
        {
          printf ("Error writing into local Pipe!\n");
          eError = OMX_ErrorNotReady;
          return eError;
        }
      }
    
      return eError;
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientCbFillBufferDone() : This method is the callback implementation to 
    * handle FBD events from the OMX Derived component
    *
    * @param hComponent        : Handle to the component
    * @param ptrAppData        : app pointer, which was passed during the getHandle
    * @param pBuffer           : buffer header, for the buffer which is produced
    *
    *  @return      
    *  OMX_ErrorNone = Successful 
    *
    *  Other_value = Failed (Error code is returned)
    *
    */
    /* ========================================================================== */
    
    OMX_ERRORTYPE IL_ClientCbFillBufferDone (OMX_HANDLETYPE hComponent,
                                             OMX_PTR ptrAppData,
                                             OMX_BUFFERHEADERTYPE *pBuffer)
    {
      IL_CLIENT_COMP_PRIVATE *thisComp = (IL_CLIENT_COMP_PRIVATE *) ptrAppData;
      IL_CLIENT_OUTPORT_PARAMS *outPortParamsPtr;
      IL_CLIENT_PIPE_MSG localPipeMsg;
    
      OMX_ERRORTYPE eError = OMX_ErrorNone;
      int retVal = 0;
    
      /* get the pipe corrsponding to this port, portIndex is part of bufferheader
         structure */
      outPortParamsPtr =
        thisComp->outPortParams + (pBuffer->nOutputPortIndex -
                                   thisComp->startOutportIndex);
    
      /* if the buffer is from file i/o, write the free buffer header into outbuf
         pipe, else keep it in its local pipe. From local pipe It would be given to 
         remote component as "filled buffer " */
      if (outPortParamsPtr->connInfo.remotePipe[0] == NULL)
      {
        /* write the empty buffer pointer to input pipe */
        retVal = write (outPortParamsPtr->opBufPipe[1], &pBuffer, sizeof (pBuffer));
    
        if (sizeof (pBuffer) != retVal)
        {
          printf ("Error writing to Input buffer i/p Pipe!\n");
          eError = OMX_ErrorNotReady;
          return eError;
        }
      }
      else
      {
        /* Create a message that FBD is done and this buffer is ready to be used by 
           other compoenent. This message will be read in buffer processing thread
           and and remote component will be indicated about its status */
        localPipeMsg.cmd = IL_CLIENT_PIPE_CMD_FBD;
        localPipeMsg.pbufHeader = pBuffer;
        retVal = write (thisComp->localPipe[1],
                        &localPipeMsg, sizeof (IL_CLIENT_PIPE_MSG));
    
        if (sizeof (IL_CLIENT_PIPE_MSG) != retVal)
        {
          printf ("Error writing to local Pipe!\n");
          eError = OMX_ErrorNotReady;
          return eError;
        }
      }
      return eError;
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientInputBitStreamReadTask() : This task function is file read task for
    * decoder component. This function calls parser functions, which provides frames
    * in each buffer to be consumed by decoder.
    *
    * @param threadsArg        : Handle to the application
    *
    */
    /* ========================================================================== */
    int g_EXIT_TASK = 0;
    
    void
    IL_ClientInputBitStreamReadTask (void *threadsArg)
    {
      unsigned int dataRead = 0, frameSize = 0, frameCounter = IL_CLIENT_ENC_INPUT_BUFFER_COUNT;
      OMX_ERRORTYPE err = OMX_ErrorNone;
      IL_CLIENT_COMP_PRIVATE *encILComp = NULL;
      OMX_BUFFERHEADERTYPE *pBufferIn = NULL;
    
      encILComp = ((IL_Client *) threadsArg)->encILComp;
    
      /* use the initial i/p buffers and make empty this buffer calls */
      err = IL_ClientEncUseInitialInputResources (threadsArg);
    
      while (1)
      {
        /* Read empty buffer pointer from the pipe */
        read (encILComp->inPortParams->ipBufPipe[0],
              &pBufferIn, sizeof (pBufferIn));
        
        frameSize = (((IL_Client *) threadsArg)->nHeight * ((IL_Client *) threadsArg)->nWidth * 3) >> 1;
        /* Fill the data in the empty buffer */
        dataRead = fread (pBufferIn->pBuffer, 1, frameSize, ((IL_Client *) threadsArg)->fIn);
        /* Exit the loop if no data available */
    
        if ((0 >= dataRead) || (gILClientExitRead == OMX_TRUE))
        {
          g_EXIT_TASK = 1;
          encILComp->numFrames = frameCounter; 
          printf ("No data available for Read encILComp->numFrames %d \n", frameCounter);
          printf(" read task exiting \n ");
          semp_post(encILComp->eos);
         // break;
          pthread_exit (NULL);
          /* can be handled as EOS .. encILComp->inPortParams->flagInputEos =
             OMX_TRUE; */
        }
    
        pBufferIn->nFilledLen = frameSize;
        pBufferIn->nOffset = 0;
        pBufferIn->nAllocLen = frameSize;
        pBufferIn->nInputPortIndex = 0;
       
        /* Pass the input buffer to the component */
        err = OMX_EmptyThisBuffer (encILComp->handle, pBufferIn);
        frameCounter++;    
        if (OMX_ErrorNone != err)
        {
          /* put back the frame in pipe and wait for state change */
          write (encILComp->inPortParams->ipBufPipe[1],
                 &pBufferIn, sizeof (pBufferIn));
          printf (" waiting for action from IL Cleint \n");
    
          /* since in this example we are changing states in other thread it will
             return error for giving ETB/FTB calls in non-execute state. Since
             example is shutting down, we exit the thread */
    
          pthread_exit (encILComp);
    
        }
      }
    
    }
    
    void
    IL_ClientInputBitStreamReadTask2 (void *threadsArg)
    {
      unsigned int dataRead = 0, frameSize = 0, frameCounter = IL_CLIENT_ENC_INPUT_BUFFER_COUNT;
      OMX_ERRORTYPE err = OMX_ErrorNone;
      IL_CLIENT_COMP_PRIVATE *encILComp = NULL;
      OMX_BUFFERHEADERTYPE *pBufferIn = NULL;
    
      encILComp = ((IL_Client *) threadsArg)->encILComp2;
    
      /* use the initial i/p buffers and make empty this buffer calls */
      err = IL_ClientEncUseInitialInputResources2 (threadsArg);
    
      while (1)
      {
        /* Read empty buffer pointer from the pipe */
        read (encILComp->inPortParams->ipBufPipe[0],
              &pBufferIn, sizeof (pBufferIn));
        
        frameSize = (((IL_Client *) threadsArg)->nHeight * ((IL_Client *) threadsArg)->nWidth * 3) >> 1;
        /* Fill the data in the empty buffer */
        dataRead = fread (pBufferIn->pBuffer, 1, frameSize, ((IL_Client *) threadsArg)->fIn2);
        /* Exit the loop if no data available */
    
        if ((0 >= dataRead) || (gILClientExitRead == OMX_TRUE))
        {
          g_EXIT_TASK = 1;
          encILComp->numFrames = frameCounter; 
          printf ("No data available for Read encILComp->numFrames %d \n", frameCounter);
          printf(" read task exiting \n ");
          semp_post(encILComp->eos);
         // break;
          pthread_exit (NULL);
          /* can be handled as EOS .. encILComp->inPortParams->flagInputEos =
             OMX_TRUE; */
        }
    
        pBufferIn->nFilledLen = frameSize;
        pBufferIn->nOffset = 0;
        pBufferIn->nAllocLen = frameSize;
        pBufferIn->nInputPortIndex = 0;
        
        /* Pass the input buffer to the component */
        err = OMX_EmptyThisBuffer (encILComp->handle, pBufferIn);
        frameCounter++;    
    
        if (OMX_ErrorNone != err)
        {
          /* put back the frame in pipe and wait for state change */
          write (encILComp->inPortParams->ipBufPipe[1],
                 &pBufferIn, sizeof (pBufferIn));
          printf (" waiting for action from IL Cleint \n");
    
          /* since in this example we are changing states in other thread it will
             return error for giving ETB/FTB calls in non-execute state. Since
             example is shutting down, we exit the thread */
    
          pthread_exit (encILComp);
    
        }
      }
    
    }
    
    
    /* ========================================================================== */
    /**
    * IL_ClientOutputBitStreamWriteTask() : This task function is file writetask for
    * encoder component. 
    *
    * @param threadsArg        : Handle to the application
    *
    */
    /* ========================================================================== */
    static int frame_count = 0;
    static int frame_count2 = 0;
    void IL_ClientOutputBitStreamWriteTask (void *threadsArg)
    {
      unsigned int frame_counter = 0;
      OMX_ERRORTYPE err = OMX_ErrorNone;
      IL_CLIENT_COMP_PRIVATE *encILComp = NULL;
      OMX_BUFFERHEADERTYPE *pBufferOut = NULL;
      
      OMX_VIDEO_CONFIG_GDRINFOTYPE gdrInfo;
      OMX_VIDEO_CONFIG_DYNAMICPARAMS dynamicParam;
    
      encILComp = ((IL_Client *) threadsArg)->encILComp;
    
      /* use the initial i/p buffers and make empty this buffer calls */
      err = IL_ClientEncUseInitialOutputResources (encILComp);
    
      while (1)
      {
        /* Read filled buffer pointer from the pipe */
        read (encILComp->outPortParams->opBufPipe[0],
              &pBufferOut, sizeof (pBufferOut));
        /* write data to output file */
        fwrite (pBufferOut->pBuffer,
                sizeof (char),
                pBufferOut->nFilledLen, ((IL_Client *) threadsArg)->fOut);
        frame_counter++;
        frame_count = frame_counter;
        if((frame_counter == encILComp->numFrames) || (gILClientExit == 1) || (g_EXIT_TASK == 1))
        {
          gILClientExitRead = 1;
          printf(" write task exited \n");
          semp_post(encILComp->eos);
          pthread_exit(NULL);
          break;
        }
        
    #if ENABLE_GDR	
        if(frame_count == 10)
        {
            OMX_INIT_PARAM (&gdrInfo);
            gdrInfo.enableGDR = 1;
            err = OMX_SetConfig (((IL_Client *) threadsArg)->pEncHandle,
                                    (OMX_INDEXTYPE) OMX_TI_IndexConfigGDRSettings,
                                    (OMX_PTR)&gdrInfo);
        }
    
        if(frame_count == 11)
        {        
            OMX_INIT_PARAM (&gdrInfo);
            err = OMX_GetConfig (((IL_Client *) threadsArg)->pEncHandle,
                                (OMX_INDEXTYPE) OMX_TI_IndexConfigGDRSettings,
                                (OMX_PTR)&gdrInfo);
            printf (" Get gdr status %d enableGDR %d intraRefreshRateGDRDynamic %d gdrOverlapRowsBtwFramesDynamic %d\n", 
                   err, gdrInfo.enableGDR, gdrInfo.intraRefreshRateGDRDynamic, gdrInfo.gdrOverlapRowsBtwFramesDynamic);
        }   
    #endif /* ENABLE_GDR */	
    
        /* Pass the input buffer to the component */
        err = OMX_FillThisBuffer (encILComp->handle, pBufferOut);
    
        if (OMX_ErrorNone != err)
        {
          /* put back the frame in pipe and wait for state change */
          write (encILComp->outPortParams->opBufPipe[1],
                 &pBufferOut, sizeof (pBufferOut));
          printf (" waiting for action from IL Client \n");
    
          /* since in this example we are changing states in other thread it will
             return error for giving ETB/FTB calls in non-execute state. Since
             example is shutting down, we exit the thread */
    
          pthread_exit (encILComp);
    
        }
      }
    
    }
    
    void IL_ClientOutputBitStreamWriteTask2 (void *threadsArg)
    {
      unsigned int frame_counter = 0;
      OMX_ERRORTYPE err = OMX_ErrorNone;
      IL_CLIENT_COMP_PRIVATE *encILComp = NULL;
      OMX_BUFFERHEADERTYPE *pBufferOut = NULL;
      
      OMX_VIDEO_CONFIG_GDRINFOTYPE gdrInfo;
      OMX_VIDEO_CONFIG_DYNAMICPARAMS dynamicParam;
    
      encILComp = ((IL_Client *) threadsArg)->encILComp2;
    
      /* use the initial i/p buffers and make empty this buffer calls */
      err = IL_ClientEncUseInitialOutputResources (encILComp);
    
      while (1)
      {
        /* Read filled buffer pointer from the pipe */
        read (encILComp->outPortParams->opBufPipe[0],
              &pBufferOut, sizeof (pBufferOut));
        /* write data to output file */
        fwrite (pBufferOut->pBuffer,
                sizeof (char),
                pBufferOut->nFilledLen, ((IL_Client *) threadsArg)->fOut2);
    
        frame_counter++;
        frame_count2 = frame_counter;
        if((frame_counter == encILComp->numFrames) || (gILClientExit == 1) || (g_EXIT_TASK == 1))
        {
          gILClientExitRead = 1;
          printf(" write task exited \n");
          semp_post(encILComp->eos);
          pthread_exit(NULL);
          break;
        }
        
    #if ENABLE_GDR	
        if(frame_count2 == 10)
        {
            OMX_INIT_PARAM (&gdrInfo);
            gdrInfo.enableGDR = 1;
            err = OMX_SetConfig (((IL_Client *) threadsArg)->pEncHandle2,
                                    (OMX_INDEXTYPE) OMX_TI_IndexConfigGDRSettings,
                                    (OMX_PTR)&gdrInfo);
        }
    
        if(frame_count2 == 11)
        {        
            OMX_INIT_PARAM (&gdrInfo);
            err = OMX_GetConfig (((IL_Client *) threadsArg)->pEncHandle2,
                                (OMX_INDEXTYPE) OMX_TI_IndexConfigGDRSettings,
                                (OMX_PTR)&gdrInfo);
            printf (" Get gdr status %d enableGDR %d intraRefreshRateGDRDynamic %d gdrOverlapRowsBtwFramesDynamic %d\n", 
                   err, gdrInfo.enableGDR, gdrInfo.intraRefreshRateGDRDynamic, gdrInfo.gdrOverlapRowsBtwFramesDynamic);
        }   
    #endif /* ENABLE_GDR */	
    
        /* Pass the input buffer to the component */
        err = OMX_FillThisBuffer (encILComp->handle, pBufferOut);
    
        if (OMX_ErrorNone != err)
        {
          /* put back the frame in pipe and wait for state change */
          write (encILComp->outPortParams->opBufPipe[1],
                 &pBufferOut, sizeof (pBufferOut));
          printf (" waiting for action from IL Client \n");
    
          /* since in this example we are changing states in other thread it will
             return error for giving ETB/FTB calls in non-execute state. Since
             example is shutting down, we exit the thread */
    
          pthread_exit (encILComp);
    
        }
      }
    
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientSIGINTHandler() : This function is the SIGINT handler that will be
    * called when the user invokes CTRL-C. This is for demonstration purpose. Also
    * it assumes that the OMX chain is in EXECUTING state when CTRL-C is invoked
    *
    * @param sig             : Signal identifier
    */
    /* ========================================================================== */
    
    void IL_ClientSIGINTHandler(int sig)
    {
     gILClientExit = OMX_TRUE;
    }
    
    
    Int Encode_Example (IL_ARGS *args)
    {
    
      OMX_U32 i;
      OMX_S32 ret_value;
      IL_Client *pAppData = NULL;
      OMX_ERRORTYPE eError = OMX_ErrorNone;
      char str[250];
      //IL_CLIENT_PIPE_MSG pipeMsg;
    
      /* Initialize application specific data structures and buffer management
         data structure */
      IL_ClientInit (&pAppData, args->width, args->height, args->frame_rate, 
                   args->bit_rate, args->codec);
    
      printf (" opening file \n");
      /* Open the file of data to be rendered.  */
      pAppData->fIn = fopen (args->input_file, "rb");;
    
      if (pAppData->fIn == NULL)
      {
        printf ("Error: failed to open the file %s for reading\n",
                args->input_file);
        goto EXIT;
      }
      
      /* Open the file of data to be rendered.  */
      pAppData->fIn2 = fopen (args->input_file, "rb");;
    
      if (pAppData->fIn2 == NULL)
      {
        printf ("Error: failed to open the file %s for reading for second isntance\n",
                args->input_file);
        goto EXIT;
      }
    
      /* Open the file of data to be rendered.  */
      pAppData->fOut = fopen (args->output_file, "wb");
    
      if (pAppData->fOut == NULL)
      {
        printf ("Error: failed to open the file %s for writing \n",
                args->output_file);
        goto EXIT;
      }
      strcpy(str,args->output_file);
      strcat(str,"_2");
    
    
      pAppData->fOut2 = fopen (str, "wb");
    
      if (pAppData->fOut2 == NULL)
      {
        printf ("Error: failed to open the second file %s for writing \n",
                args->output_file);
        goto EXIT;
      }
    
      /* Initialize application / IL Client callback functions */
      /* Callbacks are passed during getHandle call to component, Component uses
         these callaback to communicate with IL Client */
      /* event handler is to handle the state changes , omx commands and any
         message for IL client */
      pAppData->pCb.EventHandler = IL_ClientCbEventHandler;
    
      /* Empty buffer done is data callback at the input port, where component lets 
         the application know that buffer has been consumned, this is not
         applicable if there is no input port in the component */
      pAppData->pCb.EmptyBufferDone = IL_ClientCbEmptyBufferDone;
    
      /* fill buffer done is callback at the output port, where component lets the
         application know that an output buffer is available with the processed data 
       */
      pAppData->pCb.FillBufferDone = IL_ClientCbFillBufferDone;
    
    /******************************************************************************/
      /* Create the H264 encoder Component, component handle would be returned
         component name is unique and fixed for a componnet, callback are passed
         to componnet in this function. component would be loaded state post this
         call */
    
      eError =
        OMX_GetHandle (&pAppData->pEncHandle,
                       (OMX_STRING) "OMX.TI.DUCATI.VIDENC", pAppData->encILComp,
                       &pAppData->pCb);
    
      printf (" encoder component is created \n");
    
      if ((eError != OMX_ErrorNone) || (pAppData->pEncHandle == NULL))
      {
        printf ("Error in Get Handle function : %s \n",
                IL_ClientErrorToStr (eError));
        goto EXIT;
      }
      pAppData->encILComp->handle = pAppData->pEncHandle;
    
    
      /* Configute the encode componet, ports are default enabled for encode comp,
         so no need to enable from IL Client */
      /* calling OMX_Setparam in this function */
      IL_ClientSetEncodeParams (pAppData);
      
    
    /*******************************************************************************/
    
      /* OMX_SendCommand expecting OMX_StateIdle, after this command component
         would create codec, and will wait for all buffers to be allocated */
      eError =
        OMX_SendCommand (pAppData->pEncHandle, OMX_CommandStateSet,
                         OMX_StateIdle, NULL);
      if (eError != OMX_ErrorNone)
      {
        printf ("Error in SendCommand()-OMX_StateIdle State set : %s \n",
                IL_ClientErrorToStr (eError));
        goto EXIT;
      }
      /* since encoder is connected to dei, buffers are supplied by dei to
         encoder, so encoder does not allocate the buffers. However it is informed
         to use the buffers created by dei. encode component would create only
         buffer headers corresponding to these buffers */
    
      for (i = 0; i < pAppData->encILComp->inPortParams->nBufferCountActual; i++)
      {
    
        eError = OMX_AllocateBuffer (pAppData->pEncHandle,
                                &pAppData->encILComp->inPortParams->pInBuff[i],
                                OMX_VIDENC_INPUT_PORT,
                                pAppData,
                                pAppData->encILComp->inPortParams->nBufferSize);
    
        if (eError != OMX_ErrorNone)
        {
          printf ("Error in encode OMX_UseBuffer(): %s \n",
                  IL_ClientErrorToStr (eError));
          goto EXIT;
        }
      }
      printf (" encoder input port allocate buffer done \n ");
    
      /* in SDK conventionally output port allocates the buffers, encode would
         create the buffers which would be consumed by filewrite thread */
      /* buffer alloaction for output port */
      for (i = 0; i < pAppData->encILComp->outPortParams->nBufferCountActual; i++)
      {
        eError = OMX_AllocateBuffer (pAppData->pEncHandle,
                                     &pAppData->encILComp->outPortParams->
                                     pOutBuff[i], OMX_VIDENC_OUTPUT_PORT,
                                     pAppData,
                                     pAppData->encILComp->outPortParams->
                                     nBufferSize);
        if (eError != OMX_ErrorNone)
        {
          printf ("Error in OMX_AllocateBuffer()-Output Port State set : %s \n",
                  IL_ClientErrorToStr (eError));
          goto EXIT;
        }
      }
    
      printf (" encoder outport buffers allocated \n ");
    
      semp_pend (pAppData->encILComp->done_sem);
    
      printf (" Encoder state IDLE \n ");
    /******************************************************************************/
    /******************************************************************************/
    
      /* change state to execute so that buffers processing can start */
      eError =
        OMX_SendCommand (pAppData->pEncHandle, OMX_CommandStateSet,
                         OMX_StateExecuting, NULL);
      if (eError != OMX_ErrorNone)
      {
        printf ("Error from SendCommand-Executing State set :%s \n",
                IL_ClientErrorToStr (eError));
        goto EXIT;
      }
    
      semp_pend (pAppData->encILComp->done_sem);
    
      printf (" encoder state execute \n ");
    /******************************************************************************/
    
    #if 1  
      eError =
        OMX_GetHandle (&pAppData->pEncHandle2,
                       (OMX_STRING) "OMX.TI.DUCATI.VIDENC", pAppData->encILComp2,
                       &pAppData->pCb);
    
      printf (" Second encoder component is created \n");
    
      if ((eError != OMX_ErrorNone) || (pAppData->pEncHandle == NULL))
      {
        printf ("Error in Get Handle function : %s \n",
                IL_ClientErrorToStr (eError));
        goto EXIT;
      }
      
       pAppData->encILComp2->handle = pAppData->pEncHandle2;
       
       IL_ClientSetEncodeParams2 (pAppData);
       
       /*******************************************************************************/
    
      /* OMX_SendCommand expecting OMX_StateIdle, after this command component
         would create codec, and will wait for all buffers to be allocated */
      eError =
        OMX_SendCommand (pAppData->pEncHandle2, OMX_CommandStateSet,
                         OMX_StateIdle, NULL);
      if (eError != OMX_ErrorNone)
      {
        printf ("Error in SendCommand()-OMX_StateIdle State set : %s \n",
                IL_ClientErrorToStr (eError));
        goto EXIT;
      }
      /* since encoder is connected to dei, buffers are supplied by dei to
         encoder, so encoder does not allocate the buffers. However it is informed
         to use the buffers created by dei. encode component would create only
         buffer headers corresponding to these buffers */
    
      for (i = 0; i < pAppData->encILComp2->inPortParams->nBufferCountActual; i++)
      {
    
        eError = OMX_AllocateBuffer (pAppData->pEncHandle2,
                                &pAppData->encILComp2->inPortParams->pInBuff[i],
                                OMX_VIDENC_INPUT_PORT,
                                pAppData,
                                pAppData->encILComp2->inPortParams->nBufferSize);
    
        if (eError != OMX_ErrorNone)
        {
          printf ("Error in encode OMX_UseBuffer(): %s \n",
                  IL_ClientErrorToStr (eError));
          goto EXIT;
        }
      }
      printf (" Second encoder input port allocate buffer done \n ");
    
      /* in SDK conventionally output port allocates the buffers, encode would
         create the buffers which would be consumed by filewrite thread */
      /* buffer alloaction for output port */
      for (i = 0; i < pAppData->encILComp2->outPortParams->nBufferCountActual; i++)
      {
        eError = OMX_AllocateBuffer (pAppData->pEncHandle2,
                                     &pAppData->encILComp2->outPortParams->
                                     pOutBuff[i], OMX_VIDENC_OUTPUT_PORT,
                                     pAppData,
                                     pAppData->encILComp2->outPortParams->
                                     nBufferSize);
        if (eError != OMX_ErrorNone)
        {
          printf ("Error in OMX_AllocateBuffer()-Output Port State set : %s \n",
                  IL_ClientErrorToStr (eError));
          goto EXIT;
        }
      }
    
      printf (" Second encoder outport buffers allocated \n ");
    
      semp_pend (pAppData->encILComp2->done_sem);
    
      printf (" Second Encoder state IDLE \n ");
    /******************************************************************************/
    /******************************************************************************/
       /* change state to execute so that buffers processing can start */
      eError =
        OMX_SendCommand (pAppData->pEncHandle2, OMX_CommandStateSet,
                         OMX_StateExecuting, NULL);
      if (eError != OMX_ErrorNone)
      {
        printf ("Error from SendCommand-Executing State set :%s \n",
                IL_ClientErrorToStr (eError));
        goto EXIT;
      }
    
      semp_pend (pAppData->encILComp2->done_sem);
    
      printf (" Second encoder state Executing\n ");
    #endif
    
    
      /* Create thread for writing bitstream and passing the buffers to encoder
         component */
      pthread_attr_init (&pAppData->encILComp->ThreadAttr);
    
      if (0 !=
          pthread_create (&pAppData->encILComp->outDataStrmThrdId,
                          &pAppData->encILComp->ThreadAttr,
                          (ILC_StartFcnPtr) IL_ClientOutputBitStreamWriteTask, pAppData))
      {
        printf ("Create_Task failed !");
        goto EXIT;
      }
    
      printf (" file write thread created \n ");
    
      pthread_attr_init (&pAppData->encILComp->ThreadAttr);
      if (0 !=
          pthread_create (&pAppData->encILComp->inDataStrmThrdId,
                          &pAppData->encILComp->ThreadAttr,
                          (ILC_StartFcnPtr) IL_ClientInputBitStreamReadTask, pAppData))
      {
        printf ("Create_Task failed !");
        goto EXIT;
      }
    
      printf (" file read thread created \n ");
    /******************************************************************************/
     #if 1
    /* Create thread for writing bitstream and passing the buffers to encoder
         component */
      pthread_attr_init (&pAppData->encILComp2->ThreadAttr);
    
      if (0 !=
          pthread_create (&pAppData->encILComp2->outDataStrmThrdId,
                          &pAppData->encILComp2->ThreadAttr,
                          (ILC_StartFcnPtr) IL_ClientOutputBitStreamWriteTask2, pAppData))
      {
        printf ("Create_Task failed !");
        goto EXIT;
      }
    
      printf (" file write thread created for second instance\n ");
    
      pthread_attr_init (&pAppData->encILComp2->ThreadAttr);
      if (0 !=
          pthread_create (&pAppData->encILComp2->inDataStrmThrdId,
                          &pAppData->encILComp2->ThreadAttr,
                          (ILC_StartFcnPtr) IL_ClientInputBitStreamReadTask2, pAppData))
      {
        printf ("Create_Task failed !");
        goto EXIT;
      }
    
      printf (" file read thread created for second thread\n ");
    #endif
     /* Waiting for this semaphore to be posted by the bitstream write thread */
      semp_pend(pAppData->encILComp->eos);
      semp_pend(pAppData->encILComp->eos);
      printf(" received eof \n");
    /******************************************************************************/
    #if 1
     /* Waiting for this semaphore to be posted by the bitstream write thread */
      semp_pend(pAppData->encILComp2->eos);
      semp_pend(pAppData->encILComp2->eos);
      printf(" received eof \n");
    
    #endif
    
    
      /* change state to execute so that buffers processing can stop */
      eError =
      OMX_SendCommand (pAppData->pEncHandle, OMX_CommandStateSet,
                       OMX_StateIdle, NULL);
      if (eError != OMX_ErrorNone)
      {
        printf ("Error from SendCommand-Idle State set :%s \n",
                IL_ClientErrorToStr (eError));
        goto EXIT;
      }
    
      semp_pend (pAppData->encILComp->done_sem);
    
      printf (" Encoder state idle \n ");
    
      eError =
      OMX_SendCommand (pAppData->pEncHandle2, OMX_CommandStateSet,
                       OMX_StateIdle, NULL);
      if (eError != OMX_ErrorNone)
      {
        printf ("Error from SendCommand-Idle State set :%s \n",
                IL_ClientErrorToStr (eError));
        goto EXIT;
      }
    
      semp_pend (pAppData->encILComp2->done_sem);
    
      printf (" Second Encoder state idle\n ");
    /******************************************************************************/
    
      /* change the encoder state to loaded */
      eError =
        OMX_SendCommand (pAppData->pEncHandle, OMX_CommandStateSet,
                         OMX_StateLoaded, NULL);
      if (eError != OMX_ErrorNone)
      {
        printf ("Error from SendCommand-Idle State set :%s \n",
                IL_ClientErrorToStr (eError));
        goto EXIT;
      }
      /* During idle-> loaded state transition buffers need to be freed up */
      for (i = 0; i < pAppData->encILComp->inPortParams->nBufferCountActual; i++)
      {
        eError =
          OMX_FreeBuffer (pAppData->pEncHandle, OMX_VIDENC_INPUT_PORT,
                          pAppData->encILComp->inPortParams->pInBuff[i]);
        if (eError != OMX_ErrorNone)
        {
          printf ("Error in OMX_FreeBuffer : %s \n", IL_ClientErrorToStr (eError));
          goto EXIT;
        }
      }
    
      for (i = 0; i < pAppData->encILComp->outPortParams->nBufferCountActual; i++)
      {
        eError =
          OMX_FreeBuffer (pAppData->pEncHandle, OMX_VIDENC_OUTPUT_PORT,
                          pAppData->encILComp->outPortParams->pOutBuff[i]);
        if (eError != OMX_ErrorNone)
        {
          printf ("Error in OMX_FreeBuffer : %s \n", IL_ClientErrorToStr (eError));
          goto EXIT;
        }
      }
    
      semp_pend (pAppData->encILComp->done_sem);
    
      printf (" encoder state loaded \n ");
      
    
    /******************************************************************************/
    
      eError = OMX_FreeHandle (pAppData->pEncHandle);
      if ((eError != OMX_ErrorNone))
      {
        printf ("Error in Free Handle function : %s \n",
                IL_ClientErrorToStr (eError));
        goto EXIT;
      }
      printf (" encoder free handle \n");
    #if 1
    
    /******************************************************************************/
    
      /* change the encoder state to loded */
      eError =
        OMX_SendCommand (pAppData->pEncHandle2, OMX_CommandStateSet,
                         OMX_StateLoaded, NULL);
      if (eError != OMX_ErrorNone)
      {
        printf ("Error from SendCommand-Idle State set :%s \n",
                IL_ClientErrorToStr (eError));
        goto EXIT;
      }
      /* During idle-> loaded state transition buffers need to be freed up */
      for (i = 0; i < pAppData->encILComp2->inPortParams->nBufferCountActual; i++)
      {
        eError =
          OMX_FreeBuffer (pAppData->pEncHandle2, OMX_VIDENC_INPUT_PORT,
                          pAppData->encILComp2->inPortParams->pInBuff[i]);
        if (eError != OMX_ErrorNone)
        {
          printf ("Error in OMX_FreeBuffer : %s \n", IL_ClientErrorToStr (eError));
          goto EXIT;
        }
      }
    
      for (i = 0; i < pAppData->encILComp2->outPortParams->nBufferCountActual; i++)
      {
        eError =
          OMX_FreeBuffer (pAppData->pEncHandle2, OMX_VIDENC_OUTPUT_PORT,
                          pAppData->encILComp2->outPortParams->pOutBuff[i]);
        if (eError != OMX_ErrorNone)
        {
          printf ("Error in OMX_FreeBuffer : %s \n", IL_ClientErrorToStr (eError));
          goto EXIT;
        }
      }
    
      semp_pend (pAppData->encILComp2->done_sem);
    
      printf (" Second encoder state loaded \n ");
    /******************************************************************************/
    
      eError = OMX_FreeHandle (pAppData->pEncHandle2);
      if ((eError != OMX_ErrorNone))
      {
        printf ("Error in Free Handle function : %s \n",
                IL_ClientErrorToStr (eError));
        goto EXIT;
      }
      printf (" Second encoder free handle \n");
     
    
    #endif
     
      pthread_join (pAppData->encILComp->inDataStrmThrdId, (void **) &ret_value);
    
      pthread_join(pAppData->encILComp->outDataStrmThrdId, (void **) &ret_value);
      
      pthread_join (pAppData->encILComp2->inDataStrmThrdId, (void **) &ret_value);
    
      pthread_join(pAppData->encILComp2->outDataStrmThrdId, (void **) &ret_value);
    
      fclose(pAppData->fIn);
      
      fclose(pAppData->fOut);
      
      fclose(pAppData->fIn2);
      
      fclose(pAppData->fOut2);
      
      IL_ClientDeInit (pAppData);
    
      printf ("IL Client deinitialized \n");
    
      printf (" example exit \n");
    
    EXIT:
      return (0);
    }
    

    6428.ilclient.h

    6278.ilclient_utils.c
    /*
     *  Copyright (c) 2010-2011, Texas Instruments Incorporated
     *
     *  Redistribution and use in source and binary forms, with or without
     *  modification, are permitted provided that the following conditions
     *  are met:
     *
     *  *  Redistributions of source code must retain the above copyright
     *     notice, this list of conditions and the following disclaimer.
     *
     *  *  Redistributions in binary form must reproduce the above copyright
     *     notice, this list of conditions and the following disclaimer in the
     *     documentation and/or other materials provided with the distribution.
     *
     *  *  Neither the name of Texas Instruments Incorporated nor the names of
     *     its contributors may be used to endorse or promote products derived
     *     from this software without specific prior written permission.
     *
     *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     *  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     *  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     *  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     *  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *  Contact information for paper mail:
     *  Texas Instruments
     *  Post Office Box 655303
     *  Dallas, Texas 75265
     *  Contact information:
     *  http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm?
     *  DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact
     *  ============================================================================
     *
     */
    
    #include <stdlib.h>
    #include <stdio.h>
    #include <pthread.h>
    #include <unistd.h>
    #include <xdc/std.h>
    #include <memory.h>
    #include <getopt.h>
    
    /*-------------------------program files -------------------------------------*/
    #include "ti/omx/interfaces/openMaxv11/OMX_Core.h"
    #include "ti/omx/interfaces/openMaxv11/OMX_Component.h"
    #include "OMX_TI_Common.h"
    #include "OMX_Video.h"
    #include "OMX_TI_Video.h"
    #include "ilclient.h"
    #include "ilclient_utils.h"
    #include <omx_venc.h>
    #include <omx_vfpc.h>
    #include <omx_vfdc.h>
    #include <omx_ctrl.h>
    #include <omx_vfcc.h>
    #include <OMX_TI_Index.h>
    /*---------------------- function prototypes ---------------------------------*/
    /* None */
    
    void usage (IL_ARGS *argsp)
    {
      printf
        ("encode_a8host_debug.xv5T \n"
         "-o | --output          output filename \n"
         "-i | --input           input filename \n"
         "-f | --framerate       encode frame rate \n"
         "-b | --bitrate         encode bit rate \n"
         "-w | --width           encode width \n"
         "-h | --height          encode height \n"
         "-c | --codec           h264, mpeg4, h263 \n"
       );                      
      printf(" example -    ./encode_a8host_debug.xv5T -o sample.h264 -i sample.yuv -f 60 -b 1000000 -w 1920 -h 1080 -c h264\n");
      
      exit (1);
    }
    
    /* ========================================================================== */
    /**
    * parse_args() : This function parses the input arguments provided to app.
    *
    * @param argc             : number of args 
    * @param argv             : args passed by app
    * @param argsp            : parsed data pointer
    *
    *  @return      
    *
    *
    */
    /* ========================================================================== */
    
    void parse_args (int argc, char *argv[], IL_ARGS *argsp)
    {
      const char shortOptions[] = "o:i:w:h:f:b:c:";
      const struct option longOptions[] =
      {
        {"output", required_argument, NULL, ArgID_OUTPUT_FILE},
        {"input", required_argument, NULL, ArgID_INPUT_FILE},
        {"width", required_argument, NULL, ArgID_WIDTH},
        {"height", required_argument, NULL, ArgID_HEIGHT},
        {"framerate", required_argument, NULL, ArgID_FRAMERATE},
        {"bitrate", required_argument, NULL, ArgID_BITRATE},
        {"codec", required_argument, NULL, ArgID_CODEC},
        {0, 0, 0, 0}
      };
    
      int index, outfile = 0, infile = 0, codec = 0, width = 0, height =0;
      int argID;
    
      for (;;)
      {
        argID = getopt_long (argc, argv, shortOptions, longOptions, &index);
    
        if (argID == -1)
        {
          break;
        }
    
        switch (argID)
        {
          case ArgID_OUTPUT_FILE:
          case 'o':
            strncpy (argsp->output_file, optarg, MAX_FILE_NAME_SIZE);
            outfile = 1;
            break;
          case 'i':
            strncpy (argsp->input_file, optarg, MAX_FILE_NAME_SIZE);
            infile = 1;
            break;
          case ArgID_FRAMERATE:
          case 'f':
            argsp->frame_rate = atoi (optarg);
            break;
          case ArgID_WIDTH:
          case 'w':
            argsp->width = atoi (optarg);
            width = 1;
            break;
          case ArgID_HEIGHT:
          case 'h':
            argsp->height = atoi (optarg);
            height = 1;
            break;
          case ArgID_BITRATE:
          case 'b':
            argsp->bit_rate = atoi (optarg);
            break;
          case ArgID_CODEC:
          case 'c':
            strncpy (argsp->codec, optarg, MAX_CODEC_NAME_SIZE);
            codec = 1;
            break;
          default:
            usage (argsp);
            exit (1);
        }
      }
    
      if (optind < argc)
      {
        usage (argsp);
        exit (EXIT_FAILURE);
      }
    
      if (argsp->bit_rate == 0 || !outfile || !infile || argsp->frame_rate == 0  || !width || !height || !codec)
      {
        usage (argsp);
        exit (1);
      }
    
      printf ("output file: %s\n", argsp->output_file);
      printf ("input file: %s\n", argsp->input_file);
      printf ("bit_rate: %d\n", argsp->bit_rate);
      printf ("frame_rate: %d\n", argsp->frame_rate);
      printf ("codec: %s\n", argsp->codec);
      printf ("width: %d\n", argsp->width);
      printf ("height: %d\n", argsp->height);
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientInit() : This function is to allocate and initialize the application
    *                   data structure. It is just to maintain application control.
    *
    * @param pAppData          : appliaction / client data Handle 
    * @param width             : stream width
    * @param height            : stream height
    * @param frameRate         : encode frame rate
    * @param bitrate           : encoder bit rate
    * @param numFrames         : encoded number of frames
    * @param displayId         : display instance id
    *
    *  @return      
    *
    *
    */
    /* ========================================================================== */
    
    void IL_ClientInit (IL_Client **pAppData, int width, int height, int frameRate,
                        int bitRate, char *codec)
    {
      int i;
      IL_Client *pAppDataPtr;
      IL_CLIENT_INPORT_PARAMS *inPortParamsPtr;
      IL_CLIENT_OUTPORT_PARAMS *outPortParamsPtr;
    
      /* Allocating data structure for IL client structure / buffer management */
    
      pAppDataPtr = (IL_Client *) malloc (sizeof (IL_Client));
      memset (pAppDataPtr, 0x0, sizeof (IL_Client));
    
      /* update the user provided parameters */
      pAppDataPtr->nFrameRate   = frameRate;
      pAppDataPtr->nBitRate     = bitRate;
      /* pAppDataPtr->nEncodedFrms = numFrames; */
      
      pAppDataPtr->nHeight      = height;
      pAppDataPtr->nWidth       =  width; 
    
      if (strcmp (codec, "h264") == 0)
      {
        pAppDataPtr->eCompressionFormat = OMX_VIDEO_CodingAVC;
      }
      else if (strcmp (codec, "mpeg4") == 0)
      {
        pAppDataPtr->eCompressionFormat = OMX_VIDEO_CodingMPEG4;
      }
      else if (strcmp (codec, "h263") == 0)
      {
        pAppDataPtr->eCompressionFormat = OMX_VIDEO_CodingH263;
      }
      
      /* alloacte data structure for each component used in this IL Client */
      pAppDataPtr->encILComp =
        (IL_CLIENT_COMP_PRIVATE *) malloc (sizeof (IL_CLIENT_COMP_PRIVATE));
      memset (pAppDataPtr->encILComp, 0x0, sizeof (IL_CLIENT_COMP_PRIVATE));
    
      /* these semaphores are used for tracking the callbacks received from
         component */
      pAppDataPtr->encILComp->eos = malloc (sizeof (semp_t));
      semp_init (pAppDataPtr->encILComp->eos, 0);
    
      pAppDataPtr->encILComp->done_sem = malloc (sizeof (semp_t));
      semp_init (pAppDataPtr->encILComp->done_sem, 0);
    
      pAppDataPtr->encILComp->port_sem = malloc (sizeof (semp_t));
      semp_init (pAppDataPtr->encILComp->port_sem, 0);
    
      pAppDataPtr->encILComp->numInport = 1;
      pAppDataPtr->encILComp->numOutport = 1;
      pAppDataPtr->encILComp->startOutportIndex = 1;
    
      pAppDataPtr->encILComp->inPortParams =
        malloc (sizeof (IL_CLIENT_INPORT_PARAMS) *
                pAppDataPtr->encILComp->numInport);
      memset (pAppDataPtr->encILComp->inPortParams, 0x0,
              sizeof (IL_CLIENT_INPORT_PARAMS));
    
      pAppDataPtr->encILComp->outPortParams =
        malloc (sizeof (IL_CLIENT_INPORT_PARAMS) *
                pAppDataPtr->encILComp->numOutport);
      memset (pAppDataPtr->encILComp->outPortParams, 0x0,
              sizeof (IL_CLIENT_OUTPORT_PARAMS));
    
      for (i = 0; i < pAppDataPtr->encILComp->numInport; i++)
      {
        inPortParamsPtr = pAppDataPtr->encILComp->inPortParams + i;
        inPortParamsPtr->nBufferCountActual = IL_CLIENT_ENC_INPUT_BUFFER_COUNT;
        /* input buffers size for yuv buffers, format is YUV420 hence 3/2 */
        inPortParamsPtr->nBufferSize =
          (pAppDataPtr->nHeight * pAppDataPtr->nWidth * 3) >> 1;
        /* this pipe is used for taking buffers from file read thread; in this
           example, file read is not used */
        pipe ((int *) inPortParamsPtr->ipBufPipe);
      }
      for (i = 0; i < pAppDataPtr->encILComp->numOutport; i++)
      {
        outPortParamsPtr = pAppDataPtr->encILComp->outPortParams + i;
        outPortParamsPtr->nBufferCountActual = IL_CLIENT_ENC_OUTPUT_BUFFER_COUNT;
        /* this size could be smaller than this value */
        outPortParamsPtr->nBufferSize =
          (pAppDataPtr->nHeight * pAppDataPtr->nWidth * 3) >> 1;
    
        /* This pipe is used if output is directed to file write thread, */
        pipe ((int *) outPortParamsPtr->opBufPipe);
      }
      /* each componet will have local pipe to take bufffers from other component
         or its own consumed buffer, so that it can be passed to other connected
         components */
      pipe ((int *) pAppDataPtr->encILComp->localPipe);
      
    #if 1
      /* alloacte data structure for each component used in this IL Client */
      pAppDataPtr->encILComp2 =
        (IL_CLIENT_COMP_PRIVATE *) malloc (sizeof (IL_CLIENT_COMP_PRIVATE));
      memset (pAppDataPtr->encILComp2, 0x0, sizeof (IL_CLIENT_COMP_PRIVATE));
    
      /* these semaphores are used for tracking the callbacks received from
         component */
      pAppDataPtr->encILComp2->eos = malloc (sizeof (semp_t));
      semp_init (pAppDataPtr->encILComp2->eos, 0);
    
      pAppDataPtr->encILComp2->done_sem = malloc (sizeof (semp_t));
      semp_init (pAppDataPtr->encILComp2->done_sem, 0);
    
      pAppDataPtr->encILComp2->port_sem = malloc (sizeof (semp_t));
      semp_init (pAppDataPtr->encILComp2->port_sem, 0);
    
      pAppDataPtr->encILComp2->numInport = 1;
      pAppDataPtr->encILComp2->numOutport = 1;
      pAppDataPtr->encILComp2->startOutportIndex = 1;
    
      pAppDataPtr->encILComp2->inPortParams =
      malloc (sizeof (IL_CLIENT_INPORT_PARAMS) *
                pAppDataPtr->encILComp2->numInport);
      memset (pAppDataPtr->encILComp2->inPortParams, 0x0,
              sizeof (IL_CLIENT_INPORT_PARAMS));
    
      pAppDataPtr->encILComp2->outPortParams =
        malloc (sizeof (IL_CLIENT_INPORT_PARAMS) *
                pAppDataPtr->encILComp2->numOutport);
      memset (pAppDataPtr->encILComp2->outPortParams, 0x0,
              sizeof (IL_CLIENT_OUTPORT_PARAMS));
    
      for (i = 0; i < pAppDataPtr->encILComp2->numInport; i++)
      {
        inPortParamsPtr = pAppDataPtr->encILComp2->inPortParams + i;
        inPortParamsPtr->nBufferCountActual = IL_CLIENT_ENC_INPUT_BUFFER_COUNT;
        /* input buffers size for yuv buffers, format is YUV420 hence 3/2 */
        inPortParamsPtr->nBufferSize =
          (pAppDataPtr->nHeight * pAppDataPtr->nWidth * 3) >> 1;
        /* this pipe is used for taking buffers from file read thread; in this
           example, file read is not used */
        pipe ((int *) inPortParamsPtr->ipBufPipe);
      }
      for (i = 0; i < pAppDataPtr->encILComp2->numOutport; i++)
      {
        outPortParamsPtr = pAppDataPtr->encILComp2->outPortParams + i;
        outPortParamsPtr->nBufferCountActual = IL_CLIENT_ENC_OUTPUT_BUFFER_COUNT;
        /* this size could be smaller than this value */
        outPortParamsPtr->nBufferSize =
          (pAppDataPtr->nHeight * pAppDataPtr->nWidth * 3) >> 1;
    
        /* This pipe is used if output is directed to file write thread, */
        pipe ((int *) outPortParamsPtr->opBufPipe);
      }
      /* each componet will have local pipe to take bufffers from other component
         or its own consumed buffer, so that it can be passed to other connected
         components */
      pipe ((int *) pAppDataPtr->encILComp2->localPipe);
    #endif  
    
      /* populate the pointer for allocated data structure */
      *pAppData = pAppDataPtr;
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientInit() : This function is to deinitialize the application
    *                   data structure.
    *
    * @param pAppData          : appliaction / client data Handle 
    *  @return      
    *
    *
    */
    /* ========================================================================== */
    
    void IL_ClientDeInit (IL_Client * pAppData)
    {
      int i;
      IL_CLIENT_INPORT_PARAMS *inPortParamsPtr;
      IL_CLIENT_OUTPORT_PARAMS *outPortParamsPtr;
    
    
      close ((int) pAppData->encILComp->localPipe);
    
      for (i = 0; i < pAppData->encILComp->numInport; i++)
      {
        inPortParamsPtr = pAppData->encILComp->inPortParams + i;
        /* This pipe is used if output is directed to file write thread, in this
           example, file read is not used */
        close ((int) inPortParamsPtr->ipBufPipe);
      }
      for (i = 0; i < pAppData->encILComp->numOutport; i++)
      {
        outPortParamsPtr = pAppData->encILComp->outPortParams + i;
        close ((int) outPortParamsPtr->opBufPipe);
      }
    
      free (pAppData->encILComp->inPortParams);
    
      free (pAppData->encILComp->outPortParams);
    
      /* these semaphores are used for tracking the callbacks received from
         component */
      semp_deinit (pAppData->encILComp->eos);
      free(pAppData->encILComp->eos);
    
      semp_deinit (pAppData->encILComp->done_sem);
      free(pAppData->encILComp->done_sem);
    
      semp_deinit (pAppData->encILComp->port_sem);
    
      free(pAppData->encILComp->port_sem);
    
      free (pAppData->encILComp);
      
    #if 1  
      close ((int) pAppData->encILComp2->localPipe);
    
      for (i = 0; i < pAppData->encILComp2->numInport; i++)
      {
        inPortParamsPtr = pAppData->encILComp2->inPortParams + i;
        /* This pipe is used if output is directed to file write thread, in this
           example, file read is not used */
        close ((int) inPortParamsPtr->ipBufPipe);
      }
      for (i = 0; i < pAppData->encILComp2->numOutport; i++)
      {
        outPortParamsPtr = pAppData->encILComp2->outPortParams + i;
        close ((int) outPortParamsPtr->opBufPipe);
      }
    
      free (pAppData->encILComp2->inPortParams);
    
      free (pAppData->encILComp2->outPortParams);
    
      /* these semaphores are used for tracking the callbacks received from
         component */
      semp_deinit (pAppData->encILComp2->eos);
      free(pAppData->encILComp2->eos);
    
      semp_deinit (pAppData->encILComp2->done_sem);
      free(pAppData->encILComp2->done_sem);
    
      semp_deinit (pAppData->encILComp2->port_sem);
    
      free(pAppData->encILComp2->port_sem);
    
      free (pAppData->encILComp2);
    #endif
      free (pAppData);
    
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientErrorToStr() : Function to map the OMX error enum to string
    *
    * @param error   : OMX Error type
    *
    *  @return      
    *  String conversion of the OMX_ERRORTYPE
    *
    */
    /* ========================================================================== */
    
    OMX_STRING IL_ClientErrorToStr (OMX_ERRORTYPE error)
    {
      OMX_STRING errorString;
    
      /* used for printing purpose */
      switch (error)
      {
        case OMX_ErrorNone:
          errorString = "OMX_ErrorNone";
          break;
        case OMX_ErrorInsufficientResources:
          errorString = "OMX_ErrorInsufficientResources";
          break;
        case OMX_ErrorUndefined:
          errorString = "OMX_ErrorUndefined";
          break;
        case OMX_ErrorInvalidComponentName:
          errorString = "OMX_ErrorInvalidComponentName";
          break;
        case OMX_ErrorComponentNotFound:
          errorString = "OMX_ErrorComponentNotFound";
          break;
        case OMX_ErrorInvalidComponent:
          errorString = "OMX_ErrorInvalidComponent";
          break;
        case OMX_ErrorBadParameter:
          errorString = "OMX_ErrorBadParameter";
          break;
        case OMX_ErrorNotImplemented:
          errorString = "OMX_ErrorNotImplemented";
          break;
        case OMX_ErrorUnderflow:
          errorString = "OMX_ErrorUnderflow";
          break;
        case OMX_ErrorOverflow:
          errorString = "OMX_ErrorOverflow";
          break;
        case OMX_ErrorHardware:
          errorString = "OMX_ErrorHardware";
          break;
        case OMX_ErrorInvalidState:
          errorString = "OMX_ErrorInvalidState";
          break;
        case OMX_ErrorStreamCorrupt:
          errorString = "OMX_ErrorStreamCorrupt";
          break;
        case OMX_ErrorPortsNotCompatible:
          errorString = "OMX_ErrorPortsNotCompatible";
          break;
        case OMX_ErrorResourcesLost:
          errorString = "OMX_ErrorResourcesLost";
          break;
        case OMX_ErrorNoMore:
          errorString = "OMX_ErrorNoMore";
          break;
        case OMX_ErrorVersionMismatch:
          errorString = "OMX_ErrorVersionMismatch";
          break;
        case OMX_ErrorNotReady:
          errorString = "OMX_ErrorNotReady";
          break;
        case OMX_ErrorTimeout:
          errorString = "OMX_ErrorTimeout";
          break;
        default:
          errorString = "<unknown>";
      }
    
      return errorString;
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientEncUseInitialOutputResources() :  This function gives initially all
    *                                         output buffers to a component.
    *                                         after consuming component would keep
    *                                         in local pipe for connect thread use. 
    *
    * @param pAppdata   : application data structure
    *
    *  @return      
    *  String conversion of the OMX_ERRORTYPE
    *
    */
    /* ========================================================================== */
    
    OMX_ERRORTYPE IL_ClientEncUseInitialOutputResources (IL_CLIENT_COMP_PRIVATE 
                                                           *thisComp)
    {
      OMX_ERRORTYPE err = OMX_ErrorNone;
      unsigned int i = 0;
    
      for (i = 0; i < thisComp->outPortParams->nBufferCountActual; i++)
      {
        /* Pass the output buffer to the component */
        err = OMX_FillThisBuffer (thisComp->handle,
                                  thisComp->outPortParams->pOutBuff[i]);
      }
    
      return err;
    }
    
    /* ========================================================================== */
    /**
    * IL_ClientDecUseInitialInputResources() : This function gives initially all
    *                                          input buffers to decoder component.
    *                                          after consuming decoder would keep
    *                                          in ipbufpipe for file read thread. 
    *
    * @param pAppdata   : application data structure
    *
    *  @return      
    *  String conversion of the OMX_ERRORTYPE
    *
    */
    /* ========================================================================== */
    
    OMX_ERRORTYPE IL_ClientEncUseInitialInputResources (IL_Client *pAppdata)
    {
    
      OMX_ERRORTYPE err = OMX_ErrorNone;
      unsigned int i = 0;
      int frameSize = 0;
      IL_CLIENT_COMP_PRIVATE *encILComp = NULL;
      encILComp = ((IL_Client *) pAppdata)->encILComp;
    
      /* Give input buffers to component which is limited by no of input buffers
         available. Rest of the data will be read on the callback from input data
         read thread */
      for (i = 0; i < encILComp->inPortParams->nBufferCountActual; i++)
      {
        frameSize = (pAppdata->nHeight * pAppdata->nWidth * 3) >> 1;
        /* Get the size of one frame at a time */
        frameSize = fread (encILComp->inPortParams->pInBuff[i]->pBuffer, 1, frameSize, pAppdata->fIn);
    
        /* Exit the loop if no data available */
        if (!frameSize)
        {
          break;
        }
    
        encILComp->inPortParams->pInBuff[i]->nFilledLen = frameSize;
        encILComp->inPortParams->pInBuff[i]->nOffset = 0;
        encILComp->inPortParams->pInBuff[i]->nAllocLen = frameSize;
        encILComp->inPortParams->pInBuff[i]->nInputPortIndex = 0;
    
        /* Pass the input buffer to the component */
        err = OMX_EmptyThisBuffer (encILComp->handle,
                                   encILComp->inPortParams->pInBuff[i]);
    
      }
      return err;
    }
    
    OMX_ERRORTYPE IL_ClientEncUseInitialInputResources2 (IL_Client *pAppdata)
    {
    
      OMX_ERRORTYPE err = OMX_ErrorNone;
      unsigned int i = 0;
      int frameSize = 0;
      IL_CLIENT_COMP_PRIVATE *encILComp = NULL;
      encILComp = ((IL_Client *) pAppdata)->encILComp2;
    
      /* Give input buffers to component which is limited by no of input buffers
         available. Rest of the data will be read on the callback from input data
         read thread */
      for (i = 0; i < encILComp->inPortParams->nBufferCountActual; i++)
      {
        frameSize = (pAppdata->nHeight * pAppdata->nWidth * 3) >> 1;
        /* Get the size of one frame at a time */
        frameSize = fread (encILComp->inPortParams->pInBuff[i]->pBuffer, 1, frameSize, pAppdata->fIn2);
    
        /* Exit the loop if no data available */
        if (!frameSize)
        {
          break;
        }
    
        encILComp->inPortParams->pInBuff[i]->nFilledLen = frameSize;
        encILComp->inPortParams->pInBuff[i]->nOffset = 0;
        encILComp->inPortParams->pInBuff[i]->nAllocLen = frameSize;
        encILComp->inPortParams->pInBuff[i]->nInputPortIndex = 0;
    
        /* Pass the input buffer to the component */
        err = OMX_EmptyThisBuffer (encILComp->handle,
                                   encILComp->inPortParams->pInBuff[i]);
    
      }
      return err;
    }
    
    
    /* ========================================================================== */
    /**
    * IL_ClientSetEncodeParams() : Function to fill the port definition 
    * structures and call the Set_Parameter function on to the Encode
    * Component
    *
    * @param pAppData   : Pointer to the application data
    *
    *  @return      
    *  OMX_ErrorNone = Successful 
    *
    *  Other_value = Failed (Error code is returned)
    *
    */
    /* ========================================================================== */
    
    OMX_ERRORTYPE IL_ClientSetEncodeParams (IL_Client *pAppData)
    {
      OMX_ERRORTYPE eError = OMX_ErrorUndefined;
      OMX_HANDLETYPE pHandle = NULL;
      OMX_VIDEO_PARAM_PROFILELEVELTYPE tProfileLevel;
      OMX_VIDEO_PARAM_ENCODER_PRESETTYPE tEncoderPreset;
      OMX_VIDEO_PARAM_BITRATETYPE tVidEncBitRate;
      //OMX_VIDEO_PARAM_PORTFORMATTYPE tVideoParams;
      OMX_PARAM_PORTDEFINITIONTYPE tPortDef;
      OMX_VIDEO_CONFIG_DYNAMICPARAMS tDynParams;
      OMX_VIDEO_PARAM_STATICPARAMS   tStaticParam;
      //OMX_VIDEO_PARAM_FRAMEDATACONTENTTYPE  tFrameType;
      
      pHandle = pAppData->pEncHandle;
    
      /* Number of frames to be encoded, not used by defaualt */
      pAppData->encILComp->numFrames = pAppData->nEncodedFrms;
    
    
      OMX_INIT_PARAM (&tPortDef);
      /* Get the Number of Ports */
    
      tPortDef.nPortIndex = OMX_VIDENC_INPUT_PORT;
      eError = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef);
      /* set the actual number of buffers required */
      tPortDef.nBufferCountActual = IL_CLIENT_ENC_INPUT_BUFFER_COUNT;
      /* set the video format settings */
      tPortDef.format.video.nFrameWidth = pAppData->nWidth;
      tPortDef.format.video.nStride = pAppData->nWidth;
      tPortDef.format.video.nFrameHeight = pAppData->nHeight;
      tPortDef.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
      /* settings for OMX_IndexParamVideoPortFormat */
      tPortDef.nBufferSize = (pAppData->nWidth * pAppData->nHeight * 3) >> 1;
      eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef);
      if (eError != OMX_ErrorNone)
      {
        ERROR ("failed to set Encode OMX_IndexParamPortDefinition for input \n");
      }
    
      OMX_INIT_PARAM (&tPortDef);
    
      tPortDef.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      eError = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef);
      /* settings for OMX_IndexParamPortDefinition */
      /* set the actual number of buffers required */
      tPortDef.nBufferCountActual = IL_CLIENT_ENC_OUTPUT_BUFFER_COUNT;
      tPortDef.format.video.nFrameWidth = pAppData->nWidth;
      tPortDef.format.video.nFrameHeight = pAppData->nHeight;
      tPortDef.format.video.eCompressionFormat = pAppData->eCompressionFormat;
      tPortDef.format.video.xFramerate = (pAppData->nFrameRate << 16);
      tPortDef.format.video.nBitrate = pAppData->nBitRate;
      /* settings for OMX_IndexParamVideoPortFormat */
    
      eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef);
      if (eError != OMX_ErrorNone)
      {
        ERROR ("failed to set Encode OMX_IndexParamPortDefinition for output \n");
      }
    
      /* For changing bit rate following index can be used */
      OMX_INIT_PARAM (&tVidEncBitRate);
    
      tVidEncBitRate.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      eError = OMX_GetParameter (pHandle, OMX_IndexParamVideoBitrate,
                                 &tVidEncBitRate);
    
      tVidEncBitRate.eControlRate = OMX_Video_ControlRateVariable;
      tVidEncBitRate.nTargetBitrate = pAppData->nBitRate;
      eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoBitrate,
                                 &tVidEncBitRate);
    
      if (eError != OMX_ErrorNone)
      {
        ERROR ("failed to set Encode bitrate \n");
      }
      /* Set the profile and level for H264 */
      OMX_INIT_PARAM (&tProfileLevel);
      tProfileLevel.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
    
      eError = OMX_GetParameter (pHandle, OMX_IndexParamVideoProfileLevelCurrent,
                                 &tProfileLevel);
    
      /* set as profile / level */
      if(pAppData->eCompressionFormat == OMX_VIDEO_CodingAVC) { 
      tProfileLevel.eProfile = OMX_VIDEO_AVCProfileHigh;
      tProfileLevel.eLevel = OMX_VIDEO_AVCLevel42;
      }
      else if (pAppData->eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
      tProfileLevel.eProfile = OMX_VIDEO_MPEG4ProfileSimple;
      tProfileLevel.eLevel = OMX_VIDEO_MPEG4Level5;
       }
      else if (pAppData->eCompressionFormat == OMX_VIDEO_CodingH263) {
      tProfileLevel.eProfile = OMX_VIDEO_H263ProfileBaseline;
      tProfileLevel.eLevel = OMX_VIDEO_H263Level40;
       }
      
    
      eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoProfileLevelCurrent,
                                 &tProfileLevel);
      if (eError != OMX_ErrorNone)
        ERROR ("failed to set encoder pfofile \n");
      /* before creating use set_parameters, for run-time change use set_config
         all codec supported parameters can be set using this index       */
      
      /* example for h264 parameters settings */
         
      if(pAppData->eCompressionFormat == OMX_VIDEO_CodingAVC) {   
      
      /* Encoder Preset settings */
      OMX_INIT_PARAM (&tEncoderPreset);
      tEncoderPreset.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      eError = OMX_GetParameter (pHandle, OMX_TI_IndexParamVideoEncoderPreset,
                                 &tEncoderPreset);
    
    #if ENABLE_GDR 							 
      tEncoderPreset.eEncodingModePreset = OMX_Video_Enc_User_Defined;    
    #else
      tEncoderPreset.eEncodingModePreset = OMX_Video_Enc_Default;  
    #endif
    
      tEncoderPreset.eRateControlPreset = OMX_Video_RC_None;
      eError = OMX_SetParameter (pHandle, OMX_TI_IndexParamVideoEncoderPreset,
                                 &tEncoderPreset);
      if (eError != OMX_ErrorNone)
      {
        ERROR ("failed to Encoder Preset \n");
      }
      
      OMX_INIT_PARAM (&tDynParams);
    
      tDynParams.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      
      eError = OMX_GetParameter (pHandle, OMX_TI_IndexParamVideoDynamicParams,
                                 &tDynParams);
      
      /* setting I frame interval */
      tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.targetFrameRate = pAppData->nFrameRate * 1000;
      tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.targetBitRate = pAppData->nBitRate;
      
    #if ENABLE_GDR  
      /*Parameter setting for GDR*/
      tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;  
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraCodingPreset = IH264_INTRACODING_USERDEFINED;
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_GDR;
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraRefreshRate = 4;
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.gdrOverlapRowsBtwFrames = 0;
      /* updating rows to be intra refresh */
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraRefreshRateGDRDynamic = 4;
      /* updating overlap rows */
      tDynParams.videoDynamicParams.h264EncDynamicParams.gdrOverlapRowsBtwFramesDynamic = 0;
    #else
      tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_DEFAULT;  
      tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.HRDBufferSize = pAppData->nBitRate * 2;
    #endif
      
      tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.intraFrameInterval = 90;      
                             
      eError = OMX_SetParameter (pHandle, OMX_TI_IndexParamVideoDynamicParams,
                                 &tDynParams);
    
      OMX_INIT_PARAM (&tStaticParam);
    
      tStaticParam.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      
      eError = OMX_GetParameter (pHandle, OMX_TI_IndexParamVideoStaticParams,
                                 &tStaticParam);
      
    #if ENABLE_GDR    
      /*Parameter setting for GDR*/
      tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.encodingPreset = XDM_USER_DEFINED;    
      tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.intraCodingPreset = IH264_INTRACODING_USERDEFINED;
      tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_GDR;
      tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.intraRefreshRate = 4;
      tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.gdrOverlapRowsBtwFrames = 0;
    #else 
      tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.HRDBufferSize = pAppData->nBitRate * 2;
      tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.encodingPreset = XDM_DEFAULT;
    #endif /* ENABLE_GDR */ 
      
      tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.rateControlPreset = IVIDEO_LOW_DELAY;
                              
      eError = OMX_SetParameter (pHandle, OMX_TI_IndexParamVideoStaticParams,
                                 &tStaticParam);
      }
      if((pAppData->eCompressionFormat == OMX_VIDEO_CodingMPEG4) || 
         (pAppData->eCompressionFormat == OMX_VIDEO_CodingH263))
      {
        OMX_INIT_PARAM(&tStaticParam);
        tStaticParam.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
    
        eError =
            OMX_GetParameter(pHandle, OMX_TI_IndexParamVideoStaticParams,
                             &tStaticParam);
        if (eError != OMX_ErrorNone)
        {
          ERROR ("failed to Encoder OMX_GetParameter StaticParams \n");
        }
    
        tStaticParam.videoStaticParams.mpeg4EncStaticParams.videnc2Params.encodingPreset
                                                         = XDM_USER_DEFINED;
        tStaticParam.videoStaticParams.mpeg4EncStaticParams.vopTimeIncrementResolution
                                                         = pAppData->nFrameRate;
    
        eError =
            OMX_SetParameter(pHandle, OMX_TI_IndexParamVideoStaticParams,
                             &tStaticParam);
        if (eError != OMX_ErrorNone)
        {
          ERROR ("failed to Encoder OMX_SetParameter StaticParams \n");
        }
      }
    
      return eError;
    }
    
    OMX_ERRORTYPE IL_ClientSetEncodeParams2 (IL_Client *pAppData)
    {
      OMX_ERRORTYPE eError = OMX_ErrorUndefined;
      OMX_HANDLETYPE pHandle = NULL;
      OMX_VIDEO_PARAM_PROFILELEVELTYPE tProfileLevel;
      OMX_VIDEO_PARAM_ENCODER_PRESETTYPE tEncoderPreset;
      OMX_VIDEO_PARAM_BITRATETYPE tVidEncBitRate;
      //OMX_VIDEO_PARAM_PORTFORMATTYPE tVideoParams;
      OMX_PARAM_PORTDEFINITIONTYPE tPortDef;
      OMX_VIDEO_CONFIG_DYNAMICPARAMS tDynParams;
      OMX_VIDEO_PARAM_STATICPARAMS   tStaticParam;
      //OMX_VIDEO_PARAM_FRAMEDATACONTENTTYPE  tFrameType;
      
      pHandle = pAppData->pEncHandle2;
      
      /* Number of frames to be encoded, not used by defaualt */
      pAppData->encILComp2->numFrames = pAppData->nEncodedFrms;
      
      OMX_INIT_PARAM (&tPortDef);
      /* Get the Number of Ports */
    
      tPortDef.nPortIndex = OMX_VIDENC_INPUT_PORT;
      eError = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef);
      /* set the actual number of buffers required */
      tPortDef.nBufferCountActual = IL_CLIENT_ENC_INPUT_BUFFER_COUNT;
      /* set the video format settings */
      tPortDef.format.video.nFrameWidth = pAppData->nWidth;
      tPortDef.format.video.nStride = pAppData->nWidth;
      tPortDef.format.video.nFrameHeight = pAppData->nHeight;
      tPortDef.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
      /* settings for OMX_IndexParamVideoPortFormat */
      tPortDef.nBufferSize = (pAppData->nWidth * pAppData->nHeight * 3) >> 1;
      eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef);
      if (eError != OMX_ErrorNone)
      {
        ERROR ("failed to set Encode OMX_IndexParamPortDefinition for input \n");
      }
    
      OMX_INIT_PARAM (&tPortDef);
    
      tPortDef.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      eError = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef);
      /* settings for OMX_IndexParamPortDefinition */
      /* set the actual number of buffers required */
      tPortDef.nBufferCountActual = IL_CLIENT_ENC_OUTPUT_BUFFER_COUNT;
      tPortDef.format.video.nFrameWidth = pAppData->nWidth;
      tPortDef.format.video.nFrameHeight = pAppData->nHeight;
      tPortDef.format.video.eCompressionFormat = pAppData->eCompressionFormat;
      tPortDef.format.video.xFramerate = (pAppData->nFrameRate << 16);
      tPortDef.format.video.nBitrate = pAppData->nBitRate;
      /* settings for OMX_IndexParamVideoPortFormat */
    
      eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef);
      if (eError != OMX_ErrorNone)
      {
        ERROR ("failed to set Encode OMX_IndexParamPortDefinition for output \n");
      }
    
      /* For changing bit rate following index can be used */
      OMX_INIT_PARAM (&tVidEncBitRate);
    
      tVidEncBitRate.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      eError = OMX_GetParameter (pHandle, OMX_IndexParamVideoBitrate,
                                 &tVidEncBitRate);
    
      tVidEncBitRate.eControlRate = OMX_Video_ControlRateVariable;
      tVidEncBitRate.nTargetBitrate = pAppData->nBitRate;
      eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoBitrate,
                                 &tVidEncBitRate);
    
      if (eError != OMX_ErrorNone)
      {
        ERROR ("failed to set Encode bitrate \n");
      }
      /* Set the profile and level for H264 */
      OMX_INIT_PARAM (&tProfileLevel);
      tProfileLevel.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
    
      eError = OMX_GetParameter (pHandle, OMX_IndexParamVideoProfileLevelCurrent,
                                 &tProfileLevel);
    
      /* set as profile / level */
      if(pAppData->eCompressionFormat == OMX_VIDEO_CodingAVC) { 
      tProfileLevel.eProfile = OMX_VIDEO_AVCProfileHigh;
      tProfileLevel.eLevel = OMX_VIDEO_AVCLevel42;
      }
      else if (pAppData->eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
      tProfileLevel.eProfile = OMX_VIDEO_MPEG4ProfileSimple;
      tProfileLevel.eLevel = OMX_VIDEO_MPEG4Level5;
       }
      else if (pAppData->eCompressionFormat == OMX_VIDEO_CodingH263) {
      tProfileLevel.eProfile = OMX_VIDEO_H263ProfileBaseline;
      tProfileLevel.eLevel = OMX_VIDEO_H263Level40;
       }
      
    
      eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoProfileLevelCurrent,
                                 &tProfileLevel);
      if (eError != OMX_ErrorNone)
        ERROR ("failed to set encoder pfofile \n");
      /* before creating use set_parameters, for run-time change use set_config
         all codec supported parameters can be set using this index       */
      
      /* example for h264 parameters settings */
         
      if(pAppData->eCompressionFormat == OMX_VIDEO_CodingAVC) {   
      
      /* Encoder Preset settings */
      OMX_INIT_PARAM (&tEncoderPreset);
      tEncoderPreset.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      eError = OMX_GetParameter (pHandle, OMX_TI_IndexParamVideoEncoderPreset,
                                 &tEncoderPreset);
    
    #if ENABLE_GDR 							 
      tEncoderPreset.eEncodingModePreset = OMX_Video_Enc_User_Defined;    
    #else
      tEncoderPreset.eEncodingModePreset = OMX_Video_Enc_Default;  
    #endif
    
      tEncoderPreset.eRateControlPreset = OMX_Video_RC_None;
      eError = OMX_SetParameter (pHandle, OMX_TI_IndexParamVideoEncoderPreset,
                                 &tEncoderPreset);
      if (eError != OMX_ErrorNone)
      {
        ERROR ("failed to Encoder Preset \n");
      }
      
      OMX_INIT_PARAM (&tDynParams);
    
      tDynParams.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      
      eError = OMX_GetParameter (pHandle, OMX_TI_IndexParamVideoDynamicParams,
                                 &tDynParams);
      
      /* setting I frame interval */
      tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.targetFrameRate = pAppData->nFrameRate * 1000;
      tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.targetBitRate = pAppData->nBitRate;
      
    #if ENABLE_GDR  
      /*Parameter setting for GDR*/
      tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED;  
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraCodingPreset = IH264_INTRACODING_USERDEFINED;
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_GDR;
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.intraRefreshRate = 4;
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraCodingParams.gdrOverlapRowsBtwFrames = 0;
      /* updating rows to be intra refresh */
      tDynParams.videoDynamicParams.h264EncDynamicParams.intraRefreshRateGDRDynamic = 4;
      /* updating overlap rows */
      tDynParams.videoDynamicParams.h264EncDynamicParams.gdrOverlapRowsBtwFramesDynamic = 0;
    #else
      tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_DEFAULT;  
      tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.HRDBufferSize = pAppData->nBitRate * 2;
    #endif
      
      tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.intraFrameInterval = 90;      
                             
      eError = OMX_SetParameter (pHandle, OMX_TI_IndexParamVideoDynamicParams,
                                 &tDynParams);
    
      OMX_INIT_PARAM (&tStaticParam);
    
      tStaticParam.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
      
      eError = OMX_GetParameter (pHandle, OMX_TI_IndexParamVideoStaticParams,
                                 &tStaticParam);
      
    #if ENABLE_GDR    
      /*Parameter setting for GDR*/
      tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.encodingPreset = XDM_USER_DEFINED;    
      tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.intraCodingPreset = IH264_INTRACODING_USERDEFINED;
      tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_GDR;
      tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.intraRefreshRate = 4;
      tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.gdrOverlapRowsBtwFrames = 0;
    #else 
      tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.HRDBufferSize = pAppData->nBitRate * 2;
      tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.encodingPreset = XDM_DEFAULT;
    #endif /* ENABLE_GDR */ 
      
      tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.rateControlPreset = IVIDEO_LOW_DELAY;
                              
      eError = OMX_SetParameter (pHandle, OMX_TI_IndexParamVideoStaticParams,
                                 &tStaticParam);
      }
      if((pAppData->eCompressionFormat == OMX_VIDEO_CodingMPEG4) || 
         (pAppData->eCompressionFormat == OMX_VIDEO_CodingH263))
      {
        OMX_INIT_PARAM(&tStaticParam);
        tStaticParam.nPortIndex = OMX_VIDENC_OUTPUT_PORT;
    
        eError =
            OMX_GetParameter(pHandle, OMX_TI_IndexParamVideoStaticParams,
                             &tStaticParam);
        if (eError != OMX_ErrorNone)
        {
          ERROR ("failed to Encoder OMX_GetParameter StaticParams \n");
        }
    
        tStaticParam.videoStaticParams.mpeg4EncStaticParams.videnc2Params.encodingPreset
                                                         = XDM_USER_DEFINED;
        tStaticParam.videoStaticParams.mpeg4EncStaticParams.vopTimeIncrementResolution
                                                         = pAppData->nFrameRate;
    
        eError =
            OMX_SetParameter(pHandle, OMX_TI_IndexParamVideoStaticParams,
                             &tStaticParam);
        if (eError != OMX_ErrorNone)
        {
          ERROR ("failed to Encoder OMX_SetParameter StaticParams \n");
        }
      }
    
      return eError;
    }
    
    /* Nothing beyond this point */
    
    

  • Hi Ramprasad/Prakash,

    In your above code if you change the semp_post(encILComp->eos);  in IL_ClientInputBitStreamReadTask2() to semp_post(encILComp2->eos); and similarly in  IL_ClientOutputBitStreamWriteTask2() to semp_post(encILComp2->eos); you should be able to get proper EOS for the second file aswel.

    Thanks,

    --Prabhakar Lad

  • HI Prabhakar, Ramprasad

    the Example code you provided does it work on EZSDK or it requires DVRSDK to work ? Can you please clarify?

    thanks

    Prakash

  • Hello,

    Prakash Harapanahalli said:
    the Example code you provided does it work on EZSDK or it requires DVRSDK to work ?

    EZSDK

    Best Regards,

    Margarita