music_pipe: more wrapper functions

Replace all direct music_pipe struct accesses with wrapper functions.
The compiled machine code is the same, but this way, we can change
struct internals more easily.
This commit is contained in:
Max Kellermann 2008-11-02 16:55:53 +01:00
parent 260a0cc33c
commit d430b1dc54
2 changed files with 33 additions and 8 deletions

View File

@ -76,12 +76,30 @@ void music_pipe_flush(void);
*/ */
void music_pipe_set_lazy(bool lazy); void music_pipe_set_lazy(bool lazy);
static inline unsigned
music_pipe_size(void)
{
return ob.size;
}
/** is the buffer empty? */ /** is the buffer empty? */
static inline bool music_pipe_is_empty(void) static inline bool music_pipe_is_empty(void)
{ {
return ob.begin == ob.end; return ob.begin == ob.end;
} }
static inline bool
music_pipe_head_is(unsigned i)
{
return !music_pipe_is_empty() && ob.begin == i;
}
static inline unsigned
music_pipe_tail_index(void)
{
return ob.end;
}
void music_pipe_shift(void); void music_pipe_shift(void);
/** /**
@ -102,6 +120,15 @@ int music_pipe_absolute(const unsigned relative);
struct music_chunk * struct music_chunk *
music_pipe_get_chunk(const unsigned i); music_pipe_get_chunk(const unsigned i);
static inline struct music_chunk *
music_pipe_peek(void)
{
if (music_pipe_is_empty())
return NULL;
return music_pipe_get_chunk(ob.begin);
}
/** /**
* Append a data block to the buffer. * Append a data block to the buffer.
* *

View File

@ -330,7 +330,7 @@ static void do_play(void)
assert(pc.next_song != NULL); assert(pc.next_song != NULL);
player.queued = false; player.queued = false;
player.next_song_chunk = ob.end; player.next_song_chunk = music_pipe_tail_index();
dc_start_async(pc.next_song); dc_start_async(pc.next_song);
} }
if (player.next_song_chunk >= 0 && if (player.next_song_chunk >= 0 &&
@ -342,7 +342,7 @@ static void do_play(void)
crossFadeChunks = crossFadeChunks =
cross_fade_calc(pc.crossFade, dc.totalTime, cross_fade_calc(pc.crossFade, dc.totalTime,
&dc.out_audio_format, &dc.out_audio_format,
ob.size - music_pipe_size() -
pc.buffered_before_play); pc.buffered_before_play);
if (crossFadeChunks > 0) { if (crossFadeChunks > 0) {
player.xfade = XFADE_ENABLED; player.xfade = XFADE_ENABLED;
@ -356,9 +356,8 @@ static void do_play(void)
if (player.paused) if (player.paused)
notify_wait(&pc.notify); notify_wait(&pc.notify);
else if (!music_pipe_is_empty() && else if (!music_pipe_is_empty() &&
(int)ob.begin != player.next_song_chunk) { !music_pipe_head_is(player.next_song_chunk)) {
struct music_chunk *beginChunk = struct music_chunk *beginChunk = music_pipe_peek();
music_pipe_get_chunk(ob.begin);
unsigned int fadePosition; unsigned int fadePosition;
if (player.xfade == XFADE_ENABLED && if (player.xfade == XFADE_ENABLED &&
player.next_song_chunk >= 0 && player.next_song_chunk >= 0 &&
@ -409,10 +408,9 @@ static void do_play(void)
decoder gets woken up with each chunk; it decoder gets woken up with each chunk; it
is more efficient to make it decode a is more efficient to make it decode a
larger block at a time */ larger block at a time */
if (music_pipe_available() <= (pc.buffered_before_play + ob.size * 3) / 4) if (music_pipe_available() <= (pc.buffered_before_play + music_pipe_size() * 3) / 4)
notify_signal(&dc.notify); notify_signal(&dc.notify);
} else if (!music_pipe_is_empty() && } else if (music_pipe_head_is(player.next_song_chunk)) {
(int)ob.begin == player.next_song_chunk) {
/* at the beginning of a new song */ /* at the beginning of a new song */
if (player.xfade == XFADE_ENABLED && nextChunk >= 0) { if (player.xfade == XFADE_ENABLED && nextChunk >= 0) {