1 /*****************************************************************************
2 * input.c: input thread
3 *****************************************************************************
4 * Copyright (C) 1998-2007 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_common.h>
38 #include "input_internal.h"
41 #include "es_out_timeshift.h"
48 #include "../stream_output/stream_output.h"
50 #include <vlc_interface.h>
52 #include <vlc_charset.h>
53 #include <vlc_strings.h>
55 #ifdef HAVE_SYS_STAT_H
56 # include <sys/stat.h>
59 /*****************************************************************************
61 *****************************************************************************/
62 static void Destructor( input_thread_t * p_input );
64 static void *Run ( vlc_object_t *p_this );
65 static void *RunAndDestroy ( vlc_object_t *p_this );
67 static input_thread_t * Create ( vlc_object_t *, input_item_t *,
68 const char *, bool, sout_instance_t * );
69 static int Init ( input_thread_t *p_input );
70 static void WaitDie ( input_thread_t *p_input );
71 static void End ( input_thread_t *p_input );
72 static void MainLoop( input_thread_t *p_input );
74 static void ObjectKillChildrens( input_thread_t *, vlc_object_t * );
76 static inline int ControlPopNoLock( input_thread_t *, int *, vlc_value_t *, mtime_t i_deadline );
77 static void ControlReduce( input_thread_t * );
78 static bool Control( input_thread_t *, int, vlc_value_t );
80 static int UpdateTitleSeekpointFromAccess( input_thread_t * );
81 static void UpdateGenericFromAccess( input_thread_t * );
83 static int UpdateTitleSeekpointFromDemux( input_thread_t * );
84 static void UpdateGenericFromDemux( input_thread_t * );
86 static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
88 static input_source_t *InputSourceNew( input_thread_t *);
89 static int InputSourceInit( input_thread_t *, input_source_t *,
90 const char *, const char *psz_forced_demux );
91 static void InputSourceClean( input_source_t * );
92 static void InputSourceMeta( input_thread_t *, input_source_t *, vlc_meta_t * );
95 //static void InputGetAttachments( input_thread_t *, input_source_t * );
96 static void SlaveDemux( input_thread_t *p_input );
97 static void SlaveSeek( input_thread_t *p_input );
99 static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta );
100 static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta );
101 static char *InputGetExtraFiles( input_thread_t *p_input,
102 const char *psz_access, const char *psz_path );
104 static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
105 int i_new, input_attachment_t **pp_new );
107 static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_forced );
109 static void input_ChangeState( input_thread_t *p_input, int i_state ); /* TODO fix name */
111 /*****************************************************************************
112 * This function creates a new input, and returns a pointer
113 * to its description. On error, it returns NULL.
115 * XXX Do not forget to update vlc_input.h if you add new variables.
116 *****************************************************************************/
117 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
118 const char *psz_header, bool b_quick,
119 sout_instance_t *p_sout )
121 static const char input_name[] = "input";
122 input_thread_t *p_input = NULL; /* thread descriptor */
126 /* Allocate descriptor */
127 p_input = vlc_custom_create( p_parent, sizeof( *p_input ),
128 VLC_OBJECT_INPUT, input_name );
129 if( p_input == NULL )
132 /* Construct a nice name for the input timer */
133 char psz_timer_name[255];
134 char * psz_name = input_item_GetName( p_item );
135 snprintf( psz_timer_name, sizeof(psz_timer_name),
136 "input launching for '%s'", psz_name );
138 msg_Dbg( p_input, "Creating an input for '%s'", psz_name);
142 /* Start a timer to mesure how long it takes
143 * to launch an input */
144 stats_TimerStart( p_input, psz_timer_name,
145 STATS_TIMER_INPUT_LAUNCHING );
147 p_input->p = calloc( 1, sizeof( input_thread_private_t ) );
151 /* One "randomly" selected input thread is responsible for computing
152 * the global stats. Check if there is already someone doing this */
153 if( p_input->p_libvlc->p_stats && !b_quick )
155 libvlc_priv_t *p_private = libvlc_priv( p_input->p_libvlc );
156 vlc_mutex_lock( &p_input->p_libvlc->p_stats->lock );
157 if( p_private->p_stats_computer == NULL )
158 p_private->p_stats_computer = p_input;
159 vlc_mutex_unlock( &p_input->p_libvlc->p_stats->lock );
162 p_input->b_preparsing = b_quick;
163 p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
166 vlc_event_manager_t * p_em = &p_input->p->event_manager;
167 vlc_event_manager_init_with_vlc_object( p_em, p_input );
168 vlc_event_manager_register_event_type( p_em, vlc_InputStateChanged );
169 vlc_event_manager_register_event_type( p_em, vlc_InputSelectedStreamChanged );
171 /* Init Common fields */
172 p_input->b_eof = false;
173 p_input->b_can_pace_control = true;
174 p_input->p->i_start = 0;
176 p_input->p->i_stop = 0;
177 p_input->p->i_run = 0;
178 p_input->p->i_title = 0;
179 p_input->p->title = NULL;
180 p_input->p->i_title_offset = p_input->p->i_seekpoint_offset = 0;
181 p_input->i_state = INIT_S;
182 p_input->p->i_rate = INPUT_RATE_DEFAULT;
183 p_input->p->b_recording = false;
184 memset( &p_input->p->bookmark, 0, sizeof(p_input->p->bookmark) );
185 TAB_INIT( p_input->p->i_bookmark, p_input->p->pp_bookmark );
186 TAB_INIT( p_input->p->i_attachment, p_input->p->attachment );
187 p_input->p->p_es_out_display = NULL;
188 p_input->p->p_es_out = NULL;
189 p_input->p->p_sout = NULL;
190 p_input->p->b_out_pace_control = false;
191 p_input->i_pts_delay = 0;
192 p_input->p->i_cr_average = 0;
194 vlc_gc_incref( p_item ); /* Released in Destructor() */
195 p_input->p->p_item = p_item;
197 /* Init Input fields */
198 p_input->p->input.p_access = NULL;
199 p_input->p->input.p_stream = NULL;
200 p_input->p->input.p_demux = NULL;
201 p_input->p->input.b_title_demux = false;
202 p_input->p->input.i_title = 0;
203 p_input->p->input.title = NULL;
204 p_input->p->input.i_title_offset = p_input->p->input.i_seekpoint_offset = 0;
205 p_input->p->input.b_can_pace_control = true;
206 p_input->p->input.b_can_rate_control = true;
207 p_input->p->input.b_rescale_ts = true;
208 p_input->p->input.b_eof = false;
210 vlc_mutex_lock( &p_item->lock );
212 if( !p_item->p_stats )
213 p_item->p_stats = stats_NewInputStats( p_input );
214 vlc_mutex_unlock( &p_item->lock );
217 p_input->p->i_slave = 0;
218 p_input->p->slave = NULL;
220 /* Init control buffer */
221 vlc_mutex_init( &p_input->p->lock_control );
222 vlc_cond_init( &p_input->p->wait_control );
223 p_input->p->i_control = 0;
225 /* Parse input options */
226 vlc_mutex_lock( &p_item->lock );
227 assert( (int)p_item->optflagc == p_item->i_options );
228 for( i = 0; i < p_item->i_options; i++ )
229 var_OptionParse( VLC_OBJECT(p_input), p_item->ppsz_options[i],
230 !!(p_item->optflagv[i] & VLC_INPUT_OPTION_TRUSTED) );
231 vlc_mutex_unlock( &p_item->lock );
233 /* Create Object Variables for private use only */
234 input_ConfigVarInit( p_input );
236 /* Create Objects variables for public Get and Set */
237 input_ControlVarInit( p_input );
240 p_input->p->i_cr_average = var_GetInteger( p_input, "cr-average" );
242 if( !p_input->b_preparsing )
244 var_Get( p_input, "bookmarks", &val );
247 /* FIXME: have a common cfg parsing routine used by sout and others */
248 char *psz_parser, *psz_start, *psz_end;
249 psz_parser = val.psz_string;
250 while( (psz_start = strchr( psz_parser, '{' ) ) )
252 seekpoint_t *p_seekpoint;
255 psz_end = strchr( psz_start, '}' );
256 if( !psz_end ) break;
257 psz_parser = psz_end + 1;
258 backup = *psz_parser;
262 p_seekpoint = vlc_seekpoint_New();
263 while( (psz_end = strchr( psz_start, ',' ) ) )
266 if( !strncmp( psz_start, "name=", 5 ) )
268 p_seekpoint->psz_name = strdup(psz_start + 5);
270 else if( !strncmp( psz_start, "bytes=", 6 ) )
272 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
274 else if( !strncmp( psz_start, "time=", 5 ) )
276 p_seekpoint->i_time_offset = atoll(psz_start + 5) *
279 psz_start = psz_end + 1;
281 msg_Dbg( p_input, "adding bookmark: %s, bytes=%"PRId64", time=%"PRId64,
282 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
283 p_seekpoint->i_time_offset );
284 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
285 vlc_seekpoint_Delete( p_seekpoint );
286 *psz_parser = backup;
288 free( val.psz_string );
292 /* Remove 'Now playing' info as it is probably outdated */
293 input_item_SetNowPlaying( p_item, NULL );
294 input_SendEventMeta( p_input );
297 if( p_input->b_preparsing )
298 p_input->i_flags |= OBJECT_FLAGS_QUIET | OBJECT_FLAGS_NOINTERACT;
302 p_input->p->p_sout = p_sout;
304 memset( &p_input->p->counters, 0, sizeof( p_input->p->counters ) );
305 vlc_mutex_init( &p_input->p->counters.counters_lock );
307 /* Set the destructor when we are sure we are initialized */
308 vlc_object_set_destructor( p_input, (vlc_destructor_t)Destructor );
310 /* Attach only once we are ready */
311 vlc_object_attach( p_input, p_parent );
317 * Input destructor (called when the object's refcount reaches 0).
319 static void Destructor( input_thread_t * p_input )
322 char * psz_name = input_item_GetName( p_input->p->p_item );
323 msg_Dbg( p_input, "Destroying the input for '%s'", psz_name);
327 vlc_event_manager_fini( &p_input->p->event_manager );
329 stats_TimerDump( p_input, STATS_TIMER_INPUT_LAUNCHING );
330 stats_TimerClean( p_input, STATS_TIMER_INPUT_LAUNCHING );
332 if( p_input->p->p_sout )
333 sout_DeleteInstance( p_input->p->p_sout );
335 vlc_gc_decref( p_input->p->p_item );
337 vlc_mutex_destroy( &p_input->p->counters.counters_lock );
339 vlc_cond_destroy( &p_input->p->wait_control );
340 vlc_mutex_destroy( &p_input->p->lock_control );
345 * Initialize an input thread and run it. You will need to monitor the
346 * thread to clean up after it is done
348 * \param p_parent a vlc_object
349 * \param p_item an input item
350 * \return a pointer to the spawned input thread
352 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
353 input_item_t *p_item )
355 return __input_CreateThreadExtended( p_parent, p_item, NULL, NULL );
359 input_thread_t *__input_CreateThreadExtended( vlc_object_t *p_parent,
360 input_item_t *p_item,
361 const char *psz_log, sout_instance_t *p_sout )
363 input_thread_t *p_input;
365 p_input = Create( p_parent, p_item, psz_log, false, p_sout );
369 /* Create thread and wait for its readiness. */
370 if( vlc_thread_create( p_input, "input", Run,
371 VLC_THREAD_PRIORITY_INPUT, false ) )
373 input_ChangeState( p_input, ERROR_S );
374 msg_Err( p_input, "cannot create input thread" );
375 vlc_object_detach( p_input );
376 vlc_object_release( p_input );
384 * Initialize an input thread and run it. This thread will clean after itself,
385 * you can forget about it. It can work either in blocking or non-blocking mode
387 * \param p_parent a vlc_object
388 * \param p_item an input item
389 * \param b_block should we block until read is finished ?
390 * \return an error code, VLC_SUCCESS on success
392 int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
395 input_thread_t *p_input;
397 p_input = Create( p_parent, p_item, NULL, false, NULL );
403 RunAndDestroy( VLC_OBJECT(p_input) );
408 if( vlc_thread_create( p_input, "input", RunAndDestroy,
409 VLC_THREAD_PRIORITY_INPUT, false ) )
411 input_ChangeState( p_input, ERROR_S );
412 msg_Err( p_input, "cannot create input thread" );
413 vlc_object_release( p_input );
421 * Initialize an input and initialize it to preparse the item
422 * This function is blocking. It will only accept to parse files
424 * \param p_parent a vlc_object_t
425 * \param p_item an input item
426 * \return VLC_SUCCESS or an error
428 int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
430 input_thread_t *p_input;
432 /* Allocate descriptor */
433 p_input = Create( p_parent, p_item, NULL, true, NULL );
437 if( !Init( p_input ) )
440 vlc_object_detach( p_input );
441 vlc_object_release( p_input );
447 * Request a running input thread to stop and die
449 * \param the input thread to stop
451 void input_StopThread( input_thread_t *p_input )
453 /* Set die for input and ALL of this childrens (even (grand-)grand-childrens)
454 * It is needed here even if it is done in INPUT_CONTROL_SET_DIE handler to
455 * unlock the control loop */
456 ObjectKillChildrens( p_input, VLC_OBJECT(p_input) );
458 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
461 sout_instance_t *input_DetachSout( input_thread_t *p_input )
463 assert( p_input->b_dead );
464 sout_instance_t *p_sout = p_input->p->p_sout;
465 vlc_object_detach( p_sout );
466 p_input->p->p_sout = NULL;
471 * Get the item from an input thread
472 * FIXME it does not increase ref count of the item.
473 * if it is used after p_input is destroyed nothing prevent it from
476 input_item_t *input_GetItem( input_thread_t *p_input )
478 assert( p_input && p_input->p );
479 return p_input->p->p_item;
482 /*****************************************************************************
483 * ObjectKillChildrens
484 *****************************************************************************/
485 static void ObjectKillChildrens( input_thread_t *p_input, vlc_object_t *p_obj )
490 if( p_obj->i_object_type == VLC_OBJECT_VOUT ||
491 p_obj->i_object_type == VLC_OBJECT_AOUT ||
492 p_obj == VLC_OBJECT(p_input->p->p_sout) )
495 vlc_object_kill( p_obj );
497 p_list = vlc_list_children( p_obj );
498 for( i = 0; i < p_list->i_count; i++ )
499 ObjectKillChildrens( p_input, p_list->p_values[i].p_object );
500 vlc_list_release( p_list );
503 /*****************************************************************************
504 * Run: main thread loop
505 * This is the "normal" thread that spawns the input processing chain,
506 * reads the stream, cleans up and waits
507 *****************************************************************************/
508 static void *Run( vlc_object_t *p_this )
510 input_thread_t *p_input = (input_thread_t *)p_this;
511 const int canc = vlc_savecancel();
513 if( Init( p_input ) )
515 /* If we failed, wait before we are killed, and exit */
522 /* Wait until we are asked to die */
523 if( !p_input->b_die )
530 p_input->b_dead = true;
531 vlc_restorecancel( canc );
535 /*****************************************************************************
536 * RunAndDestroy: main thread loop
537 * This is the "just forget me" thread that spawns the input processing chain,
538 * reads the stream, cleans up and releases memory
539 *****************************************************************************/
540 static void *RunAndDestroy( vlc_object_t *p_this )
542 input_thread_t *p_input = (input_thread_t *)p_this;
543 const int canc = vlc_savecancel();
545 if( Init( p_input ) )
555 vlc_object_release( p_input );
556 vlc_restorecancel( canc );
560 /*****************************************************************************
561 * Main loop: Fill buffers from access, and demux
562 *****************************************************************************/
566 * It asks the demuxer to demux some data
568 static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, mtime_t *pi_start_mdate )
574 if( ( p_input->p->i_stop > 0 && p_input->i_time >= p_input->p->i_stop ) ||
575 ( p_input->p->i_run > 0 && *pi_start_mdate+p_input->p->i_run < mdate() ) )
578 i_ret = demux_Demux( p_input->p->input.p_demux );
582 if( p_input->p->input.p_demux->info.i_update )
584 if( p_input->p->input.b_title_demux )
586 i_ret = UpdateTitleSeekpointFromDemux( p_input );
589 UpdateGenericFromDemux( p_input );
591 else if( p_input->p->input.p_access &&
592 p_input->p->input.p_access->info.i_update )
594 if( !p_input->p->input.b_title_demux )
596 i_ret = UpdateTitleSeekpointFromAccess( p_input );
599 UpdateGenericFromAccess( p_input );
603 if( i_ret == 0 ) /* EOF */
607 var_Get( p_input, "input-repeat", &repeat );
608 if( repeat.i_int == 0 )
610 /* End of file - we do not set b_die because only the
611 * playlist is allowed to do so. */
612 msg_Dbg( p_input, "EOF reached" );
613 p_input->p->input.b_eof = true;
619 msg_Dbg( p_input, "repeating the same input (%d)",
621 if( repeat.i_int > 0 )
624 var_Set( p_input, "input-repeat", repeat );
627 /* Seek to start title/seekpoint */
628 val.i_int = p_input->p->input.i_title_start -
629 p_input->p->input.i_title_offset;
630 if( val.i_int < 0 || val.i_int >= p_input->p->input.i_title )
632 input_ControlPush( p_input,
633 INPUT_CONTROL_SET_TITLE, &val );
635 val.i_int = p_input->p->input.i_seekpoint_start -
636 p_input->p->input.i_seekpoint_offset;
637 if( val.i_int > 0 /* TODO: check upper boundary */ )
638 input_ControlPush( p_input,
639 INPUT_CONTROL_SET_SEEKPOINT, &val );
641 /* Seek to start position */
642 if( p_input->p->i_start > 0 )
644 val.i_time = p_input->p->i_start;
645 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
651 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
656 *pi_start_mdate = mdate();
661 input_ChangeState( p_input, ERROR_S );
664 if( i_ret > 0 && p_input->p->i_slave > 0 )
666 SlaveDemux( p_input );
672 * It update the variables used by the interfaces
674 static void MainLoopInterface( input_thread_t *p_input )
676 double f_position = 0.0;
678 mtime_t i_length = 0;
680 /* update input status variables */
681 if( demux_Control( p_input->p->input.p_demux,
682 DEMUX_GET_POSITION, &f_position ) )
685 if( demux_Control( p_input->p->input.p_demux,
686 DEMUX_GET_TIME, &i_time ) )
689 if( demux_Control( p_input->p->input.p_demux,
690 DEMUX_GET_LENGTH, &i_length ) )
693 es_out_SetTimes( p_input->p->p_es_out, f_position, i_time, i_length );
695 /* update current bookmark */
696 vlc_mutex_lock( &p_input->p->p_item->lock );
697 p_input->p->bookmark.i_time_offset = i_time;
698 if( p_input->p->input.p_stream )
699 p_input->p->bookmark.i_byte_offset = stream_Tell( p_input->p->input.p_stream );
700 vlc_mutex_unlock( &p_input->p->p_item->lock );
705 * It updates the globals statics
707 static void MainLoopStatistic( input_thread_t *p_input )
709 stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
710 /* Are we the thread responsible for computing global stats ? */
711 if( libvlc_priv( p_input->p_libvlc )->p_stats_computer == p_input )
713 stats_ComputeGlobalStats( p_input->p_libvlc,
714 p_input->p_libvlc->p_stats );
716 input_SendEventStatistics( p_input );
721 * The main input loop.
723 static void MainLoop( input_thread_t *p_input )
725 mtime_t i_start_mdate = mdate();
726 mtime_t i_intf_update = 0;
727 mtime_t i_statistic_update = 0;
729 /* Start the timer */
730 stats_TimerStop( p_input, STATS_TIMER_INPUT_LAUNCHING );
732 while( vlc_object_alive( p_input ) && !p_input->b_error )
743 b_force_update = false;
745 /* FIXME if p_input->i_state == PAUSE_S the access/access_demux
746 * is paused -> this may cause problem with some of them
747 * The same problem can be seen when seeking while paused */
748 b_paused = p_input->i_state == PAUSE_S &&
749 !es_out_GetBuffering( p_input->p->p_es_out );
753 if( !p_input->p->input.b_eof )
755 MainLoopDemux( p_input, &b_force_update, &i_start_mdate );
757 i_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
759 else if( !p_input->b_eof && !es_out_GetEmpty( p_input->p->p_es_out ) )
761 msg_Dbg( p_input, "waiting decoder fifos to empty" );
762 i_wakeup = mdate() + INPUT_IDLE_SLEEP;
772 i_deadline = i_wakeup;
774 i_deadline = __MIN( i_intf_update, i_statistic_update );
777 vlc_mutex_lock( &p_input->p->lock_control );
778 ControlReduce( p_input );
779 while( !ControlPopNoLock( p_input, &i_type, &val, i_deadline ) )
781 msg_Dbg( p_input, "control type=%d", i_type );
783 if( Control( p_input, i_type, val ) )
784 b_force_update = true;
786 vlc_mutex_unlock( &p_input->p->lock_control );
788 /* Update interface and statistics */
790 if( i_intf_update < i_current || b_force_update )
792 MainLoopInterface( p_input );
793 i_intf_update = i_current + INT64_C(250000);
794 b_force_update = false;
796 if( i_statistic_update < i_current )
798 MainLoopStatistic( p_input );
799 i_statistic_update = i_current + INT64_C(1000000);
802 /* Check if i_wakeup is still valid */
805 mtime_t i_new_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
809 } while( i_current < i_wakeup );
812 if( !p_input->b_error )
813 input_ChangeState( p_input, END_S );
816 static void InitStatistics( input_thread_t * p_input )
818 if( p_input->b_preparsing ) return;
820 /* Prepare statistics */
821 #define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \
822 stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
823 if( libvlc_stats( p_input ) )
825 INIT_COUNTER( read_bytes, INTEGER, COUNTER );
826 INIT_COUNTER( read_packets, INTEGER, COUNTER );
827 INIT_COUNTER( demux_read, INTEGER, COUNTER );
828 INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE );
829 INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE );
830 INIT_COUNTER( played_abuffers, INTEGER, COUNTER );
831 INIT_COUNTER( lost_abuffers, INTEGER, COUNTER );
832 INIT_COUNTER( displayed_pictures, INTEGER, COUNTER );
833 INIT_COUNTER( lost_pictures, INTEGER, COUNTER );
834 INIT_COUNTER( decoded_audio, INTEGER, COUNTER );
835 INIT_COUNTER( decoded_video, INTEGER, COUNTER );
836 INIT_COUNTER( decoded_sub, INTEGER, COUNTER );
837 p_input->p->counters.p_sout_send_bitrate = NULL;
838 p_input->p->counters.p_sout_sent_packets = NULL;
839 p_input->p->counters.p_sout_sent_bytes = NULL;
840 if( p_input->p->counters.p_demux_bitrate )
841 p_input->p->counters.p_demux_bitrate->update_interval = 1000000;
842 if( p_input->p->counters.p_input_bitrate )
843 p_input->p->counters.p_input_bitrate->update_interval = 1000000;
848 static int InitSout( input_thread_t * p_input )
852 if( p_input->b_preparsing ) return VLC_SUCCESS;
854 /* Find a usable sout and attach it to p_input */
855 psz = var_GetNonEmptyString( p_input, "sout" );
856 if( psz && strncasecmp( p_input->p->p_item->psz_uri, "vlc:", 4 ) )
858 /* Check the validity of the provided sout */
859 if( p_input->p->p_sout )
861 if( strcmp( p_input->p->p_sout->psz_sout, psz ) )
863 msg_Dbg( p_input, "destroying unusable sout" );
865 sout_DeleteInstance( p_input->p->p_sout );
866 p_input->p->p_sout = NULL;
870 if( p_input->p->p_sout )
873 msg_Dbg( p_input, "sout keep: reusing sout" );
874 msg_Dbg( p_input, "sout keep: you probably want to use "
875 "gather stream_out" );
876 vlc_object_attach( p_input->p->p_sout, p_input );
880 /* Create a new one */
881 p_input->p->p_sout = sout_NewInstance( p_input, psz );
882 if( !p_input->p->p_sout )
884 input_ChangeState( p_input, ERROR_S );
885 msg_Err( p_input, "cannot start stream output instance, " \
891 if( libvlc_stats( p_input ) )
893 INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
894 INIT_COUNTER( sout_sent_bytes, INTEGER, COUNTER );
895 INIT_COUNTER( sout_send_bitrate, FLOAT, DERIVATIVE );
896 if( p_input->p->counters.p_sout_send_bitrate )
897 p_input->p->counters.p_sout_send_bitrate->update_interval =
901 else if( p_input->p->p_sout )
903 msg_Dbg( p_input, "destroying useless sout" );
905 sout_DeleteInstance( p_input->p->p_sout );
906 p_input->p->p_sout = NULL;
914 static void InitTitle( input_thread_t * p_input )
916 input_source_t *p_master = &p_input->p->input;
918 if( p_input->b_preparsing )
921 /* Create global title (from master) */
922 p_input->p->i_title = p_master->i_title;
923 p_input->p->title = p_master->title;
924 p_input->p->i_title_offset = p_master->i_title_offset;
925 p_input->p->i_seekpoint_offset = p_master->i_seekpoint_offset;
926 if( p_input->p->i_title > 0 )
928 /* Setup variables */
929 input_ControlVarNavigation( p_input );
930 input_ControlVarTitle( p_input, 0 );
934 p_input->b_can_pace_control = p_master->b_can_pace_control;
935 p_input->p->b_can_pause = p_master->b_can_pause;
936 p_input->p->b_can_rate_control = p_master->b_can_rate_control;
939 if( p_input->i_pts_delay < 0 )
940 p_input->i_pts_delay = 0;
942 /* If the desynchronisation requested by the user is < 0, we need to
943 * cache more data. */
944 const int i_desynch = var_GetInteger( p_input, "audio-desync" );
946 p_input->i_pts_delay -= i_desynch * 1000;
948 /* Update cr_average depending on the caching */
949 p_input->p->i_cr_average *= (10 * p_input->i_pts_delay / 200000);
950 p_input->p->i_cr_average /= 10;
951 if( p_input->p->i_cr_average < 10 )
952 p_input->p->i_cr_average = 10;
955 static void StartTitle( input_thread_t * p_input )
959 /* Start title/chapter */
960 val.i_int = p_input->p->input.i_title_start -
961 p_input->p->input.i_title_offset;
962 if( val.i_int > 0 && val.i_int < p_input->p->input.i_title )
963 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
965 val.i_int = p_input->p->input.i_seekpoint_start -
966 p_input->p->input.i_seekpoint_offset;
967 if( val.i_int > 0 /* TODO: check upper boundary */ )
968 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
970 /* Start/stop/run time */
971 p_input->p->i_start = INT64_C(1000000) * var_GetInteger( p_input, "start-time" );
972 p_input->p->i_stop = INT64_C(1000000) * var_GetInteger( p_input, "stop-time" );
973 p_input->p->i_run = INT64_C(1000000) * var_GetInteger( p_input, "run-time" );
974 if( p_input->p->i_run < 0 )
976 msg_Warn( p_input, "invalid run-time ignored" );
977 p_input->p->i_run = 0;
980 const mtime_t i_length = var_GetTime( p_input, "length" );
981 if( p_input->p->i_start > 0 )
983 if( p_input->p->i_start >= i_length )
985 msg_Warn( p_input, "invalid start-time ignored" );
991 msg_Dbg( p_input, "starting at time: %ds",
992 (int)( p_input->p->i_start / INT64_C(1000000) ) );
994 s.i_time = p_input->p->i_start;
995 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
998 if( p_input->p->i_stop > 0 && p_input->p->i_stop <= p_input->p->i_start )
1000 msg_Warn( p_input, "invalid stop-time ignored" );
1001 p_input->p->i_stop = 0;
1005 static void LoadSubtitles( input_thread_t *p_input )
1007 /* Load subtitles */
1008 /* Get fps and set it if not already set */
1009 const double f_fps = p_input->p->f_fps;
1012 float f_requested_fps;
1014 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
1015 var_SetFloat( p_input, "sub-original-fps", f_fps );
1017 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
1018 if( f_requested_fps != f_fps )
1020 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
1021 VLC_VAR_DOINHERIT );
1022 var_SetFloat( p_input, "sub-fps", f_requested_fps );
1026 const int i_delay = var_CreateGetInteger( p_input, "sub-delay" );
1028 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
1030 /* Look for and add subtitle files */
1031 char *psz_subtitle = var_GetNonEmptyString( p_input, "sub-file" );
1032 if( psz_subtitle != NULL )
1034 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
1035 SubtitleAdd( p_input, psz_subtitle, true );
1038 if( var_GetBool( p_input, "sub-autodetect-file" ) )
1040 char *psz_autopath = var_GetNonEmptyString( p_input, "sub-autodetect-path" );
1041 char **ppsz_subs = subtitles_Detect( p_input, psz_autopath,
1042 p_input->p->p_item->psz_uri );
1043 free( psz_autopath );
1045 for( int i = 0; ppsz_subs && ppsz_subs[i]; i++ )
1047 /* Try to autoselect the first autodetected subtitles file
1048 * if no subtitles file was specified */
1049 bool b_forced = i == 0 && !psz_subtitle;
1051 if( !psz_subtitle || strcmp( psz_subtitle, ppsz_subs[i] ) )
1052 SubtitleAdd( p_input, ppsz_subs[i], b_forced );
1054 free( ppsz_subs[i] );
1058 free( psz_subtitle );
1061 static void LoadSlaves( input_thread_t *p_input )
1063 char *psz = var_GetNonEmptyString( p_input, "input-slave" );
1067 char *psz_org = psz;
1068 while( psz && *psz )
1070 while( *psz == ' ' || *psz == '#' )
1073 char *psz_delim = strchr( psz, '#' );
1075 *psz_delim++ = '\0';
1080 msg_Dbg( p_input, "adding slave input '%s'", psz );
1082 input_source_t *p_slave = InputSourceNew( p_input );
1083 if( !InputSourceInit( p_input, p_slave, psz, NULL ) )
1084 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, p_slave );
1093 static void InitPrograms( input_thread_t * p_input )
1099 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, true );
1100 i_es_out_mode = ES_OUT_MODE_AUTO;
1102 if( p_input->p->p_sout )
1104 var_Get( p_input, "sout-all", &val );
1107 i_es_out_mode = ES_OUT_MODE_ALL;
1112 var_Get( p_input, "programs", &val );
1113 if( val.p_list && val.p_list->i_count )
1115 i_es_out_mode = ES_OUT_MODE_PARTIAL;
1116 /* Note : we should remove the "program" callback. */
1120 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
1125 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
1127 /* Inform the demuxer about waited group (needed only for DVB) */
1128 if( i_es_out_mode == ES_OUT_MODE_ALL )
1130 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
1132 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
1134 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1,
1139 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP,
1140 (int) var_GetInteger( p_input, "program" ), NULL );
1144 static int Init( input_thread_t * p_input )
1149 for( i = 0; i < p_input->p->p_item->i_options; i++ )
1151 if( !strncmp( p_input->p->p_item->ppsz_options[i], "meta-file", 9 ) )
1153 msg_Dbg( p_input, "Input is a meta file: disabling unneeded options" );
1154 var_SetString( p_input, "sout", "" );
1155 var_SetBool( p_input, "sout-all", false );
1156 var_SetString( p_input, "input-slave", "" );
1157 var_SetInteger( p_input, "input-repeat", 0 );
1158 var_SetString( p_input, "sub-file", "" );
1159 var_SetBool( p_input, "sub-autodetect-file", false );
1163 InitStatistics( p_input );
1165 ret = InitSout( p_input );
1166 if( ret != VLC_SUCCESS )
1167 return ret; /* FIXME: goto error; should be better here */
1171 p_input->p->p_es_out_display = input_EsOutNew( p_input, p_input->p->i_rate );
1172 p_input->p->p_es_out = input_EsOutTimeshiftNew( p_input, p_input->p->p_es_out_display, p_input->p->i_rate );
1173 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, false );
1174 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
1176 var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
1177 var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
1180 input_ChangeState( p_input, OPENING_S );
1181 input_SendEventCache( p_input, 0.0 );
1184 if( InputSourceInit( p_input, &p_input->p->input,
1185 p_input->p->p_item->psz_uri, NULL ) )
1190 InitTitle( p_input );
1192 /* Load master infos */
1195 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_LENGTH,
1199 i_length = input_item_GetDuration( p_input->p->p_item );
1200 input_SendEventTimes( p_input, 0.0, 0, i_length );
1202 if( !p_input->b_preparsing )
1204 StartTitle( p_input );
1205 LoadSubtitles( p_input );
1206 LoadSlaves( p_input );
1207 InitPrograms( p_input );
1210 if( !p_input->b_preparsing && p_input->p->p_sout )
1212 p_input->p->b_out_pace_control = (p_input->p->p_sout->i_out_pace_nocontrol > 0);
1214 if( p_input->b_can_pace_control && p_input->p->b_out_pace_control )
1216 /* We don't want a high input priority here or we'll
1217 * end-up sucking up all the CPU time */
1218 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
1221 msg_Dbg( p_input, "starting in %s mode",
1222 p_input->p->b_out_pace_control ? "async" : "sync" );
1225 p_meta = vlc_meta_New();
1228 /* Get meta data from users */
1229 InputMetaUser( p_input, p_meta );
1231 /* Get meta data from master input */
1232 InputSourceMeta( p_input, &p_input->p->input, p_meta );
1234 /* And from slave */
1235 for( int i = 0; i < p_input->p->i_slave; i++ )
1236 InputSourceMeta( p_input, p_input->p->slave[i], p_meta );
1239 InputUpdateMeta( p_input, p_meta );
1242 if( !p_input->b_preparsing )
1244 msg_Dbg( p_input, "`%s' successfully opened",
1245 p_input->p->p_item->psz_uri );
1249 /* initialization is complete */
1250 input_ChangeState( p_input, PLAYING_S );
1255 input_ChangeState( p_input, ERROR_S );
1257 if( p_input->p->p_es_out )
1258 es_out_Delete( p_input->p->p_es_out );
1259 if( p_input->p->p_es_out_display )
1260 es_out_Delete( p_input->p->p_es_out_display );
1262 if( p_input->p->p_sout )
1264 vlc_object_detach( p_input->p->p_sout );
1265 sout_DeleteInstance( p_input->p->p_sout );
1269 if( !p_input->b_preparsing && libvlc_stats( p_input ) )
1271 #define EXIT_COUNTER( c ) do { if( p_input->p->counters.p_##c ) \
1272 stats_CounterClean( p_input->p->counters.p_##c );\
1273 p_input->p->counters.p_##c = NULL; } while(0)
1274 EXIT_COUNTER( read_bytes );
1275 EXIT_COUNTER( read_packets );
1276 EXIT_COUNTER( demux_read );
1277 EXIT_COUNTER( input_bitrate );
1278 EXIT_COUNTER( demux_bitrate );
1279 EXIT_COUNTER( played_abuffers );
1280 EXIT_COUNTER( lost_abuffers );
1281 EXIT_COUNTER( displayed_pictures );
1282 EXIT_COUNTER( lost_pictures );
1283 EXIT_COUNTER( decoded_audio );
1284 EXIT_COUNTER( decoded_video );
1285 EXIT_COUNTER( decoded_sub );
1287 if( p_input->p->p_sout )
1289 EXIT_COUNTER( sout_sent_packets );
1290 EXIT_COUNTER( sout_sent_bytes );
1291 EXIT_COUNTER( sout_send_bitrate );
1296 /* Mark them deleted */
1297 p_input->p->input.p_demux = NULL;
1298 p_input->p->input.p_stream = NULL;
1299 p_input->p->input.p_access = NULL;
1300 p_input->p->p_es_out = NULL;
1301 p_input->p->p_es_out_display = NULL;
1302 p_input->p->p_sout = NULL;
1304 return VLC_EGENERIC;
1307 /*****************************************************************************
1308 * WaitDie: Wait until we are asked to die.
1309 *****************************************************************************
1310 * This function is called when an error occurred during thread main's loop.
1311 *****************************************************************************/
1312 static void WaitDie( input_thread_t *p_input )
1314 input_ChangeState( p_input, p_input->b_error ? ERROR_S : END_S );
1316 /* Wait a die order */
1317 vlc_object_lock( p_input );
1318 while( vlc_object_alive( p_input ) )
1319 vlc_object_wait( p_input );
1320 vlc_object_unlock( p_input );
1323 /*****************************************************************************
1324 * End: end the input thread
1325 *****************************************************************************/
1326 static void End( input_thread_t * p_input )
1330 /* We are at the end */
1331 input_ChangeState( p_input, END_S );
1333 /* Clean control variables */
1334 input_ControlVarStop( p_input );
1336 /* Stop es out activity */
1337 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, false );
1338 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
1340 /* Clean up master */
1341 InputSourceClean( &p_input->p->input );
1344 for( i = 0; i < p_input->p->i_slave; i++ )
1346 InputSourceClean( p_input->p->slave[i] );
1347 free( p_input->p->slave[i] );
1349 free( p_input->p->slave );
1351 /* Unload all modules */
1352 if( p_input->p->p_es_out )
1353 es_out_Delete( p_input->p->p_es_out );
1354 if( p_input->p->p_es_out_display )
1355 es_out_Delete( p_input->p->p_es_out_display );
1357 if( !p_input->b_preparsing )
1359 #define CL_CO( c ) stats_CounterClean( p_input->p->counters.p_##c ); p_input->p->counters.p_##c = NULL;
1360 if( libvlc_stats( p_input ) )
1362 libvlc_priv_t *p_private = libvlc_priv( p_input->p_libvlc );
1364 /* make sure we are up to date */
1365 stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
1366 if( p_private->p_stats_computer == p_input )
1368 stats_ComputeGlobalStats( p_input->p_libvlc,
1369 p_input->p_libvlc->p_stats );
1370 /* FIXME how can it be thread safe ? */
1371 p_private->p_stats_computer = NULL;
1373 CL_CO( read_bytes );
1374 CL_CO( read_packets );
1375 CL_CO( demux_read );
1376 CL_CO( input_bitrate );
1377 CL_CO( demux_bitrate );
1378 CL_CO( played_abuffers );
1379 CL_CO( lost_abuffers );
1380 CL_CO( displayed_pictures );
1381 CL_CO( lost_pictures );
1382 CL_CO( decoded_audio) ;
1383 CL_CO( decoded_video );
1384 CL_CO( decoded_sub) ;
1387 /* Close optional stream output instance */
1388 if( p_input->p->p_sout )
1390 CL_CO( sout_sent_packets );
1391 CL_CO( sout_sent_bytes );
1392 CL_CO( sout_send_bitrate );
1394 vlc_object_detach( p_input->p->p_sout );
1399 if( p_input->p->i_attachment > 0 )
1401 for( i = 0; i < p_input->p->i_attachment; i++ )
1402 vlc_input_attachment_Delete( p_input->p->attachment[i] );
1403 TAB_CLEAN( p_input->p->i_attachment, p_input->p->attachment );
1406 /* Tell we're dead */
1407 p_input->b_dead = true;
1410 /*****************************************************************************
1412 *****************************************************************************/
1413 void input_ControlPush( input_thread_t *p_input,
1414 int i_type, vlc_value_t *p_val )
1416 vlc_mutex_lock( &p_input->p->lock_control );
1417 if( i_type == INPUT_CONTROL_SET_DIE )
1419 /* Special case, empty the control */
1420 p_input->p->i_control = 1;
1421 p_input->p->control[0].i_type = i_type;
1422 memset( &p_input->p->control[0].val, 0, sizeof( vlc_value_t ) );
1424 else if( p_input->p->i_control >= INPUT_CONTROL_FIFO_SIZE )
1426 msg_Err( p_input, "input control fifo overflow, trashing type=%d",
1431 p_input->p->control[p_input->p->i_control].i_type = i_type;
1433 p_input->p->control[p_input->p->i_control].val = *p_val;
1435 memset( &p_input->p->control[p_input->p->i_control].val, 0,
1436 sizeof( vlc_value_t ) );
1438 p_input->p->i_control++;
1440 vlc_cond_signal( &p_input->p->wait_control );
1441 vlc_mutex_unlock( &p_input->p->lock_control );
1444 static inline int ControlPopNoLock( input_thread_t *p_input,
1445 int *pi_type, vlc_value_t *p_val,
1446 mtime_t i_deadline )
1449 while( p_input->p->i_control <= 0 )
1451 if( !vlc_object_alive( p_input ) )
1452 return VLC_EGENERIC;
1454 if( i_deadline < 0 )
1455 return VLC_EGENERIC;
1457 if( vlc_cond_timedwait( &p_input->p->wait_control, &p_input->p->lock_control, i_deadline ) )
1458 return VLC_EGENERIC;
1461 *pi_type = p_input->p->control[0].i_type;
1462 *p_val = p_input->p->control[0].val;
1464 p_input->p->i_control--;
1465 if( p_input->p->i_control > 0 )
1469 for( i = 0; i < p_input->p->i_control; i++ )
1471 p_input->p->control[i].i_type = p_input->p->control[i+1].i_type;
1472 p_input->p->control[i].val = p_input->p->control[i+1].val;
1479 static void ControlReduce( input_thread_t *p_input )
1486 for( i = 1; i < p_input->p->i_control; i++ )
1488 const int i_lt = p_input->p->control[i-1].i_type;
1489 const int i_ct = p_input->p->control[i].i_type;
1491 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1492 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->p->i_control,
1496 ( i_ct == INPUT_CONTROL_SET_STATE ||
1497 i_ct == INPUT_CONTROL_SET_RATE ||
1498 i_ct == INPUT_CONTROL_SET_POSITION ||
1499 i_ct == INPUT_CONTROL_SET_TIME ||
1500 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1501 i_ct == INPUT_CONTROL_SET_TITLE ||
1502 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1503 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1506 // msg_Dbg( p_input, "merged at %d", i );
1507 /* Remove the i-1 */
1508 for( j = i; j < p_input->p->i_control; j++ )
1509 p_input->p->control[j-1] = p_input->p->control[j];
1510 p_input->p->i_control--;
1514 /* TODO but that's not that important
1515 - merge SET_X with SET_X_CMD
1516 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1517 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1524 static void ControlPause( input_thread_t *p_input, mtime_t i_control_date )
1526 int i_ret = VLC_SUCCESS;
1527 int i_state = PAUSE_S;
1529 if( p_input->p->b_can_pause )
1531 if( p_input->p->input.p_access )
1532 i_ret = access_Control( p_input->p->input.p_access,
1533 ACCESS_SET_PAUSE_STATE, true );
1535 i_ret = demux_Control( p_input->p->input.p_demux,
1536 DEMUX_SET_PAUSE_STATE, true );
1540 msg_Warn( p_input, "cannot set pause state" );
1541 i_state = p_input->i_state;
1548 i_ret = es_out_SetPauseState( p_input->p->p_es_out, p_input->p->b_can_pause, true, i_control_date );
1551 msg_Warn( p_input, "cannot set pause state at es_out level" );
1552 i_state = p_input->i_state;
1556 /* Switch to new state */
1557 input_ChangeState( p_input, i_state );
1561 static void ControlUnpause( input_thread_t *p_input, mtime_t i_control_date )
1563 int i_ret = VLC_SUCCESS;
1565 if( p_input->p->b_can_pause )
1567 if( p_input->p->input.p_access )
1568 i_ret = access_Control( p_input->p->input.p_access,
1569 ACCESS_SET_PAUSE_STATE, false );
1571 i_ret = demux_Control( p_input->p->input.p_demux,
1572 DEMUX_SET_PAUSE_STATE, false );
1575 /* FIXME What to do ? */
1576 msg_Warn( p_input, "cannot unset pause -> EOF" );
1577 vlc_mutex_unlock( &p_input->p->lock_control );
1578 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1579 vlc_mutex_lock( &p_input->p->lock_control );
1583 /* Switch to play */
1584 input_ChangeState( p_input, PLAYING_S );
1588 es_out_SetPauseState( p_input->p->p_es_out, false, false, i_control_date );
1591 static bool Control( input_thread_t *p_input, int i_type,
1594 const mtime_t i_control_date = mdate();
1595 /* FIXME b_force_update is abused, it should be carefully checked */
1596 bool b_force_update = false;
1599 return b_force_update;
1603 case INPUT_CONTROL_SET_DIE:
1604 msg_Dbg( p_input, "control: stopping input" );
1606 /* Mark all submodules to die */
1607 ObjectKillChildrens( p_input, VLC_OBJECT(p_input) );
1610 case INPUT_CONTROL_SET_POSITION:
1611 case INPUT_CONTROL_SET_POSITION_OFFSET:
1615 if( p_input->p->b_recording )
1617 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) ignored while recording" );
1620 f_pos = val.f_float;
1621 if( i_type != INPUT_CONTROL_SET_POSITION )
1622 f_pos += var_GetFloat( p_input, "position" );
1625 else if( f_pos > 1.0 )
1627 /* Reset the decoders states and clock sync (before calling the demuxer */
1628 es_out_SetTime( p_input->p->p_es_out, -1 );
1629 if( demux_Control( p_input->p->input.p_demux, DEMUX_SET_POSITION,
1632 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1633 "%2.1f%% failed", f_pos * 100 );
1637 if( p_input->p->i_slave > 0 )
1638 SlaveSeek( p_input );
1639 p_input->p->input.b_eof = false;
1641 b_force_update = true;
1646 case INPUT_CONTROL_SET_TIME:
1647 case INPUT_CONTROL_SET_TIME_OFFSET:
1652 if( p_input->p->b_recording )
1654 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) ignored while recording" );
1658 i_time = val.i_time;
1659 if( i_type != INPUT_CONTROL_SET_TIME )
1660 i_time += var_GetTime( p_input, "time" );
1665 /* Reset the decoders states and clock sync (before calling the demuxer */
1666 es_out_SetTime( p_input->p->p_es_out, -1 );
1668 i_ret = demux_Control( p_input->p->input.p_demux,
1669 DEMUX_SET_TIME, i_time );
1674 /* Emulate it with a SET_POS */
1675 demux_Control( p_input->p->input.p_demux,
1676 DEMUX_GET_LENGTH, &i_length );
1679 double f_pos = (double)i_time / (double)i_length;
1680 i_ret = demux_Control( p_input->p->input.p_demux,
1681 DEMUX_SET_POSITION, f_pos );
1686 msg_Warn( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) %"PRId64
1687 " failed or not possible", i_time );
1691 if( p_input->p->i_slave > 0 )
1692 SlaveSeek( p_input );
1693 p_input->p->input.b_eof = false;
1695 b_force_update = true;
1700 case INPUT_CONTROL_SET_STATE:
1701 if( ( val.i_int == PLAYING_S && p_input->i_state == PAUSE_S ) ||
1702 ( val.i_int == PAUSE_S && p_input->i_state == PAUSE_S ) )
1704 ControlUnpause( p_input, i_control_date );
1706 b_force_update = true;
1708 else if( val.i_int == PAUSE_S && p_input->i_state == PLAYING_S /* &&
1709 p_input->p->b_can_pause */ )
1711 ControlPause( p_input, i_control_date );
1713 b_force_update = true;
1715 else if( val.i_int == PAUSE_S && !p_input->p->b_can_pause && 0 )
1717 b_force_update = true;
1719 /* Correct "state" value */
1720 input_ChangeState( p_input, p_input->i_state );
1722 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1724 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1728 case INPUT_CONTROL_SET_RATE:
1729 case INPUT_CONTROL_SET_RATE_SLOWER:
1730 case INPUT_CONTROL_SET_RATE_FASTER:
1735 /* Get rate and direction */
1736 if( i_type == INPUT_CONTROL_SET_RATE )
1738 i_rate = abs( val.i_int );
1739 i_rate_sign = val.i_int < 0 ? -1 : 1;
1743 static const int ppi_factor[][2] = {
1744 {1,64}, {1,32}, {1,16}, {1,8}, {1,4}, {1,3}, {1,2}, {2,3},
1746 {3,2}, {2,1}, {3,1}, {4,1}, {8,1}, {16,1}, {32,1}, {64,1},
1753 i_rate_sign = p_input->p->i_rate < 0 ? -1 : 1;
1757 for( i = 0; ppi_factor[i][0] != 0; i++ )
1759 const int i_test_r = INPUT_RATE_DEFAULT * ppi_factor[i][0] / ppi_factor[i][1];
1760 const int i_test_e = abs( abs( p_input->p->i_rate ) - i_test_r );
1761 if( i_test_e < i_error )
1768 assert( i_idx >= 0 && ppi_factor[i_idx][0] != 0 );
1770 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1772 if( ppi_factor[i_idx+1][0] > 0 )
1773 i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx+1][0] / ppi_factor[i_idx+1][1];
1775 i_rate = INPUT_RATE_MAX+1;
1779 assert( i_type == INPUT_CONTROL_SET_RATE_FASTER );
1781 i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx-1][0] / ppi_factor[i_idx-1][1];
1783 i_rate = INPUT_RATE_MIN-1;
1787 /* Check rate bound */
1788 if( i_rate < INPUT_RATE_MIN )
1790 msg_Dbg( p_input, "cannot set rate faster" );
1791 i_rate = INPUT_RATE_MIN;
1793 else if( i_rate > INPUT_RATE_MAX )
1795 msg_Dbg( p_input, "cannot set rate slower" );
1796 i_rate = INPUT_RATE_MAX;
1799 /* Apply direction */
1800 if( i_rate_sign < 0 )
1802 if( p_input->p->input.b_rescale_ts )
1804 msg_Dbg( p_input, "cannot set negative rate" );
1805 i_rate = p_input->p->i_rate;
1806 assert( i_rate > 0 );
1810 i_rate *= i_rate_sign;
1814 if( i_rate != INPUT_RATE_DEFAULT &&
1815 ( ( !p_input->p->b_can_rate_control && !p_input->p->input.b_rescale_ts ) ||
1816 ( p_input->p->p_sout && !p_input->p->b_out_pace_control ) ) )
1818 msg_Dbg( p_input, "cannot change rate" );
1819 i_rate = INPUT_RATE_DEFAULT;
1821 if( i_rate != p_input->p->i_rate &&
1822 !p_input->b_can_pace_control && p_input->p->b_can_rate_control )
1825 if( p_input->p->input.p_access )
1827 i_ret = VLC_EGENERIC;
1831 if( !p_input->p->input.b_rescale_ts )
1832 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1834 i_ret = demux_Control( p_input->p->input.p_demux,
1835 DEMUX_SET_RATE, &i_rate );
1839 msg_Warn( p_input, "ACCESS/DEMUX_SET_RATE failed" );
1840 i_rate = p_input->p->i_rate;
1845 if( i_rate != p_input->p->i_rate )
1847 p_input->p->i_rate = i_rate;
1848 input_SendEventRate( p_input, i_rate );
1850 if( p_input->p->input.b_rescale_ts )
1852 const int i_rate_source = (p_input->b_can_pace_control || p_input->p->b_can_rate_control ) ? i_rate : INPUT_RATE_DEFAULT;
1853 es_out_SetRate( p_input->p->p_es_out, i_rate_source, i_rate );
1856 b_force_update = true;
1861 case INPUT_CONTROL_SET_PROGRAM:
1862 /* No need to force update, es_out does it if needed */
1863 es_out_Control( p_input->p->p_es_out,
1864 ES_OUT_SET_GROUP, val.i_int );
1866 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1870 case INPUT_CONTROL_SET_ES:
1871 /* No need to force update, es_out does it if needed */
1872 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, val.i_int );
1875 case INPUT_CONTROL_RESTART_ES:
1876 es_out_Control( p_input->p->p_es_out_display, ES_OUT_RESTART_ES_BY_ID, val.i_int );
1879 case INPUT_CONTROL_SET_AUDIO_DELAY:
1880 if( !es_out_SetDelay( p_input->p->p_es_out_display, AUDIO_ES, val.i_time ) )
1881 input_SendEventAudioDelay( p_input, val.i_time );
1884 case INPUT_CONTROL_SET_SPU_DELAY:
1885 if( !es_out_SetDelay( p_input->p->p_es_out_display, SPU_ES, val.i_time ) )
1886 input_SendEventSubtitleDelay( p_input, val.i_time );
1889 case INPUT_CONTROL_SET_TITLE:
1890 case INPUT_CONTROL_SET_TITLE_NEXT:
1891 case INPUT_CONTROL_SET_TITLE_PREV:
1892 if( p_input->p->b_recording )
1894 msg_Err( p_input, "INPUT_CONTROL_SET_TITLE(*) ignored while recording" );
1897 if( p_input->p->input.b_title_demux &&
1898 p_input->p->input.i_title > 0 )
1901 /* FIXME handle demux title */
1902 demux_t *p_demux = p_input->p->input.p_demux;
1905 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1906 i_title = p_demux->info.i_title - 1;
1907 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1908 i_title = p_demux->info.i_title + 1;
1910 i_title = val.i_int;
1912 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1914 es_out_SetTime( p_input->p->p_es_out, -1 );
1916 demux_Control( p_demux, DEMUX_SET_TITLE, i_title );
1917 input_ControlVarTitle( p_input, i_title );
1920 else if( p_input->p->input.i_title > 0 )
1922 access_t *p_access = p_input->p->input.p_access;
1925 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1926 i_title = p_access->info.i_title - 1;
1927 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1928 i_title = p_access->info.i_title + 1;
1930 i_title = val.i_int;
1932 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1934 es_out_SetTime( p_input->p->p_es_out, -1 );
1936 access_Control( p_access, ACCESS_SET_TITLE, i_title );
1937 stream_AccessReset( p_input->p->input.p_stream );
1941 case INPUT_CONTROL_SET_SEEKPOINT:
1942 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1943 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1944 if( p_input->p->b_recording )
1946 msg_Err( p_input, "INPUT_CONTROL_SET_SEEKPOINT(*) ignored while recording" );
1950 if( p_input->p->input.b_title_demux &&
1951 p_input->p->input.i_title > 0 )
1953 demux_t *p_demux = p_input->p->input.p_demux;
1955 int64_t i_input_time;
1956 int64_t i_seekpoint_time;
1958 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1960 i_seekpoint = p_demux->info.i_seekpoint;
1961 i_seekpoint_time = p_input->p->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1962 i_input_time = var_GetTime( p_input, "time" );
1963 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
1965 if( i_input_time < i_seekpoint_time + 3000000 )
1971 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1972 i_seekpoint = p_demux->info.i_seekpoint + 1;
1974 i_seekpoint = val.i_int;
1976 if( i_seekpoint >= 0 && i_seekpoint <
1977 p_input->p->input.title[p_demux->info.i_title]->i_seekpoint )
1980 es_out_SetTime( p_input->p->p_es_out, -1 );
1982 demux_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1985 else if( p_input->p->input.i_title > 0 )
1987 access_t *p_access = p_input->p->input.p_access;
1989 int64_t i_input_time;
1990 int64_t i_seekpoint_time;
1992 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1994 i_seekpoint = p_access->info.i_seekpoint;
1995 i_seekpoint_time = p_input->p->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1996 i_input_time = var_GetTime( p_input, "time" );
1997 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
1999 if( i_input_time < i_seekpoint_time + 3000000 )
2005 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
2006 i_seekpoint = p_access->info.i_seekpoint + 1;
2008 i_seekpoint = val.i_int;
2010 if( i_seekpoint >= 0 && i_seekpoint <
2011 p_input->p->input.title[p_access->info.i_title]->i_seekpoint )
2013 es_out_SetTime( p_input->p->p_es_out, -1 );
2015 access_Control( p_access, ACCESS_SET_SEEKPOINT,
2017 stream_AccessReset( p_input->p->input.p_stream );
2022 case INPUT_CONTROL_ADD_SUBTITLE:
2023 if( val.psz_string )
2025 SubtitleAdd( p_input, val.psz_string, true );
2026 free( val.psz_string );
2030 case INPUT_CONTROL_ADD_SLAVE:
2031 if( val.psz_string )
2033 input_source_t *slave = InputSourceNew( p_input );
2035 if( !InputSourceInit( p_input, slave, val.psz_string, NULL ) )
2041 msg_Dbg( p_input, "adding %s as slave on the fly",
2045 if( demux_Control( p_input->p->input.p_demux,
2046 DEMUX_GET_TIME, &i_time ) )
2048 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2049 InputSourceClean( slave );
2053 if( demux_Control( slave->p_demux,
2054 DEMUX_SET_TIME, i_time ) )
2056 msg_Err( p_input, "seek failed for new slave" );
2057 InputSourceClean( slave );
2062 /* Get meta (access and demux) */
2063 p_meta = vlc_meta_New();
2066 access_Control( slave->p_access, ACCESS_GET_META, p_meta );
2067 demux_Control( slave->p_demux, DEMUX_GET_META, p_meta );
2068 InputUpdateMeta( p_input, p_meta );
2071 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, slave );
2076 msg_Warn( p_input, "failed to add %s as slave",
2080 free( val.psz_string );
2084 case INPUT_CONTROL_SET_RECORD_STATE:
2085 if( !!p_input->p->b_recording != !!val.b_bool )
2087 if( p_input->p->input.b_can_stream_record )
2089 if( demux_Control( p_input->p->input.p_demux,
2090 DEMUX_SET_RECORD_STATE, val.b_bool ) )
2095 if( es_out_SetRecordState( p_input->p->p_es_out_display, val.b_bool ) )
2098 p_input->p->b_recording = val.b_bool;
2100 input_SendEventRecord( p_input, val.b_bool );
2102 b_force_update = true;
2106 case INPUT_CONTROL_SET_FRAME_NEXT:
2107 if( p_input->i_state == PAUSE_S )
2109 es_out_SetFrameNext( p_input->p->p_es_out );
2111 else if( p_input->i_state == PLAYING_S )
2113 ControlPause( p_input, i_control_date );
2117 msg_Err( p_input, "invalid state for frame next" );
2119 b_force_update = true;
2122 case INPUT_CONTROL_SET_BOOKMARK:
2124 seekpoint_t bookmark;
2126 bookmark.i_time_offset = -1;
2127 bookmark.i_byte_offset = -1;
2129 vlc_mutex_lock( &p_input->p->p_item->lock );
2130 if( val.i_int >= 0 && val.i_int < p_input->p->i_bookmark )
2132 const seekpoint_t *p_bookmark = p_input->p->pp_bookmark[val.i_int];
2133 bookmark.i_time_offset = p_bookmark->i_time_offset;
2134 bookmark.i_byte_offset = p_bookmark->i_byte_offset;
2136 vlc_mutex_unlock( &p_input->p->p_item->lock );
2138 if( bookmark.i_time_offset < 0 && bookmark.i_byte_offset < 0 )
2140 msg_Err( p_input, "invalid bookmark %d", val.i_int );
2144 if( bookmark.i_time_offset >= 0 )
2146 val.i_time = bookmark.i_time_offset;
2147 b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME, val );
2149 else if( bookmark.i_byte_offset >= 0 &&
2150 p_input->p->input.p_stream )
2152 const int64_t i_size = stream_Size( p_input->p->input.p_stream );
2153 if( i_size > 0 && bookmark.i_byte_offset <= i_size )
2155 val.f_float = (double)bookmark.i_byte_offset / i_size;
2156 b_force_update = Control( p_input, INPUT_CONTROL_SET_POSITION, val );
2163 msg_Err( p_input, "not yet implemented" );
2167 return b_force_update;
2170 /*****************************************************************************
2171 * UpdateTitleSeekpoint
2172 *****************************************************************************/
2173 static int UpdateTitleSeekpoint( input_thread_t *p_input,
2174 int i_title, int i_seekpoint )
2176 int i_title_end = p_input->p->input.i_title_end -
2177 p_input->p->input.i_title_offset;
2178 int i_seekpoint_end = p_input->p->input.i_seekpoint_end -
2179 p_input->p->input.i_seekpoint_offset;
2181 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
2183 if( i_title > i_title_end ||
2184 ( i_title == i_title_end && i_seekpoint > i_seekpoint_end ) )
2187 else if( i_seekpoint_end >= 0 )
2189 if( i_seekpoint > i_seekpoint_end )
2192 else if( i_title_end >= 0 )
2194 if( i_title > i_title_end )
2199 /*****************************************************************************
2201 *****************************************************************************/
2202 static int UpdateTitleSeekpointFromDemux( input_thread_t *p_input )
2204 demux_t *p_demux = p_input->p->input.p_demux;
2206 /* TODO event-like */
2207 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
2209 input_SendEventTitle( p_input, p_demux->info.i_title );
2211 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
2213 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
2215 input_SendEventSeekpoint( p_input,
2216 p_demux->info.i_title, p_demux->info.i_seekpoint );
2218 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2221 /* Hmmm only works with master input */
2222 if( p_input->p->input.p_demux == p_demux )
2223 return UpdateTitleSeekpoint( p_input,
2224 p_demux->info.i_title,
2225 p_demux->info.i_seekpoint );
2229 static void UpdateGenericFromDemux( input_thread_t *p_input )
2231 demux_t *p_demux = p_input->p->input.p_demux;
2233 if( p_demux->info.i_update & INPUT_UPDATE_META )
2235 vlc_meta_t *p_meta = vlc_meta_New();
2238 demux_Control( p_input->p->input.p_demux, DEMUX_GET_META, p_meta );
2239 InputUpdateMeta( p_input, p_meta );
2241 p_demux->info.i_update &= ~INPUT_UPDATE_META;
2244 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
2248 /*****************************************************************************
2249 * Update*FromAccess:
2250 *****************************************************************************/
2251 static int UpdateTitleSeekpointFromAccess( input_thread_t *p_input )
2253 access_t *p_access = p_input->p->input.p_access;
2255 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
2257 input_SendEventTitle( p_input, p_access->info.i_title );
2259 stream_AccessUpdate( p_input->p->input.p_stream );
2261 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
2263 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
2265 input_SendEventSeekpoint( p_input,
2266 p_access->info.i_title, p_access->info.i_seekpoint );
2268 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2270 /* Hmmm only works with master input */
2271 if( p_input->p->input.p_access == p_access )
2272 return UpdateTitleSeekpoint( p_input,
2273 p_access->info.i_title,
2274 p_access->info.i_seekpoint );
2277 static void UpdateGenericFromAccess( input_thread_t *p_input )
2279 access_t *p_access = p_input->p->input.p_access;
2281 if( p_access->info.i_update & INPUT_UPDATE_META )
2283 /* TODO maybe multi - access ? */
2284 vlc_meta_t *p_meta = vlc_meta_New();
2287 access_Control( p_input->p->input.p_access, ACCESS_GET_META, p_meta );
2288 InputUpdateMeta( p_input, p_meta );
2290 p_access->info.i_update &= ~INPUT_UPDATE_META;
2292 if( p_access->info.i_update & INPUT_UPDATE_SIGNAL )
2297 if( access_Control( p_access, ACCESS_GET_SIGNAL, &f_quality, &f_strength ) )
2298 f_quality = f_strength = -1;
2300 input_SendEventSignal( p_input, f_quality, f_strength );
2302 p_access->info.i_update &= ~INPUT_UPDATE_SIGNAL;
2305 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
2308 /*****************************************************************************
2310 *****************************************************************************/
2311 static input_source_t *InputSourceNew( input_thread_t *p_input )
2313 VLC_UNUSED(p_input);
2315 return calloc( 1, sizeof( input_source_t ) );
2318 /*****************************************************************************
2320 *****************************************************************************/
2321 static int InputSourceInit( input_thread_t *p_input,
2322 input_source_t *in, const char *psz_mrl,
2323 const char *psz_forced_demux )
2325 const bool b_master = in == &p_input->p->input;
2327 char psz_dup[strlen(psz_mrl) + 1];
2328 const char *psz_access;
2329 const char *psz_demux;
2336 strcpy( psz_dup, psz_mrl );
2338 if( !in ) return VLC_EGENERIC;
2339 if( !p_input ) return VLC_EGENERIC;
2342 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_dup );
2344 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
2345 psz_mrl, psz_access, psz_demux, psz_path );
2346 if( !p_input->b_preparsing )
2348 /* Hack to allow udp://@:port syntax */
2350 (strncmp( psz_access, "udp", 3 ) &&
2351 strncmp( psz_access, "rtp", 3 )) )
2353 /* Find optional titles and seekpoints */
2354 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
2355 &in->i_seekpoint_start, &in->i_seekpoint_end );
2358 if( psz_forced_demux && *psz_forced_demux )
2360 psz_demux = psz_forced_demux;
2362 else if( *psz_demux == '\0' )
2364 /* special hack for forcing a demuxer with --demux=module
2365 * (and do nothing with a list) */
2366 char *psz_var_demux = var_GetNonEmptyString( p_input, "demux" );
2368 if( psz_var_demux != NULL &&
2369 !strchr(psz_var_demux, ',' ) &&
2370 !strchr(psz_var_demux, ':' ) )
2372 psz_demux = psz_var_demux;
2374 msg_Dbg( p_input, "enforced demux ` %s'", psz_demux );
2378 /* Try access_demux first */
2379 in->p_demux = demux_New( p_input, psz_access, psz_demux, psz_path,
2380 NULL, p_input->p->p_es_out, false );
2384 /* Preparsing is only for file:// */
2387 if( !*psz_access ) /* path without scheme:// */
2388 psz_access = "file";
2389 if( strcmp( psz_access, "file" ) )
2391 msg_Dbg( p_input, "trying to pre-parse %s", psz_path );
2396 int64_t i_pts_delay;
2398 /* Get infos from access_demux */
2399 demux_Control( in->p_demux,
2400 DEMUX_GET_PTS_DELAY, &i_pts_delay );
2401 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2403 in->b_title_demux = true;
2404 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2405 &in->title, &in->i_title,
2406 &in->i_title_offset, &in->i_seekpoint_offset ) )
2408 TAB_INIT( in->i_title, in->title );
2410 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
2411 &in->b_can_pace_control ) )
2412 in->b_can_pace_control = false;
2414 if( !in->b_can_pace_control )
2416 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_RATE,
2417 &in->b_can_rate_control, &in->b_rescale_ts ) )
2419 in->b_can_rate_control = false;
2420 in->b_rescale_ts = true; /* not used */
2425 in->b_can_rate_control = true;
2426 in->b_rescale_ts = true;
2428 if( demux_Control( in->p_demux, DEMUX_CAN_PAUSE,
2429 &in->b_can_pause ) )
2430 in->b_can_pause = false;
2431 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2432 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2433 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control );
2435 int ret = demux_Control( in->p_demux, DEMUX_CAN_SEEK,
2437 if( ret != VLC_SUCCESS )
2439 var_Set( p_input, "can-seek", val );
2443 int64_t i_pts_delay;
2445 /* Now try a real access */
2446 in->p_access = access_New( p_input, psz_access, psz_demux, psz_path );
2448 /* Access failed, URL encoded ? */
2449 if( in->p_access == NULL && strchr( psz_path, '%' ) )
2451 decode_URI( psz_path );
2453 msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
2454 psz_access, psz_demux, psz_path );
2456 in->p_access = access_New( p_input,
2457 psz_access, psz_demux, psz_path );
2459 if( in->p_access == NULL )
2461 msg_Err( p_input, "open of `%s' failed: %s", psz_mrl,
2463 intf_UserFatal( VLC_OBJECT( p_input), false,
2464 _("Your input can't be opened"),
2465 _("VLC is unable to open the MRL '%s'."
2466 " Check the log for details."), psz_mrl );
2471 psz_tmp = psz = var_GetNonEmptyString( p_input, "access-filter" );
2472 while( psz && *psz )
2474 access_t *p_access = in->p_access;
2475 char *end = strchr( psz, ':' );
2480 in->p_access = access_FilterNew( in->p_access, psz );
2481 if( in->p_access == NULL )
2483 in->p_access = p_access;
2484 msg_Warn( p_input, "failed to insert access filter %s",
2492 /* Get infos from access */
2493 if( !p_input->b_preparsing )
2495 access_Control( in->p_access,
2496 ACCESS_GET_PTS_DELAY, &i_pts_delay );
2497 p_input->i_pts_delay = __MAX( p_input->i_pts_delay, i_pts_delay );
2499 in->b_title_demux = false;
2500 if( access_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2501 &in->title, &in->i_title,
2502 &in->i_title_offset, &in->i_seekpoint_offset ) )
2505 TAB_INIT( in->i_title, in->title );
2507 access_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2508 &in->b_can_pace_control );
2509 in->b_can_rate_control = in->b_can_pace_control;
2510 in->b_rescale_ts = true;
2512 access_Control( in->p_access, ACCESS_CAN_PAUSE,
2514 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2515 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2516 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control );
2518 access_Control( in->p_access, ACCESS_CAN_SEEK,
2520 var_Set( p_input, "can-seek", val );
2523 /* Autodetect extra files if none specified */
2524 char *psz_input_list = var_CreateGetNonEmptyString( p_input, "input-list" );
2525 if( !psz_input_list )
2527 char *psz_extra_files = InputGetExtraFiles( p_input, psz_access, psz_path );
2528 if( psz_extra_files )
2529 var_SetString( p_input, "input-list", psz_extra_files );
2530 free( psz_extra_files );
2533 /* Create the stream_t */
2534 in->p_stream = stream_AccessNew( in->p_access, p_input->b_preparsing );
2536 /* Restor old value */
2537 if( !psz_input_list )
2538 var_SetString( p_input, "input-list", "" );
2539 free( psz_input_list );
2541 if( in->p_stream == NULL )
2543 msg_Warn( p_input, "cannot create a stream_t from access" );
2547 /* Open a demuxer */
2548 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2550 psz_demux = in->p_access->psz_demux;
2554 /* Take access redirections into account */
2555 char *psz_real_path;
2556 char *psz_buf = NULL;
2557 if( in->p_access->psz_path )
2559 const char *psz_a, *psz_d;
2560 psz_buf = strdup( in->p_access->psz_path );
2561 input_SplitMRL( &psz_a, &psz_d, &psz_real_path, psz_buf );
2565 psz_real_path = psz_path;
2567 in->p_demux = demux_New( p_input, psz_access, psz_demux,
2569 in->p_stream, p_input->p->p_es_out,
2570 p_input->b_preparsing );
2574 if( in->p_demux == NULL )
2576 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2577 psz_access, psz_demux, psz_path );
2578 intf_UserFatal( VLC_OBJECT( p_input ), false,
2579 _("VLC can't recognize the input's format"),
2580 _("The format of '%s' cannot be detected. "
2581 "Have a look at the log for details."), psz_mrl );
2585 /* Get title from demux */
2586 if( !p_input->b_preparsing && in->i_title <= 0 )
2588 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2589 &in->title, &in->i_title,
2590 &in->i_title_offset, &in->i_seekpoint_offset ))
2592 TAB_INIT( in->i_title, in->title );
2596 in->b_title_demux = true;
2601 /* Set record capabilities */
2602 if( demux_Control( in->p_demux, DEMUX_CAN_RECORD, &in->b_can_stream_record ) )
2603 in->b_can_stream_record = false;
2605 if( !var_CreateGetBool( p_input, "input-record-native" ) )
2606 in->b_can_stream_record = false;
2607 var_SetBool( p_input, "can-record", true );
2609 var_SetBool( p_input, "can-record", in->b_can_stream_record );
2613 * FIXME improve for b_preparsing: move it after GET_META and check psz_arturl */
2614 if( 1 || !p_input->b_preparsing )
2617 input_attachment_t **attachment;
2618 if( !demux_Control( in->p_demux, DEMUX_GET_ATTACHMENTS,
2619 &attachment, &i_attachment ) )
2621 vlc_mutex_lock( &p_input->p->p_item->lock );
2622 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2623 i_attachment, attachment );
2624 vlc_mutex_unlock( &p_input->p->p_item->lock );
2627 if( !demux_Control( in->p_demux, DEMUX_GET_FPS, &f_fps ) && f_fps > 0.0 )
2629 vlc_mutex_lock( &p_input->p->p_item->lock );
2630 p_input->p->f_fps = f_fps;
2631 vlc_mutex_unlock( &p_input->p->p_item->lock );
2634 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2635 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2641 input_ChangeState( p_input, ERROR_S );
2644 demux_Delete( in->p_demux );
2647 stream_Delete( in->p_stream );
2650 access_Delete( in->p_access );
2652 return VLC_EGENERIC;
2655 /*****************************************************************************
2657 *****************************************************************************/
2658 static void InputSourceClean( input_source_t *in )
2663 demux_Delete( in->p_demux );
2666 stream_Delete( in->p_stream );
2669 access_Delete( in->p_access );
2671 if( in->i_title > 0 )
2673 for( i = 0; i < in->i_title; i++ )
2674 vlc_input_title_Delete( in->title[i] );
2675 TAB_CLEAN( in->i_title, in->title );
2679 /*****************************************************************************
2681 *****************************************************************************/
2682 static void InputSourceMeta( input_thread_t *p_input,
2683 input_source_t *p_source, vlc_meta_t *p_meta )
2685 access_t *p_access = p_source->p_access;
2686 demux_t *p_demux = p_source->p_demux;
2688 /* XXX Remember that checking against p_item->p_meta->i_status & ITEM_PREPARSED
2691 /* Read access meta */
2693 access_Control( p_access, ACCESS_GET_META, p_meta );
2695 /* Read demux meta */
2696 demux_Control( p_demux, DEMUX_GET_META, p_meta );
2698 /* If the demux report unsupported meta data, try an external "meta reader" */
2700 if( demux_Control( p_demux, DEMUX_HAS_UNSUPPORTED_META, &b_bool ) )
2705 demux_meta_t *p_demux_meta = p_demux->p_private = calloc( 1, sizeof(*p_demux_meta) );
2709 module_t *p_id3 = module_need( p_demux, "meta reader", NULL, 0 );
2712 if( p_demux_meta->p_meta )
2714 vlc_meta_Merge( p_meta, p_demux_meta->p_meta );
2715 vlc_meta_Delete( p_demux_meta->p_meta );
2718 if( p_demux_meta->i_attachments > 0 )
2720 vlc_mutex_lock( &p_input->p->p_item->lock );
2721 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2722 p_demux_meta->i_attachments, p_demux_meta->attachments );
2723 vlc_mutex_unlock( &p_input->p->p_item->lock );
2725 module_unneed( p_demux, p_id3 );
2727 free( p_demux_meta );
2731 static void SlaveDemux( input_thread_t *p_input )
2735 bool b_set_time = true;
2737 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2739 /* msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" ); */
2743 for( i = 0; i < p_input->p->i_slave; i++ )
2745 input_source_t *in = p_input->p->slave[i];
2751 if( b_set_time && demux_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2756 if( demux_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2758 msg_Err( p_input, "slave[%d] doesn't like "
2759 "DEMUX_GET_TIME -> EOF", i );
2764 if( i_stime >= i_time )
2767 if( ( i_ret = demux_Demux( in->p_demux ) ) <= 0 )
2773 i_ret = demux_Demux( in->p_demux );
2778 msg_Dbg( p_input, "slave %d EOF", i );
2784 static void SlaveSeek( input_thread_t *p_input )
2789 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2791 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2795 for( i = 0; i < p_input->p->i_slave; i++ )
2797 input_source_t *in = p_input->p->slave[i];
2799 if( demux_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
2802 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2812 /*****************************************************************************
2814 *****************************************************************************/
2815 static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta )
2819 /* Get meta information from user */
2820 #define GET_META( field, s ) do { \
2821 var_Get( p_input, (s), &val ); \
2822 if( val.psz_string && *val.psz_string ) \
2823 vlc_meta_Set( p_meta, vlc_meta_ ## field, val.psz_string ); \
2824 free( val.psz_string ); } while(0)
2826 GET_META( Title, "meta-title" );
2827 GET_META( Artist, "meta-artist" );
2828 GET_META( Genre, "meta-genre" );
2829 GET_META( Copyright, "meta-copyright" );
2830 GET_META( Description, "meta-description" );
2831 GET_META( Date, "meta-date" );
2832 GET_META( URL, "meta-url" );
2836 /*****************************************************************************
2837 * InputUpdateMeta: merge p_item meta data with p_meta taking care of
2838 * arturl and locking issue.
2839 *****************************************************************************/
2840 static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta )
2842 input_item_t *p_item = p_input->p->p_item;
2844 char *psz_title = NULL;
2845 char *psz_arturl = input_item_GetArtURL( p_item );
2847 vlc_mutex_lock( &p_item->lock );
2849 if( vlc_meta_Get( p_meta, vlc_meta_Title ) && !p_item->b_fixed_name )
2850 psz_title = strdup( vlc_meta_Get( p_meta, vlc_meta_Title ) );
2852 vlc_meta_Merge( p_item->p_meta, p_meta );
2854 vlc_meta_Delete( p_meta );
2856 if( psz_arturl && *psz_arturl )
2858 vlc_meta_Set( p_item->p_meta, vlc_meta_ArtworkURL, psz_arturl );
2860 if( !strncmp( psz_arturl, "attachment://", strlen("attachment") ) )
2862 /* Don't look for art cover if sout
2863 * XXX It can change when sout has meta data support */
2864 if( p_input->p->p_sout && !p_input->b_preparsing )
2865 vlc_meta_Set( p_item->p_meta, vlc_meta_ArtworkURL, "" );
2867 input_ExtractAttachmentAndCacheArt( p_input );
2872 vlc_mutex_unlock( &p_item->lock );
2876 input_item_SetName( p_item, psz_title );
2879 input_item_SetPreparsed( p_item, true );
2881 input_SendEventMeta( p_input );
2883 /** \todo handle sout meta */
2886 static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
2887 int i_new, input_attachment_t **pp_new )
2889 int i_attachment = *pi_attachment;
2890 input_attachment_t **attachment = *ppp_attachment;
2893 attachment = realloc( attachment,
2894 sizeof(input_attachment_t**) * ( i_attachment + i_new ) );
2895 for( i = 0; i < i_new; i++ )
2896 attachment[i_attachment++] = pp_new[i];
2900 *pi_attachment = i_attachment;
2901 *ppp_attachment = attachment;
2903 /*****************************************************************************
2904 * InputGetExtraFiles
2905 * Autodetect extra input list
2906 *****************************************************************************/
2907 static char *InputGetExtraFiles( input_thread_t *p_input,
2908 const char *psz_access, const char *psz_path )
2910 char *psz_list = NULL;
2912 if( ( psz_access && *psz_access && strcmp( psz_access, "file" ) ) || !psz_path )
2916 const char *psz_ext = strrchr( psz_path, '.' );
2917 if( !psz_ext || strcmp( psz_ext, ".001" ) )
2920 char *psz_file = strdup( psz_path );
2924 /* Try to list .xyz files */
2925 for( int i = 2; i < 999; i++ )
2927 char *psz_ext = strrchr( psz_file, '.' );
2930 snprintf( psz_ext, 5, ".%.3d", i );
2932 if( utf8_stat( psz_file, &st )
2933 || !S_ISREG( st.st_mode ) || !st.st_size )
2936 msg_Dbg( p_input, "Detected extra file `%s'", psz_file );
2940 char *psz_old = psz_list;
2941 /* FIXME how to handle file with ',' ?*/
2942 if( asprintf( &psz_list, "%s,%s", psz_old, psz_file ) < 0 )
2950 psz_list = strdup( psz_file );
2960 static void input_ChangeState( input_thread_t *p_input, int i_state )
2962 const bool b_changed = p_input->i_state != i_state;
2964 p_input->i_state = i_state;
2965 if( i_state == ERROR_S )
2966 p_input->b_error = true;
2967 else if( i_state == END_S )
2968 p_input->b_eof = true;
2972 input_item_SetErrorWhenReading( p_input->p->p_item, p_input->b_error );
2973 input_SendEventState( p_input, i_state );
2978 /*****************************************************************************
2979 * MRLSplit: parse the access, demux and url part of the
2980 * Media Resource Locator.
2981 *****************************************************************************/
2982 void input_SplitMRL( const char **ppsz_access, const char **ppsz_demux, char **ppsz_path,
2985 char *psz_access = NULL;
2986 char *psz_demux = NULL;
2989 /* Either there is an access/demux specification before ://
2990 * or we have a plain local file path. */
2991 psz_path = strstr( psz_dup, "://" );
2992 if( psz_path != NULL )
2995 psz_path += 3; /* skips "://" */
2997 /* Separate access from demux (<access>/<demux>://<path>) */
2998 psz_access = psz_dup;
2999 psz_demux = strchr( psz_access, '/' );
3001 *psz_demux++ = '\0';
3003 /* We really don't want module name substitution here! */
3004 if( psz_access[0] == '$' )
3006 if( psz_demux && psz_demux[0] == '$' )
3013 *ppsz_access = psz_access ? psz_access : (char*)"";
3014 *ppsz_demux = psz_demux ? psz_demux : (char*)"";
3015 *ppsz_path = psz_path;
3018 static inline bool next(char ** src)
3022 long result = strtol( *src, &end, 0 );
3023 if( errno != 0 || result >= LONG_MAX || result <= LONG_MIN ||
3032 /*****************************************************************************
3033 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
3036 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
3037 *****************************************************************************/
3038 static void MRLSections( input_thread_t *p_input, char *psz_source,
3039 int *pi_title_start, int *pi_title_end,
3040 int *pi_chapter_start, int *pi_chapter_end )
3042 char *psz, *psz_end, *psz_next, *psz_check;
3044 *pi_title_start = *pi_title_end = -1;
3045 *pi_chapter_start = *pi_chapter_end = -1;
3047 /* Start by parsing titles and chapters */
3048 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
3051 /* Check we are really dealing with a title/chapter section */
3052 psz_check = psz + 1;
3053 if( !*psz_check ) return;
3054 if( isdigit(*psz_check) )
3055 if(!next(&psz_check)) return;
3056 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
3057 if( *psz_check == ':' && ++psz_check )
3059 if( isdigit(*psz_check) )
3060 if(!next(&psz_check)) return;
3062 if( *psz_check != '-' && *psz_check ) return;
3063 if( *psz_check == '-' && ++psz_check )
3065 if( isdigit(*psz_check) )
3066 if(!next(&psz_check)) return;
3068 if( *psz_check != ':' && *psz_check ) return;
3069 if( *psz_check == ':' && ++psz_check )
3071 if( isdigit(*psz_check) )
3072 if(!next(&psz_check)) return;
3074 if( *psz_check ) return;
3076 /* Separate start and end */
3078 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
3080 /* Look for the start title */
3081 *pi_title_start = strtol( psz, &psz_next, 0 );
3082 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
3083 *pi_title_end = *pi_title_start;
3086 /* Look for the start chapter */
3088 *pi_chapter_start = strtol( psz, &psz_next, 0 );
3089 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
3090 *pi_chapter_end = *pi_chapter_start;
3094 /* Look for the end title */
3095 *pi_title_end = strtol( psz_end, &psz_next, 0 );
3096 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
3099 /* Look for the end chapter */
3100 if( *psz_end ) psz_end++;
3101 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
3102 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
3105 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
3106 psz_source, *pi_title_start, *pi_chapter_start,
3107 *pi_title_end, *pi_chapter_end );
3110 /*****************************************************************************
3111 * input_AddSubtitles: add a subtitles file and enable it
3112 *****************************************************************************/
3113 static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_forced )
3115 input_source_t *sub;
3118 char *psz_path, *psz_extension;
3120 /* if we are provided a subtitle.sub file,
3121 * see if we don't have a subtitle.idx and use it instead */
3122 psz_path = strdup( psz_subtitle );
3125 psz_extension = strrchr( psz_path, '.');
3126 if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
3130 strcpy( psz_extension, ".idx" );
3132 if( !utf8_stat( psz_path, &st ) && S_ISREG( st.st_mode ) )
3134 msg_Dbg( p_input, "using %s subtitles file instead of %s",
3135 psz_path, psz_subtitle );
3136 strcpy( psz_subtitle, psz_path );
3142 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
3144 sub = InputSourceNew( p_input );
3145 if( InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
3150 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
3153 if( b_forced && !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
3155 if( count.i_int == 0 )
3157 /* if it was first one, there is disable too */
3159 if( count.i_int < list.p_list->i_count )
3161 const int i_id = list.p_list->p_values[count.i_int].i_int;
3163 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_DEFAULT_BY_ID, i_id );
3164 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, i_id );
3166 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
3170 bool input_AddSubtitles( input_thread_t *p_input, char *psz_subtitle,
3171 bool b_check_extension )
3175 if( b_check_extension && !subtitles_Filter( psz_subtitle ) )
3178 assert( psz_subtitle != NULL );
3180 val.psz_string = strdup( psz_subtitle );
3181 if( val.psz_string )
3182 input_ControlPush( p_input, INPUT_CONTROL_ADD_SUBTITLE, &val );
3186 /*****************************************************************************
3188 *****************************************************************************/
3189 void input_UpdateStatistic( input_thread_t *p_input,
3190 input_statistic_t i_type, int i_delta )
3192 assert( p_input->i_state != INIT_S );
3194 vlc_mutex_lock( &p_input->p->counters.counters_lock);
3197 #define I(c) stats_UpdateInteger( p_input, p_input->p->counters.c, i_delta, NULL )
3198 case INPUT_STATISTIC_DECODED_VIDEO:
3201 case INPUT_STATISTIC_DECODED_AUDIO:
3204 case INPUT_STATISTIC_DECODED_SUBTITLE:
3207 case INPUT_STATISTIC_SENT_PACKET:
3208 I(p_sout_sent_packets);
3211 case INPUT_STATISTIC_SENT_BYTE:
3213 int i_bytes; /* That's pretty stupid to define it as an integer, it will overflow
3215 if( !stats_UpdateInteger( p_input, p_input->p->counters.p_sout_sent_bytes, i_delta, &i_bytes ) )
3216 stats_UpdateFloat( p_input, p_input->p->counters.p_sout_send_bitrate, i_bytes, NULL );
3220 msg_Err( p_input, "Invalid statistic type %d (internal error)", i_type );
3223 vlc_mutex_unlock( &p_input->p->counters.counters_lock);
3225 /*****************************************************************************
3226 * input_get_event_manager
3227 *****************************************************************************/
3228 vlc_event_manager_t *input_get_event_manager( input_thread_t *p_input )
3230 return &p_input->p->event_manager;
3234 /* TODO FIXME nearly the same logic that snapshot code */
3235 char *input_CreateFilename( vlc_object_t *p_obj, const char *psz_path, const char *psz_prefix, const char *psz_extension )
3240 path = utf8_opendir( psz_path );
3245 char *psz_tmp = str_format( p_obj, psz_prefix );
3249 filename_sanitize( psz_tmp );
3250 if( asprintf( &psz_file, "%s"DIR_SEP"%s%s%s",
3252 psz_extension ? "." : "",
3253 psz_extension ? psz_extension : "" ) < 0 )
3260 psz_file = str_format( p_obj, psz_path );
3261 path_sanitize( psz_file );