[vlc-commits] aout: reduce filter table for resamplers and converters

Rémi Denis-Courmont git at videolan.org
Sun Nov 4 18:58:11 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Nov  4 19:46:26 2012 +0200| [79bf979ee9f22f83158c136181fac30b50c9b0cb] | committer: Rémi Denis-Courmont

aout: reduce filter table for resamplers and converters

There should never be a need for more than 5 of them. Only the
filters proper might require more than 5 members in a chain.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=79bf979ee9f22f83158c136181fac30b50c9b0cb
---

 include/vlc_aout.h               |    3 ---
 src/audio_output/aout_internal.h |   24 +++++++++++++-----------
 src/audio_output/filters.c       |   15 ++++++++-------
 src/audio_output/input.c         |    5 ++++-
 src/audio_output/output.c        |    2 ++
 5 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/include/vlc_aout.h b/include/vlc_aout.h
index 046f342..2835b27 100644
--- a/include/vlc_aout.h
+++ b/include/vlc_aout.h
@@ -28,9 +28,6 @@
  * This file defines functions, structures and macros for audio output object
  */
 
-/* Max number of pre-filters per input, and max number of post-filters */
-#define AOUT_MAX_FILTERS                10
-
 /* Buffers which arrive in advance of more than AOUT_MAX_ADVANCE_TIME
  * will be considered as bogus and be trashed */
 #define AOUT_MAX_ADVANCE_TIME           (AOUT_MAX_PREPARE_TIME + CLOCK_FREQ)
diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index ac6a9b6..2685691 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -29,6 +29,8 @@
 /* Max input rate factor (1/4 -> 4) */
 # define AOUT_MAX_INPUT_RATE (4)
 
+# define AOUT_MAX_FILTERS 10
+
 enum {
     AOUT_RESAMPLING_NONE=0,
     AOUT_RESAMPLING_UP,
@@ -49,15 +51,15 @@ struct aout_input_t
 {
     unsigned            samplerate; /**< Input sample rate */
 
-    /* pre-filters */
+    /* filters */
     filter_t *              pp_filters[AOUT_MAX_FILTERS];
-    int                     i_nb_filters;
+    unsigned                i_nb_filters;
 
     filter_t *              p_playback_rate_filter;
 
-    /* resamplers */
-    filter_t *              pp_resamplers[AOUT_MAX_FILTERS];
-    int                     i_nb_resamplers;
+    /* Resampler + converter to mixer */
+    filter_t *              pp_resamplers[5];
+    unsigned                i_nb_resamplers;
     int                     i_resampling_type;
     mtime_t                 i_resamp_start_date;
     int                     i_resamp_start_drift;
@@ -89,8 +91,8 @@ typedef struct
     audio_sample_format_t input_format;
 
     /* Filters between mixer and output */
-    filter_t *filters[AOUT_MAX_FILTERS];
-    int       nb_filters;
+    filter_t *filters[5];
+    unsigned  nb_filters;
 
     vlc_atomic_t restart;
 } aout_owner_t;
@@ -119,10 +121,10 @@ block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
                          block_t *p_buffer, int i_input_rate, date_t * );
 
 /* From filters.c : */
-int aout_FiltersCreatePipeline( vlc_object_t *, filter_t **, int *,
-    const audio_sample_format_t *, const audio_sample_format_t * );
-#define aout_FiltersCreatePipeline(o, pv, pc, inf, outf) \
-        aout_FiltersCreatePipeline(VLC_OBJECT(o), pv, pc, inf, outf)
+int aout_FiltersCreatePipeline( vlc_object_t *, filter_t **, unsigned *,
+    unsigned, const audio_sample_format_t *, const audio_sample_format_t * );
+#define aout_FiltersCreatePipeline(o, pv, pc, max, inf, outf) \
+        aout_FiltersCreatePipeline(VLC_OBJECT(o), pv, pc, max, inf, outf)
 void aout_FiltersDestroyPipeline( filter_t *const *, unsigned );
 void aout_FiltersPlay( filter_t *const *, unsigned, block_t ** );
 
diff --git a/src/audio_output/filters.c b/src/audio_output/filters.c
index 2e12e9d..bb75a89 100644
--- a/src/audio_output/filters.c
+++ b/src/audio_output/filters.c
@@ -130,30 +130,31 @@ static int SplitConversion( const audio_sample_format_t *restrict infmt,
  * @param obj parent VLC object for new filters
  * @param filters table of filters [IN/OUT]
  * @param nb_filters pointer to the number of filters in the table [IN/OUT]
+ * @param max_filters size of filters table [IN]
  * @param infmt input audio format
  * @param outfmt output audio format
  * @return 0 on success, -1 on failure
  */
-int aout_FiltersCreatePipeline( vlc_object_t *obj,
-                                filter_t **filters,
-                                int *nb_filters,
+int aout_FiltersCreatePipeline( vlc_object_t *obj, filter_t **filters,
+                                unsigned *nb_filters, unsigned max_filters,
                                 const audio_sample_format_t *restrict infmt,
                                 const audio_sample_format_t *restrict outfmt )
 {
     audio_sample_format_t curfmt = *outfmt;
-    unsigned i = 0, max = *nb_filters - AOUT_MAX_FILTERS;
+    unsigned i = 0;
 
+    max_filters -= *nb_filters;
     filters += *nb_filters;
     aout_FormatsPrint( obj, "filter(s)", infmt, outfmt );
 
     while( !AOUT_FMTS_IDENTICAL( infmt, &curfmt ) )
     {
-        if( i >= max )
+        if( i >= max_filters )
         {
-            msg_Err( obj, "max (%u) filters reached", AOUT_MAX_FILTERS );
+            msg_Err( obj, "maximum of %u filters reached", max_filters );
             dialog_Fatal( obj, _("Audio filtering failed"),
                           _("The maximum number of filters (%u) was reached."),
-                          AOUT_MAX_FILTERS );
+                          max_filters );
             goto rollback;
         }
 
diff --git a/src/audio_output/input.c b/src/audio_output/input.c
index 1c36e64..351edc6 100644
--- a/src/audio_output/input.c
+++ b/src/audio_output/input.c
@@ -211,6 +211,7 @@ aout_input_t *aout_InputNew (audio_output_t * p_aout,
             /* complete the filter chain if necessary */
             if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
                                              &p_input->i_nb_filters,
+                                             AOUT_MAX_FILTERS,
                                              &chain_input_format,
                                              &p_filter->fmt_in.audio ) < 0 )
             {
@@ -242,7 +243,7 @@ aout_input_t *aout_InputNew (audio_output_t * p_aout,
 
     /* complete the filter chain if necessary */
     if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
-                                     &p_input->i_nb_filters,
+                                     &p_input->i_nb_filters, AOUT_MAX_FILTERS,
                                      &chain_input_format,
                                      &chain_output_format ) < 0 )
     {
@@ -263,6 +264,8 @@ aout_input_t *aout_InputNew (audio_output_t * p_aout,
         }
         if (aout_FiltersCreatePipeline (p_aout, p_input->pp_resamplers,
                                         &p_input->i_nb_resamplers,
+                                        sizeof (p_input->pp_resamplers)
+                                          / sizeof (p_input->pp_resamplers[0]),
                                         &chain_output_format, outfmt) < 0)
         {
             msg_Err (p_aout, "cannot setup a resampling pipeline");
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index 925a4a2..10db22e 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -406,6 +406,8 @@ int aout_OutputNew (audio_output_t *aout, const audio_sample_format_t *fmtp)
     /* Create filters. */
     owner->nb_filters = 0;
     if (aout_FiltersCreatePipeline (aout, owner->filters, &owner->nb_filters,
+                                    sizeof (owner->filters)
+                                                  / sizeof (owner->filters[0]),
                                     &owner->mixer_format, &fmt) < 0)
     {
         msg_Err (aout, "couldn't create audio output pipeline");



More information about the vlc-commits mailing list