]> git.sesse.net Git - vlc/blobdiff - src/audio_output/filters.c
Removed duplicated code in audio intf.c
[vlc] / src / audio_output / filters.c
index 6bbaae12462f450771976471125a617774d2d72b..2bf64e7ca8bf7eadefbdc5281a128ff9f7ec4f6e 100644 (file)
@@ -28,8 +28,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
-#include <vlc_interface.h>
+#include <vlc_common.h>
+#include <vlc_dialog.h>
 
 #ifdef HAVE_ALLOCA_H
 #   include <alloca.h>
@@ -37,6 +37,7 @@
 
 #include <vlc_aout.h>
 #include "aout_internal.h"
+#include <libvlc.h>
 
 /*****************************************************************************
  * FindFilter: find an audio filter for a specific transformation
@@ -45,8 +46,11 @@ static aout_filter_t * FindFilter( aout_instance_t * p_aout,
                              const audio_sample_format_t * p_input_format,
                              const audio_sample_format_t * p_output_format )
 {
-    aout_filter_t * p_filter = vlc_object_create( p_aout,
-                                                  sizeof(aout_filter_t) );
+    static const char typename[] = "audio output";
+    aout_filter_t * p_filter;
+
+    p_filter = vlc_custom_create( p_aout, sizeof(*p_filter),
+                                  VLC_OBJECT_GENERIC, typename );
 
     if ( p_filter == NULL ) return NULL;
     vlc_object_attach( p_filter, p_aout );
@@ -54,7 +58,7 @@ static aout_filter_t * FindFilter( aout_instance_t * p_aout,
     memcpy( &p_filter->input, p_input_format, sizeof(audio_sample_format_t) );
     memcpy( &p_filter->output, p_output_format,
             sizeof(audio_sample_format_t) );
-    p_filter->p_module = module_Need( p_filter, "audio filter", NULL, 0 );
+    p_filter->p_module = module_need( p_filter, "audio filter", NULL, false );
     if ( p_filter->p_module == NULL )
     {
         vlc_object_detach( p_filter );
@@ -120,7 +124,7 @@ static int SplitConversion( const audio_sample_format_t * p_input_format,
 
 static void ReleaseFilter( aout_filter_t * p_filter )
 {
-    module_Unneed( p_filter, p_filter->p_module );
+    module_unneed( p_filter, p_filter->p_module );
     vlc_object_detach( p_filter );
     vlc_object_release( p_filter );
 }
@@ -152,9 +156,9 @@ int aout_FiltersCreatePipeline( aout_instance_t * p_aout,
     if( *pi_nb_filters + 1 > AOUT_MAX_FILTERS )
     {
         msg_Err( p_aout, "max filter reached (%d)", AOUT_MAX_FILTERS );
-        intf_UserFatal( p_aout, false, _("Audio filtering failed"),
-                        _("The maximum number of filters (%d) was reached."),
-                        AOUT_MAX_FILTERS );
+        dialog_Fatal( p_aout, _("Audio filtering failed"),
+                      _("The maximum number of filters (%d) was reached."),
+                      AOUT_MAX_FILTERS );
         return -1;
     }
 
@@ -199,9 +203,9 @@ int aout_FiltersCreatePipeline( aout_instance_t * p_aout,
     {
         ReleaseFilter( pp_filters[0] );
         msg_Err( p_aout, "max filter reached (%d)", AOUT_MAX_FILTERS );
-        intf_UserFatal( p_aout, false, _("Audio filtering failed"),
-                        _("The maximum number of filters (%d) was reached."),
-                        AOUT_MAX_FILTERS );
+        dialog_Fatal( p_aout, _("Audio filtering failed"),
+                      _("The maximum number of filters (%d) was reached."),
+                      AOUT_MAX_FILTERS );
         return -1;
     }
     pp_filters[1] = FindFilter( p_aout, &pp_filters[0]->output,
@@ -222,9 +226,9 @@ int aout_FiltersCreatePipeline( aout_instance_t * p_aout,
         {
             ReleaseFilter( pp_filters[0] );
             msg_Err( p_aout, "max filter reached (%d)", AOUT_MAX_FILTERS );
-            intf_UserFatal( p_aout, false, _("Audio filtering failed"),
-                            _("The maximum number of filters (%d) was reached."),
-                            AOUT_MAX_FILTERS );
+            dialog_Fatal( p_aout, _("Audio filtering failed"),
+                          _("The maximum number of filters (%d) was reached."),
+                          AOUT_MAX_FILTERS );
             return -1;
         }
         pp_filters[1] = FindFilter( p_aout, &pp_filters[0]->output,
@@ -271,9 +275,12 @@ void aout_FiltersDestroyPipeline( aout_instance_t * p_aout,
 
     for ( i = 0; i < i_nb_filters; i++ )
     {
-        module_Unneed( pp_filters[i], pp_filters[i]->p_module );
-        vlc_object_detach( pp_filters[i] );
-        vlc_object_release( pp_filters[i] );
+        aout_filter_t *p_filter = pp_filters[i];
+
+        module_unneed( p_filter, p_filter->p_module );
+        free( p_filter->p_owner );
+        vlc_object_detach( p_filter );
+        vlc_object_release( p_filter );
     }
 }
 
@@ -330,7 +337,7 @@ void aout_FiltersPlay( aout_instance_t * p_aout,
 {
     int i;
 
-    for ( i = 0; i < i_nb_filters; i++ )
+    for( i = 0; i < i_nb_filters; i++ )
     {
         aout_filter_t * p_filter = pp_filters[i];
         aout_buffer_t * p_output_buffer;
@@ -339,28 +346,44 @@ void aout_FiltersPlay( aout_instance_t * p_aout,
          * p_filter->output.i_rate / p_filter->input.i_rate) so we need
          * slightly bigger buffers. */
         aout_BufferAlloc( &p_filter->output_alloc,
-            ((mtime_t)(*pp_input_buffer)->i_nb_samples + 2)
-            * 1000000 / p_filter->input.i_rate,
-            *pp_input_buffer, p_output_buffer );
-        if ( p_output_buffer == NULL )
-        {
-            msg_Err( p_aout, "out of memory" );
+                          ((mtime_t)(*pp_input_buffer)->i_nb_samples + 2)
+                          * 1000000 / p_filter->input.i_rate,
+                          *pp_input_buffer, p_output_buffer );
+        if( p_output_buffer == NULL )
             return;
-        }
+
         /* Please note that p_output_buffer->i_nb_samples & i_nb_bytes
          * shall be set by the filter plug-in. */
+        if( (*pp_input_buffer)->i_nb_samples > 0 )
+        {
+            p_filter->pf_do_work( p_aout, p_filter, *pp_input_buffer,
+                                  p_output_buffer );
+        }
+        else
+        {
+            p_output_buffer->i_nb_bytes = 0;
+            p_output_buffer->i_nb_samples = 0;
+        }
 
-        p_filter->pf_do_work( p_aout, p_filter, *pp_input_buffer,
-                              p_output_buffer );
-
-        if ( !p_filter->b_in_place )
+        if( !p_filter->b_in_place )
         {
             aout_BufferFree( *pp_input_buffer );
             *pp_input_buffer = p_output_buffer;
         }
-
-        if( p_output_buffer->i_nb_samples <= 0 )
-            break;
     }
+
+    assert( (*pp_input_buffer) == NULL || (*pp_input_buffer)->i_alloc_type != AOUT_ALLOC_STACK );
+}
+
+/*****************************************************************************
+ * aout_filter_RequestVout
+ *****************************************************************************/
+vout_thread_t *aout_filter_RequestVout( aout_filter_t *p_filter,
+                                        vout_thread_t *p_vout, video_format_t *p_fmt )
+{
+    if( !p_filter->request_vout.pf_request_vout )
+        return NULL;
+    return p_filter->request_vout.pf_request_vout( p_filter->request_vout.p_private,
+                                                   p_vout, p_fmt, true );
 }