From 3f35c5171d9181434ebb16ffbdec7f7d62c28b8d Mon Sep 17 00:00:00 2001 From: Laurent Aimar Date: Thu, 17 Jul 2008 19:58:44 +0200 Subject: [PATCH 1/1] Fixed filters implemented as vout (Init/End can be called multiple times + use vout_Destroy where it should be) It closes #1722. --- modules/video_filter/clone.c | 11 +++++----- modules/video_filter/crop.c | 31 +++++++++++++++------------ modules/video_filter/deinterlace.c | 23 ++++++++++---------- modules/video_filter/logo.c | 9 ++++---- modules/video_filter/magnify.c | 14 ++++++------ modules/video_filter/opencv_wrapper.c | 14 +++++------- modules/video_filter/panoramix.c | 26 ++++++++-------------- modules/video_filter/puzzle.c | 15 ++++++------- modules/video_filter/swscale.c | 5 ++++- modules/video_filter/transform.c | 15 ++++++------- modules/video_filter/wall.c | 12 +++++------ 11 files changed, 79 insertions(+), 96 deletions(-) diff --git a/modules/video_filter/clone.c b/modules/video_filter/clone.c index 3b558d3b18..368f7d5b8b 100644 --- a/modules/video_filter/clone.c +++ b/modules/video_filter/clone.c @@ -285,12 +285,16 @@ static void End( vout_thread_t *p_vout ) { int i_index; + DEL_PARENT_CALLBACKS( SendEventsToChild ); + /* Free the fake output buffers we allocated */ for( i_index = I_OUTPUTPICTURES ; i_index ; ) { i_index--; free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig ); } + + RemoveAllVout( p_vout ); } /***************************************************************************** @@ -302,10 +306,6 @@ static void Destroy( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; - RemoveAllVout( p_vout ); - - DEL_PARENT_CALLBACKS( SendEventsToChild ); - free( p_vout->p_sys->pp_vout ); free( p_vout->p_sys ); } @@ -387,8 +387,7 @@ static void RemoveAllVout( vout_thread_t *p_vout ) --p_vout->p_sys->i_clones; DEL_CALLBACKS( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones], SendEvents ); - vlc_object_detach( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones] ); - vlc_object_release( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones] ); + vout_Destroy( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones] ); } } diff --git a/modules/video_filter/crop.c b/modules/video_filter/crop.c index e477c5c337..e220268f39 100644 --- a/modules/video_filter/crop.c +++ b/modules/video_filter/crop.c @@ -380,14 +380,14 @@ static int Init( vout_thread_t *p_vout ) 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_Destroy( 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 ); - vlc_object_release( 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 - vlc_object_release( 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; @@ -473,6 +475,7 @@ static int Manage( vout_thread_t *p_vout ) _("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 = false; p_vout->p_sys->i_lastchange = 0; diff --git a/modules/video_filter/deinterlace.c b/modules/video_filter/deinterlace.c index 26b8f0bfb3..919e94e627 100644 --- a/modules/video_filter/deinterlace.c +++ b/modules/video_filter/deinterlace.c @@ -420,6 +420,11 @@ 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 ; ) { @@ -428,13 +433,7 @@ static void End( vout_thread_t *p_vout ) } 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 ); - vlc_object_release( p_vout->p_sys->p_vout ); - } - - DEL_PARENT_CALLBACKS( SendEventsToChild ); + vout_Destroy( p_vout->p_sys->p_vout ); } /***************************************************************************** @@ -2061,11 +2060,11 @@ static int FilterCallback( vlc_object_t *p_this, char const *psz_cmd, } /* We need to kill the old vout */ - - DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents ); - - vlc_object_detach( p_vout->p_sys->p_vout ); - vlc_object_release( 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 ); + } /* Try to open a new video output */ p_vout->p_sys->p_vout = SpawnRealVout( p_vout ); diff --git a/modules/video_filter/logo.c b/modules/video_filter/logo.c index c6db247c9f..bf6bb52266 100644 --- a/modules/video_filter/logo.c +++ b/modules/video_filter/logo.c @@ -475,6 +475,10 @@ static void End( vout_thread_t *p_vout ) vout_sys_t *p_sys = p_vout->p_sys; int i_index; + DEL_PARENT_CALLBACKS( SendEventsToChild ); + + DEL_CALLBACKS( p_sys->p_vout, SendEvents ); + /* Free the fake output buffers we allocated */ for( i_index = I_OUTPUTPICTURES ; i_index ; ) { @@ -485,9 +489,7 @@ static void End( vout_thread_t *p_vout ) var_DelCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout); var_DelCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout); - DEL_CALLBACKS( p_sys->p_vout, SendEvents ); - vlc_object_detach( p_sys->p_vout ); - vlc_object_release( p_sys->p_vout ); + vout_Destroy( p_sys->p_vout ); if( p_sys->p_blend->p_module ) module_Unneed( p_sys->p_blend, p_sys->p_blend->p_module ); @@ -503,7 +505,6 @@ static void Destroy( vlc_object_t *p_this ) vout_thread_t *p_vout = (vout_thread_t *)p_this; vout_sys_t *p_sys = p_vout->p_sys; - DEL_PARENT_CALLBACKS( SendEventsToChild ); FreeLogoList( p_sys->p_logo_list ); free( p_sys->p_logo_list ); diff --git a/modules/video_filter/magnify.c b/modules/video_filter/magnify.c index 6b38557eb1..a314050b73 100644 --- a/modules/video_filter/magnify.c +++ b/modules/video_filter/magnify.c @@ -186,6 +186,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 ; ) { @@ -196,6 +200,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 ); } /***************************************************************************** @@ -205,16 +211,8 @@ 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 ); - vlc_object_release( p_vout->p_sys->p_vout ); - } - image_HandlerDelete( p_vout->p_sys->p_image ); - DEL_PARENT_CALLBACKS( SendEventsToChild ); free( p_vout->p_sys ); } diff --git a/modules/video_filter/opencv_wrapper.c b/modules/video_filter/opencv_wrapper.c index 24f1be8406..b38e215c61 100644 --- a/modules/video_filter/opencv_wrapper.c +++ b/modules/video_filter/opencv_wrapper.c @@ -374,6 +374,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 ; ) { @@ -391,6 +395,7 @@ static void End( vout_thread_t *p_vout ) p_vout->p_sys->p_opencv = NULL; } + vout_Destroy( p_vout->p_sys->p_vout ) } /***************************************************************************** @@ -402,15 +407,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 ); - vlc_object_release( p_vout->p_sys->p_vout ); - } - - DEL_PARENT_CALLBACKS( SendEventsToChild ); - ReleaseImages(p_vout); if( p_vout->p_sys->p_image ) diff --git a/modules/video_filter/panoramix.c b/modules/video_filter/panoramix.c index 91a067ff60..eda2d7f070 100644 --- a/modules/video_filter/panoramix.c +++ b/modules/video_filter/panoramix.c @@ -873,15 +873,20 @@ static void End( vout_thread_t *p_vout ) { int i_index; -#ifdef OVERLAP - var_SetInteger( p_vout, "bz-length", p_vout->p_sys->bz_length); -#endif + DEL_PARENT_CALLBACKS( SendEventsToChild ); + /* Free the fake output buffers we allocated */ for( i_index = I_OUTPUTPICTURES ; i_index ; ) { i_index--; free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig ); } + + RemoveAllVout( p_vout ); + +#ifdef OVERLAP + var_SetInteger( p_vout, "bz-length", p_vout->p_sys->bz_length); +#endif } /***************************************************************************** @@ -893,16 +898,6 @@ static void Destroy( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; -#ifdef GLOBAL_OUTPUT - DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents); - vlc_object_detach( p_vout->p_sys->p_vout ); - vlc_object_release( p_vout->p_sys->p_vout ); - DEL_PARENT_CALLBACKS( SendEventsToChild); -#endif - - RemoveAllVout( p_vout ); - DEL_PARENT_CALLBACKS( SendEventsToChild ); - free( p_vout->p_sys->pp_vout ); free( p_vout->p_sys ); @@ -1908,10 +1903,7 @@ static void RemoveAllVout( vout_thread_t *p_vout ) DEL_CALLBACKS( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout, SendEvents ); - vlc_object_detach( - p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout ); - vlc_object_release( - p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout ); + vout_Destroy( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout ); } } } diff --git a/modules/video_filter/puzzle.c b/modules/video_filter/puzzle.c index 3d62c771d7..a87c101523 100644 --- a/modules/video_filter/puzzle.c +++ b/modules/video_filter/puzzle.c @@ -289,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 ; ) { @@ -299,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 @@ -327,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 ); - vlc_object_release( 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 ); } diff --git a/modules/video_filter/swscale.c b/modules/video_filter/swscale.c index 24d603416d..3651b81e3a 100644 --- a/modules/video_filter/swscale.c +++ b/modules/video_filter/swscale.c @@ -191,6 +191,8 @@ static int OpenScaler( vlc_object_t *p_this ) free( p_sys ); return VLC_EGENERIC; } + if( p_sys->ctx ) sws_freeContext( p_sys->ctx ); + p_sys->ctx = NULL; msg_Dbg( p_filter, "%ix%i chroma: %4.4s -> %ix%i chroma: %4.4s", p_filter->fmt_in.video.i_width, p_filter->fmt_in.video.i_height, @@ -231,7 +233,8 @@ static int CheckInit( filter_t *p_filter ) if( ( p_filter->fmt_in.video.i_width != p_sys->fmt_in.video.i_width ) || ( p_filter->fmt_in.video.i_height != p_sys->fmt_in.video.i_height ) || ( p_filter->fmt_out.video.i_width != p_sys->fmt_out.video.i_width ) || - ( p_filter->fmt_out.video.i_height != p_sys->fmt_out.video.i_height ) ) + ( p_filter->fmt_out.video.i_height != p_sys->fmt_out.video.i_height ) || + !p_sys->ctx ) { int i_fmt_in, i_fmt_out; diff --git a/modules/video_filter/transform.c b/modules/video_filter/transform.c index dc880d2efc..a8eee2c9b0 100644 --- a/modules/video_filter/transform.c +++ b/modules/video_filter/transform.c @@ -276,12 +276,18 @@ 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 ; ) { i_index--; free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig ); } + + vout_Destroy( p_vout->p_sys->p_vout ); } /***************************************************************************** @@ -293,15 +299,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 ); - vlc_object_release( p_vout->p_sys->p_vout ); - } - - DEL_PARENT_CALLBACKS( SendEventsToChild ); - free( p_vout->p_sys ); } diff --git a/modules/video_filter/wall.c b/modules/video_filter/wall.c index c5833bc67f..aeec730bdc 100644 --- a/modules/video_filter/wall.c +++ b/modules/video_filter/wall.c @@ -451,12 +451,16 @@ static void End( vout_thread_t *p_vout ) { int i_index; + DEL_PARENT_CALLBACKS( SendEventsToChild ); + /* Free the fake output buffers we allocated */ for( i_index = I_OUTPUTPICTURES ; i_index ; ) { i_index--; free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig ); } + + RemoveAllVout( p_vout ); } /***************************************************************************** @@ -468,9 +472,6 @@ static void Destroy( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; - RemoveAllVout( p_vout ); - - DEL_PARENT_CALLBACKS( SendEventsToChild ); free( p_vout->p_sys->pp_vout ); free( p_vout->p_sys ); @@ -583,10 +584,7 @@ static void RemoveAllVout( vout_thread_t *p_vout ) DEL_CALLBACKS( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout, SendEvents ); - vlc_object_detach( - p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout ); - vlc_object_release( - p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout ); + vout_Destroy( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout ); } } } -- 2.39.2