]> git.sesse.net Git - vlc/commitdiff
Added sout_UpdateStatistic and fixed transcode module to use it.
authorLaurent Aimar <fenrir@videolan.org>
Sat, 20 Oct 2007 23:22:48 +0000 (23:22 +0000)
committerLaurent Aimar <fenrir@videolan.org>
Sat, 20 Oct 2007 23:22:48 +0000 (23:22 +0000)
 As a side effect, it fixed a potential segfault (race condition) when using
sout-keep (but I am not sure if we have a stream_out module that can show the
problem)

 sout_UpdateStatistic still uses input internal data and that need to
be fixed. Audio output need such a clean too.

include/vlc_sout.h
modules/stream_out/transcode.c
src/stream_output/stream_output.c

index f268fd5effb2b8f1ceff2c1b5bf681891b67aa79..2349bfd7f7d4beca7759650c919e90ba28b23655 100644 (file)
@@ -58,6 +58,21 @@ struct sout_instance_t
     sout_instance_sys_t *p_sys;
 };
 
+/** Stream output statistics */
+typedef enum
+{
+    SOUT_STATISTIC_DECODED_VIDEO,
+    SOUT_STATISTIC_DECODED_AUDIO,
+    SOUT_STATISTIC_DECODED_SUBTITLE,
+
+    /* Use them only if you do not goes through a access_out module */
+    SOUT_STATISTIC_SENT_PACKET,
+    SOUT_STATISTIC_SENT_BYTE,
+
+} sout_statistic_t;
+
+VLC_EXPORT( void, sout_UpdateStatistic, ( sout_instance_t *p_sout, sout_statistic_t, int ) );
+
 /****************************************************************************
  * sout_stream_id_t: opaque (private for all sout_stream_t)
  ****************************************************************************/
index 14d3b7f1b008601c4896232aa762054015e948af..7c7b38fdfe33f4bbb9eda175c15559187e4e4109 100644 (file)
 
 #define MASTER_SYNC_MAX_DRIFT 100000
 
-/* FIXME Ugly, needed for (disabled) stats updates  */
-#if 0
-#include "../../src/input/input_internal.h"
-#endif
-
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -1319,7 +1314,7 @@ static int transcode_audio_new( sout_stream_t *p_stream,
     id->p_decoder->fmt_out = id->p_decoder->fmt_in;
     id->p_decoder->fmt_out.i_extra = 0;
     id->p_decoder->fmt_out.p_extra = 0;
-    id->p_decoder->pf_decode_audio = 0;
+    id->p_decoder->pf_decode_audio = NULL;
     id->p_decoder->pf_aout_buffer_new = audio_new_buffer;
     id->p_decoder->pf_aout_buffer_del = audio_del_buffer;
     /* id->p_decoder->p_cfg = p_sys->p_audio_cfg; */
@@ -1551,21 +1546,11 @@ static int transcode_audio_process( sout_stream_t *p_stream,
     block_t *p_block, *p_audio_block;
     int i;
     *out = NULL;
-    input_thread_t *p_input = NULL;
-
-    if( p_stream->p_parent->p_parent && p_stream->p_parent->p_parent->
-                                i_object_type == VLC_OBJECT_INPUT )
-        p_input = (input_thread_t *)p_stream->p_parent->p_parent;
 
     while( (p_audio_buf = id->p_decoder->pf_decode_audio( id->p_decoder,
                                                           &in )) )
     {
-#warning Stats not implemented!
-#if 0
-        if( p_input )
-            stats_UpdateInteger( p_input, p_input->p->counters.p_decoded_audio,
-                                 1, NULL );
-#endif
+        sout_UpdateStatistic( p_stream->p_sout, SOUT_STATISTIC_DECODED_AUDIO, 1 );
         if( p_sys->b_master_sync )
         {
             mtime_t i_dts = date_Get( &id->interpolated_pts ) + 1;
@@ -1683,7 +1668,8 @@ static int transcode_video_new( sout_stream_t *p_stream, sout_stream_id_t *id )
     id->p_decoder->fmt_out = id->p_decoder->fmt_in;
     id->p_decoder->fmt_out.i_extra = 0;
     id->p_decoder->fmt_out.p_extra = 0;
-    id->p_decoder->pf_decode_video = 0;
+    id->p_decoder->pf_decode_video = NULL;
+    id->p_decoder->pf_get_cc = NULL;
     id->p_decoder->pf_get_cc = 0;
     id->p_decoder->pf_vout_buffer_new = video_new_buffer_decoder;
     id->p_decoder->pf_vout_buffer_del = video_del_buffer_decoder;
@@ -2155,21 +2141,12 @@ static int transcode_video_process( sout_stream_t *p_stream,
     int i_duplicate = 1, i;
     picture_t *p_pic, *p_pic2 = NULL;
     *out = NULL;
-    input_thread_t *p_input = NULL;
-
-    if( p_stream->p_parent->p_parent && p_stream->p_parent->p_parent->
-                                i_object_type == VLC_OBJECT_INPUT )
-        p_input = (input_thread_t *)p_stream->p_parent->p_parent;
 
     while( (p_pic = id->p_decoder->pf_decode_video( id->p_decoder, &in )) )
     {
         subpicture_t *p_subpic = NULL;
-#warning Stats not implemented!
-#if 0
-        if( p_input )
-            stats_UpdateInteger( p_input, p_input->p->counters.p_decoded_video,
-                                 1, NULL );
-#endif
+
+        sout_UpdateStatistic( p_stream->p_sout, SOUT_STATISTIC_DECODED_VIDEO, 1 );
 
         if( p_stream->p_sout->i_out_pace_nocontrol && p_sys->b_hurry_up )
         {
@@ -2708,6 +2685,7 @@ static int transcode_spu_new( sout_stream_t *p_stream, sout_stream_id_t *id )
      */
 
     /* Initialization of decoder structures */
+    id->p_decoder->pf_decode_sub = NULL;
     id->p_decoder->pf_spu_buffer_new = spu_new_buffer;
     id->p_decoder->pf_spu_buffer_del = spu_del_buffer;
     id->p_decoder->p_owner = (decoder_owner_sys_t *)p_stream;
@@ -2771,7 +2749,10 @@ static int transcode_spu_process( sout_stream_t *p_stream,
     *out = NULL;
 
     p_subpic = id->p_decoder->pf_decode_sub( id->p_decoder, &in );
-    if( !p_subpic ) return VLC_EGENERIC;
+    if( !p_subpic )
+        return VLC_EGENERIC;
+
+    sout_UpdateStatistic( p_stream->p_sout, SOUT_STATISTIC_DECODED_SUBTITLE, 1 );
 
     if( p_sys->b_master_sync && p_sys->i_master_drift )
     {
index 2d512e664eafad2a7bf2f56c3f8f026b9290be7e..8566da2f3f233f682952ecc39608af6670c72576 100644 (file)
@@ -147,6 +147,59 @@ void sout_DeleteInstance( sout_instance_t * p_sout )
     vlc_object_destroy( p_sout );
 }
 
+/*****************************************************************************
+ * 
+ *****************************************************************************/
+void sout_UpdateStatistic( sout_instance_t *p_sout, sout_statistic_t i_type, int i_delta )
+{
+    input_thread_t *p_input;
+    int i_bytes; /* That's pretty stupid to define it as an integer, it will overflow
+                    really fast ... */
+
+    if( !p_sout->p_libvlc->b_stats )
+        return;
+
+    /* FIXME that's ugly
+     * TODO add a private (ie not VLC_EXPORTed) input_UpdateStatistic for that */
+    p_input = vlc_object_find( p_sout, VLC_OBJECT_INPUT, FIND_PARENT );
+    if( !p_input || p_input->i_state == INIT_S || p_input->i_state == ERROR_S )
+        return;
+
+    switch( i_type )
+    {
+#define I(c) stats_UpdateInteger( p_input, p_input->p->counters.c, i_delta, NULL )
+    case SOUT_STATISTIC_DECODED_VIDEO:
+        I(p_decoded_video);
+        break;
+    case SOUT_STATISTIC_DECODED_AUDIO:
+        I(p_decoded_audio);
+        break;
+    case SOUT_STATISTIC_DECODED_SUBTITLE:
+        I(p_decoded_sub);
+        break;
+#if 0
+    case SOUT_STATISTIC_ENCODED_VIDEO:
+    case SOUT_STATISTIC_ENCODED_AUDIO:
+    case SOUT_STATISTIC_ENCODED_SUBTITLE:
+        msg_Warn( p_sout, "Not yet supported statistic type %d", i_type );
+        break;
+#endif
+
+    case SOUT_STATISTIC_SENT_PACKET:
+        I(p_sout_sent_packets);
+        break;
+#undef I
+    case SOUT_STATISTIC_SENT_BYTE:
+        if( !stats_UpdateInteger( p_input, p_input->p->counters.p_sout_sent_bytes, i_delta, &i_bytes ) )
+            stats_UpdateFloat( p_input, p_input->p->counters.p_sout_send_bitrate, i_bytes, NULL );
+        break;
+
+    default:
+        msg_Err( p_sout, "Invalid statistic type %d (internal error)", i_type );
+        break;
+    }
+    vlc_object_release( p_input );
+}
 /*****************************************************************************
  * Packetizer/Input
  *****************************************************************************/
@@ -323,26 +376,14 @@ 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 = 0;
+    const int i_packets_gather = 30;
     p_access->i_writes++;
     p_access->i_sent_bytes += p_buffer->i_buffer;
-    if( p_access->p_libvlc->b_stats && p_access->i_writes % 30 == 0 )
+    if( (p_access->i_writes % i_packets_gather) == 0 )
     {
-        /* Access_out -> sout_instance -> input_thread_t */
-        input_thread_t *p_input =
-            (input_thread_t *)vlc_object_find( p_access, VLC_OBJECT_INPUT,
-                                               FIND_PARENT );
-        if( p_input )
-        {
-            stats_UpdateInteger( p_input, p_input->p->counters.p_sout_sent_packets,
-                     30, NULL );
-            stats_UpdateInteger( p_input, p_input->p->counters.p_sout_sent_bytes,
-                                 p_access->i_sent_bytes, &i_total );
-            stats_UpdateFloat( p_input, p_input->p->counters.p_sout_send_bitrate,
-                    (float)i_total, NULL );
-            p_access->i_sent_bytes = 0;
-            vlc_object_release( p_input );
-        }
+        sout_UpdateStatistic( p_access->p_sout, SOUT_STATISTIC_SENT_PACKET, i_packets_gather );
+        sout_UpdateStatistic( p_access->p_sout, SOUT_STATISTIC_SENT_BYTE, p_access->i_sent_bytes );
+        p_access->i_sent_bytes = 0;
     }
     return p_access->pf_write( p_access, p_buffer );
 }