X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fcrop.c;h=385c4ba8a5173b281741ed02e6ed27256ea53bdf;hb=fa4bde0b26a6c7a2a617362ea0b17144686e39fe;hp=bb049f6025d19898d7ed647cdaa43a6f188a8975;hpb=94cc428df657035f243f4122b3c4ad1d910b2229;p=vlc diff --git a/modules/video_filter/crop.c b/modules/video_filter/crop.c index bb049f6025..385c4ba8a5 100644 --- a/modules/video_filter/crop.c +++ b/modules/video_filter/crop.c @@ -26,10 +26,13 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include @@ -97,42 +100,42 @@ static int FilterCallback ( vlc_object_t *, char const *, #define LUM_LONGTEXT N_("Maximum luminance to consider a pixel as black (0-255).") #endif -vlc_module_begin(); - set_description( _("Crop video filter") ); - set_shortname( _("Crop" )); - set_category( CAT_VIDEO ); - set_subcategory( SUBCAT_VIDEO_VFILTER ); - set_capability( "video filter", 0 ); +vlc_module_begin () + 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 ); + GEOMETRY_LONGTEXT, false ) add_bool( "autocrop", 0, NULL, AUTOCROP_TEXT, - AUTOCROP_LONGTEXT, VLC_FALSE ); + AUTOCROP_LONGTEXT, false ) #ifdef BEST_AUTOCROP add_integer_with_range( "autocrop-ratio-max", 2405, 0, RATIO_MAX, NULL, - RATIOMAX_TEXT, RATIOMAX_LONGTEXT, VLC_TRUE ); + RATIOMAX_TEXT, RATIOMAX_LONGTEXT, true ) add_integer_with_range( "crop-ratio", 0, 0, RATIO_MAX, NULL, RATIO_TEXT, - RATIO_LONGTEXT, VLC_FALSE ); + RATIO_LONGTEXT, false ) add_integer( "autocrop-time", 25, NULL, TIME_TEXT, - TIME_LONGTEXT, VLC_TRUE ); + TIME_LONGTEXT, true ) add_integer( "autocrop-diff", 16, NULL, DIFF_TEXT, - DIFF_LONGTEXT, VLC_TRUE ); + DIFF_LONGTEXT, true ) add_integer( "autocrop-non-black-pixels", 3, NULL, - NBP_TEXT, NBP_LONGTEXT, VLC_TRUE ); + NBP_TEXT, NBP_LONGTEXT, true ) add_integer_with_range( "autocrop-skip-percent", 17, 0, 100, NULL, - SKIP_TEXT, SKIP_LONGTEXT, VLC_TRUE ); + SKIP_TEXT, SKIP_LONGTEXT, true ) add_integer_with_range( "autocrop-luminance-threshold", 40, 0, 128, NULL, - LUM_TEXT, LUM_LONGTEXT, VLC_TRUE ); + LUM_TEXT, LUM_LONGTEXT, true ) #endif //BEST_AUTOCROP - add_shortcut( "crop" ); - set_callbacks( Create, Destroy ); -vlc_module_end(); + add_shortcut( "crop" ) + set_callbacks( Create, Destroy ) +vlc_module_end () /***************************************************************************** * vout_sys_t: Crop video output method descriptor @@ -147,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; @@ -180,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; @@ -209,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; @@ -375,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; @@ -400,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_CloseAndRelease( p_vout->p_sys->p_vout ); } /***************************************************************************** @@ -417,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 ); } @@ -455,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_CloseAndRelease( 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; @@ -469,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; @@ -501,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; @@ -510,7 +513,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_pic ) msleep( VOUT_OUTMEM_SLEEP ); } - vout_DatePicture( p_vout->p_sys->p_vout, p_outpic, p_pic->date ); + p_outpic->date = p_pic->date; vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic ); for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ ) @@ -532,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; } @@ -549,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) @@ -823,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; } /***************************************************************************** @@ -832,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; @@ -856,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; @@ -869,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" ) ) @@ -879,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) {