void QPulseAudioEngine::updateDevices() { lock(); // Get default input and output devices pa_operation *operation = pa_context_get_server_info(m_context, serverInfoCallback, this); while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) pa_threaded_mainloop_wait(m_mainLoop); pa_operation_unref(operation); // Get output devices operation = pa_context_get_sink_info_list(m_context, sinkInfoCallback, this); while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) pa_threaded_mainloop_wait(m_mainLoop); pa_operation_unref(operation); // Get input devices operation = pa_context_get_source_info_list(m_context, sourceInfoCallback, this); while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) pa_threaded_mainloop_wait(m_mainLoop); pa_operation_unref(operation); unlock(); // Swap the default output to index 0 m_sinks.removeOne(m_defaultSink); m_sinks.prepend(m_defaultSink); // Swap the default input to index 0 m_sources.removeOne(m_defaultSource); m_sources.prepend(m_defaultSource); }
/***************************************************************************** * Close: close the audio device *****************************************************************************/ static void Close ( vlc_object_t *p_this ) { aout_instance_t *p_aout = (aout_instance_t *)p_this; struct aout_sys_t * p_sys = p_aout->output.p_sys; msg_Dbg(p_aout, "Pulse Close"); if(p_sys->stream) { pa_threaded_mainloop_lock(p_sys->mainloop); pa_stream_set_write_callback(p_sys->stream, NULL, NULL); pa_operation *o; o = pa_stream_flush(p_sys->stream, success_cb, p_aout); while( pa_operation_get_state(o) == PA_OPERATION_RUNNING ) pa_threaded_mainloop_wait(p_sys->mainloop); pa_operation_unref(o); o = pa_stream_drain(p_sys->stream, success_cb, p_aout); while( pa_operation_get_state(o) == PA_OPERATION_RUNNING ) pa_threaded_mainloop_wait(p_sys->mainloop); pa_operation_unref(o); pa_threaded_mainloop_unlock(p_sys->mainloop); } uninit(p_aout); }
static PyObject* PulseAudio_set_volume(output_PulseAudio *self, PyObject *args) { pa_cvolume cvolume; pa_operation *op; struct get_volume_cb_data cb_data = {self->mainloop, &cvolume}; double new_volume_d; pa_volume_t new_volume; if (!PyArg_ParseTuple(args, "d", &new_volume_d)) return NULL; /*ensure output stream is still running*/ /*FIXME*/ /*convert volume to integer pa_volume_t value between PA_VOLUME_MUTED and PA_VOLUME_NORM*/ new_volume = round(new_volume_d * PA_VOLUME_NORM); pa_threaded_mainloop_lock(self->mainloop); /*query stream info for current sink*/ op = pa_context_get_sink_info_by_index( self->context, pa_stream_get_device_index(self->stream), (pa_sink_info_cb_t)get_volume_callback, &cb_data); /*wait for callback to complete*/ while (pa_operation_get_state(op) == PA_OPERATION_RUNNING) { pa_threaded_mainloop_wait(self->mainloop); } pa_operation_unref(op); /*scale values using the new volume setting*/ pa_cvolume_scale(&cvolume, new_volume); /*set sink's volume values*/ op = pa_context_set_sink_volume_by_index( self->context, pa_stream_get_device_index(self->stream), &cvolume, (pa_context_success_cb_t)set_volume_callback, self->mainloop); /*wait for callback to complete*/ while (pa_operation_get_state(op) == PA_OPERATION_RUNNING) { pa_threaded_mainloop_wait(self->mainloop); } pa_operation_unref(op); pa_threaded_mainloop_unlock(self->mainloop); Py_INCREF(Py_None); return Py_None; }
/** * \brief waits for a pulseaudio operation to finish, frees it and * unlocks the mainloop * \param op operation to wait for * \return 1 if operation has finished normally (DONE state), 0 otherwise */ static int waitop(struct priv *priv, pa_operation *op) { if (!op) { pa_threaded_mainloop_unlock(priv->mainloop); return 0; } pa_operation_state_t state = pa_operation_get_state(op); while (state == PA_OPERATION_RUNNING) { pa_threaded_mainloop_wait(priv->mainloop); state = pa_operation_get_state(op); } pa_operation_unref(op); pa_threaded_mainloop_unlock(priv->mainloop); return state == PA_OPERATION_DONE; }
/** * Synchronously wait until an operation completed. */ static int paWaitForEx(PDRVHOSTPULSEAUDIO pThis, pa_operation *pOP, RTMSINTERVAL cMsTimeout) { AssertPtrReturn(pThis, VERR_INVALID_POINTER); AssertPtrReturn(pOP, VERR_INVALID_POINTER); int rc = VINF_SUCCESS; uint64_t u64StartMs = RTTimeMilliTS(); while (pa_operation_get_state(pOP) == PA_OPERATION_RUNNING) { if (!pThis->fLoopWait) { AssertPtr(pThis->pMainLoop); pa_threaded_mainloop_wait(pThis->pMainLoop); } pThis->fLoopWait = false; uint64_t u64ElapsedMs = RTTimeMilliTS() - u64StartMs; if (u64ElapsedMs >= cMsTimeout) { rc = VERR_TIMEOUT; break; } } pa_operation_unref(pOP); return rc; }
static gboolean play_timeout (MokoNotify *notify) { MokoNotifyPrivate *priv; g_return_val_if_fail (MOKO_IS_NOTIFY (notify), FALSE); priv = notify->priv; if (!priv->pac) return FALSE; if (!priv->operation) { g_debug ("No operation"); return FALSE; } if (!priv->started) { pa_operation_cancel (priv->operation); g_debug ("Cancelling early"); return FALSE; } if (pa_operation_get_state (priv->operation) == PA_OPERATION_DONE) { g_timeout_add (1500, (GSourceFunc)play, (gpointer)notify); g_debug ("Playing done"); return FALSE; } g_debug ("Not finshed yet"); return TRUE; }
int pa_simple_cork(pa_simple *p, int cork, int *rerror) { pa_operation *o = NULL; pa_assert(p); pa_threaded_mainloop_lock(p->mainloop); CHECK_DEAD_GOTO(p, rerror, unlock_and_fail); o = pa_stream_cork(p->stream, cork, success_context_cb, p); CHECK_SUCCESS_GOTO(p, rerror, o, unlock_and_fail); p->operation_success = 0; while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) { pa_threaded_mainloop_wait(p->mainloop); CHECK_DEAD_GOTO(p, rerror, unlock_and_fail); } CHECK_SUCCESS_GOTO(p, rerror, p->operation_success, unlock_and_fail); pa_operation_unref(o); pa_threaded_mainloop_unlock(p->mainloop); return 0; unlock_and_fail: if (o) { pa_operation_cancel(o); pa_operation_unref(o); } pa_threaded_mainloop_unlock(p->mainloop); return -1; }
int pa_simple_flush(pa_simple *p, int *rerror) { pa_operation *o = NULL; pa_assert(p); CHECK_VALIDITY_RETURN_ANY(rerror, p->direction == PA_STREAM_PLAYBACK, PA_ERR_BADSTATE, -1); pa_threaded_mainloop_lock(p->mainloop); CHECK_DEAD_GOTO(p, rerror, unlock_and_fail); o = pa_stream_flush(p->stream, success_cb, p); CHECK_SUCCESS_GOTO(p, rerror, o, unlock_and_fail); p->operation_success = 0; while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) { pa_threaded_mainloop_wait(p->mainloop); CHECK_DEAD_GOTO(p, rerror, unlock_and_fail); } CHECK_SUCCESS_GOTO(p, rerror, p->operation_success, unlock_and_fail); pa_operation_unref(o); pa_threaded_mainloop_unlock(p->mainloop); return 0; unlock_and_fail: if (o) { pa_operation_cancel(o); pa_operation_unref(o); } pa_threaded_mainloop_unlock(p->mainloop); return -1; }
static PyObject* PulseAudio_resume(output_PulseAudio *self, PyObject *args) { /*ensure output stream is still running*/ /*FIXME*/ /*uncork output stream, if corked*/ pa_threaded_mainloop_lock(self->mainloop); if (pa_stream_is_corked(self->stream)) { pa_operation *op = pa_stream_cork( self->stream, 0, (pa_stream_success_cb_t)success_callback, self->mainloop); while (pa_operation_get_state(op) == PA_OPERATION_RUNNING) { pa_threaded_mainloop_wait(self->mainloop); } pa_operation_unref(op); } pa_threaded_mainloop_unlock(self->mainloop); Py_INCREF(Py_None); return Py_None; }
/* * 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); }
bool PulseSubscription::run() { pa_context *context = getContext(); pa_operation *operation; mainLoopLock(); // Must assume only one subscription will be alive. Can fix this if needed one day. pa_context_set_subscribe_callback(context, _subscribe_callback, this); m_triggered = 0; operation = pa_context_subscribe(context, (pa_subscription_mask_t)( PA_SUBSCRIPTION_MASK_SOURCE | PA_SUBSCRIPTION_MASK_SINK | PA_SUBSCRIPTION_MASK_MODULE), NULL, NULL); while(pa_operation_get_state(operation) != PA_OPERATION_CANCELLED){ mainLoopWait(); if(m_triggered){ fireEvent(); m_triggered = 0; } } pa_operation_unref(operation); mainLoopUnlock(); return true; }
/***************************************************************************** * Close: close the audio device *****************************************************************************/ static void Close ( vlc_object_t *p_this ) { aout_instance_t *p_aout = (aout_instance_t *)p_this; struct aout_sys_t * p_sys = p_aout->output.p_sys; msg_Dbg(p_aout, "Pulse Close"); if(p_sys->stream){ pa_operation *o; pa_threaded_mainloop_lock(p_sys->mainloop); pa_stream_set_write_callback(p_sys->stream, NULL, NULL); if((o = pa_stream_drain(p_sys->stream, success_cb, p_aout))){ while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail); pa_threaded_mainloop_wait(p_sys->mainloop); } fail: pa_operation_unref(o); } pa_threaded_mainloop_unlock(p_sys->mainloop); } uninit(p_aout); }
/** * Synchronously wait until an operation completed. */ static int drvHostPulseAudioWaitFor(pa_operation *pOP, RTMSINTERVAL cMsTimeout) { AssertPtrReturn(pOP, VERR_INVALID_POINTER); int rc = VINF_SUCCESS; if (pOP) { uint64_t u64StartMs = RTTimeMilliTS(); while (pa_operation_get_state(pOP) == PA_OPERATION_RUNNING) { if (!g_fAbortMainLoop) pa_threaded_mainloop_wait(g_pMainLoop); g_fAbortMainLoop = false; uint64_t u64ElapsedMs = RTTimeMilliTS() - u64StartMs; if (u64ElapsedMs >= cMsTimeout) { rc = VERR_TIMEOUT; break; } } pa_operation_unref(pOP); } return rc; }
int xmms_pulse_backend_volume_get (xmms_pulse *p, unsigned int *vol) { pa_operation *o; int idx; if (p == NULL) { return FALSE; } pa_threaded_mainloop_lock (p->mainloop); *vol = -1; if (p->stream != NULL) { idx = pa_stream_get_index (p->stream); o = pa_context_get_sink_input_info (p->context, idx, volume_get_cb, vol); if (o) { while (pa_operation_get_state (o) != PA_OPERATION_DONE) { pa_threaded_mainloop_wait (p->mainloop); } pa_operation_unref (o); } } pa_threaded_mainloop_unlock (p->mainloop); return *vol != -1; }
static void pulse_flush(int time) { pa_operation *o = NULL; int success = 0; CHECK_CONNECTED(); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 1); written = time * (int64_t) bytes_per_second / 1000; flush_time = time; if (!(o = pa_stream_flush(stream, stream_success_cb, &success))) { AUDDBG("pa_stream_flush() 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_flush() failed: %s", pa_strerror(pa_context_errno(context))); fail: if (o) pa_operation_unref(o); pa_threaded_mainloop_unlock(mainloop); }
static void pulse_drain(void) { pa_operation *o = NULL; int success = 0; CHECK_CONNECTED(); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 0); if (!(o = pa_stream_drain(stream, stream_success_cb, &success))) { AUDDBG("pa_stream_drain() 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_drain() failed: %s", pa_strerror(pa_context_errno(context))); fail: if (o) pa_operation_unref(o); pa_threaded_mainloop_unlock(mainloop); }
static int pa_get_devicelist(AudioDeviceInfoList& input) { pa_mainloop *pa_ml; pa_mainloop_api *pa_mlapi; pa_operation *pa_op; pa_context *pa_ctx; int state = 0; int pa_ready = 0; pa_ml = pa_mainloop_new(); pa_mlapi = pa_mainloop_get_api(pa_ml); pa_ctx = pa_context_new(pa_mlapi, "USBqemu-devicelist"); pa_context_connect(pa_ctx, NULL, PA_CONTEXT_NOFLAGS, NULL); pa_context_set_state_callback(pa_ctx, pa_context_state_cb, &pa_ready); for (;;) { if (pa_ready == 0) { pa_mainloop_iterate(pa_ml, 1, NULL); continue; } // Connection failed if (pa_ready == 2) { pa_context_disconnect(pa_ctx); pa_context_unref(pa_ctx); pa_mainloop_free(pa_ml); return -1; } switch (state) { case 0: pa_op = pa_context_get_source_info_list(pa_ctx, pa_sourcelist_cb, &input); state++; break; case 1: if (pa_operation_get_state(pa_op) == PA_OPERATION_DONE) { pa_operation_unref(pa_op); pa_context_disconnect(pa_ctx); pa_context_unref(pa_ctx); pa_mainloop_free(pa_ml); return 0; } break; default: return -1; } pa_mainloop_iterate(pa_ml, 1, NULL); } }
/** Wait until the specified operation completes */ static void wait_for_operation(struct pa_operation *o) { assert(o && context && mainloop); while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) pa_mainloop_iterate(mainloop, 1, NULL); pa_operation_unref(o); }
void PulseOutput::drain() { if (stream) { pa_operation * operation = pa_stream_drain(stream,nullptr,nullptr); while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) context->wait_plugin_events(); pa_operation_unref(operation); } }
static void tsmf_pulse_wait_for_operation(TSMFPulseAudioDevice * pulse, pa_operation * operation) { while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) { pa_threaded_mainloop_wait(pulse->mainloop); } pa_operation_unref(operation); }
static void operation_wait(cubeb * ctx, pa_operation * o) { for (;;) { if (pa_operation_get_state(o) != PA_OPERATION_RUNNING) break; pa_threaded_mainloop_wait(ctx->mainloop); } }
static void wait_for_operation(pa_operation *op, pa_threaded_mainloop *loop) { if(op) { while(pa_operation_get_state(op) == PA_OPERATION_RUNNING) pa_threaded_mainloop_wait(loop); pa_operation_unref(op); } }
static gboolean gst_pulsesrc_get_stream_mute (GstPulseSrc * pulsesrc) { pa_operation *o = NULL; gboolean mute; if (!pulsesrc->mainloop) goto no_mainloop; if (pulsesrc->source_output_idx == PA_INVALID_INDEX) goto no_index; pa_threaded_mainloop_lock (pulsesrc->mainloop); if (!(o = pa_context_get_source_output_info (pulsesrc->context, pulsesrc->source_output_idx, gst_pulsesrc_source_output_info_cb, pulsesrc))) goto info_failed; while (pa_operation_get_state (o) == PA_OPERATION_RUNNING) { pa_threaded_mainloop_wait (pulsesrc->mainloop); if (gst_pulsesrc_is_dead (pulsesrc, TRUE)) goto unlock; } unlock: mute = pulsesrc->mute; if (o) pa_operation_unref (o); pa_threaded_mainloop_unlock (pulsesrc->mainloop); return mute; /* ERRORS */ no_mainloop: { mute = pulsesrc->mute; GST_DEBUG_OBJECT (pulsesrc, "we have no mainloop"); return mute; } no_index: { mute = pulsesrc->mute; GST_DEBUG_OBJECT (pulsesrc, "we don't have a stream index"); return mute; } info_failed: { GST_ELEMENT_ERROR (pulsesrc, RESOURCE, FAILED, ("pa_context_get_source_output_info() failed: %s", pa_strerror (pa_context_errno (pulsesrc->context))), (NULL)); goto unlock; } }
static bool WaitForOperation(pa_operation *op, pa_threaded_mainloop *mainloop, const char *LogEntry = "") { if (op == NULL) return false; bool sucess = true; while (pa_operation_get_state(op) == PA_OPERATION_RUNNING) pa_threaded_mainloop_wait(mainloop); if (pa_operation_get_state(op) != PA_OPERATION_DONE) { CLog::Log(LOGERROR, "PulseAudio: %s Operation failed", LogEntry); sucess = false; } pa_operation_unref(op); return sucess; }
static void rdpsnd_pulse_wait_for_operation(rdpsndPulsePlugin* pulse, pa_operation* operation) { if (operation == NULL) return; while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) { pa_threaded_mainloop_wait(pulse->mainloop); } pa_operation_unref(operation); }
/** * \brief waits for a pulseaudio operation to finish, frees it and * unlocks the mainloop * \param operation the operation to wait for * \return true if operation has finished normally (DONE state), * false otherwise */ static bool pulse_wait_for_operation(struct pa_threaded_mainloop *mainloop, struct pa_operation *operation) { pa_operation_state_t state; assert(mainloop != NULL); assert(operation != NULL); state = pa_operation_get_state(operation); while (state == PA_OPERATION_RUNNING) { pa_threaded_mainloop_wait(mainloop); state = pa_operation_get_state(operation); } pa_operation_unref(operation); return state == PA_OPERATION_DONE; }
static void pulse_stop_capture(ALCdevice *device) //{{{ { pulse_data *data = device->ExtraData; pa_operation *o; pa_threaded_mainloop_lock(data->loop); o = pa_stream_cork(data->stream, 1, stream_success_callback, device); while(pa_operation_get_state(o) == PA_OPERATION_RUNNING) pa_threaded_mainloop_wait(data->loop); pa_operation_unref(o); pa_threaded_mainloop_unlock(data->loop); } //}}}
static int pulse_free(void) { ENTER(__FUNCTION__); size_t l = 0; pa_operation *o = NULL; CHECK_CONNECTED(0); SHOW("pulse_free: %s (call)\n", "pa_threaded_main_loop_lock"); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 1); if ((l = pa_stream_writable_size(stream)) == (size_t) -1) { SHOW("pa_stream_writable_size() failed: %s", pa_strerror(pa_context_errno(context))); l = 0; goto fail; } SHOW("pulse_free: %s (ret=%d)\n", "pa_stream_writable_size", l); /* 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; SHOW("pulse_free: %s (call)\n", "pa_stream_trigger"); if (!(o = pa_stream_trigger(stream, stream_success_cb, &success))) { SHOW("pa_stream_trigger() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } SHOW("pulse_free: %s (call)\n", "pa_threaded_main_loop"); while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail, 1); pa_threaded_mainloop_wait(mainloop); } SHOW("pulse_free: %s (ret)\n", "pa_threaded_main_loop"); if (!success) SHOW("pa_stream_trigger() failed: %s", pa_strerror(pa_context_errno(context))); } fail: SHOW("pulse_free: %s (call)\n", "pa_operation_unref"); if (o) pa_operation_unref(o); SHOW("pulse_free: %s (call)\n", "pa_threaded_main_loop_unlock"); pa_threaded_mainloop_unlock(mainloop); do_trigger = !!l; SHOW("pulse_free: %d (ret)\n", (int)l); return (int) l; }
static void rdpsnd_pulse_wait_for_operation(rdpsndDevicePlugin * devplugin, pa_operation * operation) { struct pulse_device_data * pulse_data; pulse_data = (struct pulse_device_data *) devplugin->device_data; while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) { pa_threaded_mainloop_wait(pulse_data->mainloop); } pa_operation_unref(operation); }
int pa_get_devicelist(pa_devicelist_t *output) { pa_mainloop *pa_ml = NULL; pa_mainloop_api *pa_mlapi = NULL; pa_operation *pa_op = NULL; pa_context *pa_ctx = NULL; uint8_t state = 0; int pa_ready = 0; memset(output, 0, sizeof(pa_devicelist_t) * 16); if ( (pa_ml = pa_mainloop_new()) == NULL) return -1; if ( (pa_mlapi = pa_mainloop_get_api(pa_ml)) == NULL ) return -2; if ( (pa_ctx = pa_context_new(pa_mlapi, "test")) == NULL) return -3; pa_context_connect(pa_ctx, NULL, 0, NULL); pa_context_set_state_callback(pa_ctx, pa_state_cb, &pa_ready); while (1) { if (pa_ready == 0) { pa_mainloop_iterate(pa_ml, 1, NULL); continue; } if (pa_ready == 2) { pa_context_disconnect(pa_ctx); pa_context_unref(pa_ctx); pa_mainloop_free(pa_ml); return -1; } switch (state) { case 0: pa_op = pa_context_get_sink_info_list(pa_ctx, pa_sinklist_cb, output); state++; break; case 1: if (pa_operation_get_state(pa_op) == PA_OPERATION_DONE) { pa_operation_unref(pa_op); pa_context_disconnect(pa_ctx); pa_context_unref(pa_ctx); pa_mainloop_free(pa_ml); return 0; } break; default: return -1; } pa_mainloop_iterate(pa_ml, 1, NULL); } }