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>
55 #include <vlc_strings.h>
57 #ifdef HAVE_SYS_STAT_H
58 # include <sys/stat.h>
61 /*****************************************************************************
63 *****************************************************************************/
64 static void Destructor( input_thread_t * p_input );
66 static void *Run ( 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, bool b_interactive );
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, bool b_postpone_seek );
77 static void ControlRelease( int i_type, vlc_value_t val );
78 static bool ControlIsSeekRequest( int i_type );
79 static bool Control( input_thread_t *, int, vlc_value_t );
81 static int UpdateTitleSeekpointFromAccess( input_thread_t * );
82 static void UpdateGenericFromAccess( input_thread_t * );
84 static int UpdateTitleSeekpointFromDemux( input_thread_t * );
85 static void UpdateGenericFromDemux( input_thread_t * );
87 static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
89 static input_source_t *InputSourceNew( input_thread_t *);
90 static int InputSourceInit( input_thread_t *, input_source_t *,
91 const char *, const char *psz_forced_demux );
92 static void InputSourceClean( input_source_t * );
93 static void InputSourceMeta( input_thread_t *, input_source_t *, vlc_meta_t * );
96 //static void InputGetAttachments( input_thread_t *, input_source_t * );
97 static void SlaveDemux( input_thread_t *p_input, bool *pb_demux_polled );
98 static void SlaveSeek( input_thread_t *p_input );
100 static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta );
101 static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta );
102 static void InputGetExtraFiles( input_thread_t *p_input,
103 int *pi_list, char ***pppsz_list,
104 const char *psz_access, const char *psz_path );
106 static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
107 int i_new, input_attachment_t **pp_new );
109 static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_forced );
111 static void input_ChangeState( input_thread_t *p_input, int i_state ); /* TODO fix name */
115 * Create a new input_thread_t.
117 * You need to call input_Start on it when you are done
118 * adding callback on the variables/events you want to monitor.
120 * \param p_parent a vlc_object
121 * \param p_item an input item
122 * \param psz_log an optional prefix for this input logs
123 * \param p_resource an optional input ressource
124 * \return a pointer to the spawned input thread
126 input_thread_t *input_Create( vlc_object_t *p_parent,
127 input_item_t *p_item,
128 const char *psz_log, input_resource_t *p_resource )
130 return Create( p_parent, p_item, psz_log, false, p_resource );
133 #undef input_CreateAndStart
135 * Create a new input_thread_t and start it.
137 * Provided for convenience.
141 input_thread_t *input_CreateAndStart( vlc_object_t *p_parent,
142 input_item_t *p_item, const char *psz_log )
144 input_thread_t *p_input = input_Create( p_parent, p_item, psz_log, NULL );
146 if( input_Start( p_input ) )
148 vlc_object_release( p_input );
156 * Initialize an input thread and run it until it stops by itself.
158 * \param p_parent a vlc_object
159 * \param p_item an input item
160 * \return an error code, VLC_SUCCESS on success
162 int input_Read( vlc_object_t *p_parent, input_item_t *p_item )
164 input_thread_t *p_input = Create( p_parent, p_item, NULL, false, NULL );
168 if( !Init( p_input ) )
170 MainLoop( p_input, false );
174 vlc_object_release( p_input );
179 * Initialize an input and initialize it to preparse the item
180 * This function is blocking. It will only accept parsing regular files.
182 * \param p_parent a vlc_object_t
183 * \param p_item an input item
184 * \return VLC_SUCCESS or an error
186 int input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
188 input_thread_t *p_input;
190 /* Allocate descriptor */
191 p_input = Create( p_parent, p_item, NULL, true, NULL );
195 if( !Init( p_input ) )
198 vlc_object_release( p_input );
204 * Start a input_thread_t created by input_Create.
206 * You must not start an already running input_thread_t.
208 * \param the input thread to start
210 int input_Start( input_thread_t *p_input )
212 /* Create thread and wait for its readiness. */
213 if( vlc_thread_create( p_input, "input", Run,
214 VLC_THREAD_PRIORITY_INPUT ) )
216 input_ChangeState( p_input, ERROR_S );
217 msg_Err( p_input, "cannot create input thread" );
224 * Request a running input thread to stop and die
226 * b_abort must be true when a user stop is requested and not because you have
227 * detected an error or an eof. It will be used to properly send the
228 * INPUT_EVENT_ABORT event.
230 * \param p_input the input thread to stop
231 * \param b_abort true if the input has been aborted by a user request
233 void input_Stop( input_thread_t *p_input, bool b_abort )
235 /* Set die for input and ALL of this childrens (even (grand-)grand-childrens)
236 * It is needed here even if it is done in INPUT_CONTROL_SET_DIE handler to
237 * unlock the control loop */
238 ObjectKillChildrens( p_input, VLC_OBJECT(p_input) );
240 vlc_mutex_lock( &p_input->p->lock_control );
241 p_input->p->b_abort |= b_abort;
242 vlc_mutex_unlock( &p_input->p->lock_control );
244 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
247 input_resource_t *input_DetachResource( input_thread_t *p_input )
249 assert( p_input->b_dead );
251 input_resource_SetInput( p_input->p->p_resource, NULL );
253 input_resource_t *p_resource = input_resource_Detach( p_input->p->p_resource );
254 p_input->p->p_sout = NULL;
260 * Get the item from an input thread
261 * FIXME it does not increase ref count of the item.
262 * if it is used after p_input is destroyed nothing prevent it from
265 input_item_t *input_GetItem( input_thread_t *p_input )
267 assert( p_input && p_input->p );
268 return p_input->p->p_item;
271 /*****************************************************************************
272 * ObjectKillChildrens
273 *****************************************************************************/
274 static void ObjectKillChildrens( input_thread_t *p_input, vlc_object_t *p_obj )
279 /* FIXME ObjectKillChildrens seems a very bad idea in fact */
280 i = vlc_internals( p_obj )->i_object_type;
281 if( i == VLC_OBJECT_VOUT ||i == VLC_OBJECT_AOUT ||
282 p_obj == VLC_OBJECT(p_input->p->p_sout) ||
283 i == VLC_OBJECT_DECODER )
286 vlc_object_kill( p_obj );
288 p_list = vlc_list_children( p_obj );
289 for( i = 0; i < p_list->i_count; i++ )
290 ObjectKillChildrens( p_input, p_list->p_values[i].p_object );
291 vlc_list_release( p_list );
294 /*****************************************************************************
295 * This function creates a new input, and returns a pointer
296 * to its description. On error, it returns NULL.
298 * XXX Do not forget to update vlc_input.h if you add new variables.
299 *****************************************************************************/
300 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
301 const char *psz_header, bool b_quick,
302 input_resource_t *p_resource )
304 static const char input_name[] = "input";
305 input_thread_t *p_input = NULL; /* thread descriptor */
308 /* Allocate descriptor */
309 p_input = vlc_custom_create( p_parent, sizeof( *p_input ),
310 VLC_OBJECT_INPUT, input_name );
311 if( p_input == NULL )
314 vlc_object_attach( p_input, p_parent );
316 /* Construct a nice name for the input timer */
317 char psz_timer_name[255];
318 char * psz_name = input_item_GetName( p_item );
319 snprintf( psz_timer_name, sizeof(psz_timer_name),
320 "input launching for '%s'", psz_name );
322 msg_Dbg( p_input, "Creating an input for '%s'", psz_name);
326 /* Start a timer to mesure how long it takes
327 * to launch an input */
328 stats_TimerStart( p_input, psz_timer_name,
329 STATS_TIMER_INPUT_LAUNCHING );
331 p_input->p = calloc( 1, sizeof( input_thread_private_t ) );
335 /* Parse input options */
336 vlc_mutex_lock( &p_item->lock );
337 assert( (int)p_item->optflagc == p_item->i_options );
338 for( i = 0; i < p_item->i_options; i++ )
339 var_OptionParse( VLC_OBJECT(p_input), p_item->ppsz_options[i],
340 !!(p_item->optflagv[i] & VLC_INPUT_OPTION_TRUSTED) );
341 vlc_mutex_unlock( &p_item->lock );
343 p_input->b_preparsing = b_quick;
344 p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
346 /* Init Common fields */
347 p_input->b_eof = false;
348 p_input->p->b_can_pace_control = true;
349 p_input->p->i_start = 0;
350 p_input->p->i_time = 0;
351 p_input->p->i_stop = 0;
352 p_input->p->i_run = 0;
353 p_input->p->i_title = 0;
354 p_input->p->title = NULL;
355 p_input->p->i_title_offset = p_input->p->i_seekpoint_offset = 0;
356 p_input->p->i_state = INIT_S;
357 double f_rate = var_InheritFloat( p_input, "rate" );
360 msg_Warn( p_input, "Negative or zero rate values are forbidden" );
363 p_input->p->i_rate = INPUT_RATE_DEFAULT / f_rate;
364 p_input->p->b_recording = false;
365 memset( &p_input->p->bookmark, 0, sizeof(p_input->p->bookmark) );
366 TAB_INIT( p_input->p->i_bookmark, p_input->p->pp_bookmark );
367 TAB_INIT( p_input->p->i_attachment, p_input->p->attachment );
368 p_input->p->p_sout = NULL;
369 p_input->p->b_out_pace_control = false;
371 vlc_gc_incref( p_item ); /* Released in Destructor() */
372 p_input->p->p_item = p_item;
374 /* Init Input fields */
375 p_input->p->input.p_access = NULL;
376 p_input->p->input.p_stream = NULL;
377 p_input->p->input.p_demux = NULL;
378 p_input->p->input.b_title_demux = false;
379 p_input->p->input.i_title = 0;
380 p_input->p->input.title = NULL;
381 p_input->p->input.i_title_offset = p_input->p->input.i_seekpoint_offset = 0;
382 p_input->p->input.b_can_pace_control = true;
383 p_input->p->input.b_can_rate_control = true;
384 p_input->p->input.b_rescale_ts = true;
385 p_input->p->input.b_eof = false;
387 vlc_mutex_lock( &p_item->lock );
389 if( !p_item->p_stats )
390 p_item->p_stats = stats_NewInputStats( p_input );
391 vlc_mutex_unlock( &p_item->lock );
394 p_input->p->i_slave = 0;
395 p_input->p->slave = NULL;
399 p_input->p->p_resource = p_resource;
401 p_input->p->p_resource = input_resource_New();
402 input_resource_SetInput( p_input->p->p_resource, p_input );
404 /* Init control buffer */
405 vlc_mutex_init( &p_input->p->lock_control );
406 vlc_cond_init( &p_input->p->wait_control );
407 p_input->p->i_control = 0;
408 p_input->p->b_abort = false;
410 /* Create Object Variables for private use only */
411 input_ConfigVarInit( p_input );
413 /* Create Objects variables for public Get and Set */
414 input_ControlVarInit( p_input );
417 if( !p_input->b_preparsing )
419 char *psz_bookmarks = var_GetNonEmptyString( p_input, "bookmarks" );
422 /* FIXME: have a common cfg parsing routine used by sout and others */
423 char *psz_parser, *psz_start, *psz_end;
424 psz_parser = psz_bookmarks;
425 while( (psz_start = strchr( psz_parser, '{' ) ) )
427 seekpoint_t *p_seekpoint;
430 psz_end = strchr( psz_start, '}' );
431 if( !psz_end ) break;
432 psz_parser = psz_end + 1;
433 backup = *psz_parser;
437 p_seekpoint = vlc_seekpoint_New();
438 while( (psz_end = strchr( psz_start, ',' ) ) )
441 if( !strncmp( psz_start, "name=", 5 ) )
443 p_seekpoint->psz_name = strdup(psz_start + 5);
445 else if( !strncmp( psz_start, "bytes=", 6 ) )
447 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
449 else if( !strncmp( psz_start, "time=", 5 ) )
451 p_seekpoint->i_time_offset = atoll(psz_start + 5) *
454 psz_start = psz_end + 1;
456 msg_Dbg( p_input, "adding bookmark: %s, bytes=%"PRId64", time=%"PRId64,
457 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
458 p_seekpoint->i_time_offset );
459 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
460 vlc_seekpoint_Delete( p_seekpoint );
461 *psz_parser = backup;
463 free( psz_bookmarks );
467 /* Remove 'Now playing' info as it is probably outdated */
468 input_item_SetNowPlaying( p_item, NULL );
469 input_SendEventMeta( p_input );
472 if( p_input->b_preparsing )
473 p_input->i_flags |= OBJECT_FLAGS_QUIET | OBJECT_FLAGS_NOINTERACT;
475 /* Make sure the interaction option is honored */
476 if( !var_InheritBool( p_input, "interact" ) )
477 p_input->i_flags |= OBJECT_FLAGS_NOINTERACT;
480 memset( &p_input->p->counters, 0, sizeof( p_input->p->counters ) );
481 vlc_mutex_init( &p_input->p->counters.counters_lock );
483 p_input->p->p_es_out_display = input_EsOutNew( p_input, p_input->p->i_rate );
484 p_input->p->p_es_out = NULL;
486 /* Set the destructor when we are sure we are initialized */
487 vlc_object_set_destructor( p_input, (vlc_destructor_t)Destructor );
493 * Input destructor (called when the object's refcount reaches 0).
495 static void Destructor( input_thread_t * p_input )
498 char * psz_name = input_item_GetName( p_input->p->p_item );
499 msg_Dbg( p_input, "Destroying the input for '%s'", psz_name);
503 stats_TimerDump( p_input, STATS_TIMER_INPUT_LAUNCHING );
504 stats_TimerClean( p_input, STATS_TIMER_INPUT_LAUNCHING );
506 if( p_input->p->p_es_out_display )
507 es_out_Delete( p_input->p->p_es_out_display );
509 if( p_input->p->p_resource )
510 input_resource_Delete( p_input->p->p_resource );
512 vlc_gc_decref( p_input->p->p_item );
514 vlc_mutex_destroy( &p_input->p->counters.counters_lock );
516 for( int i = 0; i < p_input->p->i_control; i++ )
518 input_control_t *p_ctrl = &p_input->p->control[i];
519 ControlRelease( p_ctrl->i_type, p_ctrl->val );
522 vlc_cond_destroy( &p_input->p->wait_control );
523 vlc_mutex_destroy( &p_input->p->lock_control );
527 /*****************************************************************************
528 * Run: main thread loop
529 * This is the "normal" thread that spawns the input processing chain,
530 * reads the stream, cleans up and waits
531 *****************************************************************************/
532 static void *Run( vlc_object_t *p_this )
534 input_thread_t *p_input = (input_thread_t *)p_this;
535 const int canc = vlc_savecancel();
537 if( Init( p_input ) )
540 MainLoop( p_input, true ); /* FIXME it can be wrong (like with VLM) */
546 /* Tell we're dead */
547 vlc_mutex_lock( &p_input->p->lock_control );
548 const bool b_abort = p_input->p->b_abort;
549 vlc_mutex_unlock( &p_input->p->lock_control );
552 input_SendEventAbort( p_input );
553 input_SendEventDead( p_input );
555 vlc_restorecancel( canc );
559 /*****************************************************************************
560 * Main loop: Fill buffers from access, and demux
561 *****************************************************************************/
565 * It asks the demuxer to demux some data
567 static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, bool *pb_demux_polled, mtime_t i_start_mdate )
572 *pb_demux_polled = p_input->p->input.p_demux->pf_demux != NULL;
574 if( ( p_input->p->i_stop > 0 && p_input->p->i_time >= p_input->p->i_stop ) ||
575 ( p_input->p->i_run > 0 && i_start_mdate+p_input->p->i_run < mdate() ) )
578 i_ret = demux_Demux( p_input->p->input.p_demux );
582 if( p_input->p->input.p_demux->info.i_update )
584 if( p_input->p->input.b_title_demux )
586 i_ret = UpdateTitleSeekpointFromDemux( p_input );
589 UpdateGenericFromDemux( p_input );
591 else if( p_input->p->input.p_access &&
592 p_input->p->input.p_access->info.i_update )
594 if( !p_input->p->input.b_title_demux )
596 i_ret = UpdateTitleSeekpointFromAccess( p_input );
599 UpdateGenericFromAccess( p_input );
603 if( i_ret == 0 ) /* EOF */
605 msg_Dbg( p_input, "EOF reached" );
606 p_input->p->input.b_eof = true;
610 input_ChangeState( p_input, ERROR_S );
613 if( i_ret > 0 && p_input->p->i_slave > 0 )
616 SlaveDemux( p_input, &b_demux_polled );
618 *pb_demux_polled |= b_demux_polled;
622 static int MainLoopTryRepeat( input_thread_t *p_input, mtime_t *pi_start_mdate )
624 int i_repeat = var_GetInteger( p_input, "input-repeat" );
630 msg_Dbg( p_input, "repeating the same input (%d)", i_repeat );
634 var_SetInteger( p_input, "input-repeat", i_repeat );
637 /* Seek to start title/seekpoint */
638 val.i_int = p_input->p->input.i_title_start -
639 p_input->p->input.i_title_offset;
640 if( val.i_int < 0 || val.i_int >= p_input->p->input.i_title )
642 input_ControlPush( p_input,
643 INPUT_CONTROL_SET_TITLE, &val );
645 val.i_int = p_input->p->input.i_seekpoint_start -
646 p_input->p->input.i_seekpoint_offset;
647 if( val.i_int > 0 /* TODO: check upper boundary */ )
648 input_ControlPush( p_input,
649 INPUT_CONTROL_SET_SEEKPOINT, &val );
651 /* Seek to start position */
652 if( p_input->p->i_start > 0 )
654 val.i_time = p_input->p->i_start;
655 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &val );
660 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &val );
664 *pi_start_mdate = mdate();
670 * It update the variables used by the interfaces
672 static void MainLoopInterface( input_thread_t *p_input )
674 double f_position = 0.0;
676 mtime_t i_length = 0;
678 /* update input status variables */
679 if( demux_Control( p_input->p->input.p_demux,
680 DEMUX_GET_POSITION, &f_position ) )
683 if( demux_Control( p_input->p->input.p_demux,
684 DEMUX_GET_TIME, &i_time ) )
686 p_input->p->i_time = i_time;
688 if( demux_Control( p_input->p->input.p_demux,
689 DEMUX_GET_LENGTH, &i_length ) )
692 es_out_SetTimes( p_input->p->p_es_out, f_position, i_time, i_length );
694 /* update current bookmark */
695 vlc_mutex_lock( &p_input->p->p_item->lock );
696 p_input->p->bookmark.i_time_offset = i_time;
697 if( p_input->p->input.p_stream )
698 p_input->p->bookmark.i_byte_offset = stream_Tell( p_input->p->input.p_stream );
699 vlc_mutex_unlock( &p_input->p->p_item->lock );
704 * It updates the globals statics
706 static void MainLoopStatistic( input_thread_t *p_input )
708 stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
709 input_SendEventStatistics( p_input );
714 * The main input loop.
716 static void MainLoop( input_thread_t *p_input, bool b_interactive )
718 mtime_t i_start_mdate = mdate();
719 mtime_t i_intf_update = 0;
720 mtime_t i_statistic_update = 0;
721 mtime_t i_last_seek_mdate = 0;
722 bool b_pause_after_eof = b_interactive &&
723 var_CreateGetBool( p_input, "play-and-pause" );
725 /* Start the timer */
726 stats_TimerStop( p_input, STATS_TIMER_INPUT_LAUNCHING );
728 while( vlc_object_alive( p_input ) && !p_input->b_error )
738 b_force_update = false;
740 /* FIXME if p_input->p->i_state == PAUSE_S the access/access_demux
741 * is paused -> this may cause problem with some of them
742 * The same problem can be seen when seeking while paused */
743 b_paused = p_input->p->i_state == PAUSE_S &&
744 ( !es_out_GetBuffering( p_input->p->p_es_out ) || p_input->p->input.b_eof );
746 b_demux_polled = true;
749 if( !p_input->p->input.b_eof )
751 MainLoopDemux( p_input, &b_force_update, &b_demux_polled, i_start_mdate );
753 i_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
755 else if( !es_out_GetEmpty( p_input->p->p_es_out ) )
757 msg_Dbg( p_input, "waiting decoder fifos to empty" );
758 i_wakeup = mdate() + INPUT_IDLE_SLEEP;
760 /* Pause after eof only if the input is pausable.
761 * This way we won't trigger timeshifting for nothing */
762 else if( b_pause_after_eof && p_input->p->b_can_pause )
764 msg_Dbg( p_input, "pausing at EOF (pause after each)");
766 Control( p_input, INPUT_CONTROL_SET_STATE, val );
768 b_pause_after_eof = false;
773 if( MainLoopTryRepeat( p_input, &i_start_mdate ) )
775 b_pause_after_eof = var_GetBool( p_input, "play-and-pause" );
781 mtime_t i_deadline = i_wakeup;
782 if( b_paused || !b_demux_polled )
783 i_deadline = __MIN( i_intf_update, i_statistic_update );
788 mtime_t i_limit = i_deadline;
790 /* We will postpone the execution of a seek until we have
791 * finished the ES bufferisation (postpone is limited to
793 bool b_buffering = es_out_GetBuffering( p_input->p->p_es_out ) &&
794 !p_input->p->input.b_eof;
797 /* When postpone is in order, check the ES level every 20ms */
798 mtime_t i_current = mdate();
799 if( i_last_seek_mdate + INT64_C(125000) >= i_current )
800 i_limit = __MIN( i_deadline, i_current + INT64_C(20000) );
804 if( ControlPop( p_input, &i_type, &val, i_limit, b_buffering ) )
806 if( b_buffering && i_limit < i_deadline )
811 msg_Dbg( p_input, "control type=%d", i_type );
813 if( Control( p_input, i_type, val ) )
815 if( ControlIsSeekRequest( i_type ) )
816 i_last_seek_mdate = mdate();
817 b_force_update = true;
821 /* Update interface and statistics */
823 if( i_intf_update < i_current || b_force_update )
825 MainLoopInterface( p_input );
826 i_intf_update = i_current + INT64_C(250000);
827 b_force_update = false;
829 if( i_statistic_update < i_current )
831 MainLoopStatistic( p_input );
832 i_statistic_update = i_current + INT64_C(1000000);
835 /* Update the wakeup time */
837 i_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
838 } while( i_current < i_wakeup );
841 if( !p_input->b_error )
842 input_ChangeState( p_input, END_S );
845 static void InitStatistics( input_thread_t * p_input )
847 if( p_input->b_preparsing ) return;
849 /* Prepare statistics */
850 #define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \
851 stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
852 if( libvlc_stats( p_input ) )
854 INIT_COUNTER( read_bytes, INTEGER, COUNTER );
855 INIT_COUNTER( read_packets, INTEGER, COUNTER );
856 INIT_COUNTER( demux_read, INTEGER, COUNTER );
857 INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE );
858 INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE );
859 INIT_COUNTER( demux_corrupted, INTEGER, COUNTER );
860 INIT_COUNTER( demux_discontinuity, INTEGER, COUNTER );
861 INIT_COUNTER( played_abuffers, INTEGER, COUNTER );
862 INIT_COUNTER( lost_abuffers, INTEGER, COUNTER );
863 INIT_COUNTER( displayed_pictures, INTEGER, COUNTER );
864 INIT_COUNTER( lost_pictures, INTEGER, COUNTER );
865 INIT_COUNTER( decoded_audio, INTEGER, COUNTER );
866 INIT_COUNTER( decoded_video, INTEGER, COUNTER );
867 INIT_COUNTER( decoded_sub, INTEGER, COUNTER );
868 p_input->p->counters.p_sout_send_bitrate = NULL;
869 p_input->p->counters.p_sout_sent_packets = NULL;
870 p_input->p->counters.p_sout_sent_bytes = NULL;
871 if( p_input->p->counters.p_demux_bitrate )
872 p_input->p->counters.p_demux_bitrate->update_interval = 1000000;
873 if( p_input->p->counters.p_input_bitrate )
874 p_input->p->counters.p_input_bitrate->update_interval = 1000000;
879 static int InitSout( input_thread_t * p_input )
881 if( p_input->b_preparsing )
884 /* Find a usable sout and attach it to p_input */
885 char *psz = var_GetNonEmptyString( p_input, "sout" );
886 if( psz && strncasecmp( p_input->p->p_item->psz_uri, "vlc:", 4 ) )
888 p_input->p->p_sout = input_resource_RequestSout( p_input->p->p_resource, NULL, psz );
889 if( !p_input->p->p_sout )
891 input_ChangeState( p_input, ERROR_S );
892 msg_Err( p_input, "cannot start stream output instance, " \
897 if( libvlc_stats( p_input ) )
899 INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
900 INIT_COUNTER( sout_sent_bytes, INTEGER, COUNTER );
901 INIT_COUNTER( sout_send_bitrate, FLOAT, DERIVATIVE );
902 if( p_input->p->counters.p_sout_send_bitrate )
903 p_input->p->counters.p_sout_send_bitrate->update_interval =
909 input_resource_RequestSout( p_input->p->p_resource, NULL, NULL );
917 static void InitTitle( input_thread_t * p_input )
919 input_source_t *p_master = &p_input->p->input;
921 if( p_input->b_preparsing )
924 /* Create global title (from master) */
925 p_input->p->i_title = p_master->i_title;
926 p_input->p->title = p_master->title;
927 p_input->p->i_title_offset = p_master->i_title_offset;
928 p_input->p->i_seekpoint_offset = p_master->i_seekpoint_offset;
929 if( p_input->p->i_title > 0 )
931 /* Setup variables */
932 input_ControlVarNavigation( p_input );
933 input_SendEventTitle( p_input, 0 );
937 p_input->p->b_can_pace_control = p_master->b_can_pace_control;
938 p_input->p->b_can_pause = p_master->b_can_pause;
939 p_input->p->b_can_rate_control = p_master->b_can_rate_control;
942 static void StartTitle( input_thread_t * p_input )
946 /* Start title/chapter */
947 val.i_int = p_input->p->input.i_title_start -
948 p_input->p->input.i_title_offset;
949 if( val.i_int > 0 && val.i_int < p_input->p->input.i_title )
950 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
952 val.i_int = p_input->p->input.i_seekpoint_start -
953 p_input->p->input.i_seekpoint_offset;
954 if( val.i_int > 0 /* TODO: check upper boundary */ )
955 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
957 /* Start/stop/run time */
958 p_input->p->i_start = (int64_t)(1000000.0
959 * var_GetFloat( p_input, "start-time" ));
960 p_input->p->i_stop = (int64_t)(1000000.0
961 * var_GetFloat( p_input, "stop-time" ));
962 p_input->p->i_run = (int64_t)(1000000.0
963 * var_GetFloat( p_input, "run-time" ));
964 if( p_input->p->i_run < 0 )
966 msg_Warn( p_input, "invalid run-time ignored" );
967 p_input->p->i_run = 0;
970 if( p_input->p->i_start > 0 )
974 msg_Dbg( p_input, "starting at time: %ds",
975 (int)( p_input->p->i_start / INT64_C(1000000) ) );
977 s.i_time = p_input->p->i_start;
978 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
980 if( p_input->p->i_stop > 0 && p_input->p->i_stop <= p_input->p->i_start )
982 msg_Warn( p_input, "invalid stop-time ignored" );
983 p_input->p->i_stop = 0;
985 p_input->p->b_fast_seek = var_GetBool( p_input, "input-fast-seek" );
988 static void LoadSubtitles( input_thread_t *p_input )
991 /* Get fps and set it if not already set */
992 const double f_fps = p_input->p->f_fps;
995 float f_requested_fps;
997 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
998 var_SetFloat( p_input, "sub-original-fps", f_fps );
1000 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
1001 if( f_requested_fps != f_fps )
1003 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
1004 VLC_VAR_DOINHERIT );
1005 var_SetFloat( p_input, "sub-fps", f_requested_fps );
1009 const int i_delay = var_CreateGetInteger( p_input, "sub-delay" );
1011 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
1013 /* Look for and add subtitle files */
1014 bool b_forced = true;
1016 char *psz_subtitle = var_GetNonEmptyString( p_input, "sub-file" );
1017 if( psz_subtitle != NULL )
1019 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
1020 SubtitleAdd( p_input, psz_subtitle, b_forced );
1024 if( var_GetBool( p_input, "sub-autodetect-file" ) )
1026 char *psz_autopath = var_GetNonEmptyString( p_input, "sub-autodetect-path" );
1027 char **ppsz_subs = subtitles_Detect( p_input, psz_autopath,
1028 p_input->p->p_item->psz_uri );
1029 free( psz_autopath );
1031 for( int i = 0; ppsz_subs && ppsz_subs[i]; i++ )
1033 if( !psz_subtitle || strcmp( psz_subtitle, ppsz_subs[i] ) )
1035 SubtitleAdd( p_input, ppsz_subs[i], b_forced );
1039 free( ppsz_subs[i] );
1043 free( psz_subtitle );
1045 /* Load subtitles from attachments */
1046 int i_attachment = 0;
1047 input_attachment_t **pp_attachment = NULL;
1049 vlc_mutex_lock( &p_input->p->p_item->lock );
1050 for( int i = 0; i < p_input->p->i_attachment; i++ )
1052 const input_attachment_t *a = p_input->p->attachment[i];
1053 if( !strcmp( a->psz_mime, "application/x-srt" ) )
1054 TAB_APPEND( i_attachment, pp_attachment,
1055 vlc_input_attachment_New( a->psz_name, NULL,
1056 a->psz_description, NULL, 0 ) );
1058 vlc_mutex_unlock( &p_input->p->p_item->lock );
1060 if( i_attachment > 0 )
1061 var_Create( p_input, "sub-description", VLC_VAR_STRING );
1062 for( int i = 0; i < i_attachment; i++ )
1064 input_attachment_t *a = pp_attachment[i];
1068 if( a->psz_name[i] &&
1069 asprintf( &psz_mrl, "attachment://%s", a->psz_name ) >= 0 )
1071 var_SetString( p_input, "sub-description", a->psz_description ? a->psz_description : "");
1073 SubtitleAdd( p_input, psz_mrl, b_forced );
1078 vlc_input_attachment_Delete( a );
1080 free( pp_attachment );
1081 if( i_attachment > 0 )
1082 var_Destroy( p_input, "sub-description" );
1085 static void LoadSlaves( input_thread_t *p_input )
1087 char *psz = var_GetNonEmptyString( p_input, "input-slave" );
1091 char *psz_org = psz;
1092 while( psz && *psz )
1094 while( *psz == ' ' || *psz == '#' )
1097 char *psz_delim = strchr( psz, '#' );
1099 *psz_delim++ = '\0';
1104 msg_Dbg( p_input, "adding slave input '%s'", psz );
1106 input_source_t *p_slave = InputSourceNew( p_input );
1107 if( p_slave && !InputSourceInit( p_input, p_slave, psz, NULL ) )
1108 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, p_slave );
1117 static void UpdatePtsDelay( input_thread_t *p_input )
1119 input_thread_private_t *p_sys = p_input->p;
1121 /* Get max pts delay from input source */
1122 mtime_t i_pts_delay = p_sys->input.i_pts_delay;
1123 for( int i = 0; i < p_sys->i_slave; i++ )
1124 i_pts_delay = __MAX( i_pts_delay, p_sys->slave[i]->i_pts_delay );
1126 if( i_pts_delay < 0 )
1129 /* Take care of audio/spu delay */
1130 const mtime_t i_audio_delay = var_GetTime( p_input, "audio-delay" );
1131 const mtime_t i_spu_delay = var_GetTime( p_input, "spu-delay" );
1132 const mtime_t i_extra_delay = __MIN( i_audio_delay, i_spu_delay );
1133 if( i_extra_delay < 0 )
1134 i_pts_delay -= i_extra_delay;
1136 /* Update cr_average depending on the caching */
1137 const int i_cr_average = var_GetInteger( p_input, "cr-average" ) * i_pts_delay / DEFAULT_PTS_DELAY;
1140 es_out_SetDelay( p_input->p->p_es_out_display, AUDIO_ES, i_audio_delay );
1141 es_out_SetDelay( p_input->p->p_es_out_display, SPU_ES, i_spu_delay );
1142 es_out_SetJitter( p_input->p->p_es_out, i_pts_delay, 0, i_cr_average );
1145 static void InitPrograms( input_thread_t * p_input )
1150 /* Compute correct pts_delay */
1151 UpdatePtsDelay( p_input );
1154 i_es_out_mode = ES_OUT_MODE_AUTO;
1155 if( p_input->p->p_sout )
1157 if( var_GetBool( p_input, "sout-all" ) )
1159 i_es_out_mode = ES_OUT_MODE_ALL;
1163 var_Get( p_input, "programs", &val );
1164 if( val.p_list && val.p_list->i_count )
1166 i_es_out_mode = ES_OUT_MODE_PARTIAL;
1167 /* Note : we should remove the "program" callback. */
1171 var_FreeList( &val, NULL );
1175 es_out_SetMode( p_input->p->p_es_out, i_es_out_mode );
1177 /* Inform the demuxer about waited group (needed only for DVB) */
1178 if( i_es_out_mode == ES_OUT_MODE_ALL )
1180 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
1182 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
1184 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1,
1189 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP,
1190 (int) var_GetInteger( p_input, "program" ), NULL );
1194 static int Init( input_thread_t * p_input )
1199 for( i = 0; i < p_input->p->p_item->i_options; i++ )
1201 if( !strncmp( p_input->p->p_item->ppsz_options[i], "meta-file", 9 ) )
1203 msg_Dbg( p_input, "Input is a meta file: disabling unneeded options" );
1204 var_SetString( p_input, "sout", "" );
1205 var_SetBool( p_input, "sout-all", false );
1206 var_SetString( p_input, "input-slave", "" );
1207 var_SetInteger( p_input, "input-repeat", 0 );
1208 var_SetString( p_input, "sub-file", "" );
1209 var_SetBool( p_input, "sub-autodetect-file", false );
1213 InitStatistics( p_input );
1215 if( InitSout( p_input ) )
1220 p_input->p->p_es_out = input_EsOutTimeshiftNew( p_input, p_input->p->p_es_out_display, p_input->p->i_rate );
1223 input_ChangeState( p_input, OPENING_S );
1224 input_SendEventCache( p_input, 0.0 );
1227 if( InputSourceInit( p_input, &p_input->p->input,
1228 p_input->p->p_item->psz_uri, NULL ) )
1233 InitTitle( p_input );
1235 /* Load master infos */
1238 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_LENGTH,
1242 i_length = input_item_GetDuration( p_input->p->p_item );
1243 input_SendEventLength( p_input, i_length );
1245 input_SendEventPosition( p_input, 0.0, 0 );
1247 if( !p_input->b_preparsing )
1249 StartTitle( p_input );
1250 LoadSubtitles( p_input );
1251 LoadSlaves( p_input );
1252 InitPrograms( p_input );
1255 if( !p_input->b_preparsing && p_input->p->p_sout )
1257 p_input->p->b_out_pace_control = (p_input->p->p_sout->i_out_pace_nocontrol > 0);
1259 if( p_input->p->b_can_pace_control && p_input->p->b_out_pace_control )
1261 /* We don't want a high input priority here or we'll
1262 * end-up sucking up all the CPU time */
1263 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
1266 msg_Dbg( p_input, "starting in %s mode",
1267 p_input->p->b_out_pace_control ? "async" : "sync" );
1270 p_meta = vlc_meta_New();
1273 /* Get meta data from users */
1274 InputMetaUser( p_input, p_meta );
1276 /* Get meta data from master input */
1277 InputSourceMeta( p_input, &p_input->p->input, p_meta );
1279 /* And from slave */
1280 for( int i = 0; i < p_input->p->i_slave; i++ )
1281 InputSourceMeta( p_input, p_input->p->slave[i], p_meta );
1284 InputUpdateMeta( p_input, p_meta );
1287 msg_Dbg( p_input, "`%s' successfully opened",
1288 p_input->p->p_item->psz_uri );
1290 /* initialization is complete */
1291 input_ChangeState( p_input, PLAYING_S );
1296 input_ChangeState( p_input, ERROR_S );
1298 if( p_input->p->p_es_out )
1299 es_out_Delete( p_input->p->p_es_out );
1300 es_out_SetMode( p_input->p->p_es_out_display, ES_OUT_MODE_END );
1301 if( p_input->p->p_resource )
1303 if( p_input->p->p_sout )
1304 input_resource_RequestSout( p_input->p->p_resource,
1305 p_input->p->p_sout, NULL );
1306 input_resource_SetInput( p_input->p->p_resource, NULL );
1309 if( !p_input->b_preparsing && libvlc_stats( p_input ) )
1311 #define EXIT_COUNTER( c ) do { if( p_input->p->counters.p_##c ) \
1312 stats_CounterClean( p_input->p->counters.p_##c );\
1313 p_input->p->counters.p_##c = NULL; } while(0)
1314 EXIT_COUNTER( read_bytes );
1315 EXIT_COUNTER( read_packets );
1316 EXIT_COUNTER( demux_read );
1317 EXIT_COUNTER( input_bitrate );
1318 EXIT_COUNTER( demux_bitrate );
1319 EXIT_COUNTER( demux_corrupted );
1320 EXIT_COUNTER( demux_discontinuity );
1321 EXIT_COUNTER( played_abuffers );
1322 EXIT_COUNTER( lost_abuffers );
1323 EXIT_COUNTER( displayed_pictures );
1324 EXIT_COUNTER( lost_pictures );
1325 EXIT_COUNTER( decoded_audio );
1326 EXIT_COUNTER( decoded_video );
1327 EXIT_COUNTER( decoded_sub );
1329 if( p_input->p->p_sout )
1331 EXIT_COUNTER( sout_sent_packets );
1332 EXIT_COUNTER( sout_sent_bytes );
1333 EXIT_COUNTER( sout_send_bitrate );
1338 /* Mark them deleted */
1339 p_input->p->input.p_demux = NULL;
1340 p_input->p->input.p_stream = NULL;
1341 p_input->p->input.p_access = NULL;
1342 p_input->p->p_es_out = NULL;
1343 p_input->p->p_sout = NULL;
1345 return VLC_EGENERIC;
1348 /*****************************************************************************
1349 * End: end the input thread
1350 *****************************************************************************/
1351 static void End( input_thread_t * p_input )
1355 /* We are at the end */
1356 input_ChangeState( p_input, END_S );
1358 /* Clean control variables */
1359 input_ControlVarStop( p_input );
1361 /* Stop es out activity */
1362 es_out_SetMode( p_input->p->p_es_out, ES_OUT_MODE_NONE );
1364 /* Clean up master */
1365 InputSourceClean( &p_input->p->input );
1368 for( i = 0; i < p_input->p->i_slave; i++ )
1370 InputSourceClean( p_input->p->slave[i] );
1371 free( p_input->p->slave[i] );
1373 free( p_input->p->slave );
1375 /* Unload all modules */
1376 if( p_input->p->p_es_out )
1377 es_out_Delete( p_input->p->p_es_out );
1378 es_out_SetMode( p_input->p->p_es_out_display, ES_OUT_MODE_END );
1380 if( !p_input->b_preparsing )
1382 #define CL_CO( c ) stats_CounterClean( p_input->p->counters.p_##c ); p_input->p->counters.p_##c = NULL;
1383 if( libvlc_stats( p_input ) )
1385 /* make sure we are up to date */
1386 stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
1387 CL_CO( read_bytes );
1388 CL_CO( read_packets );
1389 CL_CO( demux_read );
1390 CL_CO( input_bitrate );
1391 CL_CO( demux_bitrate );
1392 CL_CO( demux_corrupted );
1393 CL_CO( demux_discontinuity );
1394 CL_CO( played_abuffers );
1395 CL_CO( lost_abuffers );
1396 CL_CO( displayed_pictures );
1397 CL_CO( lost_pictures );
1398 CL_CO( decoded_audio) ;
1399 CL_CO( decoded_video );
1400 CL_CO( decoded_sub) ;
1403 /* Close optional stream output instance */
1404 if( p_input->p->p_sout )
1406 CL_CO( sout_sent_packets );
1407 CL_CO( sout_sent_bytes );
1408 CL_CO( sout_send_bitrate );
1413 vlc_mutex_lock( &p_input->p->p_item->lock );
1414 if( p_input->p->i_attachment > 0 )
1416 for( i = 0; i < p_input->p->i_attachment; i++ )
1417 vlc_input_attachment_Delete( p_input->p->attachment[i] );
1418 TAB_CLEAN( p_input->p->i_attachment, p_input->p->attachment );
1420 vlc_mutex_unlock( &p_input->p->p_item->lock );
1423 input_resource_RequestSout( p_input->p->p_resource,
1424 p_input->p->p_sout, NULL );
1425 input_resource_SetInput( p_input->p->p_resource, NULL );
1428 /*****************************************************************************
1430 *****************************************************************************/
1431 void input_ControlPush( input_thread_t *p_input,
1432 int i_type, vlc_value_t *p_val )
1434 vlc_mutex_lock( &p_input->p->lock_control );
1435 if( i_type == INPUT_CONTROL_SET_DIE )
1437 /* Special case, empty the control */
1438 for( int i = 0; i < p_input->p->i_control; i++ )
1440 input_control_t *p_ctrl = &p_input->p->control[i];
1441 ControlRelease( p_ctrl->i_type, p_ctrl->val );
1443 p_input->p->i_control = 0;
1446 if( p_input->p->i_control >= INPUT_CONTROL_FIFO_SIZE )
1448 msg_Err( p_input, "input control fifo overflow, trashing type=%d",
1451 ControlRelease( i_type, *p_val );
1460 memset( &c.val, 0, sizeof(c.val) );
1462 p_input->p->control[p_input->p->i_control++] = c;
1464 vlc_cond_signal( &p_input->p->wait_control );
1465 vlc_mutex_unlock( &p_input->p->lock_control );
1468 static int ControlGetReducedIndexLocked( input_thread_t *p_input )
1470 const int i_lt = p_input->p->control[0].i_type;
1472 for( i = 1; i < p_input->p->i_control; i++ )
1474 const int i_ct = p_input->p->control[i].i_type;
1477 ( i_ct == INPUT_CONTROL_SET_STATE ||
1478 i_ct == INPUT_CONTROL_SET_RATE ||
1479 i_ct == INPUT_CONTROL_SET_POSITION ||
1480 i_ct == INPUT_CONTROL_SET_TIME ||
1481 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1482 i_ct == INPUT_CONTROL_SET_TITLE ||
1483 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1484 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1490 /* TODO but that's not that important
1491 - merge SET_X with SET_X_CMD
1492 - ignore SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1493 - ignore SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1503 static inline int ControlPop( input_thread_t *p_input,
1504 int *pi_type, vlc_value_t *p_val,
1505 mtime_t i_deadline, bool b_postpone_seek )
1507 input_thread_private_t *p_sys = p_input->p;
1509 vlc_mutex_lock( &p_sys->lock_control );
1510 while( p_sys->i_control <= 0 ||
1511 ( b_postpone_seek && ControlIsSeekRequest( p_sys->control[0].i_type ) ) )
1513 if( !vlc_object_alive( p_input ) || i_deadline < 0 )
1515 vlc_mutex_unlock( &p_sys->lock_control );
1516 return VLC_EGENERIC;
1519 if( vlc_cond_timedwait( &p_sys->wait_control, &p_sys->lock_control,
1522 vlc_mutex_unlock( &p_sys->lock_control );
1523 return VLC_EGENERIC;
1528 const int i_index = ControlGetReducedIndexLocked( p_input );
1531 *pi_type = p_sys->control[i_index].i_type;
1532 *p_val = p_sys->control[i_index].val;
1534 p_sys->i_control -= i_index + 1;
1535 if( p_sys->i_control > 0 )
1536 memmove( &p_sys->control[0], &p_sys->control[i_index+1],
1537 sizeof(*p_sys->control) * p_sys->i_control );
1538 vlc_mutex_unlock( &p_sys->lock_control );
1542 static bool ControlIsSeekRequest( int i_type )
1546 case INPUT_CONTROL_SET_POSITION:
1547 case INPUT_CONTROL_SET_TIME:
1548 case INPUT_CONTROL_SET_TITLE:
1549 case INPUT_CONTROL_SET_TITLE_NEXT:
1550 case INPUT_CONTROL_SET_TITLE_PREV:
1551 case INPUT_CONTROL_SET_SEEKPOINT:
1552 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1553 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1554 case INPUT_CONTROL_SET_BOOKMARK:
1561 static void ControlRelease( int i_type, vlc_value_t val )
1565 case INPUT_CONTROL_ADD_SUBTITLE:
1566 case INPUT_CONTROL_ADD_SLAVE:
1567 free( val.psz_string );
1576 static void ControlPause( input_thread_t *p_input, mtime_t i_control_date )
1578 int i_ret = VLC_SUCCESS;
1579 int i_state = PAUSE_S;
1581 if( p_input->p->b_can_pause )
1583 if( p_input->p->input.p_access )
1584 i_ret = access_Control( p_input->p->input.p_access,
1585 ACCESS_SET_PAUSE_STATE, true );
1587 i_ret = demux_Control( p_input->p->input.p_demux,
1588 DEMUX_SET_PAUSE_STATE, true );
1592 msg_Warn( p_input, "cannot set pause state" );
1598 i_ret = es_out_SetPauseState( p_input->p->p_es_out,
1599 p_input->p->b_can_pause, true,
1603 msg_Warn( p_input, "cannot set pause state at es_out level" );
1607 /* Switch to new state */
1608 input_ChangeState( p_input, i_state );
1611 static void ControlUnpause( input_thread_t *p_input, mtime_t i_control_date )
1613 int i_ret = VLC_SUCCESS;
1615 if( p_input->p->b_can_pause )
1617 if( p_input->p->input.p_access )
1618 i_ret = access_Control( p_input->p->input.p_access,
1619 ACCESS_SET_PAUSE_STATE, false );
1621 i_ret = demux_Control( p_input->p->input.p_demux,
1622 DEMUX_SET_PAUSE_STATE, false );
1625 /* FIXME What to do ? */
1626 msg_Warn( p_input, "cannot unset pause -> EOF" );
1627 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1631 /* Switch to play */
1632 input_ChangeState( p_input, PLAYING_S );
1636 es_out_SetPauseState( p_input->p->p_es_out, false, false, i_control_date );
1639 static bool Control( input_thread_t *p_input,
1640 int i_type, vlc_value_t val )
1642 const mtime_t i_control_date = mdate();
1643 /* FIXME b_force_update is abused, it should be carefully checked */
1644 bool b_force_update = false;
1647 return b_force_update;
1651 case INPUT_CONTROL_SET_DIE:
1652 msg_Dbg( p_input, "control: stopping input" );
1654 /* Mark all submodules to die */
1655 ObjectKillChildrens( p_input, VLC_OBJECT(p_input) );
1658 case INPUT_CONTROL_SET_POSITION:
1662 if( p_input->p->b_recording )
1664 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) ignored while recording" );
1667 f_pos = val.f_float;
1668 if( i_type != INPUT_CONTROL_SET_POSITION )
1669 f_pos += var_GetFloat( p_input, "position" );
1672 else if( f_pos > 1.0 )
1674 /* Reset the decoders states and clock sync (before calling the demuxer */
1675 es_out_SetTime( p_input->p->p_es_out, -1 );
1676 if( demux_Control( p_input->p->input.p_demux, DEMUX_SET_POSITION,
1677 f_pos, !p_input->p->b_fast_seek ) )
1679 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1680 "%2.1f%% failed", f_pos * 100 );
1684 if( p_input->p->i_slave > 0 )
1685 SlaveSeek( p_input );
1686 p_input->p->input.b_eof = false;
1688 b_force_update = true;
1693 case INPUT_CONTROL_SET_TIME:
1698 if( p_input->p->b_recording )
1700 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) ignored while recording" );
1704 i_time = val.i_time;
1705 if( i_type != INPUT_CONTROL_SET_TIME )
1706 i_time += var_GetTime( p_input, "time" );
1711 /* Reset the decoders states and clock sync (before calling the demuxer */
1712 es_out_SetTime( p_input->p->p_es_out, -1 );
1714 i_ret = demux_Control( p_input->p->input.p_demux,
1715 DEMUX_SET_TIME, i_time,
1716 !p_input->p->b_fast_seek );
1721 /* Emulate it with a SET_POS */
1722 if( !demux_Control( p_input->p->input.p_demux,
1723 DEMUX_GET_LENGTH, &i_length ) && i_length > 0 )
1725 double f_pos = (double)i_time / (double)i_length;
1726 i_ret = demux_Control( p_input->p->input.p_demux,
1727 DEMUX_SET_POSITION, f_pos,
1728 !p_input->p->b_fast_seek );
1733 msg_Warn( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) %"PRId64
1734 " failed or not possible", i_time );
1738 if( p_input->p->i_slave > 0 )
1739 SlaveSeek( p_input );
1740 p_input->p->input.b_eof = false;
1742 b_force_update = true;
1747 case INPUT_CONTROL_SET_STATE:
1748 if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1749 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1750 else if( p_input->p->i_state == PAUSE_S )
1752 ControlUnpause( p_input, i_control_date );
1754 b_force_update = true;
1756 else if( val.i_int == PAUSE_S && p_input->p->i_state == PLAYING_S /* &&
1757 p_input->p->b_can_pause */ )
1759 ControlPause( p_input, i_control_date );
1761 b_force_update = true;
1763 else if( val.i_int == PAUSE_S && !p_input->p->b_can_pause && 0 )
1765 b_force_update = true;
1767 /* Correct "state" value */
1768 input_ChangeState( p_input, p_input->p->i_state );
1772 case INPUT_CONTROL_SET_RATE:
1774 /* Get rate and direction */
1775 int i_rate = abs( val.i_int );
1776 int i_rate_sign = val.i_int < 0 ? -1 : 1;
1778 /* Check rate bound */
1779 if( i_rate < INPUT_RATE_MIN )
1781 msg_Dbg( p_input, "cannot set rate faster" );
1782 i_rate = INPUT_RATE_MIN;
1784 else if( i_rate > INPUT_RATE_MAX )
1786 msg_Dbg( p_input, "cannot set rate slower" );
1787 i_rate = INPUT_RATE_MAX;
1790 /* Apply direction */
1791 if( i_rate_sign < 0 )
1793 if( p_input->p->input.b_rescale_ts )
1795 msg_Dbg( p_input, "cannot set negative rate" );
1796 i_rate = p_input->p->i_rate;
1797 assert( i_rate > 0 );
1801 i_rate *= i_rate_sign;
1805 if( i_rate != INPUT_RATE_DEFAULT &&
1806 ( ( !p_input->p->b_can_rate_control && !p_input->p->input.b_rescale_ts ) ||
1807 ( p_input->p->p_sout && !p_input->p->b_out_pace_control ) ) )
1809 msg_Dbg( p_input, "cannot change rate" );
1810 i_rate = INPUT_RATE_DEFAULT;
1812 if( i_rate != p_input->p->i_rate &&
1813 !p_input->p->b_can_pace_control && p_input->p->b_can_rate_control )
1816 if( p_input->p->input.p_access )
1818 i_ret = VLC_EGENERIC;
1822 if( !p_input->p->input.b_rescale_ts )
1823 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1825 i_ret = demux_Control( p_input->p->input.p_demux,
1826 DEMUX_SET_RATE, &i_rate );
1830 msg_Warn( p_input, "ACCESS/DEMUX_SET_RATE failed" );
1831 i_rate = p_input->p->i_rate;
1836 if( i_rate != p_input->p->i_rate )
1838 p_input->p->i_rate = i_rate;
1839 input_SendEventRate( p_input, i_rate );
1841 if( p_input->p->input.b_rescale_ts )
1843 const int i_rate_source = (p_input->p->b_can_pace_control || p_input->p->b_can_rate_control ) ? i_rate : INPUT_RATE_DEFAULT;
1844 es_out_SetRate( p_input->p->p_es_out, i_rate_source, i_rate );
1847 b_force_update = true;
1852 case INPUT_CONTROL_SET_PROGRAM:
1853 /* No need to force update, es_out does it if needed */
1854 es_out_Control( p_input->p->p_es_out,
1855 ES_OUT_SET_GROUP, val.i_int );
1857 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1861 case INPUT_CONTROL_SET_ES:
1862 /* No need to force update, es_out does it if needed */
1863 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, val.i_int );
1866 case INPUT_CONTROL_RESTART_ES:
1867 es_out_Control( p_input->p->p_es_out_display, ES_OUT_RESTART_ES_BY_ID, val.i_int );
1870 case INPUT_CONTROL_SET_AUDIO_DELAY:
1871 input_SendEventAudioDelay( p_input, val.i_time );
1872 UpdatePtsDelay( p_input );
1875 case INPUT_CONTROL_SET_SPU_DELAY:
1876 input_SendEventSubtitleDelay( p_input, val.i_time );
1877 UpdatePtsDelay( p_input );
1880 case INPUT_CONTROL_SET_TITLE:
1881 case INPUT_CONTROL_SET_TITLE_NEXT:
1882 case INPUT_CONTROL_SET_TITLE_PREV:
1883 if( p_input->p->b_recording )
1885 msg_Err( p_input, "INPUT_CONTROL_SET_TITLE(*) ignored while recording" );
1888 if( p_input->p->input.b_title_demux &&
1889 p_input->p->input.i_title > 0 )
1892 /* FIXME handle demux title */
1893 demux_t *p_demux = p_input->p->input.p_demux;
1896 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1897 i_title = p_demux->info.i_title - 1;
1898 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1899 i_title = p_demux->info.i_title + 1;
1901 i_title = val.i_int;
1903 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1905 es_out_SetTime( p_input->p->p_es_out, -1 );
1907 demux_Control( p_demux, DEMUX_SET_TITLE, i_title );
1908 input_SendEventTitle( p_input, i_title );
1911 else if( p_input->p->input.i_title > 0 )
1913 access_t *p_access = p_input->p->input.p_access;
1916 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1917 i_title = p_access->info.i_title - 1;
1918 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1919 i_title = p_access->info.i_title + 1;
1921 i_title = val.i_int;
1923 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1925 es_out_SetTime( p_input->p->p_es_out, -1 );
1927 stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
1928 ACCESS_SET_TITLE, i_title );
1929 input_SendEventTitle( p_input, i_title );
1933 case INPUT_CONTROL_SET_SEEKPOINT:
1934 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1935 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1936 if( p_input->p->b_recording )
1938 msg_Err( p_input, "INPUT_CONTROL_SET_SEEKPOINT(*) ignored while recording" );
1942 if( p_input->p->input.b_title_demux &&
1943 p_input->p->input.i_title > 0 )
1945 demux_t *p_demux = p_input->p->input.p_demux;
1947 int64_t i_input_time;
1948 int64_t i_seekpoint_time;
1950 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1952 i_seekpoint = p_demux->info.i_seekpoint;
1953 i_seekpoint_time = p_input->p->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1954 i_input_time = var_GetTime( p_input, "time" );
1955 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
1957 if( i_input_time < i_seekpoint_time + 3000000 )
1963 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1964 i_seekpoint = p_demux->info.i_seekpoint + 1;
1966 i_seekpoint = val.i_int;
1968 if( i_seekpoint >= 0 && i_seekpoint <
1969 p_input->p->input.title[p_demux->info.i_title]->i_seekpoint )
1972 es_out_SetTime( p_input->p->p_es_out, -1 );
1974 demux_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1975 input_SendEventSeekpoint( p_input, p_demux->info.i_title, i_seekpoint );
1978 else if( p_input->p->input.i_title > 0 )
1980 access_t *p_access = p_input->p->input.p_access;
1982 int64_t i_input_time;
1983 int64_t i_seekpoint_time;
1985 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1987 i_seekpoint = p_access->info.i_seekpoint;
1988 i_seekpoint_time = p_input->p->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1989 i_input_time = var_GetTime( p_input, "time" );
1990 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
1992 if( i_input_time < i_seekpoint_time + 3000000 )
1998 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1999 i_seekpoint = p_access->info.i_seekpoint + 1;
2001 i_seekpoint = val.i_int;
2003 if( i_seekpoint >= 0 && i_seekpoint <
2004 p_input->p->input.title[p_access->info.i_title]->i_seekpoint )
2006 es_out_SetTime( p_input->p->p_es_out, -1 );
2008 stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
2009 ACCESS_SET_SEEKPOINT, i_seekpoint );
2010 input_SendEventSeekpoint( p_input, p_access->info.i_title, i_seekpoint );
2015 case INPUT_CONTROL_ADD_SUBTITLE:
2016 if( val.psz_string )
2017 SubtitleAdd( p_input, val.psz_string, true );
2020 case INPUT_CONTROL_ADD_SLAVE:
2021 if( val.psz_string )
2023 input_source_t *slave = InputSourceNew( p_input );
2025 if( slave && !InputSourceInit( p_input, slave, val.psz_string, NULL ) )
2031 msg_Dbg( p_input, "adding %s as slave on the fly",
2035 if( demux_Control( p_input->p->input.p_demux,
2036 DEMUX_GET_TIME, &i_time ) )
2038 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2039 InputSourceClean( slave );
2043 if( demux_Control( slave->p_demux,
2044 DEMUX_SET_TIME, i_time, true ) )
2046 msg_Err( p_input, "seek failed for new slave" );
2047 InputSourceClean( slave );
2052 /* Get meta (access and demux) */
2053 p_meta = vlc_meta_New();
2056 access_Control( slave->p_access, ACCESS_GET_META, p_meta );
2057 demux_Control( slave->p_demux, DEMUX_GET_META, p_meta );
2058 InputUpdateMeta( p_input, p_meta );
2061 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, slave );
2066 msg_Warn( p_input, "failed to add %s as slave",
2072 case INPUT_CONTROL_SET_RECORD_STATE:
2073 if( !!p_input->p->b_recording != !!val.b_bool )
2075 if( p_input->p->input.b_can_stream_record )
2077 if( demux_Control( p_input->p->input.p_demux,
2078 DEMUX_SET_RECORD_STATE, val.b_bool ) )
2083 if( es_out_SetRecordState( p_input->p->p_es_out_display, val.b_bool ) )
2086 p_input->p->b_recording = val.b_bool;
2088 input_SendEventRecord( p_input, val.b_bool );
2090 b_force_update = true;
2094 case INPUT_CONTROL_SET_FRAME_NEXT:
2095 if( p_input->p->i_state == PAUSE_S )
2097 es_out_SetFrameNext( p_input->p->p_es_out );
2099 else if( p_input->p->i_state == PLAYING_S )
2101 ControlPause( p_input, i_control_date );
2105 msg_Err( p_input, "invalid state for frame next" );
2107 b_force_update = true;
2110 case INPUT_CONTROL_SET_BOOKMARK:
2112 seekpoint_t bookmark;
2114 bookmark.i_time_offset = -1;
2115 bookmark.i_byte_offset = -1;
2117 vlc_mutex_lock( &p_input->p->p_item->lock );
2118 if( val.i_int >= 0 && val.i_int < p_input->p->i_bookmark )
2120 const seekpoint_t *p_bookmark = p_input->p->pp_bookmark[val.i_int];
2121 bookmark.i_time_offset = p_bookmark->i_time_offset;
2122 bookmark.i_byte_offset = p_bookmark->i_byte_offset;
2124 vlc_mutex_unlock( &p_input->p->p_item->lock );
2126 if( bookmark.i_time_offset < 0 && bookmark.i_byte_offset < 0 )
2128 msg_Err( p_input, "invalid bookmark %d", val.i_int );
2132 if( bookmark.i_time_offset >= 0 )
2134 val.i_time = bookmark.i_time_offset;
2135 b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME, val );
2137 else if( bookmark.i_byte_offset >= 0 &&
2138 p_input->p->input.p_stream )
2140 const uint64_t i_size = stream_Size( p_input->p->input.p_stream );
2141 if( i_size > 0 && bookmark.i_byte_offset <= i_size )
2143 val.f_float = (double)bookmark.i_byte_offset / i_size;
2144 b_force_update = Control( p_input, INPUT_CONTROL_SET_POSITION, val );
2151 msg_Err( p_input, "not yet implemented" );
2155 ControlRelease( i_type, val );
2156 return b_force_update;
2159 /*****************************************************************************
2160 * UpdateTitleSeekpoint
2161 *****************************************************************************/
2162 static int UpdateTitleSeekpoint( input_thread_t *p_input,
2163 int i_title, int i_seekpoint )
2165 int i_title_end = p_input->p->input.i_title_end -
2166 p_input->p->input.i_title_offset;
2167 int i_seekpoint_end = p_input->p->input.i_seekpoint_end -
2168 p_input->p->input.i_seekpoint_offset;
2170 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
2172 if( i_title > i_title_end ||
2173 ( i_title == i_title_end && i_seekpoint > i_seekpoint_end ) )
2176 else if( i_seekpoint_end >= 0 )
2178 if( i_seekpoint > i_seekpoint_end )
2181 else if( i_title_end >= 0 )
2183 if( i_title > i_title_end )
2188 /*****************************************************************************
2190 *****************************************************************************/
2191 static int UpdateTitleSeekpointFromDemux( input_thread_t *p_input )
2193 demux_t *p_demux = p_input->p->input.p_demux;
2195 /* TODO event-like */
2196 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
2198 input_SendEventTitle( p_input, p_demux->info.i_title );
2200 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
2202 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
2204 input_SendEventSeekpoint( p_input,
2205 p_demux->info.i_title, p_demux->info.i_seekpoint );
2207 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2210 /* Hmmm only works with master input */
2211 if( p_input->p->input.p_demux == p_demux )
2212 return UpdateTitleSeekpoint( p_input,
2213 p_demux->info.i_title,
2214 p_demux->info.i_seekpoint );
2218 static void UpdateGenericFromDemux( input_thread_t *p_input )
2220 demux_t *p_demux = p_input->p->input.p_demux;
2222 if( p_demux->info.i_update & INPUT_UPDATE_META )
2224 vlc_meta_t *p_meta = vlc_meta_New();
2227 demux_Control( p_input->p->input.p_demux, DEMUX_GET_META, p_meta );
2228 InputUpdateMeta( p_input, p_meta );
2230 p_demux->info.i_update &= ~INPUT_UPDATE_META;
2233 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
2237 /*****************************************************************************
2238 * Update*FromAccess:
2239 *****************************************************************************/
2240 static int UpdateTitleSeekpointFromAccess( input_thread_t *p_input )
2242 access_t *p_access = p_input->p->input.p_access;
2244 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
2246 input_SendEventTitle( p_input, p_access->info.i_title );
2248 stream_Control( p_input->p->input.p_stream, STREAM_UPDATE_SIZE );
2250 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
2252 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
2254 input_SendEventSeekpoint( p_input,
2255 p_access->info.i_title, p_access->info.i_seekpoint );
2257 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2259 /* Hmmm only works with master input */
2260 if( p_input->p->input.p_access == p_access )
2261 return UpdateTitleSeekpoint( p_input,
2262 p_access->info.i_title,
2263 p_access->info.i_seekpoint );
2266 static void UpdateGenericFromAccess( input_thread_t *p_input )
2268 access_t *p_access = p_input->p->input.p_access;
2270 if( p_access->info.i_update & INPUT_UPDATE_META )
2272 /* TODO maybe multi - access ? */
2273 vlc_meta_t *p_meta = vlc_meta_New();
2276 access_Control( p_input->p->input.p_access, ACCESS_GET_META, p_meta );
2277 InputUpdateMeta( p_input, p_meta );
2279 p_access->info.i_update &= ~INPUT_UPDATE_META;
2281 if( p_access->info.i_update & INPUT_UPDATE_SIGNAL )
2286 if( access_Control( p_access, ACCESS_GET_SIGNAL, &f_quality, &f_strength ) )
2287 f_quality = f_strength = -1;
2289 input_SendEventSignal( p_input, f_quality, f_strength );
2291 p_access->info.i_update &= ~INPUT_UPDATE_SIGNAL;
2294 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
2297 /*****************************************************************************
2299 *****************************************************************************/
2300 static input_source_t *InputSourceNew( input_thread_t *p_input )
2302 VLC_UNUSED(p_input);
2304 return calloc( 1, sizeof( input_source_t ) );
2307 /*****************************************************************************
2309 *****************************************************************************/
2310 static int InputSourceInit( input_thread_t *p_input,
2311 input_source_t *in, const char *psz_mrl,
2312 const char *psz_forced_demux )
2314 const char *psz_access;
2315 const char *psz_demux;
2317 char *psz_var_demux = NULL;
2321 char *psz_dup = strdup( psz_mrl );
2323 if( psz_dup == NULL )
2327 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_dup );
2329 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
2330 psz_mrl, psz_access, psz_demux, psz_path );
2331 if( !p_input->b_preparsing )
2333 /* Hack to allow udp://@:port syntax */
2335 (strncmp( psz_access, "udp", 3 ) &&
2336 strncmp( psz_access, "rtp", 3 )) )
2338 /* Find optional titles and seekpoints */
2339 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
2340 &in->i_seekpoint_start, &in->i_seekpoint_end );
2343 if( psz_forced_demux && *psz_forced_demux )
2345 psz_demux = psz_forced_demux;
2347 else if( *psz_demux == '\0' )
2349 /* special hack for forcing a demuxer with --demux=module
2350 * (and do nothing with a list) */
2351 psz_var_demux = var_GetNonEmptyString( p_input, "demux" );
2353 if( psz_var_demux != NULL &&
2354 !strchr(psz_var_demux, ',' ) &&
2355 !strchr(psz_var_demux, ':' ) )
2357 psz_demux = psz_var_demux;
2359 msg_Dbg( p_input, "enforced demux ` %s'", psz_demux );
2363 /* Try access_demux first */
2364 in->p_demux = demux_New( p_input, p_input, psz_access, psz_demux, psz_path,
2365 NULL, p_input->p->p_es_out, false );
2369 /* Preparsing is only for file:// */
2372 if( !*psz_access ) /* path without scheme:// */
2373 psz_access = "file";
2374 if( strcmp( psz_access, "file" ) )
2376 msg_Dbg( p_input, "trying to pre-parse %s", psz_path );
2381 /* Get infos from access_demux */
2382 int i_ret = demux_Control( in->p_demux,
2383 DEMUX_GET_PTS_DELAY, &in->i_pts_delay );
2385 in->i_pts_delay = __MAX( 0, __MIN( in->i_pts_delay, INPUT_PTS_DELAY_MAX ) );
2388 in->b_title_demux = true;
2389 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2390 &in->title, &in->i_title,
2391 &in->i_title_offset, &in->i_seekpoint_offset ) )
2393 TAB_INIT( in->i_title, in->title );
2395 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
2396 &in->b_can_pace_control ) )
2397 in->b_can_pace_control = false;
2399 assert( in->p_demux->pf_demux != NULL || !in->b_can_pace_control );
2401 if( !in->b_can_pace_control )
2403 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_RATE,
2404 &in->b_can_rate_control, &in->b_rescale_ts ) )
2406 in->b_can_rate_control = false;
2407 in->b_rescale_ts = true; /* not used */
2412 in->b_can_rate_control = true;
2413 in->b_rescale_ts = true;
2415 if( demux_Control( in->p_demux, DEMUX_CAN_PAUSE,
2416 &in->b_can_pause ) )
2417 in->b_can_pause = false;
2418 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2419 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2420 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control && in->b_can_rate_control );
2423 if( demux_Control( in->p_demux, DEMUX_CAN_SEEK, &b_can_seek ) )
2425 var_SetBool( p_input, "can-seek", b_can_seek );
2429 /* Now try a real access */
2430 in->p_access = access_New( p_input, p_input, psz_access, psz_demux, psz_path );
2431 if( in->p_access == NULL )
2433 if( vlc_object_alive( p_input ) )
2435 msg_Err( p_input, "open of `%s' failed: %s", psz_mrl,
2437 dialog_Fatal( p_input, _("Your input can't be opened"),
2438 _("VLC is unable to open the MRL '%s'."
2439 " Check the log for details."), psz_mrl );
2444 /* Get infos from access */
2445 if( !p_input->b_preparsing )
2448 access_Control( in->p_access,
2449 ACCESS_GET_PTS_DELAY, &in->i_pts_delay );
2450 in->i_pts_delay = __MAX( 0, __MIN( in->i_pts_delay, INPUT_PTS_DELAY_MAX ) );
2452 in->b_title_demux = false;
2453 if( access_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2454 &in->title, &in->i_title,
2455 &in->i_title_offset, &in->i_seekpoint_offset ) )
2458 TAB_INIT( in->i_title, in->title );
2460 access_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2461 &in->b_can_pace_control );
2462 in->b_can_rate_control = in->b_can_pace_control;
2463 in->b_rescale_ts = true;
2465 access_Control( in->p_access, ACCESS_CAN_PAUSE, &in->b_can_pause );
2466 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2467 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2468 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control );
2470 access_Control( in->p_access, ACCESS_CAN_SEEK, &b_can_seek );
2471 var_SetBool( p_input, "can-seek", b_can_seek );
2476 char **ppsz_input_list;
2478 TAB_INIT( i_input_list, ppsz_input_list );
2480 /* On master stream only, use input-list */
2481 if( &p_input->p->input == in )
2487 psz_parser = var_CreateGetNonEmptyString( p_input, "input-list" );
2489 while( psz_parser && *psz_parser )
2491 char *p = strchr( psz_parser, ',' );
2497 char *psz_name = strdup( psz_parser );
2499 TAB_APPEND( i_input_list, ppsz_input_list, psz_name );
2506 /* Autodetect extra files if none specified */
2507 if( i_input_list <= 0 )
2509 InputGetExtraFiles( p_input, &i_input_list, &ppsz_input_list,
2510 psz_access, psz_path );
2512 if( i_input_list > 0 )
2513 TAB_APPEND( i_input_list, ppsz_input_list, NULL );
2515 /* Create the stream_t */
2516 in->p_stream = stream_AccessNew( in->p_access, ppsz_input_list );
2517 if( ppsz_input_list )
2519 for( int i = 0; ppsz_input_list[i] != NULL; i++ )
2520 free( ppsz_input_list[i] );
2521 TAB_CLEAN( i_input_list, ppsz_input_list );
2524 if( in->p_stream == NULL )
2526 msg_Warn( p_input, "cannot create a stream_t from access" );
2530 /* Add stream filters */
2531 char *psz_stream_filter = var_GetNonEmptyString( p_input,
2533 in->p_stream = stream_FilterChainNew( in->p_stream,
2535 var_GetBool( p_input, "input-record-native" ) );
2536 free( psz_stream_filter );
2538 /* Open a demuxer */
2539 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2541 psz_demux = in->p_access->psz_demux;
2544 in->p_demux = demux_New( p_input, p_input, psz_access, psz_demux,
2545 /* Take access/stream redirections into account: */
2546 in->p_stream->psz_path ? in->p_stream->psz_path : psz_path,
2547 in->p_stream, p_input->p->p_es_out,
2548 p_input->b_preparsing );
2550 if( in->p_demux == NULL )
2552 if( vlc_object_alive( p_input ) )
2554 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2555 psz_access, psz_demux, psz_path );
2556 dialog_Fatal( VLC_OBJECT( p_input ),
2557 _("VLC can't recognize the input's format"),
2558 _("The format of '%s' cannot be detected. "
2559 "Have a look at the log for details."), psz_mrl );
2563 assert( in->p_demux->pf_demux != NULL );
2565 /* Get title from demux */
2566 if( !p_input->b_preparsing && in->i_title <= 0 )
2568 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2569 &in->title, &in->i_title,
2570 &in->i_title_offset, &in->i_seekpoint_offset ))
2572 TAB_INIT( in->i_title, in->title );
2576 in->b_title_demux = true;
2581 free( psz_var_demux );
2584 /* Set record capabilities */
2585 if( demux_Control( in->p_demux, DEMUX_CAN_RECORD, &in->b_can_stream_record ) )
2586 in->b_can_stream_record = false;
2588 if( !var_GetBool( p_input, "input-record-native" ) )
2589 in->b_can_stream_record = false;
2590 var_SetBool( p_input, "can-record", true );
2592 var_SetBool( p_input, "can-record", in->b_can_stream_record );
2596 * FIXME improve for b_preparsing: move it after GET_META and check psz_arturl */
2597 if( 1 || !p_input->b_preparsing )
2600 input_attachment_t **attachment;
2601 if( !demux_Control( in->p_demux, DEMUX_GET_ATTACHMENTS,
2602 &attachment, &i_attachment ) )
2604 vlc_mutex_lock( &p_input->p->p_item->lock );
2605 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2606 i_attachment, attachment );
2607 vlc_mutex_unlock( &p_input->p->p_item->lock );
2610 if( !demux_Control( in->p_demux, DEMUX_GET_FPS, &f_fps ) && f_fps > 0.0 )
2612 vlc_mutex_lock( &p_input->p->p_item->lock );
2613 p_input->p->f_fps = f_fps;
2614 vlc_mutex_unlock( &p_input->p->p_item->lock );
2617 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2618 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2624 demux_Delete( in->p_demux );
2627 stream_Delete( in->p_stream );
2630 access_Delete( in->p_access );
2632 free( psz_var_demux );
2635 return VLC_EGENERIC;
2638 /*****************************************************************************
2640 *****************************************************************************/
2641 static void InputSourceClean( input_source_t *in )
2646 demux_Delete( in->p_demux );
2649 stream_Delete( in->p_stream );
2652 access_Delete( in->p_access );
2654 if( in->i_title > 0 )
2656 for( i = 0; i < in->i_title; i++ )
2657 vlc_input_title_Delete( in->title[i] );
2658 TAB_CLEAN( in->i_title, in->title );
2662 /*****************************************************************************
2664 *****************************************************************************/
2665 static void InputSourceMeta( input_thread_t *p_input,
2666 input_source_t *p_source, vlc_meta_t *p_meta )
2668 access_t *p_access = p_source->p_access;
2669 demux_t *p_demux = p_source->p_demux;
2671 /* XXX Remember that checking against p_item->p_meta->i_status & ITEM_PREPARSED
2676 /* Read access meta */
2677 has_meta = p_access && !access_Control( p_access, ACCESS_GET_META, p_meta );
2679 /* Read demux meta */
2680 has_meta |= !demux_Control( p_demux, DEMUX_GET_META, p_meta );
2682 bool has_unsupported;
2683 if( demux_Control( p_demux, DEMUX_HAS_UNSUPPORTED_META, &has_unsupported ) )
2684 has_unsupported = true;
2686 /* If the demux report unsupported meta data, or if we don't have meta data
2687 * try an external "meta reader" */
2688 if( has_meta && !has_unsupported )
2691 demux_meta_t *p_demux_meta =
2692 vlc_custom_create( p_demux, sizeof( *p_demux_meta ),
2693 VLC_OBJECT_GENERIC, "demux meta" );
2696 vlc_object_attach( p_demux_meta, p_demux );
2697 p_demux_meta->p_demux = p_demux;
2698 p_demux_meta->p_item = p_input->p->p_item;
2700 module_t *p_id3 = module_need( p_demux_meta, "meta reader", NULL, false );
2703 if( p_demux_meta->p_meta )
2705 vlc_meta_Merge( p_meta, p_demux_meta->p_meta );
2706 vlc_meta_Delete( p_demux_meta->p_meta );
2709 if( p_demux_meta->i_attachments > 0 )
2711 vlc_mutex_lock( &p_input->p->p_item->lock );
2712 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2713 p_demux_meta->i_attachments, p_demux_meta->attachments );
2714 vlc_mutex_unlock( &p_input->p->p_item->lock );
2716 module_unneed( p_demux, p_id3 );
2718 vlc_object_release( p_demux_meta );
2722 static void SlaveDemux( input_thread_t *p_input, bool *pb_demux_polled )
2727 *pb_demux_polled = false;
2728 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2730 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2734 for( i = 0; i < p_input->p->i_slave; i++ )
2736 input_source_t *in = p_input->p->slave[i];
2742 const bool b_demux_polled = in->p_demux->pf_demux != NULL;
2743 if( !b_demux_polled )
2746 *pb_demux_polled = true;
2748 /* Call demux_Demux until we have read enough data */
2749 if( demux_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2754 if( demux_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2756 msg_Err( p_input, "slave[%d] doesn't like "
2757 "DEMUX_GET_TIME -> EOF", i );
2762 if( i_stime >= i_time )
2768 if( ( i_ret = demux_Demux( in->p_demux ) ) <= 0 )
2774 i_ret = demux_Demux( in->p_demux );
2779 msg_Dbg( p_input, "slave %d EOF", i );
2785 static void SlaveSeek( input_thread_t *p_input )
2790 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2792 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2796 for( i = 0; i < p_input->p->i_slave; i++ )
2798 input_source_t *in = p_input->p->slave[i];
2800 if( demux_Control( in->p_demux, DEMUX_SET_TIME, i_time, true ) )
2803 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2813 /*****************************************************************************
2815 *****************************************************************************/
2816 static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta )
2818 static const struct { int i_meta; const char *psz_name; } p_list[] = {
2819 { vlc_meta_Title, "meta-title" },
2820 { vlc_meta_Artist, "meta-artist" },
2821 { vlc_meta_Genre, "meta-genre" },
2822 { vlc_meta_Copyright, "meta-copyright" },
2823 { vlc_meta_Description, "meta-description" },
2824 { vlc_meta_Date, "meta-date" },
2825 { vlc_meta_URL, "meta-url" },
2829 /* Get meta information from user */
2830 for( int i = 0; p_list[i].psz_name; i++ )
2832 char *psz_string = var_GetNonEmptyString( p_input, p_list[i].psz_name );
2836 EnsureUTF8( psz_string );
2837 vlc_meta_Set( p_meta, p_list[i].i_meta, psz_string );
2842 /*****************************************************************************
2843 * InputUpdateMeta: merge p_item meta data with p_meta taking care of
2844 * arturl and locking issue.
2845 *****************************************************************************/
2846 static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta )
2848 es_out_ControlSetMeta( p_input->p->p_es_out, p_meta );
2849 vlc_meta_Delete( p_meta );
2852 static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
2853 int i_new, input_attachment_t **pp_new )
2855 int i_attachment = *pi_attachment;
2856 input_attachment_t **attachment = *ppp_attachment;
2859 attachment = xrealloc( attachment,
2860 sizeof(input_attachment_t**) * ( i_attachment + i_new ) );
2861 for( i = 0; i < i_new; i++ )
2862 attachment[i_attachment++] = pp_new[i];
2866 *pi_attachment = i_attachment;
2867 *ppp_attachment = attachment;
2869 /*****************************************************************************
2870 * InputGetExtraFiles
2871 * Autodetect extra input list
2872 *****************************************************************************/
2873 static void InputGetExtraFilesPattern( input_thread_t *p_input,
2874 int *pi_list, char ***pppsz_list,
2875 const char *psz_path,
2876 const char *psz_match,
2877 const char *psz_format,
2878 int i_start, int i_stop )
2883 TAB_INIT( i_list, ppsz_list );
2885 char *psz_base = strdup( psz_path );
2889 /* Remove the extension */
2890 char *psz_end = &psz_base[strlen(psz_base)-strlen(psz_match)];
2891 assert( psz_end >= psz_base);
2894 /* Try to list files */
2895 for( int i = i_start; i <= i_stop; i++ )
2900 if( asprintf( &psz_file, psz_format, psz_base, i ) < 0 )
2903 if( vlc_stat( psz_file, &st ) || !S_ISREG( st.st_mode ) || !st.st_size )
2909 msg_Dbg( p_input, "Detected extra file `%s'", psz_file );
2910 TAB_APPEND( i_list, ppsz_list, psz_file );
2915 *pppsz_list = ppsz_list;
2918 static void InputGetExtraFiles( input_thread_t *p_input,
2919 int *pi_list, char ***pppsz_list,
2920 const char *psz_access, const char *psz_path )
2924 const char *psz_match;
2925 const char *psz_format;
2929 /* XXX the order is important */
2930 { ".001", "%s.%.3d", 2, 999 },
2931 { ".part1.rar", "%s.part%.1d.rar",2, 9 },
2932 { ".part01.rar", "%s.part%.2d.rar",2, 99, },
2933 { ".part001.rar", "%s.part%.3d.rar",2, 999 },
2934 { ".rar", "%s.r%.2d", 0, 99 },
2935 { NULL, NULL, 0, 0 }
2938 TAB_INIT( *pi_list, *pppsz_list );
2940 if( ( psz_access && *psz_access && strcmp( psz_access, "file" ) ) || !psz_path )
2943 const size_t i_path = strlen(psz_path);
2945 for( int i = 0; p_pattern[i].psz_match != NULL; i++ )
2947 const size_t i_ext = strlen(p_pattern[i].psz_match );
2949 if( i_path < i_ext )
2951 if( !strcmp( &psz_path[i_path-i_ext], p_pattern[i].psz_match ) )
2953 InputGetExtraFilesPattern( p_input, pi_list, pppsz_list,
2955 p_pattern[i].psz_match, p_pattern[i].psz_format,
2956 p_pattern[i].i_start, p_pattern[i].i_stop );
2963 static void input_ChangeState( input_thread_t *p_input, int i_state )
2965 const bool b_changed = p_input->p->i_state != i_state;
2967 p_input->p->i_state = i_state;
2968 if( i_state == ERROR_S )
2969 p_input->b_error = true;
2970 else if( i_state == END_S )
2971 p_input->b_eof = true;
2975 input_item_SetErrorWhenReading( p_input->p->p_item, p_input->b_error );
2976 input_SendEventState( p_input, i_state );
2981 /*****************************************************************************
2982 * MRLSplit: parse the access, demux and url part of the
2983 * Media Resource Locator.
2984 *****************************************************************************/
2985 void input_SplitMRL( const char **ppsz_access, const char **ppsz_demux,
2986 char **ppsz_path, char *psz_dup )
2988 const char *psz_access;
2989 const char *psz_demux = "";
2992 /* Either there is an access/demux specification before ://
2993 * or we have a plain local file path. */
2994 psz_path = strstr( psz_dup, "://" );
2995 if( psz_path != NULL )
2998 psz_path += 3; /* skips "://" */
3000 psz_access = psz_dup;
3001 /* We really don't want module name substitution here! */
3002 if( psz_access[0] == '$' )
3005 /* Separate access from demux (<access>/<demux>://<path>) */
3006 char *p = strchr( psz_access, '/' );
3011 if( psz_demux[0] == '$' )
3015 /* Remove HTML anchor if present (not supported).
3016 * The hash symbol itself should be URI-encoded. */
3017 p = strchr( psz_path, '#' );
3024 fprintf( stderr, "%s(\"%s\"): not a valid URI!\n", __func__,
3031 *ppsz_access = psz_access;
3032 *ppsz_demux = psz_demux;
3033 *ppsz_path = psz_path;
3036 static inline bool next(char ** src)
3040 long result = strtol( *src, &end, 0 );
3041 if( errno != 0 || result >= LONG_MAX || result <= LONG_MIN ||
3050 /*****************************************************************************
3051 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
3054 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
3055 *****************************************************************************/
3056 static void MRLSections( input_thread_t *p_input, char *psz_source,
3057 int *pi_title_start, int *pi_title_end,
3058 int *pi_chapter_start, int *pi_chapter_end )
3060 char *psz, *psz_end, *psz_next, *psz_check;
3062 *pi_title_start = *pi_title_end = -1;
3063 *pi_chapter_start = *pi_chapter_end = -1;
3065 /* Start by parsing titles and chapters */
3066 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
3069 /* Check we are really dealing with a title/chapter section */
3070 psz_check = psz + 1;
3071 if( !*psz_check ) return;
3072 if( isdigit(*psz_check) )
3073 if(!next(&psz_check)) return;
3074 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
3075 if( *psz_check == ':' && ++psz_check )
3077 if( isdigit(*psz_check) )
3078 if(!next(&psz_check)) return;
3080 if( *psz_check != '-' && *psz_check ) return;
3081 if( *psz_check == '-' && ++psz_check )
3083 if( isdigit(*psz_check) )
3084 if(!next(&psz_check)) return;
3086 if( *psz_check != ':' && *psz_check ) return;
3087 if( *psz_check == ':' && ++psz_check )
3089 if( isdigit(*psz_check) )
3090 if(!next(&psz_check)) return;
3092 if( *psz_check ) return;
3094 /* Separate start and end */
3096 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
3098 /* Look for the start title */
3099 *pi_title_start = strtol( psz, &psz_next, 0 );
3100 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
3101 *pi_title_end = *pi_title_start;
3104 /* Look for the start chapter */
3106 *pi_chapter_start = strtol( psz, &psz_next, 0 );
3107 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
3108 *pi_chapter_end = *pi_chapter_start;
3112 /* Look for the end title */
3113 *pi_title_end = strtol( psz_end, &psz_next, 0 );
3114 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
3117 /* Look for the end chapter */
3118 if( *psz_end ) psz_end++;
3119 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
3120 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
3123 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
3124 psz_source, *pi_title_start, *pi_chapter_start,
3125 *pi_title_end, *pi_chapter_end );
3128 /*****************************************************************************
3129 * input_AddSubtitles: add a subtitles file and enable it
3130 *****************************************************************************/
3131 static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_forced )
3133 input_source_t *sub;
3136 char *psz_path, *psz_extension;
3138 /* if we are provided a subtitle.sub file,
3139 * see if we don't have a subtitle.idx and use it instead */
3140 psz_path = strdup( psz_subtitle );
3143 psz_extension = strrchr( psz_path, '.');
3144 if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
3148 strcpy( psz_extension, ".idx" );
3150 if( !vlc_stat( psz_path, &st ) && S_ISREG( st.st_mode ) )
3152 msg_Dbg( p_input, "using %s subtitles file instead of %s",
3153 psz_path, psz_subtitle );
3154 strcpy( psz_subtitle, psz_path );
3160 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
3162 sub = InputSourceNew( p_input );
3163 if( !sub || InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
3168 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
3171 if( b_forced && !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
3173 if( count.i_int == 0 )
3175 /* if it was first one, there is disable too */
3177 if( count.i_int < list.p_list->i_count )
3179 const int i_id = list.p_list->p_values[count.i_int].i_int;
3181 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_DEFAULT_BY_ID, i_id );
3182 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, i_id );
3184 var_FreeList( &list, NULL );
3188 /*****************************************************************************
3190 *****************************************************************************/
3191 void input_UpdateStatistic( input_thread_t *p_input,
3192 input_statistic_t i_type, int i_delta )
3194 assert( p_input->p->i_state != INIT_S );
3196 vlc_mutex_lock( &p_input->p->counters.counters_lock);
3199 #define I(c) stats_UpdateInteger( p_input, p_input->p->counters.c, i_delta, NULL )
3200 case INPUT_STATISTIC_DECODED_VIDEO:
3203 case INPUT_STATISTIC_DECODED_AUDIO:
3206 case INPUT_STATISTIC_DECODED_SUBTITLE:
3209 case INPUT_STATISTIC_SENT_PACKET:
3210 I(p_sout_sent_packets);
3213 case INPUT_STATISTIC_SENT_BYTE:
3215 int i_bytes; /* That's pretty stupid to define it as an integer, it will overflow
3217 if( !stats_UpdateInteger( p_input, p_input->p->counters.p_sout_sent_bytes, i_delta, &i_bytes ) )
3218 stats_UpdateFloat( p_input, p_input->p->counters.p_sout_send_bitrate, i_bytes, NULL );
3222 msg_Err( p_input, "Invalid statistic type %d (internal error)", i_type );
3225 vlc_mutex_unlock( &p_input->p->counters.counters_lock);
3229 /* TODO FIXME nearly the same logic that snapshot code */
3230 char *input_CreateFilename( vlc_object_t *p_obj, const char *psz_path, const char *psz_prefix, const char *psz_extension )
3235 path = vlc_opendir( psz_path );
3240 char *psz_tmp = str_format( p_obj, psz_prefix );
3244 filename_sanitize( psz_tmp );
3246 if( asprintf( &psz_file, "%s"DIR_SEP"%s%s%s",
3248 psz_extension ? "." : "",
3249 psz_extension ? psz_extension : "" ) < 0 )
3256 psz_file = str_format( p_obj, psz_path );
3257 path_sanitize( psz_file );