]> git.sesse.net Git - vlc/commitdiff
stats: Add vout stats module.
authorPierre d'Herbemont <pdherbemont@videolan.org>
Fri, 23 May 2008 23:06:48 +0000 (01:06 +0200)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Thu, 5 Jun 2008 19:20:10 +0000 (21:20 +0200)
./vlc movie.avi --sout="#transcode{aenc=dummy,venc=stats}:std{access=http,mux=dummy,dst=0.0.0.0:8081}"
./vlc -vvv http://127.0.0.1:8081 --demux=stats --vout=stats --codec=stats

modules/misc/stats/Modules.am
modules/misc/stats/decoder.c
modules/misc/stats/demux.c
modules/misc/stats/stats.c
modules/misc/stats/stats.h
modules/misc/stats/vout.c [new file with mode: 0644]

index d166042e1fad2c12e91b3e34e5028744ede33926..0161080085bd026fca2ea81105367bf5278682ee 100644 (file)
@@ -4,5 +4,6 @@ SOURCES_stats = \
        decoder.c \
        demux.c \
        encoder.c \
+       vout.c \
        $(NULL)
 
index db11673b3b04ab766a68d0f7790ef3776bd80814..f3edb903e93d46742903664f5e87fbf59a39bb23 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <vlc/vlc.h>
 #include <vlc_codec.h>
+#include <vlc_vout.h>
 
 #include "stats.h"
 
@@ -60,21 +61,37 @@ int OpenDecoder ( vlc_object_t *p_this )
  ****************************************************************************/
 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 {
-    decoder_sys_t *p_sys = p_dec->p_sys;
     block_t *p_block;
+    picture_t * p_pic = NULL;
 
     if( !pp_block || !*pp_block ) return NULL;
     p_block = *pp_block;
 
+    p_dec->fmt_out.video.i_width = 100;
+    p_dec->fmt_out.video.i_height = 100;
+    p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR;
+    p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0');
+
+    p_pic = p_dec->pf_vout_buffer_new( p_dec );
+
     if( p_block->i_buffer == kBufferSize )
     {
+        msg_Dbg( p_dec, "got %d ms", *(mtime_t *)p_block->p_buffer  / 1000 );
         msg_Dbg( p_dec, "got %d ms offset", (mdate() - *(mtime_t *)p_block->p_buffer) / 1000 );
+        *(mtime_t *)(p_pic->p->p_pixels) = *(mtime_t *)p_block->p_buffer;
     }
     else
-        msg_Dbg( p_dec, "got offset of size %d", p_block->i_buffer );
+    {
+        msg_Dbg( p_dec, "got a packet not from stats demuxer" );
+        *(mtime_t *)(p_pic->p->p_pixels) = mdate();
+    }
+
+    p_pic->date = p_block->i_pts ? p_block->i_pts : p_block->i_dts;
+    p_pic->b_force = true;
 
     block_Release( p_block );
-    return NULL;
+    *pp_block = NULL;
+    return p_pic;
 }
 
 /*****************************************************************************
index f2e9aec56b92b9b3cac983c8f3c66315a34f5d78..1ee88a552045924ce04e4b870a1833665b726dff 100644 (file)
@@ -103,13 +103,15 @@ static int Demux( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
 
-    msg_Dbg( p_demux, "Demux" );
-
     block_t * p_block = stream_Block( p_demux->s, kBufferSize );
 
+    if( !p_block ) return 1;
+
     p_block->i_dts = p_block->i_pts =
         date_Increment( &p_sys->pts, kBufferSize );
 
+    msg_Dbg( p_demux, "demux got %d ms offset", (mdate() - *(mtime_t *)p_block->p_buffer) / 1000 );
+
     //es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
 
     es_out_Send( p_demux->out, p_sys->p_es, p_block );
index 751f3b3fa8ce0cb53de36f9ccd1bea397865c54a..f483b297fb720301935f0199a005f89265efd6c4 100644 (file)
 
 #include "stats.h"
 
+/* Example usage:
+ *  $ vlc movie.avi --sout="#transcode{aenc=dummy,venc=stats}:\
+ *                          std{access=http,mux=dummy,dst=0.0.0.0:8081}"
+ *  $ vlc -vvv http://127.0.0.1:8081 --demux=stats --vout=stats --codec=stats
+ */
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -54,5 +60,10 @@ vlc_module_begin();
         set_description( _("Stats demux function") );
         set_capability( "demux", 0 );
         set_callbacks( OpenDemux, CloseDemux );
+    add_submodule();
+        set_section( N_( "Stats video output" ), NULL );
+        set_description( _("Stats video output function") );
+        set_capability( "video output", 0 );
+        set_callbacks( OpenVideo, NULL );
 vlc_module_end();
 
index 4125f4d8930bba6ee4c493e45c2720587b875560..9d7f18db8e78446c266ef65d7a60d7c73fd4b5fc 100644 (file)
@@ -34,4 +34,6 @@ void CloseEncoder ( vlc_object_t * );
 int  OpenDemux    ( vlc_object_t * );
 void CloseDemux   ( vlc_object_t * );
 
+int  OpenVideo    ( vlc_object_t * );
+
 #define kBufferSize 0x500
diff --git a/modules/misc/stats/vout.c b/modules/misc/stats/vout.c
new file mode 100644 (file)
index 0000000..37268f5
--- /dev/null
@@ -0,0 +1,230 @@
+/*****************************************************************************
+ * vout_dummy.c: Dummy video output display method for testing purposes
+ *****************************************************************************
+ * Copyright (C) 2000, 2001 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Samuel Hocevar <sam@zoy.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc/vlc.h>
+#include <vlc_vout.h>
+
+#define DUMMY_WIDTH 16
+#define DUMMY_HEIGHT 16
+#define DUMMY_MAX_DIRECTBUFFERS 10
+
+#include "stats.h"
+
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static int  Init       ( vout_thread_t * );
+static void End        ( vout_thread_t * );
+static int  Manage     ( vout_thread_t * );
+static void Render     ( vout_thread_t *, picture_t * );
+static void Display    ( vout_thread_t *, picture_t * );
+static void SetPalette ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
+static int  Control   ( vout_thread_t *, int, va_list );
+
+/*****************************************************************************
+ * OpenVideo: activates dummy video thread output method
+ *****************************************************************************
+ * This function initializes a dummy vout method.
+ *****************************************************************************/
+int OpenVideo ( vlc_object_t *p_this )
+{
+    vout_thread_t * p_vout = (vout_thread_t *)p_this;
+
+    p_vout->pf_init = Init;
+    p_vout->pf_end = End;
+    p_vout->pf_manage = Manage;
+    p_vout->pf_render = Render;
+    p_vout->pf_display = Display;
+    p_vout->pf_control = Control;
+
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Control: control facility for the vout
+ *****************************************************************************/
+static int Control( vout_thread_t *p_vout, int i_query, va_list args )
+{
+    switch( i_query )
+    {
+       default:
+            return vout_vaControlDefault( p_vout, i_query, args );
+    }
+}
+
+
+/*****************************************************************************
+ * Init: initialize dummy video thread output method
+ *****************************************************************************/
+static int Init( vout_thread_t *p_vout )
+{
+    int i_index, i_chroma;
+    char *psz_chroma;
+    picture_t *p_pic;
+    bool b_chroma = 0;
+
+    psz_chroma = config_GetPsz( p_vout, "dummy-chroma" );
+    if( psz_chroma )
+    {
+        if( strlen( psz_chroma ) >= 4 )
+        {
+            i_chroma = VLC_FOURCC( psz_chroma[0], psz_chroma[1],
+                                   psz_chroma[2], psz_chroma[3] );
+            b_chroma = 1;
+        }
+
+        free( psz_chroma );
+    }
+
+    I_OUTPUTPICTURES = 0;
+
+    /* Initialize the output structure */
+    if( b_chroma )
+    {
+        msg_Dbg( p_vout, "forcing chroma 0x%.8x (%4.4s)",
+                         i_chroma, (char*)&i_chroma );
+        p_vout->output.i_chroma = i_chroma;
+        if ( i_chroma == VLC_FOURCC( 'R', 'G', 'B', '2' ) )
+        {
+            p_vout->output.pf_setpalette = SetPalette;
+        }
+        p_vout->output.i_width  = p_vout->render.i_width;
+        p_vout->output.i_height = p_vout->render.i_height;
+        p_vout->output.i_aspect = p_vout->render.i_aspect;
+    }
+    else
+    {
+        /* Use same chroma as input */
+        p_vout->output.i_chroma = p_vout->render.i_chroma;
+        p_vout->output.i_rmask  = p_vout->render.i_rmask;
+        p_vout->output.i_gmask  = p_vout->render.i_gmask;
+        p_vout->output.i_bmask  = p_vout->render.i_bmask;
+        p_vout->output.i_width  = p_vout->render.i_width;
+        p_vout->output.i_height = p_vout->render.i_height;
+        p_vout->output.i_aspect = p_vout->render.i_aspect;
+    }
+
+    /* Try to initialize DUMMY_MAX_DIRECTBUFFERS direct buffers */
+    while( I_OUTPUTPICTURES < DUMMY_MAX_DIRECTBUFFERS )
+    {
+        p_pic = NULL;
+
+        /* Find an empty picture slot */
+        for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
+        {
+            if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
+            {
+                p_pic = p_vout->p_picture + i_index;
+                break;
+            }
+        }
+
+        /* Allocate the picture */
+        if( p_pic == NULL )
+        {
+            break;
+        }
+
+        vout_AllocatePicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma,
+                              p_vout->output.i_width, p_vout->output.i_height,
+                              p_vout->output.i_aspect );
+
+        if( p_pic->i_planes == 0 )
+        {
+            break;
+        }
+
+        p_pic->i_status = DESTROYED_PICTURE;
+        p_pic->i_type   = DIRECT_PICTURE;
+
+        PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
+
+        I_OUTPUTPICTURES++;
+    }
+
+    return( 0 );
+}
+
+/*****************************************************************************
+ * End: terminate dummy video thread output method
+ *****************************************************************************/
+static void End( vout_thread_t *p_vout )
+{
+    int i_index;
+
+    /* Free the fake output buffers we allocated */
+    for( i_index = I_OUTPUTPICTURES ; i_index ; )
+    {
+        i_index--;
+        free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
+    }
+}
+
+/*****************************************************************************
+ * Manage: handle dummy events
+ *****************************************************************************
+ * This function should be called regularly by video output thread. It manages
+ * console events. It returns a non null value on error.
+ *****************************************************************************/
+static int Manage( vout_thread_t *p_vout )
+{
+    VLC_UNUSED(p_vout);
+    return( 0 );
+}
+
+/*****************************************************************************
+ * Render: render previously calculated output
+ *****************************************************************************/
+static void Render( vout_thread_t *p_vout, picture_t *p_pic )
+{
+    VLC_UNUSED(p_vout); VLC_UNUSED(p_pic);
+    /* No need to do anything, the fake direct buffers stay as they are */
+}
+
+/*****************************************************************************
+ * Display: displays previously rendered output
+ *****************************************************************************/
+static void Display( vout_thread_t *p_vout, picture_t *p_pic )
+{
+    msg_Dbg( p_vout, "VOUT got %d ms offset", (mdate() - *(mtime_t *)p_pic->p->p_pixels) / 1000 );
+
+    /* No need to do anything, the fake direct buffers stay as they are */
+}
+
+/*****************************************************************************
+ * SetPalette: set the palette for the picture
+ *****************************************************************************/
+static void SetPalette ( vout_thread_t *p_vout,
+                         uint16_t *red, uint16_t *green, uint16_t *blue )
+{
+    VLC_UNUSED(p_vout); VLC_UNUSED(red); VLC_UNUSED(green); VLC_UNUSED(blue);
+    /* No need to do anything, the fake direct buffers stay as they are */
+}