diff options
Diffstat (limited to 'ahl-binding/ahl-deviceenum.c')
-rw-r--r-- | ahl-binding/ahl-deviceenum.c | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/ahl-binding/ahl-deviceenum.c b/ahl-binding/ahl-deviceenum.c index 7e67d7a..763b2ca 100644 --- a/ahl-binding/ahl-deviceenum.c +++ b/ahl-binding/ahl-deviceenum.c @@ -14,16 +14,9 @@ * limitations under the License. */ -#define _GNU_SOURCE -#include <stdio.h> -#include <string.h> #include <alsa/asoundlib.h> #include <alsa/pcm.h> -#include <json-c/json.h> -#include "wrap-json.h" - #include "ahl-binding.h" -#include "ahl-policy.h" extern AHLCtxT g_AHLCtx; @@ -59,7 +52,7 @@ static int SeparateDomainFromDeviceURI( char * in_pDeviceURI, char ** out_pDomai AFB_ERROR("Error tokenizing device URI -> %s",in_pDeviceURI); return 1; } - return 0; + return AHL_SUCCESS; } static int IsAlsaDomain(const char * in_pDomainStr) @@ -90,7 +83,6 @@ static int FillALSAPCMInfo( snd_pcm_t * in_pPcmHandle, EndpointInfoT * out_pEndp snd_pcm_info_t * pPcmInfo = NULL; int iAlsaRet = 0; const char * pCardName = NULL; - int retVal = 0; snd_ctl_t * ctlHandle = NULL; snd_ctl_card_info_t * ctlInfo = NULL; @@ -121,7 +113,7 @@ static int FillALSAPCMInfo( snd_pcm_t * in_pPcmHandle, EndpointInfoT * out_pEndp if (iAlsaRet < 0) { AFB_WARNING("Error retrieving PCM device info"); - return 1; + return AHL_FAIL; } // get card number @@ -129,7 +121,7 @@ static int FillALSAPCMInfo( snd_pcm_t * in_pPcmHandle, EndpointInfoT * out_pEndp if ( out_pEndpointInfo->alsaInfo.cardNum < 0 ) { AFB_WARNING("No Alsa card number available"); - return 1; + return AHL_FAIL; } // get device number @@ -137,7 +129,7 @@ static int FillALSAPCMInfo( snd_pcm_t * in_pPcmHandle, EndpointInfoT * out_pEndp if ( out_pEndpointInfo->alsaInfo.deviceNum < 0 ) { AFB_WARNING("No Alsa device number available"); - return 1; + return AHL_FAIL; } // get sub-device number @@ -145,7 +137,7 @@ static int FillALSAPCMInfo( snd_pcm_t * in_pPcmHandle, EndpointInfoT * out_pEndp if ( out_pEndpointInfo->alsaInfo.subDeviceNum < 0 ) { AFB_WARNING("No Alsa subdevice number available"); - return 1; + return AHL_FAIL; } char cardName[32]; @@ -154,7 +146,7 @@ static int FillALSAPCMInfo( snd_pcm_t * in_pPcmHandle, EndpointInfoT * out_pEndp if ( iAlsaRet < 0 ) { AFB_WARNING("Could not open ALSA card control"); - return 1; + return AHL_FAIL; } iAlsaRet = snd_ctl_card_info(ctlHandle, ctlInfo); @@ -162,7 +154,7 @@ static int FillALSAPCMInfo( snd_pcm_t * in_pPcmHandle, EndpointInfoT * out_pEndp { AFB_WARNING("Could not retrieve ALSA card info"); snd_ctl_close(ctlHandle); - return 1; + return AHL_FAIL; } // Populate unique target card name @@ -171,13 +163,13 @@ static int FillALSAPCMInfo( snd_pcm_t * in_pPcmHandle, EndpointInfoT * out_pEndp { AFB_WARNING("No Alsa card name available"); snd_ctl_close(ctlHandle); - return 1; + return AHL_FAIL; } - out_pEndpointInfo->gsDeviceName = g_strdup(pCardName); + g_strlcpy(out_pEndpointInfo->gsDeviceName,pCardName,AHL_STR_MAX_LENGTH); snd_ctl_close(ctlHandle); - return retVal; + return AHL_SUCCESS; } EndpointInfoT * InitEndpointInfo() @@ -193,6 +185,20 @@ EndpointInfoT * InitEndpointInfo() pEndpointInfo->format.sampleRate = AHL_UNDEFINED; pEndpointInfo->format.numChannels = AHL_UNDEFINED; pEndpointInfo->format.sampleType = AHL_FORMAT_UNKNOWN; + // Assigned by device enumeration + pEndpointInfo->gsDeviceName = malloc(AHL_STR_MAX_LENGTH*sizeof(char)); + memset(pEndpointInfo->gsDeviceName,0,AHL_STR_MAX_LENGTH*sizeof(char)); + pEndpointInfo->gsDeviceDomain = malloc(AHL_STR_MAX_LENGTH*sizeof(char)); + memset(pEndpointInfo->gsDeviceDomain,0,AHL_STR_MAX_LENGTH*sizeof(char)); + pEndpointInfo->pRoleName = malloc(AHL_STR_MAX_LENGTH*sizeof(char)); + memset(pEndpointInfo->pRoleName,0,AHL_STR_MAX_LENGTH*sizeof(char)); + pEndpointInfo->gsDeviceURI = malloc(AHL_STR_MAX_LENGTH*sizeof(char)); + memset(pEndpointInfo->gsDeviceURI,0,AHL_STR_MAX_LENGTH*sizeof(char)); + // Assigned by policy initialization + pEndpointInfo->gsDisplayName = malloc(AHL_STR_MAX_LENGTH*sizeof(char)); + memset(pEndpointInfo->gsDisplayName,0,AHL_STR_MAX_LENGTH*sizeof(char)); + pEndpointInfo->gsHALAPIName = malloc(AHL_STR_MAX_LENGTH*sizeof(char)); + memset(pEndpointInfo->gsHALAPIName,0,AHL_STR_MAX_LENGTH*sizeof(char)); pEndpointInfo->pPropTable = g_hash_table_new(g_str_hash, g_str_equal); return pEndpointInfo; } @@ -200,12 +206,12 @@ EndpointInfoT * InitEndpointInfo() void TermEndpointInfo( EndpointInfoT * out_pEndpointInfo ) { #define SAFE_FREE(__ptr__) if(__ptr__) g_free(__ptr__); __ptr__ = NULL; - SAFE_FREE(out_pEndpointInfo->gsDeviceName); - SAFE_FREE(out_pEndpointInfo->gsDisplayName); + SAFE_FREE(out_pEndpointInfo->gsDeviceName); SAFE_FREE(out_pEndpointInfo->gsDeviceDomain); SAFE_FREE(out_pEndpointInfo->pRoleName); SAFE_FREE(out_pEndpointInfo->gsDeviceURI); SAFE_FREE(out_pEndpointInfo->gsHALAPIName); + SAFE_FREE(out_pEndpointInfo->gsDisplayName); if (out_pEndpointInfo->pPropTable) { // Free json_object for all property values @@ -236,7 +242,7 @@ int EnumerateDevices(json_object * in_jDeviceArray, char * in_pAudioRole, Endpoi char * pDeviceURIDomain = NULL; char * pFullDeviceURI = NULL; char * pDeviceURIPCM = NULL; - int err = 0; + int err = AHL_SUCCESS; json_object * jDevice = json_object_array_get_idx(in_jDeviceArray,i); if (jDevice == NULL) { @@ -258,10 +264,10 @@ int EnumerateDevices(json_object * in_jDeviceArray, char * in_pAudioRole, Endpoi // non ALSA URI are simply passed to application (no validation) at this time // In Non ALSA case devices in config are assumed to be available, if not application can fallback on explicit device selection - pEndpointInfo->gsDeviceName = g_strdup(pDeviceURIPCM); - pEndpointInfo->gsDeviceDomain = g_strdup(pDeviceURIDomain); - pEndpointInfo->gsDeviceURI = g_strdup(pDeviceURIPCM); - pEndpointInfo->pRoleName = g_strdup(in_pAudioRole); + g_strlcpy(pEndpointInfo->gsDeviceName,pDeviceURIPCM,AHL_STR_MAX_LENGTH); + g_strlcpy(pEndpointInfo->gsDeviceDomain,pDeviceURIDomain,AHL_STR_MAX_LENGTH); + g_strlcpy(pEndpointInfo->gsDeviceURI,pDeviceURIPCM,AHL_STR_MAX_LENGTH); + g_strlcpy(pEndpointInfo->pRoleName ,in_pAudioRole,AHL_STR_MAX_LENGTH); g_free(pFullDeviceURICopy); pFullDeviceURICopy = NULL; @@ -315,11 +321,6 @@ int EnumerateDevices(json_object * in_jDeviceArray, char * in_pAudioRole, Endpoi pEndpointInfo->endpointID = in_deviceType == ENDPOINTTYPE_SOURCE ? CreateNewSourceID() : CreateNewSinkID(); pEndpointInfo->type = in_deviceType; - // Assigned by policy initialization - pEndpointInfo->gsDisplayName = malloc(AHL_STR_MAX_LENGTH*sizeof(char)); - memset(pEndpointInfo->gsDisplayName,0,AHL_STR_MAX_LENGTH*sizeof(char)); - pEndpointInfo->gsHALAPIName = malloc(AHL_STR_MAX_LENGTH*sizeof(char)); - memset(pEndpointInfo->gsDisplayName,0,AHL_STR_MAX_LENGTH*sizeof(char)); // add to structure to list of available devices g_ptr_array_add(out_pEndpointArray, pEndpointInfo); @@ -327,5 +328,5 @@ int EnumerateDevices(json_object * in_jDeviceArray, char * in_pAudioRole, Endpoi } // for all devices AFB_DEBUG ("Audio high-level - Enumerate devices done"); - return 0; + return AHL_SUCCESS; }
\ No newline at end of file |