output/Internal: move code to ConfigureConvertFilter()

This commit is contained in:
Max Kellermann 2017-08-07 18:39:12 +02:00
parent d4ee165253
commit fc04620519
3 changed files with 17 additions and 8 deletions

View File

@ -45,6 +45,17 @@ AudioOutput::Disable() noexcept
ao_plugin_disable(*this);
}
void
AudioOutput::ConfigureConvertFilter()
{
try {
convert_filter_set(convert_filter.Get(), out_audio_format);
} catch (const std::runtime_error &e) {
std::throw_with_nested(FormatRuntimeError("Failed to convert for \"%s\" [%s]",
name, plugin.name));
}
}
void
AudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
{
@ -63,7 +74,7 @@ AudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
ToString(out_audio_format).c_str());
try {
convert_filter_set(convert_filter.Get(), out_audio_format);
ConfigureConvertFilter();
} catch (const std::runtime_error &e) {
ao_plugin_close(*this);
@ -82,8 +93,7 @@ AudioOutput::OpenOutputAndConvert(AudioFormat desired_audio_format)
return;
}
std::throw_with_nested(FormatRuntimeError("Failed to convert for \"%s\" [%s]",
name, plugin.name));
throw;
}
}

View File

@ -143,6 +143,8 @@ public:
*/
void Close(bool drain) noexcept;
void ConfigureConvertFilter();
/**
* Invoke OutputPlugin::open() and configure the
* #ConvertFilter.

View File

@ -24,7 +24,6 @@
#include "OutputPlugin.hxx"
#include "Domain.hxx"
#include "notify.hxx"
#include "filter/plugins/ConvertFilterPlugin.hxx"
#include "mixer/MixerInternal.hxx"
#include "thread/Util.hxx"
#include "thread/Slack.hxx"
@ -73,8 +72,7 @@ AudioOutputControl::InternalOpen2(const AudioFormat in_audio_format)
input AudioFormat */
try {
convert_filter_set(output->convert_filter.Get(),
output->out_audio_format);
output->ConfigureConvertFilter();
} catch (const std::runtime_error &e) {
open = false;
@ -83,8 +81,7 @@ AudioOutputControl::InternalOpen2(const AudioFormat in_audio_format)
output->CloseOutput(false);
}
std::throw_with_nested(FormatRuntimeError("Failed to convert for \"%s\" [%s]",
GetName(), output->plugin.name));
throw;
}
}