diff options
Diffstat (limited to 'src/OutputThread.cxx')
-rw-r--r-- | src/OutputThread.cxx | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/src/OutputThread.cxx b/src/OutputThread.cxx index 30d3ba30f..1a8c70196 100644 --- a/src/OutputThread.cxx +++ b/src/OutputThread.cxx @@ -35,8 +35,6 @@ #include "Log.hxx" #include "Compiler.h" -#include <glib.h> - #include <assert.h> #include <string.h> @@ -98,10 +96,16 @@ ao_filter_open(struct audio_output *ao, AudioFormat &format, assert(format.IsValid()); /* the replay_gain filter cannot fail here */ - if (ao->replay_gain_filter != nullptr) - ao->replay_gain_filter->Open(format, error_r); - if (ao->other_replay_gain_filter != nullptr) - ao->other_replay_gain_filter->Open(format, error_r); + if (ao->replay_gain_filter != nullptr && + !ao->replay_gain_filter->Open(format, error_r).IsDefined()) + return AudioFormat::Undefined(); + + if (ao->other_replay_gain_filter != nullptr && + !ao->other_replay_gain_filter->Open(format, error_r).IsDefined()) { + if (ao->replay_gain_filter != nullptr) + ao->replay_gain_filter->Close(); + return AudioFormat::Undefined(); + } const AudioFormat af = ao->filter->Open(format, error_r); if (!af.IsDefined()) { @@ -137,14 +141,7 @@ ao_open(struct audio_output *ao) assert(ao->chunk == nullptr); assert(ao->in_audio_format.IsValid()); - if (ao->fail_timer != nullptr) { - /* this can only happen when this - output thread fails while - audio_output_open() is run in the - player thread */ - g_timer_destroy(ao->fail_timer); - ao->fail_timer = nullptr; - } + ao->fail_timer.Reset(); /* enable the device (just in case the last enable has failed) */ @@ -160,7 +157,7 @@ ao_open(struct audio_output *ao) FormatError(error, "Failed to open filter for \"%s\" [%s]", ao->name, ao->plugin->name); - ao->fail_timer = g_timer_new(); + ao->fail_timer.Update(); return; } @@ -180,11 +177,19 @@ ao_open(struct audio_output *ao) ao->name, ao->plugin->name); ao_filter_close(ao); - ao->fail_timer = g_timer_new(); + ao->fail_timer.Update(); return; } - convert_filter_set(ao->convert_filter, ao->out_audio_format); + if (!convert_filter_set(ao->convert_filter, ao->out_audio_format, + error)) { + FormatError(error, "Failed to convert for \"%s\" [%s]", + ao->name, ao->plugin->name); + + ao_filter_close(ao); + ao->fail_timer.Update(); + return; + } ao->open = true; @@ -233,7 +238,9 @@ ao_reopen_filter(struct audio_output *ao) ao_filter_close(ao); const AudioFormat filter_audio_format = ao_filter_open(ao, ao->in_audio_format, error); - if (!filter_audio_format.IsDefined()) { + if (!filter_audio_format.IsDefined() || + !convert_filter_set(ao->convert_filter, ao->out_audio_format, + error)) { FormatError(error, "Failed to open filter for \"%s\" [%s]", ao->name, ao->plugin->name); @@ -246,7 +253,7 @@ ao_reopen_filter(struct audio_output *ao) ao->chunk = nullptr; ao->open = false; - ao->fail_timer = g_timer_new(); + ao->fail_timer.Update(); ao->mutex.unlock(); ao_plugin_close(ao); @@ -254,8 +261,6 @@ ao_reopen_filter(struct audio_output *ao) return; } - - convert_filter_set(ao->convert_filter, ao->out_audio_format); } static void @@ -437,7 +442,7 @@ ao_play_chunk(struct audio_output *ao, const struct music_chunk *chunk) /* don't automatically reopen this device for 10 seconds */ - ao->fail_timer = g_timer_new(); + ao->fail_timer.Update(); return false; } @@ -461,8 +466,8 @@ ao_play_chunk(struct audio_output *ao, const struct music_chunk *chunk) /* don't automatically reopen this device for 10 seconds */ - assert(ao->fail_timer == nullptr); - ao->fail_timer = g_timer_new(); + assert(!ao->fail_timer.IsDefined()); + ao->fail_timer.Update(); return false; } |