aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/DecoderBuffer.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/decoder/DecoderBuffer.cxx')
-rw-r--r--src/decoder/DecoderBuffer.cxx25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/decoder/DecoderBuffer.cxx b/src/decoder/DecoderBuffer.cxx
index b337cbc0b..e26a702b7 100644
--- a/src/decoder/DecoderBuffer.cxx
+++ b/src/decoder/DecoderBuffer.cxx
@@ -117,21 +117,40 @@ decoder_buffer_fill(DecoderBuffer *buffer)
return true;
}
+static const void *
+decoder_buffer_head(const DecoderBuffer *buffer)
+{
+ return buffer->data + buffer->consumed;
+}
+
size_t
decoder_buffer_available(const DecoderBuffer *buffer)
{
- return buffer->length - buffer->consumed;;
+ return buffer->length - buffer->consumed;
}
ConstBuffer<void>
decoder_buffer_read(const DecoderBuffer *buffer)
{
return {
- buffer->data + buffer->consumed,
- buffer->length - buffer->consumed
+ decoder_buffer_head(buffer),
+ decoder_buffer_available(buffer),
};
}
+ConstBuffer<void>
+decoder_buffer_need(DecoderBuffer *buffer, size_t min_size)
+{
+ while (true) {
+ const auto available = decoder_buffer_available(buffer);
+ if (available >= min_size)
+ return { decoder_buffer_head(buffer), available };
+
+ if (!decoder_buffer_fill(buffer))
+ return nullptr;
+ }
+}
+
void
decoder_buffer_consume(DecoderBuffer *buffer, size_t nbytes)
{