From 4d623f0d4442148f20f2ffdc85cf95e54ef83721 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 30 Aug 2007 22:57:53 +0000 Subject: Lots of assorted minor cleanups and fixes: * s/disconnect/unlink/ at many places where it makes sense * make "start_corked" a normal pa_sink_input/pa_source_output flag instead of a seperate boolean variable * add generic process() function to pa_sink_input/pa_source_output vtable that can be used by streams to do some arbitrary processing in each rt loop iteration even the sink/source is suspended * add detach()/attach() functions to pa_sink_input/pa_source_output vtable that are called when ever the rtpoll object of the event thread changes * add suspend() functions to pa_sink_input/pa_source_output vtable which are called whenever the sink/source they are attached to suspends/resumes * add PA_SINK_INIT/PA_SOURCE_INIT/PA_SINK_INPUT_INIT/PA_SINK_OUTPUT_INIT states to state machines which is active between _new() and _put() * seperate _put() from _new() for pa_sink/pa_source * add PA_SOURCE_OUTPUT_DONT_MOVE/PA_SINK_INPUT_DONT_MOVE flags * make the pa_rtpoll object a property of pa_sink/pa_source to allow streams attached to them make use of it * fix skipping over move_silence * update module-pipe-source to make use of pa_rtpoll * add pa_sink_skip() as optimization in cases where the actualy data returned by pa_sink_render() doesn't matter git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1733 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/modules/module-suspend-on-idle.c | 93 ++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 40 deletions(-) (limited to 'src/modules/module-suspend-on-idle.c') 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) -- cgit