diff options
Diffstat (limited to 'modules/alsa')
-rw-r--r-- | modules/alsa/alsa.c | 22 | ||||
-rw-r--r-- | modules/alsa/alsa.h | 2 | ||||
-rw-r--r-- | modules/alsa/alsa_play.c | 30 | ||||
-rw-r--r-- | modules/alsa/alsa_src.c | 34 |
4 files changed, 18 insertions, 70 deletions
diff --git a/modules/alsa/alsa.c b/modules/alsa/alsa.c index d695056..78de296 100644 --- a/modules/alsa/alsa.c +++ b/modules/alsa/alsa.c @@ -29,7 +29,6 @@ char alsa_dev[64] = "default"; -enum aufmt alsa_sample_format = AUFMT_S16LE; static struct ausrc *ausrc; static struct auplay *auplay; @@ -146,24 +145,13 @@ static int alsa_init(void) struct pl val; int err; + /* XXX: remove check later */ if (0 == conf_get(conf_cur(), "alsa_sample_format", &val)) { - if (0 == pl_strcasecmp(&val, "s16")) { - alsa_sample_format = AUFMT_S16LE; - } - else if (0 == pl_strcasecmp(&val, "float")) { - alsa_sample_format = AUFMT_FLOAT; - } - else if (0 == pl_strcasecmp(&val, "s24_3le")) { - alsa_sample_format = AUFMT_S24_3LE; - } - else { - warning("alsa: unknown sample format '%r'\n", &val); - return EINVAL; - } - - info("alsa: configured sample format `%s'\n", - aufmt_name(alsa_sample_format)); + warning("alsa: alsa_sample_format is deprecated" + " -- use ausrc_format or auplay_format instead\n"); + + (void)val; } err = ausrc_register(&ausrc, baresip_ausrcl(), diff --git a/modules/alsa/alsa.h b/modules/alsa/alsa.h index 61c408c..fbd67f2 100644 --- a/modules/alsa/alsa.h +++ b/modules/alsa/alsa.h @@ -6,7 +6,7 @@ extern char alsa_dev[64]; -extern enum aufmt alsa_sample_format; + int alsa_reset(snd_pcm_t *pcm, uint32_t srate, uint32_t ch, uint32_t num_frames, snd_pcm_format_t pcmfmt); diff --git a/modules/alsa/alsa_play.c b/modules/alsa/alsa_play.c index aca8da2..6547e21 100644 --- a/modules/alsa/alsa_play.c +++ b/modules/alsa/alsa_play.c @@ -22,14 +22,12 @@ struct auplay_st { pthread_t thread; bool run; snd_pcm_t *write; - int16_t *sampv; - void *xsampv; + void *sampv; size_t sampc; auplay_write_h *wh; void *arg; struct auplay_prm prm; char *device; - enum aufmt aufmt; }; @@ -48,7 +46,6 @@ static void auplay_destructor(void *arg) snd_pcm_close(st->write); mem_deref(st->sampv); - mem_deref(st->xsampv); mem_deref(st->device); } @@ -67,14 +64,7 @@ static void *write_thread(void *arg) st->wh(st->sampv, st->sampc, st->arg); - if (st->aufmt == AUFMT_S16LE) { - sampv = st->sampv; - } - else { - sampv = st->xsampv; - auconv_from_s16(st->aufmt, st->xsampv, - st->sampv, st->sampc); - } + sampv = st->sampv; n = snd_pcm_writei(st->write, sampv, samples); @@ -127,26 +117,16 @@ int alsa_play_alloc(struct auplay_st **stp, const struct auplay *ap, st->ap = ap; st->wh = wh; st->arg = arg; - st->aufmt = alsa_sample_format; st->sampc = prm->srate * prm->ch * prm->ptime / 1000; num_frames = st->prm.srate * st->prm.ptime / 1000; - st->sampv = mem_alloc(2 * st->sampc, NULL); + st->sampv = mem_alloc(aufmt_sample_size(prm->fmt) * st->sampc, NULL); if (!st->sampv) { err = ENOMEM; goto out; } - if (st->aufmt != AUFMT_S16LE) { - size_t sz = aufmt_sample_size(st->aufmt) * st->sampc; - st->xsampv = mem_alloc(sz, NULL); - if (!st->xsampv) { - err = ENOMEM; - goto out; - } - } - err = snd_pcm_open(&st->write, st->device, SND_PCM_STREAM_PLAYBACK, 0); if (err < 0) { warning("alsa: could not open auplay device '%s' (%s)\n", @@ -154,10 +134,10 @@ int alsa_play_alloc(struct auplay_st **stp, const struct auplay *ap, goto out; } - pcmfmt = aufmt_to_alsaformat(st->aufmt); + pcmfmt = aufmt_to_alsaformat(prm->fmt); if (pcmfmt == SND_PCM_FORMAT_UNKNOWN) { warning("alsa: unknown sample format '%s'\n", - aufmt_name(st->aufmt)); + aufmt_name(prm->fmt)); err = EINVAL; goto out; } diff --git a/modules/alsa/alsa_src.c b/modules/alsa/alsa_src.c index 6e850a7..a21f846 100644 --- a/modules/alsa/alsa_src.c +++ b/modules/alsa/alsa_src.c @@ -22,14 +22,12 @@ struct ausrc_st { pthread_t thread; bool run; snd_pcm_t *read; - int16_t *sampv; - void *xsampv; + void *sampv; size_t sampc; ausrc_read_h *rh; void *arg; struct ausrc_prm prm; char *device; - enum aufmt aufmt; }; @@ -48,7 +46,6 @@ static void ausrc_destructor(void *arg) snd_pcm_close(st->read); mem_deref(st->sampv); - mem_deref(st->xsampv); mem_deref(st->device); } @@ -73,10 +70,7 @@ static void *read_thread(void *arg) size_t sampc; void *sampv; - if (st->aufmt == AUFMT_S16LE) - sampv = st->sampv; - else - sampv = st->xsampv; + sampv = st->sampv; err = snd_pcm_readi(st->read, sampv, num_frames); if (err == -EPIPE) { @@ -89,11 +83,6 @@ static void *read_thread(void *arg) sampc = err * st->prm.ch; - if (st->aufmt != AUFMT_S16LE) { - auconv_to_s16(st->sampv, st->aufmt, - st->xsampv, sampc); - } - st->rh(st->sampv, sampc, st->arg); } @@ -132,26 +121,16 @@ int alsa_src_alloc(struct ausrc_st **stp, const struct ausrc *as, st->as = as; st->rh = rh; st->arg = arg; - st->aufmt = alsa_sample_format; st->sampc = prm->srate * prm->ch * prm->ptime / 1000; num_frames = st->prm.srate * st->prm.ptime / 1000; - st->sampv = mem_alloc(2 * st->sampc, NULL); + st->sampv = mem_alloc(aufmt_sample_size(prm->fmt) * st->sampc, NULL); if (!st->sampv) { err = ENOMEM; goto out; } - if (st->aufmt != AUFMT_S16LE) { - size_t sz = aufmt_sample_size(st->aufmt) * st->sampc; - st->xsampv = mem_alloc(sz, NULL); - if (!st->xsampv) { - err = ENOMEM; - goto out; - } - } - err = snd_pcm_open(&st->read, st->device, SND_PCM_STREAM_CAPTURE, 0); if (err < 0) { warning("alsa: could not open ausrc device '%s' (%s)\n", @@ -159,10 +138,10 @@ int alsa_src_alloc(struct ausrc_st **stp, const struct ausrc *as, goto out; } - pcmfmt = aufmt_to_alsaformat(st->aufmt); + pcmfmt = aufmt_to_alsaformat(prm->fmt); if (pcmfmt == SND_PCM_FORMAT_UNKNOWN) { warning("alsa: unknown sample format '%s'\n", - aufmt_name(st->aufmt)); + aufmt_name(prm->fmt)); err = EINVAL; goto out; } @@ -182,7 +161,8 @@ int alsa_src_alloc(struct ausrc_st **stp, const struct ausrc *as, goto out; } - debug("alsa: recording started (%s)\n", st->device); + debug("alsa: recording started (%s) format=%s\n", + st->device, aufmt_name(prm->fmt)); out: if (err) |