From 1c859dfc274c592eca267197131d6497b650b24c Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 30 Jun 2010 18:40:47 +0200 Subject: [PATCH] Deduplicate --channels and --sample-rate. These options are identical for all writers. Moreover, they only make sense for para_write but are ignored for para_audiod. So move these options from the writer-specific ggo file to write.m4, the config file for para_write. The writers obtain the sample rate and the channels count as before via the buffer tree exec mechanism, but it is now the check_wav node rather than the btr node of the writer that computes this information from the given option, the wav header or the builtin default. The new HANDLE_EXEC macro contains the logic for determining the source of both the sample rate and the channels count. --- alsa_write.c | 26 +++++++++++--------------- ggo/alsa_write.m4 | 24 ------------------------ ggo/oss_write.ggo | 25 +------------------------ ggo/osx_write.ggo | 23 +---------------------- ggo/write.m4 | 20 ++++++++++++++++++++ oss_write.c | 13 ++++--------- osx_write.c | 22 +++++++++------------- write.c | 25 ++++++++++++------------- 8 files changed, 58 insertions(+), 120 deletions(-) diff --git a/alsa_write.c b/alsa_write.c index 240d5123..f24e117b 100644 --- a/alsa_write.c +++ b/alsa_write.c @@ -228,23 +228,19 @@ again: return; } if (!pad->handle) { - struct alsa_write_args_info *conf = wn->conf; + int32_t val; if (bytes == 0) /* no data available */ return; - /* defaults */ - pad->sample_rate = conf->sample_rate_arg; - pad->channels = conf->channels_arg; - if (!conf->sample_rate_given) { /* config option trumps btr_exec */ - int32_t rate; - if (get_btr_sample_rate(btrn, &rate) >= 0) - pad->sample_rate = rate; - } - if (!conf->channels_given) { - int32_t ch; - if (get_btr_channels(btrn, &ch) >= 0) - pad->channels = ch; - } - PARA_INFO_LOG("%d channel(s), %dHz\n", pad->channels, pad->sample_rate); + ret = get_btr_sample_rate(btrn, &val); + if (ret < 0) + goto err; + pad->sample_rate = val; + ret = get_btr_channels(btrn, &val); + if (ret < 0) + goto err; + pad->channels = val; + PARA_INFO_LOG("%d channel(s), %dHz\n", pad->channels, + pad->sample_rate); ret = alsa_init(pad, wn->conf); if (ret < 0) goto err; diff --git a/ggo/alsa_write.m4 b/ggo/alsa_write.m4 index 54d0f72f..d0cd4071 100644 --- a/ggo/alsa_write.m4 +++ b/ggo/alsa_write.m4 @@ -11,28 +11,4 @@ details=" On systems with dmix, a better choice than the default value might be to use \"plug:swmix\". " - -option "channels" c -#~~~~~~~~~~~~~~~~~~ -"specify number of channels" -int typestr="num" -default="2" -optional -details=" - This option is only necessary for playing raw audio with - para_write. In all other cases (plaing wav files with - para_write or using this writer with para_audiod), the number - of channels will be obtained from other resources. -" - -option "sample_rate" s -#~~~~~~~~~~~~~~~~~~~~~ -"force given sample rate" -int typestr="num" -default="44100" -optional -details=" - Again, it is only necessary to specify this when playing raw - audio with para_write. -" diff --git a/ggo/oss_write.ggo b/ggo/oss_write.ggo index 1f6f5825..351561cd 100644 --- a/ggo/oss_write.ggo +++ b/ggo/oss_write.ggo @@ -4,27 +4,4 @@ option "device" d string typestr="device" default="/dev/dsp" optional - -option "channels" c -#~~~~~~~~~~~~~~~~~~ -"specify number of channels" -int typestr="num" -default="2" -optional -details=" - This option is only necessary for playing raw audio with - para_write. In all other cases (plaing wav files with - para_write or using this writer with para_audiod), the number - of channels will be obtained from other resources. -" - -option "sample_rate" s -#~~~~~~~~~~~~~~~~~~~~~ -"force given sample rate" -int typestr="num" -default="44100" -optional -details=" - Again, it is only necessary to specify this when playing raw - audio with para_write. -" +details = "" diff --git a/ggo/osx_write.ggo b/ggo/osx_write.ggo index 8dca8212..bee16d9e 100644 --- a/ggo/osx_write.ggo +++ b/ggo/osx_write.ggo @@ -1,28 +1,6 @@ section "osx options" ##################### -option "channels" c -#~~~~~~~~~~~~~~~~~~ -"channel count" - -details = " - Specify the number of channels. This is only neccessary for raw audio. -" - - int typestr="num" - default="2" - optional - -option "sample_rate" s -#~~~~~~~~~~~~~~~~~~~~~ - -"force given sample rate (only neccessary for -raw audio)" - - int typestr="num" - default="44100" - optional - option "numbuffers" n #~~~~~~~~~~~~~~~~~~~~~ @@ -32,3 +10,4 @@ you get buffer underruns)" int typestr="num" default="20" optional + details = "" diff --git a/ggo/write.m4 b/ggo/write.m4 index d954316a..847bd205 100644 --- a/ggo/write.m4 +++ b/ggo/write.m4 @@ -12,3 +12,23 @@ details=" May be give multiple times. The same writer may be specified more than once. " + +text " + The following options are only necessary for raw audio. When + playing wav files this information is obtained from the + wave header. +" + +option "channels" c +#~~~~~~~~~~~~~~~~~~ +"specify number of channels" +int typestr = "num" +default = "2" +optional + +option "sample-rate" s +#~~~~~~~~~~~~~~~~~~~~~ +"force given sample rate" +int typestr = "num" +default = "44100" +optional diff --git a/oss_write.c b/oss_write.c index 6ca1e16e..7acde1da 100644 --- a/oss_write.c +++ b/oss_write.c @@ -146,7 +146,6 @@ static void oss_post_select(__a_unused struct sched *s, struct task *t) { struct writer_node *wn = container_of(t, struct writer_node, task); - struct oss_write_args_info *conf = wn->conf; struct private_oss_write_data *powd = wn->private_data; struct btr_node *btrn = wn->btrn; size_t frames, bytes; @@ -159,16 +158,12 @@ static void oss_post_select(__a_unused struct sched *s, return; if (powd->fd < 0) { int32_t rate, ch; - ret = -1; - if (!conf->sample_rate_given) /* config option trumps btr_exec */ - ret = get_btr_sample_rate(wn->btrn, &rate); + ret = get_btr_sample_rate(btrn, &rate); if (ret < 0) - rate = conf->sample_rate_arg; - ret = -1; - if (!conf->channels_given) - ret = get_btr_channels(wn->btrn, &ch); + goto out; + ret = get_btr_channels(btrn, &ch); if (ret < 0) - ch = conf->channels_arg; + goto out; ret = oss_init(wn, rate, ch); if (ret < 0) goto out; diff --git a/osx_write.c b/osx_write.c index cde7fcea..209721cf 100644 --- a/osx_write.c +++ b/osx_write.c @@ -172,7 +172,7 @@ static int osx_write_open(struct writer_node *wn) AudioStreamBasicDescription format; int ret; struct btr_node *btrn = wn->btrn; - struct osx_write_args_info *conf = wn->conf; + int32_t val; wn->private_data = powd; /* where did that default audio output go? */ @@ -193,18 +193,14 @@ static int osx_write_open(struct writer_node *wn) if (AudioUnitInitialize(powd->audio_unit)) goto e1; powd->play = 0; - powd->sample_rate = conf->sample_rate_arg; - powd->channels = conf->channels_arg; - if (!conf->sample_rate_given) { - int32_t rate; - get_btr_sample_rate(btrn, &rate); - powd->sample_rate = rate; - } - if (!conf->channels_given) { - int32_t ch; - get_btr_channels(btrn, &ch); - powd->channels = ch; - } + ret = get_btr_sample_rate(btrn, &val); + if (ret < 0) + goto e1; + powd->sample_rate = val; + ret = get_btr_channels(btrn, &val); + if (ret < 0) + goto e1; + powd->channels = val; /* * Choose PCM format. We tell the Output Unit what format we're going * to supply data to it. This is necessary if you're providing data diff --git a/write.c b/write.c index 7dc9f85c..d2169f26 100644 --- a/write.c +++ b/write.c @@ -67,23 +67,22 @@ static void check_wav_pre_select(struct sched *s, struct task *t) sched_min_delay(s); } +#define HANDLE_EXEC(_cmd) \ + if (!strcmp(cmd, #_cmd)) { \ + if (!conf._cmd ## _given && cwt->state == CWS_NEED_HEADER) \ + return -E_BTR_NAVAIL; \ + *result = make_message("%d", cwt->state == CWS_NO_HEADER? \ + conf._cmd ## _arg : cwt->_cmd); \ + return 1; \ + } \ + + static int check_wav_exec(struct btr_node *btrn, const char *cmd, char **result) { struct check_wav_task *cwt = btr_context(btrn); - - if (!strcmp(cmd, "sample_rate")) { - if (cwt->state != CWS_HAVE_HEADER) - return -E_BTR_NAVAIL; - *result = make_message("%d", cwt->sample_rate); - return 1; - } - if (!strcmp(cmd, "channels")) { - if (cwt->state != CWS_HAVE_HEADER) - return -E_BTR_NAVAIL; - *result = make_message("%d", cwt->channels); - return 1; - } + HANDLE_EXEC(sample_rate); + HANDLE_EXEC(channels); return -ERRNO_TO_PARA_ERROR(ENOTSUP); } -- 2.39.2