Filter/Internal: migrate from class Error to C++ exceptions
This commit is contained in:
@@ -93,38 +93,28 @@ AudioOutput::Disable()
|
||||
}
|
||||
|
||||
inline AudioFormat
|
||||
AudioOutput::OpenFilter(AudioFormat &format, Error &error_r)
|
||||
{
|
||||
AudioOutput::OpenFilter(AudioFormat &format)
|
||||
try {
|
||||
assert(format.IsValid());
|
||||
|
||||
/* the replay_gain filter cannot fail here */
|
||||
if (prepared_replay_gain_filter != nullptr) {
|
||||
if (prepared_replay_gain_filter != nullptr)
|
||||
replay_gain_filter_instance =
|
||||
prepared_replay_gain_filter->Open(format, error_r);
|
||||
if (replay_gain_filter_instance == nullptr)
|
||||
return AudioFormat::Undefined();
|
||||
}
|
||||
prepared_replay_gain_filter->Open(format);
|
||||
|
||||
if (prepared_other_replay_gain_filter != nullptr) {
|
||||
if (prepared_other_replay_gain_filter != nullptr)
|
||||
other_replay_gain_filter_instance =
|
||||
prepared_other_replay_gain_filter->Open(format, error_r);
|
||||
if (other_replay_gain_filter_instance == nullptr) {
|
||||
delete replay_gain_filter_instance;
|
||||
return AudioFormat::Undefined();
|
||||
}
|
||||
}
|
||||
prepared_other_replay_gain_filter->Open(format);
|
||||
|
||||
filter_instance = prepared_filter->Open(format, error_r);
|
||||
if (filter_instance == nullptr) {
|
||||
delete other_replay_gain_filter_instance;
|
||||
delete replay_gain_filter_instance;
|
||||
return AudioFormat::Undefined();
|
||||
}
|
||||
filter_instance = prepared_filter->Open(format);
|
||||
|
||||
if (mixer != nullptr && mixer->IsPlugin(software_mixer_plugin))
|
||||
software_mixer_set_filter(*mixer, volume_filter.Get());
|
||||
|
||||
return filter_instance->GetOutAudioFormat();
|
||||
} catch (...) {
|
||||
CloseFilter();
|
||||
throw;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -165,10 +155,11 @@ AudioOutput::Open()
|
||||
|
||||
/* open the filter */
|
||||
|
||||
const AudioFormat filter_audio_format =
|
||||
OpenFilter(in_audio_format, error);
|
||||
if (!filter_audio_format.IsDefined()) {
|
||||
FormatError(error, "Failed to open filter for \"%s\" [%s]",
|
||||
AudioFormat filter_audio_format;
|
||||
try {
|
||||
filter_audio_format = OpenFilter(in_audio_format);
|
||||
} catch (const std::runtime_error &e) {
|
||||
FormatError(e, "Failed to open filter for \"%s\" [%s]",
|
||||
name, plugin.name);
|
||||
|
||||
fail_timer.Update();
|
||||
@@ -202,9 +193,10 @@ AudioOutput::Open()
|
||||
return;
|
||||
}
|
||||
|
||||
if (!convert_filter_set(convert_filter.Get(), out_audio_format,
|
||||
error)) {
|
||||
FormatError(error, "Failed to convert for \"%s\" [%s]",
|
||||
try {
|
||||
convert_filter_set(convert_filter.Get(), out_audio_format);
|
||||
} catch (const std::runtime_error &e) {
|
||||
FormatError(e, "Failed to convert for \"%s\" [%s]",
|
||||
name, plugin.name);
|
||||
|
||||
mutex.unlock();
|
||||
@@ -295,12 +287,12 @@ AudioOutput::ReopenFilter()
|
||||
CloseFilter();
|
||||
mutex.lock();
|
||||
|
||||
const AudioFormat filter_audio_format =
|
||||
OpenFilter(in_audio_format, error);
|
||||
if (!filter_audio_format.IsDefined() ||
|
||||
!convert_filter_set(convert_filter.Get(), out_audio_format,
|
||||
error)) {
|
||||
FormatError(error,
|
||||
AudioFormat filter_audio_format;
|
||||
try {
|
||||
filter_audio_format = OpenFilter(in_audio_format);
|
||||
convert_filter_set(convert_filter.Get(), out_audio_format);
|
||||
} catch (const std::runtime_error &e) {
|
||||
FormatError(e,
|
||||
"Failed to open filter for \"%s\" [%s]",
|
||||
name, plugin.name);
|
||||
|
||||
@@ -383,11 +375,13 @@ ao_chunk_data(AudioOutput *ao, const MusicChunk *chunk,
|
||||
*replay_gain_serial_p = chunk->replay_gain_serial;
|
||||
}
|
||||
|
||||
Error error;
|
||||
data = replay_gain_filter->FilterPCM(data, error);
|
||||
if (data.IsNull())
|
||||
FormatError(error, "\"%s\" [%s] failed to filter",
|
||||
try {
|
||||
data = replay_gain_filter->FilterPCM(data);
|
||||
} catch (const std::runtime_error &e) {
|
||||
FormatError(e, "\"%s\" [%s] failed to filter",
|
||||
ao->name, ao->plugin.name);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
@@ -449,15 +443,13 @@ ao_filter_chunk(AudioOutput *ao, const MusicChunk *chunk)
|
||||
|
||||
/* apply filter chain */
|
||||
|
||||
Error error;
|
||||
data = ao->filter_instance->FilterPCM(data, error);
|
||||
if (data.IsNull()) {
|
||||
FormatError(error, "\"%s\" [%s] failed to filter",
|
||||
try {
|
||||
return ao->filter_instance->FilterPCM(data);
|
||||
} catch (const std::runtime_error &e) {
|
||||
FormatError(e, "\"%s\" [%s] failed to filter",
|
||||
ao->name, ao->plugin.name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
inline bool
|
||||
|
||||
Reference in New Issue
Block a user