lib/alsa/NonBlock: move the functions into a class managing the state

This commit is contained in:
Max Kellermann 2018-11-11 07:34:08 +01:00
parent a958abde2f
commit 12308a0f55
5 changed files with 29 additions and 29 deletions

View File

@ -34,7 +34,6 @@
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"
#include "util/ReusableArray.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "Log.hxx" #include "Log.hxx"
#include "event/MultiSocketMonitor.hxx" #include "event/MultiSocketMonitor.hxx"
@ -69,7 +68,7 @@ class AlsaInputStream final
snd_pcm_t *const capture_handle; snd_pcm_t *const capture_handle;
const size_t frame_size; const size_t frame_size;
ReusableArray<pollfd> pfd_buffer; AlsaNonBlockPcm non_block;
DeferEvent defer_invalidate_sockets; DeferEvent defer_invalidate_sockets;
@ -180,7 +179,7 @@ AlsaInputStream::PrepareSockets() noexcept
return std::chrono::steady_clock::duration(-1); return std::chrono::steady_clock::duration(-1);
} }
return PrepareAlsaPcmSockets(*this, capture_handle, pfd_buffer); return non_block.PrepareSockets(*this, capture_handle);
} }
void void

View File

@ -23,8 +23,7 @@
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
std::chrono::steady_clock::duration std::chrono::steady_clock::duration
PrepareAlsaPcmSockets(MultiSocketMonitor &m, snd_pcm_t *pcm, AlsaNonBlockPcm::PrepareSockets(MultiSocketMonitor &m, snd_pcm_t *pcm)
ReusableArray<pollfd> &pfd_buffer)
{ {
int count = snd_pcm_poll_descriptors_count(pcm); int count = snd_pcm_poll_descriptors_count(pcm);
if (count <= 0) { if (count <= 0) {
@ -51,8 +50,7 @@ PrepareAlsaPcmSockets(MultiSocketMonitor &m, snd_pcm_t *pcm,
} }
std::chrono::steady_clock::duration std::chrono::steady_clock::duration
PrepareAlsaMixerSockets(MultiSocketMonitor &m, snd_mixer_t *mixer, AlsaNonBlockMixer::PrepareSockets(MultiSocketMonitor &m, snd_mixer_t *mixer) noexcept
ReusableArray<pollfd> &pfd_buffer) noexcept
{ {
int count = snd_mixer_poll_descriptors_count(mixer); int count = snd_mixer_poll_descriptors_count(mixer);
if (count <= 0) { if (count <= 0) {

View File

@ -30,23 +30,30 @@
class MultiSocketMonitor; class MultiSocketMonitor;
/** /**
* Update #MultiSocketMonitor's socket list from * Helper class for #MultiSocketMonitor's virtual methods which
* snd_pcm_poll_descriptors(). To be called from * manages the file descriptors for a #snd_pcm_t.
* MultiSocketMonitor::PrepareSockets().
*
* Throws exception on error.
*/ */
std::chrono::steady_clock::duration class AlsaNonBlockPcm {
PrepareAlsaPcmSockets(MultiSocketMonitor &m, snd_pcm_t *pcm, ReusableArray<pollfd> pfd_buffer;
ReusableArray<pollfd> &pfd_buffer);
public:
/**
* Throws on error.
*/
std::chrono::steady_clock::duration PrepareSockets(MultiSocketMonitor &m,
snd_pcm_t *pcm);
};
/** /**
* Update #MultiSocketMonitor's socket list from * Helper class for #MultiSocketMonitor's virtual methods which
* snd_mixer_poll_descriptors(). To be called from * manages the file descriptors for a #snd_mixer_t.
* MultiSocketMonitor::PrepareSockets().
*/ */
std::chrono::steady_clock::duration class AlsaNonBlockMixer {
PrepareAlsaMixerSockets(MultiSocketMonitor &m, snd_mixer_t *mixer, ReusableArray<pollfd> pfd_buffer;
ReusableArray<pollfd> &pfd_buffer) noexcept;
public:
std::chrono::steady_clock::duration PrepareSockets(MultiSocketMonitor &m,
snd_mixer_t *mixer) noexcept;
};
#endif #endif

View File

@ -26,7 +26,6 @@
#include "event/DeferEvent.hxx" #include "event/DeferEvent.hxx"
#include "event/Call.hxx" #include "event/Call.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "util/ReusableArray.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "util/RuntimeError.hxx" #include "util/RuntimeError.hxx"
#include "Log.hxx" #include "Log.hxx"
@ -48,7 +47,7 @@ class AlsaMixerMonitor final : MultiSocketMonitor {
snd_mixer_t *mixer; snd_mixer_t *mixer;
ReusableArray<pollfd> pfd_buffer; AlsaNonBlockMixer non_block;
public: public:
AlsaMixerMonitor(EventLoop &_loop, snd_mixer_t *_mixer) AlsaMixerMonitor(EventLoop &_loop, snd_mixer_t *_mixer)
@ -110,7 +109,7 @@ AlsaMixerMonitor::PrepareSockets() noexcept
return std::chrono::steady_clock::duration(-1); return std::chrono::steady_clock::duration(-1);
} }
return PrepareAlsaMixerSockets(*this, mixer, pfd_buffer); return non_block.PrepareSockets(*this, mixer);
} }
void void

View File

@ -148,10 +148,7 @@ class AlsaOutput final
*/ */
uint8_t *silence; uint8_t *silence;
/** AlsaNonBlockPcm non_block;
* For PrepareAlsaPcmSockets().
*/
ReusableArray<pollfd> pfd_buffer;
/** /**
* For copying data from OutputThread to IOThread. * For copying data from OutputThread to IOThread.
@ -881,7 +878,7 @@ AlsaOutput::PrepareSockets() noexcept
} }
try { try {
return PrepareAlsaPcmSockets(*this, pcm, pfd_buffer); return non_block.PrepareSockets(*this, pcm);
} catch (...) { } catch (...) {
ClearSocketList(); ClearSocketList();
LockCaughtError(); LockCaughtError();