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"
49 #include "../stream_output/stream_output.h"
51 #include <vlc_dialog.h>
53 #include <vlc_charset.h>
54 #include <vlc_strings.h>
56 #ifdef HAVE_SYS_STAT_H
57 # include <sys/stat.h>
60 /*****************************************************************************
62 *****************************************************************************/
63 static void Destructor( input_thread_t * p_input );
65 static void *Run ( vlc_object_t *p_this );
66 static void *RunAndDestroy ( vlc_object_t *p_this );
68 static input_thread_t * Create ( vlc_object_t *, input_item_t *,
69 const char *, bool, input_resource_t * );
70 static int Init ( 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 ControlPop( 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 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 );
108 static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_forced );
110 static void input_ChangeState( input_thread_t *p_input, int i_state ); /* TODO fix name */
112 /*****************************************************************************
113 * This function creates a new input, and returns a pointer
114 * to its description. On error, it returns NULL.
116 * XXX Do not forget to update vlc_input.h if you add new variables.
117 *****************************************************************************/
118 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
119 const char *psz_header, bool b_quick,
120 input_resource_t *p_resource )
122 static const char input_name[] = "input";
123 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 p_input->b_preparsing = b_quick;
152 p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
154 /* Init Common fields */
155 p_input->b_eof = false;
156 p_input->p->b_can_pace_control = true;
157 p_input->p->i_start = 0;
158 p_input->p->i_time = 0;
159 p_input->p->i_stop = 0;
160 p_input->p->i_run = 0;
161 p_input->p->i_title = 0;
162 p_input->p->title = NULL;
163 p_input->p->i_title_offset = p_input->p->i_seekpoint_offset = 0;
164 p_input->p->i_state = INIT_S;
165 p_input->p->i_rate = INPUT_RATE_DEFAULT;
166 p_input->p->b_recording = false;
167 memset( &p_input->p->bookmark, 0, sizeof(p_input->p->bookmark) );
168 TAB_INIT( p_input->p->i_bookmark, p_input->p->pp_bookmark );
169 TAB_INIT( p_input->p->i_attachment, p_input->p->attachment );
170 p_input->p->p_es_out_display = NULL;
171 p_input->p->p_es_out = NULL;
172 p_input->p->p_sout = NULL;
173 p_input->p->b_out_pace_control = false;
175 vlc_gc_incref( p_item ); /* Released in Destructor() */
176 p_input->p->p_item = p_item;
178 /* Init Input fields */
179 p_input->p->input.p_access = NULL;
180 p_input->p->input.p_stream = NULL;
181 p_input->p->input.p_demux = NULL;
182 p_input->p->input.b_title_demux = false;
183 p_input->p->input.i_title = 0;
184 p_input->p->input.title = NULL;
185 p_input->p->input.i_title_offset = p_input->p->input.i_seekpoint_offset = 0;
186 p_input->p->input.b_can_pace_control = true;
187 p_input->p->input.b_can_rate_control = true;
188 p_input->p->input.b_rescale_ts = true;
189 p_input->p->input.b_eof = false;
191 vlc_mutex_lock( &p_item->lock );
193 if( !p_item->p_stats )
194 p_item->p_stats = stats_NewInputStats( p_input );
195 vlc_mutex_unlock( &p_item->lock );
198 p_input->p->i_slave = 0;
199 p_input->p->slave = NULL;
203 p_input->p->p_resource = p_resource;
205 p_input->p->p_resource = input_resource_New();
206 input_resource_SetInput( p_input->p->p_resource, p_input );
208 /* Init control buffer */
209 vlc_mutex_init( &p_input->p->lock_control );
210 vlc_cond_init( &p_input->p->wait_control );
211 p_input->p->i_control = 0;
212 p_input->p->b_abort = false;
214 /* Parse input options */
215 vlc_mutex_lock( &p_item->lock );
216 assert( (int)p_item->optflagc == p_item->i_options );
217 for( i = 0; i < p_item->i_options; i++ )
218 var_OptionParse( VLC_OBJECT(p_input), p_item->ppsz_options[i],
219 !!(p_item->optflagv[i] & VLC_INPUT_OPTION_TRUSTED) );
220 vlc_mutex_unlock( &p_item->lock );
222 /* Create Object Variables for private use only */
223 input_ConfigVarInit( p_input );
225 /* Create Objects variables for public Get and Set */
226 input_ControlVarInit( p_input );
229 if( !p_input->b_preparsing )
231 char *psz_bookmarks = var_GetNonEmptyString( p_input, "bookmarks" );
234 /* FIXME: have a common cfg parsing routine used by sout and others */
235 char *psz_parser, *psz_start, *psz_end;
236 psz_parser = psz_bookmarks;
237 while( (psz_start = strchr( psz_parser, '{' ) ) )
239 seekpoint_t *p_seekpoint;
242 psz_end = strchr( psz_start, '}' );
243 if( !psz_end ) break;
244 psz_parser = psz_end + 1;
245 backup = *psz_parser;
249 p_seekpoint = vlc_seekpoint_New();
250 while( (psz_end = strchr( psz_start, ',' ) ) )
253 if( !strncmp( psz_start, "name=", 5 ) )
255 p_seekpoint->psz_name = strdup(psz_start + 5);
257 else if( !strncmp( psz_start, "bytes=", 6 ) )
259 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
261 else if( !strncmp( psz_start, "time=", 5 ) )
263 p_seekpoint->i_time_offset = atoll(psz_start + 5) *
266 psz_start = psz_end + 1;
268 msg_Dbg( p_input, "adding bookmark: %s, bytes=%"PRId64", time=%"PRId64,
269 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
270 p_seekpoint->i_time_offset );
271 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
272 vlc_seekpoint_Delete( p_seekpoint );
273 *psz_parser = backup;
275 free( psz_bookmarks );
279 /* Remove 'Now playing' info as it is probably outdated */
280 input_item_SetNowPlaying( p_item, NULL );
281 input_SendEventMeta( p_input );
284 if( p_input->b_preparsing )
285 p_input->i_flags |= OBJECT_FLAGS_QUIET | OBJECT_FLAGS_NOINTERACT;
288 memset( &p_input->p->counters, 0, sizeof( p_input->p->counters ) );
289 vlc_mutex_init( &p_input->p->counters.counters_lock );
291 /* Set the destructor when we are sure we are initialized */
292 vlc_object_set_destructor( p_input, (vlc_destructor_t)Destructor );
294 /* Attach only once we are ready */
295 vlc_object_attach( p_input, p_parent );
301 * Input destructor (called when the object's refcount reaches 0).
303 static void Destructor( input_thread_t * p_input )
306 char * psz_name = input_item_GetName( p_input->p->p_item );
307 msg_Dbg( p_input, "Destroying the input for '%s'", psz_name);
311 stats_TimerDump( p_input, STATS_TIMER_INPUT_LAUNCHING );
312 stats_TimerClean( p_input, STATS_TIMER_INPUT_LAUNCHING );
314 if( p_input->p->p_resource )
315 input_resource_Delete( p_input->p->p_resource );
317 vlc_gc_decref( p_input->p->p_item );
319 vlc_mutex_destroy( &p_input->p->counters.counters_lock );
321 vlc_cond_destroy( &p_input->p->wait_control );
322 vlc_mutex_destroy( &p_input->p->lock_control );
327 * Initialize an input thread and run it. You will need to monitor the
328 * thread to clean up after it is done
330 * \param p_parent a vlc_object
331 * \param p_item an input item
332 * \return a pointer to the spawned input thread
334 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
335 input_item_t *p_item )
337 return __input_CreateThreadExtended( p_parent, p_item, NULL, NULL );
341 input_thread_t *__input_CreateThreadExtended( vlc_object_t *p_parent,
342 input_item_t *p_item,
343 const char *psz_log, input_resource_t *p_resource )
345 input_thread_t *p_input;
347 p_input = Create( p_parent, p_item, psz_log, false, p_resource );
351 /* Create thread and wait for its readiness. */
352 if( vlc_thread_create( p_input, "input", Run,
353 VLC_THREAD_PRIORITY_INPUT ) )
355 input_ChangeState( p_input, ERROR_S );
356 msg_Err( p_input, "cannot create input thread" );
357 vlc_object_detach( p_input );
358 vlc_object_release( p_input );
366 * Initialize an input thread and run it. This thread will clean after itself,
367 * you can forget about it. It can work either in blocking or non-blocking mode
369 * \param p_parent a vlc_object
370 * \param p_item an input item
371 * \param b_block should we block until read is finished ?
372 * \return an error code, VLC_SUCCESS on success
374 int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
377 input_thread_t *p_input;
379 p_input = Create( p_parent, p_item, NULL, false, NULL );
385 RunAndDestroy( VLC_OBJECT(p_input) );
390 if( vlc_thread_create( p_input, "input", RunAndDestroy,
391 VLC_THREAD_PRIORITY_INPUT ) )
393 input_ChangeState( p_input, ERROR_S );
394 msg_Err( p_input, "cannot create input thread" );
395 vlc_object_release( p_input );
403 * Initialize an input and initialize it to preparse the item
404 * This function is blocking. It will only accept parsing regular files.
406 * \param p_parent a vlc_object_t
407 * \param p_item an input item
408 * \return VLC_SUCCESS or an error
410 int input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
412 input_thread_t *p_input;
414 /* Allocate descriptor */
415 p_input = Create( p_parent, p_item, NULL, true, NULL );
419 if( !Init( p_input ) )
422 vlc_object_detach( p_input );
423 vlc_object_release( p_input );
429 * Request a running input thread to stop and die
431 * \param the input thread to stop
433 void input_StopThread( input_thread_t *p_input, bool b_abort )
435 /* Set die for input and ALL of this childrens (even (grand-)grand-childrens)
436 * It is needed here even if it is done in INPUT_CONTROL_SET_DIE handler to
437 * unlock the control loop */
438 ObjectKillChildrens( p_input, VLC_OBJECT(p_input) );
440 vlc_mutex_lock( &p_input->p->lock_control );
441 p_input->p->b_abort |= b_abort;
442 vlc_mutex_unlock( &p_input->p->lock_control );
444 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
447 input_resource_t *input_DetachResource( input_thread_t *p_input )
449 assert( p_input->b_dead );
451 input_resource_SetInput( p_input->p->p_resource, NULL );
453 input_resource_t *p_resource = input_resource_Detach( p_input->p->p_resource );
454 p_input->p->p_sout = NULL;
460 * Get the item from an input thread
461 * FIXME it does not increase ref count of the item.
462 * if it is used after p_input is destroyed nothing prevent it from
465 input_item_t *input_GetItem( input_thread_t *p_input )
467 assert( p_input && p_input->p );
468 return p_input->p->p_item;
471 /*****************************************************************************
472 * ObjectKillChildrens
473 *****************************************************************************/
474 static void ObjectKillChildrens( input_thread_t *p_input, vlc_object_t *p_obj )
479 /* FIXME ObjectKillChildrens seems a very bad idea in fact */
480 i = vlc_internals( p_obj )->i_object_type;
481 if( i == VLC_OBJECT_VOUT ||i == VLC_OBJECT_AOUT ||
482 p_obj == VLC_OBJECT(p_input->p->p_sout) ||
483 i == VLC_OBJECT_DECODER || i == VLC_OBJECT_PACKETIZER )
486 vlc_object_kill( p_obj );
488 p_list = vlc_list_children( p_obj );
489 for( i = 0; i < p_list->i_count; i++ )
490 ObjectKillChildrens( p_input, p_list->p_values[i].p_object );
491 vlc_list_release( p_list );
494 /*****************************************************************************
495 * Run: main thread loop
496 * This is the "normal" thread that spawns the input processing chain,
497 * reads the stream, cleans up and waits
498 *****************************************************************************/
499 static void *Run( vlc_object_t *p_this )
501 input_thread_t *p_input = (input_thread_t *)p_this;
502 const int canc = vlc_savecancel();
504 if( Init( p_input ) )
513 /* Tell we're dead */
514 vlc_mutex_lock( &p_input->p->lock_control );
515 const bool b_abort = p_input->p->b_abort;
516 vlc_mutex_unlock( &p_input->p->lock_control );
519 input_SendEventAbort( p_input );
520 input_SendEventDead( p_input );
522 vlc_restorecancel( canc );
526 /*****************************************************************************
527 * RunAndDestroy: main thread loop
528 * This is the "just forget me" thread that spawns the input processing chain,
529 * reads the stream, cleans up and releases memory
530 *****************************************************************************/
531 static void *RunAndDestroy( vlc_object_t *p_this )
533 input_thread_t *p_input = (input_thread_t *)p_this;
534 const int canc = vlc_savecancel();
536 if( Init( p_input ) )
546 vlc_object_release( p_input );
547 vlc_restorecancel( canc );
551 /*****************************************************************************
552 * Main loop: Fill buffers from access, and demux
553 *****************************************************************************/
557 * It asks the demuxer to demux some data
559 static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, mtime_t *pi_start_mdate )
565 if( ( p_input->p->i_stop > 0 && p_input->p->i_time >= p_input->p->i_stop ) ||
566 ( p_input->p->i_run > 0 && *pi_start_mdate+p_input->p->i_run < mdate() ) )
569 i_ret = demux_Demux( p_input->p->input.p_demux );
573 if( p_input->p->input.p_demux->info.i_update )
575 if( p_input->p->input.b_title_demux )
577 i_ret = UpdateTitleSeekpointFromDemux( p_input );
580 UpdateGenericFromDemux( p_input );
582 else if( p_input->p->input.p_access &&
583 p_input->p->input.p_access->info.i_update )
585 if( !p_input->p->input.b_title_demux )
587 i_ret = UpdateTitleSeekpointFromAccess( p_input );
590 UpdateGenericFromAccess( p_input );
594 if( i_ret == 0 ) /* EOF */
596 int i_repeat = var_GetInteger( p_input, "input-repeat" );
599 /* End of file - we do not set b_die because only the
600 * playlist is allowed to do so. */
601 msg_Dbg( p_input, "EOF reached" );
602 p_input->p->input.b_eof = true;
608 msg_Dbg( p_input, "repeating the same input (%d)", i_repeat );
612 var_SetInteger( p_input, "input-repeat", i_repeat );
615 /* Seek to start title/seekpoint */
616 val.i_int = p_input->p->input.i_title_start -
617 p_input->p->input.i_title_offset;
618 if( val.i_int < 0 || val.i_int >= p_input->p->input.i_title )
620 input_ControlPush( p_input,
621 INPUT_CONTROL_SET_TITLE, &val );
623 val.i_int = p_input->p->input.i_seekpoint_start -
624 p_input->p->input.i_seekpoint_offset;
625 if( val.i_int > 0 /* TODO: check upper boundary */ )
626 input_ControlPush( p_input,
627 INPUT_CONTROL_SET_SEEKPOINT, &val );
629 /* Seek to start position */
630 if( p_input->p->i_start > 0 )
632 val.i_time = p_input->p->i_start;
633 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
639 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
644 *pi_start_mdate = mdate();
649 input_ChangeState( p_input, ERROR_S );
652 if( i_ret > 0 && p_input->p->i_slave > 0 )
654 SlaveDemux( p_input );
660 * It update the variables used by the interfaces
662 static void MainLoopInterface( input_thread_t *p_input )
664 double f_position = 0.0;
666 mtime_t i_length = 0;
668 /* update input status variables */
669 if( demux_Control( p_input->p->input.p_demux,
670 DEMUX_GET_POSITION, &f_position ) )
673 if( demux_Control( p_input->p->input.p_demux,
674 DEMUX_GET_TIME, &i_time ) )
676 p_input->p->i_time = i_time;
678 if( demux_Control( p_input->p->input.p_demux,
679 DEMUX_GET_LENGTH, &i_length ) )
682 es_out_SetTimes( p_input->p->p_es_out, f_position, i_time, i_length );
684 /* update current bookmark */
685 vlc_mutex_lock( &p_input->p->p_item->lock );
686 p_input->p->bookmark.i_time_offset = i_time;
687 if( p_input->p->input.p_stream )
688 p_input->p->bookmark.i_byte_offset = stream_Tell( p_input->p->input.p_stream );
689 vlc_mutex_unlock( &p_input->p->p_item->lock );
694 * It updates the globals statics
696 static void MainLoopStatistic( input_thread_t *p_input )
698 stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
699 input_SendEventStatistics( p_input );
704 * The main input loop.
706 static void MainLoop( input_thread_t *p_input )
708 mtime_t i_start_mdate = mdate();
709 mtime_t i_intf_update = 0;
710 mtime_t i_statistic_update = 0;
712 /* Start the timer */
713 stats_TimerStop( p_input, STATS_TIMER_INPUT_LAUNCHING );
715 while( vlc_object_alive( p_input ) && !p_input->b_error )
726 b_force_update = false;
728 /* FIXME if p_input->p->i_state == PAUSE_S the access/access_demux
729 * is paused -> this may cause problem with some of them
730 * The same problem can be seen when seeking while paused */
731 b_paused = p_input->p->i_state == PAUSE_S &&
732 !es_out_GetBuffering( p_input->p->p_es_out );
736 if( !p_input->p->input.b_eof )
738 MainLoopDemux( p_input, &b_force_update, &i_start_mdate );
740 i_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
742 else if( !p_input->b_eof && !es_out_GetEmpty( p_input->p->p_es_out ) )
744 msg_Dbg( p_input, "waiting decoder fifos to empty" );
745 i_wakeup = mdate() + INPUT_IDLE_SLEEP;
755 i_deadline = i_wakeup;
757 i_deadline = __MIN( i_intf_update, i_statistic_update );
760 ControlReduce( p_input );
761 while( !ControlPop( p_input, &i_type, &val, i_deadline ) )
764 msg_Dbg( p_input, "control type=%d", i_type );
766 if( Control( p_input, i_type, val ) )
767 b_force_update = true;
770 /* Update interface and statistics */
772 if( i_intf_update < i_current || b_force_update )
774 MainLoopInterface( p_input );
775 i_intf_update = i_current + INT64_C(250000);
776 b_force_update = false;
778 if( i_statistic_update < i_current )
780 MainLoopStatistic( p_input );
781 i_statistic_update = i_current + INT64_C(1000000);
784 /* Check if i_wakeup is still valid */
787 mtime_t i_new_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
791 } while( i_current < i_wakeup );
794 if( !p_input->b_error )
795 input_ChangeState( p_input, END_S );
798 static void InitStatistics( input_thread_t * p_input )
800 if( p_input->b_preparsing ) return;
802 /* Prepare statistics */
803 #define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \
804 stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
805 if( libvlc_stats( p_input ) )
807 INIT_COUNTER( read_bytes, INTEGER, COUNTER );
808 INIT_COUNTER( read_packets, INTEGER, COUNTER );
809 INIT_COUNTER( demux_read, INTEGER, COUNTER );
810 INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE );
811 INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE );
812 INIT_COUNTER( demux_corrupted, INTEGER, COUNTER );
813 INIT_COUNTER( demux_discontinuity, INTEGER, COUNTER );
814 INIT_COUNTER( played_abuffers, INTEGER, COUNTER );
815 INIT_COUNTER( lost_abuffers, INTEGER, COUNTER );
816 INIT_COUNTER( displayed_pictures, INTEGER, COUNTER );
817 INIT_COUNTER( lost_pictures, INTEGER, COUNTER );
818 INIT_COUNTER( decoded_audio, INTEGER, COUNTER );
819 INIT_COUNTER( decoded_video, INTEGER, COUNTER );
820 INIT_COUNTER( decoded_sub, INTEGER, COUNTER );
821 p_input->p->counters.p_sout_send_bitrate = NULL;
822 p_input->p->counters.p_sout_sent_packets = NULL;
823 p_input->p->counters.p_sout_sent_bytes = NULL;
824 if( p_input->p->counters.p_demux_bitrate )
825 p_input->p->counters.p_demux_bitrate->update_interval = 1000000;
826 if( p_input->p->counters.p_input_bitrate )
827 p_input->p->counters.p_input_bitrate->update_interval = 1000000;
832 static int InitSout( input_thread_t * p_input )
834 if( p_input->b_preparsing )
837 /* Find a usable sout and attach it to p_input */
838 char *psz = var_GetNonEmptyString( p_input, "sout" );
839 if( psz && strncasecmp( p_input->p->p_item->psz_uri, "vlc:", 4 ) )
841 p_input->p->p_sout = input_resource_RequestSout( p_input->p->p_resource, NULL, psz );
842 if( !p_input->p->p_sout )
844 input_ChangeState( p_input, ERROR_S );
845 msg_Err( p_input, "cannot start stream output instance, " \
850 if( libvlc_stats( p_input ) )
852 INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
853 INIT_COUNTER( sout_sent_bytes, INTEGER, COUNTER );
854 INIT_COUNTER( sout_send_bitrate, FLOAT, DERIVATIVE );
855 if( p_input->p->counters.p_sout_send_bitrate )
856 p_input->p->counters.p_sout_send_bitrate->update_interval =
862 input_resource_RequestSout( p_input->p->p_resource, NULL, NULL );
870 static void InitTitle( input_thread_t * p_input )
872 input_source_t *p_master = &p_input->p->input;
874 if( p_input->b_preparsing )
877 /* Create global title (from master) */
878 p_input->p->i_title = p_master->i_title;
879 p_input->p->title = p_master->title;
880 p_input->p->i_title_offset = p_master->i_title_offset;
881 p_input->p->i_seekpoint_offset = p_master->i_seekpoint_offset;
882 if( p_input->p->i_title > 0 )
884 /* Setup variables */
885 input_ControlVarNavigation( p_input );
886 input_SendEventTitle( p_input, 0 );
890 p_input->p->b_can_pace_control = p_master->b_can_pace_control;
891 p_input->p->b_can_pause = p_master->b_can_pause;
892 p_input->p->b_can_rate_control = p_master->b_can_rate_control;
895 static void StartTitle( input_thread_t * p_input )
899 /* Start title/chapter */
900 val.i_int = p_input->p->input.i_title_start -
901 p_input->p->input.i_title_offset;
902 if( val.i_int > 0 && val.i_int < p_input->p->input.i_title )
903 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
905 val.i_int = p_input->p->input.i_seekpoint_start -
906 p_input->p->input.i_seekpoint_offset;
907 if( val.i_int > 0 /* TODO: check upper boundary */ )
908 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
910 /* Start/stop/run time */
911 p_input->p->i_start = INT64_C(1000000) * var_GetInteger( p_input, "start-time" );
912 p_input->p->i_stop = INT64_C(1000000) * var_GetInteger( p_input, "stop-time" );
913 p_input->p->i_run = INT64_C(1000000) * var_GetInteger( p_input, "run-time" );
914 if( p_input->p->i_run < 0 )
916 msg_Warn( p_input, "invalid run-time ignored" );
917 p_input->p->i_run = 0;
920 const mtime_t i_length = var_GetTime( p_input, "length" );
921 if( p_input->p->i_start > 0 )
923 if( p_input->p->i_start >= i_length )
925 msg_Warn( p_input, "invalid start-time ignored" );
931 msg_Dbg( p_input, "starting at time: %ds",
932 (int)( p_input->p->i_start / INT64_C(1000000) ) );
934 s.i_time = p_input->p->i_start;
935 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
938 if( p_input->p->i_stop > 0 && p_input->p->i_stop <= p_input->p->i_start )
940 msg_Warn( p_input, "invalid stop-time ignored" );
941 p_input->p->i_stop = 0;
943 p_input->p->b_fast_seek = var_GetBool( p_input, "input-fast-seek" );
946 static void LoadSubtitles( input_thread_t *p_input )
949 /* Get fps and set it if not already set */
950 const double f_fps = p_input->p->f_fps;
953 float f_requested_fps;
955 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
956 var_SetFloat( p_input, "sub-original-fps", f_fps );
958 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
959 if( f_requested_fps != f_fps )
961 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
963 var_SetFloat( p_input, "sub-fps", f_requested_fps );
967 const int i_delay = var_CreateGetInteger( p_input, "sub-delay" );
969 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
971 /* Look for and add subtitle files */
972 char *psz_subtitle = var_GetNonEmptyString( p_input, "sub-file" );
973 if( psz_subtitle != NULL )
975 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
976 SubtitleAdd( p_input, psz_subtitle, true );
979 if( var_GetBool( p_input, "sub-autodetect-file" ) )
981 char *psz_autopath = var_GetNonEmptyString( p_input, "sub-autodetect-path" );
982 char **ppsz_subs = subtitles_Detect( p_input, psz_autopath,
983 p_input->p->p_item->psz_uri );
984 free( psz_autopath );
986 for( int i = 0; ppsz_subs && ppsz_subs[i]; i++ )
988 /* Try to autoselect the first autodetected subtitles file
989 * if no subtitles file was specified */
990 bool b_forced = i == 0 && !psz_subtitle;
992 if( !psz_subtitle || strcmp( psz_subtitle, ppsz_subs[i] ) )
993 SubtitleAdd( p_input, ppsz_subs[i], b_forced );
995 free( ppsz_subs[i] );
999 free( psz_subtitle );
1002 static void LoadSlaves( input_thread_t *p_input )
1004 char *psz = var_GetNonEmptyString( p_input, "input-slave" );
1008 char *psz_org = psz;
1009 while( psz && *psz )
1011 while( *psz == ' ' || *psz == '#' )
1014 char *psz_delim = strchr( psz, '#' );
1016 *psz_delim++ = '\0';
1021 msg_Dbg( p_input, "adding slave input '%s'", psz );
1023 input_source_t *p_slave = InputSourceNew( p_input );
1024 if( p_slave && !InputSourceInit( p_input, p_slave, psz, NULL ) )
1025 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, p_slave );
1034 static void UpdatePtsDelay( input_thread_t *p_input )
1036 input_thread_private_t *p_sys = p_input->p;
1038 /* Get max pts delay from input source */
1039 mtime_t i_pts_delay = p_sys->input.i_pts_delay;
1040 for( int i = 0; i < p_sys->i_slave; i++ )
1041 i_pts_delay = __MAX( i_pts_delay, p_sys->slave[i]->i_pts_delay );
1043 if( i_pts_delay < 0 )
1046 /* Take care of audio/spu delay */
1047 const mtime_t i_audio_delay = var_GetTime( p_input, "audio-delay" );
1048 const mtime_t i_spu_delay = var_GetTime( p_input, "spu-delay" );
1049 const mtime_t i_extra_delay = __MIN( i_audio_delay, i_spu_delay );
1050 if( i_extra_delay < 0 )
1051 i_pts_delay -= i_extra_delay;
1053 /* Update cr_average depending on the caching */
1054 const int i_cr_average = var_GetInteger( p_input, "cr-average" ) * i_pts_delay / DEFAULT_PTS_DELAY;
1057 es_out_SetJitter( p_input->p->p_es_out, i_pts_delay, i_cr_average );
1060 static void InitPrograms( input_thread_t * p_input )
1065 /* Compute correct pts_delay */
1066 UpdatePtsDelay( p_input );
1069 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, true );
1070 i_es_out_mode = ES_OUT_MODE_AUTO;
1072 if( p_input->p->p_sout )
1074 if( var_GetBool( p_input, "sout-all" ) )
1076 i_es_out_mode = ES_OUT_MODE_ALL;
1081 var_Get( p_input, "programs", &val );
1082 if( val.p_list && val.p_list->i_count )
1084 i_es_out_mode = ES_OUT_MODE_PARTIAL;
1085 /* Note : we should remove the "program" callback. */
1089 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
1094 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
1096 /* Inform the demuxer about waited group (needed only for DVB) */
1097 if( i_es_out_mode == ES_OUT_MODE_ALL )
1099 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
1101 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
1103 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1,
1108 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP,
1109 (int) var_GetInteger( p_input, "program" ), NULL );
1113 static int Init( input_thread_t * p_input )
1118 for( i = 0; i < p_input->p->p_item->i_options; i++ )
1120 if( !strncmp( p_input->p->p_item->ppsz_options[i], "meta-file", 9 ) )
1122 msg_Dbg( p_input, "Input is a meta file: disabling unneeded options" );
1123 var_SetString( p_input, "sout", "" );
1124 var_SetBool( p_input, "sout-all", false );
1125 var_SetString( p_input, "input-slave", "" );
1126 var_SetInteger( p_input, "input-repeat", 0 );
1127 var_SetString( p_input, "sub-file", "" );
1128 var_SetBool( p_input, "sub-autodetect-file", false );
1132 InitStatistics( p_input );
1134 ret = InitSout( p_input );
1135 if( ret != VLC_SUCCESS )
1140 p_input->p->p_es_out_display = input_EsOutNew( p_input, p_input->p->i_rate );
1141 p_input->p->p_es_out = input_EsOutTimeshiftNew( p_input, p_input->p->p_es_out_display, p_input->p->i_rate );
1142 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, false );
1143 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
1145 var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
1146 var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
1149 input_ChangeState( p_input, OPENING_S );
1150 input_SendEventCache( p_input, 0.0 );
1153 if( InputSourceInit( p_input, &p_input->p->input,
1154 p_input->p->p_item->psz_uri, NULL ) )
1159 InitTitle( p_input );
1161 /* Load master infos */
1164 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_LENGTH,
1168 i_length = input_item_GetDuration( p_input->p->p_item );
1169 input_SendEventTimes( p_input, 0.0, 0, i_length );
1171 if( !p_input->b_preparsing )
1173 StartTitle( p_input );
1174 LoadSubtitles( p_input );
1175 LoadSlaves( p_input );
1176 InitPrograms( p_input );
1179 if( !p_input->b_preparsing && p_input->p->p_sout )
1181 p_input->p->b_out_pace_control = (p_input->p->p_sout->i_out_pace_nocontrol > 0);
1183 if( p_input->p->b_can_pace_control && p_input->p->b_out_pace_control )
1185 /* We don't want a high input priority here or we'll
1186 * end-up sucking up all the CPU time */
1187 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
1190 msg_Dbg( p_input, "starting in %s mode",
1191 p_input->p->b_out_pace_control ? "async" : "sync" );
1194 p_meta = vlc_meta_New();
1197 /* Get meta data from users */
1198 InputMetaUser( p_input, p_meta );
1200 /* Get meta data from master input */
1201 InputSourceMeta( p_input, &p_input->p->input, p_meta );
1203 /* And from slave */
1204 for( int i = 0; i < p_input->p->i_slave; i++ )
1205 InputSourceMeta( p_input, p_input->p->slave[i], p_meta );
1208 InputUpdateMeta( p_input, p_meta );
1211 msg_Dbg( p_input, "`%s' successfully opened",
1212 p_input->p->p_item->psz_uri );
1214 /* initialization is complete */
1215 input_ChangeState( p_input, PLAYING_S );
1220 input_ChangeState( p_input, ERROR_S );
1222 if( p_input->p->p_es_out )
1223 es_out_Delete( p_input->p->p_es_out );
1224 if( p_input->p->p_es_out_display )
1225 es_out_Delete( p_input->p->p_es_out_display );
1226 if( p_input->p->p_resource )
1228 if( p_input->p->p_sout )
1229 input_resource_RequestSout( p_input->p->p_resource,
1230 p_input->p->p_sout, NULL );
1231 input_resource_SetInput( p_input->p->p_resource, NULL );
1237 if( !p_input->b_preparsing && libvlc_stats( p_input ) )
1239 #define EXIT_COUNTER( c ) do { if( p_input->p->counters.p_##c ) \
1240 stats_CounterClean( p_input->p->counters.p_##c );\
1241 p_input->p->counters.p_##c = NULL; } while(0)
1242 EXIT_COUNTER( read_bytes );
1243 EXIT_COUNTER( read_packets );
1244 EXIT_COUNTER( demux_read );
1245 EXIT_COUNTER( input_bitrate );
1246 EXIT_COUNTER( demux_bitrate );
1247 EXIT_COUNTER( demux_corrupted );
1248 EXIT_COUNTER( demux_discontinuity );
1249 EXIT_COUNTER( played_abuffers );
1250 EXIT_COUNTER( lost_abuffers );
1251 EXIT_COUNTER( displayed_pictures );
1252 EXIT_COUNTER( lost_pictures );
1253 EXIT_COUNTER( decoded_audio );
1254 EXIT_COUNTER( decoded_video );
1255 EXIT_COUNTER( decoded_sub );
1257 if( p_input->p->p_sout )
1259 EXIT_COUNTER( sout_sent_packets );
1260 EXIT_COUNTER( sout_sent_bytes );
1261 EXIT_COUNTER( sout_send_bitrate );
1266 /* Mark them deleted */
1267 p_input->p->input.p_demux = NULL;
1268 p_input->p->input.p_stream = NULL;
1269 p_input->p->input.p_access = NULL;
1270 p_input->p->p_es_out = NULL;
1271 p_input->p->p_es_out_display = NULL;
1272 p_input->p->p_sout = NULL;
1274 return VLC_EGENERIC;
1277 /*****************************************************************************
1278 * End: end the input thread
1279 *****************************************************************************/
1280 static void End( input_thread_t * p_input )
1284 /* We are at the end */
1285 input_ChangeState( p_input, END_S );
1287 /* Clean control variables */
1288 input_ControlVarStop( p_input );
1290 /* Stop es out activity */
1291 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, false );
1292 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
1294 /* Clean up master */
1295 InputSourceClean( &p_input->p->input );
1298 for( i = 0; i < p_input->p->i_slave; i++ )
1300 InputSourceClean( p_input->p->slave[i] );
1301 free( p_input->p->slave[i] );
1303 free( p_input->p->slave );
1305 /* Unload all modules */
1306 if( p_input->p->p_es_out )
1307 es_out_Delete( p_input->p->p_es_out );
1308 if( p_input->p->p_es_out_display )
1309 es_out_Delete( p_input->p->p_es_out_display );
1311 if( !p_input->b_preparsing )
1313 #define CL_CO( c ) stats_CounterClean( p_input->p->counters.p_##c ); p_input->p->counters.p_##c = NULL;
1314 if( libvlc_stats( p_input ) )
1316 /* make sure we are up to date */
1317 stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
1318 CL_CO( read_bytes );
1319 CL_CO( read_packets );
1320 CL_CO( demux_read );
1321 CL_CO( input_bitrate );
1322 CL_CO( demux_bitrate );
1323 CL_CO( demux_corrupted );
1324 CL_CO( demux_discontinuity );
1325 CL_CO( played_abuffers );
1326 CL_CO( lost_abuffers );
1327 CL_CO( displayed_pictures );
1328 CL_CO( lost_pictures );
1329 CL_CO( decoded_audio) ;
1330 CL_CO( decoded_video );
1331 CL_CO( decoded_sub) ;
1334 /* Close optional stream output instance */
1335 if( p_input->p->p_sout )
1337 CL_CO( sout_sent_packets );
1338 CL_CO( sout_sent_bytes );
1339 CL_CO( sout_send_bitrate );
1344 if( p_input->p->i_attachment > 0 )
1346 for( i = 0; i < p_input->p->i_attachment; i++ )
1347 vlc_input_attachment_Delete( p_input->p->attachment[i] );
1348 TAB_CLEAN( p_input->p->i_attachment, p_input->p->attachment );
1352 input_resource_RequestSout( p_input->p->p_resource,
1353 p_input->p->p_sout, NULL );
1354 input_resource_SetInput( p_input->p->p_resource, NULL );
1357 /*****************************************************************************
1359 *****************************************************************************/
1360 void input_ControlPush( input_thread_t *p_input,
1361 int i_type, vlc_value_t *p_val )
1363 vlc_mutex_lock( &p_input->p->lock_control );
1364 if( i_type == INPUT_CONTROL_SET_DIE )
1366 /* Special case, empty the control */
1367 p_input->p->i_control = 1;
1368 p_input->p->control[0].i_type = i_type;
1369 memset( &p_input->p->control[0].val, 0, sizeof( vlc_value_t ) );
1371 else if( p_input->p->i_control >= INPUT_CONTROL_FIFO_SIZE )
1373 msg_Err( p_input, "input control fifo overflow, trashing type=%d",
1378 p_input->p->control[p_input->p->i_control].i_type = i_type;
1380 p_input->p->control[p_input->p->i_control].val = *p_val;
1382 memset( &p_input->p->control[p_input->p->i_control].val, 0,
1383 sizeof( vlc_value_t ) );
1385 p_input->p->i_control++;
1387 vlc_cond_signal( &p_input->p->wait_control );
1388 vlc_mutex_unlock( &p_input->p->lock_control );
1391 static inline int ControlPop( input_thread_t *p_input,
1392 int *pi_type, vlc_value_t *p_val,
1393 mtime_t i_deadline )
1395 input_thread_private_t *p_sys = p_input->p;
1397 vlc_mutex_lock( &p_sys->lock_control );
1398 while( p_sys->i_control <= 0 )
1400 if( !vlc_object_alive( p_input ) || i_deadline < 0 )
1402 vlc_mutex_unlock( &p_sys->lock_control );
1403 return VLC_EGENERIC;
1406 if( vlc_cond_timedwait( &p_sys->wait_control, &p_sys->lock_control,
1409 vlc_mutex_unlock( &p_sys->lock_control );
1410 return VLC_EGENERIC;
1415 *pi_type = p_sys->control[0].i_type;
1416 *p_val = p_sys->control[0].val;
1419 if( p_sys->i_control > 0 )
1420 memmove( &p_sys->control[0], &p_sys->control[1],
1421 sizeof(*p_sys->control) * p_sys->i_control );
1422 vlc_mutex_unlock( &p_sys->lock_control );
1427 static void ControlReduce( input_thread_t *p_input )
1429 vlc_mutex_lock( &p_input->p->lock_control );
1431 for( int i = 1; i < p_input->p->i_control; i++ )
1433 const int i_lt = p_input->p->control[i-1].i_type;
1434 const int i_ct = p_input->p->control[i].i_type;
1436 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1437 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->p->i_control,
1441 ( i_ct == INPUT_CONTROL_SET_STATE ||
1442 i_ct == INPUT_CONTROL_SET_RATE ||
1443 i_ct == INPUT_CONTROL_SET_POSITION ||
1444 i_ct == INPUT_CONTROL_SET_TIME ||
1445 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1446 i_ct == INPUT_CONTROL_SET_TITLE ||
1447 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1448 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1451 // msg_Dbg( p_input, "merged at %d", i );
1452 /* Remove the i-1 */
1453 for( j = i; j < p_input->p->i_control; j++ )
1454 p_input->p->control[j-1] = p_input->p->control[j];
1455 p_input->p->i_control--;
1459 /* TODO but that's not that important
1460 - merge SET_X with SET_X_CMD
1461 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1462 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1467 vlc_mutex_unlock( &p_input->p->lock_control );
1470 static void ControlPause( input_thread_t *p_input, mtime_t i_control_date )
1472 int i_ret = VLC_SUCCESS;
1473 int i_state = PAUSE_S;
1475 if( p_input->p->b_can_pause )
1477 if( p_input->p->input.p_access )
1478 i_ret = access_Control( p_input->p->input.p_access,
1479 ACCESS_SET_PAUSE_STATE, true );
1481 i_ret = demux_Control( p_input->p->input.p_demux,
1482 DEMUX_SET_PAUSE_STATE, true );
1486 msg_Warn( p_input, "cannot set pause state" );
1487 i_state = p_input->p->i_state;
1494 i_ret = es_out_SetPauseState( p_input->p->p_es_out, p_input->p->b_can_pause, true, i_control_date );
1497 msg_Warn( p_input, "cannot set pause state at es_out level" );
1498 i_state = p_input->p->i_state;
1502 /* Switch to new state */
1503 input_ChangeState( p_input, i_state );
1507 static void ControlUnpause( input_thread_t *p_input, mtime_t i_control_date )
1509 int i_ret = VLC_SUCCESS;
1511 if( p_input->p->b_can_pause )
1513 if( p_input->p->input.p_access )
1514 i_ret = access_Control( p_input->p->input.p_access,
1515 ACCESS_SET_PAUSE_STATE, false );
1517 i_ret = demux_Control( p_input->p->input.p_demux,
1518 DEMUX_SET_PAUSE_STATE, false );
1521 /* FIXME What to do ? */
1522 msg_Warn( p_input, "cannot unset pause -> EOF" );
1523 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1527 /* Switch to play */
1528 input_ChangeState( p_input, PLAYING_S );
1532 es_out_SetPauseState( p_input->p->p_es_out, false, false, i_control_date );
1535 static bool Control( input_thread_t *p_input, int i_type,
1538 const mtime_t i_control_date = mdate();
1539 /* FIXME b_force_update is abused, it should be carefully checked */
1540 bool b_force_update = false;
1543 return b_force_update;
1547 case INPUT_CONTROL_SET_DIE:
1548 msg_Dbg( p_input, "control: stopping input" );
1550 /* Mark all submodules to die */
1551 ObjectKillChildrens( p_input, VLC_OBJECT(p_input) );
1554 case INPUT_CONTROL_SET_POSITION:
1555 case INPUT_CONTROL_SET_POSITION_OFFSET:
1559 if( p_input->p->b_recording )
1561 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) ignored while recording" );
1564 f_pos = val.f_float;
1565 if( i_type != INPUT_CONTROL_SET_POSITION )
1566 f_pos += var_GetFloat( p_input, "position" );
1569 else if( f_pos > 1.0 )
1571 /* Reset the decoders states and clock sync (before calling the demuxer */
1572 es_out_SetTime( p_input->p->p_es_out, -1 );
1573 if( demux_Control( p_input->p->input.p_demux, DEMUX_SET_POSITION,
1574 f_pos, !p_input->p->b_fast_seek ) )
1576 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1577 "%2.1f%% failed", f_pos * 100 );
1581 if( p_input->p->i_slave > 0 )
1582 SlaveSeek( p_input );
1583 p_input->p->input.b_eof = false;
1585 b_force_update = true;
1590 case INPUT_CONTROL_SET_TIME:
1591 case INPUT_CONTROL_SET_TIME_OFFSET:
1596 if( p_input->p->b_recording )
1598 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) ignored while recording" );
1602 i_time = val.i_time;
1603 if( i_type != INPUT_CONTROL_SET_TIME )
1604 i_time += var_GetTime( p_input, "time" );
1609 /* Reset the decoders states and clock sync (before calling the demuxer */
1610 es_out_SetTime( p_input->p->p_es_out, -1 );
1612 i_ret = demux_Control( p_input->p->input.p_demux,
1613 DEMUX_SET_TIME, i_time,
1614 !p_input->p->b_fast_seek );
1619 /* Emulate it with a SET_POS */
1620 demux_Control( p_input->p->input.p_demux,
1621 DEMUX_GET_LENGTH, &i_length );
1624 double f_pos = (double)i_time / (double)i_length;
1625 i_ret = demux_Control( p_input->p->input.p_demux,
1626 DEMUX_SET_POSITION, f_pos,
1627 !p_input->p->b_fast_seek );
1632 msg_Warn( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) %"PRId64
1633 " failed or not possible", i_time );
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_STATE:
1647 if( ( val.i_int == PLAYING_S && p_input->p->i_state == PAUSE_S ) ||
1648 ( val.i_int == PAUSE_S && p_input->p->i_state == PAUSE_S ) )
1650 ControlUnpause( p_input, i_control_date );
1652 b_force_update = true;
1654 else if( val.i_int == PAUSE_S && p_input->p->i_state == PLAYING_S /* &&
1655 p_input->p->b_can_pause */ )
1657 ControlPause( p_input, i_control_date );
1659 b_force_update = true;
1661 else if( val.i_int == PAUSE_S && !p_input->p->b_can_pause && 0 )
1663 b_force_update = true;
1665 /* Correct "state" value */
1666 input_ChangeState( p_input, p_input->p->i_state );
1668 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1670 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1674 case INPUT_CONTROL_SET_RATE:
1675 case INPUT_CONTROL_SET_RATE_SLOWER:
1676 case INPUT_CONTROL_SET_RATE_FASTER:
1681 /* Get rate and direction */
1682 if( i_type == INPUT_CONTROL_SET_RATE )
1684 i_rate = abs( val.i_int );
1685 i_rate_sign = val.i_int < 0 ? -1 : 1;
1689 static const int ppi_factor[][2] = {
1690 {1,64}, {1,32}, {1,16}, {1,8}, {1,4}, {1,3}, {1,2}, {2,3},
1692 {3,2}, {2,1}, {3,1}, {4,1}, {8,1}, {16,1}, {32,1}, {64,1},
1699 i_rate_sign = p_input->p->i_rate < 0 ? -1 : 1;
1703 for( i = 0; ppi_factor[i][0] != 0; i++ )
1705 const int i_test_r = INPUT_RATE_DEFAULT * ppi_factor[i][0] / ppi_factor[i][1];
1706 const int i_test_e = abs( abs( p_input->p->i_rate ) - i_test_r );
1707 if( i_test_e < i_error )
1714 assert( i_idx >= 0 && ppi_factor[i_idx][0] != 0 );
1716 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1718 if( ppi_factor[i_idx+1][0] > 0 )
1719 i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx+1][0] / ppi_factor[i_idx+1][1];
1721 i_rate = INPUT_RATE_MAX+1;
1725 assert( i_type == INPUT_CONTROL_SET_RATE_FASTER );
1727 i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx-1][0] / ppi_factor[i_idx-1][1];
1729 i_rate = INPUT_RATE_MIN-1;
1733 /* Check rate bound */
1734 if( i_rate < INPUT_RATE_MIN )
1736 msg_Dbg( p_input, "cannot set rate faster" );
1737 i_rate = INPUT_RATE_MIN;
1739 else if( i_rate > INPUT_RATE_MAX )
1741 msg_Dbg( p_input, "cannot set rate slower" );
1742 i_rate = INPUT_RATE_MAX;
1745 /* Apply direction */
1746 if( i_rate_sign < 0 )
1748 if( p_input->p->input.b_rescale_ts )
1750 msg_Dbg( p_input, "cannot set negative rate" );
1751 i_rate = p_input->p->i_rate;
1752 assert( i_rate > 0 );
1756 i_rate *= i_rate_sign;
1760 if( i_rate != INPUT_RATE_DEFAULT &&
1761 ( ( !p_input->p->b_can_rate_control && !p_input->p->input.b_rescale_ts ) ||
1762 ( p_input->p->p_sout && !p_input->p->b_out_pace_control ) ) )
1764 msg_Dbg( p_input, "cannot change rate" );
1765 i_rate = INPUT_RATE_DEFAULT;
1767 if( i_rate != p_input->p->i_rate &&
1768 !p_input->p->b_can_pace_control && p_input->p->b_can_rate_control )
1771 if( p_input->p->input.p_access )
1773 i_ret = VLC_EGENERIC;
1777 if( !p_input->p->input.b_rescale_ts )
1778 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1780 i_ret = demux_Control( p_input->p->input.p_demux,
1781 DEMUX_SET_RATE, &i_rate );
1785 msg_Warn( p_input, "ACCESS/DEMUX_SET_RATE failed" );
1786 i_rate = p_input->p->i_rate;
1791 if( i_rate != p_input->p->i_rate )
1793 p_input->p->i_rate = i_rate;
1794 input_SendEventRate( p_input, i_rate );
1796 if( p_input->p->input.b_rescale_ts )
1798 const int i_rate_source = (p_input->p->b_can_pace_control || p_input->p->b_can_rate_control ) ? i_rate : INPUT_RATE_DEFAULT;
1799 es_out_SetRate( p_input->p->p_es_out, i_rate_source, i_rate );
1802 b_force_update = true;
1807 case INPUT_CONTROL_SET_PROGRAM:
1808 /* No need to force update, es_out does it if needed */
1809 es_out_Control( p_input->p->p_es_out,
1810 ES_OUT_SET_GROUP, val.i_int );
1812 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1816 case INPUT_CONTROL_SET_ES:
1817 /* No need to force update, es_out does it if needed */
1818 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, val.i_int );
1821 case INPUT_CONTROL_RESTART_ES:
1822 es_out_Control( p_input->p->p_es_out_display, ES_OUT_RESTART_ES_BY_ID, val.i_int );
1825 case INPUT_CONTROL_SET_AUDIO_DELAY:
1826 if( !es_out_SetDelay( p_input->p->p_es_out_display, AUDIO_ES, val.i_time ) )
1828 input_SendEventAudioDelay( p_input, val.i_time );
1829 UpdatePtsDelay( p_input );
1833 case INPUT_CONTROL_SET_SPU_DELAY:
1834 if( !es_out_SetDelay( p_input->p->p_es_out_display, SPU_ES, val.i_time ) )
1836 input_SendEventSubtitleDelay( p_input, val.i_time );
1837 UpdatePtsDelay( p_input );
1841 case INPUT_CONTROL_SET_TITLE:
1842 case INPUT_CONTROL_SET_TITLE_NEXT:
1843 case INPUT_CONTROL_SET_TITLE_PREV:
1844 if( p_input->p->b_recording )
1846 msg_Err( p_input, "INPUT_CONTROL_SET_TITLE(*) ignored while recording" );
1849 if( p_input->p->input.b_title_demux &&
1850 p_input->p->input.i_title > 0 )
1853 /* FIXME handle demux title */
1854 demux_t *p_demux = p_input->p->input.p_demux;
1857 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1858 i_title = p_demux->info.i_title - 1;
1859 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1860 i_title = p_demux->info.i_title + 1;
1862 i_title = val.i_int;
1864 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1866 es_out_SetTime( p_input->p->p_es_out, -1 );
1868 demux_Control( p_demux, DEMUX_SET_TITLE, i_title );
1869 input_SendEventTitle( p_input, i_title );
1872 else if( p_input->p->input.i_title > 0 )
1874 access_t *p_access = p_input->p->input.p_access;
1877 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1878 i_title = p_access->info.i_title - 1;
1879 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1880 i_title = p_access->info.i_title + 1;
1882 i_title = val.i_int;
1884 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1886 es_out_SetTime( p_input->p->p_es_out, -1 );
1888 stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
1889 ACCESS_SET_TITLE, i_title );
1890 input_SendEventTitle( p_input, i_title );
1894 case INPUT_CONTROL_SET_SEEKPOINT:
1895 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1896 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1897 if( p_input->p->b_recording )
1899 msg_Err( p_input, "INPUT_CONTROL_SET_SEEKPOINT(*) ignored while recording" );
1903 if( p_input->p->input.b_title_demux &&
1904 p_input->p->input.i_title > 0 )
1906 demux_t *p_demux = p_input->p->input.p_demux;
1908 int64_t i_input_time;
1909 int64_t i_seekpoint_time;
1911 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1913 i_seekpoint = p_demux->info.i_seekpoint;
1914 i_seekpoint_time = p_input->p->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1915 i_input_time = var_GetTime( p_input, "time" );
1916 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
1918 if( i_input_time < i_seekpoint_time + 3000000 )
1924 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1925 i_seekpoint = p_demux->info.i_seekpoint + 1;
1927 i_seekpoint = val.i_int;
1929 if( i_seekpoint >= 0 && i_seekpoint <
1930 p_input->p->input.title[p_demux->info.i_title]->i_seekpoint )
1933 es_out_SetTime( p_input->p->p_es_out, -1 );
1935 demux_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1936 input_SendEventSeekpoint( p_input, p_demux->info.i_title, i_seekpoint );
1939 else if( p_input->p->input.i_title > 0 )
1941 access_t *p_access = p_input->p->input.p_access;
1943 int64_t i_input_time;
1944 int64_t i_seekpoint_time;
1946 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1948 i_seekpoint = p_access->info.i_seekpoint;
1949 i_seekpoint_time = p_input->p->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1950 i_input_time = var_GetTime( p_input, "time" );
1951 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
1953 if( i_input_time < i_seekpoint_time + 3000000 )
1959 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1960 i_seekpoint = p_access->info.i_seekpoint + 1;
1962 i_seekpoint = val.i_int;
1964 if( i_seekpoint >= 0 && i_seekpoint <
1965 p_input->p->input.title[p_access->info.i_title]->i_seekpoint )
1967 es_out_SetTime( p_input->p->p_es_out, -1 );
1969 stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
1970 ACCESS_SET_SEEKPOINT, i_seekpoint );
1971 input_SendEventSeekpoint( p_input, p_access->info.i_title, i_seekpoint );
1976 case INPUT_CONTROL_ADD_SUBTITLE:
1977 if( val.psz_string )
1979 SubtitleAdd( p_input, val.psz_string, true );
1980 free( val.psz_string );
1984 case INPUT_CONTROL_ADD_SLAVE:
1985 if( val.psz_string )
1987 input_source_t *slave = InputSourceNew( p_input );
1989 if( slave && !InputSourceInit( p_input, slave, val.psz_string, NULL ) )
1995 msg_Dbg( p_input, "adding %s as slave on the fly",
1999 if( demux_Control( p_input->p->input.p_demux,
2000 DEMUX_GET_TIME, &i_time ) )
2002 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2003 InputSourceClean( slave );
2007 if( demux_Control( slave->p_demux,
2008 DEMUX_SET_TIME, i_time, true ) )
2010 msg_Err( p_input, "seek failed for new slave" );
2011 InputSourceClean( slave );
2016 /* Get meta (access and demux) */
2017 p_meta = vlc_meta_New();
2020 access_Control( slave->p_access, ACCESS_GET_META, p_meta );
2021 demux_Control( slave->p_demux, DEMUX_GET_META, p_meta );
2022 InputUpdateMeta( p_input, p_meta );
2025 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, slave );
2030 msg_Warn( p_input, "failed to add %s as slave",
2034 free( val.psz_string );
2038 case INPUT_CONTROL_SET_RECORD_STATE:
2039 if( !!p_input->p->b_recording != !!val.b_bool )
2041 if( p_input->p->input.b_can_stream_record )
2043 if( demux_Control( p_input->p->input.p_demux,
2044 DEMUX_SET_RECORD_STATE, val.b_bool ) )
2049 if( es_out_SetRecordState( p_input->p->p_es_out_display, val.b_bool ) )
2052 p_input->p->b_recording = val.b_bool;
2054 input_SendEventRecord( p_input, val.b_bool );
2056 b_force_update = true;
2060 case INPUT_CONTROL_SET_FRAME_NEXT:
2061 if( p_input->p->i_state == PAUSE_S )
2063 es_out_SetFrameNext( p_input->p->p_es_out );
2065 else if( p_input->p->i_state == PLAYING_S )
2067 ControlPause( p_input, i_control_date );
2071 msg_Err( p_input, "invalid state for frame next" );
2073 b_force_update = true;
2076 case INPUT_CONTROL_SET_BOOKMARK:
2078 seekpoint_t bookmark;
2080 bookmark.i_time_offset = -1;
2081 bookmark.i_byte_offset = -1;
2083 vlc_mutex_lock( &p_input->p->p_item->lock );
2084 if( val.i_int >= 0 && val.i_int < p_input->p->i_bookmark )
2086 const seekpoint_t *p_bookmark = p_input->p->pp_bookmark[val.i_int];
2087 bookmark.i_time_offset = p_bookmark->i_time_offset;
2088 bookmark.i_byte_offset = p_bookmark->i_byte_offset;
2090 vlc_mutex_unlock( &p_input->p->p_item->lock );
2092 if( bookmark.i_time_offset < 0 && bookmark.i_byte_offset < 0 )
2094 msg_Err( p_input, "invalid bookmark %d", val.i_int );
2098 if( bookmark.i_time_offset >= 0 )
2100 val.i_time = bookmark.i_time_offset;
2101 b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME, val );
2103 else if( bookmark.i_byte_offset >= 0 &&
2104 p_input->p->input.p_stream )
2106 const int64_t i_size = stream_Size( p_input->p->input.p_stream );
2107 if( i_size > 0 && bookmark.i_byte_offset <= i_size )
2109 val.f_float = (double)bookmark.i_byte_offset / i_size;
2110 b_force_update = Control( p_input, INPUT_CONTROL_SET_POSITION, val );
2117 msg_Err( p_input, "not yet implemented" );
2121 return b_force_update;
2124 /*****************************************************************************
2125 * UpdateTitleSeekpoint
2126 *****************************************************************************/
2127 static int UpdateTitleSeekpoint( input_thread_t *p_input,
2128 int i_title, int i_seekpoint )
2130 int i_title_end = p_input->p->input.i_title_end -
2131 p_input->p->input.i_title_offset;
2132 int i_seekpoint_end = p_input->p->input.i_seekpoint_end -
2133 p_input->p->input.i_seekpoint_offset;
2135 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
2137 if( i_title > i_title_end ||
2138 ( i_title == i_title_end && i_seekpoint > i_seekpoint_end ) )
2141 else if( i_seekpoint_end >= 0 )
2143 if( i_seekpoint > i_seekpoint_end )
2146 else if( i_title_end >= 0 )
2148 if( i_title > i_title_end )
2153 /*****************************************************************************
2155 *****************************************************************************/
2156 static int UpdateTitleSeekpointFromDemux( input_thread_t *p_input )
2158 demux_t *p_demux = p_input->p->input.p_demux;
2160 /* TODO event-like */
2161 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
2163 input_SendEventTitle( p_input, p_demux->info.i_title );
2165 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
2167 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
2169 input_SendEventSeekpoint( p_input,
2170 p_demux->info.i_title, p_demux->info.i_seekpoint );
2172 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2175 /* Hmmm only works with master input */
2176 if( p_input->p->input.p_demux == p_demux )
2177 return UpdateTitleSeekpoint( p_input,
2178 p_demux->info.i_title,
2179 p_demux->info.i_seekpoint );
2183 static void UpdateGenericFromDemux( input_thread_t *p_input )
2185 demux_t *p_demux = p_input->p->input.p_demux;
2187 if( p_demux->info.i_update & INPUT_UPDATE_META )
2189 vlc_meta_t *p_meta = vlc_meta_New();
2192 demux_Control( p_input->p->input.p_demux, DEMUX_GET_META, p_meta );
2193 InputUpdateMeta( p_input, p_meta );
2195 p_demux->info.i_update &= ~INPUT_UPDATE_META;
2198 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
2202 /*****************************************************************************
2203 * Update*FromAccess:
2204 *****************************************************************************/
2205 static int UpdateTitleSeekpointFromAccess( input_thread_t *p_input )
2207 access_t *p_access = p_input->p->input.p_access;
2209 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
2211 input_SendEventTitle( p_input, p_access->info.i_title );
2213 stream_Control( p_input->p->input.p_stream, STREAM_UPDATE_SIZE );
2215 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
2217 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
2219 input_SendEventSeekpoint( p_input,
2220 p_access->info.i_title, p_access->info.i_seekpoint );
2222 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2224 /* Hmmm only works with master input */
2225 if( p_input->p->input.p_access == p_access )
2226 return UpdateTitleSeekpoint( p_input,
2227 p_access->info.i_title,
2228 p_access->info.i_seekpoint );
2231 static void UpdateGenericFromAccess( input_thread_t *p_input )
2233 access_t *p_access = p_input->p->input.p_access;
2235 if( p_access->info.i_update & INPUT_UPDATE_META )
2237 /* TODO maybe multi - access ? */
2238 vlc_meta_t *p_meta = vlc_meta_New();
2241 access_Control( p_input->p->input.p_access, ACCESS_GET_META, p_meta );
2242 InputUpdateMeta( p_input, p_meta );
2244 p_access->info.i_update &= ~INPUT_UPDATE_META;
2246 if( p_access->info.i_update & INPUT_UPDATE_SIGNAL )
2251 if( access_Control( p_access, ACCESS_GET_SIGNAL, &f_quality, &f_strength ) )
2252 f_quality = f_strength = -1;
2254 input_SendEventSignal( p_input, f_quality, f_strength );
2256 p_access->info.i_update &= ~INPUT_UPDATE_SIGNAL;
2259 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
2262 /*****************************************************************************
2264 *****************************************************************************/
2265 static input_source_t *InputSourceNew( input_thread_t *p_input )
2267 VLC_UNUSED(p_input);
2269 return calloc( 1, sizeof( input_source_t ) );
2272 /*****************************************************************************
2274 *****************************************************************************/
2275 static int InputSourceInit( input_thread_t *p_input,
2276 input_source_t *in, const char *psz_mrl,
2277 const char *psz_forced_demux )
2279 char psz_dup[strlen(psz_mrl) + 1];
2280 const char *psz_access;
2281 const char *psz_demux;
2285 strcpy( psz_dup, psz_mrl );
2288 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_dup );
2290 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
2291 psz_mrl, psz_access, psz_demux, psz_path );
2292 if( !p_input->b_preparsing )
2294 /* Hack to allow udp://@:port syntax */
2296 (strncmp( psz_access, "udp", 3 ) &&
2297 strncmp( psz_access, "rtp", 3 )) )
2299 /* Find optional titles and seekpoints */
2300 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
2301 &in->i_seekpoint_start, &in->i_seekpoint_end );
2304 if( psz_forced_demux && *psz_forced_demux )
2306 psz_demux = psz_forced_demux;
2308 else if( *psz_demux == '\0' )
2310 /* special hack for forcing a demuxer with --demux=module
2311 * (and do nothing with a list) */
2312 char *psz_var_demux = var_GetNonEmptyString( p_input, "demux" );
2314 if( psz_var_demux != NULL &&
2315 !strchr(psz_var_demux, ',' ) &&
2316 !strchr(psz_var_demux, ':' ) )
2318 psz_demux = psz_var_demux;
2320 msg_Dbg( p_input, "enforced demux ` %s'", psz_demux );
2324 /* Try access_demux first */
2325 in->p_demux = demux_New( p_input, psz_access, psz_demux, psz_path,
2326 NULL, p_input->p->p_es_out, false );
2330 /* Preparsing is only for file:// */
2333 if( !*psz_access ) /* path without scheme:// */
2334 psz_access = "file";
2335 if( strcmp( psz_access, "file" ) )
2337 msg_Dbg( p_input, "trying to pre-parse %s", psz_path );
2342 /* Get infos from access_demux */
2343 demux_Control( in->p_demux,
2344 DEMUX_GET_PTS_DELAY, &in->i_pts_delay );
2346 in->b_title_demux = true;
2347 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2348 &in->title, &in->i_title,
2349 &in->i_title_offset, &in->i_seekpoint_offset ) )
2351 TAB_INIT( in->i_title, in->title );
2353 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
2354 &in->b_can_pace_control ) )
2355 in->b_can_pace_control = false;
2357 if( !in->b_can_pace_control )
2359 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_RATE,
2360 &in->b_can_rate_control, &in->b_rescale_ts ) )
2362 in->b_can_rate_control = false;
2363 in->b_rescale_ts = true; /* not used */
2368 in->b_can_rate_control = true;
2369 in->b_rescale_ts = true;
2371 if( demux_Control( in->p_demux, DEMUX_CAN_PAUSE,
2372 &in->b_can_pause ) )
2373 in->b_can_pause = false;
2374 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2375 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2376 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control );
2379 if( demux_Control( in->p_demux, DEMUX_CAN_SEEK, &b_can_seek ) )
2381 var_SetBool( p_input, "can-seek", b_can_seek );
2385 /* Now try a real access */
2386 in->p_access = access_New( p_input, psz_access, psz_demux, psz_path );
2388 /* Access failed, URL encoded ? */
2389 if( in->p_access == NULL && strchr( psz_path, '%' ) )
2391 decode_URI( psz_path );
2393 msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
2394 psz_access, psz_demux, psz_path );
2396 in->p_access = access_New( p_input,
2397 psz_access, psz_demux, psz_path );
2399 if( in->p_access == NULL )
2401 msg_Err( p_input, "open of `%s' failed: %s", psz_mrl,
2403 dialog_Fatal( p_input, _("Your input can't be opened"),
2404 _("VLC is unable to open the MRL '%s'."
2405 " Check the log for details."), psz_mrl );
2409 /* Get infos from access */
2410 if( !p_input->b_preparsing )
2413 access_Control( in->p_access,
2414 ACCESS_GET_PTS_DELAY, &in->i_pts_delay );
2416 in->b_title_demux = false;
2417 if( access_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2418 &in->title, &in->i_title,
2419 &in->i_title_offset, &in->i_seekpoint_offset ) )
2422 TAB_INIT( in->i_title, in->title );
2424 access_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2425 &in->b_can_pace_control );
2426 in->b_can_rate_control = in->b_can_pace_control;
2427 in->b_rescale_ts = true;
2429 access_Control( in->p_access, ACCESS_CAN_PAUSE, &in->b_can_pause );
2430 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2431 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2432 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control );
2434 access_Control( in->p_access, ACCESS_CAN_SEEK, &b_can_seek );
2435 var_SetBool( p_input, "can-seek", b_can_seek );
2440 char **ppsz_input_list;
2442 TAB_INIT( i_input_list, ppsz_input_list );
2444 /* On master stream only, use input-list */
2445 if( &p_input->p->input == in )
2451 psz_parser = var_CreateGetNonEmptyString( p_input, "input-list" );
2453 while( psz_parser && *psz_parser )
2455 char *p = strchr( psz_parser, ',' );
2461 char *psz_name = strdup( psz_parser );
2463 TAB_APPEND( i_input_list, ppsz_input_list, psz_name );
2470 /* Autodetect extra files if none specified */
2471 if( i_input_list <= 0 )
2473 InputGetExtraFiles( p_input, &i_input_list, &ppsz_input_list,
2474 psz_access, psz_path );
2476 if( i_input_list > 0 )
2477 TAB_APPEND( i_input_list, ppsz_input_list, NULL );
2479 /* Create the stream_t */
2480 in->p_stream = stream_AccessNew( in->p_access, ppsz_input_list );
2481 if( ppsz_input_list )
2483 for( int i = 0; ppsz_input_list[i] != NULL; i++ )
2484 free( ppsz_input_list[i] );
2485 TAB_CLEAN( i_input_list, ppsz_input_list );
2488 if( in->p_stream == NULL )
2490 msg_Warn( p_input, "cannot create a stream_t from access" );
2494 /* Add stream filters */
2495 char *psz_stream_filter = var_GetNonEmptyString( p_input,
2497 in->p_stream = stream_FilterChainNew( in->p_stream,
2499 var_GetBool( p_input, "input-record-native" ) );
2500 free( psz_stream_filter );
2502 /* Open a demuxer */
2503 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2505 psz_demux = in->p_access->psz_demux;
2509 /* Take access/stream redirections into account */
2510 char *psz_real_path;
2511 char *psz_buf = NULL;
2512 if( in->p_stream->psz_path )
2514 const char *psz_a, *psz_d;
2515 psz_buf = strdup( in->p_stream->psz_path );
2516 input_SplitMRL( &psz_a, &psz_d, &psz_real_path, psz_buf );
2520 psz_real_path = psz_path;
2522 in->p_demux = demux_New( p_input, psz_access, psz_demux,
2524 in->p_stream, p_input->p->p_es_out,
2525 p_input->b_preparsing );
2529 if( in->p_demux == NULL )
2531 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2532 psz_access, psz_demux, psz_path );
2533 dialog_Fatal( VLC_OBJECT( p_input ),
2534 _("VLC can't recognize the input's format"),
2535 _("The format of '%s' cannot be detected. "
2536 "Have a look at the log for details."), psz_mrl );
2540 /* Get title from demux */
2541 if( !p_input->b_preparsing && in->i_title <= 0 )
2543 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2544 &in->title, &in->i_title,
2545 &in->i_title_offset, &in->i_seekpoint_offset ))
2547 TAB_INIT( in->i_title, in->title );
2551 in->b_title_demux = true;
2556 /* Set record capabilities */
2557 if( demux_Control( in->p_demux, DEMUX_CAN_RECORD, &in->b_can_stream_record ) )
2558 in->b_can_stream_record = false;
2560 if( !var_GetBool( p_input, "input-record-native" ) )
2561 in->b_can_stream_record = false;
2562 var_SetBool( p_input, "can-record", true );
2564 var_SetBool( p_input, "can-record", in->b_can_stream_record );
2568 * FIXME improve for b_preparsing: move it after GET_META and check psz_arturl */
2569 if( 1 || !p_input->b_preparsing )
2572 input_attachment_t **attachment;
2573 if( !demux_Control( in->p_demux, DEMUX_GET_ATTACHMENTS,
2574 &attachment, &i_attachment ) )
2576 vlc_mutex_lock( &p_input->p->p_item->lock );
2577 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2578 i_attachment, attachment );
2579 vlc_mutex_unlock( &p_input->p->p_item->lock );
2582 if( !demux_Control( in->p_demux, DEMUX_GET_FPS, &f_fps ) && f_fps > 0.0 )
2584 vlc_mutex_lock( &p_input->p->p_item->lock );
2585 p_input->p->f_fps = f_fps;
2586 vlc_mutex_unlock( &p_input->p->p_item->lock );
2589 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2590 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2596 demux_Delete( in->p_demux );
2599 stream_Delete( in->p_stream );
2602 access_Delete( in->p_access );
2604 return VLC_EGENERIC;
2607 /*****************************************************************************
2609 *****************************************************************************/
2610 static void InputSourceClean( input_source_t *in )
2615 demux_Delete( in->p_demux );
2618 stream_Delete( in->p_stream );
2621 access_Delete( in->p_access );
2623 if( in->i_title > 0 )
2625 for( i = 0; i < in->i_title; i++ )
2626 vlc_input_title_Delete( in->title[i] );
2627 TAB_CLEAN( in->i_title, in->title );
2631 /*****************************************************************************
2633 *****************************************************************************/
2634 static void InputSourceMeta( input_thread_t *p_input,
2635 input_source_t *p_source, vlc_meta_t *p_meta )
2637 access_t *p_access = p_source->p_access;
2638 demux_t *p_demux = p_source->p_demux;
2640 /* XXX Remember that checking against p_item->p_meta->i_status & ITEM_PREPARSED
2643 /* Read access meta */
2645 access_Control( p_access, ACCESS_GET_META, p_meta );
2647 /* Read demux meta */
2648 demux_Control( p_demux, DEMUX_GET_META, p_meta );
2650 /* If the demux report unsupported meta data, try an external "meta reader" */
2652 if( demux_Control( p_demux, DEMUX_HAS_UNSUPPORTED_META, &b_bool ) )
2657 demux_meta_t *p_demux_meta = p_demux->p_private = calloc( 1, sizeof(*p_demux_meta) );
2661 module_t *p_id3 = module_need( p_demux, "meta reader", NULL, false );
2664 if( p_demux_meta->p_meta )
2666 vlc_meta_Merge( p_meta, p_demux_meta->p_meta );
2667 vlc_meta_Delete( p_demux_meta->p_meta );
2670 if( p_demux_meta->i_attachments > 0 )
2672 vlc_mutex_lock( &p_input->p->p_item->lock );
2673 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2674 p_demux_meta->i_attachments, p_demux_meta->attachments );
2675 vlc_mutex_unlock( &p_input->p->p_item->lock );
2677 module_unneed( p_demux, p_id3 );
2679 free( p_demux_meta );
2683 static void SlaveDemux( input_thread_t *p_input )
2688 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2690 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2694 for( i = 0; i < p_input->p->i_slave; i++ )
2696 input_source_t *in = p_input->p->slave[i];
2702 if( demux_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2707 if( demux_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2709 msg_Err( p_input, "slave[%d] doesn't like "
2710 "DEMUX_GET_TIME -> EOF", i );
2715 if( i_stime >= i_time )
2718 if( ( i_ret = demux_Demux( in->p_demux ) ) <= 0 )
2724 i_ret = demux_Demux( in->p_demux );
2729 msg_Dbg( p_input, "slave %d EOF", i );
2735 static void SlaveSeek( input_thread_t *p_input )
2740 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2742 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2746 for( i = 0; i < p_input->p->i_slave; i++ )
2748 input_source_t *in = p_input->p->slave[i];
2750 if( demux_Control( in->p_demux, DEMUX_SET_TIME, i_time, true ) )
2753 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2763 /*****************************************************************************
2765 *****************************************************************************/
2766 static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta )
2768 /* Get meta information from user */
2769 #define GET_META( field, s ) do { \
2770 char *psz_string = var_GetNonEmptyString( p_input, (s) ); \
2772 vlc_meta_Set( p_meta, vlc_meta_ ## field, psz_string ); \
2773 free( psz_string ); } while(0)
2775 GET_META( Title, "meta-title" );
2776 GET_META( Artist, "meta-artist" );
2777 GET_META( Genre, "meta-genre" );
2778 GET_META( Copyright, "meta-copyright" );
2779 GET_META( Description, "meta-description" );
2780 GET_META( Date, "meta-date" );
2781 GET_META( URL, "meta-url" );
2785 /*****************************************************************************
2786 * InputUpdateMeta: merge p_item meta data with p_meta taking care of
2787 * arturl and locking issue.
2788 *****************************************************************************/
2789 static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta )
2791 input_item_t *p_item = p_input->p->p_item;
2793 char *psz_title = NULL;
2794 char *psz_arturl = input_item_GetArtURL( p_item );
2796 vlc_mutex_lock( &p_item->lock );
2798 if( vlc_meta_Get( p_meta, vlc_meta_Title ) && !p_item->b_fixed_name )
2799 psz_title = strdup( vlc_meta_Get( p_meta, vlc_meta_Title ) );
2801 vlc_meta_Merge( p_item->p_meta, p_meta );
2803 vlc_meta_Delete( p_meta );
2805 if( !psz_arturl || *psz_arturl == '\0' )
2807 const char *psz_tmp = vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL );
2809 psz_arturl = strdup( psz_tmp );
2811 vlc_mutex_unlock( &p_item->lock );
2813 if( psz_arturl && *psz_arturl )
2815 input_item_SetArtURL( p_item, psz_arturl );
2817 if( !strncmp( psz_arturl, "attachment://", strlen("attachment") ) )
2819 /* Don't look for art cover if sout
2820 * XXX It can change when sout has meta data support */
2821 if( p_input->p->p_sout && !p_input->b_preparsing )
2822 input_item_SetArtURL( p_item, "" );
2824 input_ExtractAttachmentAndCacheArt( p_input );
2831 input_item_SetName( p_item, psz_title );
2834 input_item_SetPreparsed( p_item, true );
2836 input_SendEventMeta( p_input );
2838 /** \todo handle sout meta */
2841 static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
2842 int i_new, input_attachment_t **pp_new )
2844 int i_attachment = *pi_attachment;
2845 input_attachment_t **attachment = *ppp_attachment;
2848 attachment = realloc( attachment,
2849 sizeof(input_attachment_t**) * ( i_attachment + i_new ) );
2850 for( i = 0; i < i_new; i++ )
2851 attachment[i_attachment++] = pp_new[i];
2855 *pi_attachment = i_attachment;
2856 *ppp_attachment = attachment;
2858 /*****************************************************************************
2859 * InputGetExtraFiles
2860 * Autodetect extra input list
2861 *****************************************************************************/
2862 static void InputGetExtraFilesPattern( input_thread_t *p_input,
2863 int *pi_list, char ***pppsz_list,
2864 const char *psz_path,
2865 const char *psz_match,
2866 const char *psz_format,
2867 int i_start, int i_stop )
2872 TAB_INIT( i_list, ppsz_list );
2874 char *psz_base = strdup( psz_path );
2878 /* Remove the extension */
2879 char *psz_end = &psz_base[strlen(psz_base)-strlen(psz_match)];
2880 assert( psz_end >= psz_base);
2883 /* Try to list files */
2884 for( int i = i_start; i <= i_stop; i++ )
2889 if( asprintf( &psz_file, psz_format, psz_base, i ) < 0 )
2892 if( utf8_stat( psz_file, &st ) || !S_ISREG( st.st_mode ) || !st.st_size )
2898 msg_Dbg( p_input, "Detected extra file `%s'", psz_file );
2899 TAB_APPEND( i_list, ppsz_list, psz_file );
2904 *pppsz_list = ppsz_list;
2907 static void InputGetExtraFiles( input_thread_t *p_input,
2908 int *pi_list, char ***pppsz_list,
2909 const char *psz_access, const char *psz_path )
2913 const char *psz_match;
2914 const char *psz_format;
2918 /* XXX the order is important */
2919 { ".001", "%s.%.3d", 2, 999 },
2920 { ".part1.rar", "%s.part%.1d.rar",2, 9 },
2921 { ".part01.rar", "%s.part%.2d.rar",2, 99, },
2922 { ".part001.rar", "%s.part%.3d.rar",2, 999 },
2923 { ".rar", "%s.r%.2d", 1, 99 },
2924 { NULL, NULL, 0, 0 }
2927 TAB_INIT( *pi_list, *pppsz_list );
2929 if( ( psz_access && *psz_access && strcmp( psz_access, "file" ) ) || !psz_path )
2932 const size_t i_path = strlen(psz_path);
2934 for( int i = 0; p_pattern[i].psz_match != NULL; i++ )
2936 const size_t i_ext = strlen(p_pattern[i].psz_match );
2938 if( i_path < i_ext )
2940 if( !strcmp( &psz_path[i_path-i_ext], p_pattern[i].psz_match ) )
2942 InputGetExtraFilesPattern( p_input, pi_list, pppsz_list,
2944 p_pattern[i].psz_match, p_pattern[i].psz_format,
2945 p_pattern[i].i_start, p_pattern[i].i_stop );
2952 static void input_ChangeState( input_thread_t *p_input, int i_state )
2954 const bool b_changed = p_input->p->i_state != i_state;
2956 p_input->p->i_state = i_state;
2957 if( i_state == ERROR_S )
2958 p_input->b_error = true;
2959 else if( i_state == END_S )
2960 p_input->b_eof = true;
2964 input_item_SetErrorWhenReading( p_input->p->p_item, p_input->b_error );
2965 input_SendEventState( p_input, i_state );
2970 /*****************************************************************************
2971 * MRLSplit: parse the access, demux and url part of the
2972 * Media Resource Locator.
2973 *****************************************************************************/
2974 void input_SplitMRL( const char **ppsz_access, const char **ppsz_demux, char **ppsz_path,
2977 char *psz_access = NULL;
2978 char *psz_demux = NULL;
2981 /* Either there is an access/demux specification before ://
2982 * or we have a plain local file path. */
2983 psz_path = strstr( psz_dup, "://" );
2984 if( psz_path != NULL )
2987 psz_path += 3; /* skips "://" */
2989 /* Separate access from demux (<access>/<demux>://<path>) */
2990 psz_access = psz_dup;
2991 psz_demux = strchr( psz_access, '/' );
2993 *psz_demux++ = '\0';
2995 /* We really don't want module name substitution here! */
2996 if( psz_access[0] == '$' )
2998 if( psz_demux && psz_demux[0] == '$' )
3005 *ppsz_access = psz_access ? psz_access : (char*)"";
3006 *ppsz_demux = psz_demux ? psz_demux : (char*)"";
3007 *ppsz_path = psz_path;
3010 static inline bool next(char ** src)
3014 long result = strtol( *src, &end, 0 );
3015 if( errno != 0 || result >= LONG_MAX || result <= LONG_MIN ||
3024 /*****************************************************************************
3025 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
3028 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
3029 *****************************************************************************/
3030 static void MRLSections( input_thread_t *p_input, char *psz_source,
3031 int *pi_title_start, int *pi_title_end,
3032 int *pi_chapter_start, int *pi_chapter_end )
3034 char *psz, *psz_end, *psz_next, *psz_check;
3036 *pi_title_start = *pi_title_end = -1;
3037 *pi_chapter_start = *pi_chapter_end = -1;
3039 /* Start by parsing titles and chapters */
3040 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
3043 /* Check we are really dealing with a title/chapter section */
3044 psz_check = psz + 1;
3045 if( !*psz_check ) return;
3046 if( isdigit(*psz_check) )
3047 if(!next(&psz_check)) return;
3048 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
3049 if( *psz_check == ':' && ++psz_check )
3051 if( isdigit(*psz_check) )
3052 if(!next(&psz_check)) return;
3054 if( *psz_check != '-' && *psz_check ) return;
3055 if( *psz_check == '-' && ++psz_check )
3057 if( isdigit(*psz_check) )
3058 if(!next(&psz_check)) return;
3060 if( *psz_check != ':' && *psz_check ) return;
3061 if( *psz_check == ':' && ++psz_check )
3063 if( isdigit(*psz_check) )
3064 if(!next(&psz_check)) return;
3066 if( *psz_check ) return;
3068 /* Separate start and end */
3070 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
3072 /* Look for the start title */
3073 *pi_title_start = strtol( psz, &psz_next, 0 );
3074 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
3075 *pi_title_end = *pi_title_start;
3078 /* Look for the start chapter */
3080 *pi_chapter_start = strtol( psz, &psz_next, 0 );
3081 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
3082 *pi_chapter_end = *pi_chapter_start;
3086 /* Look for the end title */
3087 *pi_title_end = strtol( psz_end, &psz_next, 0 );
3088 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
3091 /* Look for the end chapter */
3092 if( *psz_end ) psz_end++;
3093 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
3094 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
3097 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
3098 psz_source, *pi_title_start, *pi_chapter_start,
3099 *pi_title_end, *pi_chapter_end );
3102 /*****************************************************************************
3103 * input_AddSubtitles: add a subtitles file and enable it
3104 *****************************************************************************/
3105 static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_forced )
3107 input_source_t *sub;
3110 char *psz_path, *psz_extension;
3112 /* if we are provided a subtitle.sub file,
3113 * see if we don't have a subtitle.idx and use it instead */
3114 psz_path = strdup( psz_subtitle );
3117 psz_extension = strrchr( psz_path, '.');
3118 if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
3122 strcpy( psz_extension, ".idx" );
3124 if( !utf8_stat( psz_path, &st ) && S_ISREG( st.st_mode ) )
3126 msg_Dbg( p_input, "using %s subtitles file instead of %s",
3127 psz_path, psz_subtitle );
3128 strcpy( psz_subtitle, psz_path );
3134 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
3136 sub = InputSourceNew( p_input );
3137 if( !sub || InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
3142 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
3145 if( b_forced && !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
3147 if( count.i_int == 0 )
3149 /* if it was first one, there is disable too */
3151 if( count.i_int < list.p_list->i_count )
3153 const int i_id = list.p_list->p_values[count.i_int].i_int;
3155 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_DEFAULT_BY_ID, i_id );
3156 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, i_id );
3158 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
3162 /*****************************************************************************
3164 *****************************************************************************/
3165 void input_UpdateStatistic( input_thread_t *p_input,
3166 input_statistic_t i_type, int i_delta )
3168 assert( p_input->p->i_state != INIT_S );
3170 vlc_mutex_lock( &p_input->p->counters.counters_lock);
3173 #define I(c) stats_UpdateInteger( p_input, p_input->p->counters.c, i_delta, NULL )
3174 case INPUT_STATISTIC_DECODED_VIDEO:
3177 case INPUT_STATISTIC_DECODED_AUDIO:
3180 case INPUT_STATISTIC_DECODED_SUBTITLE:
3183 case INPUT_STATISTIC_SENT_PACKET:
3184 I(p_sout_sent_packets);
3187 case INPUT_STATISTIC_SENT_BYTE:
3189 int i_bytes; /* That's pretty stupid to define it as an integer, it will overflow
3191 if( !stats_UpdateInteger( p_input, p_input->p->counters.p_sout_sent_bytes, i_delta, &i_bytes ) )
3192 stats_UpdateFloat( p_input, p_input->p->counters.p_sout_send_bitrate, i_bytes, NULL );
3196 msg_Err( p_input, "Invalid statistic type %d (internal error)", i_type );
3199 vlc_mutex_unlock( &p_input->p->counters.counters_lock);
3203 /* TODO FIXME nearly the same logic that snapshot code */
3204 char *input_CreateFilename( vlc_object_t *p_obj, const char *psz_path, const char *psz_prefix, const char *psz_extension )
3209 path = utf8_opendir( psz_path );
3214 char *psz_tmp = str_format( p_obj, psz_prefix );
3218 filename_sanitize( psz_tmp );
3219 if( asprintf( &psz_file, "%s"DIR_SEP"%s%s%s",
3221 psz_extension ? "." : "",
3222 psz_extension ? psz_extension : "" ) < 0 )
3229 psz_file = str_format( p_obj, psz_path );
3230 path_sanitize( psz_file );