OpenMAX Bellagio  0.9.3
omx_volume_component.c
Go to the documentation of this file.
1 
27 #include <omxcore.h>
28 #include <omx_base_audio_port.h>
29 #include <omx_volume_component.h>
30 #include<OMX_Audio.h>
31 
32 /* gain value */
33 #define GAIN_VALUE 100.0f
34 
37  omx_volume_component_PrivateType* omx_volume_component_Private;
38  OMX_U32 i;
39 
40  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n",__func__);
41 
43  if (!openmaxStandComp->pComponentPrivate) {
44  openmaxStandComp->pComponentPrivate = calloc(1, sizeof(omx_volume_component_PrivateType));
45  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s allocated private structure %p for std component %p\n",
46  __func__, openmaxStandComp->pComponentPrivate, openmaxStandComp);
47  if(openmaxStandComp->pComponentPrivate == NULL) {
49  }
50  } else {
51  DEBUG(DEB_LEV_ERR, "In %s, Error Component %p Already Allocated\n", __func__, openmaxStandComp->pComponentPrivate);
52  return OMX_ErrorUndefined;
53  }
54 
55  omx_volume_component_Private = openmaxStandComp->pComponentPrivate;
56  omx_volume_component_Private->ports = NULL;
57 
59  err = omx_base_filter_Constructor(openmaxStandComp, cComponentName);
60  if (err != OMX_ErrorNone) {
61  DEBUG(DEB_LEV_ERR, "In %s failed base class constructor\n", __func__);
62  return err;
63  }
64 
65  omx_volume_component_Private->sPortTypesParam[OMX_PortDomainAudio].nStartPortNumber = 0;
66  omx_volume_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts = 2;
67 
69  if (omx_volume_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts && !omx_volume_component_Private->ports) {
70  omx_volume_component_Private->ports = calloc(omx_volume_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts, sizeof(omx_base_PortType *));
71  if (!omx_volume_component_Private->ports) {
73  }
74  for (i=0; i < omx_volume_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts; i++) {
75  omx_volume_component_Private->ports[i] = calloc(1, sizeof(omx_base_audio_PortType));
76  if (!omx_volume_component_Private->ports[i]) {
78  }
79  }
80  }
81 
82  err = base_audio_port_Constructor(openmaxStandComp, &omx_volume_component_Private->ports[0], 0, OMX_TRUE);
83  if (err != OMX_ErrorNone) {
85  }
86  err = base_audio_port_Constructor(openmaxStandComp, &omx_volume_component_Private->ports[1], 1, OMX_FALSE);
87  if (err != OMX_ErrorNone) {
89  }
90 
92  omx_volume_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]->sPortParam.nBufferSize = DEFAULT_OUT_BUFFER_SIZE;
93  omx_volume_component_Private->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX]->sPortParam.nBufferSize = DEFAULT_OUT_BUFFER_SIZE;
94 
95  omx_volume_component_Private->gain = GAIN_VALUE; //100.0f; // default gain
96  omx_volume_component_Private->destructor = omx_volume_component_Destructor;
99  openmaxStandComp->GetConfig = omx_volume_component_GetConfig;
100  openmaxStandComp->SetConfig = omx_volume_component_SetConfig;
101  omx_volume_component_Private->BufferMgmtCallback = omx_volume_component_BufferMgmtCallback;
102 
103  /* resource management special section */
104  omx_volume_component_Private->nqualitylevels = VOLUME_QUALITY_LEVELS;
105  omx_volume_component_Private->currentQualityLevel = 1;
106  omx_volume_component_Private->multiResourceLevel = malloc(sizeof(multiResourceDescriptor *) * VOLUME_QUALITY_LEVELS);
107  for (i = 0; i<VOLUME_QUALITY_LEVELS; i++) {
108  omx_volume_component_Private->multiResourceLevel[i] = malloc(sizeof(multiResourceDescriptor));
109  omx_volume_component_Private->multiResourceLevel[i]->CPUResourceRequested = volumeQualityLevels[i * 2];
110  omx_volume_component_Private->multiResourceLevel[i]->MemoryResourceRequested = volumeQualityLevels[i * 2 + 1];
111  }
112 
113  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s for component %p\n", __func__, openmaxStandComp);
114  return OMX_ErrorNone;
115 }
116 
117 
121 
122  omx_volume_component_PrivateType* omx_volume_component_Private = openmaxStandComp->pComponentPrivate;
123  OMX_U32 i;
124 
125  /* frees port/s */
126  DEBUG(DEB_LEV_FUNCTION_NAME, "In %s for component %p\n", __func__, openmaxStandComp);
127  if (omx_volume_component_Private->ports) {
128  for (i=0; i < omx_volume_component_Private->sPortTypesParam[OMX_PortDomainAudio].nPorts; i++) {
129  if(omx_volume_component_Private->ports[i]) {
130  omx_volume_component_Private->ports[i]->PortDestructor(omx_volume_component_Private->ports[i]);
131  }
132  }
133  free(omx_volume_component_Private->ports);
134  omx_volume_component_Private->ports=NULL;
135  }
136 
137  omx_base_filter_Destructor(openmaxStandComp);
138 
139  DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s for component %p\n", __func__, openmaxStandComp);
140  return OMX_ErrorNone;
141 }
142 
146  int i;
147  int sampleCount = pInputBuffer->nFilledLen / 2; // signed 16 bit samples assumed
148  omx_volume_component_PrivateType* omx_volume_component_Private = openmaxStandComp->pComponentPrivate;
149 
150  if(omx_volume_component_Private->gain != GAIN_VALUE) {
151  for (i = 0; i < sampleCount; i++) {
152  ((OMX_S16*) pOutputBuffer->pBuffer)[i] = (OMX_S16)
153  (((OMX_S16*) pInputBuffer->pBuffer)[i] * (omx_volume_component_Private->gain / 100.0f));
154  }
155  } else {
156  memcpy(pOutputBuffer->pBuffer,pInputBuffer->pBuffer,pInputBuffer->nFilledLen);
157  }
158  pOutputBuffer->nFilledLen = pInputBuffer->nFilledLen;
159  pInputBuffer->nFilledLen=0;
160 }
161 
164  OMX_HANDLETYPE hComponent,
165  OMX_INDEXTYPE nIndex,
166  OMX_PTR pComponentConfigStructure) {
167 
169  OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
170  omx_volume_component_PrivateType* omx_volume_component_Private = openmaxStandComp->pComponentPrivate;
172 
173  switch (nIndex) {
175  pVolume = (OMX_AUDIO_CONFIG_VOLUMETYPE*) pComponentConfigStructure;
176  if(pVolume->sVolume.nValue > 100) {
178  break;
179  }
180  omx_volume_component_Private->gain = pVolume->sVolume.nValue;
181  err = OMX_ErrorNone;
182  break;
183  default: // delegate to superclass
184  err = omx_base_component_SetConfig(hComponent, nIndex, pComponentConfigStructure);
185  }
186 
187  return err;
188 }
189 
191  OMX_HANDLETYPE hComponent,
192  OMX_INDEXTYPE nIndex,
193  OMX_PTR pComponentConfigStructure) {
195  OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
196  omx_volume_component_PrivateType* omx_volume_component_Private = openmaxStandComp->pComponentPrivate;
198 
199  switch (nIndex) {
201  pVolume = (OMX_AUDIO_CONFIG_VOLUMETYPE*) pComponentConfigStructure;
202  setHeader(pVolume,sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE));
203  pVolume->sVolume.nValue = omx_volume_component_Private->gain;
204  pVolume->sVolume.nMin = 0;
205  pVolume->sVolume.nMax = 100;
206  pVolume->bLinear = OMX_TRUE;
207  err = OMX_ErrorNone;
208  break;
209  default :
210  err = omx_base_component_GetConfig(hComponent, nIndex, pComponentConfigStructure);
211  }
212  return err;
213 }
214 
216  OMX_HANDLETYPE hComponent,
217  OMX_INDEXTYPE nParamIndex,
218  OMX_PTR ComponentParameterStructure) {
219 
221  OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;
222  OMX_PARAM_COMPONENTROLETYPE *pComponentRole;
223  OMX_U32 portIndex;
225 
226  /* Check which structure we are being fed and make control its header */
227  OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
228  omx_volume_component_PrivateType* omx_volume_component_Private = openmaxStandComp->pComponentPrivate;
229  if (ComponentParameterStructure == NULL) {
230  return OMX_ErrorBadParameter;
231  }
232 
233  DEBUG(DEB_LEV_SIMPLE_SEQ, " Setting parameter %i\n", nParamIndex);
234  switch(nParamIndex) {
236  pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
237  portIndex = pAudioPortFormat->nPortIndex;
238  err = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pAudioPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
239  if(err!=OMX_ErrorNone) {
240  DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,err);
241  break;
242  }
243  if (portIndex <= 1) {
244  port= (omx_base_audio_PortType *)omx_volume_component_Private->ports[portIndex];
245  memcpy(&port->sAudioParam, pAudioPortFormat, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
246  } else {
248  }
249  break;
251  pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)ComponentParameterStructure;
252 
253  if (omx_volume_component_Private->state != OMX_StateLoaded && omx_volume_component_Private->state != OMX_StateWaitForResources) {
254  DEBUG(DEB_LEV_ERR, "In %s Incorrect State=%x lineno=%d\n",__func__,omx_volume_component_Private->state,__LINE__);
256  }
257 
258  if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PARAM_COMPONENTROLETYPE))) != OMX_ErrorNone) {
259  break;
260  }
261 
262  if (strcmp( (char*) pComponentRole->cRole, VOLUME_COMP_ROLE)) {
263  return OMX_ErrorBadParameter;
264  }
265  break;
266  default:
267  err = omx_base_component_SetParameter(hComponent, nParamIndex, ComponentParameterStructure);
268  }
269  return err;
270 }
271 
273  OMX_HANDLETYPE hComponent,
274  OMX_INDEXTYPE nParamIndex,
275  OMX_PTR ComponentParameterStructure) {
276 
277  OMX_AUDIO_PARAM_PORTFORMATTYPE *pAudioPortFormat;
278  OMX_AUDIO_PARAM_PCMMODETYPE *pAudioPcmMode;
279  OMX_PARAM_COMPONENTROLETYPE *pComponentRole;
282  OMX_COMPONENTTYPE *openmaxStandComp = (OMX_COMPONENTTYPE *)hComponent;
283  omx_volume_component_PrivateType* omx_volume_component_Private = openmaxStandComp->pComponentPrivate;
284  if (ComponentParameterStructure == NULL) {
285  return OMX_ErrorBadParameter;
286  }
287  DEBUG(DEB_LEV_SIMPLE_SEQ, " Getting parameter %i\n", nParamIndex);
288  /* Check which structure we are being fed and fill its header */
289  switch(nParamIndex) {
291  if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) {
292  break;
293  }
294  memcpy(ComponentParameterStructure, &omx_volume_component_Private->sPortTypesParam[OMX_PortDomainAudio], sizeof(OMX_PORT_PARAM_TYPE));
295  break;
297  pAudioPortFormat = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)ComponentParameterStructure;
298  if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) {
299  break;
300  }
301  if (pAudioPortFormat->nPortIndex <= 1) {
302  port= (omx_base_audio_PortType *)omx_volume_component_Private->ports[pAudioPortFormat->nPortIndex];
303  memcpy(pAudioPortFormat, &port->sAudioParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
304  } else {
306  }
307  break;
309  pAudioPcmMode = (OMX_AUDIO_PARAM_PCMMODETYPE*)ComponentParameterStructure;
310  if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE))) != OMX_ErrorNone) {
311  break;
312  }
313 
314  if (pAudioPcmMode->nPortIndex > 1) {
315  return OMX_ErrorBadPortIndex;
316  }
317  pAudioPcmMode->nChannels = 2;
318  pAudioPcmMode->eNumData = OMX_NumericalDataSigned;
319  pAudioPcmMode->eEndian = OMX_EndianBig;
320  pAudioPcmMode->bInterleaved = OMX_TRUE;
321  pAudioPcmMode->nBitPerSample = 16;
322  pAudioPcmMode->nSamplingRate = 0;
323  pAudioPcmMode->ePCMMode = OMX_AUDIO_PCMModeLinear;
324  break;
326  pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)ComponentParameterStructure;
327  if ((err = checkHeader(ComponentParameterStructure, sizeof(OMX_PARAM_COMPONENTROLETYPE))) != OMX_ErrorNone) {
328  break;
329  }
330  strcpy( (char*) pComponentRole->cRole, VOLUME_COMP_ROLE);
331  break;
332  default:
333  err = omx_base_component_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
334  }
335  return err;
336 }
OMX_ERRORTYPE
Definition: OMX_Core.h:127
@ OMX_ErrorInsufficientResources
Definition: OMX_Core.h:131
@ OMX_ErrorBadPortIndex
Definition: OMX_Core.h:224
@ OMX_ErrorNone
Definition: OMX_Core.h:128
@ OMX_ErrorUndefined
Definition: OMX_Core.h:134
@ OMX_ErrorBadParameter
Definition: OMX_Core.h:147
@ OMX_ErrorIncorrectStateOperation
Definition: OMX_Core.h:215
OMX_INDEXTYPE
Definition: OMX_Index.h:60
@ OMX_IndexParamAudioPortFormat
Definition: OMX_Index.h:94
@ OMX_IndexParamAudioInit
Definition: OMX_Index.h:64
@ OMX_IndexParamStandardComponentRole
Definition: OMX_Index.h:85
@ OMX_IndexConfigAudioVolume
Definition: OMX_Index.h:128
@ OMX_IndexParamAudioPcm
Definition: OMX_Index.h:95
unsigned long OMX_U32
Definition: OMX_Types.h:145
char * OMX_STRING
Definition: OMX_Types.h:206
@ OMX_EndianBig
Definition: OMX_Types.h:236
@ OMX_TRUE
Definition: OMX_Types.h:191
@ OMX_FALSE
Definition: OMX_Types.h:190
void * OMX_PTR
Definition: OMX_Types.h:199
@ OMX_NumericalDataSigned
Definition: OMX_Types.h:247
void * OMX_HANDLETYPE
Definition: OMX_Types.h:295
signed short OMX_S16
Definition: OMX_Types.h:142
@ OMX_AUDIO_PCMModeLinear
Definition: OMX_Audio.h:130
@ OMX_PortDomainAudio
Definition: OMX_Component.h:51
@ OMX_StateWaitForResources
Definition: OMX_Core.h:108
@ OMX_StateLoaded
Definition: OMX_Core.h:97
OMX_ERRORTYPE base_audio_port_Constructor(OMX_COMPONENTTYPE *openmaxStandComp, omx_base_PortType **openmaxStandPort, OMX_U32 nPortIndex, OMX_BOOL isInput)
The base constructor for the generic OpenMAX ST Audio port.
OMX_ERRORTYPE omx_base_component_SetParameter(OMX_HANDLETYPE hComponent, OMX_INDEXTYPE nParamIndex, OMX_PTR ComponentParameterStructure)
Part of the standard OpenMAX function.
OMX_ERRORTYPE omx_base_component_ParameterSanityCheck(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex, OMX_PTR pStructure, size_t size)
void setHeader(OMX_PTR header, OMX_U32 size)
Simply fills the first two fields in any OMX structure with the size and the version.
OMX_ERRORTYPE omx_base_component_GetParameter(OMX_HANDLETYPE hComponent, OMX_INDEXTYPE nParamIndex, OMX_PTR ComponentParameterStructure)
Part of the standard OpenMAX function.
OMX_ERRORTYPE omx_base_component_SetConfig(OMX_HANDLETYPE hComponent, OMX_INDEXTYPE nIndex, OMX_PTR pComponentConfigStructure)
base SetConfig function
OMX_ERRORTYPE omx_base_component_GetConfig(OMX_HANDLETYPE hComponent, OMX_INDEXTYPE nIndex, OMX_PTR pComponentConfigStructure)
base GetConfig function
OMX_ERRORTYPE checkHeader(OMX_PTR header, OMX_U32 size)
Checks the header of a structure for consistency with size and spec version.
#define DEFAULT_OUT_BUFFER_SIZE
OMX_ERRORTYPE omx_base_filter_Constructor(OMX_COMPONENTTYPE *openmaxStandComp, OMX_STRING cComponentName)
The base filter contructor for the OpenMAX ST components.
OMX_ERRORTYPE omx_base_filter_Destructor(OMX_COMPONENTTYPE *openmaxStandComp)
the base filter destructor for ST OpenMAX components
#define OMX_BASE_FILTER_INPUTPORT_INDEX
#define OMX_BASE_FILTER_OUTPUTPORT_INDEX
#define DEB_LEV_FUNCTION_NAME
#define DEB_LEV_ERR
#define DEB_LEV_SIMPLE_SEQ
#define DEBUG(n, fmt, args...)
OMX_ERRORTYPE RM_RegisterComponent(char *name, int max_components)
OMX_ERRORTYPE omx_volume_component_SetConfig(OMX_HANDLETYPE hComponent, OMX_INDEXTYPE nIndex, OMX_PTR pComponentConfigStructure)
OMX_ERRORTYPE omx_volume_component_GetParameter(OMX_HANDLETYPE hComponent, OMX_INDEXTYPE nParamIndex, OMX_PTR ComponentParameterStructure)
OMX_ERRORTYPE omx_volume_component_Destructor(OMX_COMPONENTTYPE *openmaxStandComp)
OMX_ERRORTYPE omx_volume_component_Constructor(OMX_COMPONENTTYPE *openmaxStandComp, OMX_STRING cComponentName)
#define GAIN_VALUE
OMX_ERRORTYPE omx_volume_component_GetConfig(OMX_HANDLETYPE hComponent, OMX_INDEXTYPE nIndex, OMX_PTR pComponentConfigStructure)
void omx_volume_component_BufferMgmtCallback(OMX_COMPONENTTYPE *openmaxStandComp, OMX_BUFFERHEADERTYPE *pInputBuffer, OMX_BUFFERHEADERTYPE *pOutputBuffer)
OMX_ERRORTYPE omx_volume_component_SetParameter(OMX_HANDLETYPE hComponent, OMX_INDEXTYPE nParamIndex, OMX_PTR ComponentParameterStructure)
#define VOLUME_QUALITY_LEVELS
#define VOLUME_COMP_ROLE
#define VOLUME_COMP_NAME
#define MAX_VOLUME_COMPONENTS
OMX_ERRORTYPE err
OMX_AUDIO_PCMMODETYPE ePCMMode
Definition: OMX_Audio.h:171
OMX_ENDIANTYPE eEndian
Definition: OMX_Audio.h:165
OMX_NUMERICALDATATYPE eNumData
Definition: OMX_Audio.h:164
OMX_S32 nValue
Definition: OMX_Types.h:263
OMX_S32 nMin
Definition: OMX_Types.h:264
OMX_S32 nMax
Definition: OMX_Types.h:265
OMX_ERRORTYPE(* GetConfig)(OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_INDEXTYPE nIndex, OMX_INOUT OMX_PTR pComponentConfigStructure)
OMX_ERRORTYPE(* SetConfig)(OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_INDEXTYPE nIndex, OMX_IN OMX_PTR pComponentConfigStructure)
OMX_ERRORTYPE(* SetParameter)(OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_INDEXTYPE nIndex, OMX_IN OMX_PTR pComponentParameterStructure)
OMX_ERRORTYPE(* GetParameter)(OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_INDEXTYPE nParamIndex, OMX_INOUT OMX_PTR pComponentParameterStructure)
OMX_PTR pComponentPrivate
OMX_AUDIO_PARAM_PORTFORMATTYPE sAudioParam

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