]> git.sesse.net Git - vlc/blobdiff - src/audio_output/filters.c
Separate string list and string list callback
[vlc] / src / audio_output / filters.c
index 64e3983496c6c7c7fcb8bc8c66320a28e502595e..fdaad8e979725e1a1bc3654ed78c0b024048ce58 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * filters.c : audio output filters management
  *****************************************************************************
- * Copyright (C) 2002-2007 the VideoLAN team
+ * Copyright (C) 2002-2007 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
 #include "aout_internal.h"
 #include <libvlc.h>
 
-block_t *aout_FilterBufferNew( filter_t *p_filter, int size )
-{
-    (void) p_filter;
-    return block_Alloc( size );
-}
-
 /*****************************************************************************
  * FindFilter: find an audio filter for a specific transformation
  *****************************************************************************/
-static filter_t * FindFilter( audio_output_t * p_aout,
-                              const audio_sample_format_t * p_input_format,
-                              const audio_sample_format_t * p_output_format )
+static filter_t * FindFilter( vlc_object_t *obj,
+                              const audio_sample_format_t *infmt,
+                              const audio_sample_format_t *outfmt )
 {
     static const char typename[] = "audio filter";
+    const char *type = "audio filter", *name = NULL;
     filter_t * p_filter;
 
-    p_filter = vlc_custom_create( p_aout, sizeof(*p_filter), typename );
+    p_filter = vlc_custom_create( obj, sizeof(*p_filter), typename );
 
     if ( p_filter == NULL ) return NULL;
 
-    memcpy( &p_filter->fmt_in.audio, p_input_format,
-            sizeof(audio_sample_format_t) );
-    p_filter->fmt_in.i_codec = p_input_format->i_format;
-    memcpy( &p_filter->fmt_out.audio, p_output_format,
-            sizeof(audio_sample_format_t) );
-    p_filter->fmt_out.i_codec = p_output_format->i_format;
-    p_filter->pf_audio_buffer_new = aout_FilterBufferNew;
-    p_filter->p_owner = NULL;
+    p_filter->fmt_in.audio = *infmt;
+    p_filter->fmt_in.i_codec = infmt->i_format;
+    p_filter->fmt_out.audio = *outfmt;
+    p_filter->fmt_out.i_codec = outfmt->i_format;
+
+    if( infmt->i_format == outfmt->i_format
+     && infmt->i_physical_channels == outfmt->i_physical_channels
+     && infmt->i_original_channels == outfmt->i_original_channels )
+    {
+        assert( infmt->i_rate != outfmt->i_rate );
+        type = "audio resampler";
+        name = "$audio-resampler";
+    }
 
-    p_filter->p_module = module_need( p_filter, "audio filter", NULL, false );
+    p_filter->p_module = module_need( p_filter, type, name, false );
     if ( p_filter->p_module == NULL )
     {
         vlc_object_release( p_filter );
@@ -91,9 +91,11 @@ static int SplitConversion( const audio_sample_format_t *restrict infmt,
 {
     *midfmt = *outfmt;
 
+    /* Lastly: resample (after format conversion and remixing) */
     if( infmt->i_rate != outfmt->i_rate )
         midfmt->i_rate = infmt->i_rate;
     else
+    /* Penultimately: remix channels (after format conversion) */
     if( infmt->i_physical_channels != outfmt->i_physical_channels
      || infmt->i_original_channels != outfmt->i_original_channels )
     {
@@ -101,25 +103,28 @@ static int SplitConversion( const audio_sample_format_t *restrict infmt,
         midfmt->i_original_channels = infmt->i_original_channels;
     }
     else
+    /* Second: convert linear to S16N as intermediate format */
+    if( AOUT_FMT_LINEAR( infmt ) )
     {
-        assert( infmt->i_format != outfmt->i_format );
-        if( AOUT_FMT_NON_LINEAR( infmt ) )
-        {
-            if( AOUT_FMT_NON_LINEAR( outfmt ) )
-                return -1; /* no indirect non-linear -> non-linear */
-            /* NOTE: our non-linear -> linear filters always output 32-bits */
-            midfmt->i_format = HAVE_FPU ? VLC_CODEC_FL32 : VLC_CODEC_FI32;
-        }
-        else
-            /* NOTE: Use S16N as intermediate. We have all conversions to S16N,
-             * and all useful conversions from S16N. TODO: FL32 if HAVE_FPU. */
-            midfmt->i_format = VLC_CODEC_S16N;
+        /* All conversion from linear to S16N must be supported directly. */
+        if( outfmt->i_format == VLC_CODEC_S16N )
+            return -1;
+        midfmt->i_format = VLC_CODEC_S16N;
+    }
+    else
+    /* First: convert non-linear to FI32 as intermediate format */
+    {
+        if( outfmt->i_format == VLC_CODEC_FI32 )
+            return -1;
+        midfmt->i_format = VLC_CODEC_FI32;
     }
 
+    assert( !AOUT_FMTS_IDENTICAL( infmt, midfmt ) );
     aout_FormatPrepare( midfmt );
-    return AOUT_FMTS_IDENTICAL( infmt, midfmt ) ? -1 : 0;
+    return 0;
 }
 
+#undef aout_FiltersCreatePipeline
 /**
  * Allocates audio format conversion filters
  * @param obj parent VLC object for new filters
@@ -129,7 +134,7 @@ static int SplitConversion( const audio_sample_format_t *restrict infmt,
  * @param outfmt output audio format
  * @return 0 on success, -1 on failure
  */
-int aout_FiltersCreatePipeline( audio_output_t *obj,
+int aout_FiltersCreatePipeline( vlc_object_t *obj,
                                 filter_t **filters,
                                 int *nb_filters,
                                 const audio_sample_format_t *restrict infmt,
@@ -201,7 +206,6 @@ void aout_FiltersDestroyPipeline( filter_t *const *filters, unsigned n )
         filter_t *p_filter = filters[i];
 
         module_unneed( p_filter, p_filter->p_module );
-        free( p_filter->p_owner );
         vlc_object_release( p_filter );
     }
 }
@@ -215,7 +219,7 @@ void aout_FiltersPlay( filter_t *const *pp_filters,
     block_t *p_block = *pp_block;
 
     /* TODO: use filter chain */
-    for( unsigned i = 0; i < i_nb_filters; i++ )
+    for( unsigned i = 0; (i < i_nb_filters) && (p_block != NULL); i++ )
     {
         filter_t * p_filter = pp_filters[i];