aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/pulse/Error.cxx33
-rw-r--r--src/lib/pulse/Error.hxx29
-rw-r--r--src/output/plugins/PulseOutputPlugin.cxx38
3 files changed, 79 insertions, 21 deletions
diff --git a/src/lib/pulse/Error.cxx b/src/lib/pulse/Error.cxx
new file mode 100644
index 000000000..3eece9297
--- /dev/null
+++ b/src/lib/pulse/Error.cxx
@@ -0,0 +1,33 @@
+/*
+ * 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
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+#include "Error.hxx"
+#include "Domain.hxx"
+#include "util/Error.hxx"
+
+#include <pulse/context.h>
+#include <pulse/error.h>
+
+void
+SetPulseError(Error &error, pa_context *context, const char *prefix)
+{
+ const int e = pa_context_errno(context);
+ error.Format(pulse_domain, e, "%s: %s", prefix, pa_strerror(e));
+}
diff --git a/src/lib/pulse/Error.hxx b/src/lib/pulse/Error.hxx
new file mode 100644
index 000000000..872a893b1
--- /dev/null
+++ b/src/lib/pulse/Error.hxx
@@ -0,0 +1,29 @@
+/*
+ * 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
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_PULSE_ERROR_HXX
+#define MPD_PULSE_ERROR_HXX
+
+class Error;
+struct pa_context;
+
+void
+SetPulseError(Error &error, pa_context *context, const char *prefix);
+
+#endif
diff --git a/src/output/plugins/PulseOutputPlugin.cxx b/src/output/plugins/PulseOutputPlugin.cxx
index ff077bed5..916366bf7 100644
--- a/src/output/plugins/PulseOutputPlugin.cxx
+++ b/src/output/plugins/PulseOutputPlugin.cxx
@@ -20,6 +20,7 @@
#include "config.h"
#include "PulseOutputPlugin.hxx"
#include "lib/pulse/Domain.hxx"
+#include "lib/pulse/Error.hxx"
#include "../OutputAPI.hxx"
#include "mixer/MixerList.hxx"
#include "mixer/plugins/PulseMixerPlugin.hxx"
@@ -31,7 +32,6 @@
#include <pulse/stream.h>
#include <pulse/introspect.h>
#include <pulse/subscribe.h>
-#include <pulse/error.h>
#include <pulse/version.h>
#include <assert.h>
@@ -59,13 +59,6 @@ struct PulseOutput {
:base(pulse_output_plugin) {}
};
-static void
-SetError(Error &error, pa_context *context, const char *msg)
-{
- const int e = pa_context_errno(context);
- error.Format(pulse_domain, e, "%s: %s", msg, pa_strerror(e));
-}
-
void
pulse_output_lock(PulseOutput &po)
{
@@ -126,8 +119,8 @@ pulse_output_set_volume(PulseOutput &po, const pa_cvolume *volume,
pa_stream_get_index(po.stream),
volume, nullptr, nullptr);
if (o == nullptr) {
- SetError(error, po.context,
- "failed to set PulseAudio volume");
+ SetPulseError(error, po.context,
+ "failed to set PulseAudio volume");
return false;
}
@@ -237,8 +230,8 @@ pulse_output_connect(PulseOutput *po, Error &error)
if (pa_context_connect(po->context, po->server,
(pa_context_flags_t)0, nullptr) < 0) {
- SetError(error, po->context,
- "pa_context_connect() has failed");
+ SetPulseError(error, po->context,
+ "pa_context_connect() has failed");
return false;
}
@@ -437,7 +430,7 @@ pulse_output_wait_connection(PulseOutput *po, Error &error)
case PA_CONTEXT_TERMINATED:
case PA_CONTEXT_FAILED:
/* failure */
- SetError(error, po->context, "failed to connect");
+ SetPulseError(error, po->context, "failed to connect");
pulse_output_delete_context(po);
return false;
@@ -527,7 +520,8 @@ pulse_output_setup_stream(PulseOutput *po, const pa_sample_spec *ss,
PA_CHANNEL_MAP_WAVEEX);
po->stream = pa_stream_new(po->context, po->name, ss, &chan_map);
if (po->stream == nullptr) {
- SetError(error, po->context, "pa_stream_new() has failed");
+ SetPulseError(error, po->context,
+ "pa_stream_new() has failed");
return false;
}
@@ -599,8 +593,8 @@ pulse_output_open(AudioOutput *ao, AudioFormat &audio_format,
nullptr, nullptr) < 0) {
pulse_output_delete_stream(po);
- SetError(error, po->context,
- "pa_stream_connect_playback() has failed");
+ SetPulseError(error, po->context,
+ "pa_stream_connect_playback() has failed");
pa_threaded_mainloop_unlock(po->mainloop);
return false;
}
@@ -657,8 +651,8 @@ pulse_output_wait_stream(PulseOutput *po, Error &error)
case PA_STREAM_FAILED:
case PA_STREAM_TERMINATED:
case PA_STREAM_UNCONNECTED:
- SetError(error, po->context,
- "failed to connect the stream");
+ SetPulseError(error, po->context,
+ "failed to connect the stream");
return false;
case PA_STREAM_CREATING:
@@ -684,12 +678,14 @@ pulse_output_stream_pause(PulseOutput *po, bool pause,
o = pa_stream_cork(po->stream, pause,
pulse_output_stream_success_cb, po);
if (o == nullptr) {
- SetError(error, po->context, "pa_stream_cork() has failed");
+ SetPulseError(error, po->context,
+ "pa_stream_cork() has failed");
return false;
}
if (!pulse_wait_for_operation(po->mainloop, o)) {
- SetError(error, po->context, "pa_stream_cork() has failed");
+ SetPulseError(error, po->context,
+ "pa_stream_cork() has failed");
return false;
}
@@ -772,7 +768,7 @@ pulse_output_play(AudioOutput *ao, const void *chunk, size_t size,
0, PA_SEEK_RELATIVE);
pa_threaded_mainloop_unlock(po->mainloop);
if (result < 0) {
- SetError(error, po->context, "pa_stream_write() failed");
+ SetPulseError(error, po->context, "pa_stream_write() failed");
return 0;
}