1 /*****************************************************************************
2 * input.c: input thread
3 *****************************************************************************
4 * Copyright (C) 1998-2004 the VideoLAN team
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Laurent Aimar <fenrir@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc/input.h>
33 #include <vlc/decoder.h>
36 #include "input_internal.h"
38 #include "stream_output.h"
39 #include "vlc_playlist.h"
40 #include "vlc_interface.h"
42 /*****************************************************************************
44 *****************************************************************************/
45 static int Run ( input_thread_t *p_input );
46 static int RunAndClean ( input_thread_t *p_input );
48 static input_thread_t * Create ( vlc_object_t *, input_item_t *, vlc_bool_t );
49 static int Init ( input_thread_t *p_input, vlc_bool_t b_quick );
50 static void Error ( input_thread_t *p_input );
51 static void End ( input_thread_t *p_input );
52 static void MainLoop( input_thread_t *p_input );
54 static inline int ControlPopNoLock( input_thread_t *, int *, vlc_value_t * );
55 static void ControlReduce( input_thread_t * );
56 static vlc_bool_t Control( input_thread_t *, int, vlc_value_t );
59 static int UpdateFromAccess( input_thread_t * );
60 static int UpdateFromDemux( input_thread_t * );
61 static int UpdateMeta( input_thread_t *, vlc_bool_t );
63 static void UpdateItemLength( input_thread_t *, int64_t i_length, vlc_bool_t );
65 static void ParseOption( input_thread_t *p_input, const char *psz_option );
67 static void DecodeUrl( char * );
68 static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
70 static input_source_t *InputSourceNew( input_thread_t *);
71 static int InputSourceInit( input_thread_t *, input_source_t *,
72 char *, char *psz_forced_demux,
74 static void InputSourceClean( input_thread_t *, input_source_t * );
76 static void SlaveDemux( input_thread_t *p_input );
77 static void SlaveSeek( input_thread_t *p_input );
79 static vlc_meta_t *InputMetaUser( input_thread_t *p_input );
81 /*****************************************************************************
82 * This function creates a new input, and returns a pointer
83 * to its description. On error, it returns NULL.
85 * Variables for _public_ use:
88 * - rate,rate-slower, rate-faster
89 * - position, position-offset
91 * - title,title-next,title-prev
92 * - chapter,chapter-next, chapter-prev
93 * - program, audio-es, video-es, spu-es
94 * - audio-delay, spu-delay
99 * - seekable (if you can seek, it doesn't say if 'bar display' has be shown or not, for that check position != 0.0)
100 * * For intf callback upon changes
102 * TODO explain when Callback is called
103 * TODO complete this list (?)
104 *****************************************************************************/
105 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
108 input_thread_t *p_input; /* thread descriptor */
112 /* Allocate descriptor */
113 p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
114 if( p_input == NULL )
116 msg_Err( p_parent, "out of memory" );
120 /* Init Common fields */
121 p_input->b_eof = VLC_FALSE;
122 p_input->b_can_pace_control = VLC_TRUE;
123 p_input->i_start = 0;
126 p_input->i_title = 0;
127 p_input->title = NULL;
128 p_input->i_title_offset = p_input->i_seekpoint_offset = 0;
129 p_input->i_state = INIT_S;
130 p_input->i_rate = INPUT_RATE_DEFAULT;
131 p_input->i_bookmark = 0;
132 p_input->bookmark = NULL;
133 p_input->p_meta = NULL;
134 p_input->p_es_out = NULL;
135 p_input->p_sout = NULL;
136 p_input->b_out_pace_control = VLC_FALSE;
137 p_input->i_pts_delay = 0;
139 /* Init Input fields */
140 p_input->input.p_item = p_item;
141 p_input->input.p_access = NULL;
142 p_input->input.p_stream = NULL;
143 p_input->input.p_demux = NULL;
144 p_input->input.b_title_demux = VLC_FALSE;
145 p_input->input.i_title = 0;
146 p_input->input.title = NULL;
147 p_input->input.i_title_offset = p_input->input.i_seekpoint_offset = 0;
148 p_input->input.b_can_pace_control = VLC_TRUE;
149 p_input->input.b_eof = VLC_FALSE;
150 p_input->input.i_cr_average = 0;
153 p_input->i_slave = 0;
154 p_input->slave = NULL;
156 /* Init control buffer */
157 vlc_mutex_init( p_input, &p_input->lock_control );
158 p_input->i_control = 0;
160 /* Parse input options */
161 vlc_mutex_lock( &p_item->lock );
162 for( i = 0; i < p_item->i_options; i++ )
164 ParseOption( p_input, p_item->ppsz_options[i] );
166 vlc_mutex_unlock( &p_item->lock );
168 /* Create Object Variables for private use only */
169 input_ConfigVarInit( p_input );
171 /* Create Objects variables for public Get and Set */
172 input_ControlVarInit( p_input );
173 p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
177 var_Get( p_input, "bookmarks", &val );
180 /* FIXME: have a common cfg parsing routine used by sout and others */
181 char *psz_parser, *psz_start, *psz_end;
182 psz_parser = val.psz_string;
183 while( (psz_start = strchr( psz_parser, '{' ) ) )
185 seekpoint_t *p_seekpoint = vlc_seekpoint_New();
188 psz_end = strchr( psz_start, '}' );
189 if( !psz_end ) break;
190 psz_parser = psz_end + 1;
191 backup = *psz_parser;
194 while( (psz_end = strchr( psz_start, ',' ) ) )
197 if( !strncmp( psz_start, "name=", 5 ) )
199 p_seekpoint->psz_name = psz_start + 5;
201 else if( !strncmp( psz_start, "bytes=", 6 ) )
203 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
205 else if( !strncmp( psz_start, "time=", 5 ) )
207 p_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 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
213 p_seekpoint->i_time_offset );
214 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
215 vlc_seekpoint_Delete( p_seekpoint );
216 *psz_parser = backup;
218 free( val.psz_string );
222 /* Remove 'Now playing' info as it is probably outdated */
223 input_Control( p_input, INPUT_DEL_INFO, _("Meta-information"),
224 VLC_META_NOW_PLAYING );
230 * Initialize an input thread and run it. You will need to monitor the thread to clean
231 * up after it is done
233 * \param p_parent a vlc_object
234 * \param p_item an input item
235 * \return a pointer to the spawned input thread
237 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
238 input_item_t *p_item )
241 input_thread_t *p_input; /* thread descriptor */
243 p_input = Create( p_parent, p_item, VLC_FALSE );
244 /* Now we can attach our new input */
245 vlc_object_attach( p_input, p_parent );
247 /* Create thread and wait for its readiness. */
248 if( vlc_thread_create( p_input, "input", Run,
249 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
251 msg_Err( p_input, "cannot create input thread" );
252 vlc_object_detach( p_input );
253 vlc_object_destroy( p_input );
262 * Initialize an input thread and run it. This thread will clean after himself,
263 * you can forget about it. It can work either in blocking or non-blocking mode
265 * \param p_parent a vlc_object
266 * \param p_item an input item
267 * \param b_block should we block until read is finished ?
269 void __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
272 input_thread_t *p_input; /* thread descriptor */
274 p_input = Create( p_parent, p_item, VLC_FALSE );
275 /* Now we can attach our new input */
276 vlc_object_attach( p_input, p_parent );
280 RunAndClean( p_input );
284 if( vlc_thread_create( p_input, "input", RunAndClean,
285 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
287 msg_Err( p_input, "cannot create input thread" );
288 vlc_object_detach( p_input );
289 vlc_object_destroy( p_input );
296 * Initialize an input and initialize it to preparse the item
297 * This function is blocking. It will only accept to parse files
299 * \param p_parent a vlc_object_t
300 * \param p_item an input item
301 * \return VLC_SUCCESS or an error
303 int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
305 input_thread_t *p_input; /* thread descriptor */
307 /* Allocate descriptor */
308 p_input = Create( p_parent, p_item, VLC_TRUE );
310 /* Now we can attach our new input */
311 vlc_object_attach( p_input, p_parent );
313 Init( p_input, VLC_TRUE );
315 /* Clean up master */
316 InputSourceClean( p_input, &p_input->input );
318 /* Kill access and demux */
319 if( p_input->input.p_access ) p_input->input.p_access->b_die = VLC_TRUE;
320 if( p_input->input.p_demux ) p_input->input.p_access->b_die = VLC_TRUE;
322 /* Unload all modules */
323 if( p_input->p_es_out ) input_EsOutDelete( p_input->p_es_out );
326 if( p_input->p_meta ) vlc_meta_Delete( p_input->p_meta );
328 vlc_object_detach( p_input );
329 vlc_object_destroy( p_input );
335 * Request a running input thread to stop and die
337 * \param the input thread to stop
339 void input_StopThread( input_thread_t *p_input )
344 /* Set die for input */
345 p_input->b_die = VLC_TRUE;
347 /* We cannot touch p_input fields directly (we can from another thread),
348 * so use the vlc_object_find way, it's perfectly safe */
350 /* Set die for all access */
351 p_list = vlc_list_find( p_input, VLC_OBJECT_ACCESS, FIND_CHILD );
352 for( i = 0; i < p_list->i_count; i++ )
354 p_list->p_values[i].p_object->b_die = VLC_TRUE;
356 vlc_list_release( p_list );
358 /* Set die for all stream */
359 p_list = vlc_list_find( p_input, VLC_OBJECT_STREAM, FIND_CHILD );
360 for( i = 0; i < p_list->i_count; i++ )
362 p_list->p_values[i].p_object->b_die = VLC_TRUE;
364 vlc_list_release( p_list );
366 /* Set die for all demux */
367 p_list = vlc_list_find( p_input, VLC_OBJECT_DEMUX, FIND_CHILD );
368 for( i = 0; i < p_list->i_count; i++ )
370 p_list->p_values[i].p_object->b_die = VLC_TRUE;
372 vlc_list_release( p_list );
374 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
378 * Clean up a dead input thread
379 * This function does not return until the thread is effectively cancelled.
381 * \param the input thread to kill
383 void input_DestroyThread( input_thread_t *p_input )
385 /* Join the thread */
386 vlc_thread_join( p_input );
388 /* Delete input lock (only after thread joined) */
389 vlc_mutex_destroy( &p_input->lock_control );
391 /* TODO: maybe input_DestroyThread should also delete p_input instead
392 * of the playlist but I'm not sure if it's possible */
395 /*****************************************************************************
396 * Run: main thread loop
397 * This is the "normal" thread that spawns the input processing chain,
398 * reads the stream, cleans up and waits
399 *****************************************************************************/
400 static int Run( input_thread_t *p_input )
403 /* Signal that the thread is launched */
404 vlc_thread_ready( p_input );
406 if( Init( p_input, VLC_FALSE ) )
408 /* If we failed, wait before we are killed, and exit */
409 p_input->b_error = VLC_TRUE;
413 /* Tell we're dead */
414 p_input->b_dead = VLC_TRUE;
421 if( !p_input->b_eof && !p_input->b_error && p_input->input.b_eof )
423 /* We have finish to demux data but not to play them */
424 while( !p_input->b_die )
426 if( input_EsOutDecodersEmpty( p_input->p_es_out ) )
429 msg_Dbg( p_input, "waiting decoder fifos to empty" );
431 msleep( INPUT_IDLE_SLEEP );
434 /* We have finished */
435 p_input->b_eof = VLC_TRUE;
438 /* Wait we are asked to die */
439 if( !p_input->b_die )
450 /*****************************************************************************
451 * RunAndClean: main thread loop
452 * This is the "just forget me" thread that spawns the input processing chain,
453 * reads the stream, cleans up and releases memory
454 *****************************************************************************/
455 static int RunAndClean( input_thread_t *p_input )
457 /* Signal that the thread is launched */
458 vlc_thread_ready( p_input );
460 if( Init( p_input, VLC_FALSE ) )
462 /* If we failed, just exit */
468 if( !p_input->b_eof && !p_input->b_error && p_input->input.b_eof )
470 /* We have finish to demux data but not to play them */
471 while( !p_input->b_die )
473 if( input_EsOutDecodersEmpty( p_input->p_es_out ) )
476 msg_Dbg( p_input, "waiting decoder fifos to empty" );
478 msleep( INPUT_IDLE_SLEEP );
480 /* We have finished */
481 p_input->b_eof = VLC_TRUE;
488 vlc_object_detach( p_input );
489 vlc_object_destroy( p_input );
495 /*****************************************************************************
496 * Main loop: Fill buffers from access, and demux
497 *****************************************************************************/
498 static void MainLoop( input_thread_t *p_input )
500 int64_t i_intf_update = 0;
501 while( !p_input->b_die && !p_input->b_error && !p_input->input.b_eof )
503 vlc_bool_t b_force_update = VLC_FALSE;
509 if( p_input->i_state != PAUSE_S )
511 if( p_input->i_stop <= 0 || p_input->i_time < p_input->i_stop )
512 i_ret=p_input->input.p_demux->pf_demux(p_input->input.p_demux);
519 if( p_input->input.b_title_demux &&
520 p_input->input.p_demux->info.i_update )
522 i_ret = UpdateFromDemux( p_input );
523 b_force_update = VLC_TRUE;
525 else if( !p_input->input.b_title_demux &&
526 p_input->input.p_access &&
527 p_input->input.p_access->info.i_update )
529 i_ret = UpdateFromAccess( p_input );
530 b_force_update = VLC_TRUE;
534 if( i_ret == 0 ) /* EOF */
538 var_Get( p_input, "input-repeat", &repeat );
539 if( repeat.i_int == 0 )
541 /* End of file - we do not set b_die because only the
542 * playlist is allowed to do so. */
543 msg_Dbg( p_input, "EOF reached" );
544 p_input->input.b_eof = VLC_TRUE;
548 msg_Dbg( p_input, "repeating the same input (%d)",
550 if( repeat.i_int > 0 )
553 var_Set( p_input, "input-repeat", repeat );
556 /* Seek to start title/seekpoint */
557 val.i_int = p_input->input.i_title_start -
558 p_input->input.i_title_offset;
559 if( val.i_int < 0 || val.i_int >= p_input->input.i_title )
561 input_ControlPush( p_input,
562 INPUT_CONTROL_SET_TITLE, &val );
564 val.i_int = p_input->input.i_seekpoint_start -
565 p_input->input.i_seekpoint_offset;
566 if( val.i_int > 0 /* TODO: check upper boundary */ )
567 input_ControlPush( p_input,
568 INPUT_CONTROL_SET_SEEKPOINT, &val );
570 /* Seek to start position */
571 if( p_input->i_start > 0 )
573 val.i_time = p_input->i_start;
574 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
580 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
587 p_input->b_error = VLC_TRUE;
590 if( i_ret > 0 && p_input->i_slave > 0 )
592 SlaveDemux( p_input );
602 vlc_mutex_lock( &p_input->lock_control );
603 ControlReduce( p_input );
604 while( !ControlPopNoLock( p_input, &i_type, &val ) )
606 msg_Dbg( p_input, "control type=%d", i_type );
607 if( Control( p_input, i_type, val ) )
608 b_force_update = VLC_TRUE;
610 vlc_mutex_unlock( &p_input->lock_control );
612 if( b_force_update || i_intf_update < mdate() )
616 int64_t i_time, i_length;
617 /* update input status variables */
618 if( !demux2_Control( p_input->input.p_demux,
619 DEMUX_GET_POSITION, &f_pos ) )
621 val.f_float = (float)f_pos;
622 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
624 if( !demux2_Control( p_input->input.p_demux,
625 DEMUX_GET_TIME, &i_time ) )
627 p_input->i_time = i_time;
629 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
631 if( !demux2_Control( p_input->input.p_demux,
632 DEMUX_GET_LENGTH, &i_length ) )
635 var_Get( p_input, "length", &old_val );
636 val.i_time = i_length;
637 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
639 if( old_val.i_time != val.i_time )
641 UpdateItemLength( p_input, i_length, VLC_TRUE );
645 var_SetBool( p_input, "intf-change", VLC_TRUE );
646 i_intf_update = mdate() + I64C(150000);
652 static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
658 vlc_meta_t *p_meta, *p_meta_tmp;
662 /* Initialize optional stream output. (before access/demuxer)
663 * XXX: we add a special case if the uri starts by vlc.
664 * else 'vlc in.file --sout "" vlc:quit' cannot work (the output will
665 * be destroyed in case of a file).
666 * (this will break playing of file starting by 'vlc:' but I don't
667 * want to add more logic, just force file by file:// or code it ;)
671 psz = var_GetString( p_input, "sout" );
672 if( *psz && strncasecmp( p_input->input.p_item->psz_uri, "vlc:", 4 ) )
674 p_input->p_sout = sout_NewInstance( p_input, psz );
675 if( p_input->p_sout == NULL )
677 msg_Err( p_input, "cannot start stream output instance, " \
687 p_input->p_es_out = input_EsOutNew( p_input );
688 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
689 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
691 if( InputSourceInit( p_input, &p_input->input,
692 p_input->input.p_item->psz_uri, NULL, b_quick ) )
697 /* Create global title (from master) */
700 p_input->i_title = p_input->input.i_title;
701 p_input->title = p_input->input.title;
702 p_input->i_title_offset = p_input->input.i_title_offset;
703 p_input->i_seekpoint_offset = p_input->input.i_seekpoint_offset;
704 if( p_input->i_title > 0 )
706 /* Setup variables */
707 input_ControlVarNavigation( p_input );
708 input_ControlVarTitle( p_input, 0 );
712 p_input->b_can_pace_control = p_input->input.b_can_pace_control;
713 p_input->b_can_pause = p_input->input.b_can_pause;
716 if( p_input->i_pts_delay < 0 )
717 p_input->i_pts_delay = 0;
719 /* If the desynchronisation requested by the user is < 0, we need to
720 * cache more data. */
721 var_Get( p_input, "audio-desync", &val );
722 if( val.i_int < 0 ) p_input->i_pts_delay -= (val.i_int * 1000);
724 /* Update cr_average depending on the caching */
725 p_input->input.i_cr_average *= (10 * p_input->i_pts_delay / 200000);
726 p_input->input.i_cr_average /= 10;
727 if( p_input->input.i_cr_average < 10 ) p_input->input.i_cr_average = 10;
730 /* Load master infos */
732 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_LENGTH,
733 &val.i_time ) && val.i_time > 0 )
735 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
736 UpdateItemLength( p_input, val.i_time, b_quick );
737 p_input->input.p_item->i_duration = val.i_time;
740 /* Start title/chapter */
743 val.i_int = p_input->input.i_title_start -
744 p_input->input.i_title_offset;
745 if( val.i_int > 0 && val.i_int < p_input->input.i_title )
746 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
747 val.i_int = p_input->input.i_seekpoint_start -
748 p_input->input.i_seekpoint_offset;
749 if( val.i_int > 0 /* TODO: check upper boundary */ )
750 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
754 p_input->i_start = (int64_t)var_GetInteger( p_input, "start-time" ) *
756 p_input->i_stop = (int64_t)var_GetInteger( p_input, "stop-time" ) *
759 if( p_input->i_start > 0 )
761 if( p_input->i_start >= val.i_time )
763 msg_Warn( p_input, "invalid start-time ignored" );
769 msg_Dbg( p_input, "starting at time: %ds",
770 (int)( p_input->i_start / I64C(1000000) ) );
772 s.i_time = p_input->i_start;
773 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
776 if( p_input->i_stop > 0 && p_input->i_stop <= p_input->i_start )
778 msg_Warn( p_input, "invalid stop-time ignored" );
784 /* Get fps and set it if not already set */
785 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) &&
788 float f_requested_fps;
790 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
791 var_SetFloat( p_input, "sub-original-fps", f_fps );
793 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
794 if( f_requested_fps != f_fps )
796 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
798 var_SetFloat( p_input, "sub-fps", f_requested_fps );
802 i_delay = var_CreateGetInteger( p_input, "sub-delay" );
805 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
809 /* Look for and add subtitle files */
810 psz_subtitle = var_GetString( p_input, "sub-file" );
817 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
819 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
822 sub = InputSourceNew( p_input );
823 if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle",
826 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
829 if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list,
832 if( count.i_int == 0 )
834 /* if it was first one, there is disable too */
836 if( count.i_int < list.p_list->i_count )
838 input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
839 &list.p_list->p_values[count.i_int] );
841 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list,
847 var_Get( p_input, "sub-autodetect-file", &val );
850 char *psz_autopath = var_GetString( p_input, "sub-autodetect-path" );
851 char **subs = subtitles_Detect( p_input, psz_autopath,
852 p_input->input.p_item->psz_uri );
855 for( i = 0; subs && subs[i]; i++ )
857 if( strcmp( psz_subtitle, subs[i] ) )
859 sub = InputSourceNew( p_input );
860 if( !InputSourceInit( p_input, sub, subs[i], "subtitle",
863 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
868 if( subs ) free( subs );
869 if( psz_autopath ) free( psz_autopath );
871 free( psz_subtitle );
874 psz = var_GetString( p_input, "input-slave" );
878 input_source_t *slave;
881 while( *psz == ' ' || *psz == '#' )
885 if( ( psz_delim = strchr( psz, '#' ) ) )
894 msg_Dbg( p_input, "adding slave input '%s'", psz );
895 slave = InputSourceNew( p_input );
896 if( !InputSourceInit( p_input, slave, psz, NULL, VLC_FALSE ) )
898 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
903 if( psz ) free( psz );
907 p_input->i_start = 0;
908 p_input->i_start = 0;
914 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
915 i_es_out_mode = ES_OUT_MODE_AUTO;
917 if( p_input->p_sout )
919 var_Get( p_input, "sout-all", &val );
922 i_es_out_mode = ES_OUT_MODE_ALL;
927 var_Get( p_input, "programs", &val );
928 if ( val.p_list && val.p_list->i_count )
930 i_es_out_mode = ES_OUT_MODE_PARTIAL;
931 /* Note : we should remove the "program" callback. */
934 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
938 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
940 /* Inform the demuxer about waited group (needed only for DVB) */
941 if( i_es_out_mode == ES_OUT_MODE_ALL )
943 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
945 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
947 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1,
952 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP,
953 (int) var_GetInteger( p_input, "program" ), NULL );
956 if( p_input->p_sout )
958 if( p_input->p_sout->i_out_pace_nocontrol > 0 )
960 p_input->b_out_pace_control = VLC_FALSE;
964 p_input->b_out_pace_control = VLC_TRUE;
967 if( p_input->b_can_pace_control && p_input->b_out_pace_control )
969 /* We don't want a high input priority here or we'll
970 * end-up sucking up all the CPU time */
971 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
974 msg_Dbg( p_input, "starting in %s mode",
975 p_input->b_out_pace_control ? "asynch" : "synch" );
979 /* Get meta data from users */
980 p_meta_tmp = InputMetaUser( p_input );
982 /* Get meta data from master input */
983 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_META, &p_meta ) )
991 else if( p_meta_tmp )
993 vlc_meta_Merge( p_meta, p_meta_tmp );
994 vlc_meta_Delete( p_meta_tmp );
997 /* Access_file does not give any meta, and there are no slave */
1000 if( !p_input->input.p_access ||
1001 access2_Control( p_input->input.p_access, ACCESS_GET_META,
1005 if( p_meta == NULL )
1007 p_meta = p_meta_tmp;
1009 else if( p_meta_tmp )
1011 vlc_meta_Merge( p_meta, p_meta_tmp );
1012 vlc_meta_Delete( p_meta_tmp );
1015 /* Get meta data from slave input */
1016 for( i = 0; i < p_input->i_slave; i++ )
1018 vlc_meta_t *p_meta_slave;
1020 if( !demux2_Control( p_input->slave[i]->p_demux,
1021 DEMUX_GET_META, &p_meta_slave ) )
1023 if( p_meta == NULL )
1025 p_meta = p_meta_slave;
1027 else if( p_meta_slave )
1029 vlc_meta_Merge( p_meta, p_meta_slave );
1030 vlc_meta_Delete( p_meta_slave );
1034 if( p_input->slave[i]->p_access &&
1035 !access2_Control( p_input->slave[i]->p_access,
1036 ACCESS_GET_META, &p_meta_slave ) )
1038 if( p_meta == NULL )
1040 p_meta = p_meta_slave;
1042 else if( p_meta_slave )
1044 vlc_meta_Merge( p_meta, p_meta_slave );
1045 vlc_meta_Delete( p_meta_slave );
1051 p_input->p_meta = p_meta;
1052 UpdateMeta( p_input, b_quick );
1056 msg_Dbg( p_input, "`%s' successfully opened",
1057 p_input->input.p_item->psz_uri );
1061 /* initialization is complete */
1062 p_input->i_state = PLAYING_S;
1064 val.i_int = PLAYING_S;
1065 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1070 if( p_input->p_es_out )
1071 input_EsOutDelete( p_input->p_es_out );
1073 if( p_input->p_sout )
1074 sout_DeleteInstance( p_input->p_sout );
1076 /* Mark them deleted */
1077 p_input->input.p_demux = NULL;
1078 p_input->input.p_stream = NULL;
1079 p_input->input.p_access = NULL;
1080 p_input->p_es_out = NULL;
1081 p_input->p_sout = NULL;
1083 return VLC_EGENERIC;
1086 /*****************************************************************************
1087 * Error: RunThread() error loop
1088 *****************************************************************************
1089 * This function is called when an error occurred during thread main's loop.
1090 *****************************************************************************/
1091 static void Error( input_thread_t *p_input )
1093 while( !p_input->b_die )
1096 msleep( INPUT_IDLE_SLEEP );
1100 /*****************************************************************************
1101 * End: end the input thread
1102 *****************************************************************************/
1103 static void End( input_thread_t * p_input )
1108 msg_Dbg( p_input, "closing input" );
1110 /* We are at the end */
1111 p_input->i_state = END_S;
1114 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1116 /* Clean control variables */
1117 input_ControlVarClean( p_input );
1119 /* Clean up master */
1120 InputSourceClean( p_input, &p_input->input );
1123 for( i = 0; i < p_input->i_slave; i++ )
1125 InputSourceClean( p_input, p_input->slave[i] );
1126 free( p_input->slave[i] );
1128 if( p_input->slave ) free( p_input->slave );
1130 /* Unload all modules */
1131 if( p_input->p_es_out )
1132 input_EsOutDelete( p_input->p_es_out );
1134 /* Close optional stream output instance */
1135 if( p_input->p_sout )
1137 vlc_object_t *p_pl =
1138 vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1141 if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
1143 /* attach sout to the playlist */
1144 msg_Dbg( p_input, "keeping sout" );
1145 vlc_object_detach( p_input->p_sout );
1146 vlc_object_attach( p_input->p_sout, p_pl );
1150 msg_Dbg( p_input, "destroying sout" );
1151 sout_DeleteInstance( p_input->p_sout );
1154 vlc_object_release( p_pl );
1158 if( p_input->p_meta )
1159 vlc_meta_Delete( p_input->p_meta );
1161 /* Tell we're dead */
1162 p_input->b_dead = VLC_TRUE;
1165 /*****************************************************************************
1167 *****************************************************************************/
1168 static inline int ControlPopNoLock( input_thread_t *p_input,
1169 int *pi_type, vlc_value_t *p_val )
1171 if( p_input->i_control <= 0 )
1173 return VLC_EGENERIC;
1176 *pi_type = p_input->control[0].i_type;
1177 *p_val = p_input->control[0].val;
1179 p_input->i_control--;
1180 if( p_input->i_control > 0 )
1184 for( i = 0; i < p_input->i_control; i++ )
1186 p_input->control[i].i_type = p_input->control[i+1].i_type;
1187 p_input->control[i].val = p_input->control[i+1].val;
1194 static void ControlReduce( input_thread_t *p_input )
1197 for( i = 1; i < p_input->i_control; i++ )
1199 const int i_lt = p_input->control[i-1].i_type;
1200 const int i_ct = p_input->control[i].i_type;
1202 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1203 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->i_control,
1207 ( i_ct == INPUT_CONTROL_SET_STATE ||
1208 i_ct == INPUT_CONTROL_SET_RATE ||
1209 i_ct == INPUT_CONTROL_SET_POSITION ||
1210 i_ct == INPUT_CONTROL_SET_TIME ||
1211 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1212 i_ct == INPUT_CONTROL_SET_TITLE ||
1213 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1214 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1217 // msg_Dbg( p_input, "merged at %d", i );
1218 /* Remove the i-1 */
1219 for( j = i; j < p_input->i_control; j++ )
1220 p_input->control[j-1] = p_input->control[j];
1221 p_input->i_control--;
1225 /* TODO but that's not that important
1226 - merge SET_X with SET_X_CMD
1227 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1228 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1235 static vlc_bool_t Control( input_thread_t *p_input, int i_type,
1238 vlc_bool_t b_force_update = VLC_FALSE;
1240 if( !p_input ) return b_force_update;
1244 case INPUT_CONTROL_SET_DIE:
1245 msg_Dbg( p_input, "control: stopping input" );
1246 /* Mark all submodules to die */
1247 if( p_input->input.p_access )
1248 p_input->input.p_access->b_die = VLC_TRUE;
1249 if( p_input->input.p_stream )
1250 p_input->input.p_stream->b_die = VLC_TRUE;
1251 p_input->input.p_demux->b_die = VLC_TRUE;
1253 p_input->b_die = VLC_TRUE;
1256 case INPUT_CONTROL_SET_POSITION:
1257 case INPUT_CONTROL_SET_POSITION_OFFSET:
1260 if( i_type == INPUT_CONTROL_SET_POSITION )
1262 f_pos = val.f_float;
1266 /* Should not fail */
1267 demux2_Control( p_input->input.p_demux,
1268 DEMUX_GET_POSITION, &f_pos );
1269 f_pos += val.f_float;
1271 if( f_pos < 0.0 ) f_pos = 0.0;
1272 if( f_pos > 1.0 ) f_pos = 1.0;
1273 /* Reset the decoders states and clock synch (before calling the demuxer */
1274 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1275 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1276 if( demux2_Control( p_input->input.p_demux, DEMUX_SET_POSITION,
1279 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1280 "%2.1f%% failed", f_pos * 100 );
1284 if( p_input->i_slave > 0 )
1285 SlaveSeek( p_input );
1287 b_force_update = VLC_TRUE;
1292 case INPUT_CONTROL_SET_TIME:
1293 case INPUT_CONTROL_SET_TIME_OFFSET:
1298 if( i_type == INPUT_CONTROL_SET_TIME )
1300 i_time = val.i_time;
1304 /* Should not fail */
1305 demux2_Control( p_input->input.p_demux,
1306 DEMUX_GET_TIME, &i_time );
1307 i_time += val.i_time;
1309 if( i_time < 0 ) i_time = 0;
1311 /* Reset the decoders states and clock synch (before calling the demuxer */
1312 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1313 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1315 i_ret = demux2_Control( p_input->input.p_demux,
1316 DEMUX_SET_TIME, i_time );
1321 /* Emulate it with a SET_POS */
1322 demux2_Control( p_input->input.p_demux,
1323 DEMUX_GET_LENGTH, &i_length );
1326 double f_pos = (double)i_time / (double)i_length;
1327 i_ret = demux2_Control( p_input->input.p_demux,
1328 DEMUX_SET_POSITION, f_pos );
1333 msg_Warn( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) "I64Fd
1334 " failed or not possible", i_time );
1338 if( p_input->i_slave > 0 )
1339 SlaveSeek( p_input );
1341 b_force_update = VLC_TRUE;
1346 case INPUT_CONTROL_SET_STATE:
1347 if( ( val.i_int == PLAYING_S && p_input->i_state == PAUSE_S ) ||
1348 ( val.i_int == PAUSE_S && p_input->i_state == PAUSE_S ) )
1351 if( p_input->input.p_access )
1352 i_ret = access2_Control( p_input->input.p_access,
1353 ACCESS_SET_PAUSE_STATE, VLC_FALSE );
1355 i_ret = demux2_Control( p_input->input.p_demux,
1356 DEMUX_SET_PAUSE_STATE, VLC_FALSE );
1360 /* FIXME What to do ? */
1361 msg_Warn( p_input, "cannot unset pause -> EOF" );
1362 vlc_mutex_unlock( &p_input->lock_control );
1363 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1364 vlc_mutex_lock( &p_input->lock_control );
1367 b_force_update = VLC_TRUE;
1369 /* Switch to play */
1370 p_input->i_state = PLAYING_S;
1371 val.i_int = PLAYING_S;
1372 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1375 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1376 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1378 else if( val.i_int == PAUSE_S && p_input->i_state == PLAYING_S &&
1379 p_input->b_can_pause )
1382 if( p_input->input.p_access )
1383 i_ret = access2_Control( p_input->input.p_access,
1384 ACCESS_SET_PAUSE_STATE, VLC_TRUE );
1386 i_ret = demux2_Control( p_input->input.p_demux,
1387 DEMUX_SET_PAUSE_STATE, VLC_TRUE );
1389 b_force_update = VLC_TRUE;
1393 msg_Warn( p_input, "cannot set pause state" );
1394 val.i_int = p_input->i_state;
1398 val.i_int = PAUSE_S;
1401 /* Switch to new state */
1402 p_input->i_state = val.i_int;
1403 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1405 else if( val.i_int == PAUSE_S && !p_input->b_can_pause )
1407 b_force_update = VLC_TRUE;
1409 /* Correct "state" value */
1410 val.i_int = p_input->i_state;
1411 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1413 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1415 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1419 case INPUT_CONTROL_SET_RATE:
1420 case INPUT_CONTROL_SET_RATE_SLOWER:
1421 case INPUT_CONTROL_SET_RATE_FASTER:
1425 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1426 i_rate = p_input->i_rate * 2;
1427 else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
1428 i_rate = p_input->i_rate / 2;
1432 if( i_rate < INPUT_RATE_MIN )
1434 msg_Dbg( p_input, "cannot set rate faster" );
1435 i_rate = INPUT_RATE_MIN;
1437 else if( i_rate > INPUT_RATE_MAX )
1439 msg_Dbg( p_input, "cannot set rate slower" );
1440 i_rate = INPUT_RATE_MAX;
1442 if( i_rate != INPUT_RATE_DEFAULT &&
1443 ( !p_input->b_can_pace_control ||
1444 ( p_input->p_sout && !p_input->b_out_pace_control ) ) )
1446 msg_Dbg( p_input, "cannot change rate" );
1447 i_rate = INPUT_RATE_DEFAULT;
1449 if( i_rate != p_input->i_rate )
1451 p_input->i_rate = i_rate;
1453 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
1455 /* We haven't send data to decoder when rate != default */
1456 if( i_rate == INPUT_RATE_DEFAULT )
1457 input_EsOutDiscontinuity( p_input->p_es_out, VLC_TRUE );
1460 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1462 b_force_update = VLC_TRUE;
1467 case INPUT_CONTROL_SET_PROGRAM:
1468 /* No need to force update, es_out does it if needed */
1469 es_out_Control( p_input->p_es_out,
1470 ES_OUT_SET_GROUP, val.i_int );
1472 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1476 case INPUT_CONTROL_SET_ES:
1477 /* No need to force update, es_out does it if needed */
1478 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
1479 input_EsOutGetFromID( p_input->p_es_out,
1483 case INPUT_CONTROL_SET_AUDIO_DELAY:
1484 input_EsOutSetDelay( p_input->p_es_out,
1485 AUDIO_ES, val.i_time );
1486 var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
1489 case INPUT_CONTROL_SET_SPU_DELAY:
1490 input_EsOutSetDelay( p_input->p_es_out,
1491 SPU_ES, val.i_time );
1492 var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
1495 case INPUT_CONTROL_SET_TITLE:
1496 case INPUT_CONTROL_SET_TITLE_NEXT:
1497 case INPUT_CONTROL_SET_TITLE_PREV:
1498 if( p_input->input.b_title_demux &&
1499 p_input->input.i_title > 0 )
1502 /* FIXME handle demux title */
1503 demux_t *p_demux = p_input->input.p_demux;
1506 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1507 i_title = p_demux->info.i_title - 1;
1508 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1509 i_title = p_demux->info.i_title + 1;
1511 i_title = val.i_int;
1513 if( i_title >= 0 && i_title < p_input->input.i_title )
1515 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1516 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1518 demux2_Control( p_demux, DEMUX_SET_TITLE, i_title );
1519 input_ControlVarTitle( p_input, i_title );
1522 else if( p_input->input.i_title > 0 )
1524 access_t *p_access = p_input->input.p_access;
1527 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1528 i_title = p_access->info.i_title - 1;
1529 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1530 i_title = p_access->info.i_title + 1;
1532 i_title = val.i_int;
1534 if( i_title >= 0 && i_title < p_input->input.i_title )
1536 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1537 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1539 access2_Control( p_access, ACCESS_SET_TITLE, i_title );
1540 stream_AccessReset( p_input->input.p_stream );
1544 case INPUT_CONTROL_SET_SEEKPOINT:
1545 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1546 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1547 if( p_input->input.b_title_demux &&
1548 p_input->input.i_title > 0 )
1550 demux_t *p_demux = p_input->input.p_demux;
1552 int64_t i_input_time;
1553 int64_t i_seekpoint_time;
1555 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1557 i_seekpoint = p_demux->info.i_seekpoint;
1558 i_seekpoint_time = p_input->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1559 if( i_seekpoint_time >= 0 &&
1560 !demux2_Control( p_demux,
1561 DEMUX_GET_TIME, &i_input_time ) )
1563 if ( i_input_time < i_seekpoint_time + 3000000 )
1569 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1570 i_seekpoint = p_demux->info.i_seekpoint + 1;
1572 i_seekpoint = val.i_int;
1574 if( i_seekpoint >= 0 && i_seekpoint <
1575 p_input->input.title[p_demux->info.i_title]->i_seekpoint )
1577 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1578 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1580 demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1583 else if( p_input->input.i_title > 0 )
1585 demux_t *p_demux = p_input->input.p_demux;
1586 access_t *p_access = p_input->input.p_access;
1588 int64_t i_input_time;
1589 int64_t i_seekpoint_time;
1591 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1593 i_seekpoint = p_access->info.i_seekpoint;
1594 i_seekpoint_time = p_input->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1595 if( i_seekpoint_time >= 0 &&
1596 demux2_Control( p_demux,
1597 DEMUX_GET_TIME, &i_input_time ) )
1599 if ( i_input_time < i_seekpoint_time + 3000000 )
1605 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1606 i_seekpoint = p_access->info.i_seekpoint + 1;
1608 i_seekpoint = val.i_int;
1610 if( i_seekpoint >= 0 && i_seekpoint <
1611 p_input->input.title[p_access->info.i_title]->i_seekpoint )
1613 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1614 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1616 access2_Control( p_access, ACCESS_SET_SEEKPOINT, i_seekpoint );
1617 stream_AccessReset( p_input->input.p_stream );
1622 case INPUT_CONTROL_ADD_SLAVE:
1623 if( val.psz_string )
1625 input_source_t *slave = InputSourceNew( p_input );
1627 if( !InputSourceInit( p_input, slave, val.psz_string, NULL,
1630 vlc_meta_t *p_meta_new = NULL;
1635 msg_Dbg( p_input, "adding %s as slave on the fly",
1639 if( demux2_Control( p_input->input.p_demux,
1640 DEMUX_GET_TIME, &i_time ) )
1642 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
1643 InputSourceClean( p_input, slave );
1647 if( demux2_Control( slave->p_demux,
1648 DEMUX_SET_TIME, i_time ) )
1650 msg_Err( p_input, "seek failed for new slave" );
1651 InputSourceClean( p_input, slave );
1657 /* Get meta (access and demux) */
1658 if( access2_Control( slave->p_access,
1659 ACCESS_GET_META, &p_meta_new ) )
1661 if( !demux2_Control( slave->p_demux,
1662 DEMUX_GET_META, &p_meta ) )
1666 vlc_meta_Merge( p_meta_new, p_meta );
1667 vlc_meta_Delete( p_meta );
1671 p_meta_new = p_meta;
1677 if( p_input->p_meta )
1679 vlc_meta_Merge( p_input->p_meta, p_meta_new );
1680 vlc_meta_Delete( p_meta_new );
1684 p_input->p_meta = p_meta_new;
1686 UpdateMeta( p_input, VLC_FALSE );
1689 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
1693 msg_Warn( p_input, "failed to add %s as slave",
1697 free( val.psz_string );
1701 case INPUT_CONTROL_SET_BOOKMARK:
1703 msg_Err( p_input, "not yet implemented" );
1707 return b_force_update;
1710 /*****************************************************************************
1712 *****************************************************************************/
1713 static int UpdateFromDemux( input_thread_t *p_input )
1715 demux_t *p_demux = p_input->input.p_demux;
1718 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
1720 v.i_int = p_demux->info.i_title;
1721 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1723 input_ControlVarTitle( p_input, p_demux->info.i_title );
1725 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
1727 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
1729 v.i_int = p_demux->info.i_seekpoint;
1730 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1732 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1734 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
1736 /* Hmmm only works with master input */
1737 if( p_input->input.p_demux == p_demux )
1739 int i_title_end = p_input->input.i_title_end -
1740 p_input->input.i_title_offset;
1741 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1742 p_input->input.i_seekpoint_offset;
1744 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
1746 if( p_demux->info.i_title > i_title_end ||
1747 ( p_demux->info.i_title == i_title_end &&
1748 p_demux->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1750 else if( i_seekpoint_end >=0 )
1752 if( p_demux->info.i_seekpoint > i_seekpoint_end ) return 0;
1754 else if( i_title_end >= 0 )
1756 if( p_demux->info.i_title > i_title_end ) return 0;
1763 /*****************************************************************************
1765 *****************************************************************************/
1766 static int UpdateFromAccess( input_thread_t *p_input )
1768 access_t *p_access = p_input->input.p_access;
1771 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
1773 v.i_int = p_access->info.i_title;
1774 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1776 input_ControlVarTitle( p_input, p_access->info.i_title );
1778 stream_AccessUpdate( p_input->input.p_stream );
1780 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
1782 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
1784 v.i_int = p_access->info.i_seekpoint;
1785 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1787 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1789 if( p_access->info.i_update & INPUT_UPDATE_META )
1791 /* TODO maybe multi - access ? */
1793 if( !access2_Control( p_input->input.p_access,ACCESS_GET_META,&p_meta))
1795 if( p_input->p_meta )
1797 vlc_meta_Merge( p_input->p_meta, p_meta );
1798 vlc_meta_Delete( p_meta );
1802 p_input->p_meta = p_meta;
1805 UpdateMeta( p_input, VLC_FALSE );
1806 var_SetBool( p_input, "item-change", p_input->input.p_item->i_id );
1808 p_access->info.i_update &= ~INPUT_UPDATE_META;
1811 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
1813 /* Hmmm only works with master input */
1814 if( p_input->input.p_access == p_access )
1816 int i_title_end = p_input->input.i_title_end -
1817 p_input->input.i_title_offset;
1818 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1819 p_input->input.i_seekpoint_offset;
1821 if( i_title_end >= 0 && i_seekpoint_end >=0 )
1823 if( p_access->info.i_title > i_title_end ||
1824 ( p_access->info.i_title == i_title_end &&
1825 p_access->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1827 else if( i_seekpoint_end >=0 )
1829 if( p_access->info.i_seekpoint > i_seekpoint_end ) return 0;
1831 else if( i_title_end >= 0 )
1833 if( p_access->info.i_title > i_title_end ) return 0;
1840 /*****************************************************************************
1842 *****************************************************************************/
1843 static int UpdateMeta( input_thread_t *p_input, vlc_bool_t b_quick )
1845 vlc_meta_t *p_meta = p_input->p_meta;
1848 if( !p_meta || p_meta->i_meta == 0 )
1851 if( !b_quick ) msg_Dbg( p_input, "meta information:" );
1852 for( i = 0; i < p_meta->i_meta; i++ )
1855 msg_Dbg( p_input, " - '%s' = '%s'",
1856 _(p_meta->name[i]), p_meta->value[i] );
1858 if( !strcmp(p_meta->name[i], VLC_META_TITLE) && p_meta->value[i] &&
1859 !p_input->input.p_item->b_fixed_name )
1860 input_Control( p_input, INPUT_SET_NAME, p_meta->value[i] );
1862 if( !strcmp( p_meta->name[i], VLC_META_AUTHOR ) )
1863 input_Control( p_input, INPUT_ADD_INFO, _("General"),
1864 _("Author"), p_meta->value[i] );
1866 input_Control( p_input, INPUT_ADD_INFO, _("Meta-information"),
1867 _(p_meta->name[i]), "%s", p_meta->value[i] );
1870 for( i = 0; i < p_meta->i_track; i++ )
1872 vlc_meta_t *tk = p_meta->track[i];
1875 if( tk->i_meta > 0 )
1877 char *psz_cat = malloc( strlen(_("Stream")) + 10 );
1879 msg_Dbg( p_input, " - track[%d]:", i );
1881 sprintf( psz_cat, "%s %d", _("Stream"), i );
1882 for( j = 0; j < tk->i_meta; j++ )
1884 msg_Dbg( p_input, " - '%s' = '%s'", _(tk->name[j]),
1887 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1888 _(tk->name[j]), "%s", tk->value[j] );
1893 if( p_input->p_sout && p_input->p_sout->p_meta == NULL )
1895 p_input->p_sout->p_meta = vlc_meta_Duplicate( p_meta );
1901 /*****************************************************************************
1903 *****************************************************************************/
1904 static void UpdateItemLength( input_thread_t *p_input, int64_t i_length,
1905 vlc_bool_t b_quick )
1907 playlist_t *p_playlist;
1908 char psz_buffer[MSTRTIME_MAX_SIZE];
1910 vlc_mutex_lock( &p_input->input.p_item->lock );
1911 p_input->input.p_item->i_duration = i_length;
1912 vlc_mutex_unlock( &p_input->input.p_item->lock );
1914 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
1918 var_SetInteger( p_playlist, "item-change",
1919 p_input->input.p_item->i_id );
1920 vlc_object_release( p_playlist );
1923 input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
1924 msecstotimestr( psz_buffer, i_length / 1000 ) );
1927 /*****************************************************************************
1929 *****************************************************************************/
1930 static input_source_t *InputSourceNew( input_thread_t *p_input )
1932 input_source_t *in = (input_source_t*) malloc( sizeof( input_source_t ) );
1936 msg_Err( p_input, "out of memory for new input source" );
1941 in->p_access = NULL;
1942 in->p_stream = NULL;
1944 in->b_title_demux = VLC_FALSE;
1947 in->b_can_pace_control = VLC_TRUE;
1948 in->b_eof = VLC_FALSE;
1949 in->i_cr_average = 0;
1954 /*****************************************************************************
1956 *****************************************************************************/
1957 static int InputSourceInit( input_thread_t *p_input,
1958 input_source_t *in, char *psz_mrl,
1959 char *psz_forced_demux, vlc_bool_t b_quick )
1961 char *psz_dup = strdup( psz_mrl );
1969 if( !in ) return VLC_EGENERIC;
1974 MRLSplit( VLC_OBJECT(p_input), psz_dup,
1975 &psz_access, &psz_demux, &psz_path );
1977 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
1978 psz_mrl, psz_access, psz_demux, psz_path );
1980 /* Hack to allow udp://@:port syntax */
1982 (strncmp( psz_access, "udp", 3 ) &&
1983 strncmp( psz_access, "rtp", 3 )) )
1985 /* Find optional titles and seekpoints */
1986 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
1987 &in->i_seekpoint_start, &in->i_seekpoint_end );
1989 if( psz_forced_demux && *psz_forced_demux )
1991 psz_demux = psz_forced_demux;
1993 else if( !psz_demux || *psz_demux == '\0' )
1995 /* special hack for forcing a demuxer with --demux=module
1996 * (and do nothing with a list) */
1997 char *psz_var_demux = var_GetString( p_input, "demux" );
1999 if( *psz_var_demux != '\0' &&
2000 !strchr(psz_var_demux, ',' ) &&
2001 !strchr(psz_var_demux, ':' ) )
2003 psz_demux = psz_var_demux;
2005 msg_Dbg( p_input, "Enforce demux ` %s'", psz_demux );
2007 else if( psz_var_demux )
2009 free( psz_var_demux );
2013 /* Try access_demux if no demux given */
2014 if( *psz_demux == '\0' )
2016 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
2017 NULL, p_input->p_es_out, VLC_FALSE );
2023 msg_Dbg( p_input, "trying to preparse %s", psz_path );
2024 psz_demux = strdup( "" );
2025 psz_access = strdup( "file" );
2030 int64_t i_pts_delay;
2032 /* Get infos from access_demux */
2033 demux2_Control( in->p_demux,
2034 DEMUX_GET_PTS_DELAY, &i_pts_delay );
2035 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2037 in->b_title_demux = VLC_TRUE;
2038 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2039 &in->title, &in->i_title,
2040 &in->i_title_offset, &in->i_seekpoint_offset ) )
2045 demux2_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
2046 &in->b_can_pace_control );
2047 demux2_Control( in->p_demux, DEMUX_CAN_PAUSE,
2051 demux2_Control( in->p_demux, DEMUX_CAN_SEEK,
2057 int64_t i_pts_delay;
2059 /* Now try a real access */
2060 in->p_access = access2_New( p_input, psz_access, psz_demux, psz_path,
2063 /* Access failed, URL encoded ? */
2064 if( in->p_access == NULL && strchr( psz_path, '%' ) )
2066 DecodeUrl( psz_path );
2068 msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
2069 psz_access, psz_demux, psz_path );
2071 in->p_access = access2_New( p_input,
2072 psz_access, psz_demux, psz_path,
2075 #ifndef WIN32 /* Remove this gross hack from the win32 build as colons
2076 * are forbidden in filenames on Win32. */
2078 /* Maybe we got something like: /Volumes/toto:titi/gabu.mpg */
2079 if( in->p_access == NULL &&
2080 *psz_access == '\0' && ( *psz_demux || *psz_path ) )
2082 if( psz_dup ) free( psz_dup );
2083 psz_dup = strdup( psz_mrl );
2088 in->p_access = access2_New( p_input,
2089 psz_access, psz_demux, psz_path,
2094 if( in->p_access == NULL )
2096 msg_Err( p_input, "no suitable access module for `%s'", psz_mrl );
2097 intf_UserFatal( p_input, "Unable to open '%s'", psz_mrl );
2102 psz_tmp = psz = var_GetString( p_input, "access-filter" );
2103 while( psz && *psz )
2105 access_t *p_access = in->p_access;
2106 char *end = strchr( psz, ':' );
2111 in->p_access = access2_FilterNew( in->p_access, psz );
2112 if( in->p_access == NULL )
2114 in->p_access = p_access;
2115 msg_Warn( p_input, "failed to insert access filter %s",
2121 if( psz_tmp ) free( psz_tmp );
2123 /* Get infos from access */
2126 access2_Control( in->p_access,
2127 ACCESS_GET_PTS_DELAY, &i_pts_delay );
2128 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2130 in->b_title_demux = VLC_FALSE;
2131 if( access2_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2132 &in->title, &in->i_title,
2133 &in->i_title_offset, &in->i_seekpoint_offset ) )
2139 access2_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2140 &in->b_can_pace_control );
2141 access2_Control( in->p_access, ACCESS_CAN_PAUSE,
2143 access2_Control( in->p_access, ACCESS_CAN_SEEK,
2145 var_Set( p_input, "seekable", val );
2148 /* Create the stream_t */
2149 in->p_stream = stream_AccessNew( in->p_access, b_quick );
2150 if( in->p_stream == NULL )
2152 msg_Warn( p_input, "cannot create a stream_t from access" );
2156 /* Open a demuxer */
2157 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2159 psz_demux = in->p_access->psz_demux;
2161 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
2162 in->p_stream, p_input->p_es_out, b_quick );
2163 if( in->p_demux == NULL )
2165 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2166 psz_access, psz_demux, psz_path );
2170 /* TODO get title from demux */
2171 if( !b_quick && in->i_title <= 0 )
2173 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2174 &in->title, &in->i_title,
2175 &in->i_title_offset, &in->i_seekpoint_offset ))
2182 in->b_title_demux = VLC_TRUE;
2187 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2188 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2190 if( psz_dup ) free( psz_dup );
2195 demux2_Delete( in->p_demux );
2198 stream_Delete( in->p_stream );
2201 access2_Delete( in->p_access );
2202 if( psz_dup ) free( psz_dup );
2204 return VLC_EGENERIC;
2207 /*****************************************************************************
2209 *****************************************************************************/
2210 static void InputSourceClean( input_thread_t *p_input, input_source_t *in )
2213 demux2_Delete( in->p_demux );
2216 stream_Delete( in->p_stream );
2219 access2_Delete( in->p_access );
2221 if( in->i_title > 0 )
2224 for( i = 0; i < in->i_title; i++ )
2226 vlc_input_title_Delete( in->title[i] );
2232 static void SlaveDemux( input_thread_t *p_input )
2237 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2239 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2243 for( i = 0; i < p_input->i_slave; i++ )
2245 input_source_t *in = p_input->slave[i];
2251 if( demux2_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2256 if( demux2_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2258 msg_Err( p_input, "slave[%d] doesn't like "
2259 "DEMUX_GET_TIME -> EOF", i );
2264 if( i_stime >= i_time )
2267 if( ( i_ret = in->p_demux->pf_demux( in->p_demux ) ) <= 0 )
2273 i_ret = in->p_demux->pf_demux( in->p_demux );
2278 msg_Dbg( p_input, "slave %d EOF", i );
2279 in->b_eof = VLC_TRUE;
2284 static void SlaveSeek( input_thread_t *p_input )
2289 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2291 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2295 for( i = 0; i < p_input->i_slave; i++ )
2297 input_source_t *in = p_input->slave[i];
2299 if( demux2_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
2301 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2302 in->b_eof = VLC_TRUE;
2306 /*****************************************************************************
2308 *****************************************************************************/
2309 static vlc_meta_t *InputMetaUser( input_thread_t *p_input )
2314 if( ( p_meta = vlc_meta_New() ) == NULL )
2317 /* Get meta information from user */
2318 #define GET_META( c, s ) \
2319 var_Get( p_input, (s), &val ); \
2320 if( *val.psz_string ) \
2321 vlc_meta_Add( p_meta, c, val.psz_string ); \
2322 free( val.psz_string )
2324 GET_META( VLC_META_TITLE, "meta-title" );
2325 GET_META( VLC_META_AUTHOR, "meta-author" );
2326 GET_META( VLC_META_ARTIST, "meta-artist" );
2327 GET_META( VLC_META_GENRE, "meta-genre" );
2328 GET_META( VLC_META_COPYRIGHT, "meta-copyright" );
2329 GET_META( VLC_META_DESCRIPTION, "meta-description" );
2330 GET_META( VLC_META_DATE, "meta-date" );
2331 GET_META( VLC_META_URL, "meta-url" );
2337 /*****************************************************************************
2338 * DecodeUrl: decode a given encoded url
2339 *****************************************************************************/
2340 static void DecodeUrl( char *psz )
2342 char *dup = strdup( psz );
2360 *psz++ = strtol( val, NULL, 16 );
2362 else if( *p == '+' )
2372 if( psz ) *psz++ ='\0';
2373 if( dup ) free( dup );
2376 /*****************************************************************************
2377 * ParseOption: parses the options for the input
2378 *****************************************************************************
2379 * This function parses the input (config) options and creates their associated
2381 * Options are of the form "[no[-]]foo[=bar]" where foo is the option name and
2382 * bar is the value of the option.
2383 *****************************************************************************/
2384 static void ParseOption( input_thread_t *p_input, const char *psz_option )
2386 char *psz_name = (char *)psz_option;
2387 char *psz_value = strchr( psz_option, '=' );
2388 int i_name_len, i_type;
2389 vlc_bool_t b_isno = VLC_FALSE;
2392 if( psz_value ) i_name_len = psz_value - psz_option;
2393 else i_name_len = strlen( psz_option );
2395 /* It's too much of an hassle to remove the ':' when we parse
2396 * the cmd line :) */
2397 if( i_name_len && *psz_name == ':' )
2403 if( i_name_len == 0 ) return;
2405 psz_name = strndup( psz_name, i_name_len );
2406 if( psz_value ) psz_value++;
2408 /* FIXME: :programs should be handled generically */
2409 if( !strcmp( psz_name, "programs" ) )
2410 i_type = VLC_VAR_LIST;
2412 i_type = config_GetType( p_input, psz_name );
2414 if( !i_type && !psz_value )
2416 /* check for "no-foo" or "nofoo" */
2417 if( !strncmp( psz_name, "no-", 3 ) )
2419 memmove( psz_name, psz_name + 3, strlen(psz_name) + 1 - 3 );
2421 else if( !strncmp( psz_name, "no", 2 ) )
2423 memmove( psz_name, psz_name + 2, strlen(psz_name) + 1 - 2 );
2425 else goto cleanup; /* Option doesn't exist */
2428 i_type = config_GetType( p_input, psz_name );
2430 if( !i_type ) goto cleanup; /* Option doesn't exist */
2432 else if( !i_type ) goto cleanup; /* Option doesn't exist */
2434 if( ( i_type != VLC_VAR_BOOL ) &&
2435 ( !psz_value || !*psz_value ) ) goto cleanup; /* Invalid value */
2437 /* Create the variable in the input object.
2438 * Children of the input object will be able to retreive this value
2439 * thanks to the inheritance property of the object variables. */
2440 var_Create( p_input, psz_name, i_type );
2445 val.b_bool = !b_isno;
2448 case VLC_VAR_INTEGER:
2449 val.i_int = strtol( psz_value, NULL, 0 );
2453 val.f_float = atof( psz_value );
2456 case VLC_VAR_STRING:
2457 case VLC_VAR_MODULE:
2459 case VLC_VAR_DIRECTORY:
2460 val.psz_string = psz_value;
2465 char *psz_orig, *psz_var;
2466 vlc_list_t *p_list = malloc(sizeof(vlc_list_t));
2467 val.p_list = p_list;
2468 p_list->i_count = 0;
2470 psz_var = psz_orig = strdup(psz_value);
2471 while( psz_var && *psz_var )
2473 char *psz_item = psz_var;
2475 while( *psz_var && *psz_var != ',' ) psz_var++;
2476 if( *psz_var == ',' )
2481 val2.i_int = strtol( psz_item, NULL, 0 );
2482 INSERT_ELEM( p_list->p_values, p_list->i_count,
2483 p_list->i_count, val2 );
2484 /* p_list->i_count is incremented twice by INSERT_ELEM */
2486 INSERT_ELEM( p_list->pi_types, p_list->i_count,
2487 p_list->i_count, VLC_VAR_INTEGER );
2489 if( psz_orig ) free( psz_orig );
2498 var_Set( p_input, psz_name, val );
2500 msg_Dbg( p_input, "set input option: %s to %s", psz_name,
2501 psz_value ? psz_value : ( val.b_bool ? "true" : "false") );
2504 if( psz_name ) free( psz_name );
2508 /*****************************************************************************
2509 * MRLSplit: parse the access, demux and url part of the
2510 * Media Resource Locator.
2511 *****************************************************************************/
2512 void MRLSplit( vlc_object_t *p_input, char *psz_dup,
2513 char **ppsz_access, char **ppsz_demux, char **ppsz_path )
2515 char *psz_access = NULL;
2516 char *psz_demux = NULL;
2517 char *psz_path = NULL;
2518 char *psz, *psz_check;
2520 psz = strchr( psz_dup, ':' );
2522 /* '@' not allowed in access/demux part */
2523 psz_check = strchr( psz_dup, '@' );
2524 if( psz_check && psz_check < psz ) psz = 0;
2526 #if defined( WIN32 ) || defined( UNDER_CE )
2527 if( psz - psz_dup == 1 )
2529 msg_Warn( p_input, "drive letter %c: found in source", *psz_dup );
2538 if( psz[0] == '/' && psz[1] == '/' ) psz += 2;
2542 psz = strchr( psz_dup, '/' );
2549 psz_access = psz_dup;
2556 if( !psz_access ) *ppsz_access = "";
2557 else *ppsz_access = psz_access;
2559 if( !psz_demux ) *ppsz_demux = "";
2560 else *ppsz_demux = psz_demux;
2562 if( !psz_path ) *ppsz_path = "";
2563 else *ppsz_path = psz_path;
2566 /*****************************************************************************
2567 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
2570 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
2571 *****************************************************************************/
2572 static void MRLSections( input_thread_t *p_input, char *psz_source,
2573 int *pi_title_start, int *pi_title_end,
2574 int *pi_chapter_start, int *pi_chapter_end )
2576 char *psz, *psz_end, *psz_next, *psz_check;
2578 *pi_title_start = *pi_title_end = -1;
2579 *pi_chapter_start = *pi_chapter_end = -1;
2581 /* Start by parsing titles and chapters */
2582 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
2584 /* Check we are really dealing with a title/chapter section */
2585 psz_check = psz + 1;
2586 if( !*psz_check ) return;
2587 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2588 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
2589 if( *psz_check == ':' && ++psz_check )
2590 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2591 if( *psz_check != '-' && *psz_check ) return;
2592 if( *psz_check == '-' && ++psz_check )
2593 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2594 if( *psz_check != ':' && *psz_check ) return;
2595 if( *psz_check == ':' && ++psz_check )
2596 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2597 if( *psz_check ) return;
2599 /* Separate start and end */
2601 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
2603 /* Look for the start title */
2604 *pi_title_start = strtol( psz, &psz_next, 0 );
2605 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
2606 *pi_title_end = *pi_title_start;
2609 /* Look for the start chapter */
2611 *pi_chapter_start = strtol( psz, &psz_next, 0 );
2612 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
2613 *pi_chapter_end = *pi_chapter_start;
2617 /* Look for the end title */
2618 *pi_title_end = strtol( psz_end, &psz_next, 0 );
2619 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
2622 /* Look for the end chapter */
2623 if( *psz_end ) psz_end++;
2624 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
2625 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
2628 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
2629 psz_source, *pi_title_start, *pi_chapter_start,
2630 *pi_title_end, *pi_chapter_end );
2634 /***********************************************************************
2635 * Info management functions
2636 ***********************************************************************/
2638 * Get a info item from a given category in a given input item.
2640 * \param p_i The input item to get info from
2641 * \param psz_cat String representing the category for the info
2642 * \param psz_name String representing the name of the desired info
2643 * \return A pointer to the string with the given info if found, or an
2644 * empty string otherwise. The caller should free the returned
2647 char *vlc_input_item_GetInfo( input_item_t *p_i,
2648 const char *psz_cat,
2649 const char *psz_name )
2653 vlc_mutex_lock( &p_i->lock );
2655 for( i = 0 ; i< p_i->i_categories ; i++ )
2657 info_category_t *p_cat = p_i->pp_categories[i];
2659 if( !psz_cat || strcmp( p_cat->psz_name, psz_cat ) )
2662 for( j = 0; j < p_cat->i_infos ; j++ )
2664 if( !strcmp( p_cat->pp_infos[j]->psz_name, psz_name ) )
2666 char *psz_ret = strdup( p_cat->pp_infos[j]->psz_value );
2667 vlc_mutex_unlock( &p_i->lock );
2672 vlc_mutex_unlock( &p_i->lock );
2673 return strdup( "" );
2676 int vlc_input_item_AddInfo( input_item_t *p_i,
2677 const char *psz_cat,
2678 const char *psz_name,
2679 const char *psz_format, ... )
2683 info_t *p_info = NULL;
2684 info_category_t *p_cat = NULL ;
2686 vlc_mutex_lock( &p_i->lock );
2688 for( i = 0 ; i < p_i->i_categories ; i ++ )
2690 if( !strcmp( p_i->pp_categories[i]->psz_name, psz_cat ) )
2692 p_cat = p_i->pp_categories[i];
2698 if( !(p_cat = (info_category_t *)malloc( sizeof(info_category_t) )) )
2700 vlc_mutex_unlock( &p_i->lock );
2701 return VLC_EGENERIC;
2703 p_cat->psz_name = strdup( psz_cat );
2705 p_cat->pp_infos = 0;
2706 INSERT_ELEM( p_i->pp_categories, p_i->i_categories, p_i->i_categories,
2710 for( i = 0; i< p_cat->i_infos; i++ )
2712 if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
2714 p_info = p_cat->pp_infos[i];
2721 if( ( p_info = (info_t *)malloc( sizeof( info_t ) ) ) == NULL )
2723 vlc_mutex_unlock( &p_i->lock );
2724 return VLC_EGENERIC;
2726 INSERT_ELEM( p_cat->pp_infos, p_cat->i_infos, p_cat->i_infos, p_info );
2727 p_info->psz_name = strdup( psz_name );
2731 if( p_info->psz_value ) free( p_info->psz_value );
2734 va_start( args, psz_format );
2735 vasprintf( &p_info->psz_value, psz_format, args);
2738 vlc_mutex_unlock( &p_i->lock );