MPD  0.20.15
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"
25 #include "util/ConstBuffer.hxx"
26 
27 #include <stddef.h>
28 #include <stdint.h>
29 
30 class DecoderClient;
31 class InputStream;
32 
39  DecoderClient *const client;
40  InputStream &is;
41 
43 
44 public:
54  size_t _size)
55  :client(_client), is(_is), buffer(_size) {}
56 
57  const InputStream &GetStream() const noexcept {
58  return is;
59  }
60 
61  void Clear() noexcept {
62  buffer.Clear();
63  }
64 
72  bool Fill();
73 
77  gcc_pure
78  size_t GetAvailable() const noexcept {
79  return buffer.GetAvailable();
80  }
81 
87  ConstBuffer<void> Read() const noexcept {
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) noexcept {
106  buffer.Consume(nbytes);
107  }
108 
115  bool Skip(size_t nbytes);
116 };
117 
118 #endif
bool Fill()
Read data from the InputStream and append it to the buffer.
ConstBuffer< void > Need(size_t min_size)
Wait until this number of bytes are available.
An interface between the decoder plugin and the MPD core.
Definition: Client.hxx:39
void Clear() noexcept
constexpr Range Read() const
Return a buffer range which may be read.
void Consume(size_type n)
Marks a chunk as consumed.
ConstBuffer< void > Read() const noexcept
Reads data from the buffer.
This objects handles buffered reads in decoder plugins easily.
pointer_type data
void Consume(size_t nbytes) noexcept
Consume (delete, invalidate) a part of the buffer.
const InputStream & GetStream() const noexcept
bool Skip(size_t nbytes)
Skips the specified number of bytes, discarding its data.
constexpr size_type GetAvailable() const
DecoderBuffer(DecoderClient *_client, InputStream &_is, size_t _size)
Creates a new buffer.
#define gcc_pure
Definition: Compiler.h:116
gcc_pure size_t GetAvailable() const noexcept
How many bytes are stored in the buffer?