output/pulse: move SetError() to lib/pulse/Error.cxx
This commit is contained in:
parent
fe9db8b369
commit
6a0a5f9693
@ -1351,6 +1351,7 @@ libmixer_plugins_a_SOURCES += \
|
|||||||
|
|
||||||
noinst_LIBRARIES += libpulse.a
|
noinst_LIBRARIES += libpulse.a
|
||||||
libpulse_a_SOURCES = \
|
libpulse_a_SOURCES = \
|
||||||
|
src/lib/pulse/Error.cxx src/lib/pulse/Error.hxx \
|
||||||
src/lib/pulse/Domain.cxx src/lib/pulse/Domain.hxx
|
src/lib/pulse/Domain.cxx src/lib/pulse/Domain.hxx
|
||||||
libpulse_a_CPPFLAGS = $(AM_CPPFLAGS) $(PULSE_CFLAGS)
|
libpulse_a_CPPFLAGS = $(AM_CPPFLAGS) $(PULSE_CFLAGS)
|
||||||
PULSE_LIBS2 = libpulse.a $(PULSE_LIBS)
|
PULSE_LIBS2 = libpulse.a $(PULSE_LIBS)
|
||||||
|
33
src/lib/pulse/Error.cxx
Normal file
33
src/lib/pulse/Error.cxx
Normal file
@ -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));
|
||||||
|
}
|
29
src/lib/pulse/Error.hxx
Normal file
29
src/lib/pulse/Error.hxx
Normal file
@ -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
|
@ -20,6 +20,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "PulseOutputPlugin.hxx"
|
#include "PulseOutputPlugin.hxx"
|
||||||
#include "lib/pulse/Domain.hxx"
|
#include "lib/pulse/Domain.hxx"
|
||||||
|
#include "lib/pulse/Error.hxx"
|
||||||
#include "../OutputAPI.hxx"
|
#include "../OutputAPI.hxx"
|
||||||
#include "mixer/MixerList.hxx"
|
#include "mixer/MixerList.hxx"
|
||||||
#include "mixer/plugins/PulseMixerPlugin.hxx"
|
#include "mixer/plugins/PulseMixerPlugin.hxx"
|
||||||
@ -31,7 +32,6 @@
|
|||||||
#include <pulse/stream.h>
|
#include <pulse/stream.h>
|
||||||
#include <pulse/introspect.h>
|
#include <pulse/introspect.h>
|
||||||
#include <pulse/subscribe.h>
|
#include <pulse/subscribe.h>
|
||||||
#include <pulse/error.h>
|
|
||||||
#include <pulse/version.h>
|
#include <pulse/version.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -59,13 +59,6 @@ struct PulseOutput {
|
|||||||
:base(pulse_output_plugin) {}
|
: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
|
void
|
||||||
pulse_output_lock(PulseOutput &po)
|
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),
|
pa_stream_get_index(po.stream),
|
||||||
volume, nullptr, nullptr);
|
volume, nullptr, nullptr);
|
||||||
if (o == nullptr) {
|
if (o == nullptr) {
|
||||||
SetError(error, po.context,
|
SetPulseError(error, po.context,
|
||||||
"failed to set PulseAudio volume");
|
"failed to set PulseAudio volume");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,8 +230,8 @@ pulse_output_connect(PulseOutput *po, Error &error)
|
|||||||
|
|
||||||
if (pa_context_connect(po->context, po->server,
|
if (pa_context_connect(po->context, po->server,
|
||||||
(pa_context_flags_t)0, nullptr) < 0) {
|
(pa_context_flags_t)0, nullptr) < 0) {
|
||||||
SetError(error, po->context,
|
SetPulseError(error, po->context,
|
||||||
"pa_context_connect() has failed");
|
"pa_context_connect() has failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +430,7 @@ pulse_output_wait_connection(PulseOutput *po, Error &error)
|
|||||||
case PA_CONTEXT_TERMINATED:
|
case PA_CONTEXT_TERMINATED:
|
||||||
case PA_CONTEXT_FAILED:
|
case PA_CONTEXT_FAILED:
|
||||||
/* failure */
|
/* failure */
|
||||||
SetError(error, po->context, "failed to connect");
|
SetPulseError(error, po->context, "failed to connect");
|
||||||
pulse_output_delete_context(po);
|
pulse_output_delete_context(po);
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -527,7 +520,8 @@ pulse_output_setup_stream(PulseOutput *po, const pa_sample_spec *ss,
|
|||||||
PA_CHANNEL_MAP_WAVEEX);
|
PA_CHANNEL_MAP_WAVEEX);
|
||||||
po->stream = pa_stream_new(po->context, po->name, ss, &chan_map);
|
po->stream = pa_stream_new(po->context, po->name, ss, &chan_map);
|
||||||
if (po->stream == nullptr) {
|
if (po->stream == nullptr) {
|
||||||
SetError(error, po->context, "pa_stream_new() has failed");
|
SetPulseError(error, po->context,
|
||||||
|
"pa_stream_new() has failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,8 +593,8 @@ pulse_output_open(AudioOutput *ao, AudioFormat &audio_format,
|
|||||||
nullptr, nullptr) < 0) {
|
nullptr, nullptr) < 0) {
|
||||||
pulse_output_delete_stream(po);
|
pulse_output_delete_stream(po);
|
||||||
|
|
||||||
SetError(error, po->context,
|
SetPulseError(error, po->context,
|
||||||
"pa_stream_connect_playback() has failed");
|
"pa_stream_connect_playback() has failed");
|
||||||
pa_threaded_mainloop_unlock(po->mainloop);
|
pa_threaded_mainloop_unlock(po->mainloop);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -657,8 +651,8 @@ pulse_output_wait_stream(PulseOutput *po, Error &error)
|
|||||||
case PA_STREAM_FAILED:
|
case PA_STREAM_FAILED:
|
||||||
case PA_STREAM_TERMINATED:
|
case PA_STREAM_TERMINATED:
|
||||||
case PA_STREAM_UNCONNECTED:
|
case PA_STREAM_UNCONNECTED:
|
||||||
SetError(error, po->context,
|
SetPulseError(error, po->context,
|
||||||
"failed to connect the stream");
|
"failed to connect the stream");
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
case PA_STREAM_CREATING:
|
case PA_STREAM_CREATING:
|
||||||
@ -684,12 +678,14 @@ pulse_output_stream_pause(PulseOutput *po, bool pause,
|
|||||||
o = pa_stream_cork(po->stream, pause,
|
o = pa_stream_cork(po->stream, pause,
|
||||||
pulse_output_stream_success_cb, po);
|
pulse_output_stream_success_cb, po);
|
||||||
if (o == nullptr) {
|
if (o == nullptr) {
|
||||||
SetError(error, po->context, "pa_stream_cork() has failed");
|
SetPulseError(error, po->context,
|
||||||
|
"pa_stream_cork() has failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pulse_wait_for_operation(po->mainloop, o)) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -772,7 +768,7 @@ pulse_output_play(AudioOutput *ao, const void *chunk, size_t size,
|
|||||||
0, PA_SEEK_RELATIVE);
|
0, PA_SEEK_RELATIVE);
|
||||||
pa_threaded_mainloop_unlock(po->mainloop);
|
pa_threaded_mainloop_unlock(po->mainloop);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
SetError(error, po->context, "pa_stream_write() failed");
|
SetPulseError(error, po->context, "pa_stream_write() failed");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user