]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/transform.c
Use var_InheritString for --decklink-video-connection.
[vlc] / modules / video_filter / transform.c
index 541f08b142946aa10125c1dc2f99d91ea2ac1e6c..c5dff9d3aab5c28c377d3c5b327eb7c9bc6eb1ec 100644 (file)
@@ -33,7 +33,6 @@
 #include <vlc_plugin.h>
 #include <vlc_vout.h>
 
-#include "filter_common.h"
 #include "filter_picture.h"
 
 #define TRANSFORM_MODE_HFLIP   1
@@ -56,7 +55,7 @@ static void FilterPlanar( vout_thread_t *, const picture_t *, picture_t * );
 static void FilterI422( vout_thread_t *, const picture_t *, picture_t * );
 static void FilterYUYV( vout_thread_t *, const picture_t *, picture_t * );
 
-static int  SendEvents( vlc_object_t *, char const *,
+static int  MouseEvent( vlc_object_t *, char const *,
                         vlc_value_t, vlc_value_t, void * );
 
 /*****************************************************************************
@@ -70,22 +69,24 @@ static const char *const type_list_text[] = { N_("Rotate by 90 degrees"),
   N_("Rotate by 180 degrees"), N_("Rotate by 270 degrees"),
   N_("Flip horizontally"), N_("Flip vertically") };
 
+#define TRANSFORM_HELP N_("Rotate or flip the video")
 #define CFG_PREFIX "transform-"
 
-vlc_module_begin();
-    set_description( N_("Video transformation filter") );
-    set_shortname( N_("Transformation"));
-    set_capability( "video filter", 0 );
-    set_category( CAT_VIDEO );
-    set_subcategory( SUBCAT_VIDEO_VFILTER );
+vlc_module_begin ()
+    set_description( N_("Video transformation filter") )
+    set_shortname( N_("Transformation"))
+    set_help(TRANSFORM_HELP)
+    set_capability( "video filter", 0 )
+    set_category( CAT_VIDEO )
+    set_subcategory( SUBCAT_VIDEO_VFILTER )
 
     add_string( CFG_PREFIX "type", "90", NULL,
-                          TYPE_TEXT, TYPE_LONGTEXT, false);
-        change_string_list( type_list, type_list_text, 0);
+                          TYPE_TEXT, TYPE_LONGTEXT, false)
+        change_string_list( type_list, type_list_text, 0)
 
-    add_shortcut( "transform" );
-    set_callbacks( Create, Destroy );
-vlc_module_end();
+    add_shortcut( "transform" )
+    set_callbacks( Create, Destroy )
+vlc_module_end ()
 
 static const char *const ppsz_filter_options[] = {
     "type", NULL
@@ -145,12 +146,12 @@ static int Create( vlc_object_t *p_this )
     switch( p_vout->fmt_in.i_chroma )
     {
         CASE_PLANAR_YUV_SQUARE
-        case VLC_FOURCC('G','R','E','Y'):
+        case VLC_CODEC_GREY:
             p_vout->p_sys->pf_filter = FilterPlanar;
             break;
 
-        case VLC_FOURCC('I','4','2','2'):
-        case VLC_FOURCC('J','4','2','2'):
+        case VLC_CODEC_I422:
+        case VLC_CODEC_J422:
             p_vout->p_sys->pf_filter = FilterI422;
             break;
 
@@ -216,8 +217,6 @@ static int Create( vlc_object_t *p_this )
  *****************************************************************************/
 static int Init( vout_thread_t *p_vout )
 {
-    int i_index;
-    picture_t *p_pic;
     video_format_t fmt;
 
     I_OUTPUTPICTURES = 0;
@@ -244,9 +243,6 @@ static int Init( vout_thread_t *p_vout )
         fmt.i_visible_height = p_vout->fmt_out.i_visible_width;
         fmt.i_y_offset = p_vout->fmt_out.i_x_offset;
 
-        fmt.i_aspect = VOUT_ASPECT_FACTOR *
-            (uint64_t)VOUT_ASPECT_FACTOR / fmt.i_aspect;
-
         fmt.i_sar_num = p_vout->fmt_out.i_sar_den;
         fmt.i_sar_den = p_vout->fmt_out.i_sar_num;
     }
@@ -260,11 +256,9 @@ static int Init( vout_thread_t *p_vout )
         return VLC_EGENERIC;
     }
 
-    ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
+    vout_filter_AllocateDirectBuffers( p_vout, VOUT_MAX_PICTURES );
 
-    ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
-
-    ADD_PARENT_CALLBACKS( SendEventsToChild );
+    vout_filter_AddChild( p_vout, p_vout->p_sys->p_vout, MouseEvent );
 
     return VLC_SUCCESS;
 }
@@ -274,20 +268,12 @@ static int Init( vout_thread_t *p_vout )
  *****************************************************************************/
 static void End( vout_thread_t *p_vout )
 {
-    int i_index;
+    vout_sys_t *p_sys = p_vout->p_sys;
 
-    DEL_PARENT_CALLBACKS( SendEventsToChild );
+    vout_filter_DelChild( p_vout, p_sys->p_vout, MouseEvent );
+    vout_CloseAndRelease( p_sys->p_vout );
 
-    DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
-
-    /* Free the fake output buffers we allocated */
-    for( i_index = I_OUTPUTPICTURES ; i_index ; )
-    {
-        i_index--;
-        free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
-    }
-
-    vout_CloseAndRelease( p_vout->p_sys->p_vout );
+    vout_filter_ReleaseDirectBuffers( p_vout );
 }
 
 /*****************************************************************************
@@ -334,77 +320,51 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
     vout_DisplayPicture( p_vout->p_sys->p_vout, p_outpic );
 }
 
-/*****************************************************************************
- * SendEvents: forward mouse and keyboard events to the parent p_vout
- *****************************************************************************/
-static int SendEvents( vlc_object_t *p_this, char const *psz_var,
-                       vlc_value_t oldval, vlc_value_t newval, void *_p_vout )
+/**
+ * Forward mouse event with proper conversion.
+ */
+static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
+                       vlc_value_t oldval, vlc_value_t val, void *p_data )
 {
+    vout_thread_t *p_vout = p_data;
     VLC_UNUSED(p_this); VLC_UNUSED(oldval);
-    vout_thread_t *p_vout = (vout_thread_t *)_p_vout;
-    vlc_value_t sentval = newval;
 
-    /* Translate the mouse coordinates */
-    if( !strcmp( psz_var, "mouse-x" ) )
+    /* Translate the mouse coordinates
+     * FIXME missing lock */
+    if( !strcmp( psz_var, "mouse-button-down" ) )
+        return var_SetChecked( p_vout, psz_var, VLC_VAR_INTEGER, val );
+
+    int x = val.coords.x, y = val.coords.y;
+
+    switch( p_vout->p_sys->i_mode )
     {
-        switch( p_vout->p_sys->i_mode )
-        {
-        case TRANSFORM_MODE_270:
-            sentval.i_int = p_vout->p_sys->p_vout->output.i_width
-                             - sentval.i_int;
         case TRANSFORM_MODE_90:
-            var_Set( p_vout, "mouse-y", sentval );
-            return VLC_SUCCESS;
+            x = p_vout->p_sys->p_vout->output.i_height - val.coords.y;
+            y = val.coords.x;
+            break;
 
         case TRANSFORM_MODE_180:
-        case TRANSFORM_MODE_HFLIP:
-            sentval.i_int = p_vout->p_sys->p_vout->output.i_width
-                             - sentval.i_int;
+            x = p_vout->p_sys->p_vout->output.i_width - val.coords.x;
+            y = p_vout->p_sys->p_vout->output.i_height - val.coords.y;
             break;
 
-        case TRANSFORM_MODE_VFLIP:
-        default:
-            break;
-        }
-    }
-    else if( !strcmp( psz_var, "mouse-y" ) )
-    {
-        switch( p_vout->p_sys->i_mode )
-        {
-        case TRANSFORM_MODE_90:
-            sentval.i_int = p_vout->p_sys->p_vout->output.i_height
-                             - sentval.i_int;
         case TRANSFORM_MODE_270:
-            var_Set( p_vout, "mouse-x", sentval );
-            return VLC_SUCCESS;
+            x = val.coords.y;
+            y = p_vout->p_sys->p_vout->output.i_width - val.coords.x;
+            break;
+
+        case TRANSFORM_MODE_HFLIP:
+            x = p_vout->p_sys->p_vout->output.i_width - val.coords.x;
+            break;
 
-        case TRANSFORM_MODE_180:
         case TRANSFORM_MODE_VFLIP:
-            sentval.i_int = p_vout->p_sys->p_vout->output.i_height
-                             - sentval.i_int;
+            y = p_vout->p_sys->p_vout->output.i_height - val.coords.y;
             break;
 
-        case TRANSFORM_MODE_HFLIP:
         default:
             break;
-        }
     }
-
-    var_Set( p_vout, psz_var, sentval );
-
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * SendEventsToChild: forward events to the child/children vout
- *****************************************************************************/
-static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
-                       vlc_value_t oldval, vlc_value_t newval, void *p_data )
-{
-    VLC_UNUSED(p_data); VLC_UNUSED(oldval);
-    vout_thread_t *p_vout = (vout_thread_t *)p_this;
-    var_Set( p_vout->p_sys->p_vout, psz_var, newval );
-    return VLC_SUCCESS;
+    return var_SetCoords( p_vout, psz_var, x, y );
 }
 
 static void FilterPlanar( vout_thread_t *p_vout,
@@ -504,7 +464,7 @@ static void FilterPlanar( vout_thread_t *p_vout,
             }
             break;
 
-        case TRANSFORM_MODE_HFLIP:
+        case TRANSFORM_MODE_VFLIP:
             for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
             {
                 uint8_t *p_in = p_pic->p[i_index].p_pixels;
@@ -518,12 +478,12 @@ static void FilterPlanar( vout_thread_t *p_vout,
                     p_in_end -= p_pic->p[i_index].i_pitch;
                     vlc_memcpy( p_out, p_in_end,
                                 p_pic->p[i_index].i_visible_pitch );
-                    p_out += p_pic->p[i_index].i_pitch;
+                    p_out += p_outpic->p[i_index].i_pitch;
                 }
             }
             break;
 
-        case TRANSFORM_MODE_VFLIP:
+        case TRANSFORM_MODE_HFLIP:
             for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
             {
                 uint8_t *p_in = p_pic->p[i_index].p_pixels;
@@ -543,6 +503,8 @@ static void FilterPlanar( vout_thread_t *p_vout,
                     }
 
                     p_in += p_pic->p[i_index].i_pitch;
+                    p_out += p_outpic->p[i_index].i_pitch
+                                - p_outpic->p[i_index].i_visible_pitch;
                 }
             }
             break;
@@ -713,7 +675,7 @@ static void FilterYUYV( vout_thread_t *p_vout,
 
     switch( p_vout->p_sys->i_mode )
     {
-        case TRANSFORM_MODE_HFLIP:
+        case TRANSFORM_MODE_VFLIP:
             /* Fall back on the default implementation */
             FilterPlanar( p_vout, p_pic, p_outpic );
             return;
@@ -840,7 +802,7 @@ static void FilterYUYV( vout_thread_t *p_vout,
             }
             break;
 
-        case TRANSFORM_MODE_VFLIP:
+        case TRANSFORM_MODE_HFLIP:
             for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
             {
                 uint8_t *p_in = p_pic->p[i_index].p_pixels;
@@ -865,6 +827,8 @@ static void FilterYUYV( vout_thread_t *p_vout,
                     }
 
                     p_in += p_pic->p[i_index].i_pitch;
+                    p_out += p_outpic->p[i_index].i_pitch
+                                - p_outpic->p[i_index].i_visible_pitch;
                 }
             }
             break;