aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-03-09 19:12:06 +0100
committerMax Kellermann <max@duempel.org>2009-03-09 19:12:06 +0100
commitd213f9a3e58495b07243f9b5371eda08c99589f8 (patch)
treefc720aa2cf1f677c34e4bbfc5e2fa5894468cca5
parent8de179ef7b65f06c9f767d2401bacc9422750107 (diff)
downloadmpd-d213f9a3e58495b07243f9b5371eda08c99589f8.tar.gz
mpd-d213f9a3e58495b07243f9b5371eda08c99589f8.tar.xz
mpd-d213f9a3e58495b07243f9b5371eda08c99589f8.zip
player_thread: make the music_buffer instance global
Preparation for the next patch: since the output devices stay open even when the player thread stops playing, we will need a persistent music buffer.
Diffstat (limited to '')
-rw-r--r--src/player_thread.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/player_thread.c b/src/player_thread.c
index 3302e51a9..f42b74a1f 100644
--- a/src/player_thread.c
+++ b/src/player_thread.c
@@ -45,7 +45,6 @@ enum xfade_state {
};
struct player {
- struct music_buffer *buffer;
struct music_pipe *pipe;
/**
@@ -91,6 +90,8 @@ struct player {
double size_to_time;
};
+static struct music_buffer *player_buffer;
+
static void player_command_finished(void)
{
assert(pc.command != PLAYER_COMMAND_NONE);
@@ -105,7 +106,7 @@ player_dc_stop(struct player *player)
dc_stop(&pc.notify);
if (dc.pipe != NULL) {
- music_pipe_clear(dc.pipe, player->buffer);
+ music_pipe_clear(dc.pipe, player_buffer);
if (dc.pipe != player->pipe)
music_pipe_free(dc.pipe);
@@ -207,7 +208,7 @@ static bool player_seek_decoder(struct player *player)
if (decoder_current_song() != pc.next_song) {
player_dc_stop(player);
- music_pipe_clear(player->pipe, player->buffer);
+ music_pipe_clear(player->pipe, player_buffer);
dc.pipe = player->pipe;
dc_start_async(pc.next_song);
@@ -379,17 +380,16 @@ static void do_play(void)
bool cross_fading = false;
static const char silence[CHUNK_SIZE];
- player.buffer = music_buffer_new(pc.buffer_chunks);
player.pipe = music_pipe_new();
- dc.buffer = player.buffer;
+ dc.buffer = player_buffer;
dc.pipe = player.pipe;
dc_start(&pc.notify, pc.next_song);
if (!player_wait_for_decoder(&player)) {
player_stop_decoder();
player_command_finished();
music_pipe_free(player.pipe);
- music_buffer_free(player.buffer);
+ music_buffer_free(player_buffer);
return;
}
@@ -456,7 +456,7 @@ static void do_play(void)
cross_fade_calc(pc.cross_fade_seconds, dc.total_time,
&dc.out_audio_format,
&player.play_audio_format,
- music_buffer_size(player.buffer) -
+ music_buffer_size(player_buffer) -
pc.buffered_before_play);
if (crossFadeChunks > 0) {
player.xfade = XFADE_ENABLED;
@@ -498,7 +498,7 @@ static void do_play(void)
&dc.out_audio_format,
fadePosition,
crossFadeChunks);
- music_buffer_return(player.buffer, other_chunk);
+ music_buffer_return(player_buffer, other_chunk);
} else {
/* there are not enough
decoded chunks yet */
@@ -526,7 +526,7 @@ static void do_play(void)
success = play_chunk(player.song, chunk,
&player.play_audio_format,
player.size_to_time);
- music_buffer_return(player.buffer, chunk);
+ music_buffer_return(player_buffer, chunk);
if (!success)
break;
@@ -537,7 +537,7 @@ static void do_play(void)
larger block at a time */
if (!decoder_is_idle() &&
music_pipe_size(dc.pipe) <= (pc.buffered_before_play +
- music_buffer_size(player.buffer) * 3) / 4)
+ music_buffer_size(player_buffer) * 3) / 4)
notify_signal(&dc.notify);
} else if (dc.pipe != NULL && dc.pipe != player.pipe) {
/* at the beginning of a new song */
@@ -572,20 +572,20 @@ static void do_play(void)
player_stop_decoder();
if (dc.pipe != NULL && dc.pipe != player.pipe) {
- music_pipe_clear(dc.pipe, player.buffer);
+ music_pipe_clear(dc.pipe, player_buffer);
music_pipe_free(dc.pipe);
}
- music_pipe_clear(player.pipe, player.buffer);
+ music_pipe_clear(player.pipe, player_buffer);
music_pipe_free(player.pipe);
-
- music_buffer_free(player.buffer);
}
static gpointer player_task(G_GNUC_UNUSED gpointer arg)
{
decoder_thread_start();
+ player_buffer = music_buffer_new(pc.buffer_chunks);
+
while (1) {
switch (pc.command) {
case PLAYER_COMMAND_PLAY:
@@ -610,6 +610,7 @@ static gpointer player_task(G_GNUC_UNUSED gpointer arg)
case PLAYER_COMMAND_EXIT:
dc_quit();
audio_output_all_close();
+ music_buffer_free(player_buffer);
player_command_finished();
g_thread_exit(NULL);
break;