]> git.sesse.net Git - vlc/blob - src/input/input_programs.c
4fe43cac46827d086eb7fa035cf5642ba15c7651
[vlc] / src / input / input_programs.c
1 /*****************************************************************************
2  * input_programs.c: es_descriptor_t, pgrm_descriptor_t management
3  *****************************************************************************
4  * Copyright (C) 1999-2002 VideoLAN
5  * $Id: input_programs.c,v 1.93 2002/07/23 00:39:17 sam Exp $
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
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 <stdlib.h>
28 #include <string.h>                                    /* memcpy(), memset() */
29 #include <sys/types.h>                                              /* off_t */
30
31 #include <vlc/vlc.h>
32
33 #include "stream_control.h"
34 #include "input_ext-intf.h"
35 #include "input_ext-dec.h"
36 #include "input_ext-plugins.h"
37
38 /*
39  * NOTICE : all of these functions expect you to have taken the lock on
40  * p_input->stream.lock
41  */
42
43 /*****************************************************************************
44  * input_InitStream: init the stream descriptor of the given input
45  *****************************************************************************/
46 int input_InitStream( input_thread_t * p_input, size_t i_data_len )
47 {
48
49     p_input->stream.i_stream_id = 0;
50
51     /* initialized to 0 since we don't give the signal to the interface
52      * before the end of input initialization */
53     p_input->stream.b_changed = 0;
54     p_input->stream.pp_es = NULL;
55     p_input->stream.pp_selected_es = NULL;
56     p_input->stream.p_removed_es = NULL;
57     p_input->stream.p_newly_selected_es = NULL;
58     p_input->stream.pp_programs = NULL;
59     p_input->stream.p_selected_program = NULL;
60     p_input->stream.p_new_program = NULL;
61     
62     if( i_data_len )
63     {
64         if ( (p_input->stream.p_demux_data = malloc( i_data_len )) == NULL )
65         {
66             msg_Err( p_input, "out of memory" );
67             return 1;
68         }
69         memset( p_input->stream.p_demux_data, 0, i_data_len );
70     }
71     else
72     {
73         p_input->stream.p_demux_data = NULL;
74     }
75
76     return 0;
77 }
78
79 /*****************************************************************************
80  * input_EndStream: free all stream descriptors
81  *****************************************************************************/
82 void input_EndStream( input_thread_t * p_input )
83 {
84     /* Free all programs and associated ES, and associated decoders. */
85     while( p_input->stream.i_pgrm_number )
86     {
87         input_DelProgram( p_input, p_input->stream.pp_programs[0] );
88     }
89
90     /* Free standalone ES */
91     while( p_input->stream.i_es_number )
92     {
93         input_DelES( p_input, p_input->stream.pp_es[0] );
94     }
95
96     /* Free all areas */
97     while( p_input->stream.i_area_nb )
98     {
99         input_DelArea( p_input, p_input->stream.pp_areas[0] );
100     }
101
102     /* Free selected ES */
103     if( p_input->stream.pp_selected_es != NULL )
104     {
105         free( p_input->stream.pp_selected_es );
106     }
107     
108     if( p_input->stream.p_demux_data != NULL )
109     {
110         free( p_input->stream.p_demux_data );
111     }
112 }
113
114 /*****************************************************************************
115  * input_FindProgram: returns a pointer to a program described by its ID
116  *****************************************************************************/
117 pgrm_descriptor_t * input_FindProgram( input_thread_t * p_input, u16 i_pgrm_id )
118 {
119     int     i;
120
121     for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
122     {
123         if( p_input->stream.pp_programs[i]->i_number == i_pgrm_id )
124         {
125             return p_input->stream.pp_programs[i];
126         }
127     }
128
129     return NULL;
130 }
131
132 /*****************************************************************************
133  * input_AddProgram: add and init a program descriptor
134  *****************************************************************************
135  * This program descriptor will be referenced in the given stream descriptor
136  *****************************************************************************/
137 pgrm_descriptor_t * input_AddProgram( input_thread_t * p_input,
138                                       u16 i_pgrm_id, size_t i_data_len )
139 {
140     /* Where to add the pgrm */
141     int i_pgrm_index = p_input->stream.i_pgrm_number;
142
143     /* Add an entry to the list of program associated with the stream */
144     p_input->stream.i_pgrm_number++;
145     p_input->stream.pp_programs = realloc( p_input->stream.pp_programs,
146                                            p_input->stream.i_pgrm_number
147                                            * sizeof(pgrm_descriptor_t *) );
148     if( p_input->stream.pp_programs == NULL )
149     {
150         msg_Err( p_input, "out of memory" );
151         return( NULL );
152     }
153
154     /* Allocate the structure to store this description */
155     p_input->stream.pp_programs[i_pgrm_index] =
156                                         malloc( sizeof(pgrm_descriptor_t) );
157     if( p_input->stream.pp_programs[i_pgrm_index] == NULL )
158     {
159         msg_Err( p_input, "out of memory" );
160         return( NULL );
161     }
162     
163     /* Init this entry */
164     p_input->stream.pp_programs[i_pgrm_index]->i_number = i_pgrm_id;
165     p_input->stream.pp_programs[i_pgrm_index]->b_is_ok = 0;
166     p_input->stream.pp_programs[i_pgrm_index]->i_version = 0;
167
168     p_input->stream.pp_programs[i_pgrm_index]->i_es_number = 0;
169     p_input->stream.pp_programs[i_pgrm_index]->pp_es = NULL;
170
171     input_ClockInit( p_input->stream.pp_programs[i_pgrm_index] );
172
173     p_input->stream.pp_programs[i_pgrm_index]->i_synchro_state
174                                                 = SYNCHRO_START;
175
176     if( i_data_len )
177     {
178         p_input->stream.pp_programs[i_pgrm_index]->p_demux_data =
179             malloc( i_data_len );
180         if( p_input->stream.pp_programs[i_pgrm_index]->p_demux_data == NULL )
181         {
182             msg_Err( p_input, "out of memory" );
183             return( NULL );
184         }
185         memset( p_input->stream.pp_programs[i_pgrm_index]->p_demux_data, 0,
186                 i_data_len );
187     }
188     else
189     {
190         p_input->stream.pp_programs[i_pgrm_index]->p_demux_data = NULL;
191     }
192
193     return p_input->stream.pp_programs[i_pgrm_index];
194 }
195
196 /*****************************************************************************
197  * input_DelProgram: destroy a program descriptor
198  *****************************************************************************
199  * All ES descriptions referenced in the descriptor will be deleted.
200  *****************************************************************************/
201 void input_DelProgram( input_thread_t * p_input, pgrm_descriptor_t * p_pgrm )
202 {
203     int i_pgrm_index;
204
205     /* Find the program in the programs table */
206     for( i_pgrm_index = 0; i_pgrm_index < p_input->stream.i_pgrm_number;
207          i_pgrm_index++ )
208     {
209         if( p_input->stream.pp_programs[i_pgrm_index] == p_pgrm )
210             break;
211     }
212
213     /* If the program wasn't found, do nothing */
214     if( i_pgrm_index == p_input->stream.i_pgrm_number )
215     {
216         msg_Err( p_input, "program does not belong to this input" );
217         return;
218     }
219
220     /* Free the structures that describe the es that belongs to that program */
221     while( p_pgrm->i_es_number )
222     {
223         input_DelES( p_input, p_pgrm->pp_es[0] );
224     }
225
226     /* Free the demux data */
227     if( p_pgrm->p_demux_data != NULL )
228     {
229         free( p_pgrm->p_demux_data );
230     }
231
232     /* Remove this program from the stream's list of programs */
233     p_input->stream.i_pgrm_number--;
234
235     p_input->stream.pp_programs[i_pgrm_index] =
236         p_input->stream.pp_programs[p_input->stream.i_pgrm_number];
237     if( p_input->stream.i_pgrm_number ) 
238     {
239         p_input->stream.pp_programs = realloc( p_input->stream.pp_programs,
240                                                p_input->stream.i_pgrm_number
241                                                * sizeof(pgrm_descriptor_t *) );
242         if( p_input->stream.pp_programs == NULL )
243         {
244             msg_Err( p_input, "cannot realloc memory" );
245         }
246     }
247     else
248     {
249         free( p_input->stream.pp_programs );
250         p_input->stream.pp_programs = NULL;
251     }
252
253     /* Free the description of this program */
254     free( p_pgrm );
255 }
256
257 /*****************************************************************************
258  * input_AddArea: add and init an area descriptor
259  *****************************************************************************
260  * This area descriptor will be referenced in the given stream descriptor
261  *****************************************************************************/
262 input_area_t * input_AddArea( input_thread_t * p_input )
263 {
264     /* Where to add the pgrm */
265     int i_area_index = p_input->stream.i_area_nb;
266
267     /* Add an entry to the list of program associated with the stream */
268     p_input->stream.i_area_nb++;
269     p_input->stream.pp_areas = realloc( p_input->stream.pp_areas,
270                                         p_input->stream.i_area_nb
271                                         * sizeof(input_area_t *) );
272     if( p_input->stream.pp_areas == NULL )
273     {
274         msg_Err( p_input, "out of memory" );
275         return( NULL );
276     }
277
278     /* Allocate the structure to store this description */
279     p_input->stream.pp_areas[i_area_index] =
280                                         malloc( sizeof(input_area_t) );
281     if( p_input->stream.pp_areas[i_area_index] == NULL )
282     {
283         msg_Err( p_input, "out of memory" );
284         return( NULL );
285     }
286     
287     /* Init this entry */
288     p_input->stream.pp_areas[i_area_index]->i_id = 0;
289     p_input->stream.pp_areas[i_area_index]->i_start = 0;
290     p_input->stream.pp_areas[i_area_index]->i_size = 0;
291     p_input->stream.pp_areas[i_area_index]->i_tell = 0;
292     p_input->stream.pp_areas[i_area_index]->i_seek = NO_SEEK;
293     p_input->stream.pp_areas[i_area_index]->i_part_nb = 1;
294     p_input->stream.pp_areas[i_area_index]->i_part= 0;
295
296     return p_input->stream.pp_areas[i_area_index];
297 }
298
299 /*****************************************************************************
300  * input_SetProgram: changes the current program
301  *****************************************************************************/
302 int input_SetProgram( input_thread_t * p_input, pgrm_descriptor_t * p_new_prg )
303 {
304     int i_es_index;
305     int i_required_audio_es;
306     int i_required_spu_es;
307     int i_audio_es = 0;
308     int i_spu_es = 0;
309
310     if ( p_input->stream.p_selected_program )
311     {
312         for ( i_es_index = 1 ; /* 0 should be the PMT */
313                 i_es_index < p_input->stream.p_selected_program->
314                 i_es_number ;
315                 i_es_index ++ )
316         {
317 #define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
318             if ( p_es->p_decoder_fifo ) /* if the ES was selected */
319             {
320                 input_UnselectES( p_input , p_es );
321             }
322 #undef p_es
323         }
324     }
325     /* Get the number of the required audio stream */
326     if( config_GetInt( p_input, "audio" ) )
327     {
328         /* Default is the first one */
329         i_required_audio_es = config_GetInt( p_input, "audio-channel" );
330         if( i_required_audio_es < 0 )
331         {
332             i_required_audio_es = 1;
333         }
334     }
335     else
336     {
337         i_required_audio_es = 0;
338     }
339
340     /* Same thing for subtitles */
341     if( config_GetInt( p_input, "video" ) )
342     {
343         /* for spu, default is none */
344         i_required_spu_es = config_GetInt( p_input, "spu-channel" );
345         if( i_required_spu_es < 0 )
346         {
347             i_required_spu_es = 0;
348         }
349     }
350     else
351     {
352         i_required_spu_es = 0;
353     }
354
355     for( i_es_index = 0 ; i_es_index < p_new_prg->i_es_number ; i_es_index ++ )
356     {
357         switch( p_new_prg->pp_es[i_es_index]->i_cat )
358         {
359             case VIDEO_ES:
360                 msg_Dbg( p_input, "selecting ES %x",
361                          p_new_prg->pp_es[i_es_index]->i_id );
362                 input_SelectES( p_input, p_new_prg->pp_es[i_es_index] );
363                 break;
364             case AUDIO_ES:
365                 i_audio_es += 1;
366                 if( i_audio_es <= i_required_audio_es )
367                 {
368                     msg_Dbg( p_input, "selecting ES %x",
369                              p_new_prg->pp_es[i_es_index]->i_id );
370                     input_SelectES( p_input, p_new_prg->pp_es[i_es_index]);
371                 }
372                 break;
373             /* Not sure this one is fully specification-compliant */
374             case SPU_ES :
375                 i_spu_es += 1;
376                 if( i_spu_es <= i_required_spu_es )
377                 {
378                     msg_Dbg( p_input, "selecting ES %x",
379                              p_new_prg->pp_es[i_es_index]->i_id );
380                     input_SelectES( p_input, p_new_prg->pp_es[i_es_index] );
381                 }
382             break;
383             default :
384                 msg_Dbg( p_input, "ES %x has unknown type",
385                          p_new_prg->pp_es[i_es_index]->i_id );
386                 break;
387         }
388
389     }
390
391
392     p_input->stream.p_selected_program = p_new_prg;
393
394     return( 0 );
395 }
396
397
398 /*****************************************************************************
399  * input_DelArea: destroy a area descriptor
400  *****************************************************************************
401  * All ES descriptions referenced in the descriptor will be deleted.
402  *****************************************************************************/
403 void input_DelArea( input_thread_t * p_input, input_area_t * p_area )
404 {
405     int i_area_index;
406
407     /* Find the area in the areas table */
408     for( i_area_index = 0; i_area_index < p_input->stream.i_area_nb;
409          i_area_index++ )
410     {
411         if( p_input->stream.pp_areas[i_area_index] == p_area )
412             break;
413     }
414
415     /* If the area wasn't found, do nothing */
416     if( i_area_index == p_input->stream.i_area_nb )
417     {
418         msg_Err( p_input, "area does not belong to this input" );
419         return;
420     }
421
422     /* Remove this area from the stream's list of areas */
423     p_input->stream.i_area_nb--;
424
425     p_input->stream.pp_areas[i_area_index] =
426         p_input->stream.pp_areas[p_input->stream.i_area_nb];
427     if( p_input->stream.i_area_nb )
428     {
429         p_input->stream.pp_areas = realloc( p_input->stream.pp_areas,
430                                             p_input->stream.i_area_nb
431                                             * sizeof(input_area_t *) );
432
433         if( p_input->stream.pp_areas == NULL )
434         {
435             msg_Err( p_input, "cannot realloc memory" );
436         }
437     }
438     else
439     {
440         free( p_input->stream.pp_areas );
441         p_input->stream.pp_areas = NULL;
442     }
443
444     /* Free the description of this area */
445     free( p_area );
446 }
447
448
449 /*****************************************************************************
450  * input_FindES: returns a pointer to an ES described by its ID
451  *****************************************************************************/
452 es_descriptor_t * input_FindES( input_thread_t * p_input, u16 i_es_id )
453 {
454     int     i;
455
456     for( i = 0; i < p_input->stream.i_es_number; i++ )
457     {
458         if( p_input->stream.pp_es[i]->i_id == i_es_id )
459         {
460             return p_input->stream.pp_es[i];
461         }
462     }
463
464     return NULL;
465 }
466
467 /*****************************************************************************
468  * input_AddES:
469  *****************************************************************************
470  * Reserve a slot in the table of ES descriptors for the ES and add it to the
471  * list of ES of p_pgrm. If p_pgrm if NULL, then the ES is considered as stand
472  * alone (PSI ?)
473  *****************************************************************************/
474 es_descriptor_t * input_AddES( input_thread_t * p_input,
475                                pgrm_descriptor_t * p_pgrm, u16 i_es_id,
476                                size_t i_data_len )
477 {
478     es_descriptor_t * p_es;
479
480     p_es = (es_descriptor_t *)malloc( sizeof(es_descriptor_t) );
481     if( p_es == NULL )
482     {
483         msg_Err( p_input, "out of memory" );
484         return( NULL);
485     }
486     p_input->stream.i_es_number++;
487     p_input->stream.pp_es = realloc( p_input->stream.pp_es,
488                                      p_input->stream.i_es_number
489                                       * sizeof(es_descriptor_t *) );
490     if( p_input->stream.pp_es == NULL )
491     {
492         msg_Err( p_input, "out of memory" );
493         return( NULL );
494     }
495
496     p_input->stream.pp_es[p_input->stream.i_es_number - 1] = p_es;
497
498     /* Init its values */
499     p_es->i_id = i_es_id;
500     p_es->psz_desc[0] = '\0';
501     p_es->p_pes = NULL;
502     p_es->p_decoder_fifo = NULL;
503     p_es->i_cat = UNKNOWN_ES;
504     p_es->i_demux_fd = 0;
505     p_es->c_packets = 0;
506     p_es->c_invalid_packets = 0;
507
508     if( i_data_len )
509     {
510         p_es->p_demux_data = malloc( i_data_len );
511         if( p_es->p_demux_data == NULL )
512         {
513             msg_Err( p_input, "out of memory" );
514             return( NULL );
515         }
516         memset( p_es->p_demux_data, 0, i_data_len );
517     }
518     else
519     {
520         p_es->p_demux_data = NULL;
521     }
522
523     /* Add this ES to the program definition if one is given */
524     if( p_pgrm )
525     {
526         p_pgrm->i_es_number++;
527         p_pgrm->pp_es = realloc( p_pgrm->pp_es,
528                                  p_pgrm->i_es_number
529                                   * sizeof(es_descriptor_t *) );
530         if( p_pgrm->pp_es == NULL )
531         {
532             msg_Err( p_input, "out of memory" );
533             return( NULL );
534         }
535
536         p_pgrm->pp_es[p_pgrm->i_es_number - 1] = p_es;
537         p_es->p_pgrm = p_pgrm;
538     }
539     else
540     {
541         p_es->p_pgrm = NULL;
542     }
543
544     return p_es;
545 }
546
547 /*****************************************************************************
548  * input_DelES:
549  *****************************************************************************/
550 void input_DelES( input_thread_t * p_input, es_descriptor_t * p_es )
551 {
552     int                     i_index, i_es_index;
553     pgrm_descriptor_t *     p_pgrm;
554
555     /* Find the ES in the ES table */
556     for( i_es_index = 0; i_es_index < p_input->stream.i_es_number;
557          i_es_index++ )
558     {
559         if( p_input->stream.pp_es[i_es_index] == p_es )
560             break;
561     }
562
563     /* If the ES wasn't found, do nothing */
564     if( i_es_index == p_input->stream.i_es_number )
565     {
566         msg_Err( p_input, "ES does not belong to this input" );
567         return;
568     }
569
570     p_pgrm = p_es->p_pgrm;
571
572     /* Kill associated decoder, if any. */
573     if( p_es->p_decoder_fifo != NULL )
574     {
575         input_EndDecoder( p_input, p_es );
576     }
577
578     /* Remove this ES from the description of the program if it is associated to
579      * one */
580     if( p_pgrm )
581     {
582         for( i_index = 0; i_index < p_pgrm->i_es_number; i_index++ )
583         {
584             if( p_pgrm->pp_es[i_index] == p_es )
585             {
586                 p_pgrm->i_es_number--;
587                 p_pgrm->pp_es[i_index] = p_pgrm->pp_es[p_pgrm->i_es_number];
588                 if( p_pgrm->i_es_number )
589                 {
590                     p_pgrm->pp_es = realloc( p_pgrm->pp_es,
591                                              p_pgrm->i_es_number
592                                               * sizeof(es_descriptor_t *));
593                     if( p_pgrm->pp_es == NULL )
594                     {
595                         msg_Err( p_input, "cannot realloc memory" );
596                     }
597                 }
598                 else
599                 {
600                     free( p_pgrm->pp_es );
601                     p_pgrm->pp_es = NULL;
602                 }
603                 break;
604             }
605         }
606     }
607
608     /* Free the demux data */
609     if( p_es->p_demux_data != NULL )
610     {
611         free( p_es->p_demux_data );
612     }
613
614     /* Find the ES in the ES table */
615     for( i_es_index = 0; i_es_index < p_input->stream.i_es_number;
616          i_es_index++ )
617     {
618         if( p_input->stream.pp_es[i_es_index] == p_es )
619             break;
620     }
621
622     /* Remove this ES from the stream's list of ES */
623     p_input->stream.i_es_number--;
624     p_input->stream.pp_es[i_es_index] =
625                     p_input->stream.pp_es[p_input->stream.i_es_number];
626     if( p_input->stream.i_es_number )
627     {
628         p_input->stream.pp_es = realloc( p_input->stream.pp_es,
629                                          p_input->stream.i_es_number
630                                           * sizeof(es_descriptor_t *));
631         if( p_input->stream.pp_es == NULL )
632         {
633             msg_Err( p_input, "cannot realloc memory" );
634         }
635     }
636     else
637     {
638         free( p_input->stream.pp_es );
639         p_input->stream.pp_es = NULL;
640     }
641     
642     /* Free the ES */
643     free( p_es );
644 }
645
646 /*****************************************************************************
647  * input_SelectES: selects an ES and spawns the associated decoder
648  *****************************************************************************
649  * Remember we are still supposed to have stream_lock when entering this
650  * function ?
651  *****************************************************************************/
652 int input_SelectES( input_thread_t * p_input, es_descriptor_t * p_es )
653 {
654     decoder_fifo_t *p_fifo;
655
656     if( p_es == NULL )
657     {
658         msg_Err( p_input, "nothing to do in input_SelectES" );
659         return -1;
660     }
661
662     msg_Dbg( p_input, "selecting ES 0x%x", p_es->i_id );
663
664     if( p_es->p_decoder_fifo != NULL )
665     {
666         msg_Err( p_input, "ES 0x%x is already selected", p_es->i_id );
667         return -1;
668     }
669
670     /* Release the lock, not to block the input thread during
671      * the creation of the thread. */
672     vlc_mutex_unlock( &p_input->stream.stream_lock );
673     p_fifo = input_RunDecoder( p_input, p_es );
674     vlc_mutex_lock( &p_input->stream.stream_lock );
675
676     if( p_fifo == NULL )
677     {
678         return -1;
679     }
680
681     p_es->p_decoder_fifo = p_fifo;
682
683     return 0;
684 }
685
686 /*****************************************************************************
687  * input_UnselectES: removes an ES from the list of selected ES
688  *****************************************************************************/
689 int input_UnselectES( input_thread_t * p_input, es_descriptor_t * p_es )
690 {
691
692     int     i_index = 0;
693
694     if( p_es == NULL )
695     {
696         msg_Err( p_input, "nothing to do in input_UnselectES" );
697         return -1;
698     }
699
700     msg_Dbg( p_input, "unselecting ES 0x%x", p_es->i_id );
701
702     if( p_es->p_decoder_fifo == NULL )
703     {
704         msg_Err( p_input, "ES 0x%x is not selected", p_es->i_id );
705         return( -1 );
706     }
707
708     input_EndDecoder( p_input, p_es );
709     p_es->p_pes = NULL;
710
711     if( ( p_es->p_decoder_fifo == NULL ) &&
712         ( p_input->stream.i_selected_es_number > 0 ) )
713     {
714         p_input->stream.i_selected_es_number--;
715
716         while( ( i_index < p_input->stream.i_selected_es_number ) &&
717                ( p_input->stream.pp_selected_es[i_index] != p_es ) )
718         {
719             i_index++;
720         }
721
722         p_input->stream.pp_selected_es[i_index] = 
723           p_input->stream.pp_selected_es[p_input->stream.i_selected_es_number];
724
725         if( p_input->stream.i_selected_es_number )
726         {
727             p_input->stream.pp_selected_es = realloc(
728                                            p_input->stream.pp_selected_es,
729                                            p_input->stream.i_selected_es_number
730                                            * sizeof(es_descriptor_t *) );
731             if( p_input->stream.pp_selected_es == NULL )
732             {
733                 msg_Err( p_input, "cannot realloc memory" );
734                 return( -1 );
735             }
736         }
737         else
738         {
739             free( p_input->stream.pp_selected_es );   
740             p_input->stream.pp_selected_es = NULL;
741             msg_Dbg( p_input, "no more selected ES" );
742             return( 1 );
743         }
744     }
745
746     return( 0 );
747 }