static double get_delay_pulse(struct ao *ao) { struct priv *priv = ao->priv; pa_usec_t latency = (pa_usec_t) -1; pa_threaded_mainloop_lock(priv->mainloop); while (pa_stream_get_latency(priv->stream, &latency, NULL) < 0) { if (pa_context_errno(priv->context) != PA_ERR_NODATA) { GENERIC_ERR_MSG("pa_stream_get_latency() failed"); break; } /* Wait until latency data is available again */ pa_threaded_mainloop_wait(priv->mainloop); } pa_threaded_mainloop_unlock(priv->mainloop); return latency == (pa_usec_t) -1 ? 0 : latency / 1000000.0; }
static void pulse_write_process(MSFilter *f){ PulseWriteState *s=(PulseWriteState*)f->data; mblk_t *im; while((im=ms_queue_get(f->inputs[0]))!=NULL){ int bsize=msgdsize(im); if (s->stream){ pa_threaded_mainloop_lock(pa_loop); if (pa_stream_writable_size(s->stream)>=bsize){ //ms_message("Pushing data to pulseaudio"); pa_stream_write(s->stream,im->b_rptr,bsize,NULL,0,PA_SEEK_RELATIVE); } pa_threaded_mainloop_unlock(pa_loop); } freemsg(im); } }
static tbool audin_pulse_connect(IAudinDevice* device) { pa_context_state_t state; AudinPulseDevice* pulse = (AudinPulseDevice*) device; if (!pulse->context) return false; if (pa_context_connect(pulse->context, NULL, 0, NULL)) { DEBUG_WARN("pa_context_connect failed (%d)", pa_context_errno(pulse->context)); return false; } pa_threaded_mainloop_lock(pulse->mainloop); if (pa_threaded_mainloop_start(pulse->mainloop) < 0) { pa_threaded_mainloop_unlock(pulse->mainloop); DEBUG_WARN("pa_threaded_mainloop_start failed (%d)", pa_context_errno(pulse->context)); return false; } for (;;) { state = pa_context_get_state(pulse->context); if (state == PA_CONTEXT_READY) break; if (!PA_CONTEXT_IS_GOOD(state)) { DEBUG_WARN("bad context state (%d)", pa_context_errno(pulse->context)); break; } pa_threaded_mainloop_wait(pulse->mainloop); } pa_threaded_mainloop_unlock(pulse->mainloop); if (state == PA_CONTEXT_READY) { DEBUG_DVC("connected"); return true; } else { pa_context_disconnect(pulse->context); return false; } }
static int Open (vlc_object_t *obj) { services_discovery_t *sd = (services_discovery_t *)obj; pa_operation *op; pa_context *ctx; services_discovery_sys_t *sys = malloc (sizeof (*sys)); if (unlikely(sys == NULL)) return VLC_ENOMEM; ctx = vlc_pa_connect (obj, &sys->mainloop); if (ctx == NULL) { free (sys); return VLC_EGENERIC; } sd->p_sys = sys; sd->description = _("Audio capture"); sys->context = ctx; sys->root = NULL; /* Subscribe for source events */ const pa_subscription_mask_t mask = PA_SUBSCRIPTION_MASK_SOURCE; pa_threaded_mainloop_lock (sys->mainloop); pa_context_set_subscribe_callback (ctx, ContextCallback, sd); op = pa_context_subscribe (ctx, mask, NULL, NULL); if (likely(op != NULL)) pa_operation_unref (op); /* Enumerate existing sources */ op = pa_context_get_source_info_list (ctx, SourceCallback, sd); if (likely(op != NULL)) { //while (pa_operation_get_state (op) == PA_OPERATION_RUNNING) // pa_threaded_mainloop_wait (sys->mainloop); pa_operation_unref (op); } pa_threaded_mainloop_unlock (sys->mainloop); return VLC_SUCCESS; /* error: pa_threaded_mainloop_unlock (sys->mainloop); vlc_pa_disconnect (obj, ctx, sys->mainloop); free (sys); return VLC_EGENERIC;*/ }
static int tsmf_pulse_connect(TSMFPulseAudioDevice * pulse) { pa_context_state_t state; if (!pulse->context) return 1; if (pa_context_connect(pulse->context, NULL, 0, NULL)) { LLOGLN(0, ("tsmf_pulse_connect: pa_context_connect failed (%d)", pa_context_errno(pulse->context))); return 1; } pa_threaded_mainloop_lock(pulse->mainloop); if (pa_threaded_mainloop_start(pulse->mainloop) < 0) { pa_threaded_mainloop_unlock(pulse->mainloop); LLOGLN(0, ("tsmf_pulse_connect: pa_threaded_mainloop_start failed (%d)", pa_context_errno(pulse->context))); return 1; } for (;;) { state = pa_context_get_state(pulse->context); if (state == PA_CONTEXT_READY) break; if (!PA_CONTEXT_IS_GOOD(state)) { LLOGLN(0, ("tsmf_pulse_connect: bad context state (%d)", pa_context_errno(pulse->context))); break; } pa_threaded_mainloop_wait(pulse->mainloop); } pa_threaded_mainloop_unlock(pulse->mainloop); if (state == PA_CONTEXT_READY) { LLOGLN(0, ("tsmf_pulse_connect: connected")); return 0; } else { pa_context_disconnect(pulse->context); return 1; } }
//Flush function. Holds mainloop lock until operation is completed. void quisk_flush_pulseaudio(struct sound_dev *dev) { pa_stream *s = dev->handle; pa_operation *o; pa_threaded_mainloop_lock(pa_ml); if (!(o = pa_stream_flush(s, stream_flushed_callback, dev))) { printf("pa_stream_flush(): %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s)))); exit(1); } else { while(pa_operation_get_state(o) == PA_OPERATION_RUNNING) pa_threaded_mainloop_wait(pa_ml); pa_operation_unref(o); } pa_threaded_mainloop_unlock(pa_ml); }
static int instream_pause_pa(SoundIoPrivate *si, SoundIoInStreamPrivate *is, bool pause) { SoundIoInStreamPulseAudio *ispa = &is->backend_data.pulseaudio; SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio; pa_threaded_mainloop_lock(sipa->main_loop); if (pause != pa_stream_is_corked(ispa->stream)) { pa_operation *op = pa_stream_cork(ispa->stream, pause, NULL, NULL); if (!op) return SoundIoErrorStreaming; pa_operation_unref(op); } pa_threaded_mainloop_unlock(sipa->main_loop); return 0; }
static void instream_destroy_pa(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { struct SoundIoInStreamPulseAudio *ispa = &is->backend_data.pulseaudio; struct SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio; pa_stream *stream = ispa->stream; if (stream) { pa_threaded_mainloop_lock(sipa->main_loop); pa_stream_set_state_callback(stream, NULL, NULL); pa_stream_set_read_callback(stream, NULL, NULL); pa_stream_disconnect(stream); pa_stream_unref(stream); pa_threaded_mainloop_unlock(sipa->main_loop); ispa->stream = NULL; } }
int pa_simple_get_stream_index(pa_simple *p, unsigned int *idx, int *rerror) { pa_assert(p); CHECK_VALIDITY_RETURN_ANY(rerror, idx != NULL, PA_ERR_INVALID, -1); pa_threaded_mainloop_lock(p->mainloop); CHECK_DEAD_GOTO(p, rerror, unlock_and_fail); *idx = pa_stream_get_index(p->stream); pa_threaded_mainloop_unlock(p->mainloop); return 0; unlock_and_fail: pa_threaded_mainloop_unlock(p->mainloop); return -1; }
static gchar * gst_pulsesrc_device_description (GstPulseSrc * pulsesrc) { pa_operation *o = NULL; gchar *t; if (!pulsesrc->mainloop) goto no_mainloop; pa_threaded_mainloop_lock (pulsesrc->mainloop); if (!(o = pa_context_get_source_info_by_name (pulsesrc->context, pulsesrc->device, gst_pulsesrc_source_info_cb, pulsesrc))) { GST_ELEMENT_ERROR (pulsesrc, RESOURCE, FAILED, ("pa_stream_get_source_info() failed: %s", pa_strerror (pa_context_errno (pulsesrc->context))), (NULL)); goto unlock; } while (pa_operation_get_state (o) == PA_OPERATION_RUNNING) { if (gst_pulsesrc_is_dead (pulsesrc, FALSE)) goto unlock; pa_threaded_mainloop_wait (pulsesrc->mainloop); } unlock: if (o) pa_operation_unref (o); t = g_strdup (pulsesrc->device_description); pa_threaded_mainloop_unlock (pulsesrc->mainloop); return t; no_mainloop: { GST_DEBUG_OBJECT (pulsesrc, "have no mainloop"); return NULL; } }
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; }
static void rdpsnd_pulse_play(rdpsndDevicePlugin* device, uint8* data, int size) { rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device; int len; int ret; uint8* src; if (!pulse->stream) return; if (pulse->format == 0x11) { pulse->dsp_context->decode_ima_adpcm(pulse->dsp_context, data, size, pulse->sample_spec.channels, pulse->block_size); size = pulse->dsp_context->adpcm_size; src = pulse->dsp_context->adpcm_buffer; } else { src = data; } pa_threaded_mainloop_lock(pulse->mainloop); while (size > 0) { while ((len = pa_stream_writable_size(pulse->stream)) == 0) { pa_threaded_mainloop_wait(pulse->mainloop); } if (len < 0) break; if (len > size) len = size; ret = pa_stream_write(pulse->stream, src, len, NULL, 0LL, PA_SEEK_RELATIVE); if (ret < 0) { DEBUG_WARN("pa_stream_write failed (%d)", pa_context_errno(pulse->context)); break; } src += len; size -= len; } pa_threaded_mainloop_unlock(pulse->mainloop); }
static boolean tsmf_pulse_close_stream(TSMFPulseAudioDevice* pulse) { if (!pulse->context || !pulse->stream) return false; DEBUG_DVC(""); pa_threaded_mainloop_lock(pulse->mainloop); pa_stream_set_write_callback(pulse->stream, NULL, NULL); tsmf_pulse_wait_for_operation(pulse, pa_stream_drain(pulse->stream, tsmf_pulse_stream_success_callback, pulse)); pa_stream_disconnect(pulse->stream); pa_stream_unref(pulse->stream); pulse->stream = NULL; pa_threaded_mainloop_unlock(pulse->mainloop); return true; }
void CAESinkPULSE::GetDelay(AEDelayStatus& status) { if (!m_IsAllocated) { status.SetDelay(0); return; } pa_threaded_mainloop_lock(m_MainLoop); pa_usec_t r_usec; int negative; if (pa_stream_get_latency(m_Stream, &r_usec, &negative) < 0) r_usec = 0; pa_threaded_mainloop_unlock(m_MainLoop); status.SetDelay(r_usec / 1000000.0); }
static int rdpsnd_pulse_close(rdpsndDevicePlugin * devplugin) { struct pulse_device_data * pulse_data; pulse_data = (struct pulse_device_data *) devplugin->device_data; if (!pulse_data->context || !pulse_data->stream) return 1; LLOGLN(0, ("rdpsnd_pulse_close:")); pa_threaded_mainloop_lock(pulse_data->mainloop); rdpsnd_pulse_wait_for_operation(devplugin, pa_stream_drain(pulse_data->stream, rdpsnd_pulse_stream_success_callback, devplugin)); pa_stream_disconnect(pulse_data->stream); pa_stream_unref(pulse_data->stream); pulse_data->stream = NULL; pa_threaded_mainloop_unlock(pulse_data->mainloop); return 0; }
int AudioOutputPulseAudio::GetBufferedOnSoundcard(void) const { pa_usec_t latency; if (!pcontext || pa_context_get_state(pcontext) != PA_CONTEXT_READY) return 0; if (!pstream || pa_stream_get_state(pstream) != PA_STREAM_READY) return 0; pa_threaded_mainloop_lock(mainloop); if(pa_stream_get_latency(pstream, &latency, NULL) < 0) latency = 0; pa_threaded_mainloop_unlock(mainloop); return (int)latency * samplerate * output_bytes_per_frame / 1000000; }
const QStringList *get_source_names(){ if(source_names == NULL){ context_create(); source_names = new QStringList(); finished = false; pa_context_get_source_info_list(context, get_source_info_list_callback, NULL); do{ pa_threaded_mainloop_lock(threaded_main_loop); pa_threaded_mainloop_wait(threaded_main_loop); qDebug("Received signal..."); }while(! finished); pa_threaded_mainloop_unlock(threaded_main_loop); context_stop(); } return source_names; }
static boolean rdpsnd_pulse_connect(rdpsndDevicePlugin* device) { rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device; pa_context_state_t state; if (!pulse->context) return False; if (pa_context_connect(pulse->context, NULL, 0, NULL)) { DEBUG_WARN("pa_context_connect failed (%d)", pa_context_errno(pulse->context)); return False; } pa_threaded_mainloop_lock(pulse->mainloop); if (pa_threaded_mainloop_start(pulse->mainloop) < 0) { pa_threaded_mainloop_unlock(pulse->mainloop); DEBUG_WARN("pa_threaded_mainloop_start failed (%d)", pa_context_errno(pulse->context)); return False; } for (;;) { state = pa_context_get_state(pulse->context); if (state == PA_CONTEXT_READY) break; if (!PA_CONTEXT_IS_GOOD(state)) { DEBUG_WARN("bad context state (%d)", pa_context_errno(pulse->context)); break; } pa_threaded_mainloop_wait(pulse->mainloop); } pa_threaded_mainloop_unlock(pulse->mainloop); if (state == PA_CONTEXT_READY) { DEBUG_SVC("connected"); return True; } else { pa_context_disconnect(pulse->context); return False; } }
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; }
static int pulse_get_attribute(snd_ctl_ext_t * ext, snd_ctl_ext_key_t key, int *type, unsigned int *acc, unsigned int *count) { snd_ctl_pulse_t *ctl = ext->private_data; int err = 0; if (key > 3) return -EINVAL; assert(ctl); if (!ctl->p || !ctl->p->mainloop) return -EBADFD; pa_threaded_mainloop_lock(ctl->p->mainloop); err = pulse_check_connection(ctl->p); if (err < 0) goto finish; err = pulse_update_volume(ctl); if (err < 0) goto finish; if (key & 1) *type = SND_CTL_ELEM_TYPE_BOOLEAN; else *type = SND_CTL_ELEM_TYPE_INTEGER; *acc = SND_CTL_EXT_ACCESS_READWRITE; if (key == 0) *count = ctl->source_volume.channels; else if (key == 2) *count = ctl->sink_volume.channels; else *count = 1; finish: pa_threaded_mainloop_unlock(ctl->p->mainloop); return err; }
static BOOL tsmf_pulse_connect(TSMFPulseAudioDevice *pulse) { pa_context_state_t state; if(!pulse->context) return FALSE; if(pa_context_connect(pulse->context, NULL, 0, NULL)) { DEBUG_WARN("pa_context_connect failed (%d)", pa_context_errno(pulse->context)); return FALSE; } pa_threaded_mainloop_lock(pulse->mainloop); if(pa_threaded_mainloop_start(pulse->mainloop) < 0) { pa_threaded_mainloop_unlock(pulse->mainloop); DEBUG_WARN("pa_threaded_mainloop_start failed (%d)", pa_context_errno(pulse->context)); return FALSE; } for(;;) { state = pa_context_get_state(pulse->context); if(state == PA_CONTEXT_READY) break; if(!PA_CONTEXT_IS_GOOD(state)) { DEBUG_TSMF("bad context state (%d)", pa_context_errno(pulse->context)); break; } pa_threaded_mainloop_wait(pulse->mainloop); } pa_threaded_mainloop_unlock(pulse->mainloop); if(state == PA_CONTEXT_READY) { DEBUG_TSMF("connected"); return TRUE; } else { pa_context_disconnect(pulse->context); return FALSE; } }
AudioStream::AudioStream(pa_context *c, pa_threaded_mainloop *m, const char *desc, int type, int smplrate, std::string& deviceName) : audiostream_(0), mainloop_(m) { static const pa_channel_map channel_map = { 1, { PA_CHANNEL_POSITION_MONO }, }; pa_sample_spec sample_spec = { PA_SAMPLE_S16LE, // PA_SAMPLE_FLOAT32LE, smplrate, 1 }; assert(pa_sample_spec_valid(&sample_spec)); assert(pa_channel_map_valid(&channel_map)); audiostream_ = pa_stream_new(c, desc, &sample_spec, &channel_map); if (!audiostream_) { ERROR("%s: pa_stream_new() failed : %s" , desc, pa_strerror(pa_context_errno(c))); throw std::runtime_error("Could not create stream\n"); } pa_buffer_attr attributes; attributes.maxlength = pa_usec_to_bytes(160 * PA_USEC_PER_MSEC, &sample_spec); attributes.tlength = pa_usec_to_bytes(80 * PA_USEC_PER_MSEC, &sample_spec); attributes.prebuf = 0; attributes.fragsize = pa_usec_to_bytes(80 * PA_USEC_PER_MSEC, &sample_spec); attributes.minreq = (uint32_t) -1; pa_threaded_mainloop_lock(mainloop_); if (type == PLAYBACK_STREAM || type == RINGTONE_STREAM) pa_stream_connect_playback(audiostream_, deviceName == "" ? NULL : deviceName.c_str(), &attributes, (pa_stream_flags_t)(PA_STREAM_ADJUST_LATENCY|PA_STREAM_AUTO_TIMING_UPDATE), NULL, NULL); else if (type == CAPTURE_STREAM) pa_stream_connect_record(audiostream_, deviceName == "" ? NULL : deviceName.c_str(), &attributes, (pa_stream_flags_t)(PA_STREAM_ADJUST_LATENCY|PA_STREAM_AUTO_TIMING_UPDATE)); pa_threaded_mainloop_unlock(mainloop_); pa_stream_set_state_callback(audiostream_, stream_state_callback, NULL); }
JNIEXPORT void JNICALL Java_com_harrcharr_pulse_PulseContext_JNISubscribe( JNIEnv *jenv, jobject jcontext) { pa_context *c = get_context_ptr(jenv, jcontext); pa_threaded_mainloop *m = get_mainloop_ptr(jenv, jcontext); LOGE("Subscribing, pulse state %d", pa_context_get_state(c)); LOGE("Subscribing, pulse state %d", pa_context_get_state(c)); LOGE("Subscribing, pulse state %d", pa_context_get_state(c)); pa_threaded_mainloop_lock(m); pa_operation *o; o = pa_context_subscribe(c, PA_SUBSCRIPTION_MASK_ALL, NULL, NULL); assert(o); pa_operation_unref(o); pa_threaded_mainloop_unlock(m); }
static int tsmf_pulse_play(ITSMFAudioDevice * audio, uint8 * data, uint32 data_size) { TSMFPulseAudioDevice * pulse = (TSMFPulseAudioDevice *) audio; uint8 * src; int len; int ret; LLOGLN(10, ("tsmf_pulse_play: data_size %d", data_size)); if (pulse->stream) { pa_threaded_mainloop_lock(pulse->mainloop); src = data; while (data_size > 0) { while ((len = pa_stream_writable_size(pulse->stream)) == 0) { LLOGLN(10, ("tsmf_pulse_play: waiting")); pa_threaded_mainloop_wait(pulse->mainloop); } if (len < 0) break; if (len > data_size) len = data_size; ret = pa_stream_write(pulse->stream, src, len, NULL, 0LL, PA_SEEK_RELATIVE); if (ret < 0) { LLOGLN(0, ("tsmf_pulse_play: pa_stream_write failed (%d)", pa_context_errno(pulse->context))); break; } src += len; data_size -= len; } pa_threaded_mainloop_unlock(pulse->mainloop); } free(data); return 0; }
/* * Create a new pulseaudio context */ static pa_context *pulse_context_create(pa_threaded_mainloop *m) { pa_context *c; pa_proplist *p; p = pa_proplist_new(); pa_proplist_sets(p, PA_PROP_APPLICATION_NAME, "OBS Studio"); pa_proplist_sets(p, PA_PROP_APPLICATION_ICON_NAME, "application-exit"); pa_proplist_sets(p, PA_PROP_MEDIA_ROLE, "production"); pa_threaded_mainloop_lock(m); c = pa_context_new_with_proplist(pa_threaded_mainloop_get_api(m), "OBS Studio", p); pa_threaded_mainloop_unlock(m); pa_proplist_free(p); return c; }
int sa_stream_get_position(sa_stream_t *s, sa_position_t position, int64_t *pos) { pa_usec_t usec; if (s == NULL || s->stream == NULL) { return SA_ERROR_NO_INIT; } if (position != SA_POSITION_WRITE_SOFTWARE) { return SA_ERROR_NOT_SUPPORTED; } pa_threaded_mainloop_lock(s->m); if(pa_stream_get_time(s->stream, &usec) != PA_ERR_NODATA) { *pos = pa_usec_to_bytes(usec, &s->sample_spec); } else { *pos = s->bytes_written; } pa_threaded_mainloop_unlock(s->m); return SA_SUCCESS; }
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; } //}}}
void SoundFeedStreamData (unsigned char *pSound, long lBytes) { int error_code; int size; if (device.mainloop != NULL) { pa_threaded_mainloop_lock (device.mainloop); if (pa_stream_write (device.stream, pSound, lBytes, NULL, 0LL, PA_SEEK_RELATIVE) < 0) { fprintf (stderr, "Could not perform write\n"); } else { //fprintf (stderr, "Wrote %d bytes\n", lBytes); pa_threaded_mainloop_unlock (device.mainloop); } } }
static int pulse_free(void) { size_t l = 0; pa_operation *o = NULL; CHECK_CONNECTED(0); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 1); if ((l = pa_stream_writable_size(stream)) == (size_t) -1) { AUDDBG("pa_stream_writable_size() failed: %s", pa_strerror(pa_context_errno(context))); l = 0; goto fail; } /* If this function is called twice with no pulse_write() call in * between this means we should trigger the playback */ if (do_trigger) { int success = 0; if (!(o = pa_stream_trigger(stream, stream_success_cb, &success))) { AUDDBG("pa_stream_trigger() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail, 1); pa_threaded_mainloop_wait(mainloop); } if (!success) AUDDBG("pa_stream_trigger() failed: %s", pa_strerror(pa_context_errno(context))); } fail: if (o) pa_operation_unref(o); pa_threaded_mainloop_unlock(mainloop); do_trigger = !!l; return (int) l; }
void CPulseAE::EnumerateOutputDevices(AEDeviceList &devices, bool passthrough) { if (!m_MainLoop || ! m_Context) return; pa_threaded_mainloop_lock(m_MainLoop); SinkInfoStruct sinkStruct; sinkStruct.passthrough = passthrough; sinkStruct.mainloop = m_MainLoop; sinkStruct.list = &devices; CStdString def; def.Format("%s (PulseAudio)",g_localizeStrings.Get(409).c_str()); devices.push_back(AEDevice(def, "pulse:default@default")); WaitForOperation(pa_context_get_sink_info_list(m_Context, SinkInfo, &sinkStruct), m_MainLoop, "EnumerateAudioSinks"); pa_threaded_mainloop_unlock(m_MainLoop); }