aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/alsa/alsa-api-pcm.c16
-rw-r--r--plugins/alsa/alsa-api-sink.c13
-rw-r--r--plugins/alsa/alsa-api-streams.c49
-rw-r--r--plugins/alsa/alsa-plug-route.c13
-rw-r--r--plugins/alsa/alsa-plug-vol.c7
-rw-r--r--plugins/alsa/alsa-utils-bypath.c23
6 files changed, 84 insertions, 37 deletions
diff --git a/plugins/alsa/alsa-api-pcm.c b/plugins/alsa/alsa-api-pcm.c
index 084b54b..d67433e 100644
--- a/plugins/alsa/alsa-api-pcm.c
+++ b/plugins/alsa/alsa-api-pcm.c
@@ -417,6 +417,7 @@ OnErrorExit:
PUBLIC AlsaSndPcmT * ApiPcmAttachOne(SoftMixerT *mixer, const char *uid, snd_pcm_stream_t direction, json_object * argsJ) {
AlsaSndPcmT *pcm = calloc(1, sizeof (AlsaSndPcmT));
json_object *sourceJ = NULL, *paramsJ = NULL, *sinkJ = NULL, *targetJ = NULL;
+ char *apiVerb = NULL, *apiInfo = NULL;
int error;
pcm->sndcard = (AlsaSndCtlT*) calloc(1, sizeof (AlsaSndCtlT));
@@ -518,13 +519,16 @@ PUBLIC AlsaSndPcmT * ApiPcmAttachOne(SoftMixerT *mixer, const char *uid, snd_pcm
if (error) goto OnErrorExit;
// create master control for this sink
- char *apiVerb, *apiInfo;
if (direction == SND_PCM_STREAM_PLAYBACK) {
- (void) asprintf(&apiVerb, "%s:playback", pcm->uid);
- (void) asprintf(&apiInfo, "HAL:%s SND_PCM_STREAM_PLAYBACK", uid);
+ if (asprintf(&apiVerb, "%s:playback", pcm->uid) == -1)
+ goto OnErrorExit;
+ if (asprintf(&apiInfo, "HAL:%s SND_PCM_STREAM_PLAYBACK", uid) == -1)
+ goto OnErrorExit;
} else {
- (void) asprintf(&apiVerb, "%s:capture", pcm->uid);
- (void) asprintf(&apiInfo, "HAL:%s SND_PCM_STREAM_PLAYBACK", uid);
+ if (asprintf(&apiVerb, "%s:capture", pcm->uid) == -1)
+ goto OnErrorExit;
+ if (asprintf(&apiInfo, "HAL:%s SND_PCM_STREAM_PLAYBACK", uid) == -1)
+ goto OnErrorExit;
}
apiVerbHandleT *handle = calloc(1, sizeof (apiVerbHandleT));
@@ -546,6 +550,8 @@ PUBLIC AlsaSndPcmT * ApiPcmAttachOne(SoftMixerT *mixer, const char *uid, snd_pcm
OnErrorExit:
free(pcm);
+ free(apiVerb);
+ free(apiInfo);
return NULL;
}
diff --git a/plugins/alsa/alsa-api-sink.c b/plugins/alsa/alsa-api-sink.c
index e38621a..c8f9f9d 100644
--- a/plugins/alsa/alsa-api-sink.c
+++ b/plugins/alsa/alsa-api-sink.c
@@ -55,6 +55,8 @@ PUBLIC AlsaSndPcmT *ApiSinkGetByUid(SoftMixerT *mixer, const char *target) {
PUBLIC int ApiSinkAttach(SoftMixerT *mixer, AFB_ReqT request, const char *uid, json_object * argsJ) {
int index;
+ char *dmixUid = NULL;
+
for (index = 0; index < mixer->max.sinks; index++) {
if (!mixer->sinks[index]) break;
}
@@ -66,7 +68,7 @@ PUBLIC int ApiSinkAttach(SoftMixerT *mixer, AFB_ReqT request, const char *uid, j
switch (json_object_get_type(argsJ)) {
long count;
- char *dmixUid;
+
AlsaPcmCtlT* dmixConfig;
case json_type_object:
@@ -77,7 +79,8 @@ PUBLIC int ApiSinkAttach(SoftMixerT *mixer, AFB_ReqT request, const char *uid, j
}
// move from hardware to DMIX attach to sndcard
- (void) asprintf(&dmixUid, "dmix-%s", mixer->sinks[index]->uid);
+ if (asprintf(&dmixUid, "dmix-%s", mixer->sinks[index]->uid) == -1)
+ goto OnErrorExit;
dmixConfig = AlsaCreateDmix(mixer, dmixUid, mixer->sinks[index], 0);
if (!dmixConfig) {
@@ -103,7 +106,8 @@ PUBLIC int ApiSinkAttach(SoftMixerT *mixer, AFB_ReqT request, const char *uid, j
}
// move from hardware to DMIX attach to sndcard
- (void) asprintf(&dmixUid, "dmix-%s", mixer->sinks[index]->uid);
+ if (asprintf(&dmixUid, "dmix-%s", mixer->sinks[index]->uid) == -1)
+ goto OnErrorExit;
dmixConfig = AlsaCreateDmix(mixer, dmixUid, mixer->sinks[index], 0);
if (!dmixConfig) {
@@ -120,5 +124,6 @@ PUBLIC int ApiSinkAttach(SoftMixerT *mixer, AFB_ReqT request, const char *uid, j
return 0;
OnErrorExit:
+ free(dmixUid);
return -1;
-} \ No newline at end of file
+}
diff --git a/plugins/alsa/alsa-api-streams.c b/plugins/alsa/alsa-api-streams.c
index e11affe..3538426 100644
--- a/plugins/alsa/alsa-api-streams.c
+++ b/plugins/alsa/alsa-api-streams.c
@@ -189,8 +189,10 @@ STATIC int CreateOneStream(SoftMixerT *mixer, const char * uid, AlsaStreamAudioT
AlsaDevInfoT *captureDev = alloca(sizeof (AlsaDevInfoT));
AlsaLoopSubdevT *loopDev;
AlsaSndZoneT *zone;
- char *volSlaveId;
- char *captureName;
+ char *volSlaveId = NULL;
+ char *captureName = NULL;
+ char *runName = NULL;
+ char *volName = NULL;
loopDev = ApiLoopFindSubdev(mixer, stream->uid, stream->source, &loop);
if (loopDev) {
@@ -236,7 +238,8 @@ STATIC int CreateOneStream(SoftMixerT *mixer, const char * uid, AlsaStreamAudioT
}
// route PCM should have been create during zones attach phase.
- (void) asprintf(&volSlaveId, "route-%s", zone->uid);
+ if (asprintf(&volSlaveId, "route-%s", zone->uid) == -1)
+ goto OnErrorExit;
} else {
AlsaSndPcmT *playback = ApiSinkGetByUid(mixer, stream->sink);
@@ -246,7 +249,8 @@ STATIC int CreateOneStream(SoftMixerT *mixer, const char * uid, AlsaStreamAudioT
}
// retrieve channel count from route and push it to stream
- (void) asprintf(&volSlaveId, "dmix-%s", playback->uid);
+ if (asprintf(&volSlaveId, "dmix-%s", playback->uid) == -1)
+ goto OnErrorExit;
// create a fake zone for rate converter selection
zone=alloca(sizeof(AlsaSndZoneT));
@@ -259,8 +263,9 @@ STATIC int CreateOneStream(SoftMixerT *mixer, const char * uid, AlsaStreamAudioT
stream->params->channels = zone->ccount;
// create mute control and Registry it as pause/resume ctl)
- char *runName;
- (void) asprintf(&runName, "pause-%s", stream->uid);
+ if (asprintf(&runName, "pause-%s", stream->uid) == -1)
+ goto OnErrorExit;
+
int pauseNumid = AlsaCtlCreateControl(mixer, captureCard, runName, 1, 0, 1, 1, stream->mute);
if (pauseNumid <= 0) goto OnErrorExit;
@@ -268,9 +273,8 @@ STATIC int CreateOneStream(SoftMixerT *mixer, const char * uid, AlsaStreamAudioT
error = AlsaCtlRegister(mixer, captureCard, capturePcm, FONTEND_NUMID_PAUSE, pauseNumid);
if (error) goto OnErrorExit;
-
- char *volName;
- (void) asprintf(&volName, "vol-%s", stream->uid);
+ if (asprintf(&volName, "vol-%s", stream->uid) == -1)
+ goto OnErrorExit;
// create stream and delay pcm opening until vol control is created
streamPcm = AlsaCreateSoftvol(mixer, stream, volSlaveId, captureCard, volName, VOL_CONTROL_MAX, 0);
@@ -285,7 +289,8 @@ STATIC int CreateOneStream(SoftMixerT *mixer, const char * uid, AlsaStreamAudioT
if ((zone->params->rate != stream->params->rate) || (zone->params->format != stream->params->format)) {
char *rateName;
- (void) asprintf(&rateName, "rate-%s", stream->uid);
+ if (asprintf(&rateName, "rate-%s", stream->uid) == -1)
+ goto OnErrorExit;
streamPcm = AlsaCreateRate(mixer, rateName, streamPcm, zone->params, 0);
if (!streamPcm) {
AFB_ApiError(mixer->api, "StreamsAttach: mixer=%s stream=%s fail to create rate converter", mixer->uid, stream->uid);
@@ -323,9 +328,11 @@ STATIC int CreateOneStream(SoftMixerT *mixer, const char * uid, AlsaStreamAudioT
}
if (loop) {
- (void) asprintf((char**) &stream->source, "hw:%d,%d,%d", captureDev->cardidx, loop->playback, capturePcm->cid.subdev);
+ if (asprintf((char**) &stream->source, "hw:%d,%d,%d", captureDev->cardidx, loop->playback, capturePcm->cid.subdev))
+ goto OnErrorExit;
} else {
- (void) asprintf((char**) &stream->source, "hw:%d,%d,%d", captureDev->cardidx, captureDev->device, captureDev->subdev);
+ if (asprintf((char**) &stream->source, "hw:%d,%d,%d", captureDev->cardidx, captureDev->device, captureDev->subdev))
+ goto OnErrorExit;
}
// create a dedicated verb for this stream
@@ -355,6 +362,9 @@ STATIC int CreateOneStream(SoftMixerT *mixer, const char * uid, AlsaStreamAudioT
return 0;
OnErrorExit:
+ free(volSlaveId);
+ free(runName);
+ free(volName);
return -1;
}
@@ -398,10 +408,17 @@ STATIC AlsaStreamAudioT * AttachOneStream(SoftMixerT *mixer, const char *uid, co
// Prefix verb with uid|prefix
if (prefix) {
- if (stream->verb) asprintf((char**) &stream->verb, "%s:%s", prefix, stream->verb);
- else asprintf((char**) &stream->verb, "%s:%s", prefix, stream->uid);
+ if (stream->verb) {
+ if (asprintf((char**) &stream->verb, "%s:%s", prefix, stream->verb) == -1)
+ goto OnErrorExit;
+ }
+ else {
+ if (asprintf((char**) &stream->verb, "%s:%s", prefix, stream->uid) == -1)
+ goto OnErrorExit;
+ }
} else {
- if (!stream->verb) stream->verb = strdup(stream->uid);
+ if (!stream->verb)
+ stream->verb = strdup(stream->uid);
}
// implement stream PCM with corresponding thread and controls
@@ -433,7 +450,7 @@ PUBLIC int ApiStreamAttach(SoftMixerT *mixer, AFB_ReqT request, const char *uid,
}
switch (json_object_get_type(argsJ)) {
- long count;
+ long count;
case json_type_object:
mixer->streams[index] = AttachOneStream(mixer, uid, prefix, argsJ);
diff --git a/plugins/alsa/alsa-plug-route.c b/plugins/alsa/alsa-plug-route.c
index 306ddeb..a225983 100644
--- a/plugins/alsa/alsa-plug-route.c
+++ b/plugins/alsa/alsa-plug-route.c
@@ -70,14 +70,17 @@ PUBLIC AlsaPcmCtlT* AlsaCreateRoute(SoftMixerT *mixer, AlsaSndZoneT *zone, int o
int scount=0, error = 0;
ChannelCardPortT slave, channel;
AlsaPcmCtlT *pcmRoute = calloc(1, sizeof (AlsaPcmCtlT));
+ char *cardid = NULL;
+ char *dmixUid = NULL;
if (!mixer->sinks) {
AFB_ApiError(mixer->api, "AlsaCreateRoute: mixer=%s zone(%s)(zone) No sink found [should Registry sound card first]", mixer->uid, zone->uid);
goto OnErrorExit;
}
- char *cardid;
- (void) asprintf(&cardid, "route-%s", zone->uid);
+ if (asprintf(&cardid, "route-%s", zone->uid) == -1)
+ goto OnErrorExit;
+
pcmRoute->cid.cardid = (const char *) cardid;
pcmRoute->params = ApiSinkGetParamsByZone(mixer, zone->uid);
@@ -91,8 +94,8 @@ PUBLIC AlsaPcmCtlT* AlsaCreateRoute(SoftMixerT *mixer, AlsaSndZoneT *zone, int o
}
// move from hardware to DMIX attach to sndcard
- char *dmixUid;
- (void) asprintf(&dmixUid, "dmix-%s", slave.uid);
+ if (asprintf(&dmixUid, "dmix-%s", slave.uid) == -1)
+ goto OnErrorExit;
// temporary store to unable multiple channel to route to the same port
snd_config_t **cports = alloca(slave.ccount * sizeof (void*));
@@ -177,6 +180,8 @@ PUBLIC AlsaPcmCtlT* AlsaCreateRoute(SoftMixerT *mixer, AlsaSndZoneT *zone, int o
OnErrorExit:
free(pcmRoute);
+ free(cardid);
+ free(dmixUid);
AlsaDumpCtlConfig(mixer, "plug-pcm", snd_config, 1);
AlsaDumpCtlConfig(mixer, "plug-route", routeConfig, 1);
AFB_ApiNotice(mixer->api, "AlsaCreateRoute:zone(%s) OnErrorExit\n", zone->uid);
diff --git a/plugins/alsa/alsa-plug-vol.c b/plugins/alsa/alsa-plug-vol.c
index 968ae73..54f3c6d 100644
--- a/plugins/alsa/alsa-plug-vol.c
+++ b/plugins/alsa/alsa-plug-vol.c
@@ -27,8 +27,10 @@ PUBLIC AlsaPcmCtlT *AlsaCreateSoftvol(SoftMixerT *mixer, AlsaStreamAudioT *strea
AlsaPcmCtlT *pcmVol= calloc(1,sizeof(AlsaPcmCtlT));
int error = 0;
- char *cardid;
- (void) asprintf(&cardid, "softvol-%s", stream->uid);
+ char *cardid = NULL;
+ if (asprintf(&cardid, "softvol-%s", stream->uid) == -1)
+ goto OnErrorExit;
+
pcmVol->cid.cardid = (const char *) cardid;
// refresh global alsalib config and create PCM top config
@@ -80,6 +82,7 @@ PUBLIC AlsaPcmCtlT *AlsaCreateSoftvol(SoftMixerT *mixer, AlsaStreamAudioT *strea
return pcmVol;
OnErrorExit:
+ free(cardid);
//AlsaDumpCtlConfig (mixer, "plug-config", pcmConfig, 1);
AlsaDumpCtlConfig(mixer, "plug-softvol", streamConfig, 1);
AFB_ApiNotice(mixer->api, "AlsaCreateSoftvol:%s(stream) OnErrorExit\n", stream->uid);
diff --git a/plugins/alsa/alsa-utils-bypath.c b/plugins/alsa/alsa-utils-bypath.c
index c5c80ce..2dac0d8 100644
--- a/plugins/alsa/alsa-utils-bypath.c
+++ b/plugins/alsa/alsa-utils-bypath.c
@@ -61,13 +61,22 @@ OnErrorExit:
PUBLIC AlsaPcmCtlT *AlsaByPathOpenPcm(SoftMixerT *mixer, AlsaDevInfoT *pcmDev, snd_pcm_stream_t direction) {
int error;
AlsaPcmCtlT *pcmCtl = calloc(1, sizeof (AlsaPcmCtlT));
+ char *cardid = NULL;
if (!pcmDev->cardid) {
- char *cardid;
- if (pcmDev->subdev) (void)asprintf(&cardid, "hw:%i,%i,%i", pcmDev->cardidx, pcmDev->device, pcmDev->subdev);
- else if (pcmDev->device) (void) asprintf(&cardid, "hw:%i,%i", pcmDev->cardidx, pcmDev->device);
- else (void) asprintf(&cardid, "hw:%i", pcmDev->cardidx);
- pcmDev->cardid= (const char*)cardid;
+ if (pcmDev->subdev) {
+ if (asprintf(&cardid, "hw:%i,%i,%i", pcmDev->cardidx, pcmDev->device, pcmDev->subdev) == -1)
+ goto OnErrorExit;
+ }
+ else if (pcmDev->device) {
+ if (asprintf(&cardid, "hw:%i,%i", pcmDev->cardidx, pcmDev->device) == -1)
+ goto OnErrorExit;
+ }
+ else {
+ if (asprintf(&cardid, "hw:%i", pcmDev->cardidx) == -1)
+ goto OnErrorExit;
+ }
+ pcmDev->cardid = (const char*)cardid;
}
// inherit CID fropm pcmDev
@@ -89,6 +98,7 @@ PUBLIC AlsaPcmCtlT *AlsaByPathOpenPcm(SoftMixerT *mixer, AlsaDevInfoT *pcmDev, s
OnErrorExit:
free(pcmCtl);
+ free(cardid);
return NULL;
}
@@ -116,7 +126,8 @@ PUBLIC snd_ctl_t *AlsaByPathOpenCtl(SoftMixerT *mixer, const char *uid, AlsaSndC
dev->cid.longname = strdup(snd_ctl_card_info_get_longname(cardInfo));
// build a valid name and open sndcard
- (void) asprintf((char**) &dev->cid.cardid, "hw:%i", dev->cid.cardidx);
+ if (asprintf((char**) &dev->cid.cardid, "hw:%i", dev->cid.cardidx) == -1)
+ goto OnErrorExit;
if ((err = snd_ctl_open(&handle, dev->cid.cardid, 0)) < 0) {
AFB_ApiError(mixer->api, "AlsaByPathOpenCtl uid=%s sndcard open fail cardid=%s longname=%s error=%s", uid, dev->cid.cardid, dev->cid.longname, snd_strerror(err));