client: implement $PULSE_LATENCY_MSEC

This allows easy overriding of a clients latency setting for debugging
purposes.

http://pulseaudio.org/ticket/753
This commit is contained in:
Lennart Poettering 2010-01-15 01:25:42 +01:00 committed by Colin Guthrie
parent fb55798a3e
commit d090995262

View file

@ -39,6 +39,7 @@
#include <pulsecore/hashmap.h>
#include <pulsecore/macro.h>
#include <pulsecore/core-rtclock.h>
#include <pulsecore/core-util.h>
#include "fork-detect.h"
#include "internal.h"
@ -855,10 +856,28 @@ static void create_stream_complete(pa_stream *s) {
check_smoother_status(s, TRUE, FALSE, FALSE);
}
static void automatic_buffer_attr(pa_stream *s, pa_buffer_attr *attr, const pa_sample_spec *ss) {
static void patch_buffer_attr(pa_stream *s, pa_buffer_attr *attr, pa_stream_flags_t *flags) {
const char *e;
pa_assert(s);
pa_assert(attr);
pa_assert(ss);
if ((e = getenv("PULSE_LATENCY_MSEC"))) {
uint32_t ms;
if (pa_atou(e, &ms) < 0 || ms <= 0)
pa_log_debug("Failed to parse $PULSE_LATENCY_MSEC: %s", e);
else {
attr->maxlength = (uint32_t) -1;
attr->tlength = pa_usec_to_bytes(ms * PA_USEC_PER_MSEC, &s->sample_spec);
attr->minreq = (uint32_t) -1;
attr->prebuf = (uint32_t) -1;
attr->fragsize = attr->tlength;
}
if (flags)
*flags |= PA_STREAM_ADJUST_LATENCY;
}
if (s->context->version >= 13)
return;
@ -873,7 +892,7 @@ static void automatic_buffer_attr(pa_stream *s, pa_buffer_attr *attr, const pa_s
attr->maxlength = 4*1024*1024; /* 4MB is the maximum queue length PulseAudio <= 0.9.9 supported. */
if (attr->tlength == (uint32_t) -1)
attr->tlength = (uint32_t) pa_usec_to_bytes(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */
attr->tlength = (uint32_t) pa_usec_to_bytes(250*PA_USEC_PER_MSEC, &s->sample_spec); /* 250ms of buffering */
if (attr->minreq == (uint32_t) -1)
attr->minreq = (attr->tlength)/5; /* Ask for more data when there are only 200ms left in the playback buffer */
@ -1065,15 +1084,16 @@ static int create_stream(
pa_stream_ref(s);
s->direction = direction;
s->flags = flags;
s->corked = !!(flags & PA_STREAM_START_CORKED);
if (sync_stream)
s->syncid = sync_stream->syncid;
if (attr)
s->buffer_attr = *attr;
automatic_buffer_attr(s, &s->buffer_attr, &s->sample_spec);
patch_buffer_attr(s, &s->buffer_attr, &flags);
s->flags = flags;
s->corked = !!(flags & PA_STREAM_START_CORKED);
if (flags & PA_STREAM_INTERPOLATE_TIMING) {
pa_usec_t x;
@ -2420,6 +2440,7 @@ pa_operation* pa_stream_set_buffer_attr(pa_stream *s, const pa_buffer_attr *attr
pa_operation *o;
pa_tagstruct *t;
uint32_t tag;
pa_buffer_attr copy;
pa_assert(s);
pa_assert(PA_REFCNT_VALUE(s) >= 1);
@ -2443,6 +2464,10 @@ pa_operation* pa_stream_set_buffer_attr(pa_stream *s, const pa_buffer_attr *attr
&tag);
pa_tagstruct_putu32(t, s->channel);
copy = *attr;
patch_buffer_attr(s, &copy, NULL);
attr = &copy;
pa_tagstruct_putu32(t, attr->maxlength);
if (s->direction == PA_STREAM_PLAYBACK)