diff --git a/Makefile.am b/Makefile.am index bc248c742..ad0d65427 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1351,6 +1351,7 @@ libmixer_plugins_a_SOURCES += \ noinst_LIBRARIES += libpulse.a libpulse_a_SOURCES = \ + src/lib/pulse/LogError.cxx src/lib/pulse/LogError.hxx \ src/lib/pulse/Error.cxx src/lib/pulse/Error.hxx \ src/lib/pulse/Domain.cxx src/lib/pulse/Domain.hxx libpulse_a_CPPFLAGS = $(AM_CPPFLAGS) $(PULSE_CFLAGS) diff --git a/src/lib/pulse/LogError.cxx b/src/lib/pulse/LogError.cxx new file mode 100644 index 000000000..7f84b41e5 --- /dev/null +++ b/src/lib/pulse/LogError.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 "LogError.hxx" +#include "Domain.hxx" +#include "Log.hxx" + +#include +#include + +void +LogPulseError(pa_context *context, const char *prefix) +{ + const int e = pa_context_errno(context); + FormatError(pulse_domain, "%s: %s", prefix, pa_strerror(e)); +} diff --git a/src/lib/pulse/LogError.hxx b/src/lib/pulse/LogError.hxx new file mode 100644 index 000000000..c50fdf15c --- /dev/null +++ b/src/lib/pulse/LogError.hxx @@ -0,0 +1,28 @@ +/* + * 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_LOG_ERROR_HXX +#define MPD_PULSE_LOG_ERROR_HXX + +struct pa_context; + +void +LogPulseError(pa_context *context, const char *prefix); + +#endif diff --git a/src/mixer/plugins/PulseMixerPlugin.cxx b/src/mixer/plugins/PulseMixerPlugin.cxx index d948c4a48..1c47f5a5a 100644 --- a/src/mixer/plugins/PulseMixerPlugin.cxx +++ b/src/mixer/plugins/PulseMixerPlugin.cxx @@ -20,6 +20,7 @@ #include "config.h" #include "PulseMixerPlugin.hxx" #include "lib/pulse/Domain.hxx" +#include "lib/pulse/LogError.hxx" #include "mixer/MixerInternal.hxx" #include "mixer/Listener.hxx" #include "output/plugins/PulseOutputPlugin.hxx" @@ -30,7 +31,6 @@ #include #include #include -#include #include @@ -118,9 +118,8 @@ PulseMixer::Update(pa_context *context, pa_stream *stream) pa_stream_get_index(stream), pulse_mixer_volume_cb, this); if (o == nullptr) { - FormatError(pulse_domain, - "pa_context_get_sink_input_info() failed: %s", - pa_strerror(pa_context_errno(context))); + LogPulseError(context, + "pa_context_get_sink_input_info() failed"); Offline(); return; } @@ -140,9 +139,8 @@ pulse_mixer_on_connect(gcc_unused PulseMixer &pm, (pa_subscription_mask_t)PA_SUBSCRIPTION_MASK_SINK_INPUT, nullptr, nullptr); if (o == nullptr) { - FormatError(pulse_domain, - "pa_context_subscribe() failed: %s", - pa_strerror(pa_context_errno(context))); + LogPulseError(context, + "pa_context_subscribe() failed"); return; } diff --git a/src/output/plugins/PulseOutputPlugin.cxx b/src/output/plugins/PulseOutputPlugin.cxx index 916366bf7..3e50eac52 100644 --- a/src/output/plugins/PulseOutputPlugin.cxx +++ b/src/output/plugins/PulseOutputPlugin.cxx @@ -21,6 +21,7 @@ #include "PulseOutputPlugin.hxx" #include "lib/pulse/Domain.hxx" #include "lib/pulse/Error.hxx" +#include "lib/pulse/LogError.hxx" #include "../OutputAPI.hxx" #include "mixer/MixerList.hxx" #include "mixer/plugins/PulseMixerPlugin.hxx" @@ -618,9 +619,8 @@ pulse_output_close(AudioOutput *ao) o = pa_stream_drain(po->stream, pulse_output_stream_success_cb, po); if (o == nullptr) { - FormatWarning(pulse_domain, - "pa_stream_drain() has failed: %s", - pa_strerror(pa_context_errno(po->context))); + LogPulseError(po->context, + "pa_stream_drain() has failed"); } else pulse_wait_for_operation(po->mainloop, o); } @@ -797,9 +797,7 @@ pulse_output_cancel(AudioOutput *ao) o = pa_stream_flush(po->stream, pulse_output_stream_success_cb, po); if (o == nullptr) { - FormatWarning(pulse_domain, - "pa_stream_flush() has failed: %s", - pa_strerror(pa_context_errno(po->context))); + LogPulseError(po->context, "pa_stream_flush() has failed"); pa_threaded_mainloop_unlock(po->mainloop); return; }