Commit 9562f667 authored by Max Kellermann's avatar Max Kellermann

output_control: lock object in audio_output_open()

Protect the attributes "open" and "fail_timer".
parent 21223154
...@@ -72,6 +72,12 @@ static void ao_command_async(struct audio_output *ao, ...@@ -72,6 +72,12 @@ static void ao_command_async(struct audio_output *ao,
notify_signal(&ao->notify); notify_signal(&ao->notify);
} }
static void
audio_output_close_locked(struct audio_output *ao);
/**
* Object must be locked (and unlocked) by the caller.
*/
static bool static bool
audio_output_open(struct audio_output *ao, audio_output_open(struct audio_output *ao,
const struct audio_format *audio_format, const struct audio_format *audio_format,
...@@ -98,7 +104,7 @@ audio_output_open(struct audio_output *ao, ...@@ -98,7 +104,7 @@ audio_output_open(struct audio_output *ao,
/* we're not using audio_output_cancel() here, /* we're not using audio_output_cancel() here,
because that function is asynchronous */ because that function is asynchronous */
ao_command(ao, AO_COMMAND_CANCEL); ao_command_locked(ao, AO_COMMAND_CANCEL);
} }
return true; return true;
...@@ -109,7 +115,7 @@ audio_output_open(struct audio_output *ao, ...@@ -109,7 +115,7 @@ audio_output_open(struct audio_output *ao,
if (!ao->config_audio_format) { if (!ao->config_audio_format) {
if (ao->open) if (ao->open)
audio_output_close(ao); audio_output_close_locked(ao);
/* no audio format is configured: copy in->out, let /* no audio format is configured: copy in->out, let
the output's open() method determine the effective the output's open() method determine the effective
...@@ -124,7 +130,7 @@ audio_output_open(struct audio_output *ao, ...@@ -124,7 +130,7 @@ audio_output_open(struct audio_output *ao,
open = ao->open; open = ao->open;
if (!open) { if (!open) {
ao_command(ao, AO_COMMAND_OPEN); ao_command_locked(ao, AO_COMMAND_OPEN);
open = ao->open; open = ao->open;
} }
...@@ -141,12 +147,19 @@ audio_output_update(struct audio_output *ao, ...@@ -141,12 +147,19 @@ audio_output_update(struct audio_output *ao,
{ {
assert(mp != NULL); assert(mp != NULL);
g_mutex_lock(ao->mutex);
if (ao->enabled) { if (ao->enabled) {
if (ao->fail_timer == NULL || if (ao->fail_timer == NULL ||
g_timer_elapsed(ao->fail_timer, NULL) > REOPEN_AFTER) g_timer_elapsed(ao->fail_timer, NULL) > REOPEN_AFTER) {
return audio_output_open(ao, audio_format, mp); bool ret = audio_output_open(ao, audio_format, mp);
g_mutex_unlock(ao->mutex);
return ret;
}
} else if (audio_output_is_open(ao)) } else if (audio_output_is_open(ao))
audio_output_close(ao); audio_output_close_locked(ao);
g_mutex_unlock(ao->mutex);
return false; return false;
} }
......
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