Commit 5e50399a authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

variables: add count parameter for VLC_VAR_GETCHOICES

parent 34925c7c
......@@ -382,14 +382,15 @@ 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;
size_t count;
int i_ret = -1;
if( !p_input_thread )
return -1;
var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list,
(char ***)NULL );
for( int i = 0; i < val_list.i_count; i++ )
var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES,
&count, &val_list, (char ***)NULL );
for( size_t i = 0; i < count; i++ )
{
if( i_track == val_list.p_values[i].i_int )
{
......
......@@ -1790,12 +1790,15 @@ libvlc_track_description_t *
vlc_list_t val_list;
char **text_list;
int i_ret = var_Change( p_input, psz_variable, VLC_VAR_GETCHOICES, &val_list, &text_list );
size_t count;
int i_ret = var_Change( p_input, psz_variable, VLC_VAR_GETCHOICES,
&count, &val_list, &text_list );
if( i_ret != VLC_SUCCESS )
return NULL;
/* no tracks */
if( val_list.i_count <= 0 )
if( count == 0 )
goto end;
p_track_description = malloc( sizeof *p_track_description );
......@@ -1806,7 +1809,7 @@ libvlc_track_description_t *
}
p_actual = p_track_description;
p_previous = NULL;
for( int i = 0; i < val_list.i_count; i++ )
for( size_t i = 0; i < count; i++ )
{
if( !p_actual )
{
......
......@@ -354,14 +354,15 @@ 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;
size_t count;
int i_ret = -1;
if( !p_input_thread )
return -1;
var_Change(p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &list,
(char ***)NULL);
for (int i = 0; i < list.i_count; i++)
var_Change(p_input_thread, "spu-es", VLC_VAR_GETCHOICES,
&count, &list, (char ***)NULL);
for (size_t i = 0; i < count; i++)
{
if( i_spu == list.p_values[i].i_int )
{
......@@ -452,10 +453,12 @@ static void teletext_enable( input_thread_t *p_input_thread, bool b_enable )
if( b_enable )
{
vlc_list_t list;
size_t count;
if( !var_Change( p_input_thread, "teletext-es", VLC_VAR_GETCHOICES,
&list, (char ***)NULL ) )
&count, &list, (char ***)NULL ) )
{
if( list.i_count > 0 )
if( count > 0 )
var_SetInteger( p_input_thread, "spu-es",
list.p_values[0].i_int );
......@@ -569,14 +572,15 @@ 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;
size_t count;
int i_ret = -1;
if( !p_input_thread )
return -1;
var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list,
(char ***)NULL );
for( int i = 0; i < val_list.i_count; i++ )
var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES,
&count, &val_list, (char ***)NULL );
for( size_t i = 0; i < count; i++ )
{
if( i_track == val_list.p_values[i].i_int )
{
......
......@@ -278,25 +278,27 @@ static void ProcessGesture( intf_thread_t *p_intf )
break;
vlc_list_t list;
size_t count;
var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
&list, (char ***)NULL );
&count, &list, (char ***)NULL );
if( list.i_count > 1 )
if( count > 1 )
{
int i_audio_es = var_GetInteger( p_input, "audio-es" );
int i;
size_t i;
for( i = 0; i < list.i_count; i++ )
for( i = 0; i < count; i++ )
if( i_audio_es == list.p_values[i].i_int )
break;
/* value of audio-es was not in choices list */
if( i == list.i_count )
if( i == count )
{
msg_Warn( p_input,
"invalid current audio track, selecting 0" );
i = 0;
}
else if( i == list.i_count - 1 )
else if( i == count - 1 )
i = 1;
else
i++;
......@@ -315,25 +317,27 @@ static void ProcessGesture( intf_thread_t *p_intf )
break;
vlc_list_t list;
size_t count;
var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
&list, (char ***)NULL );
&count, &list, (char ***)NULL );
if( list.i_count > 1 )
if( count > 1 )
{
int i_audio_es = var_GetInteger( p_input, "spu-es" );
int i;
size_t i;
for( i = 0; i < list.i_count; i++ )
for( i = 0; i < count; i++ )
if( i_audio_es == list.p_values[i].i_int )
break;
/* value of audio-es was not in choices list */
if( i == list.i_count )
if( i == count )
{
msg_Warn( p_input,
"invalid current subtitle track, selecting 0" );
i = 0;
}
else if( i == list.i_count - 1 )
else if( i == count - 1 )
i = 1;
else
i++;
......
This diff is collapsed.
......@@ -1124,18 +1124,19 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
/* get */
vlc_list_t val;
char **text;
size_t count;
int i_value = var_GetInteger( p_input, psz_variable );
if ( var_Change( p_input, psz_variable,
VLC_VAR_GETCHOICES, &val, &text ) < 0 )
if ( var_Change( p_input, psz_variable, VLC_VAR_GETCHOICES,
&count, &val, &text ) < 0 )
{
free( name );
goto out;
}
msg_rc( "+----[ %s ]", name );
for ( int i = 0; i < val.i_count; i++ )
for ( size_t i = 0; i < count; i++ )
{
if ( i_value == val.p_values[i].i_int )
msg_rc( "| %"PRId64" - %s *", val.p_values[i].i_int,
......@@ -1561,6 +1562,7 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
char **text;
float f_value = 0.;
char *psz_value = NULL;
size_t count;
if( !strcmp( psz_variable, "zoom" ) )
f_value = var_GetFloat( p_vout, "zoom" );
......@@ -1574,8 +1576,8 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
}
}
if ( var_Change( p_vout, psz_variable,
VLC_VAR_GETCHOICES, &val, &text ) < 0 )
if ( var_Change( p_vout, psz_variable, VLC_VAR_GETCHOICES,
&count, &val, &text ) < 0 )
{
vlc_object_release( p_vout );
free( psz_value );
......@@ -1589,7 +1591,7 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
msg_rc( "+----[ %s ]", name );
if( !strcmp( psz_variable, "zoom" ) )
{
for ( int i = 0; i < val.i_count; i++ )
for ( size_t i = 0; i < count; i++ )
{
if ( f_value == val.p_values[i].f_float )
msg_rc( "| %f - %s *", val.p_values[i].f_float, text[i] );
......@@ -1599,7 +1601,7 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
}
else
{
for ( int i = 0; i < val.i_count; i++ )
for ( size_t i = 0; i < count; i++ )
{
if ( !strcmp( psz_value, val.p_values[i].psz_string ) )
msg_rc( "| %s - %s *", val.p_values[i].psz_string,
......@@ -1676,8 +1678,10 @@ static int AudioChannel( vlc_object_t *obj, char const *cmd,
/* Retrieve all registered ***. */
vlc_list_t val;
char **text;
if ( var_Change( p_aout, "stereo-mode",
VLC_VAR_GETCHOICES, &val, &text ) < 0 )
size_t count;
if ( var_Change( p_aout, "stereo-mode", VLC_VAR_GETCHOICES,
&count, &val, &text ) < 0 )
{
ret = VLC_ENOVAR;
goto out;
......@@ -1686,7 +1690,7 @@ static int AudioChannel( vlc_object_t *obj, char const *cmd,
int i_value = var_GetInteger( p_aout, "stereo-mode" );
msg_rc( "+----[ %s ]", cmd );
for ( int i = 0; i < val.i_count; i++ )
for ( size_t i = 0; i < count; i++ )
{
if ( i_value == val.p_values[i].i_int )
msg_rc( "| %"PRId64" - %s *", val.p_values[i].i_int, text[i] );
......
......@@ -1450,7 +1450,8 @@
vlc_value_t val;
vlc_list_t val_list;
char **text_list;
int i_type, i;
size_t count, i;
int i_type;
/* remove previous items */
[menu removeAllItems];
......@@ -1499,15 +1500,15 @@
}
if (var_Change(p_object, psz_variable, VLC_VAR_GETCHOICES,
&val_list, &text_list) < 0) {
&count, &val_list, &text_list) < 0) {
if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
return;
}
/* make (un)sensitive */
[parent setEnabled: (val_list.i_count > 1)];
[parent setEnabled: (count > 1)];
for (i = 0; i < val_list.i_count; i++) {
for (i = 0; i < count; i++) {
NSMenuItem *lmi;
NSString *title = @"";
VLCAutoGeneratedMenuContent *data;
......
......@@ -1539,18 +1539,20 @@ static void CycleESTrack(input_thread_t *input, const char *var)
return;
vlc_list_t list;
if (var_Change(input, var, VLC_VAR_GETCHOICES, &list,
(char ***)NULL) < 0)
size_t count;
if (var_Change(input, var, VLC_VAR_GETCHOICES,
&count, &list, (char ***)NULL) < 0)
return;
int64_t current = var_GetInteger(input, var);
int i;
for (i = 0; i < list.i_count; i++)
size_t i;
for (i = 0; i < count; i++)
if (list.p_values[i].i_int == current)
break;
if (++i >= list.i_count)
if (++i >= count)
i = 0;
var_SetInteger(input, var, list.p_values[i].i_int);
}
......
......@@ -270,6 +270,8 @@ void AspectRatioComboBox::updateRatios()
clear();
vlc_list_t val_list;
char **text_list;
size_t count;
vout_thread_t* p_vout = THEMIM->getVout();
/* Disable if there is no vout */
......@@ -280,8 +282,9 @@ void AspectRatioComboBox::updateRatios()
return;
}
var_Change( p_vout, "aspect-ratio", VLC_VAR_GETCHOICES, &val_list, &text_list );
for( int i = 0; i < val_list.i_count; i++ )
var_Change( p_vout, "aspect-ratio", VLC_VAR_GETCHOICES,
&count, &val_list, &text_list );
for( size_t i = 0; i < count; i++ )
addItem( qfu( text_list[i] ),
QString( val_list.p_values[i].psz_string ) );
setEnabled( true );
......
......@@ -653,8 +653,10 @@ void ExtV4l2::Refresh( void )
{
vlc_list_t val;
char **text;
size_t count;
int i_ret = var_Change( p_obj, "controls", VLC_VAR_GETCHOICES,
&val, &text );
&count, &val, &text );
if( i_ret < 0 )
{
msg_Err( p_intf, "Oops, v4l2 object doesn't have a 'controls' variable." );
......@@ -668,7 +670,7 @@ void ExtV4l2::Refresh( void )
QVBoxLayout *layout = new QVBoxLayout( box );
box->setLayout( layout );
for( int i = 0; i < val.i_count; i++ )
for( size_t i = 0; i < count; i++ )
{
char *vartext;
const char *psz_var = text[i];
......@@ -697,9 +699,11 @@ void ExtV4l2::Refresh( void )
vlc_list_t val2;
char **text2;
size_t count2;
var_Change( p_obj, psz_var, VLC_VAR_GETCHOICES,
&val2, &text2 );
for( int j = 0; j < val2.i_count; j++ )
&count2, &val2, &text2 );
for( size_t j = 0; j < count2; j++ )
{
combobox->addItem( text2[j],
qlonglong( val2.p_values[j].i_int) );
......
......@@ -861,21 +861,23 @@ void InputManager::activateTeletext( bool b_enable )
{
vlc_list_t list;
char **text;
size_t count;
if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETCHOICES, &list, &text ) )
if( hasInput() && !var_Change( p_input, "teletext-es", VLC_VAR_GETCHOICES,
&count, &list, &text ) )
{
if( list.i_count > 0 )
if( count > 0 )
{
/* Prefer the page 100 if it is present */
int i;
for( i = 0; i < list.i_count; i++ )
size_t i;
for( i = 0; i < count; i++ )
{
/* The description is the page number as a string */
const char *psz_page = text[i];
if( psz_page && !strcmp( psz_page, "100" ) )
break;
}
if( i >= list.i_count )
if( i >= count )
i = 0;
var_SetInteger( p_input, "spu-es", b_enable ? list.p_values[i].i_int : -1 );
}
......
......@@ -1377,7 +1377,8 @@ int VLCMenuBar::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
vlc_value_t val;
vlc_list_t val_list;
char **text_list;
int i_type, i;
size_t count, i;
int i_type;
/* Check the type of the object variable */
i_type = var_Type( p_object, psz_var );
......@@ -1400,7 +1401,7 @@ int VLCMenuBar::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
}
if( var_Change( p_object, psz_var, VLC_VAR_GETCHOICES,
&val_list, &text_list ) < 0 )
&count, &val_list, &text_list ) < 0 )
{
return VLC_EGENERIC;
}
......@@ -1409,7 +1410,7 @@ int VLCMenuBar::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
#define CURTEXT text_list[i]
#define RADIO_OR_COMMAND ( i_type & ( VLC_VAR_ISCOMMAND | VLC_VAR_HASCHOICE ) ) ? ITEM_RADIO : ITEM_NORMAL
for( i = 0; i < val_list.i_count; i++ )
for( i = 0; i < count; i++ )
{
vlc_value_t another_val;
QString menutext;
......
......@@ -83,21 +83,6 @@ static int vlclua_pushvalue( lua_State *L, int i_type, vlc_value_t val )
return 1;
}
static int vlclua_pushlist( lua_State *L, vlc_list_t *p_list )
{
int i_count = p_list->i_count;
lua_createtable( L, i_count, 0 );
for( int i = 0; i < i_count; i++ )
{
lua_pushinteger( L, i+1 );
if( !vlclua_pushvalue( L, p_list->i_type, p_list->p_values[i] ) )
lua_pushnil( L );
lua_settable( L, -3 );
}
return 1;
}
static int vlclua_tovalue( lua_State *L, int i_type, vlc_value_t *val )
{
switch( i_type & VLC_VAR_CLASS )
......@@ -237,17 +222,26 @@ static int vlclua_var_get_list( lua_State *L )
{
vlc_list_t val;
char **text;
size_t count;
vlc_object_t **pp_obj = luaL_checkudata( L, 1, "vlc_object" );
const char *psz_var = luaL_checkstring( L, 2 );
int i_ret = var_Change( *pp_obj, psz_var, VLC_VAR_GETCHOICES, &val, &text );
int i_ret = var_Change( *pp_obj, psz_var, VLC_VAR_GETCHOICES,
&count, &val, &text );
if( i_ret < 0 )
return vlclua_push_ret( L, i_ret );
vlclua_pushlist( L, &val );
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 );
lua_settable( L, -3 );
}
lua_createtable( L, val.i_count, 0 );
for( int i = 0; i < val.i_count; i++ )
lua_createtable( L, count, 0 );
for( size_t i = 0; i < count; i++ )
{
lua_pushinteger( L, i + 1 );
lua_pushstring( L, text[i] );
......
......@@ -472,10 +472,12 @@ static void aout_PrepareStereoMode (audio_output_t *aout,
bool mode_available = false;
vlc_list_t vals;
if (!var_Change(aout, "stereo-mode", VLC_VAR_GETCHOICES, &vals,
(char ***)NULL))
size_t count;
if (!var_Change(aout, "stereo-mode", VLC_VAR_GETCHOICES,
&count, &vals, (char ***)NULL))
{
for (int i = 0; !mode_available && i < vals.i_count; ++i)
for (size_t i = 0; !mode_available && i < count; ++i)
{
if (vals.p_values[i].i_int == i_output_mode)
mode_available = true;
......
......@@ -3278,16 +3278,17 @@ static int input_SlaveSourceAdd( input_thread_t *p_input,
/* Select the ES */
vlc_list_t list;
size_t entries;
if( var_Change( p_input, psz_es, VLC_VAR_GETCHOICES, &list,
(char ***)NULL ) )
if( var_Change( p_input, psz_es, VLC_VAR_GETCHOICES,
&entries, &list, (char ***)NULL ) )
return VLC_SUCCESS;
if( count == 0 )
count++;
/* if it was first one, there is disable too */
if( count < (size_t)list.i_count )
if( count < entries )
{
const int i_id = list.p_values[count].i_int;
......
......@@ -551,9 +551,11 @@ int (var_Change)(vlc_object_t *p_this, const char *psz_name, int i_action, ...)
break;
case VLC_VAR_GETCHOICES:
{
size_t *count = va_arg(ap, size_t *);
vlc_list_t *values = va_arg(ap, vlc_list_t *);
char ***texts = va_arg(ap, char ***);
*count = p_var->choices.i_count;
values->p_values =
xmalloc( p_var->choices.i_count * sizeof(vlc_value_t) );
values->i_type = p_var->i_type;
......
......@@ -326,6 +326,7 @@ static void test_choices( libvlc_int_t *p_libvlc )
vlc_value_t val;
vlc_list_t vals;
char **texts;
size_t count;
var_Create( p_libvlc, "bla", VLC_VAR_INTEGER | VLC_VAR_ISCOMMAND );
val.i_int = 1;
......@@ -339,8 +340,8 @@ static void test_choices( libvlc_int_t *p_libvlc )
var_Change( p_libvlc, "bla", VLC_VAR_DELCHOICE, val );
assert( var_CountChoices( p_libvlc, "bla" ) == 1 );
var_Change( p_libvlc, "bla", VLC_VAR_GETCHOICES, &vals, &texts );
assert( vals.i_count == 1 && vals.p_values[0].i_int == 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" ) );
var_FreeList( &vals, &texts );
......
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