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

View File

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

View File

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