aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/DecoderBuffer.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-07-12 01:33:12 +0200
committerMax Kellermann <max@duempel.org>2014-07-12 02:23:48 +0200
commitb2b95cad20846bb3235787c266c1723acf38f971 (patch)
tree182ef28088df9638d1a369b02b346504b2a224b9 /src/decoder/DecoderBuffer.cxx
parenteabec967ec3e431c10f50e5e83331ea0e5a4950f (diff)
downloadmpd-b2b95cad20846bb3235787c266c1723acf38f971.tar.gz
mpd-b2b95cad20846bb3235787c266c1723acf38f971.tar.xz
mpd-b2b95cad20846bb3235787c266c1723acf38f971.zip
DecoderBuffer: add method _need()
Move code from the FAAD decoder plugin.
Diffstat (limited to '')
-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)
{