summaryrefslogtreecommitdiffstats
path: root/plugins/alsa/alsa-core-pcm.c
diff options
context:
space:
mode:
authorStephane Desneux <stephane.desneux@iot.bzh>2018-12-22 11:51:54 +0100
committerStephane Desneux <stephane.desneux@iot.bzh>2018-12-22 11:51:54 +0100
commitc85fd2f131c73e8c21e05e1ea80b55d6a787dda6 (patch)
tree248aca4a75556e3546a3c89cac43bcffe3ccf634 /plugins/alsa/alsa-core-pcm.c
parente0f57e523112e1bc73a04e8615d7a21355f0ce0e (diff)
Implemented the bug cleanup at application exit
Fixes most memory leaks in softmixer. The concept of 'transaction' for dynamic streams has been generalized to the objects created at startup. The cleanup is done via a handle set through a atexit() call. Also added a missing strdup in alsa-api-loop, that fixes a double free. Warning, the bluez-alsa PCM are not closed in this version. This is intentional due to a BUG in the bluealsa ioplug PCM, that crashes upon close (pthread_cancel is used to terminate the io_thread and things get very bad. I have a pending fix for that, relying on a cancellation pipe, but deeper testing must be done). As an effect, only one phone call can be made, else 4a needs to be restarted Change-Id: Idb84cafe15f17c0ef02fcc70296d541dc55a2dcf Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh> Signed-off-by: Stephane Desneux <stephane.desneux@iot.bzh>
Diffstat (limited to 'plugins/alsa/alsa-core-pcm.c')
-rw-r--r--plugins/alsa/alsa-core-pcm.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/plugins/alsa/alsa-core-pcm.c b/plugins/alsa/alsa-core-pcm.c
index adceebc..a45d463 100644
--- a/plugins/alsa/alsa-core-pcm.c
+++ b/plugins/alsa/alsa-core-pcm.c
@@ -29,6 +29,9 @@ for the specific language governing permissions and
#include <sys/syscall.h>
#include <sched.h>
+#include <signal.h>
+#include <poll.h>
+
#include "time_utils.h"
static int xrun(snd_pcm_t * pcm, int error);
@@ -127,7 +130,7 @@ PUBLIC int AlsaPcmConf(SoftMixerT *mixer, AlsaPcmCtlT *pcm, int mode) {
if ((error = snd_pcm_hw_params_set_format(pcm->handle, pxmHwParams, opts->format)) < 0) {
AFB_ApiError(mixer->api,
"%s (%s) mixer=%s Set_Format=%s (%d) FAILED current=%d error=%s",
- __func__, card, mixer->uid, opts->formatS, opts->format, format, snd_strerror(error));
+ __func__, card, mixer->uid, opts->formatString, opts->format, format, snd_strerror(error));
AlsaDumpFormats(mixer, pcm->handle);
goto OnErrorExit;
}
@@ -483,6 +486,7 @@ static void *readThreadEntry(void *handle) {
if (muted)
readSuspend(pcmCopyHandle);
+
/* loop until end */
for (;;) {
@@ -531,7 +535,7 @@ static void *readThreadEntry(void *handle) {
continue;
}
- unsigned short revents;
+ unsigned short revents = 0;
int res = snd_pcm_poll_descriptors_revents(pcmCopyHandle->pcmIn->handle, framePfds, pcmCopyHandle->nbPcmFds, &revents);
@@ -549,6 +553,7 @@ static void *readThreadEntry(void *handle) {
}
done:
pthread_exit(0);
+
return NULL;
}
@@ -689,9 +694,14 @@ PUBLIC int AlsaPcmCopyStop(SoftMixerT *mixer, AlsaPcmCopyHandleT * handle) {
if (pthread_join(handle->rthread, NULL) != 0)
AFB_ApiDebug(mixer->api, "%s: Failed to join read thread", __func__);
+ AFB_ApiDebug(mixer->api, "%s: Copy threads of %s are STOPPED", __func__, handle->stream->uid);
+
sem_destroy(&handle->sem);
- AFB_ApiDebug(mixer->api, "%s: Copy threads of %s are STOPPED", __func__, handle->stream->uid);
+ alsa_ringbuf_free(handle->rbuf);
+
+ free(handle->pollFds);
+ free(handle);
return 0;
@@ -709,9 +719,17 @@ PUBLIC int AlsaPcmCopyStart(SoftMixerT *mixer, AlsaStreamAudioT *stream, AlsaPcm
/* remember configuration of capture */
pcmIn->params = (AlsaPcmHwInfoT*)malloc(sizeof(AlsaPcmHwInfoT));
+ if (!pcmIn->params) {
+ SOFTMIXER_NOMEM(mixer->api);
+ goto OnErrorExit;
+ }
memcpy(pcmIn->params, opts, sizeof(AlsaPcmHwInfoT));
pcmOut->params = (AlsaPcmHwInfoT*)malloc(sizeof(AlsaPcmHwInfoT));
+ if (!pcmOut->params) {
+ SOFTMIXER_NOMEM(mixer->api);
+ goto OnErrorExit;
+ }
memcpy(pcmOut->params, opts, sizeof(AlsaPcmHwInfoT));
pcmIn->mixer = mixer;