vlc_object_get() now increments the refcount of the object so you'll need to release
the object at some point.
* src/misc/variables.c, ALL: var_Change() with VLC_VAR_GETLIST now returns a vlc_value_t
which points to a vlc_list_t.
* variables.h: variables handling
*****************************************************************************
* Copyright (C) 2002 VideoLAN
- * $Id: variables.h,v 1.10 2002/12/13 01:56:29 gbazin Exp $
+ * $Id: variables.h,v 1.11 2002/12/14 19:34:07 gbazin Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
/* If the variable is to be chosen in a list */
int i_default;
- int i_choices;
- vlc_value_t *pp_choices;
+ vlc_list_t choices;
/* Set to TRUE if the variable is in a callback */
vlc_bool_t b_incallback;
* vlc.h: global header for vlc
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: vlc.h,v 1.19 2002/12/13 01:56:29 gbazin Exp $
+ * $Id: vlc.h,v 1.20 2002/12/14 19:34:07 gbazin Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
char * psz_string;
void * p_address;
vlc_object_t * p_object;
+ vlc_list_t * p_list;
/* Make sure the structure is at least 64bits */
struct { char a, b, c, d, e, f, g, h; } padding;
* rc.c : remote control stdin/stdout plugin for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: rc.c,v 1.16 2002/12/07 23:50:30 massiot Exp $
+ * $Id: rc.c,v 1.17 2002/12/14 19:34:06 gbazin Exp $
*
* Authors: Peter Surda <shurdeek@panorama.sth.ac.at>
*
{
/* Retrieve all registered ***. */
vlc_value_t val;
- int i, i_vals;
- vlc_value_t * p_vals;
- const char * psz_value;
+ int i;
+ char * psz_value;
if ( var_Get( (vlc_object_t *)p_aout, psz_variable, &val ) < 0 )
{
}
printf( "+----[ %s ]\n", psz_name );
- i_vals = ((vlc_value_t *)val.p_address)[0].i_int;
- p_vals = &((vlc_value_t *)val.p_address)[1]; /* Starts at index 1 */
- for ( i = 0; i < i_vals; i++ )
+ for ( i = 0; i < val.p_list->i_count; i++ )
{
- if ( !strcmp( psz_value, p_vals[i].psz_string ) )
- printf( "| %s *\n", p_vals[i].psz_string );
+ if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
+ printf( "| %s *\n", val.p_list->p_values[i].psz_string );
else
- printf( "| %s\n", p_vals[i].psz_string );
+ printf( "| %s\n", val.p_list->p_values[i].psz_string );
}
var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
&val );
* intf.m: MacOS X interface plugin
*****************************************************************************
* Copyright (C) 2002 VideoLAN
- * $Id: intf.m,v 1.9 2002/12/08 23:38:02 massiot Exp $
+ * $Id: intf.m,v 1.10 2002/12/14 19:34:06 gbazin Exp $
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
* Christophe Massiot <massiot@via.ecp.fr>
int i, i_nb_items;
NSMenu * o_menu = [o_mi submenu];
vlc_value_t val;
- int i_vals;
- vlc_value_t * p_vals;
char * psz_value;
/* remove previous items */
return;
}
- i_vals = ((vlc_value_t *)val.p_address)[0].i_int;
- p_vals = &((vlc_value_t *)val.p_address)[1]; /* Starts at index 1 */
-
/* make (un)sensitive */
- [o_mi setEnabled: (i_vals > 0)];
+ [o_mi setEnabled: (val.p_list->i_count > 0)];
- for ( i = 0; i < i_vals; i++ )
+ for ( i = 0; i < val.p_list->i_count; i++ )
{
NSMenuItem * o_lmi;
NSString * o_title;
- o_title = [NSString stringWithCString: p_vals[i].psz_string];
+ o_title = [NSString stringWithCString: val.p_list->p_values[i].psz_string];
o_lmi = [o_menu addItemWithTitle: o_title
action: pf_callback keyEquivalent: @""];
/* FIXME: this isn't 64-bit clean ! */
[NSValue valueWithPointer: p_object]];
[o_lmi setTarget: o_controls];
- if ( !strcmp( psz_value, p_vals[i].psz_string ) )
+ if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
[o_lmi setState: NSOnState];
}
* test4.c : Miscellaneous stress tests module for vlc
*****************************************************************************
* Copyright (C) 2002 VideoLAN
- * $Id: test4.c,v 1.5 2002/12/07 15:25:26 gbazin Exp $
+ * $Id: test4.c,v 1.6 2002/12/14 19:34:06 gbazin Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
vlc_value_t val;
- int i, i_vals;
- vlc_value_t *p_vals;
+ int i;
var_Create( p_this, "honk", VLC_VAR_STRING | VLC_VAR_HASCHOICE );
var_Get( p_this, "honk", &val ); printf( "value: %s\n", val.psz_string );
var_Change( p_this, "honk", VLC_VAR_GETLIST, &val );
- i_vals = ((vlc_value_t*)val.p_address)[0].i_int;
- p_vals = &((vlc_value_t*)val.p_address)[1];
- for( i = 0 ; i < i_vals ; i++ )
+ for( i = 0 ; i < val.p_list->i_count ; i++ )
{
- printf( "value %i: %s\n", i, p_vals[i].psz_string );
+ printf( "value %i: %s\n", i, val.p_list->p_values[i].psz_string );
}
var_Change( p_this, "honk", VLC_VAR_FREELIST, &val );
{
int id = (int) (MAXOBJ * i_level * 1.0 * rand() / (RAND_MAX));
vlc_object_get( p_this, pp_objects[id]->i_object_id );
+ vlc_object_release( p_this );
}
printf( " - destroying the objects (LIFO)\n" );
* libvlc.c: main libvlc source
*****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
- * $Id: libvlc.c,v 1.51 2002/12/13 01:56:30 gbazin Exp $
+ * $Id: libvlc.c,v 1.52 2002/12/14 19:34:06 gbazin Exp $
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
if( p_help_module == NULL )
{
//module_EndBank( p_vlc );
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_EGENERIC;
}
p_help_module->psz_object_name = "help";
config_Free( p_help_module );
vlc_object_destroy( p_help_module );
//module_EndBank( p_vlc );
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_EGENERIC;
}
config_Free( p_help_module );
vlc_object_destroy( p_help_module );
//module_EndBank( p_vlc );
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_EEXIT;
}
if( b_exit )
{
//module_EndBank( p_vlc );
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_EEXIT;
}
getchar();
#endif
//module_EndBank( p_vlc );
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_EGENERIC;
}
config_PutInt( p_vlc, "network-channel", VLC_FALSE );
}
+ msg_Err( p_vlc, "SIZEOF: %i", sizeof(vlc_list_t) );
+ msg_Err( p_vlc, "SIZEOF: %i", sizeof(vlc_value_t) );
+
/*
* Initialize playlist and get commandline files
*/
module_Unneed( p_vlc, p_vlc->p_memcpy_module );
}
//module_EndBank( p_vlc );
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_EGENERIC;
}
*/
GetFilenames( p_vlc, i_argc, ppsz_argv );
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS;
}
if( p_intf == NULL )
{
msg_Err( p_vlc, "interface initialization failed" );
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_EGENERIC;
}
{
vlc_object_detach( p_intf );
intf_Destroy( p_intf );
+ if( i_object ) vlc_object_release( p_vlc );
return i_err;
}
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS;
}
/* Stop thread system: last one out please shut the door! */
vlc_threads_end( &libvlc );
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS;
}
p_vlc->b_die = VLC_TRUE;
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS;
}
if( p_playlist == NULL )
{
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_EGENERIC;
}
vlc_object_release( p_playlist );
+ if( i_object ) vlc_object_release( p_vlc );
return i_err;
}
int VLC_Set( int i_object, char const *psz_var, vlc_value_t value )
{
vlc_t *p_vlc;
+ int i_ret;
p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
config_PutPsz( p_vlc, psz_newvar, value.psz_string );
break;
}
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS;
}
}
- return var_Set( p_vlc, psz_var, value );
+ i_ret = var_Set( p_vlc, psz_var, value );
+
+ if( i_object ) vlc_object_release( p_vlc );
+ return i_ret;
}
/*****************************************************************************
int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
{
vlc_t *p_vlc;
+ int i_ret;
p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
return VLC_ENOOBJ;
}
- return var_Get( p_vlc, psz_var, p_value );
+ i_ret = var_Get( p_vlc, psz_var, p_value );
+
+ if( i_object ) vlc_object_release( p_vlc );
+ return i_ret;
}
/* FIXME: temporary hacks */
if( !p_playlist )
{
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_ENOOBJ;
}
vlc_object_release( p_playlist );
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS;
}
aout_Delete( p_aout );
}
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS;
}
if( !p_input )
{
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_ENOOBJ;
}
input_SetStatus( p_input, INPUT_STATUS_PAUSE );
vlc_object_release( p_input );
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS;
}
if( !p_vout )
{
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_ENOOBJ;
}
p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
vlc_object_release( p_vout );
+ if( i_object ) vlc_object_release( p_vlc );
return VLC_SUCCESS;
}
* objects.c: vlc_object_t handling
*****************************************************************************
* Copyright (C) 2002 VideoLAN
- * $Id: objects.c,v 1.32 2002/12/13 01:56:30 gbazin Exp $
+ * $Id: objects.c,v 1.33 2002/12/14 19:34:06 gbazin Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
static vlc_list_t NewList ( int );
static void ListReplace ( vlc_list_t *, vlc_object_t *, int );
static void ListAppend ( vlc_list_t *, vlc_object_t * );
+static int CountChildren ( vlc_object_t *, int );
+static void ListChildren ( vlc_list_t *, vlc_object_t *, int );
/*****************************************************************************
* Local structure lock
if( pp_objects[i_middle+1]->i_object_id == i_id )
{
vlc_mutex_unlock( &structure_lock );
+ pp_objects[i_middle+1]->i_refcount++;
return pp_objects[i_middle+1];
}
break;
else
{
vlc_mutex_unlock( &structure_lock );
+ pp_objects[i_middle]->i_refcount++;
return pp_objects[i_middle];
}
vlc_list_t __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
{
vlc_list_t list;
+ vlc_object_t **pp_current, **pp_end;
+ int i_count = 0, i_index = 0;
vlc_mutex_lock( &structure_lock );
/* Look for the objects */
- if( (i_mode & 0x000f) == FIND_ANYWHERE )
+ switch( i_mode & 0x000f )
{
- vlc_object_t **pp_current, **pp_end;
- int i_count = 0, i_index = 0;
-
+ case FIND_ANYWHERE:
pp_current = p_this->p_libvlc->pp_objects;
pp_end = pp_current + p_this->p_libvlc->i_objects;
if( i_index < i_count ) i_index++;
}
}
- }
- else
- {
+ break;
+
+ case FIND_CHILD:
+ i_count = CountChildren( p_this, i_type );
+ list = NewList( i_count );
+
+ /* Check allocation was successful */
+ if( list.i_count != i_count )
+ {
+ msg_Err( p_this, "list allocation failed!" );
+ list.i_count = 0;
+ break;
+ }
+
+ list.i_count = 0;
+ ListChildren( &list, p_this, i_type );
+ break;
+
+ default:
msg_Err( p_this, "unimplemented!" );
list = NewList( 0 );
+ break;
}
vlc_mutex_unlock( &structure_lock );
DumpStructure( p_object, 0, psz_foo );
vlc_mutex_unlock( &structure_lock );
+
+ if( *newval.psz_string )
+ {
+ vlc_object_release( p_this );
+ }
}
else if( *psz_cmd == 'l' )
{
return;
}
+
+static int CountChildren( vlc_object_t *p_this, int i_type )
+{
+ vlc_object_t *p_tmp;
+ int i, i_count = 0;
+
+ for( i = 0; i < p_this->i_children; i++ )
+ {
+ p_tmp = p_this->pp_children[i];
+
+ if( p_tmp->i_object_type == i_type )
+ {
+ i_count++;
+ }
+
+ if( p_tmp->i_children )
+ {
+ i_count += CountChildren( p_tmp, i_type );
+ }
+ }
+
+ return i_count;
+}
+
+static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type )
+{
+ vlc_object_t *p_tmp;
+ int i;
+
+ for( i = 0; i < p_this->i_children; i++ )
+ {
+ p_tmp = p_this->pp_children[i];
+
+ if( p_tmp->i_object_type == i_type )
+ {
+ ListReplace( p_list, p_tmp, p_list->i_count++ );
+ }
+
+ if( p_tmp->i_children )
+ {
+ ListChildren( p_list, p_tmp, i_type );
+ }
+ }
+}
* variables.c: routines for object variables handling
*****************************************************************************
* Copyright (C) 2002 VideoLAN
- * $Id: variables.c,v 1.17 2002/12/10 18:22:01 gbazin Exp $
+ * $Id: variables.c,v 1.18 2002/12/14 19:34:06 gbazin Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
p_var->i_usage = 1;
p_var->i_default = -1;
- p_var->i_choices = 0;
- p_var->pp_choices = NULL;
+ p_var->choices.i_count = 0;
+ p_var->choices.p_values = NULL;
p_var->b_incallback = VLC_FALSE;
p_var->i_entries = 0;
p_var->pf_free( &p_var->val );
/* Free choice list if needed */
- if( p_var->pp_choices )
+ if( p_var->choices.i_count )
{
- for( i = 0 ; i < p_var->i_choices ; i++ )
+ for( i = 0 ; i < p_var->choices.i_count ; i++ )
{
- p_var->pf_free( &p_var->pp_choices[i] );
+ p_var->pf_free( &p_var->choices.p_values[i] );
}
- free( p_var->pp_choices );
+ free( p_var->choices.p_values );
}
/* Free callbacks if needed */
p_var->pf_dup( &p_var->step );
CheckValue( p_var, &p_var->val );
break;
-
case VLC_VAR_ADDCHOICE:
/* FIXME: the list is sorted, dude. Use something cleverer. */
- for( i = p_var->i_choices ; i-- ; )
+ for( i = p_var->choices.i_count ; i-- ; )
{
- if( p_var->pf_cmp( p_var->pp_choices[i], *p_val ) < 0 )
+ if( p_var->pf_cmp( p_var->choices.p_values[i], *p_val ) < 0 )
{
break;
}
p_var->i_default++;
}
- INSERT_ELEM( p_var->pp_choices, p_var->i_choices, i, *p_val );
- p_var->pf_dup( &p_var->pp_choices[i] );
+ INSERT_ELEM( p_var->choices.p_values, p_var->choices.i_count,
+ i, *p_val );
+ p_var->pf_dup( &p_var->choices.p_values[i] );
CheckValue( p_var, &p_var->val );
break;
case VLC_VAR_DELCHOICE:
/* FIXME: the list is sorted, dude. Use something cleverer. */
- for( i = 0 ; i < p_var->i_choices ; i++ )
+ for( i = 0 ; i < p_var->choices.i_count ; i++ )
{
- if( p_var->pf_cmp( p_var->pp_choices[i], *p_val ) == 0 )
+ if( p_var->pf_cmp( p_var->choices.p_values[i], *p_val ) == 0 )
{
break;
}
}
- if( i == p_var->i_choices )
+ if( i == p_var->choices.i_count )
{
/* Not found */
vlc_mutex_unlock( &p_this->var_lock );
p_var->i_default = -1;
}
- p_var->pf_free( &p_var->pp_choices[i] );
- REMOVE_ELEM( p_var->pp_choices, p_var->i_choices, i );
+ p_var->pf_free( &p_var->choices.p_values[i] );
+ REMOVE_ELEM( p_var->choices.p_values, p_var->choices.i_count, i );
CheckValue( p_var, &p_var->val );
break;
case VLC_VAR_SETDEFAULT:
/* FIXME: the list is sorted, dude. Use something cleverer. */
- for( i = 0 ; i < p_var->i_choices ; i++ )
+ for( i = 0 ; i < p_var->choices.i_count ; i++ )
{
- if( p_var->pf_cmp( p_var->pp_choices[i], *p_val ) == 0 )
+ if( p_var->pf_cmp( p_var->choices.p_values[i], *p_val ) == 0 )
{
break;
}
}
- if( i == p_var->i_choices )
+ if( i == p_var->choices.i_count )
{
/* Not found */
break;
break;
case VLC_VAR_GETLIST:
- p_val->p_address = malloc( (1 + p_var->i_choices)
- * sizeof(vlc_value_t) );
- ((vlc_value_t*)p_val->p_address)[0].i_int = p_var->i_choices;
- for( i = 0 ; i < p_var->i_choices ; i++ )
+ p_val->p_list = malloc( sizeof(vlc_list_t) );
+ p_val->p_list->p_values = malloc( p_var->choices.i_count
+ * sizeof(vlc_value_t) );
+ p_val->p_list->i_count = p_var->choices.i_count;
+ for( i = 0 ; i < p_var->choices.i_count ; i++ )
{
- ((vlc_value_t*)p_val->p_address)[i+1] = p_var->pp_choices[i];
- p_var->pf_dup( &((vlc_value_t*)p_val->p_address)[i+1] );
+ p_val->p_list->p_values[i] = p_var->choices.p_values[i];
+ p_var->pf_dup( &p_val->p_list->p_values[i] );
}
break;
case VLC_VAR_FREELIST:
- for( i = ((vlc_value_t*)p_val->p_address)[0].i_int ; i-- ; )
+ for( i = p_val->p_list->i_count ; i-- ; )
{
- p_var->pf_free( &((vlc_value_t*)p_val->p_address)[i+1] );
+ p_var->pf_free( &p_val->p_list->p_values[i] );
}
- free( p_val->p_address );
+ free( p_val->p_list->p_values );
+ free( p_val->p_list );
break;
default:
static void CheckValue ( variable_t *p_var, vlc_value_t *p_val )
{
/* Check that our variable is in the list */
- if( p_var->i_type & VLC_VAR_HASCHOICE && p_var->i_choices )
+ if( p_var->i_type & VLC_VAR_HASCHOICE && p_var->choices.i_count )
{
int i;
/* FIXME: the list is sorted, dude. Use something cleverer. */
- for( i = p_var->i_choices ; i-- ; )
+ for( i = p_var->choices.i_count ; i-- ; )
{
- if( p_var->pf_cmp( *p_val, p_var->pp_choices[i] ) == 0 )
+ if( p_var->pf_cmp( *p_val, p_var->choices.p_values[i] ) == 0 )
{
break;
}
{
/* Free the old variable, get the new one, dup it */
p_var->pf_free( p_val );
- *p_val = p_var->pp_choices[p_var->i_default >= 0
- ? p_var->i_default : 0 ];
+ *p_val = p_var->choices.p_values[p_var->i_default >= 0
+ ? p_var->i_default : 0 ];
p_var->pf_dup( p_val );
}
}
break;
}
}
-