MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

MusicPipe.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_PIPE_H
21 #define MPD_PIPE_H
22
23 #include "thread/Mutex.hxx"
24 #include "Compiler.h"
25
26 #ifndef NDEBUG
27 #include "AudioFormat.hxx"
28 #endif
29
30 #include <assert.h>
31
32 struct MusicChunk;
33 class MusicBuffer;
34
39 class MusicPipe {
41 MusicChunk *head = nullptr;
42
44 MusicChunk **tail_r = &head;
45
47 unsigned size = 0;
48
50 mutable Mutex mutex;
51
52 #ifndef NDEBUG
53 AudioFormat audio_format = AudioFormat::Undefined();
54 #endif
55
56 public:
60 MusicPipe() = default;
61
62 MusicPipe(const MusicPipe &) = delete;
63
67 ~MusicPipe() {
68 assert(head == nullptr);
69 assert(tail_r == &head);
70 }
71
72 MusicPipe &operator=(const MusicPipe &) = delete;
73
74 #ifndef NDEBUG
75
79 gcc_pure
80 bool CheckFormat(AudioFormat other) const {
81 return !audio_format.IsDefined() ||
82 audio_format == other;
83 }
84
88 gcc_pure
89 bool Contains(const MusicChunk *chunk) const;
90 #endif
91
96 gcc_pure
97 const MusicChunk *Peek() const {
98 return head;
99 }
100
104 MusicChunk *Shift();
105
111 void Clear(MusicBuffer &buffer);
112
116 void Push(MusicChunk *chunk);
117
121 gcc_pure
122 unsigned GetSize() const {
123 return size;
124 }
125
126 gcc_pure
127 bool IsEmpty() const {
128 return GetSize() == 0;
129 }
130 };
131
132 #endif
AudioFormat
This structure describes the format of a raw PCM stream.
Definition: AudioFormat.hxx:37
MusicPipe::CheckFormat
gcc_pure bool CheckFormat(AudioFormat other) const
Checks if the audio format if the chunk is equal to the specified audio_format.
Definition: MusicPipe.hxx:80
MusicPipe::Contains
gcc_pure bool Contains(const MusicChunk *chunk) const
Checks if the specified chunk is enqueued in the music pipe.
MusicPipe::GetSize
gcc_pure unsigned GetSize() const
Returns the number of chunks currently in this pipe.
Definition: MusicPipe.hxx:122
MusicPipe
A queue of MusicChunk objects.
Definition: MusicPipe.hxx:39
AudioFormat.hxx
Mutex
Definition: Mutex.hxx:43
MusicBuffer
An allocator for MusicChunk objects.
Definition: MusicBuffer.hxx:31
AudioFormat::Undefined
static constexpr AudioFormat Undefined()
Definition: AudioFormat.hxx:75
MusicChunk
A chunk of music data.
Definition: MusicChunk.hxx:43
MusicPipe::Clear
void Clear(MusicBuffer &buffer)
Clears the whole pipe and returns the chunks to the buffer.
Compiler.h
MusicPipe::Push
void Push(MusicChunk *chunk)
Pushes a chunk to the tail of the pipe.
MusicPipe::~MusicPipe
~MusicPipe()
Frees the object.
Definition: MusicPipe.hxx:67
MusicPipe::MusicPipe
MusicPipe()=default
Creates a new MusicPipe object.
MusicPipe::IsEmpty
gcc_pure bool IsEmpty() const
Definition: MusicPipe.hxx:127
MusicPipe::Shift
MusicChunk * Shift()
Removes the first chunk from the head, and returns it.
Mutex.hxx
MusicPipe::operator=
MusicPipe & operator=(const MusicPipe &)=delete
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
MusicPipe::Peek
gcc_pure const MusicChunk * Peek() const
Returns the first MusicChunk from the pipe.
Definition: MusicPipe.hxx:97
AudioFormat::IsDefined
constexpr bool IsDefined() const
Checks whether the object has a defined value.
Definition: AudioFormat.hxx:92