mixer/pipewire: new plugin

This commit is contained in:
Max Kellermann
2021-08-04 17:35:21 +02:00
parent b838bf3109
commit 968624035c
5 changed files with 180 additions and 2 deletions

View File

@@ -0,0 +1,91 @@
/*
* Copyright 2003-2021 The Music Player Daemon Project
* 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.
*/
#include "PipeWireMixerPlugin.hxx"
#include "mixer/MixerInternal.hxx"
#include "mixer/Listener.hxx"
#include "output/plugins/PipeWireOutputPlugin.hxx"
#include <cmath>
class PipeWireMixer final : public Mixer {
PipeWireOutput &output;
int volume = 100;
public:
PipeWireMixer(PipeWireOutput &_output,
MixerListener &_listener) noexcept
:Mixer(pipewire_mixer_plugin, _listener),
output(_output)
{
}
PipeWireMixer(const PipeWireMixer &) = delete;
PipeWireMixer &operator=(const PipeWireMixer &) = delete;
void OnVolumeChanged(float new_volume) noexcept {
volume = std::lround(new_volume * 100.f);
listener.OnMixerVolumeChanged(*this, volume);
}
/* virtual methods from class Mixer */
void Open() override {
}
void Close() noexcept override {
}
int GetVolume() override;
void SetVolume(unsigned volume) override;
};
void
pipewire_mixer_on_change(PipeWireMixer &pm, float new_volume) noexcept
{
pm.OnVolumeChanged(new_volume);
}
int
PipeWireMixer::GetVolume()
{
return volume;
}
void
PipeWireMixer::SetVolume(unsigned new_volume)
{
pipewire_output_set_volume(output, float(new_volume) * 0.01f);
volume = new_volume;
}
static Mixer *
pipewire_mixer_init([[maybe_unused]] EventLoop &event_loop, AudioOutput &ao,
MixerListener &listener,
const ConfigBlock &)
{
auto &po = (PipeWireOutput &)ao;
return new PipeWireMixer(po, listener);
}
const MixerPlugin pipewire_mixer_plugin = {
pipewire_mixer_init,
true,
};

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2003-2021 The Music Player Daemon Project
* 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 MPD_PIPEWIRE_MIXER_PLUGIN_HXX
#define MPD_PIPEWIRE_MIXER_PLUGIN_HXX
struct MixerPlugin;
class PipeWireMixer;
extern const MixerPlugin pipewire_mixer_plugin;
void
pipewire_mixer_on_change(PipeWireMixer &pm, float new_volume) noexcept;
#endif

View File

@@ -22,6 +22,10 @@ if is_darwin
mixer_plugins_sources += 'OSXMixerPlugin.cxx'
endif
if pipewire_dep.found()
mixer_plugins_sources += 'PipeWireMixerPlugin.cxx'
endif
if pulse_dep.found()
mixer_plugins_sources += 'PulseMixerPlugin.cxx'
endif