1 /*****************************************************************************
2 * objects.c: vlc_object_t handling
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
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"
43 #include "audio_output.h"
44 #include "aout_internal.h"
45 #include "stream_output.h"
47 #include "vlc_playlist.h"
48 #include "vlc_interface.h"
49 #include "vlc_codec.h"
50 #include "vlc_filter.h"
52 #include "vlc_httpd.h"
54 /*****************************************************************************
56 *****************************************************************************/
57 static int DumpCommand( vlc_object_t *, char const *,
58 vlc_value_t, vlc_value_t, void * );
60 static vlc_object_t * FindObject ( vlc_object_t *, int, int );
61 static void DetachObject ( vlc_object_t * );
62 static void PrintObject ( vlc_object_t *, const char * );
63 static void DumpStructure ( vlc_object_t *, int, char * );
64 static int FindIndex ( vlc_object_t *, vlc_object_t **, int );
65 static void SetAttachment ( vlc_object_t *, vlc_bool_t );
67 static vlc_list_t * NewList ( int );
68 static void ListReplace ( vlc_list_t *, vlc_object_t *, int );
69 static void ListAppend ( vlc_list_t *, vlc_object_t * );
70 static int CountChildren ( vlc_object_t *, int );
71 static void ListChildren ( vlc_list_t *, vlc_object_t *, int );
73 /*****************************************************************************
74 * Local structure lock
75 *****************************************************************************/
76 static vlc_mutex_t structure_lock;
78 /*****************************************************************************
79 * vlc_object_create: initialize a vlc object
80 *****************************************************************************
81 * This function allocates memory for a vlc object and initializes it. If
82 * i_type is not a known value such as VLC_OBJECT_ROOT, VLC_OBJECT_VOUT and
83 * so on, vlc_object_create will use its value for the object size.
84 *****************************************************************************/
87 * Initialize a vlc object
89 * This function allocates memory for a vlc object and initializes it. If
90 * i_type is not a known value such as VLC_OBJECT_ROOT, VLC_OBJECT_VOUT and
91 * so on, vlc_object_create will use its value for the object size.
93 void * __vlc_object_create( vlc_object_t *p_this, int i_type )
101 case VLC_OBJECT_ROOT:
102 i_size = sizeof(libvlc_t);
106 i_size = sizeof(vlc_t);
109 case VLC_OBJECT_MODULE:
110 i_size = sizeof(module_t);
113 case VLC_OBJECT_INTF:
114 i_size = sizeof(intf_thread_t);
115 psz_type = "interface";
117 case VLC_OBJECT_DIALOGS:
118 i_size = sizeof(intf_thread_t);
119 psz_type = "dialogs provider";
121 case VLC_OBJECT_PLAYLIST:
122 i_size = sizeof(playlist_t);
123 psz_type = "playlist";
125 case VLC_OBJECT_INPUT:
126 i_size = sizeof(input_thread_t);
129 case VLC_OBJECT_DEMUX:
130 i_size = sizeof(demux_t);
133 case VLC_OBJECT_STREAM:
134 i_size = sizeof(stream_t);
137 case VLC_OBJECT_ACCESS:
138 i_size = sizeof(access_t);
141 case VLC_OBJECT_DECODER:
142 i_size = sizeof(decoder_t);
143 psz_type = "decoder";
145 case VLC_OBJECT_PACKETIZER:
146 i_size = sizeof(decoder_t);
147 psz_type = "packetizer";
149 case VLC_OBJECT_ENCODER:
150 i_size = sizeof(encoder_t);
151 psz_type = "encoder";
153 case VLC_OBJECT_FILTER:
154 i_size = sizeof(filter_t);
157 case VLC_OBJECT_VOUT:
158 i_size = sizeof(vout_thread_t);
159 psz_type = "video output";
161 case VLC_OBJECT_AOUT:
162 i_size = sizeof(aout_instance_t);
163 psz_type = "audio output";
165 case VLC_OBJECT_SOUT:
166 i_size = sizeof(sout_instance_t);
167 psz_type = "stream output";
169 case VLC_OBJECT_HTTPD:
170 i_size = sizeof( httpd_t );
171 psz_type = "http daemon";
174 i_size = sizeof( vlm_t );
175 psz_type = "vlm dameon";
177 case VLC_OBJECT_OPENGL:
178 i_size = sizeof( vout_thread_t );
179 psz_type = "opengl provider";
181 case VLC_OBJECT_ANNOUNCE:
182 i_size = sizeof( announce_handler_t );
183 psz_type = "announce handler";
187 ? i_type > (int)sizeof(vlc_object_t)
188 ? i_type : (int)sizeof(vlc_object_t)
189 : (int)sizeof(vlc_object_t);
190 i_type = VLC_OBJECT_GENERIC;
191 psz_type = "generic";
195 if( i_type == VLC_OBJECT_ROOT )
201 p_new = malloc( i_size );
202 if( !p_new ) return NULL;
203 memset( p_new, 0, i_size );
206 p_new->i_object_type = i_type;
207 p_new->psz_object_type = psz_type;
209 p_new->psz_object_name = NULL;
211 p_new->b_die = VLC_FALSE;
212 p_new->b_error = VLC_FALSE;
213 p_new->b_dead = VLC_FALSE;
214 p_new->b_attached = VLC_FALSE;
215 p_new->b_force = VLC_FALSE;
218 p_new->p_vars = (variable_t *)malloc( 16 * sizeof( variable_t ) );
226 if( i_type == VLC_OBJECT_ROOT )
228 /* If i_type is root, then p_new is actually p_libvlc */
229 p_new->p_libvlc = (libvlc_t*)p_new;
232 p_new->p_libvlc->i_counter = 0;
233 p_new->i_object_id = 0;
235 p_new->p_libvlc->i_objects = 1;
236 p_new->p_libvlc->pp_objects = malloc( sizeof(vlc_object_t *) );
237 p_new->p_libvlc->pp_objects[0] = p_new;
238 p_new->b_attached = VLC_TRUE;
242 p_new->p_libvlc = p_this->p_libvlc;
243 p_new->p_vlc = ( i_type == VLC_OBJECT_VLC ) ? (vlc_t*)p_new
246 vlc_mutex_lock( &structure_lock );
248 p_new->p_libvlc->i_counter++;
249 p_new->i_object_id = p_new->p_libvlc->i_counter;
251 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
252 * useless to try and recover anything if pp_objects gets smashed. */
253 INSERT_ELEM( p_new->p_libvlc->pp_objects,
254 p_new->p_libvlc->i_objects,
255 p_new->p_libvlc->i_objects,
258 vlc_mutex_unlock( &structure_lock );
261 p_new->i_refcount = 0;
262 p_new->p_parent = NULL;
263 p_new->pp_children = NULL;
264 p_new->i_children = 0;
266 p_new->p_private = NULL;
268 /* Initialize mutexes and condvars */
269 vlc_mutex_init( p_new, &p_new->object_lock );
270 vlc_cond_init( p_new, &p_new->object_wait );
271 vlc_mutex_init( p_new, &p_new->var_lock );
273 if( i_type == VLC_OBJECT_ROOT )
275 vlc_mutex_init( p_new, &structure_lock );
277 var_Create( p_new, "list", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
278 var_AddCallback( p_new, "list", DumpCommand, NULL );
279 var_Create( p_new, "tree", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
280 var_AddCallback( p_new, "tree", DumpCommand, NULL );
287 ****************************************************************************
288 * Destroy a vlc object
290 * This function destroys an object that has been previously allocated with
291 * vlc_object_create. The object's refcount must be zero and it must not be
292 * attached to other objects in any way.
293 *****************************************************************************/
294 void __vlc_object_destroy( vlc_object_t *p_this )
298 if( p_this->i_children )
300 msg_Err( p_this, "cannot delete object (%i, %s) with children" ,
301 p_this->i_object_id, p_this->psz_object_name );
305 if( p_this->p_parent )
307 msg_Err( p_this, "cannot delete object (%i, %s) with a parent",
308 p_this->i_object_id, p_this->psz_object_name );
312 while( p_this->i_refcount )
316 /* Don't warn immediately ... 100ms seems OK */
319 msg_Warn( p_this, "refcount is %i, delaying before deletion",
320 p_this->i_refcount );
322 else if( i_delay == 12 )
324 msg_Err( p_this, "refcount is %i, I have a bad feeling about this",
325 p_this->i_refcount );
327 else if( i_delay == 42 )
329 msg_Err( p_this, "we waited too long, cancelling destruction" );
336 /* Destroy the associated variables, starting from the end so that
337 * no memmove calls have to be done. */
338 while( p_this->i_vars )
340 var_Destroy( p_this, p_this->p_vars[p_this->i_vars - 1].psz_name );
343 free( p_this->p_vars );
344 vlc_mutex_destroy( &p_this->var_lock );
346 if( p_this->i_object_type == VLC_OBJECT_ROOT )
348 /* We are the root object ... no need to lock. */
349 free( p_this->p_libvlc->pp_objects );
350 p_this->p_libvlc->pp_objects = NULL;
351 p_this->p_libvlc->i_objects--;
353 vlc_mutex_destroy( &structure_lock );
359 vlc_mutex_lock( &structure_lock );
361 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
362 * useless to try and recover anything if pp_objects gets smashed. */
363 i_index = FindIndex( p_this, p_this->p_libvlc->pp_objects,
364 p_this->p_libvlc->i_objects );
365 REMOVE_ELEM( p_this->p_libvlc->pp_objects,
366 p_this->p_libvlc->i_objects, i_index );
368 vlc_mutex_unlock( &structure_lock );
371 vlc_mutex_destroy( &p_this->object_lock );
372 vlc_cond_destroy( &p_this->object_wait );
378 * find an object given its ID
380 * This function looks for the object whose i_object_id field is i_id. We
381 * use a dichotomy so that lookups are in log2(n).
382 *****************************************************************************/
383 void * __vlc_object_get( vlc_object_t *p_this, int i_id )
386 vlc_object_t **pp_objects;
388 vlc_mutex_lock( &structure_lock );
390 pp_objects = p_this->p_libvlc->pp_objects;
392 /* Perform our dichotomy */
393 for( i_max = p_this->p_libvlc->i_objects - 1 ; ; )
395 i_middle = i_max / 2;
397 if( pp_objects[i_middle]->i_object_id > i_id )
401 else if( pp_objects[i_middle]->i_object_id < i_id )
405 pp_objects += i_middle;
410 /* This happens when there are only two remaining objects */
411 if( pp_objects[i_middle+1]->i_object_id == i_id )
413 vlc_mutex_unlock( &structure_lock );
414 pp_objects[i_middle+1]->i_refcount++;
415 return pp_objects[i_middle+1];
422 vlc_mutex_unlock( &structure_lock );
423 pp_objects[i_middle]->i_refcount++;
424 return pp_objects[i_middle];
429 /* this means that i_max == i_middle, and since we have already
430 * tested pp_objects[i_middle]), p_found is properly set. */
435 vlc_mutex_unlock( &structure_lock );
440 ****************************************************************************
441 * find a typed object and increment its refcount
442 *****************************************************************************
443 * This function recursively looks for a given object type. i_mode can be one
444 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
445 *****************************************************************************/
446 void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
448 vlc_object_t *p_found;
450 vlc_mutex_lock( &structure_lock );
452 /* If we are of the requested type ourselves, don't look further */
453 if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
455 p_this->i_refcount++;
456 vlc_mutex_unlock( &structure_lock );
460 /* Otherwise, recursively look for the object */
461 if( (i_mode & 0x000f) == FIND_ANYWHERE )
463 vlc_object_t *p_root = p_this;
466 while( p_root->p_parent != NULL &&
467 p_root != VLC_OBJECT( p_this->p_vlc ) )
469 p_root = p_root->p_parent;
472 p_found = FindObject( p_root, i_type, (i_mode & ~0x000f)|FIND_CHILD );
473 if( p_found == NULL && p_root != VLC_OBJECT( p_this->p_vlc ) )
475 p_found = FindObject( VLC_OBJECT( p_this->p_vlc ),
476 i_type, (i_mode & ~0x000f)|FIND_CHILD );
481 p_found = FindObject( p_this, i_type, i_mode );
484 vlc_mutex_unlock( &structure_lock );
490 ****************************************************************************
491 * increment an object refcount
492 *****************************************************************************/
493 void __vlc_object_yield( vlc_object_t *p_this )
495 vlc_mutex_lock( &structure_lock );
496 p_this->i_refcount++;
497 vlc_mutex_unlock( &structure_lock );
501 ****************************************************************************
502 * decrement an object refcount
503 *****************************************************************************/
504 void __vlc_object_release( vlc_object_t *p_this )
506 vlc_mutex_lock( &structure_lock );
507 p_this->i_refcount--;
508 vlc_mutex_unlock( &structure_lock );
512 ****************************************************************************
513 * attach object to a parent object
514 *****************************************************************************
515 * This function sets p_this as a child of p_parent, and p_parent as a parent
516 * of p_this. This link can be undone using vlc_object_detach.
517 *****************************************************************************/
518 void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
520 vlc_mutex_lock( &structure_lock );
522 /* Attach the parent to its child */
523 p_this->p_parent = p_parent;
525 /* Attach the child to its parent */
526 INSERT_ELEM( p_parent->pp_children, p_parent->i_children,
527 p_parent->i_children, p_this );
529 /* Climb up the tree to see whether we are connected with the root */
530 if( p_parent->b_attached )
532 SetAttachment( p_this, VLC_TRUE );
535 vlc_mutex_unlock( &structure_lock );
539 ****************************************************************************
540 * detach object from its parent
541 *****************************************************************************
542 * This function removes all links between an object and its parent.
543 *****************************************************************************/
544 void __vlc_object_detach( vlc_object_t *p_this )
546 vlc_mutex_lock( &structure_lock );
547 if( !p_this->p_parent )
549 msg_Err( p_this, "object is not attached" );
550 vlc_mutex_unlock( &structure_lock );
554 /* Climb up the tree to see whether we are connected with the root */
555 if( p_this->p_parent->b_attached )
557 SetAttachment( p_this, VLC_FALSE );
560 DetachObject( p_this );
561 vlc_mutex_unlock( &structure_lock );
565 ****************************************************************************
566 * find a list typed objects and increment their refcount
567 *****************************************************************************
568 * This function recursively looks for a given object type. i_mode can be one
569 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
570 *****************************************************************************/
571 vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
574 vlc_object_t **pp_current, **pp_end;
575 int i_count = 0, i_index = 0;
577 vlc_mutex_lock( &structure_lock );
579 /* Look for the objects */
580 switch( i_mode & 0x000f )
583 pp_current = p_this->p_libvlc->pp_objects;
584 pp_end = pp_current + p_this->p_libvlc->i_objects;
586 for( ; pp_current < pp_end ; pp_current++ )
588 if( (*pp_current)->b_attached
589 && (*pp_current)->i_object_type == i_type )
595 p_list = NewList( i_count );
596 pp_current = p_this->p_libvlc->pp_objects;
598 for( ; pp_current < pp_end ; pp_current++ )
600 if( (*pp_current)->b_attached
601 && (*pp_current)->i_object_type == i_type )
603 ListReplace( p_list, *pp_current, i_index );
604 if( i_index < i_count ) i_index++;
610 i_count = CountChildren( p_this, i_type );
611 p_list = NewList( i_count );
613 /* Check allocation was successful */
614 if( p_list->i_count != i_count )
616 msg_Err( p_this, "list allocation failed!" );
622 ListChildren( p_list, p_this, i_type );
626 msg_Err( p_this, "unimplemented!" );
627 p_list = NewList( 0 );
631 vlc_mutex_unlock( &structure_lock );
636 /*****************************************************************************
637 * DumpCommand: print the current vlc structure
638 *****************************************************************************
639 * This function prints either an ASCII tree showing the connections between
640 * vlc objects, and additional information such as their refcount, thread ID,
641 * etc. (command "tree"), or the same data as a simple list (command "list").
642 *****************************************************************************/
643 static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
644 vlc_value_t oldval, vlc_value_t newval, void *p_data )
646 if( *psz_cmd == 't' )
648 char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
649 vlc_object_t *p_object;
651 if( *newval.psz_string )
653 p_object = vlc_object_get( p_this, atoi(newval.psz_string) );
662 p_object = p_this->p_vlc ? VLC_OBJECT(p_this->p_vlc) : p_this;
665 vlc_mutex_lock( &structure_lock );
668 DumpStructure( p_object, 0, psz_foo );
670 vlc_mutex_unlock( &structure_lock );
672 if( *newval.psz_string )
674 vlc_object_release( p_this );
677 else if( *psz_cmd == 'l' )
679 vlc_object_t **pp_current, **pp_end;
681 vlc_mutex_lock( &structure_lock );
683 pp_current = p_this->p_libvlc->pp_objects;
684 pp_end = pp_current + p_this->p_libvlc->i_objects;
686 for( ; pp_current < pp_end ; pp_current++ )
688 if( (*pp_current)->b_attached )
690 PrintObject( *pp_current, "" );
694 printf( " o %.8i %s (not attached)\n",
695 (*pp_current)->i_object_id,
696 (*pp_current)->psz_object_type );
700 vlc_mutex_unlock( &structure_lock );
706 /*****************************************************************************
707 * vlc_list_release: free a list previously allocated by vlc_list_find
708 *****************************************************************************
709 * This function decreases the refcount of all objects in the list and
711 *****************************************************************************/
712 void vlc_list_release( vlc_list_t *p_list )
716 for( i_index = 0; i_index < p_list->i_count; i_index++ )
718 vlc_mutex_lock( &structure_lock );
720 p_list->p_values[i_index].p_object->i_refcount--;
722 vlc_mutex_unlock( &structure_lock );
725 free( p_list->p_values );
729 /* Following functions are local */
731 /*****************************************************************************
732 * FindIndex: find the index of an object in an array of objects
733 *****************************************************************************
734 * This function assumes that p_this can be found in pp_objects. It will not
735 * crash if p_this cannot be found, but will return a wrong value. It is your
736 * duty to check the return value if you are not certain that the object could
738 *****************************************************************************/
739 static int FindIndex( vlc_object_t *p_this,
740 vlc_object_t **pp_objects, int i_count )
742 int i_middle = i_count / 2;
749 if( pp_objects[i_middle] == p_this )
759 /* We take advantage of the sorted array */
760 if( pp_objects[i_middle]->i_object_id < p_this->i_object_id )
762 return i_middle + FindIndex( p_this, pp_objects + i_middle,
763 i_count - i_middle );
767 return FindIndex( p_this, pp_objects, i_middle );
771 static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
776 switch( i_mode & 0x000f )
779 p_tmp = p_this->p_parent;
782 if( p_tmp->i_object_type == i_type )
789 return FindObject( p_tmp, i_type, i_mode );
795 for( i = p_this->i_children; i--; )
797 p_tmp = p_this->pp_children[i];
798 if( p_tmp->i_object_type == i_type )
803 else if( p_tmp->i_children )
805 p_tmp = FindObject( p_tmp, i_type, i_mode );
815 /* Handled in vlc_object_find */
822 static void DetachObject( vlc_object_t *p_this )
824 vlc_object_t *p_parent = p_this->p_parent;
827 /* Remove p_this's parent */
828 p_this->p_parent = NULL;
830 /* Remove all of p_parent's children which are p_this */
831 for( i_index = p_parent->i_children ; i_index-- ; )
833 if( p_parent->pp_children[i_index] == p_this )
835 p_parent->i_children--;
836 for( i = i_index ; i < p_parent->i_children ; i++ )
838 p_parent->pp_children[i] = p_parent->pp_children[i+1];
843 if( p_parent->i_children )
845 p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children,
846 p_parent->i_children * sizeof(vlc_object_t *) );
850 free( p_parent->pp_children );
851 p_parent->pp_children = NULL;
855 /*****************************************************************************
856 * SetAttachment: recursively set the b_attached flag of a subtree.
857 *****************************************************************************
858 * This function is used by the attach and detach functions to propagate
859 * the b_attached flag in a subtree.
860 *****************************************************************************/
861 static void SetAttachment( vlc_object_t *p_this, vlc_bool_t b_attached )
865 for( i_index = p_this->i_children ; i_index-- ; )
867 SetAttachment( p_this->pp_children[i_index], b_attached );
870 p_this->b_attached = b_attached;
873 static void PrintObject( vlc_object_t *p_this, const char *psz_prefix )
875 char psz_children[20], psz_refcount[20], psz_thread[20], psz_name[50];
878 if( p_this->psz_object_name )
880 snprintf( psz_name, 50, " \"%s\"", p_this->psz_object_name );
885 psz_children[0] = '\0';
886 switch( p_this->i_children )
891 strcpy( psz_children, ", 1 child" );
894 snprintf( psz_children, 20,
895 ", %i children", p_this->i_children );
896 psz_children[19] = '\0';
900 psz_refcount[0] = '\0';
901 if( p_this->i_refcount )
903 snprintf( psz_refcount, 20, ", refcount %i", p_this->i_refcount );
904 psz_refcount[19] = '\0';
907 psz_thread[0] = '\0';
908 if( p_this->b_thread )
910 snprintf( psz_thread, 20, " (thread %d)", (int)p_this->thread_id );
911 psz_thread[19] = '\0';
914 printf( " %so %.8i %s%s%s%s%s\n", psz_prefix,
915 p_this->i_object_id, p_this->psz_object_type,
916 psz_name, psz_thread, psz_refcount, psz_children );
919 static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
922 char i_back = psz_foo[i_level];
923 psz_foo[i_level] = '\0';
925 PrintObject( p_this, psz_foo );
927 psz_foo[i_level] = i_back;
929 if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH )
931 msg_Warn( p_this, "structure tree is too deep" );
935 for( i = 0 ; i < p_this->i_children ; i++ )
939 psz_foo[i_level-1] = ' ';
941 if( psz_foo[i_level-2] == '`' )
943 psz_foo[i_level-2] = ' ';
947 if( i == p_this->i_children - 1 )
949 psz_foo[i_level] = '`';
953 psz_foo[i_level] = '|';
956 psz_foo[i_level+1] = '-';
957 psz_foo[i_level+2] = '\0';
959 DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo );
963 static vlc_list_t * NewList( int i_count )
965 vlc_list_t * p_list = (vlc_list_t *)malloc( sizeof( vlc_list_t ) );
971 p_list->i_count = i_count;
975 p_list->p_values = NULL;
979 p_list->p_values = malloc( i_count * sizeof( vlc_value_t ) );
980 if( p_list->p_values == NULL )
989 static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
992 if( p_list == NULL || i_index >= p_list->i_count )
997 p_object->i_refcount++;
999 p_list->p_values[i_index].p_object = p_object;
1004 static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
1006 if( p_list == NULL )
1011 p_list->p_values = realloc( p_list->p_values, (p_list->i_count + 1)
1012 * sizeof( vlc_value_t ) );
1013 if( p_list->p_values == NULL )
1015 p_list->i_count = 0;
1019 p_object->i_refcount++;
1021 p_list->p_values[p_list->i_count].p_object = p_object;
1027 static int CountChildren( vlc_object_t *p_this, int i_type )
1029 vlc_object_t *p_tmp;
1032 for( i = 0; i < p_this->i_children; i++ )
1034 p_tmp = p_this->pp_children[i];
1036 if( p_tmp->i_object_type == i_type )
1041 if( p_tmp->i_children )
1043 i_count += CountChildren( p_tmp, i_type );
1050 static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type )
1052 vlc_object_t *p_tmp;
1055 for( i = 0; i < p_this->i_children; i++ )
1057 p_tmp = p_this->pp_children[i];
1059 if( p_tmp->i_object_type == i_type )
1061 ListReplace( p_list, p_tmp, p_list->i_count++ );
1064 if( p_tmp->i_children )
1066 ListChildren( p_list, p_tmp, i_type );