Commit 70964042 authored by Max Kellermann's avatar Max Kellermann

player: chop the tail of the music pipe after CANCEL

When a CANCEL command is received, the player should drop all chunks of the next song. Added new funciton music_pipe_chop() which is used for that.
parent 66ce1495
...@@ -301,6 +301,18 @@ void music_pipe_skip(unsigned num) ...@@ -301,6 +301,18 @@ void music_pipe_skip(unsigned num)
music_pipe_shift(); music_pipe_shift();
} }
void music_pipe_chop(unsigned first)
{
for (unsigned i = first; i != music_pipe.end; i = successor(i))
music_chunk_free(&music_pipe.chunks[i]);
music_chunk_free(&music_pipe.chunks[music_pipe.end]);
music_pipe.end = first;
music_chunk_init(&music_pipe.chunks[first]);
}
#ifndef NDEBUG #ifndef NDEBUG
void music_pipe_check_format(const struct audio_format *current, void music_pipe_check_format(const struct audio_format *current,
int next_index, const struct audio_format *next) int next_index, const struct audio_format *next)
......
...@@ -164,6 +164,12 @@ bool music_pipe_tag(const struct tag *tag); ...@@ -164,6 +164,12 @@ bool music_pipe_tag(const struct tag *tag);
void music_pipe_skip(unsigned num); void music_pipe_skip(unsigned num);
/**
* Chop off the tail of the music pipe, starting with the chunk at
* index "first".
*/
void music_pipe_chop(unsigned first);
#ifndef NDEBUG #ifndef NDEBUG
void music_pipe_check_format(const struct audio_format *current, void music_pipe_check_format(const struct audio_format *current,
int next_index, const struct audio_format *next); int next_index, const struct audio_format *next);
......
...@@ -203,6 +203,7 @@ static void player_process_command(struct player *player) ...@@ -203,6 +203,7 @@ static void player_process_command(struct player *player)
/* the decoder is already decoding the song - /* the decoder is already decoding the song -
stop it and reset the position */ stop it and reset the position */
dc_stop(&pc.notify); dc_stop(&pc.notify);
music_pipe_chop(player->next_song_chunk);
player->next_song_chunk = -1; player->next_song_chunk = -1;
} }
......
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