]> code.delx.au - pulseaudio/commitdiff
core: Fix some FIXMEs for the extended API
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Wed, 2 Mar 2011 07:24:02 +0000 (12:54 +0530)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Mon, 2 May 2011 06:25:35 +0000 (11:55 +0530)
This adds some checks that I'd postponed and adds a
"should-be-good-enough" guess for tlength when using a compressed
format.

src/pulse/stream.c
src/pulsecore/protocol-native.c

index f5bf42c95d1feb4008f308bc19a4495ae15d1e1d..10e431cd7a4744b3ddb1d66317b5ac9356069e77 100644 (file)
@@ -151,8 +151,16 @@ static pa_stream *pa_stream_new_with_proplist_internal(
     s->buffer_attr.maxlength = (uint32_t) -1;
     if (ss)
         s->buffer_attr.tlength = (uint32_t) pa_usec_to_bytes(250*PA_USEC_PER_MSEC, ss); /* 250ms of buffering */
-    else
-        /* XXX: How do we apply worst case conversion here? */
+    else {
+        /* FIXME: We assume a worst-case compressed format corresponding to
+         * 48000 Hz, 2 ch, S16 PCM, but this can very well be incorrect */
+        pa_sample_spec tmp_ss = {
+            .format   = PA_SAMPLE_S16NE,
+            .rate     = 48000,
+            .channels = 2,
+        };
+        s->buffer_attr.tlength = (uint32_t) pa_usec_to_bytes(250*PA_USEC_PER_MSEC, &tmp_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;
@@ -224,8 +232,6 @@ pa_stream *pa_stream_new_extended(
 
     PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 21, PA_ERR_NOTSUPPORTED);
 
-    /* XXX: For the single-format PCM case, pass ss/map instead of formats */
-
     return pa_stream_new_with_proplist_internal(c, name, NULL, NULL, formats, p);
 }
 
@@ -1029,7 +1035,6 @@ void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag,
                 (!(s->flags & PA_STREAM_FIX_FORMAT) && ss.format != s->sample_spec.format) ||
                 (!(s->flags & PA_STREAM_FIX_RATE) && ss.rate != s->sample_spec.rate) ||
                 (!(s->flags & PA_STREAM_FIX_CHANNELS) && !pa_channel_map_equal(&cm, &s->channel_map))))) {
-            /* XXX: checks for the n_formats > 0 case? */
             pa_context_fail(s->context, PA_ERR_PROTOCOL);
             goto finish;
         }
@@ -1062,8 +1067,14 @@ void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag,
 
         if (pa_format_info_valid(f))
             s->format = f;
-        else
+        else {
             pa_format_info_free(f);
+            if (s->n_formats > 0) {
+                /* We used the extended API, so we should have got back a proper format */
+                pa_context_fail(s->context, PA_ERR_PROTOCOL);
+                goto finish;
+            }
+        }
     }
 
     if (!pa_tagstruct_eof(t)) {
index ee2bc4f506576ffe2e4b24b63950a2be8ae3cd91..956670befb6ff3434f0744559ddc4c76210e2f99 100644 (file)
@@ -2008,10 +2008,15 @@ static void command_create_playback_stream(pa_pdispatch *pd, uint32_t command, u
         }
     }
 
-    CHECK_VALIDITY(c->pstream, n_formats > 0 || pa_sample_spec_valid(&ss), tag, PA_ERR_INVALID);
-    CHECK_VALIDITY(c->pstream, n_formats > 0 || (map.channels == ss.channels && volume.channels == ss.channels), tag, PA_ERR_INVALID);
-    CHECK_VALIDITY(c->pstream, n_formats > 0 || pa_channel_map_valid(&map), tag, PA_ERR_INVALID);
-    /* XXX: add checks on formats. At least inverse checks of the 3 above */
+    if (n_formats == 0) {
+        CHECK_VALIDITY(c->pstream, pa_sample_spec_valid(&ss), tag, PA_ERR_INVALID);
+        CHECK_VALIDITY(c->pstream, map.channels == ss.channels && volume.channels == ss.channels, tag, PA_ERR_INVALID);
+        CHECK_VALIDITY(c->pstream, pa_channel_map_valid(&map), tag, PA_ERR_INVALID);
+    } else {
+        PA_IDXSET_FOREACH(format, formats, i) {
+            CHECK_VALIDITY(c->pstream, pa_format_info_valid(format), tag, PA_ERR_INVALID);
+        }
+    }
 
     if (!pa_tagstruct_eof(t)) {
         protocol_error(c);