From 2970c11902b46414d9ff28db1e850d94b137157c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 31 Aug 2009 21:40:59 +0200 Subject: core: always allow volume setting with single-channel pa_cvolume --- src/pulsecore/sink.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/pulsecore/sink.c') diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index 48c50b0b..f5a6fc50 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -1408,8 +1408,11 @@ void pa_sink_set_volume( pa_assert_ctl_context(); pa_assert(PA_SINK_IS_LINKED(s->state)); pa_assert(!volume || pa_cvolume_valid(volume)); - pa_assert(!volume || pa_cvolume_compatible(volume, &s->sample_spec)); pa_assert(volume || (s->flags & PA_SINK_FLAT_VOLUME)); + pa_assert(!volume || volume->channels == 1 || pa_cvolume_compatible(volume, &s->sample_spec)); + + /* As a special exception we accept mono volumes on all sinks -- + * even on those with more complex channel maps */ /* If volume is NULL we synchronize the sink's real and reference * volumes with the stream volumes. If it is not NULL we update @@ -1419,7 +1422,10 @@ void pa_sink_set_volume( if (volume) { - s->reference_volume = *volume; + if (pa_cvolume_compatible(volume, &s->sample_spec)) + s->reference_volume = *volume; + else + pa_cvolume_scale(&s->reference_volume, pa_cvolume_max(volume)); if (s->flags & PA_SINK_FLAT_VOLUME) { /* OK, propagate this volume change back to the inputs */ -- cgit From ce6dff4ee0a3fe6e0339eb1f5d605caf8af3f989 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 1 Sep 2009 22:18:01 +0200 Subject: core: add missing sink_unref() --- src/pulsecore/sink.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/pulsecore/sink.c') diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index f5a6fc50..2362db8d 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -893,6 +893,8 @@ void pa_sink_render(pa_sink*s, size_t length, pa_memchunk *result) { result->memblock = pa_memblock_ref(s->silence.memblock); result->index = s->silence.index; result->length = PA_MIN(s->silence.length, length); + + pa_sink_unref(s); return; } @@ -980,6 +982,7 @@ void pa_sink_render_into(pa_sink*s, pa_memchunk *target) { if (s->thread_info.state == PA_SINK_SUSPENDED) { pa_silence_memchunk(target, &s->sample_spec); + pa_sink_unref(s); return; } -- cgit From 17f609ac830a4a6be9658c7220292a038b2c59ac Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 1 Sep 2009 22:18:55 +0200 Subject: core: handle suspended state in pa_sink_render_full() similar to the other render functions --- src/pulsecore/sink.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/pulsecore/sink.c') diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index 2362db8d..e1ab96db 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -1099,7 +1099,16 @@ void pa_sink_render_full(pa_sink *s, size_t length, pa_memchunk *result) { pa_assert(!s->thread_info.rewind_requested); pa_assert(s->thread_info.rewind_nbytes == 0); - pa_assert(length > 0); + if (s->thread_info.state == PA_SINK_SUSPENDED) { + pa_silence_memchunk_get(&s->core->silence_cache, + s->core->mempool, + result, + &s->sample_spec, + length1st); + + pa_sink_unref(s); + return; + } n = fill_mix_info(s, &length1st, info, MAX_MIX_CHANNELS); -- cgit From 45513a2077719850353a9eb34f32ac4548c0dbea Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 1 Sep 2009 22:19:30 +0200 Subject: core: fill up memblock with pa_sink_render_into_full() in pa_sink_render_full() instead of doing our own loop --- src/pulsecore/sink.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/pulsecore/sink.c') diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index e1ab96db..9388d309 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -1163,21 +1163,15 @@ void pa_sink_render_full(pa_sink *s, size_t length, pa_memchunk *result) { if (result->length < length) { pa_memchunk chunk; - size_t l, d; + pa_memchunk_make_writable(result, length); - l = length - result->length; - d = result->index + result->length; - while (l > 0) { - chunk = *result; - chunk.index = d; - chunk.length = l; + chunk.memblock = result->memblock; + chunk.index = result->index + result->length; + chunk.length = length - result->length; - pa_sink_render_into(s, &chunk); + pa_sink_render_into_full(s, &chunk); - d += chunk.length; - l -= chunk.length; - } result->length = length; } -- cgit From 1200a0b143c370c1a9351add5f72ecabfd8630cf Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 2 Sep 2009 00:54:22 +0200 Subject: sink: simplify pa_sink_render_full() by replacing it by a pa_sink_render() plus a couple of pa_sink_render_full() --- src/pulsecore/sink.c | 90 ++++++++-------------------------------------------- 1 file changed, 14 insertions(+), 76 deletions(-) (limited to 'src/pulsecore/sink.c') diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index 9388d309..b4ecdfcc 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -790,7 +790,7 @@ static void inputs_drop(pa_sink *s, pa_mix_info *info, unsigned n, pa_memchunk * /* We optimize for the case where the order of the inputs has not changed */ - while ((i = pa_hashmap_iterate(s->thread_info.inputs, &state, NULL))) { + PA_HASHMAP_FOREACH(i, s->thread_info.inputs, state) { unsigned j; pa_mix_info* m = NULL; @@ -884,8 +884,6 @@ void pa_sink_render(pa_sink*s, size_t length, pa_memchunk *result) { pa_assert(pa_frame_aligned(length, &s->sample_spec)); pa_assert(result); - pa_sink_ref(s); - pa_assert(!s->thread_info.rewind_requested); pa_assert(s->thread_info.rewind_nbytes == 0); @@ -893,11 +891,11 @@ void pa_sink_render(pa_sink*s, size_t length, pa_memchunk *result) { result->memblock = pa_memblock_ref(s->silence.memblock); result->index = s->silence.index; result->length = PA_MIN(s->silence.length, length); - - pa_sink_unref(s); return; } + pa_sink_ref(s); + if (length <= 0) length = pa_frame_align(MIX_BUFFER_LENGTH, &s->sample_spec); @@ -975,17 +973,16 @@ void pa_sink_render_into(pa_sink*s, pa_memchunk *target) { pa_assert(target->length > 0); pa_assert(pa_frame_aligned(target->length, &s->sample_spec)); - pa_sink_ref(s); - pa_assert(!s->thread_info.rewind_requested); pa_assert(s->thread_info.rewind_nbytes == 0); if (s->thread_info.state == PA_SINK_SUSPENDED) { pa_silence_memchunk(target, &s->sample_spec); - pa_sink_unref(s); return; } + pa_sink_ref(s); + length = target->length; block_size_max = pa_mempool_block_size_max(s->core->mempool); if (length > block_size_max) @@ -1060,11 +1057,16 @@ void pa_sink_render_into_full(pa_sink *s, pa_memchunk *target) { pa_assert(target->length > 0); pa_assert(pa_frame_aligned(target->length, &s->sample_spec)); - pa_sink_ref(s); - pa_assert(!s->thread_info.rewind_requested); pa_assert(s->thread_info.rewind_nbytes == 0); + if (s->thread_info.state == PA_SINK_SUSPENDED) { + pa_silence_memchunk(target, &s->sample_spec); + return; + } + + pa_sink_ref(s); + l = target->length; d = 0; while (l > 0) { @@ -1083,10 +1085,6 @@ void pa_sink_render_into_full(pa_sink *s, pa_memchunk *target) { /* Called from IO thread context */ void pa_sink_render_full(pa_sink *s, size_t length, pa_memchunk *result) { - pa_mix_info info[MAX_MIX_CHANNELS]; - size_t length1st = length; - unsigned n; - pa_sink_assert_ref(s); pa_sink_assert_io_context(s); pa_assert(PA_SINK_IS_LINKED(s->thread_info.state)); @@ -1094,72 +1092,12 @@ void pa_sink_render_full(pa_sink *s, size_t length, pa_memchunk *result) { pa_assert(pa_frame_aligned(length, &s->sample_spec)); pa_assert(result); - pa_sink_ref(s); - pa_assert(!s->thread_info.rewind_requested); pa_assert(s->thread_info.rewind_nbytes == 0); - if (s->thread_info.state == PA_SINK_SUSPENDED) { - pa_silence_memchunk_get(&s->core->silence_cache, - s->core->mempool, - result, - &s->sample_spec, - length1st); - - pa_sink_unref(s); - return; - } - - n = fill_mix_info(s, &length1st, info, MAX_MIX_CHANNELS); - - if (n == 0) { - pa_silence_memchunk_get(&s->core->silence_cache, - s->core->mempool, - result, - &s->sample_spec, - length1st); - } else if (n == 1) { - pa_cvolume volume; - - *result = info[0].chunk; - pa_memblock_ref(result->memblock); - - if (result->length > length) - result->length = length; - - pa_sw_cvolume_multiply(&volume, &s->thread_info.soft_volume, &info[0].volume); - - if (s->thread_info.soft_muted || !pa_cvolume_is_norm(&volume)) { - if (s->thread_info.soft_muted || pa_cvolume_is_muted(&volume)) { - pa_memblock_unref(result->memblock); - pa_silence_memchunk_get(&s->core->silence_cache, - s->core->mempool, - result, - &s->sample_spec, - result->length); - } else { - pa_memchunk_make_writable(result, length); - pa_volume_memchunk(result, &s->sample_spec, &volume); - } - } - } else { - void *ptr; - - result->index = 0; - result->memblock = pa_memblock_new(s->core->mempool, length); - - ptr = pa_memblock_acquire(result->memblock); - - result->length = pa_mix(info, n, - (uint8_t*) ptr + result->index, length1st, - &s->sample_spec, - &s->thread_info.soft_volume, - s->thread_info.soft_muted); - - pa_memblock_release(result->memblock); - } + pa_sink_ref(s); - inputs_drop(s, info, n, result); + pa_sink_render(s, length, result); if (result->length < length) { pa_memchunk chunk; -- cgit From 14a97716891706d2f4984b0d1da10b354b3042db Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 3 Sep 2009 00:21:19 +0200 Subject: core: drop unnecessary variable initialization --- src/pulsecore/sink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pulsecore/sink.c') diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index b4ecdfcc..bda92fcc 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -778,7 +778,7 @@ static unsigned fill_mix_info(pa_sink *s, size_t *length, pa_mix_info *info, uns /* Called from IO thread context */ static void inputs_drop(pa_sink *s, pa_mix_info *info, unsigned n, pa_memchunk *result) { pa_sink_input *i; - void *state = NULL; + void *state; unsigned p = 0; unsigned n_unreffed = 0; -- cgit