]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
* src/input/input.c: fixed memory leak.
[vlc] / src / input / input.c
index e0c9e4c4012e680985e095703e29c70cc5225eed..2cc905fba1b88d276eec3d364b727f5b493b796d 100644 (file)
@@ -120,6 +120,19 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
         msg_Err( p_parent, "out of memory" );
         return NULL;
     }
+
+    /* One "randomly" selected input thread is responsible for computing
+     * the global stats. Check if there is already someone doing this */
+    if( p_input->p_libvlc->p_playlist->p_stats && !b_quick )
+    {
+        vlc_mutex_lock( &p_input->p_libvlc->p_playlist->p_stats->lock );
+        if( p_input->p_libvlc->p_playlist->p_stats_computer == NULL )
+        {
+            p_input->p_libvlc->p_playlist->p_stats_computer = p_input;
+        }
+        vlc_mutex_unlock( &p_input->p_libvlc->p_playlist->p_stats->lock );
+    }
+
     p_input->b_preparsing = b_quick;
     p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
 
@@ -157,7 +170,13 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
 
     if( !p_input->input.p_item->p_meta )
         p_input->input.p_item->p_meta = vlc_meta_New();
-    stats_ReinitInputStats( p_item->p_stats );
+
+    if( !p_item->p_stats )
+    {
+        p_item->p_stats = (input_stats_t*)malloc( sizeof( input_stats_t ) );
+        vlc_mutex_init( p_input, &p_item->p_stats->lock );
+        stats_ReinitInputStats( p_item->p_stats );
+    }
 
     /* No slave */
     p_input->i_slave = 0;
@@ -515,6 +534,7 @@ static int RunAndClean( input_thread_t *p_input )
 static void MainLoop( input_thread_t *p_input )
 {
     int64_t i_intf_update = 0;
+    int i_updates = 0;
     while( !p_input->b_die && !p_input->b_error && !p_input->input.b_eof )
     {
         vlc_bool_t b_force_update = VLC_FALSE;
@@ -662,6 +682,17 @@ static void MainLoop( input_thread_t *p_input )
             var_SetBool( p_input, "intf-change", VLC_TRUE );
             i_intf_update = mdate() + I64C(150000);
         }
+        /* 150ms * 8 = ~ 1 second */
+        if( ++i_updates % 8 == 0 )
+        {
+            stats_ComputeInputStats( p_input, p_input->input.p_item->p_stats );
+            /* Are we the thread responsible for computing global stats ? */
+            if( p_input->p_libvlc->p_playlist->p_stats_computer == p_input )
+            {
+                stats_ComputeGlobalStats( p_input->p_libvlc->p_playlist,
+                                     p_input->p_libvlc->p_playlist->p_stats );
+            }
+        }
     }
 }
 
@@ -901,6 +932,7 @@ static int Init( input_thread_t * p_input )
                     {
                         TAB_APPEND( p_input->i_slave, p_input->slave, sub );
                     }
+                    else free( sub );
                 }
                 free( subs[i] );
             }
@@ -936,6 +968,7 @@ static int Init( input_thread_t * p_input )
                 {
                     TAB_APPEND( p_input->i_slave, p_input->slave, slave );
                 }
+                else free( slave );
                 psz = psz_delim;
             }
         }
@@ -1119,6 +1152,14 @@ static void End( input_thread_t * p_input )
 #define CL_CO( c ) stats_CounterClean( p_input->counters.p_##c ); p_input->counters.p_##c = NULL;
     if( p_input->p_libvlc->b_stats )
     {
+        /* make sure we are up to date */
+        stats_ComputeInputStats( p_input, p_input->input.p_item->p_stats );
+        if( p_input->p_libvlc->p_playlist->p_stats_computer == p_input )
+        {
+            stats_ComputeGlobalStats( p_input->p_libvlc->p_playlist,
+                                      p_input->p_libvlc->p_playlist->p_stats );
+            p_input->p_libvlc->p_playlist->p_stats_computer = NULL;
+        }
         vlc_mutex_lock( &p_input->counters.counters_lock );
         CL_CO( read_bytes );
         CL_CO( read_packets );
@@ -1665,6 +1706,7 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
                 }
                 else
                 {
+                    free( slave );
                     msg_Warn( p_input, "failed to add %s as slave",
                               val.psz_string );
                 }
@@ -1931,8 +1973,8 @@ static int InputSourceInit( input_thread_t *p_input,
     {
         psz_path = psz_mrl;
         msg_Dbg( p_input, "trying to pre-parse %s",  psz_path );
-        psz_demux = strdup( "" );
-        psz_access = strdup( "file" );
+        psz_demux = "";
+        psz_access = "file";
     }
 
     if( in->p_demux )
@@ -2249,7 +2291,6 @@ static void InputMetaUser( input_thread_t *p_input )
     free( val.psz_string )
 
     GET_META( title, "meta-title" );
-    GET_META( author, "meta-author" );
     GET_META( artist, "meta-artist" );
     GET_META( genre, "meta-genre" );
     GET_META( copyright, "meta-copyright" );
@@ -2484,6 +2525,7 @@ vlc_bool_t input_AddSubtitles( input_thread_t *p_input, char *psz_subtitle,
             var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
         }
     }
+    else free( sub );
 
     return VLC_TRUE;
 }