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 /*****************************************************************************
47 *****************************************************************************/
48 static int Run ( input_thread_t *p_input );
49 static int RunAndClean ( input_thread_t *p_input );
51 static input_thread_t * Create ( vlc_object_t *, input_item_t *, char *,
53 static int Init ( input_thread_t *p_input, vlc_bool_t b_quick );
54 static void Error ( input_thread_t *p_input );
55 static void End ( input_thread_t *p_input );
56 static void MainLoop( input_thread_t *p_input );
58 static inline int ControlPopNoLock( input_thread_t *, int *, vlc_value_t * );
59 static void ControlReduce( input_thread_t * );
60 static vlc_bool_t Control( input_thread_t *, int, vlc_value_t );
62 static int UpdateFromAccess( input_thread_t * );
63 static int UpdateFromDemux( input_thread_t * );
64 static int UpdateMeta( input_thread_t *, vlc_bool_t );
66 static void UpdateItemLength( input_thread_t *, int64_t i_length, vlc_bool_t );
68 static void DecodeUrl( char * );
69 static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
71 static input_source_t *InputSourceNew( input_thread_t *);
72 static int InputSourceInit( input_thread_t *, input_source_t *,
73 char *, char *psz_forced_demux,
75 static void InputSourceClean( input_thread_t *, input_source_t * );
77 static void SlaveDemux( input_thread_t *p_input );
78 static void SlaveSeek( input_thread_t *p_input );
80 static void InputMetaUser( input_thread_t *p_input );
82 /*****************************************************************************
83 * This function creates a new input, and returns a pointer
84 * to its description. On error, it returns NULL.
86 * Variables for _public_ use:
89 * - rate,rate-slower, rate-faster
90 * - position, position-offset
92 * - title,title-next,title-prev
93 * - chapter,chapter-next, chapter-prev
94 * - program, audio-es, video-es, spu-es
95 * - audio-delay, spu-delay
100 * - seekable (if you can seek, it doesn't say if 'bar display' has be shown or not, for that check position != 0.0)
101 * * For intf callback upon changes
103 * TODO explain when Callback is called
104 * TODO complete this list (?)
105 *****************************************************************************/
106 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
107 char *psz_header, vlc_bool_t b_quick )
109 input_thread_t *p_input = NULL; /* thread descriptor */
113 /* Allocate descriptor */
114 p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
115 if( p_input == NULL )
117 msg_Err( p_parent, "out of memory" );
120 p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
122 /* Init Common fields */
123 p_input->b_eof = VLC_FALSE;
124 p_input->b_can_pace_control = VLC_TRUE;
125 p_input->i_start = 0;
128 p_input->i_title = 0;
129 p_input->title = NULL;
130 p_input->i_title_offset = p_input->i_seekpoint_offset = 0;
131 p_input->i_state = INIT_S;
132 p_input->i_rate = INPUT_RATE_DEFAULT;
133 p_input->i_bookmark = 0;
134 p_input->bookmark = NULL;
135 p_input->p_meta = NULL;
136 p_input->p_es_out = NULL;
137 p_input->p_sout = NULL;
138 p_input->b_out_pace_control = VLC_FALSE;
139 p_input->i_pts_delay = 0;
141 /* Init Input fields */
142 p_input->input.p_item = p_item;
143 p_input->input.p_access = NULL;
144 p_input->input.p_stream = NULL;
145 p_input->input.p_demux = NULL;
146 p_input->input.b_title_demux = VLC_FALSE;
147 p_input->input.i_title = 0;
148 p_input->input.title = NULL;
149 p_input->input.i_title_offset = p_input->input.i_seekpoint_offset = 0;
150 p_input->input.b_can_pace_control = VLC_TRUE;
151 p_input->input.b_eof = VLC_FALSE;
152 p_input->input.i_cr_average = 0;
154 if( !p_input->input.p_item->p_meta )
155 p_input->input.p_item->p_meta = vlc_meta_New();
156 stats_ReinitInputStats( p_item->p_stats );
159 p_input->i_slave = 0;
160 p_input->slave = NULL;
162 /* Init control buffer */
163 vlc_mutex_init( p_input, &p_input->lock_control );
164 p_input->i_control = 0;
166 /* Parse input options */
167 vlc_mutex_lock( &p_item->lock );
168 for( i = 0; i < p_item->i_options; i++ )
170 var_OptionParse( p_input, p_item->ppsz_options[i] );
172 vlc_mutex_unlock( &p_item->lock );
174 /* Create Object Variables for private use only */
175 input_ConfigVarInit( p_input );
177 /* Create Objects variables for public Get and Set */
178 input_ControlVarInit( p_input );
179 p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
183 var_Get( p_input, "bookmarks", &val );
186 /* FIXME: have a common cfg parsing routine used by sout and others */
187 char *psz_parser, *psz_start, *psz_end;
188 psz_parser = val.psz_string;
189 while( (psz_start = strchr( psz_parser, '{' ) ) )
191 seekpoint_t *p_seekpoint = vlc_seekpoint_New();
194 psz_end = strchr( psz_start, '}' );
195 if( !psz_end ) break;
196 psz_parser = psz_end + 1;
197 backup = *psz_parser;
200 while( (psz_end = strchr( psz_start, ',' ) ) )
203 if( !strncmp( psz_start, "name=", 5 ) )
205 p_seekpoint->psz_name = psz_start + 5;
207 else if( !strncmp( psz_start, "bytes=", 6 ) )
209 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
211 else if( !strncmp( psz_start, "time=", 5 ) )
213 p_seekpoint->i_time_offset = atoll(psz_start + 5) *
216 psz_start = psz_end + 1;
218 msg_Dbg( p_input, "adding bookmark: %s, bytes="I64Fd", time="I64Fd,
219 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
220 p_seekpoint->i_time_offset );
221 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
222 vlc_seekpoint_Delete( p_seekpoint );
223 *psz_parser = backup;
225 free( val.psz_string );
229 /* Remove 'Now playing' info as it is probably outdated */
230 input_Control( p_input, INPUT_DEL_INFO, _(VLC_META_INFO_CAT),
231 VLC_META_NOW_PLAYING ); /* ? Don't translate as it might has been copied ? */
237 * Initialize an input thread and run it. You will need to monitor the thread to clean
238 * up after it is done
240 * \param p_parent a vlc_object
241 * \param p_item an input item
242 * \return a pointer to the spawned input thread
244 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
245 input_item_t *p_item )
247 return __input_CreateThread2( p_parent, p_item, NULL );
252 input_thread_t *__input_CreateThread2( vlc_object_t *p_parent,
253 input_item_t *p_item,
256 input_thread_t *p_input = NULL; /* thread descriptor */
258 p_input = Create( p_parent, p_item, psz_header, VLC_FALSE );
259 /* Now we can attach our new input */
260 vlc_object_attach( p_input, p_parent );
262 /* Create thread and wait for its readiness. */
263 if( vlc_thread_create( p_input, "input", Run,
264 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
266 msg_Err( p_input, "cannot create input thread" );
267 vlc_object_detach( p_input );
268 vlc_object_destroy( p_input );
277 * Initialize an input thread and run it. This thread will clean after himself,
278 * you can forget about it. It can work either in blocking or non-blocking mode
280 * \param p_parent a vlc_object
281 * \param p_item an input item
282 * \param b_block should we block until read is finished ?
283 * \return the input object id if non blocking, an error code else
285 int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
288 input_thread_t *p_input = NULL; /* thread descriptor */
290 p_input = Create( p_parent, p_item, NULL, VLC_FALSE );
291 /* Now we can attach our new input */
292 vlc_object_attach( p_input, p_parent );
296 RunAndClean( p_input );
301 if( vlc_thread_create( p_input, "input", RunAndClean,
302 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
304 msg_Err( p_input, "cannot create input thread" );
305 vlc_object_detach( p_input );
306 vlc_object_destroy( p_input );
310 return p_input->i_object_id;
314 * Initialize an input and initialize it to preparse the item
315 * This function is blocking. It will only accept to parse files
317 * \param p_parent a vlc_object_t
318 * \param p_item an input item
319 * \return VLC_SUCCESS or an error
321 int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
323 input_thread_t *p_input = NULL; /* thread descriptor */
325 /* Allocate descriptor */
326 p_input = Create( p_parent, p_item, NULL, VLC_TRUE );
327 p_input->i_flags |= OBJECT_FLAGS_QUIET;
328 p_input->i_flags |= OBJECT_FLAGS_NOINTERACT;
330 /* Now we can attach our new input */
331 vlc_object_attach( p_input, p_parent );
333 Init( p_input, VLC_TRUE );
335 /* Clean up master */
336 InputSourceClean( p_input, &p_input->input );
338 /* Unload all modules */
339 if( p_input->p_es_out ) input_EsOutDelete( p_input->p_es_out );
341 vlc_object_detach( p_input );
342 vlc_object_destroy( p_input );
348 * Request a running input thread to stop and die
350 * \param the input thread to stop
352 void input_StopThread( input_thread_t *p_input )
357 /* Set die for input */
358 p_input->b_die = VLC_TRUE;
360 /* We cannot touch p_input fields directly (we can from another thread),
361 * so use the vlc_object_find way, it's perfectly safe */
363 /* Set die for all access */
364 p_list = vlc_list_find( p_input, VLC_OBJECT_ACCESS, FIND_CHILD );
365 for( i = 0; i < p_list->i_count; i++ )
367 p_list->p_values[i].p_object->b_die = VLC_TRUE;
369 vlc_list_release( p_list );
371 /* Set die for all stream */
372 p_list = vlc_list_find( p_input, VLC_OBJECT_STREAM, FIND_CHILD );
373 for( i = 0; i < p_list->i_count; i++ )
375 p_list->p_values[i].p_object->b_die = VLC_TRUE;
377 vlc_list_release( p_list );
379 /* Set die for all demux */
380 p_list = vlc_list_find( p_input, VLC_OBJECT_DEMUX, FIND_CHILD );
381 for( i = 0; i < p_list->i_count; i++ )
383 p_list->p_values[i].p_object->b_die = VLC_TRUE;
385 vlc_list_release( p_list );
387 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
391 * Clean up a dead input thread
392 * This function does not return until the thread is effectively cancelled.
394 * \param the input thread to kill
396 void input_DestroyThread( input_thread_t *p_input )
398 /* Join the thread */
399 vlc_thread_join( p_input );
401 /* Delete input lock (only after thread joined) */
402 vlc_mutex_destroy( &p_input->lock_control );
404 /* TODO: maybe input_DestroyThread should also delete p_input instead
405 * of the playlist but I'm not sure if it's possible */
408 /*****************************************************************************
409 * Run: main thread loop
410 * This is the "normal" thread that spawns the input processing chain,
411 * reads the stream, cleans up and waits
412 *****************************************************************************/
413 static int Run( input_thread_t *p_input )
415 /* Signal that the thread is launched */
416 vlc_thread_ready( p_input );
418 if( Init( p_input, VLC_FALSE ) )
420 /* If we failed, wait before we are killed, and exit */
421 p_input->b_error = VLC_TRUE;
425 /* Tell we're dead */
426 p_input->b_dead = VLC_TRUE;
433 if( !p_input->b_eof && !p_input->b_error && p_input->input.b_eof )
435 /* We have finish to demux data but not to play them */
436 while( !p_input->b_die )
438 if( input_EsOutDecodersEmpty( p_input->p_es_out ) )
441 msg_Dbg( p_input, "waiting decoder fifos to empty" );
443 msleep( INPUT_IDLE_SLEEP );
446 /* We have finished */
447 p_input->b_eof = VLC_TRUE;
450 /* Wait until we are asked to die */
451 if( !p_input->b_die )
462 /*****************************************************************************
463 * RunAndClean: main thread loop
464 * This is the "just forget me" thread that spawns the input processing chain,
465 * reads the stream, cleans up and releases memory
466 *****************************************************************************/
467 static int RunAndClean( input_thread_t *p_input )
469 /* Signal that the thread is launched */
470 vlc_thread_ready( p_input );
472 if( Init( p_input, VLC_FALSE ) )
474 /* If we failed, just exit */
480 if( !p_input->b_eof && !p_input->b_error && p_input->input.b_eof )
482 /* We have finished demuxing data but not playing it */
483 while( !p_input->b_die )
485 if( input_EsOutDecodersEmpty( p_input->p_es_out ) )
488 msg_Dbg( p_input, "waiting decoder fifos to empty" );
490 msleep( INPUT_IDLE_SLEEP );
493 /* We have finished */
494 p_input->b_eof = VLC_TRUE;
501 vlc_object_detach( p_input );
502 vlc_object_destroy( p_input );
508 /*****************************************************************************
509 * Main loop: Fill buffers from access, and demux
510 *****************************************************************************/
511 static void MainLoop( input_thread_t *p_input )
513 int64_t i_intf_update = 0;
514 while( !p_input->b_die && !p_input->b_error && !p_input->input.b_eof )
516 vlc_bool_t b_force_update = VLC_FALSE;
522 if( p_input->i_state != PAUSE_S )
524 if( p_input->i_stop <= 0 || p_input->i_time < p_input->i_stop )
525 i_ret=p_input->input.p_demux->pf_demux(p_input->input.p_demux);
532 if( p_input->input.b_title_demux &&
533 p_input->input.p_demux->info.i_update )
535 i_ret = UpdateFromDemux( p_input );
536 b_force_update = VLC_TRUE;
538 else if( !p_input->input.b_title_demux &&
539 p_input->input.p_access &&
540 p_input->input.p_access->info.i_update )
542 i_ret = UpdateFromAccess( p_input );
543 b_force_update = VLC_TRUE;
547 if( i_ret == 0 ) /* EOF */
551 var_Get( p_input, "input-repeat", &repeat );
552 if( repeat.i_int == 0 )
554 /* End of file - we do not set b_die because only the
555 * playlist is allowed to do so. */
556 msg_Dbg( p_input, "EOF reached" );
557 p_input->input.b_eof = VLC_TRUE;
561 msg_Dbg( p_input, "repeating the same input (%d)",
563 if( repeat.i_int > 0 )
566 var_Set( p_input, "input-repeat", repeat );
569 /* Seek to start title/seekpoint */
570 val.i_int = p_input->input.i_title_start -
571 p_input->input.i_title_offset;
572 if( val.i_int < 0 || val.i_int >= p_input->input.i_title )
574 input_ControlPush( p_input,
575 INPUT_CONTROL_SET_TITLE, &val );
577 val.i_int = p_input->input.i_seekpoint_start -
578 p_input->input.i_seekpoint_offset;
579 if( val.i_int > 0 /* TODO: check upper boundary */ )
580 input_ControlPush( p_input,
581 INPUT_CONTROL_SET_SEEKPOINT, &val );
583 /* Seek to start position */
584 if( p_input->i_start > 0 )
586 val.i_time = p_input->i_start;
587 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
593 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
600 p_input->b_error = VLC_TRUE;
603 if( i_ret > 0 && p_input->i_slave > 0 )
605 SlaveDemux( p_input );
615 vlc_mutex_lock( &p_input->lock_control );
616 ControlReduce( p_input );
617 while( !ControlPopNoLock( p_input, &i_type, &val ) )
619 msg_Dbg( p_input, "control type=%d", i_type );
620 if( Control( p_input, i_type, val ) )
621 b_force_update = VLC_TRUE;
623 vlc_mutex_unlock( &p_input->lock_control );
625 if( b_force_update || i_intf_update < mdate() )
629 int64_t i_time, i_length;
630 /* update input status variables */
631 if( !demux2_Control( p_input->input.p_demux,
632 DEMUX_GET_POSITION, &f_pos ) )
634 val.f_float = (float)f_pos;
635 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
637 if( !demux2_Control( p_input->input.p_demux,
638 DEMUX_GET_TIME, &i_time ) )
640 p_input->i_time = i_time;
642 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
644 if( !demux2_Control( p_input->input.p_demux,
645 DEMUX_GET_LENGTH, &i_length ) )
648 var_Get( p_input, "length", &old_val );
649 val.i_time = i_length;
650 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
652 if( old_val.i_time != val.i_time )
654 UpdateItemLength( p_input, i_length, VLC_TRUE );
658 var_SetBool( p_input, "intf-change", VLC_TRUE );
659 i_intf_update = mdate() + I64C(150000);
665 static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
675 /* Initialize optional stream output. (before access/demuxer)
676 * XXX: we add a special case if the uri starts by vlc.
677 * else 'vlc in.file --sout "" vlc:quit' cannot work (the output will
678 * be destroyed in case of a file).
679 * (this will break playing of file starting by 'vlc:' but I don't
680 * want to add more logic, just force file by file:// or code it ;)
682 memset( &p_input->counters, 0, sizeof( p_input->counters ) );
685 /* Prepare statistics */
686 #define INIT_COUNTER( p, type, compute ) p_input->counters.p_##p = \
687 stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
688 if( p_input->p_libvlc->b_stats )
690 INIT_COUNTER( read_bytes, INTEGER, COUNTER );
691 INIT_COUNTER( read_packets, INTEGER, COUNTER );
692 INIT_COUNTER( demux_read, INTEGER, COUNTER );
693 INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE );
694 INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE );
695 INIT_COUNTER( played_abuffers, INTEGER, COUNTER );
696 INIT_COUNTER( lost_abuffers, INTEGER, COUNTER );
697 INIT_COUNTER( displayed_pictures, INTEGER, COUNTER );
698 INIT_COUNTER( lost_pictures, INTEGER, COUNTER );
699 INIT_COUNTER( decoded_audio, INTEGER, COUNTER );
700 INIT_COUNTER( decoded_video, INTEGER, COUNTER );
701 INIT_COUNTER( decoded_sub, INTEGER, COUNTER );
702 p_input->counters.p_sout_send_bitrate = NULL;
703 p_input->counters.p_sout_sent_packets = NULL;
704 p_input->counters.p_sout_sent_bytes = NULL;
705 if( p_input->counters.p_demux_bitrate )
706 p_input->counters.p_demux_bitrate->update_interval = 1000000;
707 if( p_input->counters.p_input_bitrate )
708 p_input->counters.p_input_bitrate->update_interval = 1000000;
710 vlc_mutex_init( p_input, &p_input->counters.counters_lock );
713 psz = var_GetString( p_input, "sout" );
714 if( *psz && strncasecmp( p_input->input.p_item->psz_uri, "vlc:", 4 ) )
716 p_input->p_sout = sout_NewInstance( p_input, psz );
717 if( p_input->p_sout == NULL )
719 msg_Err( p_input, "cannot start stream output instance, " \
724 if( p_input->p_libvlc->b_stats )
726 INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
727 INIT_COUNTER (sout_sent_bytes, INTEGER, COUNTER );
728 INIT_COUNTER( sout_send_bitrate, FLOAT, DERIVATIVE );
729 if( p_input->counters.p_sout_send_bitrate )
730 p_input->counters.p_sout_send_bitrate->update_interval =
738 p_input->p_es_out = input_EsOutNew( p_input );
739 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
740 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
742 var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
743 var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
745 if( InputSourceInit( p_input, &p_input->input,
746 p_input->input.p_item->psz_uri, NULL, b_quick ) )
751 /* Create global title (from master) */
754 p_input->i_title = p_input->input.i_title;
755 p_input->title = p_input->input.title;
756 p_input->i_title_offset = p_input->input.i_title_offset;
757 p_input->i_seekpoint_offset = p_input->input.i_seekpoint_offset;
758 if( p_input->i_title > 0 )
760 /* Setup variables */
761 input_ControlVarNavigation( p_input );
762 input_ControlVarTitle( p_input, 0 );
766 p_input->b_can_pace_control = p_input->input.b_can_pace_control;
767 p_input->b_can_pause = p_input->input.b_can_pause;
770 if( p_input->i_pts_delay < 0 )
771 p_input->i_pts_delay = 0;
773 /* If the desynchronisation requested by the user is < 0, we need to
774 * cache more data. */
775 var_Get( p_input, "audio-desync", &val );
776 if( val.i_int < 0 ) p_input->i_pts_delay -= (val.i_int * 1000);
778 /* Update cr_average depending on the caching */
779 p_input->input.i_cr_average *= (10 * p_input->i_pts_delay / 200000);
780 p_input->input.i_cr_average /= 10;
781 if( p_input->input.i_cr_average < 10 ) p_input->input.i_cr_average = 10;
784 /* Load master infos */
786 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_LENGTH,
787 &val.i_time ) && val.i_time > 0 )
789 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
790 UpdateItemLength( p_input, val.i_time, b_quick );
791 p_input->input.p_item->i_duration = val.i_time;
794 /* Start title/chapter */
797 val.i_int = p_input->input.i_title_start -
798 p_input->input.i_title_offset;
799 if( val.i_int > 0 && val.i_int < p_input->input.i_title )
800 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
801 val.i_int = p_input->input.i_seekpoint_start -
802 p_input->input.i_seekpoint_offset;
803 if( val.i_int > 0 /* TODO: check upper boundary */ )
804 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
808 p_input->i_start = (int64_t)var_GetInteger( p_input, "start-time" ) *
810 p_input->i_stop = (int64_t)var_GetInteger( p_input, "stop-time" ) *
813 if( p_input->i_start > 0 )
815 if( p_input->i_start >= val.i_time )
817 msg_Warn( p_input, "invalid start-time ignored" );
823 msg_Dbg( p_input, "starting at time: %ds",
824 (int)( p_input->i_start / I64C(1000000) ) );
826 s.i_time = p_input->i_start;
827 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
830 if( p_input->i_stop > 0 && p_input->i_stop <= p_input->i_start )
832 msg_Warn( p_input, "invalid stop-time ignored" );
838 /* Get fps and set it if not already set */
839 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) &&
842 float f_requested_fps;
844 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
845 var_SetFloat( p_input, "sub-original-fps", f_fps );
847 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
848 if( f_requested_fps != f_fps )
850 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
852 var_SetFloat( p_input, "sub-fps", f_requested_fps );
856 i_delay = var_CreateGetInteger( p_input, "sub-delay" );
859 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
863 /* Look for and add subtitle files */
864 psz_subtitle = var_GetString( p_input, "sub-file" );
867 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
868 input_AddSubtitles( p_input, psz_subtitle, VLC_FALSE );
871 var_Get( p_input, "sub-autodetect-file", &val );
874 char *psz_autopath = var_GetString( p_input, "sub-autodetect-path" );
875 char **subs = subtitles_Detect( p_input, psz_autopath,
876 p_input->input.p_item->psz_uri );
881 /* Try to autoselect the first autodetected subtitles file
882 * if no subtitles file was specified */
883 if( *psz_subtitle == 0 && subs && subs[0] )
885 input_AddSubtitles( p_input, subs[0], VLC_FALSE );
890 /* Then, just add the following subtitles files */
891 for( ; subs && subs[i]; i++ )
893 if( strcmp( psz_subtitle, subs[i] ) )
895 sub = InputSourceNew( p_input );
896 if( !InputSourceInit( p_input, sub, subs[i], "subtitle",
899 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
904 if( subs ) free( subs );
905 if( psz_autopath ) free( psz_autopath );
907 free( psz_subtitle );
910 psz = var_GetString( p_input, "input-slave" );
914 input_source_t *slave;
917 while( *psz == ' ' || *psz == '#' )
921 if( ( psz_delim = strchr( psz, '#' ) ) )
930 msg_Dbg( p_input, "adding slave input '%s'", psz );
931 slave = InputSourceNew( p_input );
932 if( !InputSourceInit( p_input, slave, psz, NULL, VLC_FALSE ) )
934 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
939 if( psz ) free( psz );
943 p_input->i_start = 0;
944 p_input->i_start = 0;
950 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
951 i_es_out_mode = ES_OUT_MODE_AUTO;
953 if( p_input->p_sout )
955 var_Get( p_input, "sout-all", &val );
958 i_es_out_mode = ES_OUT_MODE_ALL;
963 var_Get( p_input, "programs", &val );
964 if ( val.p_list && val.p_list->i_count )
966 i_es_out_mode = ES_OUT_MODE_PARTIAL;
967 /* Note : we should remove the "program" callback. */
970 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
974 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
976 /* Inform the demuxer about waited group (needed only for DVB) */
977 if( i_es_out_mode == ES_OUT_MODE_ALL )
979 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
981 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
983 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1,
988 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP,
989 (int) var_GetInteger( p_input, "program" ), NULL );
992 if( p_input->p_sout )
994 if( p_input->p_sout->i_out_pace_nocontrol > 0 )
996 p_input->b_out_pace_control = VLC_FALSE;
1000 p_input->b_out_pace_control = VLC_TRUE;
1003 if( p_input->b_can_pace_control && p_input->b_out_pace_control )
1005 /* We don't want a high input priority here or we'll
1006 * end-up sucking up all the CPU time */
1007 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
1010 msg_Dbg( p_input, "starting in %s mode",
1011 p_input->b_out_pace_control ? "asynch" : "synch" );
1015 p_meta = p_input->input.p_item->p_meta;
1016 /* Get meta data from users */
1017 InputMetaUser( p_input );
1018 /* Get meta data from master input */
1019 demux2_Control( p_input->input.p_demux, DEMUX_GET_META, p_meta );
1021 /* Access_file does not give any meta, and there are no slave */
1024 if( p_input->input.p_access )
1025 access2_Control( p_input->input.p_access, ACCESS_GET_META,
1028 /* Get meta data from slave input */
1029 for( i = 0; i < p_input->i_slave; i++ )
1031 demux2_Control( p_input->slave[i]->p_demux,
1032 DEMUX_GET_META, p_meta );
1033 if( p_input->slave[i]->p_access )
1035 access2_Control( p_input->slave[i]->p_access,
1036 ACCESS_GET_META, p_meta );
1041 UpdateMeta( p_input, b_quick );
1045 msg_Dbg( p_input, "`%s' successfully opened",
1046 p_input->input.p_item->psz_uri );
1050 /* initialization is complete */
1051 p_input->i_state = PLAYING_S;
1053 val.i_int = PLAYING_S;
1054 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
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 )
1097 msg_Dbg( p_input, "closing input" );
1099 /* We are at the end */
1100 p_input->i_state = END_S;
1103 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1105 /* Clean control variables */
1106 input_ControlVarClean( p_input );
1108 /* Clean up master */
1109 InputSourceClean( p_input, &p_input->input );
1112 for( i = 0; i < p_input->i_slave; i++ )
1114 InputSourceClean( p_input, p_input->slave[i] );
1115 free( p_input->slave[i] );
1117 if( p_input->slave ) free( p_input->slave );
1119 /* Unload all modules */
1120 if( p_input->p_es_out )
1121 input_EsOutDelete( p_input->p_es_out );
1123 #define CL_CO( c ) stats_CounterClean( p_input->counters.p_##c ); p_input->counters.p_##c = NULL;
1124 if( p_input->p_libvlc->b_stats )
1126 vlc_mutex_lock( &p_input->counters.counters_lock );
1127 CL_CO( read_bytes );
1128 CL_CO( read_packets );
1129 CL_CO( demux_read );
1130 CL_CO( input_bitrate );
1131 CL_CO( demux_bitrate );
1132 CL_CO( played_abuffers );
1133 CL_CO( lost_abuffers );
1134 CL_CO( displayed_pictures );
1135 CL_CO( lost_pictures );
1136 CL_CO( decoded_audio) ;
1137 CL_CO( decoded_video );
1138 CL_CO( decoded_sub) ;
1139 vlc_mutex_unlock( &p_input->counters.counters_lock );
1142 /* Close optional stream output instance */
1143 if( p_input->p_sout )
1145 vlc_object_t *p_pl =
1146 vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1149 vlc_mutex_lock( &p_input->counters.counters_lock );
1150 CL_CO( sout_sent_packets );
1151 CL_CO( sout_sent_bytes );
1152 CL_CO( sout_send_bitrate );
1153 vlc_mutex_unlock( &p_input->counters.counters_lock );
1155 if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
1157 /* attach sout to the playlist */
1158 msg_Dbg( p_input, "keeping sout" );
1159 vlc_object_detach( p_input->p_sout );
1160 vlc_object_attach( p_input->p_sout, p_pl );
1164 msg_Dbg( p_input, "destroying sout" );
1165 sout_DeleteInstance( p_input->p_sout );
1168 vlc_object_release( p_pl );
1172 /* Tell we're dead */
1173 p_input->b_dead = VLC_TRUE;
1176 /*****************************************************************************
1178 *****************************************************************************/
1179 static inline int ControlPopNoLock( input_thread_t *p_input,
1180 int *pi_type, vlc_value_t *p_val )
1182 if( p_input->i_control <= 0 )
1184 return VLC_EGENERIC;
1187 *pi_type = p_input->control[0].i_type;
1188 *p_val = p_input->control[0].val;
1190 p_input->i_control--;
1191 if( p_input->i_control > 0 )
1195 for( i = 0; i < p_input->i_control; i++ )
1197 p_input->control[i].i_type = p_input->control[i+1].i_type;
1198 p_input->control[i].val = p_input->control[i+1].val;
1205 static void ControlReduce( input_thread_t *p_input )
1208 for( i = 1; i < p_input->i_control; i++ )
1210 const int i_lt = p_input->control[i-1].i_type;
1211 const int i_ct = p_input->control[i].i_type;
1213 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1214 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->i_control,
1218 ( i_ct == INPUT_CONTROL_SET_STATE ||
1219 i_ct == INPUT_CONTROL_SET_RATE ||
1220 i_ct == INPUT_CONTROL_SET_POSITION ||
1221 i_ct == INPUT_CONTROL_SET_TIME ||
1222 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1223 i_ct == INPUT_CONTROL_SET_TITLE ||
1224 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1225 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1228 // msg_Dbg( p_input, "merged at %d", i );
1229 /* Remove the i-1 */
1230 for( j = i; j < p_input->i_control; j++ )
1231 p_input->control[j-1] = p_input->control[j];
1232 p_input->i_control--;
1236 /* TODO but that's not that important
1237 - merge SET_X with SET_X_CMD
1238 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1239 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1246 static vlc_bool_t Control( input_thread_t *p_input, int i_type,
1249 vlc_bool_t b_force_update = VLC_FALSE;
1251 if( !p_input ) return b_force_update;
1255 case INPUT_CONTROL_SET_DIE:
1256 msg_Dbg( p_input, "control: stopping input" );
1257 /* Mark all submodules to die */
1258 if( p_input->input.p_access )
1259 p_input->input.p_access->b_die = VLC_TRUE;
1260 if( p_input->input.p_stream )
1261 p_input->input.p_stream->b_die = VLC_TRUE;
1262 p_input->input.p_demux->b_die = VLC_TRUE;
1264 p_input->b_die = VLC_TRUE;
1267 case INPUT_CONTROL_SET_POSITION:
1268 case INPUT_CONTROL_SET_POSITION_OFFSET:
1271 if( i_type == INPUT_CONTROL_SET_POSITION )
1273 f_pos = val.f_float;
1277 /* Should not fail */
1278 demux2_Control( p_input->input.p_demux,
1279 DEMUX_GET_POSITION, &f_pos );
1280 f_pos += val.f_float;
1282 if( f_pos < 0.0 ) f_pos = 0.0;
1283 if( f_pos > 1.0 ) f_pos = 1.0;
1284 /* Reset the decoders states and clock synch (before calling the demuxer */
1285 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1286 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1287 if( demux2_Control( p_input->input.p_demux, DEMUX_SET_POSITION,
1290 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1291 "%2.1f%% failed", f_pos * 100 );
1295 if( p_input->i_slave > 0 )
1296 SlaveSeek( p_input );
1298 b_force_update = VLC_TRUE;
1303 case INPUT_CONTROL_SET_TIME:
1304 case INPUT_CONTROL_SET_TIME_OFFSET:
1309 if( i_type == INPUT_CONTROL_SET_TIME )
1311 i_time = val.i_time;
1315 /* Should not fail */
1316 demux2_Control( p_input->input.p_demux,
1317 DEMUX_GET_TIME, &i_time );
1318 i_time += val.i_time;
1320 if( i_time < 0 ) i_time = 0;
1322 /* Reset the decoders states and clock synch (before calling the demuxer */
1323 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1324 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1326 i_ret = demux2_Control( p_input->input.p_demux,
1327 DEMUX_SET_TIME, i_time );
1332 /* Emulate it with a SET_POS */
1333 demux2_Control( p_input->input.p_demux,
1334 DEMUX_GET_LENGTH, &i_length );
1337 double f_pos = (double)i_time / (double)i_length;
1338 i_ret = demux2_Control( p_input->input.p_demux,
1339 DEMUX_SET_POSITION, f_pos );
1344 msg_Warn( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) "I64Fd
1345 " failed or not possible", i_time );
1349 if( p_input->i_slave > 0 )
1350 SlaveSeek( p_input );
1352 b_force_update = VLC_TRUE;
1357 case INPUT_CONTROL_SET_STATE:
1358 if( ( val.i_int == PLAYING_S && p_input->i_state == PAUSE_S ) ||
1359 ( val.i_int == PAUSE_S && p_input->i_state == PAUSE_S ) )
1362 if( p_input->input.p_access )
1363 i_ret = access2_Control( p_input->input.p_access,
1364 ACCESS_SET_PAUSE_STATE, VLC_FALSE );
1366 i_ret = demux2_Control( p_input->input.p_demux,
1367 DEMUX_SET_PAUSE_STATE, VLC_FALSE );
1371 /* FIXME What to do ? */
1372 msg_Warn( p_input, "cannot unset pause -> EOF" );
1373 vlc_mutex_unlock( &p_input->lock_control );
1374 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1375 vlc_mutex_lock( &p_input->lock_control );
1378 b_force_update = VLC_TRUE;
1380 /* Switch to play */
1381 p_input->i_state = PLAYING_S;
1382 val.i_int = PLAYING_S;
1383 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1386 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1387 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1389 else if( val.i_int == PAUSE_S && p_input->i_state == PLAYING_S &&
1390 p_input->b_can_pause )
1393 if( p_input->input.p_access )
1394 i_ret = access2_Control( p_input->input.p_access,
1395 ACCESS_SET_PAUSE_STATE, VLC_TRUE );
1397 i_ret = demux2_Control( p_input->input.p_demux,
1398 DEMUX_SET_PAUSE_STATE, VLC_TRUE );
1400 b_force_update = VLC_TRUE;
1404 msg_Warn( p_input, "cannot set pause state" );
1405 val.i_int = p_input->i_state;
1409 val.i_int = PAUSE_S;
1412 /* Switch to new state */
1413 p_input->i_state = val.i_int;
1414 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1416 else if( val.i_int == PAUSE_S && !p_input->b_can_pause )
1418 b_force_update = VLC_TRUE;
1420 /* Correct "state" value */
1421 val.i_int = p_input->i_state;
1422 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1424 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1426 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1430 case INPUT_CONTROL_SET_RATE:
1431 case INPUT_CONTROL_SET_RATE_SLOWER:
1432 case INPUT_CONTROL_SET_RATE_FASTER:
1436 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1437 i_rate = p_input->i_rate * 2;
1438 else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
1439 i_rate = p_input->i_rate / 2;
1443 if( i_rate < INPUT_RATE_MIN )
1445 msg_Dbg( p_input, "cannot set rate faster" );
1446 i_rate = INPUT_RATE_MIN;
1448 else if( i_rate > INPUT_RATE_MAX )
1450 msg_Dbg( p_input, "cannot set rate slower" );
1451 i_rate = INPUT_RATE_MAX;
1453 if( i_rate != INPUT_RATE_DEFAULT &&
1454 ( !p_input->b_can_pace_control ||
1455 ( p_input->p_sout && !p_input->b_out_pace_control ) ) )
1457 msg_Dbg( p_input, "cannot change rate" );
1458 i_rate = INPUT_RATE_DEFAULT;
1460 if( i_rate != p_input->i_rate )
1462 p_input->i_rate = i_rate;
1464 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
1466 /* We haven't send data to decoder when rate != default */
1467 if( i_rate == INPUT_RATE_DEFAULT )
1468 input_EsOutDiscontinuity( p_input->p_es_out, VLC_TRUE );
1471 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1473 b_force_update = VLC_TRUE;
1478 case INPUT_CONTROL_SET_PROGRAM:
1479 /* No need to force update, es_out does it if needed */
1480 es_out_Control( p_input->p_es_out,
1481 ES_OUT_SET_GROUP, val.i_int );
1483 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1487 case INPUT_CONTROL_SET_ES:
1488 /* No need to force update, es_out does it if needed */
1489 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
1490 input_EsOutGetFromID( p_input->p_es_out,
1494 case INPUT_CONTROL_SET_AUDIO_DELAY:
1495 input_EsOutSetDelay( p_input->p_es_out,
1496 AUDIO_ES, val.i_time );
1497 var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
1500 case INPUT_CONTROL_SET_SPU_DELAY:
1501 input_EsOutSetDelay( p_input->p_es_out,
1502 SPU_ES, val.i_time );
1503 var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
1506 case INPUT_CONTROL_SET_TITLE:
1507 case INPUT_CONTROL_SET_TITLE_NEXT:
1508 case INPUT_CONTROL_SET_TITLE_PREV:
1509 if( p_input->input.b_title_demux &&
1510 p_input->input.i_title > 0 )
1513 /* FIXME handle demux title */
1514 demux_t *p_demux = p_input->input.p_demux;
1517 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1518 i_title = p_demux->info.i_title - 1;
1519 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1520 i_title = p_demux->info.i_title + 1;
1522 i_title = val.i_int;
1524 if( i_title >= 0 && i_title < p_input->input.i_title )
1526 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1527 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1529 demux2_Control( p_demux, DEMUX_SET_TITLE, i_title );
1530 input_ControlVarTitle( p_input, i_title );
1533 else if( p_input->input.i_title > 0 )
1535 access_t *p_access = p_input->input.p_access;
1538 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1539 i_title = p_access->info.i_title - 1;
1540 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1541 i_title = p_access->info.i_title + 1;
1543 i_title = val.i_int;
1545 if( i_title >= 0 && i_title < p_input->input.i_title )
1547 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1548 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1550 access2_Control( p_access, ACCESS_SET_TITLE, i_title );
1551 stream_AccessReset( p_input->input.p_stream );
1555 case INPUT_CONTROL_SET_SEEKPOINT:
1556 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1557 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1558 if( p_input->input.b_title_demux &&
1559 p_input->input.i_title > 0 )
1561 demux_t *p_demux = p_input->input.p_demux;
1563 int64_t i_input_time;
1564 int64_t i_seekpoint_time;
1566 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1568 i_seekpoint = p_demux->info.i_seekpoint;
1569 i_seekpoint_time = p_input->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1570 if( i_seekpoint_time >= 0 &&
1571 !demux2_Control( p_demux,
1572 DEMUX_GET_TIME, &i_input_time ) )
1574 if ( i_input_time < i_seekpoint_time + 3000000 )
1580 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1581 i_seekpoint = p_demux->info.i_seekpoint + 1;
1583 i_seekpoint = val.i_int;
1585 if( i_seekpoint >= 0 && i_seekpoint <
1586 p_input->input.title[p_demux->info.i_title]->i_seekpoint )
1588 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1589 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1591 demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1594 else if( p_input->input.i_title > 0 )
1596 demux_t *p_demux = p_input->input.p_demux;
1597 access_t *p_access = p_input->input.p_access;
1599 int64_t i_input_time;
1600 int64_t i_seekpoint_time;
1602 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1604 i_seekpoint = p_access->info.i_seekpoint;
1605 i_seekpoint_time = p_input->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1606 if( i_seekpoint_time >= 0 &&
1607 demux2_Control( p_demux,
1608 DEMUX_GET_TIME, &i_input_time ) )
1610 if ( i_input_time < i_seekpoint_time + 3000000 )
1616 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1617 i_seekpoint = p_access->info.i_seekpoint + 1;
1619 i_seekpoint = val.i_int;
1621 if( i_seekpoint >= 0 && i_seekpoint <
1622 p_input->input.title[p_access->info.i_title]->i_seekpoint )
1624 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1625 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1627 access2_Control( p_access, ACCESS_SET_SEEKPOINT,
1629 stream_AccessReset( p_input->input.p_stream );
1634 case INPUT_CONTROL_ADD_SLAVE:
1635 if( val.psz_string )
1637 input_source_t *slave = InputSourceNew( p_input );
1639 if( !InputSourceInit( p_input, slave, val.psz_string, NULL,
1642 vlc_meta_t *p_meta = p_input->input.p_item->p_meta;
1646 msg_Dbg( p_input, "adding %s as slave on the fly",
1650 if( demux2_Control( p_input->input.p_demux,
1651 DEMUX_GET_TIME, &i_time ) )
1653 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
1654 InputSourceClean( p_input, slave );
1658 if( demux2_Control( slave->p_demux,
1659 DEMUX_SET_TIME, i_time ) )
1661 msg_Err( p_input, "seek failed for new slave" );
1662 InputSourceClean( p_input, slave );
1667 /* Get meta (access and demux) */
1668 access2_Control( slave->p_access, ACCESS_GET_META,
1670 demux2_Control( slave->p_demux, DEMUX_GET_META, p_meta );
1671 UpdateMeta( p_input, VLC_FALSE );
1673 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
1677 msg_Warn( p_input, "failed to add %s as slave",
1681 free( val.psz_string );
1685 case INPUT_CONTROL_SET_BOOKMARK:
1687 msg_Err( p_input, "not yet implemented" );
1691 return b_force_update;
1694 /*****************************************************************************
1696 *****************************************************************************/
1697 static int UpdateFromDemux( input_thread_t *p_input )
1699 demux_t *p_demux = p_input->input.p_demux;
1702 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
1704 v.i_int = p_demux->info.i_title;
1705 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1707 input_ControlVarTitle( p_input, p_demux->info.i_title );
1709 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
1711 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
1713 v.i_int = p_demux->info.i_seekpoint;
1714 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1716 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1718 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
1720 /* Hmmm only works with master input */
1721 if( p_input->input.p_demux == p_demux )
1723 int i_title_end = p_input->input.i_title_end -
1724 p_input->input.i_title_offset;
1725 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1726 p_input->input.i_seekpoint_offset;
1728 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
1730 if( p_demux->info.i_title > i_title_end ||
1731 ( p_demux->info.i_title == i_title_end &&
1732 p_demux->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1734 else if( i_seekpoint_end >=0 )
1736 if( p_demux->info.i_seekpoint > i_seekpoint_end ) return 0;
1738 else if( i_title_end >= 0 )
1740 if( p_demux->info.i_title > i_title_end ) return 0;
1747 /*****************************************************************************
1749 *****************************************************************************/
1750 static int UpdateFromAccess( input_thread_t *p_input )
1752 access_t *p_access = p_input->input.p_access;
1755 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
1757 v.i_int = p_access->info.i_title;
1758 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1760 input_ControlVarTitle( p_input, p_access->info.i_title );
1762 stream_AccessUpdate( p_input->input.p_stream );
1764 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
1766 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
1768 v.i_int = p_access->info.i_seekpoint;
1769 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1770 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1772 if( p_access->info.i_update & INPUT_UPDATE_META )
1774 /* TODO maybe multi - access ? */
1775 vlc_meta_t *p_meta = p_input->input.p_item->p_meta;
1776 access2_Control( p_input->input.p_access,ACCESS_GET_META, p_meta );
1777 UpdateMeta( p_input, VLC_FALSE );
1778 var_SetBool( p_input, "item-change", p_input->input.p_item->i_id );
1779 p_access->info.i_update &= ~INPUT_UPDATE_META;
1782 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
1784 /* Hmmm only works with master input */
1785 if( p_input->input.p_access == p_access )
1787 int i_title_end = p_input->input.i_title_end -
1788 p_input->input.i_title_offset;
1789 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1790 p_input->input.i_seekpoint_offset;
1792 if( i_title_end >= 0 && i_seekpoint_end >=0 )
1794 if( p_access->info.i_title > i_title_end ||
1795 ( p_access->info.i_title == i_title_end &&
1796 p_access->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1798 else if( i_seekpoint_end >=0 )
1800 if( p_access->info.i_seekpoint > i_seekpoint_end ) return 0;
1802 else if( i_title_end >= 0 )
1804 if( p_access->info.i_title > i_title_end ) return 0;
1811 /*****************************************************************************
1813 *****************************************************************************/
1814 static int UpdateMeta( input_thread_t *p_input, vlc_bool_t b_quick )
1816 vlc_meta_t *p_meta = p_input->input.p_item->p_meta;
1820 if( p_meta->psz_title && !p_input->input.p_item->b_fixed_name )
1821 input_Control( p_input, INPUT_SET_NAME, p_meta->psz_title );
1823 /** \todo handle sout meta */
1828 /*****************************************************************************
1830 *****************************************************************************/
1831 static void UpdateItemLength( input_thread_t *p_input, int64_t i_length,
1832 vlc_bool_t b_quick )
1834 playlist_t *p_playlist;
1835 char psz_buffer[MSTRTIME_MAX_SIZE];
1837 vlc_mutex_lock( &p_input->input.p_item->lock );
1838 p_input->input.p_item->i_duration = i_length;
1839 vlc_mutex_unlock( &p_input->input.p_item->lock );
1841 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
1845 var_SetInteger( p_playlist, "item-change",
1846 p_input->input.p_item->i_id );
1847 vlc_object_release( p_playlist );
1850 input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
1851 msecstotimestr( psz_buffer, i_length / 1000 ) );
1854 /*****************************************************************************
1856 *****************************************************************************/
1857 static input_source_t *InputSourceNew( input_thread_t *p_input )
1859 input_source_t *in = (input_source_t*) malloc( sizeof( input_source_t ) );
1863 msg_Err( p_input, "out of memory for new input source" );
1868 in->p_access = NULL;
1869 in->p_stream = NULL;
1871 in->b_title_demux = VLC_FALSE;
1874 in->b_can_pace_control = VLC_TRUE;
1875 in->b_eof = VLC_FALSE;
1876 in->i_cr_average = 0;
1881 /*****************************************************************************
1883 *****************************************************************************/
1884 static int InputSourceInit( input_thread_t *p_input,
1885 input_source_t *in, char *psz_mrl,
1886 char *psz_forced_demux, vlc_bool_t b_quick )
1888 char *psz_dup = strdup( psz_mrl );
1896 if( !in ) return VLC_EGENERIC;
1901 MRLSplit( VLC_OBJECT(p_input), psz_dup,
1902 &psz_access, &psz_demux, &psz_path );
1904 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
1905 psz_mrl, psz_access, psz_demux, psz_path );
1907 /* Hack to allow udp://@:port syntax */
1909 (strncmp( psz_access, "udp", 3 ) &&
1910 strncmp( psz_access, "rtp", 3 )) )
1912 /* Find optional titles and seekpoints */
1913 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
1914 &in->i_seekpoint_start, &in->i_seekpoint_end );
1916 if( psz_forced_demux && *psz_forced_demux )
1918 psz_demux = psz_forced_demux;
1920 else if( !psz_demux || *psz_demux == '\0' )
1922 /* special hack for forcing a demuxer with --demux=module
1923 * (and do nothing with a list) */
1924 char *psz_var_demux = var_GetString( p_input, "demux" );
1926 if( *psz_var_demux != '\0' &&
1927 !strchr(psz_var_demux, ',' ) &&
1928 !strchr(psz_var_demux, ':' ) )
1930 psz_demux = psz_var_demux;
1932 msg_Dbg( p_input, "enforced demux ` %s'", psz_demux );
1934 else if( psz_var_demux )
1936 free( psz_var_demux );
1940 /* Try access_demux if no demux given */
1941 if( *psz_demux == '\0' )
1943 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
1944 NULL, p_input->p_es_out, VLC_FALSE );
1950 msg_Dbg( p_input, "trying to pre-parse %s", psz_path );
1951 psz_demux = strdup( "" );
1952 psz_access = strdup( "file" );
1957 int64_t i_pts_delay;
1959 /* Get infos from access_demux */
1960 demux2_Control( in->p_demux,
1961 DEMUX_GET_PTS_DELAY, &i_pts_delay );
1962 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
1964 in->b_title_demux = VLC_TRUE;
1965 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
1966 &in->title, &in->i_title,
1967 &in->i_title_offset, &in->i_seekpoint_offset ) )
1972 demux2_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
1973 &in->b_can_pace_control );
1974 demux2_Control( in->p_demux, DEMUX_CAN_PAUSE,
1978 demux2_Control( in->p_demux, DEMUX_CAN_SEEK,
1984 int64_t i_pts_delay;
1986 /* Now try a real access */
1987 in->p_access = access2_New( p_input, psz_access, psz_demux, psz_path,
1990 /* Access failed, URL encoded ? */
1991 if( in->p_access == NULL && strchr( psz_path, '%' ) )
1993 DecodeUrl( psz_path );
1995 msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
1996 psz_access, psz_demux, psz_path );
1998 in->p_access = access2_New( p_input,
1999 psz_access, psz_demux, psz_path,
2002 #ifndef WIN32 /* Remove this gross hack from the win32 build as colons
2003 * are forbidden in filenames on Win32. */
2005 /* Maybe we got something like: /Volumes/toto:titi/gabu.mpg */
2006 if( in->p_access == NULL &&
2007 *psz_access == '\0' && ( *psz_demux || *psz_path ) )
2009 if( psz_dup ) free( psz_dup );
2010 psz_dup = strdup( psz_mrl );
2012 if( psz_forced_demux && *psz_forced_demux )
2014 psz_demux = psz_forced_demux;
2016 else psz_demux = "";
2019 in->p_access = access2_New( p_input,
2020 psz_access, psz_demux, psz_path,
2025 if( in->p_access == NULL )
2027 msg_Err( p_input, "no suitable access module for `%s'", psz_mrl );
2028 intf_UserFatal( VLC_OBJECT( p_input), VLC_FALSE,
2029 _("Your input can't be opened"),
2030 _("VLC is unable to open the MRL '%s'."
2031 " Check the log for details."), psz_mrl );
2036 psz_tmp = psz = var_GetString( p_input, "access-filter" );
2037 while( psz && *psz )
2039 access_t *p_access = in->p_access;
2040 char *end = strchr( psz, ':' );
2045 in->p_access = access2_FilterNew( in->p_access, psz );
2046 if( in->p_access == NULL )
2048 in->p_access = p_access;
2049 msg_Warn( p_input, "failed to insert access filter %s",
2055 if( psz_tmp ) free( psz_tmp );
2057 /* Get infos from access */
2060 access2_Control( in->p_access,
2061 ACCESS_GET_PTS_DELAY, &i_pts_delay );
2062 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2064 in->b_title_demux = VLC_FALSE;
2065 if( access2_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2066 &in->title, &in->i_title,
2067 &in->i_title_offset, &in->i_seekpoint_offset ) )
2073 access2_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2074 &in->b_can_pace_control );
2075 access2_Control( in->p_access, ACCESS_CAN_PAUSE,
2077 access2_Control( in->p_access, ACCESS_CAN_SEEK,
2079 var_Set( p_input, "seekable", val );
2082 /* Create the stream_t */
2083 in->p_stream = stream_AccessNew( in->p_access, b_quick );
2084 if( in->p_stream == NULL )
2086 msg_Warn( p_input, "cannot create a stream_t from access" );
2090 /* Open a demuxer */
2091 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2093 psz_demux = in->p_access->psz_demux;
2095 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
2096 in->p_stream, p_input->p_es_out, b_quick );
2097 if( in->p_demux == NULL )
2099 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2100 psz_access, psz_demux, psz_path );
2101 intf_UserFatal( VLC_OBJECT( p_input), VLC_FALSE,
2102 _("Can't recognize the input's format"),
2103 _("The format of '%s' can't be detected. "
2104 "Have a look the log for details."), psz_mrl );
2108 /* TODO get title from demux */
2109 if( !b_quick && in->i_title <= 0 )
2111 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2112 &in->title, &in->i_title,
2113 &in->i_title_offset, &in->i_seekpoint_offset ))
2120 in->b_title_demux = VLC_TRUE;
2125 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2126 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2128 if( psz_dup ) free( psz_dup );
2133 demux2_Delete( in->p_demux );
2136 stream_Delete( in->p_stream );
2139 access2_Delete( in->p_access );
2140 if( psz_dup ) free( psz_dup );
2142 return VLC_EGENERIC;
2145 /*****************************************************************************
2147 *****************************************************************************/
2148 static void InputSourceClean( input_thread_t *p_input, input_source_t *in )
2151 demux2_Delete( in->p_demux );
2154 stream_Delete( in->p_stream );
2157 access2_Delete( in->p_access );
2159 if( in->i_title > 0 )
2162 for( i = 0; i < in->i_title; i++ )
2164 vlc_input_title_Delete( in->title[i] );
2170 static void SlaveDemux( input_thread_t *p_input )
2175 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2177 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2181 for( i = 0; i < p_input->i_slave; i++ )
2183 input_source_t *in = p_input->slave[i];
2189 if( demux2_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2194 if( demux2_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2196 msg_Err( p_input, "slave[%d] doesn't like "
2197 "DEMUX_GET_TIME -> EOF", i );
2202 if( i_stime >= i_time )
2205 if( ( i_ret = in->p_demux->pf_demux( in->p_demux ) ) <= 0 )
2211 i_ret = in->p_demux->pf_demux( in->p_demux );
2216 msg_Dbg( p_input, "slave %d EOF", i );
2217 in->b_eof = VLC_TRUE;
2222 static void SlaveSeek( input_thread_t *p_input )
2227 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2229 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2233 for( i = 0; i < p_input->i_slave; i++ )
2235 input_source_t *in = p_input->slave[i];
2237 if( demux2_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
2239 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2240 in->b_eof = VLC_TRUE;
2244 /*****************************************************************************
2246 *****************************************************************************/
2247 static void InputMetaUser( input_thread_t *p_input )
2249 vlc_meta_t *p_meta = p_input->input.p_item->p_meta;
2252 if( !p_meta ) return;
2254 /* Get meta information from user */
2255 #define GET_META( field, s ) \
2256 var_Get( p_input, (s), &val ); \
2257 if( *val.psz_string ) { \
2258 if( p_meta->psz_ ## field ) free ( p_meta->psz_ ## field ); \
2259 p_meta->psz_ ## field = strdup( val.psz_string ); \
2261 free( val.psz_string )
2263 GET_META( title, "meta-title" );
2264 GET_META( author, "meta-author" );
2265 GET_META( artist, "meta-artist" );
2266 GET_META( genre, "meta-genre" );
2267 GET_META( copyright, "meta-copyright" );
2268 GET_META( description, "meta-description" );
2269 GET_META( date, "meta-date" );
2270 GET_META( url, "meta-url" );
2274 /*****************************************************************************
2275 * DecodeUrl: decode a given encoded url
2276 *****************************************************************************/
2277 static void DecodeUrl( char *psz )
2279 char *dup = strdup( psz );
2297 *psz++ = strtol( val, NULL, 16 );
2299 else if( *p == '+' )
2309 if( psz ) *psz++ ='\0';
2310 if( dup ) free( dup );
2313 /*****************************************************************************
2314 * MRLSplit: parse the access, demux and url part of the
2315 * Media Resource Locator.
2316 *****************************************************************************/
2317 void MRLSplit( vlc_object_t *p_input, char *psz_dup,
2318 char **ppsz_access, char **ppsz_demux, char **ppsz_path )
2320 char *psz_access = NULL;
2321 char *psz_demux = NULL;
2322 char *psz_path = NULL;
2323 char *psz, *psz_check;
2325 psz = strchr( psz_dup, ':' );
2327 /* '@' not allowed in access/demux part */
2328 psz_check = strchr( psz_dup, '@' );
2329 if( psz_check && psz_check < psz ) psz = 0;
2331 #if defined( WIN32 ) || defined( UNDER_CE )
2332 if( psz - psz_dup == 1 )
2334 msg_Dbg( p_input, "drive letter %c: found in source", *psz_dup );
2343 if( psz[0] == '/' && psz[1] == '/' ) psz += 2;
2347 psz = strchr( psz_dup, '/' );
2354 psz_access = psz_dup;
2361 if( !psz_access ) *ppsz_access = "";
2362 else *ppsz_access = psz_access;
2364 if( !psz_demux ) *ppsz_demux = "";
2365 else *ppsz_demux = psz_demux;
2367 if( !psz_path ) *ppsz_path = "";
2368 else *ppsz_path = psz_path;
2371 /*****************************************************************************
2372 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
2375 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
2376 *****************************************************************************/
2377 static void MRLSections( input_thread_t *p_input, char *psz_source,
2378 int *pi_title_start, int *pi_title_end,
2379 int *pi_chapter_start, int *pi_chapter_end )
2381 char *psz, *psz_end, *psz_next, *psz_check;
2383 *pi_title_start = *pi_title_end = -1;
2384 *pi_chapter_start = *pi_chapter_end = -1;
2386 /* Start by parsing titles and chapters */
2387 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
2389 /* Check we are really dealing with a title/chapter section */
2390 psz_check = psz + 1;
2391 if( !*psz_check ) return;
2392 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2393 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
2394 if( *psz_check == ':' && ++psz_check )
2395 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2396 if( *psz_check != '-' && *psz_check ) return;
2397 if( *psz_check == '-' && ++psz_check )
2398 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2399 if( *psz_check != ':' && *psz_check ) return;
2400 if( *psz_check == ':' && ++psz_check )
2401 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2402 if( *psz_check ) return;
2404 /* Separate start and end */
2406 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
2408 /* Look for the start title */
2409 *pi_title_start = strtol( psz, &psz_next, 0 );
2410 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
2411 *pi_title_end = *pi_title_start;
2414 /* Look for the start chapter */
2416 *pi_chapter_start = strtol( psz, &psz_next, 0 );
2417 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
2418 *pi_chapter_end = *pi_chapter_start;
2422 /* Look for the end title */
2423 *pi_title_end = strtol( psz_end, &psz_next, 0 );
2424 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
2427 /* Look for the end chapter */
2428 if( *psz_end ) psz_end++;
2429 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
2430 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
2433 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
2434 psz_source, *pi_title_start, *pi_chapter_start,
2435 *pi_title_end, *pi_chapter_end );
2438 /*****************************************************************************
2439 * input_AddSubtitles: add a subtitles file and enable it
2440 *****************************************************************************/
2441 vlc_bool_t input_AddSubtitles( input_thread_t *p_input, char *psz_subtitle,
2442 vlc_bool_t b_check_extension )
2444 input_source_t *sub;
2447 char *psz_path, *psz_extension;
2449 if( b_check_extension && !subtitles_Filter( psz_subtitle ) )
2454 /* if we are provided a subtitle.sub file,
2455 * see if we don't have a subtitle.idx and use it instead */
2456 psz_path = strdup( psz_subtitle );
2459 psz_extension = strrchr( psz_path, '.');
2460 if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
2464 strcpy( psz_extension, ".idx" );
2465 /* FIXME: a portable wrapper for stat() or access() would be more suited */
2466 if( ( f = utf8_fopen( psz_path, "rt" ) ) )
2469 msg_Dbg( p_input, "using %s subtitles file instead of %s",
2470 psz_path, psz_subtitle );
2471 strcpy( psz_subtitle, psz_path );
2477 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
2479 sub = InputSourceNew( p_input );
2480 if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle", VLC_FALSE ) )
2482 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
2485 if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
2487 if( count.i_int == 0 )
2489 /* if it was first one, there is disable too */
2491 if( count.i_int < list.p_list->i_count )
2493 input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
2494 &list.p_list->p_values[count.i_int] );
2496 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );