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";
215 case VLC_OBJECT_STATS:
216 i_size = sizeof( stats_handler_t );
217 psz_type = "statistics";
221 ? i_type > (int)sizeof(vlc_object_t)
222 ? i_type : (int)sizeof(vlc_object_t)
223 : (int)sizeof(vlc_object_t);
224 i_type = VLC_OBJECT_GENERIC;
225 psz_type = "generic";
229 if( i_type == VLC_OBJECT_ROOT )
235 p_new = malloc( i_size );
236 if( !p_new ) return NULL;
237 memset( p_new, 0, i_size );
240 p_new->i_object_type = i_type;
241 p_new->psz_object_type = psz_type;
243 p_new->psz_object_name = NULL;
245 p_new->b_die = VLC_FALSE;
246 p_new->b_error = VLC_FALSE;
247 p_new->b_dead = VLC_FALSE;
248 p_new->b_attached = VLC_FALSE;
249 p_new->b_force = VLC_FALSE;
252 p_new->p_vars = (variable_t *)malloc( 16 * sizeof( variable_t ) );
256 if( i_type != VLC_OBJECT_ROOT )
261 if( i_type == VLC_OBJECT_ROOT )
263 /* If i_type is root, then p_new is actually p_libvlc */
264 p_new->p_libvlc = (libvlc_t*)p_new;
267 p_new->p_libvlc->i_counter = 0;
268 p_new->i_object_id = 0;
270 p_new->p_libvlc->i_objects = 1;
271 p_new->p_libvlc->pp_objects = malloc( sizeof(vlc_object_t *) );
272 p_new->p_libvlc->pp_objects[0] = p_new;
273 p_new->b_attached = VLC_TRUE;
277 p_new->p_libvlc = p_this->p_libvlc;
278 p_new->p_vlc = ( i_type == VLC_OBJECT_VLC ) ? (vlc_t*)p_new
281 vlc_mutex_lock( &structure_lock );
283 p_new->p_libvlc->i_counter++;
284 p_new->i_object_id = p_new->p_libvlc->i_counter;
286 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
287 * useless to try and recover anything if pp_objects gets smashed. */
288 INSERT_ELEM( p_new->p_libvlc->pp_objects,
289 p_new->p_libvlc->i_objects,
290 p_new->p_libvlc->i_objects,
293 vlc_mutex_unlock( &structure_lock );
296 p_new->i_refcount = 0;
297 p_new->p_parent = NULL;
298 p_new->pp_children = NULL;
299 p_new->i_children = 0;
301 p_new->p_private = NULL;
303 /* Initialize mutexes and condvars */
304 vlc_mutex_init( p_new, &p_new->object_lock );
305 vlc_cond_init( p_new, &p_new->object_wait );
306 vlc_mutex_init( p_new, &p_new->var_lock );
308 if( i_type == VLC_OBJECT_ROOT )
310 vlc_mutex_init( p_new, &structure_lock );
312 var_Create( p_new, "list", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
313 var_AddCallback( p_new, "list", DumpCommand, NULL );
314 var_Create( p_new, "tree", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
315 var_AddCallback( p_new, "tree", DumpCommand, NULL );
322 ****************************************************************************
323 * Destroy a vlc object
325 * This function destroys an object that has been previously allocated with
326 * vlc_object_create. The object's refcount must be zero and it must not be
327 * attached to other objects in any way.
328 *****************************************************************************/
329 void __vlc_object_destroy( vlc_object_t *p_this )
333 if( p_this->i_children )
335 msg_Err( p_this, "cannot delete object (%i, %s) with children" ,
336 p_this->i_object_id, p_this->psz_object_name );
340 if( p_this->p_parent )
342 msg_Err( p_this, "cannot delete object (%i, %s) with a parent",
343 p_this->i_object_id, p_this->psz_object_name );
347 while( p_this->i_refcount )
351 /* Don't warn immediately ... 100ms seems OK */
355 "refcount is %i, delaying before deletion (id=%d,type=%d)",
356 p_this->i_refcount, p_this->i_object_id,
357 p_this->i_object_type );
359 else if( i_delay == 10 )
362 "refcount is %i, delaying again (id=%d,type=%d)",
363 p_this->i_refcount, p_this->i_object_id,
364 p_this->i_object_type );
366 else if( i_delay == 20 )
369 "we waited too long, cancelling destruction (id=%d,type=%d)",
370 p_this->i_object_id, p_this->i_object_type );
377 /* Destroy the associated variables, starting from the end so that
378 * no memmove calls have to be done. */
379 while( p_this->i_vars )
381 var_Destroy( p_this, p_this->p_vars[p_this->i_vars - 1].psz_name );
384 free( p_this->p_vars );
385 vlc_mutex_destroy( &p_this->var_lock );
387 if( p_this->i_object_type == VLC_OBJECT_ROOT )
389 /* We are the root object ... no need to lock. */
390 free( p_this->p_libvlc->pp_objects );
391 p_this->p_libvlc->pp_objects = NULL;
392 p_this->p_libvlc->i_objects--;
394 vlc_mutex_destroy( &structure_lock );
400 vlc_mutex_lock( &structure_lock );
402 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
403 * useless to try and recover anything if pp_objects gets smashed. */
404 i_index = FindIndex( p_this, p_this->p_libvlc->pp_objects,
405 p_this->p_libvlc->i_objects );
406 REMOVE_ELEM( p_this->p_libvlc->pp_objects,
407 p_this->p_libvlc->i_objects, i_index );
409 vlc_mutex_unlock( &structure_lock );
412 vlc_mutex_destroy( &p_this->object_lock );
413 vlc_cond_destroy( &p_this->object_wait );
415 /* root is not dynamically allocated by vlc_object_create */
416 if( p_this->i_object_type != VLC_OBJECT_ROOT )
421 * find an object given its ID
423 * This function looks for the object whose i_object_id field is i_id. We
424 * use a dichotomy so that lookups are in log2(n).
425 *****************************************************************************/
426 void * __vlc_object_get( vlc_object_t *p_this, int i_id )
429 vlc_object_t **pp_objects;
431 vlc_mutex_lock( &structure_lock );
433 pp_objects = p_this->p_libvlc->pp_objects;
435 /* Perform our dichotomy */
436 for( i_max = p_this->p_libvlc->i_objects - 1 ; ; )
438 i_middle = i_max / 2;
440 if( pp_objects[i_middle]->i_object_id > i_id )
444 else if( pp_objects[i_middle]->i_object_id < i_id )
448 pp_objects += i_middle;
453 /* This happens when there are only two remaining objects */
454 if( pp_objects[i_middle+1]->i_object_id == i_id )
456 vlc_mutex_unlock( &structure_lock );
457 pp_objects[i_middle+1]->i_refcount++;
458 return pp_objects[i_middle+1];
465 vlc_mutex_unlock( &structure_lock );
466 pp_objects[i_middle]->i_refcount++;
467 return pp_objects[i_middle];
472 /* this means that i_max == i_middle, and since we have already
473 * tested pp_objects[i_middle]), p_found is properly set. */
478 vlc_mutex_unlock( &structure_lock );
483 ****************************************************************************
484 * find a typed object and increment its refcount
485 *****************************************************************************
486 * This function recursively looks for a given object type. i_mode can be one
487 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
488 *****************************************************************************/
489 void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
491 vlc_object_t *p_found;
493 vlc_mutex_lock( &structure_lock );
495 /* If we are of the requested type ourselves, don't look further */
496 if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
498 p_this->i_refcount++;
499 vlc_mutex_unlock( &structure_lock );
503 /* Otherwise, recursively look for the object */
504 if( (i_mode & 0x000f) == FIND_ANYWHERE )
506 vlc_object_t *p_root = p_this;
509 while( p_root->p_parent != NULL &&
510 p_root != VLC_OBJECT( p_this->p_vlc ) )
512 p_root = p_root->p_parent;
515 p_found = FindObject( p_root, i_type, (i_mode & ~0x000f)|FIND_CHILD );
516 if( p_found == NULL && p_root != VLC_OBJECT( p_this->p_vlc ) )
518 p_found = FindObject( VLC_OBJECT( p_this->p_vlc ),
519 i_type, (i_mode & ~0x000f)|FIND_CHILD );
524 p_found = FindObject( p_this, i_type, i_mode );
527 vlc_mutex_unlock( &structure_lock );
533 ****************************************************************************
534 * increment an object refcount
535 *****************************************************************************/
536 void __vlc_object_yield( vlc_object_t *p_this )
538 vlc_mutex_lock( &structure_lock );
539 p_this->i_refcount++;
540 vlc_mutex_unlock( &structure_lock );
544 ****************************************************************************
545 * decrement an object refcount
546 *****************************************************************************/
547 void __vlc_object_release( vlc_object_t *p_this )
549 vlc_mutex_lock( &structure_lock );
550 p_this->i_refcount--;
551 vlc_mutex_unlock( &structure_lock );
555 ****************************************************************************
556 * attach object to a parent object
557 *****************************************************************************
558 * This function sets p_this as a child of p_parent, and p_parent as a parent
559 * of p_this. This link can be undone using vlc_object_detach.
560 *****************************************************************************/
561 void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
563 vlc_mutex_lock( &structure_lock );
565 /* Attach the parent to its child */
566 p_this->p_parent = p_parent;
568 /* Attach the child to its parent */
569 INSERT_ELEM( p_parent->pp_children, p_parent->i_children,
570 p_parent->i_children, p_this );
572 /* Climb up the tree to see whether we are connected with the root */
573 if( p_parent->b_attached )
575 SetAttachment( p_this, VLC_TRUE );
578 vlc_mutex_unlock( &structure_lock );
582 ****************************************************************************
583 * detach object from its parent
584 *****************************************************************************
585 * This function removes all links between an object and its parent.
586 *****************************************************************************/
587 void __vlc_object_detach( vlc_object_t *p_this )
589 vlc_mutex_lock( &structure_lock );
590 if( !p_this->p_parent )
592 msg_Err( p_this, "object is not attached" );
593 vlc_mutex_unlock( &structure_lock );
597 /* Climb up the tree to see whether we are connected with the root */
598 if( p_this->p_parent->b_attached )
600 SetAttachment( p_this, VLC_FALSE );
603 DetachObject( p_this );
604 vlc_mutex_unlock( &structure_lock );
608 ****************************************************************************
609 * find a list typed objects and increment their refcount
610 *****************************************************************************
611 * This function recursively looks for a given object type. i_mode can be one
612 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
613 *****************************************************************************/
614 vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
617 vlc_object_t **pp_current, **pp_end;
618 int i_count = 0, i_index = 0;
620 vlc_mutex_lock( &structure_lock );
622 /* Look for the objects */
623 switch( i_mode & 0x000f )
626 pp_current = p_this->p_libvlc->pp_objects;
627 pp_end = pp_current + p_this->p_libvlc->i_objects;
629 for( ; pp_current < pp_end ; pp_current++ )
631 if( (*pp_current)->b_attached
632 && (*pp_current)->i_object_type == i_type )
638 p_list = NewList( i_count );
639 pp_current = p_this->p_libvlc->pp_objects;
641 for( ; pp_current < pp_end ; pp_current++ )
643 if( (*pp_current)->b_attached
644 && (*pp_current)->i_object_type == i_type )
646 ListReplace( p_list, *pp_current, i_index );
647 if( i_index < i_count ) i_index++;
653 i_count = CountChildren( p_this, i_type );
654 p_list = NewList( i_count );
656 /* Check allocation was successful */
657 if( p_list->i_count != i_count )
659 msg_Err( p_this, "list allocation failed!" );
665 ListChildren( p_list, p_this, i_type );
669 msg_Err( p_this, "unimplemented!" );
670 p_list = NewList( 0 );
674 vlc_mutex_unlock( &structure_lock );
679 /*****************************************************************************
680 * DumpCommand: print the current vlc structure
681 *****************************************************************************
682 * This function prints either an ASCII tree showing the connections between
683 * vlc objects, and additional information such as their refcount, thread ID,
684 * etc. (command "tree"), or the same data as a simple list (command "list").
685 *****************************************************************************/
686 static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
687 vlc_value_t oldval, vlc_value_t newval, void *p_data )
689 if( *psz_cmd == 't' )
691 char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
692 vlc_object_t *p_object;
694 if( *newval.psz_string )
696 p_object = vlc_object_get( p_this, atoi(newval.psz_string) );
705 p_object = p_this->p_vlc ? VLC_OBJECT(p_this->p_vlc) : p_this;
708 vlc_mutex_lock( &structure_lock );
711 DumpStructure( p_object, 0, psz_foo );
713 vlc_mutex_unlock( &structure_lock );
715 if( *newval.psz_string )
717 vlc_object_release( p_this );
720 else if( *psz_cmd == 'l' )
722 vlc_object_t **pp_current, **pp_end;
724 vlc_mutex_lock( &structure_lock );
726 pp_current = p_this->p_libvlc->pp_objects;
727 pp_end = pp_current + p_this->p_libvlc->i_objects;
729 for( ; pp_current < pp_end ; pp_current++ )
731 if( (*pp_current)->b_attached )
733 PrintObject( *pp_current, "" );
737 printf( " o %.8i %s (not attached)\n",
738 (*pp_current)->i_object_id,
739 (*pp_current)->psz_object_type );
743 vlc_mutex_unlock( &structure_lock );
749 /*****************************************************************************
750 * vlc_list_release: free a list previously allocated by vlc_list_find
751 *****************************************************************************
752 * This function decreases the refcount of all objects in the list and
754 *****************************************************************************/
755 void vlc_list_release( vlc_list_t *p_list )
759 for( i_index = 0; i_index < p_list->i_count; i_index++ )
761 vlc_mutex_lock( &structure_lock );
763 p_list->p_values[i_index].p_object->i_refcount--;
765 vlc_mutex_unlock( &structure_lock );
768 free( p_list->p_values );
772 /* Following functions are local */
774 /*****************************************************************************
775 * FindIndex: find the index of an object in an array of objects
776 *****************************************************************************
777 * This function assumes that p_this can be found in pp_objects. It will not
778 * crash if p_this cannot be found, but will return a wrong value. It is your
779 * duty to check the return value if you are not certain that the object could
781 *****************************************************************************/
782 static int FindIndex( vlc_object_t *p_this,
783 vlc_object_t **pp_objects, int i_count )
785 int i_middle = i_count / 2;
792 if( pp_objects[i_middle] == p_this )
802 /* We take advantage of the sorted array */
803 if( pp_objects[i_middle]->i_object_id < p_this->i_object_id )
805 return i_middle + FindIndex( p_this, pp_objects + i_middle,
806 i_count - i_middle );
810 return FindIndex( p_this, pp_objects, i_middle );
814 static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
819 switch( i_mode & 0x000f )
822 p_tmp = p_this->p_parent;
825 if( p_tmp->i_object_type == i_type )
832 return FindObject( p_tmp, i_type, i_mode );
838 for( i = p_this->i_children; i--; )
840 p_tmp = p_this->pp_children[i];
841 if( p_tmp->i_object_type == i_type )
846 else if( p_tmp->i_children )
848 p_tmp = FindObject( p_tmp, i_type, i_mode );
858 /* Handled in vlc_object_find */
865 static void DetachObject( vlc_object_t *p_this )
867 vlc_object_t *p_parent = p_this->p_parent;
870 /* Remove p_this's parent */
871 p_this->p_parent = NULL;
873 /* Remove all of p_parent's children which are p_this */
874 for( i_index = p_parent->i_children ; i_index-- ; )
876 if( p_parent->pp_children[i_index] == p_this )
878 p_parent->i_children--;
879 for( i = i_index ; i < p_parent->i_children ; i++ )
881 p_parent->pp_children[i] = p_parent->pp_children[i+1];
886 if( p_parent->i_children )
888 p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children,
889 p_parent->i_children * sizeof(vlc_object_t *) );
893 free( p_parent->pp_children );
894 p_parent->pp_children = NULL;
898 /*****************************************************************************
899 * SetAttachment: recursively set the b_attached flag of a subtree.
900 *****************************************************************************
901 * This function is used by the attach and detach functions to propagate
902 * the b_attached flag in a subtree.
903 *****************************************************************************/
904 static void SetAttachment( vlc_object_t *p_this, vlc_bool_t b_attached )
908 for( i_index = p_this->i_children ; i_index-- ; )
910 SetAttachment( p_this->pp_children[i_index], b_attached );
913 p_this->b_attached = b_attached;
916 static void PrintObject( vlc_object_t *p_this, const char *psz_prefix )
918 char psz_children[20], psz_refcount[20], psz_thread[20], psz_name[50];
921 if( p_this->psz_object_name )
923 snprintf( psz_name, 50, " \"%s\"", p_this->psz_object_name );
928 psz_children[0] = '\0';
929 switch( p_this->i_children )
934 strcpy( psz_children, ", 1 child" );
937 snprintf( psz_children, 20,
938 ", %i children", p_this->i_children );
939 psz_children[19] = '\0';
943 psz_refcount[0] = '\0';
944 if( p_this->i_refcount )
946 snprintf( psz_refcount, 20, ", refcount %i", p_this->i_refcount );
947 psz_refcount[19] = '\0';
950 psz_thread[0] = '\0';
951 if( p_this->b_thread )
953 snprintf( psz_thread, 20, " (thread %d)", (int)p_this->thread_id );
954 psz_thread[19] = '\0';
957 printf( " %so %.8i %s%s%s%s%s\n", psz_prefix,
958 p_this->i_object_id, p_this->psz_object_type,
959 psz_name, psz_thread, psz_refcount, psz_children );
962 static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
965 char i_back = psz_foo[i_level];
966 psz_foo[i_level] = '\0';
968 PrintObject( p_this, psz_foo );
970 psz_foo[i_level] = i_back;
972 if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH )
974 msg_Warn( p_this, "structure tree is too deep" );
978 for( i = 0 ; i < p_this->i_children ; i++ )
982 psz_foo[i_level-1] = ' ';
984 if( psz_foo[i_level-2] == '`' )
986 psz_foo[i_level-2] = ' ';
990 if( i == p_this->i_children - 1 )
992 psz_foo[i_level] = '`';
996 psz_foo[i_level] = '|';
999 psz_foo[i_level+1] = '-';
1000 psz_foo[i_level+2] = '\0';
1002 DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo );
1006 static vlc_list_t * NewList( int i_count )
1008 vlc_list_t * p_list = (vlc_list_t *)malloc( sizeof( vlc_list_t ) );
1009 if( p_list == NULL )
1014 p_list->i_count = i_count;
1018 p_list->p_values = NULL;
1022 p_list->p_values = malloc( i_count * sizeof( vlc_value_t ) );
1023 if( p_list->p_values == NULL )
1025 p_list->i_count = 0;
1032 static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
1035 if( p_list == NULL || i_index >= p_list->i_count )
1040 p_object->i_refcount++;
1042 p_list->p_values[i_index].p_object = p_object;
1047 /*static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
1049 if( p_list == NULL )
1054 p_list->p_values = realloc( p_list->p_values, (p_list->i_count + 1)
1055 * sizeof( vlc_value_t ) );
1056 if( p_list->p_values == NULL )
1058 p_list->i_count = 0;
1062 p_object->i_refcount++;
1064 p_list->p_values[p_list->i_count].p_object = p_object;
1070 static int CountChildren( vlc_object_t *p_this, int i_type )
1072 vlc_object_t *p_tmp;
1075 for( i = 0; i < p_this->i_children; i++ )
1077 p_tmp = p_this->pp_children[i];
1079 if( p_tmp->i_object_type == i_type )
1084 if( p_tmp->i_children )
1086 i_count += CountChildren( p_tmp, i_type );
1093 static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type )
1095 vlc_object_t *p_tmp;
1098 for( i = 0; i < p_this->i_children; i++ )
1100 p_tmp = p_this->pp_children[i];
1102 if( p_tmp->i_object_type == i_type )
1104 ListReplace( p_list, p_tmp, p_list->i_count++ );
1107 if( p_tmp->i_children )
1109 ListChildren( p_list, p_tmp, i_type );