1 /* 2 * Copyright 2003-2021 The Music Player Daemon Project 3 * http://www.musicpd.org 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 #ifndef MPD_ALSA_NON_BLOCK_HXX 21 #define MPD_ALSA_NON_BLOCK_HXX 22 23 #include "event/Chrono.hxx" 24 #include "util/ReusableArray.hxx" 25 26 #include <alsa/asoundlib.h> 27 28 class MultiSocketMonitor; 29 30 /** 31 * Helper class for #MultiSocketMonitor's virtual methods which 32 * manages the file descriptors for a #snd_pcm_t. 33 */ 34 class AlsaNonBlockPcm { 35 ReusableArray<pollfd> pfd_buffer; 36 37 public: 38 /** 39 * Throws on error. 40 */ 41 Event::Duration PrepareSockets(MultiSocketMonitor &m, 42 snd_pcm_t *pcm); 43 44 /** 45 * Wrapper for snd_pcm_poll_descriptors_revents(), to be 46 * called from MultiSocketMonitor::DispatchSockets(). 47 * 48 * Throws on error. 49 */ 50 void DispatchSockets(MultiSocketMonitor &m, snd_pcm_t *pcm); 51 }; 52 53 /** 54 * Helper class for #MultiSocketMonitor's virtual methods which 55 * manages the file descriptors for a #snd_mixer_t. 56 */ 57 class AlsaNonBlockMixer { 58 ReusableArray<pollfd> pfd_buffer; 59 60 public: 61 Event::Duration PrepareSockets(MultiSocketMonitor &m, 62 snd_mixer_t *mixer) noexcept; 63 64 /** 65 * Wrapper for snd_mixer_poll_descriptors_revents(), to be 66 * called from MultiSocketMonitor::DispatchSockets(). 67 */ 68 void DispatchSockets(MultiSocketMonitor &m, snd_mixer_t *mixer) noexcept; 69 }; 70 71 #endif 72