[pulseaudio-commits] r1715 - in /branches/lennart/src/pulsecore: ffmpeg/Makefile resampler.c resampler.h sink-input.c source-output.c speex/Makefile

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu Aug 23 17:23:49 PDT 2007


Author: lennart
Date: Fri Aug 24 02:23:48 2007
New Revision: 1715

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1715&root=3Dpulseaudio&vi=
ew=3Drev
Log:
add makefiles to speex/ and ffmpeg/ to easy compilation from emacs

Added:
    branches/lennart/src/pulsecore/ffmpeg/Makefile   (with props)
    branches/lennart/src/pulsecore/speex/Makefile   (with props)
Modified:
    branches/lennart/src/pulsecore/resampler.c
    branches/lennart/src/pulsecore/resampler.h
    branches/lennart/src/pulsecore/sink-input.c
    branches/lennart/src/pulsecore/source-output.c

Added: branches/lennart/src/pulsecore/ffmpeg/Makefile
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
ffmpeg/Makefile?rev=3D1715&root=3Dpulseaudio&view=3Dauto
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/ffmpeg/Makefile (added)
+++ branches/lennart/src/pulsecore/ffmpeg/Makefile Fri Aug 24 02:23:48 2007
@@ -1,0 +1,13 @@
+# This is a dirty trick just to ease compilation with emacs
+#
+# This file is not intended to be distributed or anything
+#
+# So: don't touch it, even better ignore it!
+
+all:
+	$(MAKE) -C ../..
+
+clean:
+	$(MAKE) -C ../.. clean
+
+.PHONY: all clean

Propchange: branches/lennart/src/pulsecore/ffmpeg/Makefile
---------------------------------------------------------------------------=
---
    svn:keywords =3D Id

Modified: branches/lennart/src/pulsecore/resampler.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
resampler.c?rev=3D1715&root=3Dpulseaudio&r1=3D1714&r2=3D1715&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/resampler.c (original)
+++ branches/lennart/src/pulsecore/resampler.c Fri Aug 24 02:23:48 2007
@@ -38,6 +38,8 @@
 #include <pulsecore/macro.h>
 =

 #include "speexwrap.h"
+
+#include "ffmpeg/avcodec.h"
 =

 #include "resampler.h"
 =

@@ -75,11 +77,17 @@
     struct { /* data specific to speex */
         SpeexResamplerState* state;
     } speex;
+
+    struct { /* data specific to ffmpeg */
+        struct AVResampleContext *state;
+        unsigned initial_i_rate, initial_o_rate;
+    } ffmpeg;
 };
 =

 static int libsamplerate_init(pa_resampler*r);
 static int trivial_init(pa_resampler*r);
 static int speex_init(pa_resampler*r);
+static int ffmpeg_init(pa_resampler*r);
 =

 static void calc_map_table(pa_resampler *r);
 =

@@ -112,6 +120,7 @@
     [PA_RESAMPLER_SPEEX_FIXED_BASE+8]      =3D speex_init,
     [PA_RESAMPLER_SPEEX_FIXED_BASE+9]      =3D speex_init,
     [PA_RESAMPLER_SPEEX_FIXED_BASE+10]     =3D speex_init,
+    [PA_RESAMPLER_FFMPEG]                  =3D ffmpeg_init,
     [PA_RESAMPLER_AUTO]                    =3D NULL,
 };
 =

@@ -131,7 +140,8 @@
         const pa_channel_map *am,
         const pa_sample_spec *b,
         const pa_channel_map *bm,
-        pa_resample_method_t resample_method) {
+        pa_resample_method_t resample_method,
+        int variable_rate) {
 =

     pa_resampler *r =3D NULL;
 =

@@ -144,6 +154,12 @@
     pa_assert(resample_method < PA_RESAMPLER_MAX);
 =

     /* Fix method */
+
+    if (resample_method =3D=3D PA_RESAMPLER_FFMPEG && variable_rate) {
+        pa_log_info("Resampler 'ffmpeg' cannot do variable rate, reverting=
 to resampler 'auto'." );
+        resample_method =3D PA_RESAMPLER_AUTO;
+    }
+
     if (resample_method =3D=3D PA_RESAMPLER_AUTO) {
         if (a->format =3D=3D PA_SAMPLE_FLOAT32LE || a->format =3D=3D PA_SA=
MPLE_FLOAT32BE ||
             b->format =3D=3D PA_SAMPLE_FLOAT32LE || b->format =3D=3D PA_SA=
MPLE_FLOAT32BE)
@@ -151,7 +167,7 @@
         else
             resample_method =3D PA_RESAMPLER_SPEEX_FIXED_BASE + 0;
     }
-    =

+
     r =3D pa_xnew(pa_resampler, 1);
     r->mempool =3D pool;
     r->resample_method =3D resample_method;
@@ -188,7 +204,8 @@
 =

     pa_log_info("Using resampler '%s'", pa_resample_method_to_string(resam=
ple_method));
     =

-    if (resample_method >=3D PA_RESAMPLER_SPEEX_FIXED_BASE && resample_met=
hod <=3D PA_RESAMPLER_SPEEX_FIXED_MAX)
+    if ((resample_method >=3D PA_RESAMPLER_SPEEX_FIXED_BASE && resample_me=
thod <=3D PA_RESAMPLER_SPEEX_FIXED_MAX) ||
+        (resample_method =3D=3D PA_RESAMPLER_FFMPEG))
         r->work_format =3D PA_SAMPLE_S16NE;
     else if (resample_method =3D=3D PA_RESAMPLER_TRIVIAL) {
 =

@@ -268,6 +285,7 @@
         return;
 =

     r->i_ss.rate =3D rate;
+
     r->impl_update_rates(r);
 }
 =

@@ -279,6 +297,7 @@
         return;
 =

     r->o_ss.rate =3D rate;
+
     r->impl_update_rates(r);
 }
 =

@@ -323,6 +342,7 @@
     "speex-fixed-8",
     "speex-fixed-9",
     "speex-fixed-10",
+    "ffmpeg",
     "auto"
 };
 =

@@ -825,4 +845,56 @@
     return 0;
 }
 =

-
+/*** ffmpeg based implementation ***/
+
+static void ffmpeg_resample(pa_resampler *r, const pa_memchunk *input, uns=
igned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) {
+    short *src, *dst;
+    int consumed;
+    int c;
+    =

+    pa_assert(r);
+    pa_assert(input);
+    pa_assert(output);
+    pa_assert(out_n_frames);
+    =

+    src =3D (short*) ((uint8_t*) pa_memblock_acquire(input->memblock) + in=
put->index);
+    dst =3D (short*) ((uint8_t*) pa_memblock_acquire(output->memblock) + o=
utput->index);
+
+    for (c =3D 0; c < r->o_ss.channels; c++) =

+        *out_n_frames =3D av_resample(r->ffmpeg.state,
+                                    dst + r->w_sz*c,
+                                    src + r->w_sz*c,
+                                    &consumed,
+                                    in_n_frames, *out_n_frames,
+                                    c >=3D r->o_ss.channels-1);
+
+    pa_assert(*out_n_frames > 0);
+    pa_assert(consumed =3D=3D in_n_frames);
+    =

+    pa_memblock_release(input->memblock);
+    pa_memblock_release(output->memblock);
+}
+
+static void ffmpeg_free(pa_resampler *r) {
+    pa_assert(r);
+    =

+    if (r->ffmpeg.state)
+        av_resample_close(r->ffmpeg.state);
+}
+
+static int ffmpeg_init(pa_resampler *r) {
+    pa_assert(r);
+
+    /* We could probably implement different quality levels by
+     * adjusting the filter parameters here. However, ffmpeg
+     * internally only uses these hardcoded values, so let's use them
+     * here for now as well until ffmpeg makes this configurable. */
+    =

+    if (!(r->ffmpeg.state =3D av_resample_init(r->o_ss.rate, r->i_ss.rate,=
 16, 10, 0, 0.8)))
+        return -1;
+
+    r->impl_free =3D ffmpeg_free;
+    r->impl_resample =3D ffmpeg_resample;
+
+    return 0;
+}

Modified: branches/lennart/src/pulsecore/resampler.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
resampler.h?rev=3D1715&root=3Dpulseaudio&r1=3D1714&r2=3D1715&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/resampler.h (original)
+++ branches/lennart/src/pulsecore/resampler.h Fri Aug 24 02:23:48 2007
@@ -45,6 +45,7 @@
     PA_RESAMPLER_SPEEX_FLOAT_MAX =3D PA_RESAMPLER_SPEEX_FLOAT_BASE + 10,
     PA_RESAMPLER_SPEEX_FIXED_BASE,
     PA_RESAMPLER_SPEEX_FIXED_MAX =3D PA_RESAMPLER_SPEEX_FIXED_BASE + 10,
+    PA_RESAMPLER_FFMPEG,
     PA_RESAMPLER_AUTO, /* automatic select based on sample format */
     PA_RESAMPLER_MAX
 } pa_resample_method_t;
@@ -55,7 +56,8 @@
         const pa_channel_map *am,
         const pa_sample_spec *b,
         const pa_channel_map *bm,
-        pa_resample_method_t resample_method);
+        pa_resample_method_t resample_method,
+        int variable_rate);
 =

 void pa_resampler_free(pa_resampler *r);
 =


Modified: branches/lennart/src/pulsecore/sink-input.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
sink-input.c?rev=3D1715&root=3Dpulseaudio&r1=3D1714&r2=3D1715&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/sink-input.c (original)
+++ branches/lennart/src/pulsecore/sink-input.c Fri Aug 24 02:23:48 2007
@@ -153,7 +153,8 @@
                       core->mempool,
                       &data->sample_spec, &data->channel_map,
                       &data->sink->sample_spec, &data->sink->channel_map,
-                      data->resample_method))) {
+                      data->resample_method,
+                      !!(flags & PA_SINK_INPUT_VARIABLE_RATE)))) {
             pa_log_warn("Unsupported resampling operation.");
             return NULL;
         }
@@ -639,8 +640,8 @@
         new_resampler =3D i->thread_info.resampler;
 =

     else if ((i->flags & PA_SINK_INPUT_VARIABLE_RATE) ||
-        !pa_sample_spec_equal(&i->sample_spec, &dest->sample_spec) ||
-        !pa_channel_map_equal(&i->channel_map, &dest->channel_map)) {
+             !pa_sample_spec_equal(&i->sample_spec, &dest->sample_spec) ||
+             !pa_channel_map_equal(&i->channel_map, &dest->channel_map)) {
 =

         /* Okey, we need a new resampler for the new sink */
 =

@@ -648,7 +649,8 @@
                       dest->core->mempool,
                       &i->sample_spec, &i->channel_map,
                       &dest->sample_spec, &dest->channel_map,
-                      i->resample_method))) {
+                      i->resample_method,
+                      !!(i->flags & PA_SINK_INPUT_VARIABLE_RATE)))) {
             pa_log_warn("Unsupported resampling operation.");
             return -1;
         }

Modified: branches/lennart/src/pulsecore/source-output.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
source-output.c?rev=3D1715&root=3Dpulseaudio&r1=3D1714&r2=3D1715&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/source-output.c (original)
+++ branches/lennart/src/pulsecore/source-output.c Fri Aug 24 02:23:48 2007
@@ -121,7 +121,8 @@
                       core->mempool,
                       &data->source->sample_spec, &data->source->channel_m=
ap,
                       &data->sample_spec, &data->channel_map,
-                      data->resample_method))) {
+                      data->resample_method,
+                      !!(flags & PA_SOURCE_OUTPUT_VARIABLE_RATE)))) {
             pa_log_warn("Unsupported resampling operation.");
             return NULL;
         }
@@ -351,8 +352,9 @@
         /* Try to reuse the old resampler if possible */
         new_resampler =3D o->thread_info.resampler;
 =

-    else if (!pa_sample_spec_equal(&o->sample_spec, &dest->sample_spec) ||
-        !pa_channel_map_equal(&o->channel_map, &dest->channel_map)) {
+    else if ((o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE) ||
+             !pa_sample_spec_equal(&o->sample_spec, &dest->sample_spec) ||
+             !pa_channel_map_equal(&o->channel_map, &dest->channel_map)) {
 =

         /* Okey, we need a new resampler for the new source */
 =

@@ -360,7 +362,8 @@
                       dest->core->mempool,
                       &dest->sample_spec, &dest->channel_map,
                       &o->sample_spec, &o->channel_map,
-                      o->resample_method))) {
+                      o->resample_method,
+                      !!(o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE)))) {
             pa_log_warn("Unsupported resampling operation.");
             return -1;
         }

Added: branches/lennart/src/pulsecore/speex/Makefile
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
speex/Makefile?rev=3D1715&root=3Dpulseaudio&view=3Dauto
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/speex/Makefile (added)
+++ branches/lennart/src/pulsecore/speex/Makefile Fri Aug 24 02:23:48 2007
@@ -1,0 +1,13 @@
+# This is a dirty trick just to ease compilation with emacs
+#
+# This file is not intended to be distributed or anything
+#
+# So: don't touch it, even better ignore it!
+
+all:
+	$(MAKE) -C ../..
+
+clean:
+	$(MAKE) -C ../.. clean
+
+.PHONY: all clean

Propchange: branches/lennart/src/pulsecore/speex/Makefile
---------------------------------------------------------------------------=
---
    svn:keywords =3D Id




More information about the pulseaudio-commits mailing list