MPD  0.20.18
Source.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 AUDIO_OUTPUT_SOURCE_HXX
21 #define AUDIO_OUTPUT_SOURCE_HXX
22 
23 #include "check.h"
24 #include "Compiler.h"
25 #include "SharedPipeConsumer.hxx"
26 #include "AudioFormat.hxx"
27 #include "ReplayGainMode.hxx"
28 #include "pcm/PcmBuffer.hxx"
29 #include "pcm/PcmDither.hxx"
30 #include "util/ConstBuffer.hxx"
31 
32 #include <utility>
33 
34 #include <assert.h>
35 #include <stdint.h>
36 
37 struct MusicChunk;
38 struct Tag;
39 class Mutex;
40 class Filter;
41 class PreparedFilter;
42 
54  AudioFormat in_audio_format = AudioFormat::Undefined();
55 
56  ReplayGainMode replay_gain_mode = ReplayGainMode::OFF;
57 
61  SharedPipeConsumer pipe;
62 
67  unsigned replay_gain_serial;
68 
73  unsigned other_replay_gain_serial;
74 
79  Filter *replay_gain_filter_instance = nullptr;
80 
86  Filter *other_replay_gain_filter_instance = nullptr;
87 
91  PcmBuffer cross_fade_buffer;
92 
96  PcmDither cross_fade_dither;
97 
102  Filter *filter_instance = nullptr;
103 
108  const MusicChunk *current_chunk = nullptr;
109 
113  const Tag *pending_tag;
114 
119  ConstBuffer<uint8_t> pending_data;
120 
121 public:
123  replay_gain_mode = _mode;
124  }
125 
126  bool IsOpen() const {
127  return in_audio_format.IsDefined();
128  }
129 
131  assert(IsOpen());
132 
133  return in_audio_format;
134  }
135 
136  AudioFormat Open(AudioFormat audio_format, const MusicPipe &_pipe,
137  PreparedFilter *prepared_replay_gain_filter,
138  PreparedFilter *prepared_other_replay_gain_filter,
139  PreparedFilter *prepared_filter);
140 
141  void Close() noexcept;
142  void Cancel() noexcept;
143 
155  bool Fill(Mutex &mutex);
156 
161  const Tag *ReadTag() noexcept {
162  assert(current_chunk != nullptr);
163 
164  return std::exchange(pending_tag, nullptr);
165  }
166 
175  ConstBuffer<void> PeekData() const noexcept {
176  return pending_data.ToVoid();
177  }
178 
182  void ConsumeData(size_t nbytes) noexcept;
183 
184  bool IsChunkConsumed(const MusicChunk &chunk) const noexcept {
185  assert(IsOpen());
186 
187  return pipe.IsConsumed(chunk);
188  }
189 
190  void ClearTailChunk(const MusicChunk &chunk) noexcept {
191  pipe.ClearTail(chunk);
192  }
193 
194 private:
195  void OpenFilter(AudioFormat audio_format,
196  PreparedFilter *prepared_replay_gain_filter,
197  PreparedFilter *prepared_other_replay_gain_filter,
198  PreparedFilter *prepared_filter);
199 
200  void CloseFilter() noexcept;
201 
202  ConstBuffer<void> GetChunkData(const MusicChunk &chunk,
203  Filter *replay_gain_filter,
204  unsigned *replay_gain_serial_p);
205 
206  ConstBuffer<void> FilterChunk(const MusicChunk &chunk);
207 };
208 
209 #endif
bool IsChunkConsumed(const MusicChunk &chunk) const noexcept
Definition: Source.hxx:184
ReplayGainMode
This structure describes the format of a raw PCM stream.
Definition: AudioFormat.hxx:37
A utility class which helps with consuming data from a MusicPipe.
bool IsOpen() const
Definition: Source.hxx:126
A queue of MusicChunk objects.
Definition: MusicPipe.hxx:39
The meta information about a song file.
Definition: Tag.hxx:34
Definition: Mutex.hxx:43
static constexpr AudioFormat Undefined()
Definition: AudioFormat.hxx:75
A chunk of music data.
Definition: MusicChunk.hxx:43
void ClearTail(gcc_unused const MusicChunk &_chunk) noexcept
Source of audio data to be played by an AudioOutput.
Definition: Source.hxx:49
const Tag * ReadTag() noexcept
Reads the Tag to be processed.
Definition: Source.hxx:161
gcc_pure bool IsConsumed(const MusicChunk &_chunk) const noexcept
constexpr ConstBuffer< void > ToVoid() const
void Close() noexcept
Manager for a temporary buffer which grows as needed.
Definition: PcmBuffer.hxx:33
AudioFormat Open(AudioFormat audio_format, const MusicPipe &_pipe, PreparedFilter *prepared_replay_gain_filter, PreparedFilter *prepared_other_replay_gain_filter, PreparedFilter *prepared_filter)
constexpr bool IsDefined() const
Checks whether the object has a defined value.
Definition: AudioFormat.hxx:92
void ConsumeData(size_t nbytes) noexcept
Mark portions of the PeekData() return value as "consumed".
void SetReplayGainMode(ReplayGainMode _mode)
Definition: Source.hxx:122
bool Fill(Mutex &mutex)
Ensure that ReadTag() or PeekData() return any input.
const AudioFormat & GetInputAudioFormat() const
Definition: Source.hxx:130
void Cancel() noexcept
ConstBuffer< void > PeekData() const noexcept
Returns the remaining filtered PCM data be played.
Definition: Source.hxx:175
void ClearTailChunk(const MusicChunk &chunk) noexcept
Definition: Source.hxx:190