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"
59 /*****************************************************************************
61 *****************************************************************************/
62 static int DumpCommand( vlc_object_t *, char const *,
63 vlc_value_t, vlc_value_t, void * );
65 static vlc_object_t * FindObject ( vlc_object_t *, int, int );
66 static void DetachObject ( vlc_object_t * );
67 static void PrintObject ( vlc_object_t *, const char * );
68 static void DumpStructure ( vlc_object_t *, int, char * );
69 static int FindIndex ( vlc_object_t *, vlc_object_t **, int );
70 static void SetAttachment ( vlc_object_t *, vlc_bool_t );
72 static vlc_list_t * NewList ( int );
73 static void ListReplace ( vlc_list_t *, vlc_object_t *, int );
74 /*static void ListAppend ( vlc_list_t *, vlc_object_t * );*/
75 static int CountChildren ( vlc_object_t *, int );
76 static void ListChildren ( vlc_list_t *, vlc_object_t *, int );
78 /*****************************************************************************
79 * Local structure lock
80 *****************************************************************************/
81 static vlc_mutex_t structure_lock;
83 /*****************************************************************************
84 * vlc_object_create: initialize a vlc object
85 *****************************************************************************
86 * This function allocates memory for a vlc object and initializes it. If
87 * i_type is not a known value such as VLC_OBJECT_ROOT, VLC_OBJECT_VOUT and
88 * so on, vlc_object_create will use its value for the object size.
89 *****************************************************************************/
92 * Initialize a vlc object
94 * This function allocates memory for a vlc object and initializes it. If
95 * i_type is not a known value such as VLC_OBJECT_ROOT, VLC_OBJECT_VOUT and
96 * so on, vlc_object_create will use its value for the object size.
98 void * __vlc_object_create( vlc_object_t *p_this, int i_type )
100 vlc_object_t * p_new;
106 case VLC_OBJECT_ROOT:
107 i_size = sizeof(libvlc_t);
111 i_size = sizeof(vlc_t);
114 case VLC_OBJECT_MODULE:
115 i_size = sizeof(module_t);
118 case VLC_OBJECT_INTF:
119 i_size = sizeof(intf_thread_t);
120 psz_type = "interface";
122 case VLC_OBJECT_DIALOGS:
123 i_size = sizeof(intf_thread_t);
124 psz_type = "dialogs provider";
126 case VLC_OBJECT_PLAYLIST:
127 i_size = sizeof(playlist_t);
128 psz_type = "playlist";
131 i_size = sizeof(services_discovery_t);
132 psz_type = "services discovery";
134 case VLC_OBJECT_INPUT:
135 i_size = sizeof(input_thread_t);
138 case VLC_OBJECT_DEMUX:
139 i_size = sizeof(demux_t);
142 case VLC_OBJECT_STREAM:
143 i_size = sizeof(stream_t);
146 case VLC_OBJECT_ACCESS:
147 i_size = sizeof(access_t);
150 case VLC_OBJECT_DECODER:
151 i_size = sizeof(decoder_t);
152 psz_type = "decoder";
154 case VLC_OBJECT_PACKETIZER:
155 i_size = sizeof(decoder_t);
156 psz_type = "packetizer";
158 case VLC_OBJECT_ENCODER:
159 i_size = sizeof(encoder_t);
160 psz_type = "encoder";
162 case VLC_OBJECT_FILTER:
163 i_size = sizeof(filter_t);
166 case VLC_OBJECT_VOUT:
167 i_size = sizeof(vout_thread_t);
168 psz_type = "video output";
171 i_size = sizeof(spu_t);
172 psz_type = "subpicture unit";
174 case VLC_OBJECT_AOUT:
175 i_size = sizeof(aout_instance_t);
176 psz_type = "audio output";
178 case VLC_OBJECT_SOUT:
179 i_size = sizeof(sout_instance_t);
180 psz_type = "stream output";
182 case VLC_OBJECT_HTTPD:
183 i_size = sizeof( httpd_t );
184 psz_type = "http daemon";
187 i_size = sizeof( vlm_t );
188 psz_type = "vlm dameon";
191 i_size = sizeof( vod_t );
192 psz_type = "vod server";
195 i_size = sizeof( tls_t );
199 i_size = sizeof( xml_t );
202 case VLC_OBJECT_OPENGL:
203 i_size = sizeof( vout_thread_t );
204 psz_type = "opengl provider";
206 case VLC_OBJECT_ANNOUNCE:
207 i_size = sizeof( announce_handler_t );
208 psz_type = "announce handler";
212 ? i_type > (int)sizeof(vlc_object_t)
213 ? i_type : (int)sizeof(vlc_object_t)
214 : (int)sizeof(vlc_object_t);
215 i_type = VLC_OBJECT_GENERIC;
216 psz_type = "generic";
220 if( i_type == VLC_OBJECT_ROOT )
226 p_new = malloc( i_size );
227 if( !p_new ) return NULL;
228 memset( p_new, 0, i_size );
231 p_new->i_object_type = i_type;
232 p_new->psz_object_type = psz_type;
234 p_new->psz_object_name = NULL;
236 p_new->b_die = VLC_FALSE;
237 p_new->b_error = VLC_FALSE;
238 p_new->b_dead = VLC_FALSE;
239 p_new->b_attached = VLC_FALSE;
240 p_new->b_force = VLC_FALSE;
243 p_new->p_vars = (variable_t *)malloc( 16 * sizeof( variable_t ) );
247 if( i_type != VLC_OBJECT_ROOT )
252 if( i_type == VLC_OBJECT_ROOT )
254 /* If i_type is root, then p_new is actually p_libvlc */
255 p_new->p_libvlc = (libvlc_t*)p_new;
258 p_new->p_libvlc->i_counter = 0;
259 p_new->i_object_id = 0;
261 p_new->p_libvlc->i_objects = 1;
262 p_new->p_libvlc->pp_objects = malloc( sizeof(vlc_object_t *) );
263 p_new->p_libvlc->pp_objects[0] = p_new;
264 p_new->b_attached = VLC_TRUE;
268 p_new->p_libvlc = p_this->p_libvlc;
269 p_new->p_vlc = ( i_type == VLC_OBJECT_VLC ) ? (vlc_t*)p_new
272 vlc_mutex_lock( &structure_lock );
274 p_new->p_libvlc->i_counter++;
275 p_new->i_object_id = p_new->p_libvlc->i_counter;
277 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
278 * useless to try and recover anything if pp_objects gets smashed. */
279 INSERT_ELEM( p_new->p_libvlc->pp_objects,
280 p_new->p_libvlc->i_objects,
281 p_new->p_libvlc->i_objects,
284 vlc_mutex_unlock( &structure_lock );
287 p_new->i_refcount = 0;
288 p_new->p_parent = NULL;
289 p_new->pp_children = NULL;
290 p_new->i_children = 0;
292 p_new->p_private = NULL;
294 /* Initialize mutexes and condvars */
295 vlc_mutex_init( p_new, &p_new->object_lock );
296 vlc_cond_init( p_new, &p_new->object_wait );
297 vlc_mutex_init( p_new, &p_new->var_lock );
299 if( i_type == VLC_OBJECT_ROOT )
301 vlc_mutex_init( p_new, &structure_lock );
303 var_Create( p_new, "list", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
304 var_AddCallback( p_new, "list", DumpCommand, NULL );
305 var_Create( p_new, "tree", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
306 var_AddCallback( p_new, "tree", DumpCommand, NULL );
313 ****************************************************************************
314 * Destroy a vlc object
316 * This function destroys an object that has been previously allocated with
317 * vlc_object_create. The object's refcount must be zero and it must not be
318 * attached to other objects in any way.
319 *****************************************************************************/
320 void __vlc_object_destroy( vlc_object_t *p_this )
324 if( p_this->i_children )
326 msg_Err( p_this, "cannot delete object (%i, %s) with children" ,
327 p_this->i_object_id, p_this->psz_object_name );
331 if( p_this->p_parent )
333 msg_Err( p_this, "cannot delete object (%i, %s) with a parent",
334 p_this->i_object_id, p_this->psz_object_name );
338 while( p_this->i_refcount )
342 /* Don't warn immediately ... 100ms seems OK */
346 "refcount is %i, delaying before deletion (id=%d,type=%d)",
347 p_this->i_refcount, p_this->i_object_id,
348 p_this->i_object_type );
350 else if( i_delay == 10 )
353 "refcount is %i, delaying again (id=%d,type=%d)",
354 p_this->i_refcount, p_this->i_object_id,
355 p_this->i_object_type );
357 else if( i_delay == 20 )
360 "we waited too long, cancelling destruction (id=%d,type=%d)",
361 p_this->i_object_id, p_this->i_object_type );
368 /* Destroy the associated variables, starting from the end so that
369 * no memmove calls have to be done. */
370 while( p_this->i_vars )
372 var_Destroy( p_this, p_this->p_vars[p_this->i_vars - 1].psz_name );
375 free( p_this->p_vars );
376 vlc_mutex_destroy( &p_this->var_lock );
378 if( p_this->i_object_type == VLC_OBJECT_ROOT )
380 /* We are the root object ... no need to lock. */
381 free( p_this->p_libvlc->pp_objects );
382 p_this->p_libvlc->pp_objects = NULL;
383 p_this->p_libvlc->i_objects--;
385 vlc_mutex_destroy( &structure_lock );
391 vlc_mutex_lock( &structure_lock );
393 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
394 * useless to try and recover anything if pp_objects gets smashed. */
395 i_index = FindIndex( p_this, p_this->p_libvlc->pp_objects,
396 p_this->p_libvlc->i_objects );
397 REMOVE_ELEM( p_this->p_libvlc->pp_objects,
398 p_this->p_libvlc->i_objects, i_index );
400 vlc_mutex_unlock( &structure_lock );
403 vlc_mutex_destroy( &p_this->object_lock );
404 vlc_cond_destroy( &p_this->object_wait );
406 /* root is not dynamically allocated by vlc_object_create */
407 if( p_this->i_object_type != VLC_OBJECT_ROOT )
412 * find an object given its ID
414 * This function looks for the object whose i_object_id field is i_id. We
415 * use a dichotomy so that lookups are in log2(n).
416 *****************************************************************************/
417 void * __vlc_object_get( vlc_object_t *p_this, int i_id )
420 vlc_object_t **pp_objects;
422 vlc_mutex_lock( &structure_lock );
424 pp_objects = p_this->p_libvlc->pp_objects;
426 /* Perform our dichotomy */
427 for( i_max = p_this->p_libvlc->i_objects - 1 ; ; )
429 i_middle = i_max / 2;
431 if( pp_objects[i_middle]->i_object_id > i_id )
435 else if( pp_objects[i_middle]->i_object_id < i_id )
439 pp_objects += i_middle;
444 /* This happens when there are only two remaining objects */
445 if( pp_objects[i_middle+1]->i_object_id == i_id )
447 vlc_mutex_unlock( &structure_lock );
448 pp_objects[i_middle+1]->i_refcount++;
449 return pp_objects[i_middle+1];
456 vlc_mutex_unlock( &structure_lock );
457 pp_objects[i_middle]->i_refcount++;
458 return pp_objects[i_middle];
463 /* this means that i_max == i_middle, and since we have already
464 * tested pp_objects[i_middle]), p_found is properly set. */
469 vlc_mutex_unlock( &structure_lock );
474 ****************************************************************************
475 * find a typed object and increment its refcount
476 *****************************************************************************
477 * This function recursively looks for a given object type. i_mode can be one
478 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
479 *****************************************************************************/
480 void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
482 vlc_object_t *p_found;
484 vlc_mutex_lock( &structure_lock );
486 /* If we are of the requested type ourselves, don't look further */
487 if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
489 p_this->i_refcount++;
490 vlc_mutex_unlock( &structure_lock );
494 /* Otherwise, recursively look for the object */
495 if( (i_mode & 0x000f) == FIND_ANYWHERE )
497 vlc_object_t *p_root = p_this;
500 while( p_root->p_parent != NULL &&
501 p_root != VLC_OBJECT( p_this->p_vlc ) )
503 p_root = p_root->p_parent;
506 p_found = FindObject( p_root, i_type, (i_mode & ~0x000f)|FIND_CHILD );
507 if( p_found == NULL && p_root != VLC_OBJECT( p_this->p_vlc ) )
509 p_found = FindObject( VLC_OBJECT( p_this->p_vlc ),
510 i_type, (i_mode & ~0x000f)|FIND_CHILD );
515 p_found = FindObject( p_this, i_type, i_mode );
518 vlc_mutex_unlock( &structure_lock );
524 ****************************************************************************
525 * increment an object refcount
526 *****************************************************************************/
527 void __vlc_object_yield( vlc_object_t *p_this )
529 vlc_mutex_lock( &structure_lock );
530 p_this->i_refcount++;
531 vlc_mutex_unlock( &structure_lock );
535 ****************************************************************************
536 * decrement an object refcount
537 *****************************************************************************/
538 void __vlc_object_release( vlc_object_t *p_this )
540 vlc_mutex_lock( &structure_lock );
541 p_this->i_refcount--;
542 vlc_mutex_unlock( &structure_lock );
546 ****************************************************************************
547 * attach object to a parent object
548 *****************************************************************************
549 * This function sets p_this as a child of p_parent, and p_parent as a parent
550 * of p_this. This link can be undone using vlc_object_detach.
551 *****************************************************************************/
552 void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
554 vlc_mutex_lock( &structure_lock );
556 /* Attach the parent to its child */
557 p_this->p_parent = p_parent;
559 /* Attach the child to its parent */
560 INSERT_ELEM( p_parent->pp_children, p_parent->i_children,
561 p_parent->i_children, p_this );
563 /* Climb up the tree to see whether we are connected with the root */
564 if( p_parent->b_attached )
566 SetAttachment( p_this, VLC_TRUE );
569 vlc_mutex_unlock( &structure_lock );
573 ****************************************************************************
574 * detach object from its parent
575 *****************************************************************************
576 * This function removes all links between an object and its parent.
577 *****************************************************************************/
578 void __vlc_object_detach( vlc_object_t *p_this )
580 vlc_mutex_lock( &structure_lock );
581 if( !p_this->p_parent )
583 msg_Err( p_this, "object is not attached" );
584 vlc_mutex_unlock( &structure_lock );
588 /* Climb up the tree to see whether we are connected with the root */
589 if( p_this->p_parent->b_attached )
591 SetAttachment( p_this, VLC_FALSE );
594 DetachObject( p_this );
595 vlc_mutex_unlock( &structure_lock );
599 ****************************************************************************
600 * find a list typed objects and increment their refcount
601 *****************************************************************************
602 * This function recursively looks for a given object type. i_mode can be one
603 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
604 *****************************************************************************/
605 vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
608 vlc_object_t **pp_current, **pp_end;
609 int i_count = 0, i_index = 0;
611 vlc_mutex_lock( &structure_lock );
613 /* Look for the objects */
614 switch( i_mode & 0x000f )
617 pp_current = p_this->p_libvlc->pp_objects;
618 pp_end = pp_current + p_this->p_libvlc->i_objects;
620 for( ; pp_current < pp_end ; pp_current++ )
622 if( (*pp_current)->b_attached
623 && (*pp_current)->i_object_type == i_type )
629 p_list = NewList( i_count );
630 pp_current = p_this->p_libvlc->pp_objects;
632 for( ; pp_current < pp_end ; pp_current++ )
634 if( (*pp_current)->b_attached
635 && (*pp_current)->i_object_type == i_type )
637 ListReplace( p_list, *pp_current, i_index );
638 if( i_index < i_count ) i_index++;
644 i_count = CountChildren( p_this, i_type );
645 p_list = NewList( i_count );
647 /* Check allocation was successful */
648 if( p_list->i_count != i_count )
650 msg_Err( p_this, "list allocation failed!" );
656 ListChildren( p_list, p_this, i_type );
660 msg_Err( p_this, "unimplemented!" );
661 p_list = NewList( 0 );
665 vlc_mutex_unlock( &structure_lock );
670 /*****************************************************************************
671 * DumpCommand: print the current vlc structure
672 *****************************************************************************
673 * This function prints either an ASCII tree showing the connections between
674 * vlc objects, and additional information such as their refcount, thread ID,
675 * etc. (command "tree"), or the same data as a simple list (command "list").
676 *****************************************************************************/
677 static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
678 vlc_value_t oldval, vlc_value_t newval, void *p_data )
680 if( *psz_cmd == 't' )
682 char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
683 vlc_object_t *p_object;
685 if( *newval.psz_string )
687 p_object = vlc_object_get( p_this, atoi(newval.psz_string) );
696 p_object = p_this->p_vlc ? VLC_OBJECT(p_this->p_vlc) : p_this;
699 vlc_mutex_lock( &structure_lock );
702 DumpStructure( p_object, 0, psz_foo );
704 vlc_mutex_unlock( &structure_lock );
706 if( *newval.psz_string )
708 vlc_object_release( p_this );
711 else if( *psz_cmd == 'l' )
713 vlc_object_t **pp_current, **pp_end;
715 vlc_mutex_lock( &structure_lock );
717 pp_current = p_this->p_libvlc->pp_objects;
718 pp_end = pp_current + p_this->p_libvlc->i_objects;
720 for( ; pp_current < pp_end ; pp_current++ )
722 if( (*pp_current)->b_attached )
724 PrintObject( *pp_current, "" );
728 printf( " o %.8i %s (not attached)\n",
729 (*pp_current)->i_object_id,
730 (*pp_current)->psz_object_type );
734 vlc_mutex_unlock( &structure_lock );
740 /*****************************************************************************
741 * vlc_list_release: free a list previously allocated by vlc_list_find
742 *****************************************************************************
743 * This function decreases the refcount of all objects in the list and
745 *****************************************************************************/
746 void vlc_list_release( vlc_list_t *p_list )
750 for( i_index = 0; i_index < p_list->i_count; i_index++ )
752 vlc_mutex_lock( &structure_lock );
754 p_list->p_values[i_index].p_object->i_refcount--;
756 vlc_mutex_unlock( &structure_lock );
759 free( p_list->p_values );
763 /* Following functions are local */
765 /*****************************************************************************
766 * FindIndex: find the index of an object in an array of objects
767 *****************************************************************************
768 * This function assumes that p_this can be found in pp_objects. It will not
769 * crash if p_this cannot be found, but will return a wrong value. It is your
770 * duty to check the return value if you are not certain that the object could
772 *****************************************************************************/
773 static int FindIndex( vlc_object_t *p_this,
774 vlc_object_t **pp_objects, int i_count )
776 int i_middle = i_count / 2;
783 if( pp_objects[i_middle] == p_this )
793 /* We take advantage of the sorted array */
794 if( pp_objects[i_middle]->i_object_id < p_this->i_object_id )
796 return i_middle + FindIndex( p_this, pp_objects + i_middle,
797 i_count - i_middle );
801 return FindIndex( p_this, pp_objects, i_middle );
805 static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
810 switch( i_mode & 0x000f )
813 p_tmp = p_this->p_parent;
816 if( p_tmp->i_object_type == i_type )
823 return FindObject( p_tmp, i_type, i_mode );
829 for( i = p_this->i_children; i--; )
831 p_tmp = p_this->pp_children[i];
832 if( p_tmp->i_object_type == i_type )
837 else if( p_tmp->i_children )
839 p_tmp = FindObject( p_tmp, i_type, i_mode );
849 /* Handled in vlc_object_find */
856 static void DetachObject( vlc_object_t *p_this )
858 vlc_object_t *p_parent = p_this->p_parent;
861 /* Remove p_this's parent */
862 p_this->p_parent = NULL;
864 /* Remove all of p_parent's children which are p_this */
865 for( i_index = p_parent->i_children ; i_index-- ; )
867 if( p_parent->pp_children[i_index] == p_this )
869 p_parent->i_children--;
870 for( i = i_index ; i < p_parent->i_children ; i++ )
872 p_parent->pp_children[i] = p_parent->pp_children[i+1];
877 if( p_parent->i_children )
879 p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children,
880 p_parent->i_children * sizeof(vlc_object_t *) );
884 free( p_parent->pp_children );
885 p_parent->pp_children = NULL;
889 /*****************************************************************************
890 * SetAttachment: recursively set the b_attached flag of a subtree.
891 *****************************************************************************
892 * This function is used by the attach and detach functions to propagate
893 * the b_attached flag in a subtree.
894 *****************************************************************************/
895 static void SetAttachment( vlc_object_t *p_this, vlc_bool_t b_attached )
899 for( i_index = p_this->i_children ; i_index-- ; )
901 SetAttachment( p_this->pp_children[i_index], b_attached );
904 p_this->b_attached = b_attached;
907 static void PrintObject( vlc_object_t *p_this, const char *psz_prefix )
909 char psz_children[20], psz_refcount[20], psz_thread[20], psz_name[50];
912 if( p_this->psz_object_name )
914 snprintf( psz_name, 50, " \"%s\"", p_this->psz_object_name );
919 psz_children[0] = '\0';
920 switch( p_this->i_children )
925 strcpy( psz_children, ", 1 child" );
928 snprintf( psz_children, 20,
929 ", %i children", p_this->i_children );
930 psz_children[19] = '\0';
934 psz_refcount[0] = '\0';
935 if( p_this->i_refcount )
937 snprintf( psz_refcount, 20, ", refcount %i", p_this->i_refcount );
938 psz_refcount[19] = '\0';
941 psz_thread[0] = '\0';
942 if( p_this->b_thread )
944 snprintf( psz_thread, 20, " (thread %d)", (int)p_this->thread_id );
945 psz_thread[19] = '\0';
948 printf( " %so %.8i %s%s%s%s%s\n", psz_prefix,
949 p_this->i_object_id, p_this->psz_object_type,
950 psz_name, psz_thread, psz_refcount, psz_children );
953 static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
956 char i_back = psz_foo[i_level];
957 psz_foo[i_level] = '\0';
959 PrintObject( p_this, psz_foo );
961 psz_foo[i_level] = i_back;
963 if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH )
965 msg_Warn( p_this, "structure tree is too deep" );
969 for( i = 0 ; i < p_this->i_children ; i++ )
973 psz_foo[i_level-1] = ' ';
975 if( psz_foo[i_level-2] == '`' )
977 psz_foo[i_level-2] = ' ';
981 if( i == p_this->i_children - 1 )
983 psz_foo[i_level] = '`';
987 psz_foo[i_level] = '|';
990 psz_foo[i_level+1] = '-';
991 psz_foo[i_level+2] = '\0';
993 DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo );
997 static vlc_list_t * NewList( int i_count )
999 vlc_list_t * p_list = (vlc_list_t *)malloc( sizeof( vlc_list_t ) );
1000 if( p_list == NULL )
1005 p_list->i_count = i_count;
1009 p_list->p_values = NULL;
1013 p_list->p_values = malloc( i_count * sizeof( vlc_value_t ) );
1014 if( p_list->p_values == NULL )
1016 p_list->i_count = 0;
1023 static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
1026 if( p_list == NULL || i_index >= p_list->i_count )
1031 p_object->i_refcount++;
1033 p_list->p_values[i_index].p_object = p_object;
1038 /*static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
1040 if( p_list == NULL )
1045 p_list->p_values = realloc( p_list->p_values, (p_list->i_count + 1)
1046 * sizeof( vlc_value_t ) );
1047 if( p_list->p_values == NULL )
1049 p_list->i_count = 0;
1053 p_object->i_refcount++;
1055 p_list->p_values[p_list->i_count].p_object = p_object;
1061 static int CountChildren( vlc_object_t *p_this, int i_type )
1063 vlc_object_t *p_tmp;
1066 for( i = 0; i < p_this->i_children; i++ )
1068 p_tmp = p_this->pp_children[i];
1070 if( p_tmp->i_object_type == i_type )
1075 if( p_tmp->i_children )
1077 i_count += CountChildren( p_tmp, i_type );
1084 static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type )
1086 vlc_object_t *p_tmp;
1089 for( i = 0; i < p_this->i_children; i++ )
1091 p_tmp = p_this->pp_children[i];
1093 if( p_tmp->i_object_type == i_type )
1095 ListReplace( p_list, p_tmp, p_list->i_count++ );
1098 if( p_tmp->i_children )
1100 ListChildren( p_list, p_tmp, i_type );