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"
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"
57 /*****************************************************************************
59 *****************************************************************************/
60 static int DumpCommand( vlc_object_t *, char const *,
61 vlc_value_t, vlc_value_t, void * );
63 static vlc_object_t * FindObject ( vlc_object_t *, int, int );
64 static void DetachObject ( vlc_object_t * );
65 static void PrintObject ( vlc_object_t *, const char * );
66 static void DumpStructure ( vlc_object_t *, int, char * );
67 static int FindIndex ( vlc_object_t *, vlc_object_t **, int );
68 static void SetAttachment ( vlc_object_t *, vlc_bool_t );
70 static vlc_list_t * NewList ( int );
71 static void ListReplace ( vlc_list_t *, vlc_object_t *, int );
72 static void ListAppend ( vlc_list_t *, vlc_object_t * );
73 static int CountChildren ( vlc_object_t *, int );
74 static void ListChildren ( vlc_list_t *, vlc_object_t *, int );
76 /*****************************************************************************
77 * Local structure lock
78 *****************************************************************************/
79 static vlc_mutex_t structure_lock;
81 /*****************************************************************************
82 * vlc_object_create: initialize a vlc object
83 *****************************************************************************
84 * This function allocates memory for a vlc object and initializes it. If
85 * i_type is not a known value such as VLC_OBJECT_ROOT, VLC_OBJECT_VOUT and
86 * so on, vlc_object_create will use its value for the object size.
87 *****************************************************************************/
90 * Initialize a vlc object
92 * This function allocates memory for a vlc object and initializes it. If
93 * i_type is not a known value such as VLC_OBJECT_ROOT, VLC_OBJECT_VOUT and
94 * so on, vlc_object_create will use its value for the object size.
96 void * __vlc_object_create( vlc_object_t *p_this, int i_type )
104 case VLC_OBJECT_ROOT:
105 i_size = sizeof(libvlc_t);
109 i_size = sizeof(vlc_t);
112 case VLC_OBJECT_MODULE:
113 i_size = sizeof(module_t);
116 case VLC_OBJECT_INTF:
117 i_size = sizeof(intf_thread_t);
118 psz_type = "interface";
120 case VLC_OBJECT_DIALOGS:
121 i_size = sizeof(intf_thread_t);
122 psz_type = "dialogs provider";
124 case VLC_OBJECT_PLAYLIST:
125 i_size = sizeof(playlist_t);
126 psz_type = "playlist";
128 case VLC_OBJECT_INPUT:
129 i_size = sizeof(input_thread_t);
132 case VLC_OBJECT_DEMUX:
133 i_size = sizeof(demux_t);
136 case VLC_OBJECT_STREAM:
137 i_size = sizeof(stream_t);
140 case VLC_OBJECT_ACCESS:
141 i_size = sizeof(access_t);
144 case VLC_OBJECT_DECODER:
145 i_size = sizeof(decoder_t);
146 psz_type = "decoder";
148 case VLC_OBJECT_PACKETIZER:
149 i_size = sizeof(decoder_t);
150 psz_type = "packetizer";
152 case VLC_OBJECT_ENCODER:
153 i_size = sizeof(encoder_t);
154 psz_type = "encoder";
156 case VLC_OBJECT_FILTER:
157 i_size = sizeof(filter_t);
160 case VLC_OBJECT_VOUT:
161 i_size = sizeof(vout_thread_t);
162 psz_type = "video output";
165 i_size = sizeof(spu_t);
166 psz_type = "subpicture unit";
168 case VLC_OBJECT_AOUT:
169 i_size = sizeof(aout_instance_t);
170 psz_type = "audio output";
172 case VLC_OBJECT_SOUT:
173 i_size = sizeof(sout_instance_t);
174 psz_type = "stream output";
176 case VLC_OBJECT_HTTPD:
177 i_size = sizeof( httpd_t );
178 psz_type = "http daemon";
181 i_size = sizeof( vlm_t );
182 psz_type = "vlm dameon";
185 i_size = sizeof( vod_t );
186 psz_type = "vod server";
188 case VLC_OBJECT_OPENGL:
189 i_size = sizeof( vout_thread_t );
190 psz_type = "opengl provider";
192 case VLC_OBJECT_ANNOUNCE:
193 i_size = sizeof( announce_handler_t );
194 psz_type = "announce handler";
198 ? i_type > (int)sizeof(vlc_object_t)
199 ? i_type : (int)sizeof(vlc_object_t)
200 : (int)sizeof(vlc_object_t);
201 i_type = VLC_OBJECT_GENERIC;
202 psz_type = "generic";
206 if( i_type == VLC_OBJECT_ROOT )
212 p_new = malloc( i_size );
213 if( !p_new ) return NULL;
214 memset( p_new, 0, i_size );
217 p_new->i_object_type = i_type;
218 p_new->psz_object_type = psz_type;
220 p_new->psz_object_name = NULL;
222 p_new->b_die = VLC_FALSE;
223 p_new->b_error = VLC_FALSE;
224 p_new->b_dead = VLC_FALSE;
225 p_new->b_attached = VLC_FALSE;
226 p_new->b_force = VLC_FALSE;
229 p_new->p_vars = (variable_t *)malloc( 16 * sizeof( variable_t ) );
237 if( i_type == VLC_OBJECT_ROOT )
239 /* If i_type is root, then p_new is actually p_libvlc */
240 p_new->p_libvlc = (libvlc_t*)p_new;
243 p_new->p_libvlc->i_counter = 0;
244 p_new->i_object_id = 0;
246 p_new->p_libvlc->i_objects = 1;
247 p_new->p_libvlc->pp_objects = malloc( sizeof(vlc_object_t *) );
248 p_new->p_libvlc->pp_objects[0] = p_new;
249 p_new->b_attached = VLC_TRUE;
253 p_new->p_libvlc = p_this->p_libvlc;
254 p_new->p_vlc = ( i_type == VLC_OBJECT_VLC ) ? (vlc_t*)p_new
257 vlc_mutex_lock( &structure_lock );
259 p_new->p_libvlc->i_counter++;
260 p_new->i_object_id = p_new->p_libvlc->i_counter;
262 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
263 * useless to try and recover anything if pp_objects gets smashed. */
264 INSERT_ELEM( p_new->p_libvlc->pp_objects,
265 p_new->p_libvlc->i_objects,
266 p_new->p_libvlc->i_objects,
269 vlc_mutex_unlock( &structure_lock );
272 p_new->i_refcount = 0;
273 p_new->p_parent = NULL;
274 p_new->pp_children = NULL;
275 p_new->i_children = 0;
277 p_new->p_private = NULL;
279 /* Initialize mutexes and condvars */
280 vlc_mutex_init( p_new, &p_new->object_lock );
281 vlc_cond_init( p_new, &p_new->object_wait );
282 vlc_mutex_init( p_new, &p_new->var_lock );
284 if( i_type == VLC_OBJECT_ROOT )
286 vlc_mutex_init( p_new, &structure_lock );
288 var_Create( p_new, "list", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
289 var_AddCallback( p_new, "list", DumpCommand, NULL );
290 var_Create( p_new, "tree", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
291 var_AddCallback( p_new, "tree", DumpCommand, NULL );
298 ****************************************************************************
299 * Destroy a vlc object
301 * This function destroys an object that has been previously allocated with
302 * vlc_object_create. The object's refcount must be zero and it must not be
303 * attached to other objects in any way.
304 *****************************************************************************/
305 void __vlc_object_destroy( vlc_object_t *p_this )
309 if( p_this->i_children )
311 msg_Err( p_this, "cannot delete object (%i, %s) with children" ,
312 p_this->i_object_id, p_this->psz_object_name );
316 if( p_this->p_parent )
318 msg_Err( p_this, "cannot delete object (%i, %s) with a parent",
319 p_this->i_object_id, p_this->psz_object_name );
323 while( p_this->i_refcount )
327 /* Don't warn immediately ... 100ms seems OK */
330 msg_Warn( p_this, "refcount is %i, delaying before deletion",
331 p_this->i_refcount );
333 else if( i_delay == 12 )
335 msg_Err( p_this, "refcount is %i, I have a bad feeling about this",
336 p_this->i_refcount );
338 else if( i_delay == 42 )
340 msg_Err( p_this, "we waited too long, cancelling destruction" );
347 /* Destroy the associated variables, starting from the end so that
348 * no memmove calls have to be done. */
349 while( p_this->i_vars )
351 var_Destroy( p_this, p_this->p_vars[p_this->i_vars - 1].psz_name );
354 free( p_this->p_vars );
355 vlc_mutex_destroy( &p_this->var_lock );
357 if( p_this->i_object_type == VLC_OBJECT_ROOT )
359 /* We are the root object ... no need to lock. */
360 free( p_this->p_libvlc->pp_objects );
361 p_this->p_libvlc->pp_objects = NULL;
362 p_this->p_libvlc->i_objects--;
364 vlc_mutex_destroy( &structure_lock );
370 vlc_mutex_lock( &structure_lock );
372 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
373 * useless to try and recover anything if pp_objects gets smashed. */
374 i_index = FindIndex( p_this, p_this->p_libvlc->pp_objects,
375 p_this->p_libvlc->i_objects );
376 REMOVE_ELEM( p_this->p_libvlc->pp_objects,
377 p_this->p_libvlc->i_objects, i_index );
379 vlc_mutex_unlock( &structure_lock );
382 vlc_mutex_destroy( &p_this->object_lock );
383 vlc_cond_destroy( &p_this->object_wait );
389 * find an object given its ID
391 * This function looks for the object whose i_object_id field is i_id. We
392 * use a dichotomy so that lookups are in log2(n).
393 *****************************************************************************/
394 void * __vlc_object_get( vlc_object_t *p_this, int i_id )
397 vlc_object_t **pp_objects;
399 vlc_mutex_lock( &structure_lock );
401 pp_objects = p_this->p_libvlc->pp_objects;
403 /* Perform our dichotomy */
404 for( i_max = p_this->p_libvlc->i_objects - 1 ; ; )
406 i_middle = i_max / 2;
408 if( pp_objects[i_middle]->i_object_id > i_id )
412 else if( pp_objects[i_middle]->i_object_id < i_id )
416 pp_objects += i_middle;
421 /* This happens when there are only two remaining objects */
422 if( pp_objects[i_middle+1]->i_object_id == i_id )
424 vlc_mutex_unlock( &structure_lock );
425 pp_objects[i_middle+1]->i_refcount++;
426 return pp_objects[i_middle+1];
433 vlc_mutex_unlock( &structure_lock );
434 pp_objects[i_middle]->i_refcount++;
435 return pp_objects[i_middle];
440 /* this means that i_max == i_middle, and since we have already
441 * tested pp_objects[i_middle]), p_found is properly set. */
446 vlc_mutex_unlock( &structure_lock );
451 ****************************************************************************
452 * find a typed object and increment its refcount
453 *****************************************************************************
454 * This function recursively looks for a given object type. i_mode can be one
455 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
456 *****************************************************************************/
457 void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
459 vlc_object_t *p_found;
461 vlc_mutex_lock( &structure_lock );
463 /* If we are of the requested type ourselves, don't look further */
464 if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
466 p_this->i_refcount++;
467 vlc_mutex_unlock( &structure_lock );
471 /* Otherwise, recursively look for the object */
472 if( (i_mode & 0x000f) == FIND_ANYWHERE )
474 vlc_object_t *p_root = p_this;
477 while( p_root->p_parent != NULL &&
478 p_root != VLC_OBJECT( p_this->p_vlc ) )
480 p_root = p_root->p_parent;
483 p_found = FindObject( p_root, i_type, (i_mode & ~0x000f)|FIND_CHILD );
484 if( p_found == NULL && p_root != VLC_OBJECT( p_this->p_vlc ) )
486 p_found = FindObject( VLC_OBJECT( p_this->p_vlc ),
487 i_type, (i_mode & ~0x000f)|FIND_CHILD );
492 p_found = FindObject( p_this, i_type, i_mode );
495 vlc_mutex_unlock( &structure_lock );
501 ****************************************************************************
502 * increment an object refcount
503 *****************************************************************************/
504 void __vlc_object_yield( vlc_object_t *p_this )
506 vlc_mutex_lock( &structure_lock );
507 p_this->i_refcount++;
508 vlc_mutex_unlock( &structure_lock );
512 ****************************************************************************
513 * decrement an object refcount
514 *****************************************************************************/
515 void __vlc_object_release( vlc_object_t *p_this )
517 vlc_mutex_lock( &structure_lock );
518 p_this->i_refcount--;
519 vlc_mutex_unlock( &structure_lock );
523 ****************************************************************************
524 * attach object to a parent object
525 *****************************************************************************
526 * This function sets p_this as a child of p_parent, and p_parent as a parent
527 * of p_this. This link can be undone using vlc_object_detach.
528 *****************************************************************************/
529 void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
531 vlc_mutex_lock( &structure_lock );
533 /* Attach the parent to its child */
534 p_this->p_parent = p_parent;
536 /* Attach the child to its parent */
537 INSERT_ELEM( p_parent->pp_children, p_parent->i_children,
538 p_parent->i_children, p_this );
540 /* Climb up the tree to see whether we are connected with the root */
541 if( p_parent->b_attached )
543 SetAttachment( p_this, VLC_TRUE );
546 vlc_mutex_unlock( &structure_lock );
550 ****************************************************************************
551 * detach object from its parent
552 *****************************************************************************
553 * This function removes all links between an object and its parent.
554 *****************************************************************************/
555 void __vlc_object_detach( vlc_object_t *p_this )
557 vlc_mutex_lock( &structure_lock );
558 if( !p_this->p_parent )
560 msg_Err( p_this, "object is not attached" );
561 vlc_mutex_unlock( &structure_lock );
565 /* Climb up the tree to see whether we are connected with the root */
566 if( p_this->p_parent->b_attached )
568 SetAttachment( p_this, VLC_FALSE );
571 DetachObject( p_this );
572 vlc_mutex_unlock( &structure_lock );
576 ****************************************************************************
577 * find a list typed objects and increment their refcount
578 *****************************************************************************
579 * This function recursively looks for a given object type. i_mode can be one
580 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
581 *****************************************************************************/
582 vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
585 vlc_object_t **pp_current, **pp_end;
586 int i_count = 0, i_index = 0;
588 vlc_mutex_lock( &structure_lock );
590 /* Look for the objects */
591 switch( i_mode & 0x000f )
594 pp_current = p_this->p_libvlc->pp_objects;
595 pp_end = pp_current + p_this->p_libvlc->i_objects;
597 for( ; pp_current < pp_end ; pp_current++ )
599 if( (*pp_current)->b_attached
600 && (*pp_current)->i_object_type == i_type )
606 p_list = NewList( i_count );
607 pp_current = p_this->p_libvlc->pp_objects;
609 for( ; pp_current < pp_end ; pp_current++ )
611 if( (*pp_current)->b_attached
612 && (*pp_current)->i_object_type == i_type )
614 ListReplace( p_list, *pp_current, i_index );
615 if( i_index < i_count ) i_index++;
621 i_count = CountChildren( p_this, i_type );
622 p_list = NewList( i_count );
624 /* Check allocation was successful */
625 if( p_list->i_count != i_count )
627 msg_Err( p_this, "list allocation failed!" );
633 ListChildren( p_list, p_this, i_type );
637 msg_Err( p_this, "unimplemented!" );
638 p_list = NewList( 0 );
642 vlc_mutex_unlock( &structure_lock );
647 /*****************************************************************************
648 * DumpCommand: print the current vlc structure
649 *****************************************************************************
650 * This function prints either an ASCII tree showing the connections between
651 * vlc objects, and additional information such as their refcount, thread ID,
652 * etc. (command "tree"), or the same data as a simple list (command "list").
653 *****************************************************************************/
654 static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
655 vlc_value_t oldval, vlc_value_t newval, void *p_data )
657 if( *psz_cmd == 't' )
659 char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
660 vlc_object_t *p_object;
662 if( *newval.psz_string )
664 p_object = vlc_object_get( p_this, atoi(newval.psz_string) );
673 p_object = p_this->p_vlc ? VLC_OBJECT(p_this->p_vlc) : p_this;
676 vlc_mutex_lock( &structure_lock );
679 DumpStructure( p_object, 0, psz_foo );
681 vlc_mutex_unlock( &structure_lock );
683 if( *newval.psz_string )
685 vlc_object_release( p_this );
688 else if( *psz_cmd == 'l' )
690 vlc_object_t **pp_current, **pp_end;
692 vlc_mutex_lock( &structure_lock );
694 pp_current = p_this->p_libvlc->pp_objects;
695 pp_end = pp_current + p_this->p_libvlc->i_objects;
697 for( ; pp_current < pp_end ; pp_current++ )
699 if( (*pp_current)->b_attached )
701 PrintObject( *pp_current, "" );
705 printf( " o %.8i %s (not attached)\n",
706 (*pp_current)->i_object_id,
707 (*pp_current)->psz_object_type );
711 vlc_mutex_unlock( &structure_lock );
717 /*****************************************************************************
718 * vlc_list_release: free a list previously allocated by vlc_list_find
719 *****************************************************************************
720 * This function decreases the refcount of all objects in the list and
722 *****************************************************************************/
723 void vlc_list_release( vlc_list_t *p_list )
727 for( i_index = 0; i_index < p_list->i_count; i_index++ )
729 vlc_mutex_lock( &structure_lock );
731 p_list->p_values[i_index].p_object->i_refcount--;
733 vlc_mutex_unlock( &structure_lock );
736 free( p_list->p_values );
740 /* Following functions are local */
742 /*****************************************************************************
743 * FindIndex: find the index of an object in an array of objects
744 *****************************************************************************
745 * This function assumes that p_this can be found in pp_objects. It will not
746 * crash if p_this cannot be found, but will return a wrong value. It is your
747 * duty to check the return value if you are not certain that the object could
749 *****************************************************************************/
750 static int FindIndex( vlc_object_t *p_this,
751 vlc_object_t **pp_objects, int i_count )
753 int i_middle = i_count / 2;
760 if( pp_objects[i_middle] == p_this )
770 /* We take advantage of the sorted array */
771 if( pp_objects[i_middle]->i_object_id < p_this->i_object_id )
773 return i_middle + FindIndex( p_this, pp_objects + i_middle,
774 i_count - i_middle );
778 return FindIndex( p_this, pp_objects, i_middle );
782 static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
787 switch( i_mode & 0x000f )
790 p_tmp = p_this->p_parent;
793 if( p_tmp->i_object_type == i_type )
800 return FindObject( p_tmp, i_type, i_mode );
806 for( i = p_this->i_children; i--; )
808 p_tmp = p_this->pp_children[i];
809 if( p_tmp->i_object_type == i_type )
814 else if( p_tmp->i_children )
816 p_tmp = FindObject( p_tmp, i_type, i_mode );
826 /* Handled in vlc_object_find */
833 static void DetachObject( vlc_object_t *p_this )
835 vlc_object_t *p_parent = p_this->p_parent;
838 /* Remove p_this's parent */
839 p_this->p_parent = NULL;
841 /* Remove all of p_parent's children which are p_this */
842 for( i_index = p_parent->i_children ; i_index-- ; )
844 if( p_parent->pp_children[i_index] == p_this )
846 p_parent->i_children--;
847 for( i = i_index ; i < p_parent->i_children ; i++ )
849 p_parent->pp_children[i] = p_parent->pp_children[i+1];
854 if( p_parent->i_children )
856 p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children,
857 p_parent->i_children * sizeof(vlc_object_t *) );
861 free( p_parent->pp_children );
862 p_parent->pp_children = NULL;
866 /*****************************************************************************
867 * SetAttachment: recursively set the b_attached flag of a subtree.
868 *****************************************************************************
869 * This function is used by the attach and detach functions to propagate
870 * the b_attached flag in a subtree.
871 *****************************************************************************/
872 static void SetAttachment( vlc_object_t *p_this, vlc_bool_t b_attached )
876 for( i_index = p_this->i_children ; i_index-- ; )
878 SetAttachment( p_this->pp_children[i_index], b_attached );
881 p_this->b_attached = b_attached;
884 static void PrintObject( vlc_object_t *p_this, const char *psz_prefix )
886 char psz_children[20], psz_refcount[20], psz_thread[20], psz_name[50];
889 if( p_this->psz_object_name )
891 snprintf( psz_name, 50, " \"%s\"", p_this->psz_object_name );
896 psz_children[0] = '\0';
897 switch( p_this->i_children )
902 strcpy( psz_children, ", 1 child" );
905 snprintf( psz_children, 20,
906 ", %i children", p_this->i_children );
907 psz_children[19] = '\0';
911 psz_refcount[0] = '\0';
912 if( p_this->i_refcount )
914 snprintf( psz_refcount, 20, ", refcount %i", p_this->i_refcount );
915 psz_refcount[19] = '\0';
918 psz_thread[0] = '\0';
919 if( p_this->b_thread )
921 snprintf( psz_thread, 20, " (thread %d)", (int)p_this->thread_id );
922 psz_thread[19] = '\0';
925 printf( " %so %.8i %s%s%s%s%s\n", psz_prefix,
926 p_this->i_object_id, p_this->psz_object_type,
927 psz_name, psz_thread, psz_refcount, psz_children );
930 static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
933 char i_back = psz_foo[i_level];
934 psz_foo[i_level] = '\0';
936 PrintObject( p_this, psz_foo );
938 psz_foo[i_level] = i_back;
940 if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH )
942 msg_Warn( p_this, "structure tree is too deep" );
946 for( i = 0 ; i < p_this->i_children ; i++ )
950 psz_foo[i_level-1] = ' ';
952 if( psz_foo[i_level-2] == '`' )
954 psz_foo[i_level-2] = ' ';
958 if( i == p_this->i_children - 1 )
960 psz_foo[i_level] = '`';
964 psz_foo[i_level] = '|';
967 psz_foo[i_level+1] = '-';
968 psz_foo[i_level+2] = '\0';
970 DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo );
974 static vlc_list_t * NewList( int i_count )
976 vlc_list_t * p_list = (vlc_list_t *)malloc( sizeof( vlc_list_t ) );
982 p_list->i_count = i_count;
986 p_list->p_values = NULL;
990 p_list->p_values = malloc( i_count * sizeof( vlc_value_t ) );
991 if( p_list->p_values == NULL )
1000 static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
1003 if( p_list == NULL || i_index >= p_list->i_count )
1008 p_object->i_refcount++;
1010 p_list->p_values[i_index].p_object = p_object;
1015 static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
1017 if( p_list == NULL )
1022 p_list->p_values = realloc( p_list->p_values, (p_list->i_count + 1)
1023 * sizeof( vlc_value_t ) );
1024 if( p_list->p_values == NULL )
1026 p_list->i_count = 0;
1030 p_object->i_refcount++;
1032 p_list->p_values[p_list->i_count].p_object = p_object;
1038 static int CountChildren( vlc_object_t *p_this, int i_type )
1040 vlc_object_t *p_tmp;
1043 for( i = 0; i < p_this->i_children; i++ )
1045 p_tmp = p_this->pp_children[i];
1047 if( p_tmp->i_object_type == i_type )
1052 if( p_tmp->i_children )
1054 i_count += CountChildren( p_tmp, i_type );
1061 static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type )
1063 vlc_object_t *p_tmp;
1066 for( i = 0; i < p_this->i_children; i++ )
1068 p_tmp = p_this->pp_children[i];
1070 if( p_tmp->i_object_type == i_type )
1072 ListReplace( p_list, p_tmp, p_list->i_count++ );
1075 if( p_tmp->i_children )
1077 ListChildren( p_list, p_tmp, i_type );