]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
stats: Add stream quality counters to Qt4 stastics by counting corrupted blocks and...
[vlc] / src / input / input.c
index a08542ecdcde160a318f6793c978d1bcd1f491f5..bdf91af2bceadf26fbf01a36793504aaa64167a1 100644 (file)
 #include "demux.h"
 #include "stream.h"
 #include "item.h"
-#include "ressource.h"
+#include "resource.h"
 
 #include <vlc_sout.h>
 #include "../stream_output/stream_output.h"
 
-#include <vlc_interface.h>
+#include <vlc_dialog.h>
 #include <vlc_url.h>
 #include <vlc_charset.h>
 #include <vlc_strings.h>
@@ -66,7 +66,7 @@ static  void *Run            ( vlc_object_t *p_this );
 static  void *RunAndDestroy  ( vlc_object_t *p_this );
 
 static input_thread_t * Create  ( vlc_object_t *, input_item_t *,
-                                  const char *, bool, input_ressource_t * );
+                                  const char *, bool, input_resource_t * );
 static  int             Init    ( input_thread_t *p_input );
 static void             End     ( input_thread_t *p_input );
 static void             MainLoop( input_thread_t *p_input );
@@ -117,7 +117,7 @@ static void input_ChangeState( input_thread_t *p_input, int i_state ); /* TODO f
  *****************************************************************************/
 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
                                const char *psz_header, bool b_quick,
-                               input_ressource_t *p_ressource )
+                               input_resource_t *p_resource )
 {
     static const char input_name[] = "input";
     input_thread_t *p_input = NULL;                 /* thread descriptor */
@@ -149,17 +149,6 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     if( !p_input->p )
         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_stats && !b_quick )
-    {
-        libvlc_priv_t *p_private = libvlc_priv( p_input->p_libvlc );
-        vlc_mutex_lock( &p_input->p_libvlc->p_stats->lock );
-        if( p_private->p_stats_computer == NULL )
-            p_private->p_stats_computer = p_input;
-        vlc_mutex_unlock( &p_input->p_libvlc->p_stats->lock );
-    }
-
     p_input->b_preparsing = b_quick;
     p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
 
@@ -211,11 +200,11 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     p_input->p->slave   = NULL;
 
     /* */
-    if( p_ressource )
-        p_input->p->p_ressource = p_ressource;
+    if( p_resource )
+        p_input->p->p_resource = p_resource;
     else
-        p_input->p->p_ressource = input_ressource_New();
-    input_ressource_SetInput( p_input->p->p_ressource, p_input );
+        p_input->p->p_resource = input_resource_New();
+    input_resource_SetInput( p_input->p->p_resource, p_input );
 
     /* Init control buffer */
     vlc_mutex_init( &p_input->p->lock_control );
@@ -322,8 +311,8 @@ static void Destructor( input_thread_t * p_input )
     stats_TimerDump( p_input, STATS_TIMER_INPUT_LAUNCHING );
     stats_TimerClean( p_input, STATS_TIMER_INPUT_LAUNCHING );
 
-    if( p_input->p->p_ressource )
-        input_ressource_Delete( p_input->p->p_ressource );
+    if( p_input->p->p_resource )
+        input_resource_Delete( p_input->p->p_resource );
 
     vlc_gc_decref( p_input->p->p_item );
 
@@ -351,11 +340,11 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
 /* */
 input_thread_t *__input_CreateThreadExtended( vlc_object_t *p_parent,
                                               input_item_t *p_item,
-                                              const char *psz_log, input_ressource_t *p_ressource )
+                                              const char *psz_log, input_resource_t *p_resource )
 {
     input_thread_t *p_input;
 
-    p_input = Create( p_parent, p_item, psz_log, false, p_ressource );
+    p_input = Create( p_parent, p_item, psz_log, false, p_resource );
     if( !p_input )
         return NULL;
 
@@ -412,13 +401,13 @@ int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
 
 /**
  * Initialize an input and initialize it to preparse the item
- * This function is blocking. It will only accept to parse files
+ * This function is blocking. It will only accept parsing regular files.
  *
  * \param p_parent a vlc_object_t
  * \param p_item an input item
  * \return VLC_SUCCESS or an error
  */
-int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
+int input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
 {
     input_thread_t *p_input;
 
@@ -451,17 +440,16 @@ void input_StopThread( input_thread_t *p_input )
     input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
 }
 
-input_ressource_t *input_DetachRessource( input_thread_t *p_input )
+input_resource_t *input_DetachResource( input_thread_t *p_input )
 {
     assert( p_input->b_dead );
 
-    input_ressource_t *p_ressource = p_input->p->p_ressource;
-    input_ressource_SetInput( p_ressource, NULL );
+    input_resource_SetInput( p_input->p->p_resource, NULL );
 
-    p_input->p->p_ressource = NULL;
+    input_resource_t *p_resource = input_resource_Detach( p_input->p->p_resource );
     p_input->p->p_sout = NULL;
 
-    return p_ressource;
+    return p_resource;
 }
 
 /**
@@ -700,12 +688,6 @@ static void MainLoopInterface( input_thread_t *p_input )
 static void MainLoopStatistic( input_thread_t *p_input )
 {
     stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
-    /* Are we the thread responsible for computing global stats ? */
-    if( libvlc_priv( p_input->p_libvlc )->p_stats_computer == p_input )
-    {
-        stats_ComputeGlobalStats( p_input->p_libvlc,
-                                  p_input->p_libvlc->p_stats );
-    }
     input_SendEventStatistics( p_input );
 }
 
@@ -819,6 +801,8 @@ static void InitStatistics( input_thread_t * p_input )
         INIT_COUNTER( demux_read, INTEGER, COUNTER );
         INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE );
         INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE );
+        INIT_COUNTER( demux_corrupted, INTEGER, COUNTER );
+        INIT_COUNTER( demux_discontinuity, INTEGER, COUNTER );
         INIT_COUNTER( played_abuffers, INTEGER, COUNTER );
         INIT_COUNTER( lost_abuffers, INTEGER, COUNTER );
         INIT_COUNTER( displayed_pictures, INTEGER, COUNTER );
@@ -846,7 +830,7 @@ static int InitSout( input_thread_t * p_input )
     char *psz = var_GetNonEmptyString( p_input, "sout" );
     if( psz && strncasecmp( p_input->p->p_item->psz_uri, "vlc:", 4 ) )
     {
-        p_input->p->p_sout  = input_ressource_RequestSout( p_input->p->p_ressource, NULL, psz );
+        p_input->p->p_sout  = input_resource_RequestSout( p_input->p->p_resource, NULL, psz );
         if( !p_input->p->p_sout )
         {
             input_ChangeState( p_input, ERROR_S );
@@ -867,7 +851,7 @@ static int InitSout( input_thread_t * p_input )
     }
     else
     {
-        input_ressource_RequestSout( p_input->p->p_ressource, NULL, NULL );
+        input_resource_RequestSout( p_input->p->p_resource, NULL, NULL );
     }
     free( psz );
 
@@ -891,7 +875,7 @@ static void InitTitle( input_thread_t * p_input )
     {
         /* Setup variables */
         input_ControlVarNavigation( p_input );
-        input_ControlVarTitle( p_input, 0 );
+        input_SendEventTitle( p_input, 0 );
     }
 
     /* Global flag */
@@ -1142,7 +1126,7 @@ static int Init( input_thread_t * p_input )
 #ifdef ENABLE_SOUT
     ret = InitSout( p_input );
     if( ret != VLC_SUCCESS )
-        return ret; /* FIXME: goto error; should be better here */
+        goto error_stats;
 #endif
 
     /* Create es out */
@@ -1217,12 +1201,8 @@ static int Init( input_thread_t * p_input )
         InputUpdateMeta( p_input, p_meta );
     }
 
-    if( !p_input->b_preparsing )
-    {
-        msg_Dbg( p_input, "`%s' successfully opened",
-                 p_input->p->p_item->psz_uri );
-
-    }
+    msg_Dbg( p_input, "`%s' successfully opened",
+             p_input->p->p_item->psz_uri );
 
     /* initialization is complete */
     input_ChangeState( p_input, PLAYING_S );
@@ -1236,14 +1216,17 @@ error:
         es_out_Delete( p_input->p->p_es_out );
     if( p_input->p->p_es_out_display )
         es_out_Delete( p_input->p->p_es_out_display );
-    if( p_input->p->p_ressource )
+    if( p_input->p->p_resource )
     {
         if( p_input->p->p_sout )
-            input_ressource_RequestSout( p_input->p->p_ressource,
+            input_resource_RequestSout( p_input->p->p_resource,
                                          p_input->p->p_sout, NULL );
-        input_ressource_SetInput( p_input->p->p_ressource, NULL );
+        input_resource_SetInput( p_input->p->p_resource, NULL );
     }
 
+#ifdef ENABLE_SOUT
+error_stats:
+#endif
     if( !p_input->b_preparsing && libvlc_stats( p_input ) )
     {
 #define EXIT_COUNTER( c ) do { if( p_input->p->counters.p_##c ) \
@@ -1321,17 +1304,8 @@ static void End( input_thread_t * p_input )
 #define CL_CO( c ) stats_CounterClean( p_input->p->counters.p_##c ); p_input->p->counters.p_##c = NULL;
         if( libvlc_stats( p_input ) )
         {
-            libvlc_priv_t *p_private = libvlc_priv( p_input->p_libvlc );
-
             /* make sure we are up to date */
             stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
-            if( p_private->p_stats_computer == p_input )
-            {
-                stats_ComputeGlobalStats( p_input->p_libvlc,
-                                          p_input->p_libvlc->p_stats );
-                /* FIXME how can it be thread safe ? */
-                p_private->p_stats_computer = NULL;
-            }
             CL_CO( read_bytes );
             CL_CO( read_packets );
             CL_CO( demux_read );
@@ -1364,9 +1338,9 @@ static void End( input_thread_t * p_input )
     }
 
     /* */
-    input_ressource_RequestSout( p_input->p->p_ressource,
+    input_resource_RequestSout( p_input->p->p_resource,
                                  p_input->p->p_sout, NULL );
-    input_ressource_SetInput( p_input->p->p_ressource, NULL );
+    input_resource_SetInput( p_input->p->p_resource, NULL );
 }
 
 /*****************************************************************************
@@ -1881,7 +1855,7 @@ static bool Control( input_thread_t *p_input, int i_type,
                     es_out_SetTime( p_input->p->p_es_out, -1 );
 
                     demux_Control( p_demux, DEMUX_SET_TITLE, i_title );
-                    input_ControlVarTitle( p_input, i_title );
+                    input_SendEventTitle( p_input, i_title );
                 }
             }
             else if( p_input->p->input.i_title > 0 )
@@ -1902,6 +1876,7 @@ static bool Control( input_thread_t *p_input, int i_type,
 
                     stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
                                     ACCESS_SET_TITLE, i_title );
+                    input_SendEventTitle( p_input, i_title );
                 }
             }
             break;
@@ -1947,6 +1922,7 @@ static bool Control( input_thread_t *p_input, int i_type,
                     es_out_SetTime( p_input->p->p_es_out, -1 );
 
                     demux_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
+                    input_SendEventSeekpoint( p_input, p_demux->info.i_title, i_seekpoint );
                 }
             }
             else if( p_input->p->input.i_title > 0 )
@@ -1981,6 +1957,7 @@ static bool Control( input_thread_t *p_input, int i_type,
 
                     stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
                                     ACCESS_SET_SEEKPOINT, i_seekpoint );
+                    input_SendEventSeekpoint( p_input, p_access->info.i_title, i_seekpoint );
                 }
             }
             break;
@@ -2414,9 +2391,8 @@ static int InputSourceInit( input_thread_t *p_input,
         {
             msg_Err( p_input, "open of `%s' failed: %s", psz_mrl,
                                                          msg_StackMsg() );
-            intf_UserFatal( VLC_OBJECT( p_input), false,
-                            _("Your input can't be opened"),
-                            _("VLC is unable to open the MRL '%s'."
+            dialog_Fatal( p_input, _("Your input can't be opened"),
+                          _("VLC is unable to open the MRL '%s'."
                             " Check the log for details."), psz_mrl );
             goto error;
         }
@@ -2424,6 +2400,7 @@ static int InputSourceInit( input_thread_t *p_input,
         /* Get infos from access */
         if( !p_input->b_preparsing )
         {
+            bool b_can_seek;
             access_Control( in->p_access,
                              ACCESS_GET_PTS_DELAY, &in->i_pts_delay );
 
@@ -2440,15 +2417,13 @@ static int InputSourceInit( input_thread_t *p_input,
             in->b_can_rate_control = in->b_can_pace_control;
             in->b_rescale_ts = true;
 
-            access_Control( in->p_access, ACCESS_CAN_PAUSE,
-                             &in->b_can_pause );
+            access_Control( in->p_access, ACCESS_CAN_PAUSE, &in->b_can_pause );
             var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
             var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
             var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control );
 
-            access_Control( in->p_access, ACCESS_CAN_SEEK,
-                             &val.b_bool );
-            var_Set( p_input, "can-seek", val );
+            access_Control( in->p_access, ACCESS_CAN_SEEK, &b_can_seek );
+            var_SetBool( p_input, "can-seek", b_can_seek );
         }
 
         /* */
@@ -2522,13 +2497,13 @@ static int InputSourceInit( input_thread_t *p_input,
         }
 
         {
-            /* Take access redirections into account */
+            /* Take access/stream redirections into account */
             char *psz_real_path;
             char *psz_buf = NULL;
-            if( in->p_access->psz_path )
+            if( in->p_stream->psz_path )
             {
                 const char *psz_a, *psz_d;
-                psz_buf = strdup( in->p_access->psz_path );
+                psz_buf = strdup( in->p_stream->psz_path );
                 input_SplitMRL( &psz_a, &psz_d, &psz_real_path, psz_buf );
             }
             else
@@ -2546,9 +2521,9 @@ static int InputSourceInit( input_thread_t *p_input,
         {
             msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
                      psz_access, psz_demux, psz_path );
-            intf_UserFatal( VLC_OBJECT( p_input ), false,
-                            _("VLC can't recognize the input's format"),
-                            _("The format of '%s' cannot be detected. "
+            dialog_Fatal( VLC_OBJECT( p_input ),
+                          _("VLC can't recognize the input's format"),
+                          _("The format of '%s' cannot be detected. "
                             "Have a look at the log for details."), psz_mrl );
             goto error;
         }