|
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 "xaengine.h" |
|
23 #include "xaobjectitf.h" |
|
24 #include "xaengineitf.h" |
|
25 #include "xathreadsyncitf.h" |
|
26 #include "xadynintmgmtitf.h" |
|
27 #include "xaaudioiodevicecapabilitiesitf.h" |
|
28 #include "xaaudiodecodercapabilitiesitf.h" |
|
29 #include "xaaudioencodercapabilitiesitf.h" |
|
30 #include "xaimagedecodercapabilitiesitf.h" |
|
31 #include "xaimageencodercapabilitiesitf.h" |
|
32 #include "xavideodecodercapabilitiesitf.h" |
|
33 #include "xavideoencodercapabilitiesitf.h" |
|
34 #include "xacameracapabilitiesitf.h" |
|
35 #include "xadevicevolumeitf.h" |
|
36 #include "xaconfigextensionsitf.h" |
|
37 #include "xathreadsafety.h" |
|
38 #ifdef _GSTREAMER_BACKEND_ |
|
39 #include "XAStaticCameraCapsAdaptation.h" |
|
40 #endif |
|
41 /* Static mapping of enumeration XAEngineInterfaces to interface iids */ |
|
42 static const XAInterfaceID* xaEngineItfIIDs[ENGINE_ITFCOUNT]={ |
|
43 &XA_IID_OBJECT, |
|
44 &XA_IID_ENGINE, |
|
45 &XA_IID_DYNAMICINTERFACEMANAGEMENT, |
|
46 &XA_IID_THREADSYNC, |
|
47 &XA_IID_CONFIGEXTENSION, |
|
48 &XA_IID_DEVICEVOLUME, |
|
49 &XA_IID_AUDIOIODEVICECAPABILITIES, |
|
50 &XA_IID_AUDIODECODERCAPABILITIES, |
|
51 &XA_IID_AUDIOENCODERCAPABILITIES, |
|
52 &XA_IID_CAMERACAPABILITIES, |
|
53 &XA_IID_IMAGEDECODERCAPABILITIES, |
|
54 &XA_IID_IMAGEENCODERCAPABILITIES, |
|
55 &XA_IID_VIDEODECODERCAPABILITIES, |
|
56 &XA_IID_VIDEOENCODERCAPABILITIES |
|
57 }; |
|
58 |
|
59 /***************************************************************************** |
|
60 * Global methods |
|
61 *****************************************************************************/ |
|
62 |
|
63 /* XAResult XAEngineImpl_Create |
|
64 * Description: Create object |
|
65 */ |
|
66 XAresult XAEngineImpl_Create(XAObjectItf *pEngine, |
|
67 XAuint32 numOptions, |
|
68 const XAEngineOption *pEngineOptions, |
|
69 XAuint32 numInterfaces, |
|
70 const XAInterfaceID *pInterfaceIds, |
|
71 const XAboolean *pInterfaceRequired) |
|
72 { |
|
73 XAEngineImpl* pImpl = NULL; |
|
74 XAObjectItfImpl* pBaseObj = NULL; |
|
75 XAuint32 itfIndex = 0; |
|
76 //XAboolean optEnabled = XA_BOOLEAN_FALSE; |
|
77 XAboolean threadSafeEnabled = XA_BOOLEAN_TRUE; |
|
78 DEBUG_API("->XAEngineImpl_Create"); |
|
79 |
|
80 if( !pEngine ) |
|
81 { |
|
82 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
83 DEBUG_API("<-XAEngineImpl_Create"); |
|
84 /* invalid parameter */ |
|
85 return XA_RESULT_PARAMETER_INVALID; |
|
86 } |
|
87 |
|
88 /* check engine options */ |
|
89 if( pEngineOptions && (numOptions != 0)) |
|
90 { |
|
91 int i; |
|
92 for(i = 0; i<numOptions; i++) |
|
93 { |
|
94 if (pEngineOptions[i].feature==XA_ENGINEOPTION_LOSSOFCONTROL) |
|
95 { |
|
96 //XAboolean optEnabled = pEngineOptions[i].data; |
|
97 // TODO: do something with the above value or else remove the code |
|
98 } |
|
99 if (pEngineOptions[i].feature==XA_ENGINEOPTION_THREADSAFE) |
|
100 { |
|
101 threadSafeEnabled = pEngineOptions[i].data; |
|
102 } |
|
103 } |
|
104 } |
|
105 |
|
106 /* instantiate object implementation */ |
|
107 pImpl = (XAEngineImpl*)calloc(1,sizeof(XAEngineImpl)); |
|
108 if( !pImpl ) |
|
109 { |
|
110 DEBUG_ERR("XA_RESULT_MEMORY_FAILURE"); |
|
111 DEBUG_API("<-XAEngineImpl_Create"); |
|
112 /* memory allocation failed */ |
|
113 return XA_RESULT_MEMORY_FAILURE; |
|
114 } |
|
115 pBaseObj = &pImpl->baseObj; |
|
116 |
|
117 /* Initialize base object default implementation */ |
|
118 XAObjectItfImpl_Init(pBaseObj, |
|
119 ENGINE_ITFCOUNT, |
|
120 xaEngineItfIIDs, |
|
121 XAEngineImpl_DoRealize, |
|
122 XAEngineImpl_DoResume, |
|
123 XAEngineImpl_FreeResources); |
|
124 |
|
125 |
|
126 /* Mark interfaces that need to be exposed */ |
|
127 /* Implicit and mandated interfaces */ |
|
128 pBaseObj->interfaceMap[ENGINE_ENGINEITF].required = XA_BOOLEAN_TRUE; |
|
129 pBaseObj->interfaceMap[ENGINE_DIMITF].required = XA_BOOLEAN_TRUE; |
|
130 pBaseObj->interfaceMap[ENGINE_THREADSYNCITF].required = XA_BOOLEAN_TRUE; |
|
131 pBaseObj->interfaceMap[ENGINE_AUDIOIODEVICECAPAITF].required = XA_BOOLEAN_TRUE; |
|
132 pBaseObj->interfaceMap[ENGINE_AUDIOENCODERCAPAITF].required = XA_BOOLEAN_TRUE; |
|
133 /* Explicit interfaces */ |
|
134 if( (numInterfaces != 0) && pInterfaceIds && pInterfaceRequired ) |
|
135 { |
|
136 /* Check required interfaces */ |
|
137 for(itfIndex = 0; itfIndex < numInterfaces; itfIndex++) |
|
138 { |
|
139 /* If mapEntry is null then required interface is not supported.*/ |
|
140 XAObjItfMapEntry *entry = |
|
141 XAObjectItfImpl_GetItfEntry((XAObjectItf)&(pBaseObj), pInterfaceIds[itfIndex]); |
|
142 if( !entry ) |
|
143 { |
|
144 if( pInterfaceRequired[itfIndex] ) |
|
145 { |
|
146 /* required interface cannot be accommodated - fail creation */ |
|
147 XAObjectItfImpl_Destroy((XAObjectItf)&(pBaseObj)); |
|
148 DEBUG_ERR("Required interface not found - abort creation!"); |
|
149 DEBUG_API("<-XAEngineImpl_Create"); |
|
150 return XA_RESULT_FEATURE_UNSUPPORTED; |
|
151 } |
|
152 else |
|
153 { |
|
154 DEBUG_INFO("Requested (not required) interface not found - continue creation"); |
|
155 } |
|
156 } |
|
157 else |
|
158 { |
|
159 entry->required = XA_BOOLEAN_TRUE; |
|
160 } |
|
161 } |
|
162 } |
|
163 |
|
164 /* Initialize XAEngineImpl variables */ |
|
165 if( threadSafeEnabled ) |
|
166 { |
|
167 XAresult ret = XA_RESULT_SUCCESS; |
|
168 pImpl->isThreadSafe = threadSafeEnabled; |
|
169 ret = XAThreadSafety_Init( threadSafeEnabled ); |
|
170 if ( ret != XA_RESULT_SUCCESS ) |
|
171 { |
|
172 DEBUG_INFO_A1("Unable to initialize thread safety - ret:%x", ret ); |
|
173 } |
|
174 } |
|
175 |
|
176 #ifdef _GSTREAMER_BACKEND_ |
|
177 pImpl->adaptationCtx = XAEngineAdapt_Create(); |
|
178 #endif |
|
179 /* Set ObjectItf to point to newly created object */ |
|
180 *pEngine = ((XAObjectItf)&(pBaseObj->self)); |
|
181 |
|
182 DEBUG_API("<-XAEngineImpl_Create"); |
|
183 return XA_RESULT_SUCCESS; |
|
184 } |
|
185 |
|
186 /* XAResult XAEngineImpl_QueryNumSupportedInterfaces |
|
187 * Description: Statically query number of supported interfaces |
|
188 */ |
|
189 XAresult XAEngineImpl_QueryNumSupportedInterfaces( |
|
190 XAuint32 *pNumSupportedInterfaces) |
|
191 { |
|
192 DEBUG_API("->XAEngineImpl_QueryNumSupportedInterfaces"); |
|
193 if(pNumSupportedInterfaces) |
|
194 { |
|
195 *pNumSupportedInterfaces = ENGINE_ITFCOUNT; |
|
196 DEBUG_API("<-XAEngineImpl_QueryNumSupportedInterfaces"); |
|
197 return XA_RESULT_SUCCESS; |
|
198 } |
|
199 else |
|
200 { |
|
201 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
202 DEBUG_API("<-XAEngineImpl_QueryNumSupportedInterfaces"); |
|
203 return XA_RESULT_PARAMETER_INVALID; |
|
204 } |
|
205 } |
|
206 |
|
207 /* XAResult XAEngineImpl_QuerySupportedInterfaces |
|
208 * Description: Statically query supported interfaces |
|
209 */ |
|
210 XAresult XAEngineImpl_QuerySupportedInterfaces( |
|
211 XAuint32 index, |
|
212 XAInterfaceID *pInterfaceId) |
|
213 { |
|
214 DEBUG_API("->XAEngineImpl_QuerySupportedInterfaces"); |
|
215 if (index >= ENGINE_ITFCOUNT || !pInterfaceId ) |
|
216 { |
|
217 if(pInterfaceId) |
|
218 { |
|
219 *pInterfaceId = XA_IID_NULL; |
|
220 } |
|
221 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
222 DEBUG_API("<-XAEngineImpl_QuerySupportedInterfaces"); |
|
223 return XA_RESULT_PARAMETER_INVALID; |
|
224 } |
|
225 else |
|
226 { |
|
227 *pInterfaceId = *(xaEngineItfIIDs[index]); |
|
228 DEBUG_API("<-XAEngineImpl_QuerySupportedInterfaces"); |
|
229 return XA_RESULT_SUCCESS; |
|
230 } |
|
231 } |
|
232 |
|
233 /***************************************************************************** |
|
234 * base object XAObjectItfImpl methods |
|
235 *****************************************************************************/ |
|
236 |
|
237 /* XAresult XAEngineImpl_DoRealize |
|
238 * Description: Realize all implicit and explicitly wanted interfaces. |
|
239 * Create and initialize implementation-specific variables. |
|
240 * Called from base object XAObjectItfImpl |
|
241 */ |
|
242 XAresult XAEngineImpl_DoRealize(XAObjectItf self) |
|
243 { |
|
244 XAuint8 itfIdx = 0; |
|
245 XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self); |
|
246 XAEngineImpl* pObjImpl = (XAEngineImpl*)(pObj); |
|
247 XAresult ret = XA_RESULT_SUCCESS; |
|
248 |
|
249 DEBUG_API("->XAEngineImpl_DoRealize"); |
|
250 |
|
251 /* check casting from correct pointer type */ |
|
252 if( !pObjImpl || pObj != pObjImpl->baseObj.self ) |
|
253 { |
|
254 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
255 DEBUG_API("<-XAEngineImpl_DoRealize"); |
|
256 /* invalid parameter */ |
|
257 return XA_RESULT_PARAMETER_INVALID; |
|
258 } |
|
259 |
|
260 #ifdef _GSTREAMER_BACKEND_ |
|
261 ret = XAEngineAdapt_PostInit( pObjImpl->adaptationCtx ); |
|
262 #endif |
|
263 if( ret != XA_RESULT_SUCCESS ) |
|
264 { |
|
265 DEBUG_ERR_A1("Engine postinit failed - %d", ret); |
|
266 DEBUG_API("<-XAEngineImpl_DoRealize"); |
|
267 return ret; |
|
268 } |
|
269 |
|
270 ret = XAEngineAdaptMMF_PostInit( pObjImpl->adaptationMmfCtx ); |
|
271 if( ret != XA_RESULT_SUCCESS ) |
|
272 { |
|
273 DEBUG_ERR_A1("Engine postinit failed (MMF) - %d", ret); |
|
274 DEBUG_API("<-XAEngineImpl_DoRealize"); |
|
275 return ret; |
|
276 } |
|
277 /* Realize all implicit and explicitly wanted interfaces */ |
|
278 for(itfIdx=0; itfIdx<ENGINE_ITFCOUNT; itfIdx++) |
|
279 { |
|
280 if(!(pObj->interfaceMap[itfIdx].pItf) && |
|
281 pObj->interfaceMap[itfIdx].required ) |
|
282 { |
|
283 void *pItf = NULL; |
|
284 switch(itfIdx) |
|
285 { |
|
286 case ENGINE_ENGINEITF: |
|
287 pItf = XAEngineItfImpl_Create(); |
|
288 break; |
|
289 case ENGINE_THREADSYNCITF: |
|
290 pItf = XAThreadSyncItfImpl_Create(); |
|
291 break; |
|
292 case ENGINE_DIMITF: |
|
293 pItf = XADIMItfImpl_Create(); |
|
294 break; |
|
295 case ENGINE_AUDIOIODEVICECAPAITF: |
|
296 pItf = XAAudIODevCapaItfImpl_Create(); |
|
297 break; |
|
298 case ENGINE_AUDIOENCODERCAPAITF: |
|
299 pItf = XAAudioEncoderCapabilitiesItfImpl_Create(); |
|
300 break; |
|
301 case ENGINE_AUDIODECODERCAPAITF: |
|
302 pItf = XAAudioDecoderCapabilitiesItfImpl_Create(); |
|
303 break; |
|
304 case ENGINE_CONFIGEXTENSIONSITF: |
|
305 pItf = XAConfigExtensionsItfImpl_Create(); |
|
306 break; |
|
307 case ENGINE_DEVICEVOLUMEITF: |
|
308 #ifdef _GSTREAMER_BACKEND_ |
|
309 pItf = XADeviceVolumeItfImpl_Create(pObjImpl->adaptationCtx); |
|
310 #endif |
|
311 break; |
|
312 case ENGINE_CAMERACAPAITF: |
|
313 #ifdef _GSTREAMER_BACKEND_ |
|
314 XAStaticCameraCaps_Init(); |
|
315 pItf = XACameraCapabilitiesItfImpl_Create(); |
|
316 #endif |
|
317 break; |
|
318 case ENGINE_IMAGEDECODERCAPAITF: |
|
319 pItf = XAImageDecoderCapabilitiesItfImpl_Create(); |
|
320 break; |
|
321 case ENGINE_IMAGEENCODERCAPAITF: |
|
322 pItf = XAImageEncoderCapabilitiesItfImpl_Create(); |
|
323 break; |
|
324 case ENGINE_VIDEODECODERCAPAITF: |
|
325 pItf = XAVideoDecoderCapabilitiesItfImpl_Create(); |
|
326 break; |
|
327 case ENGINE_VIDEOENCODERCAPAITF: |
|
328 pItf = XAVideoEncoderCapabilitiesItfImpl_Create(); |
|
329 break; |
|
330 default: |
|
331 break; |
|
332 } |
|
333 if(!pItf) |
|
334 { |
|
335 DEBUG_ERR("XA_RESULT_MEMORY_FAILURE"); |
|
336 DEBUG_API("<-XAEngineImpl_DoRealize"); |
|
337 /* memory allocation failed */ |
|
338 return XA_RESULT_MEMORY_FAILURE; |
|
339 } |
|
340 else |
|
341 { |
|
342 pObj->interfaceMap[itfIdx].pItf = pItf; |
|
343 } |
|
344 } |
|
345 } |
|
346 |
|
347 pObj->state = XA_OBJECT_STATE_REALIZED; |
|
348 DEBUG_API("<-XAEngineImpl_DoRealize"); |
|
349 return XA_RESULT_SUCCESS; |
|
350 } |
|
351 |
|
352 /* XAresult XAEngineImpl_DoResume |
|
353 * Description: Resume object from suspended state |
|
354 */ |
|
355 XAresult XAEngineImpl_DoResume(XAObjectItf self) |
|
356 { |
|
357 DEBUG_API("->XAEngineImpl_DoResume"); |
|
358 DEBUG_API("<-XAEngineImpl_DoResume"); |
|
359 |
|
360 return XA_RESULT_PRECONDITIONS_VIOLATED; |
|
361 } |
|
362 |
|
363 /* void XAEngineImpl_FreeResources |
|
364 * Description: Free all resources reserved at XA%ExampleObject%Impl_DoRealize() |
|
365 */ |
|
366 void XAEngineImpl_FreeResources(XAObjectItf self) |
|
367 { |
|
368 XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self); |
|
369 XAEngineImpl* pImpl = (XAEngineImpl*)(*self); |
|
370 XAuint8 itfIdx = 0; |
|
371 DEBUG_API("->XAEngineImpl_FreeResources"); |
|
372 assert( pObj && pImpl && pObj == pObj->self ); |
|
373 |
|
374 /* free all allocated interfaces */ |
|
375 for(itfIdx=0; itfIdx<ENGINE_ITFCOUNT; itfIdx++) |
|
376 { |
|
377 void *pItf = pObj->interfaceMap[itfIdx].pItf; |
|
378 if(pItf) |
|
379 { |
|
380 switch(itfIdx) |
|
381 { |
|
382 case ENGINE_ENGINEITF: |
|
383 XAEngineItfImpl_Free(pItf); |
|
384 break; |
|
385 case ENGINE_THREADSYNCITF: |
|
386 XAThreadSyncItfImpl_Free(pItf); |
|
387 break; |
|
388 case ENGINE_DIMITF: |
|
389 XADIMItfImpl_Free(pItf); |
|
390 break; |
|
391 case ENGINE_AUDIOIODEVICECAPAITF: |
|
392 XAAudIODevCapaItfImpl_Free(pItf); |
|
393 break; |
|
394 case ENGINE_AUDIOENCODERCAPAITF: |
|
395 XAAudioEncoderCapabilitiesItfImpl_Free(pItf); |
|
396 break; |
|
397 case ENGINE_AUDIODECODERCAPAITF: |
|
398 XAAudioDecoderCapabilitiesItfImpl_Free(pItf); |
|
399 break; |
|
400 case ENGINE_CONFIGEXTENSIONSITF: |
|
401 XAConfigExtensionsItfImpl_Free(pItf); |
|
402 break; |
|
403 case ENGINE_DEVICEVOLUMEITF: |
|
404 XADeviceVolumeItfImpl_Free(pItf); |
|
405 break; |
|
406 case ENGINE_CAMERACAPAITF: |
|
407 #ifdef _GSTREAMER_BACKEND_ |
|
408 XACameraCapabilitiesItfImpl_Free(pItf); |
|
409 #endif |
|
410 break; |
|
411 case ENGINE_IMAGEDECODERCAPAITF: |
|
412 XAImageDecoderCapabilitiesItfImpl_Free(pItf); |
|
413 break; |
|
414 case ENGINE_IMAGEENCODERCAPAITF: |
|
415 XAImageEncoderCapabilitiesItfImpl_Free(pItf); |
|
416 break; |
|
417 case ENGINE_VIDEODECODERCAPAITF: |
|
418 XAVideoDecoderCapabilitiesItfImpl_Free(pItf); |
|
419 break; |
|
420 case ENGINE_VIDEOENCODERCAPAITF: |
|
421 XAVideoEncoderCapabilitiesItfImpl_Free(pItf); |
|
422 break; |
|
423 default: |
|
424 break; |
|
425 } |
|
426 pObj->interfaceMap[itfIdx].pItf = NULL; |
|
427 } |
|
428 } |
|
429 |
|
430 /* free all other allocated resources*/ |
|
431 #ifdef _GSTREAMER_BACKEND_ |
|
432 if ( pImpl->adaptationCtx != NULL ) |
|
433 { |
|
434 XAEngineAdapt_Destroy( pImpl->adaptationCtx ); |
|
435 pImpl->adaptationCtx = NULL; |
|
436 } |
|
437 #endif |
|
438 if ( pImpl->adaptationMmfCtx != NULL ) |
|
439 { |
|
440 XAEngineAdaptMMF_Destroy( pImpl->adaptationMmfCtx ); |
|
441 pImpl->adaptationMmfCtx = NULL; |
|
442 } |
|
443 |
|
444 XAThreadSafety_Destroy(); |
|
445 |
|
446 DEBUG_API("<-XAEngineImpl_FreeResources"); |
|
447 return; |
|
448 } |
|
449 |
|
450 /* END OF FILE */ |