Commit 933fcf42 authored by Max Kellermann's avatar Max Kellermann

output_all: moved code to audio_output_all_wait()

Synchronization with the output thread will be implemented in output_all.c, not in player_thread.c. Currently, that's just a simple g_usleep(1ms).
parent 4dbf73d8
...@@ -408,6 +408,18 @@ audio_output_all_check(void) ...@@ -408,6 +408,18 @@ audio_output_all_check(void)
return 0; return 0;
} }
bool
audio_output_all_wait(unsigned threshold)
{
if (audio_output_all_check() < threshold)
return true;
/* XXX synchronize in a better way */
g_usleep(1000);
return audio_output_all_check() < threshold;
}
void void
audio_output_all_pause(void) audio_output_all_pause(void)
{ {
......
...@@ -105,6 +105,17 @@ unsigned ...@@ -105,6 +105,17 @@ unsigned
audio_output_all_check(void); audio_output_all_check(void);
/** /**
* Checks if the size of the #music_pipe is below the #threshold. If
* not, it attempts to synchronize with all output threads, and waits
* until another #music_chunk is finished.
*
* @param threshold the maximum number of chunks in the pipe
* @return true if there are less than #threshold chunks in the pipe
*/
bool
audio_output_all_wait(unsigned threshold);
/**
* Puts all audio outputs into pause mode. Most implementations will * Puts all audio outputs into pause mode. Most implementations will
* simply close it then. * simply close it then.
*/ */
......
...@@ -192,14 +192,10 @@ player_check_decoder_startup(struct player *player) ...@@ -192,14 +192,10 @@ player_check_decoder_startup(struct player *player)
/* the decoder is ready and ok */ /* the decoder is ready and ok */
if (audio_format_defined(&player->play_audio_format) && if (audio_format_defined(&player->play_audio_format) &&
audio_output_all_check() > 0) { !audio_output_all_wait(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 */
/* XXX synchronize in a better way */
g_usleep(1000);
return true; return true;
}
player->decoder_starting = false; player->decoder_starting = false;
...@@ -479,14 +475,10 @@ play_next_chunk(struct player *player) ...@@ -479,14 +475,10 @@ play_next_chunk(struct player *player)
unsigned cross_fade_position; unsigned cross_fade_position;
bool success; bool success;
if (audio_output_all_check() >= 64) { if (!audio_output_all_wait(64))
/* the output pipe is still large enough, don't send /* the output pipe is still large enough, don't send
another chunk */ another chunk */
/* XXX synchronize in a better way */
g_usleep(1000);
return true; return true;
}
if (player->xfade == XFADE_ENABLED && if (player->xfade == XFADE_ENABLED &&
dc.pipe != NULL && dc.pipe != player->pipe && dc.pipe != NULL && dc.pipe != player->pipe &&
......
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