lib/alsa/HwSetup: return effective parameters

This commit is contained in:
Max Kellermann
2017-10-26 12:13:00 +02:00
parent b7e035b6f3
commit e2a74051dc
3 changed files with 45 additions and 33 deletions

View File

@@ -176,11 +176,14 @@ SetupSampleFormat(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
return err;
}
void
SetupHw(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
HwResult
SetupHw(snd_pcm_t *pcm,
unsigned buffer_time, unsigned period_time,
AudioFormat &audio_format, PcmExport::Params &params)
{
snd_pcm_hw_params_t *hwparams;
snd_pcm_hw_params_alloca(&hwparams);
int err;
unsigned int period_time_ro = period_time;
@@ -285,6 +288,26 @@ SetupHw(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
if (err < 0)
throw FormatRuntimeError("snd_pcm_hw_params() failed: %s",
snd_strerror(-err));
HwResult result;
err = snd_pcm_hw_params_get_format(hwparams, &result.format);
if (err < 0)
throw FormatRuntimeError("snd_pcm_hw_params_get_format() failed: %s",
snd_strerror(-err));
err = snd_pcm_hw_params_get_buffer_size(hwparams, &result.buffer_size);
if (err < 0)
throw FormatRuntimeError("snd_pcm_hw_params_get_buffer_size() failed: %s",
snd_strerror(-err));
err = snd_pcm_hw_params_get_period_size(hwparams, &result.period_size,
nullptr);
if (err < 0)
throw FormatRuntimeError("snd_pcm_hw_params_get_period_size() failed: %s",
snd_strerror(-err));
return result;
}
} // namespace Alsa

View File

@@ -29,6 +29,11 @@ struct AudioFormat;
namespace Alsa {
struct HwResult {
snd_pcm_format_t format;
snd_pcm_uframes_t buffer_size, period_size;
};
/**
* Wrapper for snd_pcm_hw_params().
*
@@ -38,8 +43,8 @@ namespace Alsa {
* by this function
* @param params to be modified by this function
*/
void
SetupHw(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
HwResult
SetupHw(snd_pcm_t *pcm,
unsigned buffer_time, unsigned period_time,
AudioFormat &audio_format, PcmExport::Params &params);