{mixer,output}/pulse: use a common Domain instance
This commit is contained in:
		
							
								
								
									
										10
									
								
								Makefile.am
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								Makefile.am
									
									
									
									
									
								
							@@ -1231,7 +1231,6 @@ OUTPUT_LIBS = \
 | 
				
			|||||||
	$(ROAR_LIBS) \
 | 
						$(ROAR_LIBS) \
 | 
				
			||||||
	$(JACK_LIBS) \
 | 
						$(JACK_LIBS) \
 | 
				
			||||||
	$(OPENAL_LIBS) \
 | 
						$(OPENAL_LIBS) \
 | 
				
			||||||
	$(PULSE_LIBS) \
 | 
					 | 
				
			||||||
	$(SHOUT_LIBS)
 | 
						$(SHOUT_LIBS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
OUTPUT_API_SRC = \
 | 
					OUTPUT_API_SRC = \
 | 
				
			||||||
@@ -1256,7 +1255,7 @@ liboutput_plugins_a_SOURCES = \
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
MIXER_LIBS = \
 | 
					MIXER_LIBS = \
 | 
				
			||||||
	libmixer_plugins.a \
 | 
						libmixer_plugins.a \
 | 
				
			||||||
	$(PULSE_LIBS)
 | 
						$(PULSE_LIBS2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MIXER_API_SRC = \
 | 
					MIXER_API_SRC = \
 | 
				
			||||||
	src/mixer/Listener.hxx \
 | 
						src/mixer/Listener.hxx \
 | 
				
			||||||
@@ -1349,6 +1348,13 @@ liboutput_plugins_a_SOURCES += \
 | 
				
			|||||||
	src/output/plugins/PulseOutputPlugin.hxx
 | 
						src/output/plugins/PulseOutputPlugin.hxx
 | 
				
			||||||
libmixer_plugins_a_SOURCES += \
 | 
					libmixer_plugins_a_SOURCES += \
 | 
				
			||||||
	src/mixer/plugins/PulseMixerPlugin.cxx src/mixer/plugins/PulseMixerPlugin.hxx
 | 
						src/mixer/plugins/PulseMixerPlugin.cxx src/mixer/plugins/PulseMixerPlugin.hxx
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					noinst_LIBRARIES += libpulse.a
 | 
				
			||||||
 | 
					libpulse_a_SOURCES = \
 | 
				
			||||||
 | 
						src/lib/pulse/Domain.cxx src/lib/pulse/Domain.hxx
 | 
				
			||||||
 | 
					libpulse_a_CPPFLAGS = $(AM_CPPFLAGS) $(PULSE_CFLAGS)
 | 
				
			||||||
 | 
					PULSE_LIBS2 = libpulse.a $(PULSE_LIBS)
 | 
				
			||||||
 | 
					OUTPUT_LIBS += $(PULSE_LIBS2)
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if HAVE_SHOUT
 | 
					if HAVE_SHOUT
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								src/lib/pulse/Domain.cxx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/lib/pulse/Domain.cxx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * 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 "Domain.hxx"
 | 
				
			||||||
 | 
					#include "util/Domain.hxx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const Domain pulse_domain("pulse");
 | 
				
			||||||
							
								
								
									
										27
									
								
								src/lib/pulse/Domain.hxx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/lib/pulse/Domain.hxx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * 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_DOMAIN_HXX
 | 
				
			||||||
 | 
					#define MPD_PULSE_DOMAIN_HXX
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Domain;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern const Domain pulse_domain;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
@@ -19,11 +19,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "config.h"
 | 
					#include "config.h"
 | 
				
			||||||
#include "PulseMixerPlugin.hxx"
 | 
					#include "PulseMixerPlugin.hxx"
 | 
				
			||||||
 | 
					#include "lib/pulse/Domain.hxx"
 | 
				
			||||||
#include "mixer/MixerInternal.hxx"
 | 
					#include "mixer/MixerInternal.hxx"
 | 
				
			||||||
#include "mixer/Listener.hxx"
 | 
					#include "mixer/Listener.hxx"
 | 
				
			||||||
#include "output/plugins/PulseOutputPlugin.hxx"
 | 
					#include "output/plugins/PulseOutputPlugin.hxx"
 | 
				
			||||||
#include "util/Error.hxx"
 | 
					#include "util/Error.hxx"
 | 
				
			||||||
#include "util/Domain.hxx"
 | 
					 | 
				
			||||||
#include "Log.hxx"
 | 
					#include "Log.hxx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <pulse/context.h>
 | 
					#include <pulse/context.h>
 | 
				
			||||||
@@ -66,8 +66,6 @@ public:
 | 
				
			|||||||
	bool SetVolume(unsigned volume, Error &error) override;
 | 
						bool SetVolume(unsigned volume, Error &error) override;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static constexpr Domain pulse_mixer_domain("pulse_mixer");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
PulseMixer::Offline()
 | 
					PulseMixer::Offline()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -120,7 +118,7 @@ PulseMixer::Update(pa_context *context, pa_stream *stream)
 | 
				
			|||||||
					       pa_stream_get_index(stream),
 | 
										       pa_stream_get_index(stream),
 | 
				
			||||||
					       pulse_mixer_volume_cb, this);
 | 
										       pulse_mixer_volume_cb, this);
 | 
				
			||||||
	if (o == nullptr) {
 | 
						if (o == nullptr) {
 | 
				
			||||||
		FormatError(pulse_mixer_domain,
 | 
							FormatError(pulse_domain,
 | 
				
			||||||
			    "pa_context_get_sink_input_info() failed: %s",
 | 
								    "pa_context_get_sink_input_info() failed: %s",
 | 
				
			||||||
			    pa_strerror(pa_context_errno(context)));
 | 
								    pa_strerror(pa_context_errno(context)));
 | 
				
			||||||
		Offline();
 | 
							Offline();
 | 
				
			||||||
@@ -142,7 +140,7 @@ pulse_mixer_on_connect(gcc_unused PulseMixer &pm,
 | 
				
			|||||||
				 (pa_subscription_mask_t)PA_SUBSCRIPTION_MASK_SINK_INPUT,
 | 
									 (pa_subscription_mask_t)PA_SUBSCRIPTION_MASK_SINK_INPUT,
 | 
				
			||||||
				 nullptr, nullptr);
 | 
									 nullptr, nullptr);
 | 
				
			||||||
	if (o == nullptr) {
 | 
						if (o == nullptr) {
 | 
				
			||||||
		FormatError(pulse_mixer_domain,
 | 
							FormatError(pulse_domain,
 | 
				
			||||||
			    "pa_context_subscribe() failed: %s",
 | 
								    "pa_context_subscribe() failed: %s",
 | 
				
			||||||
			    pa_strerror(pa_context_errno(context)));
 | 
								    pa_strerror(pa_context_errno(context)));
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
@@ -212,7 +210,7 @@ PulseMixer::SetVolume(unsigned new_volume, Error &error)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (!online) {
 | 
						if (!online) {
 | 
				
			||||||
		pulse_output_unlock(output);
 | 
							pulse_output_unlock(output);
 | 
				
			||||||
		error.Set(pulse_mixer_domain, "disconnected");
 | 
							error.Set(pulse_domain, "disconnected");
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,11 +19,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "config.h"
 | 
					#include "config.h"
 | 
				
			||||||
#include "PulseOutputPlugin.hxx"
 | 
					#include "PulseOutputPlugin.hxx"
 | 
				
			||||||
 | 
					#include "lib/pulse/Domain.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"
 | 
				
			||||||
#include "util/Error.hxx"
 | 
					#include "util/Error.hxx"
 | 
				
			||||||
#include "util/Domain.hxx"
 | 
					 | 
				
			||||||
#include "Log.hxx"
 | 
					#include "Log.hxx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <pulse/thread-mainloop.h>
 | 
					#include <pulse/thread-mainloop.h>
 | 
				
			||||||
@@ -59,13 +59,11 @@ struct PulseOutput {
 | 
				
			|||||||
		:base(pulse_output_plugin) {}
 | 
							:base(pulse_output_plugin) {}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static constexpr Domain pulse_output_domain("pulse_output");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
SetError(Error &error, pa_context *context, const char *msg)
 | 
					SetError(Error &error, pa_context *context, const char *msg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const int e = pa_context_errno(context);
 | 
						const int e = pa_context_errno(context);
 | 
				
			||||||
	error.Format(pulse_output_domain, e, "%s: %s", msg, pa_strerror(e));
 | 
						error.Format(pulse_domain, e, "%s: %s", msg, pa_strerror(e));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
@@ -120,7 +118,7 @@ pulse_output_set_volume(PulseOutput &po, const pa_cvolume *volume,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (po.context == nullptr || po.stream == nullptr ||
 | 
						if (po.context == nullptr || po.stream == nullptr ||
 | 
				
			||||||
	    pa_stream_get_state(po.stream) != PA_STREAM_READY) {
 | 
						    pa_stream_get_state(po.stream) != PA_STREAM_READY) {
 | 
				
			||||||
		error.Set(pulse_output_domain, "disconnected");
 | 
							error.Set(pulse_domain, "disconnected");
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -301,7 +299,7 @@ pulse_output_setup_context(PulseOutput *po, Error &error)
 | 
				
			|||||||
	po->context = pa_context_new(pa_threaded_mainloop_get_api(po->mainloop),
 | 
						po->context = pa_context_new(pa_threaded_mainloop_get_api(po->mainloop),
 | 
				
			||||||
				     MPD_PULSE_NAME);
 | 
									     MPD_PULSE_NAME);
 | 
				
			||||||
	if (po->context == nullptr) {
 | 
						if (po->context == nullptr) {
 | 
				
			||||||
		error.Set(pulse_output_domain, "pa_context_new() has failed");
 | 
							error.Set(pulse_domain, "pa_context_new() has failed");
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -364,7 +362,7 @@ pulse_output_enable(AudioOutput *ao, Error &error)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	po->mainloop = pa_threaded_mainloop_new();
 | 
						po->mainloop = pa_threaded_mainloop_new();
 | 
				
			||||||
	if (po->mainloop == nullptr) {
 | 
						if (po->mainloop == nullptr) {
 | 
				
			||||||
		error.Set(pulse_output_domain,
 | 
							error.Set(pulse_domain,
 | 
				
			||||||
			  "pa_threaded_mainloop_new() has failed");
 | 
								  "pa_threaded_mainloop_new() has failed");
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -376,7 +374,7 @@ pulse_output_enable(AudioOutput *ao, Error &error)
 | 
				
			|||||||
		pa_threaded_mainloop_free(po->mainloop);
 | 
							pa_threaded_mainloop_free(po->mainloop);
 | 
				
			||||||
		po->mainloop = nullptr;
 | 
							po->mainloop = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		error.Set(pulse_output_domain,
 | 
							error.Set(pulse_domain,
 | 
				
			||||||
			  "pa_threaded_mainloop_start() has failed");
 | 
								  "pa_threaded_mainloop_start() has failed");
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -626,7 +624,7 @@ pulse_output_close(AudioOutput *ao)
 | 
				
			|||||||
		o = pa_stream_drain(po->stream,
 | 
							o = pa_stream_drain(po->stream,
 | 
				
			||||||
				    pulse_output_stream_success_cb, po);
 | 
									    pulse_output_stream_success_cb, po);
 | 
				
			||||||
		if (o == nullptr) {
 | 
							if (o == nullptr) {
 | 
				
			||||||
			FormatWarning(pulse_output_domain,
 | 
								FormatWarning(pulse_domain,
 | 
				
			||||||
				      "pa_stream_drain() has failed: %s",
 | 
									      "pa_stream_drain() has failed: %s",
 | 
				
			||||||
				      pa_strerror(pa_context_errno(po->context)));
 | 
									      pa_strerror(pa_context_errno(po->context)));
 | 
				
			||||||
		} else
 | 
							} else
 | 
				
			||||||
@@ -749,7 +747,7 @@ pulse_output_play(AudioOutput *ao, const void *chunk, size_t size,
 | 
				
			|||||||
	while (po->writable == 0) {
 | 
						while (po->writable == 0) {
 | 
				
			||||||
		if (pa_stream_is_suspended(po->stream)) {
 | 
							if (pa_stream_is_suspended(po->stream)) {
 | 
				
			||||||
			pa_threaded_mainloop_unlock(po->mainloop);
 | 
								pa_threaded_mainloop_unlock(po->mainloop);
 | 
				
			||||||
			error.Set(pulse_output_domain, "suspended");
 | 
								error.Set(pulse_domain, "suspended");
 | 
				
			||||||
			return 0;
 | 
								return 0;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -757,7 +755,7 @@ pulse_output_play(AudioOutput *ao, const void *chunk, size_t size,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		if (pa_stream_get_state(po->stream) != PA_STREAM_READY) {
 | 
							if (pa_stream_get_state(po->stream) != PA_STREAM_READY) {
 | 
				
			||||||
			pa_threaded_mainloop_unlock(po->mainloop);
 | 
								pa_threaded_mainloop_unlock(po->mainloop);
 | 
				
			||||||
			error.Set(pulse_output_domain, "disconnected");
 | 
								error.Set(pulse_domain, "disconnected");
 | 
				
			||||||
			return 0;
 | 
								return 0;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -803,7 +801,7 @@ pulse_output_cancel(AudioOutput *ao)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	o = pa_stream_flush(po->stream, pulse_output_stream_success_cb, po);
 | 
						o = pa_stream_flush(po->stream, pulse_output_stream_success_cb, po);
 | 
				
			||||||
	if (o == nullptr) {
 | 
						if (o == nullptr) {
 | 
				
			||||||
		FormatWarning(pulse_output_domain,
 | 
							FormatWarning(pulse_domain,
 | 
				
			||||||
			      "pa_stream_flush() has failed: %s",
 | 
								      "pa_stream_flush() has failed: %s",
 | 
				
			||||||
			      pa_strerror(pa_context_errno(po->context)));
 | 
								      pa_strerror(pa_context_errno(po->context)));
 | 
				
			||||||
		pa_threaded_mainloop_unlock(po->mainloop);
 | 
							pa_threaded_mainloop_unlock(po->mainloop);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user