1 /*****************************************************************************
2 * input.c: input thread
3 *****************************************************************************
4 * Copyright (C) 1998-2004 the VideoLAN team
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Laurent Aimar <fenrir@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc/input.h>
33 #include <vlc/decoder.h>
36 #include "input_internal.h"
38 #include "stream_output.h"
39 #include "vlc_playlist.h"
40 #include "vlc_interface.h"
41 #include "vlc_interaction.h"
45 #ifdef HAVE_SYS_STAT_H
46 # include <sys/stat.h>
49 /*****************************************************************************
51 *****************************************************************************/
52 static int Run ( input_thread_t *p_input );
53 static int RunAndClean ( input_thread_t *p_input );
55 static input_thread_t * Create ( vlc_object_t *, input_item_t *, char *,
57 static int Init ( input_thread_t *p_input );
58 static void Error ( input_thread_t *p_input );
59 static void End ( input_thread_t *p_input );
60 static void MainLoop( input_thread_t *p_input );
62 static inline int ControlPopNoLock( input_thread_t *, int *, vlc_value_t * );
63 static void ControlReduce( input_thread_t * );
64 static vlc_bool_t Control( input_thread_t *, int, vlc_value_t );
66 static int UpdateFromAccess( input_thread_t * );
67 static int UpdateFromDemux( input_thread_t * );
68 static int UpdateMeta( input_thread_t * );
70 static void UpdateItemLength( input_thread_t *, int64_t i_length );
72 static void DecodeUrl( char * );
73 static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
75 static input_source_t *InputSourceNew( input_thread_t *);
76 static int InputSourceInit( input_thread_t *, input_source_t *,
77 char *, char *psz_forced_demux );
78 static void InputSourceClean( input_thread_t *, input_source_t * );
80 static void SlaveDemux( input_thread_t *p_input );
81 static void SlaveSeek( input_thread_t *p_input );
83 static void InputMetaUser( input_thread_t *p_input );
85 /*****************************************************************************
86 * This function creates a new input, and returns a pointer
87 * to its description. On error, it returns NULL.
89 * Variables for _public_ use:
92 * - rate,rate-slower, rate-faster
93 * - position, position-offset
95 * - title,title-next,title-prev
96 * - chapter,chapter-next, chapter-prev
97 * - program, audio-es, video-es, spu-es
98 * - audio-delay, spu-delay
103 * - seekable (if you can seek, it doesn't say if 'bar display' has be shown or not, for that check position != 0.0)
104 * * For intf callback upon changes
106 * TODO explain when Callback is called
107 * TODO complete this list (?)
108 *****************************************************************************/
109 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
110 char *psz_header, vlc_bool_t b_quick )
112 input_thread_t *p_input = NULL; /* thread descriptor */
116 /* Allocate descriptor */
117 p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
118 if( p_input == NULL )
120 msg_Err( p_parent, "out of memory" );
123 p_input->b_preparsing = b_quick;
124 p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
126 /* Init Common fields */
127 p_input->b_eof = VLC_FALSE;
128 p_input->b_can_pace_control = VLC_TRUE;
129 p_input->i_start = 0;
132 p_input->i_title = 0;
133 p_input->title = NULL;
134 p_input->i_title_offset = p_input->i_seekpoint_offset = 0;
135 p_input->i_state = INIT_S;
136 p_input->i_rate = INPUT_RATE_DEFAULT;
137 p_input->i_bookmark = 0;
138 p_input->bookmark = NULL;
139 p_input->p_meta = NULL;
140 p_input->p_es_out = NULL;
141 p_input->p_sout = NULL;
142 p_input->b_out_pace_control = VLC_FALSE;
143 p_input->i_pts_delay = 0;
145 /* Init Input fields */
146 p_input->input.p_item = p_item;
147 p_input->input.p_access = NULL;
148 p_input->input.p_stream = NULL;
149 p_input->input.p_demux = NULL;
150 p_input->input.b_title_demux = VLC_FALSE;
151 p_input->input.i_title = 0;
152 p_input->input.title = NULL;
153 p_input->input.i_title_offset = p_input->input.i_seekpoint_offset = 0;
154 p_input->input.b_can_pace_control = VLC_TRUE;
155 p_input->input.b_eof = VLC_FALSE;
156 p_input->input.i_cr_average = 0;
158 if( !p_input->input.p_item->p_meta )
159 p_input->input.p_item->p_meta = vlc_meta_New();
160 stats_ReinitInputStats( p_item->p_stats );
163 p_input->i_slave = 0;
164 p_input->slave = NULL;
166 /* Init control buffer */
167 vlc_mutex_init( p_input, &p_input->lock_control );
168 p_input->i_control = 0;
170 /* Parse input options */
171 vlc_mutex_lock( &p_item->lock );
172 for( i = 0; i < p_item->i_options; i++ )
174 var_OptionParse( p_input, p_item->ppsz_options[i] );
176 vlc_mutex_unlock( &p_item->lock );
178 /* Create Object Variables for private use only */
179 input_ConfigVarInit( p_input );
181 /* Create Objects variables for public Get and Set */
182 input_ControlVarInit( p_input );
183 p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
185 if( !p_input->b_preparsing )
187 var_Get( p_input, "bookmarks", &val );
190 /* FIXME: have a common cfg parsing routine used by sout and others */
191 char *psz_parser, *psz_start, *psz_end;
192 psz_parser = val.psz_string;
193 while( (psz_start = strchr( psz_parser, '{' ) ) )
195 seekpoint_t *p_seekpoint = vlc_seekpoint_New();
198 psz_end = strchr( psz_start, '}' );
199 if( !psz_end ) break;
200 psz_parser = psz_end + 1;
201 backup = *psz_parser;
204 while( (psz_end = strchr( psz_start, ',' ) ) )
207 if( !strncmp( psz_start, "name=", 5 ) )
209 p_seekpoint->psz_name = psz_start + 5;
211 else if( !strncmp( psz_start, "bytes=", 6 ) )
213 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
215 else if( !strncmp( psz_start, "time=", 5 ) )
217 p_seekpoint->i_time_offset = atoll(psz_start + 5) *
220 psz_start = psz_end + 1;
222 msg_Dbg( p_input, "adding bookmark: %s, bytes="I64Fd", time="I64Fd,
223 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
224 p_seekpoint->i_time_offset );
225 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
226 vlc_seekpoint_Delete( p_seekpoint );
227 *psz_parser = backup;
229 free( val.psz_string );
233 /* Remove 'Now playing' info as it is probably outdated */
234 input_Control( p_input, INPUT_DEL_INFO, _(VLC_META_INFO_CAT),
235 VLC_META_NOW_PLAYING ); /* ? Don't translate as it might has been copied ? */
241 * Initialize an input thread and run it. You will need to monitor the
242 * thread to clean up after it is done
244 * \param p_parent a vlc_object
245 * \param p_item an input item
246 * \return a pointer to the spawned input thread
248 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
249 input_item_t *p_item )
251 return __input_CreateThread2( p_parent, p_item, NULL );
256 input_thread_t *__input_CreateThread2( vlc_object_t *p_parent,
257 input_item_t *p_item,
260 input_thread_t *p_input = NULL; /* thread descriptor */
262 p_input = Create( p_parent, p_item, psz_header, VLC_FALSE );
263 /* Now we can attach our new input */
264 vlc_object_attach( p_input, p_parent );
266 /* Create thread and wait for its readiness. */
267 if( vlc_thread_create( p_input, "input", Run,
268 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
270 msg_Err( p_input, "cannot create input thread" );
271 vlc_object_detach( p_input );
272 vlc_object_destroy( p_input );
281 * Initialize an input thread and run it. This thread will clean after himself,
282 * you can forget about it. It can work either in blocking or non-blocking mode
284 * \param p_parent a vlc_object
285 * \param p_item an input item
286 * \param b_block should we block until read is finished ?
287 * \return the input object id if non blocking, an error code else
289 int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
292 input_thread_t *p_input = NULL; /* thread descriptor */
294 p_input = Create( p_parent, p_item, NULL, VLC_FALSE );
295 /* Now we can attach our new input */
296 vlc_object_attach( p_input, p_parent );
300 RunAndClean( p_input );
305 if( vlc_thread_create( p_input, "input", RunAndClean,
306 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
308 msg_Err( p_input, "cannot create input thread" );
309 vlc_object_detach( p_input );
310 vlc_object_destroy( p_input );
314 return p_input->i_object_id;
318 * Initialize an input and initialize it to preparse the item
319 * This function is blocking. It will only accept to parse files
321 * \param p_parent a vlc_object_t
322 * \param p_item an input item
323 * \return VLC_SUCCESS or an error
325 int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
327 input_thread_t *p_input = NULL; /* thread descriptor */
329 /* Allocate descriptor */
330 p_input = Create( p_parent, p_item, NULL, VLC_TRUE );
331 p_input->i_flags |= OBJECT_FLAGS_QUIET;
332 p_input->i_flags |= OBJECT_FLAGS_NOINTERACT;
334 /* Now we can attach our new input */
335 vlc_object_attach( p_input, p_parent );
339 /* Clean up master */
340 InputSourceClean( p_input, &p_input->input );
342 /* Unload all modules */
343 if( p_input->p_es_out ) input_EsOutDelete( p_input->p_es_out );
345 vlc_object_detach( p_input );
346 vlc_object_destroy( p_input );
352 * Request a running input thread to stop and die
354 * \param the input thread to stop
356 void input_StopThread( input_thread_t *p_input )
361 /* Set die for input */
362 p_input->b_die = VLC_TRUE;
364 /* We cannot touch p_input fields directly (we can from another thread),
365 * so use the vlc_object_find way, it's perfectly safe */
367 /* Set die for all access */
368 p_list = vlc_list_find( p_input, VLC_OBJECT_ACCESS, FIND_CHILD );
369 for( i = 0; i < p_list->i_count; i++ )
371 p_list->p_values[i].p_object->b_die = VLC_TRUE;
373 vlc_list_release( p_list );
375 /* Set die for all stream */
376 p_list = vlc_list_find( p_input, VLC_OBJECT_STREAM, FIND_CHILD );
377 for( i = 0; i < p_list->i_count; i++ )
379 p_list->p_values[i].p_object->b_die = VLC_TRUE;
381 vlc_list_release( p_list );
383 /* Set die for all demux */
384 p_list = vlc_list_find( p_input, VLC_OBJECT_DEMUX, FIND_CHILD );
385 for( i = 0; i < p_list->i_count; i++ )
387 p_list->p_values[i].p_object->b_die = VLC_TRUE;
389 vlc_list_release( p_list );
391 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
395 * Clean up a dead input thread
396 * This function does not return until the thread is effectively cancelled.
398 * \param the input thread to kill
400 void input_DestroyThread( input_thread_t *p_input )
402 /* Join the thread */
403 vlc_thread_join( p_input );
405 /* Delete input lock (only after thread joined) */
406 vlc_mutex_destroy( &p_input->lock_control );
408 /* TODO: maybe input_DestroyThread should also delete p_input instead
409 * of the playlist but I'm not sure if it's possible */
412 /*****************************************************************************
413 * Run: main thread loop
414 * This is the "normal" thread that spawns the input processing chain,
415 * reads the stream, cleans up and waits
416 *****************************************************************************/
417 static int Run( input_thread_t *p_input )
419 /* Signal that the thread is launched */
420 vlc_thread_ready( p_input );
422 if( Init( p_input ) )
424 /* If we failed, wait before we are killed, and exit */
425 p_input->b_error = VLC_TRUE;
429 /* Tell we're dead */
430 p_input->b_dead = VLC_TRUE;
437 if( !p_input->b_eof && !p_input->b_error && p_input->input.b_eof )
439 /* We have finish to demux data but not to play them */
440 while( !p_input->b_die )
442 if( input_EsOutDecodersEmpty( p_input->p_es_out ) )
445 msg_Dbg( p_input, "waiting decoder fifos to empty" );
447 msleep( INPUT_IDLE_SLEEP );
450 /* We have finished */
451 p_input->b_eof = VLC_TRUE;
454 /* Wait until we are asked to die */
455 if( !p_input->b_die )
466 /*****************************************************************************
467 * RunAndClean: main thread loop
468 * This is the "just forget me" thread that spawns the input processing chain,
469 * reads the stream, cleans up and releases memory
470 *****************************************************************************/
471 static int RunAndClean( input_thread_t *p_input )
473 /* Signal that the thread is launched */
474 vlc_thread_ready( p_input );
476 if( Init( p_input ) )
478 /* If we failed, just exit */
484 if( !p_input->b_eof && !p_input->b_error && p_input->input.b_eof )
486 /* We have finished demuxing data but not playing it */
487 while( !p_input->b_die )
489 if( input_EsOutDecodersEmpty( p_input->p_es_out ) )
492 msg_Dbg( p_input, "waiting decoder fifos to empty" );
494 msleep( INPUT_IDLE_SLEEP );
497 /* We have finished */
498 p_input->b_eof = VLC_TRUE;
505 vlc_object_detach( p_input );
506 vlc_object_destroy( p_input );
512 /*****************************************************************************
513 * Main loop: Fill buffers from access, and demux
514 *****************************************************************************/
515 static void MainLoop( input_thread_t *p_input )
517 int64_t i_intf_update = 0;
518 while( !p_input->b_die && !p_input->b_error && !p_input->input.b_eof )
520 vlc_bool_t b_force_update = VLC_FALSE;
526 if( p_input->i_state != PAUSE_S )
528 if( p_input->i_stop <= 0 || p_input->i_time < p_input->i_stop )
529 i_ret=p_input->input.p_demux->pf_demux(p_input->input.p_demux);
536 if( p_input->input.b_title_demux &&
537 p_input->input.p_demux->info.i_update )
539 i_ret = UpdateFromDemux( p_input );
540 b_force_update = VLC_TRUE;
542 else if( !p_input->input.b_title_demux &&
543 p_input->input.p_access &&
544 p_input->input.p_access->info.i_update )
546 i_ret = UpdateFromAccess( p_input );
547 b_force_update = VLC_TRUE;
551 if( i_ret == 0 ) /* EOF */
555 var_Get( p_input, "input-repeat", &repeat );
556 if( repeat.i_int == 0 )
558 /* End of file - we do not set b_die because only the
559 * playlist is allowed to do so. */
560 msg_Dbg( p_input, "EOF reached" );
561 p_input->input.b_eof = VLC_TRUE;
565 msg_Dbg( p_input, "repeating the same input (%d)",
567 if( repeat.i_int > 0 )
570 var_Set( p_input, "input-repeat", repeat );
573 /* Seek to start title/seekpoint */
574 val.i_int = p_input->input.i_title_start -
575 p_input->input.i_title_offset;
576 if( val.i_int < 0 || val.i_int >= p_input->input.i_title )
578 input_ControlPush( p_input,
579 INPUT_CONTROL_SET_TITLE, &val );
581 val.i_int = p_input->input.i_seekpoint_start -
582 p_input->input.i_seekpoint_offset;
583 if( val.i_int > 0 /* TODO: check upper boundary */ )
584 input_ControlPush( p_input,
585 INPUT_CONTROL_SET_SEEKPOINT, &val );
587 /* Seek to start position */
588 if( p_input->i_start > 0 )
590 val.i_time = p_input->i_start;
591 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
597 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
604 p_input->b_error = VLC_TRUE;
607 if( i_ret > 0 && p_input->i_slave > 0 )
609 SlaveDemux( p_input );
619 vlc_mutex_lock( &p_input->lock_control );
620 ControlReduce( p_input );
621 while( !ControlPopNoLock( p_input, &i_type, &val ) )
623 msg_Dbg( p_input, "control type=%d", i_type );
624 if( Control( p_input, i_type, val ) )
625 b_force_update = VLC_TRUE;
627 vlc_mutex_unlock( &p_input->lock_control );
629 if( b_force_update || i_intf_update < mdate() )
633 int64_t i_time, i_length;
634 /* update input status variables */
635 if( !demux2_Control( p_input->input.p_demux,
636 DEMUX_GET_POSITION, &f_pos ) )
638 val.f_float = (float)f_pos;
639 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
641 if( !demux2_Control( p_input->input.p_demux,
642 DEMUX_GET_TIME, &i_time ) )
644 p_input->i_time = i_time;
646 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
648 if( !demux2_Control( p_input->input.p_demux,
649 DEMUX_GET_LENGTH, &i_length ) )
652 var_Get( p_input, "length", &old_val );
653 val.i_time = i_length;
654 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
656 if( old_val.i_time != val.i_time )
658 UpdateItemLength( p_input, i_length );
662 var_SetBool( p_input, "intf-change", VLC_TRUE );
663 i_intf_update = mdate() + I64C(150000);
669 static int Init( input_thread_t * p_input )
679 /* Initialize optional stream output. (before access/demuxer)
680 * XXX: we add a special case if the uri starts by vlc.
681 * else 'vlc in.file --sout "" vlc:quit' cannot work (the output will
682 * be destroyed in case of a file).
683 * (this will break playing of file starting by 'vlc:' but I don't
684 * want to add more logic, just force file by file:// or code it ;)
686 memset( &p_input->counters, 0, sizeof( p_input->counters ) );
687 if( !p_input->b_preparsing )
689 /* Prepare statistics */
690 #define INIT_COUNTER( p, type, compute ) p_input->counters.p_##p = \
691 stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
692 if( p_input->p_libvlc->b_stats )
694 INIT_COUNTER( read_bytes, INTEGER, COUNTER );
695 INIT_COUNTER( read_packets, INTEGER, COUNTER );
696 INIT_COUNTER( demux_read, INTEGER, COUNTER );
697 INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE );
698 INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE );
699 INIT_COUNTER( played_abuffers, INTEGER, COUNTER );
700 INIT_COUNTER( lost_abuffers, INTEGER, COUNTER );
701 INIT_COUNTER( displayed_pictures, INTEGER, COUNTER );
702 INIT_COUNTER( lost_pictures, INTEGER, COUNTER );
703 INIT_COUNTER( decoded_audio, INTEGER, COUNTER );
704 INIT_COUNTER( decoded_video, INTEGER, COUNTER );
705 INIT_COUNTER( decoded_sub, INTEGER, COUNTER );
706 p_input->counters.p_sout_send_bitrate = NULL;
707 p_input->counters.p_sout_sent_packets = NULL;
708 p_input->counters.p_sout_sent_bytes = NULL;
709 if( p_input->counters.p_demux_bitrate )
710 p_input->counters.p_demux_bitrate->update_interval = 1000000;
711 if( p_input->counters.p_input_bitrate )
712 p_input->counters.p_input_bitrate->update_interval = 1000000;
714 vlc_mutex_init( p_input, &p_input->counters.counters_lock );
717 psz = var_GetString( p_input, "sout" );
718 if( *psz && strncasecmp( p_input->input.p_item->psz_uri, "vlc:", 4 ) )
720 p_input->p_sout = sout_NewInstance( p_input, psz );
721 if( p_input->p_sout == NULL )
723 msg_Err( p_input, "cannot start stream output instance, " \
728 if( p_input->p_libvlc->b_stats )
730 INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
731 INIT_COUNTER (sout_sent_bytes, INTEGER, COUNTER );
732 INIT_COUNTER( sout_send_bitrate, FLOAT, DERIVATIVE );
733 if( p_input->counters.p_sout_send_bitrate )
734 p_input->counters.p_sout_send_bitrate->update_interval =
742 p_input->p_es_out = input_EsOutNew( p_input );
743 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
744 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
746 var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
747 var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
749 if( InputSourceInit( p_input, &p_input->input,
750 p_input->input.p_item->psz_uri, NULL ) )
755 /* Create global title (from master) */
756 if( !p_input->b_preparsing )
758 p_input->i_title = p_input->input.i_title;
759 p_input->title = p_input->input.title;
760 p_input->i_title_offset = p_input->input.i_title_offset;
761 p_input->i_seekpoint_offset = p_input->input.i_seekpoint_offset;
762 if( p_input->i_title > 0 )
764 /* Setup variables */
765 input_ControlVarNavigation( p_input );
766 input_ControlVarTitle( p_input, 0 );
770 p_input->b_can_pace_control = p_input->input.b_can_pace_control;
771 p_input->b_can_pause = p_input->input.b_can_pause;
774 if( p_input->i_pts_delay < 0 )
775 p_input->i_pts_delay = 0;
777 /* If the desynchronisation requested by the user is < 0, we need to
778 * cache more data. */
779 var_Get( p_input, "audio-desync", &val );
780 if( val.i_int < 0 ) p_input->i_pts_delay -= (val.i_int * 1000);
782 /* Update cr_average depending on the caching */
783 p_input->input.i_cr_average *= (10 * p_input->i_pts_delay / 200000);
784 p_input->input.i_cr_average /= 10;
785 if( p_input->input.i_cr_average < 10 ) p_input->input.i_cr_average = 10;
788 /* Load master infos */
790 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_LENGTH,
791 &val.i_time ) && val.i_time > 0 )
793 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
794 UpdateItemLength( p_input, val.i_time );
795 p_input->input.p_item->i_duration = val.i_time;
798 /* Start title/chapter */
799 if( !p_input->b_preparsing )
801 val.i_int = p_input->input.i_title_start -
802 p_input->input.i_title_offset;
803 if( val.i_int > 0 && val.i_int < p_input->input.i_title )
804 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
805 val.i_int = p_input->input.i_seekpoint_start -
806 p_input->input.i_seekpoint_offset;
807 if( val.i_int > 0 /* TODO: check upper boundary */ )
808 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
812 p_input->i_start = (int64_t)var_GetInteger( p_input, "start-time" ) *
814 p_input->i_stop = (int64_t)var_GetInteger( p_input, "stop-time" ) *
817 if( p_input->i_start > 0 )
819 if( p_input->i_start >= val.i_time )
821 msg_Warn( p_input, "invalid start-time ignored" );
827 msg_Dbg( p_input, "starting at time: %ds",
828 (int)( p_input->i_start / I64C(1000000) ) );
830 s.i_time = p_input->i_start;
831 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
834 if( p_input->i_stop > 0 && p_input->i_stop <= p_input->i_start )
836 msg_Warn( p_input, "invalid stop-time ignored" );
842 /* Get fps and set it if not already set */
843 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) &&
846 float f_requested_fps;
848 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
849 var_SetFloat( p_input, "sub-original-fps", f_fps );
851 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
852 if( f_requested_fps != f_fps )
854 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
856 var_SetFloat( p_input, "sub-fps", f_requested_fps );
860 i_delay = var_CreateGetInteger( p_input, "sub-delay" );
863 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
867 /* Look for and add subtitle files */
868 psz_subtitle = var_GetString( p_input, "sub-file" );
871 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
872 input_AddSubtitles( p_input, psz_subtitle, VLC_FALSE );
875 var_Get( p_input, "sub-autodetect-file", &val );
878 char *psz_autopath = var_GetString( p_input, "sub-autodetect-path" );
879 char **subs = subtitles_Detect( p_input, psz_autopath,
880 p_input->input.p_item->psz_uri );
885 /* Try to autoselect the first autodetected subtitles file
886 * if no subtitles file was specified */
887 if( *psz_subtitle == 0 && subs && subs[0] )
889 input_AddSubtitles( p_input, subs[0], VLC_FALSE );
894 /* Then, just add the following subtitles files */
895 for( ; subs && subs[i]; i++ )
897 if( strcmp( psz_subtitle, subs[i] ) )
899 sub = InputSourceNew( p_input );
900 if( !InputSourceInit( p_input, sub, subs[i], "subtitle" ) )
902 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
907 if( subs ) free( subs );
908 if( psz_autopath ) free( psz_autopath );
910 free( psz_subtitle );
913 psz = var_GetString( p_input, "input-slave" );
917 input_source_t *slave;
920 while( *psz == ' ' || *psz == '#' )
924 if( ( psz_delim = strchr( psz, '#' ) ) )
933 msg_Dbg( p_input, "adding slave input '%s'", psz );
934 slave = InputSourceNew( p_input );
935 if( !InputSourceInit( p_input, slave, psz, NULL ) )
937 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
942 if( psz ) free( psz );
946 p_input->i_start = 0;
947 p_input->i_start = 0;
951 if( !p_input->b_preparsing )
953 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
954 i_es_out_mode = ES_OUT_MODE_AUTO;
956 if( p_input->p_sout )
958 var_Get( p_input, "sout-all", &val );
961 i_es_out_mode = ES_OUT_MODE_ALL;
966 var_Get( p_input, "programs", &val );
967 if ( val.p_list && val.p_list->i_count )
969 i_es_out_mode = ES_OUT_MODE_PARTIAL;
970 /* Note : we should remove the "program" callback. */
973 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
977 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
979 /* Inform the demuxer about waited group (needed only for DVB) */
980 if( i_es_out_mode == ES_OUT_MODE_ALL )
982 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
984 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
986 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1,
991 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP,
992 (int) var_GetInteger( p_input, "program" ), NULL );
995 if( p_input->p_sout )
997 if( p_input->p_sout->i_out_pace_nocontrol > 0 )
999 p_input->b_out_pace_control = VLC_FALSE;
1003 p_input->b_out_pace_control = VLC_TRUE;
1006 if( p_input->b_can_pace_control && p_input->b_out_pace_control )
1008 /* We don't want a high input priority here or we'll
1009 * end-up sucking up all the CPU time */
1010 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
1013 msg_Dbg( p_input, "starting in %s mode",
1014 p_input->b_out_pace_control ? "async" : "sync" );
1018 p_meta = p_input->input.p_item->p_meta;
1019 /* Get meta data from users */
1020 InputMetaUser( p_input );
1021 /* Get meta data from master input */
1022 demux2_Control( p_input->input.p_demux, DEMUX_GET_META, p_meta );
1024 /* Access_file does not give any meta, and there are no slave */
1025 if( !p_input->b_preparsing )
1027 if( p_input->input.p_access )
1028 access2_Control( p_input->input.p_access, ACCESS_GET_META,
1031 /* Get meta data from slave input */
1032 for( i = 0; i < p_input->i_slave; i++ )
1034 demux2_Control( p_input->slave[i]->p_demux,
1035 DEMUX_GET_META, p_meta );
1036 if( p_input->slave[i]->p_access )
1038 access2_Control( p_input->slave[i]->p_access,
1039 ACCESS_GET_META, p_meta );
1044 UpdateMeta( p_input );
1046 if( !p_input->b_preparsing )
1048 msg_Dbg( p_input, "`%s' successfully opened",
1049 p_input->input.p_item->psz_uri );
1053 /* initialization is complete */
1054 input_ChangeState(p_input, PLAYING_S);
1059 if( p_input->p_es_out )
1060 input_EsOutDelete( p_input->p_es_out );
1062 if( p_input->p_sout )
1063 sout_DeleteInstance( p_input->p_sout );
1065 /* Mark them deleted */
1066 p_input->input.p_demux = NULL;
1067 p_input->input.p_stream = NULL;
1068 p_input->input.p_access = NULL;
1069 p_input->p_es_out = NULL;
1070 p_input->p_sout = NULL;
1072 return VLC_EGENERIC;
1075 /*****************************************************************************
1076 * Error: RunThread() error loop
1077 *****************************************************************************
1078 * This function is called when an error occurred during thread main's loop.
1079 *****************************************************************************/
1080 static void Error( input_thread_t *p_input )
1082 while( !p_input->b_die )
1085 msleep( INPUT_IDLE_SLEEP );
1089 /*****************************************************************************
1090 * End: end the input thread
1091 *****************************************************************************/
1092 static void End( input_thread_t * p_input )
1096 msg_Dbg( p_input, "closing input" );
1098 /* We are at the end */
1099 input_ChangeState(p_input, END_S);
1101 /* Clean control variables */
1102 input_ControlVarClean( p_input );
1104 /* Clean up master */
1105 InputSourceClean( p_input, &p_input->input );
1108 for( i = 0; i < p_input->i_slave; i++ )
1110 InputSourceClean( p_input, p_input->slave[i] );
1111 free( p_input->slave[i] );
1113 if( p_input->slave ) free( p_input->slave );
1115 /* Unload all modules */
1116 if( p_input->p_es_out )
1117 input_EsOutDelete( p_input->p_es_out );
1119 #define CL_CO( c ) stats_CounterClean( p_input->counters.p_##c ); p_input->counters.p_##c = NULL;
1120 if( p_input->p_libvlc->b_stats )
1122 vlc_mutex_lock( &p_input->counters.counters_lock );
1123 CL_CO( read_bytes );
1124 CL_CO( read_packets );
1125 CL_CO( demux_read );
1126 CL_CO( input_bitrate );
1127 CL_CO( demux_bitrate );
1128 CL_CO( played_abuffers );
1129 CL_CO( lost_abuffers );
1130 CL_CO( displayed_pictures );
1131 CL_CO( lost_pictures );
1132 CL_CO( decoded_audio) ;
1133 CL_CO( decoded_video );
1134 CL_CO( decoded_sub) ;
1135 vlc_mutex_unlock( &p_input->counters.counters_lock );
1138 /* Close optional stream output instance */
1139 if( p_input->p_sout )
1143 vlc_mutex_lock( &p_input->counters.counters_lock );
1144 CL_CO( sout_sent_packets );
1145 CL_CO( sout_sent_bytes );
1146 CL_CO( sout_send_bitrate );
1147 vlc_mutex_unlock( &p_input->counters.counters_lock );
1149 if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool )
1151 /* attach sout to the playlist */
1152 msg_Dbg( p_input, "keeping sout" );
1153 vlc_object_detach( p_input->p_sout );
1154 vlc_object_attach( p_input->p_sout, p_input->p_libvlc->p_playlist );
1158 msg_Dbg( p_input, "destroying sout" );
1159 sout_DeleteInstance( p_input->p_sout );
1164 /* Tell we're dead */
1165 p_input->b_dead = VLC_TRUE;
1168 /*****************************************************************************
1170 *****************************************************************************/
1171 static inline int ControlPopNoLock( input_thread_t *p_input,
1172 int *pi_type, vlc_value_t *p_val )
1174 if( p_input->i_control <= 0 )
1176 return VLC_EGENERIC;
1179 *pi_type = p_input->control[0].i_type;
1180 *p_val = p_input->control[0].val;
1182 p_input->i_control--;
1183 if( p_input->i_control > 0 )
1187 for( i = 0; i < p_input->i_control; i++ )
1189 p_input->control[i].i_type = p_input->control[i+1].i_type;
1190 p_input->control[i].val = p_input->control[i+1].val;
1197 static void ControlReduce( input_thread_t *p_input )
1200 for( i = 1; i < p_input->i_control; i++ )
1202 const int i_lt = p_input->control[i-1].i_type;
1203 const int i_ct = p_input->control[i].i_type;
1205 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1206 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->i_control,
1210 ( i_ct == INPUT_CONTROL_SET_STATE ||
1211 i_ct == INPUT_CONTROL_SET_RATE ||
1212 i_ct == INPUT_CONTROL_SET_POSITION ||
1213 i_ct == INPUT_CONTROL_SET_TIME ||
1214 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1215 i_ct == INPUT_CONTROL_SET_TITLE ||
1216 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1217 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1220 // msg_Dbg( p_input, "merged at %d", i );
1221 /* Remove the i-1 */
1222 for( j = i; j < p_input->i_control; j++ )
1223 p_input->control[j-1] = p_input->control[j];
1224 p_input->i_control--;
1228 /* TODO but that's not that important
1229 - merge SET_X with SET_X_CMD
1230 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1231 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1238 static vlc_bool_t Control( input_thread_t *p_input, int i_type,
1241 vlc_bool_t b_force_update = VLC_FALSE;
1243 if( !p_input ) return b_force_update;
1247 case INPUT_CONTROL_SET_DIE:
1248 msg_Dbg( p_input, "control: stopping input" );
1249 /* Mark all submodules to die */
1250 if( p_input->input.p_access )
1251 p_input->input.p_access->b_die = VLC_TRUE;
1252 if( p_input->input.p_stream )
1253 p_input->input.p_stream->b_die = VLC_TRUE;
1254 p_input->input.p_demux->b_die = VLC_TRUE;
1256 p_input->b_die = VLC_TRUE;
1259 case INPUT_CONTROL_SET_POSITION:
1260 case INPUT_CONTROL_SET_POSITION_OFFSET:
1263 if( i_type == INPUT_CONTROL_SET_POSITION )
1265 f_pos = val.f_float;
1269 /* Should not fail */
1270 demux2_Control( p_input->input.p_demux,
1271 DEMUX_GET_POSITION, &f_pos );
1272 f_pos += val.f_float;
1274 if( f_pos < 0.0 ) f_pos = 0.0;
1275 if( f_pos > 1.0 ) f_pos = 1.0;
1276 /* Reset the decoders states and clock sync (before calling the demuxer */
1277 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1278 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1279 if( demux2_Control( p_input->input.p_demux, DEMUX_SET_POSITION,
1282 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1283 "%2.1f%% failed", f_pos * 100 );
1287 if( p_input->i_slave > 0 )
1288 SlaveSeek( p_input );
1290 b_force_update = VLC_TRUE;
1295 case INPUT_CONTROL_SET_TIME:
1296 case INPUT_CONTROL_SET_TIME_OFFSET:
1301 if( i_type == INPUT_CONTROL_SET_TIME )
1303 i_time = val.i_time;
1307 /* Should not fail */
1308 demux2_Control( p_input->input.p_demux,
1309 DEMUX_GET_TIME, &i_time );
1310 i_time += val.i_time;
1312 if( i_time < 0 ) i_time = 0;
1314 /* Reset the decoders states and clock sync (before calling the demuxer */
1315 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1316 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1318 i_ret = demux2_Control( p_input->input.p_demux,
1319 DEMUX_SET_TIME, i_time );
1324 /* Emulate it with a SET_POS */
1325 demux2_Control( p_input->input.p_demux,
1326 DEMUX_GET_LENGTH, &i_length );
1329 double f_pos = (double)i_time / (double)i_length;
1330 i_ret = demux2_Control( p_input->input.p_demux,
1331 DEMUX_SET_POSITION, f_pos );
1336 msg_Warn( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) "I64Fd
1337 " failed or not possible", i_time );
1341 if( p_input->i_slave > 0 )
1342 SlaveSeek( p_input );
1344 b_force_update = VLC_TRUE;
1349 case INPUT_CONTROL_SET_STATE:
1350 if( ( val.i_int == PLAYING_S && p_input->i_state == PAUSE_S ) ||
1351 ( val.i_int == PAUSE_S && p_input->i_state == PAUSE_S ) )
1354 if( p_input->input.p_access )
1355 i_ret = access2_Control( p_input->input.p_access,
1356 ACCESS_SET_PAUSE_STATE, VLC_FALSE );
1358 i_ret = demux2_Control( p_input->input.p_demux,
1359 DEMUX_SET_PAUSE_STATE, VLC_FALSE );
1363 /* FIXME What to do ? */
1364 msg_Warn( p_input, "cannot unset pause -> EOF" );
1365 vlc_mutex_unlock( &p_input->lock_control );
1366 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1367 vlc_mutex_lock( &p_input->lock_control );
1370 b_force_update = VLC_TRUE;
1372 /* Switch to play */
1373 p_input->i_state = PLAYING_S;
1374 val.i_int = PLAYING_S;
1375 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1378 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1379 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1381 else if( val.i_int == PAUSE_S && p_input->i_state == PLAYING_S &&
1382 p_input->b_can_pause )
1385 if( p_input->input.p_access )
1386 i_ret = access2_Control( p_input->input.p_access,
1387 ACCESS_SET_PAUSE_STATE, VLC_TRUE );
1389 i_ret = demux2_Control( p_input->input.p_demux,
1390 DEMUX_SET_PAUSE_STATE, VLC_TRUE );
1392 b_force_update = VLC_TRUE;
1396 msg_Warn( p_input, "cannot set pause state" );
1397 val.i_int = p_input->i_state;
1401 val.i_int = PAUSE_S;
1404 /* Switch to new state */
1405 p_input->i_state = val.i_int;
1406 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1408 else if( val.i_int == PAUSE_S && !p_input->b_can_pause )
1410 b_force_update = VLC_TRUE;
1412 /* Correct "state" value */
1413 val.i_int = p_input->i_state;
1414 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1416 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1418 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1422 case INPUT_CONTROL_SET_RATE:
1423 case INPUT_CONTROL_SET_RATE_SLOWER:
1424 case INPUT_CONTROL_SET_RATE_FASTER:
1428 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1429 i_rate = p_input->i_rate * 2;
1430 else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
1431 i_rate = p_input->i_rate / 2;
1435 if( i_rate < INPUT_RATE_MIN )
1437 msg_Dbg( p_input, "cannot set rate faster" );
1438 i_rate = INPUT_RATE_MIN;
1440 else if( i_rate > INPUT_RATE_MAX )
1442 msg_Dbg( p_input, "cannot set rate slower" );
1443 i_rate = INPUT_RATE_MAX;
1445 if( i_rate != INPUT_RATE_DEFAULT &&
1446 ( !p_input->b_can_pace_control ||
1447 ( p_input->p_sout && !p_input->b_out_pace_control ) ) )
1449 msg_Dbg( p_input, "cannot change rate" );
1450 i_rate = INPUT_RATE_DEFAULT;
1452 if( i_rate != p_input->i_rate )
1454 p_input->i_rate = i_rate;
1456 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
1458 /* We haven't send data to decoder when rate != default */
1459 if( i_rate == INPUT_RATE_DEFAULT )
1460 input_EsOutDiscontinuity( p_input->p_es_out, VLC_TRUE );
1463 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1465 b_force_update = VLC_TRUE;
1470 case INPUT_CONTROL_SET_PROGRAM:
1471 /* No need to force update, es_out does it if needed */
1472 es_out_Control( p_input->p_es_out,
1473 ES_OUT_SET_GROUP, val.i_int );
1475 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1479 case INPUT_CONTROL_SET_ES:
1480 /* No need to force update, es_out does it if needed */
1481 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
1482 input_EsOutGetFromID( p_input->p_es_out,
1486 case INPUT_CONTROL_SET_AUDIO_DELAY:
1487 input_EsOutSetDelay( p_input->p_es_out,
1488 AUDIO_ES, val.i_time );
1489 var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
1492 case INPUT_CONTROL_SET_SPU_DELAY:
1493 input_EsOutSetDelay( p_input->p_es_out,
1494 SPU_ES, val.i_time );
1495 var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
1498 case INPUT_CONTROL_SET_TITLE:
1499 case INPUT_CONTROL_SET_TITLE_NEXT:
1500 case INPUT_CONTROL_SET_TITLE_PREV:
1501 if( p_input->input.b_title_demux &&
1502 p_input->input.i_title > 0 )
1505 /* FIXME handle demux title */
1506 demux_t *p_demux = p_input->input.p_demux;
1509 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1510 i_title = p_demux->info.i_title - 1;
1511 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1512 i_title = p_demux->info.i_title + 1;
1514 i_title = val.i_int;
1516 if( i_title >= 0 && i_title < p_input->input.i_title )
1518 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1519 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1521 demux2_Control( p_demux, DEMUX_SET_TITLE, i_title );
1522 input_ControlVarTitle( p_input, i_title );
1525 else if( p_input->input.i_title > 0 )
1527 access_t *p_access = p_input->input.p_access;
1530 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1531 i_title = p_access->info.i_title - 1;
1532 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1533 i_title = p_access->info.i_title + 1;
1535 i_title = val.i_int;
1537 if( i_title >= 0 && i_title < p_input->input.i_title )
1539 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1540 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1542 access2_Control( p_access, ACCESS_SET_TITLE, i_title );
1543 stream_AccessReset( p_input->input.p_stream );
1547 case INPUT_CONTROL_SET_SEEKPOINT:
1548 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1549 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1550 if( p_input->input.b_title_demux &&
1551 p_input->input.i_title > 0 )
1553 demux_t *p_demux = p_input->input.p_demux;
1555 int64_t i_input_time;
1556 int64_t i_seekpoint_time;
1558 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1560 i_seekpoint = p_demux->info.i_seekpoint;
1561 i_seekpoint_time = p_input->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1562 if( i_seekpoint_time >= 0 &&
1563 !demux2_Control( p_demux,
1564 DEMUX_GET_TIME, &i_input_time ) )
1566 if ( i_input_time < i_seekpoint_time + 3000000 )
1572 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1573 i_seekpoint = p_demux->info.i_seekpoint + 1;
1575 i_seekpoint = val.i_int;
1577 if( i_seekpoint >= 0 && i_seekpoint <
1578 p_input->input.title[p_demux->info.i_title]->i_seekpoint )
1580 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1581 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1583 demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1586 else if( p_input->input.i_title > 0 )
1588 demux_t *p_demux = p_input->input.p_demux;
1589 access_t *p_access = p_input->input.p_access;
1591 int64_t i_input_time;
1592 int64_t i_seekpoint_time;
1594 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1596 i_seekpoint = p_access->info.i_seekpoint;
1597 i_seekpoint_time = p_input->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1598 if( i_seekpoint_time >= 0 &&
1599 demux2_Control( p_demux,
1600 DEMUX_GET_TIME, &i_input_time ) )
1602 if ( i_input_time < i_seekpoint_time + 3000000 )
1608 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1609 i_seekpoint = p_access->info.i_seekpoint + 1;
1611 i_seekpoint = val.i_int;
1613 if( i_seekpoint >= 0 && i_seekpoint <
1614 p_input->input.title[p_access->info.i_title]->i_seekpoint )
1616 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1617 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1619 access2_Control( p_access, ACCESS_SET_SEEKPOINT,
1621 stream_AccessReset( p_input->input.p_stream );
1626 case INPUT_CONTROL_ADD_SLAVE:
1627 if( val.psz_string )
1629 input_source_t *slave = InputSourceNew( p_input );
1631 if( !InputSourceInit( p_input, slave, val.psz_string, NULL ) )
1633 vlc_meta_t *p_meta = p_input->input.p_item->p_meta;
1637 msg_Dbg( p_input, "adding %s as slave on the fly",
1641 if( demux2_Control( p_input->input.p_demux,
1642 DEMUX_GET_TIME, &i_time ) )
1644 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
1645 InputSourceClean( p_input, slave );
1649 if( demux2_Control( slave->p_demux,
1650 DEMUX_SET_TIME, i_time ) )
1652 msg_Err( p_input, "seek failed for new slave" );
1653 InputSourceClean( p_input, slave );
1658 /* Get meta (access and demux) */
1659 access2_Control( slave->p_access, ACCESS_GET_META,
1661 demux2_Control( slave->p_demux, DEMUX_GET_META, p_meta );
1662 UpdateMeta( p_input );
1664 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
1668 msg_Warn( p_input, "failed to add %s as slave",
1672 free( val.psz_string );
1676 case INPUT_CONTROL_SET_BOOKMARK:
1678 msg_Err( p_input, "not yet implemented" );
1682 return b_force_update;
1685 /*****************************************************************************
1687 *****************************************************************************/
1688 static int UpdateFromDemux( input_thread_t *p_input )
1690 demux_t *p_demux = p_input->input.p_demux;
1693 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
1695 v.i_int = p_demux->info.i_title;
1696 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1698 input_ControlVarTitle( p_input, p_demux->info.i_title );
1700 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
1702 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
1704 v.i_int = p_demux->info.i_seekpoint;
1705 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1707 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1709 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
1711 /* Hmmm only works with master input */
1712 if( p_input->input.p_demux == p_demux )
1714 int i_title_end = p_input->input.i_title_end -
1715 p_input->input.i_title_offset;
1716 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1717 p_input->input.i_seekpoint_offset;
1719 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
1721 if( p_demux->info.i_title > i_title_end ||
1722 ( p_demux->info.i_title == i_title_end &&
1723 p_demux->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1725 else if( i_seekpoint_end >=0 )
1727 if( p_demux->info.i_seekpoint > i_seekpoint_end ) return 0;
1729 else if( i_title_end >= 0 )
1731 if( p_demux->info.i_title > i_title_end ) return 0;
1738 /*****************************************************************************
1740 *****************************************************************************/
1741 static int UpdateFromAccess( input_thread_t *p_input )
1743 access_t *p_access = p_input->input.p_access;
1746 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
1748 v.i_int = p_access->info.i_title;
1749 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1751 input_ControlVarTitle( p_input, p_access->info.i_title );
1753 stream_AccessUpdate( p_input->input.p_stream );
1755 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
1757 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
1759 v.i_int = p_access->info.i_seekpoint;
1760 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1761 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1763 if( p_access->info.i_update & INPUT_UPDATE_META )
1765 /* TODO maybe multi - access ? */
1766 vlc_meta_t *p_meta = p_input->input.p_item->p_meta;
1767 access2_Control( p_input->input.p_access,ACCESS_GET_META, p_meta );
1768 UpdateMeta( p_input );
1769 var_SetBool( p_input, "item-change", p_input->input.p_item->i_id );
1770 p_access->info.i_update &= ~INPUT_UPDATE_META;
1773 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
1775 /* Hmmm only works with master input */
1776 if( p_input->input.p_access == p_access )
1778 int i_title_end = p_input->input.i_title_end -
1779 p_input->input.i_title_offset;
1780 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1781 p_input->input.i_seekpoint_offset;
1783 if( i_title_end >= 0 && i_seekpoint_end >=0 )
1785 if( p_access->info.i_title > i_title_end ||
1786 ( p_access->info.i_title == i_title_end &&
1787 p_access->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1789 else if( i_seekpoint_end >=0 )
1791 if( p_access->info.i_seekpoint > i_seekpoint_end ) return 0;
1793 else if( i_title_end >= 0 )
1795 if( p_access->info.i_title > i_title_end ) return 0;
1802 /*****************************************************************************
1804 *****************************************************************************/
1805 static int UpdateMeta( input_thread_t *p_input )
1807 vlc_meta_t *p_meta = p_input->input.p_item->p_meta;
1811 if( p_meta->psz_title && !p_input->input.p_item->b_fixed_name )
1812 input_Control( p_input, INPUT_SET_NAME, p_meta->psz_title );
1814 /** \todo handle sout meta */
1819 /*****************************************************************************
1821 *****************************************************************************/
1822 static void UpdateItemLength( input_thread_t *p_input, int64_t i_length )
1824 vlc_mutex_lock( &p_input->input.p_item->lock );
1825 p_input->input.p_item->i_duration = i_length;
1826 vlc_mutex_unlock( &p_input->input.p_item->lock );
1828 if( !p_input->b_preparsing )
1830 pl_Yield( p_input );
1831 var_SetInteger( pl_Get( p_input ), "item-change",
1832 p_input->input.p_item->i_id );
1833 pl_Release( p_input )
1837 /*****************************************************************************
1839 *****************************************************************************/
1840 static input_source_t *InputSourceNew( input_thread_t *p_input )
1842 input_source_t *in = (input_source_t*) malloc( sizeof( input_source_t ) );
1846 msg_Err( p_input, "out of memory for new input source" );
1851 in->p_access = NULL;
1852 in->p_stream = NULL;
1854 in->b_title_demux = VLC_FALSE;
1857 in->b_can_pace_control = VLC_TRUE;
1858 in->b_eof = VLC_FALSE;
1859 in->i_cr_average = 0;
1864 /*****************************************************************************
1866 *****************************************************************************/
1867 static int InputSourceInit( input_thread_t *p_input,
1868 input_source_t *in, char *psz_mrl,
1869 char *psz_forced_demux )
1871 char *psz_dup = strdup( psz_mrl );
1879 if( !in ) return VLC_EGENERIC;
1882 if( !p_input->b_preparsing )
1884 MRLSplit( VLC_OBJECT(p_input), psz_dup,
1885 &psz_access, &psz_demux, &psz_path );
1887 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
1888 psz_mrl, psz_access, psz_demux, psz_path );
1890 /* Hack to allow udp://@:port syntax */
1892 (strncmp( psz_access, "udp", 3 ) &&
1893 strncmp( psz_access, "rtp", 3 )) )
1895 /* Find optional titles and seekpoints */
1896 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
1897 &in->i_seekpoint_start, &in->i_seekpoint_end );
1899 if( psz_forced_demux && *psz_forced_demux )
1901 psz_demux = psz_forced_demux;
1903 else if( !psz_demux || *psz_demux == '\0' )
1905 /* special hack for forcing a demuxer with --demux=module
1906 * (and do nothing with a list) */
1907 char *psz_var_demux = var_GetString( p_input, "demux" );
1909 if( *psz_var_demux != '\0' &&
1910 !strchr(psz_var_demux, ',' ) &&
1911 !strchr(psz_var_demux, ':' ) )
1913 psz_demux = psz_var_demux;
1915 msg_Dbg( p_input, "enforced demux ` %s'", psz_demux );
1917 else if( psz_var_demux )
1919 free( psz_var_demux );
1923 /* Try access_demux if no demux given */
1924 if( *psz_demux == '\0' )
1926 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
1927 NULL, p_input->p_es_out, VLC_FALSE );
1933 msg_Dbg( p_input, "trying to pre-parse %s", psz_path );
1934 psz_demux = strdup( "" );
1935 psz_access = strdup( "file" );
1940 int64_t i_pts_delay;
1942 /* Get infos from access_demux */
1943 demux2_Control( in->p_demux,
1944 DEMUX_GET_PTS_DELAY, &i_pts_delay );
1945 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
1947 in->b_title_demux = VLC_TRUE;
1948 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
1949 &in->title, &in->i_title,
1950 &in->i_title_offset, &in->i_seekpoint_offset ) )
1955 demux2_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
1956 &in->b_can_pace_control );
1957 demux2_Control( in->p_demux, DEMUX_CAN_PAUSE,
1961 demux2_Control( in->p_demux, DEMUX_CAN_SEEK,
1967 int64_t i_pts_delay;
1969 input_ChangeState( p_input, OPENING_S);
1971 /* Now try a real access */
1972 in->p_access = access2_New( p_input, psz_access, psz_demux, psz_path,
1973 p_input->b_preparsing );
1975 /* Access failed, URL encoded ? */
1976 if( in->p_access == NULL && strchr( psz_path, '%' ) )
1978 DecodeUrl( psz_path );
1980 msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
1981 psz_access, psz_demux, psz_path );
1983 in->p_access = access2_New( p_input,
1984 psz_access, psz_demux, psz_path,
1985 p_input->b_preparsing );
1987 #ifndef WIN32 /* Remove this gross hack from the win32 build as colons
1988 * are forbidden in filenames on Win32. */
1990 /* Maybe we got something like: /Volumes/toto:titi/gabu.mpg */
1991 if( in->p_access == NULL &&
1992 *psz_access == '\0' && ( *psz_demux || *psz_path ) )
1994 if( psz_dup ) free( psz_dup );
1995 psz_dup = strdup( psz_mrl );
1997 if( psz_forced_demux && *psz_forced_demux )
1999 psz_demux = psz_forced_demux;
2001 else psz_demux = "";
2004 in->p_access = access2_New( p_input,
2005 psz_access, psz_demux, psz_path,
2006 p_input->b_preparsing );
2010 if( in->p_access == NULL )
2012 msg_Err( p_input, "no suitable access module for `%s'", psz_mrl );
2013 intf_UserFatal( VLC_OBJECT( p_input), VLC_FALSE,
2014 _("Your input can't be opened"),
2015 _("VLC is unable to open the MRL '%s'."
2016 " Check the log for details."), psz_mrl );
2021 psz_tmp = psz = var_GetString( p_input, "access-filter" );
2022 while( psz && *psz )
2024 access_t *p_access = in->p_access;
2025 char *end = strchr( psz, ':' );
2030 in->p_access = access2_FilterNew( in->p_access, psz );
2031 if( in->p_access == NULL )
2033 in->p_access = p_access;
2034 msg_Warn( p_input, "failed to insert access filter %s",
2040 if( psz_tmp ) free( psz_tmp );
2042 /* Get infos from access */
2043 if( !p_input->b_preparsing )
2045 access2_Control( in->p_access,
2046 ACCESS_GET_PTS_DELAY, &i_pts_delay );
2047 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2049 in->b_title_demux = VLC_FALSE;
2050 if( access2_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2051 &in->title, &in->i_title,
2052 &in->i_title_offset, &in->i_seekpoint_offset ) )
2058 access2_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2059 &in->b_can_pace_control );
2060 access2_Control( in->p_access, ACCESS_CAN_PAUSE,
2062 access2_Control( in->p_access, ACCESS_CAN_SEEK,
2064 var_Set( p_input, "seekable", val );
2067 input_ChangeState( p_input, BUFFERING_S);
2069 /* Create the stream_t */
2070 in->p_stream = stream_AccessNew( in->p_access, p_input->b_preparsing );
2071 if( in->p_stream == NULL )
2073 msg_Warn( p_input, "cannot create a stream_t from access" );
2077 /* Open a demuxer */
2078 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2080 psz_demux = in->p_access->psz_demux;
2082 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
2083 in->p_stream, p_input->p_es_out,
2084 p_input->b_preparsing );
2085 if( in->p_demux == NULL )
2087 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2088 psz_access, psz_demux, psz_path );
2089 intf_UserFatal( VLC_OBJECT( p_input), VLC_FALSE,
2090 _("Can't recognize the input's format"),
2091 _("The format of '%s' can't be detected. "
2092 "Have a look the log for details."), psz_mrl );
2096 /* TODO get title from demux */
2097 if( !p_input->b_preparsing && in->i_title <= 0 )
2099 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2100 &in->title, &in->i_title,
2101 &in->i_title_offset, &in->i_seekpoint_offset ))
2108 in->b_title_demux = VLC_TRUE;
2113 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2114 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2116 if( psz_dup ) free( psz_dup );
2121 demux2_Delete( in->p_demux );
2124 stream_Delete( in->p_stream );
2127 access2_Delete( in->p_access );
2128 if( psz_dup ) free( psz_dup );
2130 return VLC_EGENERIC;
2133 /*****************************************************************************
2135 *****************************************************************************/
2136 static void InputSourceClean( input_thread_t *p_input, input_source_t *in )
2139 demux2_Delete( in->p_demux );
2142 stream_Delete( in->p_stream );
2145 access2_Delete( in->p_access );
2147 if( in->i_title > 0 )
2150 for( i = 0; i < in->i_title; i++ )
2152 vlc_input_title_Delete( in->title[i] );
2158 static void SlaveDemux( input_thread_t *p_input )
2163 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2165 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2169 for( i = 0; i < p_input->i_slave; i++ )
2171 input_source_t *in = p_input->slave[i];
2177 if( demux2_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2182 if( demux2_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2184 msg_Err( p_input, "slave[%d] doesn't like "
2185 "DEMUX_GET_TIME -> EOF", i );
2190 if( i_stime >= i_time )
2193 if( ( i_ret = in->p_demux->pf_demux( in->p_demux ) ) <= 0 )
2199 i_ret = in->p_demux->pf_demux( in->p_demux );
2204 msg_Dbg( p_input, "slave %d EOF", i );
2205 in->b_eof = VLC_TRUE;
2210 static void SlaveSeek( input_thread_t *p_input )
2215 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2217 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2221 for( i = 0; i < p_input->i_slave; i++ )
2223 input_source_t *in = p_input->slave[i];
2225 if( demux2_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
2227 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2228 in->b_eof = VLC_TRUE;
2232 /*****************************************************************************
2234 *****************************************************************************/
2235 static void InputMetaUser( input_thread_t *p_input )
2237 vlc_meta_t *p_meta = p_input->input.p_item->p_meta;
2240 if( !p_meta ) return;
2242 /* Get meta information from user */
2243 #define GET_META( field, s ) \
2244 var_Get( p_input, (s), &val ); \
2245 if( *val.psz_string ) { \
2246 if( p_meta->psz_ ## field ) free ( p_meta->psz_ ## field ); \
2247 p_meta->psz_ ## field = strdup( val.psz_string ); \
2249 free( val.psz_string )
2251 GET_META( title, "meta-title" );
2252 GET_META( author, "meta-author" );
2253 GET_META( artist, "meta-artist" );
2254 GET_META( genre, "meta-genre" );
2255 GET_META( copyright, "meta-copyright" );
2256 GET_META( description, "meta-description" );
2257 GET_META( date, "meta-date" );
2258 GET_META( url, "meta-url" );
2262 /*****************************************************************************
2263 * DecodeUrl: decode a given encoded url
2264 *****************************************************************************/
2265 static void DecodeUrl( char *psz )
2267 char *dup = strdup( psz );
2285 *psz++ = strtol( val, NULL, 16 );
2287 else if( *p == '+' )
2297 if( psz ) *psz++ ='\0';
2298 if( dup ) free( dup );
2301 /*****************************************************************************
2302 * MRLSplit: parse the access, demux and url part of the
2303 * Media Resource Locator.
2304 *****************************************************************************/
2305 void MRLSplit( vlc_object_t *p_input, char *psz_dup,
2306 char **ppsz_access, char **ppsz_demux, char **ppsz_path )
2308 char *psz_access = NULL;
2309 char *psz_demux = NULL;
2310 char *psz_path = NULL;
2311 char *psz, *psz_check;
2313 psz = strchr( psz_dup, ':' );
2315 /* '@' not allowed in access/demux part */
2316 psz_check = strchr( psz_dup, '@' );
2317 if( psz_check && psz_check < psz ) psz = 0;
2319 #if defined( WIN32 ) || defined( UNDER_CE )
2320 if( psz - psz_dup == 1 )
2322 msg_Dbg( p_input, "drive letter %c: found in source", *psz_dup );
2331 if( psz[0] == '/' && psz[1] == '/' ) psz += 2;
2335 psz = strchr( psz_dup, '/' );
2342 psz_access = psz_dup;
2349 if( !psz_access ) *ppsz_access = "";
2350 else *ppsz_access = psz_access;
2352 if( !psz_demux ) *ppsz_demux = "";
2353 else *ppsz_demux = psz_demux;
2355 if( !psz_path ) *ppsz_path = "";
2356 else *ppsz_path = psz_path;
2359 /*****************************************************************************
2360 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
2363 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
2364 *****************************************************************************/
2365 static void MRLSections( input_thread_t *p_input, char *psz_source,
2366 int *pi_title_start, int *pi_title_end,
2367 int *pi_chapter_start, int *pi_chapter_end )
2369 char *psz, *psz_end, *psz_next, *psz_check;
2371 *pi_title_start = *pi_title_end = -1;
2372 *pi_chapter_start = *pi_chapter_end = -1;
2374 /* Start by parsing titles and chapters */
2375 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
2377 /* Check we are really dealing with a title/chapter section */
2378 psz_check = psz + 1;
2379 if( !*psz_check ) return;
2380 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2381 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
2382 if( *psz_check == ':' && ++psz_check )
2383 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2384 if( *psz_check != '-' && *psz_check ) return;
2385 if( *psz_check == '-' && ++psz_check )
2386 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2387 if( *psz_check != ':' && *psz_check ) return;
2388 if( *psz_check == ':' && ++psz_check )
2389 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2390 if( *psz_check ) return;
2392 /* Separate start and end */
2394 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
2396 /* Look for the start title */
2397 *pi_title_start = strtol( psz, &psz_next, 0 );
2398 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
2399 *pi_title_end = *pi_title_start;
2402 /* Look for the start chapter */
2404 *pi_chapter_start = strtol( psz, &psz_next, 0 );
2405 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
2406 *pi_chapter_end = *pi_chapter_start;
2410 /* Look for the end title */
2411 *pi_title_end = strtol( psz_end, &psz_next, 0 );
2412 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
2415 /* Look for the end chapter */
2416 if( *psz_end ) psz_end++;
2417 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
2418 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
2421 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
2422 psz_source, *pi_title_start, *pi_chapter_start,
2423 *pi_title_end, *pi_chapter_end );
2426 /*****************************************************************************
2427 * input_AddSubtitles: add a subtitles file and enable it
2428 *****************************************************************************/
2429 vlc_bool_t input_AddSubtitles( input_thread_t *p_input, char *psz_subtitle,
2430 vlc_bool_t b_check_extension )
2432 input_source_t *sub;
2435 char *psz_path, *psz_extension;
2437 if( b_check_extension && !subtitles_Filter( psz_subtitle ) )
2442 /* if we are provided a subtitle.sub file,
2443 * see if we don't have a subtitle.idx and use it instead */
2444 psz_path = strdup( psz_subtitle );
2447 psz_extension = strrchr( psz_path, '.');
2448 if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
2452 strcpy( psz_extension, ".idx" );
2453 /* FIXME: a portable wrapper for stat() or access() would be more suited */
2454 if( ( f = utf8_fopen( psz_path, "rt" ) ) )
2457 msg_Dbg( p_input, "using %s subtitles file instead of %s",
2458 psz_path, psz_subtitle );
2459 strcpy( psz_subtitle, psz_path );
2465 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
2467 sub = InputSourceNew( p_input );
2468 if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
2470 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
2473 if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
2475 if( count.i_int == 0 )
2477 /* if it was first one, there is disable too */
2479 if( count.i_int < list.p_list->i_count )
2481 input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
2482 &list.p_list->p_values[count.i_int] );
2484 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );