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

Generated for OpenMAX Bellagio rel. 0.3.5-svn by  doxygen 1.5.1
SourceForge.net Logo