Commit 9e503b21 authored by Max Kellermann's avatar Max Kellermann

{input,mixer}/alsa: move code to lib/alsa/NonBlock.cxx

parent 67a958a3
......@@ -256,6 +256,9 @@ UPNP_SOURCES = \
src/lib/upnp/WorkQueue.hxx \
src/lib/upnp/Action.hxx
ALSA_SOURCES = \
src/lib/alsa/NonBlock.cxx src/lib/alsa/NonBlock.hxx
#
# Android native library
#
......@@ -1294,6 +1297,7 @@ INPUT_LIBS = \
if ENABLE_ALSA
libinput_a_SOURCES += \
$(ALSA_SOURCES) \
src/input/plugins/AlsaInputPlugin.cxx \
src/input/plugins/AlsaInputPlugin.hxx
INPUT_LIBS += $(ALSA_LIBS)
......@@ -1412,6 +1416,7 @@ liboutput_plugins_a_SOURCES += \
src/output/plugins/AlsaOutputPlugin.cxx \
src/output/plugins/AlsaOutputPlugin.hxx
libmixer_plugins_a_SOURCES += \
$(ALSA_SOURCES) \
src/mixer/plugins/volume_mapping.h \
src/mixer/plugins/volume_mapping.c \
src/mixer/plugins/AlsaMixerPlugin.cxx
......
......@@ -26,6 +26,7 @@
#include "config.h"
#include "AlsaInputPlugin.hxx"
#include "lib/alsa/NonBlock.hxx"
#include "../InputPlugin.hxx"
#include "../AsyncInputStream.hxx"
#include "event/Call.hxx"
......@@ -177,20 +178,7 @@ AlsaInputStream::PrepareSockets()
return std::chrono::steady_clock::duration(-1);
}
int count = snd_pcm_poll_descriptors_count(capture_handle);
if (count <= 0) {
ClearSocketList();
return std::chrono::steady_clock::duration(-1);
}
struct pollfd *pfds = pfd_buffer.Get(count);
count = snd_pcm_poll_descriptors(capture_handle, pfds, count);
if (count < 0)
count = 0;
ReplaceSocketList(pfds, count);
return std::chrono::steady_clock::duration(-1);
return PrepareAlsaPcmSockets(*this, capture_handle, pfd_buffer);
}
void
......
/*
* Copyright 2003-2017 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "NonBlock.hxx"
#include "event/MultiSocketMonitor.hxx"
std::chrono::steady_clock::duration
PrepareAlsaPcmSockets(MultiSocketMonitor &m, snd_pcm_t *pcm,
ReusableArray<pollfd> &pfd_buffer)
{
int count = snd_pcm_poll_descriptors_count(pcm);
if (count <= 0) {
m.ClearSocketList();
return std::chrono::steady_clock::duration(-1);
}
struct pollfd *pfds = pfd_buffer.Get(count);
count = snd_pcm_poll_descriptors(pcm, pfds, count);
if (count < 0)
count = 0;
m.ReplaceSocketList(pfds, count);
return std::chrono::steady_clock::duration(-1);
}
std::chrono::steady_clock::duration
PrepareAlsaMixerSockets(MultiSocketMonitor &m, snd_mixer_t *mixer,
ReusableArray<pollfd> &pfd_buffer)
{
int count = snd_mixer_poll_descriptors_count(mixer);
if (count <= 0) {
m.ClearSocketList();
return std::chrono::steady_clock::duration(-1);
}
struct pollfd *pfds = pfd_buffer.Get(count);
count = snd_mixer_poll_descriptors(mixer, pfds, count);
if (count < 0)
count = 0;
m.ReplaceSocketList(pfds, count);
return std::chrono::steady_clock::duration(-1);
}
/*
* Copyright 2003-2017 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_ALSA_NON_BLOCK_HXX
#define MPD_ALSA_NON_BLOCK_HXX
#include "check.h"
#include "util/ReusableArray.hxx"
#include <alsa/asoundlib.h>
#include <chrono>
class MultiSocketMonitor;
/**
* Update #MultiSocketMonitor's socket list from
* snd_pcm_poll_descriptors(). To be called from
* MultiSocketMonitor::PrepareSockets().
*/
std::chrono::steady_clock::duration
PrepareAlsaPcmSockets(MultiSocketMonitor &m, snd_pcm_t *pcm,
ReusableArray<pollfd> &pfd_buffer);
/**
* Update #MultiSocketMonitor's socket list from
* snd_mixer_poll_descriptors(). To be called from
* MultiSocketMonitor::PrepareSockets().
*/
std::chrono::steady_clock::duration
PrepareAlsaMixerSockets(MultiSocketMonitor &m, snd_mixer_t *mixer,
ReusableArray<pollfd> &pfd_buffer);
#endif
......@@ -18,6 +18,7 @@
*/
#include "config.h"
#include "lib/alsa/NonBlock.hxx"
#include "mixer/MixerInternal.hxx"
#include "mixer/Listener.hxx"
#include "output/OutputAPI.hxx"
......@@ -108,18 +109,7 @@ AlsaMixerMonitor::PrepareSockets()
return std::chrono::steady_clock::duration(-1);
}
int count = snd_mixer_poll_descriptors_count(mixer);
if (count <= 0)
count = 0;
struct pollfd *pfds = pfd_buffer.Get(count);
count = snd_mixer_poll_descriptors(mixer, pfds, count);
if (count < 0)
count = 0;
ReplaceSocketList(pfds, count);
return std::chrono::steady_clock::duration(-1);
return PrepareAlsaMixerSockets(*this, mixer, pfd_buffer);
}
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment