|
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 "xacapabilitiesmgr.h" |
|
19 #include "xammfcapabilitiesmgr.h" |
|
20 #include "xagstcapabilitiesmgr.h" |
|
21 #include <stdio.h> |
|
22 #include <string.h> |
|
23 |
|
24 static XAresult XACapabilitiesMgr_GetAudioInputDeviceCapabilities(XACapabilities **ppNode); |
|
25 static XAresult XACapabilitiesMgr_GetAudioOutputDeviceCapabilities(XACapabilities **ppNode); |
|
26 |
|
27 /* XAresult XAGSTCapabilitiesMgr_UpdateAudioIOCapabilitieList |
|
28 * Description: Update the capabilities list supported by GStreamer framework. |
|
29 */ |
|
30 XAresult XACapabilitiesMgr_UpdateAudioIOCapabilitieList( |
|
31 FrameworkMap *frameworkMap, |
|
32 XACapabilities **ppListHead) |
|
33 |
|
34 { |
|
35 XAresult res = XA_RESULT_SUCCESS; |
|
36 XACapabilities *lastNode; |
|
37 XACapabilities *firstNode ; |
|
38 XACapabilities *newNode = NULL; |
|
39 |
|
40 if(!frameworkMap || !ppListHead) |
|
41 { |
|
42 res = XA_RESULT_PARAMETER_INVALID; |
|
43 return res; |
|
44 } |
|
45 |
|
46 lastNode = *ppListHead; |
|
47 firstNode = *ppListHead; |
|
48 |
|
49 |
|
50 DEBUG_API("->XACapabilitiesMgr_UpdateAudioIOCapabilitieList"); |
|
51 |
|
52 |
|
53 |
|
54 /* traverse and point to the last node in the list */ |
|
55 while(lastNode && lastNode->next) |
|
56 { |
|
57 lastNode = lastNode->next; |
|
58 } |
|
59 |
|
60 /* If no input devices are supported, the function returns |
|
61 * XA_RESULT_SUCCESS and newNode will be NULL*/ |
|
62 newNode = NULL; |
|
63 res = XACapabilitiesMgr_GetAudioInputDeviceCapabilities(&newNode); |
|
64 if (res != XA_RESULT_SUCCESS) |
|
65 { |
|
66 return res; |
|
67 } |
|
68 |
|
69 if (lastNode) |
|
70 { |
|
71 lastNode->next = newNode; |
|
72 } |
|
73 if (newNode) |
|
74 { /* if a new node is created move lastNode to the new item */ |
|
75 if (!firstNode) |
|
76 firstNode = newNode; |
|
77 lastNode = newNode; |
|
78 } |
|
79 |
|
80 /* If no input devices are supported, the function returns |
|
81 * XA_RESULT_SUCCESS and newNode will be NULL*/ |
|
82 newNode = NULL; |
|
83 res = XACapabilitiesMgr_GetAudioOutputDeviceCapabilities(&newNode); |
|
84 if (res != XA_RESULT_SUCCESS) |
|
85 { |
|
86 return res; |
|
87 } |
|
88 |
|
89 if (lastNode) |
|
90 { |
|
91 lastNode->next = newNode; |
|
92 } |
|
93 if (newNode) |
|
94 { /* if a new node is created move lastNode to the new item */ |
|
95 if (!firstNode) |
|
96 firstNode = newNode; |
|
97 lastNode = newNode; |
|
98 } |
|
99 /* if empty list, then append first node as the head */ |
|
100 if (!(*ppListHead)) |
|
101 { |
|
102 *ppListHead = firstNode; |
|
103 } |
|
104 DEBUG_API("<-XACapabilitiesMgr_UpdateAudioIOCapabilitieList"); |
|
105 return res; |
|
106 } |
|
107 |
|
108 XAresult XACapabilitiesMgr_CreateCapabilitieList( |
|
109 FrameworkMap* frameworkMap, |
|
110 XACapabilities** ppListHead) |
|
111 { |
|
112 XACapabilities* list = NULL; |
|
113 XAresult res = XA_RESULT_SUCCESS; |
|
114 if(!ppListHead) |
|
115 { |
|
116 res = XA_RESULT_PARAMETER_INVALID; |
|
117 return res; |
|
118 } |
|
119 |
|
120 *ppListHead = NULL; |
|
121 |
|
122 res = XACapabilitiesMgr_UpdateAudioIOCapabilitieList(frameworkMap, &list); |
|
123 if (res != XA_RESULT_SUCCESS) |
|
124 { |
|
125 XACapabilitiesMgr_DeleteCapabilitieList(&list); |
|
126 return res; |
|
127 } |
|
128 |
|
129 res = XAGSTCapabilitiesMgr_UpdateCapabilitieList(frameworkMap, &list); |
|
130 if (res != XA_RESULT_SUCCESS) |
|
131 { |
|
132 XACapabilitiesMgr_DeleteCapabilitieList(&list); |
|
133 return res; |
|
134 } |
|
135 |
|
136 res = XAMMFCapabilitiesMgr_UpdateCapabilitieList(frameworkMap, &list); |
|
137 if (res != XA_RESULT_SUCCESS) |
|
138 { |
|
139 XACapabilitiesMgr_DeleteCapabilitieList(&list); |
|
140 return res; |
|
141 } |
|
142 |
|
143 *ppListHead = list; |
|
144 return res; |
|
145 } |
|
146 |
|
147 XAresult XACapabilitiesMgr_DeleteCapabilitieList(XACapabilities** ppListHead) |
|
148 { |
|
149 XACapabilities* currNode = NULL; |
|
150 XACapabilities* nextNode = NULL; |
|
151 XAresult res = XA_RESULT_SUCCESS; |
|
152 |
|
153 if(!ppListHead) |
|
154 { |
|
155 res = XA_RESULT_PARAMETER_INVALID; |
|
156 return res; |
|
157 } |
|
158 |
|
159 currNode = *ppListHead; |
|
160 while (currNode) |
|
161 { |
|
162 if (currNode->capsType == AUD_I) |
|
163 { |
|
164 XAAudioInputDescriptor* entries = (XAAudioInputDescriptor*)currNode->pEntry; |
|
165 XAint32 i; |
|
166 for(i=0;i< currNode->noOfEntries;i++) |
|
167 { |
|
168 free(entries[i].samplingRatesSupported); |
|
169 free(entries[i].deviceName); |
|
170 } |
|
171 free(entries); |
|
172 } |
|
173 else if (currNode->capsType == AUD_O) |
|
174 { |
|
175 XAAudioOutputDescriptor* entries = (XAAudioOutputDescriptor*)currNode->pEntry; |
|
176 XAint32 i; |
|
177 for(i=0;i< currNode->noOfEntries;i++) |
|
178 { |
|
179 free(entries[i].samplingRatesSupported); |
|
180 free(entries[i].pDeviceName); |
|
181 } |
|
182 free(entries); |
|
183 } |
|
184 else if (currNode->capsType == AUD_E) |
|
185 { |
|
186 XAAudioCodecDescriptor* entries = (XAAudioCodecDescriptor*)currNode->pEntry; |
|
187 XAint32 i; |
|
188 for(i=0;i< currNode->noOfEntries;i++) |
|
189 { |
|
190 free(entries[i].pSampleRatesSupported); |
|
191 free(entries[i].pBitratesSupported); |
|
192 } |
|
193 free(entries); |
|
194 |
|
195 } |
|
196 |
|
197 if(currNode->adaptId) |
|
198 { |
|
199 free(currNode->adaptId); |
|
200 } |
|
201 |
|
202 nextNode = currNode->next; |
|
203 free(currNode); |
|
204 currNode = nextNode; |
|
205 } |
|
206 |
|
207 *ppListHead = NULL; |
|
208 return res; |
|
209 } |
|
210 |
|
211 |
|
212 /* XAresult XACapabilitiesMgr_GetCapsCount |
|
213 * Description: Count capabilities of certain type. Filter is specified by |
|
214 * bitmasking XACapsType values. |
|
215 */ |
|
216 XAresult XACapabilitiesMgr_GetCapsCount(XACapabilities* pListHead, XACapsType filter, XAuint32* count) |
|
217 { |
|
218 XAresult res = XA_RESULT_SUCCESS; |
|
219 XACapabilities* currNode = pListHead; |
|
220 |
|
221 DEBUG_API("->XACapabilitiesMgr_GetCapsCount"); |
|
222 if(!currNode || !count) |
|
223 { |
|
224 res = XA_RESULT_PARAMETER_INVALID; |
|
225 return res; |
|
226 } |
|
227 |
|
228 (*count)=0; |
|
229 while (currNode) |
|
230 { |
|
231 if ( (currNode->capsType & filter) == filter ) |
|
232 { |
|
233 (*count)++; |
|
234 } |
|
235 currNode = currNode->next; |
|
236 } |
|
237 |
|
238 DEBUG_API("<-XACapabilitiesMgr_GetCapsCount"); |
|
239 return res; |
|
240 } |
|
241 |
|
242 /* XAresult XACapabilitiesMgr_GetCapsById |
|
243 * Description: Get capabilities of type XACapsType and matching id |
|
244 */ |
|
245 XAresult XACapabilitiesMgr_GetCapsById(XACapabilities* pListHead, XACapsType filter, XAuint32 maxId, XACapabilities* data) |
|
246 { |
|
247 XAresult res = XA_RESULT_SUCCESS; |
|
248 XACapabilities* currNode = pListHead; |
|
249 XAboolean found = XA_BOOLEAN_FALSE; |
|
250 |
|
251 DEBUG_API("->XACapabilitiesMgr_GetCapsById"); |
|
252 |
|
253 if(!currNode) |
|
254 { |
|
255 res = XA_RESULT_PARAMETER_INVALID; |
|
256 return res; |
|
257 } |
|
258 |
|
259 while (currNode) |
|
260 { |
|
261 if (((currNode->capsType & filter) == filter ) && (maxId==currNode->xaid)) |
|
262 { |
|
263 memcpy(data, currNode, sizeof(XACapabilities)); |
|
264 found = XA_BOOLEAN_TRUE; |
|
265 break; |
|
266 } |
|
267 currNode = currNode->next; |
|
268 } |
|
269 |
|
270 if(!found) |
|
271 { |
|
272 res = XA_RESULT_FEATURE_UNSUPPORTED; |
|
273 return res; |
|
274 } |
|
275 |
|
276 DEBUG_API("<-XACapabilitiesMgr_GetCapsById"); |
|
277 return res; |
|
278 } |
|
279 |
|
280 /* XAresult XACapabilitiesMgr_GetCapsByIdx |
|
281 * Description: Get n'th capabilities of type XACapsType |
|
282 */ |
|
283 XAresult XACapabilitiesMgr_GetCapsByIdx(XACapabilities* pListHead, XACapsType filter, XAuint32 idx, XACapabilities* data) |
|
284 { |
|
285 XAresult res = XA_RESULT_SUCCESS; |
|
286 XACapabilities* currNode = pListHead; |
|
287 XAboolean found = XA_BOOLEAN_FALSE; |
|
288 XAuint32 j = 0; |
|
289 |
|
290 |
|
291 DEBUG_API("->XACapabilitiesMgr_GetCapsByIdx"); |
|
292 |
|
293 if(!currNode) |
|
294 { |
|
295 res = XA_RESULT_PARAMETER_INVALID; |
|
296 return res; |
|
297 } |
|
298 |
|
299 |
|
300 while (currNode) |
|
301 { |
|
302 if ((currNode->capsType & filter) == filter ) |
|
303 { |
|
304 if( idx == j++ ) |
|
305 { |
|
306 memcpy(data, currNode, sizeof(XACapabilities)); |
|
307 found = XA_BOOLEAN_TRUE; |
|
308 break; |
|
309 } |
|
310 } |
|
311 currNode = currNode->next; |
|
312 } |
|
313 |
|
314 if(!found) |
|
315 { |
|
316 res = XA_RESULT_PARAMETER_INVALID; |
|
317 return res; |
|
318 } |
|
319 |
|
320 DEBUG_API("<-XACapabilitiesMgr_GetCapsByIdx"); |
|
321 return res; |
|
322 } |
|
323 |
|
324 /* XAresult XACapabilitiesMgr_QueryColorFormats |
|
325 * Description: Get color formats associated with the XA_IMAGECODEC_RAW codec. |
|
326 */ |
|
327 XAresult XACapabilitiesMgr_QueryColorFormats(XACapabilities* pListHead, XAuint32* pIndex, XAuint32* pColorFormats) |
|
328 { |
|
329 XAresult res = XA_RESULT_SUCCESS; |
|
330 XACapabilities temp; |
|
331 |
|
332 DEBUG_API("->XACapabilitiesMgr_QueryColorFormats"); |
|
333 |
|
334 if( !pIndex ) |
|
335 { |
|
336 DEBUG_ERR("illegal NULL parameter"); |
|
337 res = XA_RESULT_PARAMETER_INVALID; |
|
338 return res; |
|
339 } |
|
340 |
|
341 res = XACapabilitiesMgr_GetCapsById(pListHead, (XACapsType)((XACapsType)(XACAP_ENCODER|XACAP_IMAGE)), XA_IMAGECODEC_RAW, &temp); |
|
342 if( res == XA_RESULT_SUCCESS ) |
|
343 { |
|
344 if( !pColorFormats ) |
|
345 { /* query number of color formats */ |
|
346 *pIndex = 1; /* one used by camera context */ |
|
347 } |
|
348 else |
|
349 { /* query color format */ |
|
350 if( *pIndex >= 1 ) /* one used by camera context */ |
|
351 { |
|
352 DEBUG_ERR("index parameter invalid"); |
|
353 res = XA_RESULT_PARAMETER_INVALID; |
|
354 } |
|
355 else |
|
356 { /* internal format used by pipeline, look camera context for details */ |
|
357 *pColorFormats = XA_COLORFORMAT_YUV420PLANAR; |
|
358 } |
|
359 } |
|
360 } |
|
361 else |
|
362 { |
|
363 *pIndex = 0; |
|
364 } |
|
365 |
|
366 DEBUG_API("<-XACapabilitiesMgr_QueryColorFormats"); |
|
367 return res; |
|
368 } |
|
369 |
|
370 /* Add AudioInputDeviceCaps */ |
|
371 XAresult XACapabilitiesMgr_GetAudioInputDeviceCapabilities(XACapabilities** ppNode) |
|
372 { |
|
373 XAresult res = XA_RESULT_SUCCESS; |
|
374 XACapabilities *newNode = NULL; |
|
375 XAAudioInputDescriptor *entries = NULL; |
|
376 /* XAAudioInputDescriptor *entries = NULL;*/ |
|
377 XAchar micDeviceName[] = "Default Mic"; |
|
378 int strLen = 0; |
|
379 |
|
380 newNode = (XACapabilities *)calloc(1, sizeof(XACapabilities)); |
|
381 if (!newNode) |
|
382 { |
|
383 res = XA_RESULT_MEMORY_FAILURE; |
|
384 return res; |
|
385 } |
|
386 |
|
387 newNode->capsType = AUD_I; |
|
388 newNode->xaid = 0xAD7E5001; |
|
389 newNode->noOfEntries = 1; |
|
390 |
|
391 /* Allocate array */ |
|
392 entries = (XAAudioInputDescriptor*) calloc(1 , sizeof(XAAudioInputDescriptor)); |
|
393 if (!entries) |
|
394 { |
|
395 res = XA_RESULT_MEMORY_FAILURE; |
|
396 XACapabilitiesMgr_DeleteCapabilitieList(&newNode); |
|
397 return res; |
|
398 } |
|
399 |
|
400 newNode->pEntry = (void*)entries; |
|
401 |
|
402 strLen = strlen((char*)micDeviceName); |
|
403 entries->deviceName = (XAchar *)calloc(strLen + 1, sizeof(XAchar)); |
|
404 if (!entries->deviceName) |
|
405 { |
|
406 res = XA_RESULT_MEMORY_FAILURE; |
|
407 XACapabilitiesMgr_DeleteCapabilitieList(&newNode); |
|
408 return res; |
|
409 } |
|
410 |
|
411 strncpy((char*)entries->deviceName, (char*)micDeviceName, strLen); |
|
412 entries->deviceName[strLen] = '\0'; /*Null terminate it*/ |
|
413 entries->deviceConnection = XA_DEVCONNECTION_INTEGRATED; |
|
414 entries->deviceScope = XA_DEVSCOPE_ENVIRONMENT; |
|
415 entries->deviceLocation = XA_DEVLOCATION_HANDSET; |
|
416 entries->isForTelephony = XA_BOOLEAN_FALSE; |
|
417 entries->minSampleRate=8000000; /* milliHz */ |
|
418 entries->maxSampleRate = 96000000; /* milliHz */ |
|
419 entries->isFreqRangeContinuous=XA_BOOLEAN_FALSE; |
|
420 entries->numOfSamplingRatesSupported = 12; |
|
421 entries->samplingRatesSupported = (XAmilliHertz*)calloc(entries->numOfSamplingRatesSupported, sizeof(XAmilliHertz)); |
|
422 if (!entries->samplingRatesSupported) |
|
423 { |
|
424 res = XA_RESULT_MEMORY_FAILURE; |
|
425 XACapabilitiesMgr_DeleteCapabilitieList(&newNode); |
|
426 return res; |
|
427 } |
|
428 /* entries in milliHz */ |
|
429 entries->samplingRatesSupported[0] = 8000000; |
|
430 entries->samplingRatesSupported[1] = 11025000; |
|
431 entries->samplingRatesSupported[2] = 12000000; |
|
432 entries->samplingRatesSupported[3] = 16000000; |
|
433 entries->samplingRatesSupported[4] = 22050000; |
|
434 entries->samplingRatesSupported[5] = 24000000; |
|
435 entries->samplingRatesSupported[6] = 32000000; |
|
436 entries->samplingRatesSupported[7] = 44100000; |
|
437 entries->samplingRatesSupported[8] = 48000000; |
|
438 entries->samplingRatesSupported[9] = 64000000; |
|
439 entries->samplingRatesSupported[10] = 88200000; |
|
440 entries->samplingRatesSupported[11] = 96000000; |
|
441 entries->maxChannels = 2; |
|
442 |
|
443 newNode->pEntry = (void*)entries; |
|
444 |
|
445 *ppNode = newNode; |
|
446 return res; |
|
447 } |
|
448 |
|
449 XAresult XACapabilitiesMgr_GetAudioOutputDeviceCapabilities(XACapabilities **ppNode) |
|
450 { |
|
451 XAresult res = XA_RESULT_SUCCESS; |
|
452 XACapabilities *newNode = NULL; |
|
453 XAAudioOutputDescriptor *entries = NULL; |
|
454 /* XAAudioOutputDescriptor *entries = NULL;*/ |
|
455 XAchar outputDeviceName[] = "Default Speaker"; |
|
456 int strLen = 0; |
|
457 |
|
458 newNode = (XACapabilities *)calloc(1, sizeof(XACapabilities)); |
|
459 if (!newNode) |
|
460 { |
|
461 res = XA_RESULT_MEMORY_FAILURE; |
|
462 return res; |
|
463 } |
|
464 |
|
465 newNode->capsType = AUD_O; |
|
466 newNode->xaid = 0xAD7E5002; |
|
467 newNode->noOfEntries = 1; |
|
468 |
|
469 /* Allocate array */ |
|
470 entries = (XAAudioOutputDescriptor*)calloc(1, sizeof(XAAudioOutputDescriptor)); |
|
471 if (!entries) |
|
472 { |
|
473 res = XA_RESULT_MEMORY_FAILURE; |
|
474 XACapabilitiesMgr_DeleteCapabilitieList(&newNode); |
|
475 return res; |
|
476 } |
|
477 |
|
478 newNode->pEntry = (void*)entries; |
|
479 |
|
480 strLen = strlen((char*)outputDeviceName); |
|
481 entries->pDeviceName = (XAchar *)calloc(strLen + 1, sizeof(XAchar)); |
|
482 if (!entries->pDeviceName) |
|
483 { |
|
484 res = XA_RESULT_MEMORY_FAILURE; |
|
485 XACapabilitiesMgr_DeleteCapabilitieList(&newNode); |
|
486 return res; |
|
487 } |
|
488 strncpy((char*)entries->pDeviceName, (char*)outputDeviceName, strLen); |
|
489 entries->pDeviceName[strLen] = '\0'; /*Null terminate it*/ |
|
490 entries->deviceConnection = XA_DEVCONNECTION_INTEGRATED; |
|
491 entries->deviceScope = XA_DEVSCOPE_ENVIRONMENT; |
|
492 entries->deviceLocation = XA_DEVLOCATION_HANDSET; |
|
493 entries->isForTelephony = XA_BOOLEAN_FALSE; |
|
494 entries->minSampleRate = 8000000; /* milliHz */ |
|
495 entries->maxSampleRate = 96000000; /* milliHz */ |
|
496 entries->isFreqRangeContinuous = XA_BOOLEAN_FALSE; |
|
497 entries->numOfSamplingRatesSupported = 12; |
|
498 entries->samplingRatesSupported = (XAmilliHertz*)calloc(entries->numOfSamplingRatesSupported, sizeof(XAmilliHertz)); |
|
499 if (!entries->samplingRatesSupported) |
|
500 { |
|
501 res = XA_RESULT_MEMORY_FAILURE; |
|
502 XACapabilitiesMgr_DeleteCapabilitieList(&newNode); |
|
503 return res; |
|
504 } |
|
505 /* entries in milliHz */ |
|
506 entries->samplingRatesSupported[0] = 8000000; |
|
507 entries->samplingRatesSupported[1] = 11025000; |
|
508 entries->samplingRatesSupported[2] = 12000000; |
|
509 entries->samplingRatesSupported[3] = 16000000; |
|
510 entries->samplingRatesSupported[4] = 22050000; |
|
511 entries->samplingRatesSupported[5] = 24000000; |
|
512 entries->samplingRatesSupported[6] = 32000000; |
|
513 entries->samplingRatesSupported[7] = 44100000; |
|
514 entries->samplingRatesSupported[8] = 48000000; |
|
515 entries->samplingRatesSupported[9] = 64000000; |
|
516 entries->samplingRatesSupported[10] = 88200000; |
|
517 entries->samplingRatesSupported[11] = 96000000; |
|
518 entries->maxChannels = 2; |
|
519 |
|
520 newNode->pEntry = (void*)entries; |
|
521 |
|
522 *ppNode = newNode; |
|
523 return res; |
|
524 } |
|
525 |