~ubuntu-branches/ubuntu/oneiric/pulseaudio/oneiric

« back to all changes in this revision

Viewing changes to src/modules/module-suspend-on-idle.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2007-12-04 00:56:08 UTC
  • mto: (1.15.1 sid)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20071204005608-3lzrrrpxi186kgx4
Tags: upstream-0.9.8
ImportĀ upstreamĀ versionĀ 0.9.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: module-suspend-on-idle.c 1971 2007-10-28 19:13:50Z lennart $ */
 
1
/* $Id: module-suspend-on-idle.c 2067 2007-11-21 01:30:40Z lennart $ */
2
2
 
3
3
/***
4
4
  This file is part of PulseAudio.
37
37
 
38
38
#include "module-suspend-on-idle-symdef.h"
39
39
 
40
 
PA_MODULE_AUTHOR("Lennart Poettering")
41
 
PA_MODULE_DESCRIPTION("When a sink/source is idle for too long, suspend it")
42
 
PA_MODULE_VERSION(PACKAGE_VERSION)
 
40
PA_MODULE_AUTHOR("Lennart Poettering");
 
41
PA_MODULE_DESCRIPTION("When a sink/source is idle for too long, suspend it");
 
42
PA_MODULE_VERSION(PACKAGE_VERSION);
 
43
PA_MODULE_LOAD_ONCE(TRUE);
43
44
 
44
45
static const char* const valid_modargs[] = {
45
46
    "timeout",
65
66
        *source_output_unlink_slot,
66
67
        *sink_input_move_slot,
67
68
        *source_output_move_slot,
68
 
        *sink_input_move_post_slot,
69
 
        *source_output_move_post_slot,
70
69
        *sink_input_state_changed_slot,
71
70
        *source_output_state_changed_slot;
72
71
};
130
129
    }
131
130
}
132
131
 
133
 
static pa_hook_result_t sink_input_new_hook_cb(pa_core *c, pa_sink_input *s, struct userdata *u) {
 
132
static pa_hook_result_t sink_input_fixate_hook_cb(pa_core *c, pa_sink_input_new_data *data, struct userdata *u) {
134
133
    struct device_info *d;
135
134
 
136
135
    pa_assert(c);
137
 
    pa_sink_input_assert_ref(s);
 
136
    pa_assert(data);
138
137
    pa_assert(u);
139
138
 
140
 
    if ((d = pa_hashmap_get(u->device_infos, s->sink)))
 
139
    if ((d = pa_hashmap_get(u->device_infos, data->sink)))
141
140
        resume(d);
142
141
 
143
142
    return PA_HOOK_OK;
144
143
}
145
144
 
146
 
static pa_hook_result_t source_output_new_hook_cb(pa_core *c, pa_source_output *s, struct userdata *u) {
 
145
static pa_hook_result_t source_output_fixate_hook_cb(pa_core *c, pa_source_output_new_data *data, struct userdata *u) {
147
146
    struct device_info *d;
148
147
 
149
148
    pa_assert(c);
150
 
    pa_source_output_assert_ref(s);
 
149
    pa_assert(data);
151
150
    pa_assert(u);
152
151
 
153
 
    if ((d = pa_hashmap_get(u->device_infos, s->source)))
 
152
    if ((d = pa_hashmap_get(u->device_infos, data->source)))
154
153
        resume(d);
155
154
 
156
155
    return PA_HOOK_OK;
184
183
    return PA_HOOK_OK;
185
184
}
186
185
 
187
 
static pa_hook_result_t sink_input_move_hook_cb(pa_core *c, pa_sink_input *s, struct userdata *u) {
188
 
    pa_assert(c);
189
 
    pa_sink_input_assert_ref(s);
190
 
    pa_assert(u);
191
 
 
192
 
    if (pa_sink_used_by(s->sink) <= 1) {
193
 
        struct device_info *d;
194
 
        if ((d = pa_hashmap_get(u->device_infos, s->sink)))
195
 
            restart(d);
196
 
    }
197
 
 
198
 
    return PA_HOOK_OK;
199
 
}
200
 
 
201
 
static pa_hook_result_t sink_input_move_post_hook_cb(pa_core *c, pa_sink_input *s, struct userdata *u) {
202
 
    struct device_info *d;
203
 
    pa_assert(c);
204
 
    pa_sink_input_assert_ref(s);
205
 
    pa_assert(u);
206
 
 
207
 
    if ((d = pa_hashmap_get(u->device_infos, s->sink)))
208
 
        resume(d);
209
 
 
210
 
    return PA_HOOK_OK;
211
 
}
212
 
 
213
 
static pa_hook_result_t source_output_move_hook_cb(pa_core *c, pa_source_output *s, struct userdata *u) {
214
 
    pa_assert(c);
215
 
    pa_source_output_assert_ref(s);
216
 
    pa_assert(u);
217
 
 
218
 
    if (pa_source_used_by(s->source) <= 1) {
219
 
        struct device_info *d;
220
 
 
221
 
        if ((d = pa_hashmap_get(u->device_infos, s->source)))
222
 
            restart(d);
223
 
    }
224
 
 
225
 
    return PA_HOOK_OK;
226
 
}
227
 
 
228
 
static pa_hook_result_t source_output_move_post_hook_cb(pa_core *c, pa_source_output *s, struct userdata *u) {
229
 
    struct device_info *d;
230
 
    pa_assert(c);
231
 
    pa_source_output_assert_ref(s);
232
 
    pa_assert(u);
233
 
 
234
 
    if ((d = pa_hashmap_get(u->device_infos, s->source)))
235
 
        resume(d);
 
186
static pa_hook_result_t sink_input_move_hook_cb(pa_core *c, pa_sink_input_move_hook_data *data, struct userdata *u) {
 
187
    struct device_info *d;
 
188
 
 
189
    pa_assert(c);
 
190
    pa_assert(data);
 
191
    pa_assert(u);
 
192
 
 
193
    if ((d = pa_hashmap_get(u->device_infos, data->destination)))
 
194
        resume(d);
 
195
 
 
196
    if (pa_sink_used_by(data->sink_input->sink) <= 1)
 
197
        if ((d = pa_hashmap_get(u->device_infos, data->sink_input->sink)))
 
198
            restart(d);
 
199
 
 
200
    return PA_HOOK_OK;
 
201
}
 
202
 
 
203
static pa_hook_result_t source_output_move_hook_cb(pa_core *c, pa_source_output_move_hook_data *data, struct userdata *u) {
 
204
    struct device_info *d;
 
205
 
 
206
    pa_assert(c);
 
207
    pa_assert(data);
 
208
    pa_assert(u);
 
209
 
 
210
    if ((d = pa_hashmap_get(u->device_infos, data->destination)))
 
211
        resume(d);
 
212
 
 
213
    if (pa_source_used_by(data->source_output->source) <= 1)
 
214
        if ((d = pa_hashmap_get(u->device_infos, data->source_output->source)))
 
215
            restart(d);
236
216
 
237
217
    return PA_HOOK_OK;
238
218
}
394
374
    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);
395
375
    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);
396
376
 
397
 
    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);
398
 
    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);
 
377
    u->sink_input_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], (pa_hook_cb_t) sink_input_fixate_hook_cb, u);
 
378
    u->source_output_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_FIXATE], (pa_hook_cb_t) source_output_fixate_hook_cb, u);
399
379
    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);
400
380
    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);
401
381
    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);
402
382
    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);
403
 
    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);
404
 
    u->source_output_move_post_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_POST], (pa_hook_cb_t) source_output_move_post_hook_cb, u);
405
383
    u->sink_input_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_STATE_CHANGED], (pa_hook_cb_t) sink_input_state_changed_hook_cb, u);
406
384
    u->source_output_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_STATE_CHANGED], (pa_hook_cb_t) source_output_state_changed_hook_cb, u);
407
385
 
408
 
 
409
386
    pa_modargs_free(ma);
410
387
    return 0;
411
388
 
448
425
        pa_hook_slot_free(u->sink_input_unlink_slot);
449
426
    if (u->sink_input_move_slot)
450
427
        pa_hook_slot_free(u->sink_input_move_slot);
451
 
    if (u->sink_input_move_post_slot)
452
 
        pa_hook_slot_free(u->sink_input_move_post_slot);
453
428
    if (u->sink_input_state_changed_slot)
454
429
        pa_hook_slot_free(u->sink_input_state_changed_slot);
455
430
 
459
434
        pa_hook_slot_free(u->source_output_unlink_slot);
460
435
    if (u->source_output_move_slot)
461
436
        pa_hook_slot_free(u->source_output_move_slot);
462
 
    if (u->source_output_move_post_slot)
463
 
        pa_hook_slot_free(u->source_output_move_post_slot);
464
437
    if (u->source_output_state_changed_slot)
465
438
        pa_hook_slot_free(u->source_output_state_changed_slot);
466
439