diff --git a/NEWS b/NEWS index 433328caf..8eb412698 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,7 @@ ver 0.24 (not yet released) * input - alsa: limit ALSA buffer time to 2 seconds - alsa: set up a channel map + - alsa: support the alsa-lib 1.2.11 API - curl: add "connect_timeout" configuration * decoder - ffmpeg: require FFmpeg 4.0 or later diff --git a/src/lib/alsa/NonBlock.cxx b/src/lib/alsa/NonBlock.cxx index a20255bcc..3e7c5f86c 100644 --- a/src/lib/alsa/NonBlock.cxx +++ b/src/lib/alsa/NonBlock.cxx @@ -8,21 +8,23 @@ namespace Alsa { std::span -NonBlock::CopyReturnedEvents(MultiSocketMonitor &m, std::size_t n) noexcept +NonBlock::CopyReturnedEvents(MultiSocketMonitor &m) noexcept { - const auto pfds = buffer.Get(n), end = pfds + n; + const std::span pfds = buffer; - auto *i = pfds; - m.ForEachReturnedEvent([&i, end](SocketDescriptor s, unsigned events){ - if (i >= end) - return; + for (auto &i : pfds) + i.revents = 0; - i->fd = s.Get(); - i->events = i->revents = events; - ++i; + m.ForEachReturnedEvent([pfds](SocketDescriptor s, unsigned events){ + for (auto &i : pfds) { + if (i.fd == s.Get()) { + i.revents = events; + return; + } + } }); - return {pfds, static_cast(i - pfds)}; + return pfds; } @@ -54,11 +56,7 @@ NonBlockPcm::PrepareSockets(MultiSocketMonitor &m, snd_pcm_t *pcm) void NonBlockPcm::DispatchSockets(MultiSocketMonitor &m, snd_pcm_t *pcm) { - int count = snd_pcm_poll_descriptors_count(pcm); - if (count <= 0) - return; - - const auto pfds = base.CopyReturnedEvents(m, count); + const auto pfds = base.CopyReturnedEvents(m); unsigned short dummy; int err = snd_pcm_poll_descriptors_revents(pcm, pfds.data(), pfds.size(), &dummy); @@ -88,11 +86,7 @@ NonBlockMixer::PrepareSockets(MultiSocketMonitor &m, snd_mixer_t *mixer) noexcep void NonBlockMixer::DispatchSockets(MultiSocketMonitor &m, snd_mixer_t *mixer) noexcept { - int count = snd_mixer_poll_descriptors_count(mixer); - if (count <= 0) - return; - - const auto pfds = base.CopyReturnedEvents(m, count); + const auto pfds = base.CopyReturnedEvents(m); unsigned short dummy; snd_mixer_poll_descriptors_revents(mixer, pfds.data(), pfds.size(), &dummy); diff --git a/src/lib/alsa/NonBlock.hxx b/src/lib/alsa/NonBlock.hxx index 16cfb3102..0b523f166 100644 --- a/src/lib/alsa/NonBlock.hxx +++ b/src/lib/alsa/NonBlock.hxx @@ -4,7 +4,7 @@ #pragma once #include "event/Chrono.hxx" -#include "util/ReusableArray.hxx" +#include "util/AllocatedArray.hxx" #include @@ -15,15 +15,15 @@ class MultiSocketMonitor; namespace Alsa { class NonBlock { - ReusableArray buffer; + AllocatedArray buffer; public: std::span Allocate(std::size_t n) noexcept { - return {buffer.Get(n), n}; + buffer.ResizeDiscard(n); + return buffer; } - std::span CopyReturnedEvents(MultiSocketMonitor &m, - std::size_t n) noexcept; + std::span CopyReturnedEvents(MultiSocketMonitor &m) noexcept; }; /**