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++;
......
......@@ -629,12 +629,13 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
{
vlc_value_t val;
vlc_list_t list;
size_t count;
var_Get( p_input, "spu-es", &val );
var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
&list, (char ***)NULL );
&count, &list, (char ***)NULL );
if( list.i_count < 1 || val.i_int < 0 )
if( count < 1 || val.i_int < 0 )
{
DisplayMessage( p_vout, _("No active subtitle") );
var_FreeList( &list, NULL );
......@@ -698,12 +699,13 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
{
vlc_value_t val;
vlc_list_t list;
size_t count;
var_Get( p_input, "spu-es", &val );
var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
&list, (char ***)NULL );
&count, &list, (char ***)NULL );
if( list.i_count < 1 || val.i_int < 0 )
if( count < 1 || val.i_int < 0 )
{
DisplayMessage( p_vout, _("No active subtitle") );
var_FreeList( &list, NULL );
......@@ -742,16 +744,17 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
vlc_value_t val;
vlc_list_t list;
char **list2;
size_t count;
var_Get( p_input, "audio-es", &val );
var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
&list, &list2 );
&count, &list, &list2 );
if( list.i_count > 1 )
if( count > 1 )
{
int i;
size_t i;
for( i = 0; i < list.i_count; i++ )
for( i = 0; i < count; i++ )
{
if( val.i_int == list.p_values[i].i_int )
{
......@@ -759,13 +762,13 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
}
}
/* 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++;
......@@ -783,37 +786,33 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
vlc_value_t val;
vlc_list_t list;
char **list2;
int i;
size_t count, i;
var_Get( p_input, "spu-es", &val );
var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
&list, &list2 );
&count, &list, &list2 );
if( list.i_count <= 1 )
if( count <= 1 )
{
DisplayMessage( p_vout, _("Subtitle track: %s"),
_("N/A") );
var_FreeList( &list, &list2 );
break;
}
for( i = 0; i < list.i_count; i++ )
{
for( i = 0; i < count; i++ )
if( val.i_int == list.p_values[i].i_int )
{
break;
}
}
/* value of spu-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) && (i_action == ACTIONID_SUBTITLE_TRACK))
else if ((i == count - 1) && (i_action == ACTIONID_SUBTITLE_TRACK))
i = 0;
else if ((i == 0) && (i_action == ACTIONID_SUBTITLE_REVERSE_TRACK))
i = list.i_count - 1;
i = count - 1;
else
i = (i_action == ACTIONID_SUBTITLE_TRACK) ? i+1 : i-1;
var_SetInteger( p_input, "spu-es", list.p_values[i].i_int );
......@@ -826,11 +825,12 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
{
vlc_list_t list;
char **list2;
size_t count;
var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
&list, &list2 );
&count, &list, &list2 );
if( list.i_count <= 1 )
if( count <= 1 )
{
DisplayMessage( p_vout, _("Subtitle track: %s"),
_("N/A") );
......@@ -858,7 +858,7 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
/* if subtitles were disabled with no saved id, use the first track */
if( i_cur_id != -1 || i_new_id != -1 )
{
for( int i = 0; i < list.i_count; ++i )
for( size_t i = 0; i < count; ++i )
{
if( i_new_id == list.p_values[i].i_int )
{
......@@ -880,42 +880,38 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
vlc_value_t val;
vlc_list_t list;
char **list2;
int i;
size_t count, i;
var_Get( p_input, "program", &val );
var_Change( p_input, "program", VLC_VAR_GETCHOICES,
&list, &list2 );
&count, &list, &list2 );
if( list.i_count <= 1 )
if( count <= 1 )
{
DisplayMessage( p_vout, _("Program Service ID: %s"),
_("N/A") );
var_FreeList( &list, &list2 );
break;
}
for( i = 0; i < list.i_count; i++ )
{
for( i = 0; i < count; i++ )
if( val.i_int == list.p_values[i].i_int )
{
break;
}
}
/* value of program sid was not in choices list */
if( i == list.i_count )
if( i == count )
{
msg_Warn( p_input,
"invalid current program SID, selecting 0" );
i = 0;
}
else if( i_action == ACTIONID_PROGRAM_SID_NEXT ) {
if( i == list.i_count - 1 )
if( i == count - 1 )
i = 0;
else
i++;
}
else { /* ACTIONID_PROGRAM_SID_PREV */
if( i == 0 )
i = list.i_count - 1;
i = count - 1;
else
i--;
}
......@@ -1048,13 +1044,14 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
vlc_value_t val;
vlc_list_t val_list;
char **text_list;
size_t count;
var_Get( p_vout, "aspect-ratio", &val );
if( var_Change( p_vout, "aspect-ratio", VLC_VAR_GETCHOICES,
&val_list, &text_list ) >= 0 )
&count, &val_list, &text_list ) >= 0 )
{
int i;
for( i = 0; i < val_list.i_count; i++ )
size_t i;
for( i = 0; i < count; i++ )
{
if( !strcmp( val_list.p_values[i].psz_string,
val.psz_string ) )
......@@ -1063,7 +1060,7 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
break;
}
}
if( i == val_list.i_count ) i = 0;
if( i == count ) i = 0;
var_SetString( p_vout, "aspect-ratio",
val_list.p_values[i].psz_string );
DisplayMessage( p_vout, _("Aspect ratio: %s"),
......@@ -1081,13 +1078,14 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
vlc_value_t val;
vlc_list_t val_list;
char **text_list;
size_t count;
var_Get( p_vout, "crop", &val );
if( var_Change( p_vout, "crop", VLC_VAR_GETCHOICES,
&val_list, &text_list ) >= 0 )
&count, &val_list, &text_list ) >= 0 )
{
int i;
for( i = 0; i < val_list.i_count; i++ )
size_t i;
for( i = 0; i < count; i++ )
{
if( !strcmp( val_list.p_values[i].psz_string,
val.psz_string ) )
......@@ -1096,7 +1094,7 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
break;
}
}
if( i == val_list.i_count ) i = 0;
if( i == count ) i = 0;
var_SetString( p_vout, "crop",
val_list.p_values[i].psz_string );
DisplayMessage( p_vout, _("Crop: %s"), text_list[i] );
......@@ -1231,13 +1229,14 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
vlc_value_t val;
vlc_list_t val_list;
char **text_list;
size_t count;
var_Get( p_vout, "zoom", &val );
if( var_Change( p_vout, "zoom", VLC_VAR_GETCHOICES,
&val_list, &text_list ) >= 0 )
&count, &val_list, &text_list ) >= 0 )
{
int i;
for( i = 0; i < val_list.i_count; i++ )
size_t i;
for( i = 0; i < count; i++ )
{
if( val_list.p_values[i].f_float == val.f_float )
{
......@@ -1248,8 +1247,8 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
break;
}
}
if( i == val_list.i_count ) i = 0;
if( i == -1 ) i = val_list.i_count-1;
if( i == count ) i = 0;
if( i == (size_t)-1 ) i = count-1;
var_SetFloat( p_vout, "zoom",
val_list.p_values[i].f_float );
DisplayMessage( p_vout, _("Zoom mode: %s"), text_list[i] );
......@@ -1275,10 +1274,12 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
char *psz_mode = var_GetString( p_vout, "deinterlace-mode" );
vlc_list_t vlist;
char **tlist;
if( psz_mode && !var_Change( p_vout, "deinterlace-mode", VLC_VAR_GETCHOICES, &vlist, &tlist ) )
size_t count;
if( psz_mode && !var_Change( p_vout, "deinterlace-mode", VLC_VAR_GETCHOICES, &count, &vlist, &tlist ) )
{
const char *psz_text = NULL;
for( int i = 0; i < vlist.i_count; i++ )
for( size_t i = 0; i < count; i++ )
{
if( !strcmp( vlist.p_values[i].psz_string, psz_mode ) )
{
......@@ -1301,12 +1302,14 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
char *psz_mode = var_GetString( p_vout, "deinterlace-mode" );
vlc_list_t vlist;
char **tlist;
size_t count;
if( psz_mode && !var_Change( p_vout, "deinterlace-mode", VLC_VAR_GETCHOICES, &vlist, &tlist ))
if( psz_mode && !var_Change( p_vout, "deinterlace-mode", VLC_VAR_GETCHOICES, &count, &vlist, &tlist ))
{
const char *psz_text = NULL;
int i;
for( i = 0; i < vlist.i_count; i++ )
size_t i;
for( i = 0; i < count; i++ )
{
if( !strcmp( vlist.p_values[i].psz_string, psz_mode ) )
{
......@@ -1314,7 +1317,7 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
break;
}
}
if( i == vlist.i_count ) i = 0;
if( i == count ) i = 0;
psz_text = tlist[i];
var_SetString( p_vout, "deinterlace-mode", vlist.p_values[i].psz_string );
......@@ -1343,11 +1346,13 @@ static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
{
vlc_value_t val;
vlc_list_t list;
size_t count;
var_Get( p_input, "spu-es", &val );
var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
&list, (char ***)NULL );
if( list.i_count < 1 || val.i_int < 0 )
&count, &list, (char ***)NULL );
if( count < 1 || val.i_int < 0 )
{
DisplayMessage( p_vout,
_("Subtitle position: no active subtitle") );
......
......@@ -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;
}