void Context::connectToDaemon() { Q_ASSERT(m_context == nullptr); // We require a glib event loop if (!QByteArray(QAbstractEventDispatcher::instance()->metaObject()->className()).contains("EventDispatcherGlib")) { qCWarning(PLASMAPA) << "Disabling PulseAudio integration for lack of GLib event loop"; return; } qCDebug(PLASMAPA) << "Attempting connection to PulseAudio sound daemon"; if (!m_mainloop) { m_mainloop = pa_glib_mainloop_new(nullptr); Q_ASSERT(m_mainloop); } pa_mainloop_api *api = pa_glib_mainloop_get_api(m_mainloop); Q_ASSERT(api); m_context = pa_context_new(api, "QPulse"); Q_ASSERT(m_context); if (pa_context_connect(m_context, NULL, PA_CONTEXT_NOFAIL, nullptr) < 0) { pa_context_unref(m_context); pa_glib_mainloop_free(m_mainloop); m_context = nullptr; m_mainloop = nullptr; return; } pa_context_set_state_callback(m_context, &context_state_callback, this); }
void swfdec_playback_close (SwfdecPlayback *sound) { pa_operation *op; #define REMOVE_HANDLER_FULL(obj,func,data,count) G_STMT_START {\ if (g_signal_handlers_disconnect_by_func ((obj), \ G_CALLBACK (func), (data)) != (count)) { \ g_assert_not_reached (); \ } \ } G_STMT_END #define REMOVE_HANDLER(obj,func,data) REMOVE_HANDLER_FULL (obj, func, data, 1) while (sound->streams) swfdec_playback_stream_close (sound->streams->data); REMOVE_HANDLER (sound->player, advance_before, sound); REMOVE_HANDLER (sound->player, audio_added, sound); REMOVE_HANDLER (sound->player, audio_removed, sound); if (sound->pa != NULL) { op = pa_context_drain (sound->pa, context_drain_complete, NULL); if (op == NULL) { pa_context_disconnect (sound->pa); pa_context_unref (sound->pa); } else { pa_operation_unref (op); } pa_glib_mainloop_free (sound->pa_mainloop); } g_main_context_unref (sound->context); g_free (sound); }
int main(int argc, char *argv[]) { GtkWidget *window; gtk_init(&argc, &argv); g_set_application_name("This is a test"); gtk_window_set_default_icon_name("foobar"); g_setenv("PULSE_PROP_media.role", "phone", TRUE); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW (window), g_get_application_name()); gtk_widget_show_all(window); m = pa_glib_mainloop_new(NULL); g_assert(m); connect(); gtk_main(); pa_context_unref(ctxt); pa_glib_mainloop_free(m); return 0; }
gboolean PulseSrc::quit_pulse(void* user_data) { PulseSrc* context = static_cast<PulseSrc*>(user_data); pa_context_disconnect(context->pa_context_); // pa_context_unref (context->pa_context_); // context->pa_context_ = nullptr; pa_glib_mainloop_free(context->pa_glib_mainloop_); std::unique_lock<std::mutex> lock(context->quit_mutex_); context->quit_cond_.notify_all(); return FALSE; }
/* This finalizer is called if we are shutting down cleanly */ void pulse_finalize_audio() { #ifdef USE_GLIB_MAINLOOP pa_glib_mainloop_free (pulse.loop); #else pa_threaded_mainloop_free(pulse.loop); #endif pulse.finalize = TRUE; g_debug("PulseAudio finalization complete"); }
void eventd_sound_pulseaudio_uninit(EventdSoundPulseaudioContext *context) { if ( context == NULL ) return; pa_context_unref(context->context); pa_glib_mainloop_free(context->pa_loop); g_free(context); }
static gboolean free_pa_context(AudioListContext *context) { pa_context_disconnect(context->pa_context); pa_context_unref(context->pa_context); pa_glib_mainloop_free(context->mainloop); g_slice_free(AudioListContext, context); return FALSE; }
void xvd_close_pulse (XvdInstance *i) { if (i->pulse_context) { pa_context_unref (i->pulse_context); i->pulse_context = NULL; } pa_glib_mainloop_free (i->pa_main_loop); i->pa_main_loop = NULL; }
int main(int argc, char *argv[]) { pa_mainloop_api *a; pa_io_event *ioe; pa_time_event *te; struct timeval tv; #ifdef GLIB_MAIN_LOOP pa_glib_mainloop *g; glib_main_loop = g_main_loop_new(NULL, FALSE); assert(glib_main_loop); g = pa_glib_mainloop_new(NULL); assert(g); a = pa_glib_mainloop_get_api(g); assert(a); #else /* GLIB_MAIN_LOOP */ pa_mainloop *m; m = pa_mainloop_new(); assert(m); a = pa_mainloop_get_api(m); assert(a); #endif /* GLIB_MAIN_LOOP */ ioe = a->io_new(a, 0, PA_IO_EVENT_INPUT, iocb, NULL); assert(ioe); de = a->defer_new(a, dcb, NULL); assert(de); te = a->time_new(a, pa_timeval_rtstore(&tv, pa_rtclock_now() + 2 * PA_USEC_PER_SEC, TRUE), tcb, NULL); #if defined(GLIB_MAIN_LOOP) g_main_loop_run(glib_main_loop); #else pa_mainloop_run(m, NULL); #endif a->time_free(te); a->defer_free(de); a->io_free(ioe); #ifdef GLIB_MAIN_LOOP pa_glib_mainloop_free(g); g_main_loop_unref(glib_main_loop); #else pa_mainloop_free(m); #endif return 0; }
Context::~Context() { if (m_context) { pa_context_unref(m_context); m_context = nullptr; } if (m_mainloop) { pa_glib_mainloop_free(m_mainloop); m_mainloop = nullptr; } reset(); }
void ausrv_destroy(struct ausrv *ausrv) { if (ausrv != NULL) { stream_kill_all(ausrv); if (ausrv->context != NULL) pa_context_unref(ausrv->context); if (ausrv->mainloop != NULL) pa_glib_mainloop_free(ausrv->mainloop); free(ausrv->server); free(ausrv); } }
struct ausrv *ausrv_create(struct tonegend *tonegend, char *server) { pa_glib_mainloop *mainloop = NULL; struct ausrv *ausrv; pa_mainloop_api *mainloop_api; if ((ausrv = malloc(sizeof(*ausrv))) == NULL) { LOG_ERROR("%s(): Can't allocate memory", __FUNCTION__); goto failed; } if ((mainloop = pa_glib_mainloop_new(NULL)) == NULL) { LOG_ERROR("%s(): pa_glib_mainloop_new() failed", __FUNCTION__); goto failed; } mainloop_api = pa_glib_mainloop_get_api(mainloop); if (pa_signal_init(mainloop_api) < 0) { LOG_ERROR("%s(): pa_signal_init() failed", __FUNCTION__); goto failed; } memset(ausrv, 0, sizeof(*ausrv)); ausrv->tonegend = tonegend; ausrv->server = strdup(server ? server : DEFAULT_SERVER); ausrv->mainloop = mainloop; connect_server(ausrv); return ausrv; failed: if (mainloop != NULL) pa_glib_mainloop_free(mainloop); if (ausrv != NULL) free(ausrv); return NULL; }
EventdSoundPulseaudioContext * eventd_sound_pulseaudio_init() { EventdSoundPulseaudioContext *context; context = g_new0(EventdSoundPulseaudioContext, 1); context->pa_loop = pa_glib_mainloop_new(NULL); context->context = pa_context_new(pa_glib_mainloop_get_api(context->pa_loop), PACKAGE_NAME " sndfile plugin"); if ( context->context == NULL ) { g_warning("Couldn't open sound system"); pa_glib_mainloop_free(context->pa_loop); g_free(context); return NULL; } pa_context_set_state_callback(context->context, _eventd_sound_pulseaudio_context_state_callback, NULL); return context; }
static gboolean enumerate_audio_source_devices(GClosure *callback) { AudioListContext *context; context = g_slice_new0(AudioListContext); context->callback = callback; context->mainloop = pa_glib_mainloop_new(_owr_get_main_context()); if (!context->mainloop) { g_warning("PulseAudio: failed to create glib mainloop"); goto cleanup; } context->pa_context = pa_context_new(pa_glib_mainloop_get_api(context->mainloop), "Owr"); if (!context->pa_context) { g_warning("PulseAudio: failed to create context"); goto cleanup_mainloop; } pa_context_set_state_callback(context->pa_context, (pa_context_notify_cb_t) on_pulse_context_state_change, context); pa_context_connect(context->pa_context, NULL, 0, NULL); done: return FALSE; cleanup_mainloop: pa_glib_mainloop_free(context->mainloop); cleanup: finish_pa_list(context); goto done; }
int main(int argc, char **argv) { pa_glib_mainloop *mainloop; pa_mainloop_api *mainloop_api; pa_context *context; GdkWindow *root; int status = EXIT_SUCCESS; int i; gtk_init(&argc, &argv); mainloop = pa_glib_mainloop_new(NULL); if (!mainloop) { fprintf(stderr, "pa_glib_mainloop_new() failed\n"); status = EXIT_FAILURE; goto out; } mainloop_api = pa_glib_mainloop_get_api(mainloop); if (pa_signal_init(mainloop_api) < 0) { fprintf(stderr, "pa_signal_init() failed\n"); status = EXIT_FAILURE; goto mainloop_free; } pa_signal_new(SIGINT, exit_signal_callback, NULL); pa_signal_new(SIGTERM, exit_signal_callback, NULL); context = pa_context_new(mainloop_api, NULL); if (!context) { fprintf(stderr, "pa_context_new() failed\n"); status = EXIT_FAILURE; goto mainloop_free; } pa_context_set_state_callback(context, context_state_callback, NULL); if (pa_context_connect(context, NULL, 0, NULL) < 0) { fprintf(stderr, "pa_context_connect() failed: %s\n", pa_strerror(pa_context_errno(context))); status = EXIT_FAILURE; goto context_unref; } if (!notify_init(APP_NAME)) { fprintf(stderr, "Could not initialize libnotify\n"); status = EXIT_FAILURE; goto context_unref; } notification = notify_notification_new(APP_NAME, NULL, NULL); if (!notification) { fprintf(stderr, "notify_notification_new() failed\n"); status = EXIT_FAILURE; goto notify_uninit; } notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT); notify_notification_set_hint_string(notification, "synchronous", "volume"); root = gdk_get_default_root_window(); gdk_window_set_events(root, GDK_KEY_PRESS_MASK); gdk_window_add_filter(root, filter, context); for (i = 0; i < sizeof(keysyms) / sizeof(keysyms[0]); i++) { keycodes[i] = XKeysymToKeycode(GDK_WINDOW_XDISPLAY(root), keysyms[i]); if (!keycodes[i]) { fprintf(stderr, "%s is not mapped on this keyboard\n", XKeysymToString(keysyms[i])); continue; } XGrabKey(GDK_WINDOW_XDISPLAY(root), keycodes[i], AnyModifier, GDK_WINDOW_XID(root), False, GrabModeAsync, GrabModeAsync); } gtk_main(); g_object_unref(G_OBJECT(notification)); notify_uninit: notify_uninit(); context_unref: pa_context_unref(context); mainloop_free: pa_glib_mainloop_free(mainloop); out: return status; }
struct audio_service* audio_service_create() { struct audio_service *service; LSError error; pa_mainloop_api *mainloop_api; char name[100]; service = g_try_new0(struct audio_service, 1); if (!service) return NULL; LSErrorInit(&error); if (!LSRegisterPubPriv("org.webosports.audio", &service->handle, false, &error)) { g_warning("Failed to register the luna service: %s", error.message); LSErrorFree(&error); goto error; } if (!LSRegisterCategory(service->handle, "/", audio_service_methods, NULL, NULL, &error)) { g_warning("Could not register service category: %s", error.message); LSErrorFree(&error); goto error; } if (!LSCategorySetData(service->handle, "/", service, &error)) { g_warning("Could not set daa for service category: %s", error.message); LSErrorFree(&error); goto error; } if (!LSGmainAttach(service->handle, event_loop, &error)) { g_warning("Could not attach service handle to mainloop: %s", error.message); LSErrorFree(&error); goto error; } service->pa_mainloop = pa_glib_mainloop_new(g_main_context_default()); mainloop_api = pa_glib_mainloop_get_api(service->pa_mainloop); snprintf(name, 100, "AudioServiceContext:%i", getpid()); service->context = pa_context_new(mainloop_api, name); service->context_initialized = false; pa_context_set_state_callback(service->context, context_state_cb, service); if (pa_context_connect(service->context, NULL, 0, NULL) < 0) { g_warning("Failed to connect to PulseAudio"); pa_context_unref(service->context); pa_glib_mainloop_free(service->pa_mainloop); goto error; } sample_list = g_slist_alloc(); return service; error: if (service->handle != NULL) { LSUnregister(service->handle, &error); LSErrorFree(&error); } g_free(service); return NULL; }