]> git.sesse.net Git - vlc/blobdiff - modules/visualization/projectm.cpp
Qt: CaptureOpenPanel: check and prefill with usual devices
[vlc] / modules / visualization / projectm.cpp
index 229b0abbedebf82151dd80ff380bf1de855e197a..90ca9c8eefc3752ca381b641f3ee1ad55d4565c6 100644 (file)
@@ -48,6 +48,15 @@ static void Close        ( vlc_object_t * );
 #define CONFIG_LONGTEXT N_("File that will be used to configure the projectM " \
                            "module.")
 
+#define PRESET_PATH_TXT N_("projectM preset path")
+#define PRESET_PATH_LONGTXT N_("Path to the projectM preset directory")
+
+#define TITLE_FONT_TXT N_("Title font")
+#define TITLE_FONT_LONGTXT N_("Font used for the titles")
+
+#define MENU_FONT_TXT N_("Font menu")
+#define MENU_FONT_LONGTXT N_("Font used for the menus")
+
 #define WIDTH_TEXT N_("Video width")
 #define WIDTH_LONGTEXT N_("The width of the video window, in pixels.")
 
@@ -60,8 +69,17 @@ vlc_module_begin ()
     set_capability( "visualization2", 0 )
     set_category( CAT_AUDIO )
     set_subcategory( SUBCAT_AUDIO_VISUAL )
+#ifndef HAVE_PROJECTM2
     add_file( "projectm-config", "/usr/share/projectM/config.inp", NULL,
-                CONFIG_TEXT, CONFIG_LONGTEXT, true )
+              CONFIG_TEXT, CONFIG_LONGTEXT, true )
+#else
+    add_file( "projectm-preset-path", "/usr/share/projectM/presets", NULL,
+              PRESET_PATH_TXT, PRESET_PATH_LONGTXT, true )
+    add_file( "projectm-title-font", "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf", NULL,
+              TITLE_FONT_TXT, TITLE_FONT_LONGTXT, true )
+    add_file( "projectm-menu-font", "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf", NULL,
+              MENU_FONT_TXT, MENU_FONT_LONGTXT, true )
+#endif
     add_integer( "projectm-width", 800, NULL, WIDTH_TEXT, WIDTH_LONGTEXT,
                  false )
     add_integer( "projectm-height", 640, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT,
@@ -87,7 +105,13 @@ struct filter_sys_t
 
     /* libprojectM objects */
     projectM      *p_projectm;
+#ifndef HAVE_PROJECTM2
     char          *psz_config;
+#else
+    char          *psz_preset_path;
+    char          *psz_title_font;
+    char          *psz_menu_font;
+#endif
 
     /* Window size */
     int i_width;
@@ -96,7 +120,9 @@ struct filter_sys_t
     /* audio info */
     int i_channels;
 
+    /* */
     vlc_mutex_t lock;
+    bool  b_quit;
     float *p_buffer;
     int   i_buffer_size;
     int   i_nb_samples;
@@ -138,10 +164,17 @@ static int Open( vlc_object_t * p_this )
     /* Create the object for the thread */
     vlc_sem_init( &p_sys->ready, 0 );
     p_sys->b_error  = false;
-    p_sys->i_width  = var_CreateGetInteger( p_filter, "projectm-width" );
-    p_sys->i_height = var_CreateGetInteger( p_filter, "projectm-height" );
+    p_sys->b_quit   = false;
+    p_sys->i_width  = var_InheritInteger( p_filter, "projectm-width" );
+    p_sys->i_height = var_InheritInteger( p_filter, "projectm-height" );
     p_sys->i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio );
-    p_sys->psz_config = var_CreateGetString( p_filter, "projectm-config" );
+#ifndef HAVE_PROJECTM2
+    p_sys->psz_config = var_InheritString( p_filter, "projectm-config" );
+#else
+    p_sys->psz_preset_path = var_InheritString( p_filter, "projectm-preset-path" );
+    p_sys->psz_title_font = var_InheritString( p_filter, "projectm-title-font" );
+    p_sys->psz_menu_font = var_InheritString( p_filter, "projectm-menu-font" );
+#endif
     vlc_mutex_init( &p_sys->lock );
     p_sys->p_buffer = NULL;
     p_sys->i_buffer_size = 0;
@@ -176,15 +209,26 @@ static void Close( vlc_object_t *p_this )
     filter_t     *p_filter = (filter_t *)p_this;
     filter_sys_t *p_sys = p_filter->p_sys;
 
-    /* Stop the thread */
-    vlc_cancel( p_sys->thread );
+    /* Stop the thread
+     * XXX vlc_cleanup_push does not seems to work with C++ so no
+     * vlc_cancel()... */
+    vlc_mutex_lock( &p_sys->lock );
+    p_sys->b_quit = true;
+    vlc_mutex_unlock( &p_sys->lock );
+
     vlc_join( p_sys->thread, NULL );
 
     /* Free the ressources */
     vlc_sem_destroy( &p_sys->ready );
     vlc_mutex_destroy( &p_sys->lock );
     free( p_sys->p_buffer );
+#ifndef HAVE_PROJECTM2
     free( p_sys->psz_config );
+#else
+    free( p_sys->psz_preset_path );
+    free( p_sys->psz_title_font );
+    free( p_sys->psz_menu_font );
+#endif
     free( p_sys );
 }
 
@@ -232,25 +276,9 @@ static int VoutCallback( vlc_object_t *p_vout, char const *psz_name,
     {
         vout_SetDisplayFullscreen( p_vd, newv.b_bool );
     }
+    return VLC_SUCCESS;
 }
 
-/**
- * Clean up function when Thread() is cancelled.
- */
-static void ThreadCleanup( void *p_data )
-{
-    filter_t     *p_filter = (filter_t*)p_data;
-    filter_sys_t *p_sys = p_filter->p_sys;
-
-    /* Cleanup */
-    delete p_sys->p_projectm;
-
-    /* Free the openGL provider */
-    vout_DeleteDisplay( p_sys->p_vd, NULL );
-    vlc_object_release( p_sys->p_vout );
-}
-
-
 /**
  * ProjectM update thread which do the rendering
  * @param p_this: the p_thread object
@@ -262,6 +290,11 @@ static void *Thread( void *p_data )
     int cancel = vlc_savecancel();
     video_format_t fmt;
     vout_opengl_t *gl;
+    int i_last_width  = 0;
+    int i_last_height = 0;
+#ifdef HAVE_PROJECTM2
+    projectM::Settings settings;
+#endif
 
     /* Create the openGL provider */
     p_sys->p_vout =
@@ -269,10 +302,12 @@ static void *Thread( void *p_data )
     if( !p_sys->p_vout )
         goto error;
 
+    vlc_object_attach( p_sys->p_vout, p_filter );
+
     /* */
     video_format_Init( &fmt, 0 );
     video_format_Setup( &fmt, VLC_CODEC_RGB32,
-                        p_sys->i_width, p_sys->i_height, 0 );
+                        p_sys->i_width, p_sys->i_height, 0, 1 );
     fmt.i_sar_num = 1;
     fmt.i_sar_den = 1;
 
@@ -303,10 +338,28 @@ static void *Thread( void *p_data )
         vlc_object_release( p_sys->p_vout );
         goto error;
     }
-    vlc_cleanup_push( ThreadCleanup, p_filter );
 
     /* Create the projectM object */
+#ifndef HAVE_PROJECTM2
     p_sys->p_projectm = new projectM( p_sys->psz_config );
+#else
+    settings.meshX = 32;
+    settings.meshY = 24;
+    settings.fps = 35;
+    settings.textureSize = 1024;
+    settings.windowWidth = p_sys->i_width;
+    settings.windowHeight = p_sys->i_height;
+    settings.presetURL = p_sys->psz_preset_path;
+    settings.titleFontURL =  p_sys->psz_title_font;
+    settings.menuFontURL = p_sys->psz_menu_font;
+    settings.smoothPresetDuration = 5;
+    settings.presetDuration = 30;
+    settings.beatSensitivity = 10;
+    settings.aspectCorrection = 1;
+    settings.easterEgg = 1;
+    settings.shuffleEnabled = 1;
+    p_sys->p_projectm = new projectM( settings );
+#endif
     p_sys->i_buffer_size = p_sys->p_projectm->pcm()->maxsamples;
     p_sys->p_buffer = (float*)calloc( p_sys->i_buffer_size,
                                       sizeof( float ) );
@@ -317,8 +370,6 @@ static void *Thread( void *p_data )
     p_sys->p_projectm->projectM_setTitle( "" ); */
 
     /* */
-    int i_last_width  = 0;
-    int i_last_height = 0;
     for( ;; )
     {
         const mtime_t i_deadline = mdate() + CLOCK_FREQ / 50; /* 50 fps max */
@@ -344,14 +395,21 @@ static void *Thread( void *p_data )
                                                    p_sys->i_nb_samples );
             p_sys->i_nb_samples = 0;
         }
+        if( p_sys->b_quit )
+        {
+            vlc_mutex_unlock( &p_sys->lock );
+
+            delete p_sys->p_projectm;
+            vout_DeleteDisplay( p_sys->p_vd, NULL );
+            vlc_object_release( p_sys->p_vout );
+            return NULL;
+        }
         vlc_mutex_unlock( &p_sys->lock );
 
         p_sys->p_projectm->renderFrame();
 
         /* */
-        vlc_restorecancel( cancel );
         mwait( i_deadline );
-        cancel = vlc_savecancel();
 
         if( !vout_opengl_Lock(gl) )
         {
@@ -359,13 +417,11 @@ static void *Thread( void *p_data )
             vout_opengl_Unlock( gl );
         }
     }
-    vlc_cleanup_pop();
     abort();
 
 error:
     p_sys->b_error = true;
     vlc_sem_post( &p_sys->ready );
     return NULL;
-
 }