+
+ /* Create the random PulseAudio pieces. */
+ loop = pa_threaded_mainloop_new();
+ if(!loop) disorder_fatal(0, "failed to create pulseaudio main loop");
+ pa_threaded_mainloop_lock(loop);
+ ctx = pa_context_new(pa_threaded_mainloop_get_api(loop),
+ uaudio_get("application", "DisOrder"));
+ if(!ctx) disorder_fatal(0, "failed to create pulseaudio context");
+ pa_context_set_state_callback(ctx, cb_ctxstate, 0);
+ if(pa_context_connect(ctx, 0, 0, 0) < 0)
+ disorder_fatal(0, "failed to connect to pulseaudio server: %s",
+ PAERRSTR);
+
+ /* Set the main loop going. */
+ if(pa_threaded_mainloop_start(loop) < 0)
+ disorder_fatal(0, "failed to start pulseaudio main loop");
+ while(pa_context_get_state(ctx) != PA_CONTEXT_READY)
+ pa_threaded_mainloop_wait(loop);
+
+ /* Set up my stream. */
+ str = pa_stream_new(ctx, "DisOrder", &ss, 0);
+ if(!str)
+ disorder_fatal(0, "failed to create pulseaudio stream: %s", PAERRSTR);
+ pa_stream_set_write_callback(str, cb_wakeup, 0);
+ if(pa_stream_connect_playback(str, 0, 0,
+ PA_STREAM_ADJUST_LATENCY,
+ 0, 0))
+ disorder_fatal(0, "failed to connect pulseaudio stream for playback: %s",
+ PAERRSTR);
+ pa_stream_set_state_callback(str, cb_strstate, 0);
+
+ /* Wait until the stream is ready. */
+ while(pa_stream_get_state(str) != PA_STREAM_READY)
+ pa_threaded_mainloop_wait(loop);
+
+ /* All done. */
+ strix = pa_stream_get_index(str);
+ pa_threaded_mainloop_unlock(loop);