Commit a276a7a2 authored by Dale Curtis's avatar Dale Curtis Committed by Commit Bot

Allow autospawn for pulse deamon to attempt to fix flaky tests.

Locally if I run "pactl exit" and log the start time, up to 3 seconds
may elapse before the pa_context reaches the PA_CONTEXT_READY state. On
my local machine, something is restarting the pulse daemon
automatically within a few seconds. It's possible the bots are running
in some state where the pulsedaemon will not respawn, so we end up
hanging forever.

There's no easy way to timeout the wait for PA_CONTEXT_READY since on
the call into pa_threaded_mainloop_wait() just hangs and there's no way
to pump the mainloop otherwise it looks like. If we want to make the
loop timeout, we need to switch away from wait() to a spin/sleep loop.

Lets see if this fixes the issue first, if not then we can try a timeout
based approach.

R=guidou

Bug: 1047655
Change-Id: If81ef546c04aa33df8e35368102fd890016db76f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2036901
Auto-Submit: Dale Curtis <dalecurtis@chromium.org>
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738151}
parent f171a6c3
......@@ -48,7 +48,7 @@ void DestroyMainloop(pa_threaded_mainloop* mainloop) {
}
void DestroyContext(pa_context* context) {
pa_context_set_state_callback(context, NULL, NULL);
pa_context_set_state_callback(context, nullptr, nullptr);
pa_context_disconnect(context);
pa_context_unref(context);
}
......@@ -202,10 +202,13 @@ bool InitPulse(pa_threaded_mainloop** mainloop, pa_context** context) {
pa_context_set_state_callback(pa_context, &pulse::ContextStateCallback,
pa_mainloop);
if (pa_context_connect(pa_context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL)) {
// Note: We don't use PA_CONTEXT_NOAUTOSPAWN here since when the daemon is
// missing, we seem to just hang forever.
if (pa_context_connect(pa_context, nullptr, PA_CONTEXT_NOFLAGS, nullptr)) {
VLOG(1) << "Failed to connect to the context. Error: "
<< pa_strerror(pa_context_errno(pa_context));
pa_context_set_state_callback(pa_context, NULL, NULL);
pa_context_set_state_callback(pa_context, nullptr, nullptr);
pa_context_unref(pa_context);
pa_threaded_mainloop_free(pa_mainloop);
return false;
......@@ -377,8 +380,8 @@ bool CreateInputStream(pa_threaded_mainloop* mainloop,
// Get channel mapping and open recording stream.
pa_channel_map source_channel_map = ChannelLayoutToPAChannelMap(
params.channel_layout());
pa_channel_map* map = (source_channel_map.channels != 0) ?
&source_channel_map : NULL;
pa_channel_map* map =
(source_channel_map.channels != 0) ? &source_channel_map : nullptr;
// Create a new recording stream and
// tells PulseAudio what the stream icon should be.
......@@ -408,9 +411,10 @@ bool CreateInputStream(pa_threaded_mainloop* mainloop,
PA_STREAM_START_CORKED;
RETURN_ON_FAILURE(
pa_stream_connect_record(
*stream, device_id == AudioDeviceDescription::kDefaultDeviceId
? NULL
: device_id.c_str(),
*stream,
device_id == AudioDeviceDescription::kDefaultDeviceId
? nullptr
: device_id.c_str(),
&buffer_attributes, static_cast<pa_stream_flags_t>(flags)) == 0,
"pa_stream_connect_record FAILED ");
......@@ -457,9 +461,9 @@ bool CreateOutputStream(pa_threaded_mainloop** mainloop,
RETURN_ON_FAILURE(pa_threaded_mainloop_start(*mainloop) == 0,
"Failed to start PulseAudio main loop.");
RETURN_ON_FAILURE(
pa_context_connect(*context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) == 0,
"Failed to connect PulseAudio context.");
RETURN_ON_FAILURE(pa_context_connect(*context, nullptr,
PA_CONTEXT_NOAUTOSPAWN, nullptr) == 0,
"Failed to connect PulseAudio context.");
// Wait until |pa_context_| is ready. pa_threaded_mainloop_wait() must be
// called after pa_context_get_state() in case the context is already ready,
......@@ -480,12 +484,12 @@ bool CreateOutputStream(pa_threaded_mainloop** mainloop,
sample_specifications.channels = params.channels();
// Get channel mapping.
pa_channel_map* map = NULL;
pa_channel_map* map = nullptr;
pa_channel_map source_channel_map = ChannelLayoutToPAChannelMap(
params.channel_layout());
if (source_channel_map.channels != 0) {
// The source data uses a supported channel map so we will use it rather
// than the default channel map (NULL).
// than the default channel map (nullptr).
map = &source_channel_map;
}
......@@ -527,15 +531,16 @@ bool CreateOutputStream(pa_threaded_mainloop** mainloop,
// and error.
RETURN_ON_FAILURE(
pa_stream_connect_playback(
*stream, device_id == AudioDeviceDescription::kDefaultDeviceId
? NULL
: device_id.c_str(),
*stream,
device_id == AudioDeviceDescription::kDefaultDeviceId
? nullptr
: device_id.c_str(),
&pa_buffer_attributes,
static_cast<pa_stream_flags_t>(
PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY |
PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_NOT_MONOTONIC |
PA_STREAM_START_CORKED),
NULL, NULL) == 0,
nullptr, nullptr) == 0,
"pa_stream_connect_playback FAILED ");
// Wait for the stream to be ready.
......
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