Commit b1935d83 authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Vitaly Lipatov

winepulse.drv: Use a separate mainloop and ctx for pulse_test_connect.

parent 36d69d19
...@@ -661,7 +661,8 @@ static void convert_channel_map(const pa_channel_map *pa_map, WAVEFORMATEXTENSIB ...@@ -661,7 +661,8 @@ static void convert_channel_map(const pa_channel_map *pa_map, WAVEFORMATEXTENSIB
fmt->dwChannelMask = pa_mask; fmt->dwChannelMask = pa_mask;
} }
static void pulse_probe_settings(int render, const char *pulse_name, WAVEFORMATEXTENSIBLE *fmt, REFERENCE_TIME *def_period, REFERENCE_TIME *min_period) static void pulse_probe_settings(pa_mainloop *ml, pa_context *ctx, int render, const char *pulse_name,
WAVEFORMATEXTENSIBLE *fmt, REFERENCE_TIME *def_period, REFERENCE_TIME *min_period)
{ {
WAVEFORMATEX *wfx = &fmt->Format; WAVEFORMATEX *wfx = &fmt->Format;
pa_stream *stream; pa_stream *stream;
...@@ -684,7 +685,7 @@ static void pulse_probe_settings(int render, const char *pulse_name, WAVEFORMATE ...@@ -684,7 +685,7 @@ static void pulse_probe_settings(int render, const char *pulse_name, WAVEFORMATE
attr.minreq = attr.fragsize = pa_frame_size(&ss); attr.minreq = attr.fragsize = pa_frame_size(&ss);
attr.prebuf = 0; attr.prebuf = 0;
stream = pa_stream_new(pulse_ctx, "format test stream", &ss, &map); stream = pa_stream_new(ctx, "format test stream", &ss, &map);
if (stream) if (stream)
pa_stream_set_state_callback(stream, pulse_stream_state, NULL); pa_stream_set_state_callback(stream, pulse_stream_state, NULL);
if (!stream) if (!stream)
...@@ -695,7 +696,7 @@ static void pulse_probe_settings(int render, const char *pulse_name, WAVEFORMATE ...@@ -695,7 +696,7 @@ static void pulse_probe_settings(int render, const char *pulse_name, WAVEFORMATE
else else
ret = pa_stream_connect_record(stream, pulse_name, &attr, PA_STREAM_START_CORKED|PA_STREAM_FIX_RATE|PA_STREAM_FIX_CHANNELS|PA_STREAM_EARLY_REQUESTS); ret = pa_stream_connect_record(stream, pulse_name, &attr, PA_STREAM_START_CORKED|PA_STREAM_FIX_RATE|PA_STREAM_FIX_CHANNELS|PA_STREAM_EARLY_REQUESTS);
if (ret >= 0) { if (ret >= 0) {
while (pa_mainloop_iterate(pulse_ml, 1, &ret) >= 0 && while (pa_mainloop_iterate(ml, 1, &ret) >= 0 &&
pa_stream_get_state(stream) == PA_STREAM_CREATING) pa_stream_get_state(stream) == PA_STREAM_CREATING)
{} {}
if (pa_stream_get_state(stream) == PA_STREAM_READY) { if (pa_stream_get_state(stream) == PA_STREAM_READY) {
...@@ -706,7 +707,7 @@ static void pulse_probe_settings(int render, const char *pulse_name, WAVEFORMATE ...@@ -706,7 +707,7 @@ static void pulse_probe_settings(int render, const char *pulse_name, WAVEFORMATE
else else
length = pa_stream_get_buffer_attr(stream)->fragsize; length = pa_stream_get_buffer_attr(stream)->fragsize;
pa_stream_disconnect(stream); pa_stream_disconnect(stream);
while (pa_mainloop_iterate(pulse_ml, 1, &ret) >= 0 && while (pa_mainloop_iterate(ml, 1, &ret) >= 0 &&
pa_stream_get_state(stream) == PA_STREAM_READY) pa_stream_get_state(stream) == PA_STREAM_READY)
{} {}
} }
...@@ -753,31 +754,32 @@ static NTSTATUS pulse_test_connect(void *args) ...@@ -753,31 +754,32 @@ static NTSTATUS pulse_test_connect(void *args)
PhysDevice *dev; PhysDevice *dev;
pa_operation *o; pa_operation *o;
int ret; int ret;
pa_mainloop *ml;
pa_context *ctx;
pulse_lock(); pulse_lock();
pulse_ml = pa_mainloop_new(); ml = pa_mainloop_new();
pa_mainloop_set_poll_func(pulse_ml, pulse_poll_func, NULL); pa_mainloop_set_poll_func(ml, pulse_poll_func, NULL);
pulse_ctx = pa_context_new(pa_mainloop_get_api(pulse_ml), params->name); ctx = pa_context_new(pa_mainloop_get_api(ml), params->name);
if (!pulse_ctx) { if (!ctx) {
ERR("Failed to create context\n"); ERR("Failed to create context\n");
pa_mainloop_free(pulse_ml); pa_mainloop_free(ml);
pulse_ml = NULL;
pulse_unlock(); pulse_unlock();
params->result = E_FAIL; params->result = E_FAIL;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
pa_context_set_state_callback(pulse_ctx, pulse_contextcallback, NULL); pa_context_set_state_callback(ctx, pulse_contextcallback, NULL);
TRACE("libpulse protocol version: %u. API Version %u\n", pa_context_get_protocol_version(pulse_ctx), PA_API_VERSION); TRACE("libpulse protocol version: %u. API Version %u\n", pa_context_get_protocol_version(ctx), PA_API_VERSION);
if (pa_context_connect(pulse_ctx, NULL, 0, NULL) < 0) if (pa_context_connect(ctx, NULL, 0, NULL) < 0)
goto fail; goto fail;
/* Wait for connection */ /* Wait for connection */
while (pa_mainloop_iterate(pulse_ml, 1, &ret) >= 0) { while (pa_mainloop_iterate(ml, 1, &ret) >= 0) {
pa_context_state_t state = pa_context_get_state(pulse_ctx); pa_context_state_t state = pa_context_get_state(ctx);
if (state == PA_CONTEXT_FAILED || state == PA_CONTEXT_TERMINATED) if (state == PA_CONTEXT_FAILED || state == PA_CONTEXT_TERMINATED)
goto fail; goto fail;
...@@ -786,12 +788,12 @@ static NTSTATUS pulse_test_connect(void *args) ...@@ -786,12 +788,12 @@ static NTSTATUS pulse_test_connect(void *args)
break; break;
} }
if (pa_context_get_state(pulse_ctx) != PA_CONTEXT_READY) if (pa_context_get_state(ctx) != PA_CONTEXT_READY)
goto fail; goto fail;
TRACE("Test-connected to server %s with protocol version: %i.\n", TRACE("Test-connected to server %s with protocol version: %i.\n",
pa_context_get_server(pulse_ctx), pa_context_get_server(ctx),
pa_context_get_server_protocol_version(pulse_ctx)); pa_context_get_server_protocol_version(ctx));
free_phys_device_lists(); free_phys_device_lists();
list_init(&g_phys_speakers); list_init(&g_phys_speakers);
...@@ -800,34 +802,32 @@ static NTSTATUS pulse_test_connect(void *args) ...@@ -800,34 +802,32 @@ static NTSTATUS pulse_test_connect(void *args)
pulse_add_device(&g_phys_speakers, NULL, 0, Speakers, 0, "", "PulseAudio"); pulse_add_device(&g_phys_speakers, NULL, 0, Speakers, 0, "", "PulseAudio");
pulse_add_device(&g_phys_sources, NULL, 0, Microphone, 0, "", "PulseAudio"); pulse_add_device(&g_phys_sources, NULL, 0, Microphone, 0, "", "PulseAudio");
o = pa_context_get_sink_info_list(pulse_ctx, &pulse_phys_speakers_cb, NULL); o = pa_context_get_sink_info_list(ctx, &pulse_phys_speakers_cb, NULL);
if (o) { if (o) {
while (pa_mainloop_iterate(pulse_ml, 1, &ret) >= 0 && while (pa_mainloop_iterate(ml, 1, &ret) >= 0 &&
pa_operation_get_state(o) == PA_OPERATION_RUNNING) pa_operation_get_state(o) == PA_OPERATION_RUNNING)
{} {}
pa_operation_unref(o); pa_operation_unref(o);
} }
o = pa_context_get_source_info_list(pulse_ctx, &pulse_phys_sources_cb, NULL); o = pa_context_get_source_info_list(ctx, &pulse_phys_sources_cb, NULL);
if (o) { if (o) {
while (pa_mainloop_iterate(pulse_ml, 1, &ret) >= 0 && while (pa_mainloop_iterate(ml, 1, &ret) >= 0 &&
pa_operation_get_state(o) == PA_OPERATION_RUNNING) pa_operation_get_state(o) == PA_OPERATION_RUNNING)
{} {}
pa_operation_unref(o); pa_operation_unref(o);
} }
LIST_FOR_EACH_ENTRY(dev, &g_phys_speakers, PhysDevice, entry) { LIST_FOR_EACH_ENTRY(dev, &g_phys_speakers, PhysDevice, entry) {
pulse_probe_settings(1, dev->pulse_name, &dev->fmt, &dev->def_period, &dev->min_period); pulse_probe_settings(ml, ctx, 1, dev->pulse_name, &dev->fmt, &dev->def_period, &dev->min_period);
} }
LIST_FOR_EACH_ENTRY(dev, &g_phys_sources, PhysDevice, entry) { LIST_FOR_EACH_ENTRY(dev, &g_phys_sources, PhysDevice, entry) {
pulse_probe_settings(0, dev->pulse_name, &dev->fmt, &dev->def_period, &dev->min_period); pulse_probe_settings(ml, ctx, 0, dev->pulse_name, &dev->fmt, &dev->def_period, &dev->min_period);
} }
pa_context_unref(pulse_ctx); pa_context_unref(ctx);
pulse_ctx = NULL; pa_mainloop_free(ml);
pa_mainloop_free(pulse_ml);
pulse_ml = NULL;
pulse_unlock(); pulse_unlock();
...@@ -835,10 +835,8 @@ static NTSTATUS pulse_test_connect(void *args) ...@@ -835,10 +835,8 @@ static NTSTATUS pulse_test_connect(void *args)
return STATUS_SUCCESS; return STATUS_SUCCESS;
fail: fail:
pa_context_unref(pulse_ctx); pa_context_unref(ctx);
pulse_ctx = NULL; pa_mainloop_free(ml);
pa_mainloop_free(pulse_ml);
pulse_ml = NULL;
pulse_unlock(); pulse_unlock();
params->result = E_FAIL; params->result = E_FAIL;
return STATUS_SUCCESS; return STATUS_SUCCESS;
......
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