Blame pulse/conf_pulse.c

Packit 675970
/*-*- linux-c -*-*/
Packit 675970
Packit 675970
/*
Packit 675970
 * ALSA configuration function extensions for pulse
Packit 675970
 *
Packit 675970
 * Copyright (c) 2008 by Sjoerd Simons <sjoerd@luon.net>
Packit 675970
 *
Packit 675970
 * This library is free software; you can redistribute it and/or modify
Packit 675970
 * it under the terms of the GNU Lesser General Public License as
Packit 675970
 * published by the Free Software Foundation; either version 2.1 of
Packit 675970
 * the License, or (at your option) any later version.
Packit 675970
 *
Packit 675970
 * This program is distributed in the hope that it will be useful,
Packit 675970
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 675970
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 675970
 * GNU Lesser General Public License for more details.
Packit 675970
 *
Packit 675970
 * You should have received a copy of the GNU Lesser General Public
Packit 675970
 * License along with this library; if not, write to the Free
Packit 675970
 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
Packit 675970
 * 02111-1307 USA
Packit 675970
 *
Packit 675970
 */
Packit 675970
Packit 675970
#include <stdio.h>
Packit 675970
Packit 675970
#include <alsa/asoundlib.h>
Packit 675970
#include <pulse/pulseaudio.h>
Packit 675970
Packit 675970
Packit 675970
/* Not actually part of the alsa api....  */
Packit 675970
extern int
Packit 675970
snd_config_hook_load(snd_config_t * root, snd_config_t * config,
Packit 675970
		     snd_config_t ** dst, snd_config_t * private_data);
Packit 675970
Packit 675970
int
Packit 675970
conf_pulse_hook_load_if_running(snd_config_t * root, snd_config_t * config,
Packit 675970
				snd_config_t ** dst,
Packit 675970
				snd_config_t * private_data)
Packit 675970
{
Packit 675970
	pa_mainloop *loop = NULL;
Packit 675970
	pa_context *context = NULL;
Packit 675970
	int ret = 0, err, state;
Packit 675970
Packit 675970
	*dst = NULL;
Packit 675970
Packit 675970
	/* Defined if we're called inside the pulsedaemon itself */
Packit 675970
	if (getenv("PULSE_INTERNAL") != NULL)
Packit 675970
		goto out;
Packit 675970
Packit 675970
	loop = pa_mainloop_new();
Packit 675970
	if (loop == NULL)
Packit 675970
		goto out;
Packit 675970
Packit 675970
	context = pa_context_new(pa_mainloop_get_api(loop), "Alsa hook");
Packit 675970
	if (context == NULL)
Packit 675970
		goto out;
Packit 675970
Packit 675970
	err = pa_context_connect(context, NULL, 0, NULL);
Packit 675970
	if (err < 0)
Packit 675970
		goto out;
Packit 675970
Packit 675970
	do {
Packit 675970
		err = pa_mainloop_iterate(loop, 1, NULL);
Packit 675970
		if (err < 0)
Packit 675970
			goto out;
Packit 675970
Packit 675970
		state = pa_context_get_state(context);
Packit 675970
	} while (state < PA_CONTEXT_AUTHORIZING);
Packit 675970
Packit 675970
	if (state > PA_CONTEXT_READY)
Packit 675970
		goto out;
Packit 675970
Packit 675970
	ret = snd_config_hook_load(root, config, dst, private_data);
Packit 675970
Packit 675970
      out:
Packit 675970
	if (context != NULL)
Packit 675970
		pa_context_unref(context);
Packit 675970
Packit 675970
	if (loop != NULL)
Packit 675970
		pa_mainloop_free(loop);
Packit 675970
Packit 675970
	return ret;
Packit 675970
}
Packit 675970
Packit 675970
SND_DLSYM_BUILD_VERSION(conf_pulse_hook_load_if_running,
Packit 675970
			SND_CONFIG_DLSYM_VERSION_HOOK);