MPD  0.20.15
MultipleOutputs.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 /*
21  * Functions for dealing with all configured (enabled) audion outputs
22  * at once.
23  *
24  */
25 
26 #ifndef OUTPUT_ALL_H
27 #define OUTPUT_ALL_H
28 
29 #include "AudioFormat.hxx"
30 #include "ReplayGainMode.hxx"
31 #include "Chrono.hxx"
32 #include "Compiler.h"
33 
34 #include <vector>
35 
36 #include <assert.h>
37 
38 class MusicBuffer;
39 class MusicPipe;
40 class EventLoop;
41 class MixerListener;
42 class AudioOutputClient;
43 struct MusicChunk;
44 struct AudioOutput;
45 struct ReplayGainConfig;
46 
48  MixerListener &mixer_listener;
49 
50  std::vector<AudioOutput *> outputs;
51 
52  AudioFormat input_audio_format = AudioFormat::Undefined();
53 
57  MusicBuffer *buffer = nullptr;
58 
63  MusicPipe *pipe = nullptr;
64 
70 
71 public:
76  MultipleOutputs(MixerListener &_mixer_listener);
78 
79  void Configure(EventLoop &event_loop,
80  const ReplayGainConfig &replay_gain_config,
81  AudioOutputClient &client);
82 
87  gcc_pure
88  unsigned Size() const noexcept {
89  return outputs.size();
90  }
91 
95  const AudioOutput &Get(unsigned i) const {
96  assert(i < Size());
97 
98  return *outputs[i];
99  }
100 
101  AudioOutput &Get(unsigned i) {
102  assert(i < Size());
103 
104  return *outputs[i];
105  }
106 
111  gcc_pure
112  AudioOutput *FindByName(const char *name) const noexcept;
113 
118  void EnableDisable();
119 
129  void Open(const AudioFormat audio_format, MusicBuffer &_buffer);
130 
134  void Close();
135 
140  void Release();
141 
143 
152  void Play(MusicChunk *chunk);
153 
160  unsigned Check();
161 
166  void Pause();
167 
171  void Drain();
172 
176  void Cancel();
177 
181  void SongBorder();
182 
188  gcc_pure
189  SignedSongTime GetElapsedTime() const noexcept {
190  return elapsed_time;
191  }
192 
197  gcc_pure
198  int GetVolume() const noexcept;
199 
206  bool SetVolume(unsigned volume) noexcept;
207 
213  gcc_pure
214  int GetSoftwareVolume() const noexcept;
215 
222  void SetSoftwareVolume(unsigned volume) noexcept;
223 
224 private:
229  gcc_pure
230  bool AllFinished() const noexcept;
231 
232  void WaitAll() noexcept;
233 
237  void AllowPlay();
238 
245  bool Update(bool force);
246 
250  bool IsChunkConsumed(const MusicChunk *chunk) const noexcept;
251 
257  void ClearTailChunk(const MusicChunk *chunk, bool *locked);
258 };
259 
260 #endif
ReplayGainMode
This structure describes the format of a raw PCM stream.
Definition: AudioFormat.hxx:37
An interface between the AudioOutput and the #Player.
Definition: Client.hxx:28
bool SetVolume(unsigned volume) noexcept
Sets the volume on all available mixers.
void Open(const AudioFormat audio_format, MusicBuffer &_buffer)
Opens all audio outputs which are not disabled.
void Pause()
Puts all audio outputs into pause mode.
A queue of MusicChunk objects.
Definition: MusicPipe.hxx:39
void SetReplayGainMode(ReplayGainMode mode)
void Drain()
Drain all audio outputs.
An event loop that polls for events on file/socket descriptors.
Definition: Loop.hxx:51
gcc_pure unsigned Size() const noexcept
Returns the total number of audio output devices, including those which are disabled right now...
MultipleOutputs(MixerListener &_mixer_listener)
Load audio outputs from the configuration file and initialize them.
unsigned Check()
Checks if the output devices have drained their music pipe, and returns the consumed music chunks to ...
An allocator for MusicChunk objects.
Definition: MusicBuffer.hxx:31
void Play(MusicChunk *chunk)
Enqueue a MusicChunk object for playing, i.e.
void Release()
Closes all audio outputs.
static constexpr AudioFormat Undefined()
Definition: AudioFormat.hxx:75
static constexpr SignedSongTime Negative()
Generate a negative value.
Definition: Chrono.hxx:137
A chunk of music data.
Definition: MusicChunk.hxx:43
gcc_pure SignedSongTime GetElapsedTime() const noexcept
Returns the "elapsed_time" stamp of the most recently finished chunk.
void Close()
Closes all audio outputs.
void SetSoftwareVolume(unsigned volume) noexcept
Similar to SetVolume(), but sets the volume only for software mixers.
void EnableDisable()
Checks the "enabled" flag of all audio outputs, and if one has changed, commit the change...
void Cancel()
Try to cancel data which may still be in the device&#39;s buffers.
gcc_pure AudioOutput * FindByName(const char *name) const noexcept
Returns the audio output device with the specified name.
A variant of SongTime that is based on a signed integer.
Definition: Chrono.hxx:115
An interface that listens on events from mixer plugins.
Definition: Listener.hxx:29
void SongBorder()
Indicate that a new song will begin now.
void Configure(EventLoop &event_loop, const ReplayGainConfig &replay_gain_config, AudioOutputClient &client)
AudioOutput & Get(unsigned i)
gcc_pure int GetVolume() const noexcept
Returns the average volume of all available mixers (range 0..100).
const AudioOutput & Get(unsigned i) const
Returns the "i"th audio output device.
#define gcc_pure
Definition: Compiler.h:116
gcc_pure int GetSoftwareVolume() const noexcept
Similar to GetVolume(), but gets the volume only for software mixers.
const Partition const char * name
Definition: Count.hxx:34