From 4c38d926e6d9fa1ba9aa2b5eab3b09bd3a520bb7 Mon Sep 17 00:00:00 2001 From: bruceperens Date: Fri, 14 Mar 2014 19:59:26 +0000 Subject: [PATCH] Start defining poll interface. git-svn-id: https://svn.code.sf.net/p/freetel/code@1442 01035d8c-6547-0410-b346-abe4f91aad63 --- freedv-server/source/drivers.h | 5 +++++ .../source/platform/linux/audio_out_alsa.cpp | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/freedv-server/source/drivers.h b/freedv-server/source/drivers.h index 9b13440c..ae7ef72c 100644 --- a/freedv-server/source/drivers.h +++ b/freedv-server/source/drivers.h @@ -222,8 +222,13 @@ namespace FreeDV { /// All drivers present a unidirectional interface. /// If the underlying device is bidirectional that detail is hidden and /// we present one or more separate read and write drivers. + /// \return The number of audio samples or bytes that can be read or + /// written. virtual std::size_t ready() = 0; + /// + virtual int poll_fds(struct pollfd * array, int space) = 0; + virtual ~IODevice() = 0; }; diff --git a/freedv-server/source/platform/linux/audio_out_alsa.cpp b/freedv-server/source/platform/linux/audio_out_alsa.cpp index 8600c544..dca77e80 100644 --- a/freedv-server/source/platform/linux/audio_out_alsa.cpp +++ b/freedv-server/source/platform/linux/audio_out_alsa.cpp @@ -37,6 +37,14 @@ namespace FreeDV { AudioOutALSA(const char * parameters); ~AudioOutALSA(); + /// Return file descriptors for poll() + /// \param size The address of a variable that will be written + /// with the number of file descriptors in the array. + /// \return The address of an array of integers containing the + /// file descriptors. + virtual int + poll_fds(struct pollfd * array, int space); + /// Return the number of audio samples the device can handle in /// a write without blocking. virtual std::size_t @@ -105,6 +113,19 @@ namespace FreeDV { return ALSAEnumerate(stream, SND_PCM_STREAM_PLAYBACK); } + int + AudioOutALSA::poll_fds(struct pollfd * array, int space) + { + const int size = snd_pcm_poll_descriptors_count(handle); + + snd_pcm_poll_descriptors( + handle, + array, + space); + + return size; + } + std::size_t AudioOutALSA::ready() { -- 2.25.1