[pulseaudio-discuss] [PATCH 03/11] resampler: Change interface, resampler may return the number of leftover frames

Peter Meerwald pmeerw at pmeerw.net
Sun Jul 21 14:14:40 PDT 2013


some resampler implementations (e.g. libsamplerate and ffmpeg) do not consume
the entire input buffer; the impl_resample() function now has a return value
returning the number of frames in the input buffer not processed

these frames must be saved in appropriate buffer and presented together with
new input data

also change the parameter names from in_samples, out_samples to in_n_frames,
out_n_frames, respectively (n_frames = samples / channels)

Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
 src/pulsecore/resampler.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c
index df5dba9..feca8c9 100644
--- a/src/pulsecore/resampler.c
+++ b/src/pulsecore/resampler.c
@@ -77,7 +77,8 @@ struct pa_resampler {
 
     void (*impl_free)(pa_resampler *r);
     void (*impl_update_rates)(pa_resampler *r);
-    void (*impl_resample)(pa_resampler *r, const pa_memchunk *in, unsigned in_samples, pa_memchunk *out, unsigned *out_samples);
+    /* returns number of leftover frames in the input buffer */
+    unsigned (*impl_resample)(pa_resampler *r, const pa_memchunk *in, unsigned in_n_frames, pa_memchunk *out, unsigned *out_n_frames);
     void (*impl_reset)(pa_resampler *r);
 
     struct { /* data specific to the trivial resampler */
@@ -1257,7 +1258,7 @@ static void save_leftover(pa_resampler *r, void *buf, size_t len) {
 /*** libsamplerate based implementation ***/
 
 #ifdef HAVE_LIBSAMPLERATE
-static void libsamplerate_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
+static unsigned libsamplerate_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
     SRC_DATA data;
 
     pa_assert(r);
@@ -1289,6 +1290,8 @@ static void libsamplerate_resample(pa_resampler *r, const pa_memchunk *input, un
     pa_memblock_release(output->memblock);
 
     *out_n_frames = (unsigned) data.output_frames_gen;
+
+    return 0;
 }
 
 static void libsamplerate_update_rates(pa_resampler *r) {
@@ -1330,7 +1333,7 @@ static int libsamplerate_init(pa_resampler *r) {
 #ifdef HAVE_SPEEX
 /*** speex based implementation ***/
 
-static void speex_resample_float(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
+static unsigned speex_resample_float(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
     float *in, *out;
     uint32_t inf = in_n_frames, outf = *out_n_frames;
 
@@ -1349,9 +1352,11 @@ static void speex_resample_float(pa_resampler *r, const pa_memchunk *input, unsi
 
     pa_assert(inf == in_n_frames);
     *out_n_frames = outf;
+
+    return 0;
 }
 
-static void speex_resample_int(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
+static unsigned speex_resample_int(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
     int16_t *in, *out;
     uint32_t inf = in_n_frames, outf = *out_n_frames;
 
@@ -1370,6 +1375,8 @@ static void speex_resample_int(pa_resampler *r, const pa_memchunk *input, unsign
 
     pa_assert(inf == in_n_frames);
     *out_n_frames = outf;
+
+    return 0;
 }
 
 static void speex_update_rates(pa_resampler *r) {
@@ -1425,7 +1432,7 @@ static int speex_init(pa_resampler *r) {
 
 /* Trivial implementation */
 
-static void trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
+static unsigned trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
     unsigned i_index, o_index;
     void *src, *dst;
 
@@ -1463,6 +1470,8 @@ static void trivial_resample(pa_resampler *r, const pa_memchunk *input, unsigned
         r->trivial.i_counter -= r->i_ss.rate;
         r->trivial.o_counter -= r->o_ss.rate;
     }
+
+    return 0;
 }
 
 static void trivial_update_rates_or_reset(pa_resampler *r) {
@@ -1486,7 +1495,7 @@ static int trivial_init(pa_resampler*r) {
 
 /* Peak finder implementation */
 
-static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
+static unsigned peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
     unsigned c, o_index = 0;
     unsigned i, i_end = 0;
     void *src, *dst;
@@ -1580,6 +1589,8 @@ static void peaks_resample(pa_resampler *r, const pa_memchunk *input, unsigned i
         r->peaks.i_counter -= r->i_ss.rate;
         r->peaks.o_counter -= r->o_ss.rate;
     }
+
+    return 0;
 }
 
 static void peaks_update_rates_or_reset(pa_resampler *r) {
@@ -1607,7 +1618,7 @@ static int peaks_init(pa_resampler*r) {
 
 /*** ffmpeg based implementation ***/
 
-static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
+static unsigned 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;
 
@@ -1675,6 +1686,8 @@ static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, unsigned
     }
 
     *out_n_frames = used_frames;
+
+    return 0;
 }
 
 static void ffmpeg_free(pa_resampler *r) {
-- 
1.8.3.2



More information about the pulseaudio-discuss mailing list