omx_symbianoutputstreamsink_component.c

Go to the documentation of this file.
00001 
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 #include <string.h>
00029 #include <assert.h>
00030 
00031 #include "omxcore.h"
00032 #include "omx_symbianoutputstreamsink_component.h"
00033 #include "omx_symbian_output_stream_wrapper.h"
00034 
00035 OMX_ERRORTYPE 
00036 omx_symbianoutputstreamsink_component_Constructor(OMX_COMPONENTTYPE *openmaxStandComp, OMX_STRING cComponentName) 
00037 {
00038     OMX_ERRORTYPE err = OMX_ErrorNone;  
00039     OMX_S32 i;
00040     omx_symbianoutputstreamsink_component_PortType *pPort;
00041     omx_symbianoutputstreamsink_component_PrivateType* omx_symbianoutputstreamsink_component_Private;
00042 
00043     if (!openmaxStandComp->pComponentPrivate) 
00044     {
00045         openmaxStandComp->pComponentPrivate = calloc(1, sizeof(omx_symbianoutputstreamsink_component_PrivateType));
00046         if(openmaxStandComp->pComponentPrivate==NULL)
00047         {
00048             return OMX_ErrorInsufficientResources;
00049         }
00050     }
00051 
00052     err = omx_base_sink_Constructor(openmaxStandComp,cComponentName);
00053 
00054     omx_symbianoutputstreamsink_component_Private = openmaxStandComp->pComponentPrivate;
00055 
00056     if (omx_symbianoutputstreamsink_component_Private->sPortTypesParam.nPorts && !omx_symbianoutputstreamsink_component_Private->ports) 
00057     {
00058         omx_symbianoutputstreamsink_component_Private->ports = calloc(omx_symbianoutputstreamsink_component_Private->sPortTypesParam.nPorts,sizeof (omx_base_PortType *));
00059 
00060         if (!omx_symbianoutputstreamsink_component_Private->ports) 
00061         {
00062             return OMX_ErrorInsufficientResources;
00063         }
00064         
00065         for (i=0; i < omx_symbianoutputstreamsink_component_Private->sPortTypesParam.nPorts; i++) 
00066         {
00067             omx_symbianoutputstreamsink_component_Private->ports[i] = calloc(1, sizeof(omx_symbianoutputstreamsink_component_PortType));
00068             if (!omx_symbianoutputstreamsink_component_Private->ports[i]) 
00069             {
00070                 return OMX_ErrorInsufficientResources;
00071             }
00072         }
00073     }
00074     else 
00075     {
00076         DEBUG(DEB_LEV_ERR, "In %s Not allocated ports\n", __func__);
00077     }
00078      
00079     base_port_Constructor(openmaxStandComp,&omx_symbianoutputstreamsink_component_Private->ports[0],0, OMX_TRUE);
00080 
00081     pPort = (omx_symbianoutputstreamsink_component_PortType *) omx_symbianoutputstreamsink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];
00082 
00083     // set the pPort params, now that the ports exist   
00085     pPort->sPortParam.eDir = OMX_DirInput;
00086     pPort->sPortParam.nBufferCountActual = 2;
00087     pPort->sPortParam.nBufferCountMin = 2;
00088     pPort->sPortParam.bEnabled = OMX_TRUE;
00089     pPort->sPortParam.bPopulated = OMX_FALSE;
00090     pPort->sPortParam.eDomain = OMX_PortDomainAudio;
00091     pPort->sPortParam.format.audio.pNativeRender = 0;
00092     pPort->sPortParam.format.audio.cMIMEType = "raw";
00093     pPort->sPortParam.format.audio.bFlagErrorConcealment = OMX_FALSE;
00094     /*Input pPort buffer size is equal to the size of the output buffer of the previous component*/
00095     pPort->sPortParam.nBufferSize = DEFAULT_OUT_BUFFER_SIZE;
00096 
00097     omx_symbianoutputstreamsink_component_Private->BufferMgmtCallback = omx_symbianoutputstreamsink_component_BufferMgmtCallback;
00098     
00099     setHeader(&pPort->sAudioParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00100     pPort->sAudioParam.nPortIndex = 0;
00101     pPort->sAudioParam.nIndex = 0;
00102     pPort->sAudioParam.eEncoding = OMX_AUDIO_CodingPCM;
00103 
00104     /* OMX_AUDIO_PARAM_PCMMODETYPE */
00105     pPort->omxAudioParamPcmMode.nPortIndex = 0;
00106     pPort->omxAudioParamPcmMode.nChannels = 2;
00107     pPort->omxAudioParamPcmMode.eNumData = OMX_NumericalDataSigned;
00108     pPort->omxAudioParamPcmMode.eEndian = OMX_EndianLittle;
00109     pPort->omxAudioParamPcmMode.bInterleaved = OMX_TRUE;
00110     pPort->omxAudioParamPcmMode.nBitPerSample = 16;
00111     pPort->omxAudioParamPcmMode.nSamplingRate = 44100;
00112     pPort->omxAudioParamPcmMode.ePCMMode = OMX_AUDIO_PCMModeLinear;
00113     pPort->omxAudioParamPcmMode.eChannelMapping[0] = OMX_AUDIO_ChannelNone;
00114 
00115     omx_symbianoutputstreamsink_component_Private->destructor = omx_symbianoutputstreamsink_component_Destructor;
00116 
00117     /* Allocate the playback handle and the hardware parameter structure */
00118     if (create_output_stream(&pPort->output_handle) < 0) 
00119     {
00120         DEBUG(DEB_LEV_ERR, "cannot create audio device\n");
00121         return OMX_ErrorHardware;
00122     }
00123     else
00124     {
00125         DEBUG(DEB_LEV_SIMPLE_SEQ, "Got playback handle at %08x %08X\n", (int)pPort->output_handle, (int)&pPort->output_handle);
00126     }
00127 
00128     DEBUG(DEB_LEV_PARAMS, "output stream component open pointer is %p\n", pPort->output_handle);
00129   
00130     openmaxStandComp->SetParameter  = omx_symbianoutputstreamsink_component_SetParameter;
00131     openmaxStandComp->GetParameter  = omx_symbianoutputstreamsink_component_GetParameter;
00132     openmaxStandComp->SetConfig     = omx_symbianoutputstreamsink_component_SetConfig;
00133     openmaxStandComp->GetConfig     = omx_symbianoutputstreamsink_component_GetConfig;
00134 
00135     /* Write in the default paramenters */
00136     omx_symbianoutputstreamsink_component_SetParameter(openmaxStandComp, OMX_IndexParamAudioInit, &omx_symbianoutputstreamsink_component_Private->sPortTypesParam);
00137     pPort->AudioPCMConfigured   = 0;
00138 
00139     if (!pPort->AudioPCMConfigured) 
00140     {
00141         DEBUG(DEB_LEV_SIMPLE_SEQ, "Configuring the PCM interface in the Init function\n");
00142         omx_symbianoutputstreamsink_component_SetParameter(openmaxStandComp, OMX_IndexParamAudioPcm, &pPort->omxAudioParamPcmMode);
00143     }
00144 
00145     return err;
00146 }
00147 
00150 OMX_ERRORTYPE 
00151 omx_symbianoutputstreamsink_component_Destructor(OMX_COMPONENTTYPE *openmaxStandComp)
00152 {
00153     omx_symbianoutputstreamsink_component_PrivateType* omx_symbianoutputstreamsink_component_Private = openmaxStandComp->pComponentPrivate;
00154 
00155     omx_symbianoutputstreamsink_component_PortType* pPort = (omx_symbianoutputstreamsink_component_PortType *) omx_symbianoutputstreamsink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];
00156 
00157     if(pPort->output_handle)
00158     {
00159         close_output_stream(pPort->output_handle);
00160     }   
00161 
00162     return omx_base_sink_Destructor(openmaxStandComp);
00163 }
00164 
00168 void 
00169 omx_symbianoutputstreamsink_component_BufferMgmtCallback(OMX_COMPONENTTYPE *openmaxStandComp, OMX_BUFFERHEADERTYPE* inputbuffer) 
00170 {
00171     OMX_S32 totalBuffer;
00172     omx_symbianoutputstreamsink_component_PrivateType* omx_symbianoutputstreamsink_component_Private = openmaxStandComp->pComponentPrivate;
00173     omx_symbianoutputstreamsink_component_PortType *port = (omx_symbianoutputstreamsink_component_PortType *) omx_symbianoutputstreamsink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];
00174 
00175     if(inputbuffer->nFilledLen <= 0)
00176     {
00177         DEBUG(DEB_LEV_FULL_SEQ, "inputBuffer filledLen is %d\n", inputbuffer->nFilledLen);
00178         return;
00179     }
00180 
00181     totalBuffer = inputbuffer->nFilledLen;
00182 
00183     DEBUG(DEB_LEV_FULL_SEQ, "opening stream at symbianoutputstreamsink\n");
00184     
00185     open_output_stream(port->output_handle, 44100, 2);
00186 
00187     DEBUG(DEB_LEV_FULL_SEQ, "writing audio data at symbianoutputstreamsink\n");
00188 
00189     write_audio_data(port->output_handle, inputbuffer->pBuffer, totalBuffer);
00190     
00191     DEBUG(DEB_LEV_FULL_SEQ, "audio data  written at symbianoutputstreamsink\n");
00192 
00193     inputbuffer->nFilledLen=0;
00194 }
00195 
00196 OMX_ERRORTYPE omx_symbianoutputstreamsink_component_SetConfig(
00197     OMX_IN  OMX_HANDLETYPE hComponent,
00198     OMX_IN  OMX_INDEXTYPE nIndex,
00199     OMX_IN  OMX_PTR pComponentConfigStructure) 
00200 {
00201     /*Call the base component function*/
00202     return omx_base_component_SetConfig(hComponent, nIndex, pComponentConfigStructure);
00203 }
00204 
00205 OMX_ERRORTYPE omx_symbianoutputstreamsink_component_GetConfig(
00206     OMX_IN  OMX_HANDLETYPE hComponent,
00207     OMX_IN  OMX_INDEXTYPE nIndex,
00208     OMX_INOUT OMX_PTR pComponentConfigStructure)
00209 {
00210     /*Call the base component function*/
00211     return omx_base_component_GetConfig(hComponent, nIndex, pComponentConfigStructure);
00212 }
00213 
00214 OMX_ERRORTYPE 
00215 omx_symbianoutputstreamsink_component_SetParameter(OMX_IN  OMX_HANDLETYPE hComponent,
00216                                                    OMX_IN  OMX_INDEXTYPE nParamIndex,
00217                                                    OMX_IN  OMX_PTR ComponentParameterStructure)
00218 {
00219     OMX_ERRORTYPE err = OMX_ErrorNone;
00220     OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;
00221     OMX_AUDIO_PARAM_MP3TYPE * pAudioMp3;
00222     OMX_U32 portIndex;
00223     OMX_AUDIO_PARAM_PCMMODETYPE* omxAudioParamPcmMode;
00224     
00225     /* Check which structure we are being fed and make control its header */
00226     OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE*)hComponent;
00227     omx_symbianoutputstreamsink_component_PrivateType* omx_symbianoutputstreamsink_component_Private = openmaxStandComp->pComponentPrivate;
00228     omx_symbianoutputstreamsink_component_PortType* pPort = (omx_symbianoutputstreamsink_component_PortType *) omx_symbianoutputstreamsink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX];
00229  
00230     if (ComponentParameterStructure == NULL) 
00231     {
00232         return OMX_ErrorBadParameter;
00233     }
00234 
00235     DEBUG(DEB_LEV_SIMPLE_SEQ, "   Setting parameter %i\n", nParamIndex);
00236 
00237     switch(nParamIndex) 
00238     {
00239         case OMX_IndexParamAudioInit:
00240             /*Check Structure Header*/
00241             err = checkHeader(ComponentParameterStructure , sizeof(OMX_PORT_PARAM_TYPE));
00242             if(err!=OMX_ErrorNone) 
00243             { 
00244                 DEBUG(DEB_LEV_ERR, "Header Check Error=%x\n",err); 
00245                 break;
00246             }
00247             memcpy(&omx_symbianoutputstreamsink_component_Private->sPortTypesParam,ComponentParameterStructure,sizeof(OMX_PORT_PARAM_TYPE));
00248             break;
00249 
00250         case OMX_IndexParamAudioPortFormat:
00251             pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
00252             portIndex = pAudioPortFormat->nPortIndex;
00253             /*Check Structure Header and verify component state*/
00254             err = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pAudioPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00255             if(err!=OMX_ErrorNone) 
00256             { 
00257                 DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err); 
00258                 break;
00259             }
00260             if (portIndex < 1) 
00261             {
00262                 memcpy(&pPort->sAudioParam,pAudioPortFormat,sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00263             } 
00264             else 
00265             {
00266                 return OMX_ErrorBadPortIndex;
00267             }
00268             break;
00269 
00270         case OMX_IndexParamAudioPcm:
00271             omxAudioParamPcmMode = (OMX_AUDIO_PARAM_PCMMODETYPE*)ComponentParameterStructure;
00272             pPort->AudioPCMConfigured   = 1;
00273             if(omxAudioParamPcmMode->nPortIndex != pPort->omxAudioParamPcmMode.nPortIndex)
00274             {
00275                 DEBUG(DEB_LEV_ERR, "Error setting input pPort index\n");
00276                 err = OMX_ErrorBadParameter;
00277                 break;
00278             }   
00279             break;
00280 
00281         case OMX_IndexParamAudioMp3:
00282             pAudioMp3 = (OMX_AUDIO_PARAM_MP3TYPE*)ComponentParameterStructure;
00283             /*Check Structure Header and verify component state*/
00284             err = omx_base_component_ParameterSanityCheck(hComponent, pAudioMp3->nPortIndex, pAudioMp3, sizeof(OMX_AUDIO_PARAM_MP3TYPE));
00285             if(err!=OMX_ErrorNone) 
00286             { 
00287                 DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err); 
00288                 break;
00289             }
00290             break;
00291 
00292         default: /*Call the base component function*/
00293             return omx_base_component_SetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00294     }
00295     return OMX_ErrorNone;
00296 }
00297 
00298 OMX_ERRORTYPE 
00299 omx_symbianoutputstreamsink_component_GetParameter(OMX_IN  OMX_HANDLETYPE hComponent,
00300                                                    OMX_IN  OMX_INDEXTYPE nParamIndex,
00301                                                    OMX_INOUT OMX_PTR ComponentParameterStructure)
00302 {
00303     OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;   
00304     
00305     OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE*)hComponent;
00306     omx_symbianoutputstreamsink_component_PrivateType* omx_symbianoutputstreamsink_component_Private = openmaxStandComp->pComponentPrivate;
00307     omx_symbianoutputstreamsink_component_PortType *pPort = (omx_symbianoutputstreamsink_component_PortType *) omx_symbianoutputstreamsink_component_Private->ports[OMX_BASE_SINK_INPUTPORT_INDEX]; 
00308     
00309     if (ComponentParameterStructure == NULL) 
00310     {
00311         return OMX_ErrorBadParameter;
00312     }
00313     
00314     DEBUG(DEB_LEV_SIMPLE_SEQ, "   Getting parameter %i\n", nParamIndex);
00315     
00316     /* Check which structure we are being fed and fill its header */
00317     switch(nParamIndex) 
00318     {
00319         case OMX_IndexParamAudioInit:
00320             setHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE));
00321             memcpy(ComponentParameterStructure, &omx_symbianoutputstreamsink_component_Private->sPortTypesParam, sizeof(OMX_PORT_PARAM_TYPE));
00322             break;
00323 
00324         case OMX_IndexParamAudioPortFormat:
00325             pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
00326             setHeader(pAudioPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00327             if (pAudioPortFormat->nPortIndex < 1) 
00328             {
00329                 memcpy(pAudioPortFormat, &pPort->sAudioParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
00330             } 
00331             else 
00332             {
00333                 return OMX_ErrorBadPortIndex;
00334             }
00335             break;      
00336 
00337         case OMX_IndexParamAudioPcm:
00338             if(((OMX_AUDIO_PARAM_PCMMODETYPE*)ComponentParameterStructure)->nPortIndex !=
00339                 pPort->omxAudioParamPcmMode.nPortIndex)
00340             {
00341                 return OMX_ErrorBadParameter;
00342             }
00343             memcpy(ComponentParameterStructure, &pPort->omxAudioParamPcmMode, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
00344             break;
00345 
00346         default: /*Call the base component function*/
00347             return omx_base_component_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00348     }
00349 
00350     return OMX_ErrorNone;
00351 }

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