Skip to content

Commit 90dfa43

Browse files
committed
lib/alsa/NonBlock: use a persistent pollfd array
This implements the semantic API change introduced by commit alsa-project/alsa-lib@cd04da2
1 parent 4486b2e commit 90dfa43

File tree

3 files changed

+22
-27
lines changed

3 files changed

+22
-27
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ ver 0.24 (not yet released)
3131
* input
3232
- alsa: limit ALSA buffer time to 2 seconds
3333
- alsa: set up a channel map
34+
- alsa: support the alsa-lib 1.2.11 API
3435
- curl: add "connect_timeout" configuration
3536
* decoder
3637
- ffmpeg: require FFmpeg 4.0 or later

src/lib/alsa/NonBlock.cxx

+16-22
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@
88
namespace Alsa {
99

1010
std::span<pollfd>
11-
NonBlock::CopyReturnedEvents(MultiSocketMonitor &m, std::size_t n) noexcept
11+
NonBlock::CopyReturnedEvents(MultiSocketMonitor &m) noexcept
1212
{
13-
const auto pfds = buffer.Get(n), end = pfds + n;
14-
15-
auto *i = pfds;
16-
m.ForEachReturnedEvent([&i, end](SocketDescriptor s, unsigned events){
17-
if (i >= end)
18-
return;
19-
20-
i->fd = s.Get();
21-
i->events = i->revents = events;
22-
++i;
13+
const std::span<pollfd> pfds = buffer;
14+
15+
for (auto &i : pfds)
16+
i.revents = 0;
17+
18+
m.ForEachReturnedEvent([pfds](SocketDescriptor s, unsigned events){
19+
for (auto &i : pfds) {
20+
if (i.fd == s.Get()) {
21+
i.revents = events;
22+
return;
23+
}
24+
}
2325
});
2426

25-
return {pfds, static_cast<std::size_t>(i - pfds)};
27+
return pfds;
2628

2729
}
2830

@@ -54,11 +56,7 @@ NonBlockPcm::PrepareSockets(MultiSocketMonitor &m, snd_pcm_t *pcm)
5456
void
5557
NonBlockPcm::DispatchSockets(MultiSocketMonitor &m, snd_pcm_t *pcm)
5658
{
57-
int count = snd_pcm_poll_descriptors_count(pcm);
58-
if (count <= 0)
59-
return;
60-
61-
const auto pfds = base.CopyReturnedEvents(m, count);
59+
const auto pfds = base.CopyReturnedEvents(m);
6260

6361
unsigned short dummy;
6462
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
8886
void
8987
NonBlockMixer::DispatchSockets(MultiSocketMonitor &m, snd_mixer_t *mixer) noexcept
9088
{
91-
int count = snd_mixer_poll_descriptors_count(mixer);
92-
if (count <= 0)
93-
return;
94-
95-
const auto pfds = base.CopyReturnedEvents(m, count);
89+
const auto pfds = base.CopyReturnedEvents(m);
9690

9791
unsigned short dummy;
9892
snd_mixer_poll_descriptors_revents(mixer, pfds.data(), pfds.size(), &dummy);

src/lib/alsa/NonBlock.hxx

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#pragma once
55

66
#include "event/Chrono.hxx"
7-
#include "util/ReusableArray.hxx"
7+
#include "util/AllocatedArray.hxx"
88

99
#include <alsa/asoundlib.h>
1010

@@ -15,15 +15,15 @@ class MultiSocketMonitor;
1515
namespace Alsa {
1616

1717
class NonBlock {
18-
ReusableArray<pollfd> buffer;
18+
AllocatedArray<pollfd> buffer;
1919

2020
public:
2121
std::span<pollfd> Allocate(std::size_t n) noexcept {
22-
return {buffer.Get(n), n};
22+
buffer.ResizeDiscard(n);
23+
return buffer;
2324
}
2425

25-
std::span<pollfd> CopyReturnedEvents(MultiSocketMonitor &m,
26-
std::size_t n) noexcept;
26+
std::span<pollfd> CopyReturnedEvents(MultiSocketMonitor &m) noexcept;
2727
};
2828

2929
/**

0 commit comments

Comments
 (0)