summaryrefslogtreecommitdiffstats
path: root/src/modules/module-pipe-source.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/module-pipe-source.c')
-rw-r--r--src/modules/module-pipe-source.c59
1 files changed, 33 insertions, 26 deletions
diff --git a/src/modules/module-pipe-source.c b/src/modules/module-pipe-source.c
index 2313df67..b0de34ca 100644
--- a/src/modules/module-pipe-source.c
+++ b/src/modules/module-pipe-source.c
@@ -1,5 +1,3 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
@@ -49,16 +47,17 @@
#include "module-pipe-source-symdef.h"
-PA_MODULE_AUTHOR("Lennart Poettering")
-PA_MODULE_DESCRIPTION("UNIX pipe source")
-PA_MODULE_VERSION(PACKAGE_VERSION)
+PA_MODULE_AUTHOR("Lennart Poettering");
+PA_MODULE_DESCRIPTION("UNIX pipe source");
+PA_MODULE_VERSION(PACKAGE_VERSION);
+PA_MODULE_LOAD_ONCE(FALSE);
PA_MODULE_USAGE(
"source_name=<name for the source> "
"file=<path of the FIFO> "
"format=<sample format> "
"channels=<number of channels> "
"rate=<sample rate> "
- "channel_map=<channel map>")
+ "channel_map=<channel map>");
#define DEFAULT_FILE_NAME "/tmp/music.input"
#define DEFAULT_SOURCE_NAME "fifo_input"
@@ -100,13 +99,13 @@ static void thread_func(void *userdata) {
pa_thread_mq_install(&u->thread_mq);
pa_rtpoll_install(u->rtpoll);
-
+
for (;;) {
int ret;
struct pollfd *pollfd;
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
-
+
/* Try to read some data and pass it on to the source driver */
if (u->source->thread_info.state == PA_SOURCE_RUNNING && pollfd->revents) {
ssize_t l;
@@ -152,13 +151,14 @@ static void thread_func(void *userdata) {
/* Hmm, nothing to do. Let's sleep */
pollfd->events = u->source->thread_info.state == PA_SOURCE_RUNNING ? POLLIN : 0;
- if ((ret = pa_rtpoll_run(u->rtpoll, 1)) < 0)
+ if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0)
goto fail;
if (ret == 0)
goto finish;
-
+
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
+
if (pollfd->revents & ~POLLIN) {
pa_log("FIFO shutdown.");
goto fail;
@@ -181,8 +181,8 @@ int pa__init(pa_module*m) {
pa_sample_spec ss;
pa_channel_map map;
pa_modargs *ma;
- char *t;
struct pollfd *pollfd;
+ pa_source_new_data data;
pa_assert(m);
@@ -202,12 +202,11 @@ int pa__init(pa_module*m) {
u->module = m;
m->userdata = u;
pa_memchunk_reset(&u->memchunk);
- pa_thread_mq_init(&u->thread_mq, m->core->mainloop);
u->rtpoll = pa_rtpoll_new();
- pa_rtpoll_item_new_asyncmsgq(u->rtpoll, PA_RTPOLL_EARLY, u->thread_mq.inq);
+ pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
+
+ u->filename = pa_runtime_path(pa_modargs_get_value(ma, "file", DEFAULT_FILE_NAME));
- u->filename = pa_xstrdup(pa_modargs_get_value(ma, "file", DEFAULT_FILE_NAME));
-
mkfifo(u->filename, 0666);
if ((u->fd = open(u->filename, O_RDWR|O_NOCTTY)) < 0) {
pa_log("open('%s'): %s", u->filename, pa_cstrerror(errno));
@@ -227,25 +226,33 @@ int pa__init(pa_module*m) {
goto fail;
}
- if (!(u->source = pa_source_new(m->core, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map))) {
+ pa_source_new_data_init(&data);
+ data.driver = __FILE__;
+ data.module = m;
+ pa_source_new_data_set_name(&data, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME));
+ pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->filename);
+ pa_proplist_setf(data.proplist, PA_PROP_DEVICE_DESCRIPTION, "Unix FIFO source %s", u->filename);
+ pa_source_new_data_set_sample_spec(&data, &ss);
+ pa_source_new_data_set_channel_map(&data, &map);
+
+ u->source = pa_source_new(m->core, &data, 0);
+ pa_source_new_data_done(&data);
+
+ if (!u->source) {
pa_log("Failed to create source.");
goto fail;
}
u->source->userdata = u;
- u->source->flags = 0;
-
- pa_source_set_module(u->source, m);
+
pa_source_set_asyncmsgq(u->source, u->thread_mq.inq);
pa_source_set_rtpoll(u->source, u->rtpoll);
- pa_source_set_description(u->source, t = pa_sprintf_malloc("Unix FIFO source '%s'", u->filename));
- pa_xfree(t);
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))) {
pa_log("Failed to create thread.");
goto fail;
@@ -268,7 +275,7 @@ fail:
void pa__done(pa_module*m) {
struct userdata *u;
-
+
pa_assert(m);
if (!(u = m->userdata))
@@ -286,16 +293,16 @@ void pa__done(pa_module*m) {
if (u->source)
pa_source_unref(u->source);
-
+
if (u->memchunk.memblock)
pa_memblock_unref(u->memchunk.memblock);
if (u->rtpoll_item)
pa_rtpoll_item_free(u->rtpoll_item);
-
+
if (u->rtpoll)
pa_rtpoll_free(u->rtpoll);
-
+
if (u->filename) {
unlink(u->filename);
pa_xfree(u->filename);