From e5c9f6c1fe316ab60122516b6948fc3e355da905 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 21 Dec 2016 17:00:29 +0100 Subject: [PATCH] output/Internal: add attribute request.audio_format Make in_audio_format accessible only from within the OutputThread, and add a new one for inter-thread communication. --- src/output/Internal.hxx | 12 ++++++++++++ src/output/OutputControl.cxx | 4 ++-- src/output/OutputThread.cxx | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/output/Internal.hxx b/src/output/Internal.hxx index b7c83b7b5..39e3ae345 100644 --- a/src/output/Internal.hxx +++ b/src/output/Internal.hxx @@ -166,6 +166,8 @@ struct AudioOutput { /** * The audio_format in which audio data is received from the * player thread (which in turn receives it from the decoder). + * + * Only accessible from within the OutputThread. */ AudioFormat in_audio_format; @@ -246,6 +248,16 @@ struct AudioOutput { */ Command command = Command::NONE; + /** + * Additional data for #command. Protected by #mutex. + */ + struct Request { + /** + * The #AudioFormat requested by #Command::OPEN. + */ + AudioFormat audio_format; + } request; + /** * This mutex protects #open, #fail_timer, #pipe. */ diff --git a/src/output/OutputControl.cxx b/src/output/OutputControl.cxx index f2c635fba..74a1765d5 100644 --- a/src/output/OutputControl.cxx +++ b/src/output/OutputControl.cxx @@ -112,7 +112,7 @@ AudioOutput::Open(const AudioFormat audio_format, const MusicPipe &mp) fail_timer.Reset(); - if (open && audio_format == in_audio_format) { + if (open && audio_format == request.audio_format) { assert(&pipe.GetPipe() == &mp || (always_on && pause)); if (pause) { @@ -131,7 +131,7 @@ AudioOutput::Open(const AudioFormat audio_format, const MusicPipe &mp) return true; } - in_audio_format = audio_format; + request.audio_format = audio_format; pipe.Init(mp); diff --git a/src/output/OutputThread.cxx b/src/output/OutputThread.cxx index 071ce37f0..42a97b2bd 100644 --- a/src/output/OutputThread.cxx +++ b/src/output/OutputThread.cxx @@ -134,7 +134,7 @@ inline void AudioOutput::Open() { assert(!open); - assert(in_audio_format.IsValid()); + assert(request.audio_format.IsValid()); fail_timer.Reset(); @@ -144,6 +144,8 @@ AudioOutput::Open() /* still no luck */ return; + in_audio_format = request.audio_format; + bool success; {