Esempio n. 1
0
static int
tsmf_pulse_open(ITSMFAudioDevice * audio, const char * device)
{
	TSMFPulseAudioDevice * pulse = (TSMFPulseAudioDevice *) audio;

	if (device)
	{
		strcpy(pulse->device, device);
	}

	pulse->mainloop = pa_threaded_mainloop_new();
	if (!pulse->mainloop)
	{
		LLOGLN(0, ("tsmf_pulse_open: pa_threaded_mainloop_new failed"));
		return 1;
	}
	pulse->context = pa_context_new(pa_threaded_mainloop_get_api(pulse->mainloop), "freerdp");
	if (!pulse->context)
	{
		LLOGLN(0, ("tsmf_pulse_open: pa_context_new failed"));
		return 1;
	}
	pa_context_set_state_callback(pulse->context, tsmf_pulse_context_state_callback, pulse);
	if (tsmf_pulse_connect(pulse))
	{
		LLOGLN(0, ("tsmf_pulse_open: tsmf_pulse_connect failed"));
		return 1;
	}

	LLOGLN(0, ("tsmf_pulse_open: open device %s", pulse->device));
	return 0;
}
Esempio n. 2
0
int
audio_pa_init(void)
{
  pa_audio_mode_t *pam;
  audio_mode_t *am;

  TRACE(TRACE_DEBUG, "PA", "Headerversion: %s, library: %s",
	pa_get_headers_version(), pa_get_library_version());

  mainloop = pa_threaded_mainloop_new();
  api = pa_threaded_mainloop_get_api(mainloop);

  pa_threaded_mainloop_lock(mainloop);
  pa_threaded_mainloop_start(mainloop);
  pa_threaded_mainloop_unlock(mainloop);

  pam = calloc(1, sizeof(pa_audio_mode_t));
  am = &pam->am;
  am->am_multich_controls = 1;
  am->am_formats = 
    AM_FORMAT_PCM_STEREO | AM_FORMAT_PCM_5DOT1 | AM_FORMAT_PCM_7DOT1;
  am->am_sample_rates = AM_SR_ANY;
  am->am_title = strdup("Pulseaudio");
  am->am_id = strdup("pulseaudio");
  am->am_preferred_size = 1024;
  am->am_entry = pa_audio_start;
  am->am_float = 1;

  audio_mode_register(am);
  return 1;
}
Esempio n. 3
0
static BOOL tsmf_pulse_open(ITSMFAudioDevice *audio, const char *device)
{
	TSMFPulseAudioDevice *pulse = (TSMFPulseAudioDevice *) audio;
	if(device)
	{
		strcpy(pulse->device, device);
	}
	pulse->mainloop = pa_threaded_mainloop_new();
	if(!pulse->mainloop)
	{
		DEBUG_WARN("pa_threaded_mainloop_new failed");
		return FALSE;
	}
	pulse->context = pa_context_new(pa_threaded_mainloop_get_api(pulse->mainloop), "freerdp");
	if(!pulse->context)
	{
		DEBUG_WARN("pa_context_new failed");
		return FALSE;
	}
	pa_context_set_state_callback(pulse->context, tsmf_pulse_context_state_callback, pulse);
	if(tsmf_pulse_connect(pulse))
	{
		DEBUG_WARN("tsmf_pulse_connect failed");
		return FALSE;
	}
	DEBUG_TSMF("open device %s", pulse->device);
	return TRUE;
}
Esempio n. 4
0
/*
 * enumerate input/output devices
 */
static void pulse_enumerate_devices(obs_properties_t props, bool input)
{
	pa_context *c;
	pa_operation *op;
	pa_threaded_mainloop *m = pa_threaded_mainloop_new();
	struct pulse_enumerate e;

	e.mainloop = m;
	e.devices = obs_properties_add_list(props, "device_id", "Device",
		OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
	e.input = input;

	pa_threaded_mainloop_start(m);
	c = pulse_context_create(m);

	if (pulse_context_connect(m, c) < 0)
		goto fail;

	pa_threaded_mainloop_lock(m);

	op = pa_context_get_source_info_list(c, pulse_source_info, (void *) &e);
	while (pa_operation_get_state(op) == PA_OPERATION_RUNNING)
		pa_threaded_mainloop_wait(m);
	pa_operation_unref(op);

	pa_threaded_mainloop_unlock(m);

	pa_context_disconnect(c);
fail:
	pa_context_unref(c);
	pa_threaded_mainloop_stop(m);
	pa_threaded_mainloop_free(m);
}
Esempio n. 5
0
/******************************************************************************
 * Start the PulseAudio mainloop background thread.
 * This function returns as soon as the PulseAudio thread is started.
 * Initialization of PulseAudio is done in the background thread.
 * In order to learn when initialization is finished, you need to wait until
 * context_state_cb() is called, and check the PulseAudio context state.
 *****************************************************************************/
static mbx_error_code init_pulseaudio(_mbx_out out) {
    if ((out->pa_ml = pa_threaded_mainloop_new()) == NULL ) {
        mbx_log_error(MBX_LOG_AUDIO_OUTPUT, "Unable to allocate a PulseAudio threaded main "
            "loop object.");
        return MBX_PULSEAUDIO_ERROR;
    }
    out->pa_props = pa_proplist_new(); /* TODO: Set properties in proplist */
    pa_mainloop_api *pa_mlapi = pa_threaded_mainloop_get_api(out->pa_ml);
    out->pa_ctx = pa_context_new_with_proplist(pa_mlapi, NULL, out->pa_props);
    if ( out->pa_ctx == NULL ) {
        mbx_log_error(MBX_LOG_AUDIO_OUTPUT, "Unable to instantiate a pulseaudio connection "
            "context.");
        return MBX_PULSEAUDIO_ERROR;
    }
    pa_context_set_state_callback(out->pa_ctx, context_state_cb, out);
    if ( pa_context_connect(out->pa_ctx, NULL, 0, NULL) < 0 ) {
        mbx_log_error(MBX_LOG_AUDIO_OUTPUT, "Unable to connect to the pulseaudio server: %s",
            pa_msg(out));
        return MBX_PULSEAUDIO_ERROR;
    }
    if ( pa_threaded_mainloop_start(out->pa_ml) ) {
        mbx_log_error(MBX_LOG_AUDIO_OUTPUT, "Failed to start pulseaudio mainloop "
            "in background thread.");
        return MBX_PULSEAUDIO_ERROR;
    }
    return MBX_SUCCESS;
}
Esempio n. 6
0
void guac_pa_start_stream(guac_client* client) {

    vnc_guac_client_data* client_data = (vnc_guac_client_data*) client->data;
    pa_context* context;

    guac_client_log_info(client, "Starting audio stream");
    guac_audio_stream_begin(client_data->audio,
                GUAC_VNC_AUDIO_RATE,
                GUAC_VNC_AUDIO_CHANNELS,
                GUAC_VNC_AUDIO_BPS);

    /* Init main loop */
    client_data->pa_mainloop = pa_threaded_mainloop_new();

    /* Create context */
    context = pa_context_new(
            pa_threaded_mainloop_get_api(client_data->pa_mainloop),
            "Guacamole Audio");

    /* Set up context */
    pa_context_set_state_callback(context, __context_state_callback, client);
    pa_context_connect(context, client_data->pa_servername,
            PA_CONTEXT_NOAUTOSPAWN, NULL);

    /* Start loop */
    pa_threaded_mainloop_start(client_data->pa_mainloop);

}
Esempio n. 7
0
/**
 * Creates and references the VLC PulseAudio threaded main loop.
 * @return the mainloop or NULL on failure
 */
static pa_threaded_mainloop *vlc_pa_mainloop_init (void)
{
    pa_threaded_mainloop *mainloop;

    vlc_mutex_lock (&lock);
    if (refs == 0)
    {
        mainloop = pa_threaded_mainloop_new ();
        if (unlikely(mainloop == NULL))
            goto out;

        if (pa_threaded_mainloop_start (mainloop) < 0)
        {
            pa_threaded_mainloop_free (mainloop);
            goto out;
        }
        vlc_pa_mainloop = mainloop;
    }
    else
    {
        if (unlikely(refs < UINT_MAX))
        {
            mainloop = NULL;
            goto out;
        }
        mainloop = vlc_pa_mainloop;
    }

    assert (mainloop != NULL);
    refs++;
out:
    vlc_mutex_unlock (&lock);
    return mainloop;
}
Esempio n. 8
0
static void
moko_notify_init (MokoNotify *notify)
{
  MokoNotifyPrivate *priv;
  pa_threaded_mainloop *mainloop = NULL;
  pa_mainloop_api *mapi = NULL;

  priv = notify->priv = MOKO_NOTIFY_GET_PRIVATE (notify);

  priv->started = 0;
  priv->pac = NULL;

  /* Start up pulse audio */
  mainloop = pa_threaded_mainloop_new ();
  if (!mainloop)
  {
    g_warning ("Unable to create PulseAudio mainloop.");
    return;
  }
  mapi = pa_threaded_mainloop_get_api (mainloop);
  priv->pac = pa_context_new (mapi, "Openmoko Dialer");
  if (!priv->pac)
  {
    g_warning ("Could create the PulseAudio context");
    return;
  }
  pa_context_connect (priv->pac, NULL, 0, NULL);
  pa_threaded_mainloop_start (mainloop);
}
Esempio n. 9
0
context_t *backend_new(callback_t *callback) {
    context_t *context = (context_t*)malloc(sizeof(context_t));
    context->loop = pa_threaded_mainloop_new();
    context->state = PA_CONTEXT_UNCONNECTED;
    backend_init(context, callback);
    pa_threaded_mainloop_start(context->loop);
    return context;
}
Esempio n. 10
0
/*
 * Public API.
 */
xmms_pulse *
xmms_pulse_backend_new (const char *server, const char *name,
                        int *rerror)
{
	xmms_pulse *p;
	int error = PA_ERR_INTERNAL;

	if (server && !*server) {
		if (rerror)
			*rerror = PA_ERR_INVALID;
		return NULL;
	}

	p = g_new0 (xmms_pulse, 1);
	if (!p)
		return NULL;

	p->volume = 100;

	p->mainloop = pa_threaded_mainloop_new ();
	if (!p->mainloop)
		goto fail;

	p->context = pa_context_new (pa_threaded_mainloop_get_api (p->mainloop), name);
	if (!p->context)
		goto fail;

	pa_context_set_state_callback (p->context, context_state_cb, p);

	if (pa_context_connect (p->context, server, 0, NULL) < 0) {
		error = pa_context_errno (p->context);
		goto fail;
	}

	pa_threaded_mainloop_lock (p->mainloop);

	if (pa_threaded_mainloop_start (p->mainloop) < 0)
		goto unlock_and_fail;

	/* Wait until the context is ready */
	pa_threaded_mainloop_wait (p->mainloop);

	if (pa_context_get_state (p->context) != PA_CONTEXT_READY) {
		error = pa_context_errno (p->context);
		goto unlock_and_fail;
	}

	pa_threaded_mainloop_unlock (p->mainloop);
	return p;

 unlock_and_fail:
	pa_threaded_mainloop_unlock (p->mainloop);
 fail:
	if (rerror)
		*rerror = error;
	xmms_pulse_backend_free (p);
	return NULL;
}
Esempio n. 11
0
static void init_pulse_context(){
	if (context==NULL){
		pa_loop=pa_threaded_mainloop_new();
		context=pa_context_new(pa_threaded_mainloop_get_api(pa_loop),NULL);
		pa_context_set_state_callback(context,state_notify,NULL);	
		pa_context_connect(context,NULL,0,NULL);
		pa_threaded_mainloop_start(pa_loop);
		atexit(uninit_pulse_context);
	}
}
void PulseAudioSinksManager::retrieveSinks()
{
    pa_mainloop_api *pa_mlapi;
    // Create a mainloop API and connection to the default server
    pa_ml.reset(pa_threaded_mainloop_new());
    pa_mlapi = pa_threaded_mainloop_get_api(pa_ml.get());
    pa_ctx.reset(pa_context_new(pa_mlapi, "QAudioSwitcher"));
    pa_context_set_state_callback(pa_ctx.get(), PulseAudioSinksManager::pulseAudioStateCallback, this);
    pa_context_connect(pa_ctx.get(), NULL, PA_CONTEXT_NOFAIL  , NULL);
    pa_threaded_mainloop_start(pa_ml.get());
}
Esempio n. 13
0
WavegenClient::WavegenClient(std::string const& name)
	: name_(name)
{
	paMainLoop_ = pa_threaded_mainloop_new();
	pa_threaded_mainloop_set_name(paMainLoop_, name_.c_str());
	pa_threaded_mainloop_start(paMainLoop_);

	paMainApi_ = pa_threaded_mainloop_get_api(paMainLoop_);
	paContext_ = pa_context_new(paMainApi_, name_.c_str());
	pa_context_set_state_callback(paContext_, &WavegenClient::contextStateCallback, this);
}
Esempio n. 14
0
int FreeRDPRdpsndDeviceEntry(PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)
{
	rdpsndPulsePlugin* pulse;
	RDP_PLUGIN_DATA* data;

	pulse = xnew(rdpsndPulsePlugin);

	pulse->device.Open = rdpsnd_pulse_open;
	pulse->device.FormatSupported = rdpsnd_pulse_format_supported;
	pulse->device.SetFormat = rdpsnd_pulse_set_format;
	pulse->device.SetVolume = rdpsnd_pulse_set_volume;
	pulse->device.Play = rdpsnd_pulse_play;
	pulse->device.Start = rdpsnd_pulse_start;
	pulse->device.Close = rdpsnd_pulse_close;
	pulse->device.Free = rdpsnd_pulse_free;

	data = pEntryPoints->plugin_data;
	if (data && strcmp((char*)data->data[0], "pulse") == 0)
	{
		if(data->data[1] && strlen((char*)data->data[1]) > 0) 
			pulse->device_name = xstrdup((char*)data->data[1]);
		else
			pulse->device_name = NULL;
	}

	pulse->dsp_context = freerdp_dsp_context_new();

	pulse->mainloop = pa_threaded_mainloop_new();
	if (!pulse->mainloop)
	{
		DEBUG_WARN("pa_threaded_mainloop_new failed");
		rdpsnd_pulse_free((rdpsndDevicePlugin*)pulse);
		return 1;
	}
	pulse->context = pa_context_new(pa_threaded_mainloop_get_api(pulse->mainloop), "freerdp");
	if (!pulse->context)
	{
		DEBUG_WARN("pa_context_new failed");
		rdpsnd_pulse_free((rdpsndDevicePlugin*)pulse);
		return 1;
	}
	pa_context_set_state_callback(pulse->context, rdpsnd_pulse_context_state_callback, pulse);
	if (!rdpsnd_pulse_connect((rdpsndDevicePlugin*)pulse))
	{
		DEBUG_WARN("rdpsnd_pulse_connect failed");
		rdpsnd_pulse_free((rdpsndDevicePlugin*)pulse);
		return 1;
	}

	pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, (rdpsndDevicePlugin*)pulse);

	return 0;
}
Esempio n. 15
0
bool CPulseAE::Initialize()
{
  m_Volume = g_settings.m_fVolumeLevel;

  if ((m_MainLoop = pa_threaded_mainloop_new()) == NULL)
  {
    CLog::Log(LOGERROR, "PulseAudio: Failed to allocate main loop");
    return false;
  }

  if ((m_Context = pa_context_new(pa_threaded_mainloop_get_api(m_MainLoop), "XBMC")) == NULL)
  {
    CLog::Log(LOGERROR, "PulseAudio: Failed to allocate context");
    return false;
  }

  pa_context_set_state_callback(m_Context, ContextStateCallback, m_MainLoop);

  if (pa_context_connect(m_Context, NULL, (pa_context_flags_t)0, NULL) < 0)
  {
    CLog::Log(LOGERROR, "PulseAudio: Failed to connect context");
    return false;
  }

  pa_threaded_mainloop_lock(m_MainLoop);
  if (pa_threaded_mainloop_start(m_MainLoop) < 0)
  {
    CLog::Log(LOGERROR, "PulseAudio: Failed to start MainLoop");
    pa_threaded_mainloop_unlock(m_MainLoop);
    return false;
  }

  /* Wait until the context is ready */
  do
  {
    pa_threaded_mainloop_wait(m_MainLoop);
    CLog::Log(LOGDEBUG, "PulseAudio: Context %s", ContextStateToString(pa_context_get_state(m_Context)));
  }
  while (pa_context_get_state(m_Context) != PA_CONTEXT_READY && pa_context_get_state(m_Context) != PA_CONTEXT_FAILED);

  if (pa_context_get_state(m_Context) == PA_CONTEXT_FAILED)
  {
    CLog::Log(LOGERROR, "PulseAudio: Waited for the Context but it failed");
    pa_threaded_mainloop_unlock(m_MainLoop);
    return false;
  }

  pa_threaded_mainloop_unlock(m_MainLoop);
  return true;
}
Esempio n. 16
0
bool CAESinkPULSE::SetupContext(const char *host, pa_context **context, pa_threaded_mainloop **mainloop)
{
  if ((*mainloop = pa_threaded_mainloop_new()) == NULL)
  {
    CLog::Log(LOGERROR, "PulseAudio: Failed to allocate main loop");
    return false;
  }

  if (((*context) = pa_context_new(pa_threaded_mainloop_get_api(*mainloop), "Kodi")) == NULL)
  {
    CLog::Log(LOGERROR, "PulseAudio: Failed to allocate context");
    return false;
  }

  pa_context_set_state_callback(*context, ContextStateCallback, *mainloop);

  if (pa_context_connect(*context, host, (pa_context_flags_t)0, NULL) < 0)
  {
    CLog::Log(LOGERROR, "PulseAudio: Failed to connect context");
    return false;
  }
  pa_threaded_mainloop_lock(*mainloop);

  if (pa_threaded_mainloop_start(*mainloop) < 0)
  {
    CLog::Log(LOGERROR, "PulseAudio: Failed to start MainLoop");
    pa_threaded_mainloop_unlock(*mainloop);
    return false;
  }

  /* Wait until the context is ready */
  do
  {
    pa_threaded_mainloop_wait(*mainloop);
    CLog::Log(LOGDEBUG, "PulseAudio: Context %s", ContextStateToString(pa_context_get_state(*context)));
  }
  while (pa_context_get_state(*context) != PA_CONTEXT_READY && pa_context_get_state(*context) != PA_CONTEXT_FAILED);

  if (pa_context_get_state(*context) == PA_CONTEXT_FAILED)
  {
    CLog::Log(LOGERROR, "PulseAudio: Waited for the Context but it failed");
    pa_threaded_mainloop_unlock(*mainloop);
    return false;
  }

  pa_threaded_mainloop_unlock(*mainloop);
  return true;
}
Esempio n. 17
0
int_fast32_t pulse_init()
{
	pthread_mutex_lock(&pulse_mutex);

	if (pulse_refs == 0) {
		pulse_mainloop = pa_threaded_mainloop_new();
		pa_threaded_mainloop_start(pulse_mainloop);

		pulse_init_context();
	}

	pulse_refs++;

	pthread_mutex_unlock(&pulse_mutex);

	return 0;
}
Esempio n. 18
0
static bool
pulse_output_enable(struct audio_output *ao, GError **error_r)
{
	struct pulse_output *po = (struct pulse_output *)ao;

	assert(po->mainloop == NULL);
	assert(po->context == NULL);

	/* create the libpulse mainloop and start the thread */

	po->mainloop = pa_threaded_mainloop_new();
	if (po->mainloop == NULL) {
		g_free(po);

		g_set_error(error_r, pulse_output_quark(), 0,
			    "pa_threaded_mainloop_new() has failed");
		return false;
	}

	pa_threaded_mainloop_lock(po->mainloop);

	if (pa_threaded_mainloop_start(po->mainloop) < 0) {
		pa_threaded_mainloop_unlock(po->mainloop);
		pa_threaded_mainloop_free(po->mainloop);
		po->mainloop = NULL;

		g_set_error(error_r, pulse_output_quark(), 0,
			    "pa_threaded_mainloop_start() has failed");
		return false;
	}

	/* create the libpulse context and connect it */

	if (!pulse_output_setup_context(po, error_r)) {
		pa_threaded_mainloop_unlock(po->mainloop);
		pa_threaded_mainloop_stop(po->mainloop);
		pa_threaded_mainloop_free(po->mainloop);
		po->mainloop = NULL;
		return false;
	}

	pa_threaded_mainloop_unlock(po->mainloop);

	return true;
}
Esempio n. 19
0
int FreeRDPAudinDeviceEntry(PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)
{
    AudinPulseDevice* pulse;
    RDP_PLUGIN_DATA * data;

    pulse = xnew(AudinPulseDevice);

    pulse->iface.Open = audin_pulse_open;
    pulse->iface.FormatSupported = audin_pulse_format_supported;
    pulse->iface.SetFormat = audin_pulse_set_format;
    pulse->iface.Close = audin_pulse_close;
    pulse->iface.Free = audin_pulse_free;

    data = pEntryPoints->plugin_data;
    if (data && data->data[0] && strcmp(data->data[0], "audin") == 0 &&
            data->data[1] && strcmp(data->data[1], "pulse") == 0)
    {
        strncpy(pulse->device_name, (char*)data->data[2], sizeof(pulse->device_name));
    }

    pulse->mainloop = pa_threaded_mainloop_new();
    if (!pulse->mainloop)
    {
        DEBUG_WARN("pa_threaded_mainloop_new failed");
        audin_pulse_free((IAudinDevice*) pulse);
        return 1;
    }
    pulse->context = pa_context_new(pa_threaded_mainloop_get_api(pulse->mainloop), "freerdp");
    if (!pulse->context)
    {
        DEBUG_WARN("pa_context_new failed");
        audin_pulse_free((IAudinDevice*) pulse);
        return 1;
    }
    pa_context_set_state_callback(pulse->context, audin_pulse_context_state_callback, pulse);
    if (!audin_pulse_connect((IAudinDevice*) pulse))
    {
        audin_pulse_free((IAudinDevice*) pulse);
        return 1;
    }

    pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*) pulse);

    return 0;
}
Esempio n. 20
0
ALCboolean alc_pulse_init(BackendFuncs *func_list)
{
    ALCboolean ret = ALC_FALSE;

    if(pulse_load())
    {
        pa_threaded_mainloop *loop;

        pulse_ctx_flags = 0;
        if(!GetConfigValueBool("pulse", "spawn-server", 0))
            pulse_ctx_flags |= PA_CONTEXT_NOAUTOSPAWN;

        if((loop=pa_threaded_mainloop_new()) &&
           pa_threaded_mainloop_start(loop) >= 0)
        {
            pa_context *context;

            pa_threaded_mainloop_lock(loop);
            context = connect_context(loop, AL_TRUE);
            if(context)
            {
                *func_list = pulse_funcs;
                ret = ALC_TRUE;

                /* Some libraries (Phonon, Qt) set some pulseaudio properties
                 * through environment variables, which causes all streams in
                 * the process to inherit them. This attempts to filter those
                 * properties out by setting them to 0-length data. */
                prop_filter = pa_proplist_new();
                pa_proplist_set(prop_filter, PA_PROP_MEDIA_ROLE, NULL, 0);
                pa_proplist_set(prop_filter, "phonon.streamid", NULL, 0);

                pa_context_disconnect(context);
                pa_context_unref(context);
            }
            pa_threaded_mainloop_unlock(loop);
            pa_threaded_mainloop_stop(loop);
        }
        if(loop)
            pa_threaded_mainloop_free(loop);
    }

    return ret;
}
Esempio n. 21
0
static ALCboolean pulse_open(ALCdevice *device, const ALCchar *device_name) //{{{
{
    pulse_data *data = pa_xmalloc(sizeof(pulse_data));
    memset(data, 0, sizeof(*data));

    if(!(data->loop = pa_threaded_mainloop_new()))
    {
        ERR("pa_threaded_mainloop_new() failed!\n");
        goto out;
    }
    if(pa_threaded_mainloop_start(data->loop) < 0)
    {
        ERR("pa_threaded_mainloop_start() failed\n");
        goto out;
    }

    pa_threaded_mainloop_lock(data->loop);
    device->ExtraData = data;

    data->context = connect_context(data->loop, AL_FALSE);
    if(!data->context)
    {
        pa_threaded_mainloop_unlock(data->loop);
        goto out;
    }
    pa_context_set_state_callback(data->context, context_state_callback2, device);

    device->szDeviceName = strdup(device_name);

    pa_threaded_mainloop_unlock(data->loop);
    return ALC_TRUE;

out:
    if(data->loop)
    {
        pa_threaded_mainloop_stop(data->loop);
        pa_threaded_mainloop_free(data->loop);
    }

    device->ExtraData = NULL;
    pa_xfree(data);
    return ALC_FALSE;
} //}}}
Esempio n. 22
0
int main(int argc, char **argv)
{
    GtkWidget *window = NULL;
    GtkWidget *scale = NULL;
    
    m_pa_ml = pa_threaded_mainloop_new();
    if (!m_pa_ml) {
        printf("pa_threaded_mainloop_new() failed");
        return -1;
    }
    
    m_pa_mlapi = pa_threaded_mainloop_get_api(m_pa_ml);
    if (!m_pa_mlapi) {
        printf("pa_threaded_mainloop_get_api() failed");
        return -1;
    }

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "PulseAudio Gtk Demo");
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 300);

    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(m_destroy), NULL);

    m_adjust = gtk_adjustment_new(60000, 0, 100000, 1, 1, 0);
    g_signal_connect(m_adjust, "value-changed", G_CALLBACK(m_value_changed), NULL);
    
    scale = gtk_hscale_new(m_adjust);
    gtk_container_add(GTK_CONTAINER(window), scale);

    gtk_widget_show(scale);
    gtk_widget_show(window);
  
    pa_threaded_mainloop_start(m_pa_ml);
    m_connect_to_pulse();
    
    gtk_main();

    return 0;
}
Esempio n. 23
0
audio_class_t *
audio_driver_init(void)
{
  TRACE(TRACE_DEBUG, "PA", "Headerversion: %s, library: %s",
	pa_get_headers_version(), pa_get_library_version());

  mainloop = pa_threaded_mainloop_new();
  api = pa_threaded_mainloop_get_api(mainloop);

  pa_threaded_mainloop_lock(mainloop);
  pa_threaded_mainloop_start(mainloop);

#if PA_API_VERSION >= 12
  pa_proplist *pl = pa_proplist_new();

  pa_proplist_sets(pl, PA_PROP_APPLICATION_ID, "com.lonelycoder.hts.showtime");
  pa_proplist_sets(pl, PA_PROP_APPLICATION_NAME, "Showtime");
  
  /* Create a new connection context */
  ctx = pa_context_new_with_proplist(api, "Showtime", pl);
  pa_proplist_free(pl);
#else
  ctx = pa_context_new(api, "Showtime");
#endif

  pa_context_set_state_callback(ctx, context_state_callback, NULL);

  /* Connect the context */
  if(pa_context_connect(ctx, NULL, 0, NULL) < 0) {
    TRACE(TRACE_ERROR, "PA", "pa_context_connect() failed: %s",
	  pa_strerror(pa_context_errno(ctx)));
    pa_threaded_mainloop_unlock(mainloop);
    return NULL;
  }

  pa_threaded_mainloop_unlock(mainloop);

  return &pulseaudio_audio_class;
}
Esempio n. 24
0
int context_create(){
    if(context != NULL){
        return 0;
    }
    connected = false;
    failed = false;

    threaded_main_loop = pa_threaded_mainloop_new();
    pa_mainloop_api *main_loop_api = pa_threaded_mainloop_get_api(threaded_main_loop);
    context =  pa_context_new(main_loop_api, "vumeter");

    pa_context_set_state_callback(context, context_state_callback, NULL);

    if(pa_context_connect(context, NULL, (pa_context_flags_t) PA_CONTEXT_NOAUTOSPAWN, NULL)){
        qDebug("Error connecting to server...");
        pa_threaded_mainloop_stop(threaded_main_loop);
        pa_threaded_mainloop_free(threaded_main_loop);
        return -1;
    }

    pa_threaded_mainloop_start(threaded_main_loop);

    pa_threaded_mainloop_lock(threaded_main_loop);
    while ((! connected) && (! failed)) {
        qDebug("Waiting until connection is established...");
        pa_threaded_mainloop_wait(threaded_main_loop);
        qDebug("Received signal...");
    }
    pa_threaded_mainloop_unlock(threaded_main_loop);

    if(failed){
        pa_context_unref(context);
        context = NULL;
        return -2;
    }

    return 0;
}
Esempio n. 25
0
int
cubeb_init(cubeb ** context, char const * context_name)
{
  cubeb * ctx;

  ctx = calloc(1, sizeof(*ctx));

  ctx->mainloop = pa_threaded_mainloop_new();
  ctx->context = pa_context_new(pa_threaded_mainloop_get_api(ctx->mainloop), context_name);

  pa_context_set_state_callback(ctx->context, context_state_callback, ctx->mainloop);
  pa_threaded_mainloop_start(ctx->mainloop);

  pa_threaded_mainloop_lock(ctx->mainloop);
  pa_context_connect(ctx->context, NULL, 0, NULL);
  pa_threaded_mainloop_unlock(ctx->mainloop);

  state_wait(ctx, PA_CONTEXT_READY);

  *context = ctx;

  return CUBEB_OK;
}
Esempio n. 26
0
File: te.c Progetto: ITikhonov/tem
void audio_init() {
	pa_threaded_mainloop *pa_ml=pa_threaded_mainloop_new();
	pa_mainloop_api *pa_mlapi=pa_threaded_mainloop_get_api(pa_ml);
	pa_context *pa_ctx=pa_context_new(pa_mlapi, "te");
	pa_context_connect(pa_ctx, NULL, 0, NULL);
	int pa_ready = 0;
	pa_context_set_state_callback(pa_ctx, pa_state_cb, &pa_ready);

	pa_threaded_mainloop_start(pa_ml);
	while(pa_ready==0) { ; }

	printf("audio ready\n");

	if (pa_ready == 2) {
		pa_context_disconnect(pa_ctx);
		pa_context_unref(pa_ctx);
		pa_threaded_mainloop_free(pa_ml);
	}

	pa_sample_spec ss;
	ss.rate=96000;
	ss.channels=1;
	ss.format=PA_SAMPLE_S24_32LE;
	ps=pa_stream_new(pa_ctx,"Playback",&ss,NULL);
	pa_stream_set_write_callback(ps,audio_request_cb,NULL);
	pa_stream_set_underflow_callback(ps,audio_underflow_cb,NULL);

	pa_buffer_attr bufattr;
	bufattr.fragsize = (uint32_t)-1;
	bufattr.maxlength = pa_usec_to_bytes(20000,&ss);
	bufattr.minreq = pa_usec_to_bytes(0,&ss);
	bufattr.prebuf = 0;
	bufattr.tlength = pa_usec_to_bytes(20000,&ss);

	pa_stream_connect_playback(ps,NULL,&bufattr,
		PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_ADJUST_LATENCY|PA_STREAM_AUTO_TIMING_UPDATE|PA_STREAM_START_CORKED,NULL,NULL);
}
Esempio n. 27
0
static void probe_devices(ALboolean capture)
{
    pa_threaded_mainloop *loop;

    if(capture == AL_FALSE)
        allDevNameMap = malloc(sizeof(DevMap) * 1);
    else
        allCaptureDevNameMap = malloc(sizeof(DevMap) * 1);

    if((loop=pa_threaded_mainloop_new()) &&
       pa_threaded_mainloop_start(loop) >= 0)
    {
        pa_context *context;

        pa_threaded_mainloop_lock(loop);
        context = connect_context(loop, AL_FALSE);
        if(context)
        {
            pa_operation *o;

            if(capture == AL_FALSE)
                o = pa_context_get_sink_info_list(context, sink_device_callback, loop);
            else
                o = pa_context_get_source_info_list(context, source_device_callback, loop);
            while(pa_operation_get_state(o) == PA_OPERATION_RUNNING)
                pa_threaded_mainloop_wait(loop);
            pa_operation_unref(o);

            pa_context_disconnect(context);
            pa_context_unref(context);
        }
        pa_threaded_mainloop_unlock(loop);
        pa_threaded_mainloop_stop(loop);
    }
    if(loop)
        pa_threaded_mainloop_free(loop);
}
Esempio n. 28
0
PulseAudioSystem::PulseAudioSystem() {
	pasInput = pasOutput = pasSpeaker = NULL;
	bSourceDone=bSinkDone=bServerDone = false;
	iDelayCache = 0;
	bPositionalCache = false;
	bAttenuating = false;
	iRemainingOperations = 0;
	bPulseIsGood = false;
	iSinkId = -1;

	pam = pa_threaded_mainloop_new();
	pa_mainloop_api *api = pa_threaded_mainloop_get_api(pam);

	pa_proplist *proplist;

	proplist = pa_proplist_new();
	pa_proplist_sets(proplist, PA_PROP_APPLICATION_NAME, "Mumble");
	pa_proplist_sets(proplist, PA_PROP_APPLICATION_ID, "net.sourceforge.mumble.mumble");
	pa_proplist_sets(proplist, PA_PROP_APPLICATION_ICON_NAME, "mumble");
	pa_proplist_sets(proplist, PA_PROP_MEDIA_ROLE, "game");

	pacContext = pa_context_new_with_proplist(api, NULL, proplist);
	pa_proplist_free(proplist);

	pa_context_set_subscribe_callback(pacContext, subscribe_callback, this);

	pa_context_set_state_callback(pacContext, context_state_callback, this);
	pa_context_connect(pacContext, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL);

	pade = api->defer_new(api, defer_event_callback, this);
	api->defer_enable(pade, false);

	pa_threaded_mainloop_start(pam);

	bRunning = true;
}
/* Initialization */
std::string RageSoundDriver_PulseAudio::Init()
{
	int error = 0;

	LOG->Trace("Pulse: pa_threaded_mainloop_new()...");
	m_PulseMainLoop = pa_threaded_mainloop_new();
	if(m_PulseMainLoop == nullptr)
	{
		return "pa_threaded_mainloop_new() failed!";
	}

#ifdef PA_PROP_APPLICATION_NAME /* proplist available only since 0.9.11 */
	pa_proplist *plist = pa_proplist_new();
	pa_proplist_sets(plist, PA_PROP_APPLICATION_NAME, PACKAGE_NAME);
	pa_proplist_sets(plist, PA_PROP_APPLICATION_VERSION, PACKAGE_VERSION);
	pa_proplist_sets(plist, PA_PROP_MEDIA_ROLE, "game");

	LOG->Trace("Pulse: pa_context_new_with_proplist()...");

	m_PulseCtx = pa_context_new_with_proplist(
			pa_threaded_mainloop_get_api(m_PulseMainLoop),
			"StepMania", plist);
	pa_proplist_free(plist);

	if(m_PulseCtx == nullptr)
	{
		return "pa_context_new_with_proplist() failed!";
	}
#else
	LOG->Trace("Pulse: pa_context_new()...");
	m_PulseCtx = pa_context_new(
			pa_threaded_mainloop_get_api(m_PulseMainLoop),
			"Stepmania");
	if(m_PulseCtx == nullptr)
	{
		return "pa_context_new() failed!";
	}
#endif

	pa_context_set_state_callback(m_PulseCtx, StaticCtxStateCb, this);

	LOG->Trace("Pulse: pa_context_connect()...");
	error = pa_context_connect(m_PulseCtx, nullptr, (pa_context_flags_t)0, nullptr);

	if(error < 0)
	{
		return fmt::sprintf("pa_contect_connect(): %s",
			pa_strerror(pa_context_errno(m_PulseCtx)));
	}

	LOG->Trace("Pulse: pa_threaded_mainloop_start()...");
	error = pa_threaded_mainloop_start(m_PulseMainLoop);
	if(error < 0)
	{
		return fmt::sprintf("pa_threaded_mainloop_start() returned %i", error);
	}

	/* Create the decode thread, this will be needed for Mix(), that we
 	 * will use as soon as a stream is ready. */
	StartDecodeThread();

	/* Wait for the pulseaudio stream to be ready before returning.
	* An error may occur, if it appends, m_Error becomes non-nullptr. */
	m_Sem.Wait();

	if(m_Error == nullptr)
	{
		return "";
	}
	else
	{
		return m_Error;
	}
}
Esempio n. 30
0
static void *pulse_init(const char *device, unsigned rate, unsigned latency)
{
   pa_sample_spec spec;
   pa_t *pa;
   pa_buffer_attr buffer_attr = {0};
   const pa_buffer_attr *server_attr = NULL;

   memset(&spec, 0, sizeof(spec));
   
   pa = (pa_t*)calloc(1, sizeof(*pa));
   if (!pa)
      goto error;

   pa->mainloop = pa_threaded_mainloop_new();
   if (!pa->mainloop)
      goto error;

   pa->context = pa_context_new(pa_threaded_mainloop_get_api(pa->mainloop), "RetroArch");
   if (!pa->context)
      goto error;

   pa_context_set_state_callback(pa->context, context_state_cb, pa);

   if (pa_context_connect(pa->context, device, PA_CONTEXT_NOFLAGS, NULL) < 0)
      goto error;

   pa_threaded_mainloop_lock(pa->mainloop);
   if (pa_threaded_mainloop_start(pa->mainloop) < 0)
      goto error;

   pa_threaded_mainloop_wait(pa->mainloop);

   if (pa_context_get_state(pa->context) != PA_CONTEXT_READY)
      goto unlock_error;

   spec.format = is_little_endian() ? PA_SAMPLE_FLOAT32LE : PA_SAMPLE_FLOAT32BE;
   spec.channels = 2;
   spec.rate = rate;

   pa->stream = pa_stream_new(pa->context, "audio", &spec, NULL);
   if (!pa->stream)
      goto unlock_error;

   pa_stream_set_state_callback(pa->stream, stream_state_cb, pa);
   pa_stream_set_write_callback(pa->stream, stream_request_cb, pa);
   pa_stream_set_latency_update_callback(pa->stream, stream_latency_update_cb, pa);
   pa_stream_set_underflow_callback(pa->stream, underrun_update_cb, pa);
   pa_stream_set_buffer_attr_callback(pa->stream, buffer_attr_cb, pa);

   buffer_attr.maxlength = -1;
   buffer_attr.tlength = pa_usec_to_bytes(latency * PA_USEC_PER_MSEC, &spec);
   buffer_attr.prebuf = -1;
   buffer_attr.minreq = -1;
   buffer_attr.fragsize = -1;

   if (pa_stream_connect_playback(pa->stream, NULL, &buffer_attr, PA_STREAM_ADJUST_LATENCY, NULL, NULL) < 0)
      goto error;

   pa_threaded_mainloop_wait(pa->mainloop);

   if (pa_stream_get_state(pa->stream) != PA_STREAM_READY)
      goto unlock_error;

   server_attr = pa_stream_get_buffer_attr(pa->stream);
   if (server_attr)
   {
      pa->buffer_size = server_attr->tlength;
      RARCH_LOG("[PulseAudio]: Requested %u bytes buffer, got %u.\n",
            (unsigned)buffer_attr.tlength,
            (unsigned)pa->buffer_size);
   }
   else
      pa->buffer_size = buffer_attr.tlength;

   pa_threaded_mainloop_unlock(pa->mainloop);

   return pa;

unlock_error:
   pa_threaded_mainloop_unlock(pa->mainloop);
error:
   pulse_free(pa); 
   return NULL;
}