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