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.
This commit is contained in:
parent
a3cc928c71
commit
b7ad3e4121
@ -37,6 +37,19 @@ typedef struct {
|
|||||||
int atEof;
|
int atEof;
|
||||||
} AacBuffer;
|
} 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)
|
static void fillAacBuffer(AacBuffer * b)
|
||||||
{
|
{
|
||||||
size_t bread;
|
size_t bread;
|
||||||
@ -45,13 +58,7 @@ static void fillAacBuffer(AacBuffer * b)
|
|||||||
/* buffer already full */
|
/* buffer already full */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (b->bytesConsumed > 0 && b->bytesIntoBuffer > 0) {
|
aac_buffer_shift(b, b->bytesConsumed);
|
||||||
memmove((void *)b->buffer, (void *)(b->buffer +
|
|
||||||
b->bytesConsumed),
|
|
||||||
b->bytesIntoBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
b->bytesConsumed = 0;
|
|
||||||
|
|
||||||
if (!b->atEof) {
|
if (!b->atEof) {
|
||||||
size_t rest = FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS -
|
size_t rest = FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS -
|
||||||
|
Loading…
Reference in New Issue
Block a user