]> 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 3385a8f9f45a833d62688ec03a0f2fe5e6dde89d..c5dff9d3aab5c28c377d3c5b327eb7c9bc6eb1ec 100644 (file)
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #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 * );
 
 /*****************************************************************************
@@ -65,29 +64,31 @@ static int  SendEvents( vlc_object_t *, char const *,
 #define TYPE_TEXT N_("Transform type")
 #define TYPE_LONGTEXT N_("One of '90', '180', '270', 'hflip' and 'vflip'")
 
-static const char *type_list[] = { "90", "180", "270", "hflip", "vflip" };
-static const char *type_list_text[] = { N_("Rotate by 90 degrees"),
+static const char *const type_list[] = { "90", "180", "270", "hflip", "vflip" };
+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( _("Video transformation filter") );
-    set_shortname( _("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 *ppsz_filter_options[] = {
+static const char *const ppsz_filter_options[] = {
     "type", NULL
 };
 
@@ -127,10 +128,7 @@ static int Create( vlc_object_t *p_this )
     /* Allocate structure */
     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
     if( p_vout->p_sys == NULL )
-    {
-        msg_Err( p_vout, "out of memory" );
         return VLC_ENOMEM;
-    }
 
     p_vout->pf_init = Init;
     p_vout->pf_end = End;
@@ -143,17 +141,17 @@ static int Create( vlc_object_t *p_this )
                            p_vout->p_cfg );
 
     /* Look what method was requested */
-    psz_method = var_CreateGetNonEmptyString( p_vout, "transform-type" );
+    psz_method = var_CreateGetNonEmptyStringCommand( p_vout, "transform-type" );
 
     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;
 
@@ -219,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;
@@ -247,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;
     }
@@ -263,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;
 }
@@ -277,14 +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;
 
-    /* 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_filter_DelChild( p_vout, p_sys->p_vout, MouseEvent );
+    vout_CloseAndRelease( p_sys->p_vout );
+
+    vout_filter_ReleaseDirectBuffers( p_vout );
 }
 
 /*****************************************************************************
@@ -296,15 +285,6 @@ static void Destroy( vlc_object_t *p_this )
 {
     vout_thread_t *p_vout = (vout_thread_t *)p_this;
 
-    if( p_vout->p_sys->p_vout )
-    {
-        DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
-        vlc_object_detach( p_vout->p_sys->p_vout );
-        vout_Destroy( p_vout->p_sys->p_vout );
-    }
-
-    DEL_PARENT_CALLBACKS( SendEventsToChild );
-
     free( p_vout->p_sys );
 }
 
@@ -323,14 +303,14 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
     while( ( p_outpic = vout_CreatePicture( p_vout->p_sys->p_vout, 0, 0, 0 ) )
               == NULL )
     {
-        if( p_vout->b_die || p_vout->b_error )
+        if( !vlc_object_alive (p_vout) || p_vout->b_error )
         {
             return;
         }
         msleep( VOUT_OUTMEM_SLEEP );
     }
 
-    vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date );
+    p_outpic->date = p_pic->date;
     vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic );
 
     p_vout->p_sys->pf_filter( p_vout, p_pic, p_outpic );
@@ -340,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,
@@ -510,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;
@@ -524,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;
@@ -549,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;
@@ -719,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;
@@ -846,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;
@@ -871,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;