MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

DecoderBuffer.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_DECODER_BUFFER_HXX
21 #define MPD_DECODER_BUFFER_HXX
22
23 #include "Compiler.h"
24 #include "util/DynamicFifoBuffer.hxx"
25 #include "util/ConstBuffer.hxx"
26
27 #include <stddef.h>
28 #include <stdint.h>
29
30 class DecoderClient;
31 class InputStream;
32
38 class DecoderBuffer {
39 DecoderClient *const client;
40 InputStream &is;
41
42 DynamicFifoBuffer<uint8_t> buffer;
43
44 public:
53 DecoderBuffer(DecoderClient *_client, InputStream &_is,
54 size_t _size)
55 :client(_client), is(_is), buffer(_size) {}
56
57 const InputStream &GetStream() const {
58 return is;
59 }
60
61 void Clear() {
62 buffer.Clear();
63 }
64
72 bool Fill();
73
77 gcc_pure
78 size_t GetAvailable() const {
79 return buffer.GetAvailable();
80 }
81
87 ConstBuffer<void> Read() const {
88 auto r = buffer.Read();
89 return { r.data, r.size };
90 }
91
96 ConstBuffer<void> Need(size_t min_size);
97
105 void Consume(size_t nbytes) {
106 buffer.Consume(nbytes);
107 }
108
115 bool Skip(size_t nbytes);
116 };
117
118 #endif
DecoderBuffer::Fill
bool Fill()
Read data from the InputStream and append it to the buffer.
DecoderBuffer::GetStream
const InputStream & GetStream() const
Definition: DecoderBuffer.hxx:57
DecoderBuffer::Need
ConstBuffer< void > Need(size_t min_size)
Wait until this number of bytes are available.
DecoderClient
An interface between the decoder plugin and the MPD core.
Definition: Client.hxx:39
ConstBuffer< void >
Definition: ConstBuffer.hxx:45
ForeignFifoBuffer::Clear
void Clear()
Definition: ForeignFifoBuffer.hxx:133
ForeignFifoBuffer::Consume
void Consume(size_type n)
Marks a chunk as consumed.
Definition: ForeignFifoBuffer.hxx:200
InputStream
Definition: InputStream.hxx:36
DecoderBuffer::Clear
void Clear()
Definition: DecoderBuffer.hxx:61
ForeignFifoBuffer::GetAvailable
constexpr size_type GetAvailable() const
Definition: ForeignFifoBuffer.hxx:185
Compiler.h
DecoderBuffer
This objects handles buffered reads in decoder plugins easily.
Definition: DecoderBuffer.hxx:38
WritableBuffer::data
pointer_type data
Definition: WritableBuffer.hxx:90
ForeignFifoBuffer::Read
constexpr Range Read() const
Return a buffer range which may be read.
Definition: ForeignFifoBuffer.hxx:193
DecoderBuffer::GetAvailable
gcc_pure size_t GetAvailable() const
How many bytes are stored in the buffer?
Definition: DecoderBuffer.hxx:78
DecoderBuffer::Skip
bool Skip(size_t nbytes)
Skips the specified number of bytes, discarding its data.
DynamicFifoBuffer.hxx
DecoderBuffer::DecoderBuffer
DecoderBuffer(DecoderClient *_client, InputStream &_is, size_t _size)
Creates a new buffer.
Definition: DecoderBuffer.hxx:53
DynamicFifoBuffer< uint8_t >
ConstBuffer.hxx
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
DecoderBuffer::Read
ConstBuffer< void > Read() const
Reads data from the buffer.
Definition: DecoderBuffer.hxx:87
DecoderBuffer::Consume
void Consume(size_t nbytes)
Consume (delete, invalidate) a part of the buffer.
Definition: DecoderBuffer.hxx:105