#include "alsa_pool.h"
-#include <alsa/control.h>
-#include <alsa/error.h>
-#include <alsa/pcm.h>
+#include <alsa/asoundlib.h>
#include <assert.h>
+#include <errno.h>
#include <limits.h>
+#include <poll.h>
+#include <stdint.h>
#include <stdio.h>
+#include <sys/eventfd.h>
#include <sys/inotify.h>
#include <unistd.h>
#include <algorithm>
+#include <chrono>
+#include <functional>
+#include <iterator>
#include <memory>
+#include <ratio>
#include "alsa_input.h"
#include "audio_mixer.h"
using namespace std;
using namespace std::placeholders;
+ALSAPool::ALSAPool()
+{
+ should_quit_fd = eventfd(/*initval=*/0, /*flags=*/0);
+ assert(should_quit_fd != -1);
+}
+
ALSAPool::~ALSAPool()
{
for (Device &device : devices) {
}
}
should_quit = true;
+ const uint64_t one = 1;
+ write(should_quit_fd, &one, sizeof(one));
inotify_thread.join();
while (retry_threads_running > 0) {
int size = sizeof(inotify_event) + NAME_MAX + 1;
unique_ptr<char[]> buf(new char[size]);
while (!should_quit) {
- pollfd fds;
- fds.fd = inotify_fd;
- fds.events = POLLIN;
- fds.revents = 0;
-
- int ret = poll(&fds, 1, 100);
+ pollfd fds[2];
+ fds[0].fd = inotify_fd;
+ fds[0].events = POLLIN;
+ fds[0].revents = 0;
+ fds[1].fd = should_quit_fd;
+ fds[1].events = POLLIN;
+ fds[1].revents = 0;
+
+ int ret = poll(fds, 2, -1);
if (ret == -1) {
if (errno == EINTR) {
continue;
continue;
}
+ if (fds[1].revents) break; // should_quit_fd asserted.
+
ret = read(inotify_fd, buf.get(), size);
if (ret == -1) {
if (errno == EINTR) {
}
close(watch_fd);
close(inotify_fd);
+ close(should_quit_fd);
}
void ALSAPool::reset_device(unsigned index)