summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2018-11-08 14:05:30 +0100
committerThierry Bultel <thierry.bultel@iot.bzh>2018-11-13 14:41:17 +0100
commit7ba2e9583a67d0c3efd633f7b2140cb5d13066bd (patch)
tree4888c4b1a618a291246081e095e83153cd7226f5 /plugins
parent109036431c4bde92c67105a6044616a4c035d82c (diff)
remove dead code and renamed unobvious variables
Changed the ringbuffer "xxx_free" function to something more explicit, because it does not free anything. Changed "single letter" variables to nicer names Change-Id: I000c57aa5cc684d387105441889e011a45a6ccf3 Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/alsa/alsa-api-mixer.c4
-rw-r--r--plugins/alsa/alsa-bluez.c2
-rw-r--r--plugins/alsa/alsa-bluez.h2
-rw-r--r--plugins/alsa/alsa-core-pcm.c80
-rw-r--r--plugins/alsa/alsa-ringbuf.c2
-rw-r--r--plugins/alsa/alsa-ringbuf.h2
6 files changed, 41 insertions, 51 deletions
diff --git a/plugins/alsa/alsa-api-mixer.c b/plugins/alsa/alsa-api-mixer.c
index f8222df..171046b 100644
--- a/plugins/alsa/alsa-api-mixer.c
+++ b/plugins/alsa/alsa-api-mixer.c
@@ -664,8 +664,8 @@ static void MixerBluezAlsaDevVerb(AFB_ReqT request) {
}
parsed:
- printf("%s: interface %s, device %s, profile %s\n", __func__, interface, device, profile);
- error = alsa_bluez_set_device(interface, device, profile);
+ AFB_ApiNotice(mixer->api, "%s: interface %s, device %s, profile %s\n", __func__, interface, device, profile);
+ error = alsa_bluez_set_remote_device(interface, device, profile);
if (error) {
AFB_ReqFailF(request,
"runtime error",
diff --git a/plugins/alsa/alsa-bluez.c b/plugins/alsa/alsa-bluez.c
index 53612df..080c3c8 100644
--- a/plugins/alsa/alsa-bluez.c
+++ b/plugins/alsa/alsa-bluez.c
@@ -61,7 +61,7 @@ failed:
return;
}
-int alsa_bluez_set_device(const char * interface, const char * device, const char * profile) {
+int alsa_bluez_set_remote_device(const char * interface, const char * device, const char * profile) {
if (!bluealsa_proxy_set_remote_device)
return -1;
diff --git a/plugins/alsa/alsa-bluez.h b/plugins/alsa/alsa-bluez.h
index 85d153a..c288d38 100644
--- a/plugins/alsa/alsa-bluez.h
+++ b/plugins/alsa/alsa-bluez.h
@@ -24,6 +24,6 @@
#include <alsa/asoundlib.h>
extern void alsa_bluez_init();
-extern int alsa_bluez_set_device(const char * interface, const char * device, const char * profile);
+extern int alsa_bluez_set_remote_device(const char * interface, const char * device, const char * profile);
#endif /* __INC_ALSA_BLUEZ_H */
diff --git a/plugins/alsa/alsa-core-pcm.c b/plugins/alsa/alsa-core-pcm.c
index f41aed0..25872ae 100644
--- a/plugins/alsa/alsa-core-pcm.c
+++ b/plugins/alsa/alsa-core-pcm.c
@@ -165,7 +165,7 @@ PUBLIC int AlsaPcmConf(SoftMixerT *mixer, AlsaPcmCtlT *pcm, int mode) {
error = snd_pcm_hw_params_get_buffer_time_max(pxmHwParams, &buffer_time, 0);
- printf("HW_BUFFER_TIME MAX is %d\n", buffer_time);
+ AFB_ApiInfo(mixer->api, "HW_BUFFER_TIME MAX is %d\n", buffer_time);
if (buffer_time > 500000)
buffer_time = 500000;
@@ -178,11 +178,11 @@ PUBLIC int AlsaPcmConf(SoftMixerT *mixer, AlsaPcmCtlT *pcm, int mode) {
}
if (period_time > 0) {
- printf("SET PERIOD TIME to %d\n", period_time);
+ AFB_ApiInfo(mixer->api, "SET PERIOD TIME to %d", period_time);
error = snd_pcm_hw_params_set_period_time_near(pcm->handle, pxmHwParams, &period_time, 0);
}
else {
- printf("SET PERIOD SIZE\n");
+ AFB_ApiInfo(mixer->api, "SET PERIOD SIZE...");
error = snd_pcm_hw_params_set_period_size_near(pcm->handle, pxmHwParams, &period_frames, 0);
}
@@ -194,10 +194,10 @@ PUBLIC int AlsaPcmConf(SoftMixerT *mixer, AlsaPcmCtlT *pcm, int mode) {
}
if (buffer_time > 0) {
- printf("SET BUFFER TIME to %d\n", buffer_time);
+ AFB_ApiInfo(mixer->api, "SET BUFFER TIME to %d", buffer_time);
error = snd_pcm_hw_params_set_buffer_time_near(pcm->handle, pxmHwParams, &buffer_time, 0);
} else {
- printf("SET BUFFER SIZE\n");
+ AFB_ApiInfo(mixer->api, "SET BUFFER SIZE...");
error = snd_pcm_hw_params_set_buffer_size_near(pcm->handle, pxmHwParams, &buffer_frames);
}
@@ -285,7 +285,7 @@ PUBLIC int AlsaPcmConf(SoftMixerT *mixer, AlsaPcmCtlT *pcm, int mode) {
if (start_threshold > n/2)
start_threshold = n/2;
- printf("CALCULATED START THRESHOLD: %ld\n", start_threshold);
+ AFB_ApiInfo(mixer->api, "CALCULATED START THRESHOLD: %ld", start_threshold);
if (mode == SND_PCM_STREAM_PLAYBACK) {
start_threshold = 1;
@@ -353,24 +353,14 @@ STATIC int AlsaPcmReadCB( struct pollfd * pfd, AlsaPcmCopyHandleT * pcmCopyHandl
goto ExitOnSuccess;
}
- pthread_mutex_lock(&pcmCopyHandle->mutex);
- snd_pcm_sframes_t availInBuf = alsa_ringbuf_frames_free(rbuf);
- pthread_mutex_unlock(&pcmCopyHandle->mutex);
-
- /* we get too much data, take what we can now,
- * hopefully we will have more luck next time */
-
- if (availIn > availInBuf) {
-// printf("INCOMING BUFFER TOO SMALL !\n");
- availIn = availInBuf;
- }
-
while (true) {
+ snd_pcm_sframes_t nbRead;
+
pthread_mutex_lock(&pcmCopyHandle->mutex);
- snd_pcm_sframes_t r = alsa_ringbuf_frames_free(rbuf);
+ snd_pcm_sframes_t remain = alsa_ringbuf_frames_remain_capacity(rbuf);
- if (r <= 0) {
+ if (remain <= 0) {
pthread_mutex_unlock(&pcmCopyHandle->mutex);
// Wake up the reader, in case it is sleeping,
// that lets it an opportunity to pop something.
@@ -378,33 +368,33 @@ STATIC int AlsaPcmReadCB( struct pollfd * pfd, AlsaPcmCopyHandleT * pcmCopyHandl
break;
}
- if (r < availIn)
- r = availIn;
+ if (remain < availIn)
+ remain = availIn;
- char buf[r*pcmCopyHandle->frame_size];
+ char buf[remain*pcmCopyHandle->frame_size];
pthread_mutex_unlock(&pcmCopyHandle->mutex);
- r = snd_pcm_readi(pcmIn, buf, r);
+ nbRead = snd_pcm_readi(pcmIn, buf, remain);
- if (r == 0) {
+ if (nbRead == 0) {
break;
}
- if (r < 0) {
- if (r == -EPIPE) {
- err = xrun(pcmIn, (int)r);
+ if (nbRead < 0) {
+ if (nbRead== -EPIPE) {
+ err = xrun(pcmIn, (int)nbRead);
AFB_ApiDebug(pcmCopyHandle->api, "read EPIPE (%d), recov %d", ++pcmCopyHandle->read_err_count, err);
goto ExitOnSuccess;
- } else if (r == -ESTRPIPE) {
+ } else if (nbRead== -ESTRPIPE) {
AFB_ApiDebug(pcmCopyHandle->api, "read ESTRPIPE");
- if ((err = suspend(pcmIn, (int)r)) < 0)
+ if ((err = suspend(pcmIn, (int)nbRead)) < 0)
goto ExitOnSuccess;
- r = 0;
+ nbRead = 0;
} else {
goto ExitOnSuccess;
}
}
pthread_mutex_lock(&pcmCopyHandle->mutex);
- alsa_ringbuf_frames_push(rbuf, buf, r);
+ alsa_ringbuf_frames_push(rbuf, buf, nbRead);
snd_pcm_uframes_t used = alsa_ringbuf_frames_used(rbuf);
pthread_mutex_unlock(&pcmCopyHandle->mutex);
@@ -414,7 +404,7 @@ STATIC int AlsaPcmReadCB( struct pollfd * pfd, AlsaPcmCopyHandleT * pcmCopyHandl
sem_post(&pcmCopyHandle->sem);
}
- availIn -= r;
+ availIn -= nbRead;
// completed, we have read everything
if (availIn <= 0) {
@@ -576,7 +566,7 @@ static void *writeThreadEntry(void *handle) {
sem_wait(&pcmCopyHandle->sem);
while (true) {
- snd_pcm_sframes_t r;
+ snd_pcm_sframes_t used, nbWritten;
snd_pcm_sframes_t availOut = snd_pcm_avail(pcmOut);
if (availOut < 0) {
@@ -599,27 +589,27 @@ static void *writeThreadEntry(void *handle) {
}
pthread_mutex_lock(&pcmCopyHandle->mutex);
- r = alsa_ringbuf_frames_used(rbuf);
- if (r <= 0) {
+ used = alsa_ringbuf_frames_used(rbuf);
+ if (used <= 0) {
pthread_mutex_unlock(&pcmCopyHandle->mutex);
break; // will wait again
}
- if (r > availOut)
- r = availOut;
+ if (used > availOut)
+ used = availOut;
- char buf[r*pcmCopyHandle->frame_size];
- alsa_ringbuf_frames_pop(rbuf, buf, r);
+ char buf[used*pcmCopyHandle->frame_size];
+ alsa_ringbuf_frames_pop(rbuf, buf, used);
pthread_mutex_unlock(&pcmCopyHandle->mutex);
- r = snd_pcm_writei( pcmOut, buf, r);
- if (r <= 0) {
- if (r == -EPIPE) {
- int err = xrun(pcmOut, (int)r);
+ nbWritten = snd_pcm_writei( pcmOut, buf, used);
+ if (nbWritten <= 0) {
+ if (nbWritten == -EPIPE) {
+ int err = xrun(pcmOut, (int)nbWritten);
AFB_ApiDebug(pcmCopyHandle->api, "XXX write EPIPE (%d), recov %d", ++pcmCopyHandle->write_err_count , err);
continue;
- } else if (r == -ESTRPIPE) {
+ } else if (nbWritten == -ESTRPIPE) {
AFB_ApiDebug(pcmCopyHandle->api, "XXX write ESTRPIPE");
break;
}
diff --git a/plugins/alsa/alsa-ringbuf.c b/plugins/alsa/alsa-ringbuf.c
index 2d77e4c..476222c 100644
--- a/plugins/alsa/alsa-ringbuf.c
+++ b/plugins/alsa/alsa-ringbuf.c
@@ -25,7 +25,7 @@ snd_pcm_uframes_t alsa_ringbuf_capacity(const alsa_ringbuf_t *rb) {
return ringbuf_capacity(rb->rbuf)/rb->frameSize;
}
-snd_pcm_uframes_t alsa_ringbuf_frames_free(const alsa_ringbuf_t *rb) {
+snd_pcm_uframes_t alsa_ringbuf_frames_remain_capacity(const alsa_ringbuf_t *rb) {
return ringbuf_bytes_free(rb->rbuf)/rb->frameSize;
}
diff --git a/plugins/alsa/alsa-ringbuf.h b/plugins/alsa/alsa-ringbuf.h
index 5ecc7fe..4ab709c 100644
--- a/plugins/alsa/alsa-ringbuf.h
+++ b/plugins/alsa/alsa-ringbuf.h
@@ -16,7 +16,7 @@ extern snd_pcm_uframes_t alsa_ringbuf_buffer_size(const alsa_ringbuf_t *rb);
extern void alsa_ringbuf_free(alsa_ringbuf_t *rb);
extern void alsa_ringbuf_reset(alsa_ringbuf_t *rb);
extern snd_pcm_uframes_t alsa_ringbuf_capacity(const alsa_ringbuf_t *rb);
-extern snd_pcm_uframes_t alsa_ringbuf_frames_free(const alsa_ringbuf_t *rb);
+extern snd_pcm_uframes_t alsa_ringbuf_frames_remain_capacity(const alsa_ringbuf_t *rb);
extern snd_pcm_uframes_t alsa_ringbuf_frames_used(const alsa_ringbuf_t *rb);
extern bool alsa_ringbuf_is_full(const alsa_ringbuf_t *rb);
extern bool alsa_ringbuf_is_empty(const alsa_ringbuf_t *rb);