Commit 0b3b1edf authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

variables: use table of vlc_value_t for VLC_VAR_GETCHOICES

This simplifies the notation. No function differences.
parent 7a51579a
......@@ -381,7 +381,7 @@ int libvlc_audio_get_track( libvlc_media_player_t *p_mi )
int libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track )
{
input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
vlc_list_t val_list;
vlc_value_t *val_list;
size_t count;
int i_ret = -1;
......@@ -392,7 +392,7 @@ int libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track )
&count, &val_list, (char ***)NULL );
for( size_t i = 0; i < count; i++ )
{
if( i_track == val_list.p_values[i].i_int )
if( i_track == val_list[i].i_int )
{
if( var_SetInteger( p_input_thread, "audio-es", i_track ) < 0 )
break;
......@@ -402,7 +402,7 @@ int libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track )
}
libvlc_printerr( "Track identifier not found" );
end:
free( val_list.p_values );
free( val_list );
vlc_object_release( p_input_thread );
return i_ret;
}
......
......@@ -1787,7 +1787,7 @@ libvlc_track_description_t *
if( !p_input )
return NULL;
vlc_list_t val_list;
vlc_value_t *val_list;
char **text_list;
size_t count;
......@@ -1806,13 +1806,13 @@ libvlc_track_description_t *
}
*pp = tr;
tr->i_id = val_list.p_values[i].i_int;
tr->i_id = val_list[i].i_int;
tr->psz_name = text_list[i];
pp = &tr->p_next;
}
*pp = NULL;
free(val_list.p_values);
free(val_list);
free(text_list);
vlc_object_release( p_input );
......
......@@ -353,7 +353,7 @@ libvlc_track_description_t *
int libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu )
{
input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
vlc_list_t list;
vlc_value_t *list;
size_t count;
int i_ret = -1;
......@@ -364,7 +364,7 @@ int libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu )
&count, &list, (char ***)NULL);
for (size_t i = 0; i < count; i++)
{
if( i_spu == list.p_values[i].i_int )
if( i_spu == list[i].i_int )
{
if( var_SetInteger( p_input_thread, "spu-es", i_spu ) < 0 )
break;
......@@ -375,7 +375,7 @@ int libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu )
libvlc_printerr( "Track identifier not found" );
end:
vlc_object_release (p_input_thread);
free(list.p_values);
free(list);
return i_ret;
}
......@@ -452,17 +452,16 @@ static void teletext_enable( input_thread_t *p_input_thread, bool b_enable )
{
if( b_enable )
{
vlc_list_t list;
vlc_value_t *list;
size_t count;
if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETCHOICES,
&count, &list, (char ***)NULL ) )
{
if( count > 0 )
var_SetInteger( p_input_thread, "spu-es",
list.p_values[0].i_int );
var_SetInteger( p_input_thread, "spu-es", list[0].i_int );
free(list.p_values);
free(list);
}
}
else
......@@ -571,7 +570,7 @@ int libvlc_video_get_track( libvlc_media_player_t *p_mi )
int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
{
input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi );
vlc_list_t val_list;
vlc_value_t *val_list;
size_t count;
int i_ret = -1;
......@@ -582,7 +581,7 @@ int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
&count, &val_list, (char ***)NULL );
for( size_t i = 0; i < count; i++ )
{
if( i_track == val_list.p_values[i].i_int )
if( i_track == val_list[i].i_int )
{
if( var_SetInteger( p_input_thread, "video-es", i_track ) < 0 )
break;
......@@ -592,7 +591,7 @@ int libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track )
}
libvlc_printerr( "Track identifier not found" );
end:
free(val_list.p_values);
free(val_list);
vlc_object_release( p_input_thread );
return i_ret;
}
......
......@@ -277,7 +277,7 @@ static void ProcessGesture( intf_thread_t *p_intf )
if( p_input == NULL )
break;
vlc_list_t list;
vlc_value_t *list;
size_t count;
var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
......@@ -289,7 +289,7 @@ static void ProcessGesture( intf_thread_t *p_intf )
size_t i;
for( i = 0; i < count; i++ )
if( i_audio_es == list.p_values[i].i_int )
if( i_audio_es == list[i].i_int )
break;
/* value of audio-es was not in choices list */
if( i == count )
......@@ -302,10 +302,9 @@ static void ProcessGesture( intf_thread_t *p_intf )
i = 1;
else
i++;
var_SetInteger( p_input, "audio-es",
list.p_values[i].i_int );
var_SetInteger( p_input, "audio-es", list[i].i_int );
}
free(list.p_values);
free(list);
vlc_object_release( p_input );
break;
}
......@@ -316,7 +315,7 @@ static void ProcessGesture( intf_thread_t *p_intf )
if( p_input == NULL )
break;
vlc_list_t list;
vlc_value_t *list;
size_t count;
var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
......@@ -328,7 +327,7 @@ static void ProcessGesture( intf_thread_t *p_intf )
size_t i;
for( i = 0; i < count; i++ )
if( i_audio_es == list.p_values[i].i_int )
if( i_audio_es == list[i].i_int )
break;
/* value of audio-es was not in choices list */
if( i == count )
......@@ -341,10 +340,9 @@ static void ProcessGesture( intf_thread_t *p_intf )
i = 1;
else
i++;
var_SetInteger( p_input, "audio-es",
list.p_values[i].i_int );
var_SetInteger( p_input, "audio-es", list[i].i_int );
}
free(list.p_values);
free(list);
vlc_object_release( p_input );
break;
}
......
This diff is collapsed.
......@@ -1122,7 +1122,7 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
else
{
/* get */
vlc_list_t val;
vlc_value_t *val;
char **text;
size_t count;
......@@ -1138,12 +1138,12 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
msg_rc( "+----[ %s ]", name );
for ( size_t i = 0; i < count; i++ )
{
msg_rc( "| %"PRId64" - %s%s", val.p_values[i].i_int, text[i],
(i_value == val.p_values[i].i_int) ? " *" : "" );
msg_rc( "| %"PRId64" - %s%s", val[i].i_int, text[i],
(i_value == val[i].i_int) ? " *" : "" );
free(text[i]);
}
free(text);
free(val.p_values);
free(val);
msg_rc( "+----[ end of %s ]", name );
}
free( name );
......@@ -1556,7 +1556,7 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
{
/* get */
char *name;
vlc_list_t val;
vlc_value_t *val;
char **text;
float f_value = 0.;
char *psz_value = NULL;
......@@ -1591,8 +1591,8 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
{
for ( size_t i = 0; i < count; i++ )
{
msg_rc( "| %f - %s%s", val.p_values[i].f_float, text[i],
f_value == val.p_values[i].f_float ? " *" : "" );
msg_rc( "| %f - %s%s", val[i].f_float, text[i],
f_value == val[i].f_float ? " *" : "" );
free(text[i]);
}
}
......@@ -1600,16 +1600,16 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
{
for ( size_t i = 0; i < count; i++ )
{
msg_rc( "| %s - %s%s", val.p_values[i].psz_string, text[i],
strcmp(psz_value, val.p_values[i].psz_string)
msg_rc( "| %s - %s%s", val[i].psz_string, text[i],
strcmp(psz_value, val[i].psz_string)
? "" : " *" );
free(text[i]);
free(val.p_values[i].psz_string);
free(val[i].psz_string);
}
free( psz_value );
}
free(text);
free(val.p_values);
free(val);
msg_rc( "+----[ end of %s ]", name );
free( name );
......@@ -1674,7 +1674,7 @@ static int AudioChannel( vlc_object_t *obj, char const *cmd,
if ( !*cur.psz_string )
{
/* Retrieve all registered ***. */
vlc_list_t val;
vlc_value_t *val;
char **text;
size_t count;
......@@ -1690,12 +1690,12 @@ static int AudioChannel( vlc_object_t *obj, char const *cmd,
msg_rc( "+----[ %s ]", cmd );
for ( size_t i = 0; i < count; i++ )
{
msg_rc( "| %"PRId64" - %s%s", val.p_values[i].i_int, text[i],
i_value == val.p_values[i].i_int ? " *" : "" );
msg_rc( "| %"PRId64" - %s%s", val[i].i_int, text[i],
i_value == val[i].i_int ? " *" : "" );
free(text[i]);
}
free(text);
free(val.p_values);
free(val);
msg_rc( "+----[ end of %s ]", cmd );
}
else
......
......@@ -1448,7 +1448,7 @@
selector:(SEL)pf_callback
{
vlc_value_t val;
vlc_list_t val_list;
vlc_value_t *val_list;
char **text_list;
size_t count, i;
int i_type;
......@@ -1516,33 +1516,33 @@
switch(i_type & VLC_VAR_TYPE) {
case VLC_VAR_STRING:
title = _NS(text_list[i] ? text_list[i] : val_list.p_values[i].psz_string);
title = _NS(text_list[i] ? text_list[i] : val_list[i].psz_string);
lmi = [menu addItemWithTitle: title action: pf_callback keyEquivalent: @""];
data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
andValue: val_list.p_values[i] ofType: i_type];
andValue: val_list[i] ofType: i_type];
[lmi setRepresentedObject:data];
[lmi setTarget: self];
if (!strcmp(val.psz_string, val_list.p_values[i].psz_string) && !(i_type & VLC_VAR_ISCOMMAND))
if (!strcmp(val.psz_string, val_list[i].psz_string) && !(i_type & VLC_VAR_ISCOMMAND))
[lmi setState: TRUE ];
free(text_list[i]);
free(val_list.p_values[i].psz_string);
free(val_list[i].psz_string);
break;
case VLC_VAR_INTEGER:
title = text_list[i] ?
_NS(text_list[i]) : [NSString stringWithFormat: @"%"PRId64, val_list.p_values[i].i_int];
_NS(text_list[i]) : [NSString stringWithFormat: @"%"PRId64, val_list[i].i_int];
lmi = [menu addItemWithTitle: title action: pf_callback keyEquivalent: @""];
data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
andValue: val_list.p_values[i] ofType: i_type];
andValue: val_list[i] ofType: i_type];
[lmi setRepresentedObject:data];
[lmi setTarget: self];
if (val_list.p_values[i].i_int == val.i_int && !(i_type & VLC_VAR_ISCOMMAND))
if (val_list[i].i_int == val.i_int && !(i_type & VLC_VAR_ISCOMMAND))
[lmi setState: TRUE ];
free(text_list[i]);
......@@ -1556,7 +1556,7 @@
/* clean up everything */
if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
free(text);
free(val_list.p_values);
free(val_list);
}
- (void)toggleVar:(id)sender
......
......@@ -1538,7 +1538,7 @@ static void CycleESTrack(input_thread_t *input, const char *var)
if (!input)
return;
vlc_list_t list;
vlc_value_t *list;
size_t count;
if (var_Change(input, var, VLC_VAR_GETCHOICES,
......@@ -1549,13 +1549,13 @@ static void CycleESTrack(input_thread_t *input, const char *var)
size_t i;
for (i = 0; i < count; i++)
if (list.p_values[i].i_int == current)
if (list[i].i_int == current)
break;
if (++i >= count)
i = 0;
var_SetInteger(input, var, list.p_values[i].i_int);
free(list.p_values);
var_SetInteger(input, var, list[i].i_int);
free(list);
}
static void HandleCommonKey(intf_thread_t *intf, input_thread_t *input,
......
......@@ -268,7 +268,7 @@ void AspectRatioComboBox::updateRatios()
{
/* Clear the list before updating */
clear();
vlc_list_t val_list;
vlc_value_t *val_list;
char **text_list;
size_t count;
......@@ -287,13 +287,13 @@ void AspectRatioComboBox::updateRatios()
for( size_t i = 0; i < count; i++ )
{
addItem( qfu( text_list[i] ),
QString( val_list.p_values[i].psz_string ) );
QString( val_list[i].psz_string ) );
free(text_list[i]);
free(val_list.p_values[i].psz_string);
free(val_list[i].psz_string);
}
setEnabled( true );
free(text_list);
free(val_list.p_values);
free(val_list);
vlc_object_release( p_vout );
}
......
......@@ -651,7 +651,7 @@ void ExtV4l2::Refresh( void )
}
if( p_obj )
{
vlc_list_t val;
vlc_value_t *val;
char **text;
size_t count;
......@@ -684,7 +684,7 @@ void ExtV4l2::Refresh( void )
name = qfu(psz_var);
msg_Dbg( p_intf, "v4l2 control \"%" PRIx64 "\": %s (%s)",
val.p_values[i].i_int, psz_var, qtu( name ) );
val[i].i_int, psz_var, qtu( name ) );
int i_type = var_Type( p_obj, psz_var );
switch( i_type & VLC_VAR_TYPE )
......@@ -700,7 +700,7 @@ void ExtV4l2::Refresh( void )
QComboBox *combobox = new QComboBox( box );
combobox->setObjectName( qfu( psz_var ) );
vlc_list_t val2;
vlc_value_t *val2;
char **text2;
size_t count2;
......@@ -709,13 +709,13 @@ void ExtV4l2::Refresh( void )
for( size_t j = 0; j < count2; j++ )
{
combobox->addItem( text2[j],
qlonglong( val2.p_values[j].i_int) );
if( i_val == val2.p_values[j].i_int )
qlonglong( val2[j].i_int) );
if( i_val == val2[j].i_int )
combobox->setCurrentIndex( j );
free(text2[j]);
}
free(text2);
free(val2.p_values);
free(val2);
CONNECT( combobox, currentIndexChanged( int ), this,
ValueChange( int ) );
......@@ -782,7 +782,7 @@ void ExtV4l2::Refresh( void )
free(psz_var);
}
free(text);
free(val.p_values);
free(val);
vlc_object_release( p_obj );
}
else
......
......@@ -859,7 +859,7 @@ void InputManager::telexSetTransparency( bool b_transparentTelextext )
void InputManager::activateTeletext( bool b_enable )
{
vlc_list_t list;
vlc_value_t *list;
char **text;
size_t count;
......@@ -868,17 +868,17 @@ void InputManager::activateTeletext( bool b_enable )
{
if( count > 0 )
{ /* Prefer the page 100 if it is present */
int id = list.p_values[0].i_int;
int id = list[0].i_int;
for( size_t i = 0; i < count; i++ )
{ /* The description is the page number as a string */
if( text[i] != NULL && !strcmp( text[i], "100" ) )
id = list.p_values[i].i_int;
id = list[i].i_int;
free(text[i]);
}
var_SetInteger( p_input, "spu-es", b_enable ? id : -1 );
}
free(text);
free(list.p_values);
free(list);
}
}
......
......@@ -1375,7 +1375,7 @@ int VLCMenuBar::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
vlc_object_t *p_object )
{
vlc_value_t val;
vlc_list_t val_list;
vlc_value_t *val_list;
char **text_list;
size_t count, i;
int i_type;
......@@ -1406,7 +1406,7 @@ int VLCMenuBar::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
return VLC_EGENERIC;
}
#define CURVAL val_list.p_values[i]
#define CURVAL val_list[i]
#define CURTEXT text_list[i]
#define RADIO_OR_COMMAND ( i_type & ( VLC_VAR_ISCOMMAND | VLC_VAR_HASCHOICE ) ) ? ITEM_RADIO : ITEM_NORMAL
......@@ -1457,7 +1457,7 @@ int VLCMenuBar::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
/* clean up everything */
free(text_list);
free(val_list.p_values);
free(val_list);
#undef RADIO_OR_COMMAND
#undef CURVAL
......
......@@ -220,7 +220,7 @@ static int vlclua_var_create( lua_State *L )
static int vlclua_var_get_list( lua_State *L )
{
vlc_list_t val;
vlc_value_t *val;
char **text;
size_t count;
vlc_object_t **pp_obj = luaL_checkudata( L, 1, "vlc_object" );
......@@ -231,15 +231,17 @@ static int vlclua_var_get_list( lua_State *L )
if( i_ret < 0 )
return vlclua_push_ret( L, i_ret );
int type = var_Type( *pp_obj, psz_var );
lua_createtable( L, count, 0 );
for( size_t i = 0; i < count; i++ )
{
lua_pushinteger( L, i+1 );
if( !vlclua_pushvalue( L, val.i_type, val.p_values[i] ) )
lua_pushnil( L );
if( !vlclua_pushvalue( L, type, val[i] ) )
lua_pushnil( L );
lua_settable( L, -3 );
if( (val.i_type & VLC_VAR_CLASS) == VLC_VAR_STRING )
free(val.p_values[i].psz_string);
if( (type & VLC_VAR_CLASS) == VLC_VAR_STRING )
free(val[i].psz_string);
}
lua_createtable( L, count, 0 );
......@@ -252,7 +254,7 @@ static int vlclua_var_get_list( lua_State *L )
}
free(text);
free(val.p_values);
free(val);
return 2;
}
......
......@@ -471,7 +471,7 @@ static void aout_PrepareStereoMode (audio_output_t *aout,
}
bool mode_available = false;
vlc_list_t vals;
vlc_value_t *vals;
size_t count;
if (!var_Change(aout, "stereo-mode", VLC_VAR_GETCHOICES,
......@@ -479,10 +479,10 @@ static void aout_PrepareStereoMode (audio_output_t *aout,
{
for (size_t i = 0; !mode_available && i < count; ++i)
{
if (vals.p_values[i].i_int == i_output_mode)
if (vals[i].i_int == i_output_mode)
mode_available = true;
}
free(vals.p_values);
free(vals);
}
if (!mode_available)
i_output_mode = i_default_mode;
......
......@@ -3277,7 +3277,7 @@ static int input_SlaveSourceAdd( input_thread_t *p_input,
return VLC_SUCCESS;
/* Select the ES */
vlc_list_t list;
vlc_value_t *list;
size_t entries;
if( var_Change( p_input, psz_es, VLC_VAR_GETCHOICES,
......@@ -3290,12 +3290,12 @@ static int input_SlaveSourceAdd( input_thread_t *p_input,
if( count < entries )
{
const int i_id = list.p_values[count].i_int;
const int i_id = list[count].i_int;
es_out_Control( input_priv(p_input)->p_es_out_display, ES_OUT_SET_ES_DEFAULT_BY_ID, i_id );
es_out_Control( input_priv(p_input)->p_es_out_display, ES_OUT_SET_ES_BY_ID, i_id );
}
free(list.p_values);
free(list);
return VLC_SUCCESS;
}
......
......@@ -545,18 +545,17 @@ int (var_Change)(vlc_object_t *p_this, const char *psz_name, int i_action, ...)
case VLC_VAR_GETCHOICES:
{
size_t *count = va_arg(ap, size_t *);
vlc_list_t *values = va_arg(ap, vlc_list_t *);
vlc_value_t **values = va_arg(ap, vlc_value_t **);
char ***texts = va_arg(ap, char ***);
*count = p_var->choices_count;
values->i_type = p_var->i_type;
values->i_count = *count;
values->p_values = xmalloc(*count * sizeof (values->p_values));
*values = xmalloc(p_var->choices_count * sizeof (**values));
for (size_t i = 0; i < p_var->choices_count; i++)
{
values->p_values[i] = p_var->choices[i];
p_var->ops->pf_dup( &values->p_values[i] );
vlc_value_t *val = (*values) + i;
*val = p_var->choices[i];
p_var->ops->pf_dup(val);
}
if( texts != NULL )
......
......@@ -324,7 +324,7 @@ static void test_limits( libvlc_int_t *p_libvlc )
static void test_choices( libvlc_int_t *p_libvlc )
{
vlc_value_t val;
vlc_list_t vals;
vlc_value_t *vals;
char **texts;
size_t count;
......@@ -341,11 +341,10 @@ static void test_choices( libvlc_int_t *p_libvlc )
assert( var_CountChoices( p_libvlc, "bla" ) == 1 );
var_Change( p_libvlc, "bla", VLC_VAR_GETCHOICES, &count, &vals, &texts );
assert( count == 1 && vals.i_count == 1 && vals.p_values[0].i_int == 1 &&
!strcmp( texts[0], "one" ) );
assert( count == 1 && vals[0].i_int == 1 && !strcmp( texts[0], "one" ) );
free(texts[0]);
free(texts);
free(vals.p_values);
free(vals);
var_Change( p_libvlc, "bla", VLC_VAR_CLEARCHOICES );
assert( var_CountChoices( p_libvlc, "bla" ) == 0 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment