Commit eac9fabd authored by Max Kellermann's avatar Max Kellermann

DecoderBuffer: add method _clear()

parent e2a08fa8
...@@ -82,6 +82,12 @@ decoder_buffer_is_full(const DecoderBuffer *buffer) ...@@ -82,6 +82,12 @@ decoder_buffer_is_full(const DecoderBuffer *buffer)
return buffer->consumed == 0 && buffer->length == buffer->size; return buffer->consumed == 0 && buffer->length == buffer->size;
} }
void
decoder_buffer_clear(DecoderBuffer *buffer)
{
buffer->length = buffer->consumed = 0;
}
static void static void
decoder_buffer_shift(DecoderBuffer *buffer) decoder_buffer_shift(DecoderBuffer *buffer)
{ {
......
...@@ -56,6 +56,9 @@ decoder_buffer_is_empty(const DecoderBuffer *buffer); ...@@ -56,6 +56,9 @@ decoder_buffer_is_empty(const DecoderBuffer *buffer);
bool bool
decoder_buffer_is_full(const DecoderBuffer *buffer); decoder_buffer_is_full(const DecoderBuffer *buffer);
void
decoder_buffer_clear(DecoderBuffer *buffer);
/** /**
* Read data from the input_stream and append it to the buffer. * Read data from the input_stream and append it to the buffer.
* *
......
...@@ -84,7 +84,7 @@ adts_find_frame(DecoderBuffer *buffer) ...@@ -84,7 +84,7 @@ adts_find_frame(DecoderBuffer *buffer)
const uint8_t *p = (const uint8_t *)memchr(data, 0xff, length); const uint8_t *p = (const uint8_t *)memchr(data, 0xff, length);
if (p == nullptr) { if (p == nullptr) {
/* no marker - discard the buffer */ /* no marker - discard the buffer */
decoder_buffer_consume(buffer, length); decoder_buffer_clear(buffer);
continue; continue;
} }
...@@ -111,10 +111,7 @@ adts_find_frame(DecoderBuffer *buffer) ...@@ -111,10 +111,7 @@ adts_find_frame(DecoderBuffer *buffer)
/* not enough data; discard this frame /* not enough data; discard this frame
to prevent a possible buffer to prevent a possible buffer
overflow */ overflow */
data = (const uint8_t *) decoder_buffer_clear(buffer);
decoder_buffer_read(buffer, &length);
if (data != nullptr)
decoder_buffer_consume(buffer, length);
} }
continue; continue;
...@@ -196,9 +193,7 @@ faad_song_duration(DecoderBuffer *buffer, InputStream &is) ...@@ -196,9 +193,7 @@ faad_song_duration(DecoderBuffer *buffer, InputStream &is)
is.LockSeek(tagsize, SEEK_SET, IgnoreError()); is.LockSeek(tagsize, SEEK_SET, IgnoreError());
data = (const uint8_t *)decoder_buffer_read(buffer, &length); decoder_buffer_clear(buffer);
if (data != nullptr)
decoder_buffer_consume(buffer, length);
decoder_buffer_fill(buffer); decoder_buffer_fill(buffer);
return song_length; return song_length;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment