X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fbluescreen.c;h=378219168dc021cd2f2df4da2998fe332f0e7e74;hb=c60652e38ac6afd74bd8225e9dae5406f13aaa4f;hp=cfdf9116c93a0e16e61553846ac986f40c652d20;hpb=733a686ea25ee196a0b402d8794646dfb25f5c9b;p=vlc diff --git a/modules/video_filter/bluescreen.c b/modules/video_filter/bluescreen.c index cfdf9116c9..378219168d 100644 --- a/modules/video_filter/bluescreen.c +++ b/modules/video_filter/bluescreen.c @@ -29,16 +29,15 @@ # include "config.h" #endif -#include -#include - -#include "vlc_filter.h" +#include +#include +#include #define BLUESCREEN_HELP N_( \ "This effect, also known as \"greenscreen\" or \"chroma key\" blends " \ "the \"blue parts\" of the foreground image of the mosaic on the " \ - "background (like weather forcasts). You can choose the \"key\" " \ - "color for blending (blyyue by default)." ) + "background (like weather forecasts). You can choose the \"key\" " \ + "color for blending (blue by default)." ) #define BLUESCREENU_TEXT N_("Bluescreen U value") #define BLUESCREENU_LONGTEXT N_( \ @@ -74,34 +73,35 @@ static int BluescreenCallback( vlc_object_t *, char const *, /***************************************************************************** * Module descriptor *****************************************************************************/ -vlc_module_begin(); - set_description( _("Bluescreen video filter") ); - set_shortname( _("Bluescreen" )); - set_help( BLUESCREEN_HELP ); - set_category( CAT_VIDEO ); - set_subcategory( SUBCAT_VIDEO_VFILTER ); - set_capability( "video filter2", 0 ); - add_shortcut( "bluescreen" ); - set_callbacks( Create, Destroy ); +vlc_module_begin () + set_description( N_("Bluescreen video filter") ) + set_shortname( N_("Bluescreen" )) + set_help( BLUESCREEN_HELP ) + set_category( CAT_VIDEO ) + set_subcategory( SUBCAT_VIDEO_VFILTER ) + set_capability( "video filter2", 0 ) + add_shortcut( "bluescreen" ) + set_callbacks( Create, Destroy ) add_integer_with_range( CFG_PREFIX "u", 120, 0, 255, NULL, - BLUESCREENU_TEXT, BLUESCREENU_LONGTEXT, VLC_FALSE ); + BLUESCREENU_TEXT, BLUESCREENU_LONGTEXT, false ) add_integer_with_range( CFG_PREFIX "v", 90, 0, 255, NULL, - BLUESCREENV_TEXT, BLUESCREENV_LONGTEXT, VLC_FALSE ); + BLUESCREENV_TEXT, BLUESCREENV_LONGTEXT, false ) add_integer_with_range( CFG_PREFIX "ut", 17, 0, 255, NULL, BLUESCREENUTOL_TEXT, BLUESCREENUTOL_LONGTEXT, - VLC_FALSE ); + false ) add_integer_with_range( CFG_PREFIX "vt", 17, 0, 255, NULL, BLUESCREENVTOL_TEXT, BLUESCREENVTOL_LONGTEXT, - VLC_FALSE ); -vlc_module_end(); + false ) +vlc_module_end () -static const char *ppsz_filter_options[] = { +static const char *const ppsz_filter_options[] = { "u", "v", "ut", "vt", NULL }; struct filter_sys_t { + vlc_mutex_t lock; int i_u, i_v, i_ut, i_vt; uint8_t *p_at; }; @@ -111,10 +111,10 @@ static int Create( vlc_object_t *p_this ) filter_t *p_filter = (filter_t *)p_this; filter_sys_t *p_sys; - if( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','U','V','A') ) + if( p_filter->fmt_in.video.i_chroma != VLC_CODEC_YUVA ) { msg_Err( p_filter, - "Unsupported input chroma \"%4s\". " + "Unsupported input chroma \"%4.4s\". " "Bluescreen can only use \"YUVA\".", (char*)&p_filter->fmt_in.video.i_chroma ); return VLC_EGENERIC; @@ -123,18 +123,17 @@ static int Create( vlc_object_t *p_this ) /* Allocate structure */ p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); if( p_filter->p_sys == NULL ) - { - msg_Err( p_filter, "out of memory" ); return VLC_ENOMEM; - } p_sys = p_filter->p_sys; config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options, p_filter->p_cfg ); + int val; + vlc_mutex_init( &p_sys->lock ); #define GET_VAR( name, min, max ) \ - p_sys->i_##name = __MIN( max, __MAX( min, \ - var_CreateGetIntegerCommand( p_filter, CFG_PREFIX #name ) ) ); \ + val = var_CreateGetIntegerCommand( p_filter, CFG_PREFIX #name ); \ + p_sys->i_##name = __MIN( max, __MAX( min, val ) ); \ var_AddCallback( p_filter, CFG_PREFIX #name, BluescreenCallback, p_sys ); GET_VAR( u, 0x00, 0xff ); @@ -142,6 +141,7 @@ static int Create( vlc_object_t *p_this ) GET_VAR( ut, 0x00, 0xff ); GET_VAR( vt, 0x00, 0xff ); p_sys->p_at = NULL; +#undef GET_VAR p_filter->pf_video_filter = Filter; @@ -151,9 +151,16 @@ static int Create( vlc_object_t *p_this ) static void Destroy( vlc_object_t *p_this ) { filter_t *p_filter = (filter_t *)p_this; + filter_sys_t *p_sys = p_filter->p_sys; - free( p_filter->p_sys->p_at ); - free( p_filter->p_sys ); + var_DelCallback( p_filter, CFG_PREFIX "u", BluescreenCallback, p_sys ); + var_DelCallback( p_filter, CFG_PREFIX "v", BluescreenCallback, p_sys ); + var_DelCallback( p_filter, CFG_PREFIX "ut", BluescreenCallback, p_sys ); + var_DelCallback( p_filter, CFG_PREFIX "vt", BluescreenCallback, p_sys ); + + free( p_sys->p_at ); + vlc_mutex_destroy( &p_sys->lock ); + free( p_sys ); } static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) @@ -169,22 +176,25 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) uint8_t *p_v = p_pic->p[ V_PLANE ].p_pixels; uint8_t umin, umax, vmin, vmax; - if( p_pic->format.i_chroma != VLC_FOURCC('Y','U','V','A') ) + if( p_pic->format.i_chroma != VLC_CODEC_YUVA ) { msg_Err( p_filter, - "Unsupported input chroma \"%4s\". " + "Unsupported input chroma \"%4.4s\". " "Bluescreen can only use \"YUVA\".", (char*)&p_pic->format.i_chroma ); return NULL; } - p_sys->p_at = realloc( p_sys->p_at, i_lines * i_pitch * sizeof( uint8_t ) ); + p_sys->p_at = xrealloc( p_sys->p_at, + i_lines * i_pitch * sizeof( uint8_t ) ); p_at = p_sys->p_at; + vlc_mutex_lock( &p_sys->lock ); umin = p_sys->i_u - p_sys->i_ut >= 0x00 ? p_sys->i_u - p_sys->i_ut : 0x00; umax = p_sys->i_u + p_sys->i_ut <= 0xff ? p_sys->i_u + p_sys->i_ut : 0xff; vmin = p_sys->i_v - p_sys->i_vt >= 0x00 ? p_sys->i_v - p_sys->i_vt : 0x00; vmax = p_sys->i_v + p_sys->i_vt <= 0xff ? p_sys->i_v + p_sys->i_vt : 0xff; + vlc_mutex_unlock( &p_sys->lock ); for( i = 0; i < i_lines*i_pitch; i++ ) { @@ -199,7 +209,7 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) } } /* Gaussian convolution to make it look cleaner */ - p_filter->p_libvlc->pf_memset( p_a, 0, 2 * i_pitch ); + vlc_memset( p_a, 0, 2 * i_pitch ); for( i = 2; i < i_lines - 2; i++ ) { p_a[i*i_pitch] = 0x00; @@ -254,23 +264,17 @@ static int BluescreenCallback( vlc_object_t *p_this, char const *psz_var, VLC_UNUSED(p_this); VLC_UNUSED(oldval); filter_sys_t *p_sys = (filter_sys_t *) p_data; + vlc_mutex_lock( &p_sys->lock ); #define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a ) if( VAR_IS( "u" ) ) - { p_sys->i_u = __MAX( 0, __MIN( 255, newval.i_int ) ); - } else if( VAR_IS( "v" ) ) - { p_sys->i_v = __MAX( 0, __MIN( 255, newval.i_int ) ); - } else if( VAR_IS( "ut" ) ) - { p_sys->i_ut = __MAX( 0, __MIN( 255, newval.i_int ) ); - } else if( VAR_IS( "vt" ) ) - { p_sys->i_vt = __MAX( 0, __MIN( 255, newval.i_int ) ); - } + vlc_mutex_unlock( &p_sys->lock ); return VLC_SUCCESS; }