lib/alsa/NonBlock: use a persistent pollfd array
This implements the semantic API change introduced by commit
cd04da2bcf
This commit is contained in:
parent
4486b2eded
commit
90dfa437e0
1
NEWS
1
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
|
||||
|
|
|
@ -8,21 +8,23 @@
|
|||
namespace Alsa {
|
||||
|
||||
std::span<pollfd>
|
||||
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<pollfd> pfds = buffer;
|
||||
|
||||
auto *i = pfds;
|
||||
m.ForEachReturnedEvent([&i, end](SocketDescriptor s, unsigned events){
|
||||
if (i >= end)
|
||||
for (auto &i : pfds)
|
||||
i.revents = 0;
|
||||
|
||||
m.ForEachReturnedEvent([pfds](SocketDescriptor s, unsigned events){
|
||||
for (auto &i : pfds) {
|
||||
if (i.fd == s.Get()) {
|
||||
i.revents = events;
|
||||
return;
|
||||
|
||||
i->fd = s.Get();
|
||||
i->events = i->revents = events;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return {pfds, static_cast<std::size_t>(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);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "event/Chrono.hxx"
|
||||
#include "util/ReusableArray.hxx"
|
||||
#include "util/AllocatedArray.hxx"
|
||||
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
|
@ -15,15 +15,15 @@ class MultiSocketMonitor;
|
|||
namespace Alsa {
|
||||
|
||||
class NonBlock {
|
||||
ReusableArray<pollfd> buffer;
|
||||
AllocatedArray<pollfd> buffer;
|
||||
|
||||
public:
|
||||
std::span<pollfd> Allocate(std::size_t n) noexcept {
|
||||
return {buffer.Get(n), n};
|
||||
buffer.ResizeDiscard(n);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::span<pollfd> CopyReturnedEvents(MultiSocketMonitor &m,
|
||||
std::size_t n) noexcept;
|
||||
std::span<pollfd> CopyReturnedEvents(MultiSocketMonitor &m) noexcept;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue