output/Thread: ao_filter_chunk() throws exception on error

Move the error logging to AudioOutput::PlayChunk().
This commit is contained in:
Max Kellermann 2016-12-20 17:35:32 +01:00
parent c2abd02b9b
commit 176dc11748
1 changed files with 14 additions and 25 deletions

View File

@ -36,6 +36,7 @@
#include "thread/Name.hxx" #include "thread/Name.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include "util/ScopeExit.hxx" #include "util/ScopeExit.hxx"
#include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "Compiler.h" #include "Compiler.h"
@ -335,13 +336,7 @@ ao_chunk_data(AudioOutput &ao, const MusicChunk &chunk,
*replay_gain_serial_p = chunk.replay_gain_serial; *replay_gain_serial_p = chunk.replay_gain_serial;
} }
try { data = replay_gain_filter->FilterPCM(data);
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; return data;
@ -363,9 +358,6 @@ ao_filter_chunk(AudioOutput &ao, const MusicChunk &chunk)
ao_chunk_data(ao, *chunk.other, ao_chunk_data(ao, *chunk.other,
ao.other_replay_gain_filter_instance, ao.other_replay_gain_filter_instance,
&ao.other_replay_gain_serial); &ao.other_replay_gain_serial);
if (other_data.IsNull())
return nullptr;
if (other_data.IsEmpty()) if (other_data.IsEmpty())
return data; return data;
@ -390,12 +382,9 @@ ao_filter_chunk(AudioOutput &ao, const MusicChunk &chunk)
memcpy(dest, other_data.data, other_data.size); memcpy(dest, other_data.data, other_data.size);
if (!pcm_mix(ao.cross_fade_dither, dest, data.data, data.size, if (!pcm_mix(ao.cross_fade_dither, dest, data.data, data.size,
ao.in_audio_format.format, ao.in_audio_format.format,
mix_ratio)) { mix_ratio))
FormatError(output_domain, throw FormatRuntimeError("Cannot cross-fade format %s",
"Cannot cross-fade format %s", sample_format_to_string(ao.in_audio_format.format));
sample_format_to_string(ao.in_audio_format.format));
return nullptr;
}
data.data = dest; data.data = dest;
data.size = other_data.size; data.size = other_data.size;
@ -403,13 +392,7 @@ ao_filter_chunk(AudioOutput &ao, const MusicChunk &chunk)
/* apply filter chain */ /* apply filter chain */
try { return ao.filter_instance->FilterPCM(data);
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;
}
} }
inline bool inline bool
@ -427,8 +410,14 @@ AudioOutput::PlayChunk(const MusicChunk &chunk)
} }
} }
auto data = ConstBuffer<char>::FromVoid(ao_filter_chunk(*this, chunk)); ConstBuffer<uint8_t> data;
if (data.IsNull()) {
try {
data = data.FromVoid(ao_filter_chunk(*this, chunk));
} catch (const std::runtime_error &e) {
FormatError(e, "Failed to filter for output \"%s\" [%s]",
name, plugin.name);
Close(false); Close(false);
/* don't automatically reopen this device for 10 /* don't automatically reopen this device for 10