diff options
Diffstat (limited to '')
-rw-r--r-- | src/decoder_api.c | 4 | ||||
-rw-r--r-- | src/decoder_thread.c | 2 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/pipe.c | 40 | ||||
-rw-r--r-- | src/pipe.h | 28 | ||||
-rw-r--r-- | src/player_thread.c | 33 |
6 files changed, 56 insertions, 55 deletions
diff --git a/src/decoder_api.c b/src/decoder_api.c index 1c9bd822a..715a46c8d 100644 --- a/src/decoder_api.c +++ b/src/decoder_api.c @@ -66,7 +66,7 @@ void decoder_command_finished(mpd_unused struct decoder * decoder) if (dc.command == DECODE_COMMAND_SEEK) /* delete frames from the old song position */ - ob_clear(); + music_pipe_clear(); dc.command = DECODE_COMMAND_NONE; notify_signal(&pc.notify); @@ -181,7 +181,7 @@ decoder_data(struct decoder *decoder, normalizeData(data, datalen, &ob.audioFormat); while (datalen > 0) { - nbytes = ob_append(data, datalen, data_time, bitRate); + nbytes = music_pipe_append(data, datalen, data_time, bitRate); datalen -= nbytes; data += nbytes; diff --git a/src/decoder_thread.c b/src/decoder_thread.c index f45446dc2..a05783a62 100644 --- a/src/decoder_thread.c +++ b/src/decoder_thread.c @@ -158,7 +158,7 @@ static void decodeStart(void) } } - ob_flush(); + music_pipe_flush(); if (!ret) { dc.error = plugin == NULL diff --git a/src/main.c b/src/main.c index 5b50b135d..325254b62 100644 --- a/src/main.c +++ b/src/main.c @@ -424,7 +424,7 @@ int main(int argc, char *argv[]) command_init(); initPlayerData(); pc_init(buffered_before_play); - ob_init(buffered_chunks, &pc.notify); + music_pipe_init(buffered_chunks, &pc.notify); dc_init(); initAudioConfig(); initAudioDriver(); @@ -488,7 +488,7 @@ int main(int argc, char *argv[]) pc_deinit(); command_finish(); decoder_plugin_deinit_all(); - ob_free(); + music_pipe_free(); cleanUpPidFile(); finishConf(); diff --git a/src/pipe.c b/src/pipe.c index 28a248030..b6912b5fa 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -26,7 +26,7 @@ struct music_pipe ob; void -ob_init(unsigned int size, struct notify *notify) +music_pipe_init(unsigned int size, struct notify *notify) { assert(size > 0); @@ -39,13 +39,13 @@ ob_init(unsigned int size, struct notify *notify) ob.chunks[0].chunkSize = 0; } -void ob_free(void) +void music_pipe_free(void) { assert(ob.chunks != NULL); free(ob.chunks); } -void ob_clear(void) +void music_pipe_clear(void) { ob.end = ob.begin; ob.chunks[ob.end].chunkSize = 0; @@ -66,7 +66,7 @@ static inline unsigned successor(unsigned i) */ static void output_buffer_expand(unsigned i) { - int was_empty = ob.notify != NULL && (!ob.lazy || ob_is_empty()); + int was_empty = ob.notify != NULL && (!ob.lazy || music_pipe_is_empty()); assert(i == (ob.end + 1) % ob.size); assert(i != ob.end); @@ -80,9 +80,9 @@ static void output_buffer_expand(unsigned i) notify_signal(ob.notify); } -void ob_flush(void) +void music_pipe_flush(void) { - struct music_chunk *chunk = ob_get_chunk(ob.end); + struct music_chunk *chunk = music_pipe_get_chunk(ob.end); if (chunk->chunkSize > 0) { unsigned int next = successor(ob.end); @@ -96,12 +96,12 @@ void ob_flush(void) } } -void ob_set_lazy(bool lazy) +void music_pipe_set_lazy(bool lazy) { ob.lazy = lazy; } -void ob_shift(void) +void music_pipe_shift(void) { assert(ob.begin != ob.end); assert(ob.begin < ob.size); @@ -109,7 +109,7 @@ void ob_shift(void) ob.begin = successor(ob.begin); } -unsigned int ob_relative(const unsigned i) +unsigned int music_pipe_relative(const unsigned i) { if (i >= ob.begin) return i - ob.begin; @@ -117,12 +117,12 @@ unsigned int ob_relative(const unsigned i) return i + ob.size - ob.begin; } -unsigned ob_available(void) +unsigned music_pipe_available(void) { - return ob_relative(ob.end); + return music_pipe_relative(ob.end); } -int ob_absolute(const unsigned relative) +int music_pipe_absolute(const unsigned relative) { unsigned i, max; @@ -140,7 +140,7 @@ int ob_absolute(const unsigned relative) } struct music_chunk * -ob_get_chunk(const unsigned i) +music_pipe_get_chunk(const unsigned i) { assert(i < ob.size); @@ -160,7 +160,7 @@ tail_chunk(float data_time, uint16_t bitRate) unsigned int next; struct music_chunk *chunk; - chunk = ob_get_chunk(ob.end); + chunk = music_pipe_get_chunk(ob.end); assert(chunk->chunkSize <= sizeof(chunk->data)); if (chunk->chunkSize + frame_size > sizeof(chunk->data)) { /* this chunk is full; allocate a new chunk */ @@ -170,7 +170,7 @@ tail_chunk(float data_time, uint16_t bitRate) return NULL; output_buffer_expand(next); - chunk = ob_get_chunk(next); + chunk = music_pipe_get_chunk(next); assert(chunk->chunkSize == 0); } @@ -185,8 +185,8 @@ tail_chunk(float data_time, uint16_t bitRate) return chunk; } -size_t ob_append(const void *data0, size_t datalen, - float data_time, uint16_t bitRate) +size_t music_pipe_append(const void *data0, size_t datalen, + float data_time, uint16_t bitRate) { const unsigned char *data = data0; const size_t frame_size = audio_format_frame_size(&ob.audioFormat); @@ -217,14 +217,14 @@ size_t ob_append(const void *data0, size_t datalen, } if (chunk != NULL && chunk->chunkSize == sizeof(chunk->data)) - ob_flush(); + music_pipe_flush(); return ret; } -void ob_skip(unsigned num) +void music_pipe_skip(unsigned num) { - int i = ob_absolute(num); + int i = music_pipe_absolute(num); if (i >= 0) ob.begin = i; } diff --git a/src/pipe.h b/src/pipe.h index bc25ec820..a27629697 100644 --- a/src/pipe.h +++ b/src/pipe.h @@ -61,13 +61,13 @@ struct music_pipe { extern struct music_pipe ob; void -ob_init(unsigned int size, struct notify *notify); +music_pipe_init(unsigned int size, struct notify *notify); -void ob_free(void); +void music_pipe_free(void); -void ob_clear(void); +void music_pipe_clear(void); -void ob_flush(void); +void music_pipe_flush(void); /** * When a chunk is decoded, we wake up the player thread to tell him @@ -75,42 +75,42 @@ void ob_flush(void); * previously empty, i.e. when the player thread has really been * waiting for us. */ -void ob_set_lazy(bool lazy); +void music_pipe_set_lazy(bool lazy); /** is the buffer empty? */ -static inline bool ob_is_empty(void) +static inline bool music_pipe_is_empty(void) { return ob.begin == ob.end; } -void ob_shift(void); +void music_pipe_shift(void); /** * what is the position of the specified chunk number, relative to * the first chunk in use? */ -unsigned int ob_relative(const unsigned i); +unsigned int music_pipe_relative(const unsigned i); /** determine the number of decoded chunks */ -unsigned ob_available(void); +unsigned music_pipe_available(void); /** * Get the absolute index of the nth used chunk after the first one. * Returns -1 if there is no such chunk. */ -int ob_absolute(const unsigned relative); +int music_pipe_absolute(const unsigned relative); struct music_chunk * -ob_get_chunk(const unsigned i); +music_pipe_get_chunk(const unsigned i); /** * Append a data block to the buffer. * * @return the number of bytes actually written */ -size_t ob_append(const void *data, size_t datalen, - float data_time, uint16_t bitRate); +size_t music_pipe_append(const void *data, size_t datalen, + float data_time, uint16_t bitRate); -void ob_skip(unsigned num); +void music_pipe_skip(unsigned num); #endif diff --git a/src/player_thread.c b/src/player_thread.c index 7da0269c0..733d7ea41 100644 --- a/src/player_thread.c +++ b/src/player_thread.c @@ -114,7 +114,7 @@ static bool decodeSeek(struct player *player) if (decoder_current_song() != pc.next_song) { dc_stop(&pc.notify); player->next_song_chunk = -1; - ob_clear(); + music_pipe_clear(); dc_start_async(pc.next_song); waitOnDecode(player); } @@ -241,8 +241,8 @@ static void do_play(void) struct audio_format play_audio_format; double sizeToTime = 0.0; - ob_clear(); - ob_set_lazy(false); + music_pipe_clear(); + music_pipe_set_lazy(false); dc_start(&pc.notify, pc.next_song); if (waitOnDecode(&player) < 0) { @@ -265,7 +265,7 @@ static void do_play(void) } if (player.buffering) { - if (ob_available() < pc.buffered_before_play && + if (music_pipe_available() < pc.buffered_before_play && !decoder_is_idle()) { /* not enough decoded buffer space yet */ notify_wait(&pc.notify); @@ -273,7 +273,7 @@ static void do_play(void) } else { /* buffering is complete */ player.buffering = false; - ob_set_lazy(true); + music_pipe_set_lazy(true); } } @@ -355,13 +355,14 @@ static void do_play(void) if (player.paused) notify_wait(&pc.notify); - else if (!ob_is_empty() && + else if (!music_pipe_is_empty() && (int)ob.begin != player.next_song_chunk) { - struct music_chunk *beginChunk = ob_get_chunk(ob.begin); + struct music_chunk *beginChunk = + music_pipe_get_chunk(ob.begin); unsigned int fadePosition; if (player.xfade == XFADE_ENABLED && player.next_song_chunk >= 0 && - (fadePosition = ob_relative(player.next_song_chunk)) + (fadePosition = music_pipe_relative(player.next_song_chunk)) <= crossFadeChunks) { /* perform cross fade */ if (nextChunk < 0) { @@ -372,11 +373,11 @@ static void do_play(void) chunks in the old song */ crossFadeChunks = fadePosition; } - nextChunk = ob_absolute(crossFadeChunks); + nextChunk = music_pipe_absolute(crossFadeChunks); if (nextChunk >= 0) { - ob_set_lazy(true); + music_pipe_set_lazy(true); cross_fade_apply(beginChunk, - ob_get_chunk(nextChunk), + music_pipe_get_chunk(nextChunk), &(ob.audioFormat), fadePosition, crossFadeChunks); @@ -391,7 +392,7 @@ static void do_play(void) } else { /* wait for the decoder */ - ob_set_lazy(false); + music_pipe_set_lazy(false); notify_wait(&pc.notify); continue; } @@ -402,15 +403,15 @@ static void do_play(void) if (playChunk(beginChunk, &play_audio_format, sizeToTime) < 0) break; - ob_shift(); + music_pipe_shift(); /* this formula should prevent that the decoder gets woken up with each chunk; it is more efficient to make it decode a larger block at a time */ - if (ob_available() <= (pc.buffered_before_play + ob.size * 3) / 4) + if (music_pipe_available() <= (pc.buffered_before_play + ob.size * 3) / 4) notify_signal(&dc.notify); - } else if (!ob_is_empty() && + } else if (!music_pipe_is_empty() && (int)ob.begin == player.next_song_chunk) { /* at the beginning of a new song */ @@ -418,7 +419,7 @@ static void do_play(void) /* the cross-fade is finished; skip the section which was cross-faded (and thus already played) */ - ob_skip(crossFadeChunks); + music_pipe_skip(crossFadeChunks); } player.xfade = XFADE_UNKNOWN; |