From e11770b64ffbe0a5e5d172244c175fa0bc4034db Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 2 Mar 2011 12:54:02 +0530 Subject: core: Fix some FIXMEs for the extended API 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 | 23 +++++++++++++++++------ src/pulsecore/protocol-native.c | 13 +++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/pulse/stream.c b/src/pulse/stream.c index f5bf42c9..10e431cd 100644 --- a/src/pulse/stream.c +++ b/src/pulse/stream.c @@ -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)) { diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index ee2bc4f5..956670be 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -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); -- cgit