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"
58 /*****************************************************************************
60 *****************************************************************************/
61 static int DumpCommand( vlc_object_t *, char const *,
62 vlc_value_t, vlc_value_t, void * );
64 static vlc_object_t * FindObject ( vlc_object_t *, int, int );
65 static void DetachObject ( vlc_object_t * );
66 static void PrintObject ( vlc_object_t *, const char * );
67 static void DumpStructure ( vlc_object_t *, int, char * );
68 static int FindIndex ( vlc_object_t *, vlc_object_t **, int );
69 static void SetAttachment ( vlc_object_t *, vlc_bool_t );
71 static vlc_list_t * NewList ( int );
72 static void ListReplace ( vlc_list_t *, vlc_object_t *, int );
73 static void ListAppend ( vlc_list_t *, vlc_object_t * );
74 static int CountChildren ( vlc_object_t *, int );
75 static void ListChildren ( vlc_list_t *, vlc_object_t *, int );
77 /*****************************************************************************
78 * Local structure lock
79 *****************************************************************************/
80 static vlc_mutex_t structure_lock;
82 /*****************************************************************************
83 * vlc_object_create: initialize a vlc object
84 *****************************************************************************
85 * This function allocates memory for a vlc object and initializes it. If
86 * i_type is not a known value such as VLC_OBJECT_ROOT, VLC_OBJECT_VOUT and
87 * so on, vlc_object_create will use its value for the object size.
88 *****************************************************************************/
91 * Initialize a vlc object
93 * This function allocates memory for a vlc object and initializes it. If
94 * i_type is not a known value such as VLC_OBJECT_ROOT, VLC_OBJECT_VOUT and
95 * so on, vlc_object_create will use its value for the object size.
97 void * __vlc_object_create( vlc_object_t *p_this, int i_type )
105 case VLC_OBJECT_ROOT:
106 i_size = sizeof(libvlc_t);
110 i_size = sizeof(vlc_t);
113 case VLC_OBJECT_MODULE:
114 i_size = sizeof(module_t);
117 case VLC_OBJECT_INTF:
118 i_size = sizeof(intf_thread_t);
119 psz_type = "interface";
121 case VLC_OBJECT_DIALOGS:
122 i_size = sizeof(intf_thread_t);
123 psz_type = "dialogs provider";
125 case VLC_OBJECT_PLAYLIST:
126 i_size = sizeof(playlist_t);
127 psz_type = "playlist";
130 i_size = sizeof(services_discovery_t);
131 psz_type = "services discovery";
133 case VLC_OBJECT_INPUT:
134 i_size = sizeof(input_thread_t);
137 case VLC_OBJECT_DEMUX:
138 i_size = sizeof(demux_t);
141 case VLC_OBJECT_STREAM:
142 i_size = sizeof(stream_t);
145 case VLC_OBJECT_ACCESS:
146 i_size = sizeof(access_t);
149 case VLC_OBJECT_DECODER:
150 i_size = sizeof(decoder_t);
151 psz_type = "decoder";
153 case VLC_OBJECT_PACKETIZER:
154 i_size = sizeof(decoder_t);
155 psz_type = "packetizer";
157 case VLC_OBJECT_ENCODER:
158 i_size = sizeof(encoder_t);
159 psz_type = "encoder";
161 case VLC_OBJECT_FILTER:
162 i_size = sizeof(filter_t);
165 case VLC_OBJECT_VOUT:
166 i_size = sizeof(vout_thread_t);
167 psz_type = "video output";
170 i_size = sizeof(spu_t);
171 psz_type = "subpicture unit";
173 case VLC_OBJECT_AOUT:
174 i_size = sizeof(aout_instance_t);
175 psz_type = "audio output";
177 case VLC_OBJECT_SOUT:
178 i_size = sizeof(sout_instance_t);
179 psz_type = "stream output";
181 case VLC_OBJECT_HTTPD:
182 i_size = sizeof( httpd_t );
183 psz_type = "http daemon";
186 i_size = sizeof( vlm_t );
187 psz_type = "vlm dameon";
190 i_size = sizeof( vod_t );
191 psz_type = "vod server";
194 i_size = sizeof( tls_t );
197 case VLC_OBJECT_OPENGL:
198 i_size = sizeof( vout_thread_t );
199 psz_type = "opengl provider";
201 case VLC_OBJECT_ANNOUNCE:
202 i_size = sizeof( announce_handler_t );
203 psz_type = "announce handler";
207 ? i_type > (int)sizeof(vlc_object_t)
208 ? i_type : (int)sizeof(vlc_object_t)
209 : (int)sizeof(vlc_object_t);
210 i_type = VLC_OBJECT_GENERIC;
211 psz_type = "generic";
215 if( i_type == VLC_OBJECT_ROOT )
221 p_new = malloc( i_size );
222 if( !p_new ) return NULL;
223 memset( p_new, 0, i_size );
226 p_new->i_object_type = i_type;
227 p_new->psz_object_type = psz_type;
229 p_new->psz_object_name = NULL;
231 p_new->b_die = VLC_FALSE;
232 p_new->b_error = VLC_FALSE;
233 p_new->b_dead = VLC_FALSE;
234 p_new->b_attached = VLC_FALSE;
235 p_new->b_force = VLC_FALSE;
238 p_new->p_vars = (variable_t *)malloc( 16 * sizeof( variable_t ) );
246 if( i_type == VLC_OBJECT_ROOT )
248 /* If i_type is root, then p_new is actually p_libvlc */
249 p_new->p_libvlc = (libvlc_t*)p_new;
252 p_new->p_libvlc->i_counter = 0;
253 p_new->i_object_id = 0;
255 p_new->p_libvlc->i_objects = 1;
256 p_new->p_libvlc->pp_objects = malloc( sizeof(vlc_object_t *) );
257 p_new->p_libvlc->pp_objects[0] = p_new;
258 p_new->b_attached = VLC_TRUE;
262 p_new->p_libvlc = p_this->p_libvlc;
263 p_new->p_vlc = ( i_type == VLC_OBJECT_VLC ) ? (vlc_t*)p_new
266 vlc_mutex_lock( &structure_lock );
268 p_new->p_libvlc->i_counter++;
269 p_new->i_object_id = p_new->p_libvlc->i_counter;
271 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
272 * useless to try and recover anything if pp_objects gets smashed. */
273 INSERT_ELEM( p_new->p_libvlc->pp_objects,
274 p_new->p_libvlc->i_objects,
275 p_new->p_libvlc->i_objects,
278 vlc_mutex_unlock( &structure_lock );
281 p_new->i_refcount = 0;
282 p_new->p_parent = NULL;
283 p_new->pp_children = NULL;
284 p_new->i_children = 0;
286 p_new->p_private = NULL;
288 /* Initialize mutexes and condvars */
289 vlc_mutex_init( p_new, &p_new->object_lock );
290 vlc_cond_init( p_new, &p_new->object_wait );
291 vlc_mutex_init( p_new, &p_new->var_lock );
293 if( i_type == VLC_OBJECT_ROOT )
295 vlc_mutex_init( p_new, &structure_lock );
297 var_Create( p_new, "list", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
298 var_AddCallback( p_new, "list", DumpCommand, NULL );
299 var_Create( p_new, "tree", VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
300 var_AddCallback( p_new, "tree", DumpCommand, NULL );
307 ****************************************************************************
308 * Destroy a vlc object
310 * This function destroys an object that has been previously allocated with
311 * vlc_object_create. The object's refcount must be zero and it must not be
312 * attached to other objects in any way.
313 *****************************************************************************/
314 void __vlc_object_destroy( vlc_object_t *p_this )
318 if( p_this->i_children )
320 msg_Err( p_this, "cannot delete object (%i, %s) with children" ,
321 p_this->i_object_id, p_this->psz_object_name );
325 if( p_this->p_parent )
327 msg_Err( p_this, "cannot delete object (%i, %s) with a parent",
328 p_this->i_object_id, p_this->psz_object_name );
332 while( p_this->i_refcount )
336 /* Don't warn immediately ... 100ms seems OK */
339 msg_Warn( p_this, "refcount is %i, delaying before deletion",
340 p_this->i_refcount );
342 else if( i_delay == 12 )
344 msg_Err( p_this, "refcount is %i, I have a bad feeling about this",
345 p_this->i_refcount );
347 else if( i_delay == 42 )
349 msg_Err( p_this, "we waited too long, cancelling destruction" );
356 /* Destroy the associated variables, starting from the end so that
357 * no memmove calls have to be done. */
358 while( p_this->i_vars )
360 var_Destroy( p_this, p_this->p_vars[p_this->i_vars - 1].psz_name );
363 free( p_this->p_vars );
364 vlc_mutex_destroy( &p_this->var_lock );
366 if( p_this->i_object_type == VLC_OBJECT_ROOT )
368 /* We are the root object ... no need to lock. */
369 free( p_this->p_libvlc->pp_objects );
370 p_this->p_libvlc->pp_objects = NULL;
371 p_this->p_libvlc->i_objects--;
373 vlc_mutex_destroy( &structure_lock );
379 vlc_mutex_lock( &structure_lock );
381 /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
382 * useless to try and recover anything if pp_objects gets smashed. */
383 i_index = FindIndex( p_this, p_this->p_libvlc->pp_objects,
384 p_this->p_libvlc->i_objects );
385 REMOVE_ELEM( p_this->p_libvlc->pp_objects,
386 p_this->p_libvlc->i_objects, i_index );
388 vlc_mutex_unlock( &structure_lock );
391 vlc_mutex_destroy( &p_this->object_lock );
392 vlc_cond_destroy( &p_this->object_wait );
398 * find an object given its ID
400 * This function looks for the object whose i_object_id field is i_id. We
401 * use a dichotomy so that lookups are in log2(n).
402 *****************************************************************************/
403 void * __vlc_object_get( vlc_object_t *p_this, int i_id )
406 vlc_object_t **pp_objects;
408 vlc_mutex_lock( &structure_lock );
410 pp_objects = p_this->p_libvlc->pp_objects;
412 /* Perform our dichotomy */
413 for( i_max = p_this->p_libvlc->i_objects - 1 ; ; )
415 i_middle = i_max / 2;
417 if( pp_objects[i_middle]->i_object_id > i_id )
421 else if( pp_objects[i_middle]->i_object_id < i_id )
425 pp_objects += i_middle;
430 /* This happens when there are only two remaining objects */
431 if( pp_objects[i_middle+1]->i_object_id == i_id )
433 vlc_mutex_unlock( &structure_lock );
434 pp_objects[i_middle+1]->i_refcount++;
435 return pp_objects[i_middle+1];
442 vlc_mutex_unlock( &structure_lock );
443 pp_objects[i_middle]->i_refcount++;
444 return pp_objects[i_middle];
449 /* this means that i_max == i_middle, and since we have already
450 * tested pp_objects[i_middle]), p_found is properly set. */
455 vlc_mutex_unlock( &structure_lock );
460 ****************************************************************************
461 * find a typed object and increment its refcount
462 *****************************************************************************
463 * This function recursively looks for a given object type. i_mode can be one
464 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
465 *****************************************************************************/
466 void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
468 vlc_object_t *p_found;
470 vlc_mutex_lock( &structure_lock );
472 /* If we are of the requested type ourselves, don't look further */
473 if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
475 p_this->i_refcount++;
476 vlc_mutex_unlock( &structure_lock );
480 /* Otherwise, recursively look for the object */
481 if( (i_mode & 0x000f) == FIND_ANYWHERE )
483 vlc_object_t *p_root = p_this;
486 while( p_root->p_parent != NULL &&
487 p_root != VLC_OBJECT( p_this->p_vlc ) )
489 p_root = p_root->p_parent;
492 p_found = FindObject( p_root, i_type, (i_mode & ~0x000f)|FIND_CHILD );
493 if( p_found == NULL && p_root != VLC_OBJECT( p_this->p_vlc ) )
495 p_found = FindObject( VLC_OBJECT( p_this->p_vlc ),
496 i_type, (i_mode & ~0x000f)|FIND_CHILD );
501 p_found = FindObject( p_this, i_type, i_mode );
504 vlc_mutex_unlock( &structure_lock );
510 ****************************************************************************
511 * increment an object refcount
512 *****************************************************************************/
513 void __vlc_object_yield( vlc_object_t *p_this )
515 vlc_mutex_lock( &structure_lock );
516 p_this->i_refcount++;
517 vlc_mutex_unlock( &structure_lock );
521 ****************************************************************************
522 * decrement an object refcount
523 *****************************************************************************/
524 void __vlc_object_release( vlc_object_t *p_this )
526 vlc_mutex_lock( &structure_lock );
527 p_this->i_refcount--;
528 vlc_mutex_unlock( &structure_lock );
532 ****************************************************************************
533 * attach object to a parent object
534 *****************************************************************************
535 * This function sets p_this as a child of p_parent, and p_parent as a parent
536 * of p_this. This link can be undone using vlc_object_detach.
537 *****************************************************************************/
538 void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
540 vlc_mutex_lock( &structure_lock );
542 /* Attach the parent to its child */
543 p_this->p_parent = p_parent;
545 /* Attach the child to its parent */
546 INSERT_ELEM( p_parent->pp_children, p_parent->i_children,
547 p_parent->i_children, p_this );
549 /* Climb up the tree to see whether we are connected with the root */
550 if( p_parent->b_attached )
552 SetAttachment( p_this, VLC_TRUE );
555 vlc_mutex_unlock( &structure_lock );
559 ****************************************************************************
560 * detach object from its parent
561 *****************************************************************************
562 * This function removes all links between an object and its parent.
563 *****************************************************************************/
564 void __vlc_object_detach( vlc_object_t *p_this )
566 vlc_mutex_lock( &structure_lock );
567 if( !p_this->p_parent )
569 msg_Err( p_this, "object is not attached" );
570 vlc_mutex_unlock( &structure_lock );
574 /* Climb up the tree to see whether we are connected with the root */
575 if( p_this->p_parent->b_attached )
577 SetAttachment( p_this, VLC_FALSE );
580 DetachObject( p_this );
581 vlc_mutex_unlock( &structure_lock );
585 ****************************************************************************
586 * find a list typed objects and increment their refcount
587 *****************************************************************************
588 * This function recursively looks for a given object type. i_mode can be one
589 * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
590 *****************************************************************************/
591 vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
594 vlc_object_t **pp_current, **pp_end;
595 int i_count = 0, i_index = 0;
597 vlc_mutex_lock( &structure_lock );
599 /* Look for the objects */
600 switch( i_mode & 0x000f )
603 pp_current = p_this->p_libvlc->pp_objects;
604 pp_end = pp_current + p_this->p_libvlc->i_objects;
606 for( ; pp_current < pp_end ; pp_current++ )
608 if( (*pp_current)->b_attached
609 && (*pp_current)->i_object_type == i_type )
615 p_list = NewList( i_count );
616 pp_current = p_this->p_libvlc->pp_objects;
618 for( ; pp_current < pp_end ; pp_current++ )
620 if( (*pp_current)->b_attached
621 && (*pp_current)->i_object_type == i_type )
623 ListReplace( p_list, *pp_current, i_index );
624 if( i_index < i_count ) i_index++;
630 i_count = CountChildren( p_this, i_type );
631 p_list = NewList( i_count );
633 /* Check allocation was successful */
634 if( p_list->i_count != i_count )
636 msg_Err( p_this, "list allocation failed!" );
642 ListChildren( p_list, p_this, i_type );
646 msg_Err( p_this, "unimplemented!" );
647 p_list = NewList( 0 );
651 vlc_mutex_unlock( &structure_lock );
656 /*****************************************************************************
657 * DumpCommand: print the current vlc structure
658 *****************************************************************************
659 * This function prints either an ASCII tree showing the connections between
660 * vlc objects, and additional information such as their refcount, thread ID,
661 * etc. (command "tree"), or the same data as a simple list (command "list").
662 *****************************************************************************/
663 static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
664 vlc_value_t oldval, vlc_value_t newval, void *p_data )
666 if( *psz_cmd == 't' )
668 char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
669 vlc_object_t *p_object;
671 if( *newval.psz_string )
673 p_object = vlc_object_get( p_this, atoi(newval.psz_string) );
682 p_object = p_this->p_vlc ? VLC_OBJECT(p_this->p_vlc) : p_this;
685 vlc_mutex_lock( &structure_lock );
688 DumpStructure( p_object, 0, psz_foo );
690 vlc_mutex_unlock( &structure_lock );
692 if( *newval.psz_string )
694 vlc_object_release( p_this );
697 else if( *psz_cmd == 'l' )
699 vlc_object_t **pp_current, **pp_end;
701 vlc_mutex_lock( &structure_lock );
703 pp_current = p_this->p_libvlc->pp_objects;
704 pp_end = pp_current + p_this->p_libvlc->i_objects;
706 for( ; pp_current < pp_end ; pp_current++ )
708 if( (*pp_current)->b_attached )
710 PrintObject( *pp_current, "" );
714 printf( " o %.8i %s (not attached)\n",
715 (*pp_current)->i_object_id,
716 (*pp_current)->psz_object_type );
720 vlc_mutex_unlock( &structure_lock );
726 /*****************************************************************************
727 * vlc_list_release: free a list previously allocated by vlc_list_find
728 *****************************************************************************
729 * This function decreases the refcount of all objects in the list and
731 *****************************************************************************/
732 void vlc_list_release( vlc_list_t *p_list )
736 for( i_index = 0; i_index < p_list->i_count; i_index++ )
738 vlc_mutex_lock( &structure_lock );
740 p_list->p_values[i_index].p_object->i_refcount--;
742 vlc_mutex_unlock( &structure_lock );
745 free( p_list->p_values );
749 /* Following functions are local */
751 /*****************************************************************************
752 * FindIndex: find the index of an object in an array of objects
753 *****************************************************************************
754 * This function assumes that p_this can be found in pp_objects. It will not
755 * crash if p_this cannot be found, but will return a wrong value. It is your
756 * duty to check the return value if you are not certain that the object could
758 *****************************************************************************/
759 static int FindIndex( vlc_object_t *p_this,
760 vlc_object_t **pp_objects, int i_count )
762 int i_middle = i_count / 2;
769 if( pp_objects[i_middle] == p_this )
779 /* We take advantage of the sorted array */
780 if( pp_objects[i_middle]->i_object_id < p_this->i_object_id )
782 return i_middle + FindIndex( p_this, pp_objects + i_middle,
783 i_count - i_middle );
787 return FindIndex( p_this, pp_objects, i_middle );
791 static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
796 switch( i_mode & 0x000f )
799 p_tmp = p_this->p_parent;
802 if( p_tmp->i_object_type == i_type )
809 return FindObject( p_tmp, i_type, i_mode );
815 for( i = p_this->i_children; i--; )
817 p_tmp = p_this->pp_children[i];
818 if( p_tmp->i_object_type == i_type )
823 else if( p_tmp->i_children )
825 p_tmp = FindObject( p_tmp, i_type, i_mode );
835 /* Handled in vlc_object_find */
842 static void DetachObject( vlc_object_t *p_this )
844 vlc_object_t *p_parent = p_this->p_parent;
847 /* Remove p_this's parent */
848 p_this->p_parent = NULL;
850 /* Remove all of p_parent's children which are p_this */
851 for( i_index = p_parent->i_children ; i_index-- ; )
853 if( p_parent->pp_children[i_index] == p_this )
855 p_parent->i_children--;
856 for( i = i_index ; i < p_parent->i_children ; i++ )
858 p_parent->pp_children[i] = p_parent->pp_children[i+1];
863 if( p_parent->i_children )
865 p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children,
866 p_parent->i_children * sizeof(vlc_object_t *) );
870 free( p_parent->pp_children );
871 p_parent->pp_children = NULL;
875 /*****************************************************************************
876 * SetAttachment: recursively set the b_attached flag of a subtree.
877 *****************************************************************************
878 * This function is used by the attach and detach functions to propagate
879 * the b_attached flag in a subtree.
880 *****************************************************************************/
881 static void SetAttachment( vlc_object_t *p_this, vlc_bool_t b_attached )
885 for( i_index = p_this->i_children ; i_index-- ; )
887 SetAttachment( p_this->pp_children[i_index], b_attached );
890 p_this->b_attached = b_attached;
893 static void PrintObject( vlc_object_t *p_this, const char *psz_prefix )
895 char psz_children[20], psz_refcount[20], psz_thread[20], psz_name[50];
898 if( p_this->psz_object_name )
900 snprintf( psz_name, 50, " \"%s\"", p_this->psz_object_name );
905 psz_children[0] = '\0';
906 switch( p_this->i_children )
911 strcpy( psz_children, ", 1 child" );
914 snprintf( psz_children, 20,
915 ", %i children", p_this->i_children );
916 psz_children[19] = '\0';
920 psz_refcount[0] = '\0';
921 if( p_this->i_refcount )
923 snprintf( psz_refcount, 20, ", refcount %i", p_this->i_refcount );
924 psz_refcount[19] = '\0';
927 psz_thread[0] = '\0';
928 if( p_this->b_thread )
930 snprintf( psz_thread, 20, " (thread %d)", (int)p_this->thread_id );
931 psz_thread[19] = '\0';
934 printf( " %so %.8i %s%s%s%s%s\n", psz_prefix,
935 p_this->i_object_id, p_this->psz_object_type,
936 psz_name, psz_thread, psz_refcount, psz_children );
939 static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
942 char i_back = psz_foo[i_level];
943 psz_foo[i_level] = '\0';
945 PrintObject( p_this, psz_foo );
947 psz_foo[i_level] = i_back;
949 if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH )
951 msg_Warn( p_this, "structure tree is too deep" );
955 for( i = 0 ; i < p_this->i_children ; i++ )
959 psz_foo[i_level-1] = ' ';
961 if( psz_foo[i_level-2] == '`' )
963 psz_foo[i_level-2] = ' ';
967 if( i == p_this->i_children - 1 )
969 psz_foo[i_level] = '`';
973 psz_foo[i_level] = '|';
976 psz_foo[i_level+1] = '-';
977 psz_foo[i_level+2] = '\0';
979 DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo );
983 static vlc_list_t * NewList( int i_count )
985 vlc_list_t * p_list = (vlc_list_t *)malloc( sizeof( vlc_list_t ) );
991 p_list->i_count = i_count;
995 p_list->p_values = NULL;
999 p_list->p_values = malloc( i_count * sizeof( vlc_value_t ) );
1000 if( p_list->p_values == NULL )
1002 p_list->i_count = 0;
1009 static void ListReplace( vlc_list_t *p_list, vlc_object_t *p_object,
1012 if( p_list == NULL || i_index >= p_list->i_count )
1017 p_object->i_refcount++;
1019 p_list->p_values[i_index].p_object = p_object;
1024 static void ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
1026 if( p_list == NULL )
1031 p_list->p_values = realloc( p_list->p_values, (p_list->i_count + 1)
1032 * sizeof( vlc_value_t ) );
1033 if( p_list->p_values == NULL )
1035 p_list->i_count = 0;
1039 p_object->i_refcount++;
1041 p_list->p_values[p_list->i_count].p_object = p_object;
1047 static int CountChildren( vlc_object_t *p_this, int i_type )
1049 vlc_object_t *p_tmp;
1052 for( i = 0; i < p_this->i_children; i++ )
1054 p_tmp = p_this->pp_children[i];
1056 if( p_tmp->i_object_type == i_type )
1061 if( p_tmp->i_children )
1063 i_count += CountChildren( p_tmp, i_type );
1070 static void ListChildren( vlc_list_t *p_list, vlc_object_t *p_this, int i_type )
1072 vlc_object_t *p_tmp;
1075 for( i = 0; i < p_this->i_children; i++ )
1077 p_tmp = p_this->pp_children[i];
1079 if( p_tmp->i_object_type == i_type )
1081 ListReplace( p_list, p_tmp, p_list->i_count++ );
1084 if( p_tmp->i_children )
1086 ListChildren( p_list, p_tmp, i_type );