From 66df4a7e6507f436b901cfd9fa56b3e9a0dfebde Mon Sep 17 00:00:00 2001 From: Abramo Bagnara Date: Tue, 10 Oct 2000 09:11:07 +0000 Subject: [PATCH] Added name support --- src/pcm/pcm.c | 2 ++ src/pcm/pcm_adpcm.c | 6 ++++-- src/pcm/pcm_alaw.c | 6 ++++-- src/pcm/pcm_file.c | 6 ++++-- src/pcm/pcm_hw.c | 12 +++++++++++- src/pcm/pcm_linear.c | 6 ++++-- src/pcm/pcm_local.h | 4 +--- src/pcm/pcm_mulaw.c | 6 ++++-- src/pcm/pcm_multi.c | 35 +++++++++++++++++++---------------- src/pcm/pcm_plug.c | 17 ++++++++++------- src/pcm/pcm_plugin.h | 12 ++++++------ src/pcm/pcm_rate.c | 6 ++++-- src/pcm/pcm_route.c | 6 ++++-- 13 files changed, 77 insertions(+), 47 deletions(-) diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 10977676..6bcf50c2 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -73,6 +73,8 @@ int snd_pcm_close(snd_pcm_t *pcm) if ((err = pcm->ops->close(pcm->op_arg)) < 0) ret = err; pcm->valid_setup = 0; + if (pcm->name) + free(pcm->name); free(pcm); return ret; } diff --git a/src/pcm/pcm_adpcm.c b/src/pcm/pcm_adpcm.c index ee6580ce..4c916ab3 100644 --- a/src/pcm/pcm_adpcm.c +++ b/src/pcm/pcm_adpcm.c @@ -552,7 +552,7 @@ struct snd_pcm_ops snd_pcm_adpcm_ops = { munmap_data: snd_pcm_plugin_munmap_data, }; -int snd_pcm_adpcm_open(snd_pcm_t **handlep, int sformat, snd_pcm_t *slave, int close_slave) +int snd_pcm_adpcm_open(snd_pcm_t **handlep, char *name, int sformat, snd_pcm_t *slave, int close_slave) { snd_pcm_t *handle; snd_pcm_adpcm_t *adpcm; @@ -577,6 +577,8 @@ int snd_pcm_adpcm_open(snd_pcm_t **handlep, int sformat, snd_pcm_t *slave, int c free(adpcm); return -ENOMEM; } + if (name) + handle->name = strdup(name); handle->type = SND_PCM_TYPE_ADPCM; handle->stream = slave->stream; handle->ops = &snd_pcm_adpcm_ops; @@ -643,7 +645,7 @@ int _snd_pcm_adpcm_open(snd_pcm_t **pcmp, char *name, free(sname); if (err < 0) return err; - err = snd_pcm_adpcm_open(pcmp, sformat, spcm, 1); + err = snd_pcm_adpcm_open(pcmp, name, sformat, spcm, 1); if (err < 0) snd_pcm_close(spcm); return err; diff --git a/src/pcm/pcm_alaw.c b/src/pcm/pcm_alaw.c index 2646de9e..27f616e6 100644 --- a/src/pcm/pcm_alaw.c +++ b/src/pcm/pcm_alaw.c @@ -420,7 +420,7 @@ struct snd_pcm_ops snd_pcm_alaw_ops = { munmap_data: snd_pcm_plugin_munmap_data, }; -int snd_pcm_alaw_open(snd_pcm_t **handlep, int sformat, snd_pcm_t *slave, int close_slave) +int snd_pcm_alaw_open(snd_pcm_t **handlep, char *name, int sformat, snd_pcm_t *slave, int close_slave) { snd_pcm_t *handle; snd_pcm_alaw_t *alaw; @@ -444,6 +444,8 @@ int snd_pcm_alaw_open(snd_pcm_t **handlep, int sformat, snd_pcm_t *slave, int cl free(alaw); return -ENOMEM; } + if (name) + handle->name = strdup(name); handle->type = SND_PCM_TYPE_ALAW; handle->stream = slave->stream; handle->ops = &snd_pcm_alaw_ops; @@ -510,7 +512,7 @@ int _snd_pcm_alaw_open(snd_pcm_t **pcmp, char *name, free(sname); if (err < 0) return err; - err = snd_pcm_alaw_open(pcmp, sformat, spcm, 1); + err = snd_pcm_alaw_open(pcmp, name, sformat, spcm, 1); if (err < 0) snd_pcm_close(spcm); return err; diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c index acb09a57..3e7ea2a7 100644 --- a/src/pcm/pcm_file.c +++ b/src/pcm/pcm_file.c @@ -370,7 +370,7 @@ struct snd_pcm_fast_ops snd_pcm_file_fast_ops = { mmap_forward: snd_pcm_file_mmap_forward, }; -int snd_pcm_file_open(snd_pcm_t **handlep, char *fname, int fd, snd_pcm_t *slave, int close_slave) +int snd_pcm_file_open(snd_pcm_t **handlep, char *name, char *fname, int fd, snd_pcm_t *slave, int close_slave) { snd_pcm_t *handle; snd_pcm_file_t *file; @@ -395,6 +395,8 @@ int snd_pcm_file_open(snd_pcm_t **handlep, char *fname, int fd, snd_pcm_t *slave free(file); return -ENOMEM; } + if (name) + handle->name = strdup(name); handle->type = SND_PCM_TYPE_FILE; handle->stream = slave->stream; handle->ops = &snd_pcm_file_ops; @@ -463,7 +465,7 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, char *name, free(sname); if (err < 0) return err; - err = snd_pcm_file_open(pcmp, fname, fd, spcm, 1); + err = snd_pcm_file_open(pcmp, name, fname, fd, spcm, 1); if (err < 0) snd_pcm_close(spcm); return err; diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index 795b0594..9a056d79 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -576,6 +576,16 @@ int snd_pcm_hw_open_device(snd_pcm_t **handlep, int card, int device, int stream return snd_pcm_hw_open_subdevice(handlep, card, device, -1, stream, mode); } +int snd_pcm_hw_open(snd_pcm_t **handlep, char *name, int card, int device, int subdevice, int stream, int mode) +{ + int err = snd_pcm_hw_open_subdevice(handlep, card, device, subdevice, stream, mode); + if (err < 0) + return err; + if (name) + (*handlep)->name = strdup(name); + return 0; +} + int _snd_pcm_hw_open(snd_pcm_t **pcmp, char *name, snd_config_t *conf, int stream, int mode) { @@ -619,6 +629,6 @@ int _snd_pcm_hw_open(snd_pcm_t **pcmp, char *name, snd_config_t *conf, } if (card < 0) return -EINVAL; - return snd_pcm_hw_open_subdevice(pcmp, card, device, subdevice, stream, mode); + return snd_pcm_hw_open(pcmp, name, card, device, subdevice, stream, mode); } diff --git a/src/pcm/pcm_linear.c b/src/pcm/pcm_linear.c index b3cea851..b335445e 100644 --- a/src/pcm/pcm_linear.c +++ b/src/pcm/pcm_linear.c @@ -263,7 +263,7 @@ struct snd_pcm_ops snd_pcm_linear_ops = { munmap_data: snd_pcm_plugin_munmap_data, }; -int snd_pcm_linear_open(snd_pcm_t **handlep, int sformat, snd_pcm_t *slave, int close_slave) +int snd_pcm_linear_open(snd_pcm_t **handlep, char *name, int sformat, snd_pcm_t *slave, int close_slave) { snd_pcm_t *handle; snd_pcm_linear_t *linear; @@ -286,6 +286,8 @@ int snd_pcm_linear_open(snd_pcm_t **handlep, int sformat, snd_pcm_t *slave, int free(linear); return -ENOMEM; } + if (name) + handle->name = strdup(name); handle->type = SND_PCM_TYPE_LINEAR; handle->stream = slave->stream; handle->ops = &snd_pcm_linear_ops; @@ -351,7 +353,7 @@ int _snd_pcm_linear_open(snd_pcm_t **pcmp, char *name, free(sname); if (err < 0) return err; - err = snd_pcm_linear_open(pcmp, sformat, spcm, 1); + err = snd_pcm_linear_open(pcmp, name, sformat, spcm, 1); if (err < 0) snd_pcm_close(spcm); return err; diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index c6fb5808..7772af60 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -66,6 +66,7 @@ struct snd_pcm_fast_ops { }; struct snd_pcm { + char *name; snd_pcm_type_t type; int stream; int mode; @@ -143,7 +144,6 @@ static inline size_t snd_pcm_mmap_avail(snd_pcm_t *pcm) return snd_pcm_mmap_playback_avail(pcm); else return snd_pcm_mmap_capture_avail(pcm); - return 0; } static inline ssize_t snd_pcm_mmap_playback_hw_avail(snd_pcm_t *pcm) @@ -170,7 +170,6 @@ static inline ssize_t snd_pcm_mmap_hw_avail(snd_pcm_t *pcm) return snd_pcm_mmap_playback_hw_avail(pcm); else return snd_pcm_mmap_capture_hw_avail(pcm); - return 0; } #define snd_pcm_mmap_playback_delay snd_pcm_mmap_playback_hw_avail @@ -182,7 +181,6 @@ static inline ssize_t snd_pcm_mmap_delay(snd_pcm_t *pcm) return snd_pcm_mmap_playback_delay(pcm); else return snd_pcm_mmap_capture_delay(pcm); - return 0; } static inline void *snd_pcm_channel_area_addr(snd_pcm_channel_area_t *area, size_t offset) diff --git a/src/pcm/pcm_mulaw.c b/src/pcm/pcm_mulaw.c index 1139717d..65448586 100644 --- a/src/pcm/pcm_mulaw.c +++ b/src/pcm/pcm_mulaw.c @@ -437,7 +437,7 @@ struct snd_pcm_ops snd_pcm_mulaw_ops = { munmap_data: snd_pcm_plugin_munmap_data, }; -int snd_pcm_mulaw_open(snd_pcm_t **handlep, int sformat, snd_pcm_t *slave, int close_slave) +int snd_pcm_mulaw_open(snd_pcm_t **handlep, char *name, int sformat, snd_pcm_t *slave, int close_slave) { snd_pcm_t *handle; snd_pcm_mulaw_t *mulaw; @@ -461,6 +461,8 @@ int snd_pcm_mulaw_open(snd_pcm_t **handlep, int sformat, snd_pcm_t *slave, int c free(mulaw); return -ENOMEM; } + if (name) + handle->name = strdup(name); handle->type = SND_PCM_TYPE_MULAW; handle->stream = slave->stream; handle->ops = &snd_pcm_mulaw_ops; @@ -527,7 +529,7 @@ int _snd_pcm_mulaw_open(snd_pcm_t **pcmp, char *name, free(sname); if (err < 0) return err; - err = snd_pcm_mulaw_open(pcmp, sformat, spcm, 1); + err = snd_pcm_mulaw_open(pcmp, name, sformat, spcm, 1); if (err < 0) snd_pcm_close(spcm); return err; diff --git a/src/pcm/pcm_multi.c b/src/pcm/pcm_multi.c index b97e1d1b..a2ead720 100644 --- a/src/pcm/pcm_multi.c +++ b/src/pcm/pcm_multi.c @@ -49,17 +49,17 @@ typedef struct { static int snd_pcm_multi_close(snd_pcm_t *pcm) { snd_pcm_multi_t *multi = pcm->private; - unsigned int i; + size_t i; int ret = 0; for (i = 0; i < multi->slaves_count; ++i) { int err; snd_pcm_multi_slave_t *slave = &multi->slaves[i]; - if (slave->close_slave) { + if (slave->close_slave) err = snd_pcm_close(slave->pcm); - if (err < 0) - ret = err; - } else - snd_pcm_unlink(slave->pcm); + else + err = snd_pcm_unlink(slave->pcm); + if (err < 0) + ret = err; } free(multi->slaves); free(multi->channels); @@ -532,11 +532,12 @@ struct snd_pcm_fast_ops snd_pcm_multi_fast_ops = { mmap_forward: snd_pcm_multi_mmap_forward, }; -int snd_pcm_multi_create(snd_pcm_t **handlep, size_t slaves_count, - snd_pcm_t **slaves_handle, size_t *schannels_count, - size_t channels_count, - int *sidxs, unsigned int *schannels, - int close_slaves) +int snd_pcm_multi_open(snd_pcm_t **handlep, char *name, + size_t slaves_count, + snd_pcm_t **slaves_handle, size_t *schannels_count, + size_t channels_count, + int *sidxs, unsigned int *schannels, + int close_slaves) { snd_pcm_t *handle; snd_pcm_multi_t *multi; @@ -587,6 +588,8 @@ int snd_pcm_multi_create(snd_pcm_t **handlep, size_t slaves_count, free(multi); return -ENOMEM; } + if (name) + handle->name = strdup(name); handle->type = SND_PCM_TYPE_MULTI; handle->stream = stream; handle->mode = multi->slaves[0].pcm->mode; @@ -761,11 +764,11 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, char *name, snd_config_t *conf, if (err < 0) goto _free; } - err = snd_pcm_multi_create(pcmp, slaves_count, slaves_pcm, - slaves_channels, - channels_count, - channels_sidx, channels_schannel, - 1); + err = snd_pcm_multi_open(pcmp, name, slaves_count, slaves_pcm, + slaves_channels, + channels_count, + channels_sidx, channels_schannel, + 1); _free: if (err < 0) { for (idx = 0; idx < slaves_count; ++idx) { diff --git a/src/pcm/pcm_plug.c b/src/pcm/pcm_plug.c index b46ef673..af47c679 100644 --- a/src/pcm/pcm_plug.c +++ b/src/pcm/pcm_plug.c @@ -314,7 +314,7 @@ static int snd_pcm_plug_change_rate(snd_pcm_t *pcm, snd_pcm_t **new, snd_pcm_for assert(snd_pcm_format_linear(slv->sfmt)); if (clt->rate == slv->rate) return 0; - err = snd_pcm_rate_open(new, slv->sfmt, slv->rate, plug->slave, plug->slave != plug->req_slave); + err = snd_pcm_rate_open(new, NULL, slv->sfmt, slv->rate, plug->slave, plug->slave != plug->req_slave); if (err < 0) return err; slv->rate = clt->rate; @@ -378,7 +378,7 @@ static int snd_pcm_plug_change_channels(snd_pcm_t *pcm, snd_pcm_t **new, snd_pcm s = 0; } } - err = snd_pcm_route_open(new, slv->sfmt, slv->channels, ttable, tt_ssize, tt_cused, tt_sused, plug->slave, plug->slave != plug->req_slave); + err = snd_pcm_route_open(new, NULL, slv->sfmt, slv->channels, ttable, tt_ssize, tt_cused, tt_sused, plug->slave, plug->slave != plug->req_slave); if (err < 0) return err; slv->channels = clt->channels; @@ -391,7 +391,7 @@ static int snd_pcm_plug_change_format(snd_pcm_t *pcm, snd_pcm_t **new, snd_pcm_f { snd_pcm_plug_t *plug = pcm->private; int err, cfmt; - int (*f)(snd_pcm_t **handle, int sformat, snd_pcm_t *slave, int close_slave); + int (*f)(snd_pcm_t **handle, char *name, int sformat, snd_pcm_t *slave, int close_slave); if (snd_pcm_format_linear(slv->sfmt)) { /* Conversion is done in another plugin */ if (clt->sfmt == slv->sfmt || @@ -442,7 +442,7 @@ static int snd_pcm_plug_change_format(snd_pcm_t *pcm, snd_pcm_t **new, snd_pcm_f else cfmt = SND_PCM_SFMT_S16; } - err = f(new, slv->sfmt, plug->slave, plug->slave != plug->req_slave); + err = f(new, NULL, slv->sfmt, plug->slave, plug->slave != plug->req_slave); if (err < 0) return err; slv->sfmt = cfmt; @@ -667,6 +667,7 @@ struct snd_pcm_ops snd_pcm_plug_ops = { }; int snd_pcm_plug_open(snd_pcm_t **handlep, + char *name, ttable_entry_t *ttable, unsigned int tt_ssize, unsigned int tt_cused, unsigned int tt_sused, @@ -691,6 +692,8 @@ int snd_pcm_plug_open(snd_pcm_t **handlep, free(plug); return -ENOMEM; } + if (name) + handle->name = strdup(name); handle->type = SND_PCM_TYPE_PLUG; handle->stream = slave->stream; handle->ops = &snd_pcm_plug_ops; @@ -716,10 +719,10 @@ int snd_pcm_plug_open_subdevice(snd_pcm_t **handlep, int card, int device, int s err = snd_pcm_hw_open_subdevice(&slave, card, device, subdevice, stream, mode); if (err < 0) return err; - return snd_pcm_plug_open(handlep, 0, 0, 0, 0, slave, 1); + return snd_pcm_plug_open(handlep, NULL, 0, 0, 0, 0, slave, 1); } -int snd_pcm_plug_open_card(snd_pcm_t **handlep, int card, int device, int stream, int mode) +int snd_pcm_plug_open_device(snd_pcm_t **handlep, int card, int device, int stream, int mode) { return snd_pcm_plug_open_subdevice(handlep, card, device, -1, stream, mode); } @@ -777,7 +780,7 @@ int _snd_pcm_plug_open(snd_pcm_t **pcmp, char *name, free(sname); if (err < 0) return err; - err = snd_pcm_plug_open(pcmp, ttable, MAX_CHANNELS, cused, sused, spcm, 1); + err = snd_pcm_plug_open(pcmp, name, ttable, MAX_CHANNELS, cused, sused, spcm, 1); if (err < 0) snd_pcm_close(spcm); return err; diff --git a/src/pcm/pcm_plugin.h b/src/pcm/pcm_plugin.h index fe216d1b..25de6d2a 100644 --- a/src/pcm/pcm_plugin.h +++ b/src/pcm/pcm_plugin.h @@ -87,19 +87,19 @@ typedef int ttable_entry_t; #define FULL ROUTE_PLUGIN_RESOLUTION #endif -int snd_pcm_linear_open(snd_pcm_t **handlep, int sformat, snd_pcm_t *slave, int close_slave); -int snd_pcm_mulaw_open(snd_pcm_t **handlep, int sformat, snd_pcm_t *slave, int close_slave); -int snd_pcm_alaw_open(snd_pcm_t **handlep, int sformat, snd_pcm_t *slave, int close_slave); -int snd_pcm_adpcm_open(snd_pcm_t **handlep, int sformat, snd_pcm_t *slave, int close_slave); +int snd_pcm_linear_open(snd_pcm_t **handlep, char *name, int sformat, snd_pcm_t *slave, int close_slave); +int snd_pcm_mulaw_open(snd_pcm_t **handlep, char *name, int sformat, snd_pcm_t *slave, int close_slave); +int snd_pcm_alaw_open(snd_pcm_t **handlep, char *name, int sformat, snd_pcm_t *slave, int close_slave); +int snd_pcm_adpcm_open(snd_pcm_t **handlep, char *name, int sformat, snd_pcm_t *slave, int close_slave); int snd_pcm_route_load_ttable(snd_config_t *tt, ttable_entry_t *ttable, unsigned int tt_csize, unsigned int tt_ssize, unsigned int *tt_cused, unsigned int *tt_sused, int schannels); -int snd_pcm_route_open(snd_pcm_t **handlep, +int snd_pcm_route_open(snd_pcm_t **handlep, char *name, int sformat, unsigned int schannels, ttable_entry_t *ttable, unsigned int tt_ssize, unsigned int tt_cused, unsigned int tt_sused, snd_pcm_t *slave, int close_slave); -int snd_pcm_rate_open(snd_pcm_t **handlep, int sformat, int srate, snd_pcm_t *slave, int close_slave); +int snd_pcm_rate_open(snd_pcm_t **handlep, char *name, int sformat, int srate, snd_pcm_t *slave, int close_slave); diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c index c2ef1796..9606c274 100644 --- a/src/pcm/pcm_rate.c +++ b/src/pcm/pcm_rate.c @@ -584,7 +584,7 @@ struct snd_pcm_ops snd_pcm_rate_ops = { munmap_data: snd_pcm_plugin_munmap_data, }; -int snd_pcm_rate_open(snd_pcm_t **handlep, int sformat, int srate, snd_pcm_t *slave, int close_slave) +int snd_pcm_rate_open(snd_pcm_t **handlep, char *name, int sformat, int srate, snd_pcm_t *slave, int close_slave) { snd_pcm_t *handle; snd_pcm_rate_t *rate; @@ -610,6 +610,8 @@ int snd_pcm_rate_open(snd_pcm_t **handlep, int sformat, int srate, snd_pcm_t *sl free(rate); return -ENOMEM; } + if (name) + handle->name = strdup(name); handle->type = SND_PCM_TYPE_RATE; handle->stream = slave->stream; handle->ops = &snd_pcm_rate_ops; @@ -682,7 +684,7 @@ int _snd_pcm_rate_open(snd_pcm_t **pcmp, char *name, free(sname); if (err < 0) return err; - err = snd_pcm_rate_open(pcmp, sformat, srate, spcm, 1); + err = snd_pcm_rate_open(pcmp, name, sformat, srate, spcm, 1); if (err < 0) snd_pcm_close(spcm); return err; diff --git a/src/pcm/pcm_route.c b/src/pcm/pcm_route.c index 08f9d43d..341e3be6 100644 --- a/src/pcm/pcm_route.c +++ b/src/pcm/pcm_route.c @@ -775,7 +775,7 @@ int route_load_ttable(route_params_t *params, int stream, } -int snd_pcm_route_open(snd_pcm_t **handlep, +int snd_pcm_route_open(snd_pcm_t **handlep, char *name, int sformat, unsigned int schannels, ttable_entry_t *ttable, unsigned int tt_ssize, @@ -804,6 +804,8 @@ int snd_pcm_route_open(snd_pcm_t **handlep, free(route); return -ENOMEM; } + if (name) + handle->name = strdup(name); handle->type = SND_PCM_TYPE_ROUTE; handle->stream = slave->stream; handle->ops = &snd_pcm_route_ops; @@ -952,7 +954,7 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, char *name, free(sname); if (err < 0) return err; - err = snd_pcm_route_open(pcmp, sformat, schannels, + err = snd_pcm_route_open(pcmp, name, sformat, schannels, ttable, MAX_CHANNELS, cused, sused, spcm, 1); -- 2.11.0