4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
7 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2 of the License,
12 or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33 #include <pulse/utf8.h>
34 #include <pulse/xmalloc.h>
35 #include <pulse/timeval.h>
37 #include <pulsecore/source-output.h>
38 #include <pulsecore/namereg.h>
39 #include <pulsecore/core-subscribe.h>
40 #include <pulsecore/log.h>
41 #include <pulsecore/sample-util.h>
45 #define DEFAULT_MIN_LATENCY (4*PA_USEC_PER_MSEC)
47 static PA_DEFINE_CHECK_TYPE(pa_source
, pa_msgobject
);
49 static void source_free(pa_object
*o
);
51 pa_source_new_data
* pa_source_new_data_init(pa_source_new_data
*data
) {
54 memset(data
, 0, sizeof(*data
));
55 data
->proplist
= pa_proplist_new();
60 void pa_source_new_data_set_name(pa_source_new_data
*data
, const char *name
) {
64 data
->name
= pa_xstrdup(name
);
67 void pa_source_new_data_set_sample_spec(pa_source_new_data
*data
, const pa_sample_spec
*spec
) {
70 if ((data
->sample_spec_is_set
= !!spec
))
71 data
->sample_spec
= *spec
;
74 void pa_source_new_data_set_channel_map(pa_source_new_data
*data
, const pa_channel_map
*map
) {
77 if ((data
->channel_map_is_set
= !!map
))
78 data
->channel_map
= *map
;
81 void pa_source_new_data_set_volume(pa_source_new_data
*data
, const pa_cvolume
*volume
) {
84 if ((data
->volume_is_set
= !!volume
))
85 data
->volume
= *volume
;
88 void pa_source_new_data_set_muted(pa_source_new_data
*data
, pa_bool_t mute
) {
91 data
->muted_is_set
= TRUE
;
95 void pa_source_new_data_done(pa_source_new_data
*data
) {
99 pa_proplist_free(data
->proplist
);
102 static void reset_callbacks(pa_source
*s
) {
106 s
->get_volume
= NULL
;
107 s
->set_volume
= NULL
;
110 s
->get_latency
= NULL
;
111 s
->update_requested_latency
= NULL
;
114 pa_source
* pa_source_new(
116 pa_source_new_data
*data
,
117 pa_source_flags_t flags
) {
121 char st
[PA_SAMPLE_SPEC_SNPRINT_MAX
], cm
[PA_CHANNEL_MAP_SNPRINT_MAX
];
125 s
= pa_msgobject_new(pa_source
);
127 if (!(name
= pa_namereg_register(core
, data
->name
, PA_NAMEREG_SOURCE
, s
, data
->namereg_fail
))) {
132 if (pa_hook_fire(&core
->hooks
[PA_CORE_HOOK_SOURCE_NEW
], data
) < 0) {
134 pa_namereg_unregister(core
, name
);
138 pa_return_null_if_fail(!data
->driver
|| pa_utf8_valid(data
->driver
));
139 pa_return_null_if_fail(data
->name
&& pa_utf8_valid(data
->name
) && data
->name
[0]);
141 pa_return_null_if_fail(data
->sample_spec_is_set
&& pa_sample_spec_valid(&data
->sample_spec
));
143 if (!data
->channel_map_is_set
)
144 pa_return_null_if_fail(pa_channel_map_init_auto(&data
->channel_map
, data
->sample_spec
.channels
, PA_CHANNEL_MAP_DEFAULT
));
146 pa_return_null_if_fail(pa_channel_map_valid(&data
->channel_map
));
147 pa_return_null_if_fail(data
->channel_map
.channels
== data
->sample_spec
.channels
);
149 if (!data
->volume_is_set
)
150 pa_cvolume_reset(&data
->volume
, data
->sample_spec
.channels
);
152 pa_return_null_if_fail(pa_cvolume_valid(&data
->volume
));
153 pa_return_null_if_fail(data
->volume
.channels
== data
->sample_spec
.channels
);
155 if (!data
->muted_is_set
)
158 if (pa_hook_fire(&core
->hooks
[PA_CORE_HOOK_SOURCE_FIXATE
], data
) < 0) {
160 pa_namereg_unregister(core
, name
);
164 s
->parent
.parent
.free
= source_free
;
165 s
->parent
.process_msg
= pa_source_process_msg
;
168 s
->state
= PA_SOURCE_INIT
;
170 s
->name
= pa_xstrdup(name
);
171 s
->proplist
= pa_proplist_copy(data
->proplist
);
172 s
->driver
= pa_xstrdup(data
->driver
);
173 s
->module
= data
->module
;
175 s
->sample_spec
= data
->sample_spec
;
176 s
->channel_map
= data
->channel_map
;
178 s
->outputs
= pa_idxset_new(NULL
, NULL
);
180 s
->monitor_of
= NULL
;
182 s
->volume
= data
->volume
;
183 s
->muted
= data
->muted
;
184 s
->refresh_volume
= s
->refresh_muted
= FALSE
;
192 pa_silence_memchunk_get(
193 &core
->silence_cache
,
199 s
->min_latency
= DEFAULT_MIN_LATENCY
;
200 s
->max_latency
= s
->min_latency
;
202 s
->thread_info
.outputs
= pa_hashmap_new(pa_idxset_trivial_hash_func
, pa_idxset_trivial_compare_func
);
203 s
->thread_info
.soft_volume
= s
->volume
;
204 s
->thread_info
.soft_muted
= s
->muted
;
205 s
->thread_info
.state
= s
->state
;
206 s
->thread_info
.max_rewind
= 0;
207 s
->thread_info
.requested_latency_valid
= FALSE
;
208 s
->thread_info
.requested_latency
= 0;
210 pa_assert_se(pa_idxset_put(core
->sources
, s
, &s
->index
) >= 0);
212 pa_log_info("Created source %u \"%s\" with sample spec %s and channel map %s",
215 pa_sample_spec_snprint(st
, sizeof(st
), &s
->sample_spec
),
216 pa_channel_map_snprint(cm
, sizeof(cm
), &s
->channel_map
));
221 static int source_set_state(pa_source
*s
, pa_source_state_t state
) {
223 pa_bool_t suspend_change
;
227 if (s
->state
== state
)
231 (s
->state
== PA_SOURCE_SUSPENDED
&& PA_SOURCE_IS_OPENED(state
)) ||
232 (PA_SOURCE_IS_OPENED(s
->state
) && state
== PA_SOURCE_SUSPENDED
);
235 if ((ret
= s
->set_state(s
, state
)) < 0)
238 if (pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SOURCE_MESSAGE_SET_STATE
, PA_UINT_TO_PTR(state
), 0, NULL
) < 0)
243 if (suspend_change
) {
247 /* We're suspending or resuming, tell everyone about it */
249 for (o
= PA_SOURCE_OUTPUT(pa_idxset_first(s
->outputs
, &idx
)); o
; o
= PA_SOURCE_OUTPUT(pa_idxset_next(s
->outputs
, &idx
)))
251 o
->suspend(o
, state
== PA_SINK_SUSPENDED
);
254 if (state
!= PA_SOURCE_UNLINKED
) /* if we enter UNLINKED state pa_source_unlink() will fire the apropriate events */
255 pa_hook_fire(&s
->core
->hooks
[PA_CORE_HOOK_SOURCE_STATE_CHANGED
], s
);
260 void pa_source_put(pa_source
*s
) {
261 pa_source_assert_ref(s
);
263 pa_assert(s
->state
== PA_SINK_INIT
);
264 pa_assert(s
->asyncmsgq
);
265 pa_assert(s
->rtpoll
);
267 pa_assert(!s
->min_latency
|| !s
->max_latency
|| s
->min_latency
<= s
->max_latency
);
269 if (!(s
->flags
& PA_SOURCE_HW_VOLUME_CTRL
))
270 s
->flags
|= PA_SOURCE_DECIBEL_VOLUME
;
272 pa_assert_se(source_set_state(s
, PA_SOURCE_IDLE
) == 0);
274 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SOURCE
| PA_SUBSCRIPTION_EVENT_NEW
, s
->index
);
275 pa_hook_fire(&s
->core
->hooks
[PA_CORE_HOOK_SOURCE_PUT
], s
);
278 void pa_source_unlink(pa_source
*s
) {
280 pa_source_output
*o
, *j
= NULL
;
284 /* See pa_sink_unlink() for a couple of comments how this function
287 linked
= PA_SOURCE_IS_LINKED(s
->state
);
290 pa_hook_fire(&s
->core
->hooks
[PA_CORE_HOOK_SOURCE_UNLINK
], s
);
292 if (s
->state
!= PA_SOURCE_UNLINKED
)
293 pa_namereg_unregister(s
->core
, s
->name
);
294 pa_idxset_remove_by_data(s
->core
->sources
, s
, NULL
);
296 while ((o
= pa_idxset_first(s
->outputs
, NULL
))) {
298 pa_source_output_kill(o
);
303 source_set_state(s
, PA_SOURCE_UNLINKED
);
305 s
->state
= PA_SOURCE_UNLINKED
;
310 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SOURCE
| PA_SUBSCRIPTION_EVENT_REMOVE
, s
->index
);
311 pa_hook_fire(&s
->core
->hooks
[PA_CORE_HOOK_SOURCE_UNLINK_POST
], s
);
315 static void source_free(pa_object
*o
) {
316 pa_source_output
*so
;
317 pa_source
*s
= PA_SOURCE(o
);
320 pa_assert(pa_source_refcnt(s
) == 0);
322 if (PA_SOURCE_IS_LINKED(s
->state
))
325 pa_log_info("Freeing source %u \"%s\"", s
->index
, s
->name
);
327 pa_idxset_free(s
->outputs
, NULL
, NULL
);
329 while ((so
= pa_hashmap_steal_first(s
->thread_info
.outputs
)))
330 pa_source_output_unref(so
);
332 pa_hashmap_free(s
->thread_info
.outputs
, NULL
, NULL
);
334 if (s
->silence
.memblock
)
335 pa_memblock_unref(s
->silence
.memblock
);
341 pa_proplist_free(s
->proplist
);
346 void pa_source_set_asyncmsgq(pa_source
*s
, pa_asyncmsgq
*q
) {
347 pa_source_assert_ref(s
);
352 void pa_source_set_rtpoll(pa_source
*s
, pa_rtpoll
*p
) {
353 pa_source_assert_ref(s
);
358 int pa_source_update_status(pa_source
*s
) {
359 pa_source_assert_ref(s
);
360 pa_assert(PA_SOURCE_IS_LINKED(s
->state
));
362 if (s
->state
== PA_SOURCE_SUSPENDED
)
365 return source_set_state(s
, pa_source_used_by(s
) ? PA_SOURCE_RUNNING
: PA_SOURCE_IDLE
);
368 int pa_source_suspend(pa_source
*s
, pa_bool_t suspend
) {
369 pa_source_assert_ref(s
);
370 pa_assert(PA_SOURCE_IS_LINKED(s
->state
));
373 return source_set_state(s
, PA_SOURCE_SUSPENDED
);
375 return source_set_state(s
, pa_source_used_by(s
) ? PA_SOURCE_RUNNING
: PA_SOURCE_IDLE
);
378 void pa_source_process_rewind(pa_source
*s
, size_t nbytes
) {
382 pa_source_assert_ref(s
);
383 pa_assert(PA_SOURCE_IS_OPENED(s
->thread_info
.state
));
388 pa_log_debug("Processing rewind...");
390 while ((o
= pa_hashmap_iterate(s
->thread_info
.outputs
, &state
, NULL
))) {
391 pa_source_output_assert_ref(o
);
392 pa_source_output_process_rewind(o
, nbytes
);
396 void pa_source_post(pa_source
*s
, const pa_memchunk
*chunk
) {
400 pa_source_assert_ref(s
);
401 pa_assert(PA_SOURCE_IS_OPENED(s
->thread_info
.state
));
404 if (s
->thread_info
.state
!= PA_SOURCE_RUNNING
)
407 if (s
->thread_info
.soft_muted
|| !pa_cvolume_is_norm(&s
->thread_info
.soft_volume
)) {
408 pa_memchunk vchunk
= *chunk
;
410 pa_memblock_ref(vchunk
.memblock
);
411 pa_memchunk_make_writable(&vchunk
, 0);
413 if (s
->thread_info
.soft_muted
|| pa_cvolume_is_muted(&s
->thread_info
.soft_volume
))
414 pa_silence_memchunk(&vchunk
, &s
->sample_spec
);
416 pa_volume_memchunk(&vchunk
, &s
->sample_spec
, &s
->thread_info
.soft_volume
);
418 while ((o
= pa_hashmap_iterate(s
->thread_info
.outputs
, &state
, NULL
))) {
419 pa_source_output_assert_ref(o
);
420 pa_source_output_push(o
, &vchunk
);
423 pa_memblock_unref(vchunk
.memblock
);
426 while ((o
= pa_hashmap_iterate(s
->thread_info
.outputs
, &state
, NULL
))) {
427 pa_source_output_assert_ref(o
);
428 pa_source_output_push(o
, chunk
);
433 pa_usec_t
pa_source_get_latency(pa_source
*s
) {
436 pa_source_assert_ref(s
);
437 pa_assert(PA_SOURCE_IS_LINKED(s
->state
));
439 if (!PA_SOURCE_IS_OPENED(s
->state
))
443 return s
->get_latency(s
);
445 if (pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SOURCE_MESSAGE_GET_LATENCY
, &usec
, 0, NULL
) < 0)
451 void pa_source_set_volume(pa_source
*s
, const pa_cvolume
*volume
) {
454 pa_source_assert_ref(s
);
455 pa_assert(PA_SOURCE_IS_LINKED(s
->state
));
458 changed
= !pa_cvolume_equal(volume
, &s
->volume
);
461 if (s
->set_volume
&& s
->set_volume(s
) < 0)
462 s
->set_volume
= NULL
;
465 pa_asyncmsgq_post(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SOURCE_MESSAGE_SET_VOLUME
, pa_xnewdup(struct pa_cvolume
, volume
, 1), 0, NULL
, pa_xfree
);
468 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SOURCE
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
471 const pa_cvolume
*pa_source_get_volume(pa_source
*s
) {
472 pa_cvolume old_volume
;
474 pa_source_assert_ref(s
);
475 pa_assert(PA_SOURCE_IS_LINKED(s
->state
));
477 old_volume
= s
->volume
;
479 if (s
->get_volume
&& s
->get_volume(s
) < 0)
480 s
->get_volume
= NULL
;
482 if (!s
->get_volume
&& s
->refresh_volume
)
483 pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SOURCE_MESSAGE_GET_VOLUME
, &s
->volume
, 0, NULL
);
485 if (!pa_cvolume_equal(&old_volume
, &s
->volume
))
486 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SOURCE
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
491 void pa_source_set_mute(pa_source
*s
, pa_bool_t mute
) {
494 pa_source_assert_ref(s
);
495 pa_assert(PA_SOURCE_IS_LINKED(s
->state
));
497 changed
= s
->muted
!= mute
;
500 if (s
->set_mute
&& s
->set_mute(s
) < 0)
504 pa_asyncmsgq_post(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SOURCE_MESSAGE_SET_MUTE
, PA_UINT_TO_PTR(mute
), 0, NULL
, NULL
);
507 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SOURCE
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
510 pa_bool_t
pa_source_get_mute(pa_source
*s
) {
513 pa_source_assert_ref(s
);
514 pa_assert(PA_SOURCE_IS_LINKED(s
->state
));
516 old_muted
= s
->muted
;
518 if (s
->get_mute
&& s
->get_mute(s
) < 0)
521 if (!s
->get_mute
&& s
->refresh_muted
)
522 pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SOURCE_MESSAGE_GET_MUTE
, &s
->muted
, 0, NULL
);
524 if (old_muted
!= s
->muted
)
525 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SOURCE
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
530 void pa_source_set_description(pa_source
*s
, const char *description
) {
532 pa_source_assert_ref(s
);
534 if (!description
&& !pa_proplist_contains(s
->proplist
, PA_PROP_DEVICE_DESCRIPTION
))
537 old
= pa_proplist_gets(s
->proplist
, PA_PROP_DEVICE_DESCRIPTION
);
539 if (old
&& description
&& !strcmp(old
, description
))
543 pa_proplist_sets(s
->proplist
, PA_PROP_DEVICE_DESCRIPTION
, description
);
545 pa_proplist_unset(s
->proplist
, PA_PROP_DEVICE_DESCRIPTION
);
547 if (PA_SOURCE_IS_LINKED(s
->state
)) {
548 pa_subscription_post(s
->core
, PA_SUBSCRIPTION_EVENT_SOURCE
|PA_SUBSCRIPTION_EVENT_CHANGE
, s
->index
);
549 pa_hook_fire(&s
->core
->hooks
[PA_CORE_HOOK_SOURCE_PROPLIST_CHANGED
], s
);
553 unsigned pa_source_linked_by(pa_source
*s
) {
554 pa_source_assert_ref(s
);
555 pa_assert(PA_SOURCE_IS_LINKED(s
->state
));
557 return pa_idxset_size(s
->outputs
);
560 unsigned pa_source_used_by(pa_source
*s
) {
563 pa_source_assert_ref(s
);
564 pa_assert(PA_SOURCE_IS_LINKED(s
->state
));
566 ret
= pa_idxset_size(s
->outputs
);
567 pa_assert(ret
>= s
->n_corked
);
569 return ret
- s
->n_corked
;
572 int pa_source_process_msg(pa_msgobject
*object
, int code
, void *userdata
, int64_t offset
, pa_memchunk
*chunk
) {
573 pa_source
*s
= PA_SOURCE(object
);
574 pa_source_assert_ref(s
);
575 pa_assert(s
->thread_info
.state
!= PA_SOURCE_UNLINKED
);
577 switch ((pa_source_message_t
) code
) {
578 case PA_SOURCE_MESSAGE_ADD_OUTPUT
: {
579 pa_source_output
*o
= PA_SOURCE_OUTPUT(userdata
);
581 pa_hashmap_put(s
->thread_info
.outputs
, PA_UINT32_TO_PTR(o
->index
), pa_source_output_ref(o
));
583 pa_source_output_update_max_rewind(o
, s
->thread_info
.max_rewind
);
585 pa_assert(!o
->thread_info
.attached
);
586 o
->thread_info
.attached
= TRUE
;
591 pa_source_output_set_state_within_thread(o
, o
->state
);
593 pa_source_invalidate_requested_latency(s
);
598 case PA_SOURCE_MESSAGE_REMOVE_OUTPUT
: {
599 pa_source_output
*o
= PA_SOURCE_OUTPUT(userdata
);
601 pa_source_output_set_state_within_thread(o
, o
->state
);
606 pa_assert(o
->thread_info
.attached
);
607 o
->thread_info
.attached
= FALSE
;
609 if (pa_hashmap_remove(s
->thread_info
.outputs
, PA_UINT32_TO_PTR(o
->index
)))
610 pa_source_output_unref(o
);
612 pa_source_invalidate_requested_latency(s
);
617 case PA_SOURCE_MESSAGE_SET_VOLUME
:
618 s
->thread_info
.soft_volume
= *((pa_cvolume
*) userdata
);
621 case PA_SOURCE_MESSAGE_SET_MUTE
:
622 s
->thread_info
.soft_muted
= PA_PTR_TO_UINT(userdata
);
625 case PA_SOURCE_MESSAGE_GET_VOLUME
:
626 *((pa_cvolume
*) userdata
) = s
->thread_info
.soft_volume
;
629 case PA_SOURCE_MESSAGE_GET_MUTE
:
630 *((pa_bool_t
*) userdata
) = s
->thread_info
.soft_muted
;
633 case PA_SOURCE_MESSAGE_SET_STATE
:
634 s
->thread_info
.state
= PA_PTR_TO_UINT(userdata
);
637 case PA_SOURCE_MESSAGE_DETACH
:
639 /* We're detaching all our output streams so that the
640 * asyncmsgq and rtpoll fields can be changed without
642 pa_source_detach_within_thread(s
);
645 case PA_SOURCE_MESSAGE_ATTACH
:
647 /* Reattach all streams */
648 pa_source_attach_within_thread(s
);
651 case PA_SOURCE_MESSAGE_GET_REQUESTED_LATENCY
: {
653 pa_usec_t
*usec
= userdata
;
654 *usec
= pa_source_get_requested_latency_within_thread(s
);
658 case PA_SOURCE_MESSAGE_GET_LATENCY
:
659 case PA_SOURCE_MESSAGE_MAX
:
666 int pa_source_suspend_all(pa_core
*c
, pa_bool_t suspend
) {
671 pa_core_assert_ref(c
);
673 for (source
= PA_SOURCE(pa_idxset_first(c
->sources
, &idx
)); source
; source
= PA_SOURCE(pa_idxset_next(c
->sources
, &idx
)))
674 ret
-= pa_source_suspend(source
, suspend
) < 0;
679 void pa_source_detach(pa_source
*s
) {
680 pa_source_assert_ref(s
);
681 pa_assert(PA_SOURCE_IS_LINKED(s
->state
));
683 pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SOURCE_MESSAGE_DETACH
, NULL
, 0, NULL
);
686 void pa_source_attach(pa_source
*s
) {
687 pa_source_assert_ref(s
);
688 pa_assert(PA_SOURCE_IS_LINKED(s
->state
));
690 pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SOURCE_MESSAGE_ATTACH
, NULL
, 0, NULL
);
693 void pa_source_detach_within_thread(pa_source
*s
) {
697 pa_source_assert_ref(s
);
698 pa_assert(PA_SOURCE_IS_LINKED(s
->thread_info
.state
));
700 while ((o
= pa_hashmap_iterate(s
->thread_info
.outputs
, &state
, NULL
)))
705 void pa_source_attach_within_thread(pa_source
*s
) {
709 pa_source_assert_ref(s
);
710 pa_assert(PA_SOURCE_IS_LINKED(s
->thread_info
.state
));
712 while ((o
= pa_hashmap_iterate(s
->thread_info
.outputs
, &state
, NULL
)))
717 pa_usec_t
pa_source_get_requested_latency_within_thread(pa_source
*s
) {
718 pa_usec_t result
= (pa_usec_t
) -1;
722 pa_source_assert_ref(s
);
724 if (s
->thread_info
.requested_latency_valid
)
725 return s
->thread_info
.requested_latency
;
727 while ((o
= pa_hashmap_iterate(s
->thread_info
.outputs
, &state
, NULL
)))
729 if (o
->thread_info
.requested_source_latency
!= (pa_usec_t
) -1 &&
730 (result
== (pa_usec_t
) -1 || result
> o
->thread_info
.requested_source_latency
))
731 result
= o
->thread_info
.requested_source_latency
;
733 if (result
!= (pa_usec_t
) -1) {
734 if (s
->max_latency
> 0 && result
> s
->max_latency
)
735 result
= s
->max_latency
;
737 if (s
->min_latency
> 0 && result
< s
->min_latency
)
738 result
= s
->min_latency
;
741 s
->thread_info
.requested_latency
= result
;
742 s
->thread_info
.requested_latency_valid
= TRUE
;
747 pa_usec_t
pa_source_get_requested_latency(pa_source
*s
) {
750 pa_source_assert_ref(s
);
751 pa_assert(PA_SOURCE_IS_LINKED(s
->state
));
753 if (!PA_SOURCE_IS_OPENED(s
->state
))
756 if (pa_asyncmsgq_send(s
->asyncmsgq
, PA_MSGOBJECT(s
), PA_SOURCE_MESSAGE_GET_REQUESTED_LATENCY
, &usec
, 0, NULL
) < 0)
759 if (usec
== (pa_usec_t
) -1)
760 usec
= s
->max_latency
;
765 void pa_source_set_max_rewind(pa_source
*s
, size_t max_rewind
) {
769 pa_source_assert_ref(s
);
771 if (max_rewind
== s
->thread_info
.max_rewind
)
774 s
->thread_info
.max_rewind
= max_rewind
;
776 while ((o
= pa_hashmap_iterate(s
->thread_info
.outputs
, &state
, NULL
)))
777 pa_source_output_update_max_rewind(o
, s
->thread_info
.max_rewind
);
780 void pa_source_invalidate_requested_latency(pa_source
*s
) {
782 pa_source_assert_ref(s
);
783 pa_assert(PA_SOURCE_IS_LINKED(s
->thread_info
.state
));
785 if (!s
->thread_info
.requested_latency_valid
)
788 s
->thread_info
.requested_latency_valid
= FALSE
;
790 if (s
->update_requested_latency
)
791 s
->update_requested_latency(s
);