summaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/module-alsa-sink.c49
-rw-r--r--src/modules/module-alsa-source.c51
-rw-r--r--src/modules/module-null-sink.c39
-rw-r--r--src/modules/module-oss.c70
-rw-r--r--src/modules/module-pipe-sink.c39
-rw-r--r--src/modules/module-pipe-source.c103
-rw-r--r--src/modules/module-rescue-streams.c4
-rw-r--r--src/modules/module-sine.c4
-rw-r--r--src/modules/module-suspend-on-idle.c93
9 files changed, 219 insertions, 233 deletions
diff --git a/src/modules/module-alsa-sink.c b/src/modules/module-alsa-sink.c
index a805845c..24765a04 100644
--- a/src/modules/module-alsa-sink.c
+++ b/src/modules/module-alsa-sink.c
@@ -347,7 +347,7 @@ static int suspend(struct userdata *u) {
u->alsa_rtpoll_item = NULL;
}
- pa_log_debug("Device suspended...");
+ pa_log_info("Device suspended...");
return 0;
}
@@ -361,7 +361,7 @@ static int unsuspend(struct userdata *u) {
pa_assert(u);
pa_assert(!u->pcm_handle);
- pa_log_debug("Trying resume...");
+ pa_log_info("Trying resume...");
snd_config_update_free_global();
if ((err = snd_pcm_open(&u->pcm_handle, u->device_name, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)) < 0) {
@@ -406,7 +406,7 @@ static int unsuspend(struct userdata *u) {
u->first = 1;
- pa_log_debug("Resumed successfully...");
+ pa_log_info("Resumed successfully...");
return 0;
@@ -457,7 +457,8 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
break;
- case PA_SINK_DISCONNECTED:
+ case PA_SINK_UNLINKED:
+ case PA_SINK_INIT:
;
}
@@ -607,13 +608,7 @@ static void thread_func(void *userdata) {
goto fail;
for (;;) {
- pa_msgobject *object;
- int code;
- void *data;
- pa_memchunk chunk;
- int64_t offset;
-
-/* pa_log("loop"); */
+ int ret;
/* Render some data and write it to the dsp */
if (PA_SINK_OPENED(u->sink->thread_info.state)) {
@@ -635,28 +630,25 @@ static void thread_func(void *userdata) {
}
}
-/* pa_log("loop2"); */
+ /* Now give the sink inputs some to time to process their data */
+ if ((ret = pa_sink_process_inputs(u->sink)) < 0)
+ goto fail;
+ if (ret > 0)
+ continue;
/* Check whether there is a message for us to process */
- if (pa_asyncmsgq_get(u->thread_mq.inq, &object, &code, &data, &offset, &chunk, 0) == 0) {
- int ret;
-
- if (!object && code == PA_MESSAGE_SHUTDOWN) {
- pa_asyncmsgq_done(u->thread_mq.inq, 0);
- goto finish;
- }
-
- ret = pa_asyncmsgq_dispatch(object, code, data, offset, &chunk);
- pa_asyncmsgq_done(u->thread_mq.inq, ret);
+ if ((ret = pa_thread_mq_process(&u->thread_mq) < 0))
+ goto finish;
+ if (ret > 0)
continue;
- }
-
+
/* Hmm, nothing to do. Let's sleep */
if (pa_rtpoll_run(u->rtpoll) < 0) {
pa_log("poll() failed: %s", pa_cstrerror(errno));
goto fail;
}
+ /* Tell ALSA about this and process its response */
if (PA_SINK_OPENED(u->sink->thread_info.state)) {
struct pollfd *pollfd;
unsigned short revents = 0;
@@ -680,9 +672,7 @@ static void thread_func(void *userdata) {
goto fail;
}
-/* pa_log("got alsa event"); */
}
-
}
fail:
@@ -828,6 +818,7 @@ int pa__init(pa_module*m) {
pa_sink_set_module(u->sink, m);
pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
+ pa_sink_set_rtpoll(u->sink, u->rtpoll);
pa_sink_set_description(u->sink, t = pa_sprintf_malloc(
"ALSA PCM on %s (%s)%s",
dev,
@@ -835,7 +826,7 @@ int pa__init(pa_module*m) {
use_mmap ? " via DMA" : ""));
pa_xfree(t);
- u->sink->is_hardware = 1;
+ u->sink->flags = PA_SINK_HARDWARE|PA_SINK_CAN_SUSPEND|PA_SINK_HW_VOLUME_CTRL|PA_SINK_LATENCY;
u->frame_size = frame_size;
u->fragment_size = frag_size = period_size * frame_size;
@@ -894,6 +885,8 @@ int pa__init(pa_module*m) {
if (u->sink->get_mute)
u->sink->get_mute(u->sink);
+ pa_sink_put(u->sink);
+
pa_modargs_free(ma);
return 0;
@@ -917,7 +910,7 @@ void pa__done(pa_module*m) {
return;
if (u->sink)
- pa_sink_disconnect(u->sink);
+ pa_sink_unlink(u->sink);
if (u->thread) {
pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL);
diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c
index 6ea99ec7..0d76cabc 100644
--- a/src/modules/module-alsa-source.c
+++ b/src/modules/module-alsa-source.c
@@ -328,7 +328,7 @@ static int suspend(struct userdata *u) {
u->alsa_rtpoll_item = NULL;
}
- pa_log_debug("Device suspended...");
+ pa_log_info("Device suspended...");
return 0;
}
@@ -342,7 +342,7 @@ static int unsuspend(struct userdata *u) {
pa_assert(u);
pa_assert(!u->pcm_handle);
- pa_log_debug("Trying resume...");
+ pa_log_info("Trying resume...");
snd_config_update_free_global();
if ((err = snd_pcm_open(&u->pcm_handle, u->device_name, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK)) < 0) {
@@ -387,7 +387,7 @@ static int unsuspend(struct userdata *u) {
/* FIXME: We need to reload the volume somehow */
- pa_log_debug("Resumed successfully...");
+ pa_log_info("Resumed successfully...");
return 0;
@@ -438,7 +438,8 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
break;
- case PA_SOURCE_DISCONNECTED:
+ case PA_SOURCE_UNLINKED:
+ case PA_SOURCE_INIT:
;
}
@@ -590,15 +591,9 @@ static void thread_func(void *userdata) {
snd_pcm_start(u->pcm_handle);
for (;;) {
- pa_msgobject *object;
- int code;
- void *data;
- int64_t offset;
- pa_memchunk chunk;
+ int ret;
-/* pa_log("loop"); */
-
- /* Render some data and write it to the dsp */
+ /* Read some data and pass it to the sources */
if (PA_SOURCE_OPENED(u->source->thread_info.state)) {
if (u->use_mmap) {
@@ -611,29 +606,25 @@ static void thread_func(void *userdata) {
}
}
-/* pa_log("loop2"); */
+ /* Now give the source outputs some to time to process their data */
+ if ((ret = pa_source_process_outputs(u->source)) < 0)
+ goto fail;
+ if (ret > 0)
+ continue;
/* Check whether there is a message for us to process */
- if (pa_asyncmsgq_get(u->thread_mq.inq, &object, &code, &data, &offset, &chunk, 0) == 0) {
- int ret;
-
-/* pa_log("processing msg"); */
-
- if (!object && code == PA_MESSAGE_SHUTDOWN) {
- pa_asyncmsgq_done(u->thread_mq.inq, 0);
- goto finish;
- }
-
- ret = pa_asyncmsgq_dispatch(object, code, data, offset, &chunk);
- pa_asyncmsgq_done(u->thread_mq.inq, ret);
+ if ((ret = pa_thread_mq_process(&u->thread_mq) < 0))
+ goto finish;
+ if (ret > 0)
continue;
- }
+ /* Hmm, nothing to do. Let's sleep */
if (pa_rtpoll_run(u->rtpoll) < 0) {
pa_log("poll() failed: %s", pa_cstrerror(errno));
goto fail;
}
+ /* Tell ALSA about this and process its response */
if (PA_SOURCE_OPENED(u->source->thread_info.state)) {
struct pollfd *pollfd;
unsigned short revents = 0;
@@ -657,7 +648,6 @@ static void thread_func(void *userdata) {
goto fail;
}
-/* pa_log("got alsa event"); */
}
}
@@ -802,6 +792,7 @@ int pa__init(pa_module*m) {
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(
"ALSA PCM on %s (%s)%s",
dev,
@@ -809,7 +800,7 @@ int pa__init(pa_module*m) {
use_mmap ? " via DMA" : ""));
pa_xfree(t);
- u->source->is_hardware = 1;
+ u->source->flags = PA_SOURCE_HARDWARE|PA_SOURCE_CAN_SUSPEND|PA_SOURCE_LATENCY|PA_SOURCE_HW_VOLUME_CTRL;
u->frame_size = frame_size;
u->fragment_size = frag_size = period_size * frame_size;
@@ -863,6 +854,8 @@ int pa__init(pa_module*m) {
if (u->source->get_mute)
u->source->get_mute(u->source);
+ pa_source_put(u->source);
+
pa_modargs_free(ma);
return 0;
@@ -886,7 +879,7 @@ void pa__done(pa_module*m) {
return;
if (u->source)
- pa_source_disconnect(u->source);
+ pa_source_unlink(u->source);
if (u->thread) {
pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL);
diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c
index 3b512371..78d99ceb 100644
--- a/src/modules/module-null-sink.c
+++ b/src/modules/module-null-sink.c
@@ -128,11 +128,7 @@ static void thread_func(void *userdata) {
pa_rtclock_get(&u->timestamp);
for (;;) {
- pa_msgobject *object;
- int code;
- void *data;
- pa_memchunk chunk;
- int64_t offset;
+ int ret;
/* Render some data and drop it immediately */
if (u->sink->thread_info.state == PA_SINK_RUNNING) {
@@ -141,30 +137,25 @@ static void thread_func(void *userdata) {
pa_rtclock_get(&now);
if (pa_timespec_cmp(&u->timestamp, &now) <= 0) {
-
- pa_sink_render(u->sink, u->block_size, &chunk);
- pa_memblock_unref(chunk.memblock);
-
- pa_timespec_add(&u->timestamp, pa_bytes_to_usec(chunk.length, &u->sink->sample_spec));
+ pa_sink_skip(u->sink, u->block_size);
+ pa_timespec_add(&u->timestamp, pa_bytes_to_usec(u->block_size, &u->sink->sample_spec));
}
pa_rtpoll_set_timer_absolute(u->rtpoll, &u->timestamp);
} else
pa_rtpoll_set_timer_disabled(u->rtpoll);
- /* Check whether there is a message for us to process */
- if (pa_asyncmsgq_get(u->thread_mq.inq, &object, &code, &data, &offset, &chunk, 0) == 0) {
- int ret;
-
- if (!object && code == PA_MESSAGE_SHUTDOWN) {
- pa_asyncmsgq_done(u->thread_mq.inq, 0);
- goto finish;
- }
+ /* Now give the sink inputs some to time to process their data */
+ if ((ret = pa_sink_process_inputs(u->sink)) < 0)
+ goto fail;
+ if (ret > 0)
+ continue;
- ret = pa_asyncmsgq_dispatch(object, code, data, offset, &chunk);
- pa_asyncmsgq_done(u->thread_mq.inq, ret);
+ /* Check whether there is a message for us to process */
+ if ((ret = pa_thread_mq_process(&u->thread_mq) < 0))
+ goto finish;
+ if (ret > 0)
continue;
- }
/* Hmm, nothing to do. Let's sleep */
if (pa_rtpoll_run(u->rtpoll) < 0) {
@@ -217,9 +208,11 @@ int pa__init(pa_module*m) {
u->sink->parent.process_msg = sink_process_msg;
u->sink->userdata = u;
+ u->sink->flags = PA_SINK_LATENCY;
pa_sink_set_module(u->sink, m);
pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
+ pa_sink_set_rtpoll(u->sink, u->rtpoll);
pa_sink_set_description(u->sink, pa_modargs_get_value(ma, "description", "NULL sink"));
u->block_size = pa_bytes_per_second(&ss) / 20; /* 50 ms */
@@ -231,6 +224,8 @@ int pa__init(pa_module*m) {
goto fail;
}
+ pa_sink_put(u->sink);
+
pa_modargs_free(ma);
return 0;
@@ -253,7 +248,7 @@ void pa__done(pa_module*m) {
return;
if (u->sink)
- pa_sink_disconnect(u->sink);
+ pa_sink_unlink(u->sink);
if (u->thread) {
pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL);
diff --git a/src/modules/module-oss.c b/src/modules/module-oss.c
index 85fdd9c8..bbb1e0d2 100644
--- a/src/modules/module-oss.c
+++ b/src/modules/module-oss.c
@@ -443,7 +443,7 @@ static int suspend(struct userdata *u) {
pa_assert(u);
pa_assert(u->fd >= 0);
- pa_log_debug("Suspending...");
+ pa_log_info("Suspending...");
if (u->out_mmap_memblocks) {
unsigned i;
@@ -483,7 +483,7 @@ static int suspend(struct userdata *u) {
u->rtpoll_item = NULL;
}
- pa_log_debug("Device suspended...");
+ pa_log_info("Device suspended...");
return 0;
}
@@ -501,7 +501,7 @@ static int unsuspend(struct userdata *u) {
m = u->mode;
- pa_log_debug("Trying resume...");
+ pa_log_info("Trying resume...");
if ((u->fd = pa_oss_open(u->device_name, &m, NULL)) < 0) {
pa_log_warn("Resume failed, device busy (%s)", pa_cstrerror(errno));
@@ -582,7 +582,7 @@ static int unsuspend(struct userdata *u) {
pollfd->events = 0;
pollfd->revents = 0;
- pa_log_debug("Resumed successfully...");
+ pa_log_info("Resumed successfully...");
return 0;
@@ -651,7 +651,8 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
break;
- case PA_SINK_DISCONNECTED:
+ case PA_SINK_UNLINKED:
+ case PA_SINK_INIT:
;
}
@@ -748,7 +749,8 @@ static int source_process_msg(pa_msgobject *o, int code, void *data, int64_t off
}
break;
- case PA_SOURCE_DISCONNECTED:
+ case PA_SOURCE_UNLINKED:
+ case PA_SOURCE_INIT:
;
}
@@ -807,20 +809,15 @@ static void thread_func(void *userdata) {
trigger(u, 0);
for (;;) {
- pa_msgobject *object;
- int code;
- void *data;
- pa_memchunk chunk;
- int64_t offset;
+ int ret;
/* pa_log("loop"); */
/* Render some data and write it to the dsp */
- if (u->sink && u->sink->thread_info.state != PA_SINK_DISCONNECTED && u->fd >= 0 && (revents & POLLOUT)) {
+ if (u->sink && u->sink->thread_info.state != PA_SINK_UNLINKED && u->fd >= 0 && (revents & POLLOUT)) {
if (u->use_mmap) {
- int ret;
if ((ret = mmap_write(u)) < 0)
goto fail;
@@ -908,10 +905,9 @@ static void thread_func(void *userdata) {
/* Try to read some data and pass it on to the source driver */
- if (u->source && u->source->thread_info.state != PA_SOURCE_DISCONNECTED && u->fd >= 0 && ((revents & POLLIN))) {
+ if (u->source && u->source->thread_info.state != PA_SOURCE_UNLINKED && u->fd >= 0 && ((revents & POLLIN))) {
if (u->use_mmap) {
- int ret;
if ((ret = mmap_read(u)) < 0)
goto fail;
@@ -995,21 +991,23 @@ static void thread_func(void *userdata) {
/* pa_log("loop2"); */
- /* Check whether there is a message for us to process */
- if (pa_asyncmsgq_get(u->thread_mq.inq, &object, &code, &data, &offset, &chunk, 0) == 0) {
- int ret;
-
-/* pa_log("processing msg"); */
-
- if (!object && code == PA_MESSAGE_SHUTDOWN) {
- pa_asyncmsgq_done(u->thread_mq.inq, 0);
- goto finish;
- }
+ /* Now give the sink inputs some to time to process their data */
+ if ((ret = pa_sink_process_inputs(u->sink)) < 0)
+ goto fail;
+ if (ret > 0)
+ continue;
- ret = pa_asyncmsgq_dispatch(object, code, data, offset, &chunk);
- pa_asyncmsgq_done(u->thread_mq.inq, ret);
+ /* Now give the source outputs some to time to process their data */
+ if ((ret = pa_source_process_outputs(u->source)) < 0)
+ goto fail;
+ if (ret > 0)
+ continue;
+
+ /* Check whether there is a message for us to process */
+ if ((ret = pa_thread_mq_process(&u->thread_mq) < 0))
+ goto finish;
+ if (ret > 0)
continue;
- }
if (u->fd >= 0) {
struct pollfd *pollfd;
@@ -1019,7 +1017,6 @@ static void thread_func(void *userdata) {
((u->source && PA_SOURCE_OPENED(u->source->thread_info.state)) ? POLLIN : 0) |
((u->sink && PA_SINK_OPENED(u->sink->thread_info.state)) ? POLLOUT : 0);
}
-
/* Hmm, nothing to do. Let's sleep */
if (pa_rtpoll_run(u->rtpoll) < 0) {
@@ -1212,6 +1209,7 @@ int pa__init(pa_module*m) {
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(
"OSS PCM on %s%s%s%s%s",
dev,
@@ -1220,7 +1218,7 @@ int pa__init(pa_module*m) {
hwdesc[0] ? ")" : "",
use_mmap ? " via DMA" : ""));
pa_xfree(t);
- u->source->is_hardware = 1;
+ u->source->flags = PA_SOURCE_HARDWARE|PA_SOURCE_CAN_SUSPEND|PA_SOURCE_LATENCY|PA_SOURCE_HW_VOLUME_CTRL;
u->source->refresh_volume = 1;
if (use_mmap)
@@ -1266,6 +1264,7 @@ int pa__init(pa_module*m) {
pa_sink_set_module(u->sink, m);
pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
+ pa_sink_set_rtpoll(u->sink, u->rtpoll);
pa_sink_set_description(u->sink, t = pa_sprintf_malloc(
"OSS PCM on %s%s%s%s%s",
dev,
@@ -1274,7 +1273,7 @@ int pa__init(pa_module*m) {
hwdesc[0] ? ")" : "",
use_mmap ? " via DMA" : ""));
pa_xfree(t);
- u->sink->is_hardware = 1;
+ u->sink->flags = PA_SINK_HARDWARE|PA_SINK_CAN_SUSPEND|PA_SINK_LATENCY|PA_SINK_HW_VOLUME_CTRL;
u->sink->refresh_volume = 1;
if (use_mmap)
@@ -1298,6 +1297,11 @@ go_on:
if (u->sink)
pa_asyncmsgq_post(u->thread_mq.inq, PA_MSGOBJECT(u->sink), PA_SINK_MESSAGE_GET_VOLUME, &u->sink->volume, 0, NULL, NULL);
+ if (u->sink)
+ pa_sink_put(u->sink);
+ if (u->source)
+ pa_source_put(u->source);
+
pa_modargs_free(ma);
return 0;
@@ -1324,10 +1328,10 @@ void pa__done(pa_module*m) {
return;
if (u->sink)
- pa_sink_disconnect(u->sink);
+ pa_sink_unlink(u->sink);
if (u->source)
- pa_source_disconnect(u->source);
+ pa_source_unlink(u->source);
if (u->thread) {
pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL);
diff --git a/src/modules/module-pipe-sink.c b/src/modules/module-pipe-sink.c
index a1101ab8..d5ef194f 100644
--- a/src/modules/module-pipe-sink.c
+++ b/src/modules/module-pipe-sink.c
@@ -124,17 +124,12 @@ static void thread_func(void *userdata) {
pa_rtpoll_install(u->rtpoll);
for (;;) {
- pa_msgobject *object;
- int code;
- void *data;
- pa_memchunk chunk;
- int64_t offset;
+ int ret;
struct pollfd *pollfd;
- /* Render some data and write it to the fifo */
-
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
-
+
+ /* Render some data and write it to the fifo */
if (u->sink->thread_info.state == PA_SINK_RUNNING && pollfd->revents) {
ssize_t l;
void *p;
@@ -173,19 +168,17 @@ static void thread_func(void *userdata) {
}
}
- /* Check whether there is a message for us to process */
- if (pa_asyncmsgq_get(u->thread_mq.inq, &object, &code, &data, &offset, &chunk, 0) == 0) {
- int ret;
-
- if (!object && code == PA_MESSAGE_SHUTDOWN) {
- pa_asyncmsgq_done(u->thread_mq.inq, 0);
- goto finish;
- }
+ /* Now give the sink inputs some to time to process their data */
+ if ((ret = pa_sink_process_inputs(u->sink)) < 0)
+ goto fail;
+ if (ret > 0)
+ continue;
- ret = pa_asyncmsgq_dispatch(object, code, data, offset, &chunk);
- pa_asyncmsgq_done(u->thread_mq.inq, ret);
+ /* Check whether there is a message for us to process */
+ if ((ret = pa_thread_mq_process(&u->thread_mq) < 0))
+ goto finish;
+ if (ret > 0)
continue;
- }
/* Hmm, nothing to do. Let's sleep */
pollfd->events = u->sink->thread_info.state == PA_SINK_RUNNING ? POLLOUT : 0;
@@ -271,9 +264,11 @@ int pa__init(pa_module*m) {
u->sink->parent.process_msg = sink_process_msg;
u->sink->userdata = u;
+ u->sink->flags = PA_SINK_LATENCY;
pa_sink_set_module(u->sink, m);
pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
+ pa_sink_set_rtpoll(u->sink, u->rtpoll);
pa_sink_set_description(u->sink, t = pa_sprintf_malloc("Unix FIFO sink '%s'", u->filename));
pa_xfree(t);
@@ -281,12 +276,14 @@ int pa__init(pa_module*m) {
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;
}
+ pa_sink_put(u->sink);
+
pa_modargs_free(ma);
return 0;
@@ -309,7 +306,7 @@ void pa__done(pa_module*m) {
return;
if (u->sink)
- pa_sink_disconnect(u->sink);
+ pa_sink_unlink(u->sink);
if (u->thread) {
pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL);
diff --git a/src/modules/module-pipe-source.c b/src/modules/module-pipe-source.c
index 2209d1ee..6dc94648 100644
--- a/src/modules/module-pipe-source.c
+++ b/src/modules/module-pipe-source.c
@@ -45,6 +45,7 @@
#include <pulsecore/log.h>
#include <pulsecore/thread.h>
#include <pulsecore/thread-mq.h>
+#include <pulsecore/rtpoll.h>
#include "module-pipe-source-symdef.h"
@@ -66,13 +67,17 @@ struct userdata {
pa_core *core;
pa_module *module;
pa_source *source;
+
pa_thread *thread;
pa_thread_mq thread_mq;
-
+ pa_rtpoll *rtpoll;
+
char *filename;
int fd;
pa_memchunk memchunk;
+
+ pa_rtpoll_item *rtpoll_item;
};
static const char* const valid_modargs[] = {
@@ -86,14 +91,7 @@ static const char* const valid_modargs[] = {
};
static void thread_func(void *userdata) {
- enum {
- POLLFD_ASYNCQ,
- POLLFD_FIFO,
- POLLFD_MAX,
- };
-
struct userdata *u = userdata;
- struct pollfd pollfd[POLLFD_MAX];
int read_type = 0;
pa_assert(u);
@@ -101,40 +99,18 @@ static void thread_func(void *userdata) {
pa_log_debug("Thread starting up");
pa_thread_mq_install(&u->thread_mq);
-
- memset(&pollfd, 0, sizeof(pollfd));
+ pa_rtpoll_install(u->rtpoll);
- pollfd[POLLFD_ASYNCQ].fd = pa_asyncmsgq_get_fd(u->thread_mq.inq);
- pollfd[POLLFD_ASYNCQ].events = POLLIN;
- pollfd[POLLFD_FIFO].fd = u->fd;
-
for (;;) {
- pa_msgobject *object;
- int code;
- void *data;
- pa_memchunk chunk;
- int r;
- int64_t offset;
-
- /* Check whether there is a message for us to process */
- if (pa_asyncmsgq_get(u->thread_mq.inq, &object, &code, &data, &offset, &chunk, 0) == 0) {
- int ret;
-
- if (!object && code == PA_MESSAGE_SHUTDOWN) {
- pa_asyncmsgq_done(u->thread_mq.inq, 0);
- goto finish;
- }
-
- ret = pa_asyncmsgq_dispatch(object, code, data, offset, &chunk);
- pa_asyncmsgq_done(u->thread_mq.inq, ret);
- continue;
- }
+ 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[POLLFD_FIFO].revents) {
- void *p;
+ if (u->source->thread_info.state == PA_SOURCE_RUNNING && pollfd->revents) {
ssize_t l;
+ void *p;
if (!u->memchunk.memblock) {
u->memchunk.memblock = pa_memblock_new(u->core->mempool, PIPE_BUF);
@@ -169,38 +145,35 @@ static void thread_func(void *userdata) {
pa_memchunk_reset(&u->memchunk);
}
- pollfd[POLLFD_FIFO].revents = 0;
- continue;
+ pollfd->revents = 0;
}
}
- pollfd[POLLFD_FIFO].events = u->source->thread_info.state == PA_SOURCE_RUNNING ? POLLIN : 0;
-
- /* Hmm, nothing to do. Let's sleep */
-
- if (pa_asyncmsgq_before_poll(u->thread_mq.inq) < 0)
+ /* Now give the source outputs some to time to process their data */
+ if ((ret = pa_source_process_outputs(u->source)) < 0)
+ goto fail;
+ if (ret > 0)
continue;
-/* pa_log("polling for %i", pollfd[POLLFD_FIFO].events); */
- r = poll(pollfd, POLLFD_MAX, -1);
-/* pa_log("polling got %i (r=%i) %i", r > 0 ? pollfd[POLLFD_FIFO].revents : 0, r, r > 0 ? pollfd[POLLFD_ASYNCQ].revents: 0); */
-
- pa_asyncmsgq_after_poll(u->thread_mq.inq);
+ /* Check whether there is a message for us to process */
+ if ((ret = pa_thread_mq_process(&u->thread_mq) < 0))
+ goto finish;
+ if (ret > 0)
+ continue;
- if (r < 0) {
- if (errno == EINTR)
- continue;
+ /* Hmm, nothing to do. Let's sleep */
+ pollfd->events = u->source->thread_info.state == PA_SOURCE_RUNNING ? POLLIN : 0;
+ if (pa_rtpoll_run(u->rtpoll) < 0) {
pa_log("poll() failed: %s", pa_cstrerror(errno));
goto fail;
}
- if (pollfd[POLLFD_FIFO].revents & ~POLLIN) {
+ pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
+ if (pollfd->revents & ~POLLIN) {
pa_log("FIFO shutdown.");
goto fail;
}
-
- pa_assert((pollfd[POLLFD_ASYNCQ].revents & ~POLLIN) == 0);
}
fail:
@@ -220,6 +193,7 @@ int pa__init(pa_module*m) {
pa_channel_map map;
pa_modargs *ma;
char *t;
+ struct pollfd *pollfd;
pa_assert(m);
@@ -240,6 +214,8 @@ int pa__init(pa_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, u->thread_mq.inq);
u->filename = pa_xstrdup(pa_modargs_get_value(ma, "file", DEFAULT_FILE_NAME));
@@ -268,17 +244,26 @@ int pa__init(pa_module*m) {
}
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, 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;
}
+ pa_source_put(u->source);
+
pa_modargs_free(ma);
return 0;
@@ -301,7 +286,7 @@ void pa__done(pa_module*m) {
return;
if (u->source)
- pa_source_disconnect(u->source);
+ pa_source_unlink(u->source);
if (u->thread) {
pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL);
@@ -316,6 +301,12 @@ void pa__done(pa_module*m) {
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);
diff --git a/src/modules/module-rescue-streams.c b/src/modules/module-rescue-streams.c
index e0eed036..24077dc2 100644
--- a/src/modules/module-rescue-streams.c
+++ b/src/modules/module-rescue-streams.c
@@ -138,8 +138,8 @@ int pa__init(pa_module*m) {
}
m->userdata = u = pa_xnew(struct userdata, 1);
- u->sink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_DISCONNECT], (pa_hook_cb_t) sink_hook_callback, NULL);
- u->source_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_DISCONNECT], (pa_hook_cb_t) source_hook_callback, NULL);
+ u->sink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], (pa_hook_cb_t) sink_hook_callback, NULL);
+ u->source_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], (pa_hook_cb_t) source_hook_callback, NULL);
pa_modargs_free(ma);
return 0;
diff --git a/src/modules/module-sine.c b/src/modules/module-sine.c
index f2830ff0..94036f6c 100644
--- a/src/modules/module-sine.c
+++ b/src/modules/module-sine.c
@@ -98,7 +98,7 @@ static void sink_input_kill_cb(pa_sink_input *i) {
u = i->userdata;
pa_assert(u);
- pa_sink_input_disconnect(u->sink_input);
+ pa_sink_input_unlink(u->sink_input);
pa_sink_input_unref(u->sink_input);
u->sink_input = NULL;
@@ -195,7 +195,7 @@ void pa__done(pa_module*m) {
return;
if (u->sink_input) {
- pa_sink_input_disconnect(u->sink_input);
+ pa_sink_input_unlink(u->sink_input);
pa_sink_input_unref(u->sink_input);
}
diff --git a/src/modules/module-suspend-on-idle.c b/src/modules/module-suspend-on-idle.c
index e9226ca2..79850e71 100644
--- a/src/modules/module-suspend-on-idle.c
+++ b/src/modules/module-suspend-on-idle.c
@@ -53,16 +53,16 @@ struct userdata {
pa_hook_slot
*sink_new_slot,
*source_new_slot,
- *sink_disconnect_slot,
- *source_disconnect_slot,
+ *sink_unlink_slot,
+ *source_unlink_slot,
*sink_state_changed_slot,
*source_state_changed_slot;
pa_hook_slot
*sink_input_new_slot,
*source_output_new_slot,
- *sink_input_disconnect_slot,
- *source_output_disconnect_slot,
+ *sink_input_unlink_slot,
+ *source_output_unlink_slot,
*sink_input_move_slot,
*source_output_move_slot,
*sink_input_move_post_slot,
@@ -139,8 +139,8 @@ static pa_hook_result_t sink_input_new_hook_cb(pa_core *c, pa_sink_input *s, str
pa_sink_input_assert_ref(s);
pa_assert(u);
- pa_assert_se((d = pa_hashmap_get(u->device_infos, s->sink)));
- resume(d);
+ if ((d = pa_hashmap_get(u->device_infos, s->sink)))
+ resume(d);
return PA_HOOK_OK;
}
@@ -152,35 +152,35 @@ static pa_hook_result_t source_output_new_hook_cb(pa_core *c, pa_source_output *
pa_source_output_assert_ref(s);
pa_assert(u);
- pa_assert_se((d = pa_hashmap_get(u->device_infos, s->source)));
- resume(d);
+ if ((d = pa_hashmap_get(u->device_infos, s->source)))
+ resume(d);
return PA_HOOK_OK;
}
-static pa_hook_result_t sink_input_disconnect_hook_cb(pa_core *c, pa_sink_input *s, struct userdata *u) {
+static pa_hook_result_t sink_input_unlink_hook_cb(pa_core *c, pa_sink_input *s, struct userdata *u) {
pa_assert(c);
pa_sink_input_assert_ref(s);
pa_assert(u);
if (pa_sink_used_by(s->sink) <= 0) {
struct device_info *d;
- pa_assert_se((d = pa_hashmap_get(u->device_infos, s->sink)));
- restart(d);
+ if ((d = pa_hashmap_get(u->device_infos, s->sink)))
+ restart(d);
}
return PA_HOOK_OK;
}
-static pa_hook_result_t source_output_disconnect_hook_cb(pa_core *c, pa_source_output *s, struct userdata *u) {
+static pa_hook_result_t source_output_unlink_hook_cb(pa_core *c, pa_source_output *s, struct userdata *u) {
pa_assert(c);
pa_source_output_assert_ref(s);
pa_assert(u);
if (pa_source_used_by(s->source) <= 0) {
struct device_info *d;
- pa_assert_se((d = pa_hashmap_get(u->device_infos, s->source)));
- restart(d);
+ if ((d = pa_hashmap_get(u->device_infos, s->source)))
+ restart(d);
}
return PA_HOOK_OK;
@@ -193,8 +193,8 @@ static pa_hook_result_t sink_input_move_hook_cb(pa_core *c, pa_sink_input *s, st
if (pa_sink_used_by(s->sink) <= 1) {
struct device_info *d;
- pa_assert_se((d = pa_hashmap_get(u->device_infos, s->sink)));
- restart(d);
+ if ((d = pa_hashmap_get(u->device_infos, s->sink)))
+ restart(d);
}
return PA_HOOK_OK;
@@ -206,8 +206,8 @@ static pa_hook_result_t sink_input_move_post_hook_cb(pa_core *c, pa_sink_input *
pa_sink_input_assert_ref(s);
pa_assert(u);
- pa_assert_se((d = pa_hashmap_get(u->device_infos, s->sink)));
- resume(d);
+ if ((d = pa_hashmap_get(u->device_infos, s->sink)))
+ resume(d);
return PA_HOOK_OK;
}
@@ -219,8 +219,9 @@ static pa_hook_result_t source_output_move_hook_cb(pa_core *c, pa_source_output
if (pa_source_used_by(s->source) <= 1) {
struct device_info *d;
- pa_assert_se((d = pa_hashmap_get(u->device_infos, s->source)));
- restart(d);
+
+ if ((d = pa_hashmap_get(u->device_infos, s->source)))
+ restart(d);
}
return PA_HOOK_OK;
@@ -232,24 +233,36 @@ static pa_hook_result_t source_output_move_post_hook_cb(pa_core *c, pa_source_ou
pa_source_output_assert_ref(s);
pa_assert(u);
- pa_assert_se((d = pa_hashmap_get(u->device_infos, s->source)));
- resume(d);
+ if ((d = pa_hashmap_get(u->device_infos, s->source)))
+ resume(d);
return PA_HOOK_OK;
}
static pa_hook_result_t device_new_hook_cb(pa_core *c, pa_object *o, struct userdata *u) {
struct device_info *d;
+ pa_source *source;
+ pa_sink *sink;
pa_assert(c);
pa_object_assert_ref(o);
pa_assert(u);
+ source = pa_source_isinstance(o) ? PA_SOURCE(o) : NULL;
+ sink = pa_sink_isinstance(o) ? PA_SINK(o) : NULL;
+
+ pa_assert(source || sink);
+
+ if (source && !(source->flags & PA_SOURCE_CAN_SUSPEND))
+ return PA_HOOK_OK;
+
+ if (sink && !(sink->flags & PA_SINK_CAN_SUSPEND))
+ return PA_HOOK_OK;
+
d = pa_xnew(struct device_info, 1);
d->userdata = u;
- d->source = pa_source_isinstance(o) ? pa_source_ref(PA_SOURCE(o)) : NULL;
- d->sink = pa_sink_isinstance(o) ? pa_sink_ref(PA_SINK(o)) : NULL;
- pa_assert(d->source || d->sink);
+ d->source = source ? pa_source_ref(source) : NULL;
+ d->sink = sink ? pa_sink_ref(sink) : NULL;
d->time_event = c->mainloop->time_new(c->mainloop, NULL, timeout_cb, d);
pa_hashmap_put(u->device_infos, o, d);
@@ -273,15 +286,15 @@ static void device_info_free(struct device_info *d) {
pa_xfree(d);
}
-static pa_hook_result_t device_disconnect_hook_cb(pa_core *c, pa_object *o, struct userdata *u) {
+static pa_hook_result_t device_unlink_hook_cb(pa_core *c, pa_object *o, struct userdata *u) {
struct device_info *d;
pa_assert(c);
pa_object_assert_ref(o);
pa_assert(u);
- pa_assert_se((d = pa_hashmap_remove(u->device_infos, o)));
- device_info_free(d);
+ if ((d = pa_hashmap_remove(u->device_infos, o)))
+ device_info_free(d);
return PA_HOOK_OK;
}
@@ -353,15 +366,15 @@ int pa__init(pa_module*m) {
u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_NEW_POST], (pa_hook_cb_t) device_new_hook_cb, u);
u->source_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_NEW_POST], (pa_hook_cb_t) device_new_hook_cb, u);
- u->sink_disconnect_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_DISCONNECT_POST], (pa_hook_cb_t) device_disconnect_hook_cb, u);
- u->source_disconnect_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_DISCONNECT_POST], (pa_hook_cb_t) device_disconnect_hook_cb, u);
+ u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK_POST], (pa_hook_cb_t) device_unlink_hook_cb, u);
+ u->source_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK_POST], (pa_hook_cb_t) device_unlink_hook_cb, u);
u->sink_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_STATE_CHANGED], (pa_hook_cb_t) device_state_changed_hook_cb, u);
u->source_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_STATE_CHANGED], (pa_hook_cb_t) device_state_changed_hook_cb, u);
u->sink_input_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], (pa_hook_cb_t) sink_input_new_hook_cb, u);
u->source_output_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PUT], (pa_hook_cb_t) source_output_new_hook_cb, u);
- u->sink_input_disconnect_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_DISCONNECT_POST], (pa_hook_cb_t) sink_input_disconnect_hook_cb, u);
- u->source_output_disconnect_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_DISCONNECT_POST], (pa_hook_cb_t) source_output_disconnect_hook_cb, u);
+ u->sink_input_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK_POST], (pa_hook_cb_t) sink_input_unlink_hook_cb, u);
+ u->source_output_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK_POST], (pa_hook_cb_t) source_output_unlink_hook_cb, u);
u->sink_input_move_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE], (pa_hook_cb_t) sink_input_move_hook_cb, u);
u->source_output_move_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE], (pa_hook_cb_t) source_output_move_hook_cb, u);
u->sink_input_move_post_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_POST], (pa_hook_cb_t) sink_input_move_post_hook_cb, u);
@@ -392,22 +405,22 @@ void pa__done(pa_module*m) {
if (u->sink_new_slot)
pa_hook_slot_free(u->sink_new_slot);
- if (u->sink_disconnect_slot)
- pa_hook_slot_free(u->sink_disconnect_slot);
+ if (u->sink_unlink_slot)
+ pa_hook_slot_free(u->sink_unlink_slot);
if (u->sink_state_changed_slot)
pa_hook_slot_free(u->sink_state_changed_slot);
if (u->source_new_slot)
pa_hook_slot_free(u->source_new_slot);
- if (u->source_disconnect_slot)
- pa_hook_slot_free(u->source_disconnect_slot);
+ if (u->source_unlink_slot)
+ pa_hook_slot_free(u->source_unlink_slot);
if (u->source_state_changed_slot)
pa_hook_slot_free(u->source_state_changed_slot);
if (u->sink_input_new_slot)
pa_hook_slot_free(u->sink_input_new_slot);
- if (u->sink_input_disconnect_slot)
- pa_hook_slot_free(u->sink_input_disconnect_slot);
+ if (u->sink_input_unlink_slot)
+ pa_hook_slot_free(u->sink_input_unlink_slot);
if (u->sink_input_move_slot)
pa_hook_slot_free(u->sink_input_move_slot);
if (u->sink_input_move_post_slot)
@@ -415,8 +428,8 @@ void pa__done(pa_module*m) {
if (u->source_output_new_slot)
pa_hook_slot_free(u->source_output_new_slot);
- if (u->source_output_disconnect_slot)
- pa_hook_slot_free(u->source_output_disconnect_slot);
+ if (u->source_output_unlink_slot)
+ pa_hook_slot_free(u->source_output_unlink_slot);
if (u->source_output_move_slot)
pa_hook_slot_free(u->source_output_move_slot);
if (u->source_output_move_post_slot)