2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2014-01-27 08:20:25 +01:00
|
|
|
|
|
|
|
#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"
|
2014-01-27 08:20:25 +01:00
|
|
|
|
2020-03-27 05:29:30 +01:00
|
|
|
#include <algorithm>
|
2020-03-12 23:20:59 +01:00
|
|
|
#include <cassert>
|
2019-04-26 14:28:59 +02:00
|
|
|
#include <memory>
|
2014-01-27 08:20:25 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
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 {
|
2020-01-20 14:51:06 +01:00
|
|
|
AudioOutputClient &client;
|
|
|
|
|
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.
|
|
|
|
*/
|
2020-01-20 14:51:06 +01:00
|
|
|
MultipleOutputs(AudioOutputClient &_client,
|
|
|
|
MixerListener &_mixer_listener) noexcept;
|
2017-12-29 16:29:49 +01:00
|
|
|
~MultipleOutputs() noexcept;
|
2014-01-27 08:20:25 +01:00
|
|
|
|
2021-02-24 16:06:06 +01:00
|
|
|
void Configure(EventLoop &event_loop, EventLoop &rt_event_loop,
|
2018-07-17 23:13:35 +02:00
|
|
|
const ConfigData &config,
|
2020-01-20 14:51:06 +01:00
|
|
|
const ReplayGainConfig &replay_gain_config);
|
2014-01-27 08:20:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the total number of audio output devices, including
|
|
|
|
* those which are disabled right now.
|
|
|
|
*/
|
2022-07-13 13:25:02 +02:00
|
|
|
[[gnu::pure]]
|
2022-07-13 13:25:59 +02:00
|
|
|
std::size_t Size() const noexcept {
|
2014-01-27 08:20:25 +01:00
|
|
|
return outputs.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the "i"th audio output device.
|
|
|
|
*/
|
2022-07-13 13:25:59 +02:00
|
|
|
const AudioOutputControl &Get(std::size_t i) const noexcept {
|
2014-01-27 08:20:25 +01:00
|
|
|
assert(i < Size());
|
|
|
|
|
|
|
|
return *outputs[i];
|
|
|
|
}
|
|
|
|
|
2022-07-13 13:25:59 +02:00
|
|
|
AudioOutputControl &Get(std::size_t i) noexcept {
|
2014-01-27 08:20:25 +01:00
|
|
|
assert(i < Size());
|
|
|
|
|
|
|
|
return *outputs[i];
|
|
|
|
}
|
|
|
|
|
2020-01-20 09:10:02 +01:00
|
|
|
/**
|
|
|
|
* Are all outputs dummy?
|
|
|
|
*/
|
2022-07-13 13:25:02 +02:00
|
|
|
[[gnu::pure]]
|
2020-01-20 09:10:02 +01:00
|
|
|
bool IsDummy() const noexcept {
|
2020-03-27 05:29:30 +01:00
|
|
|
return std::all_of(outputs.begin(), outputs.end(), [](const auto &i) { return i->IsDummy(); });
|
2020-01-20 09:10:02 +01:00
|
|
|
}
|
|
|
|
|
2014-01-27 08:20:25 +01:00
|
|
|
/**
|
|
|
|
* Returns the audio output device with the specified name.
|
|
|
|
* Returns nullptr if the name does not exist.
|
|
|
|
*/
|
2022-07-13 13:25:02 +02:00
|
|
|
[[gnu::pure]]
|
2022-07-13 11:32:29 +02:00
|
|
|
AudioOutputControl *FindByName(std::string_view 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?
|
|
|
|
*/
|
2022-07-13 13:25:02 +02:00
|
|
|
[[gnu::pure]]
|
2022-07-13 11:32:29 +02:00
|
|
|
bool HasName(std::string_view name) noexcept {
|
2019-09-26 14:40:19 +02:00
|
|
|
return FindByName(name) != nullptr;
|
|
|
|
}
|
|
|
|
|
2021-10-22 20:10:42 +02:00
|
|
|
void AddMoveFrom(AudioOutputControl &&src,
|
|
|
|
bool enable) noexcept;
|
2020-11-13 17:35:36 +01:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
2022-07-13 13:25:02 +02:00
|
|
|
[[gnu::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.
|
|
|
|
*
|
2022-07-08 10:46:15 +02:00
|
|
|
* Throws on error.
|
|
|
|
*
|
2014-01-27 08:20:25 +01:00
|
|
|
* @param volume the volume (range 0..100)
|
|
|
|
*/
|
2022-07-08 10:46:15 +02:00
|
|
|
void SetVolume(unsigned volume);
|
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.
|
|
|
|
*/
|
2022-07-13 13:25:02 +02:00
|
|
|
[[gnu::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 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
|