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
|
* input
|
||||||
- alsa: limit ALSA buffer time to 2 seconds
|
- alsa: limit ALSA buffer time to 2 seconds
|
||||||
- alsa: set up a channel map
|
- alsa: set up a channel map
|
||||||
|
- alsa: support the alsa-lib 1.2.11 API
|
||||||
- curl: add "connect_timeout" configuration
|
- curl: add "connect_timeout" configuration
|
||||||
* decoder
|
* decoder
|
||||||
- ffmpeg: require FFmpeg 4.0 or later
|
- ffmpeg: require FFmpeg 4.0 or later
|
||||||
|
|
|
@ -8,21 +8,23 @@
|
||||||
namespace Alsa {
|
namespace Alsa {
|
||||||
|
|
||||||
std::span<pollfd>
|
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;
|
for (auto &i : pfds)
|
||||||
m.ForEachReturnedEvent([&i, end](SocketDescriptor s, unsigned events){
|
i.revents = 0;
|
||||||
if (i >= end)
|
|
||||||
return;
|
|
||||||
|
|
||||||
i->fd = s.Get();
|
m.ForEachReturnedEvent([pfds](SocketDescriptor s, unsigned events){
|
||||||
i->events = i->revents = events;
|
for (auto &i : pfds) {
|
||||||
++i;
|
if (i.fd == s.Get()) {
|
||||||
|
i.revents = events;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return {pfds, static_cast<std::size_t>(i - pfds)};
|
return pfds;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,11 +56,7 @@ NonBlockPcm::PrepareSockets(MultiSocketMonitor &m, snd_pcm_t *pcm)
|
||||||
void
|
void
|
||||||
NonBlockPcm::DispatchSockets(MultiSocketMonitor &m, snd_pcm_t *pcm)
|
NonBlockPcm::DispatchSockets(MultiSocketMonitor &m, snd_pcm_t *pcm)
|
||||||
{
|
{
|
||||||
int count = snd_pcm_poll_descriptors_count(pcm);
|
const auto pfds = base.CopyReturnedEvents(m);
|
||||||
if (count <= 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const auto pfds = base.CopyReturnedEvents(m, count);
|
|
||||||
|
|
||||||
unsigned short dummy;
|
unsigned short dummy;
|
||||||
int err = snd_pcm_poll_descriptors_revents(pcm, pfds.data(), pfds.size(), &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
|
void
|
||||||
NonBlockMixer::DispatchSockets(MultiSocketMonitor &m, snd_mixer_t *mixer) noexcept
|
NonBlockMixer::DispatchSockets(MultiSocketMonitor &m, snd_mixer_t *mixer) noexcept
|
||||||
{
|
{
|
||||||
int count = snd_mixer_poll_descriptors_count(mixer);
|
const auto pfds = base.CopyReturnedEvents(m);
|
||||||
if (count <= 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const auto pfds = base.CopyReturnedEvents(m, count);
|
|
||||||
|
|
||||||
unsigned short dummy;
|
unsigned short dummy;
|
||||||
snd_mixer_poll_descriptors_revents(mixer, pfds.data(), pfds.size(), &dummy);
|
snd_mixer_poll_descriptors_revents(mixer, pfds.data(), pfds.size(), &dummy);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "event/Chrono.hxx"
|
#include "event/Chrono.hxx"
|
||||||
#include "util/ReusableArray.hxx"
|
#include "util/AllocatedArray.hxx"
|
||||||
|
|
||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
|
|
||||||
|
@ -15,15 +15,15 @@ class MultiSocketMonitor;
|
||||||
namespace Alsa {
|
namespace Alsa {
|
||||||
|
|
||||||
class NonBlock {
|
class NonBlock {
|
||||||
ReusableArray<pollfd> buffer;
|
AllocatedArray<pollfd> buffer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::span<pollfd> Allocate(std::size_t n) noexcept {
|
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::span<pollfd> CopyReturnedEvents(MultiSocketMonitor &m) noexcept;
|
||||||
std::size_t n) noexcept;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue