]> git.sesse.net Git - vlc/blob - src/misc/objects.c
* ./src/misc/modules.c: the module linked list is going bye bye. We now use
[vlc] / src / misc / objects.c
1 /*****************************************************************************
2  * objects.c: vlc_object_t handling
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: objects.c,v 1.19 2002/08/15 12:11:15 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28
29 #ifdef HAVE_STDLIB_H
30 #   include <stdlib.h>                                          /* realloc() */
31 #endif
32
33 #include "stream_control.h"
34 #include "input_ext-intf.h"
35 #include "input_ext-dec.h"
36
37 #include "video.h"
38 #include "video_output.h"
39
40 #include "audio_output.h"
41 #include "aout_internal.h"
42
43 #include "vlc_playlist.h"
44 #include "interface.h"
45
46 /*****************************************************************************
47  * Local prototypes
48  *****************************************************************************/
49 static vlc_object_t * FindObject    ( vlc_object_t *, int, int );
50 static void           DetachObject  ( vlc_object_t * );
51 static void           PrintObject   ( vlc_object_t *, const char * );
52 static void           DumpStructure ( vlc_object_t *, int, char * );
53 static int            FindIndex     ( vlc_object_t *, vlc_object_t **, int );
54 static void           SetAttachment ( vlc_object_t *, vlc_bool_t );
55
56 static vlc_list_t *   NewList       ( void );
57 static vlc_list_t *   ListAppend    ( vlc_list_t *, vlc_object_t * );
58
59 /*****************************************************************************
60  * vlc_object_create: initialize a vlc object
61  *****************************************************************************
62  * This function allocates memory for a vlc object and initializes it. If
63  * i_type is not a known value such as VLC_OBJECT_ROOT, VLC_OBJECT_VOUT and
64  * so on, vlc_object_create will use its value for the object size.
65  *****************************************************************************/
66 void * __vlc_object_create( vlc_object_t *p_this, int i_type )
67 {
68     vlc_object_t * p_new;
69     char *         psz_type;
70     size_t         i_size;
71
72     switch( i_type )
73     {
74         case VLC_OBJECT_ROOT:
75             i_size = sizeof(vlc_t);
76             psz_type = "root";
77             break;
78         case VLC_OBJECT_MODULE:
79             i_size = sizeof(module_t);
80             psz_type = "module";
81             break;
82         case VLC_OBJECT_INTF:
83             i_size = sizeof(intf_thread_t);
84             psz_type = "interface";
85             break;
86         case VLC_OBJECT_PLAYLIST:
87             i_size = sizeof(playlist_t);
88             psz_type = "playlist";
89             break;
90         case VLC_OBJECT_INPUT:
91             i_size = sizeof(input_thread_t);
92             psz_type = "input";
93             break;
94         case VLC_OBJECT_DECODER:
95             i_size = sizeof(decoder_fifo_t);
96             psz_type = "decoder";
97             break;
98         case VLC_OBJECT_VOUT:
99             i_size = sizeof(vout_thread_t);
100             psz_type = "video output";
101             break;
102         case VLC_OBJECT_AOUT:
103             i_size = sizeof(aout_instance_t);
104             psz_type = "audio output";
105             break;
106         default:
107             i_size = i_type > sizeof(vlc_object_t)
108                    ? i_type : sizeof(vlc_object_t);
109             i_type = VLC_OBJECT_GENERIC;
110             psz_type = "generic";
111             break;
112     }
113
114     p_new = malloc( i_size );
115
116     if( !p_new )
117     {
118         return NULL;
119     }
120
121     memset( p_new, 0, i_size );
122
123     p_new->i_object_type = i_type;
124     p_new->psz_object_type = psz_type;
125
126     p_new->psz_object_name = NULL;
127
128     p_new->i_refcount = 0;
129     p_new->b_die = VLC_FALSE;
130     p_new->b_error = VLC_FALSE;
131     p_new->b_dead = VLC_FALSE;
132     p_new->b_attached = VLC_FALSE;
133
134     /* If i_type is root, then p_new is our own p_vlc */
135     if( i_type == VLC_OBJECT_ROOT )
136     {
137         /* We are the first object ... no need to lock. */
138         p_new->p_vlc = (vlc_t*)p_new;
139
140         p_new->p_vlc->i_counter = 0;
141         p_new->i_object_id = 0;
142
143         p_new->p_vlc->i_objects = 1;
144         p_new->p_vlc->pp_objects = malloc( sizeof(vlc_object_t *) );
145         p_new->p_vlc->pp_objects[0] = p_new;
146         p_new->b_attached = VLC_TRUE;
147     }
148     else
149     {
150         p_new->p_vlc = p_this->p_vlc;
151
152         vlc_mutex_lock( &p_this->p_vlc->structure_lock );
153
154         p_new->p_vlc->i_counter++;
155         p_new->i_object_id = p_new->p_vlc->i_counter;
156
157         /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
158          * useless to try and recover anything if pp_objects gets smashed. */
159         p_new->p_vlc->i_objects++;
160         p_new->p_vlc->pp_objects =
161                   realloc( p_new->p_vlc->pp_objects,
162                            p_new->p_vlc->i_objects * sizeof(vlc_object_t *) );
163         p_new->p_vlc->pp_objects[ p_new->p_vlc->i_objects - 1 ] = p_new;
164
165         vlc_mutex_unlock( &p_this->p_vlc->structure_lock );
166     }
167
168     p_new->p_parent = NULL;
169     p_new->pp_children = NULL;
170     p_new->i_children = 0;
171
172     p_new->p_private = NULL;
173
174     vlc_mutex_init( p_new, &p_new->object_lock );
175     vlc_cond_init( p_new, &p_new->object_wait );
176
177     return p_new;
178 }
179
180 /*****************************************************************************
181  * vlc_object_destroy: destroy a vlc object
182  *****************************************************************************
183  * This function destroys an object that has been previously allocated with
184  * vlc_object_create. The object's refcount must be zero and it must not be
185  * attached to other objects in any way.
186  *****************************************************************************/
187 void __vlc_object_destroy( vlc_object_t *p_this )
188 {
189     int i_delay = 0;
190
191     if( p_this->i_children )
192     {
193         msg_Err( p_this, "cannot delete object with children" );
194         vlc_dumpstructure( p_this );
195         return;
196     }
197
198     if( p_this->p_parent )
199     {
200         msg_Err( p_this, "cannot delete object with a parent" );
201         vlc_dumpstructure( p_this );
202         return;
203     }
204
205     while( p_this->i_refcount )
206     {
207         i_delay++;
208
209         /* Don't warn immediately ... 100ms seems OK */
210         if( i_delay == 2 )
211         {
212             msg_Warn( p_this, "refcount is %i, delaying before deletion",
213                               p_this->i_refcount );
214         }
215         else if( i_delay == 12 )
216         {
217             msg_Err( p_this, "refcount is %i, I have a bad feeling about this",
218                              p_this->i_refcount );
219         }
220         else if( i_delay == 42 )
221         {
222             msg_Err( p_this, "we waited too long, cancelling destruction" );
223             return;
224         }
225
226         msleep( 100000 );
227     }
228
229     vlc_mutex_lock( &p_this->p_vlc->structure_lock );
230
231     /* Wooohaa! If *this* fails, we're in serious trouble! Anyway it's
232      * useless to try and recover anything if pp_objects gets smashed. */
233     if( p_this->p_vlc->i_objects > 1 )
234     {
235         int i_index = FindIndex( p_this, p_this->p_vlc->pp_objects,
236                                          p_this->p_vlc->i_objects );
237         memmove( p_this->p_vlc->pp_objects + i_index,
238                  p_this->p_vlc->pp_objects + i_index + 1,
239                  (p_this->p_vlc->i_objects - i_index - 1)
240                    * sizeof( vlc_object_t *) );
241
242         p_this->p_vlc->pp_objects =
243             realloc( p_this->p_vlc->pp_objects,
244                      (p_this->p_vlc->i_objects - 1) * sizeof(vlc_object_t *) );
245     }
246     else
247     {
248         free( p_this->p_vlc->pp_objects );
249         p_this->p_vlc->pp_objects = NULL;
250     }
251
252     p_this->p_vlc->i_objects--;
253
254     vlc_mutex_unlock( &p_this->p_vlc->structure_lock );
255
256     vlc_mutex_destroy( &p_this->object_lock );
257     vlc_cond_destroy( &p_this->object_wait );
258
259     free( p_this );
260 }
261
262 /*****************************************************************************
263  * vlc_object_find: find a typed object and increment its refcount
264  *****************************************************************************
265  * This function recursively looks for a given object type. i_mode can be one
266  * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
267  *****************************************************************************/
268 void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
269 {
270     vlc_object_t *p_found;
271
272     vlc_mutex_lock( &p_this->p_vlc->structure_lock );
273
274     /* If we are of the requested type ourselves, don't look further */
275     if( !(i_mode & FIND_STRICT) && p_this->i_object_type == i_type )
276     {
277         p_this->i_refcount++;
278         vlc_mutex_unlock( &p_this->p_vlc->structure_lock );
279         return p_this;
280     }
281
282     /* Otherwise, recursively look for the object */
283     if( (i_mode & 0x000f) == FIND_ANYWHERE )
284     {
285         p_found = FindObject( VLC_OBJECT(p_this->p_vlc), i_type,
286                               (i_mode & ~0x000f) | FIND_CHILD );
287     }
288     else
289     {
290         p_found = FindObject( p_this, i_type, i_mode );
291     }
292
293     vlc_mutex_unlock( &p_this->p_vlc->structure_lock );
294
295     return p_found;
296 }
297
298 /*****************************************************************************
299  * vlc_object_yield: increment an object refcount
300  *****************************************************************************/
301 void __vlc_object_yield( vlc_object_t *p_this )
302 {
303     vlc_mutex_lock( &p_this->p_vlc->structure_lock );
304     p_this->i_refcount++;
305     vlc_mutex_unlock( &p_this->p_vlc->structure_lock );
306 }
307
308 /*****************************************************************************
309  * vlc_object_release: decrement an object refcount
310  *****************************************************************************/
311 void __vlc_object_release( vlc_object_t *p_this )
312 {
313     vlc_mutex_lock( &p_this->p_vlc->structure_lock );
314     p_this->i_refcount--;
315     vlc_mutex_unlock( &p_this->p_vlc->structure_lock );
316 }
317
318 /*****************************************************************************
319  * vlc_object_attach: attach object to a parent object
320  *****************************************************************************
321  * This function sets p_this as a child of p_parent, and p_parent as a parent
322  * of p_this. This link can be undone using vlc_object_detach.
323  *****************************************************************************/
324 void __vlc_object_attach( vlc_object_t *p_this, vlc_object_t *p_parent )
325 {
326     vlc_mutex_lock( &p_this->p_vlc->structure_lock );
327
328     /* Attach the parent to its child */
329     p_this->p_parent = p_parent;
330
331     /* Attach the child to its parent */
332     p_parent->i_children++;
333     p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children,
334                                p_parent->i_children * sizeof(vlc_object_t *) );
335     p_parent->pp_children[p_parent->i_children - 1] = p_this;
336
337     /* Climb up the tree to see whether we are connected with the root */
338     if( p_parent->b_attached )
339     {
340         SetAttachment( p_this, VLC_TRUE );
341     }
342
343     vlc_mutex_unlock( &p_this->p_vlc->structure_lock );
344 }
345
346 /*****************************************************************************
347  * vlc_object_detach: detach object from its parent
348  *****************************************************************************
349  * This function removes all links between an object and its parent.
350  *****************************************************************************/
351 void __vlc_object_detach( vlc_object_t *p_this )
352 {
353     vlc_mutex_lock( &p_this->p_vlc->structure_lock );
354     if( !p_this->p_parent )
355     {
356         msg_Err( p_this, "object is not attached" );
357         vlc_mutex_unlock( &p_this->p_vlc->structure_lock );
358         return;
359     }
360
361     /* Climb up the tree to see whether we are connected with the root */
362     if( p_this->p_parent->b_attached )
363     {
364         SetAttachment( p_this, VLC_FALSE );
365     }
366
367     DetachObject( p_this );
368     vlc_mutex_unlock( &p_this->p_vlc->structure_lock );
369 }
370
371 /*****************************************************************************
372  * vlc_list_find: find a list typed objects and increment their refcount
373  *****************************************************************************
374  * This function recursively looks for a given object type. i_mode can be one
375  * of FIND_PARENT, FIND_CHILD or FIND_ANYWHERE.
376  *****************************************************************************/
377 vlc_list_t * __vlc_list_find( vlc_object_t *p_this, int i_type, int i_mode )
378 {
379     vlc_list_t *p_list = NewList();
380
381     vlc_mutex_lock( &p_this->p_vlc->structure_lock );
382
383     /* Look for the objects */
384     if( (i_mode & 0x000f) == FIND_ANYWHERE )
385     {
386         vlc_object_t **pp_current, **pp_end;
387
388         pp_current = p_this->p_vlc->pp_objects;
389         pp_end = pp_current + p_this->p_vlc->i_objects;
390
391         for( ; pp_current < pp_end ; pp_current++ )
392         {
393             if( (*pp_current)->b_attached
394                  && (*pp_current)->i_object_type == i_type )
395             {
396                 p_list = ListAppend( p_list, *pp_current );
397             }
398         }
399     }
400     else
401     {
402         msg_Err( p_this, "unimplemented!" );
403     }
404
405     vlc_mutex_unlock( &p_this->p_vlc->structure_lock );
406
407     return p_list;
408 }
409
410 /*****************************************************************************
411  * vlc_liststructure: print the current vlc objects
412  *****************************************************************************
413  * This function prints alist of vlc objects, and additional information such
414  * as their refcount, thread ID, etc.
415  *****************************************************************************/
416 void __vlc_liststructure( vlc_object_t *p_this )
417 {
418     vlc_object_t **pp_current, **pp_end;
419
420     vlc_mutex_lock( &p_this->p_vlc->structure_lock );
421
422     pp_current = p_this->p_vlc->pp_objects;
423     pp_end = pp_current + p_this->p_vlc->i_objects;
424
425     for( ; pp_current < pp_end ; pp_current++ )
426     {
427         if( (*pp_current)->b_attached )
428         {
429             PrintObject( *pp_current, "" );
430         }
431         else
432         {
433             msg_Info( p_this->p_vlc, "o %.6x %s (not attached)",
434                       (*pp_current)->i_object_id,
435                       (*pp_current)->psz_object_type );
436         }
437     }
438
439     vlc_mutex_unlock( &p_this->p_vlc->structure_lock );
440 }
441
442 /*****************************************************************************
443  * vlc_dumpstructure: print the current vlc structure
444  *****************************************************************************
445  * This function prints an ASCII tree showing the connections between vlc
446  * objects, and additional information such as their refcount, thread ID, etc.
447  *****************************************************************************/
448 void __vlc_dumpstructure( vlc_object_t *p_this )
449 {
450     char psz_foo[2 * MAX_DUMPSTRUCTURE_DEPTH + 1];
451
452     vlc_mutex_lock( &p_this->p_vlc->structure_lock );
453     psz_foo[0] = '|';
454     DumpStructure( p_this, 0, psz_foo );
455     vlc_mutex_unlock( &p_this->p_vlc->structure_lock );
456 }
457
458 /*****************************************************************************
459  * vlc_list_release: free a list previously allocated by vlc_list_find
460  *****************************************************************************
461  * This function decreases the refcount of all objects in the list and
462  * frees the list.
463  *****************************************************************************/
464 void vlc_list_release( vlc_list_t *p_list )
465 {
466     if( p_list->i_count )
467     {
468         vlc_t *         p_vlc = p_list->pp_objects[0]->p_vlc;
469         vlc_object_t ** pp_current = p_list->pp_objects;
470
471         vlc_mutex_lock( &p_vlc->structure_lock );
472
473         while( pp_current[0] )
474         {
475             pp_current[0]->i_refcount--;
476             pp_current++;
477         }
478
479         vlc_mutex_unlock( &p_vlc->structure_lock );
480     }
481
482     free( p_list );
483 }
484
485 /* Following functions are local */
486
487 /*****************************************************************************
488  * FindIndex: find the index of an object in an array of objects
489  *****************************************************************************
490  * This function assumes that p_this can be found in pp_objects. It will not
491  * crash if p_this cannot be found, but will return a wrong value. It is your
492  * duty to check the return value if you are not certain that the object could
493  * be found for sure.
494  *****************************************************************************/
495 static int FindIndex( vlc_object_t *p_this,
496                       vlc_object_t **pp_objects, int i_count )
497 {
498     int i_middle = i_count / 2;
499
500     if( i_count == 0 )
501     {
502         return 0;
503     }
504
505     if( pp_objects[i_middle] == p_this )
506     {
507         return i_middle;
508     }
509
510     if( i_count == 1 )
511     {
512         return 0;
513     }
514
515     /* We take advantage of the sorted array */
516     if( pp_objects[i_middle]->i_object_id < p_this->i_object_id )
517     {
518         return i_middle + FindIndex( p_this, pp_objects + i_middle,
519                                              i_count - i_middle );
520     }
521     else
522     {
523         return FindIndex( p_this, pp_objects, i_middle );
524     }
525 }
526
527 static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode )
528 {
529     int i;
530     vlc_object_t *p_tmp;
531
532     switch( i_mode & 0x000f )
533     {
534     case FIND_PARENT:
535         p_tmp = p_this->p_parent;
536         if( p_tmp )
537         {
538             if( p_tmp->i_object_type == i_type )
539             {
540                 p_tmp->i_refcount++;
541                 return p_tmp;
542             }
543             else
544             {
545                 return FindObject( p_tmp, i_type, i_mode );
546             }
547         }
548         break;
549
550     case FIND_CHILD:
551         for( i = p_this->i_children; i--; )
552         {
553             p_tmp = p_this->pp_children[i];
554             if( p_tmp->i_object_type == i_type )
555             {
556                 p_tmp->i_refcount++;
557                 return p_tmp;
558             }
559             else if( p_tmp->i_children )
560             {
561                 p_tmp = FindObject( p_tmp, i_type, i_mode );
562                 if( p_tmp )
563                 {
564                     return p_tmp;
565                 }
566             }
567         }
568         break;
569
570     case FIND_ANYWHERE:
571         /* Handled in vlc_object_find */
572         break;
573     }
574
575     return NULL;
576 }
577
578 static void DetachObject( vlc_object_t *p_this )
579 {
580     vlc_object_t *p_parent = p_this->p_parent;
581     int i_index, i;
582
583     /* Remove p_this's parent */
584     p_this->p_parent = NULL;
585
586     /* Remove all of p_parent's children which are p_this */
587     for( i_index = p_parent->i_children ; i_index-- ; )
588     {
589         if( p_parent->pp_children[i_index] == p_this )
590         {
591             p_parent->i_children--;
592             for( i = i_index ; i < p_parent->i_children ; i++ )
593             {
594                 p_parent->pp_children[i] = p_parent->pp_children[i+1];
595             }
596         }
597     }
598
599     if( p_parent->i_children )
600     {
601         p_parent->pp_children = (vlc_object_t **)realloc( p_parent->pp_children,
602                                p_parent->i_children * sizeof(vlc_object_t *) );
603     }
604     else
605     {
606         free( p_parent->pp_children );
607         p_parent->pp_children = NULL;
608     }
609 }
610
611 /*****************************************************************************
612  * SetAttachment: recursively set the b_attached flag of a subtree.
613  *****************************************************************************
614  * This function is used by the attach and detach functions to propagate
615  * the b_attached flag in a subtree.
616  *****************************************************************************/
617 static void SetAttachment( vlc_object_t *p_this, vlc_bool_t b_attached )
618 {
619     int i_index;
620
621     for( i_index = p_this->i_children ; i_index-- ; )
622     {
623         SetAttachment( p_this->pp_children[i_index], b_attached );
624     }
625
626     p_this->b_attached = b_attached;
627 }
628
629 static void PrintObject( vlc_object_t *p_this, const char *psz_prefix )
630 {
631     char psz_children[20], psz_refcount[20], psz_thread[20], psz_name[50];
632
633     psz_name[0] = '\0';
634     if( p_this->psz_object_name )
635     {
636         snprintf( psz_name, 50, " \"%s\"", p_this->psz_object_name );
637         psz_name[48] = '\"';
638         psz_name[49] = '\0';
639     }
640
641     psz_children[0] = '\0';
642     switch( p_this->i_children )
643     {
644         case 0:
645             break;
646         case 1:
647             strcpy( psz_children, ", 1 child" );
648             break;
649         default:
650             snprintf( psz_children, 20,
651                       ", %i children", p_this->i_children );
652             psz_children[19] = '\0';
653             break;
654     }
655
656     psz_refcount[0] = '\0';
657     if( p_this->i_refcount )
658     {
659         snprintf( psz_refcount, 20, ", refcount %i", p_this->i_refcount );
660         psz_refcount[19] = '\0';
661     }
662
663     psz_thread[0] = '\0';
664     if( p_this->b_thread )
665     {
666         snprintf( psz_thread, 20, " (thread %d)", (int)p_this->thread_id );
667         psz_thread[19] = '\0';
668     }
669
670     msg_Info( p_this->p_vlc, "%so %.6x %s%s%s%s%s", psz_prefix,
671               p_this->i_object_id, p_this->psz_object_type,
672               psz_name, psz_thread, psz_refcount, psz_children );
673 }
674
675 static void DumpStructure( vlc_object_t *p_this, int i_level, char *psz_foo )
676 {
677     int i;
678     char i_back = psz_foo[i_level];
679     psz_foo[i_level] = '\0';
680
681     PrintObject( p_this, psz_foo );
682
683     psz_foo[i_level] = i_back;
684
685     if( i_level / 2 >= MAX_DUMPSTRUCTURE_DEPTH )
686     {
687         msg_Warn( p_this, "structure tree is too deep" );
688         return;
689     }
690
691     for( i = 0 ; i < p_this->i_children ; i++ )
692     {
693         if( i_level )
694         {
695             psz_foo[i_level-1] = ' ';
696
697             if( psz_foo[i_level-2] == '`' )
698             {
699                 psz_foo[i_level-2] = ' ';
700             }
701         }
702
703         if( i == p_this->i_children - 1 )
704         {
705             psz_foo[i_level] = '`';
706         }
707         else
708         {
709             psz_foo[i_level] = '|';
710         }
711
712         psz_foo[i_level+1] = '-';
713         psz_foo[i_level+2] = '\0';
714
715         DumpStructure( p_this->pp_children[i], i_level + 2, psz_foo );
716     }
717 }
718
719 static vlc_list_t * NewList( void )
720 {
721     vlc_list_t *p_list = malloc( sizeof( vlc_list_t )
722                                      + 3 * sizeof( vlc_object_t * ) );
723
724     if( p_list == NULL )
725     {
726         return NULL;
727     }
728
729     p_list->i_count = 0;
730     p_list->pp_objects = &p_list->_p_first;
731
732     /* We allocated space for NULL and for three extra objects */
733     p_list->_i_extra = 3;
734     p_list->_p_first = NULL;
735
736     return p_list;
737 }
738
739 static vlc_list_t * ListAppend( vlc_list_t *p_list, vlc_object_t *p_object )
740 {
741     if( p_list == NULL )
742     {
743         return NULL;
744     }
745
746     if( p_list->_i_extra == 0 )
747     {
748         /* If we had X objects it means the array has a size of X+1, we
749          * make it size 2X+2, so we alloc 2X+1 because there is already
750          * one allocated in the real structure */
751         p_list = realloc( p_list, sizeof( vlc_list_t )
752                                    + (p_list->i_count * 2 + 1)
753                                        * sizeof( vlc_object_t * ) );
754         if( p_list == NULL ) 
755         {
756             return NULL;
757         }
758
759         /* We have X+1 extra slots */
760         p_list->_i_extra = p_list->i_count + 1;
761         p_list->pp_objects = &p_list->_p_first;
762     }
763
764     p_object->i_refcount++;
765
766     p_list->pp_objects[p_list->i_count] = p_object;
767     p_list->i_count++;
768     p_list->pp_objects[p_list->i_count] = NULL;
769     p_list->_i_extra--;
770
771     return p_list;
772 }
773