Commit c666cf1c authored by Max Kellermann's avatar Max Kellermann

output/pulse: move code to _setup_stream()

parent 2be245b7
......@@ -496,6 +496,41 @@ pulse_output_stream_write_cb(G_GNUC_UNUSED pa_stream *stream, size_t nbytes,
pa_threaded_mainloop_signal(po->mainloop, 0);
}
/**
* Create, set up and connect a context.
*
* Caller must lock the main loop.
*
* @return true on success, false on error
*/
static bool
pulse_output_setup_stream(struct pulse_output *po, const pa_sample_spec *ss,
GError **error_r)
{
assert(po != NULL);
assert(po->context != NULL);
po->stream = pa_stream_new(po->context, po->name, ss, NULL);
if (po->stream == NULL) {
g_set_error(error_r, pulse_output_quark(), 0,
"pa_stream_new() has failed: %s",
pa_strerror(pa_context_errno(po->context)));
return false;
}
#if PA_CHECK_VERSION(0,9,8)
pa_stream_set_suspended_callback(po->stream,
pulse_output_stream_suspended_cb, po);
#endif
pa_stream_set_state_callback(po->stream,
pulse_output_stream_state_cb, po);
pa_stream_set_write_callback(po->stream,
pulse_output_stream_write_cb, po);
return true;
}
static bool
pulse_output_open(void *data, struct audio_format *audio_format,
GError **error_r)
......@@ -540,25 +575,11 @@ pulse_output_open(void *data, struct audio_format *audio_format,
/* create a stream .. */
po->stream = pa_stream_new(po->context, po->name, &ss, NULL);
if (po->stream == NULL) {
g_set_error(error_r, pulse_output_quark(), 0,
"pa_stream_new() has failed: %s",
pa_strerror(pa_context_errno(po->context)));
if (!pulse_output_setup_stream(po, &ss, error_r)) {
pa_threaded_mainloop_unlock(po->mainloop);
return false;
}
#if PA_CHECK_VERSION(0,9,8)
pa_stream_set_suspended_callback(po->stream,
pulse_output_stream_suspended_cb, po);
#endif
pa_stream_set_state_callback(po->stream,
pulse_output_stream_state_cb, po);
pa_stream_set_write_callback(po->stream,
pulse_output_stream_write_cb, po);
/* .. and connect it (asynchronously) */
error = pa_stream_connect_playback(po->stream, po->sink,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment