}
m->userdata = u = pa_xnew(struct userdata, 1);
- u->sink_slot = pa_hook_connect(&m->core->hook_sink_disconnect, (pa_hook_cb_t) sink_hook_callback, NULL);
- u->source_slot = pa_hook_connect(&m->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_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);
pa_modargs_free(ma);
return 0;
pa_core *core;
pa_usec_t timeout;
pa_hashmap *device_infos;
- pa_hook_slot *sink_new_slot, *source_new_slot, *sink_disconnect_slot, *source_disconnect_slot;
+ pa_hook_slot *sink_new_slot, *source_new_slot, *sink_disconnect_slot, *source_disconnect_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;
};
d->userdata->core->mainloop->time_restart(d->time_event, NULL);
- if (d->sink && pa_sink_used_by(d->sink) <= 0) {
+ if (d->sink && pa_sink_used_by(d->sink) <= 0 && pa_sink_get_state(d->sink) != PA_SINK_SUSPENDED) {
pa_log_info("Sink %s idle for too long, suspending ...", d->sink->name);
pa_sink_suspend(d->sink, 1);
pa_source_suspend(d->sink->monitor_source, 1);
}
- if (d->source && pa_source_used_by(d->source) <= 0) {
+ if (d->source && pa_source_used_by(d->source) <= 0 && pa_source_get_state(d->source) != PA_SOURCE_SUSPENDED) {
pa_log_info("Source %s idle for too long, suspending ...", d->source->name);
pa_source_suspend(d->source, 1);
}
return PA_HOOK_OK;
}
+static pa_hook_result_t device_state_changed_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);
+
+ if (!(d = pa_hashmap_get(u->device_infos, o)))
+ return PA_HOOK_OK;
+
+ if (pa_sink_isinstance(o)) {
+ pa_sink *s = PA_SINK(o);
+
+ if (pa_sink_used_by(s) <= 0) {
+ pa_sink_state_t state = pa_sink_get_state(s);
+
+ if (state == PA_SINK_RUNNING || state == PA_SINK_IDLE)
+ restart(d);
+ }
+
+ } else if (pa_source_isinstance(o)) {
+ pa_source *s = PA_SOURCE(o);
+
+ if (pa_source_used_by(s) <= 0) {
+ pa_sink_state_t state = pa_source_get_state(s);
+
+ if (state == PA_SINK_RUNNING || state == PA_SINK_IDLE)
+ restart(d);
+ }
+ }
+
+ return PA_HOOK_OK;
+}
+
int pa__init(pa_module*m) {
pa_modargs *ma = NULL;
struct userdata *u;
for (source = pa_idxset_first(m->core->sources, &idx); source; source = pa_idxset_next(m->core->sources, &idx))
device_new_hook_cb(m->core, PA_OBJECT(source), u);
- u->sink_new_slot = pa_hook_connect(&m->core->hook_sink_new_post, (pa_hook_cb_t) device_new_hook_cb, u);
- u->source_new_slot = pa_hook_connect(&m->core->hook_source_new_post, (pa_hook_cb_t) device_new_hook_cb, u);
- u->sink_disconnect_slot = pa_hook_connect(&m->core->hook_sink_disconnect_post, (pa_hook_cb_t) device_disconnect_hook_cb, u);
- u->source_disconnect_slot = pa_hook_connect(&m->core->hook_source_disconnect_post, (pa_hook_cb_t) device_disconnect_hook_cb, u);
-
- u->sink_input_new_slot = pa_hook_connect(&m->core->hook_sink_input_new_post, (pa_hook_cb_t) sink_input_new_hook_cb, u);
- u->source_output_new_slot = pa_hook_connect(&m->core->hook_source_output_new_post, (pa_hook_cb_t) source_output_new_hook_cb, u);
- u->sink_input_disconnect_slot = pa_hook_connect(&m->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->hook_source_output_disconnect_post, (pa_hook_cb_t) source_output_disconnect_hook_cb, u);
+ 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], (pa_hook_cb_t) device_disconnect_hook_cb, u);
+ u->source_disconnect_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_DISCONNECT], (pa_hook_cb_t) device_disconnect_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);
pa_modargs_free(ma);
return 0;
pa_hook_slot_free(u->sink_new_slot);
if (u->sink_disconnect_slot)
pa_hook_slot_free(u->sink_disconnect_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_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);
goto fail;
u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK_INPUT|PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT, subscribe_callback, u);
- u->sink_input_hook_slot = pa_hook_connect(&m->core->hook_sink_input_new, (pa_hook_cb_t) sink_input_hook_callback, u);
- u->source_output_hook_slot = pa_hook_connect(&m->core->hook_source_output_new, (pa_hook_cb_t) source_output_hook_callback, u);
+ u->sink_input_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], (pa_hook_cb_t) sink_input_hook_callback, u);
+ u->source_output_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_NEW], (pa_hook_cb_t) source_output_hook_callback, u);
pa_modargs_free(ma);
return 0;
pa_core* pa_core_new(pa_mainloop_api *m, int shared) {
pa_core* c;
pa_mempool *pool;
-
+ int j;
+
pa_assert(m);
if (shared) {
c->is_system_instance = 0;
- pa_hook_init(&c->hook_sink_new, c);
- pa_hook_init(&c->hook_sink_new_post, c);
- pa_hook_init(&c->hook_sink_disconnect, c);
- pa_hook_init(&c->hook_sink_disconnect_post, c);
- pa_hook_init(&c->hook_source_new, c);
- pa_hook_init(&c->hook_source_new_post, c);
- pa_hook_init(&c->hook_source_disconnect, c);
- pa_hook_init(&c->hook_source_disconnect_post, c);
- pa_hook_init(&c->hook_sink_input_new, c);
- pa_hook_init(&c->hook_sink_input_new_post, c);
- pa_hook_init(&c->hook_sink_input_disconnect, c);
- pa_hook_init(&c->hook_sink_input_disconnect_post, c);
- pa_hook_init(&c->hook_source_output_new, c);
- pa_hook_init(&c->hook_source_output_new_post, c);
- pa_hook_init(&c->hook_source_output_disconnect, c);
- pa_hook_init(&c->hook_source_output_disconnect_post, c);
+ for (j = 0; j < PA_CORE_HOOK_MAX; j++)
+ pa_hook_init(&c->hooks[j], c);
pa_property_init(c);
static void core_free(pa_object *o) {
pa_core *c = PA_CORE(o);
+ int j;
pa_assert(c);
pa_module_unload_all(c);
pa_property_cleanup(c);
- pa_hook_free(&c->hook_sink_new);
- pa_hook_free(&c->hook_sink_new_post);
- pa_hook_free(&c->hook_sink_disconnect);
- pa_hook_free(&c->hook_sink_disconnect_post);
- pa_hook_free(&c->hook_source_new);
- pa_hook_free(&c->hook_source_new_post);
- pa_hook_free(&c->hook_source_disconnect);
- pa_hook_free(&c->hook_source_disconnect_post);
- pa_hook_free(&c->hook_sink_input_new);
- pa_hook_free(&c->hook_sink_input_new_post);
- pa_hook_free(&c->hook_sink_input_disconnect);
- pa_hook_free(&c->hook_sink_input_disconnect_post);
- pa_hook_free(&c->hook_source_output_new);
- pa_hook_free(&c->hook_source_output_new_post);
- pa_hook_free(&c->hook_source_output_disconnect);
- pa_hook_free(&c->hook_source_output_disconnect_post);
+ for (j = 0; j < PA_CORE_HOOK_MAX; j++)
+ pa_hook_free(&c->hooks[j]);
pa_xfree(c);
}
#include <pulsecore/sink-input.h>
#include <pulsecore/msgobject.h>
+typedef enum pa_core_hook {
+ PA_CORE_HOOK_SINK_NEW_POST,
+ PA_CORE_HOOK_SINK_DISCONNECT,
+ PA_CORE_HOOK_SINK_DISCONNECT_POST,
+ PA_CORE_HOOK_SINK_STATE_CHANGED,
+ PA_CORE_HOOK_SOURCE_NEW_POST,
+ PA_CORE_HOOK_SOURCE_DISCONNECT,
+ PA_CORE_HOOK_SOURCE_DISCONNECT_POST,
+ PA_CORE_HOOK_SOURCE_STATE_CHANGED,
+ PA_CORE_HOOK_SINK_INPUT_NEW,
+ PA_CORE_HOOK_SINK_INPUT_PUT,
+ PA_CORE_HOOK_SINK_INPUT_DISCONNECT,
+ PA_CORE_HOOK_SINK_INPUT_DISCONNECT_POST,
+ PA_CORE_HOOK_SOURCE_OUTPUT_NEW,
+ PA_CORE_HOOK_SOURCE_OUTPUT_PUT,
+ PA_CORE_HOOK_SOURCE_OUTPUT_DISCONNECT,
+ PA_CORE_HOOK_SOURCE_OUTPUT_DISCONNECT_POST,
+ PA_CORE_HOOK_MAX
+} pa_core_hook_t;
+
/* The core structure of PulseAudio. Every PulseAudio daemon contains
* exactly one of these. It is used for storing kind of global
* variables for the daemon. */
int is_system_instance;
/* hooks */
- pa_hook
- hook_sink_new,
- hook_sink_new_post,
- hook_sink_disconnect,
- hook_sink_disconnect_post,
- hook_source_new,
- hook_source_new_post,
- hook_source_disconnect,
- hook_source_disconnect_post,
- hook_sink_input_new,
- hook_sink_input_new_post,
- hook_sink_input_disconnect,
- hook_sink_input_disconnect_post,
- hook_source_output_new,
- hook_source_output_new_post,
- hook_source_output_disconnect,
- hook_source_output_disconnect_post;
+ pa_hook hooks[PA_CORE_HOOK_MAX];
};
PA_DECLARE_CLASS(pa_core);
pa_assert(core);
pa_assert(data);
- if (!(flags & PA_SINK_INPUT_NO_HOOKS))
- if (pa_hook_fire(&core->hook_sink_input_new, data) < 0)
- return NULL;
+ if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], data) < 0)
+ return NULL;
pa_return_null_if_fail(!data->driver || pa_utf8_valid(data->driver));
pa_return_null_if_fail(!data->name || pa_utf8_valid(data->name));
pa_assert(i);
pa_return_if_fail(i->state != PA_SINK_INPUT_DISCONNECTED);
- pa_hook_fire(&i->sink->core->hook_sink_input_disconnect, i);
+ pa_hook_fire(&i->sink->core->hooks[PA_CORE_HOOK_SINK_INPUT_DISCONNECT], i);
if (i->sync_prev)
i->sync_prev->sync_next = i->sync_next;
i->get_latency = NULL;
i->underrun = NULL;
- pa_hook_fire(&i->sink->core->hook_sink_input_disconnect_post, i);
+ pa_hook_fire(&i->sink->core->hooks[PA_CORE_HOOK_SINK_INPUT_DISCONNECT_POST], i);
i->sink = NULL;
pa_sink_input_unref(i);
}
pa_sink_update_status(i->sink);
pa_subscription_post(i->sink->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_NEW, i->index);
- pa_hook_fire(&i->sink->core->hook_sink_input_new_post, i);
+ pa_hook_fire(&i->sink->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], i);
}
void pa_sink_input_kill(pa_sink_input*i) {
typedef enum pa_sink_input_flags {
PA_SINK_INPUT_VARIABLE_RATE = 1,
- PA_SINK_INPUT_NO_HOOKS = 2
} pa_sink_input_flags_t;
struct pa_sink_input {
pa_return_null_if_fail(!driver || pa_utf8_valid(driver));
pa_return_null_if_fail(name && pa_utf8_valid(name) && *name);
- if (pa_hook_fire(&core->hook_sink_new, NULL) < 0) /* FIXME */
- return NULL;
-
s = pa_msgobject_new(pa_sink);
if (!(name = pa_namereg_register(core, name, PA_NAMEREG_SINK, s, fail))) {
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_NEW, s->index);
- pa_hook_fire(&core->hook_sink_new_post, s);
+ pa_hook_fire(&core->hooks[PA_CORE_HOOK_SINK_NEW_POST], s);
return s;
}
return -1;
s->state = state;
+
+ pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SINK_STATE_CHANGED], s);
return 0;
}
pa_assert(s);
pa_return_if_fail(s->state != PA_SINK_DISCONNECTED);
- pa_hook_fire(&s->core->hook_sink_disconnect, s);
+ pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SINK_DISCONNECT], s);
pa_namereg_unregister(s->core, s->name);
pa_idxset_remove_by_data(s->core->sinks, s, NULL);
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_REMOVE, s->index);
- pa_hook_fire(&s->core->hook_sink_disconnect_post, s);
+ pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SINK_DISCONNECT_POST], s);
}
static void sink_free(pa_object *o) {
pa_assert(core);
pa_assert(data);
- if (!(flags & PA_SOURCE_OUTPUT_NO_HOOKS))
- if (pa_hook_fire(&core->hook_source_output_new, data) < 0)
- return NULL;
+ if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_NEW], data) < 0)
+ return NULL;
pa_return_null_if_fail(!data->driver || pa_utf8_valid(data->driver));
pa_return_null_if_fail(!data->name || pa_utf8_valid(data->name));
pa_assert(o);
pa_return_if_fail(o->state != PA_SOURCE_OUTPUT_DISCONNECTED);
- pa_hook_fire(&o->source->core->hook_source_output_disconnect, o);
+ pa_hook_fire(&o->source->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_DISCONNECT], o);
pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o->source), PA_SOURCE_MESSAGE_REMOVE_OUTPUT, o, 0, NULL);
o->kill = NULL;
o->get_latency = NULL;
- pa_hook_fire(&o->source->core->hook_source_output_disconnect_post, o);
+ pa_hook_fire(&o->source->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_DISCONNECT_POST], o);
o->source = NULL;
pa_source_output_unref(o);
pa_subscription_post(o->source->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_NEW, o->index);
- pa_hook_fire(&o->source->core->hook_source_output_new_post, o);
+ pa_hook_fire(&o->source->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_PUT], o);
}
void pa_source_output_kill(pa_source_output*o) {
} pa_source_output_state_t;
typedef enum pa_source_output_flags {
- PA_SOURCE_OUTPUT_NO_HOOKS = 1,
- PA_SOURCE_OUTPUT_VARIABLE_RATE = 2
+ PA_SOURCE_OUTPUT_VARIABLE_RATE = 1
} pa_source_output_flags_t;
struct pa_source_output {
pa_return_null_if_fail(!driver || pa_utf8_valid(driver));
pa_return_null_if_fail(pa_utf8_valid(name) && *name);
- if (pa_hook_fire(&core->hook_sink_new, NULL) < 0) /* FIXME */
- return NULL;
-
s = pa_msgobject_new(pa_source);
if (!(name = pa_namereg_register(core, name, PA_NAMEREG_SOURCE, s, fail))) {
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_NEW, s->index);
- pa_hook_fire(&core->hook_source_new_post, s);
+ pa_hook_fire(&core->hooks[PA_CORE_HOOK_SOURCE_NEW_POST], s);
return s;
}
return -1;
s->state = state;
+ pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_STATE_CHANGED], s);
return 0;
}
pa_assert(s);
pa_return_if_fail(s->state != PA_SOURCE_DISCONNECTED);
- pa_hook_fire(&s->core->hook_source_disconnect, s);
+ pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_DISCONNECT], s);
pa_namereg_unregister(s->core, s->name);
pa_idxset_remove_by_data(s->core->sources, s, NULL);
pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE | PA_SUBSCRIPTION_EVENT_REMOVE, s->index);
- pa_hook_fire(&s->core->hook_source_disconnect_post, s);
+ pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SOURCE_DISCONNECT_POST], s);
}
static void source_free(pa_object *o) {