simplify latency config functions a bit and make them callable in more contexts

This commit is contained in:
Lennart Poettering 2009-03-30 18:23:48 +02:00
parent d04f3e1aef
commit 7f5481ede0
2 changed files with 50 additions and 60 deletions

View file

@ -818,27 +818,13 @@ void pa_sink_input_update_max_request(pa_sink_input *i, size_t nbytes /* in the
i->update_max_request(i, i->thread_info.resampler ? pa_resampler_request(i->thread_info.resampler, nbytes) : nbytes);
}
/* Called from thread context */
static pa_usec_t fixup_latency(pa_sink *s, pa_usec_t usec) {
pa_sink_assert_ref(s);
if (usec == (pa_usec_t) -1)
return usec;
if (s->thread_info.max_latency > 0 && usec > s->thread_info.max_latency)
usec = s->thread_info.max_latency;
if (s->thread_info.min_latency > 0 && usec < s->thread_info.min_latency)
usec = s->thread_info.min_latency;
return usec;
}
/* Called from thread context */
pa_usec_t pa_sink_input_set_requested_latency_within_thread(pa_sink_input *i, pa_usec_t usec) {
pa_sink_input_assert_ref(i);
usec = fixup_latency(i->sink, usec);
if (usec != (pa_usec_t) -1)
usec = PA_CLAMP(usec, i->sink->thread_info.min_latency, i->sink->thread_info.max_latency);
i->thread_info.requested_sink_latency = usec;
pa_sink_invalidate_requested_latency(i->sink);
@ -847,13 +833,22 @@ pa_usec_t pa_sink_input_set_requested_latency_within_thread(pa_sink_input *i, pa
/* Called from main context */
pa_usec_t pa_sink_input_set_requested_latency(pa_sink_input *i, pa_usec_t usec) {
pa_usec_t min_latency, max_latency;
pa_sink_input_assert_ref(i);
if (PA_SINK_INPUT_IS_LINKED(i->state))
if (PA_SINK_INPUT_IS_LINKED(i->state) && i->sink) {
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_REQUESTED_LATENCY, &usec, 0, NULL) == 0);
else
/* If this sink input is not realized yet, we have to touch
* the thread info data directly */
return usec;
}
/* If this sink input is not realized yet or we are being moved,
* we have to touch the thread info data directly */
pa_sink_get_latency_range(i->sink, &min_latency, &max_latency);
if (usec != (pa_usec_t) -1)
usec = PA_CLAMP(usec, min_latency, max_latency);
i->thread_info.requested_sink_latency = usec;
@ -862,20 +857,20 @@ pa_usec_t pa_sink_input_set_requested_latency(pa_sink_input *i, pa_usec_t usec)
/* Called from main context */
pa_usec_t pa_sink_input_get_requested_latency(pa_sink_input *i) {
pa_usec_t usec = 0;
pa_sink_input_assert_ref(i);
if (PA_SINK_INPUT_IS_LINKED(i->state))
if (PA_SINK_INPUT_IS_LINKED(i->state) && i->sink) {
pa_usec_t usec = 0;
pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_GET_REQUESTED_LATENCY, &usec, 0, NULL) == 0);
else
/* If this sink input is not realized yet, we have to touch
* the thread info data directly */
usec = i->thread_info.requested_sink_latency;
return usec;
}
/* If this sink input is not realized yet or we are being moved,
* we have to touch the thread info data directly */
return i->thread_info.requested_sink_latency;
}
/* Called from main context */
void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save) {
pa_sink_input_assert_ref(i);

View file

@ -515,27 +515,13 @@ void pa_source_output_update_max_rewind(pa_source_output *o, size_t nbytes /* i
o->update_max_rewind(o, o->thread_info.resampler ? pa_resampler_result(o->thread_info.resampler, nbytes) : nbytes);
}
/* Called from thread context */
static pa_usec_t fixup_latency(pa_source *s, pa_usec_t usec) {
pa_source_assert_ref(s);
if (usec == (pa_usec_t) -1)
return usec;
if (s->thread_info.max_latency > 0 && usec > s->thread_info.max_latency)
usec = s->thread_info.max_latency;
if (s->thread_info.min_latency > 0 && usec < s->thread_info.min_latency)
usec = s->thread_info.min_latency;
return usec;
}
/* Called from thread context */
pa_usec_t pa_source_output_set_requested_latency_within_thread(pa_source_output *o, pa_usec_t usec) {
pa_source_output_assert_ref(o);
usec = fixup_latency(o->source, usec);
if (usec != (pa_usec_t) -1)
usec = PA_CLAMP(usec, o->source->thread_info.min_latency, o->source->thread_info.max_latency);
o->thread_info.requested_source_latency = usec;
pa_source_invalidate_requested_latency(o->source);
@ -544,13 +530,22 @@ pa_usec_t pa_source_output_set_requested_latency_within_thread(pa_source_output
/* Called from main context */
pa_usec_t pa_source_output_set_requested_latency(pa_source_output *o, pa_usec_t usec) {
pa_usec_t min_latency, max_latency;
pa_source_output_assert_ref(o);
if (PA_SOURCE_OUTPUT_IS_LINKED(o->state))
if (PA_SOURCE_OUTPUT_IS_LINKED(o->state) && o->source) {
pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o), PA_SOURCE_OUTPUT_MESSAGE_SET_REQUESTED_LATENCY, &usec, 0, NULL) == 0);
else
/* If this source output is not realized yet, we have to touch
* the thread info data directly */
return usec;
}
/* If this source output is not realized yet or is being moved, we
* have to touch the thread info data directly */
pa_source_get_latency_range(o->source, &min_latency, &max_latency);
if (usec != (pa_usec_t) -1)
usec = PA_CLAMP(usec, min_latency, max_latency);
o->thread_info.requested_source_latency = usec;
@ -559,20 +554,20 @@ pa_usec_t pa_source_output_set_requested_latency(pa_source_output *o, pa_usec_t
/* Called from main context */
pa_usec_t pa_source_output_get_requested_latency(pa_source_output *o) {
pa_usec_t usec = 0;
pa_source_output_assert_ref(o);
if (PA_SOURCE_OUTPUT_IS_LINKED(o->state))
if (PA_SOURCE_OUTPUT_IS_LINKED(o->state) && o->source) {
pa_usec_t usec = 0;
pa_assert_se(pa_asyncmsgq_send(o->source->asyncmsgq, PA_MSGOBJECT(o), PA_SOURCE_OUTPUT_MESSAGE_GET_REQUESTED_LATENCY, &usec, 0, NULL) == 0);
else
/* If this source output is not realized yet, we have to touch
* the thread info data directly */
usec = o->thread_info.requested_source_latency;
return usec;
}
/* If this source output is not realized yet or is being moved, we
* have to touch the thread info data directly */
return o->thread_info.requested_source_latency;
}
/* Called from main context */
void pa_source_output_cork(pa_source_output *o, pa_bool_t b) {
pa_source_output_assert_ref(o);