[vlc-devel] [PATCH v2] udp: support packets dump in access_out module

Tzu-Jung Lee roylee17 at gmail.com
Thu Jul 11 13:42:58 CEST 2013


Signed-off-by: Tzu-Jung Lee <tjlee at ambarella.com>
---
 modules/access_output/udp.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/modules/access_output/udp.c b/modules/access_output/udp.c
index 54aadd2..d7887fc 100644
--- a/modules/access_output/udp.c
+++ b/modules/access_output/udp.c
@@ -33,6 +33,7 @@
 #include <vlc_plugin.h>
 
 #include <sys/types.h>
+#include <fcntl.h>
 #include <assert.h>
 
 #include <vlc_sout.h>
@@ -50,6 +51,8 @@
 #endif
 
 #include <vlc_network.h>
+#include <vlc_fs.h>
+
 
 #define MAX_EMPTY_BLOCKS 200
 
@@ -73,6 +76,10 @@ static void Close( vlc_object_t * );
                           "helps reducing the scheduling load on " \
                           "heavily-loaded systems." )
 
+#define DUMP_TEXT N_("Dump packets to a file")
+#define DUMP_LONGTEXT N_("Dump the exact packets we sent to a file for " \
+                          "debugging or diagnostic purpose." )
+
 vlc_module_begin ()
     set_description( N_("UDP stream output") )
     set_shortname( "UDP" )
@@ -81,6 +88,7 @@ vlc_module_begin ()
     add_integer( SOUT_CFG_PREFIX "caching", DEFAULT_PTS_DELAY / 1000, CACHING_TEXT, CACHING_LONGTEXT, true )
     add_integer( SOUT_CFG_PREFIX "group", 1, GROUP_TEXT, GROUP_LONGTEXT,
                                  true )
+    add_string (SOUT_CFG_PREFIX "dump", NULL, DUMP_TEXT, DUMP_LONGTEXT, true)
 
     set_capability( "sout access", 0 )
     add_shortcut( "udp" )
@@ -94,6 +102,7 @@ vlc_module_end ()
 static const char *const ppsz_sout_options[] = {
     "caching",
     "group",
+    "dump",
     NULL
 };
 
@@ -116,6 +125,7 @@ struct sout_access_out_sys_t
 {
     mtime_t       i_caching;
     int           i_handle;
+    int           i_fd;
     bool          b_mtu_warning;
     size_t        i_mtu;
 
@@ -140,6 +150,7 @@ static int Open( vlc_object_t *p_this )
     int                 i_dst_port;
 
     int                 i_handle;
+    int                 i_fd = -1;
 
     config_ChainParse( p_access, SOUT_CFG_PREFIX,
                        ppsz_sout_options, p_access->p_cfg );
@@ -207,9 +218,23 @@ static int Open( vlc_object_t *p_this )
     }
     shutdown( i_handle, SHUT_RD );
 
+    const char *filename = var_InheritString (p_access, SOUT_CFG_PREFIX "dump");
+    if ( filename )
+    {
+        i_fd = vlc_open(filename, O_CREAT | O_WRONLY | O_TRUNC | O_LARGEFILE, 0666);
+        if ( i_fd < 0 )
+        {
+            msg_Err( p_access, "cannot open %s for dumping sent packets",
+                     filename);
+            return VLC_EGENERIC;
+        }
+        msg_Info( p_access, "dump sent packets to %s", filename);
+    }
+
     p_sys->i_caching = UINT64_C(1000)
                      * var_GetInteger( p_access, SOUT_CFG_PREFIX "caching");
     p_sys->i_handle = i_handle;
+    p_sys->i_fd = i_fd;
     p_sys->i_mtu = var_CreateGetInteger( p_this, "mtu" );
     p_sys->b_mtu_warning = false;
     p_sys->p_fifo = block_FifoNew();
@@ -223,6 +248,8 @@ static int Open( vlc_object_t *p_this )
         block_FifoRelease( p_sys->p_fifo );
         block_FifoRelease( p_sys->p_empty_blocks );
         net_Close (i_handle);
+        if( i_fd != -1)
+            close(i_fd);
         free (p_sys);
         return VLC_EGENERIC;
     }
@@ -444,6 +471,13 @@ static void* ThreadWrite( void *data )
         }
         if ( send( p_sys->i_handle, p_pk->p_buffer, p_pk->i_buffer, 0 ) == -1 )
             msg_Warn( p_access, "send error: %m" );
+
+        if ( p_sys->i_fd != -1 )
+        {
+            if ( write(p_sys->i_fd, p_pk->p_buffer, p_pk->i_buffer) == -1 )
+                msg_Warn( p_access, "dump error: %m" );
+        }
+
         vlc_cleanup_pop();
 
         if( i_dropped_packets )
-- 
1.8.2.1




More information about the vlc-devel mailing list