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 UpdateItemLength( input_thread_t *, int64_t i_length );
61 static void ParseOption( input_thread_t *p_input, const char *psz_option );
63 static void DecodeUrl ( char * );
64 static void MRLSplit( input_thread_t *, char *, char **, char **, char ** );
66 static input_source_t *InputSourceNew( input_thread_t *);
67 static int InputSourceInit( input_thread_t *, input_source_t *,
68 char *, char *psz_forced_demux );
69 static void InputSourceClean( input_thread_t *, input_source_t * );
71 static void SlaveDemux( input_thread_t *p_input );
72 static void SlaveSeek( input_thread_t *p_input );
74 static vlc_meta_t *InputMetaUser( input_thread_t *p_input );
76 /*****************************************************************************
77 * input_CreateThread: creates a new input thread
78 *****************************************************************************
79 * This function creates a new input, and returns a pointer
80 * to its description. On error, it returns NULL.
82 * Variables for _public_ use:
85 * - rate,rate-slower, rate-faster
86 * - position, position-offset
88 * - title,title-next,title-prev
89 * - chapter,chapter-next, chapter-prev
90 * - program, audio-es, video-es, spu-es
91 * - audio-delay, spu-delay
96 * - seekable (if you can seek, it doesn't say if 'bar display' has be shown or not, for that check position != 0.0)
97 * * For intf callback upon changes
99 * TODO explain when Callback is called
100 * TODO complete this list (?)
101 *****************************************************************************/
102 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
103 input_item_t *p_item )
106 input_thread_t *p_input; /* thread descriptor */
110 /* Allocate descriptor */
111 p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
112 if( p_input == NULL )
114 msg_Err( p_parent, "out of memory" );
118 /* Init Common fields */
119 p_input->b_eof = VLC_FALSE;
120 p_input->b_can_pace_control = VLC_TRUE;
121 p_input->i_start = 0;
124 p_input->i_title = 0;
125 p_input->title = NULL;
126 p_input->i_state = INIT_S;
127 p_input->i_rate = INPUT_RATE_DEFAULT;
128 p_input->i_bookmark = 0;
129 p_input->bookmark = NULL;
130 p_input->p_es_out = NULL;
131 p_input->p_sout = NULL;
132 p_input->b_out_pace_control = VLC_FALSE;
133 p_input->i_pts_delay = 0;
136 /* Init Input fields */
137 p_input->input.p_item = p_item;
138 p_input->input.p_access = NULL;
139 p_input->input.p_stream = NULL;
140 p_input->input.p_demux = NULL;
141 p_input->input.b_title_demux = VLC_FALSE;
142 p_input->input.i_title = 0;
143 p_input->input.title = NULL;
144 p_input->input.b_can_pace_control = VLC_TRUE;
145 p_input->input.b_eof = VLC_FALSE;
146 p_input->input.i_cr_average = 0;
149 p_input->i_slave = 0;
150 p_input->slave = NULL;
152 /* Init control buffer */
153 vlc_mutex_init( p_input, &p_input->lock_control );
154 p_input->i_control = 0;
156 /* Parse input options */
157 vlc_mutex_lock( &p_item->lock );
158 for( i = 0; i < p_item->i_options; i++ )
160 msg_Dbg( p_input, "option: %s", p_item->ppsz_options[i] );
161 ParseOption( p_input, p_item->ppsz_options[i] );
163 vlc_mutex_unlock( &p_item->lock );
165 /* Create Object Variables for private use only */
166 input_ConfigVarInit( p_input );
168 /* Create Objects variables for public Get and Set */
169 input_ControlVarInit( p_input );
170 p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
173 var_Get( p_input, "bookmarks", &val );
176 /* FIXME: have a common cfg parsing routine used by sout and others */
177 char *psz_parser, *psz_start, *psz_end;
178 psz_parser = val.psz_string;
179 while( (psz_start = strchr( psz_parser, '{' ) ) )
181 seekpoint_t seekpoint;
184 psz_end = strchr( psz_start, '}' );
185 if( !psz_end ) break;
186 psz_parser = psz_end + 1;
187 backup = *psz_parser;
191 seekpoint.psz_name = 0;
192 seekpoint.i_byte_offset = 0;
193 seekpoint.i_time_offset = 0;
194 while( (psz_end = strchr( psz_start, ',' ) ) )
197 if( !strncmp( psz_start, "name=", 5 ) )
199 seekpoint.psz_name = psz_start + 5;
201 else if( !strncmp( psz_start, "bytes=", 6 ) )
203 seekpoint.i_byte_offset = atoll(psz_start + 6);
205 else if( !strncmp( psz_start, "time=", 5 ) )
207 seekpoint.i_time_offset = atoll(psz_start + 5) * 1000000;
209 psz_start = psz_end + 1;
211 msg_Dbg( p_input, "adding bookmark: %s, bytes="I64Fd", time="I64Fd,
212 seekpoint.psz_name, seekpoint.i_byte_offset,
213 seekpoint.i_time_offset );
214 input_Control( p_input, INPUT_ADD_BOOKMARK, &seekpoint );
215 *psz_parser = backup;
217 free( val.psz_string );
220 /* Now we can attach our new input */
221 vlc_object_attach( p_input, p_parent );
223 /* Create thread and wait for its readiness. */
224 if( vlc_thread_create( p_input, "input", Run,
225 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
227 msg_Err( p_input, "cannot create input thread" );
228 vlc_object_detach( p_input );
229 vlc_object_destroy( p_input );
236 /*****************************************************************************
237 * input_StopThread: mark an input thread as zombie
238 *****************************************************************************
239 * This function should not return until the thread is effectively cancelled.
240 *****************************************************************************/
241 void input_StopThread( input_thread_t *p_input )
246 /* Set die for input */
247 p_input->b_die = VLC_TRUE;
249 /* We cannot touch p_input fields directly (we can from another thread),
250 * so use the vlc_object_find way, it's perfectly safe */
252 /* Set die for all access */
253 p_list = vlc_list_find( p_input, VLC_OBJECT_ACCESS, FIND_CHILD );
254 for( i = 0; i < p_list->i_count; i++ )
256 p_list->p_values[i].p_object->b_die = VLC_TRUE;
258 vlc_list_release( p_list );
260 /* Set die for all stream */
261 p_list = vlc_list_find( p_input, VLC_OBJECT_STREAM, FIND_CHILD );
262 for( i = 0; i < p_list->i_count; i++ )
264 p_list->p_values[i].p_object->b_die = VLC_TRUE;
266 vlc_list_release( p_list );
268 /* Set die for all demux */
269 p_list = vlc_list_find( p_input, VLC_OBJECT_DEMUX, FIND_CHILD );
270 for( i = 0; i < p_list->i_count; i++ )
272 p_list->p_values[i].p_object->b_die = VLC_TRUE;
274 vlc_list_release( p_list );
276 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
279 /*****************************************************************************
280 * input_DestroyThread: mark an input thread as zombie
281 *****************************************************************************
282 * This function should not return until the thread is effectively cancelled.
283 *****************************************************************************/
284 void input_DestroyThread( input_thread_t *p_input )
286 /* Join the thread */
287 vlc_thread_join( p_input );
289 /* Delete input lock (only after thread joined) */
290 vlc_mutex_destroy( &p_input->lock_control );
292 /* TODO: maybe input_DestroyThread should also delete p_input instead
293 * of the playlist but I'm not sure if it's possible */
296 /*****************************************************************************
297 * Run: main thread loop
298 *****************************************************************************
299 * Thread in charge of processing the network packets and demultiplexing.
302 * read subtitle support (XXX take care of spu-delay in the right way).
303 * multi-input support (XXX may be done with subs)
304 *****************************************************************************/
305 static int Run( input_thread_t *p_input )
307 int64_t i_intf_update = 0;
309 /* Signal that the thread is launched */
310 vlc_thread_ready( p_input );
312 if( Init( p_input ) )
314 /* If we failed, wait before we are killed, and exit */
315 p_input->b_error = VLC_TRUE;
319 /* Tell we're dead */
320 p_input->b_dead = VLC_TRUE;
326 while( !p_input->b_die && !p_input->b_error && !p_input->input.b_eof )
328 vlc_bool_t b_force_update = VLC_FALSE;
334 if( p_input->i_state != PAUSE_S )
336 if( p_input->i_stop <= 0 || p_input->i_time < p_input->i_stop )
337 i_ret=p_input->input.p_demux->pf_demux(p_input->input.p_demux);
344 if( p_input->input.b_title_demux &&
345 p_input->input.p_demux->info.i_update )
347 UpdateFromDemux( p_input );
348 b_force_update = VLC_TRUE;
350 else if( !p_input->input.b_title_demux &&
351 p_input->input.p_access &&
352 p_input->input.p_access->info.i_update )
354 UpdateFromAccess( p_input );
355 b_force_update = VLC_TRUE;
358 else if( i_ret == 0 ) /* EOF */
362 var_Get( p_input, "input-repeat", &repeat );
363 if( repeat.i_int == 0 )
365 /* End of file - we do not set b_die because only the
366 * playlist is allowed to do so. */
367 msg_Dbg( p_input, "EOF reached" );
368 p_input->input.b_eof = VLC_TRUE;
372 msg_Dbg( p_input, "repeating the same input (%d)",
374 if( repeat.i_int > 0 )
377 var_Set( p_input, "input-repeat", repeat );
380 /* Seek to title 0 position 0(start) */
382 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
383 if( p_input->i_start > 0 )
385 val.i_time = p_input->i_start;
386 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
392 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
399 p_input->b_error = VLC_TRUE;
402 if( i_ret > 0 && p_input->i_slave > 0 )
404 SlaveDemux( p_input );
414 vlc_mutex_lock( &p_input->lock_control );
415 ControlReduce( p_input );
416 while( !ControlPopNoLock( p_input, &i_type, &val ) )
418 msg_Dbg( p_input, "control type=%d", i_type );
419 if( Control( p_input, i_type, val ) )
420 b_force_update = VLC_TRUE;
422 vlc_mutex_unlock( &p_input->lock_control );
424 if( b_force_update ||
425 i_intf_update < mdate() )
429 int64_t i_time, i_length;
430 /* update input status variables */
431 if( !demux2_Control( p_input->input.p_demux,
432 DEMUX_GET_POSITION, &f_pos ) )
434 val.f_float = (float)f_pos;
435 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
437 if( !demux2_Control( p_input->input.p_demux,
438 DEMUX_GET_TIME, &i_time ) )
440 p_input->i_time = i_time;
442 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
444 if( !demux2_Control( p_input->input.p_demux,
445 DEMUX_GET_LENGTH, &i_length ) )
448 var_Get( p_input, "length", &old_val );
449 val.i_time = i_length;
450 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
452 if( old_val.i_time != val.i_time )
454 UpdateItemLength( p_input, i_length );
458 var_SetBool( p_input, "intf-change", VLC_TRUE );
459 i_intf_update = mdate() + I64C(150000);
463 if( !p_input->b_eof && !p_input->b_error && p_input->input.b_eof )
465 /* We have finish to demux data but not to play them */
466 while( !p_input->b_die )
468 if( input_EsOutDecodersEmpty( p_input->p_es_out ) )
471 msg_Dbg( p_input, "waiting decoder fifos to empty" );
473 msleep( INPUT_IDLE_SLEEP );
476 /* We have finished */
477 p_input->b_eof = VLC_TRUE;
480 /* Wait we are asked to die */
481 if( !p_input->b_die )
492 /*****************************************************************************
493 * Init: init the input Thread
494 *****************************************************************************/
495 static int Init( input_thread_t * p_input )
501 vlc_meta_t *p_meta, *p_meta_user;
504 /* Initialize optional stream output. (before access/demuxer) */
505 psz = var_GetString( p_input, "sout" );
508 p_input->p_sout = sout_NewInstance( p_input, psz );
509 if( p_input->p_sout == NULL )
511 msg_Err( p_input, "cannot start stream output instance, aborting" );
519 p_input->p_es_out = input_EsOutNew( p_input );
520 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
521 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
523 if( InputSourceInit( p_input, &p_input->input,
524 p_input->input.p_item->psz_uri, NULL ) )
529 /* Create global title (from master) */
530 p_input->i_title = p_input->input.i_title;
531 p_input->title = p_input->input.title;
532 if( p_input->i_title > 0 )
534 /* Setup variables */
535 input_ControlVarNavigation( p_input );
536 input_ControlVarTitle( p_input, 0 );
540 p_input->b_can_pace_control = p_input->input.b_can_pace_control;
541 p_input->b_can_pause = p_input->input.b_can_pause;
544 if( p_input->i_pts_delay <= 0 )
545 p_input->i_pts_delay = DEFAULT_PTS_DELAY;
547 /* If the desynchronisation requested by the user is < 0, we need to
548 * cache more data. */
549 var_Get( p_input, "audio-desync", &val );
551 p_input->i_pts_delay -= (val.i_int * 1000);
553 /* Load master infos */
555 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_LENGTH,
556 &val.i_time ) && val.i_time > 0 )
558 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
560 UpdateItemLength( p_input, val.i_time );
564 p_input->i_start = (int64_t)var_GetInteger( p_input, "start-time" ) *
566 p_input->i_stop = (int64_t)var_GetInteger( p_input, "stop-time" ) *
569 if( p_input->i_start > 0 )
571 if( p_input->i_start >= val.i_time )
573 msg_Warn( p_input, "invalid start-time ignored" );
579 msg_Dbg( p_input, "start-time: %ds",
580 (int)( p_input->i_start / I64C(1000000) ) );
582 s.i_time = p_input->i_start;
583 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
586 if( p_input->i_stop > 0 && p_input->i_stop <= p_input->i_start )
588 msg_Warn( p_input, "invalid stop-time ignored" );
594 /* Get fps and set it if not already set */
595 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) &&
600 if( var_Get( p_input, "sub-fps", &fps ) )
602 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT| VLC_VAR_DOINHERIT );
603 var_SetFloat( p_input, "sub-fps", f_fps );
607 /* Look for and add subtitle files */
608 psz_subtitle = var_GetString( p_input, "sub-file" );
615 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
617 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
620 sub = InputSourceNew( p_input );
621 if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
623 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
626 if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
628 if( count.i_int == 0 )
629 count.i_int++; /* if it was first one, there is disable too */
631 if( count.i_int < list.p_list->i_count )
633 input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
634 &list.p_list->p_values[count.i_int] );
636 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
641 var_Get( p_input, "sub-autodetect-file", &val );
644 char *psz_autopath = var_GetString( p_input, "sub-autodetect-path" );
645 char **subs = subtitles_Detect( p_input, psz_autopath,
646 p_input->input.p_item->psz_uri );
649 for( i = 0; subs[i] != NULL; i++ )
651 if( strcmp( psz_subtitle, subs[i] ) )
653 sub = InputSourceNew( p_input );
654 if( !InputSourceInit( p_input, sub, subs[i], "subtitle" ) )
656 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
662 free( psz_autopath );
664 free( psz_subtitle );
667 psz = var_GetString( p_input, "input-slave" );
670 char *psz_delim = strchr( psz, '#' );
674 input_source_t *slave;
689 msg_Dbg( p_input, "adding slave '%s'", psz );
690 slave = InputSourceNew( p_input );
691 if( !InputSourceInit( p_input, slave, psz, NULL ) )
693 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
702 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
703 val.b_bool = VLC_FALSE;
704 if( p_input->p_sout )
706 var_Get( p_input, "sout-all", &val );
708 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE,
709 val.b_bool ? ES_OUT_MODE_ALL : ES_OUT_MODE_AUTO );
711 if( p_input->p_sout )
713 if( p_input->p_sout->i_out_pace_nocontrol > 0 )
715 p_input->b_out_pace_control = VLC_FALSE;
719 p_input->b_out_pace_control = VLC_TRUE;
721 msg_Dbg( p_input, "starting in %s mode",
722 p_input->b_out_pace_control ? "asynch" : "synch" );
725 /* Get meta data from users */
726 p_meta_user = InputMetaUser( p_input );
728 /* Get meta data from master input */
729 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_META, &p_meta ) )
735 p_meta = p_meta_user;
737 else if( p_meta_user )
739 vlc_meta_Merge( p_meta, p_meta_user );
740 vlc_meta_Delete( p_meta_user );
743 /* Get meta data from slave input */
744 for( i = 0; i < p_input->i_slave; i++ )
746 vlc_meta_t *p_meta_slave;
748 if( !demux2_Control( p_input->slave[i]->p_demux, DEMUX_GET_META, &p_meta_slave ) )
752 p_meta = p_meta_slave;
754 else if( p_meta_slave )
756 vlc_meta_Merge( p_meta, p_meta_slave );
757 vlc_meta_Delete( p_meta_slave );
762 if( p_meta && p_meta->i_meta > 0 )
764 msg_Dbg( p_input, "meta information:" );
765 for( i = 0; i < p_meta->i_meta; i++ )
767 msg_Dbg( p_input, " - '%s' = '%s'",
768 _(p_meta->name[i]), p_meta->value[i] );
770 if( !strcmp(p_meta->name[i], VLC_META_TITLE) && p_meta->value[i] )
771 input_Control( p_input, INPUT_SET_NAME, p_meta->value[i] );
773 if( !strcmp( p_meta->name[i], VLC_META_AUTHOR ) )
774 input_Control( p_input, INPUT_ADD_INFO, _("General"),
775 _("Author"), p_meta->value[i] );
777 input_Control( p_input, INPUT_ADD_INFO, _("Meta-information"),
778 _(p_meta->name[i]), "%s", p_meta->value[i] );
781 for( i = 0; i < p_meta->i_track; i++ )
783 vlc_meta_t *tk = p_meta->track[i];
788 char *psz_cat = malloc( strlen(_("Stream")) + 10 );
790 msg_Dbg( p_input, " - track[%d]:", i );
792 sprintf( psz_cat, "%s %d", _("Stream"), i );
793 for( j = 0; j < tk->i_meta; j++ )
795 msg_Dbg( p_input, " - '%s' = '%s'", _(tk->name[j]),
798 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
799 _(tk->name[j]), "%s", tk->value[j] );
804 if( p_input->p_sout && p_input->p_sout->p_meta == NULL )
806 p_input->p_sout->p_meta = p_meta;
810 vlc_meta_Delete( p_meta );
814 msg_Dbg( p_input, "`%s' sucessfully opened",
815 p_input->input.p_item->psz_uri );
817 /* initialization is complete */
818 p_input->i_state = PLAYING_S;
820 val.i_int = PLAYING_S;
821 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
826 if( p_input->p_es_out )
827 input_EsOutDelete( p_input->p_es_out );
829 if( p_input->p_sout )
830 sout_DeleteInstance( p_input->p_sout );
832 /* Mark them deleted */
833 p_input->input.p_demux = NULL;
834 p_input->input.p_stream = NULL;
835 p_input->input.p_access = NULL;
836 p_input->p_es_out = NULL;
837 p_input->p_sout = NULL;
842 /*****************************************************************************
843 * Error: RunThread() error loop
844 *****************************************************************************
845 * This function is called when an error occured during thread main's loop.
846 *****************************************************************************/
847 static void Error( input_thread_t *p_input )
849 while( !p_input->b_die )
852 msleep( INPUT_IDLE_SLEEP );
856 /*****************************************************************************
857 * End: end the input thread
858 *****************************************************************************/
859 static void End( input_thread_t * p_input )
864 msg_Dbg( p_input, "closing `%s'",
865 p_input->input.p_item->psz_uri );
867 /* We are at the end */
868 p_input->i_state = END_S;
871 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
873 /* Clean control variables */
874 input_ControlVarClean( p_input );
876 /* Clean up master */
877 InputSourceClean( p_input, &p_input->input );
880 for( i = 0; i < p_input->i_slave; i++ )
882 InputSourceClean( p_input, p_input->slave[i] );
883 free( p_input->slave[i] );
885 if( p_input->slave ) free( p_input->slave );
887 /* Unload all modules */
888 if( p_input->p_es_out )
889 input_EsOutDelete( p_input->p_es_out );
891 /* Close optional stream output instance */
892 if( p_input->p_sout )
895 vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
898 if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
900 /* attach sout to the playlist */
901 msg_Warn( p_input, "keeping sout" );
902 vlc_object_detach( p_input->p_sout );
903 vlc_object_attach( p_input->p_sout, p_pl );
907 msg_Warn( p_input, "destroying sout" );
908 sout_DeleteInstance( p_input->p_sout );
911 vlc_object_release( p_pl );
914 /* Tell we're dead */
915 p_input->b_dead = VLC_TRUE;
918 /*****************************************************************************
920 *****************************************************************************/
921 static inline int ControlPopNoLock( input_thread_t *p_input,
922 int *pi_type, vlc_value_t *p_val )
924 if( p_input->i_control <= 0 )
929 *pi_type = p_input->control[0].i_type;
930 *p_val = p_input->control[0].val;
932 p_input->i_control--;
933 if( p_input->i_control > 0 )
937 for( i = 0; i < p_input->i_control; i++ )
939 p_input->control[i].i_type = p_input->control[i+1].i_type;
940 p_input->control[i].val = p_input->control[i+1].val;
947 static void ControlReduce( input_thread_t *p_input )
950 for( i = 1; i < p_input->i_control; i++ )
952 const int i_lt = p_input->control[i-1].i_type;
953 const int i_ct = p_input->control[i].i_type;
955 /* XXX We can't merge INPUT_CONTROL_SET_ES */
956 msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->i_control,
959 ( i_ct == INPUT_CONTROL_SET_STATE ||
960 i_ct == INPUT_CONTROL_SET_RATE ||
961 i_ct == INPUT_CONTROL_SET_POSITION ||
962 i_ct == INPUT_CONTROL_SET_TIME ||
963 i_ct == INPUT_CONTROL_SET_PROGRAM ||
964 i_ct == INPUT_CONTROL_SET_TITLE ||
965 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
966 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
969 msg_Dbg( p_input, "merged at %d", i );
971 for( j = i; j < p_input->i_control; j++ )
972 p_input->control[j-1] = p_input->control[j];
973 p_input->i_control--;
977 /* TODO but that's not that important
978 - merge SET_X with SET_X_CMD
979 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
980 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
987 static vlc_bool_t Control( input_thread_t *p_input, int i_type,
990 vlc_bool_t b_force_update = VLC_FALSE;
994 case INPUT_CONTROL_SET_DIE:
995 msg_Dbg( p_input, "control: INPUT_CONTROL_SET_DIE proceed" );
996 /* Mark all submodules to die */
997 if( p_input->input.p_access )
998 p_input->input.p_access->b_die = VLC_TRUE;
999 if( p_input->input.p_stream )
1000 p_input->input.p_stream->b_die = VLC_TRUE;
1001 p_input->input.p_demux->b_die = VLC_TRUE;
1003 p_input->b_die = VLC_TRUE;
1006 case INPUT_CONTROL_SET_POSITION:
1007 case INPUT_CONTROL_SET_POSITION_OFFSET:
1010 if( i_type == INPUT_CONTROL_SET_POSITION )
1012 f_pos = val.f_float;
1016 /* Should not fail */
1017 demux2_Control( p_input->input.p_demux,
1018 DEMUX_GET_POSITION, &f_pos );
1019 f_pos += val.f_float;
1021 if( f_pos < 0.0 ) f_pos = 0.0;
1022 if( f_pos > 1.0 ) f_pos = 1.0;
1023 if( demux2_Control( p_input->input.p_demux, DEMUX_SET_POSITION,
1026 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1027 "%2.1f%% failed", f_pos * 100 );
1031 if( p_input->i_slave > 0 )
1032 SlaveSeek( p_input );
1034 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1035 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1036 b_force_update = VLC_TRUE;
1041 case INPUT_CONTROL_SET_TIME:
1042 case INPUT_CONTROL_SET_TIME_OFFSET:
1047 if( i_type == INPUT_CONTROL_SET_TIME )
1049 i_time = val.i_time;
1053 /* Should not fail */
1054 demux2_Control( p_input->input.p_demux,
1055 DEMUX_GET_TIME, &i_time );
1056 i_time += val.i_time;
1058 if( i_time < 0 ) i_time = 0;
1059 i_ret = demux2_Control( p_input->input.p_demux,
1060 DEMUX_SET_TIME, i_time );
1064 /* Emulate it with a SET_POS */
1066 demux2_Control( p_input->input.p_demux,
1067 DEMUX_GET_LENGTH, &i_length );
1070 double f_pos = (double)i_time / (double)i_length;
1071 i_ret = demux2_Control( p_input->input.p_demux,
1072 DEMUX_SET_POSITION, f_pos );
1077 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) "I64Fd
1078 " failed", i_time );
1082 if( p_input->i_slave > 0 )
1083 SlaveSeek( p_input );
1085 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1087 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1088 b_force_update = VLC_TRUE;
1093 case INPUT_CONTROL_SET_STATE:
1094 if( ( val.i_int == PLAYING_S && p_input->i_state == PAUSE_S ) ||
1095 ( val.i_int == PAUSE_S && p_input->i_state == PAUSE_S ) )
1098 if( p_input->input.p_access )
1099 i_ret = access2_Control( p_input->input.p_access,
1100 ACCESS_SET_PAUSE_STATE, VLC_FALSE );
1102 i_ret = demux2_Control( p_input->input.p_demux,
1103 DEMUX_SET_PAUSE_STATE, VLC_FALSE );
1107 /* FIXME What to do ? */
1108 msg_Warn( p_input, "cannot unset pause -> EOF" );
1109 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1112 b_force_update = VLC_TRUE;
1114 /* Switch to play */
1115 p_input->i_state = PLAYING_S;
1116 val.i_int = PLAYING_S;
1117 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1120 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1122 else if( val.i_int == PAUSE_S && p_input->i_state == PLAYING_S &&
1123 p_input->b_can_pause )
1126 if( p_input->input.p_access )
1127 i_ret = access2_Control( p_input->input.p_access,
1128 ACCESS_SET_PAUSE_STATE, VLC_TRUE );
1130 i_ret = demux2_Control( p_input->input.p_demux,
1131 DEMUX_SET_PAUSE_STATE, VLC_TRUE );
1133 b_force_update = VLC_TRUE;
1137 msg_Warn( p_input, "cannot set pause state" );
1138 val.i_int = p_input->i_state;
1142 val.i_int = PAUSE_S;
1145 /* Switch to new state */
1146 p_input->i_state = val.i_int;
1147 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1149 else if( val.i_int == PAUSE_S && !p_input->b_can_pause )
1151 b_force_update = VLC_TRUE;
1153 /* Correct "state" value */
1154 val.i_int = p_input->i_state;
1155 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1157 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1159 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1163 case INPUT_CONTROL_SET_RATE:
1164 case INPUT_CONTROL_SET_RATE_SLOWER:
1165 case INPUT_CONTROL_SET_RATE_FASTER:
1169 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1170 i_rate = p_input->i_rate * 2;
1171 else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
1172 i_rate = p_input->i_rate / 2;
1176 if( i_rate < INPUT_RATE_MIN )
1178 msg_Dbg( p_input, "cannot set rate faster" );
1179 i_rate = INPUT_RATE_MIN;
1181 else if( i_rate > INPUT_RATE_MAX )
1183 msg_Dbg( p_input, "cannot set rate slower" );
1184 i_rate = INPUT_RATE_MAX;
1186 if( i_rate != INPUT_RATE_DEFAULT &&
1187 ( !p_input->b_can_pace_control ||
1188 ( p_input->p_sout && !p_input->b_out_pace_control ) ) )
1190 msg_Dbg( p_input, "cannot change rate" );
1191 i_rate = INPUT_RATE_DEFAULT;
1193 if( i_rate != p_input->i_rate )
1195 p_input->i_rate = i_rate;
1197 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
1199 /* We haven't send data to decoder when rate != default */
1200 if( i_rate == INPUT_RATE_DEFAULT )
1201 input_EsOutDiscontinuity( p_input->p_es_out, VLC_TRUE );
1204 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1206 b_force_update = VLC_TRUE;
1211 case INPUT_CONTROL_SET_PROGRAM:
1212 /* No need to force update, es_out does it if needed */
1213 es_out_Control( p_input->p_es_out,
1214 ES_OUT_SET_GROUP, val.i_int );
1217 case INPUT_CONTROL_SET_ES:
1218 /* No need to force update, es_out does it if needed */
1219 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
1220 input_EsOutGetFromID( p_input->p_es_out,
1224 case INPUT_CONTROL_SET_AUDIO_DELAY:
1225 input_EsOutSetDelay( p_input->p_es_out,
1226 AUDIO_ES, val.i_time );
1227 var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
1230 case INPUT_CONTROL_SET_SPU_DELAY:
1231 input_EsOutSetDelay( p_input->p_es_out,
1232 SPU_ES, val.i_time );
1233 var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
1236 case INPUT_CONTROL_SET_TITLE:
1237 case INPUT_CONTROL_SET_TITLE_NEXT:
1238 case INPUT_CONTROL_SET_TITLE_PREV:
1239 if( p_input->input.b_title_demux &&
1240 p_input->input.i_title > 0 )
1243 /* FIXME handle demux title */
1244 demux_t *p_demux = p_input->input.p_demux;
1247 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1248 i_title = p_demux->info.i_title - 1;
1249 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1250 i_title = p_demux->info.i_title + 1;
1252 i_title = val.i_int;
1254 if( i_title >= 0 && i_title < p_input->input.i_title )
1256 demux2_Control( p_demux, DEMUX_SET_TITLE, i_title );
1258 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1259 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1261 input_ControlVarTitle( p_input, i_title );
1264 else if( p_input->input.i_title > 0 )
1266 access_t *p_access = p_input->input.p_access;
1269 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1270 i_title = p_access->info.i_title - 1;
1271 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1272 i_title = p_access->info.i_title + 1;
1274 i_title = val.i_int;
1276 if( i_title >= 0 && i_title < p_input->input.i_title )
1278 access2_Control( p_access, ACCESS_SET_TITLE, i_title );
1279 stream_AccessReset( p_input->input.p_stream );
1281 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1282 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1286 case INPUT_CONTROL_SET_SEEKPOINT:
1287 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1288 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1289 if( p_input->input.b_title_demux &&
1290 p_input->input.i_title > 0 )
1292 demux_t *p_demux = p_input->input.p_demux;
1295 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1296 i_seekpoint = p_demux->info.i_seekpoint - 1;
1297 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1298 i_seekpoint = p_demux->info.i_seekpoint + 1;
1300 i_seekpoint = val.i_int;
1302 if( i_seekpoint >= 0 && i_seekpoint <
1303 p_input->input.title[p_demux->info.i_title]->i_seekpoint )
1305 demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1307 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1308 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1311 else if( p_input->input.i_title > 0 )
1313 access_t *p_access = p_input->input.p_access;
1316 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1317 i_seekpoint = p_access->info.i_seekpoint - 1;
1318 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1319 i_seekpoint = p_access->info.i_seekpoint + 1;
1321 i_seekpoint = val.i_int;
1323 if( i_seekpoint >= 0 && i_seekpoint <
1324 p_input->input.title[p_access->info.i_title]->i_seekpoint )
1326 access2_Control( p_access, ACCESS_SET_SEEKPOINT, i_seekpoint );
1327 stream_AccessReset( p_input->input.p_stream );
1329 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1330 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1335 case INPUT_CONTROL_SET_BOOKMARK:
1337 msg_Err( p_input, "not yet implemented" );
1341 return b_force_update;
1344 /*****************************************************************************
1346 *****************************************************************************/
1347 static void UpdateFromDemux( input_thread_t *p_input )
1349 demux_t *p_demux = p_input->input.p_demux;
1352 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
1354 v.i_int = p_demux->info.i_title;
1355 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1357 input_ControlVarTitle( p_input, p_demux->info.i_title );
1359 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
1361 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
1363 v.i_int = p_demux->info.i_seekpoint;
1364 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1366 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1368 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
1371 /*****************************************************************************
1373 *****************************************************************************/
1374 static void UpdateFromAccess( input_thread_t *p_input )
1376 access_t *p_access = p_input->input.p_access;
1379 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
1381 v.i_int = p_access->info.i_title;
1382 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1384 input_ControlVarTitle( p_input, p_access->info.i_title );
1386 stream_AccessUpdate( p_input->input.p_stream );
1388 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
1390 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
1392 v.i_int = p_access->info.i_seekpoint;
1393 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1395 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1397 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
1400 /*****************************************************************************
1402 *****************************************************************************/
1403 static void UpdateItemLength( input_thread_t *p_input, int64_t i_length )
1405 char psz_buffer[MSTRTIME_MAX_SIZE];
1407 vlc_mutex_lock( &p_input->input.p_item->lock );
1408 p_input->input.p_item->i_duration = i_length;
1409 vlc_mutex_unlock( &p_input->input.p_item->lock );
1411 input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
1412 msecstotimestr( psz_buffer, i_length / 1000 ) );
1415 /*****************************************************************************
1417 *****************************************************************************/
1418 static input_source_t *InputSourceNew( input_thread_t *p_input )
1420 input_source_t *in = malloc( sizeof( input_source_t ) );
1423 in->p_access = NULL;
1424 in->p_stream = NULL;
1426 in->b_title_demux = VLC_FALSE;
1429 in->b_can_pace_control = VLC_TRUE;
1430 in->b_eof = VLC_FALSE;
1431 in->i_cr_average = 0;
1436 /*****************************************************************************
1438 *****************************************************************************/
1439 static int InputSourceInit( input_thread_t *p_input,
1440 input_source_t *in, char *psz_mrl,
1441 char *psz_forced_demux )
1443 char *psz_dup = strdup( psz_mrl );
1450 MRLSplit( p_input, psz_dup, &psz_access, &psz_demux, &psz_path );
1452 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
1453 psz_mrl, psz_access, psz_demux, psz_path );
1455 if( psz_forced_demux && *psz_forced_demux )
1456 psz_demux = psz_forced_demux;
1458 /* Try access_demux if no demux given */
1459 if( *psz_demux == '\0' )
1461 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
1462 NULL, p_input->p_es_out );
1467 int64_t i_pts_delay;
1469 /* Get infos from access_demux */
1470 demux2_Control( in->p_demux,
1471 DEMUX_GET_PTS_DELAY, &i_pts_delay );
1472 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
1474 in->b_title_demux = VLC_TRUE;
1475 if( demux2_Control( in->p_demux,
1476 DEMUX_GET_TITLE_INFO,
1477 &in->title, &in->i_title ) )
1482 demux2_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
1483 &in->b_can_pace_control );
1484 demux2_Control( in->p_demux, DEMUX_CAN_PAUSE,
1488 demux2_Control( in->p_demux, DEMUX_CAN_SEEK,
1494 int64_t i_pts_delay;
1496 /* Now try a real access */
1497 in->p_access = access2_New( p_input, psz_access, psz_demux, psz_path );
1499 /* Access failed, URL encoded ? */
1500 if( in->p_access == NULL && strchr( psz_path, '%' ) )
1502 DecodeUrl( psz_path );
1504 msg_Dbg( p_input, "retying with access `%s' demux `%s' path `%s'",
1505 psz_access, psz_demux, psz_path );
1507 in->p_access = access2_New( p_input,
1508 psz_access, psz_demux, psz_path );
1510 #ifndef WIN32 /* Remove this gross hack from the win32 build as colons
1511 * are forbidden in filenames on Win32. */
1513 /* Maybe we got something like: /Volumes/toto:titi/gabu.mpg */
1514 if( in->p_access == NULL &&
1515 *psz_access == '\0' && ( *psz_demux || *psz_path ) )
1518 psz_dup = strdup( psz_mrl );
1523 in->p_access = access2_New( p_input,
1524 psz_access, psz_demux, psz_path );
1528 if( in->p_access == NULL )
1530 msg_Err( p_input, "no suitable access module for `%s'", psz_mrl );
1534 /* Get infos from access */
1535 access2_Control( in->p_access,
1536 ACCESS_GET_PTS_DELAY, &i_pts_delay );
1537 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
1539 in->b_title_demux = VLC_FALSE;
1540 if( access2_Control( in->p_access,
1541 ACCESS_GET_TITLE_INFO,
1542 &in->title, &in->i_title ) )
1547 access2_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
1548 &in->b_can_pace_control );
1549 access2_Control( in->p_access, ACCESS_CAN_PAUSE,
1551 access2_Control( in->p_access, ACCESS_CAN_SEEK,
1553 var_Set( p_input, "seekable", val );
1555 /* Create the stream_t */
1556 in->p_stream = stream_AccessNew( in->p_access );
1557 if( in->p_stream == NULL )
1559 msg_Warn( p_input, "cannot create a stream_t from access" );
1563 /* Open a demuxer */
1564 if( *psz_demux == '\0' && *in->p_access->psz_demux )
1566 psz_demux = in->p_access->psz_demux;
1568 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
1569 in->p_stream, p_input->p_es_out );
1570 if( in->p_demux == NULL )
1572 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
1573 psz_access, psz_demux, psz_path );
1577 /* TODO get title from demux */
1578 if( in->i_title <= 0 )
1580 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
1581 &in->title, &in->i_title ) )
1588 in->b_title_demux = VLC_TRUE;
1597 demux2_Delete( in->p_demux );
1600 stream_AccessDelete( in->p_stream );
1603 access2_Delete( in->p_access );
1606 return VLC_EGENERIC;
1609 /*****************************************************************************
1611 *****************************************************************************/
1612 static void InputSourceClean( input_thread_t *p_input, input_source_t *in )
1615 demux2_Delete( in->p_demux );
1618 stream_AccessDelete( in->p_stream );
1621 access2_Delete( in->p_access );
1623 if( in->i_title > 0 )
1626 for( i = 0; i < in->i_title; i++ )
1628 vlc_input_title_Delete( in->title[i] );
1634 static void SlaveDemux( input_thread_t *p_input )
1638 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
1640 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
1644 for( i = 0; i < p_input->i_slave; i++ )
1646 input_source_t *in = p_input->slave[i];
1652 if( demux2_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
1657 if( demux2_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
1659 msg_Err( p_input, "slave[%d] doesn't like "
1660 "DEMUX_GET_TIME -> EOF", i );
1665 if( i_stime >= i_time )
1668 if( ( i_ret = in->p_demux->pf_demux( in->p_demux ) ) <= 0 )
1674 i_ret = in->p_demux->pf_demux( in->p_demux );
1679 msg_Dbg( p_input, "slave %d EOF", i );
1680 in->b_eof = VLC_TRUE;
1685 static void SlaveSeek( input_thread_t *p_input )
1690 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
1692 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
1696 for( i = 0; i < p_input->i_slave; i++ )
1698 input_source_t *in = p_input->slave[i];
1700 if( demux2_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
1702 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
1703 in->b_eof = VLC_TRUE;
1707 /*****************************************************************************
1709 *****************************************************************************/
1710 static vlc_meta_t *InputMetaUser( input_thread_t *p_input )
1715 if( ( p_meta = vlc_meta_New() ) == NULL )
1718 /* Get meta information from user */
1719 #define GET_META( c, s ) \
1720 var_Get( p_input, (s), &val ); \
1721 if( *val.psz_string ) \
1722 vlc_meta_Add( p_meta, c, val.psz_string ); \
1723 free( val.psz_string )
1725 GET_META( VLC_META_TITLE, "meta-title" );
1726 GET_META( VLC_META_AUTHOR, "meta-author" );
1727 GET_META( VLC_META_ARTIST, "meta-artist" );
1728 GET_META( VLC_META_GENRE, "meta-genre" );
1729 GET_META( VLC_META_COPYRIGHT, "meta-copyright" );
1730 GET_META( VLC_META_DESCRIPTION, "meta-description" );
1731 GET_META( VLC_META_DATE, "meta-date" );
1732 GET_META( VLC_META_URL, "meta-url" );
1738 /*****************************************************************************
1739 * DecodeUrl: decode a given encoded url
1740 *****************************************************************************/
1741 static void DecodeUrl( char *psz )
1743 char *dup = strdup( psz );
1761 *psz++ = strtol( val, NULL, 16 );
1763 else if( *p == '+' )
1777 /*****************************************************************************
1778 * ParseOption: parses the options for the input
1779 *****************************************************************************
1780 * This function parses the input (config) options and creates their associated
1782 * Options are of the form "[no[-]]foo[=bar]" where foo is the option name and
1783 * bar is the value of the option.
1784 *****************************************************************************/
1785 static void ParseOption( input_thread_t *p_input, const char *psz_option )
1787 char *psz_name = (char *)psz_option;
1788 char *psz_value = strchr( psz_option, '=' );
1789 int i_name_len, i_type;
1790 vlc_bool_t b_isno = VLC_FALSE;
1793 if( psz_value ) i_name_len = psz_value - psz_option;
1794 else i_name_len = strlen( psz_option );
1796 /* It's too much of an hassle to remove the ':' when we parse
1797 * the cmd line :) */
1798 if( i_name_len && *psz_name == ':' )
1804 if( i_name_len == 0 ) return;
1806 psz_name = strndup( psz_name, i_name_len );
1807 if( psz_value ) psz_value++;
1809 i_type = config_GetType( p_input, psz_name );
1811 if( !i_type && !psz_value )
1813 /* check for "no-foo" or "nofoo" */
1814 if( !strncmp( psz_name, "no-", 3 ) )
1816 memmove( psz_name, psz_name + 3, strlen(psz_name) + 1 - 3 );
1818 else if( !strncmp( psz_name, "no", 2 ) )
1820 memmove( psz_name, psz_name + 2, strlen(psz_name) + 1 - 2 );
1822 else goto cleanup; /* Option doesn't exist */
1825 i_type = config_GetType( p_input, psz_name );
1827 if( !i_type ) goto cleanup; /* Option doesn't exist */
1829 else if( !i_type ) goto cleanup; /* Option doesn't exist */
1831 if( ( i_type != VLC_VAR_BOOL ) &&
1832 ( !psz_value || !*psz_value ) ) goto cleanup; /* Invalid value */
1834 /* Create the variable in the input object.
1835 * Children of the input object will be able to retreive this value
1836 * thanks to the inheritance property of the object variables. */
1837 var_Create( p_input, psz_name, i_type );
1842 val.b_bool = !b_isno;
1845 case VLC_VAR_INTEGER:
1846 val.i_int = atoi( psz_value );
1850 val.f_float = atof( psz_value );
1853 case VLC_VAR_STRING:
1854 case VLC_VAR_MODULE:
1856 case VLC_VAR_DIRECTORY:
1857 val.psz_string = psz_value;
1865 var_Set( p_input, psz_name, val );
1867 msg_Dbg( p_input, "set input option: %s to %s", psz_name, psz_value );
1870 if( psz_name ) free( psz_name );
1874 static void MRLSplit( input_thread_t *p_input, char *psz_dup,
1875 char **ppsz_access, char **ppsz_demux, char **ppsz_path )
1877 char *psz_access = NULL;
1878 char *psz_demux = NULL;
1879 char *psz_path = NULL;
1882 psz = strchr( psz_dup, ':' );
1884 #if defined( WIN32 ) || defined( UNDER_CE )
1885 if( psz - psz_dup == 1 )
1887 msg_Warn( p_input, "drive letter %c: found in source string",
1897 if( psz[0] == '/' && psz[1] == '/' )
1902 psz = strchr( psz_dup, '/' );
1909 psz_access = psz_dup;
1916 if( psz_access == NULL )
1919 *ppsz_access = psz_access;
1921 if( psz_demux == NULL )
1924 *ppsz_demux = psz_demux;
1926 if( psz_path == NULL )
1929 *ppsz_path = psz_path;