]> git.sesse.net Git - vlc/blobdiff - src/input/input.c
Add ability to prepend headers to messages (object-specific) and use it for VLM media...
[vlc] / src / input / input.c
index 5ab59b5085a31842dac2f056652db0beeca5a7ef..14983915e8be955b0c6320574b14b77d8796364e 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 );
@@ -104,7 +105,7 @@ 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 */
     vlc_value_t val;
@@ -117,6 +118,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 +152,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;
@@ -237,11 +241,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 )
+{
+    __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 */
 
-    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 +278,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 */
 
-    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 +302,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;
 }
 
 /**
@@ -306,7 +321,7 @@ int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
     input_thread_t *p_input;                        /* thread descriptor */
 
     /* Allocate descriptor */
-    p_input = Create( p_parent, p_item, VLC_TRUE );
+    p_input = Create( p_parent, p_item, NULL, VLC_TRUE );
 
     /* Now we can attach our new input */
     vlc_object_attach( p_input, p_parent );
@@ -669,6 +684,21 @@ static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
      */
     if( !b_quick )
     {
+        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 );
+        p_counter = stats_CounterGet( p_input, p_input->i_object_id,
+                                      "input_bitrate" );
+        if( p_counter ) p_counter->update_interval = 1000000;
+        p_counter = stats_CounterGet( p_input, p_input->i_object_id,
+                                      "demux_bitrate" );
+        if( p_counter ) p_counter->update_interval = 1000000;
+
         psz = var_GetString( p_input, "sout" );
         if( *psz && strncasecmp( p_input->input.p_item->psz_uri, "vlc:", 4 ) )
         {
@@ -2095,9 +2125,8 @@ static int InputSourceInit( input_thread_t *p_input,
         if( in->p_access == NULL )
         {
             msg_Err( p_input, "no suitable access module for `%s'", psz_mrl );
-            intf_UserFatal( VLC_OBJECT( p_input), DIALOG_NOACCESS,
-                            "Error opening stream",
-                            "Unable to open '%s'", psz_mrl );
+            intf_UserFatal( VLC_OBJECT( p_input),
+                            _("Errors"),"Unable to open '%s'", psz_mrl );
             goto error;
         }
 
@@ -2167,6 +2196,8 @@ 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), _("Errors"),
+                            "Unrecognized format for '%s'", psz_mrl );
             goto error;
         }