omx_parser3gp_component.c

Go to the documentation of this file.
00001 
00031 #include <omxcore.h>
00032 #include <omx_base_video_port.h>
00033 #include <omx_base_audio_port.h>  
00034 #include <omx_base_clock_port.h>
00035 #include <omx_parser3gp_component.h>
00036 
00037 #define MAX_COMPONENT_PARSER_3GP 1
00038 
00040 static OMX_U32 noParser3gpInstance=0;
00041 #define DEFAULT_FILENAME_LENGTH 256
00042 #define VIDEO_PORT_INDEX 0
00043 #define AUDIO_PORT_INDEX 1
00044 #define CLOCK_PORT_INDEX 2
00045 #define VIDEO_STREAM 0
00046 #define AUDIO_STREAM 1
00047 
00048 static OMX_BOOL FirstTimeStampFlag[2];  // flags for the start time stamp for audio and video
00049 
00052 OMX_ERRORTYPE omx_parser3gp_component_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,OMX_STRING cComponentName) {
00053  
00054   OMX_ERRORTYPE err = OMX_ErrorNone;
00055   omx_base_video_PortType *pPortV;
00056   omx_base_audio_PortType *pPortA;  
00057   omx_parser3gp_component_PrivateType* omx_parser3gp_component_Private;
00058   DEBUG(DEB_LEV_FUNCTION_NAME,"In %s \n",__func__);
00059 
00060   if (!openmaxStandComp->pComponentPrivate) {
00061     openmaxStandComp->pComponentPrivate = calloc(1, sizeof(omx_parser3gp_component_PrivateType));
00062     if(openmaxStandComp->pComponentPrivate == NULL) {
00063       return OMX_ErrorInsufficientResources;
00064     }
00065   }
00066 
00067   /*Assign size of the derived port class,so that proper memory for port class can be allocated*/
00068   omx_parser3gp_component_Private = openmaxStandComp->pComponentPrivate;
00069   omx_parser3gp_component_Private->ports = NULL;
00070 
00071   err = omx_base_source_Constructor(openmaxStandComp, cComponentName);
00072 
00073   omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainVideo].nStartPortNumber = 0;
00074   omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts = 1;
00075 
00076   omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainAudio].nStartPortNumber = 1;
00077   omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts = 1;
00078 
00079   omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainOther].nStartPortNumber = 2;
00080   omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts = 1;
00081 
00083   if ((omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts  +
00084        omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
00085        omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts ) && !omx_parser3gp_component_Private->ports) {
00086        omx_parser3gp_component_Private->ports = calloc((omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts  +
00087                                                         omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
00088                                                         omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts ), sizeof(omx_base_PortType *));
00089     if (!omx_parser3gp_component_Private->ports) {
00090       return OMX_ErrorInsufficientResources;
00091     }
00092     /* allocate video port*/
00093    omx_parser3gp_component_Private->ports[VIDEO_PORT_INDEX] = calloc(1, sizeof(omx_base_video_PortType)); 
00094    if (!omx_parser3gp_component_Private->ports[VIDEO_PORT_INDEX]) 
00095        return OMX_ErrorInsufficientResources;
00096    /* allocate audio port*/
00097    omx_parser3gp_component_Private->ports[AUDIO_PORT_INDEX] = calloc(1, sizeof(omx_base_audio_PortType)); 
00098    if (!omx_parser3gp_component_Private->ports[AUDIO_PORT_INDEX]) 
00099        return OMX_ErrorInsufficientResources;
00100    /* allocate clock port*/
00101    omx_parser3gp_component_Private->ports[CLOCK_PORT_INDEX] = calloc(1, sizeof(omx_base_clock_PortType));
00102    if (!omx_parser3gp_component_Private->ports[CLOCK_PORT_INDEX]) 
00103      return OMX_ErrorInsufficientResources;
00104        
00105   }
00106 
00107   base_video_port_Constructor(openmaxStandComp, &omx_parser3gp_component_Private->ports[VIDEO_PORT_INDEX], VIDEO_PORT_INDEX, OMX_FALSE);
00108   base_audio_port_Constructor(openmaxStandComp, &omx_parser3gp_component_Private->ports[AUDIO_PORT_INDEX], AUDIO_PORT_INDEX, OMX_FALSE); 
00109   base_clock_port_Constructor(openmaxStandComp, &omx_parser3gp_component_Private->ports[CLOCK_PORT_INDEX], CLOCK_PORT_INDEX, OMX_TRUE); 
00110 
00111   pPortV = (omx_base_video_PortType *) omx_parser3gp_component_Private->ports[VIDEO_PORT_INDEX];
00112   pPortA = (omx_base_audio_PortType *) omx_parser3gp_component_Private->ports[AUDIO_PORT_INDEX]; 
00113 
00114   /*Input pPort buffer size is equal to the size of the output buffer of the previous component*/
00115   pPortV->sPortParam.nBufferSize = DEFAULT_OUT_BUFFER_SIZE;
00116   pPortA->sPortParam.nBufferSize = DEFAULT_IN_BUFFER_SIZE;
00117 
00118   omx_parser3gp_component_Private->BufferMgmtCallback = omx_parser3gp_component_BufferMgmtCallback;
00119   omx_parser3gp_component_Private->BufferMgmtFunction = omx_base_source_twoport_BufferMgmtFunction; 
00120 
00121   setHeader(&omx_parser3gp_component_Private->sTimeStamp, sizeof(OMX_TIME_CONFIG_TIMESTAMPTYPE));
00122   omx_parser3gp_component_Private->sTimeStamp.nPortIndex=0;
00123   omx_parser3gp_component_Private->sTimeStamp.nTimestamp=0x0;
00124 
00125   omx_parser3gp_component_Private->destructor = omx_parser3gp_component_Destructor;
00126   omx_parser3gp_component_Private->messageHandler = omx_parser3gp_component_MessageHandler;
00127 
00128   noParser3gpInstance++;
00129   if(noParser3gpInstance > MAX_COMPONENT_PARSER_3GP) {
00130     return OMX_ErrorInsufficientResources;
00131   }
00132 
00133   openmaxStandComp->SetParameter  = omx_parser3gp_component_SetParameter;
00134   openmaxStandComp->GetParameter  = omx_parser3gp_component_GetParameter;
00135   openmaxStandComp->SetConfig     = omx_parser3gp_component_SetConfig;
00136   openmaxStandComp->GetConfig     = omx_parser3gp_component_GetConfig;
00137   openmaxStandComp->GetExtensionIndex = omx_parser3gp_component_GetExtensionIndex;
00138 
00139   /* Write in the default paramenters */
00140 
00141   omx_parser3gp_component_Private->pTmpOutputBuffer = (OMX_BUFFERHEADERTYPE*) malloc(sizeof(OMX_BUFFERHEADERTYPE));
00142   omx_parser3gp_component_Private->pTmpOutputBuffer->pBuffer = (OMX_U8*) malloc(DEFAULT_OUT_BUFFER_SIZE);
00143   memset(omx_parser3gp_component_Private->pTmpOutputBuffer->pBuffer, 0, DEFAULT_OUT_BUFFER_SIZE);
00144   omx_parser3gp_component_Private->pTmpOutputBuffer->nFilledLen=0;
00145   omx_parser3gp_component_Private->pTmpOutputBuffer->nAllocLen=DEFAULT_OUT_BUFFER_SIZE;
00146   omx_parser3gp_component_Private->pTmpOutputBuffer->nOffset=0;
00147  
00148   omx_parser3gp_component_Private->avformatReady = OMX_FALSE;
00149   if(!omx_parser3gp_component_Private->avformatSyncSem) {
00150     omx_parser3gp_component_Private->avformatSyncSem = calloc(1,sizeof(tsem_t));
00151     if(omx_parser3gp_component_Private->avformatSyncSem == NULL) return OMX_ErrorInsufficientResources;
00152     tsem_init(omx_parser3gp_component_Private->avformatSyncSem, 0);
00153   }
00154   omx_parser3gp_component_Private->sInputFileName = (char *)malloc(DEFAULT_FILENAME_LENGTH);
00155   memset(omx_parser3gp_component_Private->sInputFileName,0,DEFAULT_FILENAME_LENGTH);
00156   /*Default Coding type*/
00157   omx_parser3gp_component_Private->video_coding_type = OMX_VIDEO_CodingAVC;
00158   omx_parser3gp_component_Private->audio_coding_type = OMX_AUDIO_CodingMP3; 
00159   av_register_all();  /* without this file opening gives an error */
00160 
00161   return err;
00162 }
00163 
00164 /* The Destructor */
00165 OMX_ERRORTYPE omx_parser3gp_component_Destructor(OMX_COMPONENTTYPE *openmaxStandComp) {
00166   omx_parser3gp_component_PrivateType* omx_parser3gp_component_Private = openmaxStandComp->pComponentPrivate;
00167   OMX_U32 i;
00168 
00169   if(omx_parser3gp_component_Private->avformatSyncSem) {
00170     tsem_deinit(omx_parser3gp_component_Private->avformatSyncSem);
00171     free(omx_parser3gp_component_Private->avformatSyncSem);
00172     omx_parser3gp_component_Private->avformatSyncSem=NULL;
00173   }
00174 
00175   if(omx_parser3gp_component_Private->sInputFileName) {
00176     free(omx_parser3gp_component_Private->sInputFileName);
00177   }
00178 
00179   if(omx_parser3gp_component_Private->pTmpOutputBuffer) {
00180     free(omx_parser3gp_component_Private->pTmpOutputBuffer);
00181   }
00182   
00183   /* frees port/s */
00184   if (omx_parser3gp_component_Private->ports) {
00185     for (i=0; i < (omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts  +
00186                    omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
00187                    omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts ); i++) {
00188       if(omx_parser3gp_component_Private->ports[i])
00189         omx_parser3gp_component_Private->ports[i]->PortDestructor(omx_parser3gp_component_Private->ports[i]);
00190     }
00191     free(omx_parser3gp_component_Private->ports);
00192     omx_parser3gp_component_Private->ports=NULL;
00193   }
00194   
00195   noParser3gpInstance--;
00196   DEBUG(DEB_LEV_FUNCTION_NAME,"In %s \n",__func__);
00197   return omx_base_source_Destructor(openmaxStandComp);
00198 }
00199 
00202 OMX_ERRORTYPE omx_parser3gp_component_Init(OMX_COMPONENTTYPE *openmaxStandComp) {
00203 
00204   omx_parser3gp_component_PrivateType* omx_parser3gp_component_Private = openmaxStandComp->pComponentPrivate;
00205   omx_base_video_PortType *pPortV;
00206   omx_base_audio_PortType *pPortA;
00207   int error;
00208   
00209   DEBUG(DEB_LEV_FUNCTION_NAME,"In %s \n",__func__);
00210 
00211   /* set the first time stamp flags to false */
00212   FirstTimeStampFlag[0] = OMX_FALSE;
00213   FirstTimeStampFlag[1] = OMX_FALSE;
00214 
00217   error = av_open_input_file(&omx_parser3gp_component_Private->avformatcontext, 
00218                             (char*)omx_parser3gp_component_Private->sInputFileName,
00219                             omx_parser3gp_component_Private->avinputformat,
00220                             0,
00221                             omx_parser3gp_component_Private->avformatparameters);
00222 
00223   if(error != 0) {
00224     DEBUG(DEB_LEV_ERR,"Couldn't Open Input Stream error=%d File Name=%s\n",
00225       error,(char*)omx_parser3gp_component_Private->sInputFileName);
00226   
00227     return OMX_ErrorBadParameter;
00228   }
00229 
00230   av_find_stream_info(omx_parser3gp_component_Private->avformatcontext);
00231 
00232  /* Setting the audio and video coding types of the audio and video ports based on the information obtained from the stream */
00233  /* for the video port */
00234   pPortV = (omx_base_video_PortType *) omx_parser3gp_component_Private->ports[VIDEO_PORT_INDEX];
00235   switch(omx_parser3gp_component_Private->avformatcontext->streams[VIDEO_PORT_INDEX]->codec->codec_id){
00236     case  CODEC_ID_H264:
00237         pPortV->sPortParam.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; 
00238         pPortV->sPortParam.format.video.nFrameWidth =omx_parser3gp_component_Private->avformatcontext->streams[VIDEO_STREAM]->codec->width;   
00239         pPortV->sPortParam.format.video.nFrameHeight =omx_parser3gp_component_Private->avformatcontext->streams[VIDEO_STREAM]->codec->height;   
00240         omx_parser3gp_component_Private->video_coding_type = OMX_VIDEO_CodingAVC;
00241         DEBUG(DEB_LEV_SIMPLE_SEQ,"In %s Video Coding Type h.264\n",__func__);
00242         break;
00243     case CODEC_ID_MPEG4:
00244         pPortV->sPortParam.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; 
00245         pPortV->sPortParam.format.video.nFrameWidth =omx_parser3gp_component_Private->avformatcontext->streams[VIDEO_STREAM]->codec->width;   
00246         pPortV->sPortParam.format.video.nFrameHeight =omx_parser3gp_component_Private->avformatcontext->streams[VIDEO_STREAM]->codec->height;   
00247         omx_parser3gp_component_Private->video_coding_type = OMX_VIDEO_CodingMPEG4;
00248         DEBUG(DEB_LEV_SIMPLE_SEQ,"In %s Video Coding Type Mpeg4\n",__func__);
00249         break;
00250     default :
00251     (*(omx_parser3gp_component_Private->callbacks->EventHandler))
00252       (openmaxStandComp,
00253       omx_parser3gp_component_Private->callbackData,
00254       OMX_EventError, /* The command was completed */
00255       OMX_ErrorFormatNotDetected, /* Format Not Detected */ 
00256       VIDEO_PORT_INDEX, /* This is the output port index*/ 
00257       NULL);  
00258     DEBUG(DEB_LEV_ERR,"Trouble in %s No Video Coding Type Selected (only H264 and MPEG4 codecs supported)\n",__func__);
00259     return OMX_ErrorBadParameter;
00260   }
00261 
00262   /* for the audio port*/
00263   pPortA = (omx_base_audio_PortType *) omx_parser3gp_component_Private->ports[AUDIO_PORT_INDEX];
00264   switch(omx_parser3gp_component_Private->avformatcontext->streams[AUDIO_STREAM]->codec->codec_id){
00265     case CODEC_ID_MP3:
00266         pPortA->sPortParam.format.audio.eEncoding = OMX_AUDIO_CodingMP3;
00267         pPortA->sAudioParam.eEncoding = OMX_AUDIO_CodingMP3;
00268         omx_parser3gp_component_Private->audio_coding_type = OMX_AUDIO_CodingMP3;
00269         break;
00270     case CODEC_ID_AAC:
00271         pPortA->sPortParam.format.audio.eEncoding = OMX_AUDIO_CodingAAC;
00272         pPortA->sAudioParam.eEncoding = OMX_AUDIO_CodingAAC;
00273         omx_parser3gp_component_Private->audio_coding_type = OMX_AUDIO_CodingAAC;
00274         break;
00275     default:
00276     (*(omx_parser3gp_component_Private->callbacks->EventHandler))
00277       (openmaxStandComp,
00278       omx_parser3gp_component_Private->callbackData,
00279       OMX_EventError, /* The command was completed */
00280       OMX_ErrorFormatNotDetected, /* Format Not Detected */ 
00281       AUDIO_PORT_INDEX, /* This is the output port index */
00282       NULL);  
00283     DEBUG(DEB_LEV_ERR,"Trouble in %s No Audio Coding Type Selected (only MP3 and AAC codecs supported)\n",__func__);
00284     return OMX_ErrorBadParameter;
00285 
00286   }
00287 
00288   DEBUG(DEB_LEV_SIMPLE_SEQ,"In %s Video Extra data size=%d\n",__func__,omx_parser3gp_component_Private->avformatcontext->streams[VIDEO_STREAM]->codec->extradata_size);
00289   DEBUG(DEB_LEV_SIMPLE_SEQ,"In %s Audio Extra data size=%d\n",__func__,omx_parser3gp_component_Private->avformatcontext->streams[AUDIO_STREAM]->codec->extradata_size); 
00295   (*(omx_parser3gp_component_Private->callbacks->EventHandler))
00296     (openmaxStandComp,
00297     omx_parser3gp_component_Private->callbackData,
00298     OMX_EventPortFormatDetected, /* The command was completed */
00299     OMX_IndexParamVideoPortFormat, /* port Format Detected */ 
00300     VIDEO_PORT_INDEX, /* This is the output port index */
00301     NULL);  
00302 
00303   (*(omx_parser3gp_component_Private->callbacks->EventHandler))
00304     (openmaxStandComp,
00305     omx_parser3gp_component_Private->callbackData,
00306     OMX_EventPortSettingsChanged, /* The command was completed */
00307     OMX_IndexParamCommonExtraQuantData, /* port settings changed */ 
00308     VIDEO_PORT_INDEX, /* This is the output port index */  
00309     NULL);  
00310 
00311   (*(omx_parser3gp_component_Private->callbacks->EventHandler))
00312     (openmaxStandComp,
00313     omx_parser3gp_component_Private->callbackData,
00314     OMX_EventPortFormatDetected, /* The command was completed */
00315     OMX_IndexParamVideoPortFormat, /* port Format Detected */ 
00316     AUDIO_PORT_INDEX, /* This is the output port index */
00317     NULL);
00318 
00319   (*(omx_parser3gp_component_Private->callbacks->EventHandler))
00320     (openmaxStandComp,
00321     omx_parser3gp_component_Private->callbackData,
00322     OMX_EventPortSettingsChanged, /* The command was completed */
00323     OMX_IndexParamCommonExtraQuantData, /* port settings changed */ 
00324     AUDIO_PORT_INDEX, /* This is the output port index */
00325     NULL);  
00326 
00327   omx_parser3gp_component_Private->avformatReady = OMX_TRUE;
00328 /*Indicate that avformat is ready*/
00329   tsem_up(omx_parser3gp_component_Private->avformatSyncSem);
00330 
00331   return OMX_ErrorNone;
00332 }
00333 
00336 OMX_ERRORTYPE omx_parser3gp_component_Deinit(OMX_COMPONENTTYPE *openmaxStandComp) {
00337 
00338   omx_parser3gp_component_PrivateType* omx_parser3gp_component_Private = openmaxStandComp->pComponentPrivate;
00339 
00340   DEBUG(DEB_LEV_FUNCTION_NAME, "In %s \n",__func__);
00342   av_close_input_file(omx_parser3gp_component_Private->avformatcontext);
00343   
00344   omx_parser3gp_component_Private->avformatReady = OMX_FALSE;
00345   tsem_reset(omx_parser3gp_component_Private->avformatSyncSem);
00346 
00347   return OMX_ErrorNone;
00348 }
00349 
00354 void omx_parser3gp_component_BufferMgmtCallback(OMX_COMPONENTTYPE *openmaxStandComp, OMX_BUFFERHEADERTYPE* pOutputBuffer) {
00355   omx_parser3gp_component_PrivateType* omx_parser3gp_component_Private = openmaxStandComp->pComponentPrivate;
00356   OMX_BUFFERHEADERTYPE*                temp_buffer;
00357   int                                  error;
00358   int                                  stream_index;
00359   AVRational                           bq = { 1, 1000000 };
00360   omx_base_clock_PortType              *pClockPort;
00361   OMX_TIME_MEDIATIMETYPE*              pMediaTime;
00362   OMX_BUFFERHEADERTYPE*                clockBuffer;
00363   OMX_S32                              Scale;
00364 
00365   temp_buffer = omx_parser3gp_component_Private->pTmpOutputBuffer;
00366   DEBUG(DEB_LEV_FUNCTION_NAME,"In %s \n",__func__);
00367 
00368   if (omx_parser3gp_component_Private->avformatReady == OMX_FALSE) {
00369     if(omx_parser3gp_component_Private->state == OMX_StateExecuting) {
00370       /*wait for avformat to be ready*/
00371       tsem_down(omx_parser3gp_component_Private->avformatSyncSem);
00372     } else {
00373       return;
00374     }
00375   }
00376 
00377   pOutputBuffer->nFilledLen = 0;
00378   pOutputBuffer->nOffset = 0;
00379 
00380   /* check for any information from the clock component */
00381   pClockPort = (omx_base_clock_PortType*)omx_parser3gp_component_Private->ports[CLOCK_PORT_INDEX];
00382   if(pClockPort->pBufferSem->semval>0){
00383    tsem_down(pClockPort->pBufferSem);
00384    clockBuffer = dequeue(pClockPort->pBufferQueue);
00385    pMediaTime  = (OMX_TIME_MEDIATIMETYPE*)clockBuffer->pBuffer;
00386    omx_parser3gp_component_Private->xScale = pMediaTime->xScale;
00387    pClockPort->ReturnBufferFunction((omx_base_PortType*)pClockPort,clockBuffer);
00388   }
00389 
00390   /* read the stream */
00391   if(temp_buffer->nFilledLen==0) {  /* no data available in temporary buffer*/
00392      error = av_read_frame(omx_parser3gp_component_Private->avformatcontext, &omx_parser3gp_component_Private->pkt);
00393      if(error < 0) {
00394        DEBUG(DEB_LEV_ERR,"In %s EOS - no more packet,state=%x\n",__func__, omx_parser3gp_component_Private->state);
00395        pOutputBuffer->nFlags = OMX_BUFFERFLAG_EOS;
00396      } else {
00397        stream_index = omx_parser3gp_component_Private->pkt.stream_index; 
00398        Scale = omx_parser3gp_component_Private->xScale >> 16;
00399        if(Scale!=1  && Scale!=0 && stream_index==VIDEO_STREAM){  /* TODO - change to a switch statement to handle all cases */
00400          /* fast forward the stream if Scale>1 */
00401         if(Scale>1){
00402            error = av_seek_frame(omx_parser3gp_component_Private->avformatcontext, stream_index, omx_parser3gp_component_Private->pkt.pts+Scale ,0); 
00403            if(error < 0) {
00404               DEBUG(DEB_LEV_ERR,"Error in seeking stream=%d\n",stream_index);
00405            }else DEBUG(DEB_LEV_SIMPLE_SEQ,"Success in seeking stream=%d\n",stream_index);
00406         }
00407         if(Scale<0){
00408           error = av_seek_frame(omx_parser3gp_component_Private->avformatcontext, stream_index, omx_parser3gp_component_Private->pkt.pts+Scale ,AVSEEK_FLAG_BACKWARD);
00409          if(error < 0) {
00410             DEBUG(DEB_LEV_ERR,"Error in seeking stream=%d\n",stream_index);
00411          }else DEBUG(DEB_LEV_SIMPLE_SEQ,"Success in seeking stream=%d\n",stream_index);
00412         }
00413        }
00414        if((stream_index==VIDEO_STREAM && pOutputBuffer->nOutputPortIndex==VIDEO_PORT_INDEX) || 
00415           (stream_index==AUDIO_STREAM && pOutputBuffer->nOutputPortIndex==AUDIO_PORT_INDEX)){  
00417          if(pOutputBuffer->nAllocLen >= omx_parser3gp_component_Private->pkt.size) {
00418            memcpy(pOutputBuffer->pBuffer, omx_parser3gp_component_Private->pkt.data, omx_parser3gp_component_Private->pkt.size);
00419            pOutputBuffer->nFilledLen = omx_parser3gp_component_Private->pkt.size;
00420            pOutputBuffer->nTimeStamp = av_rescale_q(omx_parser3gp_component_Private->pkt.pts, 
00421                                                     omx_parser3gp_component_Private->avformatcontext->streams[stream_index]->time_base, bq);
00422            if(FirstTimeStampFlag[stream_index]==OMX_FALSE){
00423               pOutputBuffer->nFlags = OMX_BUFFERFLAG_STARTTIME;
00424               FirstTimeStampFlag[stream_index] = OMX_TRUE;
00425            } 
00426          } else {
00427            DEBUG(DEB_LEV_ERR,"In %s Buffer Size=%d less than Pkt size=%d buffer=%x port_index=%d \n",__func__,
00428                               (int)pOutputBuffer->nAllocLen,(int)omx_parser3gp_component_Private->pkt.size,
00429                               (unsigned int)pOutputBuffer,(int)pOutputBuffer->nOutputPortIndex);
00430          }
00431        }else { /* the port type and the stream data do not match so keep the data in temporary buffer*/
00432          if(temp_buffer->nAllocLen >= omx_parser3gp_component_Private->pkt.size) {
00433            memcpy(temp_buffer->pBuffer, omx_parser3gp_component_Private->pkt.data, omx_parser3gp_component_Private->pkt.size);
00434            temp_buffer->nFilledLen = omx_parser3gp_component_Private->pkt.size;
00435            temp_buffer->nTimeStamp = av_rescale_q (omx_parser3gp_component_Private->pkt.pts, 
00436                                                    omx_parser3gp_component_Private->avformatcontext->streams[stream_index]->time_base, bq);
00437            temp_buffer->nOutputPortIndex = omx_parser3gp_component_Private->pkt.stream_index; /* keep the stream_index in OutputPortIndex for identification */
00438            if(FirstTimeStampFlag[temp_buffer->nOutputPortIndex]==OMX_FALSE){
00439              temp_buffer->nFlags = OMX_BUFFERFLAG_STARTTIME;
00440              FirstTimeStampFlag[temp_buffer->nOutputPortIndex] = OMX_TRUE;
00441            } 
00442          } else {
00443            DEBUG(DEB_LEV_ERR,"In %s Buffer Size=%d less than Pkt size=%d\n",__func__,
00444              (int)temp_buffer->nAllocLen,(int)omx_parser3gp_component_Private->pkt.size);
00445          }
00446        }
00447      }
00448    } else {  /* data available in temporary buffer */
00449      DEBUG(DEB_LEV_SIMPLE_SEQ,"\n data size in temp buffer : %d \n",(int)temp_buffer->nFilledLen);
00450      if(( temp_buffer->nOutputPortIndex==VIDEO_STREAM && pOutputBuffer->nOutputPortIndex==VIDEO_PORT_INDEX) ||
00451         ( temp_buffer->nOutputPortIndex==AUDIO_STREAM && pOutputBuffer->nOutputPortIndex==AUDIO_PORT_INDEX)){
00453        if(pOutputBuffer->nAllocLen >= temp_buffer->nFilledLen) {
00454          memcpy(pOutputBuffer->pBuffer, temp_buffer->pBuffer, temp_buffer->nFilledLen);
00455          pOutputBuffer->nFilledLen = temp_buffer->nFilledLen;
00456          pOutputBuffer->nTimeStamp = temp_buffer->nTimeStamp;
00457          pOutputBuffer->nFlags     = temp_buffer->nFlags;
00458          temp_buffer->nFlags       = 0; /* clear the Flags of the temp_buffer */
00459          temp_buffer->nFilledLen   = 0;
00460          DEBUG(DEB_LEV_SIMPLE_SEQ," time stamp=%llx index=%d\n",pOutputBuffer->nTimeStamp,(int)temp_buffer->nOutputPortIndex);
00461         } else {
00462           DEBUG(DEB_LEV_ERR,"In %s Buffer Size=%d less than Pkt size=%d\n",__func__,
00463            (int)pOutputBuffer->nAllocLen,(int)omx_parser3gp_component_Private->pkt.size);
00464        }
00465      }
00466    }
00467 
00468   av_free_packet(&omx_parser3gp_component_Private->pkt);
00469   
00471   DEBUG(DEB_LEV_FULL_SEQ, "One output buffer %x len=%d is full returning\n", (int)pOutputBuffer->pBuffer, (int)pOutputBuffer->nFilledLen);
00472 }
00473 
00474 OMX_ERRORTYPE omx_parser3gp_component_SetParameter(
00475   OMX_IN  OMX_HANDLETYPE hComponent,
00476   OMX_IN  OMX_INDEXTYPE nParamIndex,
00477   OMX_IN  OMX_PTR ComponentParameterStructure) {
00478 
00479   OMX_ERRORTYPE err = OMX_ErrorNone;
00480   OMX_VIDEO_PARAM_PORTFORMATTYPE *pVideoPortFormat;
00481   OMX_VIDEO_PARAM_AVCTYPE * pVideoAvc;
00482   OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;
00483   OMX_AUDIO_PARAM_MP3TYPE * pAudioMp3;
00484   OMX_U32 portIndex;
00485   OMX_U32 nFileNameLength;
00486 
00487   /* Check which structure we are being fed and make control its header */
00488   OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE*)hComponent;
00489   omx_parser3gp_component_PrivateType* omx_parser3gp_component_Private = openmaxStandComp->pComponentPrivate;
00490   omx_base_video_PortType* pVideoPort = (omx_base_video_PortType *) omx_parser3gp_component_Private->ports[OMX_BASE_SOURCE_OUTPUTPORT_INDEX];
00491   omx_base_audio_PortType* pAudioPort = (omx_base_audio_PortType *) omx_parser3gp_component_Private->ports[OMX_BASE_SOURCE_OUTPUTPORT_INDEX_1];
00492 
00493   if(ComponentParameterStructure == NULL) {
00494     return OMX_ErrorBadParameter;
00495   }
00496 
00497   DEBUG(DEB_LEV_SIMPLE_SEQ, "   Setting parameter %i\n", nParamIndex);
00498 
00499   switch(nParamIndex) {
00500   case OMX_IndexParamVideoPortFormat:
00501     pVideoPortFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
00502     portIndex = pVideoPortFormat->nPortIndex;
00503     /*Check Structure Header and verify component state*/
00504     err = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pVideoPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
00505     if(err!=OMX_ErrorNone) { 
00506       DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err); 
00507       break;
00508     }
00509     if (portIndex < 1) {
00510       memcpy(&pVideoPort->sVideoParam,pVideoPortFormat,sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
00511     } else {
00512       return OMX_ErrorBadPortIndex;
00513     }
00514     break;
00515   case OMX_IndexParamVideoAvc: 
00516     pVideoAvc = (OMX_VIDEO_PARAM_AVCTYPE*)ComponentParameterStructure;
00517     /*Check Structure Header and verify component state*/
00518     err = omx_base_component_ParameterSanityCheck(hComponent, pVideoAvc->nPortIndex, pVideoAvc, sizeof(OMX_VIDEO_PARAM_AVCTYPE));
00519     if(err!=OMX_ErrorNone) { 
00520       DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err); 
00521       break;
00522     }
00523     break;
00524   case OMX_IndexParamAudioPortFormat:
00525     pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
00526     portIndex = pAudioPortFormat->nPortIndex;
00527     /*Check Structure Header and verify component state*/
00528     err = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pAudioPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00529     if(err!=OMX_ErrorNone) {
00530       DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err);
00531       break;
00532     }
00533     if (portIndex == 1) {
00534       memcpy(&pAudioPort->sAudioParam,pAudioPortFormat,sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00535     } else {
00536       return OMX_ErrorBadPortIndex;
00537     }
00538     break;
00539   case OMX_IndexParamAudioMp3:
00540     pAudioMp3 = (OMX_AUDIO_PARAM_MP3TYPE*)ComponentParameterStructure;
00541     /*Check Structure Header and verify component state*/
00542     err = omx_base_component_ParameterSanityCheck(hComponent, pAudioMp3->nPortIndex, pAudioMp3, sizeof(OMX_AUDIO_PARAM_MP3TYPE));
00543     if(err!=OMX_ErrorNone) {
00544       DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err);
00545       break;
00546     }
00547     break;
00548   case OMX_IndexVendorParser3gpInputFilename : 
00549     nFileNameLength = strlen((char *)ComponentParameterStructure) * sizeof(char) + 1;
00550     if(nFileNameLength > DEFAULT_FILENAME_LENGTH) {
00551       free(omx_parser3gp_component_Private->sInputFileName);
00552       omx_parser3gp_component_Private->sInputFileName = (char *)malloc(nFileNameLength);
00553     }
00554     strcpy(omx_parser3gp_component_Private->sInputFileName, (char *)ComponentParameterStructure);
00555     break;
00556   default: /*Call the base component function*/
00557     return omx_base_component_SetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00558   }
00559   return err;
00560 }
00561 
00562 OMX_ERRORTYPE omx_parser3gp_component_GetParameter(
00563   OMX_IN  OMX_HANDLETYPE hComponent,
00564   OMX_IN  OMX_INDEXTYPE nParamIndex,
00565   OMX_INOUT OMX_PTR ComponentParameterStructure) {
00566 
00567   OMX_ERRORTYPE err = OMX_ErrorNone;
00568   OMX_PORT_PARAM_TYPE *pVideoPortParam, *pAudioPortParam;
00569   OMX_VIDEO_PARAM_PORTFORMATTYPE *pVideoPortFormat;
00570   OMX_VENDOR_EXTRADATATYPE sExtraData;
00571   OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;
00572 
00573   OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE*)hComponent;
00574   omx_parser3gp_component_PrivateType* omx_parser3gp_component_Private = openmaxStandComp->pComponentPrivate;
00575   omx_base_video_PortType *pVideoPort = (omx_base_video_PortType *) omx_parser3gp_component_Private->ports[OMX_BASE_SOURCE_OUTPUTPORT_INDEX];
00576   omx_base_audio_PortType* pAudioPort = (omx_base_audio_PortType *) omx_parser3gp_component_Private->ports[OMX_BASE_SOURCE_OUTPUTPORT_INDEX_1];
00577 
00578 
00579   if (ComponentParameterStructure == NULL) {
00580     return OMX_ErrorBadParameter;
00581   }
00582 
00583   DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Getting parameter %08x\n",__func__, nParamIndex);
00584 
00585   /* Check which structure we are being fed and fill its header */
00586   switch(nParamIndex) {
00587   case OMX_IndexParamVideoInit:
00588     pVideoPortParam = (OMX_PORT_PARAM_TYPE*)  ComponentParameterStructure;
00589     if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) { 
00590       break;
00591     }
00592     pVideoPortParam->nStartPortNumber = 0;
00593     pVideoPortParam->nPorts = 1;
00594     break;
00595   case OMX_IndexParamVideoPortFormat:
00596     pVideoPortFormat = (OMX_VIDEO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
00597     if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) { 
00598       break;
00599     }
00600     if (pVideoPortFormat->nPortIndex < 1) {
00601       memcpy(pVideoPortFormat, &pVideoPort->sVideoParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
00602     } else {
00603       return OMX_ErrorBadPortIndex;
00604     }
00605     break;
00606   case OMX_IndexParamAudioInit:
00607     pAudioPortParam = (OMX_PORT_PARAM_TYPE *) ComponentParameterStructure;
00608     if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) {
00609       break;
00610     }
00611     pAudioPortParam->nStartPortNumber = 1;
00612     pAudioPortParam->nPorts = 1;
00613     break;
00614   case OMX_IndexParamAudioPortFormat:
00615     pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
00616     if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) {
00617       break;
00618     }
00619     if (pAudioPortFormat->nPortIndex <= 1) {
00620       memcpy(pAudioPortFormat, &pAudioPort->sAudioParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00621     } else {
00622       return OMX_ErrorBadPortIndex;
00623     }
00624     break;
00625   case  OMX_IndexVendorParser3gpInputFilename:
00626     strcpy((char *)ComponentParameterStructure, "still no filename");
00627     break;
00628   case OMX_IndexVendorVideoExtraData:
00629     sExtraData.nPortIndex = VIDEO_PORT_INDEX;
00630     sExtraData.nDataSize  = omx_parser3gp_component_Private->avformatcontext->streams[VIDEO_STREAM]->codec->extradata_size;  
00631     sExtraData.pData      = omx_parser3gp_component_Private->avformatcontext->streams[VIDEO_STREAM]->codec->extradata;
00632     memcpy(ComponentParameterStructure, &sExtraData, sizeof(OMX_VENDOR_EXTRADATATYPE));
00633     break;
00634   case OMX_IndexVendorAudioExtraData:
00635     sExtraData.nPortIndex = AUDIO_PORT_INDEX;
00636     sExtraData.nDataSize  = omx_parser3gp_component_Private->avformatcontext->streams[AUDIO_STREAM]->codec->extradata_size;  
00637     sExtraData.pData      = omx_parser3gp_component_Private->avformatcontext->streams[AUDIO_STREAM]->codec->extradata;
00638     memcpy(ComponentParameterStructure, &sExtraData, sizeof(OMX_VENDOR_EXTRADATATYPE));
00639     break;
00640   default: /*Call the base component function*/
00641     return omx_base_component_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00642   }
00643   return err;
00644 }
00645 
00649 OMX_ERRORTYPE omx_parser3gp_component_MessageHandler(OMX_COMPONENTTYPE* openmaxStandComp,internalRequestMessageType *message) {
00650   omx_parser3gp_component_PrivateType* omx_parser3gp_component_Private = (omx_parser3gp_component_PrivateType*)openmaxStandComp->pComponentPrivate;
00651   OMX_ERRORTYPE err = OMX_ErrorNone;
00652   OMX_STATETYPE oldState = omx_parser3gp_component_Private->state;
00653 
00654   DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s\n", __func__);
00655 
00656   /* Execute the base message handling */
00657   err = omx_base_component_MessageHandler(openmaxStandComp,message);
00658 
00659   if (message->messageType == OMX_CommandStateSet){ 
00660     if ((message->messageParam == OMX_StateExecuting) && (oldState == OMX_StateIdle)) {
00661       err = omx_parser3gp_component_Init(openmaxStandComp);
00662       if(err!=OMX_ErrorNone) { 
00663         DEBUG(DEB_LEV_ERR, "In %s  parser3gp Init Failed Error=%x\n",__func__,err); 
00664         return err;
00665       }
00666     } else if ((message->messageParam == OMX_StateIdle) && (oldState == OMX_StateExecuting)) {
00667       err = omx_parser3gp_component_Deinit(openmaxStandComp);
00668       if(err!=OMX_ErrorNone) { 
00669         DEBUG(DEB_LEV_ERR, "In %s parser3gp Deinit Failed Error=%x\n",__func__,err); 
00670         return err;
00671       }
00672     }
00673   }
00674 
00675   return err;
00676 }
00677 
00679 OMX_ERRORTYPE omx_parser3gp_component_SetConfig(
00680   OMX_IN  OMX_HANDLETYPE hComponent,
00681   OMX_IN  OMX_INDEXTYPE nIndex,
00682   OMX_IN  OMX_PTR pComponentConfigStructure) {
00683 
00684   OMX_TIME_CONFIG_TIMESTAMPTYPE* sTimeStamp;
00685   OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
00686   omx_parser3gp_component_PrivateType* omx_parser3gp_component_Private = openmaxStandComp->pComponentPrivate;
00687   OMX_ERRORTYPE err = OMX_ErrorNone;
00688   omx_base_video_PortType *pPort;
00689 
00690   switch (nIndex) {
00691     case OMX_IndexConfigTimePosition :
00692       sTimeStamp = (OMX_TIME_CONFIG_TIMESTAMPTYPE*)pComponentConfigStructure;
00693       /*Check Structure Header and verify component state*/
00694       if (sTimeStamp->nPortIndex >= (omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts  +
00695                                      omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
00696                                      omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts )) {
00697         DEBUG(DEB_LEV_ERR, "Bad Port index %i when the component has %i ports\n", (int)sTimeStamp->nPortIndex, (int)(omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts  +
00698                                                                                                                      omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainVideo].nPorts +
00699                                                                                                                      omx_parser3gp_component_Private->sPortTypesParam[OMX_PortDomainOther].nPorts ));
00700         return OMX_ErrorBadPortIndex;
00701       }
00702 
00703       err= checkHeader(sTimeStamp , sizeof(OMX_TIME_CONFIG_TIMESTAMPTYPE));
00704       if(err != OMX_ErrorNone) {
00705         return err;
00706       }
00707 
00708       if (sTimeStamp->nPortIndex < 1) {
00709         pPort= (omx_base_video_PortType *)omx_parser3gp_component_Private->ports[sTimeStamp->nPortIndex];
00710         memcpy(&omx_parser3gp_component_Private->sTimeStamp,sTimeStamp,sizeof(OMX_TIME_CONFIG_TIMESTAMPTYPE));
00711       } else {
00712         return OMX_ErrorBadPortIndex;
00713       }
00714       break;
00715     default: // delegate to superclass
00716       return omx_base_component_SetConfig(hComponent, nIndex, pComponentConfigStructure);
00717   }
00718   return OMX_ErrorNone;
00719 }
00720 
00722 OMX_ERRORTYPE omx_parser3gp_component_GetConfig(
00723   OMX_IN  OMX_HANDLETYPE hComponent,
00724   OMX_IN  OMX_INDEXTYPE nIndex,
00725   OMX_IN  OMX_PTR pComponentConfigStructure) {
00726 
00727   OMX_VENDOR_EXTRADATATYPE sExtraData;
00728   OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
00729   omx_parser3gp_component_PrivateType* omx_parser3gp_component_Private = openmaxStandComp->pComponentPrivate;
00730 
00731   switch (nIndex) {
00732     case OMX_IndexVendorVideoExtraData:
00733       sExtraData.nPortIndex = VIDEO_PORT_INDEX;
00734       sExtraData.nDataSize  = omx_parser3gp_component_Private->avformatcontext->streams[VIDEO_STREAM]->codec->extradata_size;
00735       sExtraData.pData      = omx_parser3gp_component_Private->avformatcontext->streams[VIDEO_STREAM]->codec->extradata;
00736       memcpy(pComponentConfigStructure, &sExtraData, sizeof(OMX_VENDOR_EXTRADATATYPE));
00737       break;
00738     case OMX_IndexVendorAudioExtraData:
00739       sExtraData.nPortIndex = AUDIO_PORT_INDEX;
00740       sExtraData.nDataSize  = omx_parser3gp_component_Private->avformatcontext->streams[AUDIO_STREAM]->codec->extradata_size;
00741       sExtraData.pData      = omx_parser3gp_component_Private->avformatcontext->streams[AUDIO_STREAM]->codec->extradata;
00742       memcpy(pComponentConfigStructure, &sExtraData, sizeof(OMX_VENDOR_EXTRADATATYPE));
00743       break;
00744     default: // delegate to superclass
00745       return omx_base_component_GetConfig(hComponent, nIndex, pComponentConfigStructure);
00746   }
00747   return OMX_ErrorNone;
00748 }
00749 
00750 OMX_ERRORTYPE omx_parser3gp_component_GetExtensionIndex(
00751   OMX_IN  OMX_HANDLETYPE hComponent,
00752   OMX_IN  OMX_STRING cParameterName,
00753   OMX_OUT OMX_INDEXTYPE* pIndexType) {
00754 
00755   DEBUG(DEB_LEV_FUNCTION_NAME,"In  %s \n",__func__);
00756 
00757   if(strcmp(cParameterName,"OMX.ST.index.param.parser3gp.inputfilename") == 0) {
00758     *pIndexType = OMX_IndexVendorParser3gpInputFilename;
00759   } else if(strcmp(cParameterName,"OMX.ST.index.config.videoextradata") == 0) {
00760     *pIndexType = OMX_IndexVendorVideoExtraData;
00761   } else if(strcmp(cParameterName,"OMX.ST.index.config.audioextradata") == 0) {
00762     *pIndexType = OMX_IndexVendorAudioExtraData;
00763   } else {
00764     return OMX_ErrorBadParameter;
00765   }
00766   return OMX_ErrorNone;
00767 }
00768 
00769 

Generated for OpenMAX Bellagio rel. 0.9.0 by  doxygen 1.5.1
SourceForge.net Logo