|
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 <string.h> |
|
22 |
|
23 #include "xaglobals.h" |
|
24 #include "xaaudioiodevicecapabilitiesitf.h" |
|
25 #ifdef _GSTREAMER_BACKEND_ |
|
26 #include "XAStaticCapsAdaptation.h" |
|
27 #endif |
|
28 |
|
29 static XAchar deviceName1[] = "Default Mic"; |
|
30 |
|
31 /* XAAudIODevCapaItfImpl* GetImpl |
|
32 * Description: Validate interface pointer and cast it to implementation pointer. |
|
33 */ |
|
34 static XAAudIODevCapaItfImpl* GetImpl(XAAudioIODeviceCapabilitiesItf self) |
|
35 { |
|
36 if( self ) |
|
37 { |
|
38 XAAudIODevCapaItfImpl* impl = (XAAudIODevCapaItfImpl*)(*self); |
|
39 if( impl && (impl == impl->self) ) |
|
40 { |
|
41 return impl; |
|
42 } |
|
43 } |
|
44 return NULL; |
|
45 } |
|
46 |
|
47 /** |
|
48 * Base interface XAAudioIODeviceCapabilitiesItf implementation |
|
49 **/ |
|
50 |
|
51 /* XAresult XAAudIODevCapaItfImpl_GetAvailableAudioInputs |
|
52 * Description: Gets the number and IDs of audio input devices currently available. |
|
53 */ |
|
54 XAresult XAAudIODevCapaItfImpl_GetAvailableAudioInputs( |
|
55 XAAudioIODeviceCapabilitiesItf self, |
|
56 XAint32* pNumInputs, |
|
57 XAuint32* pInputDeviceIDs) |
|
58 { |
|
59 XAAudIODevCapaItfImpl* impl = GetImpl(self); |
|
60 XAresult res = XA_RESULT_SUCCESS; |
|
61 DEBUG_API("->XAAudIODevCapaItfImpl_GetAvailableAudioInputs"); |
|
62 |
|
63 if( !impl || !pNumInputs ) |
|
64 { |
|
65 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
66 res = XA_RESULT_PARAMETER_INVALID; |
|
67 } |
|
68 else |
|
69 { |
|
70 if( pInputDeviceIDs ) |
|
71 { /* query array of input devices */ |
|
72 if( *pNumInputs < impl->numInputDevices ) |
|
73 { |
|
74 DEBUG_ERR("XA_RESULT_BUFFER_INSUFFICIENT"); |
|
75 res = XA_RESULT_BUFFER_INSUFFICIENT; |
|
76 } |
|
77 else |
|
78 { |
|
79 |
|
80 #ifdef _GSTREAMER_BACKEND_ |
|
81 XAuint32 i; |
|
82 XAStaticCapsData temp; |
|
83 for( i=0; i<impl->numInputDevices; i++ ) |
|
84 { |
|
85 /* query device id from adaptation using index value */ |
|
86 res = XAStaticCapsAdapt_GetCapsByIdx(XACAP_DEVSRC|XACAP_AUDIO, i, &temp); |
|
87 pInputDeviceIDs[i] = temp.xaid; |
|
88 } |
|
89 #endif |
|
90 pInputDeviceIDs[0] = 0xAD7E5001; |
|
91 } |
|
92 } |
|
93 *pNumInputs = impl->numInputDevices; |
|
94 } |
|
95 DEBUG_API("<-XAAudIODevCapaItfImpl_GetAvailableAudioInputs"); |
|
96 return res; |
|
97 } |
|
98 |
|
99 /* XAresult XAAudIODevCapaItfImpl_QueryAudioInputCapabilities |
|
100 * Description: Gets the capabilities of the specified audio input device. |
|
101 */ |
|
102 XAresult XAAudIODevCapaItfImpl_QueryAudioInputCapabilities( |
|
103 XAAudioIODeviceCapabilitiesItf self, |
|
104 XAuint32 deviceId, |
|
105 XAAudioInputDescriptor* pDescriptor) |
|
106 { |
|
107 XAAudIODevCapaItfImpl* impl = GetImpl(self); |
|
108 XAresult res = XA_RESULT_SUCCESS; |
|
109 DEBUG_API("->XAAudIODevCapaItfImpl_QueryAudioInputCapabilities"); |
|
110 |
|
111 if( !impl || !pDescriptor ) |
|
112 { |
|
113 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
114 res = XA_RESULT_PARAMETER_INVALID; |
|
115 } |
|
116 else |
|
117 { |
|
118 memset(pDescriptor,0,sizeof(XAAudioInputDescriptor)); |
|
119 #ifdef _GSTREAMER_BACKEND_ |
|
120 /* query capabilities from adaptation using device id */ |
|
121 XAStaticCapsData temp; |
|
122 |
|
123 res = XAStaticCapsAdapt_GetCapsById(XACAP_DEVSRC|XACAP_AUDIO, deviceId, &temp); |
|
124 if( res == XA_RESULT_SUCCESS ) |
|
125 { |
|
126 /* map applicable values to XAAudioCodecCapabilities */ |
|
127 pDescriptor->maxChannels=temp.maxCh; |
|
128 pDescriptor->minSampleRate=temp.minSR*1000; /* milliHz */ |
|
129 if (temp.maxSR < (0xFFFFFFFF / 1000)) |
|
130 { |
|
131 pDescriptor->maxSampleRate = temp.maxSR*1000; |
|
132 } |
|
133 else |
|
134 { |
|
135 pDescriptor->maxSampleRate = 0xFFFFFFFF; |
|
136 } |
|
137 pDescriptor->isFreqRangeContinuous=XA_BOOLEAN_TRUE; |
|
138 pDescriptor->deviceConnection = XA_DEVCONNECTION_INTEGRATED; |
|
139 pDescriptor->deviceScope = XA_DEVSCOPE_ENVIRONMENT; |
|
140 pDescriptor->deviceLocation = XA_DEVLOCATION_HANDSET; |
|
141 pDescriptor->deviceName = temp.adaptId; |
|
142 /* other caps undefined */ |
|
143 } |
|
144 #endif |
|
145 switch (deviceId) |
|
146 { |
|
147 case 0xAD7E5001: |
|
148 { |
|
149 impl->sampleRateArray[0] = 8000000; |
|
150 impl->sampleRateArray[1] = 11025000; |
|
151 impl->sampleRateArray[2] = 12000000; |
|
152 impl->sampleRateArray[3] = 16000000; |
|
153 impl->sampleRateArray[4] = 22050000; |
|
154 impl->sampleRateArray[5] = 24000000; |
|
155 impl->sampleRateArray[6] = 32000000; |
|
156 impl->sampleRateArray[7] = 44100000; |
|
157 impl->sampleRateArray[8] = 48000000; |
|
158 impl->sampleRateArray[9] = 64000000; |
|
159 impl->sampleRateArray[10] = 88200000; |
|
160 impl->sampleRateArray[11] = 96000000; |
|
161 |
|
162 pDescriptor->deviceName = (XAchar *)deviceName1; |
|
163 pDescriptor->deviceConnection = XA_DEVCONNECTION_INTEGRATED; |
|
164 pDescriptor->deviceScope = XA_DEVSCOPE_ENVIRONMENT; |
|
165 pDescriptor->deviceLocation = XA_DEVLOCATION_HANDSET; |
|
166 pDescriptor->isForTelephony = XA_BOOLEAN_FALSE; |
|
167 pDescriptor->minSampleRate=8000000; /* milliHz */ |
|
168 pDescriptor->maxSampleRate = 96000000; |
|
169 pDescriptor->isFreqRangeContinuous=XA_BOOLEAN_FALSE; |
|
170 pDescriptor->samplingRatesSupported = (XAmilliHertz*)(&(impl->sampleRateArray)); |
|
171 pDescriptor->numOfSamplingRatesSupported = 12; |
|
172 pDescriptor->maxChannels = 2; |
|
173 } |
|
174 break; |
|
175 default: |
|
176 res = XA_RESULT_PARAMETER_INVALID; |
|
177 break; |
|
178 } |
|
179 } |
|
180 |
|
181 DEBUG_API("<-XAAudIODevCapaItfImpl_QueryAudioInputCapabilities"); |
|
182 return res; |
|
183 } |
|
184 |
|
185 /* XAresult XAAudIODevCapaItfImpl_RegisterAvailableAudioInputsChangedCallback |
|
186 * Description: Sets or clears xaAvailableAudioInputsChangedCallback(). |
|
187 */ |
|
188 XAresult XAAudIODevCapaItfImpl_RegisterAvailableAudioInputsChangedCallback( |
|
189 XAAudioIODeviceCapabilitiesItf self, |
|
190 xaAvailableAudioInputsChangedCallback callback, |
|
191 void* pContext) |
|
192 { |
|
193 XAAudIODevCapaItfImpl* impl = GetImpl(self); |
|
194 XAresult res = XA_RESULT_SUCCESS; |
|
195 |
|
196 DEBUG_API("->XAAudIODevCapaItfImpl_RegisterAvailableAudioInputsChangedCallback"); |
|
197 |
|
198 if( !impl ) |
|
199 { |
|
200 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
201 res = XA_RESULT_PARAMETER_INVALID; |
|
202 } |
|
203 else |
|
204 { |
|
205 impl->inputCb = callback; |
|
206 impl->inputCbCtx = pContext; |
|
207 impl->inputCbPtrToSelf = self; |
|
208 } |
|
209 |
|
210 DEBUG_API("<-XAAudIODevCapaItfImpl_RegisterAvailableAudioInputsChangedCallback"); |
|
211 return res; |
|
212 } |
|
213 |
|
214 /* XAresult XAAudIODevCapaItfImpl_GetAvailableAudioOutputs |
|
215 * Description: Gets the number and IDs of audio output devices currently available. |
|
216 */ |
|
217 XAresult XAAudIODevCapaItfImpl_GetAvailableAudioOutputs( |
|
218 XAAudioIODeviceCapabilitiesItf self, |
|
219 XAint32* pNumOutputs, |
|
220 XAuint32* pOutputDeviceIDs) |
|
221 { |
|
222 XAAudIODevCapaItfImpl* impl = GetImpl(self); |
|
223 XAresult res = XA_RESULT_SUCCESS; |
|
224 |
|
225 DEBUG_API("->XAAudIODevCapaItfImpl_GetAvailableAudioOutputs"); |
|
226 |
|
227 /* NOTE: only default speaker supported by this impl */ |
|
228 if( !impl || !pNumOutputs ) |
|
229 { |
|
230 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
231 res = XA_RESULT_PARAMETER_INVALID; |
|
232 } |
|
233 else |
|
234 { |
|
235 if( pOutputDeviceIDs ) |
|
236 { /* query array of output devices */ |
|
237 if( *pNumOutputs < impl->numOutputDevices ) |
|
238 { |
|
239 DEBUG_ERR("XA_RESULT_BUFFER_INSUFFICIENT"); |
|
240 res = XA_RESULT_BUFFER_INSUFFICIENT; |
|
241 } |
|
242 else |
|
243 { |
|
244 |
|
245 #ifdef _GSTREAMER_BACKEND_ |
|
246 XAuint32 i = 0; |
|
247 XAStaticCapsData temp; |
|
248 for( i=0; i<impl->numOutputDevices; i++ ) |
|
249 { |
|
250 /* query device id from adaptation using index value */ |
|
251 res = XAStaticCapsAdapt_GetCapsByIdx(XACAP_DEVSNK|XACAP_AUDIO, i, &temp); |
|
252 pOutputDeviceIDs[i] = temp.xaid; |
|
253 } |
|
254 #endif |
|
255 pOutputDeviceIDs[0] = 0xAD7E5002; |
|
256 } |
|
257 } |
|
258 *pNumOutputs = impl->numOutputDevices; |
|
259 } |
|
260 DEBUG_API("<-XAAudIODevCapaItfImpl_GetAvailableAudioOutputs"); |
|
261 return res; |
|
262 } |
|
263 |
|
264 /* XAresult XAAudIODevCapaItfImpl_QueryAudioOutputCapabilities |
|
265 * Description: Gets the capabilities of the specified audio output device. |
|
266 */ |
|
267 XAresult XAAudIODevCapaItfImpl_QueryAudioOutputCapabilities( |
|
268 XAAudioIODeviceCapabilitiesItf self, |
|
269 XAuint32 deviceId, |
|
270 XAAudioOutputDescriptor* pDescriptor) |
|
271 { |
|
272 |
|
273 XAAudIODevCapaItfImpl* impl = GetImpl(self); |
|
274 XAresult res = XA_RESULT_SUCCESS; |
|
275 DEBUG_API("->XAAudIODevCapaItfImpl_QueryAudioOutputCapabilities"); |
|
276 |
|
277 if( !impl || !pDescriptor ) |
|
278 { |
|
279 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
280 res = XA_RESULT_PARAMETER_INVALID; |
|
281 } |
|
282 else |
|
283 { |
|
284 memset(pDescriptor,0,sizeof(XAAudioOutputDescriptor)); |
|
285 /* query capabilities from adaptation using device id */ |
|
286 #ifdef _GSTREAMER_BACKEND_ |
|
287 XAStaticCapsData temp; |
|
288 |
|
289 res = XAStaticCapsAdapt_GetCapsById(XACAP_DEVSNK|XACAP_AUDIO, deviceId, &temp); |
|
290 if( res == XA_RESULT_SUCCESS ) |
|
291 { |
|
292 /* map applicable values to XAAudioCodecCapabilities */ |
|
293 pDescriptor->maxChannels=temp.maxCh; |
|
294 pDescriptor->minSampleRate=temp.minSR*1000; /* milliHz */ |
|
295 if (temp.maxSR < (0xFFFFFFFF / 1000)) |
|
296 { |
|
297 pDescriptor->maxSampleRate = temp.maxSR*1000; |
|
298 } |
|
299 else |
|
300 { |
|
301 pDescriptor->maxSampleRate = 0xFFFFFFFF; |
|
302 } |
|
303 pDescriptor->isFreqRangeContinuous=XA_BOOLEAN_TRUE; |
|
304 pDescriptor->deviceConnection = XA_DEVCONNECTION_INTEGRATED; |
|
305 pDescriptor->deviceScope = XA_DEVSCOPE_ENVIRONMENT; |
|
306 pDescriptor->deviceLocation = XA_DEVLOCATION_HANDSET; |
|
307 pDescriptor->pDeviceName = temp.adaptId; |
|
308 /* other caps undefined */ |
|
309 } |
|
310 #endif |
|
311 |
|
312 switch (deviceId) |
|
313 { |
|
314 case 0xAD7E5002: |
|
315 { |
|
316 impl->sampleRateArray[0] = 8000000; |
|
317 impl->sampleRateArray[1] = 11025000; |
|
318 impl->sampleRateArray[2] = 12000000; |
|
319 impl->sampleRateArray[3] = 16000000; |
|
320 impl->sampleRateArray[4] = 22050000; |
|
321 impl->sampleRateArray[5] = 24000000; |
|
322 impl->sampleRateArray[6] = 32000000; |
|
323 impl->sampleRateArray[7] = 44100000; |
|
324 impl->sampleRateArray[8] = 48000000; |
|
325 impl->sampleRateArray[9] = 64000000; |
|
326 impl->sampleRateArray[10] = 88200000; |
|
327 impl->sampleRateArray[11] = 96000000; |
|
328 |
|
329 pDescriptor->pDeviceName = (XAchar *)"Device Speaker"; |
|
330 pDescriptor->deviceConnection = XA_DEVCONNECTION_INTEGRATED; |
|
331 pDescriptor->deviceScope = XA_DEVSCOPE_ENVIRONMENT; |
|
332 pDescriptor->deviceLocation = XA_DEVLOCATION_HANDSET; |
|
333 pDescriptor->isForTelephony = XA_BOOLEAN_FALSE; |
|
334 pDescriptor->minSampleRate=8000000; /* milliHz */ |
|
335 pDescriptor->maxSampleRate = 96000000; |
|
336 pDescriptor->isFreqRangeContinuous=XA_BOOLEAN_FALSE; |
|
337 pDescriptor->samplingRatesSupported = (XAmilliHertz*)(&(impl->sampleRateArray)); |
|
338 pDescriptor->numOfSamplingRatesSupported = 12; |
|
339 pDescriptor->maxChannels = 2; |
|
340 } |
|
341 break; |
|
342 default: |
|
343 res = XA_RESULT_PARAMETER_INVALID; |
|
344 break; |
|
345 } |
|
346 } |
|
347 |
|
348 DEBUG_API("<-XAAudIODevCapaItfImpl_QueryAudioOutputCapabilities"); |
|
349 return res; |
|
350 } |
|
351 |
|
352 /* XAresult XAAudIODevCapaItfImpl_RegisterAvailableAudioOutputsChangedCallback |
|
353 * Description: Sets or clears xaAvailableAudioOutputsChangedCallback(). |
|
354 */ |
|
355 XAresult XAAudIODevCapaItfImpl_RegisterAvailableAudioOutputsChangedCallback( |
|
356 XAAudioIODeviceCapabilitiesItf self, |
|
357 xaAvailableAudioOutputsChangedCallback callback, |
|
358 void* pContext) |
|
359 { |
|
360 |
|
361 XAAudIODevCapaItfImpl* impl = GetImpl(self); |
|
362 XAresult res = XA_RESULT_SUCCESS; |
|
363 DEBUG_API("->XAAudIODevCapaItfImpl_RegisterAvailableAudioOutputsChangedCallback"); |
|
364 |
|
365 if( !impl ) |
|
366 { |
|
367 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
368 res = XA_RESULT_PARAMETER_INVALID; |
|
369 } |
|
370 else |
|
371 { |
|
372 impl->outputCb = callback; |
|
373 impl->outputCbCtx = pContext; |
|
374 impl->outputCbPtrToSelf = self; |
|
375 } |
|
376 |
|
377 DEBUG_API("<-XAAudIODevCapaItfImpl_RegisterAvailableAudioOutputsChangedCallback"); |
|
378 return res; |
|
379 } |
|
380 |
|
381 /* XAresult XAAudIODevCapaItfImpl_RegisterDefaultDeviceIDMapChangedCallback |
|
382 * Description: Sets or clears xaDefaultDeviceIDMapChangedCallback(). |
|
383 */ |
|
384 XAresult XAAudIODevCapaItfImpl_RegisterDefaultDeviceIDMapChangedCallback( |
|
385 XAAudioIODeviceCapabilitiesItf self, |
|
386 xaDefaultDeviceIDMapChangedCallback callback, |
|
387 void* pContext) |
|
388 { |
|
389 XAAudIODevCapaItfImpl* impl = GetImpl(self); |
|
390 XAresult res = XA_RESULT_SUCCESS; |
|
391 |
|
392 DEBUG_API("->XAAudIODevCapaItfImpl_RegisterDefaultDeviceIDMapChangedCallback"); |
|
393 |
|
394 if( !impl ) |
|
395 { |
|
396 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
397 res = XA_RESULT_PARAMETER_INVALID; |
|
398 } |
|
399 else |
|
400 { |
|
401 impl->deviceMapCb = callback; |
|
402 impl->deviceMapCtx = pContext; |
|
403 impl->deviceMapCbPtrToSelf = self; |
|
404 } |
|
405 |
|
406 DEBUG_API("<-XAAudIODevCapaItfImpl_RegisterDefaultDeviceIDMapChangedCallback"); |
|
407 return res; |
|
408 } |
|
409 |
|
410 /* XAresult XAAudIODevCapaItfImpl_GetAssociatedAudioInputs |
|
411 * Description: This method returns an array of audio input devices physically |
|
412 * associated with this audio I/O device. |
|
413 */ |
|
414 XAresult XAAudIODevCapaItfImpl_GetAssociatedAudioInputs( |
|
415 XAAudioIODeviceCapabilitiesItf self, |
|
416 XAuint32 deviceId, |
|
417 XAint32* pNumAudioInputs, |
|
418 XAuint32* pAudioInputDeviceIDs) |
|
419 { |
|
420 XAAudIODevCapaItfImpl* impl = GetImpl(self); |
|
421 XAresult res = XA_RESULT_SUCCESS; |
|
422 DEBUG_API("->XAAudIODevCapaItfImpl_GetAssociatedAudioInputs"); |
|
423 if( !impl || !pNumAudioInputs ) |
|
424 { |
|
425 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
426 res = XA_RESULT_PARAMETER_INVALID; |
|
427 } |
|
428 else |
|
429 { |
|
430 #ifdef _GSTREAMER_BACKEND_ |
|
431 XAStaticCapsData temp; |
|
432 XAuint32 associatedCount = 0; |
|
433 |
|
434 XAuint32 i = 0; |
|
435 for( i=0; i<impl->numInputDevices; i++ ) |
|
436 { |
|
437 /* query device id from adaptation using index value */ |
|
438 res = XAStaticCapsAdapt_GetCapsByIdx(XACAP_DEVSRC|XACAP_AUDIO, i, &temp); |
|
439 if (temp.xaid != deviceId) |
|
440 { |
|
441 associatedCount++; |
|
442 } |
|
443 } |
|
444 |
|
445 if (pAudioInputDeviceIDs) |
|
446 { |
|
447 if( *pNumAudioInputs < associatedCount ) |
|
448 { |
|
449 DEBUG_ERR("XA_RESULT_BUFFER_INSUFFICIENT"); |
|
450 DEBUG_API("<-XAAudIODevCapaItfImpl_GetAssociatedAudioInputs"); |
|
451 return XA_RESULT_BUFFER_INSUFFICIENT; |
|
452 } |
|
453 |
|
454 for( i=0, associatedCount = 0; i<impl->numInputDevices; i++ ) |
|
455 { |
|
456 /* query device id from adaptation using index value */ |
|
457 res = XAStaticCapsAdapt_GetCapsByIdx(XACAP_DEVSRC|XACAP_AUDIO, i, &temp); |
|
458 if (temp.xaid != deviceId) |
|
459 { |
|
460 pAudioInputDeviceIDs[associatedCount++] = temp.xaid; |
|
461 } |
|
462 } |
|
463 } |
|
464 |
|
465 *pNumAudioInputs = associatedCount; |
|
466 #endif |
|
467 |
|
468 if(!pAudioInputDeviceIDs) |
|
469 { |
|
470 switch(deviceId) |
|
471 { |
|
472 case 0xAD7E5001: |
|
473 *pNumAudioInputs = 0; |
|
474 break; |
|
475 case 0xAD7E5002: |
|
476 *pNumAudioInputs = 1; |
|
477 break; |
|
478 default: |
|
479 res = XA_RESULT_PARAMETER_INVALID; |
|
480 break; |
|
481 } |
|
482 } |
|
483 else |
|
484 { |
|
485 switch(deviceId) |
|
486 { |
|
487 case 0xAD7E5001: |
|
488 res = XA_RESULT_PARAMETER_INVALID; |
|
489 break; |
|
490 case 0xAD7E5002: |
|
491 pAudioInputDeviceIDs[*pNumAudioInputs - 1] = 0xAD7E5001; |
|
492 break; |
|
493 default: |
|
494 res = XA_RESULT_PARAMETER_INVALID; |
|
495 break; |
|
496 } |
|
497 } |
|
498 |
|
499 } |
|
500 |
|
501 DEBUG_API("<-XAAudIODevCapaItfImpl_GetAssociatedAudioInputs"); |
|
502 return res; |
|
503 } |
|
504 |
|
505 /* XAresult XAAudIODevCapaItfImpl_GetAssociatedAudioOutputs |
|
506 * Description: This method returns an array of audio output devices physically |
|
507 * associated with this audio I/O device. |
|
508 */ |
|
509 XAresult XAAudIODevCapaItfImpl_GetAssociatedAudioOutputs( |
|
510 XAAudioIODeviceCapabilitiesItf self, |
|
511 XAuint32 deviceId, |
|
512 XAint32* pNumAudioOutputs, |
|
513 XAuint32* pAudioOutputDeviceIDs) |
|
514 { |
|
515 XAAudIODevCapaItfImpl* impl = GetImpl(self); |
|
516 XAresult res = XA_RESULT_SUCCESS; |
|
517 DEBUG_API("->XAAudIODevCapaItfImpl_GetAssociatedAudioOutputs"); |
|
518 |
|
519 if( !impl || !pNumAudioOutputs ) |
|
520 { |
|
521 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
522 res = XA_RESULT_PARAMETER_INVALID; |
|
523 } |
|
524 else |
|
525 { |
|
526 #ifdef _GSTREAMER_BACKEND_ |
|
527 XAStaticCapsData temp; |
|
528 XAuint32 associatedCount = 0; |
|
529 |
|
530 XAuint32 i = 0; |
|
531 for( i=0; i<impl->numOutputDevices; i++ ) |
|
532 { |
|
533 /* query device id from adaptation using index value */ |
|
534 res = XAStaticCapsAdapt_GetCapsByIdx(XACAP_DEVSNK|XACAP_AUDIO, i, &temp); |
|
535 if (temp.xaid != deviceId) |
|
536 { |
|
537 associatedCount++; |
|
538 } |
|
539 } |
|
540 |
|
541 if (pAudioOutputDeviceIDs) |
|
542 { |
|
543 if( *pNumAudioOutputs < associatedCount ) |
|
544 { |
|
545 DEBUG_ERR("XA_RESULT_BUFFER_INSUFFICIENT"); |
|
546 DEBUG_API("<-XAAudIODevCapaItfImpl_GetAssociatedAudioOutputs"); |
|
547 return XA_RESULT_BUFFER_INSUFFICIENT; |
|
548 } |
|
549 |
|
550 for( i=0, associatedCount = 0; i<impl->numOutputDevices; i++ ) |
|
551 { |
|
552 /* query device id from adaptation using index value */ |
|
553 res = XAStaticCapsAdapt_GetCapsByIdx(XACAP_DEVSNK|XACAP_AUDIO, i, &temp); |
|
554 if (temp.xaid != deviceId) |
|
555 { |
|
556 pAudioOutputDeviceIDs[associatedCount++] = temp.xaid; |
|
557 } |
|
558 } |
|
559 } |
|
560 |
|
561 *pNumAudioOutputs = associatedCount; |
|
562 #endif |
|
563 |
|
564 if(!pAudioOutputDeviceIDs) |
|
565 { |
|
566 switch(deviceId) |
|
567 { |
|
568 case 0xAD7E5002: |
|
569 *pNumAudioOutputs = 0; |
|
570 break; |
|
571 case 0xAD7E5001: |
|
572 *pNumAudioOutputs = 1; |
|
573 break; |
|
574 default: |
|
575 res = XA_RESULT_PARAMETER_INVALID; |
|
576 break; |
|
577 } |
|
578 } |
|
579 else |
|
580 { |
|
581 switch(deviceId) |
|
582 { |
|
583 case 0xAD7E5002: |
|
584 res = XA_RESULT_PARAMETER_INVALID; |
|
585 break; |
|
586 case 0xAD7E5001: |
|
587 pAudioOutputDeviceIDs[*pNumAudioOutputs - 1] = 0xAD7E5001; |
|
588 break; |
|
589 default: |
|
590 res = XA_RESULT_PARAMETER_INVALID; |
|
591 break; |
|
592 } |
|
593 } |
|
594 } |
|
595 |
|
596 DEBUG_API("<-XAAudIODevCapaItfImpl_GetAssociatedAudioOutputs"); |
|
597 return res; |
|
598 } |
|
599 |
|
600 /* XAresult XAAudIODevCapaItfImpl_GetDefaultAudioDevices |
|
601 * Gets the number of audio devices currently mapped to the given default device ID. |
|
602 */ |
|
603 XAresult XAAudIODevCapaItfImpl_GetDefaultAudioDevices(XAAudioIODeviceCapabilitiesItf self, |
|
604 XAuint32 defaultDeviceID, |
|
605 XAint32 *pNumAudioDevices, |
|
606 XAuint32 *pAudioDeviceIDs) |
|
607 { |
|
608 XAAudIODevCapaItfImpl* impl = GetImpl(self); |
|
609 XAresult res = XA_RESULT_SUCCESS; |
|
610 DEBUG_API("->XAAudIODevCapaItfImpl_GetDefaultAudioDevices"); |
|
611 |
|
612 if( !impl || !pNumAudioDevices ) |
|
613 { |
|
614 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
615 res = XA_RESULT_PARAMETER_INVALID; |
|
616 } |
|
617 else |
|
618 { |
|
619 if(!pAudioDeviceIDs) |
|
620 { |
|
621 switch(defaultDeviceID) |
|
622 { |
|
623 case XA_DEFAULTDEVICEID_AUDIOOUTPUT: |
|
624 *pNumAudioDevices = 1; |
|
625 break; |
|
626 case XA_DEFAULTDEVICEID_AUDIOINPUT : |
|
627 *pNumAudioDevices = 1; |
|
628 break; |
|
629 default: |
|
630 res = XA_RESULT_PARAMETER_INVALID; |
|
631 break; |
|
632 } |
|
633 } |
|
634 else |
|
635 { |
|
636 switch(defaultDeviceID) |
|
637 { |
|
638 case XA_DEFAULTDEVICEID_AUDIOOUTPUT: |
|
639 pAudioDeviceIDs[*pNumAudioDevices - 1] = 0xAD7E5002; |
|
640 break; |
|
641 case XA_DEFAULTDEVICEID_AUDIOINPUT: |
|
642 pAudioDeviceIDs[*pNumAudioDevices - 1] = 0xAD7E5001; |
|
643 break; |
|
644 default: |
|
645 res = XA_RESULT_PARAMETER_INVALID; |
|
646 break; |
|
647 } |
|
648 } |
|
649 |
|
650 } |
|
651 DEBUG_API("<-XAAudIODevCapaItfImpl_GetDefaultAudioDevices"); |
|
652 return res; |
|
653 } |
|
654 |
|
655 /* XAresult XAAudIODevCapaItfImpl_GetAssociatedAudioOutputs |
|
656 * Description: Gets an array of sample formats supported by the audio I/O |
|
657 * device for the given sampling rate. |
|
658 */ |
|
659 XAresult XAAudIODevCapaItfImpl_QuerySampleFormatsSupported( |
|
660 XAAudioIODeviceCapabilitiesItf self, |
|
661 XAuint32 deviceId, |
|
662 XAmilliHertz samplingRate, |
|
663 XAint32* pSampleFormats, |
|
664 XAint32* pNumOfSampleFormats) |
|
665 { |
|
666 XAAudIODevCapaItfImpl* impl = GetImpl(self); |
|
667 XAresult res = XA_RESULT_SUCCESS; |
|
668 DEBUG_API("->XAAudIODevCapaItfImpl_QuerySampleFormatsSupported"); |
|
669 |
|
670 if( !impl || !pNumOfSampleFormats ) |
|
671 { |
|
672 DEBUG_ERR("XA_RESULT_PARAMETER_INVALID"); |
|
673 res = XA_RESULT_PARAMETER_INVALID; |
|
674 } |
|
675 else |
|
676 { |
|
677 #ifdef _GSTREAMER_BACKEND_ |
|
678 XAStaticCapsData temp; |
|
679 res = XAStaticCapsAdapt_GetCapsById(XACAP_DEVSNK|XACAP_AUDIO, |
|
680 deviceId, &temp); |
|
681 /* deviceid can be either input or output*/ |
|
682 if( res == XA_RESULT_FEATURE_UNSUPPORTED ) |
|
683 { |
|
684 res = XAStaticCapsAdapt_GetCapsById(XACAP_DEVSRC|XACAP_AUDIO, |
|
685 deviceId, &temp); |
|
686 } |
|
687 if( res == XA_RESULT_SUCCESS ) |
|
688 { |
|
689 XAuint32 count = 0, i = 0; |
|
690 for (i=0; i < sizeof(temp.pcmProfilesSupported)*8; i++) |
|
691 count+=temp.pcmProfilesSupported>>i&0x1; |
|
692 |
|
693 if(pSampleFormats) |
|
694 { |
|
695 if(*pNumOfSampleFormats<count) |
|
696 { |
|
697 res = XA_RESULT_BUFFER_INSUFFICIENT; |
|
698 } |
|
699 else |
|
700 { |
|
701 XAuint32 insertCount = 0; |
|
702 if (temp.pcmProfilesSupported & XA_ADAPT_PCMSAMPLEFORMAT_SUPPORTED_8) { |
|
703 pSampleFormats[insertCount++] = XA_PCMSAMPLEFORMAT_FIXED_8; } |
|
704 if (temp.pcmProfilesSupported & XA_ADAPT_PCMSAMPLEFORMAT_SUPPORTED_16) { |
|
705 pSampleFormats[insertCount++] = XA_PCMSAMPLEFORMAT_FIXED_16; } |
|
706 if (temp.pcmProfilesSupported & XA_ADAPT_PCMSAMPLEFORMAT_SUPPORTED_20) { |
|
707 pSampleFormats[insertCount++] = XA_PCMSAMPLEFORMAT_FIXED_20; } |
|
708 if (temp.pcmProfilesSupported & XA_ADAPT_PCMSAMPLEFORMAT_SUPPORTED_24) { |
|
709 pSampleFormats[insertCount++] = XA_PCMSAMPLEFORMAT_FIXED_20; } |
|
710 if (temp.pcmProfilesSupported & XA_ADAPT_PCMSAMPLEFORMAT_SUPPORTED_28) { |
|
711 pSampleFormats[insertCount++] = XA_PCMSAMPLEFORMAT_FIXED_20; } |
|
712 if (temp.pcmProfilesSupported & XA_ADAPT_PCMSAMPLEFORMAT_SUPPORTED_32) { |
|
713 pSampleFormats[insertCount++] = XA_PCMSAMPLEFORMAT_FIXED_20; } |
|
714 } |
|
715 } |
|
716 *pNumOfSampleFormats = count; |
|
717 } |
|
718 #endif |
|
719 |
|
720 if(!pSampleFormats) |
|
721 { |
|
722 *pNumOfSampleFormats = 1; |
|
723 } |
|
724 else |
|
725 { |
|
726 pSampleFormats[*pNumOfSampleFormats - 1] = XA_PCMSAMPLEFORMAT_FIXED_16; |
|
727 } |
|
728 |
|
729 } |
|
730 |
|
731 DEBUG_API("<-XAAudIODevCapaItfImpl_QuerySampleFormatsSupported"); |
|
732 return res; |
|
733 } |
|
734 |
|
735 /** |
|
736 * XAAudIODevCapaItfImpl -specific methods |
|
737 **/ |
|
738 |
|
739 /* XAAudIODevCapaItfImpl_Create |
|
740 * Description: Allocate and initialize XAAudIODevCapaItfImpl |
|
741 */ |
|
742 XAAudIODevCapaItfImpl* XAAudIODevCapaItfImpl_Create() |
|
743 { |
|
744 XAAudIODevCapaItfImpl* self = (XAAudIODevCapaItfImpl*) |
|
745 calloc(1,sizeof(XAAudIODevCapaItfImpl)); |
|
746 DEBUG_API("->XAAudIODevCapaItfImpl_Create"); |
|
747 |
|
748 if( self ) |
|
749 { |
|
750 /* init itf default implementation */ |
|
751 self->itf.GetAssociatedAudioInputs = |
|
752 XAAudIODevCapaItfImpl_GetAssociatedAudioInputs; |
|
753 self->itf.GetAssociatedAudioOutputs = |
|
754 XAAudIODevCapaItfImpl_GetAssociatedAudioOutputs; |
|
755 self->itf.GetAvailableAudioInputs = |
|
756 XAAudIODevCapaItfImpl_GetAvailableAudioInputs; |
|
757 self->itf.GetAvailableAudioOutputs = |
|
758 XAAudIODevCapaItfImpl_GetAvailableAudioOutputs; |
|
759 self->itf.QueryAudioInputCapabilities = |
|
760 XAAudIODevCapaItfImpl_QueryAudioInputCapabilities; |
|
761 self->itf.QueryAudioOutputCapabilities = |
|
762 XAAudIODevCapaItfImpl_QueryAudioOutputCapabilities; |
|
763 self->itf.GetDefaultAudioDevices = |
|
764 XAAudIODevCapaItfImpl_GetDefaultAudioDevices; |
|
765 self->itf.QuerySampleFormatsSupported = |
|
766 XAAudIODevCapaItfImpl_QuerySampleFormatsSupported; |
|
767 self->itf.RegisterAvailableAudioInputsChangedCallback = |
|
768 XAAudIODevCapaItfImpl_RegisterAvailableAudioInputsChangedCallback; |
|
769 self->itf.RegisterAvailableAudioOutputsChangedCallback = |
|
770 XAAudIODevCapaItfImpl_RegisterAvailableAudioOutputsChangedCallback; |
|
771 self->itf.RegisterDefaultDeviceIDMapChangedCallback = |
|
772 XAAudIODevCapaItfImpl_RegisterDefaultDeviceIDMapChangedCallback; |
|
773 #ifdef _GSTREAMER_BACKEND_ |
|
774 /* init variables */ |
|
775 assert( XAStaticCapsAdapt_GetCapsCount( XACAP_DEVSNK|XACAP_AUDIO, |
|
776 &(self->numOutputDevices) ) == XA_RESULT_SUCCESS ); |
|
777 assert( XAStaticCapsAdapt_GetCapsCount( XACAP_DEVSRC|XACAP_AUDIO, |
|
778 &(self->numInputDevices) ) == XA_RESULT_SUCCESS ); |
|
779 #endif |
|
780 self->inputCbPtrToSelf = NULL; |
|
781 self->outputCbPtrToSelf = NULL; |
|
782 self->deviceMapCbPtrToSelf = NULL; |
|
783 self->numInputDevices = 1; |
|
784 self->numOutputDevices = 1; |
|
785 self->self = self; |
|
786 } |
|
787 DEBUG_API("<-XAAudIODevCapaItfImpl_Create"); |
|
788 return self; |
|
789 } |
|
790 |
|
791 /* void XAAudIODevCapaItfImpl_Free |
|
792 * Description: Free all resources reserved at XAAudIODevCapaItfImpl_Create |
|
793 */ |
|
794 void XAAudIODevCapaItfImpl_Free(XAAudIODevCapaItfImpl* self) |
|
795 { |
|
796 DEBUG_API("->XAAudIODevCapaItfImpl_Free"); |
|
797 assert(self==self->self); |
|
798 free(self); |
|
799 DEBUG_API("<-XAAudIODevCapaItfImpl_Free"); |
|
800 } |