]> git.sesse.net Git - vlc/blobdiff - modules/visualization/visual/visual.c
input options whitelisting, step 2 (refs #1371)
[vlc] / modules / visualization / visual / visual.c
index 8c2c182cbc5fd41a67d4435746695bd944c1605b..38f79e80efc862996251d9eb82442f29ba31b4a8 100644 (file)
@@ -1,10 +1,10 @@
 /*****************************************************************************
  * visual.c : Visualisation system
  *****************************************************************************
- * Copyright (C) 2002 VideoLAN
- * $Id: visual.c,v 1.9 2003/09/20 00:37:53 fenrir Exp $
+ * Copyright (C) 2002-2006 the VideoLAN team
+ * $Id$
  *
- * Authors: Clément Stenac <zorglub@via.ecp.fr>
+ * Authors: Clément Stenac <zorglub@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
 #include <vlc/vlc.h>
-#include <vlc/vout.h>
-#include "audio_output.h"
-#include "aout_internal.h"
+#include <vlc_vout.h>
+#include <vlc_aout.h>
 
 #include "visual.h"
 
 #define ELIST_TEXT N_( "Effects list" )
 #define ELIST_LONGTEXT N_( \
       "A list of visual effect, separated by commas.\n"  \
-      "Current effects include: dummy, random, scope, spectrum" )
+      "Current effects include: dummy, scope, spectrum." )
 
 #define WIDTH_TEXT N_( "Video width" )
-#define HEIGHT_LONGTEXT N_( \
-      "The width of the effects video window, in pixels." )
-
-#define HEIGHT_TEXT N_( "Video width" )
 #define WIDTH_LONGTEXT N_( \
       "The width of the effects video window, in pixels." )
 
+#define HEIGHT_TEXT N_( "Video height" )
+#define HEIGHT_LONGTEXT N_( \
+      "The height of the effects video window, in pixels." )
+
 #define NBBANDS_TEXT N_( "Number of bands" )
 #define NBBANDS_LONGTEXT N_( \
-      "Number of bands used by spectrum analizer, should be 20 or 80" )
+      "Number of bands used by spectrum analyzer, should be 20 or 80." )
+#define SPNBBANDS_LONGTEXT N_( \
+      "Number of bands used by the spectrometer, from 20 to 80." )
 
 #define SEPAR_TEXT N_( "Band separator" )
 #define SEPAR_LONGTEXT N_( \
-        "Number of blank pixels between bands")
+        "Number of blank pixels between bands.")
 
 #define AMP_TEXT N_( "Amplification" )
 #define AMP_LONGTEXT N_( \
-        "This is a coefficient that modifies the height of the bands")
+        "This is a coefficient that modifies the height of the bands.")
 
 #define PEAKS_TEXT N_( "Enable peaks" )
 #define PEAKS_LONGTEXT N_( \
-        "Defines whether to draw peaks" )
+        "Draw \"peaks\" in the spectrum analyzer." )
+
+#define ORIG_TEXT N_( "Enable original graphic spectrum" )
+#define ORIG_LONGTEXT N_( \
+        "Enable the \"flat\" spectrum analyzer in the spectrometer." )
+
+#define BANDS_TEXT N_( "Enable bands" )
+#define BANDS_LONGTEXT N_( \
+        "Draw bands in the spectrometer." )
+
+#define BASE_TEXT N_( "Enable base" )
+#define BASE_LONGTEXT N_( \
+        "Defines whether to draw the base of the bands." )
+
+#define RADIUS_TEXT N_( "Base pixel radius" )
+#define RADIUS_LONGTEXT N_( \
+        "Defines radius size in pixels, of base of bands(beginning)." )
+
+#define SSECT_TEXT N_( "Spectral sections" )
+#define SSECT_LONGTEXT N_( \
+        "Determines how many sections of spectrum will exist." )
+
+#define PEAK_HEIGHT_TEXT N_( "Peak height" )
+#define PEAK_HEIGHT_LONGTEXT N_( \
+        "Total pixel height of the peak items." )
+
+#define PEAK_WIDTH_TEXT N_( "Peak extra width" )
+#define PEAK_WIDTH_LONGTEXT N_( \
+        "Additions or subtractions of pixels on the peak width." )
+
+#define COLOR1_TEXT N_( "V-plane color" )
+#define COLOR1_LONGTEXT N_( \
+        "YUV-Color cube shifting across the V-plane ( 0 - 127 )." )
 
 #define STARS_TEXT N_( "Number of stars" )
 #define STARS_LONGTEXT N_( \
-        "Defines the number of stars to draw with random effect" )
+        "Number of stars to draw with random effect." )
 
 static int  Open         ( vlc_object_t * );
 static void Close        ( vlc_object_t * );
 
 vlc_module_begin();
-    add_category_hint( N_("visualizer") , NULL , VLC_FALSE);
-    set_description( _("visualizer filter") );
-    add_string("effect-list", "dummy", NULL,
+    set_shortname( _("Visualizer"));
+    set_category( CAT_AUDIO );
+    set_subcategory( SUBCAT_AUDIO_VISUAL );
+    set_description( _("Visualizer filter") );
+    set_section( N_( "General") , NULL );
+    add_string("effect-list", "spectrum", NULL,
             ELIST_TEXT, ELIST_LONGTEXT, VLC_TRUE );
+        change_safe();
     add_integer("effect-width",VOUT_WIDTH,NULL,
              WIDTH_TEXT, WIDTH_LONGTEXT, VLC_FALSE );
+        change_safe();
     add_integer("effect-height" , VOUT_HEIGHT , NULL,
              HEIGHT_TEXT, HEIGHT_LONGTEXT, VLC_FALSE );
+        change_safe();
+    set_section( N_("Spectrum analyser") , NULL );
     add_integer("visual-nbbands", 80, NULL,
-             NBBANDS_TEXT, NBBANDS_LONGTEXT, VLC_FALSE );
+             NBBANDS_TEXT, NBBANDS_LONGTEXT, VLC_TRUE );
+        change_safe();
     add_integer("visual-separ", 1, NULL,
-             SEPAR_TEXT, SEPAR_LONGTEXT, VLC_FALSE );
+             SEPAR_TEXT, SEPAR_LONGTEXT, VLC_TRUE );
+        change_safe();
     add_integer("visual-amp", 3, NULL,
-             AMP_TEXT, AMP_LONGTEXT, VLC_FALSE );
+             AMP_TEXT, AMP_LONGTEXT, VLC_TRUE );
+        change_safe();
     add_bool("visual-peaks", VLC_TRUE, NULL,
-             PEAKS_TEXT, PEAKS_LONGTEXT, VLC_FALSE );
-    add_integer("visual-stars", 200, NULL,
-             STARS_TEXT, STARS_LONGTEXT, VLC_FALSE );
-    set_capability( "audio filter", 0 );
+             PEAKS_TEXT, PEAKS_LONGTEXT, VLC_TRUE );
+        change_safe();
+    set_section( N_("Spectrometer") , NULL );
+    add_bool("spect-show-original", VLC_FALSE, NULL,
+             ORIG_TEXT, ORIG_LONGTEXT, VLC_TRUE );
+        change_safe();
+    add_bool("spect-show-base", VLC_TRUE, NULL,
+             BASE_TEXT, BASE_LONGTEXT, VLC_TRUE );
+        change_safe();
+    add_integer("spect-radius", 42, NULL,
+             RADIUS_TEXT, RADIUS_LONGTEXT, VLC_TRUE );
+        change_safe();
+    add_integer("spect-sections", 3, NULL,
+             SSECT_TEXT, SSECT_LONGTEXT, VLC_TRUE );
+        change_safe();
+    add_integer("spect-color", 80, NULL,
+             COLOR1_TEXT, COLOR1_LONGTEXT, VLC_TRUE );
+        change_safe();
+    add_bool("spect-show-bands", VLC_TRUE, NULL,
+             BANDS_TEXT, BANDS_LONGTEXT, VLC_TRUE );
+        change_safe();
+    add_integer("spect-nbbands", 32, NULL,
+             NBBANDS_TEXT, SPNBBANDS_LONGTEXT, VLC_TRUE );
+        change_safe();
+    add_integer("spect-separ", 1, NULL,
+             SEPAR_TEXT, SEPAR_LONGTEXT, VLC_TRUE );
+        change_safe();
+    add_integer("spect-amp", 8, NULL,
+             AMP_TEXT, AMP_LONGTEXT, VLC_TRUE );
+        change_safe();
+    add_bool("spect-show-peaks", VLC_TRUE, NULL,
+             PEAKS_TEXT, PEAKS_LONGTEXT, VLC_TRUE );
+        change_safe();
+    add_integer("spect-peak-width", 61, NULL,
+             PEAK_WIDTH_TEXT, PEAK_WIDTH_LONGTEXT, VLC_TRUE );
+        change_safe();
+    add_integer("spect-peak-height", 1, NULL,
+             PEAK_HEIGHT_TEXT, PEAK_HEIGHT_LONGTEXT, VLC_TRUE );
+        change_safe();
+    set_capability( "visualization", 0 );
     set_callbacks( Open, Close );
     add_shortcut( "visualizer");
 vlc_module_end();
@@ -101,16 +179,18 @@ vlc_module_end();
  *****************************************************************************/
 static void DoWork( aout_instance_t *, aout_filter_t *,
                     aout_buffer_t *, aout_buffer_t * );
+static int FilterCallback( vlc_object_t *, char const *,
+                           vlc_value_t, vlc_value_t, void * );
 static struct
 {
-    char *psz_name;
+    const char *psz_name;
     int  (*pf_run)( visual_effect_t *, aout_instance_t *,
                     aout_buffer_t *, picture_t *);
 } pf_effect_run[]=
 {
     { "scope",      scope_Run },
     { "spectrum",   spectrum_Run },
-    { "random",     random_Run},
+    { "spectrometer",   spectrometer_Run },
     { "dummy",      dummy_Run},
     { NULL,         dummy_Run}
 };
@@ -122,8 +202,11 @@ static int Open( vlc_object_t *p_this )
 {
     aout_filter_t     *p_filter = (aout_filter_t *)p_this;
     aout_filter_sys_t *p_sys;
+    vlc_value_t        val;
 
     char *psz_effects, *psz_parser;
+    video_format_t fmt;
+
 
     if( ( p_filter->input.i_format != VLC_FOURCC('f','l','3','2') &&
           p_filter->input.i_format != VLC_FOURCC('f','i','3','2') ) )
@@ -150,8 +233,12 @@ static int Open( vlc_object_t *p_this )
     p_sys->effect   = NULL;
 
     /* Parse the effect list */
-    psz_parser = psz_effects = config_GetPsz( p_filter, "effect-list" );
-    msg_Dbg( p_filter , "Building list of effects" );
+    var_Create( p_filter, "effect-list", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    var_Get( p_filter, "effect-list", &val);
+    psz_parser = psz_effects = strdup( val.psz_string );
+    free( val.psz_string );
+
+    var_AddCallback( p_filter, "effect-list", FilterCallback, NULL );
 
     while( psz_parser && *psz_parser != '\0' )
     {
@@ -192,19 +279,20 @@ static int Open( vlc_object_t *p_this )
 
                 if( ( psz_eoa = strchr( psz_parser, '}') ) == NULL )
                 {
-                   msg_Err( p_filter, "Unable to parse effect list. Aborting");
+                   msg_Err( p_filter, "unable to parse effect list. Aborting");
                    break;
                 }
-                p_effect->psz_args = strndup( psz_parser, psz_eoa - psz_parser);
+                p_effect->psz_args =
+                    strndup( psz_parser, psz_eoa - psz_parser);
             }
+            TAB_APPEND( p_sys->i_effect, p_sys->effect, p_effect );
         }
         else
         {
-            msg_Err( p_filter, "unknown visual effect" );
+            msg_Err( p_filter, "unknown visual effect: %s", psz_parser );
+            free( p_effect );
         }
 
-        TAB_APPEND( p_sys->i_effect, p_sys->effect, p_effect );
-
         if( strchr( psz_parser, ',' ) )
         {
             psz_parser = strchr( psz_parser, ',' ) + 1;
@@ -224,14 +312,23 @@ static int Open( vlc_object_t *p_this )
         free( psz_effects );
     }
 
+    if( !p_sys->i_effect )
+    {
+        msg_Err( p_filter, "no effects found" );
+        free( p_sys );
+        return VLC_EGENERIC;
+    }
 
     /* Open the video output */
-    p_sys->p_vout =
-         vout_Request( p_filter, NULL,
-                       p_sys->i_width, p_sys->i_height,
-                       VLC_FOURCC('I','4','2','0'),
-                       VOUT_ASPECT_FACTOR * p_sys->i_width/p_sys->i_height );
+    memset( &fmt, 0, sizeof(video_format_t) );
+
+    fmt.i_width = fmt.i_visible_width = p_sys->i_width;
+    fmt.i_height = fmt.i_visible_height = p_sys->i_height;
+    fmt.i_chroma = VLC_FOURCC('I','4','2','0');
+    fmt.i_aspect = VOUT_ASPECT_FACTOR * p_sys->i_width/p_sys->i_height;
+    fmt.i_sar_num = fmt.i_sar_den = 1;
 
+    p_sys->p_vout = vout_Request( p_filter, NULL, &fmt );
     if( p_sys->p_vout == NULL )
     {
         msg_Err( p_filter, "no suitable vout module" );
@@ -242,7 +339,6 @@ static int Open( vlc_object_t *p_this )
     p_filter->pf_do_work = DoWork;
     p_filter->b_in_place= 1;
 
-    msg_Dbg( p_filter,"Visualizer initialized");
     return VLC_SUCCESS;
 }
 
@@ -277,7 +373,7 @@ static void DoWork( aout_instance_t *p_aout, aout_filter_t *p_filter,
     for( i = 0 ; i < p_outpic->i_planes ; i++ )
     {
         memset( p_outpic->p[i].p_pixels, i > 0 ? 0x80 : 0x00,
-                p_outpic->p[i].i_lines * p_outpic->p[i].i_pitch );
+                p_outpic->p[i].i_visible_lines * p_outpic->p[i].i_pitch );
     }
 
     /* We can now call our visualization effects */
@@ -309,7 +405,7 @@ static void Close( vlc_object_t *p_this )
 
     if( p_filter->p_sys->p_vout )
     {
-        vout_Request( p_filter, p_filter->p_sys->p_vout, 0, 0, 0, 0 );
+        vout_Request( p_filter, p_filter->p_sys->p_vout, 0 );
     }
 
     /* Free the list */
@@ -335,3 +431,17 @@ static void Close( vlc_object_t *p_this )
 
     free( p_filter->p_sys );
 }
+
+/*****************************************************************************
+ * FilterCallback: called when changing the deinterlace method on the fly.
+ *****************************************************************************/
+static int FilterCallback( vlc_object_t *p_this, char const *psz_cmd,
+                           vlc_value_t oldval, vlc_value_t newval,
+                           void *p_data )
+{
+    aout_filter_t     *p_filter = (aout_filter_t *)p_this;
+    /* restart this baby */
+    msg_Dbg( p_filter, "we should restart the visual filter" );
+    return VLC_SUCCESS;
+}
+