]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/crop.c
Fixed filters implemented as vout (Init/End can be called multiple times
[vlc] / modules / video_filter / crop.c
index 200aba17a8cb144c168e6dce9fa6c7827cb59012..e220268f3979ebfbe8b3e3f54ed0589caa32e5ae 100644 (file)
  * Preamble
  *****************************************************************************/
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_vout.h>
 #include <vlc_interface.h>
 
@@ -96,45 +101,36 @@ static int FilterCallback ( vlc_object_t *, char const *,
 #endif
 
 vlc_module_begin();
-    set_description( _("Crop video filter") );
-    set_shortname( _("Crop" ));
+    set_description( N_("Crop video filter") );
+    set_shortname( N_("Crop" ));
     set_category( CAT_VIDEO );
     set_subcategory( SUBCAT_VIDEO_VFILTER );
     set_capability( "video filter", 0 );
 
     add_string( "crop-geometry", NULL, NULL, GEOMETRY_TEXT,
-                                             GEOMETRY_LONGTEXT, VLC_FALSE );
-        change_safe();
+                                             GEOMETRY_LONGTEXT, false );
     add_bool( "autocrop", 0, NULL, AUTOCROP_TEXT,
-                                   AUTOCROP_LONGTEXT, VLC_FALSE );
-        change_safe();
+                                   AUTOCROP_LONGTEXT, false );
 
 #ifdef BEST_AUTOCROP
     add_integer_with_range( "autocrop-ratio-max", 2405, 0, RATIO_MAX, NULL,
-                            RATIOMAX_TEXT, RATIOMAX_LONGTEXT, VLC_TRUE );
-        change_safe();
+                            RATIOMAX_TEXT, RATIOMAX_LONGTEXT, true );
 
     add_integer_with_range( "crop-ratio", 0, 0, RATIO_MAX, NULL, RATIO_TEXT,
-                            RATIO_LONGTEXT, VLC_FALSE );
-        change_safe();
+                            RATIO_LONGTEXT, false );
     add_integer( "autocrop-time", 25, NULL, TIME_TEXT,
-                 TIME_LONGTEXT, VLC_TRUE );
-        change_safe();
+                 TIME_LONGTEXT, true );
     add_integer( "autocrop-diff", 16, NULL, DIFF_TEXT,
-                                            DIFF_LONGTEXT, VLC_TRUE );
-        change_safe();
+                                            DIFF_LONGTEXT, true );
 
     add_integer( "autocrop-non-black-pixels", 3, NULL,
-                 NBP_TEXT, NBP_LONGTEXT, VLC_TRUE );
-        change_safe();
+                 NBP_TEXT, NBP_LONGTEXT, true );
 
     add_integer_with_range( "autocrop-skip-percent", 17, 0, 100, NULL,
-                            SKIP_TEXT, SKIP_LONGTEXT, VLC_TRUE );
-        change_safe();
+                            SKIP_TEXT, SKIP_LONGTEXT, true );
 
     add_integer_with_range( "autocrop-luminance-threshold", 40, 0, 128, NULL,
-                            LUM_TEXT, LUM_LONGTEXT, VLC_TRUE );
-        change_safe();
+                            LUM_TEXT, LUM_LONGTEXT, true );
 #endif //BEST_AUTOCROP
 
     add_shortcut( "crop" );
@@ -154,11 +150,11 @@ struct vout_sys_t
     unsigned int i_x, i_y;
     unsigned int i_width, i_height, i_aspect;
 
-    vlc_bool_t b_autocrop;
+    bool b_autocrop;
 
     /* Autocrop specific variables */
     unsigned int i_lastchange;
-    vlc_bool_t   b_changed;
+    bool   b_changed;
 #ifdef BEST_AUTOCROP
     unsigned int i_ratio_max;
     unsigned int i_threshold, i_skipPercent, i_nonBlackPixel, i_diff, i_time;
@@ -187,10 +183,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;
@@ -216,7 +209,7 @@ static int Init( vout_thread_t *p_vout )
     memset( &fmt, 0, sizeof(video_format_t) );
 
     p_vout->p_sys->i_lastchange = 0;
-    p_vout->p_sys->b_changed = VLC_FALSE;
+    p_vout->p_sys->b_changed = false;
 
     /* Initialize the output structure */
     p_vout->output.i_chroma = p_vout->render.i_chroma;
@@ -382,19 +375,19 @@ static int Init( vout_thread_t *p_vout )
     if( p_vout->p_sys->p_vout == NULL )
     {
         msg_Err( p_vout, "failed to create vout" );
-        intf_UserFatal( p_vout, VLC_FALSE, _("Cropping failed"),
+        intf_UserFatal( p_vout, false, _("Cropping failed"),
                         _("VLC could not open the video output module.") );
         return VLC_EGENERIC;
     }
 
-    ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
-
-    ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
-
 #ifdef BEST_AUTOCROP
     var_AddCallback( p_vout, "ratio-crop", FilterCallback, NULL );
 #endif
 
+    ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
+
+    ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
+
     ADD_PARENT_CALLBACKS( SendEventsToChild );
 
     return VLC_SUCCESS;
@@ -407,12 +400,19 @@ static void End( vout_thread_t *p_vout )
 {
     int i_index;
 
+    DEL_PARENT_CALLBACKS( SendEventsToChild );
+    if( p_vout->p_sys->p_vout )
+        DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
+
     /* Free the fake output buffers we allocated */
     for( i_index = I_OUTPUTPICTURES ; i_index ; )
     {
         i_index--;
         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
     }
+
+    if( p_vout->p_sys->p_vout )
+        vout_Destroy( p_vout->p_sys->p_vout );
 }
 
 /*****************************************************************************
@@ -424,15 +424,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 );
 }
 
@@ -462,7 +453,11 @@ static int Manage( vout_thread_t *p_vout )
     msg_Info( p_vout, "ratio %d",  p_vout->p_sys->i_aspect / 432);
 #endif
 
-    vout_Destroy( p_vout->p_sys->p_vout );
+    if( p_vout->p_sys->p_vout )
+    {
+        DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
+        vout_Destroy( p_vout->p_sys->p_vout );
+    }
 
     fmt.i_width = fmt.i_visible_width = p_vout->p_sys->i_width;
     fmt.i_height = fmt.i_visible_height = p_vout->p_sys->i_height;
@@ -476,12 +471,13 @@ static int Manage( vout_thread_t *p_vout )
     if( p_vout->p_sys->p_vout == NULL )
     {
         msg_Err( p_vout, "failed to create vout" );
-        intf_UserFatal( p_vout, VLC_FALSE, _("Cropping failed"),
+        intf_UserFatal( p_vout, false, _("Cropping failed"),
                         _("VLC could not open the video output module.") );
         return VLC_EGENERIC;
     }
+    ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
 
-    p_vout->p_sys->b_changed = VLC_FALSE;
+    p_vout->p_sys->b_changed = false;
     p_vout->p_sys->i_lastchange = 0;
 
     return VLC_SUCCESS;
@@ -508,7 +504,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
                  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 )
         {
             vout_DestroyPicture( p_vout->p_sys->p_vout, p_outpic );
             return;
@@ -539,7 +535,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
 
         while( p_out < p_out_end )
         {
-            p_vout->p_libvlc->pf_memcpy( p_out, p_in, i_copy_pitch );
+            vlc_memcpy( p_out, p_in, i_copy_pitch );
             p_in += i_in_pitch;
             p_out += i_out_pitch;
         }
@@ -556,7 +552,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic )
 }
 
 #ifdef BEST_AUTOCROP
-static vlc_bool_t NonBlackLine(uint8_t *p_in, int i_line, int i_pitch,
+static bool NonBlackLine(uint8_t *p_in, int i_line, int i_pitch,
                                int i_visible_pitch, int i_lines,
                                int i_lumThreshold, int i_skipCountPercent,
                                int i_nonBlackPixel, int i_chroma)
@@ -830,7 +826,7 @@ static void UpdateStats( vout_thread_t *p_vout, picture_t *p_pic )
                             * p_vout->output.i_height / p_vout->p_sys->i_height
                             * p_vout->p_sys->i_width / p_vout->output.i_width;
 
-    p_vout->p_sys->b_changed = VLC_TRUE;
+    p_vout->p_sys->b_changed = true;
 }
 
 /*****************************************************************************
@@ -839,6 +835,7 @@ static void UpdateStats( vout_thread_t *p_vout, picture_t *p_pic )
 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
                        vlc_value_t oldval, vlc_value_t newval, void *_p_vout )
 {
+    VLC_UNUSED(p_this); VLC_UNUSED(oldval);
     vout_thread_t *p_vout = (vout_thread_t *)_p_vout;
     vlc_value_t sentval = newval;
 
@@ -863,6 +860,7 @@ static int SendEvents( vlc_object_t *p_this, char const *psz_var,
 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;
@@ -876,6 +874,7 @@ static int FilterCallback( 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;
 
     if( !strcmp( psz_var, "ratio-crop" ) )
@@ -886,7 +885,7 @@ static int FilterCallback( vlc_object_t *p_this, char const *psz_var,
         {
             p_vout->p_sys->i_ratio = (unsigned int)atoi(newval.psz_string);
             p_vout->p_sys->i_lastchange = p_vout->p_sys->i_time;
-            p_vout->p_sys->b_autocrop = VLC_TRUE;
+            p_vout->p_sys->b_autocrop = true;
         }
         if (p_vout->p_sys->i_ratio)
         {