use (uint32_t) -1 to signify default buffer_attr values instead of 0, to allow prebuf=0
authorLennart Poettering <lennart@poettering.net>
Thu, 26 Jun 2008 22:34:17 +0000 (00:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 26 Jun 2008 22:34:17 +0000 (00:34 +0200)
src/pulse/stream.c
src/pulsecore/protocol-native.c
src/tests/sync-playback.c
src/utils/pacat.c

index 89838c5..585518f 100644 (file)
@@ -122,7 +122,12 @@ pa_stream *pa_stream_new_with_proplist(
     /* We initialize der target length here, so that if the user
      * passes no explicit buffering metrics the default is similar to
      * what older PA versions provided. */
+
+    s->buffer_attr.maxlength = (uint32_t) -1;
     s->buffer_attr.tlength = pa_usec_to_bytes(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */
+    s->buffer_attr.minreq = (uint32_t) -1;
+    s->buffer_attr.prebuf = (uint32_t) -1;
+    s->buffer_attr.fragsize = (uint32_t) -1;
 
     s->device_index = PA_INVALID_INDEX;
     s->device_name = NULL;
@@ -713,20 +718,20 @@ static void automatic_buffer_attr(pa_stream *s, pa_buffer_attr *attr, const pa_s
     /* We choose fairly conservative values here, to not confuse
      * old clients with extremely large playback buffers */
 
-    if (!attr->maxlength <= 0)
+    if (attr->maxlength == (uint32_t) -1)
         attr->maxlength = 4*1024*1024; /* 4MB is the maximum queue length PulseAudio <= 0.9.9 supported. */
 
-    if (!attr->tlength <= 0)
+    if (attr->tlength == (uint32_t) -1)
         attr->tlength = pa_usec_to_bytes(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */
 
-    if (!attr->minreq <= 0)
+    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 */
 
-    if (!attr->prebuf)
+    if (attr->prebuf == (uint32_t) -1)
         attr->prebuf = attr->tlength; /* Start to play only when the playback is fully filled up once */
 
-    if (!attr->fragsize)
-        attr->fragsize  = attr->tlength; /* Pass data to the app only when the buffer is filled up once */
+    if (attr->fragsize == (uint32_t) -1)
+        attr->fragsize = attr->tlength; /* Pass data to the app only when the buffer is filled up once */
 }
 
 void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, PA_GCC_UNUSED uint32_t tag, pa_tagstruct *t, void *userdata) {
index 862b062..2974dc0 100644 (file)
@@ -474,11 +474,15 @@ static void fix_record_buffer_attr_pre(record_stream *s, pa_bool_t adjust_latenc
     pa_assert(maxlength);
     pa_assert(fragsize);
 
-    if (*maxlength <= 0 || *maxlength > MAX_MEMBLOCKQ_LENGTH)
+    if (*maxlength == (uint32_t) -1 || *maxlength > MAX_MEMBLOCKQ_LENGTH)
         *maxlength = MAX_MEMBLOCKQ_LENGTH;
+    if (*maxlength <= 0)
+        *maxlength = pa_frame_size(&s->source_output->sample_spec);
 
-    if (*fragsize <= 0)
+    if (*fragsize == (uint32_t) -1)
         *fragsize = pa_usec_to_bytes(DEFAULT_FRAGSIZE_MSEC*PA_USEC_PER_MSEC, &s->source_output->sample_spec);
+    if (*fragsize <= 0)
+        *fragsize = pa_frame_size(&s->source_output->sample_spec);
 
     if (adjust_latency) {
         pa_usec_t fragsize_usec;
@@ -729,16 +733,23 @@ static void fix_playback_buffer_attr_pre(playback_stream *s, pa_bool_t adjust_la
     pa_assert(prebuf);
     pa_assert(minreq);
 
-    if (*maxlength <= 0 || *maxlength > MAX_MEMBLOCKQ_LENGTH)
+    frame_size = pa_frame_size(&s->sink_input->sample_spec);
+
+    if (*maxlength == (uint32_t) -1 || *maxlength > MAX_MEMBLOCKQ_LENGTH)
         *maxlength = MAX_MEMBLOCKQ_LENGTH;
-    if (*tlength <= 0)
+    if (*maxlength <= 0)
+        *maxlength = frame_size;
+
+    if (*tlength == (uint32_t) -1)
         *tlength = pa_usec_to_bytes(DEFAULT_TLENGTH_MSEC*PA_USEC_PER_MSEC, &s->sink_input->sample_spec);
-    if (*minreq <= 0)
-        *minreq = pa_usec_to_bytes(DEFAULT_PROCESS_MSEC*PA_USEC_PER_MSEC, &s->sink_input->sample_spec);
+    if (*tlength <= 0)
+        *tlength = frame_size;
 
-    frame_size = pa_frame_size(&s->sink_input->sample_spec);
+    if (*minreq == (uint32_t) -1)
+        *minreq = pa_usec_to_bytes(DEFAULT_PROCESS_MSEC*PA_USEC_PER_MSEC, &s->sink_input->sample_spec);
     if (*minreq <= 0)
         *minreq = frame_size;
+
     if (*tlength < *minreq+frame_size)
         *tlength = *minreq+frame_size;
 
@@ -810,7 +821,7 @@ static void fix_playback_buffer_attr_pre(playback_stream *s, pa_bool_t adjust_la
     if (*tlength <= *minreq)
         *tlength =  *minreq*2 + frame_size;
 
-    if (*prebuf <= 0 || *prebuf > *tlength)
+    if (*prebuf == (uint32_t) -1 || *prebuf > *tlength)
         *prebuf = *tlength;
 }
 
index 7ab3a25..7e36468 100644 (file)
@@ -54,9 +54,10 @@ static const pa_sample_spec sample_spec = {
 
 static const pa_buffer_attr buffer_attr = {
     .maxlength = SAMPLE_HZ*sizeof(float)*NSTREAMS, /* exactly space for the entire play time */
-    .tlength = 0,
+    .tlength = (uint32_t) -1,
     .prebuf = 0, /* Setting prebuf to 0 guarantees us the the streams will run synchronously, no matter what */
-    .minreq = 0
+    .minreq = (uint32_t) -1,
+    .fragsize = 0
 };
 
 static void nop_free_cb(void *p) {}
index ee784a9..78b9cef 100644 (file)
@@ -278,6 +278,8 @@ static void context_state_callback(pa_context *c, void *userdata) {
                 memset(&buffer_attr, 0, sizeof(buffer_attr));
                 buffer_attr.tlength = latency;
                 buffer_attr.minreq = process_time;
+                buffer_attr.maxlength = (uint32_t) -1;
+                buffer_attr.prebuf = (uint32_t) -1;
                 flags |= PA_STREAM_ADJUST_LATENCY;
             }