]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/distort.c
CD/DVD detection patch by Brian Robb
[vlc] / modules / video_filter / distort.c
index 02c9fdd76ea76882821992a7bb4564347e00068f..e370ea35a09f4742a093d8a9d9181381c74a9ee0 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * distort.c : Misc video effects plugin for vlc
  *****************************************************************************
- * Copyright (C) 2000, 2001, 2002, 2003 VideoLAN
- * $Id: distort.c,v 1.8 2003/03/18 23:30:28 gbazin Exp $
+ * Copyright (C) 2000, 2001, 2002, 2003 the VideoLAN team
+ * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -56,17 +56,23 @@ static int  SendEvents   ( vlc_object_t *, char const *,
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
-#define MODE_TEXT N_("distort mode")
+#define MODE_TEXT N_("Distort mode")
 #define MODE_LONGTEXT N_("Distort mode, one of \"wave\" and \"ripple\"")
 
-static char *mode_list[] = { "wave", "ripple", NULL };
+static char *mode_list[] = { "wave", "ripple" };
+static char *mode_list_text[] = { N_("Wave"), N_("Ripple") };
 
 vlc_module_begin();
-    add_category_hint( N_("Distort"), NULL, VLC_FALSE );
-    add_string_from_list( "distort-mode", "wave", mode_list, NULL,
-                          MODE_TEXT, MODE_LONGTEXT, VLC_FALSE );
-    set_description( _("miscellaneous video effects module") );
+    set_description( _("Distort video filter") );
+    set_shortname( N_( "Distortion" ));
     set_capability( "video filter", 0 );
+    set_category( CAT_VIDEO );
+    set_subcategory( SUBCAT_VIDEO_VFILTER );
+
+    add_string( "distort-mode", "wave", NULL, MODE_TEXT, MODE_LONGTEXT,
+                VLC_FALSE );
+        change_string_list( mode_list, mode_list_text, 0 );
+
     add_shortcut( "distort" );
     set_callbacks( Create, Destroy );
 vlc_module_end();
@@ -87,6 +93,14 @@ struct vout_sys_t
     mtime_t last_date;
 };
 
+/*****************************************************************************
+ * Control: control facility for the vout (forwards to child vout)
+ *****************************************************************************/
+static int Control( vout_thread_t *p_vout, int i_query, va_list args )
+{
+    return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
+}
+
 /*****************************************************************************
  * Create: allocates Distort video thread output method
  *****************************************************************************
@@ -110,55 +124,33 @@ static int Create( vlc_object_t *p_this )
     p_vout->pf_manage = NULL;
     p_vout->pf_render = Render;
     p_vout->pf_display = NULL;
+    p_vout->pf_control = Control;
 
     p_vout->p_sys->i_mode = 0;
-    /* Look what method was requested from command line*/
-    if( !(psz_method = psz_method_tmp = config_GetPsz( p_vout, "filter" )) )
-    {
-        msg_Err( p_vout, "configuration variable %s empty", "filter" );
-        return VLC_EGENERIC;
-    }
-    while( *psz_method && *psz_method != ':' )
-    {
-        psz_method++;
-    }
 
-    if( !strcmp( psz_method, ":wave" ) )
+    if( !(psz_method = psz_method_tmp
+          = config_GetPsz( p_vout, "distort-mode" )) )
     {
+        msg_Err( p_vout, "configuration variable %s empty, using 'wave'",
+                         "distort-mode" );
         p_vout->p_sys->i_mode = DISTORT_MODE_WAVE;
     }
-    else if( !strcmp( psz_method, ":ripple" ) )
+    else
     {
-        p_vout->p_sys->i_mode = DISTORT_MODE_RIPPLE;
-    }
-    free( psz_method_tmp );
-    if( !p_vout->p_sys->i_mode )
-    {
-        /* No method given in commandline. Look what method was
-         requested in configuration system */
-        if( !(psz_method = psz_method_tmp
-              = config_GetPsz( p_vout, "distort-mode" )) )
+
+        if( !strcmp( psz_method, "wave" ) )
         {
-            msg_Err( p_vout, "configuration variable %s empty, using 'wave'",
-                             "distort-mode" );
             p_vout->p_sys->i_mode = DISTORT_MODE_WAVE;
         }
-        else {
-
-            if( !strcmp( psz_method, "wave" ) )
-            {
-                p_vout->p_sys->i_mode = DISTORT_MODE_WAVE;
-            }
-            else if( !strcmp( psz_method, "ripple" ) )
-            {
-                p_vout->p_sys->i_mode = DISTORT_MODE_RIPPLE;
-            }
-            else
-            {
-                msg_Err( p_vout, "no valid distort mode provided, "
-                                 "using wave" );
-                p_vout->p_sys->i_mode = DISTORT_MODE_WAVE;
-            }
+        else if( !strcmp( psz_method, "ripple" ) )
+        {
+            p_vout->p_sys->i_mode = DISTORT_MODE_RIPPLE;
+        }
+        else
+        {
+            msg_Err( p_vout, "no valid distort mode provided, "
+                             "using wave" );
+            p_vout->p_sys->i_mode = DISTORT_MODE_WAVE;
         }
     }
     free( psz_method_tmp );
@@ -173,6 +165,7 @@ static int Init( vout_thread_t *p_vout )
 {
     int i_index;
     picture_t *p_pic;
+    video_format_t fmt = {0};
 
     I_OUTPUTPICTURES = 0;
 
@@ -182,18 +175,23 @@ static int Init( vout_thread_t *p_vout )
     p_vout->output.i_height = p_vout->render.i_height;
     p_vout->output.i_aspect = p_vout->render.i_aspect;
 
+    fmt.i_width = fmt.i_visible_width = p_vout->render.i_width;
+    fmt.i_height = fmt.i_visible_height = p_vout->render.i_height;
+    fmt.i_x_offset = fmt.i_y_offset = 0;
+    fmt.i_chroma = p_vout->render.i_chroma;
+    fmt.i_aspect = p_vout->render.i_aspect;
+    fmt.i_sar_num = p_vout->render.i_aspect * fmt.i_height / fmt.i_width;
+    fmt.i_sar_den = VOUT_ASPECT_FACTOR;
+
     /* Try to open the real video output */
     msg_Dbg( p_vout, "spawning the real video output" );
 
-    p_vout->p_sys->p_vout = vout_Create( p_vout,
-                           p_vout->render.i_width, p_vout->render.i_height,
-                           p_vout->render.i_chroma, p_vout->render.i_aspect );
+    p_vout->p_sys->p_vout = vout_Create( p_vout, &fmt );
 
     /* Everything failed */
     if( p_vout->p_sys->p_vout == NULL )
     {
         msg_Err( p_vout, "cannot open vout, aborting" );
-
         return VLC_EGENERIC;
     }
 
@@ -201,6 +199,8 @@ static int Init( vout_thread_t *p_vout )
 
     ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
 
+    ADD_PARENT_CALLBACKS( SendEventsToChild );
+
     p_vout->p_sys->f_angle = 0.0;
     p_vout->p_sys->last_date = 0;
 
@@ -231,9 +231,14 @@ static void Destroy( vlc_object_t *p_this )
 {
     vout_thread_t *p_vout = (vout_thread_t *)p_this;
 
-    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 );
+    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 );
 }
@@ -302,7 +307,7 @@ static void DistortWave( vout_thread_t *p_vout, picture_t *p_inpic,
         p_in = p_inpic->p[i_index].p_pixels;
         p_out = p_outpic->p[i_index].p_pixels;
 
-        i_num_lines = p_inpic->p[i_index].i_lines;
+        i_num_lines = p_inpic->p[i_index].i_visible_lines;
 
         black_pixel = ( i_index == Y_PLANE ) ? 0x00 : 0x80;
 
@@ -368,7 +373,7 @@ static void DistortRipple( vout_thread_t *p_vout, picture_t *p_inpic,
 
         black_pixel = ( i_index == Y_PLANE ) ? 0x00 : 0x80;
 
-        i_num_lines = p_inpic->p[i_index].i_lines;
+        i_num_lines = p_inpic->p[i_index].i_visible_lines;
 
         i_first_line = i_num_lines * 4 / 5;
 
@@ -437,3 +442,13 @@ static int SendEvents( vlc_object_t *p_this, char const *psz_var,
     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 )
+{
+    vout_thread_t *p_vout = (vout_thread_t *)p_this;
+    var_Set( p_vout->p_sys->p_vout, psz_var, newval );
+    return VLC_SUCCESS;
+}