]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
fileinfo.hpp: we need to use b_stats in Update()
[vlc] / src / input / input.c
index 69c4f8c7d8ed3b8a3b0f88a64c26a6ab3921fb80..b733e31ba01d3ddd57f09799716e2ea7154a9d97 100644 (file)
@@ -19,7 +19,7 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -46,7 +46,8 @@
 static  int Run  ( input_thread_t *p_input );
 static  int RunAndClean  ( input_thread_t *p_input );
 
-static input_thread_t * Create  ( vlc_object_t *, input_item_t *, vlc_bool_t );
+static input_thread_t * Create  ( vlc_object_t *, input_item_t *, char *,
+                                  vlc_bool_t );
 static  int             Init    ( input_thread_t *p_input, vlc_bool_t b_quick );
 static void             Error   ( input_thread_t *p_input );
 static void             End     ( input_thread_t *p_input );
@@ -63,8 +64,6 @@ static int  UpdateMeta( input_thread_t *, vlc_bool_t );
 
 static void UpdateItemLength( input_thread_t *, int64_t i_length, vlc_bool_t );
 
-static void ParseOption( input_thread_t *p_input, const char *psz_option );
-
 static void DecodeUrl( char * );
 static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
 
@@ -104,9 +103,9 @@ static vlc_meta_t *InputMetaUser( input_thread_t *p_input );
  * TODO complete this list (?)
  *****************************************************************************/
 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
-                               vlc_bool_t b_quick )
+                               char *psz_header, vlc_bool_t b_quick )
 {
-    input_thread_t *p_input;                        /* thread descriptor */
+    input_thread_t *p_input = NULL;                 /* thread descriptor */
     vlc_value_t val;
     int i;
 
@@ -117,6 +116,7 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
         msg_Err( p_parent, "out of memory" );
         return NULL;
     }
+    p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
 
     /* Init Common fields */
     p_input->b_eof = VLC_FALSE;
@@ -150,6 +150,8 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     p_input->input.b_eof = VLC_FALSE;
     p_input->input.i_cr_average = 0;
 
+    stats_ReinitInputStats( p_item->p_stats );
+
     /* No slave */
     p_input->i_slave = 0;
     p_input->slave   = NULL;
@@ -162,7 +164,7 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     vlc_mutex_lock( &p_item->lock );
     for( i = 0; i < p_item->i_options; i++ )
     {
-        ParseOption( p_input, p_item->ppsz_options[i] );
+        var_OptionParse( p_input, p_item->ppsz_options[i] );
     }
     vlc_mutex_unlock( &p_item->lock );
 
@@ -221,8 +223,8 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     }
 
     /* Remove 'Now playing' info as it is probably outdated */
-    input_Control( p_input, INPUT_DEL_INFO, _("Meta-information"),
-                    VLC_META_NOW_PLAYING );
+    input_Control( p_input, INPUT_DEL_INFO, _(VLC_META_INFO_CAT),
+                   VLC_META_NOW_PLAYING );     /* ? Don't translate as it might has been copied ? */
 
     return p_input;
 }
@@ -237,11 +239,19 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
  */
 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
                                       input_item_t *p_item )
+{
+    return __input_CreateThread2( p_parent, p_item, NULL );
+}
 
+
+/* Gruik ! */
+input_thread_t *__input_CreateThread2( vlc_object_t *p_parent,
+                                       input_item_t *p_item,
+                                       char *psz_header )
 {
-    input_thread_t *p_input;                        /* thread descriptor */
+    input_thread_t *p_input = NULL;      /* thread descriptor */
 
-    p_input = Create( p_parent, p_item, VLC_FALSE );
+    p_input = Create( p_parent, p_item, psz_header, VLC_FALSE );
     /* Now we can attach our new input */
     vlc_object_attach( p_input, p_parent );
 
@@ -266,19 +276,21 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
  * \param p_parent a vlc_object
  * \param p_item an input item
  * \param b_block should we block until read is finished ?
+ * \return the input object id if non blocking, an error code else
  */
-void __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
+int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
                    vlc_bool_t b_block )
 {
-    input_thread_t *p_input;                        /* thread descriptor */
+    input_thread_t *p_input = NULL;         /* thread descriptor */
 
-    p_input = Create( p_parent, p_item, VLC_FALSE );
+    p_input = Create( p_parent, p_item, NULL, VLC_FALSE );
     /* Now we can attach our new input */
     vlc_object_attach( p_input, p_parent );
 
     if( b_block )
     {
         RunAndClean( p_input );
+        return VLC_SUCCESS;
     }
     else
     {
@@ -288,9 +300,10 @@ void __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
             msg_Err( p_input, "cannot create input thread" );
             vlc_object_detach( p_input );
             vlc_object_destroy( p_input );
-            return;
+            return VLC_EGENERIC;
         }
     }
+    return p_input->i_object_id;
 }
 
 /**
@@ -303,10 +316,12 @@ void __input_Read( 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;                        /* thread descriptor */
+    input_thread_t *p_input = NULL;           /* thread descriptor */
 
     /* Allocate descriptor */
-    p_input = Create( p_parent, p_item, VLC_TRUE );
+    p_input = Create( p_parent, p_item, NULL, VLC_TRUE );
+    p_input->i_flags |= OBJECT_FLAGS_NODBG;
+    p_input->i_flags |= OBJECT_FLAGS_NOINTERACT;
 
     /* Now we can attach our new input */
     vlc_object_attach( p_input, p_parent );
@@ -400,7 +415,6 @@ void input_DestroyThread( input_thread_t *p_input )
  *****************************************************************************/
 static int Run( input_thread_t *p_input )
 {
-
     /* Signal that the thread is launched */
     vlc_thread_ready( p_input );
 
@@ -669,6 +683,32 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
      */
     if( !b_quick )
     {
+        /* Prepare statistics */
+        counter_t *p_counter;
+        stats_Create( p_input, "read_bytes", STATS_READ_BYTES,
+                      VLC_VAR_INTEGER, STATS_COUNTER );
+        stats_Create( p_input, "read_packets", STATS_READ_PACKETS,
+                      VLC_VAR_INTEGER, STATS_COUNTER );
+        stats_Create( p_input, "demux_read", STATS_DEMUX_READ,
+                      VLC_VAR_INTEGER, STATS_COUNTER );
+        stats_Create( p_input, "input_bitrate", STATS_INPUT_BITRATE,
+                      VLC_VAR_FLOAT, STATS_DERIVATIVE );
+        stats_Create( p_input, "demux_bitrate", STATS_DEMUX_BITRATE,
+                      VLC_VAR_FLOAT,  STATS_DERIVATIVE );
+
+        p_counter = stats_CounterGet( p_input, p_input->i_object_id,
+                                      STATS_INPUT_BITRATE );
+        if( p_counter ) p_counter->update_interval = 1000000;
+        p_counter = stats_CounterGet( p_input, p_input->i_object_id,
+                                      STATS_DEMUX_BITRATE );
+        if( p_counter ) p_counter->update_interval = 1000000;
+
+        stats_Create( p_input, "played_abuffers", STATS_PLAYED_ABUFFERS,
+                      VLC_VAR_INTEGER, STATS_COUNTER );
+        stats_Create( p_input, "lost_abuffers", STATS_LOST_ABUFFERS,
+                      VLC_VAR_INTEGER, STATS_COUNTER );
+
+        /* handle sout */
         psz = var_GetString( p_input, "sout" );
         if( *psz && strncasecmp( p_input->input.p_item->psz_uri, "vlc:", 4 ) )
         {
@@ -1856,15 +1896,15 @@ static int  UpdateMeta( input_thread_t *p_input, vlc_bool_t b_quick )
             msg_Dbg( p_input, "  - '%s' = '%s'",
                      _(p_meta->name[i]), p_meta->value[i] );
 
-        if( !strcmp(p_meta->name[i], VLC_META_TITLE) && p_meta->value[i] &&
+        if( !strcmp(p_meta->name[i], _(VLC_META_TITLE)) && p_meta->value[i] &&
             !p_input->input.p_item->b_fixed_name )
             input_Control( p_input, INPUT_SET_NAME, p_meta->value[i] );
 
-        if( !strcmp( p_meta->name[i], VLC_META_AUTHOR ) )
+        if( !strcmp( p_meta->name[i], _(VLC_META_AUTHOR) ) )
             input_Control( p_input, INPUT_ADD_INFO, _("General"),
-                           _("Author"), p_meta->value[i] );
+                           _(VLC_META_AUTHOR), p_meta->value[i] );
 
-        input_Control( p_input, INPUT_ADD_INFO, _("Meta-information"),
+        input_Control( p_input, INPUT_ADD_INFO, _(VLC_META_INFO_CAT),
                       _(p_meta->name[i]), "%s", p_meta->value[i] );
     }
 
@@ -2322,7 +2362,7 @@ static vlc_meta_t *InputMetaUser( input_thread_t *p_input )
 #define GET_META( c, s ) \
     var_Get( p_input, (s), &val );  \
     if( *val.psz_string )       \
-        vlc_meta_Add( p_meta, c, val.psz_string ); \
+        vlc_meta_Add( p_meta, _(c), val.psz_string ); \
     free( val.psz_string )
 
     GET_META( VLC_META_TITLE, "meta-title" );
@@ -2377,138 +2417,6 @@ static void DecodeUrl( char *psz )
     if( dup ) free( dup );
 }
 
-/*****************************************************************************
- * ParseOption: parses the options for the input
- *****************************************************************************
- * This function parses the input (config) options and creates their associated
- * object variables.
- * Options are of the form "[no[-]]foo[=bar]" where foo is the option name and
- * bar is the value of the option.
- *****************************************************************************/
-static void ParseOption( input_thread_t *p_input, const char *psz_option )
-{
-    char *psz_name = (char *)psz_option;
-    char *psz_value = strchr( psz_option, '=' );
-    int  i_name_len, i_type;
-    vlc_bool_t b_isno = VLC_FALSE;
-    vlc_value_t val;
-
-    if( psz_value ) i_name_len = psz_value - psz_option;
-    else i_name_len = strlen( psz_option );
-
-    /* It's too much of an hassle to remove the ':' when we parse
-     * the cmd line :) */
-    if( i_name_len && *psz_name == ':' )
-    {
-        psz_name++;
-        i_name_len--;
-    }
-
-    if( i_name_len == 0 ) return;
-
-    psz_name = strndup( psz_name, i_name_len );
-    if( psz_value ) psz_value++;
-
-    /* FIXME: :programs should be handled generically */
-    if( !strcmp( psz_name, "programs" ) )
-        i_type = VLC_VAR_LIST;
-    else
-        i_type = config_GetType( p_input, psz_name );
-
-    if( !i_type && !psz_value )
-    {
-        /* check for "no-foo" or "nofoo" */
-        if( !strncmp( psz_name, "no-", 3 ) )
-        {
-            memmove( psz_name, psz_name + 3, strlen(psz_name) + 1 - 3 );
-        }
-        else if( !strncmp( psz_name, "no", 2 ) )
-        {
-            memmove( psz_name, psz_name + 2, strlen(psz_name) + 1 - 2 );
-        }
-        else goto cleanup;           /* Option doesn't exist */
-
-        b_isno = VLC_TRUE;
-        i_type = config_GetType( p_input, psz_name );
-
-        if( !i_type ) goto cleanup;  /* Option doesn't exist */
-    }
-    else if( !i_type ) goto cleanup; /* Option doesn't exist */
-
-    if( ( i_type != VLC_VAR_BOOL ) &&
-        ( !psz_value || !*psz_value ) ) goto cleanup; /* Invalid value */
-
-    /* Create the variable in the input object.
-     * Children of the input object will be able to retreive this value
-     * thanks to the inheritance property of the object variables. */
-    var_Create( p_input, psz_name, i_type );
-
-    switch( i_type )
-    {
-    case VLC_VAR_BOOL:
-        val.b_bool = !b_isno;
-        break;
-
-    case VLC_VAR_INTEGER:
-        val.i_int = strtol( psz_value, NULL, 0 );
-        break;
-
-    case VLC_VAR_FLOAT:
-        val.f_float = atof( psz_value );
-        break;
-
-    case VLC_VAR_STRING:
-    case VLC_VAR_MODULE:
-    case VLC_VAR_FILE:
-    case VLC_VAR_DIRECTORY:
-        val.psz_string = psz_value;
-        break;
-
-    case VLC_VAR_LIST:
-    {
-        char *psz_orig, *psz_var;
-        vlc_list_t *p_list = malloc(sizeof(vlc_list_t));
-        val.p_list = p_list;
-        p_list->i_count = 0;
-
-        psz_var = psz_orig = strdup(psz_value);
-        while( psz_var && *psz_var )
-        {
-            char *psz_item = psz_var;
-            vlc_value_t val2;
-            while( *psz_var && *psz_var != ',' ) psz_var++;
-            if( *psz_var == ',' )
-            {
-                *psz_var = '\0';
-                psz_var++;
-            }
-            val2.i_int = strtol( psz_item, NULL, 0 );
-            INSERT_ELEM( p_list->p_values, p_list->i_count,
-                         p_list->i_count, val2 );
-            /* p_list->i_count is incremented twice by INSERT_ELEM */
-            p_list->i_count--;
-            INSERT_ELEM( p_list->pi_types, p_list->i_count,
-                         p_list->i_count, VLC_VAR_INTEGER );
-        }
-        if( psz_orig ) free( psz_orig );
-        break;
-    }
-
-    default:
-        goto cleanup;
-        break;
-    }
-
-    var_Set( p_input, psz_name, val );
-
-    msg_Dbg( p_input, "set input option: %s to %s", psz_name,
-             psz_value ? psz_value : ( val.b_bool ? "true" : "false") );
-
-  cleanup:
-    if( psz_name ) free( psz_name );
-    return;
-}
-
 /*****************************************************************************
  * MRLSplit: parse the access, demux and url part of the
  *           Media Resource Locator.