1 /*****************************************************************************
2 * input.c: input thread
3 *****************************************************************************
4 * Copyright (C) 1998-2004 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
31 #include <vlc/input.h>
32 #include <vlc/decoder.h>
35 #include "input_internal.h"
37 #include "stream_output.h"
39 #include "vlc_interface.h"
42 /*****************************************************************************
44 *****************************************************************************/
45 static int Run ( input_thread_t *p_input );
47 static int Init ( input_thread_t *p_input );
48 static void Error( input_thread_t *p_input );
49 static void End ( input_thread_t *p_input );
51 static inline int ControlPopNoLock( input_thread_t *, int *, vlc_value_t * );
52 static void ControlReduce( input_thread_t * );
53 static vlc_bool_t Control( input_thread_t *, int, vlc_value_t );
56 static void UpdateFromAccess( input_thread_t * );
57 static void UpdateFromDemux( input_thread_t * );
59 static void ParseOption( input_thread_t *p_input, const char *psz_option );
61 static void DecodeUrl ( char * );
63 /*****************************************************************************
64 * input_CreateThread: creates a new input thread
65 *****************************************************************************
66 * This function creates a new input, and returns a pointer
67 * to its description. On error, it returns NULL.
69 * Variables for _public_ use:
72 * - rate,rate-slower, rate-faster
73 * - position, position-offset
75 * - title,title-next,title-prev
76 * - chapter,chapter-next, chapter-prev
77 * - program, audio-es, video-es, spu-es
82 * * For intf callback upon changes
84 * TODO explain when Callback is called
85 * TODO complete this list (?)
86 *****************************************************************************/
87 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
88 input_item_t *p_item )
91 input_thread_t *p_input; /* thread descriptor */
94 /* Allocate descriptor */
95 p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
98 msg_Err( p_parent, "out of memory" );
102 /* Init Common fields */
103 p_input->b_eof = VLC_FALSE;
104 p_input->b_can_pace_control = VLC_TRUE;
105 p_input->i_start = 0;
108 p_input->i_title = 0;
109 p_input->title = NULL;
110 p_input->i_state = INIT_S;
111 p_input->i_rate = INPUT_RATE_DEFAULT;
112 p_input->i_bookmark = 0;
113 p_input->bookmark = NULL;
114 p_input->p_es_out = NULL;
115 p_input->p_sout = NULL;
116 p_input->b_out_pace_control = VLC_FALSE;
117 p_input->i_pts_delay = 0;
120 /* Init Input fields */
121 p_input->input.p_item = p_item;
122 p_input->input.p_access = NULL;
123 p_input->input.p_stream = NULL;
124 p_input->input.p_demux = NULL;
125 p_input->input.b_title_demux = VLC_FALSE;
126 p_input->input.i_title = 0;
127 p_input->input.title = NULL;
128 p_input->input.b_can_pace_control = VLC_TRUE;
129 p_input->input.b_eof = VLC_FALSE;
130 p_input->input.i_cr_average = 0;
132 /* Init control buffer */
133 vlc_mutex_init( p_input, &p_input->lock_control );
134 p_input->i_control = 0;
135 p_input->p_sys = NULL;
137 /* Parse input options */
138 vlc_mutex_lock( &p_item->lock );
139 for( i = 0; i < p_item->i_options; i++ )
141 msg_Dbg( p_input, "option: %s", p_item->ppsz_options[i] );
142 ParseOption( p_input, p_item->ppsz_options[i] );
144 vlc_mutex_unlock( &p_item->lock );
146 /* Create Object Variables for private use only */
147 input_ConfigVarInit( p_input );
149 /* Create Objects variables for public Get and Set */
150 input_ControlVarInit( p_input );
151 p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
155 var_Get( p_input, "bookmarks", &val );
158 /* FIXME: have a common cfg parsing routine used by sout and others */
159 char *psz_parser, *psz_start, *psz_end;
160 psz_parser = val.psz_string;
161 while( (psz_start = strchr( psz_parser, '{' ) ) )
163 seekpoint_t seekpoint;
166 psz_end = strchr( psz_start, '}' );
167 if( !psz_end ) break;
168 psz_parser = psz_end + 1;
169 backup = *psz_parser;
173 seekpoint.psz_name = 0;
174 seekpoint.i_byte_offset = 0;
175 seekpoint.i_time_offset = 0;
176 while( (psz_end = strchr( psz_start, ',' ) ) )
179 if( !strncmp( psz_start, "name=", 5 ) )
181 seekpoint.psz_name = psz_start + 5;
183 else if( !strncmp( psz_start, "bytes=", 6 ) )
185 seekpoint.i_byte_offset = atoll(psz_start + 6);
187 else if( !strncmp( psz_start, "time=", 5 ) )
189 seekpoint.i_time_offset = atoll(psz_start + 5) * 1000000;
191 psz_start = psz_end + 1;
193 msg_Dbg( p_input, "adding bookmark: %s, bytes="I64Fd", time="I64Fd,
194 seekpoint.psz_name, seekpoint.i_byte_offset,
195 seekpoint.i_time_offset );
196 input_Control( p_input, INPUT_ADD_BOOKMARK, &seekpoint );
197 *psz_parser = backup;
199 free( val.psz_string );
203 /* Now we can attach our new input */
204 vlc_object_attach( p_input, p_parent );
206 /* Create thread and wait for its readiness. */
207 if( vlc_thread_create( p_input, "input", Run,
208 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
210 msg_Err( p_input, "cannot create input thread" );
211 vlc_object_detach( p_input );
212 vlc_object_destroy( p_input );
219 /*****************************************************************************
220 * input_StopThread: mark an input thread as zombie
221 *****************************************************************************
222 * This function should not return until the thread is effectively cancelled.
223 *****************************************************************************/
224 void input_StopThread( input_thread_t *p_input )
229 /* Set die for input */
230 p_input->b_die = VLC_TRUE;
232 /* We cannot touch p_input fields directly (we can from another thread),
233 * so use the vlc_object_find way, it's perfectly safe */
235 /* Set die for all access */
236 p_list = vlc_list_find( p_input, VLC_OBJECT_ACCESS, FIND_CHILD );
237 for( i = 0; i < p_list->i_count; i++ )
239 p_list->p_values[i].p_object->b_die = VLC_TRUE;
241 vlc_list_release( p_list );
243 /* Set die for all stream */
244 p_list = vlc_list_find( p_input, VLC_OBJECT_STREAM, FIND_CHILD );
245 for( i = 0; i < p_list->i_count; i++ )
247 p_list->p_values[i].p_object->b_die = VLC_TRUE;
249 vlc_list_release( p_list );
251 /* Set die for all demux */
252 p_list = vlc_list_find( p_input, VLC_OBJECT_DEMUX, FIND_CHILD );
253 for( i = 0; i < p_list->i_count; i++ )
255 p_list->p_values[i].p_object->b_die = VLC_TRUE;
257 vlc_list_release( p_list );
259 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
262 /*****************************************************************************
263 * input_DestroyThread: mark an input thread as zombie
264 *****************************************************************************
265 * This function should not return until the thread is effectively cancelled.
266 *****************************************************************************/
267 void input_DestroyThread( input_thread_t *p_input )
269 /* Join the thread */
270 vlc_thread_join( p_input );
272 /* Delete input lock (only after thread joined) */
273 vlc_mutex_destroy( &p_input->lock_control );
275 /* TODO: maybe input_DestroyThread should also delete p_input instead
276 * of the playlist but I'm not sure if it's possible */
279 /*****************************************************************************
280 * Run: main thread loop
281 *****************************************************************************
282 * Thread in charge of processing the network packets and demultiplexing.
283 *****************************************************************************/
284 static int Run( input_thread_t *p_input )
286 int64_t i_intf_update = 0;
288 /* Signal that the thread is launched */
289 vlc_thread_ready( p_input );
291 if( Init( p_input ) )
293 /* If we failed, wait before we are killed, and exit */
294 p_input->b_error = VLC_TRUE;
298 /* Tell we're dead */
299 p_input->b_dead = VLC_TRUE;
305 while( !p_input->b_die && !p_input->b_error && !p_input->b_eof )
307 vlc_bool_t b_force_update = VLC_FALSE;
313 if( p_input->i_state != PAUSE_S )
315 if( p_input->i_stop <= 0 || p_input->i_time < p_input->i_stop )
316 i_ret=p_input->input.p_demux->pf_demux(p_input->input.p_demux);
323 if( p_input->input.b_title_demux &&
324 p_input->input.p_demux->info.i_update )
326 UpdateFromDemux( p_input );
327 b_force_update = VLC_TRUE;
329 else if( !p_input->input.b_title_demux &&
330 p_input->input.p_access &&
331 p_input->input.p_access->info.i_update )
333 UpdateFromAccess( p_input );
334 b_force_update = VLC_TRUE;
337 else if( i_ret == 0 ) /* EOF */
341 var_Get( p_input, "input-repeat", &repeat );
342 if( repeat.i_int == 0 )
344 /* End of file - we do not set b_die because only the
345 * playlist is allowed to do so. */
346 msg_Dbg( p_input, "EOF reached" );
347 p_input->b_eof = VLC_TRUE;
348 p_input->input.b_eof = VLC_TRUE;
352 msg_Dbg( p_input, "repeating the same input (%d)", repeat.i_int );
353 if( repeat.i_int > 0 )
356 var_Set( p_input, "input-repeat", repeat );
359 /* Seek to title 0 position 0(start) */
361 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
362 if( p_input->i_start > 0 )
364 val.i_time = p_input->i_start;
365 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
371 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
378 p_input->b_error = VLC_TRUE;
388 vlc_mutex_lock( &p_input->lock_control );
389 ControlReduce( p_input );
390 while( !ControlPopNoLock( p_input, &i_type, &val ) )
392 msg_Dbg( p_input, "control type=%d", i_type );
393 if( Control( p_input, i_type, val ) )
394 b_force_update = VLC_TRUE;
396 vlc_mutex_unlock( &p_input->lock_control );
398 if( b_force_update ||
399 i_intf_update < mdate() )
403 int64_t i_time, i_length;
404 /* update input status variables */
405 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_POSITION, &f_pos ) )
407 val.f_float = (float)f_pos;
408 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
410 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
412 p_input->i_time = i_time;
414 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
416 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_LENGTH, &i_length ) )
419 var_Get( p_input, "length", &old_val );
420 val.i_time = i_length;
421 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
423 if( old_val.i_time != val.i_time )
427 char psz_buffer[MSTRTIME_MAX_SIZE];
429 vlc_mutex_lock( &p_input->p_item->lock );
430 p_input->p_item->i_duration = i_length;
431 vlc_mutex_unlock( &p_input->p_item->lock );
433 input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
434 msecstotimestr( psz_buffer, i_length / 1000 ) );
439 var_SetBool( p_input, "intf-change", VLC_TRUE );
440 i_intf_update = mdate() + I64C(150000);
444 /* Wait we are asked to die */
445 if( !p_input->b_die )
456 while( !p_input->b_die && !p_input->b_error && !p_input->b_eof )
458 if( p_input->stream.p_selected_area->i_seek != NO_SEEK )
460 if( p_input->stream.p_selected_area->i_size > 0 )
464 double f = (double)p_input->stream.p_selected_area->i_seek /
465 (double)p_input->stream.p_selected_area->i_size;
467 vlc_mutex_unlock( &p_input->stream.stream_lock );
468 demux_Control( p_input, DEMUX_SET_POSITION, f );
469 vlc_mutex_lock( &p_input->stream.stream_lock );
471 /* Escape all decoders for the stream discontinuity they
473 input_EscapeDiscontinuity( p_input );
475 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
477 pgrm_descriptor_t * p_pgrm=p_input->stream.pp_programs[i];
479 /* Reinitialize synchro. */
480 p_pgrm->i_synchro_state = SYNCHRO_REINIT;
483 vlc_mutex_unlock( &p_input->stream.stream_lock );
484 if( !demux_Control( p_input, DEMUX_GET_TIME, &i_time ) )
489 /* Help in bar display */
491 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
494 for( i = 0; i < p_input->p_sys->i_sub; i++ )
496 subtitle_Seek( p_input->p_sys->sub[i], i_time );
499 if( !demux_Control( p_input, DEMUX_GET_POSITION, &f ) )
501 val.f_float = (float)f;
502 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
504 vlc_mutex_lock( &p_input->stream.stream_lock );
506 p_input->stream.p_selected_area->i_seek = NO_SEEK;
509 /* Read and demultiplex some data. */
510 i_count = p_input->pf_demux( p_input );
514 if( !p_input->b_error && !p_input->b_eof && i_update_next < mdate() )
521 /* update input status variables */
522 if( !demux_Control( p_input, DEMUX_GET_POSITION, &d_pos ) )
524 val.f_float = (float)d_pos;
525 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
527 if( !demux_Control( p_input, DEMUX_GET_TIME, &i_time ) )
530 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
532 if( !demux_Control( p_input, DEMUX_GET_LENGTH, &i_length ) )
535 var_Get( p_input, "length", &old_val );
536 val.i_time = i_length;
537 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
538 if( old_val.i_time != val.i_time )
540 char psz_buffer[MSTRTIME_MAX_SIZE];
542 vlc_mutex_lock( &p_input->p_item->lock );
543 p_input->p_item->i_duration = i_length;
544 vlc_mutex_unlock( &p_input->p_item->lock );
546 input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
547 msecstotimestr( psz_buffer, i_length / 1000 ) );
551 /* Check stop-time */
552 if( p_input->p_sys->i_stop_time > 0 && p_input->p_sys->i_stop_time < i_time )
554 msg_Warn( p_input, "EOF reached because of stop-time" );
559 for( i = 0; i < p_input->p_sys->i_sub; i++ )
561 subtitle_Demux( p_input->p_sys->sub[i], i_time );
564 i_update_next = mdate() + I64C(150000);
568 if( p_input->b_error || p_input->b_eof )
570 ErrorThread( p_input );
573 EndThread( p_input );
579 /*****************************************************************************
580 * Init: init the input Thread
581 *****************************************************************************/
582 static int Init( input_thread_t * p_input )
584 char *psz_dup = strdup( p_input->input.p_item->psz_uri );
585 char *psz_access = NULL;
586 char *psz_demux = NULL;
587 char *psz_path = NULL;
591 /* Open access/stream/demux */
592 psz = strchr( psz_dup, ':' );
593 #if defined( WIN32 ) || defined( UNDER_CE )
594 if( psz - psz_dup == 1 )
596 msg_Warn( p_input, "drive letter %c: found in source string", psz_dup[0] );
604 if( psz[0] == '/' && psz[1] == '/' )
609 psz = strchr( psz_dup, '/' );
616 psz_access = psz_dup;
623 if( psz_access == NULL ) psz_access = "";
624 if( psz_demux == NULL ) psz_demux = "";
625 if( psz_path == NULL ) psz_path = "";
627 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
628 p_input->input.p_item->psz_uri,
629 psz_access, psz_demux, psz_path );
631 /* Initialize optional stream output. (before access/demuxer) */
632 psz = var_GetString( p_input, "sout" );
635 p_input->p_sout = sout_NewInstance( p_input, psz );
636 if( p_input->p_sout == NULL )
638 msg_Err( p_input, "cannot start stream output instance, aborting" );
648 p_input->p_es_out = input_EsOutNew( p_input );
649 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
650 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
652 /* Try access_demux if no demux given */
653 if( *psz_access && *psz_demux == '\0' )
655 p_input->input.p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
656 NULL, p_input->p_es_out );
659 if( p_input->input.p_demux )
661 /* Get infos from access_demux */
662 demux2_Control( p_input->input.p_demux,
663 DEMUX_GET_PTS_DELAY, &p_input->i_pts_delay );
664 p_input->input.b_title_demux = VLC_TRUE;
665 if( demux2_Control( p_input->input.p_demux,
666 DEMUX_GET_TITLE_INFO,
667 &p_input->input.title, &p_input->input.i_title ) )
669 p_input->input.i_title = 0;
670 p_input->input.title = NULL;
672 demux2_Control( p_input->input.p_demux, DEMUX_CAN_CONTROL_PACE,
673 &p_input->input.b_can_pace_control );
674 demux2_Control( p_input->input.p_demux, DEMUX_CAN_PAUSE,
675 &p_input->input.b_can_pause );
679 /* Now try a real access */
680 p_input->input.p_access = access2_New( p_input, psz_access, psz_demux, psz_path );
682 /* Access failed, URL encoded ? */
683 if( p_input->input.p_access == NULL && strchr( psz_path, '%' ) )
685 DecodeUrl( psz_path );
687 msg_Dbg( p_input, "retying with access `%s' demux `%s' path `%s'",
688 psz_access, psz_demux, psz_path );
690 p_input->input.p_access = access2_New( p_input, psz_access, psz_demux, psz_path );
692 #ifndef WIN32 /* Remove this gross hack from the win32 build as colons
693 * are forbidden in filenames on Win32. */
695 /* Maybe we got something like: /Volumes/toto:titi/gabu.mpg */
696 if( p_input->input.p_access == NULL &&
697 *psz_access == '\0' && ( *psz_demux || *psz_path ) )
700 psz_dup = strdup( p_input->input.p_item->psz_uri );
705 p_input->input.p_access = access2_New( p_input, psz_access, psz_demux, psz_path );
709 if( p_input->input.p_access == NULL )
711 msg_Err( p_input, "no suitable access module for `%s'",
712 p_input->input.p_item->psz_uri );
716 /* Get infos from access */
717 access2_Control( p_input->input.p_access,
718 ACCESS_GET_PTS_DELAY, &p_input->i_pts_delay );
719 p_input->input.b_title_demux = VLC_FALSE;
720 if( access2_Control( p_input->input.p_access,
721 ACCESS_GET_TITLE_INFO,
722 &p_input->input.title, &p_input->input.i_title ) )
724 p_input->input.i_title = 0;
725 p_input->input.title = NULL;
727 access2_Control( p_input->input.p_access, ACCESS_CAN_CONTROL_PACE,
728 &p_input->input.b_can_pace_control );
729 access2_Control( p_input->input.p_access, ACCESS_CAN_PAUSE,
730 &p_input->input.b_can_pace_control );
732 /* Create the stream_t */
733 p_input->input.p_stream = stream_AccessNew( p_input->input.p_access );
734 if( p_input->input.p_stream == NULL )
736 msg_Warn( p_input, "cannot create a stream_t from access" );
741 if( *psz_demux == '\0' && *p_input->input.p_access->psz_demux )
743 psz_demux = p_input->input.p_access->psz_demux;
745 p_input->input.p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
746 p_input->input.p_stream,
748 if( p_input->input.p_demux == NULL )
750 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
751 psz_access, psz_demux, psz_path );
755 /* TODO get title from demux */
756 if( p_input->input.i_title <= 0 )
758 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TITLE_INFO,
759 &p_input->input.title, &p_input->input.i_title ) )
761 p_input->input.i_title = 0;
762 p_input->input.title = NULL;
766 p_input->input.b_title_demux = VLC_TRUE;
770 /* Create global title (for now, just a copy) */
771 p_input->i_title = p_input->input.i_title;
772 if( p_input->i_title > 0 )
775 p_input->title = malloc( sizeof( input_title_t *) * p_input->i_title );
776 for( i = 0; i < p_input->i_title; i++ )
778 p_input->title[i] = vlc_input_title_Duplicate( p_input->input.title[i] );
781 /* Setup variables */
782 input_ControlVarNavigation( p_input );
783 input_ControlVarTitle( p_input, 0 );
786 p_input->b_can_pace_control = p_input->input.b_can_pace_control;
787 p_input->b_can_pause = p_input->input.b_can_pause;
790 if( p_input->i_pts_delay <= 0 )
791 p_input->i_pts_delay = DEFAULT_PTS_DELAY;
793 /* If the desynchronisation requested by the user is < 0, we need to
794 * cache more data. */
795 var_Get( p_input, "audio-desync", &val );
797 p_input->i_pts_delay -= (val.i_int * 1000);
799 /* Init input_thread_sys_t */
800 p_input->p_sys = malloc( sizeof( input_thread_sys_t ) );
801 p_input->p_sys->i_sub = 0;
802 p_input->p_sys->sub = NULL;
804 /* TODO: check meta data from users */
806 /* TODO: get meta data from demuxer */
809 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_LENGTH, &val.i_time ) && val.i_time > 0 )
811 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
812 /* TODO update playlist meta data */
816 p_input->i_start = (int64_t)var_GetInteger( p_input, "start-time" ) *
818 p_input->i_stop = (int64_t)var_GetInteger( p_input, "stop-time" ) *
821 if( p_input->i_start > 0 )
823 if( p_input->i_start >= val.i_time )
825 msg_Warn( p_input, "invalid start-time ignored" );
831 msg_Dbg( p_input, "start-time: %ds",
832 (int)( p_input->i_start / I64C(1000000) ) );
834 s.i_time = p_input->i_start;
835 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
838 if( p_input->i_stop > 0 && p_input->i_stop <= p_input->i_start )
840 msg_Warn( p_input, "invalid stop-time ignored" );
845 /* TODO: do subtitle loading */
849 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
850 val.b_bool = VLC_FALSE;
851 if( p_input->p_sout )
853 var_Get( p_input, "sout-all", &val );
855 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE,
856 val.b_bool ? ES_OUT_MODE_ALL : ES_OUT_MODE_AUTO );
858 /* TODO select forced subs */
862 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
863 p_sub_toselect->p_es, VLC_TRUE );
867 if( p_input->p_sout )
869 if( p_input->p_sout->i_out_pace_nocontrol > 0 )
871 p_input->b_out_pace_control = VLC_FALSE;
875 p_input->b_out_pace_control = VLC_TRUE;
877 msg_Dbg( p_input, "starting in %s mode",
878 p_input->b_out_pace_control ? "asynch" : "synch" );
881 msg_Dbg( p_input, "`%s' sucessfully opened",
882 p_input->input.p_item->psz_uri );
884 /* initialization is complete */
885 p_input->i_state = PLAYING_S;
887 val.i_int = PLAYING_S;
888 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
893 if( p_input->input.p_demux )
894 demux2_Delete( p_input->input.p_demux );
896 if( p_input->input.p_stream )
897 stream_AccessDelete( p_input->input.p_stream );
899 if( p_input->input.p_access )
900 access2_Delete( p_input->input.p_access );
902 if( p_input->p_es_out )
903 input_EsOutDelete( p_input->p_es_out );
905 if( p_input->p_sout )
906 sout_DeleteInstance( p_input->p_sout );
908 /* Mark them deleted */
909 p_input->input.p_demux = NULL;
910 p_input->input.p_stream = NULL;
911 p_input->input.p_access = NULL;
912 p_input->p_es_out = NULL;
913 p_input->p_sout = NULL;
918 vlc_meta_t *p_meta = NULL, *p_meta_user = NULL;
924 p_input->input.i_cr_average = config_GetInt( p_input, "cr-average" );
925 p_input->stream.control.i_status = INIT_S;
926 p_input->stream.control.i_rate = DEFAULT_RATE;
929 /* Init input_thread_sys_t */
930 p_input->p_sys = malloc( sizeof( input_thread_sys_t ) );
931 p_input->p_sys->i_sub = 0;
932 p_input->p_sys->sub = NULL;
934 /* Get meta information from user */
935 var_Create( p_input, "meta-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
936 var_Create( p_input, "meta-author", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
937 var_Create( p_input, "meta-artist", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
938 var_Create( p_input, "meta-genre", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
939 var_Create( p_input, "meta-copyright", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
940 var_Create( p_input, "meta-description", VLC_VAR_STRING|VLC_VAR_DOINHERIT);
941 var_Create( p_input, "meta-date", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
942 var_Create( p_input, "meta-url", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
943 if( (p_meta_user = vlc_meta_New()) )
947 var_Get( p_input, "meta-title", &val );
948 if( *val.psz_string )
949 vlc_meta_Add( p_meta_user, VLC_META_TITLE, val.psz_string );
950 free( val.psz_string );
951 var_Get( p_input, "meta-author", &val );
952 if( *val.psz_string )
953 vlc_meta_Add( p_meta_user, VLC_META_AUTHOR, val.psz_string );
954 free( val.psz_string );
955 var_Get( p_input, "meta-artist", &val );
956 if( *val.psz_string )
957 vlc_meta_Add( p_meta_user, VLC_META_ARTIST, val.psz_string );
958 free( val.psz_string );
959 var_Get( p_input, "meta-genre", &val );
960 if( *val.psz_string )
961 vlc_meta_Add( p_meta_user, VLC_META_GENRE, val.psz_string );
962 free( val.psz_string );
963 var_Get( p_input, "meta-copyright", &val );
964 if( *val.psz_string )
965 vlc_meta_Add( p_meta_user, VLC_META_COPYRIGHT, val.psz_string );
966 free( val.psz_string );
967 var_Get( p_input, "meta-description", &val );
968 if( *val.psz_string )
969 vlc_meta_Add( p_meta_user, VLC_META_DESCRIPTION, val.psz_string );
970 free( val.psz_string );
971 var_Get( p_input, "meta-date", &val );
972 if( *val.psz_string )
973 vlc_meta_Add( p_meta_user, VLC_META_DATE, val.psz_string );
974 free( val.psz_string );
975 var_Get( p_input, "meta-url", &val );
976 if( *val.psz_string )
977 vlc_meta_Add( p_meta_user, VLC_META_URL, val.psz_string );
978 free( val.psz_string );
981 /* Get meta informations from demuxer */
982 if( !demux_Control( p_input, DEMUX_GET_META, &p_meta ) ||
983 ( p_meta_user && p_meta_user->i_meta ) )
987 /* Merge demux and user metadata */
988 if( !p_meta ){ p_meta = p_meta_user; p_meta_user = NULL; }
989 else if( p_meta && p_meta_user ) vlc_meta_Merge( p_meta, p_meta_user );
991 msg_Dbg( p_input, "meta informations:" );
992 if( p_meta->i_meta > 0 )
994 for( i = 0; i < p_meta->i_meta; i++ )
996 msg_Dbg( p_input, " - '%s' = '%s'", _(p_meta->name[i]),
998 if( !strcmp( p_meta->name[i], VLC_META_TITLE ) &&
1000 input_Control( p_input, INPUT_SET_NAME, p_meta->value[i] );
1002 if( !strcmp( p_meta->name[i], VLC_META_AUTHOR ) )
1003 input_Control( p_input, INPUT_ADD_INFO, _("General"),
1004 _("Author"), p_meta->value[i] );
1006 input_Control( p_input, INPUT_ADD_INFO, _("File"),
1007 _(p_meta->name[i]), "%s", p_meta->value[i] );
1010 for( i = 0; i < p_meta->i_track; i++ )
1012 vlc_meta_t *tk = p_meta->track[i];
1015 msg_Dbg( p_input, " - track[%d]:", i );
1016 if( tk->i_meta > 0 )
1018 char *psz_cat = malloc( strlen(_("Stream")) + 10 );
1019 sprintf( psz_cat, "%s %d", _("Stream"), i );
1021 for( j = 0; j < tk->i_meta; j++ )
1023 msg_Dbg( p_input, " - '%s' = '%s'", _(tk->name[j]),
1026 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1027 _(tk->name[j]), "%s", tk->value[j] );
1032 if( p_input->stream.p_sout && p_input->stream.p_sout->p_meta == NULL )
1034 p_input->stream.p_sout->p_meta = p_meta;
1038 vlc_meta_Delete( p_meta );
1041 if( p_meta_user ) vlc_meta_Delete( p_meta_user );
1044 if( !demux_Control( p_input, DEMUX_GET_LENGTH, &i_length ) &&
1047 char psz_buffer[MSTRTIME_MAX_SIZE];
1049 vlc_mutex_lock( &p_input->p_item->lock );
1050 p_input->p_item->i_duration = i_length;
1051 vlc_mutex_unlock( &p_input->p_item->lock );
1053 input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
1054 msecstotimestr( psz_buffer, i_length / 1000 ) );
1056 /* Set start time */
1057 var_Get( p_input, "start-time", &val );
1060 double f_pos = val.i_int * I64C(1000000) / (double)i_length;
1064 msg_Warn( p_input, "invalid start-time, ignored (start-time "
1065 ">= media length)" );
1069 p_input->stream.p_selected_area->i_seek =
1070 (int64_t)( f_pos * (double)p_input->stream.p_selected_area->i_size );
1072 msg_Dbg( p_input, "start-time %ds (%2.2f)", val.i_int, f_pos );
1078 if( demux_Control( p_input, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 )
1080 i_microsecondperframe = 0;
1084 i_microsecondperframe = (int64_t)( (double)1000000.0 / (double)f_fps );
1087 /* Look for and add subtitle files */
1088 var_Get( p_input, "sub-file", &val );
1089 if( val.psz_string && *val.psz_string )
1091 subtitle_demux_t *p_sub;
1093 msg_Dbg( p_input, "force subtitle: %s", val.psz_string );
1094 if( ( p_sub = subtitle_New( p_input, strdup(val.psz_string),
1095 i_microsecondperframe ) ) )
1097 p_sub_toselect = p_sub;
1098 TAB_APPEND( p_input->p_sys->i_sub, p_input->p_sys->sub, p_sub );
1101 psz_sub_file = val.psz_string;
1103 var_Get( p_input, "sub-autodetect-file", &val );
1104 var_Get( p_input, "sub-autodetect-path", &val1 );
1107 subtitle_demux_t *p_sub;
1109 char **tmp = subtitles_Detect( p_input, val1.psz_string, p_input->psz_name );
1111 for( i = 0; *tmp2 != NULL; i++ )
1113 if( psz_sub_file == NULL || strcmp( psz_sub_file, *tmp2 ) )
1115 if( ( p_sub = subtitle_New( p_input, *tmp2,
1116 i_microsecondperframe ) ) )
1118 TAB_APPEND( p_input->p_sys->i_sub, p_input->p_sys->sub,
1125 free( val1.psz_string );
1127 if( psz_sub_file ) free( psz_sub_file );
1129 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
1130 val.b_bool = VLC_FALSE;
1131 if( p_input->stream.p_sout )
1133 var_Get( p_input, "sout-all", &val );
1135 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE,
1136 val.b_bool ? ES_OUT_MODE_ALL : ES_OUT_MODE_AUTO );
1137 if( p_sub_toselect )
1139 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
1140 p_sub_toselect->p_es, VLC_TRUE );
1145 /*****************************************************************************
1146 * Error: RunThread() error loop
1147 *****************************************************************************
1148 * This function is called when an error occured during thread main's loop.
1149 *****************************************************************************/
1150 static void Error( input_thread_t *p_input )
1152 while( !p_input->b_die )
1155 msleep( INPUT_IDLE_SLEEP );
1159 /*****************************************************************************
1160 * End: end the input thread
1161 *****************************************************************************/
1162 static void End( input_thread_t * p_input )
1166 msg_Dbg( p_input, "closing `%s'",
1167 p_input->input.p_item->psz_uri );
1169 /* We are at the end */
1170 p_input->i_state = END_S;
1173 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1175 /* Clean control variables */
1176 input_ControlVarClean( p_input );
1178 /* Unload all modules */
1179 if( p_input->input.p_demux )
1180 demux2_Delete( p_input->input.p_demux );
1182 if( p_input->input.p_stream )
1183 stream_AccessDelete( p_input->input.p_stream );
1185 if( p_input->input.p_access )
1186 access2_Delete( p_input->input.p_access );
1188 if( p_input->p_es_out )
1189 input_EsOutDelete( p_input->p_es_out );
1191 /* Close optional stream output instance */
1192 if( p_input->p_sout )
1194 vlc_object_t *p_pl =
1195 vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1198 if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
1200 /* attach sout to the playlist */
1201 msg_Warn( p_input, "keeping sout" );
1202 vlc_object_detach( p_input->p_sout );
1203 vlc_object_attach( p_input->p_sout, p_pl );
1207 msg_Warn( p_input, "destroying sout" );
1208 sout_DeleteInstance( p_input->p_sout );
1211 vlc_object_release( p_pl );
1216 /* Destroy subtitles demuxers */
1217 if( p_input->p_sys )
1219 for( i = 0; i < p_input->p_sys->i_sub; i++ )
1221 subtitle_Close( p_input->p_sys->sub[i] );
1223 if( p_input->p_sys->i_sub > 0 )
1225 free( p_input->p_sys->sub );
1231 /* Free input_thread_sys_t */
1232 free( p_input->p_sys );
1234 /* Tell we're dead */
1235 p_input->b_dead = VLC_TRUE;
1238 /*****************************************************************************
1240 *****************************************************************************/
1241 static inline int ControlPopNoLock( input_thread_t *p_input,
1242 int *pi_type, vlc_value_t *p_val )
1244 if( p_input->i_control <= 0 )
1246 return VLC_EGENERIC;
1249 *pi_type = p_input->control[0].i_type;
1250 *p_val = p_input->control[0].val;
1252 p_input->i_control--;
1253 if( p_input->i_control > 0 )
1257 for( i = 0; i < p_input->i_control; i++ )
1259 p_input->control[i].i_type = p_input->control[i+1].i_type;
1260 p_input->control[i].val = p_input->control[i+1].val;
1267 static void ControlReduce( input_thread_t *p_input )
1270 for( i = 1; i < p_input->i_control; i++ )
1272 const int i_lt = p_input->control[i-1].i_type;
1273 const int i_ct = p_input->control[i].i_type;
1275 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1276 msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->i_control, i_lt, i_ct );
1278 ( i_ct == INPUT_CONTROL_SET_STATE ||
1279 i_ct == INPUT_CONTROL_SET_RATE ||
1280 i_ct == INPUT_CONTROL_SET_POSITION ||
1281 i_ct == INPUT_CONTROL_SET_TIME ||
1282 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1283 i_ct == INPUT_CONTROL_SET_TITLE ||
1284 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1285 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1288 msg_Dbg( p_input, "merged at %d", i );
1289 /* Remove the i-1 */
1290 for( j = i; j < p_input->i_control; j++ )
1291 p_input->control[j-1] = p_input->control[j];
1292 p_input->i_control--;
1296 /* TODO but that's not that important
1297 - merge SET_X with SET_X_CMD
1298 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1299 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1306 static vlc_bool_t Control( input_thread_t *p_input, int i_type, vlc_value_t val )
1308 vlc_bool_t b_force_update = VLC_FALSE;
1312 case INPUT_CONTROL_SET_DIE:
1313 msg_Dbg( p_input, "control: INPUT_CONTROL_SET_DIE proceed" );
1314 /* Mark all submodules to die */
1315 if( p_input->input.p_access )
1316 p_input->input.p_access->b_die = VLC_TRUE;
1317 if( p_input->input.p_stream )
1318 p_input->input.p_stream->b_die = VLC_TRUE;
1319 p_input->input.p_demux->b_die = VLC_TRUE;
1321 p_input->b_die = VLC_TRUE;
1324 case INPUT_CONTROL_SET_POSITION:
1325 case INPUT_CONTROL_SET_POSITION_OFFSET:
1328 if( i_type == INPUT_CONTROL_SET_POSITION )
1330 f_pos = val.f_float;
1334 /* Should not fail */
1335 demux2_Control( p_input->input.p_demux, DEMUX_GET_POSITION, &f_pos );
1336 f_pos += val.f_float;
1338 if( f_pos < 0.0 ) f_pos = 0.0;
1339 if( f_pos > 1.0 ) f_pos = 1.0;
1340 if( demux2_Control( p_input->input.p_demux, DEMUX_SET_POSITION, f_pos ) )
1342 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) %2.1f%% failed",
1347 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1348 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1349 b_force_update = VLC_TRUE;
1354 case INPUT_CONTROL_SET_TIME:
1355 case INPUT_CONTROL_SET_TIME_OFFSET:
1360 if( i_type == INPUT_CONTROL_SET_TIME )
1362 i_time = val.i_time;
1366 /* Should not fail */
1367 demux2_Control( p_input->input.p_demux,
1368 DEMUX_GET_TIME, &i_time );
1369 i_time += val.i_time;
1371 if( i_time < 0 ) i_time = 0;
1372 i_ret = demux2_Control( p_input->input.p_demux,
1373 DEMUX_SET_TIME, i_time );
1377 /* Emulate it with a SET_POS */
1379 demux2_Control( p_input->input.p_demux,
1380 DEMUX_GET_LENGTH, &i_length );
1383 double f_pos = (double)i_time / (double)i_length;
1384 i_ret = demux2_Control( p_input->input.p_demux,
1385 DEMUX_SET_POSITION, f_pos );
1390 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) %lld failed",
1395 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1397 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1398 b_force_update = VLC_TRUE;
1403 case INPUT_CONTROL_SET_STATE:
1404 if( ( val.i_int == PLAYING_S && p_input->i_state == PAUSE_S ) ||
1405 ( val.i_int == PAUSE_S && p_input->i_state == PAUSE_S ) )
1408 if( p_input->input.p_access )
1409 i_ret = access2_Control( p_input->input.p_access,
1410 ACCESS_SET_PAUSE_STATE, VLC_FALSE );
1412 i_ret = demux2_Control( p_input->input.p_demux,
1413 DEMUX_SET_PAUSE_STATE, VLC_FALSE );
1417 /* FIXME What to do ? */
1418 msg_Warn( p_input, "cannot unset pause -> EOF" );
1419 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1422 b_force_update = VLC_TRUE;
1424 /* Switch to play */
1425 p_input->i_state = PLAYING_S;
1426 val.i_int = PLAYING_S;
1427 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1430 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1432 else if( val.i_int == PAUSE_S && p_input->i_state == PLAYING_S && p_input->b_can_pause )
1435 if( p_input->input.p_access )
1436 i_ret = access2_Control( p_input->input.p_access,
1437 ACCESS_SET_PAUSE_STATE, VLC_TRUE );
1439 i_ret = demux2_Control( p_input->input.p_demux,
1440 DEMUX_SET_PAUSE_STATE, VLC_TRUE );
1442 b_force_update = VLC_TRUE;
1446 msg_Warn( p_input, "cannot set pause state" );
1447 val.i_int = p_input->i_state;
1451 val.i_int = PAUSE_S;
1454 /* Switch to new state */
1455 p_input->i_state = val.i_int;
1456 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1458 else if( val.i_int == PAUSE_S && !p_input->b_can_pause )
1460 b_force_update = VLC_TRUE;
1462 /* Correct "state" value */
1463 val.i_int = p_input->i_state;
1464 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1466 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1468 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1472 case INPUT_CONTROL_SET_RATE:
1473 case INPUT_CONTROL_SET_RATE_SLOWER:
1474 case INPUT_CONTROL_SET_RATE_FASTER:
1478 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1479 i_rate = p_input->i_rate * 2;
1480 else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
1481 i_rate = p_input->i_rate / 2;
1485 if( i_rate < INPUT_RATE_MIN )
1487 msg_Dbg( p_input, "cannot set rate faster" );
1488 i_rate = INPUT_RATE_MIN;
1490 else if( i_rate > INPUT_RATE_MAX )
1492 msg_Dbg( p_input, "cannot set rate slower" );
1493 i_rate = INPUT_RATE_MAX;
1495 if( i_rate != INPUT_RATE_DEFAULT &&
1496 ( !p_input->b_can_pace_control || !p_input->b_out_pace_control ) )
1498 msg_Dbg( p_input, "cannot change rate" );
1499 i_rate = INPUT_RATE_DEFAULT;
1501 if( i_rate != p_input->i_rate )
1503 p_input->i_rate = i_rate;
1505 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
1507 /* We haven't send data to decoder when rate != default */
1508 if( i_rate == INPUT_RATE_DEFAULT )
1509 input_EsOutDiscontinuity( p_input->p_es_out, VLC_TRUE );
1512 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1514 b_force_update = VLC_TRUE;
1519 case INPUT_CONTROL_SET_PROGRAM:
1520 /* No need to force update, es_out does it if needed */
1521 es_out_Control( p_input->p_es_out,
1522 ES_OUT_SET_GROUP, val.i_int );
1525 case INPUT_CONTROL_SET_ES:
1526 /* No need to force update, es_out does it if needed */
1527 es_out_Control( p_input->p_es_out,
1528 ES_OUT_SET_ES, input_EsOutGetFromID( p_input->p_es_out, val.i_int ) );
1531 case INPUT_CONTROL_SET_TITLE:
1532 case INPUT_CONTROL_SET_TITLE_NEXT:
1533 case INPUT_CONTROL_SET_TITLE_PREV:
1534 if( p_input->input.b_title_demux &&
1535 p_input->input.i_title > 0 )
1538 /* FIXME handle demux title */
1539 demux_t *p_demux = p_input->input.p_demux;
1542 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1543 i_title = p_demux->info.i_title - 1;
1544 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1545 i_title = p_demux->info.i_title + 1;
1547 i_title = val.i_int;
1549 if( i_title >= 0 && i_title < p_input->input.i_title )
1551 demux2_Control( p_demux, DEMUX_SET_TITLE, i_title );
1553 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1554 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1556 input_ControlVarTitle( p_input, i_title );
1559 else if( p_input->input.i_title > 0 )
1561 access_t *p_access = p_input->input.p_access;
1564 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1565 i_title = p_access->info.i_title - 1;
1566 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1567 i_title = p_access->info.i_title + 1;
1569 i_title = val.i_int;
1571 if( i_title >= 0 && i_title < p_input->input.i_title )
1573 access2_Control( p_access, ACCESS_SET_TITLE, i_title );
1574 stream_AccessReset( p_input->input.p_stream );
1576 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1577 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1581 case INPUT_CONTROL_SET_SEEKPOINT:
1582 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1583 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1584 if( p_input->input.b_title_demux &&
1585 p_input->input.i_title > 0 )
1587 demux_t *p_demux = p_input->input.p_demux;
1590 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1591 i_seekpoint = p_demux->info.i_seekpoint - 1;
1592 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1593 i_seekpoint = p_demux->info.i_seekpoint + 1;
1595 i_seekpoint = val.i_int;
1597 if( i_seekpoint >= 0 &&
1598 i_seekpoint < p_input->input.title[p_demux->info.i_title]->i_seekpoint )
1600 demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1602 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1603 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1606 else if( p_input->input.i_title > 0 )
1608 access_t *p_access = p_input->input.p_access;
1611 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1612 i_seekpoint = p_access->info.i_seekpoint - 1;
1613 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1614 i_seekpoint = p_access->info.i_seekpoint + 1;
1616 i_seekpoint = val.i_int;
1618 if( i_seekpoint >= 0 &&
1619 i_seekpoint < p_input->input.title[p_access->info.i_title]->i_seekpoint )
1621 access2_Control( p_access, ACCESS_SET_SEEKPOINT, i_seekpoint );
1622 stream_AccessReset( p_input->input.p_stream );
1624 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1625 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1630 case INPUT_CONTROL_SET_BOOKMARK:
1632 msg_Err( p_input, "not yet implemented" );
1636 return b_force_update;
1639 /*****************************************************************************
1641 *****************************************************************************/
1642 static void UpdateFromDemux( input_thread_t *p_input )
1644 demux_t *p_demux = p_input->input.p_demux;
1647 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
1649 v.i_int = p_demux->info.i_title;
1650 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1652 input_ControlVarTitle( p_input, p_demux->info.i_title );
1654 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
1656 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
1658 v.i_int = p_demux->info.i_seekpoint;
1659 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1661 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1663 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
1666 /*****************************************************************************
1668 *****************************************************************************/
1669 static void UpdateFromAccess( input_thread_t *p_input )
1671 access_t *p_access = p_input->input.p_access;
1674 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
1676 v.i_int = p_access->info.i_title;
1677 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1679 input_ControlVarTitle( p_input, p_access->info.i_title );
1681 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
1683 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
1685 v.i_int = p_access->info.i_seekpoint;
1686 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1688 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1690 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
1693 /*****************************************************************************
1694 * DecodeUrl: decode a given encoded url
1695 *****************************************************************************/
1696 static void DecodeUrl( char *psz )
1698 char *dup = strdup( psz );
1716 *psz++ = strtol( val, NULL, 16 );
1718 else if( *p == '+' )
1732 /*****************************************************************************
1733 * ParseOption: parses the options for the input
1734 *****************************************************************************
1735 * This function parses the input (config) options and creates their associated
1737 * Options are of the form "[no[-]]foo[=bar]" where foo is the option name and
1738 * bar is the value of the option.
1739 *****************************************************************************/
1740 static void ParseOption( input_thread_t *p_input, const char *psz_option )
1742 char *psz_name = (char *)psz_option;
1743 char *psz_value = strchr( psz_option, '=' );
1744 int i_name_len, i_type;
1745 vlc_bool_t b_isno = VLC_FALSE;
1748 if( psz_value ) i_name_len = psz_value - psz_option;
1749 else i_name_len = strlen( psz_option );
1751 /* It's too much of an hassle to remove the ':' when we parse
1752 * the cmd line :) */
1753 if( i_name_len && *psz_name == ':' )
1759 if( i_name_len == 0 ) return;
1761 psz_name = strndup( psz_name, i_name_len );
1762 if( psz_value ) psz_value++;
1764 i_type = config_GetType( p_input, psz_name );
1766 if( !i_type && !psz_value )
1768 /* check for "no-foo" or "nofoo" */
1769 if( !strncmp( psz_name, "no-", 3 ) )
1771 memmove( psz_name, psz_name + 3, strlen(psz_name) + 1 - 3 );
1773 else if( !strncmp( psz_name, "no", 2 ) )
1775 memmove( psz_name, psz_name + 2, strlen(psz_name) + 1 - 2 );
1777 else goto cleanup; /* Option doesn't exist */
1780 i_type = config_GetType( p_input, psz_name );
1782 if( !i_type ) goto cleanup; /* Option doesn't exist */
1784 else if( !i_type ) goto cleanup; /* Option doesn't exist */
1786 if( ( i_type != VLC_VAR_BOOL ) &&
1787 ( !psz_value || !*psz_value ) ) goto cleanup; /* Invalid value */
1789 /* Create the variable in the input object.
1790 * Children of the input object will be able to retreive this value
1791 * thanks to the inheritance property of the object variables. */
1792 var_Create( p_input, psz_name, i_type );
1797 val.b_bool = !b_isno;
1800 case VLC_VAR_INTEGER:
1801 val.i_int = atoi( psz_value );
1805 val.f_float = atof( psz_value );
1808 case VLC_VAR_STRING:
1809 case VLC_VAR_MODULE:
1811 case VLC_VAR_DIRECTORY:
1812 val.psz_string = psz_value;
1820 var_Set( p_input, psz_name, val );
1822 msg_Dbg( p_input, "set input option: %s to %s", psz_name, psz_value );
1825 if( psz_name ) free( psz_name );