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