1 /*****************************************************************************
2 * input.c: input thread
3 *****************************************************************************
4 * Copyright (C) 1998-2004 the VideoLAN team
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Laurent Aimar <fenrir@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
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"
41 #include "vlc_interaction.h"
43 /*****************************************************************************
45 *****************************************************************************/
46 static int Run ( input_thread_t *p_input );
47 static int RunAndClean ( input_thread_t *p_input );
49 static input_thread_t * Create ( vlc_object_t *, input_item_t *, char *,
51 static int Init ( input_thread_t *p_input, vlc_bool_t b_quick );
52 static void Error ( input_thread_t *p_input );
53 static void End ( input_thread_t *p_input );
54 static void MainLoop( input_thread_t *p_input );
56 static inline int ControlPopNoLock( input_thread_t *, int *, vlc_value_t * );
57 static void ControlReduce( input_thread_t * );
58 static vlc_bool_t Control( input_thread_t *, int, vlc_value_t );
61 static int UpdateFromAccess( input_thread_t * );
62 static int UpdateFromDemux( input_thread_t * );
63 static int UpdateMeta( input_thread_t *, vlc_bool_t );
65 static void UpdateItemLength( input_thread_t *, int64_t i_length, vlc_bool_t );
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,
106 char *psz_header, vlc_bool_t b_quick )
108 input_thread_t *p_input = NULL; /* 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" );
119 p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
121 /* Init Common fields */
122 p_input->b_eof = VLC_FALSE;
123 p_input->b_can_pace_control = VLC_TRUE;
124 p_input->i_start = 0;
127 p_input->i_title = 0;
128 p_input->title = NULL;
129 p_input->i_title_offset = p_input->i_seekpoint_offset = 0;
130 p_input->i_state = INIT_S;
131 p_input->i_rate = INPUT_RATE_DEFAULT;
132 p_input->i_bookmark = 0;
133 p_input->bookmark = NULL;
134 p_input->p_meta = NULL;
135 p_input->p_es_out = NULL;
136 p_input->p_sout = NULL;
137 p_input->b_out_pace_control = VLC_FALSE;
138 p_input->i_pts_delay = 0;
140 /* Init Input fields */
141 p_input->input.p_item = p_item;
142 p_input->input.p_access = NULL;
143 p_input->input.p_stream = NULL;
144 p_input->input.p_demux = NULL;
145 p_input->input.b_title_demux = VLC_FALSE;
146 p_input->input.i_title = 0;
147 p_input->input.title = NULL;
148 p_input->input.i_title_offset = p_input->input.i_seekpoint_offset = 0;
149 p_input->input.b_can_pace_control = VLC_TRUE;
150 p_input->input.b_eof = VLC_FALSE;
151 p_input->input.i_cr_average = 0;
153 stats_ReinitInputStats( p_item->p_stats );
156 p_input->i_slave = 0;
157 p_input->slave = NULL;
159 /* Init control buffer */
160 vlc_mutex_init( p_input, &p_input->lock_control );
161 p_input->i_control = 0;
163 /* Parse input options */
164 vlc_mutex_lock( &p_item->lock );
165 for( i = 0; i < p_item->i_options; i++ )
167 var_OptionParse( p_input, p_item->ppsz_options[i] );
169 vlc_mutex_unlock( &p_item->lock );
171 /* Create Object Variables for private use only */
172 input_ConfigVarInit( p_input );
174 /* Create Objects variables for public Get and Set */
175 input_ControlVarInit( p_input );
176 p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
180 var_Get( p_input, "bookmarks", &val );
183 /* FIXME: have a common cfg parsing routine used by sout and others */
184 char *psz_parser, *psz_start, *psz_end;
185 psz_parser = val.psz_string;
186 while( (psz_start = strchr( psz_parser, '{' ) ) )
188 seekpoint_t *p_seekpoint = vlc_seekpoint_New();
191 psz_end = strchr( psz_start, '}' );
192 if( !psz_end ) break;
193 psz_parser = psz_end + 1;
194 backup = *psz_parser;
197 while( (psz_end = strchr( psz_start, ',' ) ) )
200 if( !strncmp( psz_start, "name=", 5 ) )
202 p_seekpoint->psz_name = psz_start + 5;
204 else if( !strncmp( psz_start, "bytes=", 6 ) )
206 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
208 else if( !strncmp( psz_start, "time=", 5 ) )
210 p_seekpoint->i_time_offset = atoll(psz_start + 5) * 1000000;
212 psz_start = psz_end + 1;
214 msg_Dbg( p_input, "adding bookmark: %s, bytes="I64Fd", time="I64Fd,
215 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
216 p_seekpoint->i_time_offset );
217 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
218 vlc_seekpoint_Delete( p_seekpoint );
219 *psz_parser = backup;
221 free( val.psz_string );
225 /* Remove 'Now playing' info as it is probably outdated */
226 input_Control( p_input, INPUT_DEL_INFO, _(VLC_META_INFO_CAT),
227 VLC_META_NOW_PLAYING ); /* ? Don't translate as it might has been copied ? */
233 * Initialize an input thread and run it. You will need to monitor the thread to clean
234 * up after it is done
236 * \param p_parent a vlc_object
237 * \param p_item an input item
238 * \return a pointer to the spawned input thread
240 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
241 input_item_t *p_item )
243 return __input_CreateThread2( p_parent, p_item, NULL );
248 input_thread_t *__input_CreateThread2( vlc_object_t *p_parent,
249 input_item_t *p_item,
252 input_thread_t *p_input = NULL; /* thread descriptor */
254 p_input = Create( p_parent, p_item, psz_header, VLC_FALSE );
255 /* Now we can attach our new input */
256 vlc_object_attach( p_input, p_parent );
258 /* Create thread and wait for its readiness. */
259 if( vlc_thread_create( p_input, "input", Run,
260 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
262 msg_Err( p_input, "cannot create input thread" );
263 vlc_object_detach( p_input );
264 vlc_object_destroy( p_input );
273 * Initialize an input thread and run it. This thread will clean after himself,
274 * you can forget about it. It can work either in blocking or non-blocking mode
276 * \param p_parent a vlc_object
277 * \param p_item an input item
278 * \param b_block should we block until read is finished ?
279 * \return the input object id if non blocking, an error code else
281 int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
284 input_thread_t *p_input = NULL; /* thread descriptor */
286 p_input = Create( p_parent, p_item, NULL, VLC_FALSE );
287 /* Now we can attach our new input */
288 vlc_object_attach( p_input, p_parent );
292 RunAndClean( p_input );
297 if( vlc_thread_create( p_input, "input", RunAndClean,
298 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
300 msg_Err( p_input, "cannot create input thread" );
301 vlc_object_detach( p_input );
302 vlc_object_destroy( p_input );
306 return p_input->i_object_id;
310 * Initialize an input and initialize it to preparse the item
311 * This function is blocking. It will only accept to parse files
313 * \param p_parent a vlc_object_t
314 * \param p_item an input item
315 * \return VLC_SUCCESS or an error
317 int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
319 input_thread_t *p_input = NULL; /* thread descriptor */
321 /* Allocate descriptor */
322 p_input = Create( p_parent, p_item, NULL, VLC_TRUE );
323 p_input->i_flags |= OBJECT_FLAGS_NODBG;
324 p_input->i_flags |= OBJECT_FLAGS_NOINTERACT;
326 /* Now we can attach our new input */
327 vlc_object_attach( p_input, p_parent );
329 Init( p_input, VLC_TRUE );
331 /* Clean up master */
332 InputSourceClean( p_input, &p_input->input );
334 /* Kill access and demux */
335 if( p_input->input.p_access ) p_input->input.p_access->b_die = VLC_TRUE;
336 if( p_input->input.p_demux ) p_input->input.p_access->b_die = VLC_TRUE;
338 /* Unload all modules */
339 if( p_input->p_es_out ) input_EsOutDelete( p_input->p_es_out );
342 if( p_input->p_meta ) vlc_meta_Delete( p_input->p_meta );
344 vlc_object_detach( p_input );
345 vlc_object_destroy( p_input );
351 * Request a running input thread to stop and die
353 * \param the input thread to stop
355 void input_StopThread( input_thread_t *p_input )
360 /* Set die for input */
361 p_input->b_die = VLC_TRUE;
363 /* We cannot touch p_input fields directly (we can from another thread),
364 * so use the vlc_object_find way, it's perfectly safe */
366 /* Set die for all access */
367 p_list = vlc_list_find( p_input, VLC_OBJECT_ACCESS, 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 /* Set die for all stream */
375 p_list = vlc_list_find( p_input, VLC_OBJECT_STREAM, FIND_CHILD );
376 for( i = 0; i < p_list->i_count; i++ )
378 p_list->p_values[i].p_object->b_die = VLC_TRUE;
380 vlc_list_release( p_list );
382 /* Set die for all demux */
383 p_list = vlc_list_find( p_input, VLC_OBJECT_DEMUX, FIND_CHILD );
384 for( i = 0; i < p_list->i_count; i++ )
386 p_list->p_values[i].p_object->b_die = VLC_TRUE;
388 vlc_list_release( p_list );
390 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
394 * Clean up a dead input thread
395 * This function does not return until the thread is effectively cancelled.
397 * \param the input thread to kill
399 void input_DestroyThread( input_thread_t *p_input )
401 /* Join the thread */
402 vlc_thread_join( p_input );
404 /* Delete input lock (only after thread joined) */
405 vlc_mutex_destroy( &p_input->lock_control );
407 /* TODO: maybe input_DestroyThread should also delete p_input instead
408 * of the playlist but I'm not sure if it's possible */
411 /*****************************************************************************
412 * Run: main thread loop
413 * This is the "normal" thread that spawns the input processing chain,
414 * reads the stream, cleans up and waits
415 *****************************************************************************/
416 static int Run( input_thread_t *p_input )
418 /* Signal that the thread is launched */
419 vlc_thread_ready( p_input );
421 if( Init( p_input, VLC_FALSE ) )
423 /* If we failed, wait before we are killed, and exit */
424 p_input->b_error = VLC_TRUE;
428 /* Tell we're dead */
429 p_input->b_dead = VLC_TRUE;
436 if( !p_input->b_eof && !p_input->b_error && p_input->input.b_eof )
438 /* We have finish to demux data but not to play them */
439 while( !p_input->b_die )
441 if( input_EsOutDecodersEmpty( p_input->p_es_out ) )
444 msg_Dbg( p_input, "waiting decoder fifos to empty" );
446 msleep( INPUT_IDLE_SLEEP );
449 /* We have finished */
450 p_input->b_eof = VLC_TRUE;
453 /* Wait we are asked to die */
454 if( !p_input->b_die )
465 /*****************************************************************************
466 * RunAndClean: main thread loop
467 * This is the "just forget me" thread that spawns the input processing chain,
468 * reads the stream, cleans up and releases memory
469 *****************************************************************************/
470 static int RunAndClean( input_thread_t *p_input )
472 /* Signal that the thread is launched */
473 vlc_thread_ready( p_input );
475 if( Init( p_input, VLC_FALSE ) )
477 /* If we failed, just exit */
483 if( !p_input->b_eof && !p_input->b_error && p_input->input.b_eof )
485 /* We have finish to demux data but not to play them */
486 while( !p_input->b_die )
488 if( input_EsOutDecodersEmpty( p_input->p_es_out ) )
491 msg_Dbg( p_input, "waiting decoder fifos to empty" );
493 msleep( INPUT_IDLE_SLEEP );
495 /* We have finished */
496 p_input->b_eof = VLC_TRUE;
503 vlc_object_detach( p_input );
504 vlc_object_destroy( p_input );
510 /*****************************************************************************
511 * Main loop: Fill buffers from access, and demux
512 *****************************************************************************/
513 static void MainLoop( input_thread_t *p_input )
515 int64_t i_intf_update = 0;
516 while( !p_input->b_die && !p_input->b_error && !p_input->input.b_eof )
518 vlc_bool_t b_force_update = VLC_FALSE;
524 if( p_input->i_state != PAUSE_S )
526 if( p_input->i_stop <= 0 || p_input->i_time < p_input->i_stop )
527 i_ret=p_input->input.p_demux->pf_demux(p_input->input.p_demux);
534 if( p_input->input.b_title_demux &&
535 p_input->input.p_demux->info.i_update )
537 i_ret = UpdateFromDemux( p_input );
538 b_force_update = VLC_TRUE;
540 else if( !p_input->input.b_title_demux &&
541 p_input->input.p_access &&
542 p_input->input.p_access->info.i_update )
544 i_ret = UpdateFromAccess( p_input );
545 b_force_update = VLC_TRUE;
549 if( i_ret == 0 ) /* EOF */
553 var_Get( p_input, "input-repeat", &repeat );
554 if( repeat.i_int == 0 )
556 /* End of file - we do not set b_die because only the
557 * playlist is allowed to do so. */
558 msg_Dbg( p_input, "EOF reached" );
559 p_input->input.b_eof = VLC_TRUE;
563 msg_Dbg( p_input, "repeating the same input (%d)",
565 if( repeat.i_int > 0 )
568 var_Set( p_input, "input-repeat", repeat );
571 /* Seek to start title/seekpoint */
572 val.i_int = p_input->input.i_title_start -
573 p_input->input.i_title_offset;
574 if( val.i_int < 0 || val.i_int >= p_input->input.i_title )
576 input_ControlPush( p_input,
577 INPUT_CONTROL_SET_TITLE, &val );
579 val.i_int = p_input->input.i_seekpoint_start -
580 p_input->input.i_seekpoint_offset;
581 if( val.i_int > 0 /* TODO: check upper boundary */ )
582 input_ControlPush( p_input,
583 INPUT_CONTROL_SET_SEEKPOINT, &val );
585 /* Seek to start position */
586 if( p_input->i_start > 0 )
588 val.i_time = p_input->i_start;
589 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
595 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
602 p_input->b_error = VLC_TRUE;
605 if( i_ret > 0 && p_input->i_slave > 0 )
607 SlaveDemux( p_input );
617 vlc_mutex_lock( &p_input->lock_control );
618 ControlReduce( p_input );
619 while( !ControlPopNoLock( p_input, &i_type, &val ) )
621 msg_Dbg( p_input, "control type=%d", i_type );
622 if( Control( p_input, i_type, val ) )
623 b_force_update = VLC_TRUE;
625 vlc_mutex_unlock( &p_input->lock_control );
627 if( b_force_update || i_intf_update < mdate() )
631 int64_t i_time, i_length;
632 /* update input status variables */
633 if( !demux2_Control( p_input->input.p_demux,
634 DEMUX_GET_POSITION, &f_pos ) )
636 val.f_float = (float)f_pos;
637 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
639 if( !demux2_Control( p_input->input.p_demux,
640 DEMUX_GET_TIME, &i_time ) )
642 p_input->i_time = i_time;
644 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
646 if( !demux2_Control( p_input->input.p_demux,
647 DEMUX_GET_LENGTH, &i_length ) )
650 var_Get( p_input, "length", &old_val );
651 val.i_time = i_length;
652 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
654 if( old_val.i_time != val.i_time )
656 UpdateItemLength( p_input, i_length, VLC_TRUE );
660 var_SetBool( p_input, "intf-change", VLC_TRUE );
661 i_intf_update = mdate() + I64C(150000);
667 static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
673 vlc_meta_t *p_meta, *p_meta_tmp;
677 /* Initialize optional stream output. (before access/demuxer)
678 * XXX: we add a special case if the uri starts by vlc.
679 * else 'vlc in.file --sout "" vlc:quit' cannot work (the output will
680 * be destroyed in case of a file).
681 * (this will break playing of file starting by 'vlc:' but I don't
682 * want to add more logic, just force file by file:// or code it ;)
686 /* Prepare statistics */
687 counter_t *p_counter;
688 stats_Create( p_input, "read_bytes", STATS_READ_BYTES,
689 VLC_VAR_INTEGER, STATS_COUNTER );
690 stats_Create( p_input, "read_packets", STATS_READ_PACKETS,
691 VLC_VAR_INTEGER, STATS_COUNTER );
692 stats_Create( p_input, "demux_read", STATS_DEMUX_READ,
693 VLC_VAR_INTEGER, STATS_COUNTER );
694 stats_Create( p_input, "input_bitrate", STATS_INPUT_BITRATE,
695 VLC_VAR_FLOAT, STATS_DERIVATIVE );
696 stats_Create( p_input, "demux_bitrate", STATS_DEMUX_BITRATE,
697 VLC_VAR_FLOAT, STATS_DERIVATIVE );
699 p_counter = stats_CounterGet( p_input, p_input->i_object_id,
700 STATS_INPUT_BITRATE );
701 if( p_counter ) p_counter->update_interval = 1000000;
702 p_counter = stats_CounterGet( p_input, p_input->i_object_id,
703 STATS_DEMUX_BITRATE );
704 if( p_counter ) p_counter->update_interval = 1000000;
706 stats_Create( p_input, "played_abuffers", STATS_PLAYED_ABUFFERS,
707 VLC_VAR_INTEGER, STATS_COUNTER );
708 stats_Create( p_input, "lost_abuffers", STATS_LOST_ABUFFERS,
709 VLC_VAR_INTEGER, STATS_COUNTER );
712 psz = var_GetString( p_input, "sout" );
713 if( *psz && strncasecmp( p_input->input.p_item->psz_uri, "vlc:", 4 ) )
715 p_input->p_sout = sout_NewInstance( p_input, psz );
716 if( p_input->p_sout == NULL )
718 msg_Err( p_input, "cannot start stream output instance, " \
728 p_input->p_es_out = input_EsOutNew( p_input );
729 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
730 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
732 if( InputSourceInit( p_input, &p_input->input,
733 p_input->input.p_item->psz_uri, NULL, b_quick ) )
738 /* Create global title (from master) */
741 p_input->i_title = p_input->input.i_title;
742 p_input->title = p_input->input.title;
743 p_input->i_title_offset = p_input->input.i_title_offset;
744 p_input->i_seekpoint_offset = p_input->input.i_seekpoint_offset;
745 if( p_input->i_title > 0 )
747 /* Setup variables */
748 input_ControlVarNavigation( p_input );
749 input_ControlVarTitle( p_input, 0 );
753 p_input->b_can_pace_control = p_input->input.b_can_pace_control;
754 p_input->b_can_pause = p_input->input.b_can_pause;
757 if( p_input->i_pts_delay < 0 )
758 p_input->i_pts_delay = 0;
760 /* If the desynchronisation requested by the user is < 0, we need to
761 * cache more data. */
762 var_Get( p_input, "audio-desync", &val );
763 if( val.i_int < 0 ) p_input->i_pts_delay -= (val.i_int * 1000);
765 /* Update cr_average depending on the caching */
766 p_input->input.i_cr_average *= (10 * p_input->i_pts_delay / 200000);
767 p_input->input.i_cr_average /= 10;
768 if( p_input->input.i_cr_average < 10 ) p_input->input.i_cr_average = 10;
771 /* Load master infos */
773 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_LENGTH,
774 &val.i_time ) && val.i_time > 0 )
776 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
777 UpdateItemLength( p_input, val.i_time, b_quick );
778 p_input->input.p_item->i_duration = val.i_time;
781 /* Start title/chapter */
784 val.i_int = p_input->input.i_title_start -
785 p_input->input.i_title_offset;
786 if( val.i_int > 0 && val.i_int < p_input->input.i_title )
787 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
788 val.i_int = p_input->input.i_seekpoint_start -
789 p_input->input.i_seekpoint_offset;
790 if( val.i_int > 0 /* TODO: check upper boundary */ )
791 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
795 p_input->i_start = (int64_t)var_GetInteger( p_input, "start-time" ) *
797 p_input->i_stop = (int64_t)var_GetInteger( p_input, "stop-time" ) *
800 if( p_input->i_start > 0 )
802 if( p_input->i_start >= val.i_time )
804 msg_Warn( p_input, "invalid start-time ignored" );
810 msg_Dbg( p_input, "starting at time: %ds",
811 (int)( p_input->i_start / I64C(1000000) ) );
813 s.i_time = p_input->i_start;
814 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
817 if( p_input->i_stop > 0 && p_input->i_stop <= p_input->i_start )
819 msg_Warn( p_input, "invalid stop-time ignored" );
825 /* Get fps and set it if not already set */
826 if( !demux2_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) &&
829 float f_requested_fps;
831 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
832 var_SetFloat( p_input, "sub-original-fps", f_fps );
834 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
835 if( f_requested_fps != f_fps )
837 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
839 var_SetFloat( p_input, "sub-fps", f_requested_fps );
843 i_delay = var_CreateGetInteger( p_input, "sub-delay" );
846 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
850 /* Look for and add subtitle files */
851 psz_subtitle = var_GetString( p_input, "sub-file" );
858 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
860 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
863 sub = InputSourceNew( p_input );
864 if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle",
867 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
870 if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list,
873 if( count.i_int == 0 )
875 /* if it was first one, there is disable too */
877 if( count.i_int < list.p_list->i_count )
879 input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
880 &list.p_list->p_values[count.i_int] );
882 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list,
888 var_Get( p_input, "sub-autodetect-file", &val );
891 char *psz_autopath = var_GetString( p_input, "sub-autodetect-path" );
892 char **subs = subtitles_Detect( p_input, psz_autopath,
893 p_input->input.p_item->psz_uri );
896 for( i = 0; subs && subs[i]; i++ )
898 if( strcmp( psz_subtitle, subs[i] ) )
900 sub = InputSourceNew( p_input );
901 if( !InputSourceInit( p_input, sub, subs[i], "subtitle",
904 TAB_APPEND( p_input->i_slave, p_input->slave, sub );
909 if( subs ) free( subs );
910 if( psz_autopath ) free( psz_autopath );
912 free( psz_subtitle );
915 psz = var_GetString( p_input, "input-slave" );
919 input_source_t *slave;
922 while( *psz == ' ' || *psz == '#' )
926 if( ( psz_delim = strchr( psz, '#' ) ) )
935 msg_Dbg( p_input, "adding slave input '%s'", psz );
936 slave = InputSourceNew( p_input );
937 if( !InputSourceInit( p_input, slave, psz, NULL, VLC_FALSE ) )
939 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
944 if( psz ) free( psz );
948 p_input->i_start = 0;
949 p_input->i_start = 0;
955 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
956 i_es_out_mode = ES_OUT_MODE_AUTO;
958 if( p_input->p_sout )
960 var_Get( p_input, "sout-all", &val );
963 i_es_out_mode = ES_OUT_MODE_ALL;
968 var_Get( p_input, "programs", &val );
969 if ( val.p_list && val.p_list->i_count )
971 i_es_out_mode = ES_OUT_MODE_PARTIAL;
972 /* Note : we should remove the "program" callback. */
975 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
979 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
981 /* Inform the demuxer about waited group (needed only for DVB) */
982 if( i_es_out_mode == ES_OUT_MODE_ALL )
984 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
986 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
988 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, -1,
993 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP,
994 (int) var_GetInteger( p_input, "program" ), NULL );
997 if( p_input->p_sout )
999 if( p_input->p_sout->i_out_pace_nocontrol > 0 )
1001 p_input->b_out_pace_control = VLC_FALSE;
1005 p_input->b_out_pace_control = VLC_TRUE;
1008 if( p_input->b_can_pace_control && p_input->b_out_pace_control )
1010 /* We don't want a high input priority here or we'll
1011 * end-up sucking up all the CPU time */
1012 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
1015 msg_Dbg( p_input, "starting in %s mode",
1016 p_input->b_out_pace_control ? "asynch" : "synch" );
1020 /* Get meta data from users */
1021 p_meta_tmp = InputMetaUser( p_input );
1023 /* Get meta data from master input */
1024 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_META, &p_meta ) )
1028 if( p_meta == NULL )
1030 p_meta = p_meta_tmp;
1032 else if( p_meta_tmp )
1034 vlc_meta_Merge( p_meta, p_meta_tmp );
1035 vlc_meta_Delete( p_meta_tmp );
1038 /* Access_file does not give any meta, and there are no slave */
1041 if( !p_input->input.p_access ||
1042 access2_Control( p_input->input.p_access, ACCESS_GET_META,
1046 if( p_meta == NULL )
1048 p_meta = p_meta_tmp;
1050 else if( p_meta_tmp )
1052 vlc_meta_Merge( p_meta, p_meta_tmp );
1053 vlc_meta_Delete( p_meta_tmp );
1056 /* Get meta data from slave input */
1057 for( i = 0; i < p_input->i_slave; i++ )
1059 vlc_meta_t *p_meta_slave;
1061 if( !demux2_Control( p_input->slave[i]->p_demux,
1062 DEMUX_GET_META, &p_meta_slave ) )
1064 if( p_meta == NULL )
1066 p_meta = p_meta_slave;
1068 else if( p_meta_slave )
1070 vlc_meta_Merge( p_meta, p_meta_slave );
1071 vlc_meta_Delete( p_meta_slave );
1075 if( p_input->slave[i]->p_access &&
1076 !access2_Control( p_input->slave[i]->p_access,
1077 ACCESS_GET_META, &p_meta_slave ) )
1079 if( p_meta == NULL )
1081 p_meta = p_meta_slave;
1083 else if( p_meta_slave )
1085 vlc_meta_Merge( p_meta, p_meta_slave );
1086 vlc_meta_Delete( p_meta_slave );
1092 p_input->p_meta = p_meta;
1093 UpdateMeta( p_input, b_quick );
1097 msg_Dbg( p_input, "`%s' successfully opened",
1098 p_input->input.p_item->psz_uri );
1102 /* initialization is complete */
1103 p_input->i_state = PLAYING_S;
1105 val.i_int = PLAYING_S;
1106 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1111 if( p_input->p_es_out )
1112 input_EsOutDelete( p_input->p_es_out );
1114 if( p_input->p_sout )
1115 sout_DeleteInstance( p_input->p_sout );
1117 /* Mark them deleted */
1118 p_input->input.p_demux = NULL;
1119 p_input->input.p_stream = NULL;
1120 p_input->input.p_access = NULL;
1121 p_input->p_es_out = NULL;
1122 p_input->p_sout = NULL;
1124 return VLC_EGENERIC;
1127 /*****************************************************************************
1128 * Error: RunThread() error loop
1129 *****************************************************************************
1130 * This function is called when an error occurred during thread main's loop.
1131 *****************************************************************************/
1132 static void Error( input_thread_t *p_input )
1134 while( !p_input->b_die )
1137 msleep( INPUT_IDLE_SLEEP );
1141 /*****************************************************************************
1142 * End: end the input thread
1143 *****************************************************************************/
1144 static void End( input_thread_t * p_input )
1149 msg_Dbg( p_input, "closing input" );
1151 /* We are at the end */
1152 p_input->i_state = END_S;
1155 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1157 /* Clean control variables */
1158 input_ControlVarClean( p_input );
1160 /* Clean up master */
1161 InputSourceClean( p_input, &p_input->input );
1164 for( i = 0; i < p_input->i_slave; i++ )
1166 InputSourceClean( p_input, p_input->slave[i] );
1167 free( p_input->slave[i] );
1169 if( p_input->slave ) free( p_input->slave );
1171 /* Unload all modules */
1172 if( p_input->p_es_out )
1173 input_EsOutDelete( p_input->p_es_out );
1175 /* Close optional stream output instance */
1176 if( p_input->p_sout )
1178 vlc_object_t *p_pl =
1179 vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1182 if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
1184 /* attach sout to the playlist */
1185 msg_Dbg( p_input, "keeping sout" );
1186 vlc_object_detach( p_input->p_sout );
1187 vlc_object_attach( p_input->p_sout, p_pl );
1191 msg_Dbg( p_input, "destroying sout" );
1192 sout_DeleteInstance( p_input->p_sout );
1195 vlc_object_release( p_pl );
1199 if( p_input->p_meta )
1200 vlc_meta_Delete( p_input->p_meta );
1202 /* Tell we're dead */
1203 p_input->b_dead = VLC_TRUE;
1206 /*****************************************************************************
1208 *****************************************************************************/
1209 static inline int ControlPopNoLock( input_thread_t *p_input,
1210 int *pi_type, vlc_value_t *p_val )
1212 if( p_input->i_control <= 0 )
1214 return VLC_EGENERIC;
1217 *pi_type = p_input->control[0].i_type;
1218 *p_val = p_input->control[0].val;
1220 p_input->i_control--;
1221 if( p_input->i_control > 0 )
1225 for( i = 0; i < p_input->i_control; i++ )
1227 p_input->control[i].i_type = p_input->control[i+1].i_type;
1228 p_input->control[i].val = p_input->control[i+1].val;
1235 static void ControlReduce( input_thread_t *p_input )
1238 for( i = 1; i < p_input->i_control; i++ )
1240 const int i_lt = p_input->control[i-1].i_type;
1241 const int i_ct = p_input->control[i].i_type;
1243 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1244 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->i_control,
1248 ( i_ct == INPUT_CONTROL_SET_STATE ||
1249 i_ct == INPUT_CONTROL_SET_RATE ||
1250 i_ct == INPUT_CONTROL_SET_POSITION ||
1251 i_ct == INPUT_CONTROL_SET_TIME ||
1252 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1253 i_ct == INPUT_CONTROL_SET_TITLE ||
1254 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1255 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1258 // msg_Dbg( p_input, "merged at %d", i );
1259 /* Remove the i-1 */
1260 for( j = i; j < p_input->i_control; j++ )
1261 p_input->control[j-1] = p_input->control[j];
1262 p_input->i_control--;
1266 /* TODO but that's not that important
1267 - merge SET_X with SET_X_CMD
1268 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1269 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1276 static vlc_bool_t Control( input_thread_t *p_input, int i_type,
1279 vlc_bool_t b_force_update = VLC_FALSE;
1281 if( !p_input ) return b_force_update;
1285 case INPUT_CONTROL_SET_DIE:
1286 msg_Dbg( p_input, "control: stopping input" );
1287 /* Mark all submodules to die */
1288 if( p_input->input.p_access )
1289 p_input->input.p_access->b_die = VLC_TRUE;
1290 if( p_input->input.p_stream )
1291 p_input->input.p_stream->b_die = VLC_TRUE;
1292 p_input->input.p_demux->b_die = VLC_TRUE;
1294 p_input->b_die = VLC_TRUE;
1297 case INPUT_CONTROL_SET_POSITION:
1298 case INPUT_CONTROL_SET_POSITION_OFFSET:
1301 if( i_type == INPUT_CONTROL_SET_POSITION )
1303 f_pos = val.f_float;
1307 /* Should not fail */
1308 demux2_Control( p_input->input.p_demux,
1309 DEMUX_GET_POSITION, &f_pos );
1310 f_pos += val.f_float;
1312 if( f_pos < 0.0 ) f_pos = 0.0;
1313 if( f_pos > 1.0 ) f_pos = 1.0;
1314 /* Reset the decoders states and clock synch (before calling the demuxer */
1315 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1316 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1317 if( demux2_Control( p_input->input.p_demux, DEMUX_SET_POSITION,
1320 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1321 "%2.1f%% failed", f_pos * 100 );
1325 if( p_input->i_slave > 0 )
1326 SlaveSeek( p_input );
1328 b_force_update = VLC_TRUE;
1333 case INPUT_CONTROL_SET_TIME:
1334 case INPUT_CONTROL_SET_TIME_OFFSET:
1339 if( i_type == INPUT_CONTROL_SET_TIME )
1341 i_time = val.i_time;
1345 /* Should not fail */
1346 demux2_Control( p_input->input.p_demux,
1347 DEMUX_GET_TIME, &i_time );
1348 i_time += val.i_time;
1350 if( i_time < 0 ) i_time = 0;
1352 /* Reset the decoders states and clock synch (before calling the demuxer */
1353 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1354 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1356 i_ret = demux2_Control( p_input->input.p_demux,
1357 DEMUX_SET_TIME, i_time );
1362 /* Emulate it with a SET_POS */
1363 demux2_Control( p_input->input.p_demux,
1364 DEMUX_GET_LENGTH, &i_length );
1367 double f_pos = (double)i_time / (double)i_length;
1368 i_ret = demux2_Control( p_input->input.p_demux,
1369 DEMUX_SET_POSITION, f_pos );
1374 msg_Warn( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) "I64Fd
1375 " failed or not possible", i_time );
1379 if( p_input->i_slave > 0 )
1380 SlaveSeek( p_input );
1382 b_force_update = VLC_TRUE;
1387 case INPUT_CONTROL_SET_STATE:
1388 if( ( val.i_int == PLAYING_S && p_input->i_state == PAUSE_S ) ||
1389 ( val.i_int == PAUSE_S && p_input->i_state == PAUSE_S ) )
1392 if( p_input->input.p_access )
1393 i_ret = access2_Control( p_input->input.p_access,
1394 ACCESS_SET_PAUSE_STATE, VLC_FALSE );
1396 i_ret = demux2_Control( p_input->input.p_demux,
1397 DEMUX_SET_PAUSE_STATE, VLC_FALSE );
1401 /* FIXME What to do ? */
1402 msg_Warn( p_input, "cannot unset pause -> EOF" );
1403 vlc_mutex_unlock( &p_input->lock_control );
1404 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1405 vlc_mutex_lock( &p_input->lock_control );
1408 b_force_update = VLC_TRUE;
1410 /* Switch to play */
1411 p_input->i_state = PLAYING_S;
1412 val.i_int = PLAYING_S;
1413 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1416 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1417 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1419 else if( val.i_int == PAUSE_S && p_input->i_state == PLAYING_S &&
1420 p_input->b_can_pause )
1423 if( p_input->input.p_access )
1424 i_ret = access2_Control( p_input->input.p_access,
1425 ACCESS_SET_PAUSE_STATE, VLC_TRUE );
1427 i_ret = demux2_Control( p_input->input.p_demux,
1428 DEMUX_SET_PAUSE_STATE, VLC_TRUE );
1430 b_force_update = VLC_TRUE;
1434 msg_Warn( p_input, "cannot set pause state" );
1435 val.i_int = p_input->i_state;
1439 val.i_int = PAUSE_S;
1442 /* Switch to new state */
1443 p_input->i_state = val.i_int;
1444 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1446 else if( val.i_int == PAUSE_S && !p_input->b_can_pause )
1448 b_force_update = VLC_TRUE;
1450 /* Correct "state" value */
1451 val.i_int = p_input->i_state;
1452 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
1454 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1456 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1460 case INPUT_CONTROL_SET_RATE:
1461 case INPUT_CONTROL_SET_RATE_SLOWER:
1462 case INPUT_CONTROL_SET_RATE_FASTER:
1466 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1467 i_rate = p_input->i_rate * 2;
1468 else if( i_type == INPUT_CONTROL_SET_RATE_FASTER )
1469 i_rate = p_input->i_rate / 2;
1473 if( i_rate < INPUT_RATE_MIN )
1475 msg_Dbg( p_input, "cannot set rate faster" );
1476 i_rate = INPUT_RATE_MIN;
1478 else if( i_rate > INPUT_RATE_MAX )
1480 msg_Dbg( p_input, "cannot set rate slower" );
1481 i_rate = INPUT_RATE_MAX;
1483 if( i_rate != INPUT_RATE_DEFAULT &&
1484 ( !p_input->b_can_pace_control ||
1485 ( p_input->p_sout && !p_input->b_out_pace_control ) ) )
1487 msg_Dbg( p_input, "cannot change rate" );
1488 i_rate = INPUT_RATE_DEFAULT;
1490 if( i_rate != p_input->i_rate )
1492 p_input->i_rate = i_rate;
1494 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
1496 /* We haven't send data to decoder when rate != default */
1497 if( i_rate == INPUT_RATE_DEFAULT )
1498 input_EsOutDiscontinuity( p_input->p_es_out, VLC_TRUE );
1501 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1503 b_force_update = VLC_TRUE;
1508 case INPUT_CONTROL_SET_PROGRAM:
1509 /* No need to force update, es_out does it if needed */
1510 es_out_Control( p_input->p_es_out,
1511 ES_OUT_SET_GROUP, val.i_int );
1513 demux2_Control( p_input->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1517 case INPUT_CONTROL_SET_ES:
1518 /* No need to force update, es_out does it if needed */
1519 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
1520 input_EsOutGetFromID( p_input->p_es_out,
1524 case INPUT_CONTROL_SET_AUDIO_DELAY:
1525 input_EsOutSetDelay( p_input->p_es_out,
1526 AUDIO_ES, val.i_time );
1527 var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
1530 case INPUT_CONTROL_SET_SPU_DELAY:
1531 input_EsOutSetDelay( p_input->p_es_out,
1532 SPU_ES, val.i_time );
1533 var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
1536 case INPUT_CONTROL_SET_TITLE:
1537 case INPUT_CONTROL_SET_TITLE_NEXT:
1538 case INPUT_CONTROL_SET_TITLE_PREV:
1539 if( p_input->input.b_title_demux &&
1540 p_input->input.i_title > 0 )
1543 /* FIXME handle demux title */
1544 demux_t *p_demux = p_input->input.p_demux;
1547 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1548 i_title = p_demux->info.i_title - 1;
1549 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1550 i_title = p_demux->info.i_title + 1;
1552 i_title = val.i_int;
1554 if( i_title >= 0 && i_title < p_input->input.i_title )
1556 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1557 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1559 demux2_Control( p_demux, DEMUX_SET_TITLE, i_title );
1560 input_ControlVarTitle( p_input, i_title );
1563 else if( p_input->input.i_title > 0 )
1565 access_t *p_access = p_input->input.p_access;
1568 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1569 i_title = p_access->info.i_title - 1;
1570 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1571 i_title = p_access->info.i_title + 1;
1573 i_title = val.i_int;
1575 if( i_title >= 0 && i_title < p_input->input.i_title )
1577 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1578 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1580 access2_Control( p_access, ACCESS_SET_TITLE, i_title );
1581 stream_AccessReset( p_input->input.p_stream );
1585 case INPUT_CONTROL_SET_SEEKPOINT:
1586 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1587 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1588 if( p_input->input.b_title_demux &&
1589 p_input->input.i_title > 0 )
1591 demux_t *p_demux = p_input->input.p_demux;
1593 int64_t i_input_time;
1594 int64_t i_seekpoint_time;
1596 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1598 i_seekpoint = p_demux->info.i_seekpoint;
1599 i_seekpoint_time = p_input->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1600 if( i_seekpoint_time >= 0 &&
1601 !demux2_Control( p_demux,
1602 DEMUX_GET_TIME, &i_input_time ) )
1604 if ( i_input_time < i_seekpoint_time + 3000000 )
1610 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1611 i_seekpoint = p_demux->info.i_seekpoint + 1;
1613 i_seekpoint = val.i_int;
1615 if( i_seekpoint >= 0 && i_seekpoint <
1616 p_input->input.title[p_demux->info.i_title]->i_seekpoint )
1618 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1619 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1621 demux2_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1624 else if( p_input->input.i_title > 0 )
1626 demux_t *p_demux = p_input->input.p_demux;
1627 access_t *p_access = p_input->input.p_access;
1629 int64_t i_input_time;
1630 int64_t i_seekpoint_time;
1632 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1634 i_seekpoint = p_access->info.i_seekpoint;
1635 i_seekpoint_time = p_input->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1636 if( i_seekpoint_time >= 0 &&
1637 demux2_Control( p_demux,
1638 DEMUX_GET_TIME, &i_input_time ) )
1640 if ( i_input_time < i_seekpoint_time + 3000000 )
1646 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1647 i_seekpoint = p_access->info.i_seekpoint + 1;
1649 i_seekpoint = val.i_int;
1651 if( i_seekpoint >= 0 && i_seekpoint <
1652 p_input->input.title[p_access->info.i_title]->i_seekpoint )
1654 input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
1655 es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
1657 access2_Control( p_access, ACCESS_SET_SEEKPOINT, i_seekpoint );
1658 stream_AccessReset( p_input->input.p_stream );
1663 case INPUT_CONTROL_ADD_SLAVE:
1664 if( val.psz_string )
1666 input_source_t *slave = InputSourceNew( p_input );
1668 if( !InputSourceInit( p_input, slave, val.psz_string, NULL,
1671 vlc_meta_t *p_meta_new = NULL;
1676 msg_Dbg( p_input, "adding %s as slave on the fly",
1680 if( demux2_Control( p_input->input.p_demux,
1681 DEMUX_GET_TIME, &i_time ) )
1683 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
1684 InputSourceClean( p_input, slave );
1688 if( demux2_Control( slave->p_demux,
1689 DEMUX_SET_TIME, i_time ) )
1691 msg_Err( p_input, "seek failed for new slave" );
1692 InputSourceClean( p_input, slave );
1698 /* Get meta (access and demux) */
1699 if( access2_Control( slave->p_access,
1700 ACCESS_GET_META, &p_meta_new ) )
1702 if( !demux2_Control( slave->p_demux,
1703 DEMUX_GET_META, &p_meta ) )
1707 vlc_meta_Merge( p_meta_new, p_meta );
1708 vlc_meta_Delete( p_meta );
1712 p_meta_new = p_meta;
1718 if( p_input->p_meta )
1720 vlc_meta_Merge( p_input->p_meta, p_meta_new );
1721 vlc_meta_Delete( p_meta_new );
1725 p_input->p_meta = p_meta_new;
1727 UpdateMeta( p_input, VLC_FALSE );
1730 TAB_APPEND( p_input->i_slave, p_input->slave, slave );
1734 msg_Warn( p_input, "failed to add %s as slave",
1738 free( val.psz_string );
1742 case INPUT_CONTROL_SET_BOOKMARK:
1744 msg_Err( p_input, "not yet implemented" );
1748 return b_force_update;
1751 /*****************************************************************************
1753 *****************************************************************************/
1754 static int UpdateFromDemux( input_thread_t *p_input )
1756 demux_t *p_demux = p_input->input.p_demux;
1759 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
1761 v.i_int = p_demux->info.i_title;
1762 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1764 input_ControlVarTitle( p_input, p_demux->info.i_title );
1766 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
1768 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
1770 v.i_int = p_demux->info.i_seekpoint;
1771 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1773 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1775 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
1777 /* Hmmm only works with master input */
1778 if( p_input->input.p_demux == p_demux )
1780 int i_title_end = p_input->input.i_title_end -
1781 p_input->input.i_title_offset;
1782 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1783 p_input->input.i_seekpoint_offset;
1785 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
1787 if( p_demux->info.i_title > i_title_end ||
1788 ( p_demux->info.i_title == i_title_end &&
1789 p_demux->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1791 else if( i_seekpoint_end >=0 )
1793 if( p_demux->info.i_seekpoint > i_seekpoint_end ) return 0;
1795 else if( i_title_end >= 0 )
1797 if( p_demux->info.i_title > i_title_end ) return 0;
1804 /*****************************************************************************
1806 *****************************************************************************/
1807 static int UpdateFromAccess( input_thread_t *p_input )
1809 access_t *p_access = p_input->input.p_access;
1812 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
1814 v.i_int = p_access->info.i_title;
1815 var_Change( p_input, "title", VLC_VAR_SETVALUE, &v, NULL );
1817 input_ControlVarTitle( p_input, p_access->info.i_title );
1819 stream_AccessUpdate( p_input->input.p_stream );
1821 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
1823 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
1825 v.i_int = p_access->info.i_seekpoint;
1826 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &v, NULL);
1828 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
1830 if( p_access->info.i_update & INPUT_UPDATE_META )
1832 /* TODO maybe multi - access ? */
1834 if( !access2_Control( p_input->input.p_access,ACCESS_GET_META,&p_meta))
1836 if( p_input->p_meta )
1838 vlc_meta_Merge( p_input->p_meta, p_meta );
1839 vlc_meta_Delete( p_meta );
1843 p_input->p_meta = p_meta;
1846 UpdateMeta( p_input, VLC_FALSE );
1847 var_SetBool( p_input, "item-change", p_input->input.p_item->i_id );
1849 p_access->info.i_update &= ~INPUT_UPDATE_META;
1852 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
1854 /* Hmmm only works with master input */
1855 if( p_input->input.p_access == p_access )
1857 int i_title_end = p_input->input.i_title_end -
1858 p_input->input.i_title_offset;
1859 int i_seekpoint_end = p_input->input.i_seekpoint_end -
1860 p_input->input.i_seekpoint_offset;
1862 if( i_title_end >= 0 && i_seekpoint_end >=0 )
1864 if( p_access->info.i_title > i_title_end ||
1865 ( p_access->info.i_title == i_title_end &&
1866 p_access->info.i_seekpoint > i_seekpoint_end ) ) return 0;
1868 else if( i_seekpoint_end >=0 )
1870 if( p_access->info.i_seekpoint > i_seekpoint_end ) return 0;
1872 else if( i_title_end >= 0 )
1874 if( p_access->info.i_title > i_title_end ) return 0;
1881 /*****************************************************************************
1883 *****************************************************************************/
1884 static int UpdateMeta( input_thread_t *p_input, vlc_bool_t b_quick )
1886 vlc_meta_t *p_meta = p_input->p_meta;
1889 if( !p_meta || p_meta->i_meta == 0 )
1892 if( !b_quick ) msg_Dbg( p_input, "meta information:" );
1893 for( i = 0; i < p_meta->i_meta; i++ )
1896 msg_Dbg( p_input, " - '%s' = '%s'",
1897 _(p_meta->name[i]), p_meta->value[i] );
1899 if( !strcmp(p_meta->name[i], _(VLC_META_TITLE)) && p_meta->value[i] &&
1900 !p_input->input.p_item->b_fixed_name )
1901 input_Control( p_input, INPUT_SET_NAME, p_meta->value[i] );
1903 if( !strcmp( p_meta->name[i], _(VLC_META_AUTHOR) ) )
1904 input_Control( p_input, INPUT_ADD_INFO, _("General"),
1905 _(VLC_META_AUTHOR), p_meta->value[i] );
1907 input_Control( p_input, INPUT_ADD_INFO, _(VLC_META_INFO_CAT),
1908 _(p_meta->name[i]), "%s", p_meta->value[i] );
1911 for( i = 0; i < p_meta->i_track; i++ )
1913 vlc_meta_t *tk = p_meta->track[i];
1916 if( tk->i_meta > 0 )
1918 char *psz_cat = malloc( strlen(_("Stream")) + 10 );
1920 msg_Dbg( p_input, " - track[%d]:", i );
1922 sprintf( psz_cat, "%s %d", _("Stream"), i );
1923 for( j = 0; j < tk->i_meta; j++ )
1925 msg_Dbg( p_input, " - '%s' = '%s'", _(tk->name[j]),
1928 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1929 _(tk->name[j]), "%s", tk->value[j] );
1934 if( p_input->p_sout && p_input->p_sout->p_meta == NULL )
1936 p_input->p_sout->p_meta = vlc_meta_Duplicate( p_meta );
1942 /*****************************************************************************
1944 *****************************************************************************/
1945 static void UpdateItemLength( input_thread_t *p_input, int64_t i_length,
1946 vlc_bool_t b_quick )
1948 playlist_t *p_playlist;
1949 char psz_buffer[MSTRTIME_MAX_SIZE];
1951 vlc_mutex_lock( &p_input->input.p_item->lock );
1952 p_input->input.p_item->i_duration = i_length;
1953 vlc_mutex_unlock( &p_input->input.p_item->lock );
1955 p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
1959 var_SetInteger( p_playlist, "item-change",
1960 p_input->input.p_item->i_id );
1961 vlc_object_release( p_playlist );
1964 input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
1965 msecstotimestr( psz_buffer, i_length / 1000 ) );
1968 /*****************************************************************************
1970 *****************************************************************************/
1971 static input_source_t *InputSourceNew( input_thread_t *p_input )
1973 input_source_t *in = (input_source_t*) malloc( sizeof( input_source_t ) );
1977 msg_Err( p_input, "out of memory for new input source" );
1982 in->p_access = NULL;
1983 in->p_stream = NULL;
1985 in->b_title_demux = VLC_FALSE;
1988 in->b_can_pace_control = VLC_TRUE;
1989 in->b_eof = VLC_FALSE;
1990 in->i_cr_average = 0;
1995 /*****************************************************************************
1997 *****************************************************************************/
1998 static int InputSourceInit( input_thread_t *p_input,
1999 input_source_t *in, char *psz_mrl,
2000 char *psz_forced_demux, vlc_bool_t b_quick )
2002 char *psz_dup = strdup( psz_mrl );
2010 if( !in ) return VLC_EGENERIC;
2015 MRLSplit( VLC_OBJECT(p_input), psz_dup,
2016 &psz_access, &psz_demux, &psz_path );
2018 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
2019 psz_mrl, psz_access, psz_demux, psz_path );
2021 /* Hack to allow udp://@:port syntax */
2023 (strncmp( psz_access, "udp", 3 ) &&
2024 strncmp( psz_access, "rtp", 3 )) )
2026 /* Find optional titles and seekpoints */
2027 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
2028 &in->i_seekpoint_start, &in->i_seekpoint_end );
2030 if( psz_forced_demux && *psz_forced_demux )
2032 psz_demux = psz_forced_demux;
2034 else if( !psz_demux || *psz_demux == '\0' )
2036 /* special hack for forcing a demuxer with --demux=module
2037 * (and do nothing with a list) */
2038 char *psz_var_demux = var_GetString( p_input, "demux" );
2040 if( *psz_var_demux != '\0' &&
2041 !strchr(psz_var_demux, ',' ) &&
2042 !strchr(psz_var_demux, ':' ) )
2044 psz_demux = psz_var_demux;
2046 msg_Dbg( p_input, "Enforce demux ` %s'", psz_demux );
2048 else if( psz_var_demux )
2050 free( psz_var_demux );
2054 /* Try access_demux if no demux given */
2055 if( *psz_demux == '\0' )
2057 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
2058 NULL, p_input->p_es_out, VLC_FALSE );
2064 msg_Dbg( p_input, "trying to preparse %s", psz_path );
2065 psz_demux = strdup( "" );
2066 psz_access = strdup( "file" );
2071 int64_t i_pts_delay;
2073 /* Get infos from access_demux */
2074 demux2_Control( in->p_demux,
2075 DEMUX_GET_PTS_DELAY, &i_pts_delay );
2076 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2078 in->b_title_demux = VLC_TRUE;
2079 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2080 &in->title, &in->i_title,
2081 &in->i_title_offset, &in->i_seekpoint_offset ) )
2086 demux2_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
2087 &in->b_can_pace_control );
2088 demux2_Control( in->p_demux, DEMUX_CAN_PAUSE,
2092 demux2_Control( in->p_demux, DEMUX_CAN_SEEK,
2098 int64_t i_pts_delay;
2100 /* Now try a real access */
2101 in->p_access = access2_New( p_input, psz_access, psz_demux, psz_path,
2104 /* Access failed, URL encoded ? */
2105 if( in->p_access == NULL && strchr( psz_path, '%' ) )
2107 DecodeUrl( psz_path );
2109 msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
2110 psz_access, psz_demux, psz_path );
2112 in->p_access = access2_New( p_input,
2113 psz_access, psz_demux, psz_path,
2116 #ifndef WIN32 /* Remove this gross hack from the win32 build as colons
2117 * are forbidden in filenames on Win32. */
2119 /* Maybe we got something like: /Volumes/toto:titi/gabu.mpg */
2120 if( in->p_access == NULL &&
2121 *psz_access == '\0' && ( *psz_demux || *psz_path ) )
2123 if( psz_dup ) free( psz_dup );
2124 psz_dup = strdup( psz_mrl );
2129 in->p_access = access2_New( p_input,
2130 psz_access, psz_demux, psz_path,
2135 if( in->p_access == NULL )
2137 msg_Err( p_input, "no suitable access module for `%s'", psz_mrl );
2138 intf_UserFatal( VLC_OBJECT( p_input),
2139 _("Errors"),"Unable to open '%s'", psz_mrl );
2144 psz_tmp = psz = var_GetString( p_input, "access-filter" );
2145 while( psz && *psz )
2147 access_t *p_access = in->p_access;
2148 char *end = strchr( psz, ':' );
2153 in->p_access = access2_FilterNew( in->p_access, psz );
2154 if( in->p_access == NULL )
2156 in->p_access = p_access;
2157 msg_Warn( p_input, "failed to insert access filter %s",
2163 if( psz_tmp ) free( psz_tmp );
2165 /* Get infos from access */
2168 access2_Control( in->p_access,
2169 ACCESS_GET_PTS_DELAY, &i_pts_delay );
2170 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2172 in->b_title_demux = VLC_FALSE;
2173 if( access2_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2174 &in->title, &in->i_title,
2175 &in->i_title_offset, &in->i_seekpoint_offset ) )
2181 access2_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2182 &in->b_can_pace_control );
2183 access2_Control( in->p_access, ACCESS_CAN_PAUSE,
2185 access2_Control( in->p_access, ACCESS_CAN_SEEK,
2187 var_Set( p_input, "seekable", val );
2190 /* Create the stream_t */
2191 in->p_stream = stream_AccessNew( in->p_access, b_quick );
2192 if( in->p_stream == NULL )
2194 msg_Warn( p_input, "cannot create a stream_t from access" );
2198 /* Open a demuxer */
2199 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2201 psz_demux = in->p_access->psz_demux;
2203 in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
2204 in->p_stream, p_input->p_es_out, b_quick );
2205 if( in->p_demux == NULL )
2207 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2208 psz_access, psz_demux, psz_path );
2209 intf_UserFatal( VLC_OBJECT( p_input), _("Errors"),
2210 "Unrecognized format for '%s'", psz_mrl );
2214 /* TODO get title from demux */
2215 if( !b_quick && in->i_title <= 0 )
2217 if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2218 &in->title, &in->i_title,
2219 &in->i_title_offset, &in->i_seekpoint_offset ))
2226 in->b_title_demux = VLC_TRUE;
2231 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2232 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2234 if( psz_dup ) free( psz_dup );
2239 demux2_Delete( in->p_demux );
2242 stream_Delete( in->p_stream );
2245 access2_Delete( in->p_access );
2246 if( psz_dup ) free( psz_dup );
2248 return VLC_EGENERIC;
2251 /*****************************************************************************
2253 *****************************************************************************/
2254 static void InputSourceClean( input_thread_t *p_input, input_source_t *in )
2257 demux2_Delete( in->p_demux );
2260 stream_Delete( in->p_stream );
2263 access2_Delete( in->p_access );
2265 if( in->i_title > 0 )
2268 for( i = 0; i < in->i_title; i++ )
2270 vlc_input_title_Delete( in->title[i] );
2276 static void SlaveDemux( input_thread_t *p_input )
2281 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2283 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2287 for( i = 0; i < p_input->i_slave; i++ )
2289 input_source_t *in = p_input->slave[i];
2295 if( demux2_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2300 if( demux2_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2302 msg_Err( p_input, "slave[%d] doesn't like "
2303 "DEMUX_GET_TIME -> EOF", i );
2308 if( i_stime >= i_time )
2311 if( ( i_ret = in->p_demux->pf_demux( in->p_demux ) ) <= 0 )
2317 i_ret = in->p_demux->pf_demux( in->p_demux );
2322 msg_Dbg( p_input, "slave %d EOF", i );
2323 in->b_eof = VLC_TRUE;
2328 static void SlaveSeek( input_thread_t *p_input )
2333 if( demux2_Control( p_input->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2335 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2339 for( i = 0; i < p_input->i_slave; i++ )
2341 input_source_t *in = p_input->slave[i];
2343 if( demux2_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
2345 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2346 in->b_eof = VLC_TRUE;
2350 /*****************************************************************************
2352 *****************************************************************************/
2353 static vlc_meta_t *InputMetaUser( input_thread_t *p_input )
2358 if( ( p_meta = vlc_meta_New() ) == NULL )
2361 /* Get meta information from user */
2362 #define GET_META( c, s ) \
2363 var_Get( p_input, (s), &val ); \
2364 if( *val.psz_string ) \
2365 vlc_meta_Add( p_meta, _(c), val.psz_string ); \
2366 free( val.psz_string )
2368 GET_META( VLC_META_TITLE, "meta-title" );
2369 GET_META( VLC_META_AUTHOR, "meta-author" );
2370 GET_META( VLC_META_ARTIST, "meta-artist" );
2371 GET_META( VLC_META_GENRE, "meta-genre" );
2372 GET_META( VLC_META_COPYRIGHT, "meta-copyright" );
2373 GET_META( VLC_META_DESCRIPTION, "meta-description" );
2374 GET_META( VLC_META_DATE, "meta-date" );
2375 GET_META( VLC_META_URL, "meta-url" );
2381 /*****************************************************************************
2382 * DecodeUrl: decode a given encoded url
2383 *****************************************************************************/
2384 static void DecodeUrl( char *psz )
2386 char *dup = strdup( psz );
2404 *psz++ = strtol( val, NULL, 16 );
2406 else if( *p == '+' )
2416 if( psz ) *psz++ ='\0';
2417 if( dup ) free( dup );
2420 /*****************************************************************************
2421 * MRLSplit: parse the access, demux and url part of the
2422 * Media Resource Locator.
2423 *****************************************************************************/
2424 void MRLSplit( vlc_object_t *p_input, char *psz_dup,
2425 char **ppsz_access, char **ppsz_demux, char **ppsz_path )
2427 char *psz_access = NULL;
2428 char *psz_demux = NULL;
2429 char *psz_path = NULL;
2430 char *psz, *psz_check;
2432 psz = strchr( psz_dup, ':' );
2434 /* '@' not allowed in access/demux part */
2435 psz_check = strchr( psz_dup, '@' );
2436 if( psz_check && psz_check < psz ) psz = 0;
2438 #if defined( WIN32 ) || defined( UNDER_CE )
2439 if( psz - psz_dup == 1 )
2441 msg_Warn( p_input, "drive letter %c: found in source", *psz_dup );
2450 if( psz[0] == '/' && psz[1] == '/' ) psz += 2;
2454 psz = strchr( psz_dup, '/' );
2461 psz_access = psz_dup;
2468 if( !psz_access ) *ppsz_access = "";
2469 else *ppsz_access = psz_access;
2471 if( !psz_demux ) *ppsz_demux = "";
2472 else *ppsz_demux = psz_demux;
2474 if( !psz_path ) *ppsz_path = "";
2475 else *ppsz_path = psz_path;
2478 /*****************************************************************************
2479 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
2482 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
2483 *****************************************************************************/
2484 static void MRLSections( input_thread_t *p_input, char *psz_source,
2485 int *pi_title_start, int *pi_title_end,
2486 int *pi_chapter_start, int *pi_chapter_end )
2488 char *psz, *psz_end, *psz_next, *psz_check;
2490 *pi_title_start = *pi_title_end = -1;
2491 *pi_chapter_start = *pi_chapter_end = -1;
2493 /* Start by parsing titles and chapters */
2494 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
2496 /* Check we are really dealing with a title/chapter section */
2497 psz_check = psz + 1;
2498 if( !*psz_check ) return;
2499 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2500 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
2501 if( *psz_check == ':' && ++psz_check )
2502 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2503 if( *psz_check != '-' && *psz_check ) return;
2504 if( *psz_check == '-' && ++psz_check )
2505 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2506 if( *psz_check != ':' && *psz_check ) return;
2507 if( *psz_check == ':' && ++psz_check )
2508 if( isdigit(*psz_check) ) strtol( psz_check, &psz_check, 0 );
2509 if( *psz_check ) return;
2511 /* Separate start and end */
2513 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
2515 /* Look for the start title */
2516 *pi_title_start = strtol( psz, &psz_next, 0 );
2517 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
2518 *pi_title_end = *pi_title_start;
2521 /* Look for the start chapter */
2523 *pi_chapter_start = strtol( psz, &psz_next, 0 );
2524 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
2525 *pi_chapter_end = *pi_chapter_start;
2529 /* Look for the end title */
2530 *pi_title_end = strtol( psz_end, &psz_next, 0 );
2531 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
2534 /* Look for the end chapter */
2535 if( *psz_end ) psz_end++;
2536 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
2537 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
2540 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
2541 psz_source, *pi_title_start, *pi_chapter_start,
2542 *pi_title_end, *pi_chapter_end );
2546 /***********************************************************************
2547 * Info management functions
2548 ***********************************************************************/
2550 * Get a info item from a given category in a given input item.
2552 * \param p_i The input item to get info from
2553 * \param psz_cat String representing the category for the info
2554 * \param psz_name String representing the name of the desired info
2555 * \return A pointer to the string with the given info if found, or an
2556 * empty string otherwise. The caller should free the returned
2559 char *vlc_input_item_GetInfo( input_item_t *p_i,
2560 const char *psz_cat,
2561 const char *psz_name )
2565 vlc_mutex_lock( &p_i->lock );
2567 for( i = 0 ; i< p_i->i_categories ; i++ )
2569 info_category_t *p_cat = p_i->pp_categories[i];
2571 if( !psz_cat || strcmp( p_cat->psz_name, psz_cat ) )
2574 for( j = 0; j < p_cat->i_infos ; j++ )
2576 if( !strcmp( p_cat->pp_infos[j]->psz_name, psz_name ) )
2578 char *psz_ret = strdup( p_cat->pp_infos[j]->psz_value );
2579 vlc_mutex_unlock( &p_i->lock );
2584 vlc_mutex_unlock( &p_i->lock );
2585 return strdup( "" );
2588 int vlc_input_item_AddInfo( input_item_t *p_i,
2589 const char *psz_cat,
2590 const char *psz_name,
2591 const char *psz_format, ... )
2595 info_t *p_info = NULL;
2596 info_category_t *p_cat = NULL ;
2598 vlc_mutex_lock( &p_i->lock );
2600 for( i = 0 ; i < p_i->i_categories ; i ++ )
2602 if( !strcmp( p_i->pp_categories[i]->psz_name, psz_cat ) )
2604 p_cat = p_i->pp_categories[i];
2610 if( !(p_cat = (info_category_t *)malloc( sizeof(info_category_t) )) )
2612 vlc_mutex_unlock( &p_i->lock );
2613 return VLC_EGENERIC;
2615 p_cat->psz_name = strdup( psz_cat );
2617 p_cat->pp_infos = 0;
2618 INSERT_ELEM( p_i->pp_categories, p_i->i_categories, p_i->i_categories,
2622 for( i = 0; i< p_cat->i_infos; i++ )
2624 if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
2626 p_info = p_cat->pp_infos[i];
2633 if( ( p_info = (info_t *)malloc( sizeof( info_t ) ) ) == NULL )
2635 vlc_mutex_unlock( &p_i->lock );
2636 return VLC_EGENERIC;
2638 INSERT_ELEM( p_cat->pp_infos, p_cat->i_infos, p_cat->i_infos, p_info );
2639 p_info->psz_name = strdup( psz_name );
2643 if( p_info->psz_value ) free( p_info->psz_value );
2646 va_start( args, psz_format );
2647 vasprintf( &p_info->psz_value, psz_format, args);
2650 vlc_mutex_unlock( &p_i->lock );