summaryrefslogtreecommitdiffstats
path: root/src/modules/module-combine.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/module-combine.c')
-rw-r--r--src/modules/module-combine.c151
1 files changed, 82 insertions, 69 deletions
diff --git a/src/modules/module-combine.c b/src/modules/module-combine.c
index 996cd4f6..fc8be18d 100644
--- a/src/modules/module-combine.c
+++ b/src/modules/module-combine.c
@@ -66,7 +66,7 @@ PA_MODULE_USAGE(
"channel_map=<channel map>");
#define DEFAULT_SINK_NAME "combined"
-#define MEMBLOCKQ_MAXLENGTH (1024*170)
+#define MEMBLOCKQ_MAXLENGTH (1024*1024*16)
#define DEFAULT_ADJUST_TIME 10
@@ -139,7 +139,7 @@ enum {
};
enum {
- SINK_INPUT_MESSAGE_POST = PA_SINK_INPUT_MESSAGE_MAX
+ SINK_INPUT_MESSAGE_POST = PA_SINK_INPUT_MESSAGE_MAX,
};
static void output_free(struct output *o);
@@ -162,13 +162,13 @@ static void adjust_rates(struct userdata *u) {
if (!u->master)
return;
- if (!PA_SINK_OPENED(pa_sink_get_state(u->sink)))
+ if (!PA_SINK_IS_OPENED(pa_sink_get_state(u->sink)))
return;
for (o = pa_idxset_first(u->outputs, &idx); o; o = pa_idxset_next(u->outputs, &idx)) {
pa_usec_t sink_latency;
- if (!o->sink_input || !PA_SINK_OPENED(pa_sink_get_state(o->sink)))
+ if (!o->sink_input || !PA_SINK_IS_OPENED(pa_sink_get_state(o->sink)))
continue;
sink_latency = pa_sink_get_latency(o->sink);
@@ -194,7 +194,7 @@ static void adjust_rates(struct userdata *u) {
for (o = pa_idxset_first(u->outputs, &idx); o; o = pa_idxset_next(u->outputs, &idx)) {
uint32_t r = base_rate;
- if (!o->sink_input || !PA_SINK_OPENED(pa_sink_get_state(o->sink)))
+ if (!o->sink_input || !PA_SINK_IS_OPENED(pa_sink_get_state(o->sink)))
continue;
if (o->total_latency < target_latency)
@@ -203,10 +203,10 @@ static void adjust_rates(struct userdata *u) {
r += (uint32_t) (((((double) o->total_latency - target_latency))/u->adjust_time)*r/PA_USEC_PER_SEC);
if (r < (uint32_t) (base_rate*0.9) || r > (uint32_t) (base_rate*1.1)) {
- pa_log_warn("[%s] sample rates too different, not adjusting (%u vs. %u).", o->sink_input->name, base_rate, r);
+ pa_log_warn("[%s] sample rates too different, not adjusting (%u vs. %u).", pa_proplist_gets(o->sink_input->proplist, PA_PROP_MEDIA_NAME), base_rate, r);
pa_sink_input_set_rate(o->sink_input, base_rate);
} else {
- pa_log_info("[%s] new rate is %u Hz; ratio is %0.3f; latency is %0.0f usec.", o->sink_input->name, r, (double) r / base_rate, (float) o->total_latency);
+ pa_log_info("[%s] new rate is %u Hz; ratio is %0.3f; latency is %0.0f usec.", pa_proplist_gets(o->sink_input->proplist, PA_PROP_MEDIA_NAME), r, (double) r / base_rate, (float) o->total_latency);
pa_sink_input_set_rate(o->sink_input, r);
}
}
@@ -250,10 +250,18 @@ static void thread_func(void *userdata) {
if (u->sink->thread_info.state == PA_SINK_RUNNING && !u->thread_info.active_outputs) {
struct timeval now;
+ /* Just rewind if necessary, since we are in NULL mode, we
+ * don't have to pass this on */
+ pa_sink_process_rewind(u->sink, u->sink->thread_info.rewind_nbytes);
+ u->sink->thread_info.rewind_nbytes = 0;
+
pa_rtclock_get(&now);
if (!u->thread_info.in_null_mode || pa_timeval_cmp(&u->thread_info.timestamp, &now) <= 0) {
- pa_sink_skip(u->sink, u->block_size);
+ pa_memchunk chunk;
+
+ pa_sink_render_full(u->sink, u->block_size, &chunk);
+ pa_memblock_unref(chunk.memblock);
if (!u->thread_info.in_null_mode)
u->thread_info.timestamp = now;
@@ -354,27 +362,20 @@ static void request_memblock(struct output *o, size_t length) {
}
/* Called from I/O thread context */
-static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chunk) {
+static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk) {
struct output *o;
pa_sink_input_assert_ref(i);
pa_assert_se(o = i->userdata);
/* If necessary, get some new data */
- request_memblock(o, length);
-
- return pa_memblockq_peek(o->memblockq, chunk);
-}
-
-/* Called from I/O thread context */
-static void sink_input_drop_cb(pa_sink_input *i, size_t length) {
- struct output *o;
+ request_memblock(o, nbytes);
- pa_sink_input_assert_ref(i);
- pa_assert(length > 0);
- pa_assert_se(o = i->userdata);
+ if (pa_memblockq_peek(o->memblockq, chunk) < 0)
+ return -1;
- pa_memblockq_drop(o->memblockq, length);
+ pa_memblockq_drop(o->memblockq, chunk->length);
+ return 0;
}
/* Called from I/O thread context */
@@ -386,7 +387,7 @@ static void sink_input_attach_cb(pa_sink_input *i) {
/* Set up the queue from the sink thread to us */
pa_assert(!o->inq_rtpoll_item);
- o->inq_rtpoll_item = pa_rtpoll_item_new_asyncmsgq(
+ o->inq_rtpoll_item = pa_rtpoll_item_new_asyncmsgq_read(
i->sink->rtpoll,
PA_RTPOLL_LATE, /* This one is not that important, since we check for data in _peek() anyway. */
o->inq);
@@ -434,12 +435,13 @@ static int sink_input_process_msg(pa_msgobject *obj, int code, void *data, int64
case SINK_INPUT_MESSAGE_POST:
- if (PA_SINK_OPENED(o->sink_input->sink->thread_info.state))
+ if (PA_SINK_IS_OPENED(o->sink_input->sink->thread_info.state))
pa_memblockq_push_align(o->memblockq, chunk);
else
pa_memblockq_flush(o->memblockq);
break;
+
}
return pa_sink_input_process_msg(obj, code, data, offset, chunk);
@@ -472,7 +474,7 @@ static void enable_output(struct output *o) {
pa_sink_input_put(o->sink_input);
- if (o->userdata->sink && PA_SINK_LINKED(pa_sink_get_state(o->userdata->sink)))
+ if (o->userdata->sink && PA_SINK_IS_LINKED(pa_sink_get_state(o->userdata->sink)))
pa_asyncmsgq_send(o->userdata->sink->asyncmsgq, PA_MSGOBJECT(o->userdata->sink), SINK_MESSAGE_ADD_OUTPUT, o, 0, NULL);
}
}
@@ -505,7 +507,7 @@ static void unsuspend(struct userdata *u) {
pa_sink_suspend(o->sink, FALSE);
- if (PA_SINK_OPENED(pa_sink_get_state(o->sink)))
+ if (PA_SINK_IS_OPENED(pa_sink_get_state(o->sink)))
enable_output(o);
}
@@ -526,7 +528,7 @@ static int sink_set_state(pa_sink *sink, pa_sink_state_t state) {
switch (state) {
case PA_SINK_SUSPENDED:
- pa_assert(PA_SINK_OPENED(pa_sink_get_state(u->sink)));
+ pa_assert(PA_SINK_IS_OPENED(pa_sink_get_state(u->sink)));
suspend(u);
break;
@@ -585,7 +587,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
/* Create pa_asyncmsgq to the sink thread */
- op->outq_rtpoll_item = pa_rtpoll_item_new_asyncmsgq(
+ op->outq_rtpoll_item = pa_rtpoll_item_new_asyncmsgq_read(
u->rtpoll,
PA_RTPOLL_EARLY-1, /* This item is very important */
op->outq);
@@ -616,35 +618,35 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse
}
/* Called from main context */
-static pa_usec_t sink_get_latency_cb(pa_sink *s) {
- struct userdata *u;
+/* static pa_usec_t sink_get_latency_cb(pa_sink *s) { */
+/* struct userdata *u; */
- pa_sink_assert_ref(s);
- pa_assert_se(u = s->userdata);
+/* pa_sink_assert_ref(s); */
+/* pa_assert_se(u = s->userdata); */
- if (u->master) {
- /* If we have a master sink, we just return the latency of it
- * and add our own buffering on top */
+/* if (u->master) { */
+/* /\* If we have a master sink, we just return the latency of it */
+/* * and add our own buffering on top *\/ */
- if (!u->master->sink_input)
- return 0;
+/* if (!u->master->sink_input) */
+/* return 0; */
- return
- pa_sink_input_get_latency(u->master->sink_input) +
- pa_sink_get_latency(u->master->sink);
+/* return */
+/* pa_sink_input_get_latency(u->master->sink_input) + */
+/* pa_sink_get_latency(u->master->sink); */
- } else {
- pa_usec_t usec = 0;
+/* } else { */
+/* pa_usec_t usec = 0; */
- /* We have no master, hence let's ask our own thread which
- * implements the NULL sink */
+/* /\* We have no master, hence let's ask our own thread which */
+/* * implements the NULL sink *\/ */
- if (pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_GET_LATENCY, &usec, 0, NULL) < 0)
- return 0;
+/* if (pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_GET_LATENCY, &usec, 0, NULL) < 0) */
+/* return 0; */
- return usec;
- }
-}
+/* return usec; */
+/* } */
+/* } */
static void update_description(struct userdata *u) {
int first = 1;
@@ -665,10 +667,10 @@ static void update_description(struct userdata *u) {
char *e;
if (first) {
- e = pa_sprintf_malloc("%s %s", t, o->sink->description);
+ e = pa_sprintf_malloc("%s %s", t, pa_strnull(pa_proplist_gets(o->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
first = 0;
} else
- e = pa_sprintf_malloc("%s, %s", t, o->sink->description);
+ e = pa_sprintf_malloc("%s, %s", t, pa_strnull(pa_proplist_gets(o->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
pa_xfree(t);
t = e;
@@ -698,7 +700,7 @@ static void pick_master(struct userdata *u, struct output *except) {
if (u->master &&
u->master != except &&
u->master->sink_input &&
- PA_SINK_OPENED(pa_sink_get_state(u->master->sink))) {
+ PA_SINK_IS_OPENED(pa_sink_get_state(u->master->sink))) {
update_master(u, u->master);
return;
}
@@ -706,7 +708,7 @@ static void pick_master(struct userdata *u, struct output *except) {
for (o = pa_idxset_first(u->outputs, &idx); o; o = pa_idxset_next(u->outputs, &idx))
if (o != except &&
o->sink_input &&
- PA_SINK_OPENED(pa_sink_get_state(o->sink))) {
+ PA_SINK_IS_OPENED(pa_sink_get_state(o->sink))) {
update_master(u, o);
return;
}
@@ -723,12 +725,12 @@ static int output_create_sink_input(struct output *o) {
if (o->sink_input)
return 0;
- t = pa_sprintf_malloc("Simultaneous output on %s", o->sink->description);
+ t = pa_sprintf_malloc("Simultaneous output on %s", pa_strnull(pa_proplist_gets(o->sink->proplist, PA_PROP_DEVICE_DESCRIPTION)));
pa_sink_input_new_data_init(&data);
data.sink = o->sink;
data.driver = __FILE__;
- data.name = t;
+ pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, t);
pa_sink_input_new_data_set_sample_spec(&data, &o->userdata->sink->sample_spec);
pa_sink_input_new_data_set_channel_map(&data, &o->userdata->sink->channel_map);
data.module = o->userdata->module;
@@ -736,14 +738,15 @@ static int output_create_sink_input(struct output *o) {
o->sink_input = pa_sink_input_new(o->userdata->core, &data, PA_SINK_INPUT_VARIABLE_RATE|PA_SINK_INPUT_DONT_MOVE);
+ pa_sink_input_new_data_done(&data);
+
pa_xfree(t);
if (!o->sink_input)
return -1;
o->sink_input->parent.process_msg = sink_input_process_msg;
- o->sink_input->peek = sink_input_peek_cb;
- o->sink_input->drop = sink_input_drop_cb;
+ o->sink_input->pop = sink_input_pop_cb;
o->sink_input->attach = sink_input_attach_cb;
o->sink_input->detach = sink_input_detach_cb;
o->sink_input->kill = sink_input_kill_cb;
@@ -775,26 +778,27 @@ static struct output *output_new(struct userdata *u, pa_sink *sink) {
pa_frame_size(&u->sink->sample_spec),
1,
0,
+ 0,
NULL);
pa_assert_se(pa_idxset_put(u->outputs, o, NULL) == 0);
- if (u->sink && PA_SINK_LINKED(pa_sink_get_state(u->sink)))
+ if (u->sink && PA_SINK_IS_LINKED(pa_sink_get_state(u->sink)))
pa_asyncmsgq_send(u->sink->asyncmsgq, PA_MSGOBJECT(u->sink), SINK_MESSAGE_ADD_OUTPUT, o, 0, NULL);
else {
/* If the sink is not yet started, we need to do the activation ourselves */
PA_LLIST_PREPEND(struct output, u->thread_info.active_outputs, o);
- o->outq_rtpoll_item = pa_rtpoll_item_new_asyncmsgq(
+ o->outq_rtpoll_item = pa_rtpoll_item_new_asyncmsgq_read(
u->rtpoll,
PA_RTPOLL_EARLY-1, /* This item is very important */
o->outq);
}
- if (PA_SINK_OPENED(pa_sink_get_state(u->sink)) || pa_sink_get_state(u->sink) == PA_SINK_INIT) {
+ if (PA_SINK_IS_OPENED(pa_sink_get_state(u->sink)) || pa_sink_get_state(u->sink) == PA_SINK_INIT) {
pa_sink_suspend(sink, FALSE);
- if (PA_SINK_OPENED(pa_sink_get_state(sink)))
+ if (PA_SINK_IS_OPENED(pa_sink_get_state(sink)))
if (output_create_sink_input(o) < 0)
goto fail;
}
@@ -897,7 +901,7 @@ static pa_hook_result_t sink_state_changed_hook_cb(pa_core *c, pa_sink *s, struc
state = pa_sink_get_state(s);
- if (PA_SINK_OPENED(state) && PA_SINK_OPENED(pa_sink_get_state(u->sink)) && !o->sink_input) {
+ if (PA_SINK_IS_OPENED(state) && PA_SINK_IS_OPENED(pa_sink_get_state(u->sink)) && !o->sink_input) {
enable_output(o);
pick_master(u, NULL);
}
@@ -920,6 +924,7 @@ int pa__init(pa_module*m) {
pa_channel_map map;
struct output *o;
uint32_t idx;
+ pa_sink_new_data data;
pa_assert(m);
@@ -943,8 +948,8 @@ int pa__init(pa_module*m) {
u->master = NULL;
u->time_event = NULL;
u->adjust_time = DEFAULT_ADJUST_TIME;
- pa_thread_mq_init(&u->thread_mq, m->core->mainloop);
u->rtpoll = pa_rtpoll_new();
+ pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll);
u->thread = NULL;
u->resample_method = resample_method;
u->outputs = pa_idxset_new(NULL, NULL);
@@ -953,7 +958,6 @@ int pa__init(pa_module*m) {
PA_LLIST_HEAD_INIT(struct output, u->thread_info.active_outputs);
pa_atomic_store(&u->thread_info.running, FALSE);
u->thread_info.in_null_mode = FALSE;
- pa_rtpoll_item_new_asyncmsgq(u->rtpoll, PA_RTPOLL_EARLY, u->thread_mq.inq);
if (pa_modargs_get_value_u32(ma, "adjust_time", &u->adjust_time) < 0) {
pa_log("Failed to parse adjust_time value");
@@ -1003,19 +1007,28 @@ int pa__init(pa_module*m) {
goto fail;
}
- if (!(u->sink = pa_sink_new(m->core, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) {
+ pa_sink_new_data_init(&data);
+ data.name = pa_xstrdup(pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME));
+ data.namereg_fail = FALSE;
+ data.driver = __FILE__;
+ data.module = m;
+ pa_sink_new_data_set_sample_spec(&data, &ss);
+ pa_sink_new_data_set_channel_map(&data, &map);
+ pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, "Simultaneous Output");
+
+ u->sink = pa_sink_new(m->core, &data, PA_SINK_LATENCY);
+ pa_sink_new_data_done(&data);
+
+ if (!u->sink) {
pa_log("Failed to create sink");
goto fail;
}
u->sink->parent.process_msg = sink_process_msg;
- u->sink->get_latency = sink_get_latency_cb;
+/* u->sink->get_latency = sink_get_latency_cb; */
u->sink->set_state = sink_set_state;
u->sink->userdata = u;
- u->sink->flags = PA_SINK_LATENCY;
- pa_sink_set_module(u->sink, m);
- pa_sink_set_description(u->sink, "Simultaneous output");
pa_sink_set_rtpoll(u->sink, u->rtpoll);
pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
@@ -1075,7 +1088,7 @@ 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) sink_new_hook_cb, u);
+ u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], (pa_hook_cb_t) sink_new_hook_cb, u);
}
u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], (pa_hook_cb_t) sink_unlink_hook_cb, u);