diff options
author | Max Kellermann <max@duempel.org> | 2008-08-26 08:27:11 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-08-26 08:27:11 +0200 |
commit | 00c47b3c85ef5d67e02bb1ea5f7e35b727803d01 (patch) | |
tree | 34a265d4fa386ddc034db606f3e70ffa0d6b0fac /src/inputPlugins | |
parent | f43e39047dba92860072e53ae322bf444538a09b (diff) | |
download | mpd-00c47b3c85ef5d67e02bb1ea5f7e35b727803d01.tar.gz mpd-00c47b3c85ef5d67e02bb1ea5f7e35b727803d01.tar.xz mpd-00c47b3c85ef5d67e02bb1ea5f7e35b727803d01.zip |
find AAC frames
Find AAC frames in the input and skip invalid data. This prepares AAC
streaming.
Diffstat (limited to '')
-rw-r--r-- | src/inputPlugins/aac_plugin.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c index 9438eb7c6..8bdf22446 100644 --- a/src/inputPlugins/aac_plugin.c +++ b/src/inputPlugins/aac_plugin.c @@ -111,6 +111,40 @@ static size_t adts_check_frame(AacBuffer * b) (b->buffer[5] >> 5); } +/** + * Find the next AAC frame in the buffer. Returns 0 if no frame is + * found or if not enough data is available. + */ +static size_t adts_find_frame(AacBuffer * b) +{ + const unsigned char *p; + size_t frame_length; + + while ((p = memchr(b->buffer, 0xff, b->bytesIntoBuffer)) != NULL) { + /* discard data before 0xff */ + if (p > b->buffer) + aac_buffer_shift(b, p - b->buffer); + + if (b->bytesIntoBuffer <= 7) + /* not enough data yet */ + return 0; + + /* is it a frame? */ + frame_length = adts_check_frame(b); + if (frame_length > 0) + /* yes, it is */ + return frame_length; + + /* it's just some random 0xff byte; discard and and + continue searching */ + aac_buffer_shift(b, 1); + } + + /* nothing at all; discard the whole buffer */ + aac_buffer_shift(b, b->bytesIntoBuffer); + return 0; +} + static void adtsParse(AacBuffer * b, float *length) { unsigned int frames, frameLength; @@ -121,7 +155,7 @@ static void adtsParse(AacBuffer * b, float *length) for (frames = 0;; frames++) { fillAacBuffer(b); - frameLength = adts_check_frame(b); + frameLength = adts_find_frame(b); if (frameLength > 0) { if (frames == 0) { sampleRate = adtsSampleRates[(b-> |