[vlc-devel] [PATCH] Add motiondetect options to resend values over UDP
Gonzague Defos du Rau
gonzagueddr at gmail.com
Sat Jun 9 13:56:01 CEST 2012
If --motiondetect-port is given, detected boxes values are send on the specified UDP port.
You can also use --motiondetect-ip.
This have been tested on linux and windows, but, as i'm not a developper nor a mac user, i don't know if it'll be ok on mac.
---
modules/video_filter/motiondetect.c | 55 +++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/modules/video_filter/motiondetect.c b/modules/video_filter/motiondetect.c
index 99e35cc..bbfbea3 100644
--- a/modules/video_filter/motiondetect.c
+++ b/modules/video_filter/motiondetect.c
@@ -36,6 +36,9 @@
#include <vlc_filter.h>
#include "filter_picture.h"
+/* Boxes UDP resend */
+#include <vlc_network.h>
+
/*****************************************************************************
* Module descriptor
*****************************************************************************/
@@ -51,6 +54,10 @@ vlc_module_begin ()
set_subcategory( SUBCAT_VIDEO_VFILTER )
set_capability( "video filter2", 0 )
+ /* Boxes UDP resend . Default port is to zero = unactive */
+ add_integer(FILTER_PREFIX "port", 0, "motiondetect resend udp port", "resend detected boxes values over udp, default is not active", false)
+ add_string(FILTER_PREFIX "ip", "127.0.0.1", "motiondetect resend udp ip", "resend detected boxes values over udp, default is localhost", true)
+
add_shortcut( "motion" )
set_callbacks( Create, Destroy )
vlc_module_end ()
@@ -66,6 +73,11 @@ static int FindShapes( uint32_t *, uint32_t *, int, int, int,
static void Draw( filter_t *p_filter, uint8_t *p_pix, int i_pix_pitch, int i_pix_size );
#define NUM_COLORS (5000)
+/* Boxes UDP resend, options */
+static const char *const ppsz_filter_options[] = {
+ "port", "ip", NULL
+};
+
struct filter_sys_t
{
bool is_yuv_planar;
@@ -81,6 +93,11 @@ struct filter_sys_t
int color_x_max[NUM_COLORS];
int color_y_min[NUM_COLORS];
int color_y_max[NUM_COLORS];
+
+ /* Boxes UDP resend , socket */
+ int fd;
+ int port;
+
};
/*****************************************************************************
@@ -115,6 +132,28 @@ static int Create( vlc_object_t *p_this )
if( p_filter->p_sys == NULL )
return VLC_ENOMEM;
+ /* Boxes UDP resend , open socket */
+ int fd;
+ config_ChainParse( p_filter, FILTER_PREFIX, ppsz_filter_options, p_filter->p_cfg );
+ int i_port = var_CreateGetIntegerCommand( p_filter, FILTER_PREFIX "port" );
+ char *psz_master = var_InheritString( p_filter, FILTER_PREFIX "ip");
+ if( i_port > 0 )
+ {
+ fd = net_ConnectUDP( VLC_OBJECT( p_filter ), psz_master, i_port, -1 );
+ free(psz_master);
+ if (fd == -1)
+ {
+ msg_Err(p_filter, "Can not open socket");
+ i_port = 0 ;
+ p_sys->port = 0 ;
+ }
+ else
+ {
+ p_sys->fd = fd;
+ p_sys->port = i_port ;
+ }
+ }
+
p_sys->is_yuv_planar = is_yuv_planar;
p_sys->b_old = false;
p_sys->p_old = picture_NewFromFormat( p_fmt );
@@ -144,6 +183,11 @@ static void Destroy( vlc_object_t *p_this )
free( p_sys->p_buf2 );
free( p_sys->p_buf );
picture_Release( p_sys->p_old );
+
+ /* Boxes UDP resend , close socket */
+ if( p_sys->port > 0 )
+ net_Close( p_sys->fd );
+
free( p_sys );
}
@@ -537,6 +581,17 @@ static void Draw( filter_t *p_filter, uint8_t *p_pix, int i_pix_pitch, int i_pix
const int color_y_min = p_sys->color_y_min[i];
const int color_y_max = p_sys->color_y_max[i];
+ /* Boxes UDP resend, send boxes datas */
+ if( p_sys->port > 0)
+ {
+ char buffer[NUM_COLORS] = "";
+ sprintf(buffer, "%d %d %d %d %d ;\n", j, color_x_min, color_x_max, color_y_min, color_y_max);
+ if ( send( p_sys->fd, buffer, sizeof( buffer ), 0 ) <= 0 )
+ {
+ msg_Err( p_filter, "Can not send to socket");
+ }
+ }
+
if( color_x_min == -1 )
continue;
if( ( color_y_max - color_y_min ) * ( color_x_max - color_x_min ) < 16 )
--
1.7.11.rc2.2.g02101c9
More information about the vlc-devel
mailing list