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 *****************************************************************************/
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;
251 p_new->psz_header = NULL;
254 if( p_this->i_flags & OBJECT_FLAGS_NODBG )
255 p_new->i_flags |= OBJECT_FLAGS_NODBG;
256 if( p_this->i_flags & OBJECT_FLAGS_QUIET )
257 p_new->i_flags |= OBJECT_FLAGS_QUIET;
258 if( p_this->i_flags & OBJECT_FLAGS_NOINTERACT )
259 p_new->i_flags |= OBJECT_FLAGS_NOINTERACT;
262 p_new->p_vars = (variable_t *)malloc( 16 * sizeof( variable_t ) );
266 if( i_type != VLC_OBJECT_ROOT )
271 if( i_type == VLC_OBJECT_ROOT )
273 /* If i_type is root, then p_new is actually p_libvlc */
274 p_new->p_libvlc = (libvlc_t*)p_new;
277 p_new->p_libvlc->i_counter = 0;
278 p_new->i_object_id = 0;
280 p_new->p_libvlc->i_objects = 1;
281 p_new->p_libvlc->pp_objects = malloc( sizeof(vlc_object_t *) );
282 p_new->p_libvlc->pp_objects[0] = p_new;
283 p_new->b_attached = VLC_TRUE;
287 p_new->p_libvlc = p_this->p_libvlc;
288 p_new->p_vlc = ( i_type == VLC_OBJECT_VLC ) ? (vlc_t*)p_new
291 vlc_mutex_lock( &structure_lock );
293 p_new->p_libvlc->i_counter++;
294 p_new->i_object_id = p_new->p_libvlc->i_counter;
296 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
297 * useless to try and recover anything if pp_objects gets smashed. */
298 INSERT_ELEM( p_new->p_libvlc->pp_objects,
299 p_new->p_libvlc->i_objects,
300 p_new->p_libvlc->i_objects,
303 vlc_mutex_unlock( &structure_lock );
306 p_new->i_refcount = 0;
307 p_new->p_parent = NULL;
308 p_new->pp_children = NULL;
309 p_new->i_children = 0;
311 p_new->p_private = NULL;
313 /* Initialize mutexes and condvars */
314 vlc_mutex_init( p_new, &p_new->object_lock );
315 vlc_cond_init( p_new, &p_new->object_wait );
316 vlc_mutex_init( p_new, &p_new->var_lock );
318 if( i_type == VLC_OBJECT_ROOT )
320 vlc_mutex_init( p_new, &structure_lock );
322 var_Create( p_new, "list", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
323 var_AddCallback( p_new, "list", DumpCommand, NULL );
324 var_Create( p_new, "tree", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
325 var_AddCallback( p_new, "tree", DumpCommand, NULL );
332 ****************************************************************************
333 * Destroy a vlc object
335 * This function destroys an object that has been previously allocated with
336 * vlc_object_create. The object's refcount must be zero and it must not be
337 * attached to other objects in any way.
338 *****************************************************************************/
339 void __vlc_object_destroy( vlc_object_t *p_this )
343 if( p_this->i_children )
345 msg_Err( p_this, "cannot delete object (%i, %s) with children" ,
346 p_this->i_object_id, p_this->psz_object_name );
350 if( p_this->p_parent )
352 msg_Err( p_this, "cannot delete object (%i, %s) with a parent",
353 p_this->i_object_id, p_this->psz_object_name );
357 while( p_this->i_refcount )
361 /* Don't warn immediately ... 100ms seems OK */
365 "refcount is %i, delaying before deletion (id=%d,type=%d)",
366 p_this->i_refcount, p_this->i_object_id,
367 p_this->i_object_type );
369 else if( i_delay == 10 )
372 "refcount is %i, delaying again (id=%d,type=%d)",
373 p_this->i_refcount, p_this->i_object_id,
374 p_this->i_object_type );
376 else if( i_delay == 20 )
379 "we waited too long, cancelling destruction (id=%d,type=%d)",
380 p_this->i_object_id, p_this->i_object_type );
387 /* Destroy the associated variables, starting from the end so that
388 * no memmove calls have to be done. */
389 while( p_this->i_vars )
391 var_Destroy( p_this, p_this->p_vars[p_this->i_vars - 1].psz_name );
394 free( p_this->p_vars );
395 vlc_mutex_destroy( &p_this->var_lock );
397 if( p_this->psz_header ) free( p_this->psz_header );
399 if( p_this->i_object_type == VLC_OBJECT_ROOT )
401 /* We are the root object ... no need to lock. */
402 free( p_this->p_libvlc->pp_objects );
403 p_this->p_libvlc->pp_objects = NULL;
404 p_this->p_libvlc->i_objects--;
406 vlc_mutex_destroy( &structure_lock );
412 vlc_mutex_lock( &structure_lock );
414 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
415 * useless to try and recover anything if pp_objects gets smashed. */
416 i_index = FindIndex( p_this, p_this->p_libvlc->pp_objects,
417 p_this->p_libvlc->i_objects );
418 REMOVE_ELEM( p_this->p_libvlc->pp_objects,
419 p_this->p_libvlc->i_objects, i_index );
421 vlc_mutex_unlock( &structure_lock );
424 vlc_mutex_destroy( &p_this->object_lock );
425 vlc_cond_destroy( &p_this->object_wait );
427 /* root is not dynamically allocated by vlc_object_create */
428 if( p_this->i_object_type != VLC_OBJECT_ROOT )
433 * find an object given its ID
435 * This function looks for the object whose i_object_id field is i_id. We
436 * use a dichotomy so that lookups are in log2(n).
437 *****************************************************************************/
438 void * __vlc_object_get( vlc_object_t *p_this, int i_id )
441 vlc_object_t **pp_objects;
443 vlc_mutex_lock( &structure_lock );
445 pp_objects = p_this->p_libvlc->pp_objects;
447 /* Perform our dichotomy */
448 for( i_max = p_this->p_libvlc->i_objects - 1 ; ; )
450 i_middle = i_max / 2;
452 if( pp_objects[i_middle]->i_object_id > i_id )
456 else if( pp_objects[i_middle]->i_object_id < i_id )
460 pp_objects += i_middle;
465 /* This happens when there are only two remaining objects */
466 if( pp_objects[i_middle+1]->i_object_id == i_id )
468 vlc_mutex_unlock( &structure_lock );
469 pp_objects[i_middle+1]->i_refcount++;
470 return pp_objects[i_middle+1];
477 vlc_mutex_unlock( &structure_lock );
478 pp_objects[i_middle]->i_refcount++;
479 return pp_objects[i_middle];
484 /* this means that i_max == i_middle, and since we have already
485 * tested pp_objects[i_middle]), p_found is properly set. */
490 vlc_mutex_unlock( &structure_lock );
495 ****************************************************************************
496 * find a typed object and increment its refcount
497 *****************************************************************************
498 * This function recursively looks for a given object type. i_mode can be one
499 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
500 *****************************************************************************/
501 void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
503 vlc_object_t *p_found;
505 vlc_mutex_lock( &structure_lock );
507 /* If we are of the requested type ourselves, don't look further */
508 if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
510 p_this->i_refcount++;
511 vlc_mutex_unlock( &structure_lock );
515 /* Otherwise, recursively look for the object */
516 if( (i_mode & 0x000f) == FIND_ANYWHERE )
518 vlc_object_t *p_root = p_this;
521 while( p_root->p_parent != NULL &&
522 p_root != VLC_OBJECT( p_this->p_vlc ) )
524 p_root = p_root->p_parent;
527 p_found = FindObject( p_root, i_type, (i_mode & ~0x000f)|FIND_CHILD );
528 if( p_found == NULL && p_root != VLC_OBJECT( p_this->p_vlc ) )
530 p_found = FindObject( VLC_OBJECT( p_this->p_vlc ),
531 i_type, (i_mode & ~0x000f)|FIND_CHILD );
536 p_found = FindObject( p_this, i_type, i_mode );
539 vlc_mutex_unlock( &structure_lock );
545 ****************************************************************************
546 * increment an object refcount
547 *****************************************************************************/
548 void __vlc_object_yield( vlc_object_t *p_this )
550 vlc_mutex_lock( &structure_lock );
551 p_this->i_refcount++;
552 vlc_mutex_unlock( &structure_lock );
556 ****************************************************************************
557 * decrement an object refcount
558 *****************************************************************************/
559 void __vlc_object_release( vlc_object_t *p_this )
561 vlc_mutex_lock( &structure_lock );
562 p_this->i_refcount--;
563 vlc_mutex_unlock( &structure_lock );
567 ****************************************************************************
568 * attach object to a parent object
569 *****************************************************************************
570 * This function sets p_this as a child of p_parent, and p_parent as a parent
571 * of p_this. This link can be undone using vlc_object_detach.
572 *****************************************************************************/
573 void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
575 vlc_mutex_lock( &structure_lock );
577 /* Attach the parent to its child */
578 p_this->p_parent = p_parent;
580 /* Attach the child to its parent */
581 INSERT_ELEM( p_parent->pp_children, p_parent->i_children,
582 p_parent->i_children, p_this );
584 /* Climb up the tree to see whether we are connected with the root */
585 if( p_parent->b_attached )
587 SetAttachment( p_this, VLC_TRUE );
590 vlc_mutex_unlock( &structure_lock );
594 ****************************************************************************
595 * detach object from its parent
596 *****************************************************************************
597 * This function removes all links between an object and its parent.
598 *****************************************************************************/
599 void __vlc_object_detach( vlc_object_t *p_this )
601 vlc_mutex_lock( &structure_lock );
602 if( !p_this->p_parent )
604 msg_Err( p_this, "object is not attached" );
605 vlc_mutex_unlock( &structure_lock );
609 /* Climb up the tree to see whether we are connected with the root */
610 if( p_this->p_parent->b_attached )
612 SetAttachment( p_this, VLC_FALSE );
615 DetachObject( p_this );
616 vlc_mutex_unlock( &structure_lock );
620 ****************************************************************************
621 * find a list typed objects and increment their refcount
622 *****************************************************************************
623 * This function recursively looks for a given object type. i_mode can be one
624 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
625 *****************************************************************************/
626 vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
629 vlc_object_t **pp_current, **pp_end;
630 int i_count = 0, i_index = 0;
632 vlc_mutex_lock( &structure_lock );
634 /* Look for the objects */
635 switch( i_mode & 0x000f )
638 pp_current = p_this->p_libvlc->pp_objects;
639 pp_end = pp_current + p_this->p_libvlc->i_objects;
641 for( ; pp_current < pp_end ; pp_current++ )
643 if( (*pp_current)->b_attached
644 && (*pp_current)->i_object_type == i_type )
650 p_list = NewList( i_count );
651 pp_current = p_this->p_libvlc->pp_objects;
653 for( ; pp_current < pp_end ; pp_current++ )
655 if( (*pp_current)->b_attached
656 && (*pp_current)->i_object_type == i_type )
658 ListReplace( p_list, *pp_current, i_index );
659 if( i_index < i_count ) i_index++;
665 i_count = CountChildren( p_this, i_type );
666 p_list = NewList( i_count );
668 /* Check allocation was successful */
669 if( p_list->i_count != i_count )
671 msg_Err( p_this, "list allocation failed!" );
677 ListChildren( p_list, p_this, i_type );
681 msg_Err( p_this, "unimplemented!" );
682 p_list = NewList( 0 );
686 vlc_mutex_unlock( &structure_lock );
691 /*****************************************************************************
692 * DumpCommand: print the current vlc structure
693 *****************************************************************************
694 * This function prints either an ASCII tree showing the connections between
695 * vlc objects, and additional information such as their refcount, thread ID,
696 * etc. (command "tree"), or the same data as a simple list (command "list").
697 *****************************************************************************/
698 static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
699 vlc_value_t oldval, vlc_value_t newval, void *p_data )
701 if( *psz_cmd == 't' )
703 char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
704 vlc_object_t *p_object;
706 if( *newval.psz_string )
708 p_object = vlc_object_get( p_this, atoi(newval.psz_string) );
717 p_object = p_this->p_vlc ? VLC_OBJECT(p_this->p_vlc) : p_this;
720 vlc_mutex_lock( &structure_lock );
723 DumpStructure( p_object, 0, psz_foo );
725 vlc_mutex_unlock( &structure_lock );
727 if( *newval.psz_string )
729 vlc_object_release( p_this );
732 else if( *psz_cmd == 'l' )
734 vlc_object_t **pp_current, **pp_end;
736 vlc_mutex_lock( &structure_lock );
738 pp_current = p_this->p_libvlc->pp_objects;
739 pp_end = pp_current + p_this->p_libvlc->i_objects;
741 for( ; pp_current < pp_end ; pp_current++ )
743 if( (*pp_current)->b_attached )
745 PrintObject( *pp_current, "" );
749 printf( " o %.8i %s (not attached)\n",
750 (*pp_current)->i_object_id,
751 (*pp_current)->psz_object_type );
755 vlc_mutex_unlock( &structure_lock );
761 /*****************************************************************************
762 * vlc_list_release: free a list previously allocated by vlc_list_find
763 *****************************************************************************
764 * This function decreases the refcount of all objects in the list and
766 *****************************************************************************/
767 void vlc_list_release( vlc_list_t *p_list )
771 for( i_index = 0; i_index < p_list->i_count; i_index++ )
773 vlc_mutex_lock( &structure_lock );
775 p_list->p_values[i_index].p_object->i_refcount--;
777 vlc_mutex_unlock( &structure_lock );
780 free( p_list->p_values );
784 /* Following functions are local */
786 /*****************************************************************************
787 * FindIndex: find the index of an object in an array of objects
788 *****************************************************************************
789 * This function assumes that p_this can be found in pp_objects. It will not
790 * crash if p_this cannot be found, but will return a wrong value. It is your
791 * duty to check the return value if you are not certain that the object could
793 *****************************************************************************/
794 static int FindIndex( vlc_object_t *p_this,
795 vlc_object_t **pp_objects, int i_count )
797 int i_middle = i_count / 2;
804 if( pp_objects[i_middle] == p_this )
814 /* We take advantage of the sorted array */
815 if( pp_objects[i_middle]->i_object_id < p_this->i_object_id )
817 return i_middle + FindIndex( p_this, pp_objects + i_middle,
818 i_count - i_middle );
822 return FindIndex( p_this, pp_objects, i_middle );
826 static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
831 switch( i_mode & 0x000f )
834 p_tmp = p_this->p_parent;
837 if( p_tmp->i_object_type == i_type )
844 return FindObject( p_tmp, i_type, i_mode );
850 for( i = p_this->i_children; i--; )
852 p_tmp = p_this->pp_children[i];
853 if( p_tmp->i_object_type == i_type )
858 else if( p_tmp->i_children )
860 p_tmp = FindObject( p_tmp, i_type, i_mode );
870 /* Handled in vlc_object_find */
877 static void DetachObject( vlc_object_t *p_this )
879 vlc_object_t *p_parent = p_this->p_parent;
882 /* Remove p_this's parent */
883 p_this->p_parent = NULL;
885 /* Remove all of p_parent's children which are p_this */
886 for( i_index = p_parent->i_children ; i_index-- ; )
888 if( p_parent->pp_children[i_index] == p_this )
890 p_parent->i_children--;
891 for( i = i_index ; i < p_parent->i_children ; i++ )
893 p_parent->pp_children[i] = p_parent->pp_children[i+1];
898 if( p_parent->i_children )
900 p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children,
901 p_parent->i_children * sizeof(vlc_object_t *) );
905 free( p_parent->pp_children );
906 p_parent->pp_children = NULL;
910 /*****************************************************************************
911 * SetAttachment: recursively set the b_attached flag of a subtree.
912 *****************************************************************************
913 * This function is used by the attach and detach functions to propagate
914 * the b_attached flag in a subtree.
915 *****************************************************************************/
916 static void SetAttachment( vlc_object_t *p_this, vlc_bool_t b_attached )
920 for( i_index = p_this->i_children ; i_index-- ; )
922 SetAttachment( p_this->pp_children[i_index], b_attached );
925 p_this->b_attached = b_attached;
928 static void PrintObject( vlc_object_t *p_this, const char *psz_prefix )
930 char psz_children[20], psz_refcount[20], psz_thread[20], psz_name[50];
933 if( p_this->psz_object_name )
935 snprintf( psz_name, 50, " \"%s\"", p_this->psz_object_name );
940 psz_children[0] = '\0';
941 switch( p_this->i_children )
946 strcpy( psz_children, ", 1 child" );
949 snprintf( psz_children, 20,
950 ", %i children", p_this->i_children );
951 psz_children[19] = '\0';
955 psz_refcount[0] = '\0';
956 if( p_this->i_refcount )
958 snprintf( psz_refcount, 20, ", refcount %i", p_this->i_refcount );
959 psz_refcount[19] = '\0';
962 psz_thread[0] = '\0';
963 if( p_this->b_thread )
965 snprintf( psz_thread, 20, " (thread %d)", (int)p_this->thread_id );
966 psz_thread[19] = '\0';
969 printf( " %so %.8i %s%s%s%s%s\n", psz_prefix,
970 p_this->i_object_id, p_this->psz_object_type,
971 psz_name, psz_thread, psz_refcount, psz_children );
974 static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
977 char i_back = psz_foo[i_level];
978 psz_foo[i_level] = '\0';
980 PrintObject( p_this, psz_foo );
982 psz_foo[i_level] = i_back;
984 if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH )
986 msg_Warn( p_this, "structure tree is too deep" );
990 for( i = 0 ; i < p_this->i_children ; i++ )
994 psz_foo[i_level-1] = ' ';
996 if( psz_foo[i_level-2] == '`' )
998 psz_foo[i_level-2] = ' ';
1002 if( i == p_this->i_children - 1 )
1004 psz_foo[i_level] = '`';
1008 psz_foo[i_level] = '|';
1011 psz_foo[i_level+1] = '-';
1012 psz_foo[i_level+2] = '\0';
1014 DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo );
1018 static vlc_list_t * NewList( int i_count )
1020 vlc_list_t * p_list = (vlc_list_t *)malloc( sizeof( vlc_list_t ) );
1021 if( p_list == NULL )
1026 p_list->i_count = i_count;
1030 p_list->p_values = NULL;
1034 p_list->p_values = malloc( i_count * sizeof( vlc_value_t ) );
1035 if( p_list->p_values == NULL )
1037 p_list->i_count = 0;
1044 static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
1047 if( p_list == NULL || i_index >= p_list->i_count )
1052 p_object->i_refcount++;
1054 p_list->p_values[i_index].p_object = p_object;
1059 /*static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
1061 if( p_list == NULL )
1066 p_list->p_values = realloc( p_list->p_values, (p_list->i_count + 1)
1067 * sizeof( vlc_value_t ) );
1068 if( p_list->p_values == NULL )
1070 p_list->i_count = 0;
1074 p_object->i_refcount++;
1076 p_list->p_values[p_list->i_count].p_object = p_object;
1082 static int CountChildren( vlc_object_t *p_this, int i_type )
1084 vlc_object_t *p_tmp;
1087 for( i = 0; i < p_this->i_children; i++ )
1089 p_tmp = p_this->pp_children[i];
1091 if( p_tmp->i_object_type == i_type )
1096 if( p_tmp->i_children )
1098 i_count += CountChildren( p_tmp, i_type );
1105 static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type )
1107 vlc_object_t *p_tmp;
1110 for( i = 0; i < p_this->i_children; i++ )
1112 p_tmp = p_this->pp_children[i];
1114 if( p_tmp->i_object_type == i_type )
1116 ListReplace( p_list, p_tmp, p_list->i_count++ );
1119 if( p_tmp->i_children )
1121 ListChildren( p_list, p_tmp, i_type );