[alsa-devel] [alsa-lib][PATCH 00/34] pcm/conf/alisp: replace usage of alloca() with automatic variables
Hi,
A batch of this patchset is to save storage consumption and to improve execution performance, just for a little.
Currently, ALSA userspace library doesn't disclose layouts of major structures to applications. The applications call some APIs in the library to get memory objects for the structures, then operates to corresponding opaque pointers. In most cases, the objects are kept on stack by calls of alloca(3).
On the other hand, inner the library, the layouts are decided in pre-compile or compile time. Therefore, there's little needs to call of alloca(3).
However, inner the library, we can see some usages of alloca(3). This brings two disadvantages to system. One is to execute more instructions to use stack than automatic variables, for the same task. Another is to enlarge size of shared object. Although both disadvantages are not so remarkable, it's better to improve them.
This patchset replaces usages of alloca() with automatic variables just to raw structures. Additionally, this commit improves code formats in related functions.
I can see below effect on my environment (Ubuntu 16.04, amd64, gcc) $ git checkout master $ git show HEAD commit 941bd150bef2560f3e38a3bf74d546447e3126d1 ... $ ./gitcompile --with-plugindir=/usr/lib/x86_64-linux-gnu/alsa-lib/ ... $ ls -l src/.libs/libasound.so.2.0.0 -rwxrwxr-x 1 mocchi mocchi 4794528 7月 14 22:22 src/.libs/libasound.so.2.0.0 $ git checkout remove-alloca-asound $ make ... $ ls -l src/.libs/libasound.so.2.0.0 -rwxrwxr-x 1 mocchi mocchi 4783712 7月 14 22:21 src/.libs/libasound.so.2.0.0 $ gcc -v ... gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.1)
Takashi Sakamoto (34): pcm: change code formatting for snd_pcm_set_params() pcm: remove alloca() from snd_pcm_set_params() pcm: change code formatting for snd_pcm_get_params() pcm: remove alloca() from snd_pcm_get_params pcm: change code formatting for snd_pcm_direct_initialize_slave() pcm: remove alloca() from snd_pcm_direct_initialize_slave pcm: change code formatting for snd_pcm_direct_initialize_poll_fd() pcm: remove alloca() from snd_pcm_direct_initialize_poll_fd() pcm: change code formatting for snd_pcm_direct_set_timer_params() pcm: remove alloca() from snd_pcm_direct_set_timer_params pcm: remove alloca() from _snd_pcm_hook_ctl_elems_install() pcm: change code formatting for snd_pcm_hw_change_timer() pcm: remove alloca() from snd_pcm_hw_change_timer() pcm: remove alloca() from snd_pcm_query_chmaps_from_hw() pcm: remove alloca() from snd_pcm_hw_get_chmap() pcm: remove alloca() from snd_pcm_hw_set_chmap() pcm: remove alloca() from snd_spcm_init() pcm: remove alloca() from snd_spcm_init_duplex() pcm: change code formatting for softvol_load_control() pcm: remove alloca() from softvol_load_control() pcm: change code formatting for _snd_pcm_softvol_open() pcm: remove alloca() from _snd_pcm_softvol_open() conf: remove alloca() from snd_determine_driver() conf: remove alloca() from snd_func_card_id() conf: remove alloca() from snd_func_card_name() conf: remove alloca() from snd_func_pcm_id() conf: remove alloca() from snd_func_pcm_args_by_class() conf: remove alloca() from snd_func_private_pcm_subdevice() alisp: remove alloca() from FA_card_info() alisp: remove alloca() from FA_hctl_find_elem() alisp: remove alloca() from FA_hctl_elem_info() alisp: remove alloca() from FA_hctl_elem_read() alisp: remove alloca() from FA_hctl_elem_write() alisp: remove alloca() from FA_pcm_info()
src/alisp/alisp_snd.c | 153 ++++++++++++++++----------------- src/confmisc.c | 51 +++++------ src/pcm/pcm.c | 232 ++++++++++++++++++++++++++++---------------------- src/pcm/pcm_direct.c | 132 ++++++++++++++++------------ src/pcm/pcm_hooks.c | 8 +- src/pcm/pcm_hw.c | 74 +++++++++------- src/pcm/pcm_simple.c | 22 ++--- src/pcm/pcm_softvol.c | 69 ++++++++------- 8 files changed, 393 insertions(+), 348 deletions(-)
This commit applies code format according to typical and moderate rule, for snd_pcm_set_params().
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm.c | 193 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 114 insertions(+), 79 deletions(-)
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 6c34719..64f841d 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -8291,142 +8291,177 @@ int snd_pcm_set_params(snd_pcm_t *pcm, int soft_resample, unsigned int latency) { - snd_pcm_hw_params_t *params, params_saved; - snd_pcm_sw_params_t *swparams; - const char *s = snd_pcm_stream_name(snd_pcm_stream(pcm)); - snd_pcm_uframes_t buffer_size, period_size; - unsigned int rrate, period_time; - int err; + snd_pcm_hw_params_t *params, params_saved; + snd_pcm_sw_params_t *swparams; + const char *s = snd_pcm_stream_name(snd_pcm_stream(pcm)); + snd_pcm_uframes_t buffer_size, period_size; + unsigned int rrate, period_time; + int err;
- snd_pcm_hw_params_alloca(¶ms); - snd_pcm_sw_params_alloca(&swparams); + snd_pcm_hw_params_alloca(¶ms); + snd_pcm_sw_params_alloca(&swparams);
assert(pcm); /* choose all parameters */ err = snd_pcm_hw_params_any(pcm, params); if (err < 0) { - SNDERR("Broken configuration for %s: no configurations available", s); - return err; - } - /* set software resampling */ - err = snd_pcm_hw_params_set_rate_resample(pcm, params, soft_resample); - if (err < 0) { - SNDERR("Resampling setup failed for %s: %s", s, snd_strerror(err)); - return err; + SNDERR("Broken configuration for %s: no configurations available", + s); + return err; } + /* set software resampling */ + err = snd_pcm_hw_params_set_rate_resample(pcm, params, soft_resample); + if (err < 0) { + SNDERR("Resampling setup failed for %s: %s", + s, snd_strerror(err)); + return err; + } /* set the selected read/write format */ err = snd_pcm_hw_params_set_access(pcm, params, access); if (err < 0) { - SNDERR("Access type not available for %s: %s", s, snd_strerror(err)); + SNDERR("Access type not available for %s: %s", + s, snd_strerror(err)); return err; } /* set the sample format */ err = snd_pcm_hw_params_set_format(pcm, params, format); if (err < 0) { - SNDERR("Sample format not available for %s: %s", s, snd_strerror(err)); + SNDERR("Sample format not available for %s: %s", + s, snd_strerror(err)); return err; } /* set the count of channels */ err = snd_pcm_hw_params_set_channels(pcm, params, channels); if (err < 0) { - SNDERR("Channels count (%i) not available for %s: %s", channels, s, snd_strerror(err)); + SNDERR("Channels count (%i) not available for %s: %s", + channels, s, snd_strerror(err)); return err; } /* set the stream rate */ rrate = rate; err = INTERNAL(snd_pcm_hw_params_set_rate_near)(pcm, params, &rrate, 0); if (err < 0) { - SNDERR("Rate %iHz not available for playback: %s", rate, snd_strerror(err)); + SNDERR("Rate %iHz not available for playback: %s", + rate, snd_strerror(err)); return err; } if (rrate != rate) { - SNDERR("Rate doesn't match (requested %iHz, get %iHz)", rate, rrate); + SNDERR("Rate doesn't match (requested %iHz, get %iHz)", + rate, rrate); return -EINVAL; } /* set the buffer time */ params_saved = *params; - err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, params, &latency, NULL); + err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, params, + &latency, NULL); if (err < 0) { - /* error path -> set period size as first */ + /* error path -> set period size as first */ *params = params_saved; - /* set the period time */ - period_time = latency / 4; - err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm, params, &period_time, NULL); - if (err < 0) { - SNDERR("Unable to set period time %i for %s: %s", period_time, s, snd_strerror(err)); - return err; - } - err = INTERNAL(snd_pcm_hw_params_get_period_size)(params, &period_size, NULL); - if (err < 0) { - SNDERR("Unable to get period size for %s: %s", s, snd_strerror(err)); - return err; - } - buffer_size = period_size * 4; - err = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(pcm, params, &buffer_size); - if (err < 0) { - SNDERR("Unable to set buffer size %lu %s: %s", buffer_size, s, snd_strerror(err)); - return err; - } - err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(params, &buffer_size); - if (err < 0) { - SNDERR("Unable to get buffer size for %s: %s", s, snd_strerror(err)); - return err; - } + /* set the period time */ + period_time = latency / 4; + err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm, + params, &period_time, NULL); + if (err < 0) { + SNDERR("Unable to set period time %i for %s: %s", + period_time, s, snd_strerror(err)); + return err; + } + err = INTERNAL(snd_pcm_hw_params_get_period_size)(params, + &period_size, NULL); + if (err < 0) { + SNDERR("Unable to get period size for %s: %s", + s, snd_strerror(err)); + return err; + } + buffer_size = period_size * 4; + err = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(pcm, + params, &buffer_size); + if (err < 0) { + SNDERR("Unable to set buffer size %lu %s: %s", + buffer_size, s, snd_strerror(err)); + return err; + } + err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(params, + &buffer_size); + if (err < 0) { + SNDERR("Unable to get buffer size for %s: %s", + s, snd_strerror(err)); + return err; + } } else { - /* standard configuration buffer_time -> periods */ - err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(params, &buffer_size); - if (err < 0) { - SNDERR("Unable to get buffer size for %s: %s", s, snd_strerror(err)); - return err; - } - err = INTERNAL(snd_pcm_hw_params_get_buffer_time)(params, &latency, NULL); - if (err < 0) { - SNDERR("Unable to get buffer time (latency) for %s: %s", s, snd_strerror(err)); - return err; - } - /* set the period time */ - period_time = latency / 4; - err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm, params, &period_time, NULL); - if (err < 0) { - SNDERR("Unable to set period time %i for %s: %s", period_time, s, snd_strerror(err)); - return err; - } - err = INTERNAL(snd_pcm_hw_params_get_period_size)(params, &period_size, NULL); - if (err < 0) { - SNDERR("Unable to get period size for %s: %s", s, snd_strerror(err)); - return err; - } - } + /* standard configuration buffer_time -> periods */ + err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(params, + &buffer_size); + if (err < 0) { + SNDERR("Unable to get buffer size for %s: %s", + s, snd_strerror(err)); + return err; + } + err = INTERNAL(snd_pcm_hw_params_get_buffer_time)(params, + &latency, NULL); + if (err < 0) { + SNDERR("Unable to get buffer time (latency) for %s: %s", + s, snd_strerror(err)); + return err; + } + /* set the period time */ + period_time = latency / 4; + err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm, + params, &period_time, NULL); + if (err < 0) { + SNDERR("Unable to set period time %i for %s: %s", + period_time, s, snd_strerror(err)); + return err; + } + err = INTERNAL(snd_pcm_hw_params_get_period_size)(params, + &period_size, NULL); + if (err < 0) { + SNDERR("Unable to get period size for %s: %s", + s, snd_strerror(err)); + return err; + } + } /* write the parameters to device */ err = snd_pcm_hw_params(pcm, params); if (err < 0) { - SNDERR("Unable to set hw params for %s: %s", s, snd_strerror(err)); + SNDERR("Unable to set hw params for %s: %s", + s, snd_strerror(err)); return err; }
/* get the current swparams */ err = snd_pcm_sw_params_current(pcm, swparams); if (err < 0) { - SNDERR("Unable to determine current swparams for %s: %s", s, snd_strerror(err)); + SNDERR("Unable to determine current swparams for %s: %s", + s, snd_strerror(err)); return err; } - /* start the transfer when the buffer is almost full: */ - /* (buffer_size / avail_min) * avail_min */ - err = snd_pcm_sw_params_set_start_threshold(pcm, swparams, (buffer_size / period_size) * period_size); + /* + * start the transfer when the buffer is almost full: + * (buffer_size / avail_min) * avail_min + */ + err = snd_pcm_sw_params_set_start_threshold(pcm, swparams, + (buffer_size / period_size) * period_size); if (err < 0) { - SNDERR("Unable to set start threshold mode for %s: %s", s, snd_strerror(err)); + SNDERR("Unable to set start threshold mode for %s: %s", + s, snd_strerror(err)); return err; } - /* allow the transfer when at least period_size samples can be processed */ + /* + * allow the transfer when at least period_size samples can be + * processed + */ err = snd_pcm_sw_params_set_avail_min(pcm, swparams, period_size); if (err < 0) { - SNDERR("Unable to set avail min for %s: %s", s, snd_strerror(err)); + SNDERR("Unable to set avail min for %s: %s", + s, snd_strerror(err)); return err; } /* write the parameters to the playback device */ err = snd_pcm_sw_params(pcm, swparams); if (err < 0) { - SNDERR("Unable to set sw params for %s: %s", s, snd_strerror(err)); + SNDERR("Unable to set sw params for %s: %s", + s, snd_strerror(err)); return err; } return 0;
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm.c | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-)
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 64f841d..4cace0b 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -8291,47 +8291,44 @@ int snd_pcm_set_params(snd_pcm_t *pcm, int soft_resample, unsigned int latency) { - snd_pcm_hw_params_t *params, params_saved; - snd_pcm_sw_params_t *swparams; + snd_pcm_hw_params_t params_saved, params = {0}; + snd_pcm_sw_params_t swparams = {0}; const char *s = snd_pcm_stream_name(snd_pcm_stream(pcm)); snd_pcm_uframes_t buffer_size, period_size; unsigned int rrate, period_time; int err;
- snd_pcm_hw_params_alloca(¶ms); - snd_pcm_sw_params_alloca(&swparams); - assert(pcm); /* choose all parameters */ - err = snd_pcm_hw_params_any(pcm, params); + err = snd_pcm_hw_params_any(pcm, ¶ms); if (err < 0) { SNDERR("Broken configuration for %s: no configurations available", s); return err; } /* set software resampling */ - err = snd_pcm_hw_params_set_rate_resample(pcm, params, soft_resample); + err = snd_pcm_hw_params_set_rate_resample(pcm, ¶ms, soft_resample); if (err < 0) { SNDERR("Resampling setup failed for %s: %s", s, snd_strerror(err)); return err; } /* set the selected read/write format */ - err = snd_pcm_hw_params_set_access(pcm, params, access); + err = snd_pcm_hw_params_set_access(pcm, ¶ms, access); if (err < 0) { SNDERR("Access type not available for %s: %s", s, snd_strerror(err)); return err; } /* set the sample format */ - err = snd_pcm_hw_params_set_format(pcm, params, format); + err = snd_pcm_hw_params_set_format(pcm, ¶ms, format); if (err < 0) { SNDERR("Sample format not available for %s: %s", s, snd_strerror(err)); return err; } /* set the count of channels */ - err = snd_pcm_hw_params_set_channels(pcm, params, channels); + err = snd_pcm_hw_params_set_channels(pcm, ¶ms, channels); if (err < 0) { SNDERR("Channels count (%i) not available for %s: %s", channels, s, snd_strerror(err)); @@ -8339,7 +8336,8 @@ int snd_pcm_set_params(snd_pcm_t *pcm, } /* set the stream rate */ rrate = rate; - err = INTERNAL(snd_pcm_hw_params_set_rate_near)(pcm, params, &rrate, 0); + err = INTERNAL(snd_pcm_hw_params_set_rate_near)(pcm, ¶ms, &rrate, + 0); if (err < 0) { SNDERR("Rate %iHz not available for playback: %s", rate, snd_strerror(err)); @@ -8351,22 +8349,22 @@ int snd_pcm_set_params(snd_pcm_t *pcm, return -EINVAL; } /* set the buffer time */ - params_saved = *params; - err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, params, + params_saved = params; + err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, ¶ms, &latency, NULL); if (err < 0) { /* error path -> set period size as first */ - *params = params_saved; + params = params_saved; /* set the period time */ period_time = latency / 4; err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm, - params, &period_time, NULL); + ¶ms, &period_time, NULL); if (err < 0) { SNDERR("Unable to set period time %i for %s: %s", period_time, s, snd_strerror(err)); return err; } - err = INTERNAL(snd_pcm_hw_params_get_period_size)(params, + err = INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms, &period_size, NULL); if (err < 0) { SNDERR("Unable to get period size for %s: %s", @@ -8375,13 +8373,13 @@ int snd_pcm_set_params(snd_pcm_t *pcm, } buffer_size = period_size * 4; err = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(pcm, - params, &buffer_size); + ¶ms, &buffer_size); if (err < 0) { SNDERR("Unable to set buffer size %lu %s: %s", buffer_size, s, snd_strerror(err)); return err; } - err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(params, + err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms, &buffer_size); if (err < 0) { SNDERR("Unable to get buffer size for %s: %s", @@ -8390,14 +8388,14 @@ int snd_pcm_set_params(snd_pcm_t *pcm, } } else { /* standard configuration buffer_time -> periods */ - err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(params, + err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms, &buffer_size); if (err < 0) { SNDERR("Unable to get buffer size for %s: %s", s, snd_strerror(err)); return err; } - err = INTERNAL(snd_pcm_hw_params_get_buffer_time)(params, + err = INTERNAL(snd_pcm_hw_params_get_buffer_time)(¶ms, &latency, NULL); if (err < 0) { SNDERR("Unable to get buffer time (latency) for %s: %s", @@ -8407,13 +8405,13 @@ int snd_pcm_set_params(snd_pcm_t *pcm, /* set the period time */ period_time = latency / 4; err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm, - params, &period_time, NULL); + ¶ms, &period_time, NULL); if (err < 0) { SNDERR("Unable to set period time %i for %s: %s", period_time, s, snd_strerror(err)); return err; } - err = INTERNAL(snd_pcm_hw_params_get_period_size)(params, + err = INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms, &period_size, NULL); if (err < 0) { SNDERR("Unable to get period size for %s: %s", @@ -8422,7 +8420,7 @@ int snd_pcm_set_params(snd_pcm_t *pcm, } } /* write the parameters to device */ - err = snd_pcm_hw_params(pcm, params); + err = snd_pcm_hw_params(pcm, ¶ms); if (err < 0) { SNDERR("Unable to set hw params for %s: %s", s, snd_strerror(err)); @@ -8430,7 +8428,7 @@ int snd_pcm_set_params(snd_pcm_t *pcm, }
/* get the current swparams */ - err = snd_pcm_sw_params_current(pcm, swparams); + err = snd_pcm_sw_params_current(pcm, &swparams); if (err < 0) { SNDERR("Unable to determine current swparams for %s: %s", s, snd_strerror(err)); @@ -8440,7 +8438,7 @@ int snd_pcm_set_params(snd_pcm_t *pcm, * start the transfer when the buffer is almost full: * (buffer_size / avail_min) * avail_min */ - err = snd_pcm_sw_params_set_start_threshold(pcm, swparams, + err = snd_pcm_sw_params_set_start_threshold(pcm, &swparams, (buffer_size / period_size) * period_size); if (err < 0) { SNDERR("Unable to set start threshold mode for %s: %s", @@ -8451,14 +8449,14 @@ int snd_pcm_set_params(snd_pcm_t *pcm, * allow the transfer when at least period_size samples can be * processed */ - err = snd_pcm_sw_params_set_avail_min(pcm, swparams, period_size); + err = snd_pcm_sw_params_set_avail_min(pcm, &swparams, period_size); if (err < 0) { SNDERR("Unable to set avail min for %s: %s", s, snd_strerror(err)); return err; } /* write the parameters to the playback device */ - err = snd_pcm_sw_params(pcm, swparams); + err = snd_pcm_sw_params(pcm, &swparams); if (err < 0) { SNDERR("Unable to set sw params for %s: %s", s, snd_strerror(err));
This commit applies code format according to typical and moderate rule, for snd_pcm_get_params().
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 4cace0b..23655e6 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -8484,11 +8484,9 @@ int snd_pcm_get_params(snd_pcm_t *pcm, err = snd_pcm_hw_params_current(pcm, hw); if (err < 0) return err; - err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(hw, buffer_size); - if (err < 0) - return err; - err = INTERNAL(snd_pcm_hw_params_get_period_size)(hw, period_size, NULL); - if (err < 0) - return err; - return 0; + err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(hw, buffer_size); + if (err < 0) + return err; + return INTERNAL(snd_pcm_hw_params_get_period_size)(hw, period_size, + NULL); }
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 23655e6..f832399 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -8476,17 +8476,16 @@ int snd_pcm_get_params(snd_pcm_t *pcm, snd_pcm_uframes_t *buffer_size, snd_pcm_uframes_t *period_size) { - snd_pcm_hw_params_t *hw; + snd_pcm_hw_params_t params = {0}; int err;
assert(pcm); - snd_pcm_hw_params_alloca(&hw); - err = snd_pcm_hw_params_current(pcm, hw); + err = snd_pcm_hw_params_current(pcm, ¶ms); if (err < 0) return err; - err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(hw, buffer_size); + err = INTERNAL(snd_pcm_hw_params_get_buffer_size)(¶ms, buffer_size); if (err < 0) return err; - return INTERNAL(snd_pcm_hw_params_get_period_size)(hw, period_size, + return INTERNAL(snd_pcm_hw_params_get_period_size)(¶ms, period_size, NULL); }
This commit applies code format according to typical and moderate rule, for snd_pcm_direct_initialize_slave().
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_direct.c | 67 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 22 deletions(-)
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index fb3531c..a4b5214 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -933,9 +933,11 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str SNDERR("snd_pcm_hw_params_any failed"); return ret; } - ret = snd_pcm_hw_params_set_access(spcm, hw_params, SND_PCM_ACCESS_MMAP_INTERLEAVED); + ret = snd_pcm_hw_params_set_access(spcm, hw_params, + SND_PCM_ACCESS_MMAP_INTERLEAVED); if (ret < 0) { - ret = snd_pcm_hw_params_set_access(spcm, hw_params, SND_PCM_ACCESS_MMAP_NONINTERLEAVED); + ret = snd_pcm_hw_params_set_access(spcm, hw_params, + SND_PCM_ACCESS_MMAP_NONINTERLEAVED); if (ret < 0) { SNDERR("slave plugin does not support mmap interleaved or mmap noninterleaved access"); return ret; @@ -949,9 +951,11 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str if (ret < 0) { static const snd_pcm_format_t dmix_formats[] = { SND_PCM_FORMAT_S32, - SND_PCM_FORMAT_S32 ^ SND_PCM_FORMAT_S32_LE ^ SND_PCM_FORMAT_S32_BE, + SND_PCM_FORMAT_S32 ^ SND_PCM_FORMAT_S32_LE ^ + SND_PCM_FORMAT_S32_BE, SND_PCM_FORMAT_S16, - SND_PCM_FORMAT_S16 ^ SND_PCM_FORMAT_S16_LE ^ SND_PCM_FORMAT_S16_BE, + SND_PCM_FORMAT_S16 ^ SND_PCM_FORMAT_S16_LE ^ + SND_PCM_FORMAT_S16_BE, SND_PCM_FORMAT_S24_LE, SND_PCM_FORMAT_S24_3LE, SND_PCM_FORMAT_U8, @@ -959,15 +963,17 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str snd_pcm_format_t format; unsigned int i;
- for (i = 0; i < sizeof dmix_formats / sizeof dmix_formats[0]; ++i) { + for (i = 0; i < ARRAY_SIZE(dmix_formats); ++i) { format = dmix_formats[i]; - ret = snd_pcm_hw_params_set_format(spcm, hw_params, format); + ret = snd_pcm_hw_params_set_format(spcm, hw_params, + format); if (ret >= 0) break; } if (ret < 0 && dmix->type != SND_PCM_TYPE_DMIX) { /* TODO: try to choose a good format */ - ret = INTERNAL(snd_pcm_hw_params_set_format_first)(spcm, hw_params, &format); + ret = INTERNAL(snd_pcm_hw_params_set_format_first)(spcm, + hw_params, &format); } if (ret < 0) { SNDERR("requested or auto-format is not available"); @@ -975,12 +981,14 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str } params->format = format; } - ret = INTERNAL(snd_pcm_hw_params_set_channels_near)(spcm, hw_params, (unsigned int *)¶ms->channels); + ret = INTERNAL(snd_pcm_hw_params_set_channels_near)(spcm, hw_params, + (unsigned int *)¶ms->channels); if (ret < 0) { SNDERR("requested count of channels is not available"); return ret; } - ret = INTERNAL(snd_pcm_hw_params_set_rate_near)(spcm, hw_params, (unsigned int *)¶ms->rate, 0); + ret = INTERNAL(snd_pcm_hw_params_set_rate_near)(spcm, hw_params, + (unsigned int *)¶ms->rate, 0); if (ret < 0) { SNDERR("requested rate is not available"); return ret; @@ -988,13 +996,15 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str
buffer_is_not_initialized = 0; if (params->buffer_time > 0) { - ret = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(spcm, hw_params, (unsigned int *)¶ms->buffer_time, 0); + ret = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(spcm, + hw_params, (unsigned int *)¶ms->buffer_time, 0); if (ret < 0) { SNDERR("unable to set buffer time"); return ret; } } else if (params->buffer_size > 0) { - ret = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(spcm, hw_params, (snd_pcm_uframes_t *)¶ms->buffer_size); + ret = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(spcm, + hw_params, (snd_pcm_uframes_t *)¶ms->buffer_size); if (ret < 0) { SNDERR("unable to set buffer size"); return ret; @@ -1004,13 +1014,16 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str }
if (params->period_time > 0) { - ret = INTERNAL(snd_pcm_hw_params_set_period_time_near)(spcm, hw_params, (unsigned int *)¶ms->period_time, 0); + ret = INTERNAL(snd_pcm_hw_params_set_period_time_near)(spcm, + hw_params, (unsigned int *)¶ms->period_time, 0); if (ret < 0) { SNDERR("unable to set period_time"); return ret; } } else if (params->period_size > 0) { - ret = INTERNAL(snd_pcm_hw_params_set_period_size_near)(spcm, hw_params, (snd_pcm_uframes_t *)¶ms->period_size, 0); + ret = INTERNAL(snd_pcm_hw_params_set_period_size_near)(spcm, + hw_params, (snd_pcm_uframes_t *)¶ms->period_size, + 0); if (ret < 0) { SNDERR("unable to set period_size"); return ret; @@ -1019,7 +1032,8 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str if (buffer_is_not_initialized && params->periods > 0) { unsigned int periods = params->periods; - ret = INTERNAL(snd_pcm_hw_params_set_periods_near)(spcm, hw_params, ¶ms->periods, 0); + ret = INTERNAL(snd_pcm_hw_params_set_periods_near)(spcm, + hw_params, ¶ms->periods, 0); if (ret < 0) { SNDERR("unable to set requested periods"); return ret; @@ -1045,13 +1059,21 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str }
/* store some hw_params values to shared info */ - dmix->shmptr->hw.format = snd_mask_value(hw_param_mask(hw_params, SND_PCM_HW_PARAM_FORMAT)); - dmix->shmptr->hw.rate = *hw_param_interval(hw_params, SND_PCM_HW_PARAM_RATE); - dmix->shmptr->hw.buffer_size = *hw_param_interval(hw_params, SND_PCM_HW_PARAM_BUFFER_SIZE); - dmix->shmptr->hw.buffer_time = *hw_param_interval(hw_params, SND_PCM_HW_PARAM_BUFFER_TIME); - dmix->shmptr->hw.period_size = *hw_param_interval(hw_params, SND_PCM_HW_PARAM_PERIOD_SIZE); - dmix->shmptr->hw.period_time = *hw_param_interval(hw_params, SND_PCM_HW_PARAM_PERIOD_TIME); - dmix->shmptr->hw.periods = *hw_param_interval(hw_params, SND_PCM_HW_PARAM_PERIODS); + dmix->shmptr->hw.format = + snd_mask_value(hw_param_mask(hw_params, + SND_PCM_HW_PARAM_FORMAT)); + dmix->shmptr->hw.rate = + *hw_param_interval(hw_params, SND_PCM_HW_PARAM_RATE); + dmix->shmptr->hw.buffer_size = + *hw_param_interval(hw_params, SND_PCM_HW_PARAM_BUFFER_SIZE); + dmix->shmptr->hw.buffer_time = + *hw_param_interval(hw_params, SND_PCM_HW_PARAM_BUFFER_TIME); + dmix->shmptr->hw.period_size = + *hw_param_interval(hw_params, SND_PCM_HW_PARAM_PERIOD_SIZE); + dmix->shmptr->hw.period_time = + *hw_param_interval(hw_params, SND_PCM_HW_PARAM_PERIOD_TIME); + dmix->shmptr->hw.periods = + *hw_param_interval(hw_params, SND_PCM_HW_PARAM_PERIODS);
ret = snd_pcm_sw_params_current(spcm, sw_params); @@ -1107,7 +1129,8 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str if (dmix->type == SND_PCM_TYPE_DSHARE) { const snd_pcm_channel_area_t *dst_areas; dst_areas = snd_pcm_mmap_areas(spcm); - snd_pcm_areas_silence(dst_areas, 0, spcm->channels, spcm->buffer_size, spcm->format); + snd_pcm_areas_silence(dst_areas, 0, spcm->channels, + spcm->buffer_size, spcm->format); } ret = snd_pcm_start(spcm);
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_direct.c | 63 +++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 33 deletions(-)
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index a4b5214..5984d7f 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -913,30 +913,27 @@ static void save_slave_setting(snd_pcm_direct_t *dmix, snd_pcm_t *spcm) */ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, struct slave_params *params) { - snd_pcm_hw_params_t *hw_params; - snd_pcm_sw_params_t *sw_params; + snd_pcm_hw_params_t hw_params = {0}; + snd_pcm_sw_params_t sw_params = {0}; int ret, buffer_is_not_initialized; snd_pcm_uframes_t boundary; struct pollfd fd; int loops = 10;
- snd_pcm_hw_params_alloca(&hw_params); - snd_pcm_sw_params_alloca(&sw_params); - __again: if (loops-- <= 0) { SNDERR("unable to find a valid configuration for slave"); return -EINVAL; } - ret = snd_pcm_hw_params_any(spcm, hw_params); + ret = snd_pcm_hw_params_any(spcm, &hw_params); if (ret < 0) { SNDERR("snd_pcm_hw_params_any failed"); return ret; } - ret = snd_pcm_hw_params_set_access(spcm, hw_params, + ret = snd_pcm_hw_params_set_access(spcm, &hw_params, SND_PCM_ACCESS_MMAP_INTERLEAVED); if (ret < 0) { - ret = snd_pcm_hw_params_set_access(spcm, hw_params, + ret = snd_pcm_hw_params_set_access(spcm, &hw_params, SND_PCM_ACCESS_MMAP_NONINTERLEAVED); if (ret < 0) { SNDERR("slave plugin does not support mmap interleaved or mmap noninterleaved access"); @@ -946,7 +943,7 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str if (params->format == SND_PCM_FORMAT_UNKNOWN) ret = -EINVAL; else - ret = snd_pcm_hw_params_set_format(spcm, hw_params, + ret = snd_pcm_hw_params_set_format(spcm, &hw_params, params->format); if (ret < 0) { static const snd_pcm_format_t dmix_formats[] = { @@ -965,7 +962,7 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str
for (i = 0; i < ARRAY_SIZE(dmix_formats); ++i) { format = dmix_formats[i]; - ret = snd_pcm_hw_params_set_format(spcm, hw_params, + ret = snd_pcm_hw_params_set_format(spcm, &hw_params, format); if (ret >= 0) break; @@ -973,7 +970,7 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str if (ret < 0 && dmix->type != SND_PCM_TYPE_DMIX) { /* TODO: try to choose a good format */ ret = INTERNAL(snd_pcm_hw_params_set_format_first)(spcm, - hw_params, &format); + &hw_params, &format); } if (ret < 0) { SNDERR("requested or auto-format is not available"); @@ -981,13 +978,13 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str } params->format = format; } - ret = INTERNAL(snd_pcm_hw_params_set_channels_near)(spcm, hw_params, + ret = INTERNAL(snd_pcm_hw_params_set_channels_near)(spcm, &hw_params, (unsigned int *)¶ms->channels); if (ret < 0) { SNDERR("requested count of channels is not available"); return ret; } - ret = INTERNAL(snd_pcm_hw_params_set_rate_near)(spcm, hw_params, + ret = INTERNAL(snd_pcm_hw_params_set_rate_near)(spcm, &hw_params, (unsigned int *)¶ms->rate, 0); if (ret < 0) { SNDERR("requested rate is not available"); @@ -997,14 +994,14 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str buffer_is_not_initialized = 0; if (params->buffer_time > 0) { ret = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(spcm, - hw_params, (unsigned int *)¶ms->buffer_time, 0); + &hw_params, (unsigned int *)¶ms->buffer_time, 0); if (ret < 0) { SNDERR("unable to set buffer time"); return ret; } } else if (params->buffer_size > 0) { ret = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(spcm, - hw_params, (snd_pcm_uframes_t *)¶ms->buffer_size); + &hw_params, (snd_pcm_uframes_t *)¶ms->buffer_size); if (ret < 0) { SNDERR("unable to set buffer size"); return ret; @@ -1015,14 +1012,14 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str
if (params->period_time > 0) { ret = INTERNAL(snd_pcm_hw_params_set_period_time_near)(spcm, - hw_params, (unsigned int *)¶ms->period_time, 0); + &hw_params, (unsigned int *)¶ms->period_time, 0); if (ret < 0) { SNDERR("unable to set period_time"); return ret; } } else if (params->period_size > 0) { ret = INTERNAL(snd_pcm_hw_params_set_period_size_near)(spcm, - hw_params, (snd_pcm_uframes_t *)¶ms->period_size, + &hw_params, (snd_pcm_uframes_t *)¶ms->period_size, 0); if (ret < 0) { SNDERR("unable to set period_size"); @@ -1033,7 +1030,7 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str if (buffer_is_not_initialized && params->periods > 0) { unsigned int periods = params->periods; ret = INTERNAL(snd_pcm_hw_params_set_periods_near)(spcm, - hw_params, ¶ms->periods, 0); + &hw_params, ¶ms->periods, 0); if (ret < 0) { SNDERR("unable to set requested periods"); return ret; @@ -1052,7 +1049,7 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str } } - ret = snd_pcm_hw_params(spcm, hw_params); + ret = snd_pcm_hw_params(spcm, &hw_params); if (ret < 0) { SNDERR("unable to install hw params"); return ret; @@ -1060,34 +1057,34 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str
/* store some hw_params values to shared info */ dmix->shmptr->hw.format = - snd_mask_value(hw_param_mask(hw_params, + snd_mask_value(hw_param_mask(&hw_params, SND_PCM_HW_PARAM_FORMAT)); dmix->shmptr->hw.rate = - *hw_param_interval(hw_params, SND_PCM_HW_PARAM_RATE); + *hw_param_interval(&hw_params, SND_PCM_HW_PARAM_RATE); dmix->shmptr->hw.buffer_size = - *hw_param_interval(hw_params, SND_PCM_HW_PARAM_BUFFER_SIZE); + *hw_param_interval(&hw_params, SND_PCM_HW_PARAM_BUFFER_SIZE); dmix->shmptr->hw.buffer_time = - *hw_param_interval(hw_params, SND_PCM_HW_PARAM_BUFFER_TIME); + *hw_param_interval(&hw_params, SND_PCM_HW_PARAM_BUFFER_TIME); dmix->shmptr->hw.period_size = - *hw_param_interval(hw_params, SND_PCM_HW_PARAM_PERIOD_SIZE); + *hw_param_interval(&hw_params, SND_PCM_HW_PARAM_PERIOD_SIZE); dmix->shmptr->hw.period_time = - *hw_param_interval(hw_params, SND_PCM_HW_PARAM_PERIOD_TIME); + *hw_param_interval(&hw_params, SND_PCM_HW_PARAM_PERIOD_TIME); dmix->shmptr->hw.periods = - *hw_param_interval(hw_params, SND_PCM_HW_PARAM_PERIODS); + *hw_param_interval(&hw_params, SND_PCM_HW_PARAM_PERIODS);
- ret = snd_pcm_sw_params_current(spcm, sw_params); + ret = snd_pcm_sw_params_current(spcm, &sw_params); if (ret < 0) { SNDERR("unable to get current sw_params"); return ret; }
- ret = snd_pcm_sw_params_get_boundary(sw_params, &boundary); + ret = snd_pcm_sw_params_get_boundary(&sw_params, &boundary); if (ret < 0) { SNDERR("unable to get boundary"); return ret; } - ret = snd_pcm_sw_params_set_stop_threshold(spcm, sw_params, boundary); + ret = snd_pcm_sw_params_set_stop_threshold(spcm, &sw_params, boundary); if (ret < 0) { SNDERR("unable to set stop threshold"); return ret; @@ -1097,7 +1094,7 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str * the slave timestamp is copied appropriately in dsnoop/dmix/dshare * based on the tstamp_mode of each client */ - ret = snd_pcm_sw_params_set_tstamp_mode(spcm, sw_params, + ret = snd_pcm_sw_params_set_tstamp_mode(spcm, &sw_params, SND_PCM_TSTAMP_ENABLE); if (ret < 0) { SNDERR("unable to tstamp mode MMAP"); @@ -1107,12 +1104,12 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str if (dmix->type != SND_PCM_TYPE_DMIX) goto __skip_silencing;
- ret = snd_pcm_sw_params_set_silence_threshold(spcm, sw_params, 0); + ret = snd_pcm_sw_params_set_silence_threshold(spcm, &sw_params, 0); if (ret < 0) { SNDERR("unable to set silence threshold"); return ret; } - ret = snd_pcm_sw_params_set_silence_size(spcm, sw_params, boundary); + ret = snd_pcm_sw_params_set_silence_size(spcm, &sw_params, boundary); if (ret < 0) { SNDERR("unable to set silence threshold (please upgrade to 0.9.0rc8+ driver)"); return ret; @@ -1120,7 +1117,7 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str
__skip_silencing:
- ret = snd_pcm_sw_params(spcm, sw_params); + ret = snd_pcm_sw_params(spcm, &sw_params); if (ret < 0) { SNDERR("unable to install sw params (please upgrade to 0.9.0rc8+ driver)"); return ret;
This commit applies code format according to typical and moderate rule, for snd_pcm_direct_initialize_poll_fd().
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_direct.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index 5984d7f..8a53cef 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -1189,14 +1189,16 @@ int snd_pcm_direct_initialize_poll_fd(snd_pcm_direct_t *dmix) return ret; } sprintf(name, "hw:CLASS=%i,SCLASS=0,CARD=%i,DEV=%i,SUBDEV=%i", - (int)SND_TIMER_CLASS_PCM, - snd_pcm_info_get_card(info), - snd_pcm_info_get_device(info), - snd_pcm_info_get_subdevice(info) * 2 + capture); - ret = snd_timer_open(&dmix->timer, name, SND_TIMER_OPEN_NONBLOCK | SND_TIMER_OPEN_TREAD); + (int)SND_TIMER_CLASS_PCM, + snd_pcm_info_get_card(info), + snd_pcm_info_get_device(info), + snd_pcm_info_get_subdevice(info) * 2 + capture); + ret = snd_timer_open(&dmix->timer, name, + SND_TIMER_OPEN_NONBLOCK | SND_TIMER_OPEN_TREAD); if (ret < 0) { dmix->tread = 0; - ret = snd_timer_open(&dmix->timer, name, SND_TIMER_OPEN_NONBLOCK); + ret = snd_timer_open(&dmix->timer, name, + SND_TIMER_OPEN_NONBLOCK); if (ret < 0) { SNDERR("unable to open timer '%s'", name); return ret;
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_direct.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index 8a53cef..dbd7e2b 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -1176,23 +1176,22 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str int snd_pcm_direct_initialize_poll_fd(snd_pcm_direct_t *dmix) { int ret; - snd_pcm_info_t *info; + snd_pcm_info_t info = {0}; char name[128]; int capture = dmix->type == SND_PCM_TYPE_DSNOOP ? 1 : 0;
dmix->tread = 1; dmix->timer_need_poll = 0; - snd_pcm_info_alloca(&info); - ret = snd_pcm_info(dmix->spcm, info); + ret = snd_pcm_info(dmix->spcm, &info); if (ret < 0) { SNDERR("unable to info for slave pcm"); return ret; } sprintf(name, "hw:CLASS=%i,SCLASS=0,CARD=%i,DEV=%i,SUBDEV=%i", (int)SND_TIMER_CLASS_PCM, - snd_pcm_info_get_card(info), - snd_pcm_info_get_device(info), - snd_pcm_info_get_subdevice(info) * 2 + capture); + snd_pcm_info_get_card(&info), + snd_pcm_info_get_device(&info), + snd_pcm_info_get_subdevice(&info) * 2 + capture); ret = snd_timer_open(&dmix->timer, name, SND_TIMER_OPEN_NONBLOCK | SND_TIMER_OPEN_TREAD); if (ret < 0) {
This commit applies code format according to typical and moderate rule, for snd_pcm_direct_set_timer_params().
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_direct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index dbd7e2b..50d5539 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -1375,7 +1375,7 @@ int snd_pcm_direct_set_timer_params(snd_pcm_direct_t *dmix) ret = snd_timer_params(dmix->timer, params); if (ret < 0) { SNDERR("unable to set timer parameters"); - return ret; + return ret; } return 0; }
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_direct.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index 50d5539..c3925cc 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -1358,21 +1358,20 @@ int snd_pcm_direct_initialize_secondary_slave(snd_pcm_direct_t *dmix,
int snd_pcm_direct_set_timer_params(snd_pcm_direct_t *dmix) { - snd_timer_params_t *params; + snd_timer_params_t params = {0}; unsigned int filter; int ret;
- snd_timer_params_alloca(¶ms); - snd_timer_params_set_auto_start(params, 1); + snd_timer_params_set_auto_start(¶ms, 1); if (dmix->type != SND_PCM_TYPE_DSNOOP) - snd_timer_params_set_early_event(params, 1); - snd_timer_params_set_ticks(params, 1); + snd_timer_params_set_early_event(¶ms, 1); + snd_timer_params_set_ticks(¶ms, 1); if (dmix->tread) { filter = (1<<SND_TIMER_EVENT_TICK) | dmix->timer_events; - snd_timer_params_set_filter(params, filter); + snd_timer_params_set_filter(¶ms, filter); } - ret = snd_timer_params(dmix->timer, params); + ret = snd_timer_params(dmix->timer, ¶ms); if (ret < 0) { SNDERR("unable to set timer parameters"); return ret;
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_hooks.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/pcm/pcm_hooks.c b/src/pcm/pcm_hooks.c index ce1cf36..66e7051 100644 --- a/src/pcm/pcm_hooks.c +++ b/src/pcm/pcm_hooks.c @@ -667,7 +667,7 @@ int _snd_pcm_hook_ctl_elems_install(snd_pcm_t *pcm, snd_config_t *conf) { int err; int card; - snd_pcm_info_t *info; + snd_pcm_info_t info = {0}; char ctl_name[16]; snd_ctl_t *ctl; snd_sctl_t *sctl = NULL; @@ -675,11 +675,11 @@ int _snd_pcm_hook_ctl_elems_install(snd_pcm_t *pcm, snd_config_t *conf) snd_pcm_hook_t *h_hw_params = NULL, *h_hw_free = NULL, *h_close = NULL; assert(conf); assert(snd_config_get_type(conf) == SND_CONFIG_TYPE_COMPOUND); - snd_pcm_info_alloca(&info); - err = snd_pcm_info(pcm, info); + + err = snd_pcm_info(pcm, &info); if (err < 0) return err; - card = snd_pcm_info_get_card(info); + card = snd_pcm_info_get_card(&info); if (card < 0) { SNDERR("No card for this PCM"); return -EINVAL;
This commit applies code format according to typical and moderate rule, for snd_pcm_hw_change_timer().
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_hw.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index 5aa987b..0daaccc 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -357,9 +357,19 @@ static int snd_pcm_hw_change_timer(snd_pcm_t *pcm, int enable) if (enable) { snd_timer_params_alloca(¶ms); - err = snd_timer_hw_open(&hw->period_timer, "hw-pcm-period-event", SND_TIMER_CLASS_PCM, SND_TIMER_SCLASS_NONE, hw->card, hw->device, (hw->subdevice << 1) | (pcm->stream & 1), SND_TIMER_OPEN_NONBLOCK | SND_TIMER_OPEN_TREAD); + err = snd_timer_hw_open(&hw->period_timer, + "hw-pcm-period-event", + SND_TIMER_CLASS_PCM, SND_TIMER_SCLASS_NONE, + hw->card, hw->device, + (hw->subdevice << 1) | (pcm->stream & 1), + SND_TIMER_OPEN_NONBLOCK | SND_TIMER_OPEN_TREAD); if (err < 0) { - err = snd_timer_hw_open(&hw->period_timer, "hw-pcm-period-event", SND_TIMER_CLASS_PCM, SND_TIMER_SCLASS_NONE, hw->card, hw->device, (hw->subdevice << 1) | (pcm->stream & 1), SND_TIMER_OPEN_NONBLOCK); + err = snd_timer_hw_open(&hw->period_timer, + "hw-pcm-period-event", + SND_TIMER_CLASS_PCM, SND_TIMER_SCLASS_NONE, + hw->card, hw->device, + (hw->subdevice << 1) | (pcm->stream & 1), + SND_TIMER_OPEN_NONBLOCK); return err; } if (snd_timer_poll_descriptors_count(hw->period_timer) != 1) { @@ -368,7 +378,8 @@ static int snd_pcm_hw_change_timer(snd_pcm_t *pcm, int enable) } hw->period_timer_pfd.events = POLLIN; hw->period_timer_pfd.revents = 0; - snd_timer_poll_descriptors(hw->period_timer, &hw->period_timer_pfd, 1); + snd_timer_poll_descriptors(hw->period_timer, + &hw->period_timer_pfd, 1); hw->period_timer_need_poll = 0; suspend = 1<<SND_TIMER_EVENT_MSUSPEND; resume = 1<<SND_TIMER_EVENT_MRESUME; @@ -377,10 +388,12 @@ static int snd_pcm_hw_change_timer(snd_pcm_t *pcm, int enable) */ { int ver = 0; - ioctl(hw->period_timer_pfd.fd, SNDRV_TIMER_IOCTL_PVERSION, &ver); - /* In older versions, check via poll before read() is needed - * because of the confliction between TIMER_START and - * FIONBIO ioctls. + ioctl(hw->period_timer_pfd.fd, + SNDRV_TIMER_IOCTL_PVERSION, &ver); + /* + * In older versions, check via poll before read() is + * needed because of the confliction between + * TIMER_START and FIONBIO ioctls. */ if (ver < SNDRV_PROTOCOL_VERSION(2, 0, 4)) hw->period_timer_need_poll = 1;
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_hw.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index 0daaccc..864d5fa 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -351,12 +351,11 @@ static void snd_pcm_hw_close_timer(snd_pcm_hw_t *hw) static int snd_pcm_hw_change_timer(snd_pcm_t *pcm, int enable) { snd_pcm_hw_t *hw = pcm->private_data; - snd_timer_params_t *params; + snd_timer_params_t params = {0}; unsigned int suspend, resume; int err; if (enable) { - snd_timer_params_alloca(¶ms); err = snd_timer_hw_open(&hw->period_timer, "hw-pcm-period-event", SND_TIMER_CLASS_PCM, SND_TIMER_SCLASS_NONE, @@ -406,11 +405,11 @@ static int snd_pcm_hw_change_timer(snd_pcm_t *pcm, int enable) resume = 1<<SND_TIMER_EVENT_MCONTINUE; } } - snd_timer_params_set_auto_start(params, 1); - snd_timer_params_set_ticks(params, 1); - snd_timer_params_set_filter(params, (1<<SND_TIMER_EVENT_TICK) | + snd_timer_params_set_auto_start(¶ms, 1); + snd_timer_params_set_ticks(¶ms, 1); + snd_timer_params_set_filter(¶ms, (1<<SND_TIMER_EVENT_TICK) | suspend | resume); - err = snd_timer_params(hw->period_timer, params); + err = snd_timer_params(hw->period_timer, ¶ms); if (err < 0) { snd_pcm_hw_close_timer(hw); return err;
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_hw.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index 864d5fa..e7a2393 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -1094,7 +1094,7 @@ snd_pcm_query_chmaps_from_hw(int card, int dev, int subdev, snd_pcm_stream_t stream) { snd_ctl_t *ctl; - snd_ctl_elem_id_t *id; + snd_ctl_elem_id_t id = {0}; unsigned int tlv[2048], *start; snd_pcm_chmap_query_t **map; int i, ret, nums; @@ -1105,9 +1105,8 @@ snd_pcm_query_chmaps_from_hw(int card, int dev, int subdev, return NULL; }
- snd_ctl_elem_id_alloca(&id); - __fill_chmap_ctl_id(id, dev, subdev, stream); - ret = snd_ctl_elem_tlv_read(ctl, id, tlv, sizeof(tlv)); + __fill_chmap_ctl_id(&id, dev, subdev, stream); + ret = snd_ctl_elem_tlv_read(ctl, &id, tlv, sizeof(tlv)); snd_ctl_close(ctl); if (ret < 0) { SYSMSG("Cannot read Channel Map TLV\n");
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_hw.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index e7a2393..20c233b 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -1206,8 +1206,8 @@ static snd_pcm_chmap_t *snd_pcm_hw_get_chmap(snd_pcm_t *pcm) snd_pcm_hw_t *hw = pcm->private_data; snd_pcm_chmap_t *map; snd_ctl_t *ctl; - snd_ctl_elem_id_t *id; - snd_ctl_elem_value_t *val; + snd_ctl_elem_id_t id = {0}; + snd_ctl_elem_value_t val = {0}; unsigned int i; int ret;
@@ -1241,11 +1241,9 @@ static snd_pcm_chmap_t *snd_pcm_hw_get_chmap(snd_pcm_t *pcm) chmap_caps_set_error(hw, CHMAP_CTL_GET); return NULL; } - snd_ctl_elem_value_alloca(&val); - snd_ctl_elem_id_alloca(&id); - fill_chmap_ctl_id(pcm, id); - snd_ctl_elem_value_set_id(val, id); - ret = snd_ctl_elem_read(ctl, val); + fill_chmap_ctl_id(pcm, &id); + snd_ctl_elem_value_set_id(&val, &id); + ret = snd_ctl_elem_read(ctl, &val); snd_ctl_close(ctl); if (ret < 0) { free(map); @@ -1254,7 +1252,7 @@ static snd_pcm_chmap_t *snd_pcm_hw_get_chmap(snd_pcm_t *pcm) return NULL; } for (i = 0; i < pcm->channels; i++) - map->pos[i] = snd_ctl_elem_value_get_integer(val, i); + map->pos[i] = snd_ctl_elem_value_get_integer(&val, i); chmap_caps_set_ok(hw, CHMAP_CTL_GET); return map; }
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_hw.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index 20c233b..3a5634c 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -1261,8 +1261,8 @@ static int snd_pcm_hw_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map) { snd_pcm_hw_t *hw = pcm->private_data; snd_ctl_t *ctl; - snd_ctl_elem_id_t *id; - snd_ctl_elem_value_t *val; + snd_ctl_elem_id_t id = {0}; + snd_ctl_elem_value_t val = {0}; unsigned int i; int ret;
@@ -1287,13 +1287,12 @@ static int snd_pcm_hw_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map) chmap_caps_set_error(hw, CHMAP_CTL_SET); return ret; } - snd_ctl_elem_id_alloca(&id); - snd_ctl_elem_value_alloca(&val); - fill_chmap_ctl_id(pcm, id); - snd_ctl_elem_value_set_id(val, id); + + fill_chmap_ctl_id(pcm, &id); + snd_ctl_elem_value_set_id(&val, &id); for (i = 0; i < map->channels; i++) - snd_ctl_elem_value_set_integer(val, i, map->pos[i]); - ret = snd_ctl_elem_write(ctl, val); + snd_ctl_elem_value_set_integer(&val, i, map->pos[i]); + ret = snd_ctl_elem_write(ctl, &val); snd_ctl_close(ctl); if (ret >= 0) chmap_caps_set_ok(hw, CHMAP_CTL_SET);
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_simple.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/pcm/pcm_simple.c b/src/pcm/pcm_simple.c index ce11083..3ae24ff 100644 --- a/src/pcm/pcm_simple.c +++ b/src/pcm/pcm_simple.c @@ -164,14 +164,11 @@ int snd_spcm_init(snd_pcm_t *pcm, snd_spcm_xrun_type_t xrun_type) { int err; - snd_pcm_hw_params_t *hw_params; - snd_pcm_sw_params_t *sw_params; + snd_pcm_hw_params_t hw_params = {0}; + snd_pcm_sw_params_t sw_params = {0}; unsigned int rrate; unsigned int buffer_time;
- snd_pcm_hw_params_alloca(&hw_params); - snd_pcm_sw_params_alloca(&sw_params); - assert(pcm); assert(rate >= 5000 && rate <= 192000); assert(channels >= 1 && channels <= 512); @@ -180,13 +177,13 @@ int snd_spcm_init(snd_pcm_t *pcm, err = set_buffer_time(latency, &buffer_time); if (err < 0) return err; - err = set_hw_params(pcm, hw_params, + err = set_hw_params(pcm, &hw_params, &rrate, channels, format, subformat, &buffer_time, NULL, access); if (err < 0) return err;
- err = set_sw_params(pcm, sw_params, xrun_type); + err = set_sw_params(pcm, &sw_params, xrun_type); if (err < 0) return err;
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_simple.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/pcm/pcm_simple.c b/src/pcm/pcm_simple.c index 3ae24ff..8985987 100644 --- a/src/pcm/pcm_simple.c +++ b/src/pcm/pcm_simple.c @@ -218,16 +218,13 @@ int snd_spcm_init_duplex(snd_pcm_t *playback_pcm, snd_spcm_duplex_type_t duplex_type) { int err, i; - snd_pcm_hw_params_t *hw_params; - snd_pcm_sw_params_t *sw_params; + snd_pcm_hw_params_t hw_params = {0}; + snd_pcm_sw_params_t sw_params = {0}; unsigned int rrate; unsigned int xbuffer_time, buffer_time[2]; unsigned int period_time[2]; snd_pcm_t *pcms[2];
- snd_pcm_hw_params_alloca(&hw_params); - snd_pcm_sw_params_alloca(&sw_params); - assert(playback_pcm); assert(capture_pcm); assert(rate >= 5000 && rate <= 192000); @@ -247,7 +244,7 @@ int snd_spcm_init_duplex(snd_pcm_t *playback_pcm, buffer_time[i] = xbuffer_time; period_time[i] = i > 0 ? period_time[0] : 0; rrate = rate; - err = set_hw_params(pcms[i], hw_params, + err = set_hw_params(pcms[i], &hw_params, &rrate, channels, format, subformat, &buffer_time[i], &period_time[i], access); if (err < 0) @@ -266,7 +263,7 @@ int snd_spcm_init_duplex(snd_pcm_t *playback_pcm, */ __sw_params: for (i = 0; i < 2; i++) { - err = set_sw_params(pcms[i], sw_params, xrun_type); + err = set_sw_params(pcms[i], &sw_params, xrun_type); if (err < 0) return err; }
This commit applies code format according to typical and moderate rule, for softvol_load_control().
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_softvol.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/pcm/pcm_softvol.c b/src/pcm/pcm_softvol.c index a667c85..4d2c62a 100644 --- a/src/pcm/pcm_softvol.c +++ b/src/pcm/pcm_softvol.c @@ -734,7 +734,8 @@ static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol, else if (svol->max_dB < 0) svol->zero_dB_val = 0; /* there is no 0 dB setting */ else - svol->zero_dB_val = (min_dB / (min_dB - max_dB)) * svol->max_val; + svol->zero_dB_val = (min_dB / (min_dB - max_dB)) * + svol->max_val; snd_ctl_elem_info_alloca(&cinfo); snd_ctl_elem_info_set_id(cinfo, ctl_id); @@ -758,11 +759,13 @@ static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol, cinfo->count != (unsigned int)cchannels || cinfo->value.integer.min != 0 || cinfo->value.integer.max != resolution - 1) { - if ((err = snd_ctl_elem_remove(svol->ctl, &cinfo->id)) < 0) { + err = snd_ctl_elem_remove(svol->ctl, &cinfo->id); + if (err < 0) { SNDERR("Control %s mismatch", tmp_name); return err; } - snd_ctl_elem_info_set_id(cinfo, ctl_id); /* reset numid */ + /* reset numid */ + snd_ctl_elem_info_set_id(cinfo, ctl_id); if ((err = add_user_ctl(svol, cinfo, cchannels)) < 0) { SNDERR("Cannot add a control"); return err; @@ -770,7 +773,8 @@ static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol, } else if (svol->max_val > 1) { /* check TLV availability */ unsigned int tlv[4]; - err = snd_ctl_elem_tlv_read(svol->ctl, &cinfo->id, tlv, sizeof(tlv)); + err = snd_ctl_elem_tlv_read(svol->ctl, &cinfo->id, tlv, + sizeof(tlv)); if (err < 0) add_tlv_info(svol, cinfo); } @@ -780,7 +784,8 @@ static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol, return 0;
/* set up dB table */ - if (min_dB == PRESET_MIN_DB && max_dB == ZERO_DB && resolution == PRESET_RESOLUTION) + if (min_dB == PRESET_MIN_DB && max_dB == ZERO_DB && + resolution == PRESET_RESOLUTION) svol->dB_value = (unsigned int*)preset_dB_value; else { #ifndef HAVE_SOFT_FLOAT @@ -792,8 +797,11 @@ static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol, svol->min_dB = min_dB; svol->max_dB = max_dB; for (i = 0; i <= svol->max_val; i++) { - double db = svol->min_dB + (i * (svol->max_dB - svol->min_dB)) / svol->max_val; - double v = (pow(10.0, db / 20.0) * (double)(1 << VOL_SCALE_SHIFT)); + double db = svol->min_dB + + (i * (svol->max_dB - svol->min_dB)) / + svol->max_val; + double v = (pow(10.0, db / 20.0) * + (double)(1 << VOL_SCALE_SHIFT)); svol->dB_value[i] = (unsigned int)v; } if (svol->zero_dB_val)
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_softvol.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/src/pcm/pcm_softvol.c b/src/pcm/pcm_softvol.c index 4d2c62a..fc45d6d 100644 --- a/src/pcm/pcm_softvol.c +++ b/src/pcm/pcm_softvol.c @@ -702,17 +702,16 @@ static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol, int resolution) { char tmp_name[32]; - snd_pcm_info_t *info; - snd_ctl_elem_info_t *cinfo; + snd_pcm_info_t info = {0}; + snd_ctl_elem_info_t cinfo = {0}; int err; unsigned int i;
if (ctl_card < 0) { - snd_pcm_info_alloca(&info); - err = snd_pcm_info(pcm, info); + err = snd_pcm_info(pcm, &info); if (err < 0) return err; - ctl_card = snd_pcm_info_get_card(info); + ctl_card = snd_pcm_info_get_card(&info); if (ctl_card < 0) { SNDERR("No card defined for softvol control"); return -EINVAL; @@ -737,46 +736,45 @@ static int softvol_load_control(snd_pcm_t *pcm, snd_pcm_softvol_t *svol, svol->zero_dB_val = (min_dB / (min_dB - max_dB)) * svol->max_val; - snd_ctl_elem_info_alloca(&cinfo); - snd_ctl_elem_info_set_id(cinfo, ctl_id); - if ((err = snd_ctl_elem_info(svol->ctl, cinfo)) < 0) { + snd_ctl_elem_info_set_id(&cinfo, ctl_id); + if ((err = snd_ctl_elem_info(svol->ctl, &cinfo)) < 0) { if (err != -ENOENT) { SNDERR("Cannot get info for CTL %s", tmp_name); return err; } - err = add_user_ctl(svol, cinfo, cchannels); + err = add_user_ctl(svol, &cinfo, cchannels); if (err < 0) { SNDERR("Cannot add a control"); return err; } } else { - if (! (cinfo->access & SNDRV_CTL_ELEM_ACCESS_USER)) { + if (! (cinfo.access & SNDRV_CTL_ELEM_ACCESS_USER)) { /* hardware control exists */ return 1; /* notify */
- } else if ((cinfo->type != SND_CTL_ELEM_TYPE_INTEGER && - cinfo->type != SND_CTL_ELEM_TYPE_BOOLEAN) || - cinfo->count != (unsigned int)cchannels || - cinfo->value.integer.min != 0 || - cinfo->value.integer.max != resolution - 1) { - err = snd_ctl_elem_remove(svol->ctl, &cinfo->id); + } else if ((cinfo.type != SND_CTL_ELEM_TYPE_INTEGER && + cinfo.type != SND_CTL_ELEM_TYPE_BOOLEAN) || + cinfo.count != (unsigned int)cchannels || + cinfo.value.integer.min != 0 || + cinfo.value.integer.max != resolution - 1) { + err = snd_ctl_elem_remove(svol->ctl, &cinfo.id); if (err < 0) { SNDERR("Control %s mismatch", tmp_name); return err; } /* reset numid */ - snd_ctl_elem_info_set_id(cinfo, ctl_id); - if ((err = add_user_ctl(svol, cinfo, cchannels)) < 0) { + snd_ctl_elem_info_set_id(&cinfo, ctl_id); + if ((err = add_user_ctl(svol, &cinfo, cchannels)) < 0) { SNDERR("Cannot add a control"); return err; } } else if (svol->max_val > 1) { /* check TLV availability */ unsigned int tlv[4]; - err = snd_ctl_elem_tlv_read(svol->ctl, &cinfo->id, tlv, + err = snd_ctl_elem_tlv_read(svol->ctl, &cinfo.id, tlv, sizeof(tlv)); if (err < 0) - add_tlv_info(svol, cinfo); + add_tlv_info(svol, &cinfo); } }
This commit applies code format according to typical and moderate rule, for _snd_pcm_softvol_open().
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_softvol.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/pcm/pcm_softvol.c b/src/pcm/pcm_softvol.c index fc45d6d..e2345b3 100644 --- a/src/pcm/pcm_softvol.c +++ b/src/pcm/pcm_softvol.c @@ -1085,8 +1085,7 @@ int _snd_pcm_softvol_open(snd_pcm_t **pcmp, const char *name, sformat != SND_PCM_FORMAT_S24_3LE && sformat != SND_PCM_FORMAT_S32_LE && sformat != SND_PCM_FORMAT_S32_BE) { - SNDERR("only S16_LE, S16_BE, S24_3LE, S32_LE or S32_BE format " - "is supported"); + SNDERR("only S16_LE, S16_BE, S24_3LE, S32_LE or S32_BE format is supported"); snd_config_delete(sconf); return -EINVAL; } @@ -1094,12 +1093,15 @@ int _snd_pcm_softvol_open(snd_pcm_t **pcmp, const char *name, snd_config_delete(sconf); if (err < 0) return err; - if ((err = snd_pcm_parse_control_id(control, ctl_id, &card, &cchannels, NULL)) < 0) { + err = snd_pcm_parse_control_id(control, ctl_id, &card, + &cchannels, NULL); + if (err < 0) { snd_pcm_close(spcm); return err; } - err = snd_pcm_softvol_open(pcmp, name, sformat, card, ctl_id, cchannels, - min_dB, max_dB, resolution, spcm, 1); + err = snd_pcm_softvol_open(pcmp, name, sformat, card, ctl_id, + cchannels, min_dB, max_dB, + resolution, spcm, 1); if (err < 0) snd_pcm_close(spcm); }
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/pcm/pcm_softvol.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/pcm/pcm_softvol.c b/src/pcm/pcm_softvol.c index e2345b3..6135778 100644 --- a/src/pcm/pcm_softvol.c +++ b/src/pcm/pcm_softvol.c @@ -995,7 +995,7 @@ int _snd_pcm_softvol_open(snd_pcm_t **pcmp, const char *name, snd_config_t *slave = NULL, *sconf; snd_config_t *control = NULL; snd_pcm_format_t sformat = SND_PCM_FORMAT_UNKNOWN; - snd_ctl_elem_id_t *ctl_id; + snd_ctl_elem_id_t ctl_id = {0}; int resolution = PRESET_RESOLUTION; double min_dB = PRESET_MIN_DB; double max_dB = ZERO_DB; @@ -1074,7 +1074,6 @@ int _snd_pcm_softvol_open(snd_pcm_t **pcmp, const char *name, mode, conf); snd_config_delete(sconf); } else { - snd_ctl_elem_id_alloca(&ctl_id); err = snd_pcm_slave_conf(root, slave, &sconf, 1, SND_PCM_HW_PARAM_FORMAT, 0, &sformat); if (err < 0) @@ -1093,13 +1092,13 @@ int _snd_pcm_softvol_open(snd_pcm_t **pcmp, const char *name, snd_config_delete(sconf); if (err < 0) return err; - err = snd_pcm_parse_control_id(control, ctl_id, &card, + err = snd_pcm_parse_control_id(control, &ctl_id, &card, &cchannels, NULL); if (err < 0) { snd_pcm_close(spcm); return err; } - err = snd_pcm_softvol_open(pcmp, name, sformat, card, ctl_id, + err = snd_pcm_softvol_open(pcmp, name, sformat, card, &ctl_id, cchannels, min_dB, max_dB, resolution, spcm, 1); if (err < 0)
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/confmisc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/confmisc.c b/src/confmisc.c index ae0275f..3f12e34 100644 --- a/src/confmisc.c +++ b/src/confmisc.c @@ -664,7 +664,7 @@ SND_DLSYM_BUILD_VERSION(snd_func_private_string, SND_CONFIG_DLSYM_VERSION_EVALUA int snd_determine_driver(int card, char **driver) { snd_ctl_t *ctl = NULL; - snd_ctl_card_info_t *info; + snd_ctl_card_info_t info = {0}; char *res = NULL; int err;
@@ -674,13 +674,12 @@ int snd_determine_driver(int card, char **driver) SNDERR("could not open control for card %i", card); goto __error; } - snd_ctl_card_info_alloca(&info); - err = snd_ctl_card_info(ctl, info); + err = snd_ctl_card_info(ctl, &info); if (err < 0) { SNDERR("snd_ctl_card_info error: %s", snd_strerror(err)); goto __error; } - res = strdup(snd_ctl_card_info_get_driver(info)); + res = strdup(snd_ctl_card_info_get_driver(&info)); if (res == NULL) err = -ENOMEM; else {
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/confmisc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/confmisc.c b/src/confmisc.c index 3f12e34..7763511 100644 --- a/src/confmisc.c +++ b/src/confmisc.c @@ -862,7 +862,7 @@ int snd_func_card_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src, snd_config_t *private_data) { snd_ctl_t *ctl = NULL; - snd_ctl_card_info_t *info; + snd_ctl_card_info_t info = {0}; const char *id; int card, err; @@ -874,8 +874,7 @@ int snd_func_card_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src, SNDERR("could not open control for card %i", card); goto __error; } - snd_ctl_card_info_alloca(&info); - err = snd_ctl_card_info(ctl, info); + err = snd_ctl_card_info(ctl, &info); if (err < 0) { SNDERR("snd_ctl_card_info error: %s", snd_strerror(err)); goto __error; @@ -883,7 +882,7 @@ int snd_func_card_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src, err = snd_config_get_id(src, &id); if (err >= 0) err = snd_config_imake_string(dst, id, - snd_ctl_card_info_get_id(info)); + snd_ctl_card_info_get_id(&info)); __error: if (ctl) snd_ctl_close(ctl);
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/confmisc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/confmisc.c b/src/confmisc.c index 7763511..fd10b34 100644 --- a/src/confmisc.c +++ b/src/confmisc.c @@ -913,7 +913,7 @@ int snd_func_card_name(snd_config_t **dst, snd_config_t *root, snd_config_t *src, snd_config_t *private_data) { snd_ctl_t *ctl = NULL; - snd_ctl_card_info_t *info; + snd_ctl_card_info_t info = {0}; const char *id; int card, err; @@ -925,8 +925,7 @@ int snd_func_card_name(snd_config_t **dst, snd_config_t *root, SNDERR("could not open control for card %i", card); goto __error; } - snd_ctl_card_info_alloca(&info); - err = snd_ctl_card_info(ctl, info); + err = snd_ctl_card_info(ctl, &info); if (err < 0) { SNDERR("snd_ctl_card_info error: %s", snd_strerror(err)); goto __error; @@ -934,7 +933,7 @@ int snd_func_card_name(snd_config_t **dst, snd_config_t *root, err = snd_config_get_id(src, &id); if (err >= 0) err = snd_config_imake_safe_string(dst, id, - snd_ctl_card_info_get_name(info)); + snd_ctl_card_info_get_name(&info)); __error: if (ctl) snd_ctl_close(ctl);
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/confmisc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/confmisc.c b/src/confmisc.c index fd10b34..2275ccd 100644 --- a/src/confmisc.c +++ b/src/confmisc.c @@ -969,7 +969,7 @@ int snd_func_pcm_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src, v { snd_config_t *n; snd_ctl_t *ctl = NULL; - snd_pcm_info_t *info; + snd_pcm_info_t info = {0}; const char *id; long card, device, subdevice = 0; int err; @@ -1009,17 +1009,17 @@ int snd_func_pcm_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src, v SNDERR("could not open control for card %li", card); goto __error; } - snd_pcm_info_alloca(&info); - snd_pcm_info_set_device(info, device); - snd_pcm_info_set_subdevice(info, subdevice); - err = snd_ctl_pcm_info(ctl, info); + snd_pcm_info_set_device(&info, device); + snd_pcm_info_set_subdevice(&info, subdevice); + err = snd_ctl_pcm_info(ctl, &info); if (err < 0) { SNDERR("snd_ctl_pcm_info error: %s", snd_strerror(err)); goto __error; } err = snd_config_get_id(src, &id); if (err >= 0) - err = snd_config_imake_string(dst, id, snd_pcm_info_get_id(info)); + err = snd_config_imake_string(dst, id, + snd_pcm_info_get_id(&info)); __error: if (ctl) snd_ctl_close(ctl);
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/confmisc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/confmisc.c b/src/confmisc.c index 2275ccd..99be48b 100644 --- a/src/confmisc.c +++ b/src/confmisc.c @@ -1053,7 +1053,7 @@ int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_confi { snd_config_t *n; snd_ctl_t *ctl = NULL; - snd_pcm_info_t *info; + snd_pcm_info_t info = {0}; const char *id; int card = -1, dev; long class, index; @@ -1091,7 +1091,6 @@ int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_confi goto __out; }
- snd_pcm_info_alloca(&info); while(1) { err = snd_card_next(&card); if (err < 0) { @@ -1106,7 +1105,6 @@ int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_confi goto __out; } dev = -1; - memset(info, 0, snd_pcm_info_sizeof()); while(1) { err = snd_ctl_pcm_next_device(ctl, &dev); if (err < 0) { @@ -1115,11 +1113,11 @@ int snd_func_pcm_args_by_class(snd_config_t **dst, snd_config_t *root, snd_confi } if (dev < 0) break; - snd_pcm_info_set_device(info, dev); - err = snd_ctl_pcm_info(ctl, info); + snd_pcm_info_set_device(&info, dev); + err = snd_ctl_pcm_info(ctl, &info); if (err < 0) continue; - if (snd_pcm_info_get_class(info) == (snd_pcm_class_t)class && + if (snd_pcm_info_get_class(&info) == (snd_pcm_class_t)class && index == idx++) goto __out; }
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/confmisc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/confmisc.c b/src/confmisc.c index 99be48b..a985f14 100644 --- a/src/confmisc.c +++ b/src/confmisc.c @@ -1162,7 +1162,7 @@ SND_DLSYM_BUILD_VERSION(snd_func_pcm_args_by_class, SND_CONFIG_DLSYM_VERSION_EVA int snd_func_private_pcm_subdevice(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED, snd_config_t *src, snd_config_t *private_data) { - snd_pcm_info_t *info; + snd_pcm_info_t info = {0}; const char *id; const void *data; snd_pcm_t *pcm; @@ -1181,15 +1181,15 @@ int snd_func_private_pcm_subdevice(snd_config_t **dst, snd_config_t *root ATTRIB SNDERR("field pcm_handle is not a pointer"); return err; } - snd_pcm_info_alloca(&info); - err = snd_pcm_info(pcm, info); + err = snd_pcm_info(pcm, &info); if (err < 0) { SNDERR("snd_ctl_pcm_info error: %s", snd_strerror(err)); return err; } err = snd_config_get_id(src, &id); if (err >= 0) - err = snd_config_imake_integer(dst, id, snd_pcm_info_get_subdevice(info)); + err = snd_config_imake_integer(dst, id, + snd_pcm_info_get_subdevice(&info)); return err; } #ifndef DOC_HIDDEN
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/alisp/alisp_snd.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/alisp/alisp_snd.c b/src/alisp/alisp_snd.c index 0a1a3b4..e622035 100644 --- a/src/alisp/alisp_snd.c +++ b/src/alisp/alisp_snd.c @@ -444,7 +444,7 @@ static struct alisp_object * FA_card_info(struct alisp_instance * instance, stru { snd_ctl_t *handle; struct alisp_object * lexpr, * p1; - snd_ctl_card_info_t * info; + snd_ctl_card_info_t info = {0}; int err;
p1 = eval(instance, car(args)); @@ -453,17 +453,16 @@ static struct alisp_object * FA_card_info(struct alisp_instance * instance, stru handle = (snd_ctl_t *)get_ptr(instance, p1, item->prefix); if (handle == NULL) return &alsa_lisp_nil; - snd_ctl_card_info_alloca(&info); - err = snd_ctl_card_info(handle, info); + err = snd_ctl_card_info(handle, &info); lexpr = new_lexpr(instance, err); if (err < 0) return lexpr; - p1 = add_cons(instance, lexpr->value.c.cdr, 0, "id", new_string(instance, snd_ctl_card_info_get_id(info))); - p1 = add_cons(instance, p1, 1, "driver", new_string(instance, snd_ctl_card_info_get_driver(info))); - p1 = add_cons(instance, p1, 1, "name", new_string(instance, snd_ctl_card_info_get_name(info))); - p1 = add_cons(instance, p1, 1, "longname", new_string(instance, snd_ctl_card_info_get_longname(info))); - p1 = add_cons(instance, p1, 1, "mixername", new_string(instance, snd_ctl_card_info_get_mixername(info))); - p1 = add_cons(instance, p1, 1, "components", new_string(instance, snd_ctl_card_info_get_components(info))); + p1 = add_cons(instance, lexpr->value.c.cdr, 0, "id", new_string(instance, snd_ctl_card_info_get_id(&info))); + p1 = add_cons(instance, p1, 1, "driver", new_string(instance, snd_ctl_card_info_get_driver(&info))); + p1 = add_cons(instance, p1, 1, "name", new_string(instance, snd_ctl_card_info_get_name(&info))); + p1 = add_cons(instance, p1, 1, "longname", new_string(instance, snd_ctl_card_info_get_longname(&info))); + p1 = add_cons(instance, p1, 1, "mixername", new_string(instance, snd_ctl_card_info_get_mixername(&info))); + p1 = add_cons(instance, p1, 1, "components", new_string(instance, snd_ctl_card_info_get_components(&info))); if (p1 == NULL) { delete_tree(instance, lexpr); return NULL;
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/alisp/alisp_snd.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/alisp/alisp_snd.c b/src/alisp/alisp_snd.c index e622035..e9c3573 100644 --- a/src/alisp/alisp_snd.c +++ b/src/alisp/alisp_snd.c @@ -522,7 +522,7 @@ static int parse_ctl_elem_id(struct alisp_instance * instance, static struct alisp_object * FA_hctl_find_elem(struct alisp_instance * instance, struct acall_table * item, struct alisp_object * args) { snd_hctl_t *handle; - snd_ctl_elem_id_t *id; + snd_ctl_elem_id_t id = {0}; struct alisp_object *p1;
handle = (snd_hctl_t *)get_ptr(instance, car(args), item->prefix); @@ -531,14 +531,13 @@ static struct alisp_object * FA_hctl_find_elem(struct alisp_instance * instance, delete_object(instance, args); return &alsa_lisp_nil; } - snd_ctl_elem_id_alloca(&id); p1 = car(cdr(args)); delete_tree(instance, cdr(cdr(args))); delete_object(instance, cdr(args)); delete_object(instance, args); - if (parse_ctl_elem_id(instance, eval(instance, p1), id) < 0) + if (parse_ctl_elem_id(instance, eval(instance, p1), &id) < 0) return &alsa_lisp_nil; - return new_cons_pointer(instance, "hctl_elem", snd_hctl_find_elem(handle, id)); + return new_cons_pointer(instance, "hctl_elem", snd_hctl_find_elem(handle, &id)); }
static struct alisp_object * FA_hctl_elem_info(struct alisp_instance * instance, struct acall_table * item, struct alisp_object * args)
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/alisp/alisp_snd.c | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 28 deletions(-)
diff --git a/src/alisp/alisp_snd.c b/src/alisp/alisp_snd.c index e9c3573..c63806b 100644 --- a/src/alisp/alisp_snd.c +++ b/src/alisp/alisp_snd.c @@ -544,8 +544,8 @@ static struct alisp_object * FA_hctl_elem_info(struct alisp_instance * instance, { snd_hctl_elem_t *handle; struct alisp_object * lexpr, * p1, * p2; - snd_ctl_elem_info_t *info; - snd_ctl_elem_id_t *id; + snd_ctl_elem_info_t info = {0}; + snd_ctl_elem_id_t id = {0}; snd_ctl_elem_type_t type; int err;
@@ -555,60 +555,58 @@ static struct alisp_object * FA_hctl_elem_info(struct alisp_instance * instance, handle = (snd_hctl_elem_t *)get_ptr(instance, p1, item->prefix); if (handle == NULL) return &alsa_lisp_nil; - snd_ctl_elem_info_alloca(&info); - snd_ctl_elem_id_alloca(&id); - err = snd_hctl_elem_info(handle, info); + err = snd_hctl_elem_info(handle, &info); lexpr = new_lexpr(instance, err); if (err < 0) return lexpr; - type = snd_ctl_elem_info_get_type(info); + type = snd_ctl_elem_info_get_type(&info); p1 = add_cons(instance, lexpr->value.c.cdr, 0, "id", p2 = new_object(instance, ALISP_OBJ_CONS)); - snd_ctl_elem_info_get_id(info, id); - if (create_ctl_elem_id(instance, id, p2) == NULL) { + snd_ctl_elem_info_get_id(&info, &id); + if (create_ctl_elem_id(instance, &id, p2) == NULL) { delete_tree(instance, lexpr); return NULL; } p1 = add_cons(instance, p1, 1, "type", new_string(instance, snd_ctl_elem_type_name(type))); - p1 = add_cons(instance, p1, 1, "readable", new_integer(instance, snd_ctl_elem_info_is_readable(info))); - p1 = add_cons(instance, p1, 1, "writable", new_integer(instance, snd_ctl_elem_info_is_writable(info))); - p1 = add_cons(instance, p1, 1, "volatile", new_integer(instance, snd_ctl_elem_info_is_volatile(info))); - p1 = add_cons(instance, p1, 1, "inactive", new_integer(instance, snd_ctl_elem_info_is_inactive(info))); - p1 = add_cons(instance, p1, 1, "locked", new_integer(instance, snd_ctl_elem_info_is_locked(info))); - p1 = add_cons(instance, p1, 1, "isowner", new_integer(instance, snd_ctl_elem_info_is_owner(info))); - p1 = add_cons(instance, p1, 1, "owner", new_integer(instance, snd_ctl_elem_info_get_owner(info))); - p1 = add_cons(instance, p1, 1, "count", new_integer(instance, snd_ctl_elem_info_get_count(info))); - err = snd_ctl_elem_info_get_dimensions(info); + p1 = add_cons(instance, p1, 1, "readable", new_integer(instance, snd_ctl_elem_info_is_readable(&info))); + p1 = add_cons(instance, p1, 1, "writable", new_integer(instance, snd_ctl_elem_info_is_writable(&info))); + p1 = add_cons(instance, p1, 1, "volatile", new_integer(instance, snd_ctl_elem_info_is_volatile(&info))); + p1 = add_cons(instance, p1, 1, "inactive", new_integer(instance, snd_ctl_elem_info_is_inactive(&info))); + p1 = add_cons(instance, p1, 1, "locked", new_integer(instance, snd_ctl_elem_info_is_locked(&info))); + p1 = add_cons(instance, p1, 1, "isowner", new_integer(instance, snd_ctl_elem_info_is_owner(&info))); + p1 = add_cons(instance, p1, 1, "owner", new_integer(instance, snd_ctl_elem_info_get_owner(&info))); + p1 = add_cons(instance, p1, 1, "count", new_integer(instance, snd_ctl_elem_info_get_count(&info))); + err = snd_ctl_elem_info_get_dimensions(&info); if (err > 0) { int idx; p1 = add_cons(instance, p1, 1, "dimensions", p2 = new_object(instance, ALISP_OBJ_CONS)); for (idx = 0; idx < err; idx++) - p2 = add_cons2(instance, p2, idx > 0, new_integer(instance, snd_ctl_elem_info_get_dimension(info, idx))); + p2 = add_cons2(instance, p2, idx > 0, new_integer(instance, snd_ctl_elem_info_get_dimension(&info, idx))); } switch (type) { case SND_CTL_ELEM_TYPE_ENUMERATED: { unsigned int items, item; - items = snd_ctl_elem_info_get_items(info); + items = snd_ctl_elem_info_get_items(&info); p1 = add_cons(instance, p1, 1, "items", p2 = new_object(instance, ALISP_OBJ_CONS)); for (item = 0; item < items; item++) { - snd_ctl_elem_info_set_item(info, item); - err = snd_hctl_elem_info(handle, info); + snd_ctl_elem_info_set_item(&info, item); + err = snd_hctl_elem_info(handle, &info); if (err < 0) { p2 = add_cons2(instance, p2, item, &alsa_lisp_nil); } else { - p2 = add_cons2(instance, p2, item, new_string(instance, snd_ctl_elem_info_get_item_name(info))); + p2 = add_cons2(instance, p2, item, new_string(instance, snd_ctl_elem_info_get_item_name(&info))); } } break; } case SND_CTL_ELEM_TYPE_INTEGER: - p1 = add_cons(instance, p1, 1, "min", new_integer(instance, snd_ctl_elem_info_get_min(info))); - p1 = add_cons(instance, p1, 1, "max", new_integer(instance, snd_ctl_elem_info_get_max(info))); - p1 = add_cons(instance, p1, 1, "step", new_integer(instance, snd_ctl_elem_info_get_step(info))); + p1 = add_cons(instance, p1, 1, "min", new_integer(instance, snd_ctl_elem_info_get_min(&info))); + p1 = add_cons(instance, p1, 1, "max", new_integer(instance, snd_ctl_elem_info_get_max(&info))); + p1 = add_cons(instance, p1, 1, "step", new_integer(instance, snd_ctl_elem_info_get_step(&info))); break; case SND_CTL_ELEM_TYPE_INTEGER64: - p1 = add_cons(instance, p1, 1, "min64", new_float(instance, snd_ctl_elem_info_get_min64(info))); - p1 = add_cons(instance, p1, 1, "max64", new_float(instance, snd_ctl_elem_info_get_max64(info))); - p1 = add_cons(instance, p1, 1, "step64", new_float(instance, snd_ctl_elem_info_get_step64(info))); + p1 = add_cons(instance, p1, 1, "min64", new_float(instance, snd_ctl_elem_info_get_min64(&info))); + p1 = add_cons(instance, p1, 1, "max64", new_float(instance, snd_ctl_elem_info_get_max64(&info))); + p1 = add_cons(instance, p1, 1, "step64", new_float(instance, snd_ctl_elem_info_get_step64(&info))); break; default: break;
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/alisp/alisp_snd.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/src/alisp/alisp_snd.c b/src/alisp/alisp_snd.c index c63806b..6d5018a 100644 --- a/src/alisp/alisp_snd.c +++ b/src/alisp/alisp_snd.c @@ -622,8 +622,8 @@ static struct alisp_object * FA_hctl_elem_read(struct alisp_instance * instance, { snd_hctl_elem_t *handle; struct alisp_object * lexpr, * p1 = NULL, * obj; - snd_ctl_elem_info_t *info; - snd_ctl_elem_value_t *value; + snd_ctl_elem_info_t info = {0}; + snd_ctl_elem_value_t value = {0}; snd_ctl_elem_type_t type; unsigned int idx, count; int err; @@ -634,16 +634,14 @@ static struct alisp_object * FA_hctl_elem_read(struct alisp_instance * instance, handle = (snd_hctl_elem_t *)get_ptr(instance, p1, item->prefix); if (handle == NULL) return &alsa_lisp_nil; - snd_ctl_elem_info_alloca(&info); - snd_ctl_elem_value_alloca(&value); - err = snd_hctl_elem_info(handle, info); + err = snd_hctl_elem_info(handle, &info); if (err >= 0) - err = snd_hctl_elem_read(handle, value); + err = snd_hctl_elem_read(handle, &value); lexpr = new_lexpr(instance, err); if (err < 0) return lexpr; - type = snd_ctl_elem_info_get_type(info); - count = snd_ctl_elem_info_get_count(info); + type = snd_ctl_elem_info_get_type(&info); + count = snd_ctl_elem_info_get_count(&info); if (type == SND_CTL_ELEM_TYPE_IEC958) { count = sizeof(snd_aes_iec958_t); type = SND_CTL_ELEM_TYPE_BYTES; @@ -651,19 +649,19 @@ static struct alisp_object * FA_hctl_elem_read(struct alisp_instance * instance, for (idx = 0; idx < count; idx++) { switch (type) { case SND_CTL_ELEM_TYPE_BOOLEAN: - obj = new_integer(instance, snd_ctl_elem_value_get_boolean(value, idx)); + obj = new_integer(instance, snd_ctl_elem_value_get_boolean(&value, idx)); break; case SND_CTL_ELEM_TYPE_INTEGER: - obj = new_integer(instance, snd_ctl_elem_value_get_integer(value, idx)); + obj = new_integer(instance, snd_ctl_elem_value_get_integer(&value, idx)); break; case SND_CTL_ELEM_TYPE_INTEGER64: - obj = new_integer(instance, snd_ctl_elem_value_get_integer64(value, idx)); + obj = new_integer(instance, snd_ctl_elem_value_get_integer64(&value, idx)); break; case SND_CTL_ELEM_TYPE_ENUMERATED: - obj = new_integer(instance, snd_ctl_elem_value_get_enumerated(value, idx)); + obj = new_integer(instance, snd_ctl_elem_value_get_enumerated(&value, idx)); break; case SND_CTL_ELEM_TYPE_BYTES: - obj = new_integer(instance, snd_ctl_elem_value_get_byte(value, idx)); + obj = new_integer(instance, snd_ctl_elem_value_get_byte(&value, idx)); break; default: obj = NULL;
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/alisp/alisp_snd.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/src/alisp/alisp_snd.c b/src/alisp/alisp_snd.c index 6d5018a..72c6ab0 100644 --- a/src/alisp/alisp_snd.c +++ b/src/alisp/alisp_snd.c @@ -684,8 +684,8 @@ static struct alisp_object * FA_hctl_elem_write(struct alisp_instance * instance { snd_hctl_elem_t *handle; struct alisp_object * p1 = NULL, * obj; - snd_ctl_elem_info_t *info; - snd_ctl_elem_value_t *value; + snd_ctl_elem_info_t info = {0}; + snd_ctl_elem_value_t value = {0}; snd_ctl_elem_type_t type; unsigned int idx, count; int err; @@ -700,15 +700,13 @@ static struct alisp_object * FA_hctl_elem_write(struct alisp_instance * instance delete_tree(instance, p1); return &alsa_lisp_nil; } - snd_ctl_elem_info_alloca(&info); - snd_ctl_elem_value_alloca(&value); - err = snd_hctl_elem_info(handle, info); + err = snd_hctl_elem_info(handle, &info); if (err < 0) { delete_tree(instance, p1); return new_integer(instance, err); } - type = snd_ctl_elem_info_get_type(info); - count = snd_ctl_elem_info_get_count(info); + type = snd_ctl_elem_info_get_type(&info); + count = snd_ctl_elem_info_get_count(&info); if (type == SND_CTL_ELEM_TYPE_IEC958) { count = sizeof(snd_aes_iec958_t); type = SND_CTL_ELEM_TYPE_BYTES; @@ -722,19 +720,19 @@ static struct alisp_object * FA_hctl_elem_write(struct alisp_instance * instance obj = car(p1); switch (type) { case SND_CTL_ELEM_TYPE_BOOLEAN: - snd_ctl_elem_value_set_boolean(value, idx, get_integer(obj)); + snd_ctl_elem_value_set_boolean(&value, idx, get_integer(obj)); break; case SND_CTL_ELEM_TYPE_INTEGER: - snd_ctl_elem_value_set_integer(value, idx, get_integer(obj)); + snd_ctl_elem_value_set_integer(&value, idx, get_integer(obj)); break; case SND_CTL_ELEM_TYPE_INTEGER64: - snd_ctl_elem_value_set_integer64(value, idx, get_integer(obj)); + snd_ctl_elem_value_set_integer64(&value, idx, get_integer(obj)); break; case SND_CTL_ELEM_TYPE_ENUMERATED: - snd_ctl_elem_value_set_enumerated(value, idx, get_integer(obj)); + snd_ctl_elem_value_set_enumerated(&value, idx, get_integer(obj)); break; case SND_CTL_ELEM_TYPE_BYTES: - snd_ctl_elem_value_set_byte(value, idx, get_integer(obj)); + snd_ctl_elem_value_set_byte(&value, idx, get_integer(obj)); break; default: break; @@ -743,7 +741,7 @@ static struct alisp_object * FA_hctl_elem_write(struct alisp_instance * instance p1 = cdr(obj = p1); delete_object(instance, obj); } while (p1 != &alsa_lisp_nil); - err = snd_hctl_elem_write(handle, value); + err = snd_hctl_elem_write(handle, &value); return new_integer(instance, err); }
Both of alloca() and automatic variables keeps storages on stack, while the former generates more instructions than the latter. It's better to use the latter if the size of storage is computable at pre-compile or compile time; i.e. just for structures.
This commit obsolete usages of alloca() with automatic variables.
Signed-off-by: Takashi Sakamoto o-takashi@sakamocchi.jp --- src/alisp/alisp_snd.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/src/alisp/alisp_snd.c b/src/alisp/alisp_snd.c index 72c6ab0..c5e96e8 100644 --- a/src/alisp/alisp_snd.c +++ b/src/alisp/alisp_snd.c @@ -749,7 +749,7 @@ static struct alisp_object * FA_pcm_info(struct alisp_instance * instance, struc { snd_pcm_t *handle; struct alisp_object * lexpr, * p1; - snd_pcm_info_t *info; + snd_pcm_info_t info = {0}; int err;
p1 = eval(instance, car(args)); @@ -758,22 +758,21 @@ static struct alisp_object * FA_pcm_info(struct alisp_instance * instance, struc handle = (snd_pcm_t *)get_ptr(instance, p1, item->prefix); if (handle == NULL) return &alsa_lisp_nil; - snd_pcm_info_alloca(&info); - err = snd_pcm_info(handle, info); + err = snd_pcm_info(handle, &info); lexpr = new_lexpr(instance, err); if (err < 0) return lexpr; - p1 = add_cons(instance, lexpr->value.c.cdr, 0, "card", new_integer(instance, snd_pcm_info_get_card(info))); - p1 = add_cons(instance, p1, 1, "device", new_integer(instance, snd_pcm_info_get_device(info))); - p1 = add_cons(instance, p1, 1, "subdevice", new_integer(instance, snd_pcm_info_get_subdevice(info))); - p1 = add_cons(instance, p1, 1, "id", new_string(instance, snd_pcm_info_get_id(info))); - p1 = add_cons(instance, p1, 1, "name", new_string(instance, snd_pcm_info_get_name(info))); - p1 = add_cons(instance, p1, 1, "subdevice_name", new_string(instance, snd_pcm_info_get_subdevice_name(info))); - p1 = add_cons(instance, p1, 1, "class", new_integer(instance, snd_pcm_info_get_class(info))); - p1 = add_cons(instance, p1, 1, "subclass", new_integer(instance, snd_pcm_info_get_subclass(info))); - p1 = add_cons(instance, p1, 1, "subdevices_count", new_integer(instance, snd_pcm_info_get_subdevices_count(info))); - p1 = add_cons(instance, p1, 1, "subdevices_avail", new_integer(instance, snd_pcm_info_get_subdevices_avail(info))); - //p1 = add_cons(instance, p1, 1, "sync", new_string(instance, snd_pcm_info_get_sync(info))); + p1 = add_cons(instance, lexpr->value.c.cdr, 0, "card", new_integer(instance, snd_pcm_info_get_card(&info))); + p1 = add_cons(instance, p1, 1, "device", new_integer(instance, snd_pcm_info_get_device(&info))); + p1 = add_cons(instance, p1, 1, "subdevice", new_integer(instance, snd_pcm_info_get_subdevice(&info))); + p1 = add_cons(instance, p1, 1, "id", new_string(instance, snd_pcm_info_get_id(&info))); + p1 = add_cons(instance, p1, 1, "name", new_string(instance, snd_pcm_info_get_name(&info))); + p1 = add_cons(instance, p1, 1, "subdevice_name", new_string(instance, snd_pcm_info_get_subdevice_name(&info))); + p1 = add_cons(instance, p1, 1, "class", new_integer(instance, snd_pcm_info_get_class(&info))); + p1 = add_cons(instance, p1, 1, "subclass", new_integer(instance, snd_pcm_info_get_subclass(&info))); + p1 = add_cons(instance, p1, 1, "subdevices_count", new_integer(instance, snd_pcm_info_get_subdevices_count(&info))); + p1 = add_cons(instance, p1, 1, "subdevices_avail", new_integer(instance, snd_pcm_info_get_subdevices_avail(&info))); + //p1 = add_cons(instance, p1, 1, "sync", new_string(instance, snd_pcm_info_get_sync(&info))); return lexpr; }
On Thu, 14 Jul 2016 16:07:17 +0200, Takashi Sakamoto wrote:
Hi,
A batch of this patchset is to save storage consumption and to improve execution performance, just for a little.
Currently, ALSA userspace library doesn't disclose layouts of major structures to applications. The applications call some APIs in the library to get memory objects for the structures, then operates to corresponding opaque pointers. In most cases, the objects are kept on stack by calls of alloca(3).
On the other hand, inner the library, the layouts are decided in pre-compile or compile time. Therefore, there's little needs to call of alloca(3).
However, inner the library, we can see some usages of alloca(3). This brings two disadvantages to system. One is to execute more instructions to use stack than automatic variables, for the same task. Another is to enlarge size of shared object. Although both disadvantages are not so remarkable, it's better to improve them.
This patchset replaces usages of alloca() with automatic variables just to raw structures. Additionally, this commit improves code formats in related functions.
I can see below effect on my environment (Ubuntu 16.04, amd64, gcc) $ git checkout master $ git show HEAD commit 941bd150bef2560f3e38a3bf74d546447e3126d1 ... $ ./gitcompile --with-plugindir=/usr/lib/x86_64-linux-gnu/alsa-lib/ ... $ ls -l src/.libs/libasound.so.2.0.0 -rwxrwxr-x 1 mocchi mocchi 4794528 7月 14 22:22 src/.libs/libasound.so.2.0.0 $ git checkout remove-alloca-asound $ make ... $ ls -l src/.libs/libasound.so.2.0.0 -rwxrwxr-x 1 mocchi mocchi 4783712 7月 14 22:21 src/.libs/libasound.so.2.0.0 $ gcc -v ... gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.1)
Takashi Sakamoto (34): pcm: change code formatting for snd_pcm_set_params() pcm: remove alloca() from snd_pcm_set_params() pcm: change code formatting for snd_pcm_get_params() pcm: remove alloca() from snd_pcm_get_params pcm: change code formatting for snd_pcm_direct_initialize_slave() pcm: remove alloca() from snd_pcm_direct_initialize_slave pcm: change code formatting for snd_pcm_direct_initialize_poll_fd() pcm: remove alloca() from snd_pcm_direct_initialize_poll_fd() pcm: change code formatting for snd_pcm_direct_set_timer_params() pcm: remove alloca() from snd_pcm_direct_set_timer_params pcm: remove alloca() from _snd_pcm_hook_ctl_elems_install() pcm: change code formatting for snd_pcm_hw_change_timer() pcm: remove alloca() from snd_pcm_hw_change_timer() pcm: remove alloca() from snd_pcm_query_chmaps_from_hw() pcm: remove alloca() from snd_pcm_hw_get_chmap() pcm: remove alloca() from snd_pcm_hw_set_chmap() pcm: remove alloca() from snd_spcm_init() pcm: remove alloca() from snd_spcm_init_duplex() pcm: change code formatting for softvol_load_control() pcm: remove alloca() from softvol_load_control() pcm: change code formatting for _snd_pcm_softvol_open() pcm: remove alloca() from _snd_pcm_softvol_open() conf: remove alloca() from snd_determine_driver() conf: remove alloca() from snd_func_card_id() conf: remove alloca() from snd_func_card_name() conf: remove alloca() from snd_func_pcm_id() conf: remove alloca() from snd_func_pcm_args_by_class() conf: remove alloca() from snd_func_private_pcm_subdevice() alisp: remove alloca() from FA_card_info() alisp: remove alloca() from FA_hctl_find_elem() alisp: remove alloca() from FA_hctl_elem_info() alisp: remove alloca() from FA_hctl_elem_read() alisp: remove alloca() from FA_hctl_elem_write() alisp: remove alloca() from FA_pcm_info()
Thanks, it's a nice cleanup. Applied all patches now.
Takashi
participants (2)
-
Takashi Iwai
-
Takashi Sakamoto