aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputPlugins
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-08-26 08:27:11 +0200
committerEric Wong <normalperson@yhbt.net>2008-08-30 18:45:06 -0700
commitc7e1a79a6b10f6714db31bb65d17db479b4a69d2 (patch)
treecbc7b58814c497bbf0653b19e02ea6bf0a3f81b7 /src/inputPlugins
parentd39395f3cdd937fc38d794de8706c9bc4cb96bd2 (diff)
downloadmpd-c7e1a79a6b10f6714db31bb65d17db479b4a69d2.tar.gz
mpd-c7e1a79a6b10f6714db31bb65d17db479b4a69d2.tar.xz
mpd-c7e1a79a6b10f6714db31bb65d17db479b4a69d2.zip
aac: moved code to aac_buffer_shift()
Shifting from the buffer queue is a common operation, and should be provided as a separate function. Move code to aac_buffer_shift() and add a bunch of assertions.
Diffstat (limited to 'src/inputPlugins')
-rw-r--r--src/inputPlugins/aac_plugin.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c
index b6e7e3fe4..3d6c40fb6 100644
--- a/src/inputPlugins/aac_plugin.c
+++ b/src/inputPlugins/aac_plugin.c
@@ -37,6 +37,19 @@ typedef struct {
int atEof;
} AacBuffer;
+static void aac_buffer_shift(AacBuffer * b, size_t length)
+{
+ assert(length >= b->bytesConsumed);
+ assert(length <= b->bytesConsumed + b->bytesIntoBuffer);
+
+ memmove(b->buffer, b->buffer + length,
+ b->bytesConsumed + b->bytesIntoBuffer - length);
+
+ length -= b->bytesConsumed;
+ b->bytesConsumed = 0;
+ b->bytesIntoBuffer -= length;
+}
+
static void fillAacBuffer(AacBuffer * b)
{
size_t bread;
@@ -45,13 +58,7 @@ static void fillAacBuffer(AacBuffer * b)
/* buffer already full */
return;
- if (b->bytesConsumed > 0 && b->bytesIntoBuffer > 0) {
- memmove((void *)b->buffer, (void *)(b->buffer +
- b->bytesConsumed),
- b->bytesIntoBuffer);
- }
-
- b->bytesConsumed = 0;
+ aac_buffer_shift(b, b->bytesConsumed);
if (!b->atEof) {
size_t rest = FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS -