X-Git-Url: https://code.delx.au/pulseaudio/blobdiff_plain/0bc538b08ca5c4efea86700cb6c4685da3f34345..f4f4c42fc611b0bca2293e9b517a88a525f2c1fb:/src/modules/module-pipe-source.c diff --git a/src/modules/module-pipe-source.c b/src/modules/module-pipe-source.c index e5609fb5..36e87322 100644 --- a/src/modules/module-pipe-source.c +++ b/src/modules/module-pipe-source.c @@ -27,12 +27,13 @@ #include #include #include -#include #include #include -#include #include -#include + +#ifdef HAVE_SYS_FILIO_H +#include +#endif #include @@ -45,13 +46,14 @@ #include #include #include +#include #include "module-pipe-source-symdef.h" PA_MODULE_AUTHOR("Lennart Poettering"); PA_MODULE_DESCRIPTION("UNIX pipe source"); PA_MODULE_VERSION(PACKAGE_VERSION); -PA_MODULE_LOAD_ONCE(FALSE); +PA_MODULE_LOAD_ONCE(false); PA_MODULE_USAGE( "source_name= " "source_properties= " @@ -105,9 +107,10 @@ static int source_process_msg( case PA_SOURCE_MESSAGE_GET_LATENCY: { size_t n = 0; - int l; #ifdef FIONREAD + int l; + if (ioctl(u->fd, FIONREAD, &l) >= 0 && l > 0) n = (size_t) l; #endif @@ -142,7 +145,7 @@ static void thread_func(void *userdata) { void *p; if (!u->memchunk.memblock) { - u->memchunk.memblock = pa_memblock_new(u->core->mempool, PIPE_BUF); + u->memchunk.memblock = pa_memblock_new(u->core->mempool, pa_pipe_buf(u->fd)); u->memchunk.index = u->memchunk.length = 0; } @@ -159,7 +162,7 @@ static void thread_func(void *userdata) { if (errno == EINTR) continue; else if (errno != EAGAIN) { - pa_log("Faile to read data from FIFO: %s", pa_cstrerror(errno)); + pa_log("Failed to read data from FIFO: %s", pa_cstrerror(errno)); goto fail; } @@ -181,7 +184,7 @@ static void thread_func(void *userdata) { /* Hmm, nothing to do. Let's sleep */ pollfd->events = (short) (u->source->thread_info.state == PA_SOURCE_RUNNING ? POLLIN : 0); - if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0) + if ((ret = pa_rtpoll_run(u->rtpoll, true)) < 0) goto fail; if (ret == 0) @@ -205,7 +208,7 @@ finish: pa_log_debug("Thread shutting down"); } -int pa__init(pa_module*m) { +int pa__init(pa_module *m) { struct userdata *u; struct stat st; pa_sample_spec ss; @@ -217,14 +220,14 @@ int pa__init(pa_module*m) { pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { - pa_log("failed to parse module arguments."); + pa_log("Failed to parse module arguments."); goto fail; } ss = m->core->default_sample_spec; map = m->core->default_channel_map; if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) { - pa_log("invalid sample format specification or channel map"); + pa_log("Invalid sample format specification or channel map"); goto fail; } @@ -237,17 +240,19 @@ int pa__init(pa_module*m) { u->filename = pa_runtime_path(pa_modargs_get_value(ma, "file", DEFAULT_FILE_NAME)); - mkfifo(u->filename, 0666); - if ((u->fd = open(u->filename, O_RDWR|O_NOCTTY)) < 0) { + if (mkfifo(u->filename, 0666) < 0) { + pa_log("mkfifo('%s'): %s", u->filename, pa_cstrerror(errno)); + goto fail; + } + if ((u->fd = pa_open_cloexec(u->filename, O_RDWR, 0)) < 0) { pa_log("open('%s'): %s", u->filename, pa_cstrerror(errno)); goto fail; } - pa_make_fd_cloexec(u->fd); pa_make_fd_nonblock(u->fd); if (fstat(u->fd, &st) < 0) { - pa_log("fstat('%s'): %s",u->filename, pa_cstrerror(errno)); + pa_log("fstat('%s'): %s", u->filename, pa_cstrerror(errno)); goto fail; } @@ -284,14 +289,14 @@ int pa__init(pa_module*m) { pa_source_set_asyncmsgq(u->source, u->thread_mq.inq); pa_source_set_rtpoll(u->source, u->rtpoll); - pa_source_set_fixed_latency(u->source, pa_bytes_to_usec(PIPE_BUF, &u->source->sample_spec)); + pa_source_set_fixed_latency(u->source, pa_bytes_to_usec(pa_pipe_buf(u->fd), &u->source->sample_spec)); u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1); pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL); pollfd->fd = u->fd; pollfd->events = pollfd->revents = 0; - if (!(u->thread = pa_thread_new(thread_func, u))) { + if (!(u->thread = pa_thread_new("pipe-source", thread_func, u))) { pa_log("Failed to create thread."); goto fail; } @@ -320,7 +325,7 @@ int pa__get_n_used(pa_module *m) { return pa_source_linked_by(u->source); } -void pa__done(pa_module*m) { +void pa__done(pa_module *m) { struct userdata *u; pa_assert(m);