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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
26 * This file contains the functions to handle the vlc_object_t type
30 /*****************************************************************************
32 *****************************************************************************/
36 # include <stdlib.h> /* realloc() */
39 #include "../libvlc.h"
42 #include "audio_output/aout_internal.h"
44 #include <vlc_access.h>
45 #include <vlc_demux.h>
46 #include <vlc_stream.h>
49 #include "stream_output/stream_output.h"
51 #include "vlc_playlist.h"
52 #include "vlc_interface.h"
53 #include "vlc_codec.h"
54 #include "vlc_filter.h"
56 #include "vlc_httpd.h"
64 #include "variables.h"
66 /*****************************************************************************
68 *****************************************************************************/
69 static int DumpCommand( vlc_object_t *, char const *,
70 vlc_value_t, vlc_value_t, void * );
72 static vlc_object_t * FindObject ( vlc_object_t *, int, int );
73 static void DetachObject ( vlc_object_t * );
74 static void PrintObject ( vlc_object_t *, const char * );
75 static void DumpStructure ( vlc_object_t *, int, char * );
76 static int FindIndex ( vlc_object_t *, vlc_object_t **, int );
77 static void SetAttachment ( vlc_object_t *, vlc_bool_t );
79 static vlc_list_t * NewList ( int );
80 static void ListReplace ( vlc_list_t *, vlc_object_t *, int );
81 /*static void ListAppend ( vlc_list_t *, vlc_object_t * );*/
82 static int CountChildren ( vlc_object_t *, int );
83 static void ListChildren ( vlc_list_t *, vlc_object_t *, int );
85 /*****************************************************************************
86 * Local structure lock
87 *****************************************************************************/
88 static vlc_mutex_t structure_lock;
90 vlc_object_t *vlc_custom_create( vlc_object_t *p_this, size_t i_size,
91 int i_type, const char *psz_type )
95 if( i_type == VLC_OBJECT_GLOBAL )
101 p_new = malloc( i_size );
102 if( !p_new ) return NULL;
103 memset( p_new, 0, i_size );
106 p_new->i_object_type = i_type;
107 p_new->psz_object_type = psz_type;
109 p_new->psz_object_name = NULL;
111 p_new->b_die = VLC_FALSE;
112 p_new->b_error = VLC_FALSE;
113 p_new->b_dead = VLC_FALSE;
114 p_new->b_attached = VLC_FALSE;
115 p_new->b_force = VLC_FALSE;
117 p_new->psz_header = NULL;
120 if( p_this->i_flags & OBJECT_FLAGS_NODBG )
121 p_new->i_flags |= OBJECT_FLAGS_NODBG;
122 if( p_this->i_flags & OBJECT_FLAGS_QUIET )
123 p_new->i_flags |= OBJECT_FLAGS_QUIET;
124 if( p_this->i_flags & OBJECT_FLAGS_NOINTERACT )
125 p_new->i_flags |= OBJECT_FLAGS_NOINTERACT;
128 p_new->p_vars = (variable_t *)malloc( 16 * sizeof( variable_t ) );
132 if( i_type != VLC_OBJECT_GLOBAL )
137 if( i_type == VLC_OBJECT_GLOBAL )
139 /* If i_type is global, then p_new is actually p_libvlc_global */
140 p_new->p_libvlc_global = (libvlc_global_data_t*)p_new;
141 p_new->p_libvlc = NULL;
143 p_new->p_libvlc_global->i_counter = 0;
144 p_new->i_object_id = 0;
146 p_new->p_libvlc_global->i_objects = 1;
147 p_new->p_libvlc_global->pp_objects = malloc( sizeof(vlc_object_t *) );
148 p_new->p_libvlc_global->pp_objects[0] = p_new;
149 p_new->b_attached = VLC_TRUE;
153 p_new->p_libvlc_global = p_this->p_libvlc_global;
154 p_new->p_libvlc = ( i_type == VLC_OBJECT_LIBVLC ) ? (libvlc_int_t*)p_new
157 vlc_mutex_lock( &structure_lock );
159 p_new->p_libvlc_global->i_counter++;
160 p_new->i_object_id = p_new->p_libvlc_global->i_counter;
162 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
163 * useless to try and recover anything if pp_objects gets smashed. */
164 TAB_APPEND( p_new->p_libvlc_global->i_objects,
165 p_new->p_libvlc_global->pp_objects,
168 vlc_mutex_unlock( &structure_lock );
171 p_new->i_refcount = 0;
172 p_new->p_parent = NULL;
173 p_new->pp_children = NULL;
174 p_new->i_children = 0;
176 p_new->p_private = NULL;
178 /* Initialize mutexes and condvars */
179 vlc_mutex_init( p_new, &p_new->object_lock );
180 vlc_cond_init( p_new, &p_new->object_wait );
181 vlc_mutex_init( p_new, &p_new->var_lock );
183 if( i_type == VLC_OBJECT_GLOBAL )
185 vlc_mutex_init( p_new, &structure_lock );
187 var_Create( p_new, "list", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
188 var_AddCallback( p_new, "list", DumpCommand, NULL );
189 var_Create( p_new, "tree", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
190 var_AddCallback( p_new, "tree", DumpCommand, NULL );
198 * Allocates and initializes a vlc object.
200 * @param i_type known object type (all of them are negative integer values),
201 * or object byte size (always positive).
203 * @return the new object, or NULL on error.
205 void * __vlc_object_create( vlc_object_t *p_this, int i_type )
207 const char * psz_type;
212 case VLC_OBJECT_GLOBAL:
213 i_size = sizeof(libvlc_global_data_t);
216 case VLC_OBJECT_LIBVLC:
217 i_size = sizeof(libvlc_int_t);
220 case VLC_OBJECT_MODULE:
221 i_size = sizeof(module_t);
224 case VLC_OBJECT_INTF:
225 i_size = sizeof(intf_thread_t);
226 psz_type = "interface";
228 case VLC_OBJECT_DIALOGS:
229 i_size = sizeof(intf_thread_t);
230 psz_type = "dialogs";
232 case VLC_OBJECT_PLAYLIST:
233 i_size = sizeof(playlist_t);
234 psz_type = "playlist";
237 i_size = sizeof(services_discovery_t);
238 psz_type = "services discovery";
240 case VLC_OBJECT_INPUT:
241 i_size = sizeof(input_thread_t);
244 case VLC_OBJECT_DEMUX:
245 i_size = sizeof(demux_t);
248 case VLC_OBJECT_STREAM:
249 i_size = sizeof(stream_t);
252 case VLC_OBJECT_ACCESS:
253 i_size = sizeof(access_t);
256 case VLC_OBJECT_DECODER:
257 i_size = sizeof(decoder_t);
258 psz_type = "decoder";
260 case VLC_OBJECT_PACKETIZER:
261 i_size = sizeof(decoder_t);
262 psz_type = "packetizer";
264 case VLC_OBJECT_ENCODER:
265 i_size = sizeof(encoder_t);
266 psz_type = "encoder";
268 case VLC_OBJECT_FILTER:
269 i_size = sizeof(filter_t);
272 case VLC_OBJECT_VOUT:
273 i_size = sizeof(vout_thread_t);
274 psz_type = "video output";
277 i_size = sizeof(spu_t);
278 psz_type = "subpicture";
280 case VLC_OBJECT_AOUT:
281 i_size = sizeof(aout_instance_t);
282 psz_type = "audio output";
284 case VLC_OBJECT_SOUT:
285 i_size = sizeof(sout_instance_t);
286 psz_type = "stream output";
289 i_size = sizeof( vlm_t );
290 psz_type = "vlm dameon";
293 i_size = sizeof( vod_t );
294 psz_type = "vod server";
297 i_size = sizeof( tls_t );
301 i_size = sizeof( xml_t );
304 case VLC_OBJECT_OPENGL:
305 i_size = sizeof( vout_thread_t );
308 case VLC_OBJECT_ANNOUNCE:
309 i_size = sizeof( announce_handler_t );
310 psz_type = "announce";
312 case VLC_OBJECT_META_ENGINE:
313 i_size = sizeof( meta_engine_t );
314 psz_type = "meta engine";
316 case VLC_OBJECT_OSDMENU:
317 i_size = sizeof( osd_menu_t );
318 psz_type = "osd menu";
321 i_size = i_type > (int)sizeof(vlc_object_t)
322 ? i_type : (int)sizeof(vlc_object_t);
323 i_type = VLC_OBJECT_GENERIC;
324 psz_type = "generic";
328 return vlc_custom_create( p_this, i_size, i_type, psz_type );
333 ****************************************************************************
334 * Destroy a vlc object
336 * This function destroys an object that has been previously allocated with
337 * vlc_object_create. The object's refcount must be zero and it must not be
338 * attached to other objects in any way.
339 *****************************************************************************/
340 void __vlc_object_destroy( vlc_object_t *p_this )
344 if( p_this->i_children )
346 msg_Err( p_this, "cannot delete object (%i, %s) with children" ,
347 p_this->i_object_id, p_this->psz_object_name );
351 if( p_this->p_parent )
353 msg_Err( p_this, "cannot delete object (%i, %s) with a parent",
354 p_this->i_object_id, p_this->psz_object_name );
358 while( p_this->i_refcount )
362 /* Don't warn immediately ... 100ms seems OK */
366 "refcount is %i, delaying before deletion (id=%d,type=%d)",
367 p_this->i_refcount, p_this->i_object_id,
368 p_this->i_object_type );
370 else if( i_delay == 10 )
373 "refcount is %i, delaying again (id=%d,type=%d)",
374 p_this->i_refcount, p_this->i_object_id,
375 p_this->i_object_type );
377 else if( i_delay == 20 )
380 "waited too long, cancelling destruction (id=%d,type=%d)",
381 p_this->i_object_id, p_this->i_object_type );
388 /* Destroy the associated variables, starting from the end so that
389 * no memmove calls have to be done. */
390 while( p_this->i_vars )
392 var_Destroy( p_this, p_this->p_vars[p_this->i_vars - 1].psz_name );
395 free( p_this->p_vars );
396 vlc_mutex_destroy( &p_this->var_lock );
398 if( p_this->psz_header ) free( p_this->psz_header );
400 if( p_this->i_object_type == VLC_OBJECT_GLOBAL )
402 /* We are the global object ... no need to lock. */
403 free( p_this->p_libvlc_global->pp_objects );
404 p_this->p_libvlc_global->pp_objects = NULL;
405 p_this->p_libvlc_global->i_objects--;
407 vlc_mutex_destroy( &structure_lock );
413 vlc_mutex_lock( &structure_lock );
415 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
416 * useless to try and recover anything if pp_objects gets smashed. */
417 i_index = FindIndex( p_this, p_this->p_libvlc_global->pp_objects,
418 p_this->p_libvlc_global->i_objects );
419 REMOVE_ELEM( p_this->p_libvlc_global->pp_objects,
420 p_this->p_libvlc_global->i_objects, i_index );
422 vlc_mutex_unlock( &structure_lock );
425 vlc_mutex_destroy( &p_this->object_lock );
426 vlc_cond_destroy( &p_this->object_wait );
428 /* global is not dynamically allocated by vlc_object_create */
429 if( p_this->i_object_type != VLC_OBJECT_GLOBAL )
434 * find an object given its ID
436 * This function looks for the object whose i_object_id field is i_id. We
437 * use a dichotomy so that lookups are in log2(n).
438 *****************************************************************************/
439 void * __vlc_object_get( vlc_object_t *p_this, int i_id )
442 vlc_object_t **pp_objects;
444 vlc_mutex_lock( &structure_lock );
446 pp_objects = p_this->p_libvlc_global->pp_objects;
448 /* Perform our dichotomy */
449 for( i_max = p_this->p_libvlc_global->i_objects - 1 ; ; )
451 i_middle = i_max / 2;
453 if( pp_objects[i_middle]->i_object_id > i_id )
457 else if( pp_objects[i_middle]->i_object_id < i_id )
461 pp_objects += i_middle;
466 /* This happens when there are only two remaining objects */
467 if( pp_objects[i_middle+1]->i_object_id == i_id )
469 vlc_mutex_unlock( &structure_lock );
470 pp_objects[i_middle+1]->i_refcount++;
471 return pp_objects[i_middle+1];
478 vlc_mutex_unlock( &structure_lock );
479 pp_objects[i_middle]->i_refcount++;
480 return pp_objects[i_middle];
485 /* this means that i_max == i_middle, and since we have already
486 * tested pp_objects[i_middle]), p_found is properly set. */
491 vlc_mutex_unlock( &structure_lock );
496 ****************************************************************************
497 * find a typed object and increment its refcount
498 *****************************************************************************
499 * This function recursively looks for a given object type. i_mode can be one
500 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
501 *****************************************************************************/
502 void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
504 vlc_object_t *p_found;
506 vlc_mutex_lock( &structure_lock );
508 /* If we are of the requested type ourselves, don't look further */
509 if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
511 p_this->i_refcount++;
512 vlc_mutex_unlock( &structure_lock );
516 /* Otherwise, recursively look for the object */
517 if( (i_mode & 0x000f) == FIND_ANYWHERE )
519 vlc_object_t *p_root = p_this;
522 while( p_root->p_parent != NULL &&
523 p_root != VLC_OBJECT( p_this->p_libvlc ) )
525 p_root = p_root->p_parent;
528 p_found = FindObject( p_root, i_type, (i_mode & ~0x000f)|FIND_CHILD );
529 if( p_found == NULL && p_root != VLC_OBJECT( p_this->p_libvlc ) )
531 p_found = FindObject( VLC_OBJECT( p_this->p_libvlc ),
532 i_type, (i_mode & ~0x000f)|FIND_CHILD );
537 p_found = FindObject( p_this, i_type, i_mode );
540 vlc_mutex_unlock( &structure_lock );
546 ****************************************************************************
547 * increment an object refcount
548 *****************************************************************************/
549 void __vlc_object_yield( vlc_object_t *p_this )
551 vlc_mutex_lock( &structure_lock );
552 p_this->i_refcount++;
553 vlc_mutex_unlock( &structure_lock );
557 ****************************************************************************
558 * decrement an object refcount
559 *****************************************************************************/
560 void __vlc_object_release( vlc_object_t *p_this )
562 vlc_mutex_lock( &structure_lock );
563 p_this->i_refcount--;
564 vlc_mutex_unlock( &structure_lock );
568 ****************************************************************************
569 * attach object to a parent object
570 *****************************************************************************
571 * This function sets p_this as a child of p_parent, and p_parent as a parent
572 * of p_this. This link can be undone using vlc_object_detach.
573 *****************************************************************************/
574 void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
576 vlc_mutex_lock( &structure_lock );
578 /* Attach the parent to its child */
579 p_this->p_parent = p_parent;
581 /* Attach the child to its parent */
582 INSERT_ELEM( p_parent->pp_children, p_parent->i_children,
583 p_parent->i_children, p_this );
585 /* Climb up the tree to see whether we are connected with the root */
586 if( p_parent->b_attached )
588 SetAttachment( p_this, VLC_TRUE );
591 vlc_mutex_unlock( &structure_lock );
595 ****************************************************************************
596 * detach object from its parent
597 *****************************************************************************
598 * This function removes all links between an object and its parent.
599 *****************************************************************************/
600 void __vlc_object_detach( vlc_object_t *p_this )
602 vlc_mutex_lock( &structure_lock );
603 if( !p_this->p_parent )
605 msg_Err( p_this, "object is not attached" );
606 vlc_mutex_unlock( &structure_lock );
610 /* Climb up the tree to see whether we are connected with the root */
611 if( p_this->p_parent->b_attached )
613 SetAttachment( p_this, VLC_FALSE );
616 DetachObject( p_this );
617 vlc_mutex_unlock( &structure_lock );
621 ****************************************************************************
622 * find a list typed objects and increment their refcount
623 *****************************************************************************
624 * This function recursively looks for a given object type. i_mode can be one
625 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
626 *****************************************************************************/
627 vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
630 vlc_object_t **pp_current, **pp_end;
631 int i_count = 0, i_index = 0;
633 vlc_mutex_lock( &structure_lock );
635 /* Look for the objects */
636 switch( i_mode & 0x000f )
639 pp_current = p_this->p_libvlc_global->pp_objects;
640 pp_end = pp_current + p_this->p_libvlc_global->i_objects;
642 for( ; pp_current < pp_end ; pp_current++ )
644 if( (*pp_current)->b_attached
645 && (*pp_current)->i_object_type == i_type )
651 p_list = NewList( i_count );
652 pp_current = p_this->p_libvlc_global->pp_objects;
654 for( ; pp_current < pp_end ; pp_current++ )
656 if( (*pp_current)->b_attached
657 && (*pp_current)->i_object_type == i_type )
659 ListReplace( p_list, *pp_current, i_index );
660 if( i_index < i_count ) i_index++;
666 i_count = CountChildren( p_this, i_type );
667 p_list = NewList( i_count );
669 /* Check allocation was successful */
670 if( p_list->i_count != i_count )
672 msg_Err( p_this, "list allocation failed!" );
678 ListChildren( p_list, p_this, i_type );
682 msg_Err( p_this, "unimplemented!" );
683 p_list = NewList( 0 );
687 vlc_mutex_unlock( &structure_lock );
692 /*****************************************************************************
693 * DumpCommand: print the current vlc structure
694 *****************************************************************************
695 * This function prints either an ASCII tree showing the connections between
696 * vlc objects, and additional information such as their refcount, thread ID,
697 * etc. (command "tree"), or the same data as a simple list (command "list").
698 *****************************************************************************/
699 static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
700 vlc_value_t oldval, vlc_value_t newval, void *p_data )
702 if( *psz_cmd == 't' )
704 char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
705 vlc_object_t *p_object;
707 if( *newval.psz_string )
709 p_object = vlc_object_get( p_this, atoi(newval.psz_string) );
718 p_object = p_this->p_libvlc ? VLC_OBJECT(p_this->p_libvlc) : p_this;
721 vlc_mutex_lock( &structure_lock );
724 DumpStructure( p_object, 0, psz_foo );
726 vlc_mutex_unlock( &structure_lock );
728 if( *newval.psz_string )
730 vlc_object_release( p_this );
733 else if( *psz_cmd == 'l' )
735 vlc_object_t **pp_current, **pp_end;
737 vlc_mutex_lock( &structure_lock );
739 pp_current = p_this->p_libvlc_global->pp_objects;
740 pp_end = pp_current + p_this->p_libvlc_global->i_objects;
742 for( ; pp_current < pp_end ; pp_current++ )
744 if( (*pp_current)->b_attached )
746 PrintObject( *pp_current, "" );
750 printf( " o %.8i %s (not attached)\n",
751 (*pp_current)->i_object_id,
752 (*pp_current)->psz_object_type );
756 vlc_mutex_unlock( &structure_lock );
762 /*****************************************************************************
763 * vlc_list_release: free a list previously allocated by vlc_list_find
764 *****************************************************************************
765 * This function decreases the refcount of all objects in the list and
767 *****************************************************************************/
768 void vlc_list_release( vlc_list_t *p_list )
772 for( i_index = 0; i_index < p_list->i_count; i_index++ )
774 vlc_mutex_lock( &structure_lock );
776 p_list->p_values[i_index].p_object->i_refcount--;
778 vlc_mutex_unlock( &structure_lock );
781 free( p_list->p_values );
785 /* Following functions are local */
787 /*****************************************************************************
788 * FindIndex: find the index of an object in an array of objects
789 *****************************************************************************
790 * This function assumes that p_this can be found in pp_objects. It will not
791 * crash if p_this cannot be found, but will return a wrong value. It is your
792 * duty to check the return value if you are not certain that the object could
794 *****************************************************************************/
795 static int FindIndex( vlc_object_t *p_this,
796 vlc_object_t **pp_objects, int i_count )
798 int i_middle = i_count / 2;
805 if( pp_objects[i_middle] == p_this )
815 /* We take advantage of the sorted array */
816 if( pp_objects[i_middle]->i_object_id < p_this->i_object_id )
818 return i_middle + FindIndex( p_this, pp_objects + i_middle,
819 i_count - i_middle );
823 return FindIndex( p_this, pp_objects, i_middle );
827 static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
832 switch( i_mode & 0x000f )
835 p_tmp = p_this->p_parent;
838 if( p_tmp->i_object_type == i_type )
845 return FindObject( p_tmp, i_type, i_mode );
851 for( i = p_this->i_children; i--; )
853 p_tmp = p_this->pp_children[i];
854 if( p_tmp->i_object_type == i_type )
859 else if( p_tmp->i_children )
861 p_tmp = FindObject( p_tmp, i_type, i_mode );
871 /* Handled in vlc_object_find */
878 static void DetachObject( vlc_object_t *p_this )
880 vlc_object_t *p_parent = p_this->p_parent;
883 /* Remove p_this's parent */
884 p_this->p_parent = NULL;
886 /* Remove all of p_parent's children which are p_this */
887 for( i_index = p_parent->i_children ; i_index-- ; )
889 if( p_parent->pp_children[i_index] == p_this )
891 p_parent->i_children--;
892 for( i = i_index ; i < p_parent->i_children ; i++ )
894 p_parent->pp_children[i] = p_parent->pp_children[i+1];
899 if( p_parent->i_children )
901 p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children,
902 p_parent->i_children * sizeof(vlc_object_t *) );
906 free( p_parent->pp_children );
907 p_parent->pp_children = NULL;
911 /*****************************************************************************
912 * SetAttachment: recursively set the b_attached flag of a subtree.
913 *****************************************************************************
914 * This function is used by the attach and detach functions to propagate
915 * the b_attached flag in a subtree.
916 *****************************************************************************/
917 static void SetAttachment( vlc_object_t *p_this, vlc_bool_t b_attached )
921 for( i_index = p_this->i_children ; i_index-- ; )
923 SetAttachment( p_this->pp_children[i_index], b_attached );
926 p_this->b_attached = b_attached;
929 static void PrintObject( vlc_object_t *p_this, const char *psz_prefix )
931 char psz_children[20], psz_refcount[20], psz_thread[20], psz_name[50];
934 if( p_this->psz_object_name )
936 snprintf( psz_name, 50, " \"%s\"", p_this->psz_object_name );
941 psz_children[0] = '\0';
942 switch( p_this->i_children )
947 strcpy( psz_children, ", 1 child" );
950 snprintf( psz_children, 20,
951 ", %i children", p_this->i_children );
952 psz_children[19] = '\0';
956 psz_refcount[0] = '\0';
957 if( p_this->i_refcount )
959 snprintf( psz_refcount, 20, ", refcount %i", p_this->i_refcount );
960 psz_refcount[19] = '\0';
963 psz_thread[0] = '\0';
964 if( p_this->b_thread )
966 snprintf( psz_thread, 20, " (thread %d)", (int)p_this->thread_id );
967 psz_thread[19] = '\0';
970 printf( " %so %.8i %s%s%s%s%s\n", psz_prefix,
971 p_this->i_object_id, p_this->psz_object_type,
972 psz_name, psz_thread, psz_refcount, psz_children );
975 static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
978 char i_back = psz_foo[i_level];
979 psz_foo[i_level] = '\0';
981 PrintObject( p_this, psz_foo );
983 psz_foo[i_level] = i_back;
985 if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH )
987 msg_Warn( p_this, "structure tree is too deep" );
991 for( i = 0 ; i < p_this->i_children ; i++ )
995 psz_foo[i_level-1] = ' ';
997 if( psz_foo[i_level-2] == '`' )
999 psz_foo[i_level-2] = ' ';
1003 if( i == p_this->i_children - 1 )
1005 psz_foo[i_level] = '`';
1009 psz_foo[i_level] = '|';
1012 psz_foo[i_level+1] = '-';
1013 psz_foo[i_level+2] = '\0';
1015 DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo );
1019 static vlc_list_t * NewList( int i_count )
1021 vlc_list_t * p_list = (vlc_list_t *)malloc( sizeof( vlc_list_t ) );
1022 if( p_list == NULL )
1027 p_list->i_count = i_count;
1031 p_list->p_values = NULL;
1035 p_list->p_values = malloc( i_count * sizeof( vlc_value_t ) );
1036 if( p_list->p_values == NULL )
1038 p_list->i_count = 0;
1045 static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
1048 if( p_list == NULL || i_index >= p_list->i_count )
1053 p_object->i_refcount++;
1055 p_list->p_values[i_index].p_object = p_object;
1060 /*static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
1062 if( p_list == NULL )
1067 p_list->p_values = realloc( p_list->p_values, (p_list->i_count + 1)
1068 * sizeof( vlc_value_t ) );
1069 if( p_list->p_values == NULL )
1071 p_list->i_count = 0;
1075 p_object->i_refcount++;
1077 p_list->p_values[p_list->i_count].p_object = p_object;
1083 static int CountChildren( vlc_object_t *p_this, int i_type )
1085 vlc_object_t *p_tmp;
1088 for( i = 0; i < p_this->i_children; i++ )
1090 p_tmp = p_this->pp_children[i];
1092 if( p_tmp->i_object_type == i_type )
1097 if( p_tmp->i_children )
1099 i_count += CountChildren( p_tmp, i_type );
1106 static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type )
1108 vlc_object_t *p_tmp;
1111 for( i = 0; i < p_this->i_children; i++ )
1113 p_tmp = p_this->pp_children[i];
1115 if( p_tmp->i_object_type == i_type )
1117 ListReplace( p_list, p_tmp, p_list->i_count++ );
1120 if( p_tmp->i_children )
1122 ListChildren( p_list, p_tmp, i_type );