input/alsa: migrate from DeferredMonitor to DeferEvent

This commit is contained in:
Max Kellermann 2017-09-21 22:58:00 +02:00
parent 6fa403edd9
commit 6e7f866288

View File

@ -38,7 +38,7 @@
#include "Log.hxx" #include "Log.hxx"
#include "event/MultiSocketMonitor.hxx" #include "event/MultiSocketMonitor.hxx"
#include "event/DeferredMonitor.hxx" #include "event/DeferEvent.hxx"
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
@ -59,7 +59,7 @@ static constexpr size_t ALSA_RESUME_AT = ALSA_MAX_BUFFERED / 2;
class AlsaInputStream final class AlsaInputStream final
: public AsyncInputStream, : public AsyncInputStream,
MultiSocketMonitor, DeferredMonitor { MultiSocketMonitor {
/** /**
* The configured name of the ALSA device. * The configured name of the ALSA device.
@ -71,18 +71,21 @@ class AlsaInputStream final
ReusableArray<pollfd> pfd_buffer; ReusableArray<pollfd> pfd_buffer;
DeferEvent defer_invalidate_sockets;
public: public:
AlsaInputStream(EventLoop &loop, AlsaInputStream(EventLoop &_loop,
const char *_uri, Mutex &_mutex, Cond &_cond, const char *_uri, Mutex &_mutex, Cond &_cond,
const char *_device, const char *_device,
snd_pcm_t *_handle, int _frame_size) snd_pcm_t *_handle, int _frame_size)
:AsyncInputStream(loop, _uri, _mutex, _cond, :AsyncInputStream(_loop, _uri, _mutex, _cond,
ALSA_MAX_BUFFERED, ALSA_RESUME_AT), ALSA_MAX_BUFFERED, ALSA_RESUME_AT),
MultiSocketMonitor(loop), MultiSocketMonitor(_loop),
DeferredMonitor(loop),
device(_device), device(_device),
capture_handle(_handle), capture_handle(_handle),
frame_size(_frame_size) frame_size(_frame_size),
defer_invalidate_sockets(_loop,
BIND_THIS_METHOD(InvalidateSockets))
{ {
assert(_uri != nullptr); assert(_uri != nullptr);
assert(_handle != nullptr); assert(_handle != nullptr);
@ -95,13 +98,13 @@ public:
snd_pcm_start(capture_handle); snd_pcm_start(capture_handle);
DeferredMonitor::Schedule(); defer_invalidate_sockets.Schedule();
} }
~AlsaInputStream() { ~AlsaInputStream() {
BlockingCall(MultiSocketMonitor::GetEventLoop(), [this](){ BlockingCall(MultiSocketMonitor::GetEventLoop(), [this](){
MultiSocketMonitor::Reset(); MultiSocketMonitor::Reset();
DeferredMonitor::Cancel(); defer_invalidate_sockets.Cancel();
}); });
snd_pcm_close(capture_handle); snd_pcm_close(capture_handle);
@ -135,11 +138,7 @@ private:
int Recover(int err); int Recover(int err);
void SafeInvalidateSockets() { void SafeInvalidateSockets() {
DeferredMonitor::Schedule(); defer_invalidate_sockets.Schedule();
}
virtual void RunDeferred() override {
InvalidateSockets();
} }
virtual std::chrono::steady_clock::duration PrepareSockets() override; virtual std::chrono::steady_clock::duration PrepareSockets() override;