player/Thread: mutex must be locked inside CheckDecoderStartup()
This commit is contained in:
parent
ece5971027
commit
d0e735ee4b
@ -200,7 +200,7 @@ private:
|
|||||||
* ActivateDecoder()). This function checks if the decoder
|
* ActivateDecoder()). This function checks if the decoder
|
||||||
* initialization has completed yet.
|
* initialization has completed yet.
|
||||||
*
|
*
|
||||||
* The player lock is not held.
|
* Caller must lock the mutex.
|
||||||
*/
|
*/
|
||||||
bool CheckDecoderStartup();
|
bool CheckDecoderStartup();
|
||||||
|
|
||||||
@ -213,14 +213,19 @@ private:
|
|||||||
* allowed to be used while a command is being handled.
|
* allowed to be used while a command is being handled.
|
||||||
*/
|
*/
|
||||||
bool WaitDecoderStartup() {
|
bool WaitDecoderStartup() {
|
||||||
|
const ScopeLock lock(pc.mutex);
|
||||||
|
|
||||||
while (decoder_starting) {
|
while (decoder_starting) {
|
||||||
if (!CheckDecoderStartup()) {
|
if (!CheckDecoderStartup()) {
|
||||||
/* if decoder startup fails, make sure
|
/* if decoder startup fails, make sure
|
||||||
the previous song is not being
|
the previous song is not being
|
||||||
played anymore */
|
played anymore */
|
||||||
pc.outputs.Cancel();
|
{
|
||||||
|
const ScopeUnlock unlock(pc.mutex);
|
||||||
|
pc.outputs.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
pc.LockCommandFinished();
|
pc.CommandFinished();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -487,36 +492,28 @@ Player::CheckDecoderStartup()
|
|||||||
{
|
{
|
||||||
assert(decoder_starting);
|
assert(decoder_starting);
|
||||||
|
|
||||||
pc.Lock();
|
|
||||||
|
|
||||||
if (!ForwardDecoderError()) {
|
if (!ForwardDecoderError()) {
|
||||||
/* the decoder failed */
|
/* the decoder failed */
|
||||||
pc.Unlock();
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} else if (!dc.IsStarting()) {
|
} else if (!dc.IsStarting()) {
|
||||||
/* the decoder is ready and ok */
|
/* the decoder is ready and ok */
|
||||||
|
|
||||||
pc.Unlock();
|
|
||||||
|
|
||||||
if (output_open &&
|
if (output_open &&
|
||||||
!pc.LockWaitOutputConsumed(1))
|
!pc.WaitOutputConsumed(1))
|
||||||
/* the output devices havn't finished playing
|
/* the output devices havn't finished playing
|
||||||
all chunks yet - wait for that */
|
all chunks yet - wait for that */
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
{
|
pc.total_time = real_song_duration(*dc.song,
|
||||||
const ScopeLock lock(pc.mutex);
|
dc.total_time);
|
||||||
pc.total_time = real_song_duration(*dc.song,
|
pc.audio_format = dc.in_audio_format;
|
||||||
dc.total_time);
|
|
||||||
pc.audio_format = dc.in_audio_format;
|
|
||||||
}
|
|
||||||
|
|
||||||
idle_add(IDLE_PLAYER);
|
|
||||||
|
|
||||||
play_audio_format = dc.out_audio_format;
|
play_audio_format = dc.out_audio_format;
|
||||||
decoder_starting = false;
|
decoder_starting = false;
|
||||||
|
|
||||||
|
const ScopeUnlock unlock(pc.mutex);
|
||||||
|
|
||||||
|
idle_add(IDLE_PLAYER);
|
||||||
|
|
||||||
if (!paused && !OpenOutput()) {
|
if (!paused && !OpenOutput()) {
|
||||||
FormatError(player_domain,
|
FormatError(player_domain,
|
||||||
"problems opening audio device "
|
"problems opening audio device "
|
||||||
@ -530,7 +527,6 @@ Player::CheckDecoderStartup()
|
|||||||
/* the decoder is not yet ready; wait
|
/* the decoder is not yet ready; wait
|
||||||
some more */
|
some more */
|
||||||
dc.WaitForDecoder();
|
dc.WaitForDecoder();
|
||||||
pc.Unlock();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1011,10 +1007,13 @@ Player::Run()
|
|||||||
if (decoder_starting) {
|
if (decoder_starting) {
|
||||||
/* wait until the decoder is initialized completely */
|
/* wait until the decoder is initialized completely */
|
||||||
|
|
||||||
if (!CheckDecoderStartup())
|
|
||||||
break;
|
|
||||||
|
|
||||||
pc.Lock();
|
pc.Lock();
|
||||||
|
|
||||||
|
if (!CheckDecoderStartup()) {
|
||||||
|
pc.Unlock();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user