diff options
Diffstat (limited to 'plugins/alsa/alsa-api-pcm.c')
-rw-r--r-- | plugins/alsa/alsa-api-pcm.c | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/plugins/alsa/alsa-api-pcm.c b/plugins/alsa/alsa-api-pcm.c index 85e3c3a..036f158 100644 --- a/plugins/alsa/alsa-api-pcm.c +++ b/plugins/alsa/alsa-api-pcm.c @@ -372,11 +372,23 @@ OnErrorExit: return; } +PUBLIC AlsaPcmHwInfoT* ApiPcmParamsDup(SoftMixerT* mixer, AlsaPcmHwInfoT* params) { + AlsaPcmHwInfoT* _params = (AlsaPcmHwInfoT*) malloc(sizeof(AlsaPcmHwInfoT)); + if (params) + memcpy(_params, params, sizeof(AlsaPcmHwInfoT)); + return _params; +} + PUBLIC void ApiPcmDelParams(SoftMixerT* mixer, AlsaPcmHwInfoT* params) { - free((char*)params->formatS); free(params); } +PUBLIC void ApiPcmParamsShow(SoftMixerT * mixer, const char *msg, const AlsaPcmHwInfoT * params) { + AFB_ApiInfo(mixer->api, "%s PARAMS: rate=%d, format=%d, formatString=%s", + msg, params->rate, params->format, params->formatString); + +} + PUBLIC AlsaPcmHwInfoT * ApiPcmSetParams(SoftMixerT *mixer, const char *uid, json_object * paramsJ) { const char *format = NULL, *access = NULL; @@ -404,20 +416,14 @@ PUBLIC AlsaPcmHwInfoT * ApiPcmSetParams(SoftMixerT *mixer, const char *uid, json } } + // default format if (!format) { params->format = SND_PCM_FORMAT_S16_LE; - params->formatS = strdup("S16_LE"); - if (params->formatS == NULL) { - SOFTMIXER_NOMEM(mixer->api); - goto fail_params; - } + strcpy(params->formatString, SND_FORMAT_DEFAULT); goto check_access; } - params->formatS = strdup(format); - if (params->formatS == NULL) { - SOFTMIXER_NOMEM(mixer->api); - goto fail_params; - } + strncpy(params->formatString, format, SND_FORMAT_STRING_LEN); + #define FORMAT_CHECK(arg) if (!strcmp(format,#arg)) { params->format = SND_PCM_FORMAT_##arg; goto check_access; } FORMAT_CHECK(S16_LE); @@ -441,7 +447,7 @@ PUBLIC AlsaPcmHwInfoT * ApiPcmSetParams(SoftMixerT *mixer, const char *uid, json goto fail_params; check_access: - AFB_ApiNotice(mixer->api, "%s: %s format set to SND_PCM_FORMAT_%s", __func__, uid, params->formatS); + AFB_ApiNotice(mixer->api, "%s: %s format set to SND_PCM_FORMAT_%s", __func__, uid, params->formatString); #define ACCESS_CHECK(arg) if (!strcmp(access,#arg)) { params->access = SND_PCM_ACCESS_##arg; goto success;} @@ -466,33 +472,33 @@ success: return params; fail_params: - free(params); + ApiPcmDelParams(mixer, params); fail: return NULL; } static void pcmChannelsDestroy(SoftMixerT * mixer, AlsaSndPcmT * pcm) { - AFB_ApiDebug(mixer->api, "%s: pcm %s (%d channels)", __func__, pcm->uid, pcm->nbChannels); + AFB_ApiDebug(mixer->api, "\t%s: pcm %s (%d channels)", __func__, pcm->uid, pcm->nbChannels); AlsaPcmChannelT * channel, *tmp; cds_list_for_each_entry_safe(channel, tmp, &pcm->channels.list, list) { cds_list_del(&channel->list); - AFB_ApiDebug(mixer->api, "%s: del channel %s", __func__, channel->uid); free((char *)channel->uid); free(channel); } - AFB_ApiDebug(mixer->api, "%s: pcm %s DONE", __func__, pcm->uid); + AFB_ApiDebug(mixer->api, "\t%s: pcm %s DONE", __func__, pcm->uid); } PUBLIC void ApiPcmDelete(SoftMixerT * mixer, AlsaSndPcmT * pcm) { - AFB_ApiDebug(mixer->api, "%s: pcm %s", __func__, pcm->uid); + AFB_ApiDebug(mixer->api, "%s: pcm %s\n", __func__, pcm->uid); free(pcm->apiVerbHandle); AlsaSndCtlT * card = pcm->sndcard; - if (card->cid.pcmplug_params) + if (card->cid.pcmplug_params) { free((char*)card->cid.pcmplug_params); + } pcmChannelsDestroy(mixer, pcm); @@ -503,10 +509,11 @@ PUBLIC void ApiPcmDelete(SoftMixerT * mixer, AlsaSndPcmT * pcm) { if (pcm->verb && (strcmp(pcm->verb, SOFTMIXER_VERB_NONE)!=0)) { - int error = afb_api_del_verb(mixer->api, pcm->verb, (void**)&pcm->apiVerbHandle); + int error = afb_api_del_verb(mixer->api, pcm->verb, (void**)NULL); if (error) { AFB_ApiError(mixer->api, "Failed to remove verb %s", pcm->verb); } + free((char*)pcm->verb); } free((char*)pcm->uid); |