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