2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2.1 of the License,
10 or (at your option) any later version.
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #include <pulse/introspect.h>
32 #include <pulse/utf8.h>
33 #include <pulse/xmalloc.h>
34 #include <pulse/timeval.h>
35 #include <pulse/util.h>
36 #include <pulse/i18n.h>
38 #include <pulsecore/sink-input.h>
39 #include <pulsecore/namereg.h>
40 #include <pulsecore/core-util.h>
41 #include <pulsecore/sample-util.h>
42 #include <pulsecore/core-subscribe.h>
43 #include <pulsecore/log.h>
44 #include <pulsecore/macro.h>
45 #include <pulsecore/play-memblockq.h>
49 #define MAX_MIX_CHANNELS 32
50 #define MIX_BUFFER_LENGTH (PA_PAGE_SIZE)
51 #define ABSOLUTE_MIN_LATENCY (500)
52 #define ABSOLUTE_MAX_LATENCY (10*PA_USEC_PER_SEC)
54 static PA_DEFINE_CHECK_TYPE(pa_sink
, pa_msgobject
);
56 static void sink_free(pa_object
*s
);
58 pa_sink_new_data
* pa_sink_new_data_init(pa_sink_new_data
*data
) {
61 memset(data
, 0, sizeof(*data
));
62 data
->proplist
= pa_proplist_new();
67 void pa_sink_new_data_set_name(pa_sink_new_data
*data
, const char *name
) {
71 data
->name
= pa_xstrdup(name
);
74 void pa_sink_new_data_set_sample_spec(pa_sink_new_data
*data
, const pa_sample_spec
*spec
) {
77 if ((data
->sample_spec_is_set
= !!spec
))
78 data
->sample_spec
= *spec
;
81 void pa_sink_new_data_set_channel_map(pa_sink_new_data
*data
, const pa_channel_map
*map
) {
84 if ((data
->channel_map_is_set
= !!map
))
85 data
->channel_map
= *map
;
88 void pa_sink_new_data_set_volume(pa_sink_new_data
*data
, const pa_cvolume
*volume
) {
91 if ((data
->volume_is_set
= !!volume
))
92 data
->volume
= *volume
;
95 void pa_sink_new_data_set_muted(pa_sink_new_data
*data
, pa_bool_t mute
) {
98 data
->muted_is_set
= TRUE
;
102 void pa_sink_new_data_done(pa_sink_new_data
*data
) {
105 pa_xfree(data
->name
);
106 pa_proplist_free(data
->proplist
);
109 /* Called from main context */
110 static void reset_callbacks(pa_sink
*s
) {
114 s
->get_volume
= NULL
;
115 s
->set_volume
= NULL
;
118 s
->request_rewind
= NULL
;
119 s
->update_requested_latency
= NULL
;
122 /* Called from main context */
123 pa_sink
* pa_sink_new(
125 pa_sink_new_data
*data
,
126 pa_sink_flags_t flags
) {
130 char st
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
131 pa_source_new_data source_data
;
137 pa_assert(data
->name
);
139 s
= pa_msgobject_new(pa_sink
);
141 if (!(name
= pa_namereg_register(core
, data
->name
, PA_NAMEREG_SINK
, s
, data
->namereg_fail
))) {
146 pa_sink_new_data_set_name(data
, name
);
148 if (pa_hook_fire(&core
->hooks
[PA_CORE_HOOK_SINK_NEW
], data
) < 0) {
150 pa_namereg_unregister(core
, name
);
154 pa_return_null_if_fail(!data
->driver
|| pa_utf8_valid(data
->driver
));
155 pa_return_null_if_fail(data
->name
&& pa_utf8_valid(data
->name
) && data
->name
[0]);
157 pa_return_null_if_fail(data
->sample_spec_is_set
&& pa_sample_spec_valid(&data
->sample_spec
));
159 if (!data
->channel_map_is_set
)
160 pa_return_null_if_fail(pa_channel_map_init_auto(&data
->channel_map
, data
->sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
));
162 pa_return_null_if_fail(pa_channel_map_valid(&data
->channel_map
));
163 pa_return_null_if_fail(data
->channel_map
.channels
== data
->sample_spec
.channels
);
165 if (!data
->volume_is_set
)
166 pa_cvolume_reset(&data
->volume
, data
->sample_spec
.channels
);
168 pa_return_null_if_fail(pa_cvolume_valid(&data
->volume
));
169 pa_return_null_if_fail(data
->volume
.channels
== data
->sample_spec
.channels
);
171 if (!data
->muted_is_set
)
175 pa_proplist_update(data
->proplist
, PA_UPDATE_MERGE
, data
->card
->proplist
);
177 pa_device_init_description(data
->proplist
);
178 pa_device_init_icon(data
->proplist
, TRUE
);
180 if (pa_hook_fire(&core
->hooks
[PA_CORE_HOOK_SINK_FIXATE
], data
) < 0) {
182 pa_namereg_unregister(core
, name
);
186 s
->parent
.parent
.free
= sink_free
;
187 s
->parent
.process_msg
= pa_sink_process_msg
;
190 s
->state
= PA_SINK_INIT
;
192 s
->name
= pa_xstrdup(name
);
193 s
->proplist
= pa_proplist_copy(data
->proplist
);
194 s
->driver
= pa_xstrdup(pa_path_get_filename(data
->driver
));
195 s
->module
= data
->module
;
196 s
->card
= data
->card
;
198 s
->sample_spec
= data
->sample_spec
;
199 s
->channel_map
= data
->channel_map
;
201 s
->inputs
= pa_idxset_new(NULL
, NULL
);
204 s
->virtual_volume
= data
->volume
;
205 pa_cvolume_reset(&s
->soft_volume
, s
->sample_spec
.channels
);
206 s
->base_volume
= PA_VOLUME_NORM
;
207 s
->n_volume_steps
= PA_VOLUME_NORM
+1;
208 s
->muted
= data
->muted
;
209 s
->refresh_volume
= s
->refresh_muted
= FALSE
;
217 pa_silence_memchunk_get(
218 &core
->silence_cache
,
224 s
->thread_info
.inputs
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
225 s
->thread_info
.soft_volume
= s
->soft_volume
;
226 s
->thread_info
.soft_muted
= s
->muted
;
227 s
->thread_info
.state
= s
->state
;
228 s
->thread_info
.rewind_nbytes
= 0;
229 s
->thread_info
.rewind_requested
= FALSE
;
230 s
->thread_info
.max_rewind
= 0;
231 s
->thread_info
.max_request
= 0;
232 s
->thread_info
.requested_latency_valid
= FALSE
;
233 s
->thread_info
.requested_latency
= 0;
234 s
->thread_info
.min_latency
= ABSOLUTE_MIN_LATENCY
;
235 s
->thread_info
.max_latency
= ABSOLUTE_MAX_LATENCY
;
237 pa_assert_se(pa_idxset_put(core
->sinks
, s
, &s
->index
) >= 0);
240 pa_assert_se(pa_idxset_put(s
->card
->sinks
, s
, NULL
) >= 0);
242 pt
= pa_proplist_to_string_sep(s
->proplist
, "\n ");
243 pa_log_info("Created sink %u \"%s\" with sample spec %s and channel map %s\n %s",
246 pa_sample_spec_snprint(st
, sizeof(st
), &s
->sample_spec
),
247 pa_channel_map_snprint(cm
, sizeof(cm
), &s
->channel_map
),
251 pa_source_new_data_init(&source_data
);
252 pa_source_new_data_set_sample_spec(&source_data
, &s
->sample_spec
);
253 pa_source_new_data_set_channel_map(&source_data
, &s
->channel_map
);
254 source_data
.name
= pa_sprintf_malloc("%s.monitor", name
);
255 source_data
.driver
= data
->driver
;
256 source_data
.module
= data
->module
;
257 source_data
.card
= data
->card
;
259 dn
= pa_proplist_gets(s
->proplist
, PA_PROP_DEVICE_DESCRIPTION
);
260 pa_proplist_setf(source_data
.proplist
, PA_PROP_DEVICE_DESCRIPTION
, "Monitor of %s", dn
? dn
: s
->name
);
261 pa_proplist_sets(source_data
.proplist
, PA_PROP_DEVICE_CLASS
, "monitor");
263 s
->monitor_source
= pa_source_new(core
, &source_data
, 0);
265 pa_source_new_data_done(&source_data
);
267 if (!s
->monitor_source
) {
273 s
->monitor_source
->monitor_of
= s
;
275 pa_source_set_latency_range(s
->monitor_source
, s
->thread_info
.min_latency
, s
->thread_info
.max_latency
);
276 pa_source_set_max_rewind(s
->monitor_source
, s
->thread_info
.max_rewind
);
281 /* Called from main context */
282 static int sink_set_state(pa_sink
*s
, pa_sink_state_t state
) {
284 pa_bool_t suspend_change
;
285 pa_sink_state_t original_state
;
289 if (s
->state
== state
)
292 original_state
= s
->state
;
295 (original_state
== PA_SINK_SUSPENDED
&& PA_SINK_IS_OPENED(state
)) ||
296 (PA_SINK_IS_OPENED(original_state
) && state
== PA_SINK_SUSPENDED
);
299 if ((ret
= s
->set_state(s
, state
)) < 0)
303 if ((ret
= pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_SET_STATE
, PA_UINT_TO_PTR(state
), 0, NULL
)) < 0) {
306 s
->set_state(s
, original_state
);
313 if (state
!= PA_SINK_UNLINKED
) { /* if we enter UNLINKED state pa_sink_unlink() will fire the apropriate events */
314 pa_hook_fire(&s
->core
->hooks
[PA_CORE_HOOK_SINK_STATE_CHANGED
], s
);
315 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SINK
| PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
318 if (suspend_change
) {
322 /* We're suspending or resuming, tell everyone about it */
324 for (i
= PA_SINK_INPUT(pa_idxset_first(s
->inputs
, &idx
)); i
; i
= PA_SINK_INPUT(pa_idxset_next(s
->inputs
, &idx
)))
325 if (s
->state
== PA_SINK_SUSPENDED
&&
326 (i
->flags
& PA_SINK_INPUT_FAIL_ON_SUSPEND
))
327 pa_sink_input_kill(i
);
329 i
->suspend(i
, state
== PA_SINK_SUSPENDED
);
331 if (s
->monitor_source
)
332 pa_source_sync_suspend(s
->monitor_source
);
338 /* Called from main context */
339 void pa_sink_put(pa_sink
* s
) {
340 pa_sink_assert_ref(s
);
342 pa_assert(s
->state
== PA_SINK_INIT
);
344 /* The following fields must be initialized properly when calling _put() */
345 pa_assert(s
->asyncmsgq
);
346 pa_assert(s
->rtpoll
);
347 pa_assert(s
->thread_info
.min_latency
<= s
->thread_info
.max_latency
);
349 if (!(s
->flags
& PA_SINK_HW_VOLUME_CTRL
)) {
350 s
->flags
|= PA_SINK_DECIBEL_VOLUME
;
352 s
->thread_info
.soft_volume
= s
->soft_volume
;
353 s
->thread_info
.soft_muted
= s
->muted
;
356 if (s
->flags
& PA_SINK_DECIBEL_VOLUME
)
357 s
->n_volume_steps
= PA_VOLUME_NORM
+1;
359 if (s
->core
->flat_volumes
)
360 if (s
->flags
& PA_SINK_DECIBEL_VOLUME
)
361 s
->flags
|= PA_SINK_FLAT_VOLUME
;
363 if (s
->flags
& PA_SINK_LATENCY
)
364 s
->monitor_source
->flags
|= PA_SOURCE_LATENCY
;
366 if (s
->flags
& PA_SINK_DYNAMIC_LATENCY
)
367 s
->monitor_source
->flags
|= PA_SOURCE_DYNAMIC_LATENCY
;
369 pa_assert_se(sink_set_state(s
, PA_SINK_IDLE
) == 0);
371 pa_source_put(s
->monitor_source
);
373 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SINK
| PA_SUBSCRIPTION_EVENT_NEW
, s
->index
);
374 pa_hook_fire(&s
->core
->hooks
[PA_CORE_HOOK_SINK_PUT
], s
);
377 /* Called from main context */
378 void pa_sink_unlink(pa_sink
* s
) {
380 pa_sink_input
*i
, *j
= NULL
;
384 /* Please note that pa_sink_unlink() does more than simply
385 * reversing pa_sink_put(). It also undoes the registrations
386 * already done in pa_sink_new()! */
388 /* All operations here shall be idempotent, i.e. pa_sink_unlink()
389 * may be called multiple times on the same sink without bad
392 linked
= PA_SINK_IS_LINKED(s
->state
);
395 pa_hook_fire(&s
->core
->hooks
[PA_CORE_HOOK_SINK_UNLINK
], s
);
397 if (s
->state
!= PA_SINK_UNLINKED
)
398 pa_namereg_unregister(s
->core
, s
->name
);
399 pa_idxset_remove_by_data(s
->core
->sinks
, s
, NULL
);
402 pa_idxset_remove_by_data(s
->card
->sinks
, s
, NULL
);
404 while ((i
= pa_idxset_first(s
->inputs
, NULL
))) {
406 pa_sink_input_kill(i
);
411 sink_set_state(s
, PA_SINK_UNLINKED
);
413 s
->state
= PA_SINK_UNLINKED
;
417 if (s
->monitor_source
)
418 pa_source_unlink(s
->monitor_source
);
421 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SINK
| PA_SUBSCRIPTION_EVENT_REMOVE
, s
->index
);
422 pa_hook_fire(&s
->core
->hooks
[PA_CORE_HOOK_SINK_UNLINK_POST
], s
);
426 /* Called from main context */
427 static void sink_free(pa_object
*o
) {
428 pa_sink
*s
= PA_SINK(o
);
432 pa_assert(pa_sink_refcnt(s
) == 0);
434 if (PA_SINK_IS_LINKED(s
->state
))
437 pa_log_info("Freeing sink %u \"%s\"", s
->index
, s
->name
);
439 if (s
->monitor_source
) {
440 pa_source_unref(s
->monitor_source
);
441 s
->monitor_source
= NULL
;
444 pa_idxset_free(s
->inputs
, NULL
, NULL
);
446 while ((i
= pa_hashmap_steal_first(s
->thread_info
.inputs
)))
447 pa_sink_input_unref(i
);
449 pa_hashmap_free(s
->thread_info
.inputs
, NULL
, NULL
);
451 if (s
->silence
.memblock
)
452 pa_memblock_unref(s
->silence
.memblock
);
458 pa_proplist_free(s
->proplist
);
463 /* Called from main context */
464 void pa_sink_set_asyncmsgq(pa_sink
*s
, pa_asyncmsgq
*q
) {
465 pa_sink_assert_ref(s
);
469 if (s
->monitor_source
)
470 pa_source_set_asyncmsgq(s
->monitor_source
, q
);
473 /* Called from main context */
474 void pa_sink_set_rtpoll(pa_sink
*s
, pa_rtpoll
*p
) {
475 pa_sink_assert_ref(s
);
478 if (s
->monitor_source
)
479 pa_source_set_rtpoll(s
->monitor_source
, p
);
482 /* Called from main context */
483 int pa_sink_update_status(pa_sink
*s
) {
484 pa_sink_assert_ref(s
);
485 pa_assert(PA_SINK_IS_LINKED(s
->state
));
487 if (s
->state
== PA_SINK_SUSPENDED
)
490 return sink_set_state(s
, pa_sink_used_by(s
) ? PA_SINK_RUNNING
: PA_SINK_IDLE
);
493 /* Called from main context */
494 int pa_sink_suspend(pa_sink
*s
, pa_bool_t suspend
) {
495 pa_sink_assert_ref(s
);
496 pa_assert(PA_SINK_IS_LINKED(s
->state
));
499 return sink_set_state(s
, PA_SINK_SUSPENDED
);
501 return sink_set_state(s
, pa_sink_used_by(s
) ? PA_SINK_RUNNING
: PA_SINK_IDLE
);
504 /* Called from main context */
505 pa_queue
*pa_sink_move_all_start(pa_sink
*s
) {
507 pa_sink_input
*i
, *n
;
510 pa_sink_assert_ref(s
);
511 pa_assert(PA_SINK_IS_LINKED(s
->state
));
515 for (i
= PA_SINK_INPUT(pa_idxset_first(s
->inputs
, &idx
)); i
; i
= n
) {
516 n
= PA_SINK_INPUT(pa_idxset_next(s
->inputs
, &idx
));
518 if (pa_sink_input_start_move(i
) >= 0)
519 pa_queue_push(q
, pa_sink_input_ref(i
));
525 /* Called from main context */
526 void pa_sink_move_all_finish(pa_sink
*s
, pa_queue
*q
, pa_bool_t save
) {
529 pa_sink_assert_ref(s
);
530 pa_assert(PA_SINK_IS_LINKED(s
->state
));
533 while ((i
= PA_SINK_INPUT(pa_queue_pop(q
)))) {
534 if (pa_sink_input_finish_move(i
, s
, save
) < 0)
535 pa_sink_input_kill(i
);
537 pa_sink_input_unref(i
);
540 pa_queue_free(q
, NULL
, NULL
);
543 /* Called from main context */
544 void pa_sink_move_all_fail(pa_queue
*q
) {
548 while ((i
= PA_SINK_INPUT(pa_queue_pop(q
)))) {
549 if (pa_hook_fire(&i
->core
->hooks
[PA_CORE_HOOK_SINK_INPUT_MOVE_FAIL
], i
) == PA_HOOK_OK
) {
550 pa_sink_input_kill(i
);
551 pa_sink_input_unref(i
);
555 pa_queue_free(q
, NULL
, NULL
);
558 /* Called from IO thread context */
559 void pa_sink_process_rewind(pa_sink
*s
, size_t nbytes
) {
562 pa_sink_assert_ref(s
);
563 pa_assert(PA_SINK_IS_LINKED(s
->thread_info
.state
));
565 /* If nobody requested this and this is actually no real rewind
566 * then we can short cut this */
567 if (!s
->thread_info
.rewind_requested
&& nbytes
<= 0)
570 s
->thread_info
.rewind_nbytes
= 0;
571 s
->thread_info
.rewind_requested
= FALSE
;
573 if (s
->thread_info
.state
== PA_SINK_SUSPENDED
)
577 pa_log_debug("Processing rewind...");
579 while ((i
= pa_hashmap_iterate(s
->thread_info
.inputs
, &state
, NULL
))) {
580 pa_sink_input_assert_ref(i
);
581 pa_sink_input_process_rewind(i
, nbytes
);
585 if (s
->monitor_source
&& PA_SOURCE_IS_LINKED(s
->monitor_source
->thread_info
.state
))
586 pa_source_process_rewind(s
->monitor_source
, nbytes
);
589 /* Called from IO thread context */
590 static unsigned fill_mix_info(pa_sink
*s
, size_t *length
, pa_mix_info
*info
, unsigned maxinfo
) {
594 size_t mixlength
= *length
;
596 pa_sink_assert_ref(s
);
599 while ((i
= pa_hashmap_iterate(s
->thread_info
.inputs
, &state
, NULL
)) && maxinfo
> 0) {
600 pa_sink_input_assert_ref(i
);
602 pa_sink_input_peek(i
, *length
, &info
->chunk
, &info
->volume
);
604 if (mixlength
== 0 || info
->chunk
.length
< mixlength
)
605 mixlength
= info
->chunk
.length
;
607 if (pa_memblock_is_silence(info
->chunk
.memblock
)) {
608 pa_memblock_unref(info
->chunk
.memblock
);
612 info
->userdata
= pa_sink_input_ref(i
);
614 pa_assert(info
->chunk
.memblock
);
615 pa_assert(info
->chunk
.length
> 0);
628 /* Called from IO thread context */
629 static void inputs_drop(pa_sink
*s
, pa_mix_info
*info
, unsigned n
, pa_memchunk
*result
) {
633 unsigned n_unreffed
= 0;
635 pa_sink_assert_ref(s
);
637 pa_assert(result
->memblock
);
638 pa_assert(result
->length
> 0);
640 /* We optimize for the case where the order of the inputs has not changed */
642 while ((i
= pa_hashmap_iterate(s
->thread_info
.inputs
, &state
, NULL
))) {
644 pa_mix_info
* m
= NULL
;
646 pa_sink_input_assert_ref(i
);
648 /* Let's try to find the matching entry info the pa_mix_info array */
649 for (j
= 0; j
< n
; j
++) {
651 if (info
[p
].userdata
== i
) {
662 pa_sink_input_drop(i
, result
->length
);
664 if (s
->monitor_source
&& PA_SOURCE_IS_LINKED(s
->monitor_source
->thread_info
.state
)) {
666 if (pa_hashmap_size(i
->thread_info
.direct_outputs
) > 0) {
671 if (m
&& m
->chunk
.memblock
) {
673 pa_memblock_ref(c
.memblock
);
674 pa_assert(result
->length
<= c
.length
);
675 c
.length
= result
->length
;
677 pa_memchunk_make_writable(&c
, 0);
678 pa_volume_memchunk(&c
, &s
->sample_spec
, &m
->volume
);
681 pa_memblock_ref(c
.memblock
);
682 pa_assert(result
->length
<= c
.length
);
683 c
.length
= result
->length
;
686 while ((o
= pa_hashmap_iterate(i
->thread_info
.direct_outputs
, &ostate
, NULL
))) {
687 pa_source_output_assert_ref(o
);
688 pa_assert(o
->direct_on_input
== i
);
689 pa_source_post_direct(s
->monitor_source
, o
, &c
);
692 pa_memblock_unref(c
.memblock
);
697 if (m
->chunk
.memblock
)
698 pa_memblock_unref(m
->chunk
.memblock
);
699 pa_memchunk_reset(&m
->chunk
);
701 pa_sink_input_unref(m
->userdata
);
708 /* Now drop references to entries that are included in the
709 * pa_mix_info array but don't exist anymore */
711 if (n_unreffed
< n
) {
712 for (; n
> 0; info
++, n
--) {
714 pa_sink_input_unref(info
->userdata
);
715 if (info
->chunk
.memblock
)
716 pa_memblock_unref(info
->chunk
.memblock
);
720 if (s
->monitor_source
&& PA_SOURCE_IS_LINKED(s
->monitor_source
->thread_info
.state
))
721 pa_source_post(s
->monitor_source
, result
);
724 /* Called from IO thread context */
725 void pa_sink_render(pa_sink
*s
, size_t length
, pa_memchunk
*result
) {
726 pa_mix_info info
[MAX_MIX_CHANNELS
];
728 size_t block_size_max
;
730 pa_sink_assert_ref(s
);
731 pa_assert(PA_SINK_IS_LINKED(s
->thread_info
.state
));
732 pa_assert(pa_frame_aligned(length
, &s
->sample_spec
));
737 pa_assert(!s
->thread_info
.rewind_requested
);
738 pa_assert(s
->thread_info
.rewind_nbytes
== 0);
740 if (s
->thread_info
.state
== PA_SINK_SUSPENDED
) {
741 result
->memblock
= pa_memblock_ref(s
->silence
.memblock
);
742 result
->index
= s
->silence
.index
;
743 result
->length
= PA_MIN(s
->silence
.length
, length
);
748 length
= pa_frame_align(MIX_BUFFER_LENGTH
, &s
->sample_spec
);
750 block_size_max
= pa_mempool_block_size_max(s
->core
->mempool
);
751 if (length
> block_size_max
)
752 length
= pa_frame_align(block_size_max
, &s
->sample_spec
);
754 pa_assert(length
> 0);
756 n
= fill_mix_info(s
, &length
, info
, MAX_MIX_CHANNELS
);
760 *result
= s
->silence
;
761 pa_memblock_ref(result
->memblock
);
763 if (result
->length
> length
)
764 result
->length
= length
;
769 *result
= info
[0].chunk
;
770 pa_memblock_ref(result
->memblock
);
772 if (result
->length
> length
)
773 result
->length
= length
;
775 pa_sw_cvolume_multiply(&volume
, &s
->thread_info
.soft_volume
, &info
[0].volume
);
777 if (s
->thread_info
.soft_muted
|| !pa_cvolume_is_norm(&volume
)) {
778 pa_memchunk_make_writable(result
, 0);
779 if (s
->thread_info
.soft_muted
|| pa_cvolume_is_muted(&volume
))
780 pa_silence_memchunk(result
, &s
->sample_spec
);
782 pa_volume_memchunk(result
, &s
->sample_spec
, &volume
);
786 result
->memblock
= pa_memblock_new(s
->core
->mempool
, length
);
788 ptr
= pa_memblock_acquire(result
->memblock
);
789 result
->length
= pa_mix(info
, n
,
792 &s
->thread_info
.soft_volume
,
793 s
->thread_info
.soft_muted
);
794 pa_memblock_release(result
->memblock
);
799 inputs_drop(s
, info
, n
, result
);
804 /* Called from IO thread context */
805 void pa_sink_render_into(pa_sink
*s
, pa_memchunk
*target
) {
806 pa_mix_info info
[MAX_MIX_CHANNELS
];
808 size_t length
, block_size_max
;
810 pa_sink_assert_ref(s
);
811 pa_assert(PA_SINK_IS_LINKED(s
->thread_info
.state
));
813 pa_assert(target
->memblock
);
814 pa_assert(target
->length
> 0);
815 pa_assert(pa_frame_aligned(target
->length
, &s
->sample_spec
));
819 pa_assert(!s
->thread_info
.rewind_requested
);
820 pa_assert(s
->thread_info
.rewind_nbytes
== 0);
822 if (s
->thread_info
.state
== PA_SINK_SUSPENDED
) {
823 pa_silence_memchunk(target
, &s
->sample_spec
);
827 length
= target
->length
;
828 block_size_max
= pa_mempool_block_size_max(s
->core
->mempool
);
829 if (length
> block_size_max
)
830 length
= pa_frame_align(block_size_max
, &s
->sample_spec
);
832 pa_assert(length
> 0);
834 n
= fill_mix_info(s
, &length
, info
, MAX_MIX_CHANNELS
);
837 if (target
->length
> length
)
838 target
->length
= length
;
840 pa_silence_memchunk(target
, &s
->sample_spec
);
844 if (target
->length
> length
)
845 target
->length
= length
;
847 pa_sw_cvolume_multiply(&volume
, &s
->thread_info
.soft_volume
, &info
[0].volume
);
849 if (s
->thread_info
.soft_muted
|| pa_cvolume_is_muted(&volume
))
850 pa_silence_memchunk(target
, &s
->sample_spec
);
854 vchunk
= info
[0].chunk
;
855 pa_memblock_ref(vchunk
.memblock
);
857 if (vchunk
.length
> length
)
858 vchunk
.length
= length
;
860 if (!pa_cvolume_is_norm(&volume
)) {
861 pa_memchunk_make_writable(&vchunk
, 0);
862 pa_volume_memchunk(&vchunk
, &s
->sample_spec
, &volume
);
865 pa_memchunk_memcpy(target
, &vchunk
);
866 pa_memblock_unref(vchunk
.memblock
);
872 ptr
= pa_memblock_acquire(target
->memblock
);
874 target
->length
= pa_mix(info
, n
,
875 (uint8_t*) ptr
+ target
->index
, length
,
877 &s
->thread_info
.soft_volume
,
878 s
->thread_info
.soft_muted
);
880 pa_memblock_release(target
->memblock
);
883 inputs_drop(s
, info
, n
, target
);
888 /* Called from IO thread context */
889 void pa_sink_render_into_full(pa_sink
*s
, pa_memchunk
*target
) {
893 pa_sink_assert_ref(s
);
894 pa_assert(PA_SINK_IS_LINKED(s
->thread_info
.state
));
896 pa_assert(target
->memblock
);
897 pa_assert(target
->length
> 0);
898 pa_assert(pa_frame_aligned(target
->length
, &s
->sample_spec
));
902 pa_assert(!s
->thread_info
.rewind_requested
);
903 pa_assert(s
->thread_info
.rewind_nbytes
== 0);
912 pa_sink_render_into(s
, &chunk
);
921 /* Called from IO thread context */
922 void pa_sink_render_full(pa_sink
*s
, size_t length
, pa_memchunk
*result
) {
923 pa_sink_assert_ref(s
);
924 pa_assert(PA_SINK_IS_LINKED(s
->thread_info
.state
));
925 pa_assert(length
> 0);
926 pa_assert(pa_frame_aligned(length
, &s
->sample_spec
));
929 pa_assert(!s
->thread_info
.rewind_requested
);
930 pa_assert(s
->thread_info
.rewind_nbytes
== 0);
932 /*** This needs optimization ***/
935 result
->length
= length
;
936 result
->memblock
= pa_memblock_new(s
->core
->mempool
, length
);
938 pa_sink_render_into_full(s
, result
);
941 /* Called from main thread */
942 pa_usec_t
pa_sink_get_latency(pa_sink
*s
) {
945 pa_sink_assert_ref(s
);
946 pa_assert(PA_SINK_IS_LINKED(s
->state
));
948 /* The returned value is supposed to be in the time domain of the sound card! */
950 if (s
->state
== PA_SINK_SUSPENDED
)
953 if (!(s
->flags
& PA_SINK_LATENCY
))
956 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_GET_LATENCY
, &usec
, 0, NULL
) == 0);
961 /* Called from IO thread */
962 pa_usec_t
pa_sink_get_latency_within_thread(pa_sink
*s
) {
966 pa_sink_assert_ref(s
);
967 pa_assert(PA_SINK_IS_LINKED(s
->thread_info
.state
));
969 /* The returned value is supposed to be in the time domain of the sound card! */
971 if (s
->thread_info
.state
== PA_SINK_SUSPENDED
)
974 if (!(s
->flags
& PA_SINK_LATENCY
))
979 /* We probably should make this a proper vtable callback instead of going through process_msg() */
981 if (o
->process_msg(o
, PA_SINK_MESSAGE_GET_LATENCY
, &usec
, 0, NULL
) < 0)
987 static void compute_new_soft_volume(pa_sink_input
*i
, const pa_cvolume
*new_volume
) {
990 pa_sink_input_assert_ref(i
);
991 pa_assert(new_volume
->channels
== i
->sample_spec
.channels
);
993 /* This basically calculates i->soft_volume := i->virtual_volume / new_volume * i->volume_factor */
995 /* The new sink volume passed in here must already be remapped to
996 * the sink input's channel map! */
998 for (c
= 0; c
< i
->sample_spec
.channels
; c
++)
1000 if (new_volume
->values
[c
] <= PA_VOLUME_MUTED
)
1001 i
->soft_volume
.values
[c
] = PA_VOLUME_MUTED
;
1003 i
->soft_volume
.values
[c
] = pa_sw_volume_from_linear(
1004 pa_sw_volume_to_linear(i
->virtual_volume
.values
[c
]) *
1005 pa_sw_volume_to_linear(i
->volume_factor
.values
[c
]) /
1006 pa_sw_volume_to_linear(new_volume
->values
[c
]));
1008 i
->soft_volume
.channels
= i
->sample_spec
.channels
;
1010 /* Hooks have the ability to play games with i->soft_volume */
1011 pa_hook_fire(&i
->core
->hooks
[PA_CORE_HOOK_SINK_INPUT_SET_VOLUME
], i
);
1013 /* We don't copy the soft_volume to the thread_info data
1014 * here. That must be done by the caller */
1017 /* Called from main thread */
1018 void pa_sink_update_flat_volume(pa_sink
*s
, pa_cvolume
*new_volume
) {
1022 pa_sink_assert_ref(s
);
1023 pa_assert(new_volume
);
1024 pa_assert(PA_SINK_IS_LINKED(s
->state
));
1025 pa_assert(s
->flags
& PA_SINK_FLAT_VOLUME
);
1027 /* This is called whenever a sink input volume changes and we
1028 * might need to fix up the sink volume accordingly. Please note
1029 * that we don't actually update the sinks volume here, we only
1030 * return how it needs to be updated. The caller should then call
1031 * pa_sink_set_volume().*/
1033 if (pa_idxset_isempty(s
->inputs
)) {
1034 /* In the special case that we have no sink input we leave the
1035 * volume unmodified. */
1036 *new_volume
= s
->virtual_volume
;
1040 pa_cvolume_mute(new_volume
, s
->channel_map
.channels
);
1042 /* First let's determine the new maximum volume of all inputs
1043 * connected to this sink */
1044 for (i
= PA_SINK_INPUT(pa_idxset_first(s
->inputs
, &idx
)); i
; i
= PA_SINK_INPUT(pa_idxset_next(s
->inputs
, &idx
))) {
1046 pa_cvolume remapped_volume
;
1048 remapped_volume
= i
->virtual_volume
;
1049 pa_cvolume_remap(&remapped_volume
, &i
->channel_map
, &s
->channel_map
);
1051 for (c
= 0; c
< new_volume
->channels
; c
++)
1052 if (remapped_volume
.values
[c
] > new_volume
->values
[c
])
1053 new_volume
->values
[c
] = remapped_volume
.values
[c
];
1056 /* Then, let's update the soft volumes of all inputs connected
1058 for (i
= PA_SINK_INPUT(pa_idxset_first(s
->inputs
, &idx
)); i
; i
= PA_SINK_INPUT(pa_idxset_next(s
->inputs
, &idx
))) {
1059 pa_cvolume remapped_new_volume
;
1061 remapped_new_volume
= *new_volume
;
1062 pa_cvolume_remap(&remapped_new_volume
, &s
->channel_map
, &i
->channel_map
);
1063 compute_new_soft_volume(i
, &remapped_new_volume
);
1065 /* We don't copy soft_volume to the thread_info data here
1066 * (i.e. issue PA_SINK_INPUT_MESSAGE_SET_VOLUME) because we
1067 * want the update to be atomically with the sink volume
1068 * update, hence we do it within the pa_sink_set_volume() call
1073 /* Called from main thread */
1074 void pa_sink_propagate_flat_volume(pa_sink
*s
, const pa_cvolume
*old_volume
) {
1078 pa_sink_assert_ref(s
);
1079 pa_assert(old_volume
);
1080 pa_assert(PA_SINK_IS_LINKED(s
->state
));
1081 pa_assert(s
->flags
& PA_SINK_FLAT_VOLUME
);
1083 /* This is called whenever the sink volume changes that is not
1084 * caused by a sink input volume change. We need to fix up the
1085 * sink input volumes accordingly */
1087 for (i
= PA_SINK_INPUT(pa_idxset_first(s
->inputs
, &idx
)); i
; i
= PA_SINK_INPUT(pa_idxset_next(s
->inputs
, &idx
))) {
1088 pa_cvolume remapped_old_volume
, remapped_new_volume
, new_virtual_volume
;
1091 /* This basically calculates i->virtual_volume := i->virtual_volume * s->virtual_volume / old_volume */
1093 remapped_new_volume
= s
->virtual_volume
;
1094 pa_cvolume_remap(&remapped_new_volume
, &s
->channel_map
, &i
->channel_map
);
1096 remapped_old_volume
= *old_volume
;
1097 pa_cvolume_remap(&remapped_old_volume
, &s
->channel_map
, &i
->channel_map
);
1099 for (c
= 0; c
< i
->sample_spec
.channels
; c
++)
1101 if (remapped_old_volume
.values
[c
] <= PA_VOLUME_MUTED
)
1102 new_virtual_volume
.values
[c
] = remapped_new_volume
.values
[c
];
1104 new_virtual_volume
.values
[c
] = pa_sw_volume_from_linear(
1105 pa_sw_volume_to_linear(i
->virtual_volume
.values
[c
]) *
1106 pa_sw_volume_to_linear(remapped_new_volume
.values
[c
]) /
1107 pa_sw_volume_to_linear(remapped_old_volume
.values
[c
]));
1109 new_virtual_volume
.channels
= i
->sample_spec
.channels
;
1111 if (!pa_cvolume_equal(&new_virtual_volume
, &i
->virtual_volume
)) {
1112 i
->virtual_volume
= new_virtual_volume
;
1114 /* Hmm, the soft volume might no longer actually match
1115 * what has been chosen as new virtual volume here,
1116 * especially when the old volume was
1117 * PA_VOLUME_MUTED. Hence let's recalculate the soft
1119 compute_new_soft_volume(i
, &remapped_new_volume
);
1121 /* The virtual volume changed, let's tell people so */
1122 pa_subscription_post(i
->core
, PA_SUBSCRIPTION_EVENT_SINK_INPUT
|PA_SUBSCRIPTION_EVENT_CHANGE
, i
->index
);
1126 /* If the soft_volume of any of the sink inputs got changed, let's
1127 * make sure the thread copies are synced up. */
1128 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_SYNC_VOLUMES
, NULL
, 0, NULL
) == 0);
1131 /* Called from main thread */
1132 void pa_sink_set_volume(pa_sink
*s
, const pa_cvolume
*volume
, pa_bool_t propagate
, pa_bool_t sendmsg
) {
1133 pa_cvolume old_virtual_volume
;
1134 pa_bool_t virtual_volume_changed
;
1136 pa_sink_assert_ref(s
);
1137 pa_assert(PA_SINK_IS_LINKED(s
->state
));
1139 pa_assert(pa_cvolume_valid(volume
));
1140 pa_assert(pa_cvolume_compatible(volume
, &s
->sample_spec
));
1142 old_virtual_volume
= s
->virtual_volume
;
1143 s
->virtual_volume
= *volume
;
1144 virtual_volume_changed
= !pa_cvolume_equal(&old_virtual_volume
, &s
->virtual_volume
);
1146 /* Propagate this volume change back to the inputs */
1147 if (virtual_volume_changed
)
1148 if (propagate
&& (s
->flags
& PA_SINK_FLAT_VOLUME
))
1149 pa_sink_propagate_flat_volume(s
, &old_virtual_volume
);
1151 if (s
->set_volume
) {
1152 /* If we have a function set_volume(), then we do not apply a
1153 * soft volume by default. However, set_volume() is apply one
1154 * to s->soft_volume */
1156 pa_cvolume_reset(&s
->soft_volume
, s
->sample_spec
.channels
);
1160 /* If we have no function set_volume(), then the soft volume
1161 * becomes the virtual volume */
1162 s
->soft_volume
= s
->virtual_volume
;
1164 /* This tells the sink that soft and/or virtual volume changed */
1166 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_SET_VOLUME
, NULL
, 0, NULL
) == 0);
1168 if (virtual_volume_changed
)
1169 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SINK
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
1172 /* Called from main thread. Only to be called by sink implementor */
1173 void pa_sink_set_soft_volume(pa_sink
*s
, const pa_cvolume
*volume
) {
1174 pa_sink_assert_ref(s
);
1177 s
->soft_volume
= *volume
;
1179 if (PA_SINK_IS_LINKED(s
->state
))
1180 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_SET_VOLUME
, NULL
, 0, NULL
) == 0);
1182 s
->thread_info
.soft_volume
= *volume
;
1185 /* Called from main thread */
1186 const pa_cvolume
*pa_sink_get_volume(pa_sink
*s
, pa_bool_t force_refresh
) {
1187 pa_sink_assert_ref(s
);
1189 if (s
->refresh_volume
|| force_refresh
) {
1190 struct pa_cvolume old_virtual_volume
= s
->virtual_volume
;
1195 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_GET_VOLUME
, NULL
, 0, NULL
) == 0);
1197 if (!pa_cvolume_equal(&old_virtual_volume
, &s
->virtual_volume
)) {
1199 if (s
->flags
& PA_SINK_FLAT_VOLUME
)
1200 pa_sink_propagate_flat_volume(s
, &old_virtual_volume
);
1202 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SINK
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
1206 return &s
->virtual_volume
;
1209 /* Called from main thread */
1210 void pa_sink_volume_changed(pa_sink
*s
, const pa_cvolume
*new_volume
) {
1211 pa_sink_assert_ref(s
);
1213 /* The sink implementor may call this if the volume changed to make sure everyone is notified */
1215 if (pa_cvolume_equal(&s
->virtual_volume
, new_volume
))
1218 s
->virtual_volume
= *new_volume
;
1219 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SINK
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
1222 /* Called from main thread */
1223 void pa_sink_set_mute(pa_sink
*s
, pa_bool_t mute
) {
1224 pa_bool_t old_muted
;
1226 pa_sink_assert_ref(s
);
1227 pa_assert(PA_SINK_IS_LINKED(s
->state
));
1229 old_muted
= s
->muted
;
1235 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_SET_MUTE
, NULL
, 0, NULL
) == 0);
1237 if (old_muted
!= s
->muted
)
1238 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SINK
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
1241 /* Called from main thread */
1242 pa_bool_t
pa_sink_get_mute(pa_sink
*s
, pa_bool_t force_refresh
) {
1244 pa_sink_assert_ref(s
);
1246 if (s
->refresh_muted
|| force_refresh
) {
1247 pa_bool_t old_muted
= s
->muted
;
1252 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_GET_MUTE
, NULL
, 0, NULL
) == 0);
1254 if (old_muted
!= s
->muted
)
1255 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SINK
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
1261 /* Called from main thread */
1262 void pa_sink_mute_changed(pa_sink
*s
, pa_bool_t new_muted
) {
1263 pa_sink_assert_ref(s
);
1265 /* The sink implementor may call this if the volume changed to make sure everyone is notified */
1267 if (s
->muted
== new_muted
)
1270 s
->muted
= new_muted
;
1271 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SINK
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
1274 /* Called from main thread */
1275 pa_bool_t
pa_sink_update_proplist(pa_sink
*s
, pa_update_mode_t mode
, pa_proplist
*p
) {
1276 pa_sink_assert_ref(s
);
1279 pa_proplist_update(s
->proplist
, mode
, p
);
1281 if (PA_SINK_IS_LINKED(s
->state
)) {
1282 pa_hook_fire(&s
->core
->hooks
[PA_CORE_HOOK_SINK_PROPLIST_CHANGED
], s
);
1283 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SINK
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
1289 /* Called from main thread */
1290 void pa_sink_set_description(pa_sink
*s
, const char *description
) {
1292 pa_sink_assert_ref(s
);
1294 if (!description
&& !pa_proplist_contains(s
->proplist
, PA_PROP_DEVICE_DESCRIPTION
))
1297 old
= pa_proplist_gets(s
->proplist
, PA_PROP_DEVICE_DESCRIPTION
);
1299 if (old
&& description
&& !strcmp(old
, description
))
1303 pa_proplist_sets(s
->proplist
, PA_PROP_DEVICE_DESCRIPTION
, description
);
1305 pa_proplist_unset(s
->proplist
, PA_PROP_DEVICE_DESCRIPTION
);
1307 if (s
->monitor_source
) {
1310 n
= pa_sprintf_malloc("Monitor Source of %s", description
? description
: s
->name
);
1311 pa_source_set_description(s
->monitor_source
, n
);
1315 if (PA_SINK_IS_LINKED(s
->state
)) {
1316 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SINK
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
1317 pa_hook_fire(&s
->core
->hooks
[PA_CORE_HOOK_SINK_PROPLIST_CHANGED
], s
);
1321 /* Called from main thread */
1322 unsigned pa_sink_linked_by(pa_sink
*s
) {
1325 pa_sink_assert_ref(s
);
1326 pa_assert(PA_SINK_IS_LINKED(s
->state
));
1328 ret
= pa_idxset_size(s
->inputs
);
1330 /* We add in the number of streams connected to us here. Please
1331 * note the asymmmetry to pa_sink_used_by()! */
1333 if (s
->monitor_source
)
1334 ret
+= pa_source_linked_by(s
->monitor_source
);
1339 /* Called from main thread */
1340 unsigned pa_sink_used_by(pa_sink
*s
) {
1343 pa_sink_assert_ref(s
);
1344 pa_assert(PA_SINK_IS_LINKED(s
->state
));
1346 ret
= pa_idxset_size(s
->inputs
);
1347 pa_assert(ret
>= s
->n_corked
);
1349 /* Streams connected to our monitor source do not matter for
1350 * pa_sink_used_by()!.*/
1352 return ret
- s
->n_corked
;
1355 /* Called from main thread */
1356 unsigned pa_sink_check_suspend(pa_sink
*s
) {
1361 pa_sink_assert_ref(s
);
1363 if (!PA_SINK_IS_LINKED(s
->state
))
1368 for (i
= PA_SINK_INPUT(pa_idxset_first(s
->inputs
, &idx
)); i
; i
= PA_SINK_INPUT(pa_idxset_next(s
->inputs
, &idx
))) {
1369 pa_sink_input_state_t st
;
1371 st
= pa_sink_input_get_state(i
);
1372 pa_assert(PA_SINK_INPUT_IS_LINKED(st
));
1374 if (st
== PA_SINK_INPUT_CORKED
)
1377 if (i
->flags
& PA_SINK_INPUT_DONT_INHIBIT_AUTO_SUSPEND
)
1383 if (s
->monitor_source
)
1384 ret
+= pa_source_check_suspend(s
->monitor_source
);
1389 /* Called from the IO thread */
1390 static void sync_input_volumes_within_thread(pa_sink
*s
) {
1394 pa_sink_assert_ref(s
);
1396 while ((i
= PA_SINK_INPUT(pa_hashmap_iterate(s
->thread_info
.inputs
, &state
, NULL
)))) {
1397 if (pa_cvolume_equal(&i
->thread_info
.soft_volume
, &i
->soft_volume
))
1400 i
->thread_info
.soft_volume
= i
->soft_volume
;
1401 pa_sink_input_request_rewind(i
, 0, TRUE
, FALSE
, FALSE
);
1405 /* Called from IO thread, except when it is not */
1406 int pa_sink_process_msg(pa_msgobject
*o
, int code
, void *userdata
, int64_t offset
, pa_memchunk
*chunk
) {
1407 pa_sink
*s
= PA_SINK(o
);
1408 pa_sink_assert_ref(s
);
1410 switch ((pa_sink_message_t
) code
) {
1412 case PA_SINK_MESSAGE_ADD_INPUT
: {
1413 pa_sink_input
*i
= PA_SINK_INPUT(userdata
);
1415 /* If you change anything here, make sure to change the
1416 * sink input handling a few lines down at
1417 * PA_SINK_MESSAGE_FINISH_MOVE, too. */
1419 pa_hashmap_put(s
->thread_info
.inputs
, PA_UINT32_TO_PTR(i
->index
), pa_sink_input_ref(i
));
1421 /* Since the caller sleeps in pa_sink_input_put(), we can
1422 * safely access data outside of thread_info even though
1425 if ((i
->thread_info
.sync_prev
= i
->sync_prev
)) {
1426 pa_assert(i
->sink
== i
->thread_info
.sync_prev
->sink
);
1427 pa_assert(i
->sync_prev
->sync_next
== i
);
1428 i
->thread_info
.sync_prev
->thread_info
.sync_next
= i
;
1431 if ((i
->thread_info
.sync_next
= i
->sync_next
)) {
1432 pa_assert(i
->sink
== i
->thread_info
.sync_next
->sink
);
1433 pa_assert(i
->sync_next
->sync_prev
== i
);
1434 i
->thread_info
.sync_next
->thread_info
.sync_prev
= i
;
1437 pa_assert(!i
->thread_info
.attached
);
1438 i
->thread_info
.attached
= TRUE
;
1443 pa_sink_input_set_state_within_thread(i
, i
->state
);
1445 /* The requested latency of the sink input needs to be
1446 * fixed up and then configured on the sink */
1448 if (i
->thread_info
.requested_sink_latency
!= (pa_usec_t
) -1)
1449 pa_sink_input_set_requested_latency_within_thread(i
, i
->thread_info
.requested_sink_latency
);
1451 pa_sink_input_update_max_rewind(i
, s
->thread_info
.max_rewind
);
1452 pa_sink_input_update_max_request(i
, s
->thread_info
.max_request
);
1454 /* We don't rewind here automatically. This is left to the
1455 * sink input implementor because some sink inputs need a
1456 * slow start, i.e. need some time to buffer client
1457 * samples before beginning streaming. */
1459 /* In flat volume mode we need to update the volume as
1461 return o
->process_msg(o
, PA_SINK_MESSAGE_SET_VOLUME
, NULL
, 0, NULL
);
1464 case PA_SINK_MESSAGE_REMOVE_INPUT
: {
1465 pa_sink_input
*i
= PA_SINK_INPUT(userdata
);
1467 /* If you change anything here, make sure to change the
1468 * sink input handling a few lines down at
1469 * PA_SINK_MESSAGE_PREPAPRE_MOVE, too. */
1474 pa_sink_input_set_state_within_thread(i
, i
->state
);
1476 pa_assert(i
->thread_info
.attached
);
1477 i
->thread_info
.attached
= FALSE
;
1479 /* Since the caller sleeps in pa_sink_input_unlink(),
1480 * we can safely access data outside of thread_info even
1481 * though it is mutable */
1483 pa_assert(!i
->sync_prev
);
1484 pa_assert(!i
->sync_next
);
1486 if (i
->thread_info
.sync_prev
) {
1487 i
->thread_info
.sync_prev
->thread_info
.sync_next
= i
->thread_info
.sync_prev
->sync_next
;
1488 i
->thread_info
.sync_prev
= NULL
;
1491 if (i
->thread_info
.sync_next
) {
1492 i
->thread_info
.sync_next
->thread_info
.sync_prev
= i
->thread_info
.sync_next
->sync_prev
;
1493 i
->thread_info
.sync_next
= NULL
;
1496 if (pa_hashmap_remove(s
->thread_info
.inputs
, PA_UINT32_TO_PTR(i
->index
)))
1497 pa_sink_input_unref(i
);
1499 pa_sink_invalidate_requested_latency(s
);
1500 pa_sink_request_rewind(s
, (size_t) -1);
1502 /* In flat volume mode we need to update the volume as
1504 return o
->process_msg(o
, PA_SINK_MESSAGE_SET_VOLUME
, NULL
, 0, NULL
);
1507 case PA_SINK_MESSAGE_START_MOVE
: {
1508 pa_sink_input
*i
= PA_SINK_INPUT(userdata
);
1510 /* We don't support moving synchronized streams. */
1511 pa_assert(!i
->sync_prev
);
1512 pa_assert(!i
->sync_next
);
1513 pa_assert(!i
->thread_info
.sync_next
);
1514 pa_assert(!i
->thread_info
.sync_prev
);
1516 if (i
->thread_info
.state
!= PA_SINK_INPUT_CORKED
) {
1518 size_t sink_nbytes
, total_nbytes
;
1520 /* Get the latency of the sink */
1521 if (!(s
->flags
& PA_SINK_LATENCY
) ||
1522 PA_MSGOBJECT(s
)->process_msg(PA_MSGOBJECT(s
), PA_SINK_MESSAGE_GET_LATENCY
, &usec
, 0, NULL
) < 0)
1525 sink_nbytes
= pa_usec_to_bytes(usec
, &s
->sample_spec
);
1526 total_nbytes
= sink_nbytes
+ pa_memblockq_get_length(i
->thread_info
.render_memblockq
);
1528 if (total_nbytes
> 0) {
1529 i
->thread_info
.rewrite_nbytes
= i
->thread_info
.resampler
? pa_resampler_request(i
->thread_info
.resampler
, total_nbytes
) : total_nbytes
;
1530 i
->thread_info
.rewrite_flush
= TRUE
;
1531 pa_sink_input_process_rewind(i
, sink_nbytes
);
1538 pa_assert(i
->thread_info
.attached
);
1539 i
->thread_info
.attached
= FALSE
;
1541 /* Let's remove the sink input ...*/
1542 if (pa_hashmap_remove(s
->thread_info
.inputs
, PA_UINT32_TO_PTR(i
->index
)))
1543 pa_sink_input_unref(i
);
1545 pa_sink_invalidate_requested_latency(s
);
1547 pa_log_debug("Requesting rewind due to started move");
1548 pa_sink_request_rewind(s
, (size_t) -1);
1550 /* In flat volume mode we need to update the volume as
1552 return o
->process_msg(o
, PA_SINK_MESSAGE_SET_VOLUME
, NULL
, 0, NULL
);
1555 case PA_SINK_MESSAGE_FINISH_MOVE
: {
1556 pa_sink_input
*i
= PA_SINK_INPUT(userdata
);
1558 /* We don't support moving synchronized streams. */
1559 pa_assert(!i
->sync_prev
);
1560 pa_assert(!i
->sync_next
);
1561 pa_assert(!i
->thread_info
.sync_next
);
1562 pa_assert(!i
->thread_info
.sync_prev
);
1564 pa_hashmap_put(s
->thread_info
.inputs
, PA_UINT32_TO_PTR(i
->index
), pa_sink_input_ref(i
));
1566 pa_assert(!i
->thread_info
.attached
);
1567 i
->thread_info
.attached
= TRUE
;
1572 if (i
->thread_info
.requested_sink_latency
!= (pa_usec_t
) -1)
1573 pa_sink_input_set_requested_latency_within_thread(i
, i
->thread_info
.requested_sink_latency
);
1575 pa_sink_input_update_max_rewind(i
, s
->thread_info
.max_rewind
);
1576 pa_sink_input_update_max_request(i
, s
->thread_info
.max_request
);
1578 if (i
->thread_info
.state
!= PA_SINK_INPUT_CORKED
) {
1582 /* Get the latency of the sink */
1583 if (!(s
->flags
& PA_SINK_LATENCY
) ||
1584 PA_MSGOBJECT(s
)->process_msg(PA_MSGOBJECT(s
), PA_SINK_MESSAGE_GET_LATENCY
, &usec
, 0, NULL
) < 0)
1587 nbytes
= pa_usec_to_bytes(usec
, &s
->sample_spec
);
1590 pa_sink_input_drop(i
, nbytes
);
1592 pa_log_debug("Requesting rewind due to finished move");
1593 pa_sink_request_rewind(s
, nbytes
);
1596 /* In flat volume mode we need to update the volume as
1598 return o
->process_msg(o
, PA_SINK_MESSAGE_SET_VOLUME
, NULL
, 0, NULL
);
1601 case PA_SINK_MESSAGE_SET_VOLUME
:
1603 if (!pa_cvolume_equal(&s
->thread_info
.soft_volume
, &s
->soft_volume
)) {
1604 s
->thread_info
.soft_volume
= s
->soft_volume
;
1605 pa_sink_request_rewind(s
, (size_t) -1);
1608 if (!(s
->flags
& PA_SINK_FLAT_VOLUME
))
1611 /* Fall through ... */
1613 case PA_SINK_MESSAGE_SYNC_VOLUMES
:
1614 sync_input_volumes_within_thread(s
);
1617 case PA_SINK_MESSAGE_GET_VOLUME
:
1620 case PA_SINK_MESSAGE_SET_MUTE
:
1622 if (s
->thread_info
.soft_muted
!= s
->muted
) {
1623 s
->thread_info
.soft_muted
= s
->muted
;
1624 pa_sink_request_rewind(s
, (size_t) -1);
1629 case PA_SINK_MESSAGE_GET_MUTE
:
1632 case PA_SINK_MESSAGE_SET_STATE
: {
1634 pa_bool_t suspend_change
=
1635 (s
->thread_info
.state
== PA_SINK_SUSPENDED
&& PA_SINK_IS_OPENED(PA_PTR_TO_UINT(userdata
))) ||
1636 (PA_SINK_IS_OPENED(s
->thread_info
.state
) && PA_PTR_TO_UINT(userdata
) == PA_SINK_SUSPENDED
);
1638 s
->thread_info
.state
= PA_PTR_TO_UINT(userdata
);
1640 if (s
->thread_info
.state
== PA_SINK_SUSPENDED
) {
1641 s
->thread_info
.rewind_nbytes
= 0;
1642 s
->thread_info
.rewind_requested
= FALSE
;
1645 if (suspend_change
) {
1649 while ((i
= pa_hashmap_iterate(s
->thread_info
.inputs
, &state
, NULL
)))
1650 if (i
->suspend_within_thread
)
1651 i
->suspend_within_thread(i
, s
->thread_info
.state
== PA_SINK_SUSPENDED
);
1657 case PA_SINK_MESSAGE_DETACH
:
1659 /* Detach all streams */
1660 pa_sink_detach_within_thread(s
);
1663 case PA_SINK_MESSAGE_ATTACH
:
1665 /* Reattach all streams */
1666 pa_sink_attach_within_thread(s
);
1669 case PA_SINK_MESSAGE_GET_REQUESTED_LATENCY
: {
1671 pa_usec_t
*usec
= userdata
;
1672 *usec
= pa_sink_get_requested_latency_within_thread(s
);
1674 if (*usec
== (pa_usec_t
) -1)
1675 *usec
= s
->thread_info
.max_latency
;
1680 case PA_SINK_MESSAGE_SET_LATENCY_RANGE
: {
1681 pa_usec_t
*r
= userdata
;
1683 pa_sink_set_latency_range_within_thread(s
, r
[0], r
[1]);
1688 case PA_SINK_MESSAGE_GET_LATENCY_RANGE
: {
1689 pa_usec_t
*r
= userdata
;
1691 r
[0] = s
->thread_info
.min_latency
;
1692 r
[1] = s
->thread_info
.max_latency
;
1697 case PA_SINK_MESSAGE_GET_MAX_REWIND
:
1699 *((size_t*) userdata
) = s
->thread_info
.max_rewind
;
1702 case PA_SINK_MESSAGE_GET_MAX_REQUEST
:
1704 *((size_t*) userdata
) = s
->thread_info
.max_request
;
1707 case PA_SINK_MESSAGE_SET_MAX_REWIND
:
1709 pa_sink_set_max_rewind_within_thread(s
, (size_t) offset
);
1712 case PA_SINK_MESSAGE_SET_MAX_REQUEST
:
1714 pa_sink_set_max_request_within_thread(s
, (size_t) offset
);
1717 case PA_SINK_MESSAGE_GET_LATENCY
:
1718 case PA_SINK_MESSAGE_MAX
:
1725 /* Called from main thread */
1726 int pa_sink_suspend_all(pa_core
*c
, pa_bool_t suspend
) {
1731 pa_core_assert_ref(c
);
1733 for (sink
= PA_SINK(pa_idxset_first(c
->sinks
, &idx
)); sink
; sink
= PA_SINK(pa_idxset_next(c
->sinks
, &idx
))) {
1736 if ((r
= pa_sink_suspend(sink
, suspend
)) < 0)
1743 /* Called from main thread */
1744 void pa_sink_detach(pa_sink
*s
) {
1745 pa_sink_assert_ref(s
);
1746 pa_assert(PA_SINK_IS_LINKED(s
->state
));
1748 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_DETACH
, NULL
, 0, NULL
) == 0);
1751 /* Called from main thread */
1752 void pa_sink_attach(pa_sink
*s
) {
1753 pa_sink_assert_ref(s
);
1754 pa_assert(PA_SINK_IS_LINKED(s
->state
));
1756 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_ATTACH
, NULL
, 0, NULL
) == 0);
1759 /* Called from IO thread */
1760 void pa_sink_detach_within_thread(pa_sink
*s
) {
1764 pa_sink_assert_ref(s
);
1765 pa_assert(PA_SINK_IS_LINKED(s
->thread_info
.state
));
1767 while ((i
= pa_hashmap_iterate(s
->thread_info
.inputs
, &state
, NULL
)))
1771 if (s
->monitor_source
)
1772 pa_source_detach_within_thread(s
->monitor_source
);
1775 /* Called from IO thread */
1776 void pa_sink_attach_within_thread(pa_sink
*s
) {
1780 pa_sink_assert_ref(s
);
1781 pa_assert(PA_SINK_IS_LINKED(s
->thread_info
.state
));
1783 while ((i
= pa_hashmap_iterate(s
->thread_info
.inputs
, &state
, NULL
)))
1787 if (s
->monitor_source
)
1788 pa_source_attach_within_thread(s
->monitor_source
);
1791 /* Called from IO thread */
1792 void pa_sink_request_rewind(pa_sink
*s
, size_t nbytes
) {
1793 pa_sink_assert_ref(s
);
1794 pa_assert(PA_SINK_IS_LINKED(s
->thread_info
.state
));
1796 if (s
->thread_info
.state
== PA_SINK_SUSPENDED
)
1799 if (nbytes
== (size_t) -1)
1800 nbytes
= s
->thread_info
.max_rewind
;
1802 nbytes
= PA_MIN(nbytes
, s
->thread_info
.max_rewind
);
1804 if (s
->thread_info
.rewind_requested
&&
1805 nbytes
<= s
->thread_info
.rewind_nbytes
)
1808 s
->thread_info
.rewind_nbytes
= nbytes
;
1809 s
->thread_info
.rewind_requested
= TRUE
;
1811 if (s
->request_rewind
)
1812 s
->request_rewind(s
);
1815 /* Called from IO thread */
1816 pa_usec_t
pa_sink_get_requested_latency_within_thread(pa_sink
*s
) {
1817 pa_usec_t result
= (pa_usec_t
) -1;
1820 pa_usec_t monitor_latency
;
1822 pa_sink_assert_ref(s
);
1824 if (s
->thread_info
.requested_latency_valid
)
1825 return s
->thread_info
.requested_latency
;
1827 while ((i
= pa_hashmap_iterate(s
->thread_info
.inputs
, &state
, NULL
)))
1829 if (i
->thread_info
.requested_sink_latency
!= (pa_usec_t
) -1 &&
1830 (result
== (pa_usec_t
) -1 || result
> i
->thread_info
.requested_sink_latency
))
1831 result
= i
->thread_info
.requested_sink_latency
;
1833 monitor_latency
= pa_source_get_requested_latency_within_thread(s
->monitor_source
);
1835 if (monitor_latency
!= (pa_usec_t
) -1 &&
1836 (result
== (pa_usec_t
) -1 || result
> monitor_latency
))
1837 result
= monitor_latency
;
1839 if (result
!= (pa_usec_t
) -1) {
1840 if (result
> s
->thread_info
.max_latency
)
1841 result
= s
->thread_info
.max_latency
;
1843 if (result
< s
->thread_info
.min_latency
)
1844 result
= s
->thread_info
.min_latency
;
1847 s
->thread_info
.requested_latency
= result
;
1848 s
->thread_info
.requested_latency_valid
= TRUE
;
1853 /* Called from main thread */
1854 pa_usec_t
pa_sink_get_requested_latency(pa_sink
*s
) {
1857 pa_sink_assert_ref(s
);
1858 pa_assert(PA_SINK_IS_LINKED(s
->state
));
1860 if (s
->state
== PA_SINK_SUSPENDED
)
1863 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_GET_REQUESTED_LATENCY
, &usec
, 0, NULL
) == 0);
1867 /* Called from IO as well as the main thread -- the latter only before the IO thread started up */
1868 void pa_sink_set_max_rewind_within_thread(pa_sink
*s
, size_t max_rewind
) {
1872 pa_sink_assert_ref(s
);
1874 if (max_rewind
== s
->thread_info
.max_rewind
)
1877 s
->thread_info
.max_rewind
= max_rewind
;
1879 if (PA_SINK_IS_LINKED(s
->thread_info
.state
)) {
1880 while ((i
= pa_hashmap_iterate(s
->thread_info
.inputs
, &state
, NULL
)))
1881 pa_sink_input_update_max_rewind(i
, s
->thread_info
.max_rewind
);
1884 if (s
->monitor_source
)
1885 pa_source_set_max_rewind_within_thread(s
->monitor_source
, s
->thread_info
.max_rewind
);
1888 /* Called from main thread */
1889 void pa_sink_set_max_rewind(pa_sink
*s
, size_t max_rewind
) {
1890 pa_sink_assert_ref(s
);
1892 if (PA_SINK_IS_LINKED(s
->state
))
1893 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_SET_MAX_REWIND
, NULL
, max_rewind
, NULL
) == 0);
1895 pa_sink_set_max_rewind_within_thread(s
, max_rewind
);
1898 /* Called from IO as well as the main thread -- the latter only before the IO thread started up */
1899 void pa_sink_set_max_request_within_thread(pa_sink
*s
, size_t max_request
) {
1902 pa_sink_assert_ref(s
);
1904 if (max_request
== s
->thread_info
.max_request
)
1907 s
->thread_info
.max_request
= max_request
;
1909 if (PA_SINK_IS_LINKED(s
->thread_info
.state
)) {
1912 while ((i
= pa_hashmap_iterate(s
->thread_info
.inputs
, &state
, NULL
)))
1913 pa_sink_input_update_max_request(i
, s
->thread_info
.max_request
);
1917 /* Called from main thread */
1918 void pa_sink_set_max_request(pa_sink
*s
, size_t max_request
) {
1919 pa_sink_assert_ref(s
);
1921 if (PA_SINK_IS_LINKED(s
->state
))
1922 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_SET_MAX_REQUEST
, NULL
, max_request
, NULL
) == 0);
1924 pa_sink_set_max_request_within_thread(s
, max_request
);
1927 /* Called from IO thread */
1928 void pa_sink_invalidate_requested_latency(pa_sink
*s
) {
1932 pa_sink_assert_ref(s
);
1934 s
->thread_info
.requested_latency_valid
= FALSE
;
1936 if (PA_SINK_IS_LINKED(s
->thread_info
.state
)) {
1938 if (s
->update_requested_latency
)
1939 s
->update_requested_latency(s
);
1941 while ((i
= pa_hashmap_iterate(s
->thread_info
.inputs
, &state
, NULL
)))
1942 if (i
->update_sink_requested_latency
)
1943 i
->update_sink_requested_latency(i
);
1947 /* Called from main thread */
1948 void pa_sink_set_latency_range(pa_sink
*s
, pa_usec_t min_latency
, pa_usec_t max_latency
) {
1949 pa_sink_assert_ref(s
);
1951 /* min_latency == 0: no limit
1952 * min_latency anything else: specified limit
1954 * Similar for max_latency */
1956 if (min_latency
< ABSOLUTE_MIN_LATENCY
)
1957 min_latency
= ABSOLUTE_MIN_LATENCY
;
1959 if (max_latency
<= 0 ||
1960 max_latency
> ABSOLUTE_MAX_LATENCY
)
1961 max_latency
= ABSOLUTE_MAX_LATENCY
;
1963 pa_assert(min_latency
<= max_latency
);
1965 /* Hmm, let's see if someone forgot to set PA_SINK_DYNAMIC_LATENCY here... */
1966 pa_assert((min_latency
== ABSOLUTE_MIN_LATENCY
&&
1967 max_latency
== ABSOLUTE_MAX_LATENCY
) ||
1968 (s
->flags
& PA_SINK_DYNAMIC_LATENCY
));
1970 if (PA_SINK_IS_LINKED(s
->state
)) {
1976 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_SET_LATENCY_RANGE
, r
, 0, NULL
) == 0);
1978 pa_sink_set_latency_range_within_thread(s
, min_latency
, max_latency
);
1981 /* Called from main thread */
1982 void pa_sink_get_latency_range(pa_sink
*s
, pa_usec_t
*min_latency
, pa_usec_t
*max_latency
) {
1983 pa_sink_assert_ref(s
);
1984 pa_assert(min_latency
);
1985 pa_assert(max_latency
);
1987 if (PA_SINK_IS_LINKED(s
->state
)) {
1988 pa_usec_t r
[2] = { 0, 0 };
1990 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_GET_LATENCY_RANGE
, r
, 0, NULL
) == 0);
1992 *min_latency
= r
[0];
1993 *max_latency
= r
[1];
1995 *min_latency
= s
->thread_info
.min_latency
;
1996 *max_latency
= s
->thread_info
.max_latency
;
2000 /* Called from IO thread */
2001 void pa_sink_set_latency_range_within_thread(pa_sink
*s
, pa_usec_t min_latency
, pa_usec_t max_latency
) {
2004 pa_sink_assert_ref(s
);
2006 pa_assert(min_latency
>= ABSOLUTE_MIN_LATENCY
);
2007 pa_assert(max_latency
<= ABSOLUTE_MAX_LATENCY
);
2008 pa_assert(min_latency
<= max_latency
);
2010 /* Hmm, let's see if someone forgot to set PA_SINK_DYNAMIC_LATENCY here... */
2011 pa_assert((min_latency
== ABSOLUTE_MIN_LATENCY
&&
2012 max_latency
== ABSOLUTE_MAX_LATENCY
) ||
2013 (s
->flags
& PA_SINK_DYNAMIC_LATENCY
));
2015 s
->thread_info
.min_latency
= min_latency
;
2016 s
->thread_info
.max_latency
= max_latency
;
2018 if (PA_SINK_IS_LINKED(s
->thread_info
.state
)) {
2021 while ((i
= pa_hashmap_iterate(s
->thread_info
.inputs
, &state
, NULL
)))
2022 if (i
->update_sink_latency_range
)
2023 i
->update_sink_latency_range(i
);
2026 pa_sink_invalidate_requested_latency(s
);
2028 pa_source_set_latency_range_within_thread(s
->monitor_source
, min_latency
, max_latency
);
2031 /* Called from main context */
2032 size_t pa_sink_get_max_rewind(pa_sink
*s
) {
2034 pa_sink_assert_ref(s
);
2036 if (!PA_SINK_IS_LINKED(s
->state
))
2037 return s
->thread_info
.max_rewind
;
2039 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_GET_MAX_REWIND
, &r
, 0, NULL
) == 0);
2044 /* Called from main context */
2045 size_t pa_sink_get_max_request(pa_sink
*s
) {
2047 pa_sink_assert_ref(s
);
2049 if (!PA_SINK_IS_LINKED(s
->state
))
2050 return s
->thread_info
.max_request
;
2052 pa_assert_se(pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SINK_MESSAGE_GET_MAX_REQUEST
, &r
, 0, NULL
) == 0);
2057 /* Called from main context */
2058 pa_bool_t
pa_device_init_icon(pa_proplist
*p
, pa_bool_t is_sink
) {
2059 const char *ff
, *c
, *t
= NULL
, *s
= "", *profile
, *bus
;
2063 if (pa_proplist_contains(p
, PA_PROP_DEVICE_ICON_NAME
))
2066 if ((ff
= pa_proplist_gets(p
, PA_PROP_DEVICE_FORM_FACTOR
))) {
2068 if (pa_streq(ff
, "microphone"))
2069 t
= "audio-input-microphone";
2070 else if (pa_streq(ff
, "webcam"))
2072 else if (pa_streq(ff
, "computer"))
2074 else if (pa_streq(ff
, "handset"))
2076 else if (pa_streq(ff
, "portable"))
2077 t
= "multimedia-player";
2078 else if (pa_streq(ff
, "tv"))
2079 t
= "video-display";
2083 if ((c
= pa_proplist_gets(p
, PA_PROP_DEVICE_CLASS
)))
2084 if (pa_streq(c
, "modem"))
2091 t
= "audio-input-microphone";
2094 if ((profile
= pa_proplist_gets(p
, PA_PROP_DEVICE_PROFILE_NAME
))) {
2095 if (strstr(profile
, "analog"))
2097 else if (strstr(profile
, "iec958"))
2099 else if (strstr(profile
, "hdmi"))
2103 bus
= pa_proplist_gets(p
, PA_PROP_DEVICE_BUS
);
2105 pa_proplist_setf(p
, PA_PROP_DEVICE_ICON_NAME
, "%s%s%s%s", t
, pa_strempty(s
), bus
? "-" : "", pa_strempty(bus
));
2110 pa_bool_t
pa_device_init_description(pa_proplist
*p
) {
2114 if (pa_proplist_contains(p
, PA_PROP_DEVICE_DESCRIPTION
))
2117 if ((s
= pa_proplist_gets(p
, PA_PROP_DEVICE_FORM_FACTOR
)))
2118 if (pa_streq(s
, "internal")) {
2119 pa_proplist_sets(p
, PA_PROP_DEVICE_DESCRIPTION
, _("Internal Audio"));
2123 if ((s
= pa_proplist_gets(p
, PA_PROP_DEVICE_CLASS
)))
2124 if (pa_streq(s
, "modem")) {
2125 pa_proplist_sets(p
, PA_PROP_DEVICE_DESCRIPTION
, _("Modem"));
2129 if ((s
= pa_proplist_gets(p
, PA_PROP_DEVICE_PRODUCT_NAME
))) {
2130 pa_proplist_sets(p
, PA_PROP_DEVICE_DESCRIPTION
, s
);