]> git.sesse.net Git - vlc/blobdiff - src/stream_output/stream_output.c
Gather some sout stats (Refs:#473)
[vlc] / src / stream_output / stream_output.c
index 558560e91565663b61ff581ddc04b7fb2dfe6fe6..d01d1cac5356b677408da005087084b236e4d141 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * stream_output.c : stream output module
  *****************************************************************************
- * Copyright (C) 2002-2004 VideoLAN
+ * Copyright (C) 2002-2004 the VideoLAN team
  * $Id$
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
@@ -20,7 +20,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.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -41,7 +41,8 @@
  *****************************************************************************/
 static void sout_CfgDestroy( sout_cfg_t * );
 
-#define sout_stream_url_to_chain( p, s ) _sout_stream_url_to_chain( VLC_OBJECT(p), s )
+#define sout_stream_url_to_chain( p, s ) \
+    _sout_stream_url_to_chain( VLC_OBJECT(p), s )
 static char *_sout_stream_url_to_chain( vlc_object_t *, char * );
 
 /*
@@ -70,22 +71,22 @@ sout_instance_t *__sout_NewInstance( vlc_object_t *p_parent, char * psz_dest )
 {
     sout_instance_t *p_sout;
     vlc_value_t keep;
+    counter_t *p_counter;
 
     if( var_Get( p_parent, "sout-keep", &keep ) < 0 )
     {
         msg_Warn( p_parent, "cannot get sout-keep value" );
         keep.b_bool = VLC_FALSE;
     }
-    else if( keep.b_bool )
+    if( keep.b_bool )
     {
-        msg_Warn( p_parent, "sout-keep true" );
         if( ( p_sout = vlc_object_find( p_parent, VLC_OBJECT_SOUT,
-                                        FIND_ANYWHERE ) ) )
+                                        FIND_ANYWHERE ) ) != NULL )
         {
             if( !strcmp( p_sout->psz_sout, psz_dest ) )
             {
-                msg_Warn( p_parent, "sout keep : reusing sout" );
-                msg_Warn( p_parent, "sout keep : you probably want to use "
+                msg_Dbg( p_parent, "sout keep : reusing sout" );
+                msg_Dbg( p_parent, "sout keep : you probably want to use "
                           "gather stream_out" );
                 vlc_object_detach( p_sout );
                 vlc_object_attach( p_sout, p_parent );
@@ -94,7 +95,8 @@ sout_instance_t *__sout_NewInstance( vlc_object_t *p_parent, char * psz_dest )
             }
             else
             {
-                msg_Warn( p_parent, "sout keep : destroying unusable sout" );
+                msg_Dbg( p_parent, "sout keep : destroying unusable sout" );
+                vlc_object_release( p_sout );
                 sout_DeleteInstance( p_sout );
             }
         }
@@ -102,9 +104,10 @@ sout_instance_t *__sout_NewInstance( vlc_object_t *p_parent, char * psz_dest )
     else if( !keep.b_bool )
     {
         while( ( p_sout = vlc_object_find( p_parent, VLC_OBJECT_SOUT,
-                                           FIND_PARENT ) ) )
+                                           FIND_PARENT ) ) != NULL )
         {
-            msg_Warn( p_parent, "sout keep : destroying old sout" );
+            msg_Dbg( p_parent, "sout keep : destroying old sout" );
+            vlc_object_release( p_sout );
             sout_DeleteInstance( p_sout );
         }
     }
@@ -138,6 +141,16 @@ sout_instance_t *__sout_NewInstance( vlc_object_t *p_parent, char * psz_dest )
     /* attach it for inherit */
     vlc_object_attach( p_sout, p_parent );
 
+    /* Create statistics */
+    stats_Create( p_parent, "sout_sent_packets",
+                  VLC_VAR_INTEGER, STATS_COUNTER );
+    stats_Create( p_parent, "sout_sent_bytes", VLC_VAR_INTEGER, STATS_COUNTER );
+    stats_Create( p_parent, "sout_send_bitrate",
+                  VLC_VAR_FLOAT, STATS_DERIVATIVE );
+    p_counter = stats_CounterGet( p_parent, p_parent->i_object_id,
+                    "sout_send_bitrate" );
+    if( p_counter) p_counter->update_interval = 1000000;
+
     p_sout->p_stream = sout_StreamNew( p_sout, p_sout->psz_chain );
 
     if( p_sout->p_stream == NULL )
@@ -352,6 +365,17 @@ int sout_AccessOutRead( sout_access_out_t *p_access, block_t *p_buffer )
  *****************************************************************************/
 int sout_AccessOutWrite( sout_access_out_t *p_access, block_t *p_buffer )
 {
+    int i_total;
+    /* Access_out -> sout_instance -> input_thread_t */
+    stats_UpdateInteger( p_access->p_parent->p_parent,
+                  "sout_sent_packets", 1 );
+    stats_UpdateInteger( p_access->p_parent->p_parent,
+                  "sout_sent_bytes", p_buffer->i_buffer );
+    stats_GetInteger( p_access->p_parent->p_parent,
+                      p_access->p_parent->p_parent->i_object_id,
+                      "sout_sent_bytes", &i_total );
+    stats_UpdateFloat( p_access->p_parent->p_parent, "sout_send_bitrate",
+                       (float)i_total );
     return p_access->pf_write( p_access, p_buffer );
 }
 
@@ -364,20 +388,17 @@ sout_mux_t * sout_MuxNew( sout_instance_t *p_sout, char *psz_mux,
     sout_mux_t *p_mux;
     char       *psz_next;
 
-    p_mux = vlc_object_create( p_sout,
-                               sizeof( sout_mux_t ) );
+    p_mux = vlc_object_create( p_sout, sizeof( sout_mux_t ) );
     if( p_mux == NULL )
     {
         msg_Err( p_sout, "out of memory" );
         return NULL;
     }
 
-    p_mux->p_sout       = p_sout;
+    p_mux->p_sout = p_sout;
     psz_next = sout_CfgCreate( &p_mux->psz_mux, &p_mux->p_cfg, psz_mux );
-    if( psz_next )
-    {
-        free( psz_next );
-    }
+    if( psz_next ) free( psz_next );
+
     p_mux->p_access     = p_access;
     p_mux->pf_control   = NULL;
     p_mux->pf_addstream = NULL;
@@ -387,11 +408,15 @@ sout_mux_t * sout_MuxNew( sout_instance_t *p_sout, char *psz_mux,
     p_mux->pp_inputs    = NULL;
 
     p_mux->p_sys        = NULL;
-    p_mux->p_module = NULL;
+    p_mux->p_module     = NULL;
+
+    p_mux->b_add_stream_any_time = VLC_FALSE;
+    p_mux->b_waiting_stream = VLC_TRUE;
+    p_mux->i_add_stream_start = -1;
 
     vlc_object_attach( p_mux, p_sout );
 
-    p_mux->p_module     =
+    p_mux->p_module =
         module_Need( p_mux, "sout mux", p_mux->psz_mux, VLC_TRUE );
 
     if( p_mux->p_module == NULL )
@@ -406,21 +431,32 @@ sout_mux_t * sout_MuxNew( sout_instance_t *p_sout, char *psz_mux,
     /* *** probe mux capacity *** */
     if( p_mux->pf_control )
     {
-        int b_answer;
-        if( sout_MuxControl( p_mux, MUX_CAN_ADD_STREAM_WHILE_MUXING, &b_answer ) )
+        int b_answer = VLC_FALSE;
+
+        if( sout_MuxControl( p_mux, MUX_CAN_ADD_STREAM_WHILE_MUXING,
+                             &b_answer ) )
         {
             b_answer = VLC_FALSE;
         }
+
         if( b_answer )
         {
             msg_Dbg( p_sout, "muxer support adding stream at any time" );
             p_mux->b_add_stream_any_time = VLC_TRUE;
             p_mux->b_waiting_stream = VLC_FALSE;
 
-            if( sout_MuxControl( p_mux, MUX_GET_ADD_STREAM_WAIT, &b_answer ) )
+            /* If we control the output pace then it's better to wait before
+             * starting muxing (generates better streams/files). */
+            if( !p_sout->i_out_pace_nocontrol )
+            {
+                b_answer = VLC_TRUE;
+            }
+            else if( sout_MuxControl( p_mux, MUX_GET_ADD_STREAM_WAIT,
+                                      &b_answer ) )
             {
                 b_answer = VLC_FALSE;
             }
+
             if( b_answer )
             {
                 msg_Dbg( p_sout, "muxer prefers waiting for all ES before "
@@ -428,18 +464,7 @@ sout_mux_t * sout_MuxNew( sout_instance_t *p_sout, char *psz_mux,
                 p_mux->b_waiting_stream = VLC_TRUE;
             }
         }
-        else
-        {
-            p_mux->b_add_stream_any_time = VLC_FALSE;
-            p_mux->b_waiting_stream = VLC_TRUE;
-        }
     }
-    else
-    {
-        p_mux->b_add_stream_any_time = VLC_FALSE;
-        p_mux->b_waiting_stream = VLC_TRUE;
-    }
-    p_mux->i_add_stream_start = -1;
 
     return p_mux;
 }
@@ -470,15 +495,10 @@ sout_input_t *sout_MuxAddStream( sout_mux_t *p_mux, es_format_t *p_fmt )
 
     if( !p_mux->b_add_stream_any_time && !p_mux->b_waiting_stream )
     {
-        msg_Err( p_mux, "cannot add a new stream (unsuported while muxing "
+        msg_Err( p_mux, "cannot add a new stream (unsupported while muxing "
                         "for this format)" );
         return NULL;
     }
-    if( p_mux->i_add_stream_start < 0 )
-    {
-        /* we wait for one second */
-        p_mux->i_add_stream_start = mdate();
-    }
 
     msg_Dbg( p_mux, "adding a new input" );
 
@@ -546,12 +566,26 @@ void sout_MuxSendBuffer( sout_mux_t *p_mux, sout_input_t *p_input,
 {
     block_FifoPut( p_input->p_fifo, p_buffer );
 
+    if( p_mux->p_sout->i_out_pace_nocontrol )
+    {
+        mtime_t current_date = mdate();
+        if ( current_date > p_buffer->i_dts )
+            msg_Warn( p_mux, "late buffer for mux input ("I64Fd")",
+                      current_date - p_buffer->i_dts );
+    }
+
     if( p_mux->b_waiting_stream )
     {
-        if( p_mux->i_add_stream_start > 0 &&
-            p_mux->i_add_stream_start + (mtime_t)1500000 < mdate() )
+        if( p_mux->i_add_stream_start < 0 )
+        {
+            p_mux->i_add_stream_start = p_buffer->i_dts;
+        }
+
+        if( p_mux->i_add_stream_start >= 0 &&
+            p_mux->i_add_stream_start + I64C(1500000) < p_buffer->i_dts )
         {
-            /* more than 1.5 second, start muxing */
+            /* Wait until we have more than 1.5 seconds worth of data
+             * before start muxing */
             p_mux->b_waiting_stream = VLC_FALSE;
         }
         else
@@ -990,6 +1024,7 @@ void __sout_CfgParse( vlc_object_t *p_this, char *psz_prefix,
                 val.f_float = atof( cfg->psz_value ? cfg->psz_value : "0" );
                 break;
             case VLC_VAR_STRING:
+            case VLC_VAR_MODULE:
                 val.psz_string = cfg->psz_value;
                 break;
             default: