static int pulse_context_init(cubeb * ctx) { if (ctx->context) { assert(ctx->error == 1); pulse_context_destroy(ctx); } ctx->context = WRAP(pa_context_new)(WRAP(pa_threaded_mainloop_get_api)(ctx->mainloop), ctx->context_name); if (!ctx->context) { return -1; } WRAP(pa_context_set_state_callback)(ctx->context, context_state_callback, ctx); WRAP(pa_threaded_mainloop_lock)(ctx->mainloop); WRAP(pa_context_connect)(ctx->context, NULL, 0, NULL); if (wait_until_context_ready(ctx) != 0) { WRAP(pa_threaded_mainloop_unlock)(ctx->mainloop); pulse_context_destroy(ctx); ctx->context = NULL; return -1; } WRAP(pa_threaded_mainloop_unlock)(ctx->mainloop); ctx->error = 0; return 0; }
static void pulse_destroy(cubeb * ctx) { pa_operation * o; if (ctx->context_name) { free(ctx->context_name); } if (ctx->context) { pulse_context_destroy(ctx); } if (ctx->mainloop) { WRAP(pa_threaded_mainloop_stop)(ctx->mainloop); WRAP(pa_threaded_mainloop_free)(ctx->mainloop); } if (ctx->libpulse) { dlclose(ctx->libpulse); } if (ctx->default_sink_info) { free(ctx->default_sink_info); } free(ctx); }