mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-04 13:30:08 -05:00
pcm: remove alloca() from snd_pcm_set_params()
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> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
804312cf3e
commit
a5f54c1aeb
1 changed files with 25 additions and 27 deletions
|
|
@ -8291,47 +8291,44 @@ int snd_pcm_set_params(snd_pcm_t *pcm,
|
||||||
int soft_resample,
|
int soft_resample,
|
||||||
unsigned int latency)
|
unsigned int latency)
|
||||||
{
|
{
|
||||||
snd_pcm_hw_params_t *params, params_saved;
|
snd_pcm_hw_params_t params_saved, params = {0};
|
||||||
snd_pcm_sw_params_t *swparams;
|
snd_pcm_sw_params_t swparams = {0};
|
||||||
const char *s = snd_pcm_stream_name(snd_pcm_stream(pcm));
|
const char *s = snd_pcm_stream_name(snd_pcm_stream(pcm));
|
||||||
snd_pcm_uframes_t buffer_size, period_size;
|
snd_pcm_uframes_t buffer_size, period_size;
|
||||||
unsigned int rrate, period_time;
|
unsigned int rrate, period_time;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
snd_pcm_hw_params_alloca(¶ms);
|
|
||||||
snd_pcm_sw_params_alloca(&swparams);
|
|
||||||
|
|
||||||
assert(pcm);
|
assert(pcm);
|
||||||
/* choose all parameters */
|
/* choose all parameters */
|
||||||
err = snd_pcm_hw_params_any(pcm, params);
|
err = snd_pcm_hw_params_any(pcm, ¶ms);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Broken configuration for %s: no configurations available",
|
SNDERR("Broken configuration for %s: no configurations available",
|
||||||
s);
|
s);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
/* set software resampling */
|
/* 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) {
|
if (err < 0) {
|
||||||
SNDERR("Resampling setup failed for %s: %s",
|
SNDERR("Resampling setup failed for %s: %s",
|
||||||
s, snd_strerror(err));
|
s, snd_strerror(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
/* set the selected read/write format */
|
/* 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) {
|
if (err < 0) {
|
||||||
SNDERR("Access type not available for %s: %s",
|
SNDERR("Access type not available for %s: %s",
|
||||||
s, snd_strerror(err));
|
s, snd_strerror(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
/* set the sample format */
|
/* 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) {
|
if (err < 0) {
|
||||||
SNDERR("Sample format not available for %s: %s",
|
SNDERR("Sample format not available for %s: %s",
|
||||||
s, snd_strerror(err));
|
s, snd_strerror(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
/* set the count of channels */
|
/* 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) {
|
if (err < 0) {
|
||||||
SNDERR("Channels count (%i) not available for %s: %s",
|
SNDERR("Channels count (%i) not available for %s: %s",
|
||||||
channels, s, snd_strerror(err));
|
channels, s, snd_strerror(err));
|
||||||
|
|
@ -8339,7 +8336,8 @@ int snd_pcm_set_params(snd_pcm_t *pcm,
|
||||||
}
|
}
|
||||||
/* set the stream rate */
|
/* set the stream rate */
|
||||||
rrate = 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) {
|
if (err < 0) {
|
||||||
SNDERR("Rate %iHz not available for playback: %s",
|
SNDERR("Rate %iHz not available for playback: %s",
|
||||||
rate, snd_strerror(err));
|
rate, snd_strerror(err));
|
||||||
|
|
@ -8351,22 +8349,22 @@ int snd_pcm_set_params(snd_pcm_t *pcm,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
/* set the buffer time */
|
/* set the buffer time */
|
||||||
params_saved = *params;
|
params_saved = params;
|
||||||
err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, params,
|
err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, ¶ms,
|
||||||
&latency, NULL);
|
&latency, NULL);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
/* error path -> set period size as first */
|
/* error path -> set period size as first */
|
||||||
*params = params_saved;
|
params = params_saved;
|
||||||
/* set the period time */
|
/* set the period time */
|
||||||
period_time = latency / 4;
|
period_time = latency / 4;
|
||||||
err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
|
err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
|
||||||
params, &period_time, NULL);
|
¶ms, &period_time, NULL);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Unable to set period time %i for %s: %s",
|
SNDERR("Unable to set period time %i for %s: %s",
|
||||||
period_time, s, snd_strerror(err));
|
period_time, s, snd_strerror(err));
|
||||||
return 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);
|
&period_size, NULL);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Unable to get period size for %s: %s",
|
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;
|
buffer_size = period_size * 4;
|
||||||
err = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(pcm,
|
err = INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(pcm,
|
||||||
params, &buffer_size);
|
¶ms, &buffer_size);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Unable to set buffer size %lu %s: %s",
|
SNDERR("Unable to set buffer size %lu %s: %s",
|
||||||
buffer_size, s, snd_strerror(err));
|
buffer_size, s, snd_strerror(err));
|
||||||
return 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);
|
&buffer_size);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Unable to get buffer size for %s: %s",
|
SNDERR("Unable to get buffer size for %s: %s",
|
||||||
|
|
@ -8390,14 +8388,14 @@ int snd_pcm_set_params(snd_pcm_t *pcm,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* standard configuration buffer_time -> periods */
|
/* 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);
|
&buffer_size);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Unable to get buffer size for %s: %s",
|
SNDERR("Unable to get buffer size for %s: %s",
|
||||||
s, snd_strerror(err));
|
s, snd_strerror(err));
|
||||||
return 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);
|
&latency, NULL);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Unable to get buffer time (latency) for %s: %s",
|
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 */
|
/* set the period time */
|
||||||
period_time = latency / 4;
|
period_time = latency / 4;
|
||||||
err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
|
err = INTERNAL(snd_pcm_hw_params_set_period_time_near)(pcm,
|
||||||
params, &period_time, NULL);
|
¶ms, &period_time, NULL);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Unable to set period time %i for %s: %s",
|
SNDERR("Unable to set period time %i for %s: %s",
|
||||||
period_time, s, snd_strerror(err));
|
period_time, s, snd_strerror(err));
|
||||||
return 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);
|
&period_size, NULL);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Unable to get period size for %s: %s",
|
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 */
|
/* write the parameters to device */
|
||||||
err = snd_pcm_hw_params(pcm, params);
|
err = snd_pcm_hw_params(pcm, ¶ms);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Unable to set hw params for %s: %s",
|
SNDERR("Unable to set hw params for %s: %s",
|
||||||
s, snd_strerror(err));
|
s, snd_strerror(err));
|
||||||
|
|
@ -8430,7 +8428,7 @@ int snd_pcm_set_params(snd_pcm_t *pcm,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the current swparams */
|
/* get the current swparams */
|
||||||
err = snd_pcm_sw_params_current(pcm, swparams);
|
err = snd_pcm_sw_params_current(pcm, &swparams);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Unable to determine current swparams for %s: %s",
|
SNDERR("Unable to determine current swparams for %s: %s",
|
||||||
s, snd_strerror(err));
|
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:
|
* start the transfer when the buffer is almost full:
|
||||||
* (buffer_size / avail_min) * avail_min
|
* (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);
|
(buffer_size / period_size) * period_size);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Unable to set start threshold mode for %s: %s",
|
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
|
* allow the transfer when at least period_size samples can be
|
||||||
* processed
|
* 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) {
|
if (err < 0) {
|
||||||
SNDERR("Unable to set avail min for %s: %s",
|
SNDERR("Unable to set avail min for %s: %s",
|
||||||
s, snd_strerror(err));
|
s, snd_strerror(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
/* write the parameters to the playback device */
|
/* write the parameters to the playback device */
|
||||||
err = snd_pcm_sw_params(pcm, swparams);
|
err = snd_pcm_sw_params(pcm, &swparams);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Unable to set sw params for %s: %s",
|
SNDERR("Unable to set sw params for %s: %s",
|
||||||
s, snd_strerror(err));
|
s, snd_strerror(err));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue