diff options
author | Max Kellermann <max@duempel.org> | 2008-11-02 16:58:49 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-11-02 16:58:49 +0100 |
commit | fcc11bc9d85854f9b0dab74dd0ce7f76c412f4a1 (patch) | |
tree | 60266cfbdf397fb8162e2ae202872e1bd4067b6a /src | |
parent | 85b6ff7b594775276dcec85e8caf89d245476e47 (diff) | |
download | mpd-fcc11bc9d85854f9b0dab74dd0ce7f76c412f4a1.tar.gz mpd-fcc11bc9d85854f9b0dab74dd0ce7f76c412f4a1.tar.xz mpd-fcc11bc9d85854f9b0dab74dd0ce7f76c412f4a1.zip |
music_pipe: added functions chunk_init() and chunk_free()
These two functions will care about memory allocation and deallocation
in the future.
Diffstat (limited to 'src')
-rw-r--r-- | src/pipe.c | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/src/pipe.c b/src/pipe.c index 9d781961a..d94bac219 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -26,6 +26,18 @@ struct music_pipe music_pipe; +static void +music_chunk_init(struct music_chunk *chunk) +{ + chunk->length = 0; +} + +static void +music_chunk_free(struct music_chunk *chunk) +{ + (void)chunk; +} + void music_pipe_init(unsigned int size, struct notify *notify) { @@ -37,19 +49,16 @@ music_pipe_init(unsigned int size, struct notify *notify) music_pipe.end = 0; music_pipe.lazy = false; music_pipe.notify = notify; - music_pipe.chunks[0].length = 0; + music_chunk_init(&music_pipe.chunks[0]); } void music_pipe_free(void) { assert(music_pipe.chunks != NULL); - g_free(music_pipe.chunks); -} -void music_pipe_clear(void) -{ - music_pipe.end = music_pipe.begin; - music_pipe.chunks[music_pipe.end].length = 0; + music_pipe_clear(); + + g_free(music_pipe.chunks); } /** return the index of the chunk after i */ @@ -61,6 +70,19 @@ static inline unsigned successor(unsigned i) return i == music_pipe.num_chunks ? 0 : i; } +void music_pipe_clear(void) +{ + unsigned i; + + for (i = music_pipe.begin; 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 = music_pipe.begin; + music_chunk_init(&music_pipe.chunks[music_pipe.end]); +} + /** * Mark the tail chunk as "full" and wake up the player if is waiting * for the decoder. @@ -73,7 +95,8 @@ static void output_buffer_expand(unsigned i) assert(i != music_pipe.end); music_pipe.end = i; - music_pipe.chunks[i].length = 0; + music_chunk_init(&music_pipe.chunks[i]); + if (was_empty) /* if the buffer was empty, the player thread might be waiting for us; wake it up now that another decoded @@ -107,6 +130,8 @@ void music_pipe_shift(void) assert(music_pipe.begin != music_pipe.end); assert(music_pipe.begin < music_pipe.num_chunks); + music_chunk_free(&music_pipe.chunks[music_pipe.begin]); + music_pipe.begin = successor(music_pipe.begin); } @@ -241,6 +266,9 @@ size_t music_pipe_append(const void *data0, size_t datalen, void music_pipe_skip(unsigned num) { int i = music_pipe_absolute(num); - if (i >= 0) - music_pipe.begin = i; + if (i < 0) + return; + + while (music_pipe.begin != (unsigned)i) + music_pipe_shift(); } |