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 * );
62 static void MRLSplit( input_thread_t *, char *, char **, char **, char ** );
64 static input_source_t *InputSourceNew( input_thread_t *);
65 static int InputSourceInit( input_thread_t *, input_source_t *,
66 char *, char *psz_forced_demux );
67 static void InputSourceClean( input_thread_t *, input_source_t * );
69 static void SlaveDemux( input_thread_t *p_input );
70 static void SlaveSeek( input_thread_t *p_input );
72 static vlc_meta_t *InputMetaUser( input_thread_t *p_input );
74 /*****************************************************************************
75 * input_CreateThread: creates a new input thread
76 *****************************************************************************
77 * This function creates a new input, and returns a pointer
78 * to its description. On error, it returns NULL.
80 * Variables for _public_ use:
83 * - rate,rate-slower, rate-faster
84 * - position, position-offset
86 * - title,title-next,title-prev
87 * - chapter,chapter-next, chapter-prev
88 * - program, audio-es, video-es, spu-es
89 * - audio-delay, spu-delay
94 * - seekable (if you can seek, it doesn't say if 'bar display' has be shown or not, for that check position != 0.0)
95 * * For intf callback upon changes
97 * TODO explain when Callback is called
98 * TODO complete this list (?)
99 *****************************************************************************/
100 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
101 input_item_t *p_item )
104 input_thread_t *p_input; /* thread descriptor */
107 /* Allocate descriptor */
108 p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
109 if( p_input == NULL )
111 msg_Err( p_parent, "out of memory" );
115 /* Init Common fields */
116 p_input->b_eof = VLC_FALSE;
117 p_input->b_can_pace_control = VLC_TRUE;
118 p_input->i_start = 0;
121 p_input->i_title = 0;
122 p_input->title = NULL;
123 p_input->i_state = INIT_S;
124 p_input->i_rate = INPUT_RATE_DEFAULT;
125 p_input->i_bookmark = 0;
126 p_input->bookmark = NULL;
127 p_input->p_es_out = NULL;
128 p_input->p_sout = NULL;
129 p_input->b_out_pace_control = VLC_FALSE;
130 p_input->i_pts_delay = 0;
133 /* Init Input fields */
134 p_input->input.p_item = p_item;
135 p_input->input.p_access = NULL;
136 p_input->input.p_stream = NULL;
137 p_input->input.p_demux = NULL;
138 p_input->input.b_title_demux = VLC_FALSE;
139 p_input->input.i_title = 0;
140 p_input->input.title = NULL;
141 p_input->input.b_can_pace_control = VLC_TRUE;
142 p_input->input.b_eof = VLC_FALSE;
143 p_input->input.i_cr_average = 0;
146 p_input->i_slave = 0;
147 p_input->slave = NULL;
149 /* Init control buffer */
150 vlc_mutex_init( p_input, &p_input->lock_control );
151 p_input->i_control = 0;
153 /* Parse input options */
154 vlc_mutex_lock( &p_item->lock );
155 for( i = 0; i < p_item->i_options; i++ )
157 msg_Dbg( p_input, "option: %s", p_item->ppsz_options[i] );
158 ParseOption( p_input, p_item->ppsz_options[i] );
160 vlc_mutex_unlock( &p_item->lock );
162 /* Create Object Variables for private use only */
163 input_ConfigVarInit( p_input );
165 /* Create Objects variables for public Get and Set */
166 input_ControlVarInit( p_input );
167 p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
171 var_Get( p_input, "bookmarks", &val );
174 /* FIXME: have a common cfg parsing routine used by sout and others */
175 char *psz_parser, *psz_start, *psz_end;
176 psz_parser = val.psz_string;
177 while( (psz_start = strchr( psz_parser, '{' ) ) )
179 seekpoint_t seekpoint;
182 psz_end = strchr( psz_start, '}' );
183 if( !psz_end ) break;
184 psz_parser = psz_end + 1;
185 backup = *psz_parser;
189 seekpoint.psz_name = 0;
190 seekpoint.i_byte_offset = 0;
191 seekpoint.i_time_offset = 0;
192 while( (psz_end = strchr( psz_start, ',' ) ) )
195 if( !strncmp( psz_start, "name=", 5 ) )
197 seekpoint.psz_name = psz_start + 5;
199 else if( !strncmp( psz_start, "bytes=", 6 ) )
201 seekpoint.i_byte_offset = atoll(psz_start + 6);
203 else if( !strncmp( psz_start, "time=", 5 ) )
205 seekpoint.i_time_offset = atoll(psz_start + 5) * 1000000;
207 psz_start = psz_end + 1;
209 msg_Dbg( p_input, "adding bookmark: %s, bytes="I64Fd", time="I64Fd,
210 seekpoint.psz_name, seekpoint.i_byte_offset,
211 seekpoint.i_time_offset );
212 input_Control( p_input, INPUT_ADD_BOOKMARK, &seekpoint );
213 *psz_parser = backup;
215 free( val.psz_string );
219 /* Now we can attach our new input */
220 vlc_object_attach( p_input, p_parent );
222 /* Create thread and wait for its readiness. */
223 if( vlc_thread_create( p_input, "input", Run,
224 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
226 msg_Err( p_input, "cannot create input thread" );
227 vlc_object_detach( p_input );
228 vlc_object_destroy( p_input );
235 /*****************************************************************************
236 * input_StopThread: mark an input thread as zombie
237 *****************************************************************************
238 * This function should not return until the thread is effectively cancelled.
239 *****************************************************************************/
240 void input_StopThread( input_thread_t *p_input )
245 /* Set die for input */
246 p_input->b_die = VLC_TRUE;
248 /* We cannot touch p_input fields directly (we can from another thread),
249 * so use the vlc_object_find way, it's perfectly safe */
251 /* Set die for all access */
252 p_list = vlc_list_find( p_input, VLC_OBJECT_ACCESS, 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 /* Set die for all stream */
260 p_list = vlc_list_find( p_input, VLC_OBJECT_STREAM, FIND_CHILD );
261 for( i = 0; i < p_list->i_count; i++ )
263 p_list->p_values[i].p_object->b_die = VLC_TRUE;
265 vlc_list_release( p_list );
267 /* Set die for all demux */
268 p_list = vlc_list_find( p_input, VLC_OBJECT_DEMUX, FIND_CHILD );
269 for( i = 0; i < p_list->i_count; i++ )
271 p_list->p_values[i].p_object->b_die = VLC_TRUE;
273 vlc_list_release( p_list );
275 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
278 /*****************************************************************************
279 * input_DestroyThread: mark an input thread as zombie
280 *****************************************************************************
281 * This function should not return until the thread is effectively cancelled.
282 *****************************************************************************/
283 void input_DestroyThread( input_thread_t *p_input )
285 /* Join the thread */
286 vlc_thread_join( p_input );
288 /* Delete input lock (only after thread joined) */
289 vlc_mutex_destroy( &p_input->lock_control );
291 /* TODO: maybe input_DestroyThread should also delete p_input instead
292 * of the playlist but I'm not sure if it's possible */
295 /*****************************************************************************
296 * Run: main thread loop
297 *****************************************************************************
298 * Thread in charge of processing the network packets and demultiplexing.
301 * read subtitle support (XXX take care of spu-delay in the right way).
302 * multi-input support (XXX may be done with subs)
303 *****************************************************************************/
304 static int Run( input_thread_t *p_input )
306 int64_t i_intf_update = 0;
308 /* Signal that the thread is launched */
309 vlc_thread_ready( p_input );
311 if( Init( p_input ) )
313 /* If we failed, wait before we are killed, and exit */
314 p_input->b_error = VLC_TRUE;
318 /* Tell we're dead */
319 p_input->b_dead = VLC_TRUE;
325 while( !p_input->b_die && !p_input->b_error && !p_input->input.b_eof )
327 vlc_bool_t b_force_update = VLC_FALSE;
333 if( p_input->i_state != PAUSE_S )
335 if( p_input->i_stop <= 0 || p_input->i_time < p_input->i_stop )
336 i_ret=p_input->input.p_demux->pf_demux(p_input->input.p_demux);
343 if( p_input->input.b_title_demux &&
344 p_input->input.p_demux->info.i_update )
346 UpdateFromDemux( p_input );
347 b_force_update = VLC_TRUE;
349 else if( !p_input->input.b_title_demux &&
350 p_input->input.p_access &&
351 p_input->input.p_access->info.i_update )
353 UpdateFromAccess( p_input );
354 b_force_update = VLC_TRUE;
357 else if( i_ret == 0 ) /* EOF */
361 var_Get( p_input, "input-repeat", &repeat );
362 if( repeat.i_int == 0 )
364 /* End of file - we do not set b_die because only the
365 * playlist is allowed to do so. */
366 msg_Dbg( p_input, "EOF reached" );
367 p_input->input.b_eof = VLC_TRUE;
371 msg_Dbg( p_input, "repeating the same input (%d)",
373 if( repeat.i_int > 0 )
376 var_Set( p_input, "input-repeat", repeat );
379 /* Seek to title 0 position 0(start) */
381 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
382 if( p_input->i_start > 0 )
384 val.i_time = p_input->i_start;
385 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
391 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
398 p_input->b_error = VLC_TRUE;
401 if( i_ret > 0 && p_input->i_slave > 0 )
403 SlaveDemux( p_input );
413 vlc_mutex_lock( &p_input->lock_control );
414 ControlReduce( p_input );
415 while( !ControlPopNoLock( p_input, &i_type, &val ) )
417 msg_Dbg( p_input, "control type=%d", i_type );
418 if( Control( p_input, i_type, val ) )
419 b_force_update = VLC_TRUE;
421 vlc_mutex_unlock( &p_input->lock_control );
423 if( b_force_update ||
424 i_intf_update < mdate() )
428 int64_t i_time, i_length;
429 /* update input status variables */
430 if( !demux2_Control( p_input->input.p_demux,
431 DEMUX_GET_POSITION, &f_pos ) )
433 val.f_float = (float)f_pos;
434 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
436 if( !demux2_Control( p_input->input.p_demux,
437 DEMUX_GET_TIME, &i_time ) )
439 p_input->i_time = i_time;
441 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
443 if( !demux2_Control( p_input->input.p_demux,
444 DEMUX_GET_LENGTH, &i_length ) )
447 var_Get( p_input, "length", &old_val );
448 val.i_time = i_length;
449 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
451 if( old_val.i_time != val.i_time )
453 char psz_buffer[MSTRTIME_MAX_SIZE];
455 vlc_mutex_lock( &p_input->input.p_item->lock );
456 p_input->input.p_item->i_duration = i_length;
457 vlc_mutex_unlock( &p_input->input.p_item->lock );
459 input_Control( p_input, INPUT_ADD_INFO,
460 _("General"), _("Duration"),
461 msecstotimestr( psz_buffer, i_length / 1000 ) );
465 var_SetBool( p_input, "intf-change", VLC_TRUE );
466 i_intf_update = mdate() + I64C(150000);
470 if( !p_input->b_eof && !p_input->b_error && p_input->input.b_eof )
472 /* We have finish to demux data but not to play them */
473 while( !p_input->b_die )
475 if( input_EsOutDecodersEmpty( p_input->p_es_out ) )
478 msg_Dbg( p_input, "waiting decoder fifos to empty" );
480 msleep( INPUT_IDLE_SLEEP );
483 /* We have finished */
484 p_input->b_eof = VLC_TRUE;
487 /* Wait we are asked to die */
488 if( !p_input->b_die )
499 /*****************************************************************************
500 * Init: init the input Thread
501 *****************************************************************************/
502 static int Init( input_thread_t * p_input )
508 vlc_meta_t *p_meta, *p_meta_user;
511 /* Initialize optional stream output. (before access/demuxer) */
512 psz = var_GetString( p_input, "sout" );
515 p_input->p_sout = sout_NewInstance( p_input, psz );
516 if( p_input->p_sout == NULL )
518 msg_Err( p_input, "cannot start stream output instance, aborting" );
526 p_input->p_es_out = input_EsOutNew( p_input );
527 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
528 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
530 if( InputSourceInit( p_input, &p_input->input,
531 p_input->input.p_item->psz_uri, NULL ) )
536 /* Create global title (from master) */
537 p_input->i_title = p_input->input.i_title;
538 p_input->title = p_input->input.title;
539 if( p_input->i_title > 0 )
541 /* Setup variables */
542 input_ControlVarNavigation( p_input );
543 input_ControlVarTitle( p_input, 0 );
547 p_input->b_can_pace_control = p_input->input.b_can_pace_control;
548 p_input->b_can_pause = p_input->input.b_can_pause;
551 if( p_input->i_pts_delay <= 0 )
552 p_input->i_pts_delay = DEFAULT_PTS_DELAY;
554 /* If the desynchronisation requested by the user is < 0, we need to
555 * cache more data. */
556 var_Get( p_input, "audio-desync", &val );
558 p_input->i_pts_delay -= (val.i_int * 1000);
560 /* Load master infos */
562 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_LENGTH,
563 &val.i_time ) && val.i_time > 0 )
565 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
566 /* TODO update playlist meta data */
570 p_input->i_start = (int64_t)var_GetInteger( p_input, "start-time" ) *
572 p_input->i_stop = (int64_t)var_GetInteger( p_input, "stop-time" ) *
575 if( p_input->i_start > 0 )
577 if( p_input->i_start >= val.i_time )
579 msg_Warn( p_input, "invalid start-time ignored" );
585 msg_Dbg( p_input, "start-time: %ds",
586 (int)( p_input->i_start / I64C(1000000) ) );
588 s.i_time = p_input->i_start;
589 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
592 if( p_input->i_stop > 0 && p_input->i_stop <= p_input->i_start )
594 msg_Warn( p_input, "invalid stop-time ignored" );
600 /* Get fps and set it if not already set */
601 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) &&
606 if( var_Get( p_input, "sub-fps", &fps ) )
608 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT| VLC_VAR_DOINHERIT );
609 var_SetFloat( p_input, "sub-fps", f_fps );
613 /* Look for and add subtitle files */
614 psz_subtitle = var_GetString( p_input, "sub-file" );
621 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
623 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
626 sub = InputSourceNew( p_input );
627 if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
629 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
632 if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
634 if( count.i_int == 0 )
635 count.i_int++; /* if it was first one, there is disable too */
637 if( count.i_int < list.p_list->i_count )
639 input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
640 &list.p_list->p_values[count.i_int] );
642 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
647 var_Get( p_input, "sub-autodetect-file", &val );
650 char *psz_autopath = var_GetString( p_input, "sub-autodetect-path" );
651 char **subs = subtitles_Detect( p_input, psz_autopath,
652 p_input->input.p_item->psz_uri );
655 for( i = 0; subs[i] != NULL; i++ )
657 if( strcmp( psz_subtitle, subs[i] ) )
659 sub = InputSourceNew( p_input );
660 if( !InputSourceInit( p_input, sub, subs[i], "subtitle" ) )
662 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
668 free( psz_autopath );
670 free( psz_subtitle );
673 psz = var_GetString( p_input, "input-slave" );
676 char *psz_delim = strchr( psz, '#' );
680 input_source_t *slave;
695 msg_Dbg( p_input, "adding slave '%s'", psz );
696 slave = InputSourceNew( p_input );
697 if( !InputSourceInit( p_input, slave, psz, NULL ) )
699 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
708 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
709 val.b_bool = VLC_FALSE;
710 if( p_input->p_sout )
712 var_Get( p_input, "sout-all", &val );
714 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE,
715 val.b_bool ? ES_OUT_MODE_ALL : ES_OUT_MODE_AUTO );
717 if( p_input->p_sout )
719 if( p_input->p_sout->i_out_pace_nocontrol > 0 )
721 p_input->b_out_pace_control = VLC_FALSE;
725 p_input->b_out_pace_control = VLC_TRUE;
727 msg_Dbg( p_input, "starting in %s mode",
728 p_input->b_out_pace_control ? "asynch" : "synch" );
731 /* Get meta data from users */
732 p_meta_user = InputMetaUser( p_input );
734 /* Get meta data from master input */
735 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_META, &p_meta ) )
741 p_meta = p_meta_user;
743 else if( p_meta_user )
745 vlc_meta_Merge( p_meta, p_meta_user );
746 vlc_meta_Delete( p_meta_user );
749 /* Get meta data from slave input */
750 for( i = 0; i < p_input->i_slave; i++ )
752 vlc_meta_t *p_meta_slave;
754 if( !demux2_Control( p_input->slave[i]->p_demux, DEMUX_GET_META, &p_meta_slave ) )
758 p_meta = p_meta_slave;
760 else if( p_meta_slave )
762 vlc_meta_Merge( p_meta, p_meta_slave );
763 vlc_meta_Delete( p_meta_slave );
768 if( p_meta && p_meta->i_meta > 0 )
770 msg_Dbg( p_input, "meta information:" );
771 for( i = 0; i < p_meta->i_meta; i++ )
773 msg_Dbg( p_input, " - '%s' = '%s'",
774 _(p_meta->name[i]), p_meta->value[i] );
776 if( !strcmp(p_meta->name[i], VLC_META_TITLE) && p_meta->value[i] )
777 input_Control( p_input, INPUT_SET_NAME, p_meta->value[i] );
779 if( !strcmp( p_meta->name[i], VLC_META_AUTHOR ) )
780 input_Control( p_input, INPUT_ADD_INFO, _("General"),
781 _("Author"), p_meta->value[i] );
783 input_Control( p_input, INPUT_ADD_INFO, _("Meta-information"),
784 _(p_meta->name[i]), "%s", p_meta->value[i] );
787 for( i = 0; i < p_meta->i_track; i++ )
789 vlc_meta_t *tk = p_meta->track[i];
794 char *psz_cat = malloc( strlen(_("Stream")) + 10 );
796 msg_Dbg( p_input, " - track[%d]:", i );
798 sprintf( psz_cat, "%s %d", _("Stream"), i );
799 for( j = 0; j < tk->i_meta; j++ )
801 msg_Dbg( p_input, " - '%s' = '%s'", _(tk->name[j]),
804 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
805 _(tk->name[j]), "%s", tk->value[j] );
810 if( p_input->p_sout && p_input->p_sout->p_meta == NULL )
812 p_input->p_sout->p_meta = p_meta;
816 vlc_meta_Delete( p_meta );
820 msg_Dbg( p_input, "`%s' sucessfully opened",
821 p_input->input.p_item->psz_uri );
823 /* initialization is complete */
824 p_input->i_state = PLAYING_S;
826 val.i_int = PLAYING_S;
827 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
832 if( p_input->p_es_out )
833 input_EsOutDelete( p_input->p_es_out );
835 if( p_input->p_sout )
836 sout_DeleteInstance( p_input->p_sout );
838 /* Mark them deleted */
839 p_input->input.p_demux = NULL;
840 p_input->input.p_stream = NULL;
841 p_input->input.p_access = NULL;
842 p_input->p_es_out = NULL;
843 p_input->p_sout = NULL;
848 /*****************************************************************************
849 * Error: RunThread() error loop
850 *****************************************************************************
851 * This function is called when an error occured during thread main's loop.
852 *****************************************************************************/
853 static void Error( input_thread_t *p_input )
855 while( !p_input->b_die )
858 msleep( INPUT_IDLE_SLEEP );
862 /*****************************************************************************
863 * End: end the input thread
864 *****************************************************************************/
865 static void End( input_thread_t * p_input )
870 msg_Dbg( p_input, "closing `%s'",
871 p_input->input.p_item->psz_uri );
873 /* We are at the end */
874 p_input->i_state = END_S;
877 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
879 /* Clean control variables */
880 input_ControlVarClean( p_input );
882 /* Clean up master */
883 InputSourceClean( p_input, &p_input->input );
886 for( i = 0; i < p_input->i_slave; i++ )
888 InputSourceClean( p_input, p_input->slave[i] );
889 free( p_input->slave[i] );
891 if( p_input->slave ) free( p_input->slave );
893 /* Unload all modules */
894 if( p_input->p_es_out )
895 input_EsOutDelete( p_input->p_es_out );
897 /* Close optional stream output instance */
898 if( p_input->p_sout )
901 vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
904 if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
906 /* attach sout to the playlist */
907 msg_Warn( p_input, "keeping sout" );
908 vlc_object_detach( p_input->p_sout );
909 vlc_object_attach( p_input->p_sout, p_pl );
913 msg_Warn( p_input, "destroying sout" );
914 sout_DeleteInstance( p_input->p_sout );
917 vlc_object_release( p_pl );
920 /* Tell we're dead */
921 p_input->b_dead = VLC_TRUE;
924 /*****************************************************************************
926 *****************************************************************************/
927 static inline int ControlPopNoLock( input_thread_t *p_input,
928 int *pi_type, vlc_value_t *p_val )
930 if( p_input->i_control <= 0 )
935 *pi_type = p_input->control[0].i_type;
936 *p_val = p_input->control[0].val;
938 p_input->i_control--;
939 if( p_input->i_control > 0 )
943 for( i = 0; i < p_input->i_control; i++ )
945 p_input->control[i].i_type = p_input->control[i+1].i_type;
946 p_input->control[i].val = p_input->control[i+1].val;
953 static void ControlReduce( input_thread_t *p_input )
956 for( i = 1; i < p_input->i_control; i++ )
958 const int i_lt = p_input->control[i-1].i_type;
959 const int i_ct = p_input->control[i].i_type;
961 /* XXX We can't merge INPUT_CONTROL_SET_ES */
962 msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->i_control,
965 ( i_ct == INPUT_CONTROL_SET_STATE ||
966 i_ct == INPUT_CONTROL_SET_RATE ||
967 i_ct == INPUT_CONTROL_SET_POSITION ||
968 i_ct == INPUT_CONTROL_SET_TIME ||
969 i_ct == INPUT_CONTROL_SET_PROGRAM ||
970 i_ct == INPUT_CONTROL_SET_TITLE ||
971 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
972 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
975 msg_Dbg( p_input, "merged at %d", i );
977 for( j = i; j < p_input->i_control; j++ )
978 p_input->control[j-1] = p_input->control[j];
979 p_input->i_control--;
983 /* TODO but that's not that important
984 - merge SET_X with SET_X_CMD
985 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
986 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
993 static vlc_bool_t Control( input_thread_t *p_input, int i_type,
996 vlc_bool_t b_force_update = VLC_FALSE;
1000 case INPUT_CONTROL_SET_DIE:
1001 msg_Dbg( p_input, "control: INPUT_CONTROL_SET_DIE proceed" );
1002 /* Mark all submodules to die */
1003 if( p_input->input.p_access )
1004 p_input->input.p_access->b_die = VLC_TRUE;
1005 if( p_input->input.p_stream )
1006 p_input->input.p_stream->b_die = VLC_TRUE;
1007 p_input->input.p_demux->b_die = VLC_TRUE;
1009 p_input->b_die = VLC_TRUE;
1012 case INPUT_CONTROL_SET_POSITION:
1013 case INPUT_CONTROL_SET_POSITION_OFFSET:
1016 if( i_type == INPUT_CONTROL_SET_POSITION )
1018 f_pos = val.f_float;
1022 /* Should not fail */
1023 demux2_Control( p_input->input.p_demux,
1024 DEMUX_GET_POSITION, &f_pos );
1025 f_pos += val.f_float;
1027 if( f_pos < 0.0 ) f_pos = 0.0;
1028 if( f_pos > 1.0 ) f_pos = 1.0;
1029 if( demux2_Control( p_input->input.p_demux, DEMUX_SET_POSITION,
1032 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1033 "%2.1f%% failed", f_pos * 100 );
1037 if( p_input->i_slave > 0 )
1038 SlaveSeek( p_input );
1040 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1041 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1042 b_force_update = VLC_TRUE;
1047 case INPUT_CONTROL_SET_TIME:
1048 case INPUT_CONTROL_SET_TIME_OFFSET:
1053 if( i_type == INPUT_CONTROL_SET_TIME )
1055 i_time = val.i_time;
1059 /* Should not fail */
1060 demux2_Control( p_input->input.p_demux,
1061 DEMUX_GET_TIME, &i_time );
1062 i_time += val.i_time;
1064 if( i_time < 0 ) i_time = 0;
1065 i_ret = demux2_Control( p_input->input.p_demux,
1066 DEMUX_SET_TIME, i_time );
1070 /* Emulate it with a SET_POS */
1072 demux2_Control( p_input->input.p_demux,
1073 DEMUX_GET_LENGTH, &i_length );
1076 double f_pos = (double)i_time / (double)i_length;
1077 i_ret = demux2_Control( p_input->input.p_demux,
1078 DEMUX_SET_POSITION, f_pos );
1083 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) "I64Fd
1084 " failed", i_time );
1088 if( p_input->i_slave > 0 )
1089 SlaveSeek( p_input );
1091 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1093 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1094 b_force_update = VLC_TRUE;
1099 case INPUT_CONTROL_SET_STATE:
1100 if( ( val.i_int == PLAYING_S && p_input->i_state == PAUSE_S ) ||
1101 ( val.i_int == PAUSE_S && p_input->i_state == PAUSE_S ) )
1104 if( p_input->input.p_access )
1105 i_ret = access2_Control( p_input->input.p_access,
1106 ACCESS_SET_PAUSE_STATE, VLC_FALSE );
1108 i_ret = demux2_Control( p_input->input.p_demux,
1109 DEMUX_SET_PAUSE_STATE, VLC_FALSE );
1113 /* FIXME What to do ? */
1114 msg_Warn( p_input, "cannot unset pause -> EOF" );
1115 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1118 b_force_update = VLC_TRUE;
1120 /* Switch to play */
1121 p_input->i_state = PLAYING_S;
1122 val.i_int = PLAYING_S;
1123 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1126 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1128 else if( val.i_int == PAUSE_S && p_input->i_state == PLAYING_S &&
1129 p_input->b_can_pause )
1132 if( p_input->input.p_access )
1133 i_ret = access2_Control( p_input->input.p_access,
1134 ACCESS_SET_PAUSE_STATE, VLC_TRUE );
1136 i_ret = demux2_Control( p_input->input.p_demux,
1137 DEMUX_SET_PAUSE_STATE, VLC_TRUE );
1139 b_force_update = VLC_TRUE;
1143 msg_Warn( p_input, "cannot set pause state" );
1144 val.i_int = p_input->i_state;
1148 val.i_int = PAUSE_S;
1151 /* Switch to new state */
1152 p_input->i_state = val.i_int;
1153 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1155 else if( val.i_int == PAUSE_S && !p_input->b_can_pause )
1157 b_force_update = VLC_TRUE;
1159 /* Correct "state" value */
1160 val.i_int = p_input->i_state;
1161 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1163 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1165 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1169 case INPUT_CONTROL_SET_RATE:
1170 case INPUT_CONTROL_SET_RATE_SLOWER:
1171 case INPUT_CONTROL_SET_RATE_FASTER:
1175 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1176 i_rate = p_input->i_rate * 2;
1177 else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
1178 i_rate = p_input->i_rate / 2;
1182 if( i_rate < INPUT_RATE_MIN )
1184 msg_Dbg( p_input, "cannot set rate faster" );
1185 i_rate = INPUT_RATE_MIN;
1187 else if( i_rate > INPUT_RATE_MAX )
1189 msg_Dbg( p_input, "cannot set rate slower" );
1190 i_rate = INPUT_RATE_MAX;
1192 if( i_rate != INPUT_RATE_DEFAULT &&
1193 ( !p_input->b_can_pace_control ||
1194 !p_input->b_out_pace_control ) )
1196 msg_Dbg( p_input, "cannot change rate" );
1197 i_rate = INPUT_RATE_DEFAULT;
1199 if( i_rate != p_input->i_rate )
1201 p_input->i_rate = i_rate;
1203 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
1205 /* We haven't send data to decoder when rate != default */
1206 if( i_rate == INPUT_RATE_DEFAULT )
1207 input_EsOutDiscontinuity( p_input->p_es_out, VLC_TRUE );
1210 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1212 b_force_update = VLC_TRUE;
1217 case INPUT_CONTROL_SET_PROGRAM:
1218 /* No need to force update, es_out does it if needed */
1219 es_out_Control( p_input->p_es_out,
1220 ES_OUT_SET_GROUP, val.i_int );
1223 case INPUT_CONTROL_SET_ES:
1224 /* No need to force update, es_out does it if needed */
1225 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
1226 input_EsOutGetFromID( p_input->p_es_out,
1230 case INPUT_CONTROL_SET_AUDIO_DELAY:
1231 input_EsOutSetDelay( p_input->p_es_out,
1232 AUDIO_ES, val.i_time );
1233 var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
1236 case INPUT_CONTROL_SET_SPU_DELAY:
1237 input_EsOutSetDelay( p_input->p_es_out,
1238 SPU_ES, val.i_time );
1239 var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
1242 case INPUT_CONTROL_SET_TITLE:
1243 case INPUT_CONTROL_SET_TITLE_NEXT:
1244 case INPUT_CONTROL_SET_TITLE_PREV:
1245 if( p_input->input.b_title_demux &&
1246 p_input->input.i_title > 0 )
1249 /* FIXME handle demux title */
1250 demux_t *p_demux = p_input->input.p_demux;
1253 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1254 i_title = p_demux->info.i_title - 1;
1255 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1256 i_title = p_demux->info.i_title + 1;
1258 i_title = val.i_int;
1260 if( i_title >= 0 && i_title < p_input->input.i_title )
1262 demux2_Control( p_demux, DEMUX_SET_TITLE, i_title );
1264 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1265 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1267 input_ControlVarTitle( p_input, i_title );
1270 else if( p_input->input.i_title > 0 )
1272 access_t *p_access = p_input->input.p_access;
1275 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1276 i_title = p_access->info.i_title - 1;
1277 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1278 i_title = p_access->info.i_title + 1;
1280 i_title = val.i_int;
1282 if( i_title >= 0 && i_title < p_input->input.i_title )
1284 access2_Control( p_access, ACCESS_SET_TITLE, i_title );
1285 stream_AccessReset( p_input->input.p_stream );
1287 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1288 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1292 case INPUT_CONTROL_SET_SEEKPOINT:
1293 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1294 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1295 if( p_input->input.b_title_demux &&
1296 p_input->input.i_title > 0 )
1298 demux_t *p_demux = p_input->input.p_demux;
1301 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1302 i_seekpoint = p_demux->info.i_seekpoint - 1;
1303 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1304 i_seekpoint = p_demux->info.i_seekpoint + 1;
1306 i_seekpoint = val.i_int;
1308 if( i_seekpoint >= 0 && i_seekpoint <
1309 p_input->input.title[p_demux->info.i_title]->i_seekpoint )
1311 demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1313 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1314 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1317 else if( p_input->input.i_title > 0 )
1319 access_t *p_access = p_input->input.p_access;
1322 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1323 i_seekpoint = p_access->info.i_seekpoint - 1;
1324 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1325 i_seekpoint = p_access->info.i_seekpoint + 1;
1327 i_seekpoint = val.i_int;
1329 if( i_seekpoint >= 0 && i_seekpoint <
1330 p_input->input.title[p_access->info.i_title]->i_seekpoint )
1332 access2_Control( p_access, ACCESS_SET_SEEKPOINT, i_seekpoint );
1333 stream_AccessReset( p_input->input.p_stream );
1335 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1336 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1341 case INPUT_CONTROL_SET_BOOKMARK:
1343 msg_Err( p_input, "not yet implemented" );
1347 return b_force_update;
1350 /*****************************************************************************
1352 *****************************************************************************/
1353 static void UpdateFromDemux( input_thread_t *p_input )
1355 demux_t *p_demux = p_input->input.p_demux;
1358 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
1360 v.i_int = p_demux->info.i_title;
1361 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1363 input_ControlVarTitle( p_input, p_demux->info.i_title );
1365 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
1367 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
1369 v.i_int = p_demux->info.i_seekpoint;
1370 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1372 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1374 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
1377 /*****************************************************************************
1379 *****************************************************************************/
1380 static void UpdateFromAccess( input_thread_t *p_input )
1382 access_t *p_access = p_input->input.p_access;
1385 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
1387 v.i_int = p_access->info.i_title;
1388 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1390 input_ControlVarTitle( p_input, p_access->info.i_title );
1392 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
1394 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
1396 v.i_int = p_access->info.i_seekpoint;
1397 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1399 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1401 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
1404 /*****************************************************************************
1406 *****************************************************************************/
1407 static input_source_t *InputSourceNew( input_thread_t *p_input )
1409 input_source_t *in = malloc( sizeof( input_source_t ) );
1412 in->p_access = NULL;
1413 in->p_stream = NULL;
1415 in->b_title_demux = VLC_FALSE;
1418 in->b_can_pace_control = VLC_TRUE;
1419 in->b_eof = VLC_FALSE;
1420 in->i_cr_average = 0;
1425 /*****************************************************************************
1427 *****************************************************************************/
1428 static int InputSourceInit( input_thread_t *p_input,
1429 input_source_t *in, char *psz_mrl,
1430 char *psz_forced_demux )
1432 char *psz_dup = strdup( psz_mrl );
1439 MRLSplit( p_input, psz_dup, &psz_access, &psz_demux, &psz_path );
1441 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
1442 psz_mrl, psz_access, psz_demux, psz_path );
1444 if( psz_forced_demux && *psz_forced_demux )
1445 psz_demux = psz_forced_demux;
1447 /* Try access_demux if no demux given */
1448 if( *psz_access && *psz_demux == '\0' )
1450 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
1451 NULL, p_input->p_es_out );
1456 int64_t i_pts_delay;
1458 /* Get infos from access_demux */
1459 demux2_Control( in->p_demux,
1460 DEMUX_GET_PTS_DELAY, &i_pts_delay );
1461 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
1463 in->b_title_demux = VLC_TRUE;
1464 if( demux2_Control( in->p_demux,
1465 DEMUX_GET_TITLE_INFO,
1466 &in->title, &in->i_title ) )
1471 demux2_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
1472 &in->b_can_pace_control );
1473 demux2_Control( in->p_demux, DEMUX_CAN_PAUSE,
1477 demux2_Control( in->p_demux, DEMUX_CAN_SEEK,
1483 int64_t i_pts_delay;
1485 /* Now try a real access */
1486 in->p_access = access2_New( p_input, psz_access, psz_demux, psz_path );
1488 /* Access failed, URL encoded ? */
1489 if( in->p_access == NULL && strchr( psz_path, '%' ) )
1491 DecodeUrl( psz_path );
1493 msg_Dbg( p_input, "retying with access `%s' demux `%s' path `%s'",
1494 psz_access, psz_demux, psz_path );
1496 in->p_access = access2_New( p_input,
1497 psz_access, psz_demux, psz_path );
1499 #ifndef WIN32 /* Remove this gross hack from the win32 build as colons
1500 * are forbidden in filenames on Win32. */
1502 /* Maybe we got something like: /Volumes/toto:titi/gabu.mpg */
1503 if( in->p_access == NULL &&
1504 *psz_access == '\0' && ( *psz_demux || *psz_path ) )
1507 psz_dup = strdup( psz_mrl );
1512 in->p_access = access2_New( p_input,
1513 psz_access, psz_demux, psz_path );
1517 if( in->p_access == NULL )
1519 msg_Err( p_input, "no suitable access module for `%s'", psz_mrl );
1523 /* Get infos from access */
1524 access2_Control( in->p_access,
1525 ACCESS_GET_PTS_DELAY, &i_pts_delay );
1526 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
1528 in->b_title_demux = VLC_FALSE;
1529 if( access2_Control( in->p_access,
1530 ACCESS_GET_TITLE_INFO,
1531 &in->title, &in->i_title ) )
1536 access2_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
1537 &in->b_can_pace_control );
1538 access2_Control( in->p_access, ACCESS_CAN_PAUSE,
1540 access2_Control( in->p_access, ACCESS_CAN_SEEK,
1542 var_Set( p_input, "seekable", val );
1544 /* Create the stream_t */
1545 in->p_stream = stream_AccessNew( in->p_access );
1546 if( in->p_stream == NULL )
1548 msg_Warn( p_input, "cannot create a stream_t from access" );
1552 /* Open a demuxer */
1553 if( *psz_demux == '\0' && *in->p_access->psz_demux )
1555 psz_demux = in->p_access->psz_demux;
1557 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
1558 in->p_stream, p_input->p_es_out );
1559 if( in->p_demux == NULL )
1561 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
1562 psz_access, psz_demux, psz_path );
1566 /* TODO get title from demux */
1567 if( in->i_title <= 0 )
1569 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
1570 &in->title, &in->i_title ) )
1577 in->b_title_demux = VLC_TRUE;
1586 demux2_Delete( in->p_demux );
1589 stream_AccessDelete( in->p_stream );
1592 access2_Delete( in->p_access );
1595 return VLC_EGENERIC;
1598 /*****************************************************************************
1600 *****************************************************************************/
1601 static void InputSourceClean( input_thread_t *p_input, input_source_t *in )
1604 demux2_Delete( in->p_demux );
1607 stream_AccessDelete( in->p_stream );
1610 access2_Delete( in->p_access );
1612 if( in->i_title > 0 )
1615 for( i = 0; i < in->i_title; i++ )
1617 vlc_input_title_Delete( in->title[i] );
1623 static void SlaveDemux( input_thread_t *p_input )
1627 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
1629 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
1633 for( i = 0; i < p_input->i_slave; i++ )
1635 input_source_t *in = p_input->slave[i];
1641 if( demux2_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
1646 if( demux2_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
1648 msg_Err( p_input, "slave[%d] doesn't like "
1649 "DEMUX_GET_TIME -> EOF", i );
1654 if( i_stime >= i_time )
1657 if( ( i_ret = in->p_demux->pf_demux( in->p_demux ) ) <= 0 )
1663 i_ret = in->p_demux->pf_demux( in->p_demux );
1668 msg_Dbg( p_input, "slave %d EOF", i );
1669 in->b_eof = VLC_TRUE;
1674 static void SlaveSeek( input_thread_t *p_input )
1679 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
1681 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
1685 for( i = 0; i < p_input->i_slave; i++ )
1687 input_source_t *in = p_input->slave[i];
1689 if( demux2_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
1691 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
1692 in->b_eof = VLC_TRUE;
1696 /*****************************************************************************
1698 *****************************************************************************/
1699 static vlc_meta_t *InputMetaUser( input_thread_t *p_input )
1704 if( ( p_meta = vlc_meta_New() ) == NULL )
1707 /* Get meta information from user */
1708 #define GET_META( c, s ) \
1709 var_Get( p_input, (s), &val ); \
1710 if( *val.psz_string ) \
1711 vlc_meta_Add( p_meta, c, val.psz_string ); \
1712 free( val.psz_string )
1714 GET_META( VLC_META_TITLE, "meta-title" );
1715 GET_META( VLC_META_AUTHOR, "meta-author" );
1716 GET_META( VLC_META_ARTIST, "meta-artist" );
1717 GET_META( VLC_META_GENRE, "meta-genre" );
1718 GET_META( VLC_META_COPYRIGHT, "meta-copyright" );
1719 GET_META( VLC_META_DESCRIPTION, "meta-description" );
1720 GET_META( VLC_META_DATE, "meta-date" );
1721 GET_META( VLC_META_URL, "meta-url" );
1727 /*****************************************************************************
1728 * DecodeUrl: decode a given encoded url
1729 *****************************************************************************/
1730 static void DecodeUrl( char *psz )
1732 char *dup = strdup( psz );
1750 *psz++ = strtol( val, NULL, 16 );
1752 else if( *p == '+' )
1766 /*****************************************************************************
1767 * ParseOption: parses the options for the input
1768 *****************************************************************************
1769 * This function parses the input (config) options and creates their associated
1771 * Options are of the form "[no[-]]foo[=bar]" where foo is the option name and
1772 * bar is the value of the option.
1773 *****************************************************************************/
1774 static void ParseOption( input_thread_t *p_input, const char *psz_option )
1776 char *psz_name = (char *)psz_option;
1777 char *psz_value = strchr( psz_option, '=' );
1778 int i_name_len, i_type;
1779 vlc_bool_t b_isno = VLC_FALSE;
1782 if( psz_value ) i_name_len = psz_value - psz_option;
1783 else i_name_len = strlen( psz_option );
1785 /* It's too much of an hassle to remove the ':' when we parse
1786 * the cmd line :) */
1787 if( i_name_len && *psz_name == ':' )
1793 if( i_name_len == 0 ) return;
1795 psz_name = strndup( psz_name, i_name_len );
1796 if( psz_value ) psz_value++;
1798 i_type = config_GetType( p_input, psz_name );
1800 if( !i_type && !psz_value )
1802 /* check for "no-foo" or "nofoo" */
1803 if( !strncmp( psz_name, "no-", 3 ) )
1805 memmove( psz_name, psz_name + 3, strlen(psz_name) + 1 - 3 );
1807 else if( !strncmp( psz_name, "no", 2 ) )
1809 memmove( psz_name, psz_name + 2, strlen(psz_name) + 1 - 2 );
1811 else goto cleanup; /* Option doesn't exist */
1814 i_type = config_GetType( p_input, psz_name );
1816 if( !i_type ) goto cleanup; /* Option doesn't exist */
1818 else if( !i_type ) goto cleanup; /* Option doesn't exist */
1820 if( ( i_type != VLC_VAR_BOOL ) &&
1821 ( !psz_value || !*psz_value ) ) goto cleanup; /* Invalid value */
1823 /* Create the variable in the input object.
1824 * Children of the input object will be able to retreive this value
1825 * thanks to the inheritance property of the object variables. */
1826 var_Create( p_input, psz_name, i_type );
1831 val.b_bool = !b_isno;
1834 case VLC_VAR_INTEGER:
1835 val.i_int = atoi( psz_value );
1839 val.f_float = atof( psz_value );
1842 case VLC_VAR_STRING:
1843 case VLC_VAR_MODULE:
1845 case VLC_VAR_DIRECTORY:
1846 val.psz_string = psz_value;
1854 var_Set( p_input, psz_name, val );
1856 msg_Dbg( p_input, "set input option: %s to %s", psz_name, psz_value );
1859 if( psz_name ) free( psz_name );
1863 static void MRLSplit( input_thread_t *p_input, char *psz_dup,
1864 char **ppsz_access, char **ppsz_demux, char **ppsz_path )
1866 char *psz_access = NULL;
1867 char *psz_demux = NULL;
1868 char *psz_path = NULL;
1871 psz = strchr( psz_dup, ':' );
1873 #if defined( WIN32 ) || defined( UNDER_CE )
1874 if( psz - psz_dup == 1 )
1876 msg_Warn( p_input, "drive letter %c: found in source string",
1886 if( psz[0] == '/' && psz[1] == '/' )
1891 psz = strchr( psz_dup, '/' );
1898 psz_access = psz_dup;
1905 if( psz_access == NULL )
1908 *ppsz_access = psz_access;
1910 if( psz_demux == NULL )
1913 *ppsz_demux = psz_demux;
1915 if( psz_path == NULL )
1918 *ppsz_path = psz_path;