aboutsummaryrefslogtreecommitdiffstats
path: root/src/OutputThread.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/OutputThread.cxx60
1 files changed, 34 insertions, 26 deletions
diff --git a/src/OutputThread.cxx b/src/OutputThread.cxx
index 30d3ba30f..b56e7f1ca 100644
--- a/src/OutputThread.cxx
+++ b/src/OutputThread.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -30,13 +30,12 @@
#include "PlayerControl.hxx"
#include "MusicPipe.hxx"
#include "MusicChunk.hxx"
+#include "thread/Util.hxx"
#include "system/FatalError.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include "Compiler.h"
-#include <glib.h>
-
#include <assert.h>
#include <string.h>
@@ -98,10 +97,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 +142,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 +158,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 +178,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 +239,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 +254,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 +262,6 @@ ao_reopen_filter(struct audio_output *ao)
return;
}
-
- convert_filter_set(ao->convert_filter, ao->out_audio_format);
}
static void
@@ -387,7 +393,7 @@ ao_filter_chunk(struct audio_output *ao, const struct music_chunk *chunk,
void *dest = ao->cross_fade_buffer.Get(other_length);
memcpy(dest, other_data, other_length);
- if (!pcm_mix(dest, data, length,
+ if (!pcm_mix(ao->cross_fade_dither, dest, data, length,
ao->in_audio_format.format,
1.0 - chunk->mix_ratio)) {
FormatError(output_domain,
@@ -437,7 +443,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 +467,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;
}
@@ -573,6 +579,8 @@ audio_output_task(void *arg)
{
struct audio_output *ao = (struct audio_output *)arg;
+ SetThreadRealtime();
+
ao->mutex.lock();
while (1) {