2014-01-27 08:20:25 +01:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 The Music Player Daemon Project
|
2014-01-27 08:20:25 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OUTPUT_ALL_H
|
|
|
|
#define OUTPUT_ALL_H
|
|
|
|
|
2017-02-27 22:55:20 +01:00
|
|
|
#include "Control.hxx"
|
2017-12-30 18:00:40 +01:00
|
|
|
#include "MusicChunkPtr.hxx"
|
2017-12-29 16:23:19 +01:00
|
|
|
#include "player/Outputs.hxx"
|
2020-01-18 20:07:09 +01:00
|
|
|
#include "pcm/AudioFormat.hxx"
|
2016-11-24 16:40:47 +01:00
|
|
|
#include "ReplayGainMode.hxx"
|
2014-08-29 13:13:08 +02:00
|
|
|
#include "Chrono.hxx"
|
2018-08-20 16:19:17 +02:00
|
|
|
#include "util/Compiler.h"
|
2014-01-27 08:20:25 +01:00
|
|
|
|
2019-04-26 14:28:59 +02:00
|
|
|
#include <memory>
|
2014-01-27 08:20:25 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
class MusicPipe;
|
2014-02-05 00:02:02 +01:00
|
|
|
class EventLoop;
|
2014-02-05 23:20:33 +01:00
|
|
|
class MixerListener;
|
2016-12-14 12:14:57 +01:00
|
|
|
class AudioOutputClient;
|
2018-07-17 23:13:35 +02:00
|
|
|
struct ConfigData;
|
2016-11-25 13:54:55 +01:00
|
|
|
struct ReplayGainConfig;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
2020-01-18 19:21:51 +01:00
|
|
|
/*
|
|
|
|
* Wrap multiple #AudioOutputControl objects a single interface which
|
|
|
|
* keeps them synchronized.
|
|
|
|
*/
|
2017-12-29 16:23:19 +01:00
|
|
|
class MultipleOutputs final : public PlayerOutputs {
|
2014-02-05 23:20:33 +01:00
|
|
|
MixerListener &mixer_listener;
|
|
|
|
|
2019-04-26 14:28:59 +02:00
|
|
|
std::vector<std::unique_ptr<AudioOutputControl>> outputs;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
2016-04-21 13:27:45 +02:00
|
|
|
AudioFormat input_audio_format = AudioFormat::Undefined();
|
2014-01-27 08:20:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The #MusicPipe object which feeds all audio outputs. It is
|
2018-06-22 22:59:30 +02:00
|
|
|
* filled by Play().
|
2014-01-27 08:20:25 +01:00
|
|
|
*/
|
2018-06-23 18:45:57 +02:00
|
|
|
std::unique_ptr<MusicPipe> pipe;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The "elapsed_time" stamp of the most recently finished
|
|
|
|
* chunk.
|
|
|
|
*/
|
2016-04-21 13:27:45 +02:00
|
|
|
SignedSongTime elapsed_time = SignedSongTime::Negative();
|
2014-01-27 08:20:25 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Load audio outputs from the configuration file and
|
|
|
|
* initialize them.
|
|
|
|
*/
|
2017-12-29 16:29:49 +01:00
|
|
|
MultipleOutputs(MixerListener &_mixer_listener) noexcept;
|
|
|
|
~MultipleOutputs() noexcept;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
2016-11-25 13:54:55 +01:00
|
|
|
void Configure(EventLoop &event_loop,
|
2018-07-17 23:13:35 +02:00
|
|
|
const ConfigData &config,
|
2016-11-25 13:54:55 +01:00
|
|
|
const ReplayGainConfig &replay_gain_config,
|
2016-12-14 12:14:57 +01:00
|
|
|
AudioOutputClient &client);
|
2014-01-27 08:20:25 +01:00
|
|
|
|
2017-02-17 23:53:44 +01:00
|
|
|
void AddNullOutput(EventLoop &event_loop,
|
|
|
|
const ReplayGainConfig &replay_gain_config,
|
|
|
|
AudioOutputClient &client);
|
|
|
|
|
2014-01-27 08:20:25 +01:00
|
|
|
/**
|
|
|
|
* Returns the total number of audio output devices, including
|
|
|
|
* those which are disabled right now.
|
|
|
|
*/
|
|
|
|
gcc_pure
|
2017-06-03 21:33:44 +02:00
|
|
|
unsigned Size() const noexcept {
|
2014-01-27 08:20:25 +01:00
|
|
|
return outputs.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the "i"th audio output device.
|
|
|
|
*/
|
2017-12-29 16:29:49 +01:00
|
|
|
const AudioOutputControl &Get(unsigned i) const noexcept {
|
2014-01-27 08:20:25 +01:00
|
|
|
assert(i < Size());
|
|
|
|
|
|
|
|
return *outputs[i];
|
|
|
|
}
|
|
|
|
|
2017-12-29 16:29:49 +01:00
|
|
|
AudioOutputControl &Get(unsigned i) noexcept {
|
2014-01-27 08:20:25 +01:00
|
|
|
assert(i < Size());
|
|
|
|
|
|
|
|
return *outputs[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the audio output device with the specified name.
|
|
|
|
* Returns nullptr if the name does not exist.
|
|
|
|
*/
|
|
|
|
gcc_pure
|
2017-05-15 23:01:49 +02:00
|
|
|
AudioOutputControl *FindByName(const char *name) noexcept;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
2019-09-26 14:40:19 +02:00
|
|
|
/**
|
|
|
|
* Does an audio output device with this name exist?
|
|
|
|
*/
|
|
|
|
gcc_pure
|
|
|
|
bool HasName(const char *name) noexcept {
|
|
|
|
return FindByName(name) != nullptr;
|
|
|
|
}
|
|
|
|
|
2019-09-26 13:02:34 +02:00
|
|
|
void Add(std::unique_ptr<FilteredAudioOutput> output,
|
|
|
|
bool enable) noexcept;
|
|
|
|
|
2017-12-29 16:29:49 +01:00
|
|
|
void SetReplayGainMode(ReplayGainMode mode) noexcept;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the average volume of all available mixers (range
|
|
|
|
* 0..100). Returns -1 if no mixer can be queried.
|
|
|
|
*/
|
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
int GetVolume() const noexcept;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the volume on all available mixers.
|
|
|
|
*
|
|
|
|
* @param volume the volume (range 0..100)
|
|
|
|
* @return true on success, false on failure
|
|
|
|
*/
|
2017-05-08 14:44:49 +02:00
|
|
|
bool SetVolume(unsigned volume) noexcept;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Similar to GetVolume(), but gets the volume only for
|
|
|
|
* software mixers. See #software_mixer_plugin. This
|
|
|
|
* function fails if no software mixer is configured.
|
|
|
|
*/
|
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
int GetSoftwareVolume() const noexcept;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Similar to SetVolume(), but sets the volume only for
|
|
|
|
* software mixers. See #software_mixer_plugin. This
|
|
|
|
* function cannot fail, because the underlying software
|
|
|
|
* mixers cannot fail either.
|
|
|
|
*/
|
2017-05-08 14:44:49 +02:00
|
|
|
void SetSoftwareVolume(unsigned volume) noexcept;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
|
|
|
private:
|
2019-09-26 13:02:34 +02:00
|
|
|
AudioOutputClient &GetAnyClient() noexcept {
|
|
|
|
return outputs.front()->GetClient();
|
|
|
|
}
|
|
|
|
|
2019-09-26 14:52:19 +02:00
|
|
|
/**
|
|
|
|
* Was Open() called successfully?
|
|
|
|
*
|
|
|
|
* This method may only be called from the player thread.
|
|
|
|
*/
|
|
|
|
bool IsOpen() const noexcept {
|
|
|
|
return input_audio_format.IsDefined();
|
|
|
|
}
|
|
|
|
|
2014-01-27 08:20:25 +01:00
|
|
|
/**
|
2018-06-23 19:11:48 +02:00
|
|
|
* Wait until all (active) outputs have finished the current
|
2014-01-27 08:20:25 +01:00
|
|
|
* command.
|
|
|
|
*/
|
2017-05-08 14:44:49 +02:00
|
|
|
void WaitAll() noexcept;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals all audio outputs which are open.
|
|
|
|
*/
|
2017-12-29 16:29:49 +01:00
|
|
|
void AllowPlay() noexcept;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens all output devices which are enabled, but closed.
|
|
|
|
*
|
|
|
|
* @return true if there is at least open output device which
|
|
|
|
* is open
|
|
|
|
*/
|
2017-12-29 16:29:49 +01:00
|
|
|
bool Update(bool force) noexcept;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Has this chunk been consumed by all audio outputs?
|
|
|
|
*/
|
2017-05-08 14:44:49 +02:00
|
|
|
bool IsChunkConsumed(const MusicChunk *chunk) const noexcept;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
2017-12-29 16:23:19 +01:00
|
|
|
/* virtual methods from class PlayerOutputs */
|
|
|
|
void EnableDisable() override;
|
2018-06-23 18:04:09 +02:00
|
|
|
void Open(const AudioFormat audio_format) override;
|
2017-12-29 16:23:19 +01:00
|
|
|
void Close() noexcept override;
|
|
|
|
void Release() noexcept override;
|
2017-12-30 18:00:40 +01:00
|
|
|
void Play(MusicChunkPtr chunk) override;
|
2017-12-29 16:23:19 +01:00
|
|
|
unsigned CheckPipe() noexcept override;
|
|
|
|
void Pause() noexcept override;
|
|
|
|
void Drain() noexcept override;
|
|
|
|
void Cancel() noexcept override;
|
|
|
|
void SongBorder() noexcept override;
|
|
|
|
SignedSongTime GetElapsedTime() const noexcept override {
|
|
|
|
return elapsed_time;
|
|
|
|
}
|
2014-01-27 08:20:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|