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 #include "xacameradevice.h" |
|
22 #include "xacameraitf.h" |
|
23 #include "xaconfigextensionsitf.h" |
|
24 #include "xadynintmgmtitf.h" |
|
25 #include "xaimagecontrolsitf.h" |
|
26 #include "xaimageeffectsitf.h" |
|
27 #include "xavideopostprocessingitf.h" |
|
28 #include "xathreadsafety.h" |
|
29 #include "xaframeworkmgr.h" |
|
30 #include "xacameraadaptctx.h" |
|
31 #include "xacapabilitiesmgr.h" |
|
32 |
|
33 /* Static mapping of enumeration XACameraDeviceInterfaces to interface iids */ |
|
34 static const XAInterfaceID* XACameraDeviceItfIIDs[CAMERA_ITFCOUNT]= |
|
35 { |
|
36 &XA_IID_OBJECT, |
|
37 &XA_IID_CAMERA, |
|
38 &XA_IID_CONFIGEXTENSION, |
|
39 &XA_IID_DYNAMICINTERFACEMANAGEMENT, |
|
40 &XA_IID_IMAGECONTROLS, |
|
41 &XA_IID_IMAGEEFFECTS, |
|
42 &XA_IID_VIDEOPOSTPROCESSING |
|
43 }; |
|
44 |
|
45 |
|
46 /***************************************************************************** |
|
47 * Global methods |
|
48 *****************************************************************************/ |
|
49 |
|
50 /* XAResult XACameraDeviceImpl_Create |
|
51 * Description: Create object |
|
52 */ |
|
53 XAresult XACameraDeviceImpl_CreateCameraDevice(FrameworkMap* mapper, |
|
54 XACapabilities* capabilities, |
|
55 XAObjectItf* pDevice, |
|
56 XAuint32 deviceID, |
|
57 XAuint32 numInterfaces, |
|
58 const XAInterfaceID * pInterfaceIds, |
|
59 const XAboolean * pInterfaceRequired) |
|
60 { |
|
61 XACameraDeviceImpl* pImpl = NULL; |
|
62 XAObjectItfImpl* pBaseObj = NULL; |
|
63 XAuint8 itfIndex = 0; |
|
64 |
|
65 DEBUG_API("->XACameraDeviceImpl_Create"); |
|
66 XA_IMPL_THREAD_SAFETY_ENTRY(XATSCamera); |
|
67 |
|
68 if( !pDevice ) |
|
69 { |
|
70 XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera); |
|
71 /* invalid parameter */ |
|
72 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
73 DEBUG_API("<-XACameraDeviceImpl_Create"); |
|
74 return XA_RESULT_PARAMETER_INVALID; |
|
75 } |
|
76 |
|
77 /* instantiate object implementation */ |
|
78 pImpl = (XACameraDeviceImpl*)calloc(1,sizeof(XACameraDeviceImpl)); |
|
79 if( !pImpl ) |
|
80 { |
|
81 /* memory allocation failed */ |
|
82 XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera); |
|
83 DEBUG_ERR("XA_RESULT_MEMORY_FAILURE"); |
|
84 DEBUG_API("<-XACameraDeviceImpl_Create"); |
|
85 return XA_RESULT_MEMORY_FAILURE; |
|
86 } |
|
87 pBaseObj = &pImpl->baseObj; |
|
88 |
|
89 /* Initialize base object default implementation */ |
|
90 XAObjectItfImpl_Init(pBaseObj, |
|
91 CAMERA_ITFCOUNT, |
|
92 XACameraDeviceItfIIDs, |
|
93 XACameraDeviceImpl_DoRealize, |
|
94 XACameraDeviceImpl_DoResume, |
|
95 XACameraDeviceImpl_FreeResources); |
|
96 |
|
97 /* Mark interfaces that need to be exposed */ |
|
98 /* Implicit and mandated interfaces */ |
|
99 pBaseObj->interfaceMap[CAMERA_CAMERAITF].required = XA_BOOLEAN_TRUE; |
|
100 pBaseObj->interfaceMap[CAMERA_DIMITF].required = XA_BOOLEAN_TRUE; |
|
101 |
|
102 /* Explicit interfaces */ |
|
103 if( (numInterfaces != 0) && pInterfaceIds && pInterfaceRequired ) |
|
104 { |
|
105 /* Check required interfaces */ |
|
106 for( itfIndex = 0; itfIndex < numInterfaces; itfIndex++ ) |
|
107 { |
|
108 /* If mapEntry is null then required interface is not supported.*/ |
|
109 XAObjItfMapEntry *entry = |
|
110 XAObjectItfImpl_GetItfEntry((XAObjectItf)&(pBaseObj), pInterfaceIds[itfIndex]); |
|
111 if( !entry ) |
|
112 { |
|
113 if( pInterfaceRequired[itfIndex] ) |
|
114 { |
|
115 /* required interface cannot be accommodated - fail creation */ |
|
116 XAObjectItfImpl_Destroy((XAObjectItf)&(pBaseObj)); |
|
117 XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera); |
|
118 DEBUG_ERR("Required interface not found - abort creation!"); |
|
119 DEBUG_API("<-XACameraDeviceImpl_Create"); |
|
120 return XA_RESULT_FEATURE_UNSUPPORTED; |
|
121 } |
|
122 else |
|
123 { |
|
124 DEBUG_INFO("Requested (not required) interface not found - continue creation"); |
|
125 } |
|
126 } |
|
127 else |
|
128 { |
|
129 entry->required = XA_BOOLEAN_TRUE; |
|
130 } |
|
131 } |
|
132 } |
|
133 |
|
134 /* Mark interfaces that can be handled dynamically */ |
|
135 /* Mandated dynamic itfs */ |
|
136 pBaseObj->interfaceMap[CAMERA_IMAGEEFFECTSITF].isDynamic = XA_BOOLEAN_TRUE; |
|
137 |
|
138 /* This code is put here to return Feature Not Supported since adaptation is not present*/ |
|
139 /*************************************************/ |
|
140 XAObjectItfImpl_Destroy((XAObjectItf)&(pBaseObj)); |
|
141 XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera); |
|
142 DEBUG_ERR("Required interface not found - abort creation!"); |
|
143 DEBUG_API("<-XACameraDeviceImpl_Create"); |
|
144 return XA_RESULT_FEATURE_UNSUPPORTED; |
|
145 /*************************************************/ |
|
146 |
|
147 /* Initialize XACameraDeviceImpl variables |
|
148 pImpl->deviceID = deviceID; |
|
149 |
|
150 pImpl->adaptationCtx = XACameraAdapt_Create(pImpl->deviceID); |
|
151 |
|
152 Set ObjectItf to point to newly created object |
|
153 *pDevice = (XAObjectItf)&(pBaseObj->self); |
|
154 |
|
155 XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera); |
|
156 DEBUG_API("<-XACameraDeviceImpl_Create"); |
|
157 return XA_RESULT_SUCCESS;*/ |
|
158 } |
|
159 |
|
160 /* XAResult XACameraDeviceImpl_QueryNumSupportedInterfaces |
|
161 * Description: Statically query number of supported interfaces |
|
162 */ |
|
163 XAresult XACameraDeviceImpl_QueryNumSupportedInterfaces( XAuint32 *pNumSupportedInterfaces ) |
|
164 { |
|
165 DEBUG_API("->XACameraDeviceImpl_QueryNumSupportedInterfaces"); |
|
166 if( pNumSupportedInterfaces ) |
|
167 { |
|
168 *pNumSupportedInterfaces = CAMERA_ITFCOUNT; |
|
169 |
|
170 DEBUG_API_A1("<-XACameraDeviceImpl_QueryNumSupportedInterfaces - %i", (int)(*pNumSupportedInterfaces) ); |
|
171 return XA_RESULT_SUCCESS; |
|
172 } |
|
173 else |
|
174 { |
|
175 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
176 DEBUG_API("<-XACameraDeviceImpl_QueryNumSupportedInterfaces"); |
|
177 return XA_RESULT_PARAMETER_INVALID; |
|
178 } |
|
179 } |
|
180 /* XAResult XACameraDeviceImpl_QuerySupportedInterfaces |
|
181 * Description: Statically query supported interfaces |
|
182 */ |
|
183 XAresult XACameraDeviceImpl_QuerySupportedInterfaces( XAuint32 index, |
|
184 XAInterfaceID * pInterfaceId ) |
|
185 { |
|
186 DEBUG_API("->XACameraDeviceImpl_QuerySupportedInterfaces"); |
|
187 |
|
188 if( index >= CAMERA_ITFCOUNT || !pInterfaceId ) |
|
189 { |
|
190 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
191 DEBUG_API("<-XACameraDeviceImpl_QuerySupportedInterfaces"); |
|
192 return XA_RESULT_PARAMETER_INVALID; |
|
193 } |
|
194 else |
|
195 { |
|
196 *pInterfaceId = *(XACameraDeviceItfIIDs[index]); |
|
197 |
|
198 DEBUG_API("<-XACameraDeviceImpl_QuerySupportedInterfaces"); |
|
199 return XA_RESULT_SUCCESS; |
|
200 } |
|
201 } |
|
202 |
|
203 |
|
204 /***************************************************************************** |
|
205 * base object XAObjectItfImpl methods |
|
206 *****************************************************************************/ |
|
207 |
|
208 /* XAresult XACameraDeviceImpl_DoRealize( XAObjectItf self ) |
|
209 * Description: Realize all implicit and explicitly wanted interfaces. |
|
210 * Create and initialize implementation-specific variables. |
|
211 * Called from base object XAObjectItfImpl |
|
212 */ |
|
213 XAresult XACameraDeviceImpl_DoRealize( XAObjectItf self ) |
|
214 { |
|
215 XAuint8 itfIdx = 0; |
|
216 XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self); |
|
217 XACameraDeviceImpl* pObjImpl = (XACameraDeviceImpl*)(pObj); |
|
218 XAresult ret = XA_RESULT_SUCCESS; |
|
219 |
|
220 |
|
221 DEBUG_API("->XACameraDeviceImpl_DoRealize"); |
|
222 XA_IMPL_THREAD_SAFETY_ENTRY(XATSCamera); |
|
223 |
|
224 /* check casting from correct pointer type */ |
|
225 if( !pObjImpl || pObj != pObjImpl->baseObj.self ) |
|
226 { |
|
227 /* invalid parameter */ |
|
228 XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera); |
|
229 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
230 DEBUG_API("<-XACameraDeviceImpl_DoRealize"); |
|
231 return XA_RESULT_PARAMETER_INVALID; |
|
232 } |
|
233 |
|
234 |
|
235 ret = XACameraAdapt_PostInit( pObjImpl->adaptationCtx ); |
|
236 |
|
237 if( ret != XA_RESULT_SUCCESS ) |
|
238 { |
|
239 XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera); |
|
240 DEBUG_ERR_A1("Camera adapt postinit - %d", ret); |
|
241 DEBUG_API("<-XACameraDeviceImpl_DoRealize"); |
|
242 return ret; |
|
243 } |
|
244 |
|
245 /* Realize all implicit and explicitly wanted interfaces */ |
|
246 for( itfIdx = 0; itfIdx < CAMERA_ITFCOUNT; itfIdx++) |
|
247 { |
|
248 if( !(pObj->interfaceMap[itfIdx].pItf) && |
|
249 pObj->interfaceMap[itfIdx].required ) |
|
250 { |
|
251 void *pItf = NULL; |
|
252 switch( itfIdx ) |
|
253 { |
|
254 case CAMERA_DIMITF: |
|
255 pItf = XADIMItfImpl_Create(); |
|
256 if(pItf) |
|
257 { |
|
258 XADIMItfImpl_Init(pItf, self, |
|
259 XACameraDeviceImpl_DoAddItf, |
|
260 XACameraDeviceImpl_DoResumeItf, |
|
261 XACameraDeviceImpl_DoRemoveItf); |
|
262 } |
|
263 break; |
|
264 |
|
265 case CAMERA_CAMERAITF: |
|
266 pItf = XACameraItfImpl_Create( pObjImpl->adaptationCtx ); |
|
267 break; |
|
268 case CAMERA_CONFIGEXTENSIONITF: |
|
269 pItf = XAConfigExtensionsItfImpl_Create(); |
|
270 break; |
|
271 case CAMERA_IMAGECONTROLSITF: |
|
272 pItf = XAImageControlsItfImpl_Create( pObjImpl->adaptationCtx ); |
|
273 break; |
|
274 case CAMERA_IMAGEEFFECTSITF: |
|
275 pItf = XAImageEffectsItfImpl_Create( pObjImpl->adaptationCtx ); |
|
276 break; |
|
277 case CAMERA_VIDEOPOSTPROCESSINGITF: |
|
278 pItf = XAVideoPostProcessingItfImpl_Create( pObjImpl->adaptationCtx ); |
|
279 break; |
|
280 |
|
281 default: |
|
282 break; |
|
283 } |
|
284 if( !pItf ) |
|
285 { |
|
286 /* memory allocation failed */ |
|
287 XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera); |
|
288 DEBUG_ERR("XA_RESULT_MEMORY_FAILURE"); |
|
289 DEBUG_API("<-XACameraDeviceImpl_DoRealize"); |
|
290 return XA_RESULT_MEMORY_FAILURE; |
|
291 } |
|
292 else |
|
293 { |
|
294 pObj->interfaceMap[itfIdx].pItf = pItf; |
|
295 } |
|
296 } |
|
297 } |
|
298 |
|
299 pObj->state = XA_OBJECT_STATE_REALIZED; |
|
300 XA_IMPL_THREAD_SAFETY_EXIT(XATSCamera); |
|
301 DEBUG_API("<-XACameraDeviceImpl_DoRealize"); |
|
302 return XA_RESULT_SUCCESS; |
|
303 } |
|
304 |
|
305 /* XAresult XACameraDeviceImpl_DoResume |
|
306 * Description: Resume object from suspended state |
|
307 */ |
|
308 XAresult XACameraDeviceImpl_DoResume(XAObjectItf self) |
|
309 { |
|
310 DEBUG_API("->XACameraDeviceImpl_DoResume"); |
|
311 DEBUG_API("<-XACameraDeviceImpl_DoResume"); |
|
312 /* This implementation does not support suspended state */ |
|
313 return XA_RESULT_PRECONDITIONS_VIOLATED; |
|
314 } |
|
315 |
|
316 /* void XACameraDeviceImpl_FreeResources |
|
317 * Description: Free all resources reserved at XACameraDeviceImpl_DoRealize() |
|
318 */ |
|
319 void XACameraDeviceImpl_FreeResources(XAObjectItf self) |
|
320 { |
|
321 XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self); |
|
322 XAuint8 itfIdx = 0; |
|
323 XACameraDeviceImpl* pImpl = (XACameraDeviceImpl*)(*self); |
|
324 assert( pObj && pImpl && pObj == pObj->self ); |
|
325 DEBUG_API("->XACameraDeviceImpl_FreeResources"); |
|
326 XA_IMPL_THREAD_SAFETY_ENTRY_FOR_VOID_FUNCTIONS(XATSCamera); |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 /* free all allocated interfaces */ |
|
332 for(itfIdx = 0; itfIdx < CAMERA_ITFCOUNT; itfIdx++) |
|
333 { |
|
334 void *pItf = pObj->interfaceMap[itfIdx].pItf; |
|
335 if(pItf) |
|
336 { |
|
337 switch(itfIdx) |
|
338 { |
|
339 case CAMERA_CAMERAITF: |
|
340 XACameraItfImpl_Free( pItf ); |
|
341 break; |
|
342 case CAMERA_CONFIGEXTENSIONITF: |
|
343 XAConfigExtensionsItfImpl_Free( pItf ); |
|
344 break; |
|
345 case CAMERA_DIMITF: |
|
346 XADIMItfImpl_Free( pItf ); |
|
347 break; |
|
348 case CAMERA_IMAGECONTROLSITF: |
|
349 XAImageControlsItfImpl_Free( pItf ); |
|
350 break; |
|
351 case CAMERA_IMAGEEFFECTSITF: |
|
352 XAImageEffectsItfImpl_Free( pItf ); |
|
353 break; |
|
354 case CAMERA_VIDEOPOSTPROCESSINGITF: |
|
355 XAVideoPostProcessingItfImpl_Free( pItf ); |
|
356 break; |
|
357 default: |
|
358 break; |
|
359 } |
|
360 pObj->interfaceMap[itfIdx].pItf = NULL; |
|
361 } |
|
362 } |
|
363 |
|
364 if ( pImpl->adaptationCtx != NULL ) |
|
365 { |
|
366 XACameraAdapt_Destroy( pImpl->adaptationCtx ); |
|
367 pImpl->adaptationCtx = NULL; |
|
368 } |
|
369 |
|
370 XA_IMPL_THREAD_SAFETY_EXIT_FOR_VOID_FUNCTIONS(XATSCamera); |
|
371 DEBUG_API("<-XACameraDeviceImpl_FreeResources"); |
|
372 return; |
|
373 } |
|
374 |
|
375 /***************************************************************************** |
|
376 * CameraDeviceImpl -specific methods |
|
377 *****************************************************************************/ |
|
378 |
|
379 /* XACameraDeviceImpl_DoAddItf |
|
380 * Dynamically add an interface, object specific parts |
|
381 */ |
|
382 XAresult XACameraDeviceImpl_DoAddItf(XAObjectItf self, XAObjItfMapEntry *mapEntry ) |
|
383 { |
|
384 |
|
385 XAObjectItfImpl* pObj = (XAObjectItfImpl*)(*self); |
|
386 XACameraDeviceImpl* pImpl = (XACameraDeviceImpl*)(pObj); |
|
387 |
|
388 XAresult ret = XA_RESULT_SUCCESS; |
|
389 DEBUG_API("->XACameraDeviceImpl_DoAddItf"); |
|
390 if(mapEntry) |
|
391 { |
|
392 switch( mapEntry->mapIdx ) |
|
393 { |
|
394 case CAMERA_IMAGEEFFECTSITF: |
|
395 mapEntry->pItf = XAImageEffectsItfImpl_Create( pImpl->adaptationCtx ); |
|
396 break; |
|
397 default: |
|
398 DEBUG_ERR("XACameraDeviceImpl_DoAddItf unknown id"); |
|
399 ret = XA_RESULT_FEATURE_UNSUPPORTED; |
|
400 break; |
|
401 } |
|
402 |
|
403 if( !mapEntry->pItf && ret == XA_RESULT_SUCCESS) |
|
404 { |
|
405 DEBUG_ERR("XACameraDeviceImpl_DoAddItf itf creation failed"); |
|
406 ret = XA_RESULT_MEMORY_FAILURE; |
|
407 } |
|
408 } |
|
409 else |
|
410 { |
|
411 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
412 ret = XA_RESULT_PARAMETER_INVALID; |
|
413 } |
|
414 |
|
415 DEBUG_API("<-XACameraDeviceImpl_DoAddItf"); |
|
416 return ret; |
|
417 } |
|
418 |
|
419 /* XACameraDeviceImpl_DoResumeItf |
|
420 * Try to resume lost interface, object specific parts |
|
421 */ |
|
422 XAresult XACameraDeviceImpl_DoResumeItf(XAObjectItf self, XAObjItfMapEntry *mapEntry ) |
|
423 { |
|
424 XAresult ret = XA_RESULT_SUCCESS; |
|
425 DEBUG_API("->XACameraDeviceImpl_DoResumeItf"); |
|
426 /* For now, no difference between suspended and unrealised itfs */ |
|
427 ret = XACameraDeviceImpl_DoAddItf(self,mapEntry); |
|
428 DEBUG_API("<-XACameraDeviceImpl_DoResumeItf"); |
|
429 return ret; |
|
430 } |
|
431 |
|
432 /* XACameraDeviceImpl_DoRemoveItf |
|
433 * Dynamically remove an interface, object specific parts |
|
434 */ |
|
435 XAresult XACameraDeviceImpl_DoRemoveItf(XAObjectItf self, XAObjItfMapEntry *mapEntry ) |
|
436 { |
|
437 XAresult ret = XA_RESULT_SUCCESS; |
|
438 DEBUG_API("->XACameraDeviceImpl_DoRemoveItf"); |
|
439 if(mapEntry) |
|
440 { |
|
441 switch( mapEntry->mapIdx ) |
|
442 { |
|
443 case CAMERA_IMAGEEFFECTSITF: |
|
444 XAImageEffectsItfImpl_Free( mapEntry->pItf ); |
|
445 break; |
|
446 default: |
|
447 DEBUG_ERR("XACameraDeviceImpl_DoRemoveItf unknown id"); |
|
448 ret = XA_RESULT_FEATURE_UNSUPPORTED; |
|
449 break; |
|
450 } |
|
451 mapEntry->pItf = NULL; |
|
452 } |
|
453 else |
|
454 { |
|
455 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
456 ret = XA_RESULT_PARAMETER_INVALID; |
|
457 } |
|
458 |
|
459 DEBUG_API("<-XACameraDeviceImpl_DoRemoveItf"); |
|
460 return ret; |
|
461 } |
|
462 /* END OF FILE */ |
|