]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
* all: added a new skin text variable "$S" to get the audio sample rate
[vlc] / src / input / input.c
index d7f47c8fade20f0131ab39e7c6e7d77096390bdd..ca3c51c0dcbce4ac0a0159cce8a973341d7e70b5 100644 (file)
@@ -64,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 *);
 
@@ -166,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 );
 
@@ -209,7 +207,8 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
                      }
                      else if( !strncmp( psz_start, "time=", 5 ) )
                      {
-                         p_seekpoint->i_time_offset = atoll(psz_start + 5) * 1000000;
+                         p_seekpoint->i_time_offset = atoll(psz_start + 5) *
+                                                        1000000;
                      }
                      psz_start = psz_end + 1;
                 }
@@ -225,8 +224,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;
 }
@@ -322,6 +321,8 @@ int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
 
     /* Allocate descriptor */
     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 );
@@ -331,10 +332,6 @@ int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
     /* Clean up master */
     InputSourceClean( p_input, &p_input->input );
 
-    /* Kill access and demux */
-    if( p_input->input.p_access ) p_input->input.p_access->b_die = VLC_TRUE;
-    if( p_input->input.p_demux ) p_input->input.p_access->b_die = VLC_TRUE;
-
     /* Unload all modules */
     if( p_input->p_es_out ) input_EsOutDelete( p_input->p_es_out );
 
@@ -685,22 +682,28 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
     {
         /* Prepare statistics */
         counter_t *p_counter;
-        stats_Create( p_input, "read_bytes", VLC_VAR_INTEGER, STATS_COUNTER );
-        stats_Create( p_input, "read_packets", VLC_VAR_INTEGER, STATS_COUNTER );
-        stats_Create( p_input, "demux_read", VLC_VAR_INTEGER, STATS_COUNTER );
-        stats_Create( p_input, "input_bitrate", VLC_VAR_FLOAT,
-                               STATS_DERIVATIVE );
-        stats_Create( p_input, "demux_bitrate", VLC_VAR_FLOAT,
-                               STATS_DERIVATIVE );
+        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,
-                                      "input_bitrate" );
+                                      STATS_INPUT_BITRATE );
         if( p_counter ) p_counter->update_interval = 1000000;
         p_counter = stats_CounterGet( p_input, p_input->i_object_id,
-                                      "demux_bitrate" );
+                                      STATS_DEMUX_BITRATE );
         if( p_counter ) p_counter->update_interval = 1000000;
 
-        stats_Create( p_input, "played_abuffers", VLC_VAR_INTEGER, STATS_COUNTER );
-        stats_Create( p_input, "lost_abuffers", VLC_VAR_INTEGER, STATS_COUNTER );
+        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" );
@@ -723,6 +726,9 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
     es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
     es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
 
+    var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
+    var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
+
     if( InputSourceInit( p_input, &p_input->input,
                          p_input->input.p_item->psz_uri, NULL, b_quick ) )
     {
@@ -1570,7 +1576,7 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
                 {
                     input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
                     es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
-                    
+
                     access2_Control( p_access, ACCESS_SET_TITLE, i_title );
                     stream_AccessReset( p_input->input.p_stream );
                 }
@@ -1611,7 +1617,7 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
                 {
                     input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
                     es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
-                    
+
                     demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
                 }
             }
@@ -1647,8 +1653,9 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
                 {
                     input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
                     es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
-                    
-                    access2_Control( p_access, ACCESS_SET_SEEKPOINT, i_seekpoint );
+
+                    access2_Control( p_access, ACCESS_SET_SEEKPOINT,
+                                    i_seekpoint );
                     stream_AccessReset( p_input->input.p_stream );
                 }
             }
@@ -1890,15 +1897,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] );
     }
 
@@ -1965,7 +1972,7 @@ static void UpdateItemLength( input_thread_t *p_input, int64_t i_length,
 static input_source_t *InputSourceNew( input_thread_t *p_input )
 {
     input_source_t *in = (input_source_t*) malloc( sizeof( input_source_t ) );
-   
+
     if( !in )
     {
         msg_Err( p_input, "out of memory for new input source" );
@@ -2037,7 +2044,7 @@ static int InputSourceInit( input_thread_t *p_input,
             {
                 psz_demux = psz_var_demux;
 
-                msg_Dbg( p_input, "Enforce demux ` %s'", psz_demux );
+                msg_Dbg( p_input, "enforced demux ` %s'", psz_demux );
             }
             else if( psz_var_demux )
             {
@@ -2055,7 +2062,7 @@ static int InputSourceInit( input_thread_t *p_input,
     else
     {
         psz_path = psz_mrl;
-        msg_Dbg( p_input, "trying to preparse %s",  psz_path );
+        msg_Dbg( p_input, "trying to pre-parse %s",  psz_path );
         psz_demux = strdup( "" );
         psz_access = strdup( "file" );
     }
@@ -2117,7 +2124,11 @@ static int InputSourceInit( input_thread_t *p_input,
             if( psz_dup ) free( psz_dup );
             psz_dup = strdup( psz_mrl );
             psz_access = "";
-            psz_demux = "";
+            if( psz_forced_demux && *psz_forced_demux )
+            {
+                psz_demux = psz_forced_demux;
+            }
+            else psz_demux = "";
             psz_path = psz_dup;
 
             in->p_access = access2_New( p_input,
@@ -2271,7 +2282,7 @@ static void SlaveDemux( input_thread_t *p_input )
 {
     int64_t i_time;
     int i;
-    
     if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
     {
         msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
@@ -2356,7 +2367,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" );
@@ -2411,138 +2422,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.