]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/puzzle.c
Fixed filters implemented as vout (Init/End can be called multiple times
[vlc] / modules / video_filter / puzzle.c
index 42c12f365d7d1338fa79dbd123b3552567320002..a87c101523fe6d1feac9720d1742cbe15ac0fcde 100644 (file)
@@ -29,7 +29,8 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_vout.h>
 
 #include <math.h>
@@ -71,8 +72,8 @@ static int PuzzleCallback( vlc_object_t *, char const *,
 #define CFG_PREFIX "puzzle-"
 
 vlc_module_begin();
-    set_description( _("Puzzle interactive game video filter") );
-    set_shortname( _( "Puzzle" ));
+    set_description( N_("Puzzle interactive game video filter") );
+    set_shortname( N_( "Puzzle" ));
     set_capability( "video filter", 0 );
     set_category( CAT_VIDEO );
     set_subcategory( SUBCAT_VIDEO_VFILTER );
@@ -87,7 +88,7 @@ vlc_module_begin();
     set_callbacks( Create, Destroy );
 vlc_module_end();
 
-static const char *ppsz_filter_options[] = {
+static const char *const ppsz_filter_options[] = {
     "rows", "cols", "black-slot", NULL
 };
 
@@ -203,10 +204,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->p_sys->p_image = image_HandlerCreate( p_vout );
 
@@ -291,6 +289,10 @@ static void End( vout_thread_t *p_vout )
 {
     int i_index;
 
+    DEL_PARENT_CALLBACKS( SendEventsToChild );
+
+    DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
+
     /* Free the fake output buffers we allocated */
     for( i_index = I_OUTPUTPICTURES ; i_index ; )
     {
@@ -301,6 +303,8 @@ static void End( vout_thread_t *p_vout )
     var_DelCallback( p_vout->p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
     var_DelCallback( p_vout->p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
     var_DelCallback( p_vout->p_sys->p_vout, "mouse-clicked", MouseEvent, p_vout);
+
+    vout_Destroy( p_vout->p_sys->p_vout );
 }
 
 #define SHUFFLE_WIDTH 81
@@ -329,18 +333,9 @@ 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 );
-    }
-
     image_HandlerDelete( p_vout->p_sys->p_image );
     free( p_vout->p_sys->pi_order );
 
-    DEL_PARENT_CALLBACKS( SendEventsToChild );
-
     free( p_vout->p_sys );
 }
 
@@ -364,7 +359,7 @@ 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;
         }
@@ -398,8 +393,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
                 uint8_t color = ( i_plane == Y_PLANE ? 0x0 : 0x80 );
                 for( ; i_row < i_last_row; i_row++, i_orow++ )
                 {
-                    p_vout->p_libvlc->
-                    pf_memset( p_out->p_pixels + i_row * i_pitch
+                    vlc_memset( p_out->p_pixels + i_row * i_pitch
                                                + i_col * i_pitch / i_cols,
                                color, i_pitch / i_cols );
                 }
@@ -408,8 +402,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
             {
                 for( ; i_row < i_last_row; i_row++, i_orow++ )
                 {
-                    p_vout->p_libvlc->
-                    pf_memcpy( p_out->p_pixels + i_row * i_pitch
+                    vlc_memcpy( p_out->p_pixels + i_row * i_pitch
                                                + i_col * i_pitch / i_cols,
                                p_in->p_pixels + i_orow * i_pitch
                                               + i_ocol * i_pitch / i_cols,
@@ -430,8 +423,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
         int i_last_row = i_row + 1;
         i_row *= p_in->i_lines / i_rows;
         i_last_row *= p_in->i_lines / i_rows;
-        p_vout->p_libvlc->
-        pf_memset( p_out->p_pixels + i_row * i_pitch
+        vlc_memset( p_out->p_pixels + i_row * i_pitch
                                    + i_col * i_pitch / i_cols,
                    0xff, i_pitch / i_cols );
         for( ; i_row < i_last_row; i_row++ )
@@ -442,8 +434,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
                              + (i_col+1) * i_pitch / i_cols - 1 ] = 0xff;
         }
         i_row--;
-        p_vout->p_libvlc->
-        pf_memset( p_out->p_pixels + i_row * i_pitch
+        vlc_memset( p_out->p_pixels + i_row * i_pitch
                                    + i_col * i_pitch / i_cols,
                    0xff, i_pitch / i_cols );
     }