1 /*****************************************************************************
2 * objects.c: vlc_object_t handling
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
26 * This file contains the functions to handle the vlc_object_t type
30 /*****************************************************************************
32 *****************************************************************************/
34 #include <vlc/input.h>
37 # include <stdlib.h> /* realloc() */
40 #include "vlc_video.h"
41 #include "video_output.h"
44 #include "audio_output.h"
45 #include "aout_internal.h"
46 #include "stream_output.h"
48 #include "vlc_playlist.h"
49 #include "vlc_interface.h"
50 #include "vlc_codec.h"
51 #include "vlc_filter.h"
53 #include "vlc_httpd.h"
60 /*****************************************************************************
62 *****************************************************************************/
63 static int DumpCommand( vlc_object_t *, char const *,
64 vlc_value_t, vlc_value_t, void * );
66 static vlc_object_t * FindObject ( vlc_object_t *, int, int );
67 static void DetachObject ( vlc_object_t * );
68 static void PrintObject ( vlc_object_t *, const char * );
69 static void DumpStructure ( vlc_object_t *, int, char * );
70 static int FindIndex ( vlc_object_t *, vlc_object_t **, int );
71 static void SetAttachment ( vlc_object_t *, vlc_bool_t );
73 static vlc_list_t * NewList ( int );
74 static void ListReplace ( vlc_list_t *, vlc_object_t *, int );
75 /*static void ListAppend ( vlc_list_t *, vlc_object_t * );*/
76 static int CountChildren ( vlc_object_t *, int );
77 static void ListChildren ( vlc_list_t *, vlc_object_t *, int );
79 /*****************************************************************************
80 * Local structure lock
81 *****************************************************************************/
82 static vlc_mutex_t structure_lock;
84 /*****************************************************************************
85 * vlc_object_create: initialize a vlc object
86 *****************************************************************************
87 * This function allocates memory for a vlc object and initializes it. If
88 * i_type is not a known value such as VLC_OBJECT_ROOT, VLC_OBJECT_VOUT and
89 * so on, vlc_object_create will use its value for the object size.
90 *****************************************************************************/
93 * Initialize a vlc object
95 * This function allocates memory for a vlc object and initializes it. If
96 * i_type is not a known value such as VLC_OBJECT_ROOT, VLC_OBJECT_VOUT and
97 * so on, vlc_object_create will use its value for the object size.
99 void * __vlc_object_create( vlc_object_t *p_this, int i_type )
101 vlc_object_t * p_new;
107 case VLC_OBJECT_ROOT:
108 i_size = sizeof(libvlc_t);
112 i_size = sizeof(vlc_t);
115 case VLC_OBJECT_MODULE:
116 i_size = sizeof(module_t);
119 case VLC_OBJECT_INTF:
120 i_size = sizeof(intf_thread_t);
121 psz_type = "interface";
123 case VLC_OBJECT_DIALOGS:
124 i_size = sizeof(intf_thread_t);
125 psz_type = "dialogs provider";
127 case VLC_OBJECT_PLAYLIST:
128 i_size = sizeof(playlist_t);
129 psz_type = "playlist";
132 i_size = sizeof(services_discovery_t);
133 psz_type = "services discovery";
135 case VLC_OBJECT_INPUT:
136 i_size = sizeof(input_thread_t);
139 case VLC_OBJECT_DEMUX:
140 i_size = sizeof(demux_t);
143 case VLC_OBJECT_STREAM:
144 i_size = sizeof(stream_t);
147 case VLC_OBJECT_ACCESS:
148 i_size = sizeof(access_t);
151 case VLC_OBJECT_DECODER:
152 i_size = sizeof(decoder_t);
153 psz_type = "decoder";
155 case VLC_OBJECT_PACKETIZER:
156 i_size = sizeof(decoder_t);
157 psz_type = "packetizer";
159 case VLC_OBJECT_ENCODER:
160 i_size = sizeof(encoder_t);
161 psz_type = "encoder";
163 case VLC_OBJECT_FILTER:
164 i_size = sizeof(filter_t);
167 case VLC_OBJECT_VOUT:
168 i_size = sizeof(vout_thread_t);
169 psz_type = "video output";
172 i_size = sizeof(spu_t);
173 psz_type = "subpicture unit";
175 case VLC_OBJECT_AOUT:
176 i_size = sizeof(aout_instance_t);
177 psz_type = "audio output";
179 case VLC_OBJECT_SOUT:
180 i_size = sizeof(sout_instance_t);
181 psz_type = "stream output";
183 case VLC_OBJECT_HTTPD:
184 i_size = sizeof( httpd_t );
185 psz_type = "http daemon";
188 i_size = sizeof( vlm_t );
189 psz_type = "vlm dameon";
192 i_size = sizeof( vod_t );
193 psz_type = "vod server";
196 i_size = sizeof( tls_t );
200 i_size = sizeof( xml_t );
203 case VLC_OBJECT_OPENGL:
204 i_size = sizeof( vout_thread_t );
205 psz_type = "opengl provider";
207 case VLC_OBJECT_ANNOUNCE:
208 i_size = sizeof( announce_handler_t );
209 psz_type = "announce handler";
211 case VLC_OBJECT_OSDMENU:
212 i_size = sizeof( osd_menu_t );
213 psz_type = "osd menu";
217 ? i_type > (int)sizeof(vlc_object_t)
218 ? i_type : (int)sizeof(vlc_object_t)
219 : (int)sizeof(vlc_object_t);
220 i_type = VLC_OBJECT_GENERIC;
221 psz_type = "generic";
225 if( i_type == VLC_OBJECT_ROOT )
231 p_new = malloc( i_size );
232 if( !p_new ) return NULL;
233 memset( p_new, 0, i_size );
236 p_new->i_object_type = i_type;
237 p_new->psz_object_type = psz_type;
239 p_new->psz_object_name = NULL;
241 p_new->b_die = VLC_FALSE;
242 p_new->b_error = VLC_FALSE;
243 p_new->b_dead = VLC_FALSE;
244 p_new->b_attached = VLC_FALSE;
245 p_new->b_force = VLC_FALSE;
248 p_new->p_vars = (variable_t *)malloc( 16 * sizeof( variable_t ) );
252 if( i_type != VLC_OBJECT_ROOT )
257 if( i_type == VLC_OBJECT_ROOT )
259 /* If i_type is root, then p_new is actually p_libvlc */
260 p_new->p_libvlc = (libvlc_t*)p_new;
263 p_new->p_libvlc->i_counter = 0;
264 p_new->i_object_id = 0;
266 p_new->p_libvlc->i_objects = 1;
267 p_new->p_libvlc->pp_objects = malloc( sizeof(vlc_object_t *) );
268 p_new->p_libvlc->pp_objects[0] = p_new;
269 p_new->b_attached = VLC_TRUE;
273 p_new->p_libvlc = p_this->p_libvlc;
274 p_new->p_vlc = ( i_type == VLC_OBJECT_VLC ) ? (vlc_t*)p_new
277 vlc_mutex_lock( &structure_lock );
279 p_new->p_libvlc->i_counter++;
280 p_new->i_object_id = p_new->p_libvlc->i_counter;
282 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
283 * useless to try and recover anything if pp_objects gets smashed. */
284 INSERT_ELEM( p_new->p_libvlc->pp_objects,
285 p_new->p_libvlc->i_objects,
286 p_new->p_libvlc->i_objects,
289 vlc_mutex_unlock( &structure_lock );
292 p_new->i_refcount = 0;
293 p_new->p_parent = NULL;
294 p_new->pp_children = NULL;
295 p_new->i_children = 0;
297 p_new->p_private = NULL;
299 /* Initialize mutexes and condvars */
300 vlc_mutex_init( p_new, &p_new->object_lock );
301 vlc_cond_init( p_new, &p_new->object_wait );
302 vlc_mutex_init( p_new, &p_new->var_lock );
304 if( i_type == VLC_OBJECT_ROOT )
306 vlc_mutex_init( p_new, &structure_lock );
308 var_Create( p_new, "list", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
309 var_AddCallback( p_new, "list", DumpCommand, NULL );
310 var_Create( p_new, "tree", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
311 var_AddCallback( p_new, "tree", DumpCommand, NULL );
318 ****************************************************************************
319 * Destroy a vlc object
321 * This function destroys an object that has been previously allocated with
322 * vlc_object_create. The object's refcount must be zero and it must not be
323 * attached to other objects in any way.
324 *****************************************************************************/
325 void __vlc_object_destroy( vlc_object_t *p_this )
329 if( p_this->i_children )
331 msg_Err( p_this, "cannot delete object (%i, %s) with children" ,
332 p_this->i_object_id, p_this->psz_object_name );
336 if( p_this->p_parent )
338 msg_Err( p_this, "cannot delete object (%i, %s) with a parent",
339 p_this->i_object_id, p_this->psz_object_name );
343 while( p_this->i_refcount )
347 /* Don't warn immediately ... 100ms seems OK */
351 "refcount is %i, delaying before deletion (id=%d,type=%d)",
352 p_this->i_refcount, p_this->i_object_id,
353 p_this->i_object_type );
355 else if( i_delay == 10 )
358 "refcount is %i, delaying again (id=%d,type=%d)",
359 p_this->i_refcount, p_this->i_object_id,
360 p_this->i_object_type );
362 else if( i_delay == 20 )
365 "we waited too long, cancelling destruction (id=%d,type=%d)",
366 p_this->i_object_id, p_this->i_object_type );
373 /* Destroy the associated variables, starting from the end so that
374 * no memmove calls have to be done. */
375 while( p_this->i_vars )
377 var_Destroy( p_this, p_this->p_vars[p_this->i_vars - 1].psz_name );
380 free( p_this->p_vars );
381 vlc_mutex_destroy( &p_this->var_lock );
383 if( p_this->i_object_type == VLC_OBJECT_ROOT )
385 /* We are the root object ... no need to lock. */
386 free( p_this->p_libvlc->pp_objects );
387 p_this->p_libvlc->pp_objects = NULL;
388 p_this->p_libvlc->i_objects--;
390 vlc_mutex_destroy( &structure_lock );
396 vlc_mutex_lock( &structure_lock );
398 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
399 * useless to try and recover anything if pp_objects gets smashed. */
400 i_index = FindIndex( p_this, p_this->p_libvlc->pp_objects,
401 p_this->p_libvlc->i_objects );
402 REMOVE_ELEM( p_this->p_libvlc->pp_objects,
403 p_this->p_libvlc->i_objects, i_index );
405 vlc_mutex_unlock( &structure_lock );
408 vlc_mutex_destroy( &p_this->object_lock );
409 vlc_cond_destroy( &p_this->object_wait );
411 /* root is not dynamically allocated by vlc_object_create */
412 if( p_this->i_object_type != VLC_OBJECT_ROOT )
417 * find an object given its ID
419 * This function looks for the object whose i_object_id field is i_id. We
420 * use a dichotomy so that lookups are in log2(n).
421 *****************************************************************************/
422 void * __vlc_object_get( vlc_object_t *p_this, int i_id )
425 vlc_object_t **pp_objects;
427 vlc_mutex_lock( &structure_lock );
429 pp_objects = p_this->p_libvlc->pp_objects;
431 /* Perform our dichotomy */
432 for( i_max = p_this->p_libvlc->i_objects - 1 ; ; )
434 i_middle = i_max / 2;
436 if( pp_objects[i_middle]->i_object_id > i_id )
440 else if( pp_objects[i_middle]->i_object_id < i_id )
444 pp_objects += i_middle;
449 /* This happens when there are only two remaining objects */
450 if( pp_objects[i_middle+1]->i_object_id == i_id )
452 vlc_mutex_unlock( &structure_lock );
453 pp_objects[i_middle+1]->i_refcount++;
454 return pp_objects[i_middle+1];
461 vlc_mutex_unlock( &structure_lock );
462 pp_objects[i_middle]->i_refcount++;
463 return pp_objects[i_middle];
468 /* this means that i_max == i_middle, and since we have already
469 * tested pp_objects[i_middle]), p_found is properly set. */
474 vlc_mutex_unlock( &structure_lock );
479 ****************************************************************************
480 * find a typed object and increment its refcount
481 *****************************************************************************
482 * This function recursively looks for a given object type. i_mode can be one
483 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
484 *****************************************************************************/
485 void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
487 vlc_object_t *p_found;
489 vlc_mutex_lock( &structure_lock );
491 /* If we are of the requested type ourselves, don't look further */
492 if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
494 p_this->i_refcount++;
495 vlc_mutex_unlock( &structure_lock );
499 /* Otherwise, recursively look for the object */
500 if( (i_mode & 0x000f) == FIND_ANYWHERE )
502 vlc_object_t *p_root = p_this;
505 while( p_root->p_parent != NULL &&
506 p_root != VLC_OBJECT( p_this->p_vlc ) )
508 p_root = p_root->p_parent;
511 p_found = FindObject( p_root, i_type, (i_mode & ~0x000f)|FIND_CHILD );
512 if( p_found == NULL && p_root != VLC_OBJECT( p_this->p_vlc ) )
514 p_found = FindObject( VLC_OBJECT( p_this->p_vlc ),
515 i_type, (i_mode & ~0x000f)|FIND_CHILD );
520 p_found = FindObject( p_this, i_type, i_mode );
523 vlc_mutex_unlock( &structure_lock );
529 ****************************************************************************
530 * increment an object refcount
531 *****************************************************************************/
532 void __vlc_object_yield( vlc_object_t *p_this )
534 vlc_mutex_lock( &structure_lock );
535 p_this->i_refcount++;
536 vlc_mutex_unlock( &structure_lock );
540 ****************************************************************************
541 * decrement an object refcount
542 *****************************************************************************/
543 void __vlc_object_release( vlc_object_t *p_this )
545 vlc_mutex_lock( &structure_lock );
546 p_this->i_refcount--;
547 vlc_mutex_unlock( &structure_lock );
551 ****************************************************************************
552 * attach object to a parent object
553 *****************************************************************************
554 * This function sets p_this as a child of p_parent, and p_parent as a parent
555 * of p_this. This link can be undone using vlc_object_detach.
556 *****************************************************************************/
557 void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
559 vlc_mutex_lock( &structure_lock );
561 /* Attach the parent to its child */
562 p_this->p_parent = p_parent;
564 /* Attach the child to its parent */
565 INSERT_ELEM( p_parent->pp_children, p_parent->i_children,
566 p_parent->i_children, p_this );
568 /* Climb up the tree to see whether we are connected with the root */
569 if( p_parent->b_attached )
571 SetAttachment( p_this, VLC_TRUE );
574 vlc_mutex_unlock( &structure_lock );
578 ****************************************************************************
579 * detach object from its parent
580 *****************************************************************************
581 * This function removes all links between an object and its parent.
582 *****************************************************************************/
583 void __vlc_object_detach( vlc_object_t *p_this )
585 vlc_mutex_lock( &structure_lock );
586 if( !p_this->p_parent )
588 msg_Err( p_this, "object is not attached" );
589 vlc_mutex_unlock( &structure_lock );
593 /* Climb up the tree to see whether we are connected with the root */
594 if( p_this->p_parent->b_attached )
596 SetAttachment( p_this, VLC_FALSE );
599 DetachObject( p_this );
600 vlc_mutex_unlock( &structure_lock );
604 ****************************************************************************
605 * find a list typed objects and increment their refcount
606 *****************************************************************************
607 * This function recursively looks for a given object type. i_mode can be one
608 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
609 *****************************************************************************/
610 vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
613 vlc_object_t **pp_current, **pp_end;
614 int i_count = 0, i_index = 0;
616 vlc_mutex_lock( &structure_lock );
618 /* Look for the objects */
619 switch( i_mode & 0x000f )
622 pp_current = p_this->p_libvlc->pp_objects;
623 pp_end = pp_current + p_this->p_libvlc->i_objects;
625 for( ; pp_current < pp_end ; pp_current++ )
627 if( (*pp_current)->b_attached
628 && (*pp_current)->i_object_type == i_type )
634 p_list = NewList( i_count );
635 pp_current = p_this->p_libvlc->pp_objects;
637 for( ; pp_current < pp_end ; pp_current++ )
639 if( (*pp_current)->b_attached
640 && (*pp_current)->i_object_type == i_type )
642 ListReplace( p_list, *pp_current, i_index );
643 if( i_index < i_count ) i_index++;
649 i_count = CountChildren( p_this, i_type );
650 p_list = NewList( i_count );
652 /* Check allocation was successful */
653 if( p_list->i_count != i_count )
655 msg_Err( p_this, "list allocation failed!" );
661 ListChildren( p_list, p_this, i_type );
665 msg_Err( p_this, "unimplemented!" );
666 p_list = NewList( 0 );
670 vlc_mutex_unlock( &structure_lock );
675 /*****************************************************************************
676 * DumpCommand: print the current vlc structure
677 *****************************************************************************
678 * This function prints either an ASCII tree showing the connections between
679 * vlc objects, and additional information such as their refcount, thread ID,
680 * etc. (command "tree"), or the same data as a simple list (command "list").
681 *****************************************************************************/
682 static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
683 vlc_value_t oldval, vlc_value_t newval, void *p_data )
685 if( *psz_cmd == 't' )
687 char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
688 vlc_object_t *p_object;
690 if( *newval.psz_string )
692 p_object = vlc_object_get( p_this, atoi(newval.psz_string) );
701 p_object = p_this->p_vlc ? VLC_OBJECT(p_this->p_vlc) : p_this;
704 vlc_mutex_lock( &structure_lock );
707 DumpStructure( p_object, 0, psz_foo );
709 vlc_mutex_unlock( &structure_lock );
711 if( *newval.psz_string )
713 vlc_object_release( p_this );
716 else if( *psz_cmd == 'l' )
718 vlc_object_t **pp_current, **pp_end;
720 vlc_mutex_lock( &structure_lock );
722 pp_current = p_this->p_libvlc->pp_objects;
723 pp_end = pp_current + p_this->p_libvlc->i_objects;
725 for( ; pp_current < pp_end ; pp_current++ )
727 if( (*pp_current)->b_attached )
729 PrintObject( *pp_current, "" );
733 printf( " o %.8i %s (not attached)\n",
734 (*pp_current)->i_object_id,
735 (*pp_current)->psz_object_type );
739 vlc_mutex_unlock( &structure_lock );
745 /*****************************************************************************
746 * vlc_list_release: free a list previously allocated by vlc_list_find
747 *****************************************************************************
748 * This function decreases the refcount of all objects in the list and
750 *****************************************************************************/
751 void vlc_list_release( vlc_list_t *p_list )
755 for( i_index = 0; i_index < p_list->i_count; i_index++ )
757 vlc_mutex_lock( &structure_lock );
759 p_list->p_values[i_index].p_object->i_refcount--;
761 vlc_mutex_unlock( &structure_lock );
764 free( p_list->p_values );
768 /* Following functions are local */
770 /*****************************************************************************
771 * FindIndex: find the index of an object in an array of objects
772 *****************************************************************************
773 * This function assumes that p_this can be found in pp_objects. It will not
774 * crash if p_this cannot be found, but will return a wrong value. It is your
775 * duty to check the return value if you are not certain that the object could
777 *****************************************************************************/
778 static int FindIndex( vlc_object_t *p_this,
779 vlc_object_t **pp_objects, int i_count )
781 int i_middle = i_count / 2;
788 if( pp_objects[i_middle] == p_this )
798 /* We take advantage of the sorted array */
799 if( pp_objects[i_middle]->i_object_id < p_this->i_object_id )
801 return i_middle + FindIndex( p_this, pp_objects + i_middle,
802 i_count - i_middle );
806 return FindIndex( p_this, pp_objects, i_middle );
810 static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
815 switch( i_mode & 0x000f )
818 p_tmp = p_this->p_parent;
821 if( p_tmp->i_object_type == i_type )
828 return FindObject( p_tmp, i_type, i_mode );
834 for( i = p_this->i_children; i--; )
836 p_tmp = p_this->pp_children[i];
837 if( p_tmp->i_object_type == i_type )
842 else if( p_tmp->i_children )
844 p_tmp = FindObject( p_tmp, i_type, i_mode );
854 /* Handled in vlc_object_find */
861 static void DetachObject( vlc_object_t *p_this )
863 vlc_object_t *p_parent = p_this->p_parent;
866 /* Remove p_this's parent */
867 p_this->p_parent = NULL;
869 /* Remove all of p_parent's children which are p_this */
870 for( i_index = p_parent->i_children ; i_index-- ; )
872 if( p_parent->pp_children[i_index] == p_this )
874 p_parent->i_children--;
875 for( i = i_index ; i < p_parent->i_children ; i++ )
877 p_parent->pp_children[i] = p_parent->pp_children[i+1];
882 if( p_parent->i_children )
884 p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children,
885 p_parent->i_children * sizeof(vlc_object_t *) );
889 free( p_parent->pp_children );
890 p_parent->pp_children = NULL;
894 /*****************************************************************************
895 * SetAttachment: recursively set the b_attached flag of a subtree.
896 *****************************************************************************
897 * This function is used by the attach and detach functions to propagate
898 * the b_attached flag in a subtree.
899 *****************************************************************************/
900 static void SetAttachment( vlc_object_t *p_this, vlc_bool_t b_attached )
904 for( i_index = p_this->i_children ; i_index-- ; )
906 SetAttachment( p_this->pp_children[i_index], b_attached );
909 p_this->b_attached = b_attached;
912 static void PrintObject( vlc_object_t *p_this, const char *psz_prefix )
914 char psz_children[20], psz_refcount[20], psz_thread[20], psz_name[50];
917 if( p_this->psz_object_name )
919 snprintf( psz_name, 50, " \"%s\"", p_this->psz_object_name );
924 psz_children[0] = '\0';
925 switch( p_this->i_children )
930 strcpy( psz_children, ", 1 child" );
933 snprintf( psz_children, 20,
934 ", %i children", p_this->i_children );
935 psz_children[19] = '\0';
939 psz_refcount[0] = '\0';
940 if( p_this->i_refcount )
942 snprintf( psz_refcount, 20, ", refcount %i", p_this->i_refcount );
943 psz_refcount[19] = '\0';
946 psz_thread[0] = '\0';
947 if( p_this->b_thread )
949 snprintf( psz_thread, 20, " (thread %d)", (int)p_this->thread_id );
950 psz_thread[19] = '\0';
953 printf( " %so %.8i %s%s%s%s%s\n", psz_prefix,
954 p_this->i_object_id, p_this->psz_object_type,
955 psz_name, psz_thread, psz_refcount, psz_children );
958 static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
961 char i_back = psz_foo[i_level];
962 psz_foo[i_level] = '\0';
964 PrintObject( p_this, psz_foo );
966 psz_foo[i_level] = i_back;
968 if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH )
970 msg_Warn( p_this, "structure tree is too deep" );
974 for( i = 0 ; i < p_this->i_children ; i++ )
978 psz_foo[i_level-1] = ' ';
980 if( psz_foo[i_level-2] == '`' )
982 psz_foo[i_level-2] = ' ';
986 if( i == p_this->i_children - 1 )
988 psz_foo[i_level] = '`';
992 psz_foo[i_level] = '|';
995 psz_foo[i_level+1] = '-';
996 psz_foo[i_level+2] = '\0';
998 DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo );
1002 static vlc_list_t * NewList( int i_count )
1004 vlc_list_t * p_list = (vlc_list_t *)malloc( sizeof( vlc_list_t ) );
1005 if( p_list == NULL )
1010 p_list->i_count = i_count;
1014 p_list->p_values = NULL;
1018 p_list->p_values = malloc( i_count * sizeof( vlc_value_t ) );
1019 if( p_list->p_values == NULL )
1021 p_list->i_count = 0;
1028 static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
1031 if( p_list == NULL || i_index >= p_list->i_count )
1036 p_object->i_refcount++;
1038 p_list->p_values[i_index].p_object = p_object;
1043 /*static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
1045 if( p_list == NULL )
1050 p_list->p_values = realloc( p_list->p_values, (p_list->i_count + 1)
1051 * sizeof( vlc_value_t ) );
1052 if( p_list->p_values == NULL )
1054 p_list->i_count = 0;
1058 p_object->i_refcount++;
1060 p_list->p_values[p_list->i_count].p_object = p_object;
1066 static int CountChildren( vlc_object_t *p_this, int i_type )
1068 vlc_object_t *p_tmp;
1071 for( i = 0; i < p_this->i_children; i++ )
1073 p_tmp = p_this->pp_children[i];
1075 if( p_tmp->i_object_type == i_type )
1080 if( p_tmp->i_children )
1082 i_count += CountChildren( p_tmp, i_type );
1089 static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type )
1091 vlc_object_t *p_tmp;
1094 for( i = 0; i < p_this->i_children; i++ )
1096 p_tmp = p_this->pp_children[i];
1098 if( p_tmp->i_object_type == i_type )
1100 ListReplace( p_list, p_tmp, p_list->i_count++ );
1103 if( p_tmp->i_children )
1105 ListChildren( p_list, p_tmp, i_type );