]> git.sesse.net Git - vlc/blobdiff - src/audio_output/input.c
modules: warn when the return value is unused. It helps tracking common memory leaks.
[vlc] / src / audio_output / input.c
index dd279cb76171ca1e01abd1dd612844da71741a09..be83a6f5737be1adf7f372c187c92813756fed7e 100644 (file)
@@ -40,6 +40,7 @@
 
 #include <vlc_input.h>
 #include <vlc_vout.h>                  /* for vout_Request */
+#include <vlc_modules.h>
 
 #include <vlc_aout.h>
 #include <vlc_filter.h>
@@ -223,15 +224,10 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
         var_Create( p_aout, "audio-replay-gain-peak-protection",
                     VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     }
-    if( var_Type( p_aout, "audio-time-stretch" ) == 0 )
-    {
-        var_Create( p_aout, "audio-time-stretch",
-                    VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-    }
 
     psz_filters = var_GetString( p_aout, "audio-filter" );
     psz_visual = var_GetString( p_aout, "audio-visual");
-    psz_scaletempo = var_GetBool( p_aout, "audio-time-stretch" ) ? strdup( "scaletempo" ) : NULL;
+    psz_scaletempo = var_InheritBool( p_aout, "audio-time-stretch" ) ? strdup( "scaletempo" ) : NULL;
 
     p_input->b_recycle_vout = psz_visual && *psz_visual;
 
@@ -343,7 +339,6 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
                          psz_parser );
 
                 free( p_filter->p_owner );
-                vlc_object_detach( p_filter );
                 vlc_object_release( p_filter );
 
                 psz_parser = psz_next;
@@ -364,7 +359,6 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
 
                     module_unneed( p_filter, p_filter->p_module );
                     free( p_filter->p_owner );
-                    vlc_object_detach( p_filter );
                     vlc_object_release( p_filter );
 
                     psz_parser = psz_next;
@@ -401,10 +395,6 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
         }
     }
 
-    /* Prepare hints for the buffer allocator. */
-    p_input->input_alloc.b_alloc = true;
-    p_input->input_alloc.i_bytes_per_sec = -1;
-
     /* Create resamplers. */
     if ( !AOUT_FMT_NON_LINEAR( &p_aout->mixer_format ) )
     {
@@ -425,11 +415,6 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
             return -1;
         }
 
-        aout_FiltersHintBuffers( p_aout, p_input->pp_resamplers,
-                                 p_input->i_nb_resamplers,
-                                 &p_input->input_alloc );
-        p_input->input_alloc.b_alloc = true;
-
         /* Setup the initial rate of the resampler */
         p_input->pp_resamplers[0]->fmt_in.audio.i_rate = p_input->input.i_rate;
     }
@@ -440,23 +425,10 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_
         p_input->p_playback_rate_filter = p_input->pp_resamplers[0];
     }
 
-    aout_FiltersHintBuffers( p_aout, p_input->pp_filters,
-                             p_input->i_nb_filters,
-                             &p_input->input_alloc );
-    p_input->input_alloc.b_alloc = true;
-
-    /* i_bytes_per_sec is still == -1 if no filters */
-    p_input->input_alloc.i_bytes_per_sec = __MAX(
-                                    p_input->input_alloc.i_bytes_per_sec,
-                                    (int)(p_input->input.i_bytes_per_frame
-                                     * p_input->input.i_rate
-                                     / p_input->input.i_frame_length) );
-
     ReplayGainSelect( p_aout, p_input );
 
     /* Success */
     p_input->b_error = false;
-    p_input->b_restart = false;
     p_input->i_last_input_rate = INPUT_RATE_DEFAULT;
 
     return 0;
@@ -493,48 +465,53 @@ int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input )
 }
 
 /*****************************************************************************
- * aout_InputPlay : play a buffer
+ * aout_InputCheckAndRestart : restart an input
  *****************************************************************************
- * This function must be entered with the input lock.
+ * This function must be entered with the input and mixer lock.
  *****************************************************************************/
-/* XXX Do not activate it !! */
-//#define AOUT_PROCESS_BEFORE_CHEKS
-int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
-                    aout_buffer_t * p_buffer, int i_input_rate )
+void aout_InputCheckAndRestart( aout_instance_t * p_aout, aout_input_t * p_input )
 {
-    mtime_t start_date;
+    AOUT_ASSERT_MIXER_LOCKED;
     AOUT_ASSERT_INPUT_LOCKED;
 
-    if( p_input->b_restart )
-    {
-        aout_fifo_t fifo;
-        uint8_t     *p_first_byte_to_mix;
-        bool        b_paused;
-        mtime_t     i_pause_date;
+    if( !p_input->b_restart )
+        return;
 
-        aout_lock_mixer( p_aout );
-        aout_lock_input_fifos( p_aout );
+    aout_lock_input_fifos( p_aout );
 
-        /* A little trick to avoid loosing our input fifo and properties */
+    /* A little trick to avoid loosing our input fifo and properties */
 
-        p_first_byte_to_mix = p_input->mixer.begin;
-        fifo = p_input->mixer.fifo;
-        b_paused = p_input->b_paused;
-        i_pause_date = p_input->i_pause_date;
+    uint8_t *p_first_byte_to_mix = p_input->mixer.begin;
+    aout_fifo_t fifo = p_input->mixer.fifo;
+    bool b_paused = p_input->b_paused;
+    mtime_t i_pause_date = p_input->i_pause_date;
 
-        aout_FifoInit( p_aout, &p_input->mixer.fifo, p_aout->mixer_format.i_rate );
+    aout_FifoInit( p_aout, &p_input->mixer.fifo, p_aout->mixer_format.i_rate );
 
-        aout_InputDelete( p_aout, p_input );
+    aout_InputDelete( p_aout, p_input );
 
-        aout_InputNew( p_aout, p_input, &p_input->request_vout );
-        p_input->mixer.begin = p_first_byte_to_mix;
-        p_input->mixer.fifo = fifo;
-        p_input->b_paused = b_paused;
-        p_input->i_pause_date = i_pause_date;
+    aout_InputNew( p_aout, p_input, &p_input->request_vout );
+    p_input->mixer.begin = p_first_byte_to_mix;
+    p_input->mixer.fifo = fifo;
+    p_input->b_paused = b_paused;
+    p_input->i_pause_date = i_pause_date;
 
-        aout_unlock_input_fifos( p_aout );
-        aout_unlock_mixer( p_aout );
-    }
+    p_input->b_restart = false;
+
+    aout_unlock_input_fifos( p_aout );
+}
+/*****************************************************************************
+ * aout_InputPlay : play a buffer
+ *****************************************************************************
+ * This function must be entered with the input lock.
+ *****************************************************************************/
+/* XXX Do not activate it !! */
+//#define AOUT_PROCESS_BEFORE_CHEKS
+int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
+                    aout_buffer_t * p_buffer, int i_input_rate )
+{
+    mtime_t start_date;
+    AOUT_ASSERT_INPUT_LOCKED;
 
     if( i_input_rate != INPUT_RATE_DEFAULT && p_input->p_playback_rate_filter == NULL )
     {
@@ -759,6 +736,14 @@ int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
     return 0;
 }
 
+bool aout_InputIsEmpty( aout_instance_t * p_aout, aout_input_t * p_input )
+{
+    aout_lock_input_fifos( p_aout );
+    bool is_empty = date_Get( &p_input->mixer.fifo.end_date ) <= mdate();
+    aout_unlock_input_fifos( p_aout );
+    return is_empty;
+}
+
 /*****************************************************************************
  * static functions
  *****************************************************************************/
@@ -813,7 +798,14 @@ static vout_thread_t *RequestVout( void *p_private,
 {
     aout_instance_t *p_aout = p_private;
     VLC_UNUSED(b_recycle);
-    return vout_Request( p_aout, p_vout, p_fmt );
+    vout_configuration_t cfg = {
+        .vout       = p_vout,
+        .input      = NULL,
+        .change_fmt = true,
+        .fmt        = p_fmt,
+        .dpb_size   = 1,
+    };
+    return vout_Request( p_aout, &cfg );
 }
 
 vout_thread_t *aout_filter_RequestVout( filter_t *p_filter,
@@ -834,8 +826,8 @@ vout_thread_t *aout_filter_RequestVout( filter_t *p_filter,
 static int ChangeFiltersString( aout_instance_t * p_aout, const char* psz_variable,
                                  const char *psz_name, bool b_add )
 {
-    return AoutChangeFilterString( VLC_OBJECT(p_aout), p_aout,
-                                   psz_variable, psz_name, b_add ) ? 1 : 0;
+    return aout_ChangeFilterString( VLC_OBJECT(p_aout), p_aout,
+                                    psz_variable, psz_name, b_add ) ? 1 : 0;
 }
 
 static int VisualizationCallback( vlc_object_t *p_this, char const *psz_cmd,