diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-01-15 01:25:42 +0100 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2014-04-02 14:35:53 +0200 |
commit | 6d896ee68d9752b21b5a058613e9169ab797fc22 (patch) | |
tree | 9ae89881197824c32dafe01cb45bf46fdda823c3 /src | |
parent | b5f7c4b37fa499e2f88bb430a8520cf0cad61063 (diff) |
client: implement $PULSE_LATENCY_MSEC
This allows easy overriding of a clients latency setting for debugging
purposes.
http://pulseaudio.org/ticket/753
Diffstat (limited to 'src')
-rw-r--r-- | src/pulse/stream.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/pulse/stream.c b/src/pulse/stream.c index 79b286824..daeb53a1b 100644 --- a/src/pulse/stream.c +++ b/src/pulse/stream.c @@ -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 */ @@ -1064,15 +1083,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; @@ -2412,6 +2432,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); @@ -2435,6 +2456,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, ©, NULL); + attr = © + pa_tagstruct_putu32(t, attr->maxlength); if (s->direction == PA_STREAM_PLAYBACK) |