diff options
Diffstat (limited to 'src/mixer/AlsaMixerPlugin.cxx')
-rw-r--r-- | src/mixer/AlsaMixerPlugin.cxx | 48 |
1 files changed, 13 insertions, 35 deletions
diff --git a/src/mixer/AlsaMixerPlugin.cxx b/src/mixer/AlsaMixerPlugin.cxx index 4a4ca433c..4f92e697d 100644 --- a/src/mixer/AlsaMixerPlugin.cxx +++ b/src/mixer/AlsaMixerPlugin.cxx @@ -23,10 +23,11 @@ #include "GlobalEvents.hxx" #include "Main.hxx" #include "event/MultiSocketMonitor.hxx" +#include "event/DeferredMonitor.hxx" #include "event/Loop.hxx" -#include "event/Call.hxx" #include "util/ASCII.hxx" #include "util/ReusableArray.hxx" +#include "util/Clamp.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" #include "Log.hxx" @@ -39,29 +40,22 @@ #define VOLUME_MIXER_ALSA_CONTROL_DEFAULT "PCM" static constexpr unsigned VOLUME_MIXER_ALSA_INDEX_DEFAULT = 0; -class AlsaMixerMonitor final : private MultiSocketMonitor { +class AlsaMixerMonitor final : MultiSocketMonitor, DeferredMonitor { snd_mixer_t *mixer; ReusableArray<pollfd> pfd_buffer; public: AlsaMixerMonitor(EventLoop &_loop, snd_mixer_t *_mixer) - :MultiSocketMonitor(_loop), mixer(_mixer) { -#ifdef USE_EPOLL - _loop.AddCall([this](){ InvalidateSockets(); }); -#else - _loop.AddIdle(InitAlsaMixerMonitor, this); -#endif + :MultiSocketMonitor(_loop), DeferredMonitor(_loop), + mixer(_mixer) { + DeferredMonitor::Schedule(); } private: -#ifndef USE_EPOLL - static gboolean InitAlsaMixerMonitor(gpointer data) { - AlsaMixerMonitor &amm = *(AlsaMixerMonitor *)data; - amm.InvalidateSockets(); - return false; + virtual void RunDeferred() override { + InvalidateSockets(); } -#endif virtual int PrepareSockets() override; virtual void DispatchSockets() override; @@ -97,8 +91,10 @@ static constexpr Domain alsa_mixer_domain("alsa_mixer"); int AlsaMixerMonitor::PrepareSockets() { - if (mixer == nullptr) + if (mixer == nullptr) { + ClearSocketList(); return -1; + } int count = snd_mixer_poll_descriptors_count(mixer); if (count < 0) @@ -110,24 +106,7 @@ AlsaMixerMonitor::PrepareSockets() if (count < 0) count = 0; - struct pollfd *end = pfds + count; - - UpdateSocketList([pfds, end](int fd) -> unsigned { - auto i = std::find_if(pfds, end, [fd](const struct pollfd &pfd){ - return pfd.fd == fd; - }); - if (i == end) - return 0; - - auto events = i->events; - i->events = 0; - return events; - }); - - for (auto i = pfds; i != end; ++i) - if (i->events != 0) - AddSocket(i->fd, i->events); - + ReplaceSocketList(pfds, count); return -1; } @@ -372,8 +351,7 @@ AlsaMixer::SetVolume(unsigned volume, Error &error) level = (long)(((vol / 100.0) * (volume_max - volume_min) + volume_min) + 0.5); - level = level > volume_max ? volume_max : level; - level = level < volume_min ? volume_min : level; + level = Clamp(level, volume_min, volume_max); err = snd_mixer_selem_set_playback_volume_all(elem, level); if (err < 0) { |