1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <stdio.h> |
|
19 #include <stdlib.h> |
|
20 #include <assert.h> |
|
21 |
|
22 #include "xaoutputmix.h" |
|
23 #include "xaobjectitf.h" |
|
24 #include "xadynintmgmtitf.h" |
|
25 #include "xaconfigextensionsitf.h" |
|
26 #include "xaequalizeritf.h" |
|
27 #include "xavolumeitf.h" |
|
28 #include "xaoutputmixitf.h" |
|
29 #include "xathreadsafety.h" |
|
30 #include "xaoutputmixadaptctx.h" |
|
31 #include "xacapabilitiesmgr.h" |
|
32 |
|
33 /* Static mapping of enumeration XAOMixInterfaces to interface iids */ |
|
34 static const XAInterfaceID* xaOMixItfIIDs[OMIX_ITFCOUNT]={ |
|
35 &XA_IID_OBJECT, |
|
36 &XA_IID_DYNAMICINTERFACEMANAGEMENT, |
|
37 &XA_IID_CONFIGEXTENSION, |
|
38 &XA_IID_OUTPUTMIX, |
|
39 &XA_IID_EQUALIZER, |
|
40 &XA_IID_VOLUME |
|
41 }; |
|
42 |
|
43 /***************************************************************************** |
|
44 * Global methods |
|
45 *****************************************************************************/ |
|
46 |
|
47 |
|
48 /* |
|
49 *XAresult XAOMixImpl_CreateOutputMix(XAObjectItf *pMix, |
|
50 * XAuint32 numInterfaces, |
|
51 * const XAInterfaceID *pInterfaceIds, |
|
52 * const XAboolean *pInterfaceRequired) |
|
53 * Description: Create object |
|
54 */ |
|
55 XAresult XAOMixImpl_CreateOutputMix(FrameworkMap* mapper, |
|
56 XACapabilities* capabilities, |
|
57 XAObjectItf *pMix, |
|
58 XAuint32 numInterfaces, |
|
59 const XAInterfaceID *pInterfaceIds, |
|
60 const XAboolean *pInterfaceRequired) |
|
61 { |
|
62 |
|
63 XAObjectItfImpl* pBaseObj = NULL; |
|
64 XAOMixImpl* pImpl = NULL; |
|
65 XAuint32 itfIdx = 0; |
|
66 DEBUG_API("->XAOMixImpl_CreateOutputMix"); |
|
67 XA_IMPL_THREAD_SAFETY_ENTRY(XATSOutputMix); |
|
68 |
|
69 |
|
70 |
|
71 if(!pMix) |
|
72 { |
|
73 XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix); |
|
74 /* invalid parameter */ |
|
75 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
76 DEBUG_API("<-XAOMixImpl_CreateOutputMix"); |
|
77 return XA_RESULT_PARAMETER_INVALID; |
|
78 } |
|
79 |
|
80 /* instantiate object */ |
|
81 pImpl = (XAOMixImpl*)calloc(1,sizeof(XAOMixImpl)); |
|
82 if(!pImpl) |
|
83 { |
|
84 XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix); |
|
85 /* memory allocation failed */ |
|
86 DEBUG_ERR("XA_RESULT_MEMORY_FAILURE"); |
|
87 DEBUG_API("<-XAOMixImpl_CreateOutputMix"); |
|
88 return XA_RESULT_MEMORY_FAILURE; |
|
89 } |
|
90 pBaseObj = &pImpl->baseObj; |
|
91 |
|
92 XAObjectItfImpl_Init(pBaseObj, |
|
93 OMIX_ITFCOUNT, |
|
94 xaOMixItfIIDs, |
|
95 XAOMixImpl_DoRealize, |
|
96 XAOMixImpl_DoResume, |
|
97 XAOMixImpl_FreeResources ); |
|
98 |
|
99 /* Mark interfaces that need to be exposed */ |
|
100 /* Implicit and mandated interfaces */ |
|
101 pBaseObj->interfaceMap[OMIX_OUTPUTMIXITF].required = XA_BOOLEAN_TRUE; |
|
102 pBaseObj->interfaceMap[OMIX_DIMITF].required = XA_BOOLEAN_TRUE; |
|
103 |
|
104 /* Explicit interfaces */ |
|
105 if((numInterfaces != 0) && pInterfaceIds && pInterfaceRequired) |
|
106 { |
|
107 /* Check required interfaces */ |
|
108 for(itfIdx = 0; itfIdx < numInterfaces; itfIdx++) |
|
109 { |
|
110 /* If mapEntry is null then required interface is not supported.*/ |
|
111 XAObjItfMapEntry *entry = |
|
112 XAObjectItfImpl_GetItfEntry((XAObjectItf)&(pBaseObj), pInterfaceIds[itfIdx]); |
|
113 if( !entry ) |
|
114 { |
|
115 if( pInterfaceRequired[itfIdx] ) |
|
116 { |
|
117 /* required interface cannot be accommodated - fail creation */ |
|
118 XAObjectItfImpl_Destroy((XAObjectItf)&(pBaseObj)); |
|
119 XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix); |
|
120 DEBUG_ERR("Required interface not found - abort creation!"); |
|
121 return XA_RESULT_FEATURE_UNSUPPORTED; |
|
122 } |
|
123 else |
|
124 { |
|
125 DEBUG_INFO("Requested (not required) interface not found - continue creation"); |
|
126 } |
|
127 } |
|
128 else |
|
129 { |
|
130 entry->required = XA_BOOLEAN_TRUE; |
|
131 } |
|
132 } |
|
133 } |
|
134 /* Mark interfaces that can be handled dynamically */ |
|
135 pBaseObj->interfaceMap[OMIX_EQUALIZERITF].isDynamic = XA_BOOLEAN_TRUE; |
|
136 |
|
137 /* This code is put here to return Feature Not Supported since adaptation is not present*/ |
|
138 /*************************************************/ |
|
139 XAObjectItfImpl_Destroy((XAObjectItf)&(pBaseObj)); |
|
140 XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix); |
|
141 DEBUG_ERR("Required interface not found - abort creation!"); |
|
142 return XA_RESULT_FEATURE_UNSUPPORTED; |
|
143 /*************************************************/ |
|
144 |
|
145 /* // Create outputmix adaptation context |
|
146 pImpl->adaptationCtx = XAOutputMixAdapt_Create(); |
|
147 |
|
148 //Set ObjectItf to point to newly created object |
|
149 *pMix = (XAObjectItf)&(pBaseObj->self); |
|
150 |
|
151 XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix); |
|
152 |
|
153 DEBUG_API("<-XAOMixImpl_CreateOutputMix"); |
|
154 return XA_RESULT_SUCCESS;*/ |
|
155 } |
|
156 |
|
157 /* |
|
158 * XAresult XAOMixImpl_QueryNumSupportedInterfaces(XAuint32 * pNumSupportedInterfaces) |
|
159 * Description: Query number of supported interfaces |
|
160 */ |
|
161 XAresult XAOMixImpl_QueryNumSupportedInterfaces(XAuint32 * pNumSupportedInterfaces) |
|
162 { |
|
163 DEBUG_API("->XAOMixImpl_QueryNumSupportedInterfaces"); |
|
164 if( pNumSupportedInterfaces ) |
|
165 { |
|
166 *pNumSupportedInterfaces = OMIX_ITFCOUNT; |
|
167 DEBUG_API_A1("<-XAOMixImpl_QueryNumSupportedInterfaces - %lu", *pNumSupportedInterfaces ); |
|
168 return XA_RESULT_SUCCESS; |
|
169 } |
|
170 else |
|
171 { |
|
172 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
173 DEBUG_API("<-XAOMixImpl_QueryNumSupportedInterfaces"); |
|
174 return XA_RESULT_PARAMETER_INVALID; |
|
175 } |
|
176 } |
|
177 |
|
178 /* |
|
179 * XAresult XAOMixImpl_QuerySupportedInterfaces(XAuint32 index, XAInterfaceID * pInterfaceId) |
|
180 * Description: Statically query supported interfaces |
|
181 */ |
|
182 XAresult XAOMixImpl_QuerySupportedInterfaces(XAuint32 index, |
|
183 XAInterfaceID * pInterfaceId) |
|
184 { |
|
185 DEBUG_API("->XAOMixImpl_QuerySupportedInterfaces"); |
|
186 if (index >= OMIX_ITFCOUNT || !pInterfaceId) |
|
187 { |
|
188 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
189 DEBUG_API("<-XAOMixImpl_QuerySupportedInterfaces"); |
|
190 return XA_RESULT_PARAMETER_INVALID; |
|
191 } |
|
192 else |
|
193 { |
|
194 |
|
195 *pInterfaceId = *(xaOMixItfIIDs[index]); |
|
196 |
|
197 DEBUG_API("<-XAOMixImpl_QuerySupportedInterfaces"); |
|
198 return XA_RESULT_SUCCESS; |
|
199 } |
|
200 } |
|
201 |
|
202 /***************************************************************************** |
|
203 * base object XAObjectItfImpl methods |
|
204 *****************************************************************************/ |
|
205 |
|
206 /* XAresult XAOMixImpl_DoRealize(XAObjectItf self) |
|
207 * Description: Realize all implicit and explicitly wanted interfaces. |
|
208 * Create and initialize implementation-specific variables. |
|
209 * Called from base object XAObjectItfImpl |
|
210 */ |
|
211 XAresult XAOMixImpl_DoRealize(XAObjectItf self) |
|
212 { |
|
213 |
|
214 XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self); |
|
215 XAresult ret = XA_RESULT_SUCCESS; |
|
216 XAOMixImpl* pMixImpl = (XAOMixImpl*)(pObj); |
|
217 XAuint8 itfIdx = 0; |
|
218 DEBUG_API("->XAOMixImpl_DoRealize"); |
|
219 XA_IMPL_THREAD_SAFETY_ENTRY(XATSOutputMix); |
|
220 |
|
221 /* check casting from correct pointer type */ |
|
222 if( !pMixImpl || pObj != pMixImpl->baseObj.self ) |
|
223 { |
|
224 XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix); |
|
225 /* invalid parameter */ |
|
226 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
227 DEBUG_API("<-XAOMixImpl_DoRealize"); |
|
228 return XA_RESULT_PARAMETER_INVALID; |
|
229 } |
|
230 |
|
231 /* Initialize adaptation */ |
|
232 ret = XAOutputMixAdapt_PostInit( (XAAdaptationGstCtx*)pMixImpl->adaptationCtx ); |
|
233 if( ret != XA_RESULT_SUCCESS ) |
|
234 { |
|
235 XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix); |
|
236 DEBUG_API("<-XAOMixImpl_DoRealize"); |
|
237 return ret; |
|
238 } |
|
239 |
|
240 /* Realize all implicit and explicitly wanted interfaces */ |
|
241 for( itfIdx = 0; itfIdx < OMIX_ITFCOUNT; itfIdx++) |
|
242 { |
|
243 if( !(pObj->interfaceMap[itfIdx].pItf) && pObj->interfaceMap[itfIdx].required ) |
|
244 { |
|
245 void *pItf = NULL; |
|
246 switch( itfIdx ) |
|
247 { |
|
248 case OMIX_CONFIGEXTENSIONITF: |
|
249 pItf = XAConfigExtensionsItfImpl_Create(); |
|
250 break; |
|
251 case OMIX_DIMITF: |
|
252 pItf = XADIMItfImpl_Create(); |
|
253 if(pItf) |
|
254 { |
|
255 XADIMItfImpl_Init(pItf, self, |
|
256 XAOMixImpl_DoAddItf, |
|
257 XAOMixImpl_DoResumeItf, |
|
258 XAOMixImpl_DoRemoveItf); |
|
259 } |
|
260 break; |
|
261 case OMIX_EQUALIZERITF: |
|
262 pItf = XAEqualizerItfImpl_Create(pMixImpl->adaptationCtx); |
|
263 break; |
|
264 case OMIX_VOLUMEITF: |
|
265 pItf = XAVolumeItfImpl_Create(pMixImpl->adaptationCtx); |
|
266 break; |
|
267 case OMIX_OUTPUTMIXITF: |
|
268 pItf = XAOutputMixItfImpl_Create(pMixImpl->adaptationCtx); |
|
269 break; |
|
270 default: |
|
271 break; |
|
272 } |
|
273 if( !pItf ) |
|
274 { |
|
275 XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix); |
|
276 DEBUG_ERR("XA_RESULT_MEMORY_FAILURE"); |
|
277 /* memory allocation failed */ |
|
278 DEBUG_API("<-XAOMixImpl_DoRealize"); |
|
279 return XA_RESULT_MEMORY_FAILURE; |
|
280 } |
|
281 else |
|
282 { |
|
283 pObj->interfaceMap[itfIdx].pItf = pItf; |
|
284 } |
|
285 } |
|
286 } |
|
287 |
|
288 pObj->state = XA_OBJECT_STATE_REALIZED; |
|
289 XA_IMPL_THREAD_SAFETY_EXIT(XATSOutputMix); |
|
290 |
|
291 DEBUG_API("<-XAOMixImpl_DoRealize"); |
|
292 return XA_RESULT_SUCCESS; |
|
293 } |
|
294 |
|
295 /* |
|
296 * XAresult XAOMixImpl_DoResume(XAObjectItf self) |
|
297 * Description: Resume object from suspended state |
|
298 */ |
|
299 XAresult XAOMixImpl_DoResume(XAObjectItf self) |
|
300 { |
|
301 DEBUG_API("->XAOMixImpl_DoResume"); |
|
302 DEBUG_API("<-XAOMixImpl_DoResume"); |
|
303 /* This implementation does not support suspended state */ |
|
304 return XA_RESULT_PRECONDITIONS_VIOLATED; |
|
305 } |
|
306 |
|
307 /* |
|
308 * void XAOMixImpl_FreeResources(XAObjectItf self) |
|
309 * Description: Free all resources reserved at XACameraDeviceImpl_DoRealize() |
|
310 */ |
|
311 void XAOMixImpl_FreeResources(XAObjectItf self) |
|
312 { |
|
313 |
|
314 XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self); |
|
315 XAOMixImpl* pImpl = (XAOMixImpl*)(*self); |
|
316 XAuint8 itfIdx = 0; |
|
317 DEBUG_API("->XAOMixImpl_FreeResources"); |
|
318 XA_IMPL_THREAD_SAFETY_ENTRY_FOR_VOID_FUNCTIONS(XATSOutputMix); |
|
319 assert( pObj && pImpl && pObj == pObj->self ); |
|
320 |
|
321 if ( pImpl->adaptationCtx != NULL ) |
|
322 { |
|
323 XAOutputMixAdapt_Destroy( (XAAdaptationGstCtx*)pImpl->adaptationCtx ); |
|
324 pImpl->adaptationCtx = NULL; |
|
325 } |
|
326 |
|
327 /* free all allocated interfaces */ |
|
328 for(itfIdx = 0; itfIdx < OMIX_ITFCOUNT; itfIdx++) |
|
329 { |
|
330 void *pItf = pObj->interfaceMap[itfIdx].pItf; |
|
331 if(pItf) |
|
332 { |
|
333 switch(itfIdx) |
|
334 { |
|
335 case OMIX_CONFIGEXTENSIONITF: |
|
336 XAConfigExtensionsItfImpl_Free( pItf ); |
|
337 break; |
|
338 case OMIX_DIMITF: |
|
339 XADIMItfImpl_Free( pItf ); |
|
340 break; |
|
341 case OMIX_EQUALIZERITF: |
|
342 XAEqualizerItfImpl_Free(pItf); |
|
343 break; |
|
344 case OMIX_VOLUMEITF: |
|
345 XAVolumeItfImpl_Free(pItf); |
|
346 break; |
|
347 case OMIX_OUTPUTMIXITF: |
|
348 XAOutputMixItfImpl_Free( pItf ); |
|
349 break; |
|
350 default: |
|
351 break; |
|
352 } |
|
353 pObj->interfaceMap[itfIdx].pItf = NULL; |
|
354 } |
|
355 } |
|
356 |
|
357 if ( pImpl->adaptationCtx != NULL ) |
|
358 { |
|
359 XAOutputMixAdapt_Destroy( (XAAdaptationGstCtx*)pImpl->adaptationCtx ); |
|
360 pImpl->adaptationCtx = NULL; |
|
361 } |
|
362 |
|
363 XA_IMPL_THREAD_SAFETY_EXIT_FOR_VOID_FUNCTIONS(XATSOutputMix); |
|
364 |
|
365 DEBUG_API("<-XAOMixImpl_FreeResources"); |
|
366 } |
|
367 |
|
368 /***************************************************************************** |
|
369 * MediaRecorderImpl -specific methods |
|
370 *****************************************************************************/ |
|
371 |
|
372 /* XAOMixImpl_DoAddItf |
|
373 * Dynamically add an interface, object specific parts |
|
374 */ |
|
375 XAresult XAOMixImpl_DoAddItf(XAObjectItf self, XAObjItfMapEntry *mapEntry ) |
|
376 { |
|
377 |
|
378 XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self); |
|
379 XAOMixImpl* pImpl = (XAOMixImpl*)(pObj); |
|
380 |
|
381 XAresult ret = XA_RESULT_SUCCESS; |
|
382 DEBUG_API("->XAOMixImpl_DoAddItf"); |
|
383 if(mapEntry) |
|
384 { |
|
385 switch( mapEntry->mapIdx ) |
|
386 { |
|
387 case OMIX_EQUALIZERITF: |
|
388 |
|
389 mapEntry->pItf = XAEqualizerItfImpl_Create( pImpl->adaptationCtx ); |
|
390 |
|
391 break; |
|
392 default: |
|
393 DEBUG_ERR("XAOMixImpl_DoAddItf unknown id"); |
|
394 ret = XA_RESULT_FEATURE_UNSUPPORTED; |
|
395 break; |
|
396 } |
|
397 if( !mapEntry->pItf && ret == XA_RESULT_SUCCESS) |
|
398 { |
|
399 DEBUG_ERR("XAOMixImpl_DoAddItf itf creation failed"); |
|
400 ret = XA_RESULT_MEMORY_FAILURE; |
|
401 } |
|
402 } |
|
403 else |
|
404 { |
|
405 ret = XA_RESULT_PARAMETER_INVALID; |
|
406 } |
|
407 |
|
408 |
|
409 DEBUG_API("<-XAOMixImpl_DoAddItf"); |
|
410 return ret; |
|
411 } |
|
412 |
|
413 /* XAOMixImpl_DoResumeItf |
|
414 * Try to resume lost interface, object specific parts |
|
415 */ |
|
416 XAresult XAOMixImpl_DoResumeItf(XAObjectItf self, XAObjItfMapEntry *mapEntry ) |
|
417 { |
|
418 XAresult ret = XA_RESULT_SUCCESS; |
|
419 DEBUG_API("->XAOMixImpl_DoResumeItf"); |
|
420 /* For now, no difference between suspended and unrealised itfs */ |
|
421 ret = XAOMixImpl_DoAddItf(self,mapEntry); |
|
422 DEBUG_API("<-XAOMixImpl_DoResumeItf"); |
|
423 return ret; |
|
424 } |
|
425 |
|
426 /* XAOMixImpl_DoRemoveItf |
|
427 * Dynamically remove an interface, object specific parts |
|
428 */ |
|
429 XAresult XAOMixImpl_DoRemoveItf(XAObjectItf self, XAObjItfMapEntry *mapEntry ) |
|
430 { |
|
431 XAresult ret = XA_RESULT_SUCCESS; |
|
432 DEBUG_API("->XAOMixImpl_DoRemoveItf"); |
|
433 |
|
434 if(mapEntry) |
|
435 { |
|
436 switch( mapEntry->mapIdx ) |
|
437 { |
|
438 case OMIX_EQUALIZERITF: |
|
439 XAEqualizerItfImpl_Free( mapEntry->pItf ); |
|
440 break; |
|
441 default: |
|
442 DEBUG_ERR("XAOMixImpl_DoRemoveItf unknown id"); |
|
443 ret = XA_RESULT_FEATURE_UNSUPPORTED; |
|
444 break; |
|
445 } |
|
446 mapEntry->pItf = NULL; |
|
447 } |
|
448 else |
|
449 { |
|
450 ret = XA_RESULT_PARAMETER_INVALID; |
|
451 } |
|
452 |
|
453 DEBUG_API("<-XAOMixImpl_DoRemoveItf"); |
|
454 return ret; |
|
455 } |
|
456 |
|
457 /*END OF FILE*/ |
|
458 |
|