From 892a83945e7cd56039fcbbefc4c16ffdb3a7d722 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 25 Mar 2009 00:33:35 +0100 Subject: simplify things and make sure timing setters can be called in most contexts --- src/pulsecore/sink.c | 35 +++++++++++++++++------------------ src/pulsecore/source.c | 37 +++++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index c2012df0..68f88566 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -1843,12 +1843,15 @@ void pa_sink_invalidate_requested_latency(pa_sink *s) { s->thread_info.requested_latency_valid = FALSE; - if (s->update_requested_latency) - s->update_requested_latency(s); + if (PA_SINK_IS_LINKED(s->thread_info.state)) { - while ((i = pa_hashmap_iterate(s->thread_info.inputs, &state, NULL))) - if (i->update_sink_requested_latency) - i->update_sink_requested_latency(i); + if (s->update_requested_latency) + s->update_requested_latency(s); + + while ((i = pa_hashmap_iterate(s->thread_info.inputs, &state, NULL))) + if (i->update_sink_requested_latency) + i->update_sink_requested_latency(i); + } } /* Called from main thread */ @@ -1881,15 +1884,8 @@ void pa_sink_set_latency_range(pa_sink *s, pa_usec_t min_latency, pa_usec_t max_ r[1] = max_latency; pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SET_LATENCY_RANGE, r, 0, NULL) == 0); - } else { - s->thread_info.min_latency = min_latency; - s->thread_info.max_latency = max_latency; - - s->monitor_source->thread_info.min_latency = min_latency; - s->monitor_source->thread_info.max_latency = max_latency; - - s->thread_info.requested_latency_valid = s->monitor_source->thread_info.requested_latency_valid = FALSE; - } + } else + pa_sink_set_latency_range_within_thread(s, min_latency, max_latency); } /* Called from main thread */ @@ -1913,7 +1909,6 @@ void pa_sink_get_latency_range(pa_sink *s, pa_usec_t *min_latency, pa_usec_t *ma /* Called from IO thread */ void pa_sink_set_latency_range_within_thread(pa_sink *s, pa_usec_t min_latency, pa_usec_t max_latency) { - pa_sink_input *i; void *state = NULL; pa_sink_assert_ref(s); @@ -1930,9 +1925,13 @@ void pa_sink_set_latency_range_within_thread(pa_sink *s, pa_usec_t min_latency, s->thread_info.min_latency = min_latency; s->thread_info.max_latency = max_latency; - while ((i = pa_hashmap_iterate(s->thread_info.inputs, &state, NULL))) - if (i->update_sink_latency_range) - i->update_sink_latency_range(i); + if (PA_SINK_IS_LINKED(s->thread_info.state)) { + pa_sink_input *i; + + while ((i = pa_hashmap_iterate(s->thread_info.inputs, &state, NULL))) + if (i->update_sink_latency_range) + i->update_sink_latency_range(i); + } pa_sink_invalidate_requested_latency(s); diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 0fe6f8d9..5b4378ae 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -1124,17 +1124,21 @@ void pa_source_invalidate_requested_latency(pa_source *s) { s->thread_info.requested_latency_valid = FALSE; - if (s->update_requested_latency) - s->update_requested_latency(s); + if (PA_SOURCE_IS_LINKED(s->thread_info.state)) { - while ((o = pa_hashmap_iterate(s->thread_info.outputs, &state, NULL))) - if (o->update_source_requested_latency) - o->update_source_requested_latency(o); + if (s->update_requested_latency) + s->update_requested_latency(s); + + while ((o = pa_hashmap_iterate(s->thread_info.outputs, &state, NULL))) + if (o->update_source_requested_latency) + o->update_source_requested_latency(o); + } if (s->monitor_of) pa_sink_invalidate_requested_latency(s->monitor_of); } +/* Called from main thread */ void pa_source_set_latency_range(pa_source *s, pa_usec_t min_latency, pa_usec_t max_latency) { pa_source_assert_ref(s); @@ -1164,14 +1168,11 @@ void pa_source_set_latency_range(pa_source *s, pa_usec_t min_latency, pa_usec_t r[1] = max_latency; pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SOURCE_MESSAGE_SET_LATENCY_RANGE, r, 0, NULL) == 0); - } else { - s->thread_info.min_latency = min_latency; - s->thread_info.max_latency = max_latency; - - s->thread_info.requested_latency_valid = FALSE; - } + } else + pa_source_set_latency_range_within_thread(s, min_latency, max_latency); } +/* Called from main thread */ void pa_source_get_latency_range(pa_source *s, pa_usec_t *min_latency, pa_usec_t *max_latency) { pa_source_assert_ref(s); pa_assert(min_latency); @@ -1190,9 +1191,8 @@ void pa_source_get_latency_range(pa_source *s, pa_usec_t *min_latency, pa_usec_t } } -/* Called from IO thread */ +/* Called from IO thread, and from main thread before pa_sink_put() is called */ void pa_source_set_latency_range_within_thread(pa_source *s, pa_usec_t min_latency, pa_usec_t max_latency) { - pa_source_output *o; void *state = NULL; pa_source_assert_ref(s); @@ -1209,13 +1209,18 @@ void pa_source_set_latency_range_within_thread(pa_source *s, pa_usec_t min_laten s->thread_info.min_latency = min_latency; s->thread_info.max_latency = max_latency; - while ((o = pa_hashmap_iterate(s->thread_info.outputs, &state, NULL))) - if (o->update_source_latency_range) - o->update_source_latency_range(o); + if (PA_SOURCE_IS_LINKED(s->thread_info.state)) { + pa_source_output *o; + + while ((o = pa_hashmap_iterate(s->thread_info.outputs, &state, NULL))) + if (o->update_source_latency_range) + o->update_source_latency_range(o); + } pa_source_invalidate_requested_latency(s); } +/* Called from main thread */ size_t pa_source_get_max_rewind(pa_source *s) { size_t r; pa_source_assert_ref(s); -- cgit