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"
59 #include "vlc_meta_engine.h"
61 /*****************************************************************************
63 *****************************************************************************/
64 static int DumpCommand( vlc_object_t *, char const *,
65 vlc_value_t, vlc_value_t, void * );
67 static vlc_object_t * FindObject ( vlc_object_t *, int, int );
68 static void DetachObject ( vlc_object_t * );
69 static void PrintObject ( vlc_object_t *, const char * );
70 static void DumpStructure ( vlc_object_t *, int, char * );
71 static int FindIndex ( vlc_object_t *, vlc_object_t **, int );
72 static void SetAttachment ( vlc_object_t *, vlc_bool_t );
74 static vlc_list_t * NewList ( int );
75 static void ListReplace ( vlc_list_t *, vlc_object_t *, int );
76 /*static void ListAppend ( vlc_list_t *, vlc_object_t * );*/
77 static int CountChildren ( vlc_object_t *, int );
78 static void ListChildren ( vlc_list_t *, vlc_object_t *, int );
80 /*****************************************************************************
81 * Local structure lock
82 *****************************************************************************/
83 static vlc_mutex_t structure_lock;
85 /*****************************************************************************
86 * vlc_object_create: initialize a vlc object
87 *****************************************************************************
88 * This function allocates memory for a vlc object and initializes it. If
89 * i_type is not a known value such as VLC_OBJECT_ROOT, VLC_OBJECT_VOUT and
90 * so on, vlc_object_create will use its value for the object size.
91 *****************************************************************************/
94 * Initialize a vlc object
96 * This function allocates memory for a vlc object and initializes it. If
97 * i_type is not a known value such as VLC_OBJECT_ROOT, VLC_OBJECT_VOUT and
98 * so on, vlc_object_create will use its value for the object size.
100 void * __vlc_object_create( vlc_object_t *p_this, int i_type )
102 vlc_object_t * p_new;
103 const char * psz_type;
108 case VLC_OBJECT_ROOT:
109 i_size = sizeof(libvlc_global_data_t);
112 case VLC_OBJECT_LIBVLC:
113 i_size = sizeof(libvlc_int_t);
116 case VLC_OBJECT_MODULE:
117 i_size = sizeof(module_t);
120 case VLC_OBJECT_INTF:
121 i_size = sizeof(intf_thread_t);
122 psz_type = "interface";
124 case VLC_OBJECT_DIALOGS:
125 i_size = sizeof(intf_thread_t);
126 psz_type = "dialogs";
128 case VLC_OBJECT_PLAYLIST:
129 i_size = sizeof(playlist_t);
130 psz_type = "playlist";
133 i_size = sizeof(services_discovery_t);
134 psz_type = "services discovery";
136 case VLC_OBJECT_INPUT:
137 i_size = sizeof(input_thread_t);
140 case VLC_OBJECT_DEMUX:
141 i_size = sizeof(demux_t);
144 case VLC_OBJECT_STREAM:
145 i_size = sizeof(stream_t);
148 case VLC_OBJECT_ACCESS:
149 i_size = sizeof(access_t);
152 case VLC_OBJECT_DECODER:
153 i_size = sizeof(decoder_t);
154 psz_type = "decoder";
156 case VLC_OBJECT_PACKETIZER:
157 i_size = sizeof(decoder_t);
158 psz_type = "packetizer";
160 case VLC_OBJECT_ENCODER:
161 i_size = sizeof(encoder_t);
162 psz_type = "encoder";
164 case VLC_OBJECT_FILTER:
165 i_size = sizeof(filter_t);
168 case VLC_OBJECT_VOUT:
169 i_size = sizeof(vout_thread_t);
170 psz_type = "video output";
173 i_size = sizeof(spu_t);
174 psz_type = "subpicture";
176 case VLC_OBJECT_AOUT:
177 i_size = sizeof(aout_instance_t);
178 psz_type = "audio output";
180 case VLC_OBJECT_SOUT:
181 i_size = sizeof(sout_instance_t);
182 psz_type = "stream output";
184 case VLC_OBJECT_HTTPD:
185 i_size = sizeof( httpd_t );
186 psz_type = "http server";
188 case VLC_OBJECT_HTTPD_HOST:
189 i_size = sizeof( httpd_host_t );
190 psz_type = "http server";
193 i_size = sizeof( vlm_t );
194 psz_type = "vlm dameon";
197 i_size = sizeof( vod_t );
198 psz_type = "vod server";
201 i_size = sizeof( tls_t );
205 i_size = sizeof( xml_t );
208 case VLC_OBJECT_OPENGL:
209 i_size = sizeof( vout_thread_t );
212 case VLC_OBJECT_ANNOUNCE:
213 i_size = sizeof( announce_handler_t );
214 psz_type = "announce";
216 case VLC_OBJECT_META_ENGINE:
217 i_size = sizeof( meta_engine_t );
218 psz_type = "meta engine";
220 case VLC_OBJECT_OSDMENU:
221 i_size = sizeof( osd_menu_t );
222 psz_type = "osd menu";
225 i_size = i_type > (int)sizeof(vlc_object_t)
226 ? i_type : (int)sizeof(vlc_object_t);
227 i_type = VLC_OBJECT_GENERIC;
228 psz_type = "generic";
232 if( i_type == VLC_OBJECT_ROOT )
238 p_new = malloc( i_size );
239 if( !p_new ) return NULL;
240 memset( p_new, 0, i_size );
243 p_new->i_object_type = i_type;
244 p_new->psz_object_type = psz_type;
246 p_new->psz_object_name = NULL;
248 p_new->b_die = VLC_FALSE;
249 p_new->b_error = VLC_FALSE;
250 p_new->b_dead = VLC_FALSE;
251 p_new->b_attached = VLC_FALSE;
252 p_new->b_force = VLC_FALSE;
254 p_new->psz_header = NULL;
257 if( p_this->i_flags & OBJECT_FLAGS_NODBG )
258 p_new->i_flags |= OBJECT_FLAGS_NODBG;
259 if( p_this->i_flags & OBJECT_FLAGS_QUIET )
260 p_new->i_flags |= OBJECT_FLAGS_QUIET;
261 if( p_this->i_flags & OBJECT_FLAGS_NOINTERACT )
262 p_new->i_flags |= OBJECT_FLAGS_NOINTERACT;
265 p_new->p_vars = (variable_t *)malloc( 16 * sizeof( variable_t ) );
269 if( i_type != VLC_OBJECT_ROOT )
274 if( i_type == VLC_OBJECT_ROOT )
276 /* If i_type is root, then p_new is actually p_libvlc_global */
277 p_new->p_libvlc_global = (libvlc_global_data_t*)p_new;
278 p_new->p_libvlc = NULL;
280 p_new->p_libvlc_global->i_counter = 0;
281 p_new->i_object_id = 0;
283 p_new->p_libvlc_global->i_objects = 1;
284 p_new->p_libvlc_global->pp_objects = malloc( sizeof(vlc_object_t *) );
285 p_new->p_libvlc_global->pp_objects[0] = p_new;
286 p_new->b_attached = VLC_TRUE;
290 p_new->p_libvlc_global = p_this->p_libvlc_global;
291 p_new->p_libvlc = ( i_type == VLC_OBJECT_LIBVLC ) ? (libvlc_int_t*)p_new
294 vlc_mutex_lock( &structure_lock );
296 p_new->p_libvlc_global->i_counter++;
297 p_new->i_object_id = p_new->p_libvlc_global->i_counter;
299 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
300 * useless to try and recover anything if pp_objects gets smashed. */
301 TAB_APPEND( p_new->p_libvlc_global->i_objects,
302 p_new->p_libvlc_global->pp_objects,
305 vlc_mutex_unlock( &structure_lock );
308 p_new->i_refcount = 0;
309 p_new->p_parent = NULL;
310 p_new->pp_children = NULL;
311 p_new->i_children = 0;
313 p_new->p_private = NULL;
315 /* Initialize mutexes and condvars */
316 vlc_mutex_init( p_new, &p_new->object_lock );
317 vlc_cond_init( p_new, &p_new->object_wait );
318 vlc_mutex_init( p_new, &p_new->var_lock );
320 if( i_type == VLC_OBJECT_ROOT )
322 vlc_mutex_init( p_new, &structure_lock );
324 var_Create( p_new, "list", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
325 var_AddCallback( p_new, "list", DumpCommand, NULL );
326 var_Create( p_new, "tree", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
327 var_AddCallback( p_new, "tree", DumpCommand, NULL );
334 ****************************************************************************
335 * Destroy a vlc object
337 * This function destroys an object that has been previously allocated with
338 * vlc_object_create. The object's refcount must be zero and it must not be
339 * attached to other objects in any way.
340 *****************************************************************************/
341 void __vlc_object_destroy( vlc_object_t *p_this )
345 if( p_this->i_children )
347 msg_Err( p_this, "cannot delete object (%i, %s) with children" ,
348 p_this->i_object_id, p_this->psz_object_name );
352 if( p_this->p_parent )
354 msg_Err( p_this, "cannot delete object (%i, %s) with a parent",
355 p_this->i_object_id, p_this->psz_object_name );
359 while( p_this->i_refcount )
363 /* Don't warn immediately ... 100ms seems OK */
367 "refcount is %i, delaying before deletion (id=%d,type=%d)",
368 p_this->i_refcount, p_this->i_object_id,
369 p_this->i_object_type );
371 else if( i_delay == 10 )
374 "refcount is %i, delaying again (id=%d,type=%d)",
375 p_this->i_refcount, p_this->i_object_id,
376 p_this->i_object_type );
378 else if( i_delay == 20 )
381 "waited too long, cancelling destruction (id=%d,type=%d)",
382 p_this->i_object_id, p_this->i_object_type );
389 /* Destroy the associated variables, starting from the end so that
390 * no memmove calls have to be done. */
391 while( p_this->i_vars )
393 var_Destroy( p_this, p_this->p_vars[p_this->i_vars - 1].psz_name );
396 free( p_this->p_vars );
397 vlc_mutex_destroy( &p_this->var_lock );
399 if( p_this->psz_header ) free( p_this->psz_header );
401 if( p_this->i_object_type == VLC_OBJECT_ROOT )
403 /* We are the root object ... no need to lock. */
404 free( p_this->p_libvlc_global->pp_objects );
405 p_this->p_libvlc_global->pp_objects = NULL;
406 p_this->p_libvlc_global->i_objects--;
408 vlc_mutex_destroy( &structure_lock );
414 vlc_mutex_lock( &structure_lock );
416 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
417 * useless to try and recover anything if pp_objects gets smashed. */
418 i_index = FindIndex( p_this, p_this->p_libvlc_global->pp_objects,
419 p_this->p_libvlc_global->i_objects );
420 REMOVE_ELEM( p_this->p_libvlc_global->pp_objects,
421 p_this->p_libvlc_global->i_objects, i_index );
423 vlc_mutex_unlock( &structure_lock );
426 vlc_mutex_destroy( &p_this->object_lock );
427 vlc_cond_destroy( &p_this->object_wait );
429 /* root is not dynamically allocated by vlc_object_create */
430 if( p_this->i_object_type != VLC_OBJECT_ROOT )
435 * find an object given its ID
437 * This function looks for the object whose i_object_id field is i_id. We
438 * use a dichotomy so that lookups are in log2(n).
439 *****************************************************************************/
440 void * __vlc_object_get( vlc_object_t *p_this, int i_id )
443 vlc_object_t **pp_objects;
445 vlc_mutex_lock( &structure_lock );
447 pp_objects = p_this->p_libvlc_global->pp_objects;
449 /* Perform our dichotomy */
450 for( i_max = p_this->p_libvlc_global->i_objects - 1 ; ; )
452 i_middle = i_max / 2;
454 if( pp_objects[i_middle]->i_object_id > i_id )
458 else if( pp_objects[i_middle]->i_object_id < i_id )
462 pp_objects += i_middle;
467 /* This happens when there are only two remaining objects */
468 if( pp_objects[i_middle+1]->i_object_id == i_id )
470 vlc_mutex_unlock( &structure_lock );
471 pp_objects[i_middle+1]->i_refcount++;
472 return pp_objects[i_middle+1];
479 vlc_mutex_unlock( &structure_lock );
480 pp_objects[i_middle]->i_refcount++;
481 return pp_objects[i_middle];
486 /* this means that i_max == i_middle, and since we have already
487 * tested pp_objects[i_middle]), p_found is properly set. */
492 vlc_mutex_unlock( &structure_lock );
497 ****************************************************************************
498 * find a typed object and increment its refcount
499 *****************************************************************************
500 * This function recursively looks for a given object type. i_mode can be one
501 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
502 *****************************************************************************/
503 void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
505 vlc_object_t *p_found;
507 vlc_mutex_lock( &structure_lock );
509 /* If we are of the requested type ourselves, don't look further */
510 if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
512 p_this->i_refcount++;
513 vlc_mutex_unlock( &structure_lock );
517 /* Otherwise, recursively look for the object */
518 if( (i_mode & 0x000f) == FIND_ANYWHERE )
520 vlc_object_t *p_root = p_this;
523 while( p_root->p_parent != NULL &&
524 p_root != VLC_OBJECT( p_this->p_libvlc ) )
526 p_root = p_root->p_parent;
529 p_found = FindObject( p_root, i_type, (i_mode & ~0x000f)|FIND_CHILD );
530 if( p_found == NULL && p_root != VLC_OBJECT( p_this->p_libvlc ) )
532 p_found = FindObject( VLC_OBJECT( p_this->p_libvlc ),
533 i_type, (i_mode & ~0x000f)|FIND_CHILD );
538 p_found = FindObject( p_this, i_type, i_mode );
541 vlc_mutex_unlock( &structure_lock );
547 ****************************************************************************
548 * increment an object refcount
549 *****************************************************************************/
550 void __vlc_object_yield( vlc_object_t *p_this )
552 vlc_mutex_lock( &structure_lock );
553 p_this->i_refcount++;
554 vlc_mutex_unlock( &structure_lock );
558 ****************************************************************************
559 * decrement an object refcount
560 *****************************************************************************/
561 void __vlc_object_release( vlc_object_t *p_this )
563 vlc_mutex_lock( &structure_lock );
564 p_this->i_refcount--;
565 vlc_mutex_unlock( &structure_lock );
569 ****************************************************************************
570 * attach object to a parent object
571 *****************************************************************************
572 * This function sets p_this as a child of p_parent, and p_parent as a parent
573 * of p_this. This link can be undone using vlc_object_detach.
574 *****************************************************************************/
575 void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
577 vlc_mutex_lock( &structure_lock );
579 /* Attach the parent to its child */
580 p_this->p_parent = p_parent;
582 /* Attach the child to its parent */
583 INSERT_ELEM( p_parent->pp_children, p_parent->i_children,
584 p_parent->i_children, p_this );
586 /* Climb up the tree to see whether we are connected with the root */
587 if( p_parent->b_attached )
589 SetAttachment( p_this, VLC_TRUE );
592 vlc_mutex_unlock( &structure_lock );
596 ****************************************************************************
597 * detach object from its parent
598 *****************************************************************************
599 * This function removes all links between an object and its parent.
600 *****************************************************************************/
601 void __vlc_object_detach( vlc_object_t *p_this )
603 vlc_mutex_lock( &structure_lock );
604 if( !p_this->p_parent )
606 msg_Err( p_this, "object is not attached" );
607 vlc_mutex_unlock( &structure_lock );
611 /* Climb up the tree to see whether we are connected with the root */
612 if( p_this->p_parent->b_attached )
614 SetAttachment( p_this, VLC_FALSE );
617 DetachObject( p_this );
618 vlc_mutex_unlock( &structure_lock );
622 ****************************************************************************
623 * find a list typed objects and increment their refcount
624 *****************************************************************************
625 * This function recursively looks for a given object type. i_mode can be one
626 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
627 *****************************************************************************/
628 vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
631 vlc_object_t **pp_current, **pp_end;
632 int i_count = 0, i_index = 0;
634 vlc_mutex_lock( &structure_lock );
636 /* Look for the objects */
637 switch( i_mode & 0x000f )
640 pp_current = p_this->p_libvlc_global->pp_objects;
641 pp_end = pp_current + p_this->p_libvlc_global->i_objects;
643 for( ; pp_current < pp_end ; pp_current++ )
645 if( (*pp_current)->b_attached
646 && (*pp_current)->i_object_type == i_type )
652 p_list = NewList( i_count );
653 pp_current = p_this->p_libvlc_global->pp_objects;
655 for( ; pp_current < pp_end ; pp_current++ )
657 if( (*pp_current)->b_attached
658 && (*pp_current)->i_object_type == i_type )
660 ListReplace( p_list, *pp_current, i_index );
661 if( i_index < i_count ) i_index++;
667 i_count = CountChildren( p_this, i_type );
668 p_list = NewList( i_count );
670 /* Check allocation was successful */
671 if( p_list->i_count != i_count )
673 msg_Err( p_this, "list allocation failed!" );
679 ListChildren( p_list, p_this, i_type );
683 msg_Err( p_this, "unimplemented!" );
684 p_list = NewList( 0 );
688 vlc_mutex_unlock( &structure_lock );
693 /*****************************************************************************
694 * DumpCommand: print the current vlc structure
695 *****************************************************************************
696 * This function prints either an ASCII tree showing the connections between
697 * vlc objects, and additional information such as their refcount, thread ID,
698 * etc. (command "tree"), or the same data as a simple list (command "list").
699 *****************************************************************************/
700 static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
701 vlc_value_t oldval, vlc_value_t newval, void *p_data )
703 if( *psz_cmd == 't' )
705 char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
706 vlc_object_t *p_object;
708 if( *newval.psz_string )
710 p_object = vlc_object_get( p_this, atoi(newval.psz_string) );
719 p_object = p_this->p_libvlc ? VLC_OBJECT(p_this->p_libvlc) : p_this;
722 vlc_mutex_lock( &structure_lock );
725 DumpStructure( p_object, 0, psz_foo );
727 vlc_mutex_unlock( &structure_lock );
729 if( *newval.psz_string )
731 vlc_object_release( p_this );
734 else if( *psz_cmd == 'l' )
736 vlc_object_t **pp_current, **pp_end;
738 vlc_mutex_lock( &structure_lock );
740 pp_current = p_this->p_libvlc_global->pp_objects;
741 pp_end = pp_current + p_this->p_libvlc_global->i_objects;
743 for( ; pp_current < pp_end ; pp_current++ )
745 if( (*pp_current)->b_attached )
747 PrintObject( *pp_current, "" );
751 printf( " o %.8i %s (not attached)\n",
752 (*pp_current)->i_object_id,
753 (*pp_current)->psz_object_type );
757 vlc_mutex_unlock( &structure_lock );
763 /*****************************************************************************
764 * vlc_list_release: free a list previously allocated by vlc_list_find
765 *****************************************************************************
766 * This function decreases the refcount of all objects in the list and
768 *****************************************************************************/
769 void vlc_list_release( vlc_list_t *p_list )
773 for( i_index = 0; i_index < p_list->i_count; i_index++ )
775 vlc_mutex_lock( &structure_lock );
777 p_list->p_values[i_index].p_object->i_refcount--;
779 vlc_mutex_unlock( &structure_lock );
782 free( p_list->p_values );
786 /* Following functions are local */
788 /*****************************************************************************
789 * FindIndex: find the index of an object in an array of objects
790 *****************************************************************************
791 * This function assumes that p_this can be found in pp_objects. It will not
792 * crash if p_this cannot be found, but will return a wrong value. It is your
793 * duty to check the return value if you are not certain that the object could
795 *****************************************************************************/
796 static int FindIndex( vlc_object_t *p_this,
797 vlc_object_t **pp_objects, int i_count )
799 int i_middle = i_count / 2;
806 if( pp_objects[i_middle] == p_this )
816 /* We take advantage of the sorted array */
817 if( pp_objects[i_middle]->i_object_id < p_this->i_object_id )
819 return i_middle + FindIndex( p_this, pp_objects + i_middle,
820 i_count - i_middle );
824 return FindIndex( p_this, pp_objects, i_middle );
828 static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
833 switch( i_mode & 0x000f )
836 p_tmp = p_this->p_parent;
839 if( p_tmp->i_object_type == i_type )
846 return FindObject( p_tmp, i_type, i_mode );
852 for( i = p_this->i_children; i--; )
854 p_tmp = p_this->pp_children[i];
855 if( p_tmp->i_object_type == i_type )
860 else if( p_tmp->i_children )
862 p_tmp = FindObject( p_tmp, i_type, i_mode );
872 /* Handled in vlc_object_find */
879 static void DetachObject( vlc_object_t *p_this )
881 vlc_object_t *p_parent = p_this->p_parent;
884 /* Remove p_this's parent */
885 p_this->p_parent = NULL;
887 /* Remove all of p_parent's children which are p_this */
888 for( i_index = p_parent->i_children ; i_index-- ; )
890 if( p_parent->pp_children[i_index] == p_this )
892 p_parent->i_children--;
893 for( i = i_index ; i < p_parent->i_children ; i++ )
895 p_parent->pp_children[i] = p_parent->pp_children[i+1];
900 if( p_parent->i_children )
902 p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children,
903 p_parent->i_children * sizeof(vlc_object_t *) );
907 free( p_parent->pp_children );
908 p_parent->pp_children = NULL;
912 /*****************************************************************************
913 * SetAttachment: recursively set the b_attached flag of a subtree.
914 *****************************************************************************
915 * This function is used by the attach and detach functions to propagate
916 * the b_attached flag in a subtree.
917 *****************************************************************************/
918 static void SetAttachment( vlc_object_t *p_this, vlc_bool_t b_attached )
922 for( i_index = p_this->i_children ; i_index-- ; )
924 SetAttachment( p_this->pp_children[i_index], b_attached );
927 p_this->b_attached = b_attached;
930 static void PrintObject( vlc_object_t *p_this, const char *psz_prefix )
932 char psz_children[20], psz_refcount[20], psz_thread[20], psz_name[50];
935 if( p_this->psz_object_name )
937 snprintf( psz_name, 50, " \"%s\"", p_this->psz_object_name );
942 psz_children[0] = '\0';
943 switch( p_this->i_children )
948 strcpy( psz_children, ", 1 child" );
951 snprintf( psz_children, 20,
952 ", %i children", p_this->i_children );
953 psz_children[19] = '\0';
957 psz_refcount[0] = '\0';
958 if( p_this->i_refcount )
960 snprintf( psz_refcount, 20, ", refcount %i", p_this->i_refcount );
961 psz_refcount[19] = '\0';
964 psz_thread[0] = '\0';
965 if( p_this->b_thread )
967 snprintf( psz_thread, 20, " (thread %d)", (int)p_this->thread_id );
968 psz_thread[19] = '\0';
971 printf( " %so %.8i %s%s%s%s%s\n", psz_prefix,
972 p_this->i_object_id, p_this->psz_object_type,
973 psz_name, psz_thread, psz_refcount, psz_children );
976 static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
979 char i_back = psz_foo[i_level];
980 psz_foo[i_level] = '\0';
982 PrintObject( p_this, psz_foo );
984 psz_foo[i_level] = i_back;
986 if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH )
988 msg_Warn( p_this, "structure tree is too deep" );
992 for( i = 0 ; i < p_this->i_children ; i++ )
996 psz_foo[i_level-1] = ' ';
998 if( psz_foo[i_level-2] == '`' )
1000 psz_foo[i_level-2] = ' ';
1004 if( i == p_this->i_children - 1 )
1006 psz_foo[i_level] = '`';
1010 psz_foo[i_level] = '|';
1013 psz_foo[i_level+1] = '-';
1014 psz_foo[i_level+2] = '\0';
1016 DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo );
1020 static vlc_list_t * NewList( int i_count )
1022 vlc_list_t * p_list = (vlc_list_t *)malloc( sizeof( vlc_list_t ) );
1023 if( p_list == NULL )
1028 p_list->i_count = i_count;
1032 p_list->p_values = NULL;
1036 p_list->p_values = malloc( i_count * sizeof( vlc_value_t ) );
1037 if( p_list->p_values == NULL )
1039 p_list->i_count = 0;
1046 static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
1049 if( p_list == NULL || i_index >= p_list->i_count )
1054 p_object->i_refcount++;
1056 p_list->p_values[i_index].p_object = p_object;
1061 /*static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
1063 if( p_list == NULL )
1068 p_list->p_values = realloc( p_list->p_values, (p_list->i_count + 1)
1069 * sizeof( vlc_value_t ) );
1070 if( p_list->p_values == NULL )
1072 p_list->i_count = 0;
1076 p_object->i_refcount++;
1078 p_list->p_values[p_list->i_count].p_object = p_object;
1084 static int CountChildren( 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 )
1098 if( p_tmp->i_children )
1100 i_count += CountChildren( p_tmp, i_type );
1107 static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type )
1109 vlc_object_t *p_tmp;
1112 for( i = 0; i < p_this->i_children; i++ )
1114 p_tmp = p_this->pp_children[i];
1116 if( p_tmp->i_object_type == i_type )
1118 ListReplace( p_list, p_tmp, p_list->i_count++ );
1121 if( p_tmp->i_children )
1123 ListChildren( p_list, p_tmp, i_type );