]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/remoteosd.c
Sepia improve by being done in YUV
[vlc] / modules / video_filter / remoteosd.c
index 1bd84ca14e36a999ffe528bbedcdfbfc6a86653f..488b3717efc7475b5a6163d1e7a15a92b2027f95 100644 (file)
 #include <vlc_plugin.h>
 #include <vlc_vout.h>
 
-#include "vlc_filter.h"
-#include "filter_common.h"
-#include "vlc_image.h"
-#include "vlc_osd.h"
-#include "vlc_keys.h"
+#include <vlc_filter.h>
+#include <vlc_image.h>
+#include <vlc_keys.h>
 
 #include <vlc_network.h>
 #include <gcrypt.h>              /* to encrypt password */
@@ -77,7 +75,7 @@
 
 #define RMTOSD_PORT_TEXT N_("VNC Port")
 #define RMTOSD_PORT_LONGTEXT N_( \
-    "VNC portnumber." )
+    "VNC port number." )
 
 #define RMTOSD_PASSWORD_TEXT N_("VNC Password")
 #define RMTOSD_PASSWORD_LONGTEXT N_( \
 static int  CreateFilter ( vlc_object_t * );
 static void DestroyFilter( vlc_object_t * );
 
-vlc_module_begin();
-    set_description( N_("Remote-OSD over VNC") );
-    set_capability( "sub filter", 100 );
-    set_shortname( N_("Remote-OSD") );
-    set_category( CAT_VIDEO );
-    set_subcategory( SUBCAT_VIDEO_SUBPIC );
-    add_shortcut( "rmtosd" );
-    set_callbacks( CreateFilter, DestroyFilter );
-
-    add_string( RMTOSD_CFG "host", "myvdr", NULL, RMTOSD_HOST_TEXT,
-        RMTOSD_HOST_LONGTEXT, false );
+vlc_module_begin ()
+    set_description( N_("Remote-OSD over VNC") )
+    set_capability( "sub filter", 100 )
+    set_shortname( N_("Remote-OSD") )
+    set_category( CAT_VIDEO )
+    set_subcategory( SUBCAT_VIDEO_SUBPIC )
+    add_shortcut( "rmtosd" )
+    set_callbacks( CreateFilter, DestroyFilter )
+
+    add_string( RMTOSD_CFG "host", "myvdr", RMTOSD_HOST_TEXT,
+        RMTOSD_HOST_LONGTEXT, false )
     add_integer_with_range( RMTOSD_CFG "port", 20001, 1, 0xFFFF, NULL,
-        RMTOSD_PORT_TEXT, RMTOSD_PORT_LONGTEXT, false );
-    add_password( RMTOSD_CFG "password", "", NULL, RMTOSD_PASSWORD_TEXT,
-        RMTOSD_PASSWORD_LONGTEXT, false );
+        RMTOSD_PORT_TEXT, RMTOSD_PORT_LONGTEXT, false )
+    add_password( RMTOSD_CFG "password", "", RMTOSD_PASSWORD_TEXT,
+        RMTOSD_PASSWORD_LONGTEXT, false )
     add_integer_with_range( RMTOSD_CFG "update", RMTOSD_UPDATE_DEFAULT,
         RMTOSD_UPDATE_MIN, RMTOSD_UPDATE_MAX, NULL, RMTOSD_UPDATE_TEXT,
-        RMTOSD_UPDATE_LONGTEXT, true );
-    add_bool( RMTOSD_CFG "vnc-polling", 0, NULL,
-              RMTOSD_POLL_TEXT , RMTOSD_POLL_LONGTEXT, false );
-    add_bool( RMTOSD_CFG "mouse-events", 0, NULL,
-              RMTOSD_MOUSE_TEXT , RMTOSD_MOUSE_LONGTEXT, false );
-    add_bool( RMTOSD_CFG "key-events", 0, NULL,
-              RMTOSD_KEYS_TEXT , RMTOSD_KEYS_LONGTEXT, false );
+        RMTOSD_UPDATE_LONGTEXT, true )
+    add_bool( RMTOSD_CFG "vnc-polling", false,
+              RMTOSD_POLL_TEXT , RMTOSD_POLL_LONGTEXT, false )
+    add_bool( RMTOSD_CFG "mouse-events", false,
+              RMTOSD_MOUSE_TEXT , RMTOSD_MOUSE_LONGTEXT, false )
+    add_bool( RMTOSD_CFG "key-events", false,
+              RMTOSD_KEYS_TEXT , RMTOSD_KEYS_LONGTEXT, false )
     add_integer_with_range( RMTOSD_CFG "alpha", 255, 0, 255, NULL,
-        RMTOSD_ALPHA_TEXT, RMTOSD_ALPHA_LONGTEXT, true );
+        RMTOSD_ALPHA_TEXT, RMTOSD_ALPHA_LONGTEXT, true )
 
-vlc_module_end();
+vlc_module_end ()
 
 
 /*****************************************************************************
@@ -154,8 +152,10 @@ vlc_module_end();
 /* subfilter functions */
 static subpicture_t *Filter( filter_t *, mtime_t );
 
-static int MouseEvent ( vlc_object_t *p_this, char const *psz_var,
-                        vlc_value_t oldval, vlc_value_t newval, void *p_data );
+static int MouseEvent( filter_t *,
+                       const vlc_mouse_t *,
+                       const vlc_mouse_t *,
+                       const video_format_t * );
 
 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
                      vlc_value_t oldval, vlc_value_t newval, void *p_data );
@@ -202,8 +202,6 @@ static void vnc_encrypt_bytes( unsigned char *bytes, char *passwd );
  *****************************************************************************/
 struct filter_sys_t
 {
-    VLC_COMMON_MEMBERS
-
     bool          b_need_update;       /* VNC picture is updated, do update the OSD*/
     mtime_t       i_vnc_poll_interval; /* Update the OSD menu every n ms */
 
@@ -224,8 +222,6 @@ struct filter_sys_t
 
     picture_t     *p_pic;              /* The picture with OSD data from VNC */
 
-    vout_thread_t *p_vout;             /* Pointer to video-out thread */
-
     int           i_socket;            /* Socket used for VNC */
 
     uint16_t      i_vnc_width;          /* The with of the VNC screen */
@@ -253,10 +249,9 @@ static int CreateFilter ( vlc_object_t *p_this )
 
     msg_Dbg( p_filter, "Creating vnc osd filter..." );
 
-    p_filter->p_sys = p_sys = malloc( sizeof(*p_sys) );
+    p_filter->p_sys = p_sys = calloc( 1, sizeof(*p_sys) );
     if( !p_filter->p_sys )
         return VLC_ENOMEM;
-    memset( p_sys, 0, sizeof(*p_sys) );
 
     /* Populating struct */
     vlc_mutex_init( &p_sys->lock );
@@ -310,20 +305,11 @@ static int CreateFilter ( vlc_object_t *p_this )
 
     /* Attach subpicture filter callback */
     p_filter->pf_sub_filter = Filter;
+    p_filter->pf_sub_mouse  = MouseEvent;
 
-    p_sys->p_vout = vlc_object_find( p_this, VLC_OBJECT_VOUT, FIND_PARENT );
+    var_AddCallback( p_filter->p_libvlc, "key-pressed", KeyEvent, p_this );
 
-    if( p_sys->p_vout )
-    {
-        var_AddCallback( p_sys->p_vout, "mouse-moved",
-                         MouseEvent, p_this );
-        var_AddCallback( p_sys->p_vout, "mouse-button-down",
-                         MouseEvent, p_this );
-        var_AddCallback( p_sys->p_vout->p_libvlc, "key-pressed",
-                         KeyEvent, p_this );
-    }
-
-    es_format_Init( &p_filter->fmt_out, SPU_ES, VLC_FOURCC( 's','p','u',' ' ) );
+    es_format_Init( &p_filter->fmt_out, SPU_ES, VLC_CODEC_SPU );
     p_filter->fmt_out.i_priority = 0;
 
     vlc_gcrypt_init();
@@ -332,11 +318,9 @@ static int CreateFilter ( vlc_object_t *p_this )
     p_sys->p_worker_thread = vlc_object_create( p_this,
                                                 sizeof( vlc_object_t ) );
     vlc_object_attach( p_sys->p_worker_thread, p_this );
-    if( vlc_thread_create( p_sys->p_worker_thread, "vnc worker thread",
-                           vnc_worker_thread,
-                           VLC_THREAD_PRIORITY_LOW, false ) )
+    if( vlc_thread_create( p_sys->p_worker_thread,
+                           vnc_worker_thread, VLC_THREAD_PRIORITY_LOW ) )
     {
-        vlc_object_detach( p_sys->p_worker_thread );
         vlc_object_release( p_sys->p_worker_thread );
         msg_Err( p_filter, "cannot spawn vnc message reader thread" );
         goto error;
@@ -371,17 +355,7 @@ static void DestroyFilter( vlc_object_t *p_this )
 
     stop_osdvnc( p_filter );
 
-    if( p_sys->p_vout )
-    {
-        var_DelCallback( p_sys->p_vout, "mouse-moved",
-                         MouseEvent, p_this );
-        var_DelCallback( p_sys->p_vout, "mouse-button-down",
-                         MouseEvent, p_this );
-        var_DelCallback( p_sys->p_vout->p_libvlc, "key-pressed",
-                         KeyEvent, p_this );
-
-        vlc_object_release( p_sys->p_vout );
-    }
+    var_DelCallback( p_filter->p_libvlc, "key-pressed", KeyEvent, p_this );
 
     var_Destroy( p_this, RMTOSD_CFG "host" );
     var_Destroy( p_this, RMTOSD_CFG "port" );
@@ -411,7 +385,6 @@ static void stop_osdvnc ( filter_t *p_filter )
         msg_Dbg( p_filter, "joining worker_thread" );
         vlc_object_kill( p_sys->p_worker_thread );
         vlc_thread_join( p_sys->p_worker_thread );
-        vlc_object_detach( p_sys->p_worker_thread );
         vlc_object_release( p_sys->p_worker_thread );
         msg_Dbg( p_filter, "released worker_thread" );
     }
@@ -698,8 +671,8 @@ static void* vnc_worker_thread( vlc_object_t *p_thread_obj )
 
     /* Create an empty picture for VNC the data */
     vlc_mutex_lock( &p_sys->lock );
-    p_sys->p_pic = picture_New( VLC_FOURCC('Y','U','V','A'),
-                                p_sys->i_vnc_width, p_sys->i_vnc_height, VOUT_ASPECT_FACTOR );
+    p_sys->p_pic = picture_New( VLC_CODEC_YUVA,
+                                p_sys->i_vnc_width, p_sys->i_vnc_height, 1, 1 );
     if( !p_sys->p_pic )
     {
         vlc_mutex_unlock( &p_sys->lock );
@@ -714,11 +687,8 @@ static void* vnc_worker_thread( vlc_object_t *p_thread_obj )
                                                  sizeof( vlc_object_t ) );
     vlc_object_attach( p_update_request_thread, p_filter );
     if( vlc_thread_create( p_update_request_thread,
-                           "vnc update request thread",
-                           update_request_thread,
-                           VLC_THREAD_PRIORITY_LOW, false ) )
+                           update_request_thread, VLC_THREAD_PRIORITY_LOW ) )
     {
-        vlc_object_detach( p_update_request_thread );
         vlc_object_release( p_update_request_thread );
         msg_Err( p_filter, "cannot spawn vnc update request thread" );
         goto exit;
@@ -779,7 +749,6 @@ static void* vnc_worker_thread( vlc_object_t *p_thread_obj )
     msg_Dbg( p_filter, "joining update_request_thread" );
     vlc_object_kill( p_update_request_thread );
     vlc_thread_join( p_update_request_thread );
-    vlc_object_detach( p_update_request_thread );
     vlc_object_release( p_update_request_thread );
     msg_Dbg( p_filter, "released update_request_thread" );
 
@@ -820,8 +789,8 @@ static void* update_request_thread( vlc_object_t *p_thread_obj )
     udr.w = htons(p_sys->i_vnc_width);
     udr.h = htons(p_sys->i_vnc_height);
 
-    if( write_exact(p_filter, p_sys->i_socket, (char*)&udr,
-           sz_rfbFramebufferUpdateRequestMsg) == false)
+    if( !write_exact(p_filter, p_sys->i_socket, (char*)&udr,
+                     sz_rfbFramebufferUpdateRequestMsg) )
     {
         msg_Err( p_filter, "Could not write rfbFramebufferUpdateRequestMsg." );
         p_sys->b_continue = false;
@@ -836,8 +805,8 @@ static void* update_request_thread( vlc_object_t *p_thread_obj )
         while( vlc_object_alive( p_thread_obj ) )
         {
             msleep( i_poll_interval_microsec );
-            if( write_exact(p_filter, p_sys->i_socket, (char*)&udr,
-                   sz_rfbFramebufferUpdateRequestMsg) == false)
+            if( !write_exact(p_filter, p_sys->i_socket, (char*)&udr,
+                             sz_rfbFramebufferUpdateRequestMsg))
             {
                 msg_Err( p_filter, "Could not write rfbFramebufferUpdateRequestMsg." );
                 break;
@@ -1029,7 +998,7 @@ static bool process_server_message ( filter_t *p_filter,
             msg->scme.nColours = htons(msg->scme.nColours);
             msg->scme.firstColour = htons(msg->scme.firstColour);
             int i_datasize;
-            if ( p_sys->b_alpha_from_vnc == true )
+            if ( p_sys->b_alpha_from_vnc )
             {
                 i_datasize = 2 * msg->scme.nColours * 4;
             }
@@ -1058,7 +1027,7 @@ static bool process_server_message ( filter_t *p_filter,
             for (int i = 0; i < msg->scme.nColours; i++)
             {
                 i_color_index = i+msg->scme.firstColour;
-                if ( p_sys->b_alpha_from_vnc == true )
+                if ( p_sys->b_alpha_from_vnc )
                 {
                     i_alpha = p_sys->read_buffer[i_offset];
                     i_offset += 2;
@@ -1156,13 +1125,12 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
 
     /* Create new SPU region */
     memset( &fmt, 0, sizeof(video_format_t) );
-    fmt.i_chroma = VLC_FOURCC('Y','U','V','A');
-    fmt.i_aspect = VOUT_ASPECT_FACTOR;
+    fmt.i_chroma = VLC_CODEC_YUVA;
     fmt.i_sar_num = fmt.i_sar_den = 1;
     fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
     fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
     fmt.i_x_offset = fmt.i_y_offset = 0;
-    p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
+    p_region = subpicture_region_New( &fmt );
     if( !p_region )
     {
         msg_Err( p_filter, "cannot allocate SPU region" );
@@ -1171,7 +1139,8 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
         return NULL;
     }
 
-    vout_CopyPicture( p_filter, &p_region->picture, p_pic );
+    /* FIXME the copy is probably not needed anymore */
+    picture_Copy( p_region->p_picture, p_pic );
 
     p_sys->b_need_update = false;
 
@@ -1182,8 +1151,6 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
     p_spu->b_absolute = false;
 
 
-    p_spu->i_x = 0;
-    p_spu->i_y = 0;
     p_spu->i_original_picture_width = 0; /*Let vout core do the horizontal scaling */
     p_spu->i_original_picture_height = fmt.i_height;
 
@@ -1331,38 +1298,33 @@ static inline bool raw_line(  filter_sys_t* p_sys,
 /*****************************************************************************
  * MouseEvent: callback for mouse events
  *****************************************************************************/
-static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
-                       vlc_value_t oldval, vlc_value_t newval, void *p_data )
+static int MouseEvent( filter_t *p_filter,
+                       const vlc_mouse_t *p_old,
+                       const vlc_mouse_t *p_new,
+                       const video_format_t *p_fmt )
 {
-    VLC_UNUSED(oldval); VLC_UNUSED(newval); VLC_UNUSED(psz_var);
-
-    filter_t *p_filter = (filter_t *)p_data;
     filter_sys_t *p_sys = p_filter->p_sys;
+    VLC_UNUSED(p_old);
 
     if( !p_sys->b_vnc_mouse_events )
         return VLC_SUCCESS;
 
-    vout_thread_t *p_vout = (vout_thread_t*)p_sys->p_vout;
-    int i_x, i_y;
-    int i_v;
-
-
-    i_v = var_GetInteger( p_sys->p_vout, "mouse-button-down" );
-    i_y = var_GetInteger( p_sys->p_vout, "mouse-y" );
-    i_x = var_GetInteger( p_sys->p_vout, "mouse-x" );
+    int i_v = p_new->i_pressed;
+    int i_x = p_new->i_x;
+    int i_y = p_new->i_y;
 
     vlc_mutex_lock( &p_sys->lock );
 
-    const int v_h = p_vout->fmt_in.i_visible_height;
+    const int v_h = p_fmt->i_visible_height;
     const int v_w = p_sys->i_vnc_width * v_h / p_sys->i_vnc_height;
-    const int v_x = (p_vout->fmt_in.i_visible_width-v_w)/2;
+    const int v_x = (p_fmt->i_visible_width-v_w)/2;
 
     i_x -= v_x;
 
     if( i_y < 0 || i_x < 0 || i_y >= v_h || i_x >= v_w )
     {
         vlc_mutex_unlock( &p_sys->lock );
-        msg_Dbg( p_this, "invalid mouse event? x=%d y=%d btn=%x", i_x, i_y, i_v );
+        msg_Dbg( p_filter, "invalid mouse event? x=%d y=%d btn=%x", i_x, i_y, i_v );
         return VLC_SUCCESS;
     }
     if( !p_sys->b_connection_active )
@@ -1372,7 +1334,7 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
     }
 
 #ifdef VNC_DEBUG
-    msg_Dbg( p_this, "mouse event x=%d y=%d btn=%x", i_x, i_y, i_v );
+    msg_Dbg( p_filter, "mouse event x=%d y=%d btn=%x", i_x, i_y, i_v );
 #endif
 
     /* */
@@ -1391,7 +1353,7 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
 
     vlc_mutex_unlock( &p_sys->lock );
 
-    return VLC_SUCCESS;
+    return VLC_EGENERIC;
 }
 
 /*****************************************************************************
@@ -1408,11 +1370,11 @@ static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
     if( !p_sys->b_vnc_key_events )
         return VLC_SUCCESS;
 
-    msg_Dbg( p_this, "key pressed (%d) ", newval.i_int );
+    msg_Dbg( p_this, "key pressed (%"PRId64") ", newval.i_int );
 
     if ( !newval.i_int )
     {
-        msg_Err( p_this, "Received invalid key event %d", newval.i_int );
+        msg_Err( p_this, "Received invalid key event 0" );
         return VLC_EGENERIC;
     }