[pulseaudio-commits] 6 commits - man/pulse-daemon.conf.5.xml.in src/modules src/pulsecore
Arun Raghavan
arun at kemper.freedesktop.org
Fri May 11 05:56:46 PDT 2012
man/pulse-daemon.conf.5.xml.in | 2
src/modules/alsa/alsa-mixer.c | 1
src/modules/alsa/mixer/profile-sets/default.conf | 11
src/modules/alsa/module-alsa-card.c | 4
src/modules/bluetooth/bluetooth-util.c | 6
src/modules/module-equalizer-sink.c | 2
src/pulsecore/resampler.c | 341 ++++++++++++++---------
7 files changed, 227 insertions(+), 140 deletions(-)
New commits:
commit e54b0fa6c9776dc72d15fbcacaac93942ee4d4bd
Author: Paul Menzel <paulepanter at users.sourceforge.net>
Date: Tue Apr 24 23:31:32 2012 +0200
Correct spelling of PulseAudio
⢠s,Pulseaudio,PulseAudio,
⢠One last occurence of this âerrorâ is in the French translation.
diff --git a/man/pulse-daemon.conf.5.xml.in b/man/pulse-daemon.conf.5.xml.in
index 5f64750..79f970e 100644
--- a/man/pulse-daemon.conf.5.xml.in
+++ b/man/pulse-daemon.conf.5.xml.in
@@ -153,7 +153,7 @@ USA.
<p><opt>local-server-type=</opt> Please don't use this option if
you don't have to! This option is currently only useful when you
want D-Bus clients to use a remote server. This option may be
- removed in future versions. If you only want to run Pulseaudio
+ removed in future versions. If you only want to run PulseAudio
in the system mode, use the <opt>system-instance</opt> option.
This option takes one of <opt>user</opt>, <opt>system</opt> or
<opt>none</opt> as the argument. This is essentially a duplicate
diff --git a/src/modules/alsa/mixer/profile-sets/default.conf b/src/modules/alsa/mixer/profile-sets/default.conf
index 28c8650..31d58cf 100644
--- a/src/modules/alsa/mixer/profile-sets/default.conf
+++ b/src/modules/alsa/mixer/profile-sets/default.conf
@@ -72,7 +72,7 @@
; # section title is the name of the volume element.
; #
; # NOTE: This feature is meant just as a help for figuring out the correct
-; # decibel values. Pulseaudio is not the correct place to maintain the
+; # decibel values. PulseAudio is not the correct place to maintain the
; # decibel mappings!
; #
; # If you need this feature, then you should make sure that when you have
diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c
index 3493465..b06394d 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -540,10 +540,10 @@ int pa__init(pa_module *m) {
if (!pa_hashmap_isempty(u->profile_set->decibel_fixes))
pa_log_warn("Card %s uses decibel fixes (i.e. overrides the decibel information for some alsa volume elements). "
"Please note that this feature is meant just as a help for figuring out the correct decibel values. "
- "Pulseaudio is not the correct place to maintain the decibel mappings! The fixed decibel values "
+ "PulseAudio is not the correct place to maintain the decibel mappings! The fixed decibel values "
"should be sent to ALSA developers so that they can fix the driver. If it turns out that this feature "
"is abused (i.e. fixes are not pushed to ALSA), the decibel fix feature may be removed in some future "
- "Pulseaudio version.", u->card->name);
+ "PulseAudio version.", u->card->name);
return 0;
diff --git a/src/modules/module-equalizer-sink.c b/src/modules/module-equalizer-sink.c
index e07452c..adaef69 100644
--- a/src/modules/module-equalizer-sink.c
+++ b/src/modules/module-equalizer-sink.c
@@ -3,7 +3,7 @@
This module is based off Lennart Poettering's LADSPA sink and swaps out
LADSPA functionality for a dbus-aware STFT OLA based digital equalizer.
- All new work is published under Pulseaudio's original license.
+ All new work is published under PulseAudio's original license.
Copyright 2009 Jason Newton <nevion at gmail.com>
commit ec316b04acb9b3f0a79f7e5d322674f3fa241338
Author: Arun Raghavan <arun.raghavan at collabora.co.uk>
Date: Fri May 11 17:32:20 2012 +0530
bluetooth: Fix crash due to usage of pa_bool_t instead of dbus_bool_t
pa_bool_t and dbus_bool_t cannot be used interchangably since their size
might (and do) vary. This caused a crash on some systems which was
reported and root caused by: Aidan Thornton <makosoft at googlemail.com>.
Ref: https://bugs.gentoo.org/show_bug.cgi?id=398097
diff --git a/src/modules/bluetooth/bluetooth-util.c b/src/modules/bluetooth/bluetooth-util.c
index 3f39a91..b786502 100644
--- a/src/modules/bluetooth/bluetooth-util.c
+++ b/src/modules/bluetooth/bluetooth-util.c
@@ -753,7 +753,7 @@ int pa_bluetooth_transport_parse_property(pa_bluetooth_transport *t, DBusMessage
case DBUS_TYPE_BOOLEAN: {
- pa_bool_t *value;
+ dbus_bool_t value;
dbus_message_iter_get_basic(&variant_i, &value);
if (pa_streq(key, "NREC"))
@@ -1144,9 +1144,11 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage
goto fail;
dbus_message_iter_get_basic(&value, &dev_path);
} else if (strcasecmp(key, "NREC") == 0) {
+ dbus_bool_t tmp_boolean;
if (var != DBUS_TYPE_BOOLEAN)
goto fail;
- dbus_message_iter_get_basic(&value, &nrec);
+ dbus_message_iter_get_basic(&value, &tmp_boolean);
+ nrec = tmp_boolean;
} else if (strcasecmp(key, "Configuration") == 0) {
DBusMessageIter array;
if (var != DBUS_TYPE_ARRAY)
commit 7bb8442c111d5e1fba20eb101eb854edd5392627
Author: Tanu Kaskinen <tanuk at iki.fi>
Date: Tue May 1 20:09:12 2012 +0300
alsa: Add support for sound cards with 4-channel input.
Changes in v2:
- Call the mapping a generic 4-channel input mapping
instead of a 4-channel mic array mapping. The mapping
will be used also by sound cards that have two stereo
input jacks, so in those cases talking about mic arrays
is wrong.
- Added a comment about using the "hw" device name.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=45813
diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index abb12ee..8b54f75 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -3888,6 +3888,7 @@ static int mapping_verify(pa_alsa_mapping *m, const pa_channel_map *bonus) {
{ "analog-surround-61", N_("Analog Surround 6.1") },
{ "analog-surround-70", N_("Analog Surround 7.0") },
{ "analog-surround-71", N_("Analog Surround 7.1") },
+ { "analog-4-channel-input", N_("Analog 4-channel Input") },
{ "iec958-stereo", N_("Digital Stereo (IEC958)") },
{ "iec958-passthrough", N_("Digital Passthrough (IEC958)") },
{ "iec958-ac3-surround-40", N_("Digital Surround 4.0 (IEC958/AC3)") },
diff --git a/src/modules/alsa/mixer/profile-sets/default.conf b/src/modules/alsa/mixer/profile-sets/default.conf
index 5ac322b..28c8650 100644
--- a/src/modules/alsa/mixer/profile-sets/default.conf
+++ b/src/modules/alsa/mixer/profile-sets/default.conf
@@ -148,6 +148,15 @@ paths-output = analog-output analog-output-speaker analog-output-desktop-speaker
priority = 7
direction = output
+[Mapping analog-4-channel-input]
+# Alsa doesn't currently provide any better device name than "hw" for 4-channel
+# input. If this causes trouble at some point, then we will need to get a new
+# device name standardized in alsa.
+device-strings = hw:%f
+channel-map = aux0,aux1,aux2,aux3
+priority = 1
+direction = input
+
[Mapping iec958-stereo]
device-strings = iec958:%f
channel-map = left,right
commit 1eb7c4a465e804c3fe6e7d34e771d6d870268473
Author: Tanu Kaskinen <tanuk at iki.fi>
Date: Thu May 10 09:19:23 2012 +0300
resampler: Add support for resamplers that consume less data than asked.
libsamplerate_resample() assumed that src_process() would
always consume the whole input buffer. That was an invalid
assumption leading to crashes.
This patch adds a leftover memchunk for storing any
non-consumed input. When pa_resampler_run() is called next
time, the leftover is prepended to the new input.
Changes in v3:
- Make the calculations in pa_resampler_result() and
pa_resampler_max_block_size() more readable and more
correct.
- Rework the leftover storing: instead of using a dedicated
buffer for it, store it in the beginning of remap_buf.
This can avoid some memory copying. (The idea was
suggested by Wang Xingchao.)
- Use a generic save_leftover() function instead of doing
the leftover copying in the resampler implementation.
- Use the leftover logic also with the speex and ffmpeg
resamplers.
[ed: dropped the speex bit since the API guarantees that
it will consume everything -- Arun]
Changes in v2:
- If add_leftover() is called with zero-length input while
the leftover length is non-zero, we don't try to acquire
the input memblock.
- Instead of taking a reference to the original input in
libsamplerate_resample(), we copy the leftover data to a
new memblock. This is done, because otherwise, if the
input is one of the internal buffers, the data can get
overwritten before reading it in add_leftover().
- Store add_leftover_buf size in bytes instead of samples
(more convenient, but less consistent with other code).
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=47156
diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 258d1fe..cd95c5b 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -61,9 +61,10 @@ struct pa_resampler {
pa_memchunk resample_buf;
pa_memchunk from_work_format_buf;
unsigned to_work_format_buf_samples;
- unsigned remap_buf_samples;
+ size_t remap_buf_size;
unsigned resample_buf_samples;
unsigned from_work_format_buf_samples;
+ pa_bool_t remap_buf_contains_leftover_data;
pa_sample_format_t work_format;
@@ -379,23 +380,39 @@ void pa_resampler_set_output_rate(pa_resampler *r, uint32_t rate) {
size_t pa_resampler_request(pa_resampler *r, size_t out_length) {
pa_assert(r);
- /* Let's round up here */
-
+ /* Let's round up here to make it more likely that the caller will get at
+ * least out_length amount of data from pa_resampler_run().
+ *
+ * We don't take the leftover into account here. If we did, then it might
+ * be in theory possible that this function would return 0 and
+ * pa_resampler_run() would also return 0. That could lead to infinite
+ * loops. When the leftover is ignored here, such loops would eventually
+ * terminate, because the leftover would grow each round, finally
+ * surpassing the minimum input threshold of the resampler. */
return (((((out_length + r->o_fz-1) / r->o_fz) * r->i_ss.rate) + r->o_ss.rate-1) / r->o_ss.rate) * r->i_fz;
}
size_t pa_resampler_result(pa_resampler *r, size_t in_length) {
+ size_t frames;
+
pa_assert(r);
- /* Let's round up here */
+ /* Let's round up here to ensure that the caller will always allocate big
+ * enough output buffer. */
+
+ frames = (in_length + r->i_fz - 1) / r->i_fz;
+
+ if (r->remap_buf_contains_leftover_data)
+ frames += r->remap_buf.length / (r->w_sz * r->o_ss.channels);
- return (((((in_length + r->i_fz-1) / r->i_fz) * r->o_ss.rate) + r->i_ss.rate-1) / r->i_ss.rate) * r->o_fz;
+ return ((frames * r->o_ss.rate + r->i_ss.rate - 1) / r->i_ss.rate) * r->o_fz;
}
size_t pa_resampler_max_block_size(pa_resampler *r) {
size_t block_size_max;
- pa_sample_spec ss;
- size_t fs;
+ pa_sample_spec max_ss;
+ size_t max_fs;
+ size_t frames;
pa_assert(r);
@@ -403,17 +420,21 @@ size_t pa_resampler_max_block_size(pa_resampler *r) {
/* We deduce the "largest" sample spec we're using during the
* conversion */
- ss.channels = (uint8_t) (PA_MAX(r->i_ss.channels, r->o_ss.channels));
+ max_ss.channels = (uint8_t) (PA_MAX(r->i_ss.channels, r->o_ss.channels));
/* We silently assume that the format enum is ordered by size */
- ss.format = PA_MAX(r->i_ss.format, r->o_ss.format);
- ss.format = PA_MAX(ss.format, r->work_format);
+ max_ss.format = PA_MAX(r->i_ss.format, r->o_ss.format);
+ max_ss.format = PA_MAX(max_ss.format, r->work_format);
- ss.rate = PA_MAX(r->i_ss.rate, r->o_ss.rate);
+ max_ss.rate = PA_MAX(r->i_ss.rate, r->o_ss.rate);
- fs = pa_frame_size(&ss);
+ max_fs = pa_frame_size(&max_ss);
+ frames = block_size_max / max_fs - EXTRA_FRAMES;
- return (((block_size_max/fs - EXTRA_FRAMES)*r->i_ss.rate)/ss.rate)*r->i_fz;
+ if (r->remap_buf_contains_leftover_data)
+ frames -= r->remap_buf.length / (r->w_sz * r->o_ss.channels);
+
+ return (frames * r->i_ss.rate / max_ss.rate) * r->i_fz;
}
void pa_resampler_reset(pa_resampler *r) {
@@ -421,6 +442,8 @@ void pa_resampler_reset(pa_resampler *r) {
if (r->impl_reset)
r->impl_reset(r);
+
+ r->remap_buf_contains_leftover_data = FALSE;
}
pa_resample_method_t pa_resampler_get_method(pa_resampler *r) {
@@ -1101,41 +1124,74 @@ static pa_memchunk* convert_to_work_format(pa_resampler *r, pa_memchunk *input)
}
static pa_memchunk *remap_channels(pa_resampler *r, pa_memchunk *input) {
- unsigned in_n_samples, out_n_samples, n_frames;
+ unsigned in_n_samples, out_n_samples, in_n_frames, out_n_frames;
void *src, *dst;
- pa_remap_t *remap;
+ size_t leftover_length = 0;
+ pa_bool_t have_leftover;
pa_assert(r);
pa_assert(input);
pa_assert(input->memblock);
- /* Remap channels and place the result in remap_buf. */
+ /* Remap channels and place the result in remap_buf. There may be leftover
+ * data in the beginning of remap_buf. The leftover data is already
+ * remapped, so it's not part of the input, it's part of the output. */
+
+ have_leftover = r->remap_buf_contains_leftover_data;
+ r->remap_buf_contains_leftover_data = FALSE;
- if (!r->map_required || !input->length)
+ if (!have_leftover && (!r->map_required || input->length <= 0))
return input;
+ else if (input->length <= 0)
+ return &r->remap_buf;
in_n_samples = (unsigned) (input->length / r->w_sz);
- n_frames = in_n_samples / r->i_ss.channels;
- out_n_samples = n_frames * r->o_ss.channels;
+ in_n_frames = out_n_frames = in_n_samples / r->i_ss.channels;
- r->remap_buf.index = 0;
- r->remap_buf.length = r->w_sz * out_n_samples;
+ if (have_leftover) {
+ leftover_length = r->remap_buf.length;
+ out_n_frames += leftover_length / (r->w_sz * r->o_ss.channels);
+ }
+
+ out_n_samples = out_n_frames * r->o_ss.channels;
+ r->remap_buf.length = out_n_samples * r->w_sz;
+
+ if (have_leftover) {
+ if (r->remap_buf_size < r->remap_buf.length) {
+ pa_memblock *new_block = pa_memblock_new(r->mempool, r->remap_buf.length);
+
+ src = pa_memblock_acquire(r->remap_buf.memblock);
+ dst = pa_memblock_acquire(new_block);
+ memcpy(dst, src, leftover_length);
+ pa_memblock_release(r->remap_buf.memblock);
+ pa_memblock_release(new_block);
- if (!r->remap_buf.memblock || r->remap_buf_samples < out_n_samples) {
- if (r->remap_buf.memblock)
pa_memblock_unref(r->remap_buf.memblock);
+ r->remap_buf.memblock = new_block;
+ r->remap_buf_size = r->remap_buf.length;
+ }
- r->remap_buf_samples = out_n_samples;
- r->remap_buf.memblock = pa_memblock_new(r->mempool, r->remap_buf.length);
+ } else {
+ if (!r->remap_buf.memblock || r->remap_buf_size < r->remap_buf.length) {
+ if (r->remap_buf.memblock)
+ pa_memblock_unref(r->remap_buf.memblock);
+
+ r->remap_buf_size = r->remap_buf.length;
+ r->remap_buf.memblock = pa_memblock_new(r->mempool, r->remap_buf.length);
+ }
}
- src = ((uint8_t*) pa_memblock_acquire(input->memblock) + input->index);
- dst = pa_memblock_acquire(r->remap_buf.memblock);
+ src = (uint8_t *) pa_memblock_acquire(input->memblock) + input->index;
+ dst = (uint8_t *) pa_memblock_acquire(r->remap_buf.memblock) + leftover_length;
- remap = &r->remap;
+ if (r->map_required) {
+ pa_remap_t *remap = &r->remap;
- pa_assert(remap->do_remap);
- remap->do_remap(remap, dst, src, n_frames);
+ pa_assert(remap->do_remap);
+ remap->do_remap(remap, dst, src, in_n_frames);
+
+ } else
+ memcpy(dst, src, input->length);
pa_memblock_release(input->memblock);
pa_memblock_release(r->remap_buf.memblock);
@@ -1243,6 +1299,32 @@ void pa_resampler_run(pa_resampler *r, const pa_memchunk *in, pa_memchunk *out)
pa_memchunk_reset(out);
}
+static void save_leftover(pa_resampler *r, void *buf, size_t len) {
+ void *dst;
+
+ pa_assert(r);
+ pa_assert(buf);
+ pa_assert(len > 0);
+
+ /* Store the leftover to remap_buf. */
+
+ r->remap_buf.length = len;
+
+ if (!r->remap_buf.memblock || r->remap_buf_size < r->remap_buf.length) {
+ if (r->remap_buf.memblock)
+ pa_memblock_unref(r->remap_buf.memblock);
+
+ r->remap_buf_size = r->remap_buf.length;
+ r->remap_buf.memblock = pa_memblock_new(r->mempool, r->remap_buf.length);
+ }
+
+ dst = pa_memblock_acquire(r->remap_buf.memblock);
+ memcpy(dst, buf, r->remap_buf.length);
+ pa_memblock_release(r->remap_buf.memblock);
+
+ r->remap_buf_contains_leftover_data = TRUE;
+}
+
/*** libsamplerate based implementation ***/
#ifdef HAVE_LIBSAMPLERATE
@@ -1266,7 +1348,13 @@ static void libsamplerate_resample(pa_resampler *r, const pa_memchunk *input, un
data.end_of_input = 0;
pa_assert_se(src_process(r->src.state, &data) == 0);
- pa_assert((unsigned) data.input_frames_used == in_n_frames);
+
+ if (data.input_frames_used < in_n_frames) {
+ void *leftover_data = data.data_in + data.input_frames_used * r->o_ss.channels;
+ size_t leftover_length = (in_n_frames - data.input_frames_used) * sizeof(float) * r->o_ss.channels;
+
+ save_leftover(r, leftover_data, leftover_length);
+ }
pa_memblock_release(input->memblock);
pa_memblock_release(output->memblock);
@@ -1595,6 +1683,7 @@ static int peaks_init(pa_resampler*r) {
static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
unsigned used_frames = 0, c;
+ int previous_consumed_frames = -1;
pa_assert(r);
pa_assert(input);
@@ -1606,25 +1695,14 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned
pa_memblock *b, *w;
int16_t *p, *t, *k, *q, *s;
int consumed_frames;
- unsigned in, l;
/* Allocate a new block */
b = pa_memblock_new(r->mempool, r->ffmpeg.buf[c].length + in_n_frames * sizeof(int16_t));
p = pa_memblock_acquire(b);
- /* Copy the remaining data into it */
- l = (unsigned) r->ffmpeg.buf[c].length;
- if (r->ffmpeg.buf[c].memblock) {
- t = (int16_t*) ((uint8_t*) pa_memblock_acquire(r->ffmpeg.buf[c].memblock) + r->ffmpeg.buf[c].index);
- memcpy(p, t, l);
- pa_memblock_release(r->ffmpeg.buf[c].memblock);
- pa_memblock_unref(r->ffmpeg.buf[c].memblock);
- pa_memchunk_reset(&r->ffmpeg.buf[c]);
- }
-
- /* Now append the new data, splitting up channels */
+ /* Now copy the input data, splitting up channels */
t = ((int16_t*) ((uint8_t*) pa_memblock_acquire(input->memblock) + input->index)) + c;
- k = (int16_t*) ((uint8_t*) p + l);
+ k = (int16_t*) ((uint8_t*) p);
for (u = 0; u < in_n_frames; u++) {
*k = *t;
t += r->o_ss.channels;
@@ -1632,9 +1710,6 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned
}
pa_memblock_release(input->memblock);
- /* Calculate the resulting number of frames */
- in = (unsigned) in_n_frames + l / (unsigned) sizeof(int16_t);
-
/* Allocate buffer for the result */
w = pa_memblock_new(r->mempool, *out_n_frames * sizeof(int16_t));
q = pa_memblock_acquire(w);
@@ -1643,19 +1718,15 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned
used_frames = (unsigned) av_resample(r->ffmpeg.state,
q, p,
&consumed_frames,
- (int) in, (int) *out_n_frames,
+ (int) in_n_frames, (int) *out_n_frames,
c >= (unsigned) (r->o_ss.channels-1));
pa_memblock_release(b);
+ pa_memblock_unref(b);
- /* Now store the remaining samples away */
- pa_assert(consumed_frames <= (int) in);
- if (consumed_frames < (int) in) {
- r->ffmpeg.buf[c].memblock = b;
- r->ffmpeg.buf[c].index = (size_t) consumed_frames * sizeof(int16_t);
- r->ffmpeg.buf[c].length = (size_t) (in - (unsigned) consumed_frames) * sizeof(int16_t);
- } else
- pa_memblock_unref(b);
+ pa_assert(consumed_frames <= (int) in_n_frames);
+ pa_assert(previous_consumed_frames == -1 || consumed_frames == previous_consumed_frames);
+ previous_consumed_frames = consumed_frames;
/* And place the results in the output buffer */
s = (short*) ((uint8_t*) pa_memblock_acquire(output->memblock) + output->index) + c;
@@ -1669,6 +1740,14 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned
pa_memblock_unref(w);
}
+ if (previous_consumed_frames < (int) in_n_frames) {
+ void *leftover_data = (int16_t *) ((uint8_t *) pa_memblock_acquire(input->memblock) + output->index) + previous_consumed_frames * r->o_ss.channels;
+ size_t leftover_length = (in_n_frames - previous_consumed_frames) * r->o_ss.channels * sizeof(int16_t);
+
+ save_leftover(r, leftover_data, leftover_length);
+ pa_memblock_release(input->memblock);
+ }
+
*out_n_frames = used_frames;
}
commit 1a75e1c29757aeef3ea5f1b03df64aa257be4180
Author: Tanu Kaskinen <tanuk at iki.fi>
Date: Thu May 10 09:19:22 2012 +0300
resampler: Use more descriptive buffer names.
diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 185095b..258d1fe 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -56,8 +56,14 @@ struct pa_resampler {
size_t i_fz, o_fz, w_sz;
pa_mempool *mempool;
- pa_memchunk buf1, buf2, buf3, buf4;
- unsigned buf1_samples, buf2_samples, buf3_samples, buf4_samples;
+ pa_memchunk to_work_format_buf;
+ pa_memchunk remap_buf;
+ pa_memchunk resample_buf;
+ pa_memchunk from_work_format_buf;
+ unsigned to_work_format_buf_samples;
+ unsigned remap_buf_samples;
+ unsigned resample_buf_samples;
+ unsigned from_work_format_buf_samples;
pa_sample_format_t work_format;
@@ -334,14 +340,14 @@ void pa_resampler_free(pa_resampler *r) {
if (r->impl_free)
r->impl_free(r);
- if (r->buf1.memblock)
- pa_memblock_unref(r->buf1.memblock);
- if (r->buf2.memblock)
- pa_memblock_unref(r->buf2.memblock);
- if (r->buf3.memblock)
- pa_memblock_unref(r->buf3.memblock);
- if (r->buf4.memblock)
- pa_memblock_unref(r->buf4.memblock);
+ if (r->to_work_format_buf.memblock)
+ pa_memblock_unref(r->to_work_format_buf.memblock);
+ if (r->remap_buf.memblock)
+ pa_memblock_unref(r->remap_buf.memblock);
+ if (r->resample_buf.memblock)
+ pa_memblock_unref(r->resample_buf.memblock);
+ if (r->from_work_format_buf.memblock)
+ pa_memblock_unref(r->from_work_format_buf.memblock);
pa_xfree(r);
}
@@ -1064,33 +1070,34 @@ static pa_memchunk* convert_to_work_format(pa_resampler *r, pa_memchunk *input)
pa_assert(input);
pa_assert(input->memblock);
- /* Convert the incoming sample into the work sample format and place them in buf1 */
+ /* Convert the incoming sample into the work sample format and place them
+ * in to_work_format_buf. */
if (!r->to_work_format_func || !input->length)
return input;
n_samples = (unsigned) ((input->length / r->i_fz) * r->i_ss.channels);
- r->buf1.index = 0;
- r->buf1.length = r->w_sz * n_samples;
+ r->to_work_format_buf.index = 0;
+ r->to_work_format_buf.length = r->w_sz * n_samples;
- if (!r->buf1.memblock || r->buf1_samples < n_samples) {
- if (r->buf1.memblock)
- pa_memblock_unref(r->buf1.memblock);
+ if (!r->to_work_format_buf.memblock || r->to_work_format_buf_samples < n_samples) {
+ if (r->to_work_format_buf.memblock)
+ pa_memblock_unref(r->to_work_format_buf.memblock);
- r->buf1_samples = n_samples;
- r->buf1.memblock = pa_memblock_new(r->mempool, r->buf1.length);
+ r->to_work_format_buf_samples = n_samples;
+ r->to_work_format_buf.memblock = pa_memblock_new(r->mempool, r->to_work_format_buf.length);
}
src = (uint8_t*) pa_memblock_acquire(input->memblock) + input->index;
- dst = (uint8_t*) pa_memblock_acquire(r->buf1.memblock);
+ dst = (uint8_t*) pa_memblock_acquire(r->to_work_format_buf.memblock);
r->to_work_format_func(n_samples, src, dst);
pa_memblock_release(input->memblock);
- pa_memblock_release(r->buf1.memblock);
+ pa_memblock_release(r->to_work_format_buf.memblock);
- return &r->buf1;
+ return &r->to_work_format_buf;
}
static pa_memchunk *remap_channels(pa_resampler *r, pa_memchunk *input) {
@@ -1102,7 +1109,7 @@ static pa_memchunk *remap_channels(pa_resampler *r, pa_memchunk *input) {
pa_assert(input);
pa_assert(input->memblock);
- /* Remap channels and place the result int buf2 */
+ /* Remap channels and place the result in remap_buf. */
if (!r->map_required || !input->length)
return input;
@@ -1111,19 +1118,19 @@ static pa_memchunk *remap_channels(pa_resampler *r, pa_memchunk *input) {
n_frames = in_n_samples / r->i_ss.channels;
out_n_samples = n_frames * r->o_ss.channels;
- r->buf2.index = 0;
- r->buf2.length = r->w_sz * out_n_samples;
+ r->remap_buf.index = 0;
+ r->remap_buf.length = r->w_sz * out_n_samples;
- if (!r->buf2.memblock || r->buf2_samples < out_n_samples) {
- if (r->buf2.memblock)
- pa_memblock_unref(r->buf2.memblock);
+ if (!r->remap_buf.memblock || r->remap_buf_samples < out_n_samples) {
+ if (r->remap_buf.memblock)
+ pa_memblock_unref(r->remap_buf.memblock);
- r->buf2_samples = out_n_samples;
- r->buf2.memblock = pa_memblock_new(r->mempool, r->buf2.length);
+ r->remap_buf_samples = out_n_samples;
+ r->remap_buf.memblock = pa_memblock_new(r->mempool, r->remap_buf.length);
}
src = ((uint8_t*) pa_memblock_acquire(input->memblock) + input->index);
- dst = pa_memblock_acquire(r->buf2.memblock);
+ dst = pa_memblock_acquire(r->remap_buf.memblock);
remap = &r->remap;
@@ -1131,9 +1138,9 @@ static pa_memchunk *remap_channels(pa_resampler *r, pa_memchunk *input) {
remap->do_remap(remap, dst, src, n_frames);
pa_memblock_release(input->memblock);
- pa_memblock_release(r->buf2.memblock);
+ pa_memblock_release(r->remap_buf.memblock);
- return &r->buf2;
+ return &r->remap_buf;
}
static pa_memchunk *resample(pa_resampler *r, pa_memchunk *input) {
@@ -1143,7 +1150,7 @@ static pa_memchunk *resample(pa_resampler *r, pa_memchunk *input) {
pa_assert(r);
pa_assert(input);
- /* Resample the data and place the result in buf3 */
+ /* Resample the data and place the result in resample_buf. */
if (!r->impl_resample || !input->length)
return input;
@@ -1154,21 +1161,21 @@ static pa_memchunk *resample(pa_resampler *r, pa_memchunk *input) {
out_n_frames = ((in_n_frames*r->o_ss.rate)/r->i_ss.rate)+EXTRA_FRAMES;
out_n_samples = out_n_frames * r->o_ss.channels;
- r->buf3.index = 0;
- r->buf3.length = r->w_sz * out_n_samples;
+ r->resample_buf.index = 0;
+ r->resample_buf.length = r->w_sz * out_n_samples;
- if (!r->buf3.memblock || r->buf3_samples < out_n_samples) {
- if (r->buf3.memblock)
- pa_memblock_unref(r->buf3.memblock);
+ if (!r->resample_buf.memblock || r->resample_buf_samples < out_n_samples) {
+ if (r->resample_buf.memblock)
+ pa_memblock_unref(r->resample_buf.memblock);
- r->buf3_samples = out_n_samples;
- r->buf3.memblock = pa_memblock_new(r->mempool, r->buf3.length);
+ r->resample_buf_samples = out_n_samples;
+ r->resample_buf.memblock = pa_memblock_new(r->mempool, r->resample_buf.length);
}
- r->impl_resample(r, input, in_n_frames, &r->buf3, &out_n_frames);
- r->buf3.length = out_n_frames * r->w_sz * r->o_ss.channels;
+ r->impl_resample(r, input, in_n_frames, &r->resample_buf, &out_n_frames);
+ r->resample_buf.length = out_n_frames * r->w_sz * r->o_ss.channels;
- return &r->buf3;
+ return &r->resample_buf;
}
static pa_memchunk *convert_from_work_format(pa_resampler *r, pa_memchunk *input) {
@@ -1178,7 +1185,8 @@ static pa_memchunk *convert_from_work_format(pa_resampler *r, pa_memchunk *input
pa_assert(r);
pa_assert(input);
- /* Convert the data into the correct sample type and place the result in buf4 */
+ /* Convert the data into the correct sample type and place the result in
+ * from_work_format_buf. */
if (!r->from_work_format_func || !input->length)
return input;
@@ -1186,26 +1194,26 @@ static pa_memchunk *convert_from_work_format(pa_resampler *r, pa_memchunk *input
n_samples = (unsigned) (input->length / r->w_sz);
n_frames = n_samples / r->o_ss.channels;
- r->buf4.index = 0;
- r->buf4.length = r->o_fz * n_frames;
+ r->from_work_format_buf.index = 0;
+ r->from_work_format_buf.length = r->o_fz * n_frames;
- if (!r->buf4.memblock || r->buf4_samples < n_samples) {
- if (r->buf4.memblock)
- pa_memblock_unref(r->buf4.memblock);
+ if (!r->from_work_format_buf.memblock || r->from_work_format_buf_samples < n_samples) {
+ if (r->from_work_format_buf.memblock)
+ pa_memblock_unref(r->from_work_format_buf.memblock);
- r->buf4_samples = n_samples;
- r->buf4.memblock = pa_memblock_new(r->mempool, r->buf4.length);
+ r->from_work_format_buf_samples = n_samples;
+ r->from_work_format_buf.memblock = pa_memblock_new(r->mempool, r->from_work_format_buf.length);
}
src = (uint8_t*) pa_memblock_acquire(input->memblock) + input->index;
- dst = pa_memblock_acquire(r->buf4.memblock);
+ dst = pa_memblock_acquire(r->from_work_format_buf.memblock);
r->from_work_format_func(n_samples, src, dst);
pa_memblock_release(input->memblock);
- pa_memblock_release(r->buf4.memblock);
+ pa_memblock_release(r->from_work_format_buf.memblock);
- r->buf4.length = r->o_fz * n_frames;
+ r->from_work_format_buf.length = r->o_fz * n_frames;
- return &r->buf4;
+ return &r->from_work_format_buf;
}
void pa_resampler_run(pa_resampler *r, const pa_memchunk *in, pa_memchunk *out) {
commit 7921a851ebea998e67527f05708971aba9bb4e61
Author: Tanu Kaskinen <tanuk at iki.fi>
Date: Thu May 10 09:19:21 2012 +0300
resampler: Use pa_xnew0() to avoid manual zeroing.
diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index 9a651f4..185095b 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -234,16 +234,11 @@ pa_resampler* pa_resampler_new(
#endif
}
- r = pa_xnew(pa_resampler, 1);
+ r = pa_xnew0(pa_resampler, 1);
r->mempool = pool;
r->method = method;
r->flags = flags;
- r->impl_free = NULL;
- r->impl_update_rates = NULL;
- r->impl_resample = NULL;
- r->impl_reset = NULL;
-
/* Fill sample specs */
r->i_ss = *a;
r->o_ss = *b;
@@ -266,13 +261,6 @@ pa_resampler* pa_resampler_new(
r->i_fz = pa_frame_size(a);
r->o_fz = pa_frame_size(b);
- pa_memchunk_reset(&r->buf1);
- pa_memchunk_reset(&r->buf2);
- pa_memchunk_reset(&r->buf3);
- pa_memchunk_reset(&r->buf4);
-
- r->buf1_samples = r->buf2_samples = r->buf3_samples = r->buf4_samples = 0;
-
calc_map_table(r);
pa_log_info("Using resampler '%s'", pa_resample_method_to_string(method));
@@ -306,26 +294,26 @@ pa_resampler* pa_resampler_new(
r->w_sz = pa_sample_size_of_format(r->work_format);
- if (r->i_ss.format == r->work_format)
- r->to_work_format_func = NULL;
- else if (r->work_format == PA_SAMPLE_FLOAT32NE) {
- if (!(r->to_work_format_func = pa_get_convert_to_float32ne_function(r->i_ss.format)))
- goto fail;
- } else {
- pa_assert(r->work_format == PA_SAMPLE_S16NE);
- if (!(r->to_work_format_func = pa_get_convert_to_s16ne_function(r->i_ss.format)))
- goto fail;
+ if (r->i_ss.format != r->work_format) {
+ if (r->work_format == PA_SAMPLE_FLOAT32NE) {
+ if (!(r->to_work_format_func = pa_get_convert_to_float32ne_function(r->i_ss.format)))
+ goto fail;
+ } else {
+ pa_assert(r->work_format == PA_SAMPLE_S16NE);
+ if (!(r->to_work_format_func = pa_get_convert_to_s16ne_function(r->i_ss.format)))
+ goto fail;
+ }
}
- if (r->o_ss.format == r->work_format)
- r->from_work_format_func = NULL;
- else if (r->work_format == PA_SAMPLE_FLOAT32NE) {
- if (!(r->from_work_format_func = pa_get_convert_from_float32ne_function(r->o_ss.format)))
- goto fail;
- } else {
- pa_assert(r->work_format == PA_SAMPLE_S16NE);
- if (!(r->from_work_format_func = pa_get_convert_from_s16ne_function(r->o_ss.format)))
- goto fail;
+ if (r->o_ss.format != r->work_format) {
+ if (r->work_format == PA_SAMPLE_FLOAT32NE) {
+ if (!(r->from_work_format_func = pa_get_convert_from_float32ne_function(r->o_ss.format)))
+ goto fail;
+ } else {
+ pa_assert(r->work_format == PA_SAMPLE_S16NE);
+ if (!(r->from_work_format_func = pa_get_convert_from_s16ne_function(r->o_ss.format)))
+ goto fail;
+ }
}
/* initialize implementation */
More information about the pulseaudio-commits
mailing list