aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-04-12 04:18:04 +0000
committerEric Wong <normalperson@yhbt.net>2008-04-12 04:18:04 +0000
commite9e557c8d1562d0215e4e4a4c2f361457aec43a9 (patch)
tree13254e8a32a2d1ed4eedd750df0115601bd3004c /src
parentb2819e12e7abe9cbe918a68eb9f917d2711402fa (diff)
downloadmpd-e9e557c8d1562d0215e4e4a4c2f361457aec43a9.tar.gz
mpd-e9e557c8d1562d0215e4e4a4c2f361457aec43a9.tar.xz
mpd-e9e557c8d1562d0215e4e4a4c2f361457aec43a9.zip
pass buffered_chunks to initOutputBuffer()
Try to make OutputBuffer self-contained, without depending on a global variable. git-svn-id: https://svn.musicpd.org/mpd/trunk@7310 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/outputBuffer.c31
-rw-r--r--src/outputBuffer.h4
-rw-r--r--src/playerData.c2
3 files changed, 21 insertions, 16 deletions
diff --git a/src/outputBuffer.c b/src/outputBuffer.c
index 7a2acaac7..0d114a1a6 100644
--- a/src/outputBuffer.c
+++ b/src/outputBuffer.c
@@ -26,10 +26,13 @@
#include "conf.h"
#include "os_compat.h"
-void initOutputBuffer(OutputBuffer * cb)
+void initOutputBuffer(OutputBuffer * cb, unsigned int size)
{
+ assert(size > 0);
+
memset(&cb->convState, 0, sizeof(ConvState));
- cb->chunks = xmalloc(buffered_chunks * sizeof(*cb->chunks));
+ cb->chunks = xmalloc(size * sizeof(*cb->chunks));
+ cb->size = size;
cb->currentChunk = -1;
}
@@ -40,18 +43,18 @@ void clearOutputBuffer(OutputBuffer * cb)
}
/** return the index of the chunk after i */
-static inline unsigned successor(unsigned i)
+static inline unsigned successor(const OutputBuffer * cb, unsigned i)
{
- assert(i <= buffered_chunks);
+ assert(i <= cb->size);
++i;
- return i == buffered_chunks ? 0 : i;
+ return i == cb->size ? 0 : i;
}
void flushOutputBuffer(OutputBuffer * cb)
{
if (cb->currentChunk == cb->end) {
- cb->end = successor(cb->end);
+ cb->end = successor(cb, cb->end);
cb->currentChunk = -1;
}
}
@@ -64,9 +67,9 @@ int outputBufferEmpty(const OutputBuffer * cb)
void outputBufferShift(OutputBuffer * cb)
{
assert(cb->begin != cb->end);
- assert(cb->begin < buffered_chunks);
+ assert(cb->begin < cb->size);
- cb->begin = successor(cb->begin);
+ cb->begin = successor(cb, cb->begin);
}
unsigned int outputBufferRelative(const OutputBuffer * cb, unsigned i)
@@ -74,7 +77,7 @@ unsigned int outputBufferRelative(const OutputBuffer * cb, unsigned i)
if (i >= cb->begin)
return i - cb->begin;
else
- return i + buffered_chunks - cb->begin;
+ return i + cb->size - cb->begin;
}
unsigned availableOutputBuffer(const OutputBuffer * cb)
@@ -88,20 +91,20 @@ int outputBufferAbsolute(const OutputBuffer * cb, unsigned relative)
max = cb->end;
if (max < cb->begin)
- max += buffered_chunks;
+ max += cb->size;
i = (unsigned)cb->begin + relative;
if (i >= max)
return -1;
- if (i >= buffered_chunks)
- i -= buffered_chunks;
+ if (i >= cb->size)
+ i -= cb->size;
return (int)i;
}
OutputBufferChunk * outputBufferGetChunk(const OutputBuffer * cb, unsigned i)
{
- assert(i < buffered_chunks);
+ assert(i < cb->size);
return &cb->chunks[i];
}
@@ -125,7 +128,7 @@ static int tailChunk(OutputBuffer * cb, InputStream * inStream,
if (cb->currentChunk == cb->end)
return cb->currentChunk;
- next = successor(cb->end);
+ next = successor(cb, cb->end);
while (cb->begin == next && !dc->stop) {
if (dc->seek) {
if (seekable) {
diff --git a/src/outputBuffer.h b/src/outputBuffer.h
index 70fff1d08..ac2ffac3f 100644
--- a/src/outputBuffer.h
+++ b/src/outputBuffer.h
@@ -46,6 +46,8 @@ typedef struct _OutputBufferChunk {
typedef struct _OutputBuffer {
OutputBufferChunk *chunks;
+ unsigned int size;
+
/** the index of the first decoded chunk */
mpd_uint16 volatile begin;
@@ -58,7 +60,7 @@ typedef struct _OutputBuffer {
ConvState convState;
} OutputBuffer;
-void initOutputBuffer(OutputBuffer * cb);
+void initOutputBuffer(OutputBuffer * cb, unsigned int size);
void clearOutputBuffer(OutputBuffer * cb);
diff --git a/src/playerData.c b/src/playerData.c
index 3fd330d63..917c2a05b 100644
--- a/src/playerData.c
+++ b/src/playerData.c
@@ -75,7 +75,7 @@ void initPlayerData(void)
playerData_pd.audioDeviceStates = xmalloc(device_array_size);
- initOutputBuffer(&(playerData_pd.buffer));
+ initOutputBuffer(&(playerData_pd.buffer), buffered_chunks);
notifyInit(&playerData_pd.playerControl.notify);
playerData_pd.playerControl.stop = 0;