From f3e133c617f2fe76817b679abc9054f2395e2685 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 25 Mar 2019 08:53:58 +0100 Subject: [PATCH] test/run_filter: use class FileDescriptor --- test/run_filter.cxx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/run_filter.cxx b/test/run_filter.cxx index 9b2994da1..7402f6838 100644 --- a/test/run_filter.cxx +++ b/test/run_filter.cxx @@ -28,6 +28,7 @@ #include "pcm/Volume.hxx" #include "mixer/MixerControl.hxx" #include "system/Error.hxx" +#include "system/FileDescriptor.hxx" #include "util/ConstBuffer.hxx" #include "util/StringBuffer.hxx" #include "util/RuntimeError.hxx" @@ -40,8 +41,6 @@ #include #include #include -#include -#include void mixer_set_volume(gcc_unused Mixer *mixer, @@ -62,9 +61,9 @@ LoadFilter(const ConfigData &config, const char *name) } static size_t -ReadOrThrow(int fd, void *buffer, size_t size) +ReadOrThrow(FileDescriptor fd, void *buffer, size_t size) { - auto nbytes = read(fd, buffer, size); + auto nbytes = fd.Read(buffer, size); if (nbytes < 0) throw MakeErrno("Read failed"); @@ -72,7 +71,7 @@ ReadOrThrow(int fd, void *buffer, size_t size) } static void -FullRead(int fd, void *_buffer, size_t size) +FullRead(FileDescriptor fd, void *_buffer, size_t size) { auto buffer = (uint8_t *)_buffer; @@ -87,7 +86,7 @@ FullRead(int fd, void *_buffer, size_t size) } static size_t -ReadFrames(int fd, void *_buffer, size_t size, size_t frame_size) +ReadFrames(FileDescriptor fd, void *_buffer, size_t size, size_t frame_size) { auto buffer = (uint8_t *)_buffer; @@ -142,17 +141,20 @@ try { /* play */ + FileDescriptor input_fd(STDIN_FILENO); + FileDescriptor output_fd(STDOUT_FILENO); + while (true) { char buffer[4096]; - ssize_t nbytes = ReadFrames(0, buffer, sizeof(buffer), + ssize_t nbytes = ReadFrames(input_fd, buffer, sizeof(buffer), in_frame_size); if (nbytes == 0) break; auto dest = filter->FilterPCM({(const void *)buffer, (size_t)nbytes}); - nbytes = write(1, dest.data, dest.size); + nbytes = output_fd.Write(dest.data, dest.size); if (nbytes < 0) { fprintf(stderr, "Failed to write: %s\n", strerror(errno));