output/alsa: use Error::FormatPrefix()

This commit is contained in:
Max Kellermann 2016-11-04 10:35:03 +01:00
parent d6559e2ac9
commit 93a14a93f9

View File

@ -501,8 +501,7 @@ configure_hw:
err = AlsaSetupFormat(ad->pcm, hwparams, audio_format, params); err = AlsaSetupFormat(ad->pcm, hwparams, audio_format, params);
if (err < 0) { if (err < 0) {
error.Format(alsa_output_domain, err, error.Format(alsa_output_domain, err,
"ALSA device \"%s\" does not support format %s: %s", "Failed to configure format %s: %s",
ad->GetDevice(),
sample_format_to_string(audio_format.format), sample_format_to_string(audio_format.format),
snd_strerror(-err)); snd_strerror(-err));
return false; return false;
@ -518,8 +517,8 @@ configure_hw:
&channels); &channels);
if (err < 0) { if (err < 0) {
error.Format(alsa_output_domain, err, error.Format(alsa_output_domain, err,
"ALSA device \"%s\" does not support %i channels: %s", "Failed to configure %i channels: %s",
ad->GetDevice(), (int)audio_format.channels, (int)audio_format.channels,
snd_strerror(-err)); snd_strerror(-err));
return false; return false;
} }
@ -527,12 +526,21 @@ configure_hw:
err = snd_pcm_hw_params_set_rate_near(ad->pcm, hwparams, err = snd_pcm_hw_params_set_rate_near(ad->pcm, hwparams,
&sample_rate, nullptr); &sample_rate, nullptr);
if (err < 0 || sample_rate == 0) { if (err < 0) {
error.Format(alsa_output_domain, err, error.Format(alsa_output_domain, err,
"ALSA device \"%s\" does not support %u Hz audio", "Failed to configure sample rate %u Hz: %s",
ad->GetDevice(), audio_format.sample_rate); audio_format.sample_rate,
snd_strerror(-err));
return false; return false;
} }
if (sample_rate == 0) {
error.Format(alsa_output_domain, err,
"Failed to configure sample rate %u Hz",
audio_format.sample_rate);
return false;
}
audio_format.sample_rate = sample_rate; audio_format.sample_rate = sample_rate;
snd_pcm_uframes_t buffer_size_min, buffer_size_max; snd_pcm_uframes_t buffer_size_min, buffer_size_max;
@ -660,8 +668,8 @@ configure_hw:
error: error:
error.Format(alsa_output_domain, err, error.Format(alsa_output_domain, err,
"Error opening ALSA device \"%s\" (%s): %s", "%s failed: %s",
ad->GetDevice(), cmd, snd_strerror(-err)); cmd, snd_strerror(-err));
return false; return false;
} }
@ -698,9 +706,8 @@ AlsaOutput::SetupDop(const AudioFormat audio_format,
if (dop_format != check) { if (dop_format != check) {
/* no bit-perfect playback, which is required /* no bit-perfect playback, which is required
for DSD over USB */ for DSD over USB */
error.Format(alsa_output_domain, error.Set(alsa_output_domain,
"Failed to configure DSD-over-PCM on ALSA device \"%s\"", "Failed to configure DSD-over-PCM");
GetDevice());
delete[] silence; delete[] silence;
return false; return false;
} }
@ -757,6 +764,8 @@ AlsaOutput::Open(AudioFormat &audio_format, Error &error)
if (!SetupOrDop(audio_format, params, error)) { if (!SetupOrDop(audio_format, params, error)) {
snd_pcm_close(pcm); snd_pcm_close(pcm);
error.FormatPrefix("Error opening ALSA device \"%s\": ",
GetDevice());
return false; return false;
} }