summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-01-15 01:25:42 +0100
committerColin Guthrie <cguthrie@mandriva.org>2010-02-09 22:44:49 +0000
commitd09099526220fb87ac8c4f6bae298b23744d0dae (patch)
treeebdcbb06ba68f36310bb579b2535d66188715386 /src
parentfb55798a3eb73b4c00225232408b766f74533409 (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.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/pulse/stream.c b/src/pulse/stream.c
index a4f34d9a..5e42ab28 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 */
@@ -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)