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 *****************************************************************************/
33 #include "input_internal.h"
36 #include "../stream_output/stream_output.h"
38 #include <vlc_playlist.h>
39 #include <vlc_interface.h>
41 #include <vlc_demux.h>
42 #include <vlc_charset.h>
44 #ifdef HAVE_SYS_STAT_H
45 # include <sys/stat.h>
48 /*****************************************************************************
50 *****************************************************************************/
51 static int Run ( input_thread_t *p_input );
52 static int RunAndDestroy ( input_thread_t *p_input );
54 static input_thread_t * Create ( vlc_object_t *, input_item_t *,
55 const char *, vlc_bool_t );
56 static int Init ( input_thread_t *p_input );
57 static void Error ( input_thread_t *p_input );
58 static void End ( input_thread_t *p_input );
59 static void MainLoop( input_thread_t *p_input );
61 static inline int ControlPopNoLock( input_thread_t *, int *, vlc_value_t * );
62 static void ControlReduce( input_thread_t * );
63 static vlc_bool_t Control( input_thread_t *, int, vlc_value_t );
65 static int UpdateFromAccess( input_thread_t * );
66 static int UpdateFromDemux( input_thread_t * );
67 static int UpdateMeta( input_thread_t * );
69 static void UpdateItemLength( input_thread_t *, int64_t i_length );
71 static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
73 static input_source_t *InputSourceNew( input_thread_t *);
74 static int InputSourceInit( input_thread_t *, input_source_t *,
75 const char *, const char *psz_forced_demux );
76 static void InputSourceClean( input_thread_t *, input_source_t * );
78 static void SlaveDemux( input_thread_t *p_input );
79 static void SlaveSeek( input_thread_t *p_input );
81 static void InputMetaUser( input_thread_t *p_input );
83 /*****************************************************************************
84 * This function creates a new input, and returns a pointer
85 * to its description. On error, it returns NULL.
87 * Variables for _public_ use:
90 * - rate,rate-slower, rate-faster
91 * - position, position-offset
93 * - title,title-next,title-prev
94 * - chapter,chapter-next, chapter-prev
95 * - program, audio-es, video-es, spu-es
96 * - audio-delay, spu-delay
101 * - seekable (if you can seek, it doesn't say if 'bar display' has be shown or not, for that check position != 0.0)
102 * * For intf callback upon changes
104 * TODO explain when Callback is called
105 * TODO complete this list (?)
106 *****************************************************************************/
107 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
108 const char *psz_header, vlc_bool_t b_quick )
110 input_thread_t *p_input = NULL; /* thread descriptor */
114 /* Allocate descriptor */
115 p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
116 if( p_input == NULL )
118 msg_Err( p_parent, "out of memory" );
121 MALLOC_NULL( p_input->p, input_thread_private_t );
123 /* One "randomly" selected input thread is responsible for computing
124 * the global stats. Check if there is already someone doing this */
125 if( p_input->p_libvlc->p_playlist->p_stats && !b_quick )
127 vlc_mutex_lock( &p_input->p_libvlc->p_playlist->p_stats->lock );
128 if( p_input->p_libvlc->p_playlist->p_stats_computer == NULL )
130 p_input->p_libvlc->p_playlist->p_stats_computer = p_input;
132 vlc_mutex_unlock( &p_input->p_libvlc->p_playlist->p_stats->lock );
135 p_input->b_preparsing = b_quick;
136 p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
138 /* Init Common fields */
139 p_input->b_eof = VLC_FALSE;
140 p_input->b_can_pace_control = VLC_TRUE;
141 p_input->p->i_start = 0;
143 p_input->p->i_stop = 0;
144 p_input->p->i_title = 0;
145 p_input->p->title = NULL;
146 p_input->p->i_title_offset = p_input->p->i_seekpoint_offset = 0;
147 p_input->i_state = INIT_S;
148 p_input->p->i_rate = INPUT_RATE_DEFAULT;
149 p_input->p->i_bookmark = 0;
150 p_input->p->bookmark = NULL;
151 p_input->p->p_meta = NULL;
152 p_input->p->p_es_out = NULL;
153 p_input->p->p_sout = NULL;
154 p_input->p->b_out_pace_control = VLC_FALSE;
155 p_input->i_pts_delay = 0;
157 /* Init Input fields */
158 p_input->p->input.p_item = p_item;
159 p_input->p->input.p_access = NULL;
160 p_input->p->input.p_stream = NULL;
161 p_input->p->input.p_demux = NULL;
162 p_input->p->input.b_title_demux = VLC_FALSE;
163 p_input->p->input.i_title = 0;
164 p_input->p->input.title = NULL;
165 p_input->p->input.i_title_offset = p_input->p->input.i_seekpoint_offset = 0;
166 p_input->p->input.b_can_pace_control = VLC_TRUE;
167 p_input->p->input.b_eof = VLC_FALSE;
168 p_input->p->input.i_cr_average = 0;
170 if( !p_input->p->input.p_item->p_meta )
171 p_input->p->input.p_item->p_meta = vlc_meta_New();
173 if( !p_item->p_stats )
175 p_item->p_stats = (input_stats_t*)malloc( sizeof( input_stats_t ) );
176 vlc_mutex_init( p_input, &p_item->p_stats->lock );
177 stats_ReinitInputStats( p_item->p_stats );
181 p_input->p->i_slave = 0;
182 p_input->p->slave = NULL;
184 /* Init control buffer */
185 vlc_mutex_init( p_input, &p_input->p->lock_control );
186 p_input->p->i_control = 0;
188 /* Parse input options */
189 vlc_mutex_lock( &p_item->lock );
190 for( i = 0; i < p_item->i_options; i++ )
192 var_OptionParse( p_input, p_item->ppsz_options[i] );
194 vlc_mutex_unlock( &p_item->lock );
196 /* Create Object Variables for private use only */
197 input_ConfigVarInit( p_input );
199 /* Create Objects variables for public Get and Set */
200 input_ControlVarInit( p_input );
202 p_input->p->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
204 if( !p_input->b_preparsing )
206 var_Get( p_input, "bookmarks", &val );
209 /* FIXME: have a common cfg parsing routine used by sout and others */
210 char *psz_parser, *psz_start, *psz_end;
211 psz_parser = val.psz_string;
212 while( (psz_start = strchr( psz_parser, '{' ) ) )
214 seekpoint_t *p_seekpoint = vlc_seekpoint_New();
217 psz_end = strchr( psz_start, '}' );
218 if( !psz_end ) break;
219 psz_parser = psz_end + 1;
220 backup = *psz_parser;
223 while( (psz_end = strchr( psz_start, ',' ) ) )
226 if( !strncmp( psz_start, "name=", 5 ) )
228 p_seekpoint->psz_name = psz_start + 5;
230 else if( !strncmp( psz_start, "bytes=", 6 ) )
232 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
234 else if( !strncmp( psz_start, "time=", 5 ) )
236 p_seekpoint->i_time_offset = atoll(psz_start + 5) *
239 psz_start = psz_end + 1;
241 msg_Dbg( p_input, "adding bookmark: %s, bytes="I64Fd", time="I64Fd,
242 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
243 p_seekpoint->i_time_offset );
244 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
245 vlc_seekpoint_Delete( p_seekpoint );
246 *psz_parser = backup;
248 free( val.psz_string );
252 /* Remove 'Now playing' info as it is probably outdated */
253 input_Control( p_input, INPUT_DEL_INFO, _(VLC_META_INFO_CAT),
254 VLC_META_NOW_PLAYING ); /* ? Don't translate as it might has been copied ? */
257 if( p_input->b_preparsing )
258 p_input->i_flags |= OBJECT_FLAGS_QUIET | OBJECT_FLAGS_NOINTERACT;
260 /* Attach only once we are ready */
261 vlc_object_attach( p_input, p_parent );
266 static void Destroy( input_thread_t *p_input )
268 vlc_object_detach( p_input );
270 vlc_mutex_destroy( &p_input->p->lock_control );
273 vlc_object_destroy( p_input );
276 * Initialize an input thread and run it. You will need to monitor the
277 * thread to clean up after it is done
279 * \param p_parent a vlc_object
280 * \param p_item an input item
281 * \return a pointer to the spawned input thread
283 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
284 input_item_t *p_item )
286 return __input_CreateThread2( p_parent, p_item, NULL );
290 input_thread_t *__input_CreateThread2( vlc_object_t *p_parent,
291 input_item_t *p_item,
292 const char *psz_header )
294 input_thread_t *p_input = NULL; /* thread descriptor */
296 p_input = Create( p_parent, p_item, psz_header, VLC_FALSE );
300 /* Create thread and wait for its readiness. */
301 if( vlc_thread_create( p_input, "input", Run,
302 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
304 input_ChangeState( p_input, ERROR_S );
305 msg_Err( p_input, "cannot create input thread" );
314 * Initialize an input thread and run it. This thread will clean after himself,
315 * you can forget about it. It can work either in blocking or non-blocking mode
317 * \param p_parent a vlc_object
318 * \param p_item an input item
319 * \param b_block should we block until read is finished ?
320 * \return the input object id if non blocking, an error code else
322 int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
325 input_thread_t *p_input = NULL; /* thread descriptor */
327 p_input = Create( p_parent, p_item, NULL, VLC_FALSE );
333 RunAndDestroy( p_input );
338 if( vlc_thread_create( p_input, "input", RunAndDestroy,
339 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
341 input_ChangeState( p_input, ERROR_S );
342 msg_Err( p_input, "cannot create input thread" );
347 return p_input->i_object_id;
351 * Initialize an input and initialize it to preparse the item
352 * This function is blocking. It will only accept to parse files
354 * \param p_parent a vlc_object_t
355 * \param p_item an input item
356 * \return VLC_SUCCESS or an error
358 int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
360 input_thread_t *p_input = NULL; /* thread descriptor */
362 /* Allocate descriptor */
363 p_input = Create( p_parent, p_item, NULL, VLC_TRUE );
376 * Request a running input thread to stop and die
378 * \param the input thread to stop
380 void input_StopThread( input_thread_t *p_input )
385 /* Set die for input */
386 p_input->b_die = VLC_TRUE;
388 /* We cannot touch p_input fields directly (we come from another thread),
389 * so use the vlc_object_find way, it's perfectly safe */
391 /* Set die for all access */
392 p_list = vlc_list_find( p_input, VLC_OBJECT_ACCESS, FIND_CHILD );
393 for( i = 0; i < p_list->i_count; i++ )
395 p_list->p_values[i].p_object->b_die = VLC_TRUE;
397 vlc_list_release( p_list );
399 /* Set die for all stream */
400 p_list = vlc_list_find( p_input, VLC_OBJECT_STREAM, FIND_CHILD );
401 for( i = 0; i < p_list->i_count; i++ )
403 p_list->p_values[i].p_object->b_die = VLC_TRUE;
405 vlc_list_release( p_list );
407 /* Set die for all demux */
408 p_list = vlc_list_find( p_input, VLC_OBJECT_DEMUX, FIND_CHILD );
409 for( i = 0; i < p_list->i_count; i++ )
411 p_list->p_values[i].p_object->b_die = VLC_TRUE;
413 vlc_list_release( p_list );
415 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
419 * Clean up a dead input thread
420 * This function does not return until the thread is effectively cancelled.
422 * \param the input thread to kill
424 void input_DestroyThread( input_thread_t *p_input )
426 /* Join the thread */
427 vlc_thread_join( p_input );
433 /*****************************************************************************
434 * Run: main thread loop
435 * This is the "normal" thread that spawns the input processing chain,
436 * reads the stream, cleans up and waits
437 *****************************************************************************/
438 static int Run( input_thread_t *p_input )
440 /* Signal that the thread is launched */
441 vlc_thread_ready( p_input );
443 if( Init( p_input ) )
445 /* If we failed, wait before we are killed, and exit */
446 p_input->b_error = VLC_TRUE;
447 playlist_Signal( pl_Get( p_input ) );
451 /* Tell we're dead */
452 p_input->b_dead = VLC_TRUE;
459 if( !p_input->b_eof && !p_input->b_error && p_input->p->input.b_eof )
461 /* We have finish to demux data but not to play them */
462 while( !p_input->b_die )
464 if( input_EsOutDecodersEmpty( p_input->p->p_es_out ) )
467 msg_Dbg( p_input, "waiting decoder fifos to empty" );
469 msleep( INPUT_IDLE_SLEEP );
472 /* We have finished */
473 p_input->b_eof = VLC_TRUE;
474 playlist_Signal( pl_Get( p_input ) );
477 /* Wait until we are asked to die */
478 if( !p_input->b_die )
489 /*****************************************************************************
490 * RunAndDestroy: main thread loop
491 * This is the "just forget me" thread that spawns the input processing chain,
492 * reads the stream, cleans up and releases memory
493 *****************************************************************************/
494 static int RunAndDestroy( input_thread_t *p_input )
496 /* Signal that the thread is launched */
497 vlc_thread_ready( p_input );
499 if( Init( p_input ) )
504 if( !p_input->b_eof && !p_input->b_error && p_input->p->input.b_eof )
506 /* We have finished demuxing data but not playing it */
507 while( !p_input->b_die )
509 if( input_EsOutDecodersEmpty( p_input->p->p_es_out ) )
512 msg_Dbg( p_input, "waiting decoder fifos to empty" );
514 msleep( INPUT_IDLE_SLEEP );
517 /* We have finished */
518 p_input->b_eof = VLC_TRUE;
530 /*****************************************************************************
531 * Main loop: Fill buffers from access, and demux
532 *****************************************************************************/
533 static void MainLoop( input_thread_t *p_input )
535 int64_t i_intf_update = 0;
537 while( !p_input->b_die && !p_input->b_error && !p_input->p->input.b_eof )
539 vlc_bool_t b_force_update = VLC_FALSE;
545 if( p_input->i_state != PAUSE_S )
547 if( p_input->p->i_stop <= 0 || p_input->i_time < p_input->p->i_stop )
548 i_ret=p_input->p->input.p_demux->pf_demux(p_input->p->input.p_demux);
555 if( p_input->p->input.b_title_demux &&
556 p_input->p->input.p_demux->info.i_update )
558 i_ret = UpdateFromDemux( p_input );
559 b_force_update = VLC_TRUE;
561 else if( !p_input->p->input.b_title_demux &&
562 p_input->p->input.p_access &&
563 p_input->p->input.p_access->info.i_update )
565 i_ret = UpdateFromAccess( p_input );
566 b_force_update = VLC_TRUE;
570 if( i_ret == 0 ) /* EOF */
574 var_Get( p_input, "input-repeat", &repeat );
575 if( repeat.i_int == 0 )
577 /* End of file - we do not set b_die because only the
578 * playlist is allowed to do so. */
579 input_ChangeState( p_input, END_S );
580 msg_Dbg( p_input, "EOF reached" );
581 p_input->p->input.b_eof = VLC_TRUE;
585 msg_Dbg( p_input, "repeating the same input (%d)",
587 if( repeat.i_int > 0 )
590 var_Set( p_input, "input-repeat", repeat );
593 /* Seek to start title/seekpoint */
594 val.i_int = p_input->p->input.i_title_start -
595 p_input->p->input.i_title_offset;
596 if( val.i_int < 0 || val.i_int >= p_input->p->input.i_title )
598 input_ControlPush( p_input,
599 INPUT_CONTROL_SET_TITLE, &val );
601 val.i_int = p_input->p->input.i_seekpoint_start -
602 p_input->p->input.i_seekpoint_offset;
603 if( val.i_int > 0 /* TODO: check upper boundary */ )
604 input_ControlPush( p_input,
605 INPUT_CONTROL_SET_SEEKPOINT, &val );
607 /* Seek to start position */
608 if( p_input->p->i_start > 0 )
610 val.i_time = p_input->p->i_start;
611 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
617 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
624 p_input->b_error = VLC_TRUE;
627 if( i_ret > 0 && p_input->p->i_slave > 0 )
629 SlaveDemux( p_input );
639 vlc_mutex_lock( &p_input->p->lock_control );
640 ControlReduce( p_input );
641 while( !ControlPopNoLock( p_input, &i_type, &val ) )
643 msg_Dbg( p_input, "control type=%d", i_type );
644 if( Control( p_input, i_type, val ) )
645 b_force_update = VLC_TRUE;
647 vlc_mutex_unlock( &p_input->p->lock_control );
649 if( b_force_update || i_intf_update < mdate() )
653 int64_t i_time, i_length;
654 /* update input status variables */
655 if( !demux2_Control( p_input->p->input.p_demux,
656 DEMUX_GET_POSITION, &f_pos ) )
658 val.f_float = (float)f_pos;
659 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
661 if( !demux2_Control( p_input->p->input.p_demux,
662 DEMUX_GET_TIME, &i_time ) )
664 p_input->i_time = i_time;
666 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
668 if( !demux2_Control( p_input->p->input.p_demux,
669 DEMUX_GET_LENGTH, &i_length ) )
672 var_Get( p_input, "length", &old_val );
673 val.i_time = i_length;
674 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
676 if( old_val.i_time != val.i_time )
678 UpdateItemLength( p_input, i_length );
682 var_SetBool( p_input, "intf-change", VLC_TRUE );
683 i_intf_update = mdate() + I64C(150000);
685 /* 150ms * 8 = ~ 1 second */
686 if( ++i_updates % 8 == 0 )
688 stats_ComputeInputStats( p_input, p_input->p->input.p_item->p_stats );
689 /* Are we the thread responsible for computing global stats ? */
690 if( p_input->p_libvlc->p_playlist->p_stats_computer == p_input )
692 stats_ComputeGlobalStats( p_input->p_libvlc->p_playlist,
693 p_input->p_libvlc->p_playlist->p_stats );
699 static int Init( input_thread_t * p_input )
709 /* Initialize optional stream output. (before access/demuxer)
710 * XXX: we add a special case if the uri starts by vlc.
711 * else 'vlc in.file --sout "" vlc:quit' cannot work (the output will
712 * be destroyed in case of a file).
713 * (this will break playing of file starting by 'vlc:' but I don't
714 * want to add more logic, just force file by file:// or code it ;)
716 memset( &p_input->p->counters, 0, sizeof( p_input->p->counters ) );
717 vlc_mutex_init( p_input, &p_input->p->counters.counters_lock );
719 if( !p_input->b_preparsing )
721 /* Prepare statistics */
722 #define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \
723 stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
724 if( p_input->p_libvlc->b_stats )
726 INIT_COUNTER( read_bytes, INTEGER, COUNTER );
727 INIT_COUNTER( read_packets, INTEGER, COUNTER );
728 INIT_COUNTER( demux_read, INTEGER, COUNTER );
729 INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE );
730 INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE );
731 INIT_COUNTER( played_abuffers, INTEGER, COUNTER );
732 INIT_COUNTER( lost_abuffers, INTEGER, COUNTER );
733 INIT_COUNTER( displayed_pictures, INTEGER, COUNTER );
734 INIT_COUNTER( lost_pictures, INTEGER, COUNTER );
735 INIT_COUNTER( decoded_audio, INTEGER, COUNTER );
736 INIT_COUNTER( decoded_video, INTEGER, COUNTER );
737 INIT_COUNTER( decoded_sub, INTEGER, COUNTER );
738 p_input->p->counters.p_sout_send_bitrate = NULL;
739 p_input->p->counters.p_sout_sent_packets = NULL;
740 p_input->p->counters.p_sout_sent_bytes = NULL;
741 if( p_input->p->counters.p_demux_bitrate )
742 p_input->p->counters.p_demux_bitrate->update_interval = 1000000;
743 if( p_input->p->counters.p_input_bitrate )
744 p_input->p->counters.p_input_bitrate->update_interval = 1000000;
748 psz = var_GetString( p_input, "sout" );
749 if( *psz && strncasecmp( p_input->p->input.p_item->psz_uri, "vlc:", 4 ) )
751 p_input->p->p_sout = sout_NewInstance( p_input, psz );
752 if( p_input->p->p_sout == NULL )
754 input_ChangeState( p_input, ERROR_S );
755 msg_Err( p_input, "cannot start stream output instance, " \
760 if( p_input->p_libvlc->b_stats )
762 INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
763 INIT_COUNTER (sout_sent_bytes, INTEGER, COUNTER );
764 INIT_COUNTER( sout_send_bitrate, FLOAT, DERIVATIVE );
765 if( p_input->p->counters.p_sout_send_bitrate )
766 p_input->p->counters.p_sout_send_bitrate->update_interval =
774 p_input->p->p_es_out = input_EsOutNew( p_input );
775 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
776 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
778 var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
779 var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
781 if( InputSourceInit( p_input, &p_input->p->input,
782 p_input->p->input.p_item->psz_uri, NULL ) )
787 /* Create global title (from master) */
788 if( !p_input->b_preparsing )
790 p_input->p->i_title = p_input->p->input.i_title;
791 p_input->p->title = p_input->p->input.title;
792 p_input->p->i_title_offset = p_input->p->input.i_title_offset;
793 p_input->p->i_seekpoint_offset = p_input->p->input.i_seekpoint_offset;
794 if( p_input->p->i_title > 0 )
796 /* Setup variables */
797 input_ControlVarNavigation( p_input );
798 input_ControlVarTitle( p_input, 0 );
802 p_input->b_can_pace_control = p_input->p->input.b_can_pace_control;
803 p_input->p->b_can_pause = p_input->p->input.b_can_pause;
806 if( p_input->i_pts_delay < 0 )
807 p_input->i_pts_delay = 0;
809 /* If the desynchronisation requested by the user is < 0, we need to
810 * cache more data. */
811 var_Get( p_input, "audio-desync", &val );
812 if( val.i_int < 0 ) p_input->i_pts_delay -= (val.i_int * 1000);
814 /* Update cr_average depending on the caching */
815 p_input->p->input.i_cr_average *= (10 * p_input->i_pts_delay / 200000);
816 p_input->p->input.i_cr_average /= 10;
817 if( p_input->p->input.i_cr_average < 10 ) p_input->p->input.i_cr_average = 10;
820 /* Load master infos */
822 if( !demux2_Control( p_input->p->input.p_demux, DEMUX_GET_LENGTH,
823 &val.i_time ) && val.i_time > 0 )
825 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
826 UpdateItemLength( p_input, val.i_time );
827 p_input->p->input.p_item->i_duration = val.i_time;
830 /* Start title/chapter */
831 if( !p_input->b_preparsing )
833 val.i_int = p_input->p->input.i_title_start -
834 p_input->p->input.i_title_offset;
835 if( val.i_int > 0 && val.i_int < p_input->p->input.i_title )
836 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
837 val.i_int = p_input->p->input.i_seekpoint_start -
838 p_input->p->input.i_seekpoint_offset;
839 if( val.i_int > 0 /* TODO: check upper boundary */ )
840 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
844 p_input->p->i_start = (int64_t)var_GetInteger( p_input, "start-time" ) *
846 p_input->p->i_stop = (int64_t)var_GetInteger( p_input, "stop-time" ) *
849 if( p_input->p->i_start > 0 )
851 if( p_input->p->i_start >= val.i_time )
853 msg_Warn( p_input, "invalid start-time ignored" );
859 msg_Dbg( p_input, "starting at time: %ds",
860 (int)( p_input->p->i_start / I64C(1000000) ) );
862 s.i_time = p_input->p->i_start;
863 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
866 if( p_input->p->i_stop > 0 && p_input->p->i_stop <= p_input->p->i_start )
868 msg_Warn( p_input, "invalid stop-time ignored" );
869 p_input->p->i_stop = 0;
873 /* Get fps and set it if not already set */
874 if( !demux2_Control( p_input->p->input.p_demux, DEMUX_GET_FPS, &f_fps ) &&
877 float f_requested_fps;
879 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
880 var_SetFloat( p_input, "sub-original-fps", f_fps );
882 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
883 if( f_requested_fps != f_fps )
885 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
887 var_SetFloat( p_input, "sub-fps", f_requested_fps );
891 i_delay = var_CreateGetInteger( p_input, "sub-delay" );
894 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
897 /* Look for and add subtitle files */
898 psz_subtitle = var_GetString( p_input, "sub-file" );
901 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
902 input_AddSubtitles( p_input, psz_subtitle, VLC_FALSE );
905 var_Get( p_input, "sub-autodetect-file", &val );
908 char *psz_autopath = var_GetString( p_input, "sub-autodetect-path" );
909 char **subs = subtitles_Detect( p_input, psz_autopath,
910 p_input->p->input.p_item->psz_uri );
914 /* Try to autoselect the first autodetected subtitles file
915 * if no subtitles file was specified */
916 if( *psz_subtitle == 0 && subs && subs[0] )
918 input_AddSubtitles( p_input, subs[0], VLC_FALSE );
923 /* Then, just add the following subtitles files */
924 for( ; subs && subs[i]; i++ )
926 if( strcmp( psz_subtitle, subs[i] ) )
928 sub = InputSourceNew( p_input );
929 if( !InputSourceInit( p_input, sub, subs[i], "subtitle" ) )
931 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
937 if( subs ) free( subs );
938 if( psz_autopath ) free( psz_autopath );
940 free( psz_subtitle );
943 psz = var_GetString( p_input, "input-slave" );
947 input_source_t *slave;
950 while( *psz == ' ' || *psz == '#' )
954 if( ( psz_delim = strchr( psz, '#' ) ) )
963 msg_Dbg( p_input, "adding slave input '%s'", psz );
964 slave = InputSourceNew( p_input );
965 if( !InputSourceInit( p_input, slave, psz, NULL ) )
967 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, slave );
973 if( psz ) free( psz );
977 p_input->p->i_start = 0;
978 p_input->p->i_start = 0;
982 if( !p_input->b_preparsing )
984 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
985 i_es_out_mode = ES_OUT_MODE_AUTO;
987 if( p_input->p->p_sout )
989 var_Get( p_input, "sout-all", &val );
992 i_es_out_mode = ES_OUT_MODE_ALL;
997 var_Get( p_input, "programs", &val );
998 if ( val.p_list && val.p_list->i_count )
1000 i_es_out_mode = ES_OUT_MODE_PARTIAL;
1001 /* Note : we should remove the "program" callback. */
1004 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
1008 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
1010 /* Inform the demuxer about waited group (needed only for DVB) */
1011 if( i_es_out_mode == ES_OUT_MODE_ALL )
1013 demux2_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
1015 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
1017 demux2_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1,
1022 demux2_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP,
1023 (int) var_GetInteger( p_input, "program" ), NULL );
1026 if( p_input->p->p_sout )
1028 if( p_input->p->p_sout->i_out_pace_nocontrol > 0 )
1030 p_input->p->b_out_pace_control = VLC_FALSE;
1034 p_input->p->b_out_pace_control = VLC_TRUE;
1037 if( p_input->b_can_pace_control && p_input->p->b_out_pace_control )
1039 /* We don't want a high input priority here or we'll
1040 * end-up sucking up all the CPU time */
1041 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
1044 msg_Dbg( p_input, "starting in %s mode",
1045 p_input->p->b_out_pace_control ? "async" : "sync" );
1049 p_meta = p_input->p->input.p_item->p_meta;
1050 /* Get meta data from users */
1051 InputMetaUser( p_input );
1052 /* Get meta data from master input */
1053 demux2_Control( p_input->p->input.p_demux, DEMUX_GET_META, p_meta );
1055 /* Access_file does not give any meta, and there are no slave */
1056 if( !p_input->b_preparsing )
1058 if( p_input->p->input.p_access )
1059 access2_Control( p_input->p->input.p_access, ACCESS_GET_META,
1062 /* Get meta data from slave input */
1063 for( i = 0; i < p_input->p->i_slave; i++ )
1065 demux2_Control( p_input->p->slave[i]->p_demux,
1066 DEMUX_GET_META, p_meta );
1067 if( p_input->p->slave[i]->p_access )
1069 access2_Control( p_input->p->slave[i]->p_access,
1070 ACCESS_GET_META, p_meta );
1075 UpdateMeta( p_input );
1077 if( !p_input->b_preparsing )
1079 msg_Dbg( p_input, "`%s' successfully opened",
1080 p_input->p->input.p_item->psz_uri );
1084 /* initialization is complete */
1085 input_ChangeState( p_input, PLAYING_S );
1090 input_ChangeState( p_input, ERROR_S );
1092 if( p_input->p->p_es_out )
1093 input_EsOutDelete( p_input->p->p_es_out );
1095 if( p_input->p->p_sout )
1096 sout_DeleteInstance( p_input->p->p_sout );
1098 /* Mark them deleted */
1099 p_input->p->input.p_demux = NULL;
1100 p_input->p->input.p_stream = NULL;
1101 p_input->p->input.p_access = NULL;
1102 p_input->p->p_es_out = NULL;
1103 p_input->p->p_sout = NULL;
1105 return VLC_EGENERIC;
1108 /*****************************************************************************
1109 * Error: RunThread() error loop
1110 *****************************************************************************
1111 * This function is called when an error occurred during thread main's loop.
1112 *****************************************************************************/
1113 static void Error( input_thread_t *p_input )
1115 while( !p_input->b_die )
1118 input_ChangeState( p_input, ERROR_S );
1119 msleep( INPUT_IDLE_SLEEP );
1123 /*****************************************************************************
1124 * End: end the input thread
1125 *****************************************************************************/
1126 static void End( input_thread_t * p_input )
1130 /* We are at the end */
1131 input_ChangeState( p_input, END_S );
1133 /* Clean control variables */
1134 input_ControlVarClean( p_input );
1136 /* Clean up master */
1137 InputSourceClean( p_input, &p_input->p->input );
1140 for( i = 0; i < p_input->p->i_slave; i++ )
1142 InputSourceClean( p_input, p_input->p->slave[i] );
1143 free( p_input->p->slave[i] );
1145 if( p_input->p->slave ) free( p_input->p->slave );
1147 /* Unload all modules */
1148 if( p_input->p->p_es_out )
1149 input_EsOutDelete( p_input->p->p_es_out );
1151 if( !p_input->b_preparsing )
1153 #define CL_CO( c ) stats_CounterClean( p_input->p->counters.p_##c ); p_input->p->counters.p_##c = NULL;
1154 if( p_input->p_libvlc->b_stats )
1156 /* make sure we are up to date */
1157 stats_ComputeInputStats( p_input, p_input->p->input.p_item->p_stats );
1158 if( p_input->p_libvlc->p_playlist->p_stats_computer == p_input )
1160 stats_ComputeGlobalStats( p_input->p_libvlc->p_playlist,
1161 p_input->p_libvlc->p_playlist->p_stats );
1162 p_input->p_libvlc->p_playlist->p_stats_computer = NULL;
1164 CL_CO( read_bytes );
1165 CL_CO( read_packets );
1166 CL_CO( demux_read );
1167 CL_CO( input_bitrate );
1168 CL_CO( demux_bitrate );
1169 CL_CO( played_abuffers );
1170 CL_CO( lost_abuffers );
1171 CL_CO( displayed_pictures );
1172 CL_CO( lost_pictures );
1173 CL_CO( decoded_audio) ;
1174 CL_CO( decoded_video );
1175 CL_CO( decoded_sub) ;
1178 /* Close optional stream output instance */
1179 if( p_input->p->p_sout )
1183 CL_CO( sout_sent_packets );
1184 CL_CO( sout_sent_bytes );
1185 CL_CO( sout_send_bitrate );
1187 if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool )
1189 playlist_t *p_playlist = pl_Yield( p_input );
1191 /* attach sout to the playlist */
1192 vlc_object_detach( p_input->p->p_sout );
1193 vlc_object_attach( p_input->p->p_sout, p_playlist );
1194 pl_Release( p_input );
1195 msg_Dbg( p_input, "kept sout" );
1199 sout_DeleteInstance( p_input->p->p_sout );
1200 msg_Dbg( p_input, "destroyed sout" );
1206 vlc_mutex_destroy( &p_input->p->counters.counters_lock );
1208 /* Tell we're dead */
1209 p_input->b_dead = VLC_TRUE;
1212 /*****************************************************************************
1214 *****************************************************************************/
1215 static inline int ControlPopNoLock( input_thread_t *p_input,
1216 int *pi_type, vlc_value_t *p_val )
1218 if( p_input->p->i_control <= 0 )
1220 return VLC_EGENERIC;
1223 *pi_type = p_input->p->control[0].i_type;
1224 *p_val = p_input->p->control[0].val;
1226 p_input->p->i_control--;
1227 if( p_input->p->i_control > 0 )
1231 for( i = 0; i < p_input->p->i_control; i++ )
1233 p_input->p->control[i].i_type = p_input->p->control[i+1].i_type;
1234 p_input->p->control[i].val = p_input->p->control[i+1].val;
1241 static void ControlReduce( input_thread_t *p_input )
1248 for( i = 1; i < p_input->p->i_control; i++ )
1250 const int i_lt = p_input->p->control[i-1].i_type;
1251 const int i_ct = p_input->p->control[i].i_type;
1253 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1254 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->p->i_control,
1258 ( i_ct == INPUT_CONTROL_SET_STATE ||
1259 i_ct == INPUT_CONTROL_SET_RATE ||
1260 i_ct == INPUT_CONTROL_SET_POSITION ||
1261 i_ct == INPUT_CONTROL_SET_TIME ||
1262 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1263 i_ct == INPUT_CONTROL_SET_TITLE ||
1264 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1265 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1268 // msg_Dbg( p_input, "merged at %d", i );
1269 /* Remove the i-1 */
1270 for( j = i; j < p_input->p->i_control; j++ )
1271 p_input->p->control[j-1] = p_input->p->control[j];
1272 p_input->p->i_control--;
1276 /* TODO but that's not that important
1277 - merge SET_X with SET_X_CMD
1278 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1279 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1286 static vlc_bool_t Control( input_thread_t *p_input, int i_type,
1289 vlc_bool_t b_force_update = VLC_FALSE;
1291 if( !p_input ) return b_force_update;
1295 case INPUT_CONTROL_SET_DIE:
1296 msg_Dbg( p_input, "control: stopping input" );
1297 /* Mark all submodules to die */
1298 if( p_input->p->input.p_access )
1299 p_input->p->input.p_access->b_die = VLC_TRUE;
1300 if( p_input->p->input.p_stream )
1301 p_input->p->input.p_stream->b_die = VLC_TRUE;
1302 p_input->p->input.p_demux->b_die = VLC_TRUE;
1304 p_input->b_die = VLC_TRUE;
1307 case INPUT_CONTROL_SET_POSITION:
1308 case INPUT_CONTROL_SET_POSITION_OFFSET:
1311 if( i_type == INPUT_CONTROL_SET_POSITION )
1313 f_pos = val.f_float;
1317 /* Should not fail */
1318 demux2_Control( p_input->p->input.p_demux,
1319 DEMUX_GET_POSITION, &f_pos );
1320 f_pos += val.f_float;
1322 if( f_pos < 0.0 ) f_pos = 0.0;
1323 if( f_pos > 1.0 ) f_pos = 1.0;
1324 /* Reset the decoders states and clock sync (before calling the demuxer */
1325 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1326 input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_FALSE );
1327 if( demux2_Control( p_input->p->input.p_demux, DEMUX_SET_POSITION,
1330 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1331 "%2.1f%% failed", f_pos * 100 );
1335 if( p_input->p->i_slave > 0 )
1336 SlaveSeek( p_input );
1338 b_force_update = VLC_TRUE;
1343 case INPUT_CONTROL_SET_TIME:
1344 case INPUT_CONTROL_SET_TIME_OFFSET:
1349 if( i_type == INPUT_CONTROL_SET_TIME )
1351 i_time = val.i_time;
1355 /* Should not fail */
1356 demux2_Control( p_input->p->input.p_demux,
1357 DEMUX_GET_TIME, &i_time );
1358 i_time += val.i_time;
1360 if( i_time < 0 ) i_time = 0;
1362 /* Reset the decoders states and clock sync (before calling the demuxer */
1363 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1364 input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_FALSE );
1366 i_ret = demux2_Control( p_input->p->input.p_demux,
1367 DEMUX_SET_TIME, i_time );
1372 /* Emulate it with a SET_POS */
1373 demux2_Control( p_input->p->input.p_demux,
1374 DEMUX_GET_LENGTH, &i_length );
1377 double f_pos = (double)i_time / (double)i_length;
1378 i_ret = demux2_Control( p_input->p->input.p_demux,
1379 DEMUX_SET_POSITION, f_pos );
1384 msg_Warn( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) "I64Fd
1385 " failed or not possible", i_time );
1389 if( p_input->p->i_slave > 0 )
1390 SlaveSeek( p_input );
1392 b_force_update = VLC_TRUE;
1397 case INPUT_CONTROL_SET_STATE:
1398 if( ( val.i_int == PLAYING_S && p_input->i_state == PAUSE_S ) ||
1399 ( val.i_int == PAUSE_S && p_input->i_state == PAUSE_S ) )
1402 if( p_input->p->input.p_access )
1403 i_ret = access2_Control( p_input->p->input.p_access,
1404 ACCESS_SET_PAUSE_STATE, VLC_FALSE );
1406 i_ret = demux2_Control( p_input->p->input.p_demux,
1407 DEMUX_SET_PAUSE_STATE, VLC_FALSE );
1411 /* FIXME What to do ? */
1412 msg_Warn( p_input, "cannot unset pause -> EOF" );
1413 vlc_mutex_unlock( &p_input->p->lock_control );
1414 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1415 vlc_mutex_lock( &p_input->p->lock_control );
1418 b_force_update = VLC_TRUE;
1420 /* Switch to play */
1421 p_input->i_state = PLAYING_S;
1422 val.i_int = PLAYING_S;
1423 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1426 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1427 input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_FALSE );
1429 else if( val.i_int == PAUSE_S && p_input->i_state == PLAYING_S &&
1430 p_input->p->b_can_pause )
1433 if( p_input->p->input.p_access )
1434 i_ret = access2_Control( p_input->p->input.p_access,
1435 ACCESS_SET_PAUSE_STATE, VLC_TRUE );
1437 i_ret = demux2_Control( p_input->p->input.p_demux,
1438 DEMUX_SET_PAUSE_STATE, VLC_TRUE );
1440 b_force_update = VLC_TRUE;
1444 msg_Warn( p_input, "cannot set pause state" );
1445 val.i_int = p_input->i_state;
1449 val.i_int = PAUSE_S;
1452 /* Switch to new state */
1453 p_input->i_state = val.i_int;
1454 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1456 else if( val.i_int == PAUSE_S && !p_input->p->b_can_pause )
1458 b_force_update = VLC_TRUE;
1460 /* Correct "state" value */
1461 val.i_int = p_input->i_state;
1462 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1464 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1466 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1470 case INPUT_CONTROL_SET_RATE:
1471 case INPUT_CONTROL_SET_RATE_SLOWER:
1472 case INPUT_CONTROL_SET_RATE_FASTER:
1476 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1477 i_rate = p_input->p->i_rate * 2;
1478 else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
1479 i_rate = p_input->p->i_rate / 2;
1483 if( i_rate < INPUT_RATE_MIN )
1485 msg_Dbg( p_input, "cannot set rate faster" );
1486 i_rate = INPUT_RATE_MIN;
1488 else if( i_rate > INPUT_RATE_MAX )
1490 msg_Dbg( p_input, "cannot set rate slower" );
1491 i_rate = INPUT_RATE_MAX;
1493 if( i_rate != INPUT_RATE_DEFAULT &&
1494 ( !p_input->b_can_pace_control ||
1495 ( p_input->p->p_sout && !p_input->p->b_out_pace_control ) ) )
1497 msg_Dbg( p_input, "cannot change rate" );
1498 i_rate = INPUT_RATE_DEFAULT;
1500 if( i_rate != p_input->p->i_rate )
1502 p_input->p->i_rate = i_rate;
1504 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
1506 /* We haven't send data to decoder when rate != default */
1507 if( i_rate == INPUT_RATE_DEFAULT )
1508 input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_TRUE );
1511 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1513 b_force_update = VLC_TRUE;
1518 case INPUT_CONTROL_SET_PROGRAM:
1519 /* No need to force update, es_out does it if needed */
1520 es_out_Control( p_input->p->p_es_out,
1521 ES_OUT_SET_GROUP, val.i_int );
1523 demux2_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1527 case INPUT_CONTROL_SET_ES:
1528 /* No need to force update, es_out does it if needed */
1529 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ES,
1530 input_EsOutGetFromID( p_input->p->p_es_out,
1534 case INPUT_CONTROL_SET_AUDIO_DELAY:
1535 input_EsOutSetDelay( p_input->p->p_es_out,
1536 AUDIO_ES, val.i_time );
1537 var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
1540 case INPUT_CONTROL_SET_SPU_DELAY:
1541 input_EsOutSetDelay( p_input->p->p_es_out,
1542 SPU_ES, val.i_time );
1543 var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
1546 case INPUT_CONTROL_SET_TITLE:
1547 case INPUT_CONTROL_SET_TITLE_NEXT:
1548 case INPUT_CONTROL_SET_TITLE_PREV:
1549 if( p_input->p->input.b_title_demux &&
1550 p_input->p->input.i_title > 0 )
1553 /* FIXME handle demux title */
1554 demux_t *p_demux = p_input->p->input.p_demux;
1557 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1558 i_title = p_demux->info.i_title - 1;
1559 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1560 i_title = p_demux->info.i_title + 1;
1562 i_title = val.i_int;
1564 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1566 input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_FALSE );
1567 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1569 demux2_Control( p_demux, DEMUX_SET_TITLE, i_title );
1570 input_ControlVarTitle( p_input, i_title );
1573 else if( p_input->p->input.i_title > 0 )
1575 access_t *p_access = p_input->p->input.p_access;
1578 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1579 i_title = p_access->info.i_title - 1;
1580 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1581 i_title = p_access->info.i_title + 1;
1583 i_title = val.i_int;
1585 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1587 input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_FALSE );
1588 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1590 access2_Control( p_access, ACCESS_SET_TITLE, i_title );
1591 stream_AccessReset( p_input->p->input.p_stream );
1595 case INPUT_CONTROL_SET_SEEKPOINT:
1596 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1597 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1598 if( p_input->p->input.b_title_demux &&
1599 p_input->p->input.i_title > 0 )
1601 demux_t *p_demux = p_input->p->input.p_demux;
1603 int64_t i_input_time;
1604 int64_t i_seekpoint_time;
1606 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1608 i_seekpoint = p_demux->info.i_seekpoint;
1609 i_seekpoint_time = p_input->p->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1610 if( i_seekpoint_time >= 0 &&
1611 !demux2_Control( p_demux,
1612 DEMUX_GET_TIME, &i_input_time ) )
1614 if ( i_input_time < i_seekpoint_time + 3000000 )
1620 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1621 i_seekpoint = p_demux->info.i_seekpoint + 1;
1623 i_seekpoint = val.i_int;
1625 if( i_seekpoint >= 0 && i_seekpoint <
1626 p_input->p->input.title[p_demux->info.i_title]->i_seekpoint )
1628 input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_FALSE );
1629 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1631 demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1634 else if( p_input->p->input.i_title > 0 )
1636 demux_t *p_demux = p_input->p->input.p_demux;
1637 access_t *p_access = p_input->p->input.p_access;
1639 int64_t i_input_time;
1640 int64_t i_seekpoint_time;
1642 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1644 i_seekpoint = p_access->info.i_seekpoint;
1645 i_seekpoint_time = p_input->p->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1646 if( i_seekpoint_time >= 0 &&
1647 demux2_Control( p_demux,
1648 DEMUX_GET_TIME, &i_input_time ) )
1650 if ( i_input_time < i_seekpoint_time + 3000000 )
1656 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1657 i_seekpoint = p_access->info.i_seekpoint + 1;
1659 i_seekpoint = val.i_int;
1661 if( i_seekpoint >= 0 && i_seekpoint <
1662 p_input->p->input.title[p_access->info.i_title]->i_seekpoint )
1664 input_EsOutDiscontinuity( p_input->p->p_es_out, VLC_FALSE );
1665 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1667 access2_Control( p_access, ACCESS_SET_SEEKPOINT,
1669 stream_AccessReset( p_input->p->input.p_stream );
1674 case INPUT_CONTROL_ADD_SLAVE:
1675 if( val.psz_string )
1677 input_source_t *slave = InputSourceNew( p_input );
1679 if( !InputSourceInit( p_input, slave, val.psz_string, NULL ) )
1681 vlc_meta_t *p_meta = p_input->p->input.p_item->p_meta;
1685 msg_Dbg( p_input, "adding %s as slave on the fly",
1689 if( demux2_Control( p_input->p->input.p_demux,
1690 DEMUX_GET_TIME, &i_time ) )
1692 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
1693 InputSourceClean( p_input, slave );
1697 if( demux2_Control( slave->p_demux,
1698 DEMUX_SET_TIME, i_time ) )
1700 msg_Err( p_input, "seek failed for new slave" );
1701 InputSourceClean( p_input, slave );
1706 /* Get meta (access and demux) */
1707 access2_Control( slave->p_access, ACCESS_GET_META,
1709 demux2_Control( slave->p_demux, DEMUX_GET_META, p_meta );
1710 UpdateMeta( p_input );
1712 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, slave );
1717 msg_Warn( p_input, "failed to add %s as slave",
1721 free( val.psz_string );
1725 case INPUT_CONTROL_SET_BOOKMARK:
1727 msg_Err( p_input, "not yet implemented" );
1731 return b_force_update;
1734 /*****************************************************************************
1736 *****************************************************************************/
1737 static int UpdateFromDemux( input_thread_t *p_input )
1739 demux_t *p_demux = p_input->p->input.p_demux;
1742 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
1744 v.i_int = p_demux->info.i_title;
1745 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1747 input_ControlVarTitle( p_input, p_demux->info.i_title );
1749 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
1751 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
1753 v.i_int = p_demux->info.i_seekpoint;
1754 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1756 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1758 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
1760 /* Hmmm only works with master input */
1761 if( p_input->p->input.p_demux == p_demux )
1763 int i_title_end = p_input->p->input.i_title_end -
1764 p_input->p->input.i_title_offset;
1765 int i_seekpoint_end = p_input->p->input.i_seekpoint_end -
1766 p_input->p->input.i_seekpoint_offset;
1768 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
1770 if( p_demux->info.i_title > i_title_end ||
1771 ( p_demux->info.i_title == i_title_end &&
1772 p_demux->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1774 else if( i_seekpoint_end >=0 )
1776 if( p_demux->info.i_seekpoint > i_seekpoint_end ) return 0;
1778 else if( i_title_end >= 0 )
1780 if( p_demux->info.i_title > i_title_end ) return 0;
1787 /*****************************************************************************
1789 *****************************************************************************/
1790 static int UpdateFromAccess( input_thread_t *p_input )
1792 access_t *p_access = p_input->p->input.p_access;
1795 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
1797 v.i_int = p_access->info.i_title;
1798 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1800 input_ControlVarTitle( p_input, p_access->info.i_title );
1802 stream_AccessUpdate( p_input->p->input.p_stream );
1804 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
1806 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
1808 v.i_int = p_access->info.i_seekpoint;
1809 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1810 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1812 if( p_access->info.i_update & INPUT_UPDATE_META )
1814 /* TODO maybe multi - access ? */
1815 vlc_meta_t *p_meta = p_input->p->input.p_item->p_meta;
1816 access2_Control( p_input->p->input.p_access,ACCESS_GET_META, p_meta );
1817 UpdateMeta( p_input );
1818 var_SetBool( p_input, "item-change", p_input->p->input.p_item->i_id );
1819 p_access->info.i_update &= ~INPUT_UPDATE_META;
1822 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
1824 /* Hmmm only works with master input */
1825 if( p_input->p->input.p_access == p_access )
1827 int i_title_end = p_input->p->input.i_title_end -
1828 p_input->p->input.i_title_offset;
1829 int i_seekpoint_end = p_input->p->input.i_seekpoint_end -
1830 p_input->p->input.i_seekpoint_offset;
1832 if( i_title_end >= 0 && i_seekpoint_end >=0 )
1834 if( p_access->info.i_title > i_title_end ||
1835 ( p_access->info.i_title == i_title_end &&
1836 p_access->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1838 else if( i_seekpoint_end >=0 )
1840 if( p_access->info.i_seekpoint > i_seekpoint_end ) return 0;
1842 else if( i_title_end >= 0 )
1844 if( p_access->info.i_title > i_title_end ) return 0;
1851 /*****************************************************************************
1853 *****************************************************************************/
1854 static int UpdateMeta( input_thread_t *p_input )
1856 vlc_meta_t *p_meta = p_input->p->input.p_item->p_meta;
1860 if( p_meta->psz_title && !p_input->p->input.p_item->b_fixed_name )
1861 input_Control( p_input, INPUT_SET_NAME, p_meta->psz_title );
1863 /** \todo handle sout meta */
1868 /*****************************************************************************
1870 *****************************************************************************/
1871 static void UpdateItemLength( input_thread_t *p_input, int64_t i_length )
1873 vlc_mutex_lock( &p_input->p->input.p_item->lock );
1874 p_input->p->input.p_item->i_duration = i_length;
1875 vlc_mutex_unlock( &p_input->p->input.p_item->lock );
1877 if( !p_input->b_preparsing )
1879 pl_Yield( p_input );
1880 var_SetInteger( pl_Get( p_input ), "item-change",
1881 p_input->p->input.p_item->i_id );
1882 pl_Release( p_input )
1886 /*****************************************************************************
1888 *****************************************************************************/
1889 static input_source_t *InputSourceNew( input_thread_t *p_input )
1891 input_source_t *in = (input_source_t*) malloc( sizeof( input_source_t ) );
1895 msg_Err( p_input, "out of memory for new input source" );
1900 in->p_access = NULL;
1901 in->p_stream = NULL;
1903 in->b_title_demux = VLC_FALSE;
1906 in->b_can_pace_control = VLC_TRUE;
1907 in->b_eof = VLC_FALSE;
1908 in->i_cr_average = 0;
1913 /*****************************************************************************
1915 *****************************************************************************/
1916 static int InputSourceInit( input_thread_t *p_input,
1917 input_source_t *in, const char *psz_mrl,
1918 const char *psz_forced_demux )
1920 char psz_dup[strlen (psz_mrl) + 1];
1921 const char *psz_access;
1922 const char *psz_demux;
1928 strcpy (psz_dup, psz_mrl);
1930 if( !in ) return VLC_EGENERIC;
1931 if( !p_input ) return VLC_EGENERIC;
1934 if( !p_input->b_preparsing )
1936 MRLSplit( VLC_OBJECT(p_input), psz_dup,
1937 &psz_access, &psz_demux, &psz_path );
1939 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
1940 psz_mrl, psz_access, psz_demux, psz_path );
1942 /* Hack to allow udp://@:port syntax */
1944 (strncmp( psz_access, "udp", 3 ) &&
1945 strncmp( psz_access, "rtp", 3 )) )
1947 /* Find optional titles and seekpoints */
1948 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
1949 &in->i_seekpoint_start, &in->i_seekpoint_end );
1951 if( psz_forced_demux && *psz_forced_demux )
1953 psz_demux = psz_forced_demux;
1955 else if( !psz_demux || *psz_demux == '\0' )
1957 /* special hack for forcing a demuxer with --demux=module
1958 * (and do nothing with a list) */
1959 char *psz_var_demux = var_GetString( p_input, "demux" );
1961 if( *psz_var_demux != '\0' &&
1962 !strchr(psz_var_demux, ',' ) &&
1963 !strchr(psz_var_demux, ':' ) )
1965 psz_demux = psz_var_demux;
1967 msg_Dbg( p_input, "enforced demux ` %s'", psz_demux );
1969 else if( psz_var_demux )
1971 free( psz_var_demux );
1975 /* Try access_demux if no demux given */
1976 if( *psz_demux == '\0' )
1978 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
1979 NULL, p_input->p->p_es_out, VLC_FALSE );
1985 if( !strncmp( psz_path, "file://", 7 ) )
1987 msg_Dbg( p_input, "trying to pre-parse %s", psz_path );
1989 psz_access = "file";
1994 int64_t i_pts_delay;
1996 /* Get infos from access_demux */
1997 demux2_Control( in->p_demux,
1998 DEMUX_GET_PTS_DELAY, &i_pts_delay );
1999 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2001 in->b_title_demux = VLC_TRUE;
2002 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2003 &in->title, &in->i_title,
2004 &in->i_title_offset, &in->i_seekpoint_offset ) )
2009 demux2_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
2010 &in->b_can_pace_control );
2011 demux2_Control( in->p_demux, DEMUX_CAN_PAUSE,
2015 demux2_Control( in->p_demux, DEMUX_CAN_SEEK,
2021 int64_t i_pts_delay;
2023 input_ChangeState( p_input, OPENING_S );
2025 /* Now try a real access */
2026 in->p_access = access2_New( p_input, psz_access, psz_demux, psz_path,
2027 p_input->b_preparsing );
2029 /* Access failed, URL encoded ? */
2030 if( in->p_access == NULL && strchr( psz_path, '%' ) )
2032 decode_URI( psz_path );
2034 msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
2035 psz_access, psz_demux, psz_path );
2037 in->p_access = access2_New( p_input,
2038 psz_access, psz_demux, psz_path,
2039 p_input->b_preparsing );
2042 if( in->p_access == NULL )
2044 msg_Err( p_input, "open of `%s' failed: %s", psz_mrl,
2046 intf_UserFatal( VLC_OBJECT( p_input), VLC_FALSE,
2047 _("Your input can't be opened"),
2048 _("VLC is unable to open the MRL '%s'."
2049 " Check the log for details."), psz_mrl );
2054 psz_tmp = psz = var_GetString( p_input, "access-filter" );
2055 while( psz && *psz )
2057 access_t *p_access = in->p_access;
2058 char *end = strchr( psz, ':' );
2063 in->p_access = access2_FilterNew( in->p_access, psz );
2064 if( in->p_access == NULL )
2066 in->p_access = p_access;
2067 msg_Warn( p_input, "failed to insert access filter %s",
2073 if( psz_tmp ) free( psz_tmp );
2075 /* Get infos from access */
2076 if( !p_input->b_preparsing )
2078 access2_Control( in->p_access,
2079 ACCESS_GET_PTS_DELAY, &i_pts_delay );
2080 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2082 in->b_title_demux = VLC_FALSE;
2083 if( access2_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2084 &in->title, &in->i_title,
2085 &in->i_title_offset, &in->i_seekpoint_offset ) )
2091 access2_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2092 &in->b_can_pace_control );
2093 access2_Control( in->p_access, ACCESS_CAN_PAUSE,
2095 access2_Control( in->p_access, ACCESS_CAN_SEEK,
2097 var_Set( p_input, "seekable", val );
2100 input_ChangeState( p_input, BUFFERING_S );
2102 /* Create the stream_t */
2103 in->p_stream = stream_AccessNew( in->p_access, p_input->b_preparsing );
2104 if( in->p_stream == NULL )
2106 msg_Warn( p_input, "cannot create a stream_t from access" );
2110 /* Open a demuxer */
2111 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2113 psz_demux = in->p_access->psz_demux;
2115 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
2116 in->p_stream, p_input->p->p_es_out,
2117 p_input->b_preparsing );
2118 if( in->p_demux == NULL )
2120 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2121 psz_access, psz_demux, psz_path );
2122 intf_UserFatal( VLC_OBJECT( p_input), VLC_FALSE,
2123 _("Can't recognize the input's format"),
2124 _("The format of '%s' can't be detected. "
2125 "Have a look the log for details."), psz_mrl );
2129 /* TODO get title from demux */
2130 if( !p_input->b_preparsing && in->i_title <= 0 )
2132 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2133 &in->title, &in->i_title,
2134 &in->i_title_offset, &in->i_seekpoint_offset ))
2141 in->b_title_demux = VLC_TRUE;
2146 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2147 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2152 input_ChangeState( p_input, ERROR_S );
2155 demux2_Delete( in->p_demux );
2158 stream_Delete( in->p_stream );
2161 access2_Delete( in->p_access );
2163 return VLC_EGENERIC;
2166 /*****************************************************************************
2168 *****************************************************************************/
2169 static void InputSourceClean( input_thread_t *p_input, input_source_t *in )
2172 demux2_Delete( in->p_demux );
2175 stream_Delete( in->p_stream );
2178 access2_Delete( in->p_access );
2180 if( in->i_title > 0 )
2183 for( i = 0; i < in->i_title; i++ )
2185 vlc_input_title_Delete( in->title[i] );
2191 static void SlaveDemux( input_thread_t *p_input )
2196 if( demux2_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2198 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2202 for( i = 0; i < p_input->p->i_slave; i++ )
2204 input_source_t *in = p_input->p->slave[i];
2210 if( demux2_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2215 if( demux2_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2217 msg_Err( p_input, "slave[%d] doesn't like "
2218 "DEMUX_GET_TIME -> EOF", i );
2223 if( i_stime >= i_time )
2226 if( ( i_ret = in->p_demux->pf_demux( in->p_demux ) ) <= 0 )
2232 i_ret = in->p_demux->pf_demux( in->p_demux );
2237 msg_Dbg( p_input, "slave %d EOF", i );
2238 in->b_eof = VLC_TRUE;
2243 static void SlaveSeek( input_thread_t *p_input )
2248 if( !p_input ) return;
2250 if( demux2_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2252 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2256 for( i = 0; i < p_input->p->i_slave; i++ )
2258 input_source_t *in = p_input->p->slave[i];
2260 if( demux2_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
2262 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2263 in->b_eof = VLC_TRUE;
2268 /*****************************************************************************
2270 *****************************************************************************/
2271 static void InputMetaUser( input_thread_t *p_input )
2273 vlc_meta_t *p_meta = p_input->p->input.p_item->p_meta;
2276 if( !p_meta ) return;
2278 /* Get meta information from user */
2279 #define GET_META( field, s ) \
2280 var_Get( p_input, (s), &val ); \
2281 if( *val.psz_string ) { \
2282 if( p_meta->psz_ ## field ) free ( p_meta->psz_ ## field ); \
2283 p_meta->psz_ ## field = strdup( val.psz_string ); \
2285 free( val.psz_string )
2287 GET_META( title, "meta-title" );
2288 GET_META( artist, "meta-artist" );
2289 GET_META( genre, "meta-genre" );
2290 GET_META( copyright, "meta-copyright" );
2291 GET_META( description, "meta-description" );
2292 GET_META( date, "meta-date" );
2293 GET_META( url, "meta-url" );
2297 /*****************************************************************************
2298 * MRLSplit: parse the access, demux and url part of the
2299 * Media Resource Locator.
2300 *****************************************************************************/
2301 void MRLSplit( vlc_object_t *p_input, char *psz_dup,
2302 const char **ppsz_access, const char **ppsz_demux,
2305 const char *psz_access = "";
2306 const char *psz_demux = "";
2308 char *psz, *psz_check;
2310 psz = strchr( psz_dup, ':' );
2312 /* '@' not allowed in access/demux part */
2313 psz_check = strchr( psz_dup, '@' );
2314 if( psz_check && psz_check < psz ) psz = 0;
2316 #if defined( WIN32 ) || defined( UNDER_CE )
2317 if( psz - psz_dup == 1 )
2319 msg_Dbg( p_input, "drive letter %c: found in source", *psz_dup );
2328 if( psz[0] == '/' && psz[1] == '/' ) psz += 2;
2332 psz = strchr( psz_dup, '/' );
2339 psz_access = psz_dup;
2346 *ppsz_access = psz_access;
2347 *ppsz_demux = psz_demux;
2348 *ppsz_path = psz_path;
2351 /*****************************************************************************
2352 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
2355 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
2356 *****************************************************************************/
2357 static void MRLSections( input_thread_t *p_input, char *psz_source,
2358 int *pi_title_start, int *pi_title_end,
2359 int *pi_chapter_start, int *pi_chapter_end )
2361 char *psz, *psz_end, *psz_next, *psz_check;
2363 *pi_title_start = *pi_title_end = -1;
2364 *pi_chapter_start = *pi_chapter_end = -1;
2366 /* Start by parsing titles and chapters */
2367 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
2369 /* Check we are really dealing with a title/chapter section */
2370 psz_check = psz + 1;
2371 if( !*psz_check ) return;
2372 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2373 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
2374 if( *psz_check == ':' && ++psz_check )
2375 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2376 if( *psz_check != '-' && *psz_check ) return;
2377 if( *psz_check == '-' && ++psz_check )
2378 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2379 if( *psz_check != ':' && *psz_check ) return;
2380 if( *psz_check == ':' && ++psz_check )
2381 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2382 if( *psz_check ) return;
2384 /* Separate start and end */
2386 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
2388 /* Look for the start title */
2389 *pi_title_start = strtol( psz, &psz_next, 0 );
2390 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
2391 *pi_title_end = *pi_title_start;
2394 /* Look for the start chapter */
2396 *pi_chapter_start = strtol( psz, &psz_next, 0 );
2397 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
2398 *pi_chapter_end = *pi_chapter_start;
2402 /* Look for the end title */
2403 *pi_title_end = strtol( psz_end, &psz_next, 0 );
2404 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
2407 /* Look for the end chapter */
2408 if( *psz_end ) psz_end++;
2409 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
2410 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
2413 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
2414 psz_source, *pi_title_start, *pi_chapter_start,
2415 *pi_title_end, *pi_chapter_end );
2418 /*****************************************************************************
2419 * input_AddSubtitles: add a subtitles file and enable it
2420 *****************************************************************************/
2421 vlc_bool_t input_AddSubtitles( input_thread_t *p_input, char *psz_subtitle,
2422 vlc_bool_t b_check_extension )
2424 input_source_t *sub;
2427 char *psz_path, *psz_extension;
2429 if( b_check_extension && !subtitles_Filter( psz_subtitle ) )
2434 /* if we are provided a subtitle.sub file,
2435 * see if we don't have a subtitle.idx and use it instead */
2436 psz_path = strdup( psz_subtitle );
2439 psz_extension = strrchr( psz_path, '.');
2440 if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
2444 strcpy( psz_extension, ".idx" );
2445 /* FIXME: a portable wrapper for stat() or access() would be more suited */
2446 if( ( f = utf8_fopen( psz_path, "rt" ) ) )
2449 msg_Dbg( p_input, "using %s subtitles file instead of %s",
2450 psz_path, psz_subtitle );
2451 strcpy( psz_subtitle, psz_path );
2457 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
2459 sub = InputSourceNew( p_input );
2460 if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
2462 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
2465 if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
2467 if( count.i_int == 0 )
2469 /* if it was first one, there is disable too */
2471 if( count.i_int < list.p_list->i_count )
2473 input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
2474 &list.p_list->p_values[count.i_int] );
2476 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );