Browse Source

Merge the error labels in pulse_open to simplify the logic.

master
Reece H. Dunn 9 years ago
parent
commit
2000c20212
1 changed files with 11 additions and 10 deletions
  1. 11
    10
      src/libespeak-ng/wave_pulse.c

+ 11
- 10
src/libespeak-ng/wave_pulse.c View File

pa_threaded_mainloop_lock(mainloop); pa_threaded_mainloop_lock(mainloop);


if (!(context = pa_context_new(pa_threaded_mainloop_get_api(mainloop), "eSpeak"))) if (!(context = pa_context_new(pa_threaded_mainloop_get_api(mainloop), "eSpeak")))
goto unlock_and_fail;
goto fail;


pa_context_set_state_callback(context, context_state_cb, NULL); pa_context_set_state_callback(context, context_state_cb, NULL);
pa_context_set_subscribe_callback(context, subscribe_cb, NULL); pa_context_set_subscribe_callback(context, subscribe_cb, NULL);
if (pa_context_connect(context, NULL, (pa_context_flags_t)0, NULL) < 0) { if (pa_context_connect(context, NULL, (pa_context_flags_t)0, NULL) < 0) {
fprintf(stderr, "Failed to connect to server: %s", pa_strerror(pa_context_errno(context))); fprintf(stderr, "Failed to connect to server: %s", pa_strerror(pa_context_errno(context)));
ret = PULSE_NO_CONNECTION; ret = PULSE_NO_CONNECTION;
goto unlock_and_fail;
goto fail;
} }


if (pa_threaded_mainloop_start(mainloop) < 0) if (pa_threaded_mainloop_start(mainloop) < 0)
goto unlock_and_fail;
goto fail;


// Wait until the context is ready // Wait until the context is ready
pa_threaded_mainloop_wait(mainloop); pa_threaded_mainloop_wait(mainloop);
ret = PULSE_NO_CONNECTION; ret = PULSE_NO_CONNECTION;
if (mainloop) if (mainloop)
pa_threaded_mainloop_stop(mainloop); pa_threaded_mainloop_stop(mainloop);
goto unlock_and_fail;
goto fail;
} }


if (!(stream = pa_stream_new(context, "unknown", &ss, NULL))) { if (!(stream = pa_stream_new(context, "unknown", &ss, NULL))) {
fprintf(stderr, "Failed to create stream: %s", pa_strerror(pa_context_errno(context))); fprintf(stderr, "Failed to create stream: %s", pa_strerror(pa_context_errno(context)));
goto unlock_and_fail;
goto fail;
} }


pa_stream_set_state_callback(stream, stream_state_cb, NULL); pa_stream_set_state_callback(stream, stream_state_cb, NULL);


if (pa_stream_connect_playback(stream, device, &a_attr, (pa_stream_flags_t)(PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE), NULL, NULL) < 0) { if (pa_stream_connect_playback(stream, device, &a_attr, (pa_stream_flags_t)(PA_STREAM_INTERPOLATE_TIMING|PA_STREAM_AUTO_TIMING_UPDATE), NULL, NULL) < 0) {
fprintf(stderr, "Failed to connect stream: %s", pa_strerror(pa_context_errno(context))); fprintf(stderr, "Failed to connect stream: %s", pa_strerror(pa_context_errno(context)));
goto unlock_and_fail;
goto fail;
} }


// Wait until the stream is ready // Wait until the stream is ready


if (pa_stream_get_state(stream) != PA_STREAM_READY) { if (pa_stream_get_state(stream) != PA_STREAM_READY) {
fprintf(stderr, "Failed to connect stream: %s", pa_strerror(pa_context_errno(context))); fprintf(stderr, "Failed to connect stream: %s", pa_strerror(pa_context_errno(context)));
goto unlock_and_fail;
goto fail;
} }


// Now subscribe to events // Now subscribe to events
if (!(o = pa_context_subscribe(context, PA_SUBSCRIPTION_MASK_SINK_INPUT, context_success_cb, &success))) { if (!(o = pa_context_subscribe(context, PA_SUBSCRIPTION_MASK_SINK_INPUT, context_success_cb, &success))) {
fprintf(stderr, "pa_context_subscribe() failed: %s", pa_strerror(pa_context_errno(context))); fprintf(stderr, "pa_context_subscribe() failed: %s", pa_strerror(pa_context_errno(context)));
goto unlock_and_fail;
goto fail;
} }


while (pa_operation_get_state(o) != PA_OPERATION_DONE) { while (pa_operation_get_state(o) != PA_OPERATION_DONE) {
pa_threaded_mainloop_unlock(mainloop); pa_threaded_mainloop_unlock(mainloop);


return PULSE_OK; return PULSE_OK;
unlock_and_fail:
pa_threaded_mainloop_unlock(mainloop);
fail: fail:
if (mainloop)
pa_threaded_mainloop_unlock(mainloop);

if (ret == PULSE_NO_CONNECTION) { if (ret == PULSE_NO_CONNECTION) {
if (context) { if (context) {
pa_context_disconnect(context); pa_context_disconnect(context);

Loading…
Cancel
Save