[vlc-commits] [Git][videolan/vlc][master] mosaic: cleanup option handling using range enforcement
Hugo Beauzée-Luyssen (@chouquette)
gitlab at videolan.org
Thu Jan 6 08:35:21 UTC 2022
Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC
Commits:
c73aa7b2 by Lyndon Brown at 2022-01-06T08:03:35+00:00
mosaic: cleanup option handling using range enforcement
- cleaner code.
- places helpful bounds on controls in gui prefs that prevent cycling out
of range.
- results in range hints being given in help output.
note that it is correct for ranges to be added where there is also a
choice list. ranges are enforced, whilst choice lists are not. with a
choice lists you're restricted to a droplist in gui prefs, however any
value can come from CLI or saved settings. a range is enforced upon storing
the value where ever it came from. thus it is correct and useful for them
to be used together.
- - - - -
1 changed file:
- modules/spu/mosaic.c
Changes:
=====================================
modules/spu/mosaic.c
=====================================
@@ -180,31 +180,31 @@ vlc_module_begin ()
add_integer_with_range( CFG_PREFIX "alpha", 255, 0, 255,
ALPHA_TEXT, ALPHA_LONGTEXT )
- add_integer( CFG_PREFIX "height", 100,
+ add_integer_with_range( CFG_PREFIX "height", 100, 0, INT_MAX,
HEIGHT_TEXT, HEIGHT_LONGTEXT )
- add_integer( CFG_PREFIX "width", 100,
+ add_integer_with_range( CFG_PREFIX "width", 100, 0, INT_MAX,
WIDTH_TEXT, WIDTH_LONGTEXT )
- add_integer( CFG_PREFIX "align", 5,
+ add_integer_with_range( CFG_PREFIX "align", 5, 0, 10,
ALIGN_TEXT, ALIGN_LONGTEXT)
change_integer_list( pi_align_values, ppsz_align_descriptions )
- add_integer( CFG_PREFIX "xoffset", 0,
+ add_integer_with_range( CFG_PREFIX "xoffset", 0, 0, INT_MAX,
XOFFSET_TEXT, XOFFSET_LONGTEXT )
- add_integer( CFG_PREFIX "yoffset", 0,
+ add_integer_with_range( CFG_PREFIX "yoffset", 0, 0, INT_MAX,
YOFFSET_TEXT, YOFFSET_LONGTEXT )
- add_integer( CFG_PREFIX "borderw", 0,
+ add_integer_with_range( CFG_PREFIX "borderw", 0, 0, INT_MAX,
BORDERW_TEXT, BORDERW_LONGTEXT )
- add_integer( CFG_PREFIX "borderh", 0,
+ add_integer_with_range( CFG_PREFIX "borderh", 0, 0, INT_MAX,
BORDERH_TEXT, BORDERH_LONGTEXT )
- add_integer( CFG_PREFIX "position", 0,
+ add_integer_with_range( CFG_PREFIX "position", 0, 0, 2,
POS_TEXT, POS_LONGTEXT )
change_integer_list( pi_pos_values, ppsz_pos_descriptions )
- add_integer( CFG_PREFIX "rows", 2,
+ add_integer_with_range( CFG_PREFIX "rows", 2, 1, INT_MAX,
ROWS_TEXT, ROWS_LONGTEXT )
- add_integer( CFG_PREFIX "cols", 2,
+ add_integer_with_range( CFG_PREFIX "cols", 2, 1, INT_MAX,
COLS_TEXT, COLS_LONGTEXT )
add_bool( CFG_PREFIX "keep-aspect-ratio", false,
@@ -218,7 +218,7 @@ vlc_module_begin ()
add_string( CFG_PREFIX "offsets", "",
OFFSETS_TEXT, OFFSETS_LONGTEXT )
- add_integer( CFG_PREFIX "delay", 0, DELAY_TEXT, DELAY_LONGTEXT )
+ add_integer_with_range( CFG_PREFIX "delay", 0, 0, INT_MAX, DELAY_TEXT, DELAY_LONGTEXT )
vlc_module_end ()
static const char *const ppsz_filter_options[] = {
@@ -296,29 +296,29 @@ static int CreateFilter( filter_t *p_filter )
config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
p_filter->p_cfg );
-#define GET_VAR( name, min, max ) \
+#define GET_VAR( name ) \
i_command = var_CreateGetIntegerCommand( p_filter, CFG_PREFIX #name ); \
- p_sys->i_##name = VLC_CLIP( i_command, min, max ); \
+ p_sys->i_##name = i_command; \
var_AddCallback( p_filter, CFG_PREFIX #name, MosaicCallback, p_sys );
- GET_VAR( width, 0, INT_MAX );
- GET_VAR( height, 0, INT_MAX );
- GET_VAR( xoffset, 0, INT_MAX );
- GET_VAR( yoffset, 0, INT_MAX );
+ GET_VAR( width );
+ GET_VAR( height );
+ GET_VAR( xoffset );
+ GET_VAR( yoffset );
+ GET_VAR( align );
+ GET_VAR( borderw );
+ GET_VAR( borderh );
+ GET_VAR( rows );
+ GET_VAR( cols );
+ GET_VAR( alpha );
+ GET_VAR( position );
+#undef GET_VAR
- GET_VAR( align, 0, 10 );
if( p_sys->i_align == 3 || p_sys->i_align == 7 )
p_sys->i_align = 5;
- GET_VAR( borderw, 0, INT_MAX );
- GET_VAR( borderh, 0, INT_MAX );
- GET_VAR( rows, 1, INT_MAX );
- GET_VAR( cols, 1, INT_MAX );
- GET_VAR( alpha, 0, 255 );
- GET_VAR( position, 0, 2 );
-#undef GET_VAR
i_command = var_CreateGetIntegerCommand( p_filter, CFG_PREFIX "delay" );
- p_sys->i_delay = VLC_TICK_FROM_MS(VLC_CLIP( i_command, 0, INT_MAX ));
+ p_sys->i_delay = VLC_TICK_FROM_MS( i_command );
var_AddCallback( p_filter, CFG_PREFIX "delay", MosaicCallback, p_sys );
p_sys->b_ar = var_CreateGetBoolCommand( p_filter,
@@ -748,7 +748,7 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
vlc_mutex_lock( &p_sys->lock );
msg_Dbg( p_this, "changing alpha from %d/255 to %d/255",
p_sys->i_alpha, (int)newval.i_int);
- p_sys->i_alpha = VLC_CLIP( newval.i_int, 0, 255 );
+ p_sys->i_alpha = newval.i_int;
vlc_mutex_unlock( &p_sys->lock );
}
else if( VAR_IS( "height" ) )
@@ -756,7 +756,7 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
vlc_mutex_lock( &p_sys->lock );
msg_Dbg( p_this, "changing height from %dpx to %dpx",
p_sys->i_height, (int)newval.i_int );
- p_sys->i_height = __MAX( newval.i_int, 0 );
+ p_sys->i_height = newval.i_int;
vlc_mutex_unlock( &p_sys->lock );
}
else if( VAR_IS( "width" ) )
@@ -764,7 +764,7 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
vlc_mutex_lock( &p_sys->lock );
msg_Dbg( p_this, "changing width from %dpx to %dpx",
p_sys->i_width, (int)newval.i_int );
- p_sys->i_width = __MAX( newval.i_int, 0 );
+ p_sys->i_width = newval.i_int;
vlc_mutex_unlock( &p_sys->lock );
}
else if( VAR_IS( "xoffset" ) )
@@ -772,7 +772,7 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
vlc_mutex_lock( &p_sys->lock );
msg_Dbg( p_this, "changing x offset from %dpx to %dpx",
p_sys->i_xoffset, (int)newval.i_int );
- p_sys->i_xoffset = __MAX( newval.i_int, 0 );
+ p_sys->i_xoffset = newval.i_int;
vlc_mutex_unlock( &p_sys->lock );
}
else if( VAR_IS( "yoffset" ) )
@@ -780,14 +780,13 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
vlc_mutex_lock( &p_sys->lock );
msg_Dbg( p_this, "changing y offset from %dpx to %dpx",
p_sys->i_yoffset, (int)newval.i_int );
- p_sys->i_yoffset = __MAX( newval.i_int, 0 );
+ p_sys->i_yoffset = newval.i_int;
vlc_mutex_unlock( &p_sys->lock );
}
else if( VAR_IS( "align" ) )
{
int i_old = 0, i_new = 0;
vlc_mutex_lock( &p_sys->lock );
- newval.i_int = VLC_CLIP( newval.i_int, 0, 10 );
if( newval.i_int == 3 || newval.i_int == 7 )
newval.i_int = 5;
while( pi_align_values[i_old] != p_sys->i_align ) i_old++;
@@ -803,7 +802,7 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
vlc_mutex_lock( &p_sys->lock );
msg_Dbg( p_this, "changing border width from %dpx to %dpx",
p_sys->i_borderw, (int)newval.i_int );
- p_sys->i_borderw = __MAX( newval.i_int, 0 );
+ p_sys->i_borderw = newval.i_int;
vlc_mutex_unlock( &p_sys->lock );
}
else if( VAR_IS( "borderh" ) )
@@ -811,35 +810,24 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
vlc_mutex_lock( &p_sys->lock );
msg_Dbg( p_this, "changing border height from %dpx to %dpx",
p_sys->i_borderh, (int)newval.i_int );
- p_sys->i_borderh = __MAX( newval.i_int, 0 );
+ p_sys->i_borderh = newval.i_int;
vlc_mutex_unlock( &p_sys->lock );
}
else if( VAR_IS( "position" ) )
{
- if( newval.i_int > 2 || newval.i_int < 0 )
- {
- msg_Err( p_this,
- "Position is either 0 (%s), 1 (%s) or 2 (%s)",
- ppsz_pos_descriptions[0],
- ppsz_pos_descriptions[1],
- ppsz_pos_descriptions[2] );
- }
- else
- {
- vlc_mutex_lock( &p_sys->lock );
- msg_Dbg( p_this, "changing position method from %d (%s) to %d (%s)",
- p_sys->i_position, ppsz_pos_descriptions[p_sys->i_position],
- (int)newval.i_int, ppsz_pos_descriptions[newval.i_int]);
- p_sys->i_position = newval.i_int;
- vlc_mutex_unlock( &p_sys->lock );
- }
+ vlc_mutex_lock( &p_sys->lock );
+ msg_Dbg( p_this, "changing position method from %d (%s) to %d (%s)",
+ p_sys->i_position, ppsz_pos_descriptions[p_sys->i_position],
+ (int)newval.i_int, ppsz_pos_descriptions[newval.i_int]);
+ p_sys->i_position = newval.i_int;
+ vlc_mutex_unlock( &p_sys->lock );
}
else if( VAR_IS( "rows" ) )
{
vlc_mutex_lock( &p_sys->lock );
msg_Dbg( p_this, "changing number of rows from %d to %d",
p_sys->i_rows, (int)newval.i_int );
- p_sys->i_rows = __MAX( newval.i_int, 1 );
+ p_sys->i_rows = newval.i_int;
vlc_mutex_unlock( &p_sys->lock );
}
else if( VAR_IS( "cols" ) )
@@ -847,7 +835,7 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
vlc_mutex_lock( &p_sys->lock );
msg_Dbg( p_this, "changing number of columns from %d to %d",
p_sys->i_cols, (int)newval.i_int );
- p_sys->i_cols = __MAX( newval.i_int, 1 );
+ p_sys->i_cols = newval.i_int;
vlc_mutex_unlock( &p_sys->lock );
}
else if( VAR_IS( "order" ) )
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/c73aa7b26e4c37db0cd247abf660953d5fd0227c
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/c73aa7b26e4c37db0cd247abf660953d5fd0227c
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list