1 /*****************************************************************************
2 * input.c: input thread
3 *****************************************************************************
4 * Copyright (C) 1998-2007 VLC authors and VideoLAN
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
8 * Laurent Aimar <fenrir@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc_common.h>
39 #include "input_internal.h"
42 #include "es_out_timeshift.h"
50 #include "../stream_output/stream_output.h"
52 #include <vlc_dialog.h>
54 #include <vlc_charset.h>
56 #include <vlc_strings.h>
57 #include <vlc_modules.h>
58 #include <vlc_playlist.h> // FIXME
60 /*****************************************************************************
62 *****************************************************************************/
63 static void Destructor( input_thread_t * p_input );
65 static void *Run ( void * );
67 static input_thread_t * Create ( vlc_object_t *, input_item_t *,
68 const char *, bool, input_resource_t * );
69 static int Init ( input_thread_t *p_input );
70 static void End ( input_thread_t *p_input );
71 static void MainLoop( input_thread_t *p_input, bool b_interactive );
73 static inline int ControlPop( input_thread_t *, int *, vlc_value_t *, mtime_t i_deadline, bool b_postpone_seek );
74 static void ControlRelease( int i_type, vlc_value_t val );
75 static bool ControlIsSeekRequest( int i_type );
76 static bool Control( input_thread_t *, int, vlc_value_t );
78 static int UpdateTitleSeekpointFromAccess( input_thread_t * );
79 static void UpdateGenericFromAccess( input_thread_t * );
81 static int UpdateTitleSeekpointFromDemux( input_thread_t * );
82 static void UpdateGenericFromDemux( input_thread_t * );
83 static void UpdateTitleListfromDemux( input_thread_t * );
85 static void MRLSections( const char *, int *, int *, int *, int *);
87 static input_source_t *InputSourceNew( input_thread_t *);
88 static int InputSourceInit( input_thread_t *, input_source_t *,
89 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, bool *pb_demux_polled );
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 void InputGetExtraFiles( input_thread_t *p_input,
102 int *pi_list, char ***pppsz_list,
103 const char *psz_access, const char *psz_path );
105 static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
106 int i_new, input_attachment_t **pp_new );
113 static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, unsigned i_flags );
115 static void input_ChangeState( input_thread_t *p_input, int i_state ); /* TODO fix name */
119 * Create a new input_thread_t.
121 * You need to call input_Start on it when you are done
122 * adding callback on the variables/events you want to monitor.
124 * \param p_parent a vlc_object
125 * \param p_item an input item
126 * \param psz_log an optional prefix for this input logs
127 * \param p_resource an optional input ressource
128 * \return a pointer to the spawned input thread
130 input_thread_t *input_Create( vlc_object_t *p_parent,
131 input_item_t *p_item,
132 const char *psz_log, input_resource_t *p_resource )
134 return Create( p_parent, p_item, psz_log, false, p_resource );
137 #undef input_CreateAndStart
139 * Create a new input_thread_t and start it.
141 * Provided for convenience.
145 input_thread_t *input_CreateAndStart( vlc_object_t *p_parent,
146 input_item_t *p_item, const char *psz_log )
148 input_thread_t *p_input = input_Create( p_parent, p_item, psz_log, NULL );
150 if( input_Start( p_input ) )
152 vlc_object_release( p_input );
160 * Initialize an input thread and run it until it stops by itself.
162 * \param p_parent a vlc_object
163 * \param p_item an input item
164 * \return an error code, VLC_SUCCESS on success
166 int input_Read( vlc_object_t *p_parent, input_item_t *p_item )
168 input_thread_t *p_input = Create( p_parent, p_item, NULL, false, NULL );
172 if( !Init( p_input ) )
174 MainLoop( p_input, false );
178 vlc_object_release( p_input );
183 * Initialize an input and initialize it to preparse the item
184 * This function is blocking. It will only accept parsing regular files.
186 * \param p_parent a vlc_object_t
187 * \param p_item an input item
188 * \return VLC_SUCCESS or an error
190 int input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
192 input_thread_t *p_input;
194 /* Allocate descriptor */
195 p_input = Create( p_parent, p_item, NULL, true, NULL );
199 if( !Init( p_input ) )
202 vlc_object_release( p_input );
208 * Start a input_thread_t created by input_Create.
210 * You must not start an already running input_thread_t.
212 * \param the input thread to start
214 int input_Start( input_thread_t *p_input )
216 /* Create thread and wait for its readiness. */
217 p_input->p->is_running = !vlc_clone( &p_input->p->thread,
218 Run, p_input, VLC_THREAD_PRIORITY_INPUT );
219 if( !p_input->p->is_running )
221 input_ChangeState( p_input, ERROR_S );
222 msg_Err( p_input, "cannot create input thread" );
229 * Request a running input thread to stop and die
231 * b_abort must be true when a user stop is requested and not because you have
232 * detected an error or an eof. It will be used to properly send the
233 * INPUT_EVENT_ABORT event.
235 * \param p_input the input thread to stop
236 * \param b_abort true if the input has been aborted by a user request
238 void input_Stop( input_thread_t *p_input, bool b_abort )
240 /* Set die for input and ALL of this childrens (even (grand-)grand-childrens)
241 * It is needed here even if it is done in INPUT_CONTROL_SET_DIE handler to
242 * unlock the control loop */
243 ObjectKillChildrens( VLC_OBJECT(p_input) );
245 vlc_mutex_lock( &p_input->p->lock_control );
246 p_input->p->b_abort |= b_abort;
247 vlc_mutex_unlock( &p_input->p->lock_control );
249 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
252 void input_Join( input_thread_t *p_input )
254 if( p_input->p->is_running )
255 vlc_join( p_input->p->thread, NULL );
258 void input_Release( input_thread_t *p_input )
260 vlc_object_release( p_input );
266 * It does not call input_Stop itself.
268 void input_Close( input_thread_t *p_input )
270 input_Join( p_input );
271 input_Release( p_input );
275 * Get the item from an input thread
276 * FIXME it does not increase ref count of the item.
277 * if it is used after p_input is destroyed nothing prevent it from
280 input_item_t *input_GetItem( input_thread_t *p_input )
282 assert( p_input && p_input->p );
283 return p_input->p->p_item;
286 /*****************************************************************************
287 * This function creates a new input, and returns a pointer
288 * to its description. On error, it returns NULL.
290 * XXX Do not forget to update vlc_input.h if you add new variables.
291 *****************************************************************************/
292 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
293 const char *psz_header, bool b_quick,
294 input_resource_t *p_resource )
296 input_thread_t *p_input = NULL; /* thread descriptor */
299 /* Allocate descriptor */
300 p_input = vlc_custom_create( p_parent, sizeof( *p_input ), "input" );
301 if( p_input == NULL )
304 /* Construct a nice name for the input timer */
305 char psz_timer_name[255];
306 char * psz_name = input_item_GetName( p_item );
307 snprintf( psz_timer_name, sizeof(psz_timer_name),
308 "input launching for '%s'", psz_name );
310 msg_Dbg( p_input, "Creating an input for '%s'", psz_name);
314 p_input->p = calloc( 1, sizeof( input_thread_private_t ) );
318 /* Parse input options */
319 vlc_mutex_lock( &p_item->lock );
320 assert( (int)p_item->optflagc == p_item->i_options );
321 for( i = 0; i < p_item->i_options; i++ )
322 var_OptionParse( VLC_OBJECT(p_input), p_item->ppsz_options[i],
323 !!(p_item->optflagv[i] & VLC_INPUT_OPTION_TRUSTED) );
324 vlc_mutex_unlock( &p_item->lock );
326 p_input->b_preparsing = b_quick;
327 p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
329 /* Init Common fields */
330 p_input->b_eof = false;
331 p_input->p->b_can_pace_control = true;
332 p_input->p->i_start = 0;
333 p_input->p->i_time = 0;
334 p_input->p->i_stop = 0;
335 p_input->p->i_run = 0;
336 p_input->p->i_title = 0;
337 p_input->p->title = NULL;
338 p_input->p->i_title_offset = p_input->p->i_seekpoint_offset = 0;
339 p_input->p->i_state = INIT_S;
340 p_input->p->i_rate = INPUT_RATE_DEFAULT;
341 p_input->p->b_recording = false;
342 memset( &p_input->p->bookmark, 0, sizeof(p_input->p->bookmark) );
343 TAB_INIT( p_input->p->i_bookmark, p_input->p->pp_bookmark );
344 TAB_INIT( p_input->p->i_attachment, p_input->p->attachment );
345 p_input->p->p_sout = NULL;
346 p_input->p->b_out_pace_control = false;
348 vlc_gc_incref( p_item ); /* Released in Destructor() */
349 p_input->p->p_item = p_item;
351 /* Init Input fields */
352 p_input->p->input.p_access = NULL;
353 p_input->p->input.p_stream = NULL;
354 p_input->p->input.p_demux = NULL;
355 p_input->p->input.b_title_demux = false;
356 p_input->p->input.i_title = 0;
357 p_input->p->input.title = NULL;
358 p_input->p->input.i_title_offset = p_input->p->input.i_seekpoint_offset = 0;
359 p_input->p->input.b_can_pace_control = true;
360 p_input->p->input.b_can_rate_control = true;
361 p_input->p->input.b_rescale_ts = true;
362 p_input->p->input.b_eof = false;
364 vlc_mutex_lock( &p_item->lock );
366 if( !p_item->p_stats )
367 p_item->p_stats = stats_NewInputStats( p_input );
368 vlc_mutex_unlock( &p_item->lock );
371 p_input->p->i_slave = 0;
372 p_input->p->slave = NULL;
377 p_input->p->p_resource_private = NULL;
378 p_input->p->p_resource = input_resource_Hold( p_resource );
382 p_input->p->p_resource_private = input_resource_New( VLC_OBJECT( p_input ) );
383 p_input->p->p_resource = input_resource_Hold( p_input->p->p_resource_private );
385 input_resource_SetInput( p_input->p->p_resource, p_input );
387 /* Init control buffer */
388 vlc_mutex_init( &p_input->p->lock_control );
389 vlc_cond_init( &p_input->p->wait_control );
390 p_input->p->i_control = 0;
391 p_input->p->b_abort = false;
392 p_input->p->is_running = false;
394 /* Create Object Variables for private use only */
395 input_ConfigVarInit( p_input );
397 /* Create Objects variables for public Get and Set */
398 input_ControlVarInit( p_input );
401 if( !p_input->b_preparsing )
403 char *psz_bookmarks = var_GetNonEmptyString( p_input, "bookmarks" );
406 /* FIXME: have a common cfg parsing routine used by sout and others */
407 char *psz_parser, *psz_start, *psz_end;
408 psz_parser = psz_bookmarks;
409 while( (psz_start = strchr( psz_parser, '{' ) ) )
411 seekpoint_t *p_seekpoint;
414 psz_end = strchr( psz_start, '}' );
415 if( !psz_end ) break;
416 psz_parser = psz_end + 1;
417 backup = *psz_parser;
421 p_seekpoint = vlc_seekpoint_New();
422 while( (psz_end = strchr( psz_start, ',' ) ) )
425 if( !strncmp( psz_start, "name=", 5 ) )
427 p_seekpoint->psz_name = strdup(psz_start + 5);
429 else if( !strncmp( psz_start, "bytes=", 6 ) )
431 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
433 else if( !strncmp( psz_start, "time=", 5 ) )
435 p_seekpoint->i_time_offset = atoll(psz_start + 5) *
438 psz_start = psz_end + 1;
440 msg_Dbg( p_input, "adding bookmark: %s, bytes=%"PRId64", time=%"PRId64,
441 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
442 p_seekpoint->i_time_offset );
443 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
444 vlc_seekpoint_Delete( p_seekpoint );
445 *psz_parser = backup;
447 free( psz_bookmarks );
451 /* Remove 'Now playing' info as it is probably outdated */
452 input_item_SetNowPlaying( p_item, NULL );
453 input_SendEventMeta( p_input );
456 if( p_input->b_preparsing )
457 p_input->i_flags |= OBJECT_FLAGS_QUIET | OBJECT_FLAGS_NOINTERACT;
459 /* Make sure the interaction option is honored */
460 if( !var_InheritBool( p_input, "interact" ) )
461 p_input->i_flags |= OBJECT_FLAGS_NOINTERACT;
464 memset( &p_input->p->counters, 0, sizeof( p_input->p->counters ) );
465 vlc_mutex_init( &p_input->p->counters.counters_lock );
467 p_input->p->p_es_out_display = input_EsOutNew( p_input, p_input->p->i_rate );
468 p_input->p->p_es_out = NULL;
470 /* Set the destructor when we are sure we are initialized */
471 vlc_object_set_destructor( p_input, (vlc_destructor_t)Destructor );
477 * Input destructor (called when the object's refcount reaches 0).
479 static void Destructor( input_thread_t * p_input )
482 char * psz_name = input_item_GetName( p_input->p->p_item );
483 msg_Dbg( p_input, "Destroying the input for '%s'", psz_name);
487 if( p_input->p->p_es_out_display )
488 es_out_Delete( p_input->p->p_es_out_display );
490 if( p_input->p->p_resource )
491 input_resource_Release( p_input->p->p_resource );
492 if( p_input->p->p_resource_private )
493 input_resource_Release( p_input->p->p_resource_private );
495 vlc_gc_decref( p_input->p->p_item );
497 vlc_mutex_destroy( &p_input->p->counters.counters_lock );
499 for( int i = 0; i < p_input->p->i_control; i++ )
501 input_control_t *p_ctrl = &p_input->p->control[i];
502 ControlRelease( p_ctrl->i_type, p_ctrl->val );
505 vlc_cond_destroy( &p_input->p->wait_control );
506 vlc_mutex_destroy( &p_input->p->lock_control );
510 /*****************************************************************************
511 * Run: main thread loop
512 * This is the "normal" thread that spawns the input processing chain,
513 * reads the stream, cleans up and waits
514 *****************************************************************************/
515 static void *Run( void *obj )
517 input_thread_t *p_input = (input_thread_t *)obj;
518 const int canc = vlc_savecancel();
520 if( Init( p_input ) )
523 MainLoop( p_input, true ); /* FIXME it can be wrong (like with VLM) */
529 /* Tell we're dead */
530 vlc_mutex_lock( &p_input->p->lock_control );
531 const bool b_abort = p_input->p->b_abort;
532 vlc_mutex_unlock( &p_input->p->lock_control );
535 input_SendEventAbort( p_input );
536 input_SendEventDead( p_input );
538 vlc_restorecancel( canc );
542 /*****************************************************************************
543 * Main loop: Fill buffers from access, and demux
544 *****************************************************************************/
548 * It asks the demuxer to demux some data
550 static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, bool *pb_demux_polled, mtime_t i_start_mdate )
555 *pb_demux_polled = p_input->p->input.p_demux->pf_demux != NULL;
557 if( ( p_input->p->i_stop > 0 && p_input->p->i_time >= p_input->p->i_stop ) ||
558 ( p_input->p->i_run > 0 && i_start_mdate+p_input->p->i_run < mdate() ) )
561 i_ret = demux_Demux( p_input->p->input.p_demux );
565 if( p_input->p->input.p_demux->info.i_update )
567 if( p_input->p->input.p_demux->info.i_update & INPUT_UPDATE_TITLE_LIST )
569 UpdateTitleListfromDemux( p_input );
570 p_input->p->input.p_demux->info.i_update &= ~INPUT_UPDATE_TITLE_LIST;
572 if( p_input->p->input.b_title_demux )
574 i_ret = UpdateTitleSeekpointFromDemux( p_input );
577 UpdateGenericFromDemux( p_input );
579 else if( p_input->p->input.p_access &&
580 p_input->p->input.p_access->info.i_update )
582 if( !p_input->p->input.b_title_demux )
584 i_ret = UpdateTitleSeekpointFromAccess( p_input );
587 UpdateGenericFromAccess( p_input );
591 if( i_ret == 0 ) /* EOF */
593 msg_Dbg( p_input, "EOF reached" );
594 p_input->p->input.b_eof = true;
595 es_out_Eos(p_input->p->p_es_out);
599 input_ChangeState( p_input, ERROR_S );
602 if( i_ret > 0 && p_input->p->i_slave > 0 )
605 SlaveDemux( p_input, &b_demux_polled );
607 *pb_demux_polled |= b_demux_polled;
611 static int MainLoopTryRepeat( input_thread_t *p_input, mtime_t *pi_start_mdate )
613 int i_repeat = var_GetInteger( p_input, "input-repeat" );
619 msg_Dbg( p_input, "repeating the same input (%d)", i_repeat );
623 var_SetInteger( p_input, "input-repeat", i_repeat );
626 /* Seek to start title/seekpoint */
627 val.i_int = p_input->p->input.i_title_start -
628 p_input->p->input.i_title_offset;
629 if( val.i_int < 0 || val.i_int >= p_input->p->input.i_title )
631 input_ControlPush( p_input,
632 INPUT_CONTROL_SET_TITLE, &val );
634 val.i_int = p_input->p->input.i_seekpoint_start -
635 p_input->p->input.i_seekpoint_offset;
636 if( val.i_int > 0 /* TODO: check upper boundary */ )
637 input_ControlPush( p_input,
638 INPUT_CONTROL_SET_SEEKPOINT, &val );
640 /* Seek to start position */
641 if( p_input->p->i_start > 0 )
643 val.i_time = p_input->p->i_start;
644 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &val );
649 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &val );
653 *pi_start_mdate = mdate();
659 * It update the variables used by the interfaces
661 static void MainLoopInterface( input_thread_t *p_input )
663 double f_position = 0.0;
665 mtime_t i_length = 0;
667 /* update input status variables */
668 if( demux_Control( p_input->p->input.p_demux,
669 DEMUX_GET_POSITION, &f_position ) )
672 if( demux_Control( p_input->p->input.p_demux,
673 DEMUX_GET_TIME, &i_time ) )
675 p_input->p->i_time = i_time;
677 if( demux_Control( p_input->p->input.p_demux,
678 DEMUX_GET_LENGTH, &i_length ) )
681 es_out_SetTimes( p_input->p->p_es_out, f_position, i_time, i_length );
683 /* update current bookmark */
684 vlc_mutex_lock( &p_input->p->p_item->lock );
685 p_input->p->bookmark.i_time_offset = i_time;
686 if( p_input->p->input.p_stream )
687 p_input->p->bookmark.i_byte_offset = stream_Tell( p_input->p->input.p_stream );
688 vlc_mutex_unlock( &p_input->p->p_item->lock );
693 * It updates the globals statics
695 static void MainLoopStatistic( input_thread_t *p_input )
697 stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
698 input_SendEventStatistics( p_input );
703 * The main input loop.
705 static void MainLoop( input_thread_t *p_input, bool b_interactive )
707 mtime_t i_start_mdate = mdate();
708 mtime_t i_intf_update = 0;
709 mtime_t i_statistic_update = 0;
710 mtime_t i_last_seek_mdate = 0;
711 bool b_pause_after_eof = b_interactive &&
712 var_CreateGetBool( p_input, "play-and-pause" );
714 while( vlc_object_alive( p_input ) && !p_input->b_error )
724 b_force_update = false;
726 /* FIXME if p_input->p->i_state == PAUSE_S the access/access_demux
727 * is paused -> this may cause problem with some of them
728 * The same problem can be seen when seeking while paused */
729 b_paused = p_input->p->i_state == PAUSE_S &&
730 ( !es_out_GetBuffering( p_input->p->p_es_out ) || p_input->p->input.b_eof );
732 b_demux_polled = true;
735 if( !p_input->p->input.b_eof )
737 MainLoopDemux( p_input, &b_force_update, &b_demux_polled, i_start_mdate );
739 i_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
741 else if( !es_out_GetEmpty( p_input->p->p_es_out ) )
743 msg_Dbg( p_input, "waiting decoder fifos to empty" );
744 i_wakeup = mdate() + INPUT_IDLE_SLEEP;
746 /* Pause after eof only if the input is pausable.
747 * This way we won't trigger timeshifting for nothing */
748 else if( b_pause_after_eof && p_input->p->b_can_pause )
750 msg_Dbg( p_input, "pausing at EOF (pause after each)");
752 Control( p_input, INPUT_CONTROL_SET_STATE, val );
758 if( MainLoopTryRepeat( p_input, &i_start_mdate ) )
760 b_pause_after_eof = var_GetBool( p_input, "play-and-pause" );
766 mtime_t i_deadline = i_wakeup;
767 if( b_paused || !b_demux_polled )
768 i_deadline = __MIN( i_intf_update, i_statistic_update );
773 mtime_t i_limit = i_deadline;
775 /* We will postpone the execution of a seek until we have
776 * finished the ES bufferisation (postpone is limited to
778 bool b_buffering = es_out_GetBuffering( p_input->p->p_es_out ) &&
779 !p_input->p->input.b_eof;
782 /* When postpone is in order, check the ES level every 20ms */
783 mtime_t i_current = mdate();
784 if( i_last_seek_mdate + INT64_C(125000) >= i_current )
785 i_limit = __MIN( i_deadline, i_current + INT64_C(20000) );
789 if( ControlPop( p_input, &i_type, &val, i_limit, b_buffering ) )
791 if( b_buffering && i_limit < i_deadline )
797 msg_Dbg( p_input, "control type=%d", i_type );
800 if( Control( p_input, i_type, val ) )
802 if( ControlIsSeekRequest( i_type ) )
803 i_last_seek_mdate = mdate();
804 b_force_update = true;
808 /* Update interface and statistics */
810 if( i_intf_update < i_current || b_force_update )
812 MainLoopInterface( p_input );
813 i_intf_update = i_current + INT64_C(250000);
814 b_force_update = false;
816 if( i_statistic_update < i_current )
818 MainLoopStatistic( p_input );
819 i_statistic_update = i_current + INT64_C(1000000);
822 /* Update the wakeup time */
824 i_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
825 } while( i_current < i_wakeup );
828 if( !p_input->b_error )
829 input_ChangeState( p_input, END_S );
832 static void InitStatistics( input_thread_t * p_input )
834 if( p_input->b_preparsing ) return;
836 /* Prepare statistics */
837 #define INIT_COUNTER( c, compute ) p_input->p->counters.p_##c = \
838 stats_CounterCreate( STATS_##compute);
839 if( libvlc_stats( p_input ) )
841 INIT_COUNTER( read_bytes, COUNTER );
842 INIT_COUNTER( read_packets, COUNTER );
843 INIT_COUNTER( demux_read, COUNTER );
844 INIT_COUNTER( input_bitrate, DERIVATIVE );
845 INIT_COUNTER( demux_bitrate, DERIVATIVE );
846 INIT_COUNTER( demux_corrupted, COUNTER );
847 INIT_COUNTER( demux_discontinuity, COUNTER );
848 INIT_COUNTER( played_abuffers, COUNTER );
849 INIT_COUNTER( lost_abuffers, COUNTER );
850 INIT_COUNTER( displayed_pictures, COUNTER );
851 INIT_COUNTER( lost_pictures, COUNTER );
852 INIT_COUNTER( decoded_audio, COUNTER );
853 INIT_COUNTER( decoded_video, COUNTER );
854 INIT_COUNTER( decoded_sub, COUNTER );
855 p_input->p->counters.p_sout_send_bitrate = NULL;
856 p_input->p->counters.p_sout_sent_packets = NULL;
857 p_input->p->counters.p_sout_sent_bytes = NULL;
862 static int InitSout( input_thread_t * p_input )
864 if( p_input->b_preparsing )
867 /* Find a usable sout and attach it to p_input */
868 char *psz = var_GetNonEmptyString( p_input, "sout" );
869 if( psz && strncasecmp( p_input->p->p_item->psz_uri, "vlc:", 4 ) )
871 p_input->p->p_sout = input_resource_RequestSout( p_input->p->p_resource, NULL, psz );
872 if( !p_input->p->p_sout )
874 input_ChangeState( p_input, ERROR_S );
875 msg_Err( p_input, "cannot start stream output instance, " \
880 if( libvlc_stats( p_input ) )
882 INIT_COUNTER( sout_sent_packets, COUNTER );
883 INIT_COUNTER( sout_sent_bytes, COUNTER );
884 INIT_COUNTER( sout_send_bitrate, DERIVATIVE );
889 input_resource_RequestSout( p_input->p->p_resource, NULL, NULL );
897 static void InitTitle( input_thread_t * p_input )
899 input_source_t *p_master = &p_input->p->input;
901 if( p_input->b_preparsing )
904 vlc_mutex_lock( &p_input->p->p_item->lock );
905 /* Create global title (from master) */
906 p_input->p->i_title = p_master->i_title;
907 p_input->p->title = p_master->title;
908 p_input->p->i_title_offset = p_master->i_title_offset;
909 p_input->p->i_seekpoint_offset = p_master->i_seekpoint_offset;
910 if( p_input->p->i_title > 0 )
912 /* Setup variables */
913 input_ControlVarNavigation( p_input );
914 input_SendEventTitle( p_input, 0 );
918 p_input->p->b_can_pace_control = p_master->b_can_pace_control;
919 p_input->p->b_can_pause = p_master->b_can_pause;
920 p_input->p->b_can_rate_control = p_master->b_can_rate_control;
921 vlc_mutex_unlock( &p_input->p->p_item->lock );
924 static void StartTitle( input_thread_t * p_input )
928 /* Start title/chapter */
929 val.i_int = p_input->p->input.i_title_start -
930 p_input->p->input.i_title_offset;
931 if( val.i_int > 0 && val.i_int < p_input->p->input.i_title )
932 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
934 val.i_int = p_input->p->input.i_seekpoint_start -
935 p_input->p->input.i_seekpoint_offset;
936 if( val.i_int > 0 /* TODO: check upper boundary */ )
937 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
939 /* Start/stop/run time */
940 p_input->p->i_start = (int64_t)(1000000.0
941 * var_GetFloat( p_input, "start-time" ));
942 p_input->p->i_stop = (int64_t)(1000000.0
943 * var_GetFloat( p_input, "stop-time" ));
944 p_input->p->i_run = (int64_t)(1000000.0
945 * var_GetFloat( p_input, "run-time" ));
946 if( p_input->p->i_run < 0 )
948 msg_Warn( p_input, "invalid run-time ignored" );
949 p_input->p->i_run = 0;
952 if( p_input->p->i_start > 0 )
956 msg_Dbg( p_input, "starting at time: %ds",
957 (int)( p_input->p->i_start / INT64_C(1000000) ) );
959 s.i_time = p_input->p->i_start;
960 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
962 if( p_input->p->i_stop > 0 && p_input->p->i_stop <= p_input->p->i_start )
964 msg_Warn( p_input, "invalid stop-time ignored" );
965 p_input->p->i_stop = 0;
967 p_input->p->b_fast_seek = var_GetBool( p_input, "input-fast-seek" );
970 static void LoadSubtitles( input_thread_t *p_input )
973 /* Get fps and set it if not already set */
974 const double f_fps = p_input->p->f_fps;
977 float f_requested_fps;
979 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
980 var_SetFloat( p_input, "sub-original-fps", f_fps );
982 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
983 if( f_requested_fps != f_fps )
985 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
987 var_SetFloat( p_input, "sub-fps", f_requested_fps );
991 const int i_delay = var_CreateGetInteger( p_input, "sub-delay" );
993 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
995 /* Look for and add subtitle files */
996 unsigned i_flags = SUB_FORCED;
998 char *psz_subtitle = var_GetNonEmptyString( p_input, "sub-file" );
999 if( psz_subtitle != NULL )
1001 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
1002 SubtitleAdd( p_input, psz_subtitle, i_flags );
1003 i_flags = SUB_NOFLAG;
1006 if( var_GetBool( p_input, "sub-autodetect-file" ) )
1008 char *psz_autopath = var_GetNonEmptyString( p_input, "sub-autodetect-path" );
1009 char **ppsz_subs = subtitles_Detect( p_input, psz_autopath,
1010 p_input->p->p_item->psz_uri );
1011 free( psz_autopath );
1013 for( int i = 0; ppsz_subs && ppsz_subs[i]; i++ )
1015 if( !psz_subtitle || strcmp( psz_subtitle, ppsz_subs[i] ) )
1017 i_flags |= SUB_CANFAIL;
1018 SubtitleAdd( p_input, ppsz_subs[i], i_flags );
1019 i_flags = SUB_NOFLAG;
1022 free( ppsz_subs[i] );
1026 free( psz_subtitle );
1028 /* Load subtitles from attachments */
1029 int i_attachment = 0;
1030 input_attachment_t **pp_attachment = NULL;
1032 vlc_mutex_lock( &p_input->p->p_item->lock );
1033 for( int i = 0; i < p_input->p->i_attachment; i++ )
1035 const input_attachment_t *a = p_input->p->attachment[i];
1036 if( !strcmp( a->psz_mime, "application/x-srt" ) )
1037 TAB_APPEND( i_attachment, pp_attachment,
1038 vlc_input_attachment_New( a->psz_name, NULL,
1039 a->psz_description, NULL, 0 ) );
1041 vlc_mutex_unlock( &p_input->p->p_item->lock );
1043 if( i_attachment > 0 )
1044 var_Create( p_input, "sub-description", VLC_VAR_STRING );
1045 for( int i = 0; i < i_attachment; i++ )
1047 input_attachment_t *a = pp_attachment[i];
1051 if( a->psz_name[i] &&
1052 asprintf( &psz_mrl, "attachment://%s", a->psz_name ) >= 0 )
1054 var_SetString( p_input, "sub-description", a->psz_description ? a->psz_description : "");
1056 SubtitleAdd( p_input, psz_mrl, i_flags );
1058 i_flags = SUB_NOFLAG;
1061 vlc_input_attachment_Delete( a );
1063 free( pp_attachment );
1064 if( i_attachment > 0 )
1065 var_Destroy( p_input, "sub-description" );
1068 static void LoadSlaves( input_thread_t *p_input )
1070 char *psz = var_GetNonEmptyString( p_input, "input-slave" );
1074 char *psz_org = psz;
1075 while( psz && *psz )
1077 while( *psz == ' ' || *psz == '#' )
1080 char *psz_delim = strchr( psz, '#' );
1082 *psz_delim++ = '\0';
1087 char *uri = strstr(psz, "://")
1088 ? strdup( psz ) : vlc_path2uri( psz, NULL );
1092 msg_Dbg( p_input, "adding slave input '%s'", uri );
1094 input_source_t *p_slave = InputSourceNew( p_input );
1095 if( p_slave && !InputSourceInit( p_input, p_slave, uri, NULL, false ) )
1096 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, p_slave );
1104 static void UpdatePtsDelay( input_thread_t *p_input )
1106 input_thread_private_t *p_sys = p_input->p;
1108 /* Get max pts delay from input source */
1109 mtime_t i_pts_delay = p_sys->input.i_pts_delay;
1110 for( int i = 0; i < p_sys->i_slave; i++ )
1111 i_pts_delay = __MAX( i_pts_delay, p_sys->slave[i]->i_pts_delay );
1113 if( i_pts_delay < 0 )
1116 /* Take care of audio/spu delay */
1117 const mtime_t i_audio_delay = var_GetTime( p_input, "audio-delay" );
1118 const mtime_t i_spu_delay = var_GetTime( p_input, "spu-delay" );
1119 const mtime_t i_extra_delay = __MIN( i_audio_delay, i_spu_delay );
1120 if( i_extra_delay < 0 )
1121 i_pts_delay -= i_extra_delay;
1123 /* Update cr_average depending on the caching */
1124 const int i_cr_average = var_GetInteger( p_input, "cr-average" ) * i_pts_delay / DEFAULT_PTS_DELAY;
1127 es_out_SetDelay( p_input->p->p_es_out_display, AUDIO_ES, i_audio_delay );
1128 es_out_SetDelay( p_input->p->p_es_out_display, SPU_ES, i_spu_delay );
1129 es_out_SetJitter( p_input->p->p_es_out, i_pts_delay, 0, i_cr_average );
1132 static void InitPrograms( input_thread_t * p_input )
1137 /* Compute correct pts_delay */
1138 UpdatePtsDelay( p_input );
1141 i_es_out_mode = ES_OUT_MODE_AUTO;
1142 if( p_input->p->p_sout )
1146 if( var_GetBool( p_input, "sout-all" ) )
1148 i_es_out_mode = ES_OUT_MODE_ALL;
1151 if( (prgms = var_GetNonEmptyString( p_input, "programs" )) != NULL )
1155 TAB_INIT( list.i_count, list.p_values );
1156 for( const char *prgm = strtok_r( prgms, ",", &buf );
1158 prgm = strtok_r( NULL, ",", &buf ) )
1160 vlc_value_t val = { .i_int = atoi( prgm ) };
1161 INSERT_ELEM( list.p_values, list.i_count, list.i_count, val );
1164 if( list.i_count > 0 )
1165 i_es_out_mode = ES_OUT_MODE_PARTIAL;
1166 /* Note : we should remove the "program" callback. */
1171 es_out_SetMode( p_input->p->p_es_out, i_es_out_mode );
1173 /* Inform the demuxer about waited group (needed only for DVB) */
1174 if( i_es_out_mode == ES_OUT_MODE_ALL )
1176 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
1178 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
1180 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1,
1182 TAB_CLEAN( list.i_count, list.p_values );
1186 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP,
1187 es_out_GetGroupForced( p_input->p->p_es_out ), NULL );
1191 static int Init( input_thread_t * p_input )
1196 for( i = 0; i < p_input->p->p_item->i_options; i++ )
1198 if( !strncmp( p_input->p->p_item->ppsz_options[i], "meta-file", 9 ) )
1200 msg_Dbg( p_input, "Input is a meta file: disabling unneeded options" );
1201 var_SetString( p_input, "sout", "" );
1202 var_SetBool( p_input, "sout-all", false );
1203 var_SetString( p_input, "input-slave", "" );
1204 var_SetInteger( p_input, "input-repeat", 0 );
1205 var_SetString( p_input, "sub-file", "" );
1206 var_SetBool( p_input, "sub-autodetect-file", false );
1210 InitStatistics( p_input );
1212 if( InitSout( p_input ) )
1217 p_input->p->p_es_out = input_EsOutTimeshiftNew( p_input, p_input->p->p_es_out_display, p_input->p->i_rate );
1220 input_ChangeState( p_input, OPENING_S );
1221 input_SendEventCache( p_input, 0.0 );
1224 if( InputSourceInit( p_input, &p_input->p->input,
1225 p_input->p->p_item->psz_uri, NULL, false ) )
1230 InitTitle( p_input );
1232 /* Load master infos */
1235 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_LENGTH,
1239 i_length = input_item_GetDuration( p_input->p->p_item );
1240 input_SendEventLength( p_input, i_length );
1242 input_SendEventPosition( p_input, 0.0, 0 );
1244 if( !p_input->b_preparsing )
1246 StartTitle( p_input );
1247 LoadSubtitles( p_input );
1248 LoadSlaves( p_input );
1249 InitPrograms( p_input );
1251 double f_rate = var_InheritFloat( p_input, "rate" );
1252 if( f_rate != 0.0 && f_rate != 1.0 )
1254 vlc_value_t val = { .i_int = INPUT_RATE_DEFAULT / f_rate };
1255 input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &val );
1259 if( !p_input->b_preparsing && p_input->p->p_sout )
1261 p_input->p->b_out_pace_control = (p_input->p->p_sout->i_out_pace_nocontrol > 0);
1263 if( p_input->p->b_can_pace_control && p_input->p->b_out_pace_control )
1265 /* We don't want a high input priority here or we'll
1266 * end-up sucking up all the CPU time */
1267 vlc_set_priority( p_input->p->thread, VLC_THREAD_PRIORITY_LOW );
1270 msg_Dbg( p_input, "starting in %s mode",
1271 p_input->p->b_out_pace_control ? "async" : "sync" );
1274 p_meta = vlc_meta_New();
1277 /* Get meta data from users */
1278 InputMetaUser( p_input, p_meta );
1280 /* Get meta data from master input */
1281 InputSourceMeta( p_input, &p_input->p->input, p_meta );
1283 /* And from slave */
1284 for( int i = 0; i < p_input->p->i_slave; i++ )
1285 InputSourceMeta( p_input, p_input->p->slave[i], p_meta );
1288 InputUpdateMeta( p_input, p_meta );
1291 msg_Dbg( p_input, "`%s' successfully opened",
1292 p_input->p->p_item->psz_uri );
1294 /* initialization is complete */
1295 input_ChangeState( p_input, PLAYING_S );
1300 input_ChangeState( p_input, ERROR_S );
1302 if( p_input->p->p_es_out )
1303 es_out_Delete( p_input->p->p_es_out );
1304 es_out_SetMode( p_input->p->p_es_out_display, ES_OUT_MODE_END );
1305 if( p_input->p->p_resource )
1307 if( p_input->p->p_sout )
1308 input_resource_RequestSout( p_input->p->p_resource,
1309 p_input->p->p_sout, NULL );
1310 input_resource_SetInput( p_input->p->p_resource, NULL );
1311 if( p_input->p->p_resource_private )
1312 input_resource_Terminate( p_input->p->p_resource_private );
1315 if( !p_input->b_preparsing && libvlc_stats( p_input ) )
1317 #define EXIT_COUNTER( c ) do { if( p_input->p->counters.p_##c ) \
1318 stats_CounterClean( p_input->p->counters.p_##c );\
1319 p_input->p->counters.p_##c = NULL; } while(0)
1320 EXIT_COUNTER( read_bytes );
1321 EXIT_COUNTER( read_packets );
1322 EXIT_COUNTER( demux_read );
1323 EXIT_COUNTER( input_bitrate );
1324 EXIT_COUNTER( demux_bitrate );
1325 EXIT_COUNTER( demux_corrupted );
1326 EXIT_COUNTER( demux_discontinuity );
1327 EXIT_COUNTER( played_abuffers );
1328 EXIT_COUNTER( lost_abuffers );
1329 EXIT_COUNTER( displayed_pictures );
1330 EXIT_COUNTER( lost_pictures );
1331 EXIT_COUNTER( decoded_audio );
1332 EXIT_COUNTER( decoded_video );
1333 EXIT_COUNTER( decoded_sub );
1335 if( p_input->p->p_sout )
1337 EXIT_COUNTER( sout_sent_packets );
1338 EXIT_COUNTER( sout_sent_bytes );
1339 EXIT_COUNTER( sout_send_bitrate );
1344 /* Mark them deleted */
1345 p_input->p->input.p_demux = NULL;
1346 p_input->p->input.p_stream = NULL;
1347 p_input->p->input.p_access = NULL;
1348 p_input->p->p_es_out = NULL;
1349 p_input->p->p_sout = NULL;
1351 return VLC_EGENERIC;
1354 /*****************************************************************************
1355 * End: end the input thread
1356 *****************************************************************************/
1357 static void End( input_thread_t * p_input )
1361 /* We are at the end */
1362 input_ChangeState( p_input, END_S );
1364 /* Clean control variables */
1365 input_ControlVarStop( p_input );
1367 /* Stop es out activity */
1368 es_out_SetMode( p_input->p->p_es_out, ES_OUT_MODE_NONE );
1370 /* Clean up master */
1371 InputSourceClean( &p_input->p->input );
1374 for( i = 0; i < p_input->p->i_slave; i++ )
1376 InputSourceClean( p_input->p->slave[i] );
1377 free( p_input->p->slave[i] );
1379 free( p_input->p->slave );
1381 /* Unload all modules */
1382 if( p_input->p->p_es_out )
1383 es_out_Delete( p_input->p->p_es_out );
1384 es_out_SetMode( p_input->p->p_es_out_display, ES_OUT_MODE_END );
1386 if( !p_input->b_preparsing )
1388 #define CL_CO( c ) stats_CounterClean( p_input->p->counters.p_##c ); p_input->p->counters.p_##c = NULL;
1389 if( libvlc_stats( p_input ) )
1391 /* make sure we are up to date */
1392 stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
1393 CL_CO( read_bytes );
1394 CL_CO( read_packets );
1395 CL_CO( demux_read );
1396 CL_CO( input_bitrate );
1397 CL_CO( demux_bitrate );
1398 CL_CO( demux_corrupted );
1399 CL_CO( demux_discontinuity );
1400 CL_CO( played_abuffers );
1401 CL_CO( lost_abuffers );
1402 CL_CO( displayed_pictures );
1403 CL_CO( lost_pictures );
1404 CL_CO( decoded_audio) ;
1405 CL_CO( decoded_video );
1406 CL_CO( decoded_sub) ;
1409 /* Close optional stream output instance */
1410 if( p_input->p->p_sout )
1412 CL_CO( sout_sent_packets );
1413 CL_CO( sout_sent_bytes );
1414 CL_CO( sout_send_bitrate );
1419 vlc_mutex_lock( &p_input->p->p_item->lock );
1420 if( p_input->p->i_attachment > 0 )
1422 for( i = 0; i < p_input->p->i_attachment; i++ )
1423 vlc_input_attachment_Delete( p_input->p->attachment[i] );
1424 TAB_CLEAN( p_input->p->i_attachment, p_input->p->attachment );
1426 vlc_mutex_unlock( &p_input->p->p_item->lock );
1429 input_resource_RequestSout( p_input->p->p_resource,
1430 p_input->p->p_sout, NULL );
1431 input_resource_SetInput( p_input->p->p_resource, NULL );
1432 if( p_input->p->p_resource_private )
1433 input_resource_Terminate( p_input->p->p_resource_private );
1436 /*****************************************************************************
1438 *****************************************************************************/
1439 void input_ControlPush( input_thread_t *p_input,
1440 int i_type, vlc_value_t *p_val )
1442 vlc_mutex_lock( &p_input->p->lock_control );
1443 if( i_type == INPUT_CONTROL_SET_DIE )
1445 /* Special case, empty the control */
1446 for( int i = 0; i < p_input->p->i_control; i++ )
1448 input_control_t *p_ctrl = &p_input->p->control[i];
1449 ControlRelease( p_ctrl->i_type, p_ctrl->val );
1451 p_input->p->i_control = 0;
1454 if( p_input->p->i_control >= INPUT_CONTROL_FIFO_SIZE )
1456 msg_Err( p_input, "input control fifo overflow, trashing type=%d",
1459 ControlRelease( i_type, *p_val );
1468 memset( &c.val, 0, sizeof(c.val) );
1470 p_input->p->control[p_input->p->i_control++] = c;
1472 vlc_cond_signal( &p_input->p->wait_control );
1473 vlc_mutex_unlock( &p_input->p->lock_control );
1476 static int ControlGetReducedIndexLocked( input_thread_t *p_input )
1478 const int i_lt = p_input->p->control[0].i_type;
1480 for( i = 1; i < p_input->p->i_control; i++ )
1482 const int i_ct = p_input->p->control[i].i_type;
1485 ( i_ct == INPUT_CONTROL_SET_STATE ||
1486 i_ct == INPUT_CONTROL_SET_RATE ||
1487 i_ct == INPUT_CONTROL_SET_POSITION ||
1488 i_ct == INPUT_CONTROL_SET_TIME ||
1489 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1490 i_ct == INPUT_CONTROL_SET_TITLE ||
1491 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1492 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1498 /* TODO but that's not that important
1499 - merge SET_X with SET_X_CMD
1500 - ignore SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1501 - ignore SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1511 static inline int ControlPop( input_thread_t *p_input,
1512 int *pi_type, vlc_value_t *p_val,
1513 mtime_t i_deadline, bool b_postpone_seek )
1515 input_thread_private_t *p_sys = p_input->p;
1517 vlc_mutex_lock( &p_sys->lock_control );
1518 while( p_sys->i_control <= 0 ||
1519 ( b_postpone_seek && ControlIsSeekRequest( p_sys->control[0].i_type ) ) )
1521 if( !vlc_object_alive( p_input ) || i_deadline < 0 )
1523 vlc_mutex_unlock( &p_sys->lock_control );
1524 return VLC_EGENERIC;
1527 if( vlc_cond_timedwait( &p_sys->wait_control, &p_sys->lock_control,
1530 vlc_mutex_unlock( &p_sys->lock_control );
1531 return VLC_EGENERIC;
1536 const int i_index = ControlGetReducedIndexLocked( p_input );
1539 *pi_type = p_sys->control[i_index].i_type;
1540 *p_val = p_sys->control[i_index].val;
1542 p_sys->i_control -= i_index + 1;
1543 if( p_sys->i_control > 0 )
1544 memmove( &p_sys->control[0], &p_sys->control[i_index+1],
1545 sizeof(*p_sys->control) * p_sys->i_control );
1546 vlc_mutex_unlock( &p_sys->lock_control );
1550 static bool ControlIsSeekRequest( int i_type )
1554 case INPUT_CONTROL_SET_POSITION:
1555 case INPUT_CONTROL_SET_TIME:
1556 case INPUT_CONTROL_SET_TITLE:
1557 case INPUT_CONTROL_SET_TITLE_NEXT:
1558 case INPUT_CONTROL_SET_TITLE_PREV:
1559 case INPUT_CONTROL_SET_SEEKPOINT:
1560 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1561 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1562 case INPUT_CONTROL_SET_BOOKMARK:
1563 case INPUT_CONTROL_NAV_ACTIVATE:
1564 case INPUT_CONTROL_NAV_UP:
1565 case INPUT_CONTROL_NAV_DOWN:
1566 case INPUT_CONTROL_NAV_LEFT:
1567 case INPUT_CONTROL_NAV_RIGHT:
1574 static void ControlRelease( int i_type, vlc_value_t val )
1578 case INPUT_CONTROL_ADD_SUBTITLE:
1579 case INPUT_CONTROL_ADD_SLAVE:
1580 free( val.psz_string );
1589 static void ControlPause( input_thread_t *p_input, mtime_t i_control_date )
1591 int i_ret = VLC_SUCCESS;
1592 int i_state = PAUSE_S;
1594 if( p_input->p->b_can_pause )
1596 if( p_input->p->input.p_access )
1597 i_ret = access_Control( p_input->p->input.p_access,
1598 ACCESS_SET_PAUSE_STATE, true );
1600 i_ret = demux_Control( p_input->p->input.p_demux,
1601 DEMUX_SET_PAUSE_STATE, true );
1605 msg_Warn( p_input, "cannot set pause state" );
1611 i_ret = es_out_SetPauseState( p_input->p->p_es_out,
1612 p_input->p->b_can_pause, true,
1616 msg_Warn( p_input, "cannot set pause state at es_out level" );
1620 /* Switch to new state */
1621 input_ChangeState( p_input, i_state );
1624 static void ControlUnpause( input_thread_t *p_input, mtime_t i_control_date )
1626 int i_ret = VLC_SUCCESS;
1628 if( p_input->p->b_can_pause )
1630 if( p_input->p->input.p_access )
1631 i_ret = access_Control( p_input->p->input.p_access,
1632 ACCESS_SET_PAUSE_STATE, false );
1634 i_ret = demux_Control( p_input->p->input.p_demux,
1635 DEMUX_SET_PAUSE_STATE, false );
1638 /* FIXME What to do ? */
1639 msg_Warn( p_input, "cannot unset pause -> EOF" );
1640 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1644 /* Switch to play */
1645 input_ChangeState( p_input, PLAYING_S );
1649 es_out_SetPauseState( p_input->p->p_es_out, false, false, i_control_date );
1652 static bool Control( input_thread_t *p_input,
1653 int i_type, vlc_value_t val )
1655 const mtime_t i_control_date = mdate();
1656 /* FIXME b_force_update is abused, it should be carefully checked */
1657 bool b_force_update = false;
1660 return b_force_update;
1664 case INPUT_CONTROL_SET_DIE:
1665 msg_Dbg( p_input, "control: stopping input" );
1667 /* Mark all submodules to die */
1668 ObjectKillChildrens( VLC_OBJECT(p_input) );
1671 case INPUT_CONTROL_SET_POSITION:
1675 if( p_input->p->b_recording )
1677 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) ignored while recording" );
1680 f_pos = val.f_float;
1681 if( i_type != INPUT_CONTROL_SET_POSITION )
1682 f_pos += var_GetFloat( p_input, "position" );
1685 else if( f_pos > 1.0 )
1687 /* Reset the decoders states and clock sync (before calling the demuxer */
1688 es_out_SetTime( p_input->p->p_es_out, -1 );
1689 if( demux_Control( p_input->p->input.p_demux, DEMUX_SET_POSITION,
1690 f_pos, !p_input->p->b_fast_seek ) )
1692 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1693 "%2.1f%% failed", f_pos * 100 );
1697 if( p_input->p->i_slave > 0 )
1698 SlaveSeek( p_input );
1699 p_input->p->input.b_eof = false;
1701 b_force_update = true;
1706 case INPUT_CONTROL_SET_TIME:
1711 if( p_input->p->b_recording )
1713 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) ignored while recording" );
1717 i_time = val.i_time;
1718 if( i_type != INPUT_CONTROL_SET_TIME )
1719 i_time += var_GetTime( p_input, "time" );
1724 /* Reset the decoders states and clock sync (before calling the demuxer */
1725 es_out_SetTime( p_input->p->p_es_out, -1 );
1727 i_ret = demux_Control( p_input->p->input.p_demux,
1728 DEMUX_SET_TIME, i_time,
1729 !p_input->p->b_fast_seek );
1734 /* Emulate it with a SET_POS */
1735 if( !demux_Control( p_input->p->input.p_demux,
1736 DEMUX_GET_LENGTH, &i_length ) && i_length > 0 )
1738 double f_pos = (double)i_time / (double)i_length;
1739 i_ret = demux_Control( p_input->p->input.p_demux,
1740 DEMUX_SET_POSITION, f_pos,
1741 !p_input->p->b_fast_seek );
1746 msg_Warn( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) %"PRId64
1747 " failed or not possible", i_time );
1751 if( p_input->p->i_slave > 0 )
1752 SlaveSeek( p_input );
1753 p_input->p->input.b_eof = false;
1755 b_force_update = true;
1760 case INPUT_CONTROL_SET_STATE:
1761 if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1762 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1763 else if( p_input->p->i_state == PAUSE_S )
1765 ControlUnpause( p_input, i_control_date );
1767 b_force_update = true;
1769 else if( val.i_int == PAUSE_S && p_input->p->i_state == PLAYING_S /* &&
1770 p_input->p->b_can_pause */ )
1772 ControlPause( p_input, i_control_date );
1774 b_force_update = true;
1776 else if( val.i_int == PAUSE_S && !p_input->p->b_can_pause && 0 )
1778 b_force_update = true;
1780 /* Correct "state" value */
1781 input_ChangeState( p_input, p_input->p->i_state );
1785 case INPUT_CONTROL_SET_RATE:
1787 /* Get rate and direction */
1788 int i_rate = abs( val.i_int );
1789 int i_rate_sign = val.i_int < 0 ? -1 : 1;
1791 /* Check rate bound */
1792 if( i_rate < INPUT_RATE_MIN )
1794 msg_Dbg( p_input, "cannot set rate faster" );
1795 i_rate = INPUT_RATE_MIN;
1797 else if( i_rate > INPUT_RATE_MAX )
1799 msg_Dbg( p_input, "cannot set rate slower" );
1800 i_rate = INPUT_RATE_MAX;
1803 /* Apply direction */
1804 if( i_rate_sign < 0 )
1806 if( p_input->p->input.b_rescale_ts )
1808 msg_Dbg( p_input, "cannot set negative rate" );
1809 i_rate = p_input->p->i_rate;
1810 assert( i_rate > 0 );
1814 i_rate *= i_rate_sign;
1818 if( i_rate != INPUT_RATE_DEFAULT &&
1819 ( ( !p_input->p->b_can_rate_control && !p_input->p->input.b_rescale_ts ) ||
1820 ( p_input->p->p_sout && !p_input->p->b_out_pace_control ) ) )
1822 msg_Dbg( p_input, "cannot change rate" );
1823 i_rate = INPUT_RATE_DEFAULT;
1825 if( i_rate != p_input->p->i_rate &&
1826 !p_input->p->b_can_pace_control && p_input->p->b_can_rate_control )
1829 if( p_input->p->input.p_access )
1831 i_ret = VLC_EGENERIC;
1835 if( !p_input->p->input.b_rescale_ts )
1836 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1838 i_ret = demux_Control( p_input->p->input.p_demux,
1839 DEMUX_SET_RATE, &i_rate );
1843 msg_Warn( p_input, "ACCESS/DEMUX_SET_RATE failed" );
1844 i_rate = p_input->p->i_rate;
1849 if( i_rate != p_input->p->i_rate )
1851 p_input->p->i_rate = i_rate;
1852 input_SendEventRate( p_input, i_rate );
1854 if( p_input->p->input.b_rescale_ts )
1856 const int i_rate_source = (p_input->p->b_can_pace_control || p_input->p->b_can_rate_control ) ? i_rate : INPUT_RATE_DEFAULT;
1857 es_out_SetRate( p_input->p->p_es_out, i_rate_source, i_rate );
1860 b_force_update = true;
1865 case INPUT_CONTROL_SET_PROGRAM:
1866 /* No need to force update, es_out does it if needed */
1867 es_out_Control( p_input->p->p_es_out,
1868 ES_OUT_SET_GROUP, val.i_int );
1870 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1874 case INPUT_CONTROL_SET_ES:
1875 /* No need to force update, es_out does it if needed */
1876 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, val.i_int );
1879 case INPUT_CONTROL_RESTART_ES:
1880 es_out_Control( p_input->p->p_es_out_display, ES_OUT_RESTART_ES_BY_ID, val.i_int );
1883 case INPUT_CONTROL_SET_AUDIO_DELAY:
1884 input_SendEventAudioDelay( p_input, val.i_time );
1885 UpdatePtsDelay( p_input );
1888 case INPUT_CONTROL_SET_SPU_DELAY:
1889 input_SendEventSubtitleDelay( p_input, val.i_time );
1890 UpdatePtsDelay( p_input );
1893 case INPUT_CONTROL_SET_TITLE:
1894 case INPUT_CONTROL_SET_TITLE_NEXT:
1895 case INPUT_CONTROL_SET_TITLE_PREV:
1896 if( p_input->p->b_recording )
1898 msg_Err( p_input, "INPUT_CONTROL_SET_TITLE(*) ignored while recording" );
1901 if( p_input->p->input.b_title_demux &&
1902 p_input->p->input.i_title > 0 )
1905 /* FIXME handle demux title */
1906 demux_t *p_demux = p_input->p->input.p_demux;
1909 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1910 i_title = p_demux->info.i_title - 1;
1911 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1912 i_title = p_demux->info.i_title + 1;
1914 i_title = val.i_int;
1916 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1918 es_out_SetTime( p_input->p->p_es_out, -1 );
1920 demux_Control( p_demux, DEMUX_SET_TITLE, i_title );
1921 input_SendEventTitle( p_input, i_title );
1924 else if( p_input->p->input.i_title > 0 )
1926 access_t *p_access = p_input->p->input.p_access;
1929 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1930 i_title = p_access->info.i_title - 1;
1931 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1932 i_title = p_access->info.i_title + 1;
1934 i_title = val.i_int;
1936 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1938 es_out_SetTime( p_input->p->p_es_out, -1 );
1940 stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
1941 ACCESS_SET_TITLE, i_title );
1942 input_SendEventTitle( p_input, i_title );
1946 case INPUT_CONTROL_SET_SEEKPOINT:
1947 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1948 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1949 if( p_input->p->b_recording )
1951 msg_Err( p_input, "INPUT_CONTROL_SET_SEEKPOINT(*) ignored while recording" );
1955 if( p_input->p->input.b_title_demux &&
1956 p_input->p->input.i_title > 0 )
1958 demux_t *p_demux = p_input->p->input.p_demux;
1960 int64_t i_input_time;
1961 int64_t i_seekpoint_time;
1963 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1965 i_seekpoint = p_demux->info.i_seekpoint;
1966 i_seekpoint_time = p_input->p->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1967 i_input_time = var_GetTime( p_input, "time" );
1968 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
1970 if( i_input_time < i_seekpoint_time + 3000000 )
1976 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1977 i_seekpoint = p_demux->info.i_seekpoint + 1;
1979 i_seekpoint = val.i_int;
1981 if( i_seekpoint >= 0 && i_seekpoint <
1982 p_input->p->input.title[p_demux->info.i_title]->i_seekpoint )
1985 es_out_SetTime( p_input->p->p_es_out, -1 );
1987 demux_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1988 input_SendEventSeekpoint( p_input, p_demux->info.i_title, i_seekpoint );
1991 else if( p_input->p->input.i_title > 0 )
1993 access_t *p_access = p_input->p->input.p_access;
1995 int64_t i_input_time;
1996 int64_t i_seekpoint_time;
1998 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
2000 i_seekpoint = p_access->info.i_seekpoint;
2001 i_seekpoint_time = p_input->p->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
2002 i_input_time = var_GetTime( p_input, "time" );
2003 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
2005 if( i_input_time < i_seekpoint_time + 3000000 )
2011 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
2012 i_seekpoint = p_access->info.i_seekpoint + 1;
2014 i_seekpoint = val.i_int;
2016 if( i_seekpoint >= 0 && i_seekpoint <
2017 p_input->p->input.title[p_access->info.i_title]->i_seekpoint )
2019 es_out_SetTime( p_input->p->p_es_out, -1 );
2021 stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
2022 ACCESS_SET_SEEKPOINT, i_seekpoint );
2023 input_SendEventSeekpoint( p_input, p_access->info.i_title, i_seekpoint );
2028 case INPUT_CONTROL_ADD_SUBTITLE:
2029 if( val.psz_string )
2030 SubtitleAdd( p_input, val.psz_string, true );
2033 case INPUT_CONTROL_ADD_SLAVE:
2034 if( val.psz_string )
2036 const char *uri = val.psz_string;
2037 input_source_t *slave = InputSourceNew( p_input );
2039 if( slave && !InputSourceInit( p_input, slave, uri, NULL, false ) )
2045 msg_Dbg( p_input, "adding %s as slave on the fly", uri );
2048 if( demux_Control( p_input->p->input.p_demux,
2049 DEMUX_GET_TIME, &i_time ) )
2051 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2052 InputSourceClean( slave );
2056 if( demux_Control( slave->p_demux,
2057 DEMUX_SET_TIME, i_time, true ) )
2059 msg_Err( p_input, "seek failed for new slave" );
2060 InputSourceClean( slave );
2065 /* Get meta (access and demux) */
2066 p_meta = vlc_meta_New();
2069 access_Control( slave->p_access, ACCESS_GET_META, p_meta );
2070 demux_Control( slave->p_demux, DEMUX_GET_META, p_meta );
2071 InputUpdateMeta( p_input, p_meta );
2074 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, slave );
2079 msg_Warn( p_input, "failed to add %s as slave", uri );
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->p->i_state == PAUSE_S )
2109 es_out_SetFrameNext( p_input->p->p_es_out );
2111 else if( p_input->p->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 %"PRId64, 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 uint64_t i_size = stream_Size( p_input->p->input.p_stream );
2153 if( i_size > 0 && (uint64_t)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 );
2162 case INPUT_CONTROL_NAV_ACTIVATE:
2163 case INPUT_CONTROL_NAV_UP:
2164 case INPUT_CONTROL_NAV_DOWN:
2165 case INPUT_CONTROL_NAV_LEFT:
2166 case INPUT_CONTROL_NAV_RIGHT:
2167 demux_Control( p_input->p->input.p_demux, i_type
2168 - INPUT_CONTROL_NAV_ACTIVATE + DEMUX_NAV_ACTIVATE );
2172 msg_Err( p_input, "not yet implemented" );
2176 ControlRelease( i_type, val );
2177 return b_force_update;
2180 /*****************************************************************************
2181 * UpdateTitleSeekpoint
2182 *****************************************************************************/
2183 static int UpdateTitleSeekpoint( input_thread_t *p_input,
2184 int i_title, int i_seekpoint )
2186 int i_title_end = p_input->p->input.i_title_end -
2187 p_input->p->input.i_title_offset;
2188 int i_seekpoint_end = p_input->p->input.i_seekpoint_end -
2189 p_input->p->input.i_seekpoint_offset;
2191 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
2193 if( i_title > i_title_end ||
2194 ( i_title == i_title_end && i_seekpoint > i_seekpoint_end ) )
2197 else if( i_seekpoint_end >= 0 )
2199 if( i_seekpoint > i_seekpoint_end )
2202 else if( i_title_end >= 0 )
2204 if( i_title > i_title_end )
2209 /*****************************************************************************
2211 *****************************************************************************/
2212 static int UpdateTitleSeekpointFromDemux( input_thread_t *p_input )
2214 demux_t *p_demux = p_input->p->input.p_demux;
2216 /* TODO event-like */
2217 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
2219 input_SendEventTitle( p_input, p_demux->info.i_title );
2221 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
2223 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
2225 input_SendEventSeekpoint( p_input,
2226 p_demux->info.i_title, p_demux->info.i_seekpoint );
2228 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2231 /* Hmmm only works with master input */
2232 if( p_input->p->input.p_demux == p_demux )
2233 return UpdateTitleSeekpoint( p_input,
2234 p_demux->info.i_title,
2235 p_demux->info.i_seekpoint );
2239 static void UpdateGenericFromDemux( input_thread_t *p_input )
2241 demux_t *p_demux = p_input->p->input.p_demux;
2243 if( p_demux->info.i_update & INPUT_UPDATE_META )
2245 vlc_meta_t *p_meta = vlc_meta_New();
2248 demux_Control( p_input->p->input.p_demux, DEMUX_GET_META, p_meta );
2249 InputUpdateMeta( p_input, p_meta );
2251 p_demux->info.i_update &= ~INPUT_UPDATE_META;
2254 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
2257 static void UpdateTitleListfromDemux( input_thread_t *p_input )
2259 input_source_t *in = &p_input->p->input;
2261 /* Delete the preexisting titles */
2262 if( in->i_title > 0 )
2264 for( int i = 0; i < in->i_title; i++ )
2265 vlc_input_title_Delete( in->title[i] );
2266 TAB_CLEAN( in->i_title, in->title );
2267 in->b_title_demux = false;
2270 /* Get the new title list */
2271 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2272 &in->title, &in->i_title,
2273 &in->i_title_offset, &in->i_seekpoint_offset ) )
2274 TAB_INIT( in->i_title, in->title );
2276 in->b_title_demux = true;
2278 InitTitle( p_input );
2282 /*****************************************************************************
2283 * Update*FromAccess:
2284 *****************************************************************************/
2285 static int UpdateTitleSeekpointFromAccess( input_thread_t *p_input )
2287 access_t *p_access = p_input->p->input.p_access;
2289 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
2291 input_SendEventTitle( p_input, p_access->info.i_title );
2293 stream_Control( p_input->p->input.p_stream, STREAM_UPDATE_SIZE );
2295 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
2297 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
2299 input_SendEventSeekpoint( p_input,
2300 p_access->info.i_title, p_access->info.i_seekpoint );
2302 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2304 /* Hmmm only works with master input */
2305 if( p_input->p->input.p_access == p_access )
2306 return UpdateTitleSeekpoint( p_input,
2307 p_access->info.i_title,
2308 p_access->info.i_seekpoint );
2311 static void UpdateGenericFromAccess( input_thread_t *p_input )
2313 access_t *p_access = p_input->p->input.p_access;
2315 if( p_access->info.i_update & INPUT_UPDATE_META )
2317 /* TODO maybe multi - access ? */
2318 vlc_meta_t *p_meta = vlc_meta_New();
2321 access_Control( p_input->p->input.p_access, ACCESS_GET_META, p_meta );
2322 InputUpdateMeta( p_input, p_meta );
2324 p_access->info.i_update &= ~INPUT_UPDATE_META;
2326 if( p_access->info.i_update & INPUT_UPDATE_SIGNAL )
2331 if( access_Control( p_access, ACCESS_GET_SIGNAL, &f_quality, &f_strength ) )
2332 f_quality = f_strength = -1;
2334 input_SendEventSignal( p_input, f_quality, f_strength );
2336 p_access->info.i_update &= ~INPUT_UPDATE_SIGNAL;
2339 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
2342 /*****************************************************************************
2344 *****************************************************************************/
2345 static input_source_t *InputSourceNew( input_thread_t *p_input )
2347 VLC_UNUSED(p_input);
2349 return calloc( 1, sizeof( input_source_t ) );
2352 /*****************************************************************************
2354 *****************************************************************************/
2355 static int InputSourceInit( input_thread_t *p_input,
2356 input_source_t *in, const char *psz_mrl,
2357 const char *psz_forced_demux, bool b_in_can_fail )
2359 const char *psz_access, *psz_demux, *psz_path, *psz_anchor = NULL;
2360 char *psz_var_demux = NULL;
2364 char *psz_dup = strdup( psz_mrl );
2366 if( psz_dup == NULL )
2370 input_SplitMRL( &psz_access, &psz_demux, &psz_path, &psz_anchor, psz_dup );
2372 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
2373 psz_mrl, psz_access, psz_demux, psz_path );
2374 if( !p_input->b_preparsing )
2376 /* Find optional titles and seekpoints */
2377 MRLSections( psz_anchor, &in->i_title_start, &in->i_title_end,
2378 &in->i_seekpoint_start, &in->i_seekpoint_end );
2379 if( psz_forced_demux && *psz_forced_demux )
2381 psz_demux = psz_forced_demux;
2383 else if( *psz_demux == '\0' )
2385 /* special hack for forcing a demuxer with --demux=module
2386 * (and do nothing with a list) */
2387 psz_var_demux = var_GetNonEmptyString( p_input, "demux" );
2389 if( psz_var_demux != NULL &&
2390 !strchr(psz_var_demux, ',' ) &&
2391 !strchr(psz_var_demux, ':' ) )
2393 psz_demux = psz_var_demux;
2395 msg_Dbg( p_input, "enforced demux ` %s'", psz_demux );
2399 /* Try access_demux first */
2400 in->p_demux = demux_New( p_input, p_input, psz_access, psz_demux, psz_path,
2401 NULL, p_input->p->p_es_out, false );
2405 /* Preparsing is only for file:// */
2408 if( strcmp( psz_access, "file" ) )
2410 msg_Dbg( p_input, "trying to pre-parse %s", psz_path );
2415 /* Get infos from access_demux */
2416 in->b_title_demux = true;
2417 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2418 &in->title, &in->i_title,
2419 &in->i_title_offset, &in->i_seekpoint_offset ) )
2421 TAB_INIT( in->i_title, in->title );
2423 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
2424 &in->b_can_pace_control ) )
2425 in->b_can_pace_control = false;
2427 assert( in->p_demux->pf_demux != NULL || !in->b_can_pace_control );
2429 if( !in->b_can_pace_control )
2431 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_RATE,
2432 &in->b_can_rate_control, &in->b_rescale_ts ) )
2434 in->b_can_rate_control = false;
2435 in->b_rescale_ts = true; /* not used */
2440 in->b_can_rate_control = true;
2441 in->b_rescale_ts = true;
2443 if( demux_Control( in->p_demux, DEMUX_CAN_PAUSE,
2444 &in->b_can_pause ) )
2445 in->b_can_pause = false;
2446 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2447 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2448 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control && in->b_can_rate_control );
2451 if( demux_Control( in->p_demux, DEMUX_CAN_SEEK, &b_can_seek ) )
2453 var_SetBool( p_input, "can-seek", b_can_seek );
2457 /* Now try a real access */
2458 in->p_access = access_New( p_input, p_input, psz_access, psz_demux, psz_path );
2459 if( in->p_access == NULL )
2461 if( vlc_object_alive( p_input ) )
2463 msg_Err( p_input, "open of `%s' failed", psz_mrl );
2464 if( !b_in_can_fail )
2465 dialog_Fatal( p_input, _("Your input can't be opened"),
2466 _("VLC is unable to open the MRL '%s'."
2467 " Check the log for details."), psz_mrl );
2472 /* Get infos from access */
2473 if( !p_input->b_preparsing )
2477 in->b_title_demux = false;
2478 if( access_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2479 &in->title, &in->i_title,
2480 &in->i_title_offset, &in->i_seekpoint_offset ) )
2483 TAB_INIT( in->i_title, in->title );
2485 access_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2486 &in->b_can_pace_control );
2487 in->b_can_rate_control = in->b_can_pace_control;
2488 in->b_rescale_ts = true;
2490 access_Control( in->p_access, ACCESS_CAN_PAUSE, &in->b_can_pause );
2491 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2492 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2493 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control );
2495 access_Control( in->p_access, ACCESS_CAN_SEEK, &b_can_seek );
2496 var_SetBool( p_input, "can-seek", b_can_seek );
2501 char **ppsz_input_list;
2503 TAB_INIT( i_input_list, ppsz_input_list );
2505 /* On master stream only, use input-list */
2506 if( &p_input->p->input == in )
2512 psz_parser = var_CreateGetNonEmptyString( p_input, "input-list" );
2514 while( psz_parser && *psz_parser )
2516 char *p = strchr( psz_parser, ',' );
2522 char *psz_name = strdup( psz_parser );
2524 TAB_APPEND( i_input_list, ppsz_input_list, psz_name );
2531 /* Autodetect extra files if none specified */
2532 if( i_input_list <= 0 )
2534 InputGetExtraFiles( p_input, &i_input_list, &ppsz_input_list,
2535 psz_access, psz_path );
2537 if( i_input_list > 0 )
2538 TAB_APPEND( i_input_list, ppsz_input_list, NULL );
2540 /* Create the stream_t */
2541 in->p_stream = stream_AccessNew( in->p_access, ppsz_input_list );
2542 if( ppsz_input_list )
2544 for( int i = 0; ppsz_input_list[i] != NULL; i++ )
2545 free( ppsz_input_list[i] );
2546 TAB_CLEAN( i_input_list, ppsz_input_list );
2549 if( in->p_stream == NULL )
2551 msg_Warn( p_input, "cannot create a stream_t from access" );
2555 /* Add stream filters */
2556 char *psz_stream_filter = var_GetNonEmptyString( p_input,
2558 in->p_stream = stream_FilterChainNew( in->p_stream,
2560 var_GetBool( p_input, "input-record-native" ) );
2561 free( psz_stream_filter );
2563 /* Open a demuxer */
2564 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2566 psz_demux = in->p_access->psz_demux;
2569 in->p_demux = demux_New( p_input, p_input, psz_access, psz_demux,
2570 /* Take access/stream redirections into account: */
2571 in->p_stream->psz_path ? in->p_stream->psz_path : psz_path,
2572 in->p_stream, p_input->p->p_es_out,
2573 p_input->b_preparsing );
2575 if( in->p_demux == NULL )
2577 if( vlc_object_alive( p_input ) )
2579 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2580 psz_access, psz_demux, psz_path );
2581 if( !b_in_can_fail )
2582 dialog_Fatal( VLC_OBJECT( p_input ),
2583 _("VLC can't recognize the input's format"),
2584 _("The format of '%s' cannot be detected. "
2585 "Have a look at the log for details."), psz_mrl );
2589 assert( in->p_demux->pf_demux != NULL );
2591 /* Get title from demux */
2592 if( !p_input->b_preparsing && in->i_title <= 0 )
2594 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2595 &in->title, &in->i_title,
2596 &in->i_title_offset, &in->i_seekpoint_offset ))
2598 TAB_INIT( in->i_title, in->title );
2602 in->b_title_demux = true;
2607 free( psz_var_demux );
2610 /* Set record capabilities */
2611 if( demux_Control( in->p_demux, DEMUX_CAN_RECORD, &in->b_can_stream_record ) )
2612 in->b_can_stream_record = false;
2614 if( !var_GetBool( p_input, "input-record-native" ) )
2615 in->b_can_stream_record = false;
2616 var_SetBool( p_input, "can-record", true );
2618 var_SetBool( p_input, "can-record", in->b_can_stream_record );
2622 * FIXME improve for b_preparsing: move it after GET_META and check psz_arturl */
2623 if( !p_input->b_preparsing )
2626 input_attachment_t **attachment;
2627 if( !demux_Control( in->p_demux, DEMUX_GET_ATTACHMENTS,
2628 &attachment, &i_attachment ) )
2630 vlc_mutex_lock( &p_input->p->p_item->lock );
2631 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2632 i_attachment, attachment );
2633 vlc_mutex_unlock( &p_input->p->p_item->lock );
2636 /* PTS delay: request from demux first. This is required for
2637 * access_demux and some special cases like SDP demux. Otherwise,
2638 * fallback to access */
2639 if( demux_Control( in->p_demux, DEMUX_GET_PTS_DELAY,
2640 &in->i_pts_delay ) )
2642 /* GET_PTS_DELAY is mandatory for access_demux */
2643 assert( in->p_access );
2644 access_Control( in->p_access,
2645 ACCESS_GET_PTS_DELAY, &in->i_pts_delay );
2647 if( in->i_pts_delay > INPUT_PTS_DELAY_MAX )
2648 in->i_pts_delay = INPUT_PTS_DELAY_MAX;
2649 else if( in->i_pts_delay < 0 )
2650 in->i_pts_delay = 0;
2653 if( !demux_Control( in->p_demux, DEMUX_GET_FPS, &f_fps ) && f_fps > 0.0 )
2655 vlc_mutex_lock( &p_input->p->p_item->lock );
2656 p_input->p->f_fps = f_fps;
2657 vlc_mutex_unlock( &p_input->p->p_item->lock );
2660 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2661 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2667 demux_Delete( in->p_demux );
2670 stream_Delete( in->p_stream );
2672 free( psz_var_demux );
2675 return VLC_EGENERIC;
2678 /*****************************************************************************
2680 *****************************************************************************/
2681 static void InputSourceClean( input_source_t *in )
2686 demux_Delete( in->p_demux );
2689 stream_Delete( in->p_stream );
2691 if( in->i_title > 0 )
2693 for( i = 0; i < in->i_title; i++ )
2694 vlc_input_title_Delete( in->title[i] );
2695 TAB_CLEAN( in->i_title, in->title );
2699 /*****************************************************************************
2701 *****************************************************************************/
2702 static void InputSourceMeta( input_thread_t *p_input,
2703 input_source_t *p_source, vlc_meta_t *p_meta )
2705 access_t *p_access = p_source->p_access;
2706 demux_t *p_demux = p_source->p_demux;
2708 /* XXX Remember that checking against p_item->p_meta->i_status & ITEM_PREPARSED
2713 /* Read access meta */
2714 has_meta = p_access && !access_Control( p_access, ACCESS_GET_META, p_meta );
2716 /* Read demux meta */
2717 has_meta |= !demux_Control( p_demux, DEMUX_GET_META, p_meta );
2719 bool has_unsupported;
2720 if( demux_Control( p_demux, DEMUX_HAS_UNSUPPORTED_META, &has_unsupported ) )
2721 has_unsupported = true;
2723 /* If the demux report unsupported meta data, or if we don't have meta data
2724 * try an external "meta reader" */
2725 if( has_meta && !has_unsupported )
2728 demux_meta_t *p_demux_meta =
2729 vlc_custom_create( p_demux, sizeof( *p_demux_meta ), "demux meta" );
2732 p_demux_meta->p_demux = p_demux;
2733 p_demux_meta->p_item = p_input->p->p_item;
2735 module_t *p_id3 = module_need( p_demux_meta, "meta reader", NULL, false );
2738 if( p_demux_meta->p_meta )
2740 vlc_meta_Merge( p_meta, p_demux_meta->p_meta );
2741 vlc_meta_Delete( p_demux_meta->p_meta );
2744 if( p_demux_meta->i_attachments > 0 )
2746 vlc_mutex_lock( &p_input->p->p_item->lock );
2747 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2748 p_demux_meta->i_attachments, p_demux_meta->attachments );
2749 vlc_mutex_unlock( &p_input->p->p_item->lock );
2751 module_unneed( p_demux, p_id3 );
2753 vlc_object_release( p_demux_meta );
2757 static void SlaveDemux( input_thread_t *p_input, bool *pb_demux_polled )
2762 *pb_demux_polled = false;
2763 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2765 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2769 for( i = 0; i < p_input->p->i_slave; i++ )
2771 input_source_t *in = p_input->p->slave[i];
2777 const bool b_demux_polled = in->p_demux->pf_demux != NULL;
2778 if( !b_demux_polled )
2781 *pb_demux_polled = true;
2783 /* Call demux_Demux until we have read enough data */
2784 if( demux_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2789 if( demux_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2791 msg_Err( p_input, "slave[%d] doesn't like "
2792 "DEMUX_GET_TIME -> EOF", i );
2797 if( i_stime >= i_time )
2803 if( ( i_ret = demux_Demux( in->p_demux ) ) <= 0 )
2809 i_ret = demux_Demux( in->p_demux );
2814 msg_Dbg( p_input, "slave %d EOF", i );
2820 static void SlaveSeek( input_thread_t *p_input )
2825 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2827 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2831 for( i = 0; i < p_input->p->i_slave; i++ )
2833 input_source_t *in = p_input->p->slave[i];
2835 if( demux_Control( in->p_demux, DEMUX_SET_TIME, i_time, true ) )
2838 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2848 /*****************************************************************************
2850 *****************************************************************************/
2851 static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta )
2853 static const struct { int i_meta; const char *psz_name; } p_list[] = {
2854 { vlc_meta_Title, "meta-title" },
2855 { vlc_meta_Artist, "meta-artist" },
2856 { vlc_meta_Genre, "meta-genre" },
2857 { vlc_meta_Copyright, "meta-copyright" },
2858 { vlc_meta_Description, "meta-description" },
2859 { vlc_meta_Date, "meta-date" },
2860 { vlc_meta_URL, "meta-url" },
2864 /* Get meta information from user */
2865 for( int i = 0; p_list[i].psz_name; i++ )
2867 char *psz_string = var_GetNonEmptyString( p_input, p_list[i].psz_name );
2871 EnsureUTF8( psz_string );
2872 vlc_meta_Set( p_meta, p_list[i].i_meta, psz_string );
2877 /*****************************************************************************
2878 * InputUpdateMeta: merge p_item meta data with p_meta taking care of
2879 * arturl and locking issue.
2880 *****************************************************************************/
2881 static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta )
2883 es_out_ControlSetMeta( p_input->p->p_es_out, p_meta );
2884 vlc_meta_Delete( p_meta );
2887 static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
2888 int i_new, input_attachment_t **pp_new )
2890 int i_attachment = *pi_attachment;
2891 input_attachment_t **attachment = *ppp_attachment;
2894 attachment = xrealloc( attachment,
2895 sizeof(input_attachment_t**) * ( i_attachment + i_new ) );
2896 for( i = 0; i < i_new; i++ )
2897 attachment[i_attachment++] = pp_new[i];
2901 *pi_attachment = i_attachment;
2902 *ppp_attachment = attachment;
2904 /*****************************************************************************
2905 * InputGetExtraFiles
2906 * Autodetect extra input list
2907 *****************************************************************************/
2908 static void InputGetExtraFilesPattern( input_thread_t *p_input,
2909 int *pi_list, char ***pppsz_list,
2910 const char *psz_path,
2911 const char *psz_match,
2912 const char *psz_format,
2913 int i_start, int i_stop )
2918 TAB_INIT( i_list, ppsz_list );
2920 char *psz_base = strdup( psz_path );
2924 /* Remove the extension */
2925 char *psz_end = &psz_base[strlen(psz_base)-strlen(psz_match)];
2926 assert( psz_end >= psz_base);
2929 /* Try to list files */
2930 for( int i = i_start; i <= i_stop; i++ )
2935 if( asprintf( &psz_file, psz_format, psz_base, i ) < 0 )
2938 char *psz_tmp_path = get_path( psz_file );
2940 if( vlc_stat( psz_tmp_path, &st ) || !S_ISREG( st.st_mode ) || !st.st_size )
2943 free( psz_tmp_path );
2947 msg_Dbg( p_input, "Detected extra file `%s'", psz_file );
2948 TAB_APPEND( i_list, ppsz_list, psz_file );
2949 free( psz_tmp_path );
2954 *pppsz_list = ppsz_list;
2957 static void InputGetExtraFiles( input_thread_t *p_input,
2958 int *pi_list, char ***pppsz_list,
2959 const char *psz_access, const char *psz_path )
2963 const char *psz_match;
2964 const char *psz_format;
2968 /* XXX the order is important */
2969 { ".001", "%s.%.3d", 2, 999 },
2970 { NULL, NULL, 0, 0 }
2973 TAB_INIT( *pi_list, *pppsz_list );
2975 if( ( psz_access && *psz_access && strcmp( psz_access, "file" ) ) || !psz_path )
2978 const size_t i_path = strlen(psz_path);
2980 for( int i = 0; p_pattern[i].psz_match != NULL; i++ )
2982 const size_t i_ext = strlen(p_pattern[i].psz_match );
2984 if( i_path < i_ext )
2986 if( !strcmp( &psz_path[i_path-i_ext], p_pattern[i].psz_match ) )
2988 InputGetExtraFilesPattern( p_input, pi_list, pppsz_list,
2990 p_pattern[i].psz_match, p_pattern[i].psz_format,
2991 p_pattern[i].i_start, p_pattern[i].i_stop );
2998 static void input_ChangeState( input_thread_t *p_input, int i_state )
3000 const bool b_changed = p_input->p->i_state != i_state;
3002 p_input->p->i_state = i_state;
3003 if( i_state == ERROR_S )
3004 p_input->b_error = true;
3005 else if( i_state == END_S )
3006 p_input->b_eof = true;
3010 input_item_SetErrorWhenReading( p_input->p->p_item, p_input->b_error );
3011 input_SendEventState( p_input, i_state );
3016 /*****************************************************************************
3017 * MRLSplit: parse the access, demux and url part of the
3018 * Media Resource Locator.
3019 *****************************************************************************/
3020 void input_SplitMRL( const char **access, const char **demux,
3021 const char **path, const char **anchor, char *buf )
3025 /* Separate <path> from <access>[/<demux>]:// */
3026 p = strstr( buf, "://" );
3030 p += 3; /* skips "://" */
3033 /* Remove HTML anchor if present (not supported).
3034 * The hash symbol itself should be URI-encoded. */
3035 p = strchr( p, '#' );
3047 fprintf( stderr, "%s(\"%s\") probably not a valid URI!\n", __func__,
3050 /* Note: this is a valid non const pointer to "": */
3051 *path = buf + strlen( buf );
3054 /* Separate access from demux */
3055 p = strchr( buf, '/' );
3066 /* We really don't want module name substitution here! */
3073 static const char *MRLSeekPoint( const char *str, int *title, int *chapter )
3078 /* Look for the title */
3079 u = strtoul( str, &end, 0 );
3080 *title = (str == end || u > (unsigned long)INT_MAX) ? -1 : (int)u;
3083 /* Look for the chapter */
3087 u = strtoul( str, &end, 0 );
3088 *chapter = (str == end || u > (unsigned long)INT_MAX) ? -1 : (int)u;
3098 /*****************************************************************************
3099 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
3102 * [url][@[title_start][:chapter_start][-[title_end][:chapter_end]]]
3103 *****************************************************************************/
3104 static void MRLSections( const char *p,
3105 int *pi_title_start, int *pi_title_end,
3106 int *pi_chapter_start, int *pi_chapter_end )
3108 *pi_title_start = *pi_title_end = *pi_chapter_start = *pi_chapter_end = -1;
3110 int title_start, chapter_start, title_end, chapter_end;
3116 p = MRLSeekPoint( p, &title_start, &chapter_start );
3118 title_start = chapter_start = -1;
3121 p = MRLSeekPoint( p + 1, &title_end, &chapter_end );
3123 title_end = chapter_end = -1;
3125 if( *p ) /* syntax error */
3128 *pi_title_start = title_start;
3129 *pi_title_end = title_end;
3130 *pi_chapter_start = chapter_start;
3131 *pi_chapter_end = chapter_end;
3134 /*****************************************************************************
3135 * input_AddSubtitles: add a subtitle file and enable it
3136 *****************************************************************************/
3137 static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, unsigned i_flags )
3139 input_source_t *sub;
3142 char *psz_path, *psz_extension;
3144 /* if we are provided a subtitle.sub file,
3145 * see if we don't have a subtitle.idx and use it instead */
3146 psz_path = strdup( psz_subtitle );
3149 psz_extension = strrchr( psz_path, '.');
3150 if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
3154 strcpy( psz_extension, ".idx" );
3156 if( !vlc_stat( psz_path, &st ) && S_ISREG( st.st_mode ) )
3158 msg_Dbg( p_input, "using %s as subtitle file instead of %s",
3159 psz_path, psz_subtitle );
3160 strcpy( psz_subtitle, psz_path );
3166 char *url = vlc_path2uri( psz_subtitle, NULL );
3168 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
3170 sub = InputSourceNew( p_input );
3172 || InputSourceInit( p_input, sub, url, "subtitle", (i_flags & SUB_CANFAIL) ) )
3179 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
3182 if( (i_flags & SUB_FORCED) && !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
3184 if( count.i_int == 0 )
3186 /* if it was first one, there is disable too */
3188 if( count.i_int < list.p_list->i_count )
3190 const int i_id = list.p_list->p_values[count.i_int].i_int;
3192 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_DEFAULT_BY_ID, i_id );
3193 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, i_id );
3195 var_FreeList( &list, NULL );
3199 /*****************************************************************************
3201 *****************************************************************************/
3202 void input_UpdateStatistic( input_thread_t *p_input,
3203 input_statistic_t i_type, int i_delta )
3205 assert( p_input->p->i_state != INIT_S );
3207 vlc_mutex_lock( &p_input->p->counters.counters_lock);
3210 #define I(c) stats_Update( p_input->p->counters.c, i_delta, NULL )
3211 case INPUT_STATISTIC_DECODED_VIDEO:
3214 case INPUT_STATISTIC_DECODED_AUDIO:
3217 case INPUT_STATISTIC_DECODED_SUBTITLE:
3220 case INPUT_STATISTIC_SENT_PACKET:
3221 I(p_sout_sent_packets);
3224 case INPUT_STATISTIC_SENT_BYTE:
3228 stats_Update( p_input->p->counters.p_sout_sent_bytes, i_delta, &bytes );
3229 stats_Update( p_input->p->counters.p_sout_send_bitrate, bytes, NULL );
3233 msg_Err( p_input, "Invalid statistic type %d (internal error)", i_type );
3236 vlc_mutex_unlock( &p_input->p->counters.counters_lock);
3240 /* TODO FIXME nearly the same logic that snapshot code */
3241 char *input_CreateFilename( vlc_object_t *p_obj, const char *psz_path, const char *psz_prefix, const char *psz_extension )
3246 path = vlc_opendir( psz_path );
3251 char *psz_tmp = str_format( pl_Get(p_obj), psz_prefix );
3255 filename_sanitize( psz_tmp );
3257 if( asprintf( &psz_file, "%s"DIR_SEP"%s%s%s",
3259 psz_extension ? "." : "",
3260 psz_extension ? psz_extension : "" ) < 0 )
3267 psz_file = str_format( pl_Get(p_obj), psz_path );
3268 path_sanitize( psz_file );