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 void ControlRelease( int i_type, vlc_value_t val );
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 );
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 */
113 /* Do not let a pts_delay from access/demux go beyong 60s */
114 #define INPUT_PTS_DELAY_MAX INT64_C(60000000)
116 /*****************************************************************************
117 * This function creates a new input, and returns a pointer
118 * to its description. On error, it returns NULL.
120 * XXX Do not forget to update vlc_input.h if you add new variables.
121 *****************************************************************************/
122 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
123 const char *psz_header, bool b_quick,
124 input_resource_t *p_resource )
126 static const char input_name[] = "input";
127 input_thread_t *p_input = NULL; /* thread descriptor */
130 /* Allocate descriptor */
131 p_input = vlc_custom_create( p_parent, sizeof( *p_input ),
132 VLC_OBJECT_INPUT, input_name );
133 if( p_input == NULL )
136 /* Construct a nice name for the input timer */
137 char psz_timer_name[255];
138 char * psz_name = input_item_GetName( p_item );
139 snprintf( psz_timer_name, sizeof(psz_timer_name),
140 "input launching for '%s'", psz_name );
142 msg_Dbg( p_input, "Creating an input for '%s'", psz_name);
146 /* Start a timer to mesure how long it takes
147 * to launch an input */
148 stats_TimerStart( p_input, psz_timer_name,
149 STATS_TIMER_INPUT_LAUNCHING );
151 p_input->p = calloc( 1, sizeof( input_thread_private_t ) );
155 p_input->b_preparsing = b_quick;
156 p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
158 /* Init Common fields */
159 p_input->b_eof = false;
160 p_input->p->b_can_pace_control = true;
161 p_input->p->i_start = 0;
162 p_input->p->i_time = 0;
163 p_input->p->i_stop = 0;
164 p_input->p->i_run = 0;
165 p_input->p->i_title = 0;
166 p_input->p->title = NULL;
167 p_input->p->i_title_offset = p_input->p->i_seekpoint_offset = 0;
168 p_input->p->i_state = INIT_S;
169 p_input->p->i_rate = INPUT_RATE_DEFAULT;
170 p_input->p->b_recording = false;
171 memset( &p_input->p->bookmark, 0, sizeof(p_input->p->bookmark) );
172 TAB_INIT( p_input->p->i_bookmark, p_input->p->pp_bookmark );
173 TAB_INIT( p_input->p->i_attachment, p_input->p->attachment );
174 p_input->p->p_es_out_display = NULL;
175 p_input->p->p_es_out = NULL;
176 p_input->p->p_sout = NULL;
177 p_input->p->b_out_pace_control = false;
179 vlc_gc_incref( p_item ); /* Released in Destructor() */
180 p_input->p->p_item = p_item;
182 /* Init Input fields */
183 p_input->p->input.p_access = NULL;
184 p_input->p->input.p_stream = NULL;
185 p_input->p->input.p_demux = NULL;
186 p_input->p->input.b_title_demux = false;
187 p_input->p->input.i_title = 0;
188 p_input->p->input.title = NULL;
189 p_input->p->input.i_title_offset = p_input->p->input.i_seekpoint_offset = 0;
190 p_input->p->input.b_can_pace_control = true;
191 p_input->p->input.b_can_rate_control = true;
192 p_input->p->input.b_rescale_ts = true;
193 p_input->p->input.b_eof = false;
195 vlc_mutex_lock( &p_item->lock );
197 if( !p_item->p_stats )
198 p_item->p_stats = stats_NewInputStats( p_input );
199 vlc_mutex_unlock( &p_item->lock );
202 p_input->p->i_slave = 0;
203 p_input->p->slave = NULL;
207 p_input->p->p_resource = p_resource;
209 p_input->p->p_resource = input_resource_New();
210 input_resource_SetInput( p_input->p->p_resource, p_input );
212 /* Init control buffer */
213 vlc_mutex_init( &p_input->p->lock_control );
214 vlc_cond_init( &p_input->p->wait_control );
215 p_input->p->i_control = 0;
216 p_input->p->b_abort = false;
218 /* Parse input options */
219 vlc_mutex_lock( &p_item->lock );
220 assert( (int)p_item->optflagc == p_item->i_options );
221 for( i = 0; i < p_item->i_options; i++ )
222 var_OptionParse( VLC_OBJECT(p_input), p_item->ppsz_options[i],
223 !!(p_item->optflagv[i] & VLC_INPUT_OPTION_TRUSTED) );
224 vlc_mutex_unlock( &p_item->lock );
226 /* Create Object Variables for private use only */
227 input_ConfigVarInit( p_input );
229 /* Create Objects variables for public Get and Set */
230 input_ControlVarInit( p_input );
233 if( !p_input->b_preparsing )
235 char *psz_bookmarks = var_GetNonEmptyString( p_input, "bookmarks" );
238 /* FIXME: have a common cfg parsing routine used by sout and others */
239 char *psz_parser, *psz_start, *psz_end;
240 psz_parser = psz_bookmarks;
241 while( (psz_start = strchr( psz_parser, '{' ) ) )
243 seekpoint_t *p_seekpoint;
246 psz_end = strchr( psz_start, '}' );
247 if( !psz_end ) break;
248 psz_parser = psz_end + 1;
249 backup = *psz_parser;
253 p_seekpoint = vlc_seekpoint_New();
254 while( (psz_end = strchr( psz_start, ',' ) ) )
257 if( !strncmp( psz_start, "name=", 5 ) )
259 p_seekpoint->psz_name = strdup(psz_start + 5);
261 else if( !strncmp( psz_start, "bytes=", 6 ) )
263 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
265 else if( !strncmp( psz_start, "time=", 5 ) )
267 p_seekpoint->i_time_offset = atoll(psz_start + 5) *
270 psz_start = psz_end + 1;
272 msg_Dbg( p_input, "adding bookmark: %s, bytes=%"PRId64", time=%"PRId64,
273 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
274 p_seekpoint->i_time_offset );
275 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
276 vlc_seekpoint_Delete( p_seekpoint );
277 *psz_parser = backup;
279 free( psz_bookmarks );
283 /* Remove 'Now playing' info as it is probably outdated */
284 input_item_SetNowPlaying( p_item, NULL );
285 input_SendEventMeta( p_input );
288 if( p_input->b_preparsing )
289 p_input->i_flags |= OBJECT_FLAGS_QUIET | OBJECT_FLAGS_NOINTERACT;
292 memset( &p_input->p->counters, 0, sizeof( p_input->p->counters ) );
293 vlc_mutex_init( &p_input->p->counters.counters_lock );
295 /* Set the destructor when we are sure we are initialized */
296 vlc_object_set_destructor( p_input, (vlc_destructor_t)Destructor );
298 /* Attach only once we are ready */
299 vlc_object_attach( p_input, p_parent );
305 * Input destructor (called when the object's refcount reaches 0).
307 static void Destructor( input_thread_t * p_input )
310 char * psz_name = input_item_GetName( p_input->p->p_item );
311 msg_Dbg( p_input, "Destroying the input for '%s'", psz_name);
315 stats_TimerDump( p_input, STATS_TIMER_INPUT_LAUNCHING );
316 stats_TimerClean( p_input, STATS_TIMER_INPUT_LAUNCHING );
318 if( p_input->p->p_resource )
319 input_resource_Delete( p_input->p->p_resource );
321 vlc_gc_decref( p_input->p->p_item );
323 vlc_mutex_destroy( &p_input->p->counters.counters_lock );
325 for( int i = 0; i < p_input->p->i_control; i++ )
327 input_control_t *p_ctrl = &p_input->p->control[i];
328 ControlRelease( p_ctrl->i_type, p_ctrl->val );
331 vlc_cond_destroy( &p_input->p->wait_control );
332 vlc_mutex_destroy( &p_input->p->lock_control );
337 * Initialize an input thread and run it. You will need to monitor the
338 * thread to clean up after it is done
340 * \param p_parent a vlc_object
341 * \param p_item an input item
342 * \return a pointer to the spawned input thread
344 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
345 input_item_t *p_item )
347 return __input_CreateThreadExtended( p_parent, p_item, NULL, NULL );
351 input_thread_t *__input_CreateThreadExtended( vlc_object_t *p_parent,
352 input_item_t *p_item,
353 const char *psz_log, input_resource_t *p_resource )
355 input_thread_t *p_input;
357 p_input = Create( p_parent, p_item, psz_log, false, p_resource );
361 /* Create thread and wait for its readiness. */
362 if( vlc_thread_create( p_input, "input", Run,
363 VLC_THREAD_PRIORITY_INPUT ) )
365 input_ChangeState( p_input, ERROR_S );
366 msg_Err( p_input, "cannot create input thread" );
367 vlc_object_detach( p_input );
368 vlc_object_release( p_input );
376 * Initialize an input thread and run it. This thread will clean after itself,
377 * you can forget about it. It can work either in blocking or non-blocking mode
379 * \param p_parent a vlc_object
380 * \param p_item an input item
381 * \param b_block should we block until read is finished ?
382 * \return an error code, VLC_SUCCESS on success
384 int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
387 input_thread_t *p_input;
389 p_input = Create( p_parent, p_item, NULL, false, NULL );
395 RunAndDestroy( VLC_OBJECT(p_input) );
400 if( vlc_thread_create( p_input, "input", RunAndDestroy,
401 VLC_THREAD_PRIORITY_INPUT ) )
403 input_ChangeState( p_input, ERROR_S );
404 msg_Err( p_input, "cannot create input thread" );
405 vlc_object_release( p_input );
413 * Initialize an input and initialize it to preparse the item
414 * This function is blocking. It will only accept parsing regular files.
416 * \param p_parent a vlc_object_t
417 * \param p_item an input item
418 * \return VLC_SUCCESS or an error
420 int input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
422 input_thread_t *p_input;
424 /* Allocate descriptor */
425 p_input = Create( p_parent, p_item, NULL, true, NULL );
429 if( !Init( p_input ) )
432 vlc_object_detach( p_input );
433 vlc_object_release( p_input );
439 * Request a running input thread to stop and die
441 * \param the input thread to stop
443 void input_StopThread( input_thread_t *p_input, bool b_abort )
445 /* Set die for input and ALL of this childrens (even (grand-)grand-childrens)
446 * It is needed here even if it is done in INPUT_CONTROL_SET_DIE handler to
447 * unlock the control loop */
448 ObjectKillChildrens( p_input, VLC_OBJECT(p_input) );
450 vlc_mutex_lock( &p_input->p->lock_control );
451 p_input->p->b_abort |= b_abort;
452 vlc_mutex_unlock( &p_input->p->lock_control );
454 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
457 input_resource_t *input_DetachResource( input_thread_t *p_input )
459 assert( p_input->b_dead );
461 input_resource_SetInput( p_input->p->p_resource, NULL );
463 input_resource_t *p_resource = input_resource_Detach( p_input->p->p_resource );
464 p_input->p->p_sout = NULL;
470 * Get the item from an input thread
471 * FIXME it does not increase ref count of the item.
472 * if it is used after p_input is destroyed nothing prevent it from
475 input_item_t *input_GetItem( input_thread_t *p_input )
477 assert( p_input && p_input->p );
478 return p_input->p->p_item;
481 /*****************************************************************************
482 * ObjectKillChildrens
483 *****************************************************************************/
484 static void ObjectKillChildrens( input_thread_t *p_input, vlc_object_t *p_obj )
489 /* FIXME ObjectKillChildrens seems a very bad idea in fact */
490 i = vlc_internals( p_obj )->i_object_type;
491 if( i == VLC_OBJECT_VOUT ||i == VLC_OBJECT_AOUT ||
492 p_obj == VLC_OBJECT(p_input->p->p_sout) ||
493 i == VLC_OBJECT_DECODER || i == VLC_OBJECT_PACKETIZER )
496 vlc_object_kill( p_obj );
498 p_list = vlc_list_children( p_obj );
499 for( i = 0; i < p_list->i_count; i++ )
500 ObjectKillChildrens( p_input, p_list->p_values[i].p_object );
501 vlc_list_release( p_list );
504 /*****************************************************************************
505 * Run: main thread loop
506 * This is the "normal" thread that spawns the input processing chain,
507 * reads the stream, cleans up and waits
508 *****************************************************************************/
509 static void *Run( vlc_object_t *p_this )
511 input_thread_t *p_input = (input_thread_t *)p_this;
512 const int canc = vlc_savecancel();
514 if( Init( p_input ) )
523 /* Tell we're dead */
524 vlc_mutex_lock( &p_input->p->lock_control );
525 const bool b_abort = p_input->p->b_abort;
526 vlc_mutex_unlock( &p_input->p->lock_control );
529 input_SendEventAbort( p_input );
530 input_SendEventDead( p_input );
532 vlc_restorecancel( canc );
536 /*****************************************************************************
537 * RunAndDestroy: main thread loop
538 * This is the "just forget me" thread that spawns the input processing chain,
539 * reads the stream, cleans up and releases memory
540 *****************************************************************************/
541 static void *RunAndDestroy( vlc_object_t *p_this )
543 input_thread_t *p_input = (input_thread_t *)p_this;
544 const int canc = vlc_savecancel();
546 if( Init( p_input ) )
556 vlc_object_release( p_input );
557 vlc_restorecancel( canc );
561 /*****************************************************************************
562 * Main loop: Fill buffers from access, and demux
563 *****************************************************************************/
567 * It asks the demuxer to demux some data
569 static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, mtime_t *pi_start_mdate )
575 if( ( p_input->p->i_stop > 0 && p_input->p->i_time >= p_input->p->i_stop ) ||
576 ( p_input->p->i_run > 0 && *pi_start_mdate+p_input->p->i_run < mdate() ) )
579 i_ret = demux_Demux( p_input->p->input.p_demux );
583 if( p_input->p->input.p_demux->info.i_update )
585 if( p_input->p->input.b_title_demux )
587 i_ret = UpdateTitleSeekpointFromDemux( p_input );
590 UpdateGenericFromDemux( p_input );
592 else if( p_input->p->input.p_access &&
593 p_input->p->input.p_access->info.i_update )
595 if( !p_input->p->input.b_title_demux )
597 i_ret = UpdateTitleSeekpointFromAccess( p_input );
600 UpdateGenericFromAccess( p_input );
604 if( i_ret == 0 ) /* EOF */
606 int i_repeat = var_GetInteger( p_input, "input-repeat" );
609 /* End of file - we do not set b_die because only the
610 * playlist is allowed to do so. */
611 msg_Dbg( p_input, "EOF reached" );
612 p_input->p->input.b_eof = true;
618 msg_Dbg( p_input, "repeating the same input (%d)", i_repeat );
622 var_SetInteger( p_input, "input-repeat", i_repeat );
625 /* Seek to start title/seekpoint */
626 val.i_int = p_input->p->input.i_title_start -
627 p_input->p->input.i_title_offset;
628 if( val.i_int < 0 || val.i_int >= p_input->p->input.i_title )
630 input_ControlPush( p_input,
631 INPUT_CONTROL_SET_TITLE, &val );
633 val.i_int = p_input->p->input.i_seekpoint_start -
634 p_input->p->input.i_seekpoint_offset;
635 if( val.i_int > 0 /* TODO: check upper boundary */ )
636 input_ControlPush( p_input,
637 INPUT_CONTROL_SET_SEEKPOINT, &val );
639 /* Seek to start position */
640 if( p_input->p->i_start > 0 )
642 val.i_time = p_input->p->i_start;
643 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
649 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
654 *pi_start_mdate = mdate();
659 input_ChangeState( p_input, ERROR_S );
662 if( i_ret > 0 && p_input->p->i_slave > 0 )
664 SlaveDemux( p_input );
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 )
718 mtime_t i_start_mdate = mdate();
719 mtime_t i_intf_update = 0;
720 mtime_t i_statistic_update = 0;
722 /* Start the timer */
723 stats_TimerStop( p_input, STATS_TIMER_INPUT_LAUNCHING );
725 while( vlc_object_alive( p_input ) && !p_input->b_error )
736 b_force_update = false;
738 /* FIXME if p_input->p->i_state == PAUSE_S the access/access_demux
739 * is paused -> this may cause problem with some of them
740 * The same problem can be seen when seeking while paused */
741 b_paused = p_input->p->i_state == PAUSE_S &&
742 !es_out_GetBuffering( p_input->p->p_es_out );
746 if( !p_input->p->input.b_eof )
748 MainLoopDemux( p_input, &b_force_update, &i_start_mdate );
750 i_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
752 else if( !p_input->b_eof && !es_out_GetEmpty( p_input->p->p_es_out ) )
754 msg_Dbg( p_input, "waiting decoder fifos to empty" );
755 i_wakeup = mdate() + INPUT_IDLE_SLEEP;
765 i_deadline = i_wakeup;
767 i_deadline = __MIN( i_intf_update, i_statistic_update );
770 ControlReduce( p_input );
771 while( !ControlPop( p_input, &i_type, &val, i_deadline ) )
774 msg_Dbg( p_input, "control type=%d", i_type );
776 if( Control( p_input, i_type, val ) )
777 b_force_update = true;
780 /* Update interface and statistics */
782 if( i_intf_update < i_current || b_force_update )
784 MainLoopInterface( p_input );
785 i_intf_update = i_current + INT64_C(250000);
786 b_force_update = false;
788 if( i_statistic_update < i_current )
790 MainLoopStatistic( p_input );
791 i_statistic_update = i_current + INT64_C(1000000);
794 /* Check if i_wakeup is still valid */
797 mtime_t i_new_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
801 } while( i_current < i_wakeup );
804 if( !p_input->b_error )
805 input_ChangeState( p_input, END_S );
808 static void InitStatistics( input_thread_t * p_input )
810 if( p_input->b_preparsing ) return;
812 /* Prepare statistics */
813 #define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \
814 stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
815 if( libvlc_stats( p_input ) )
817 INIT_COUNTER( read_bytes, INTEGER, COUNTER );
818 INIT_COUNTER( read_packets, INTEGER, COUNTER );
819 INIT_COUNTER( demux_read, INTEGER, COUNTER );
820 INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE );
821 INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE );
822 INIT_COUNTER( demux_corrupted, INTEGER, COUNTER );
823 INIT_COUNTER( demux_discontinuity, INTEGER, COUNTER );
824 INIT_COUNTER( played_abuffers, INTEGER, COUNTER );
825 INIT_COUNTER( lost_abuffers, INTEGER, COUNTER );
826 INIT_COUNTER( displayed_pictures, INTEGER, COUNTER );
827 INIT_COUNTER( lost_pictures, INTEGER, COUNTER );
828 INIT_COUNTER( decoded_audio, INTEGER, COUNTER );
829 INIT_COUNTER( decoded_video, INTEGER, COUNTER );
830 INIT_COUNTER( decoded_sub, INTEGER, COUNTER );
831 p_input->p->counters.p_sout_send_bitrate = NULL;
832 p_input->p->counters.p_sout_sent_packets = NULL;
833 p_input->p->counters.p_sout_sent_bytes = NULL;
834 if( p_input->p->counters.p_demux_bitrate )
835 p_input->p->counters.p_demux_bitrate->update_interval = 1000000;
836 if( p_input->p->counters.p_input_bitrate )
837 p_input->p->counters.p_input_bitrate->update_interval = 1000000;
842 static int InitSout( input_thread_t * p_input )
844 if( p_input->b_preparsing )
847 /* Find a usable sout and attach it to p_input */
848 char *psz = var_GetNonEmptyString( p_input, "sout" );
849 if( psz && strncasecmp( p_input->p->p_item->psz_uri, "vlc:", 4 ) )
851 p_input->p->p_sout = input_resource_RequestSout( p_input->p->p_resource, NULL, psz );
852 if( !p_input->p->p_sout )
854 input_ChangeState( p_input, ERROR_S );
855 msg_Err( p_input, "cannot start stream output instance, " \
860 if( libvlc_stats( p_input ) )
862 INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
863 INIT_COUNTER( sout_sent_bytes, INTEGER, COUNTER );
864 INIT_COUNTER( sout_send_bitrate, FLOAT, DERIVATIVE );
865 if( p_input->p->counters.p_sout_send_bitrate )
866 p_input->p->counters.p_sout_send_bitrate->update_interval =
872 input_resource_RequestSout( p_input->p->p_resource, NULL, NULL );
880 static void InitTitle( input_thread_t * p_input )
882 input_source_t *p_master = &p_input->p->input;
884 if( p_input->b_preparsing )
887 /* Create global title (from master) */
888 p_input->p->i_title = p_master->i_title;
889 p_input->p->title = p_master->title;
890 p_input->p->i_title_offset = p_master->i_title_offset;
891 p_input->p->i_seekpoint_offset = p_master->i_seekpoint_offset;
892 if( p_input->p->i_title > 0 )
894 /* Setup variables */
895 input_ControlVarNavigation( p_input );
896 input_SendEventTitle( p_input, 0 );
900 p_input->p->b_can_pace_control = p_master->b_can_pace_control;
901 p_input->p->b_can_pause = p_master->b_can_pause;
902 p_input->p->b_can_rate_control = p_master->b_can_rate_control;
905 static void StartTitle( input_thread_t * p_input )
909 /* Start title/chapter */
910 val.i_int = p_input->p->input.i_title_start -
911 p_input->p->input.i_title_offset;
912 if( val.i_int > 0 && val.i_int < p_input->p->input.i_title )
913 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
915 val.i_int = p_input->p->input.i_seekpoint_start -
916 p_input->p->input.i_seekpoint_offset;
917 if( val.i_int > 0 /* TODO: check upper boundary */ )
918 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
920 /* Start/stop/run time */
921 p_input->p->i_start = INT64_C(1000000) * var_GetInteger( p_input, "start-time" );
922 p_input->p->i_stop = INT64_C(1000000) * var_GetInteger( p_input, "stop-time" );
923 p_input->p->i_run = INT64_C(1000000) * var_GetInteger( p_input, "run-time" );
924 if( p_input->p->i_run < 0 )
926 msg_Warn( p_input, "invalid run-time ignored" );
927 p_input->p->i_run = 0;
930 const mtime_t i_length = var_GetTime( p_input, "length" );
931 if( p_input->p->i_start > 0 )
933 if( p_input->p->i_start >= i_length )
935 msg_Warn( p_input, "invalid start-time ignored" );
941 msg_Dbg( p_input, "starting at time: %ds",
942 (int)( p_input->p->i_start / INT64_C(1000000) ) );
944 s.i_time = p_input->p->i_start;
945 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
948 if( p_input->p->i_stop > 0 && p_input->p->i_stop <= p_input->p->i_start )
950 msg_Warn( p_input, "invalid stop-time ignored" );
951 p_input->p->i_stop = 0;
953 p_input->p->b_fast_seek = var_GetBool( p_input, "input-fast-seek" );
956 static void LoadSubtitles( input_thread_t *p_input )
959 /* Get fps and set it if not already set */
960 const double f_fps = p_input->p->f_fps;
963 float f_requested_fps;
965 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
966 var_SetFloat( p_input, "sub-original-fps", f_fps );
968 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
969 if( f_requested_fps != f_fps )
971 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
973 var_SetFloat( p_input, "sub-fps", f_requested_fps );
977 const int i_delay = var_CreateGetInteger( p_input, "sub-delay" );
979 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
981 /* Look for and add subtitle files */
982 char *psz_subtitle = var_GetNonEmptyString( p_input, "sub-file" );
983 if( psz_subtitle != NULL )
985 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
986 SubtitleAdd( p_input, psz_subtitle, true );
989 if( var_GetBool( p_input, "sub-autodetect-file" ) )
991 char *psz_autopath = var_GetNonEmptyString( p_input, "sub-autodetect-path" );
992 char **ppsz_subs = subtitles_Detect( p_input, psz_autopath,
993 p_input->p->p_item->psz_uri );
994 free( psz_autopath );
996 for( int i = 0; ppsz_subs && ppsz_subs[i]; i++ )
998 /* Try to autoselect the first autodetected subtitles file
999 * if no subtitles file was specified */
1000 bool b_forced = i == 0 && !psz_subtitle;
1002 if( !psz_subtitle || strcmp( psz_subtitle, ppsz_subs[i] ) )
1003 SubtitleAdd( p_input, ppsz_subs[i], b_forced );
1005 free( ppsz_subs[i] );
1009 free( psz_subtitle );
1012 static void LoadSlaves( input_thread_t *p_input )
1014 char *psz = var_GetNonEmptyString( p_input, "input-slave" );
1018 char *psz_org = psz;
1019 while( psz && *psz )
1021 while( *psz == ' ' || *psz == '#' )
1024 char *psz_delim = strchr( psz, '#' );
1026 *psz_delim++ = '\0';
1031 msg_Dbg( p_input, "adding slave input '%s'", psz );
1033 input_source_t *p_slave = InputSourceNew( p_input );
1034 if( p_slave && !InputSourceInit( p_input, p_slave, psz, NULL ) )
1035 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, p_slave );
1044 static void UpdatePtsDelay( input_thread_t *p_input )
1046 input_thread_private_t *p_sys = p_input->p;
1048 /* Get max pts delay from input source */
1049 mtime_t i_pts_delay = p_sys->input.i_pts_delay;
1050 for( int i = 0; i < p_sys->i_slave; i++ )
1051 i_pts_delay = __MAX( i_pts_delay, p_sys->slave[i]->i_pts_delay );
1053 if( i_pts_delay < 0 )
1056 /* Take care of audio/spu delay */
1057 const mtime_t i_audio_delay = var_GetTime( p_input, "audio-delay" );
1058 const mtime_t i_spu_delay = var_GetTime( p_input, "spu-delay" );
1059 const mtime_t i_extra_delay = __MIN( i_audio_delay, i_spu_delay );
1060 if( i_extra_delay < 0 )
1061 i_pts_delay -= i_extra_delay;
1063 /* Update cr_average depending on the caching */
1064 const int i_cr_average = var_GetInteger( p_input, "cr-average" ) * i_pts_delay / DEFAULT_PTS_DELAY;
1067 es_out_SetJitter( p_input->p->p_es_out, i_pts_delay, i_cr_average );
1070 static void InitPrograms( input_thread_t * p_input )
1075 /* Compute correct pts_delay */
1076 UpdatePtsDelay( p_input );
1079 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, true );
1080 i_es_out_mode = ES_OUT_MODE_AUTO;
1082 if( p_input->p->p_sout )
1084 if( var_GetBool( p_input, "sout-all" ) )
1086 i_es_out_mode = ES_OUT_MODE_ALL;
1091 var_Get( p_input, "programs", &val );
1092 if( val.p_list && val.p_list->i_count )
1094 i_es_out_mode = ES_OUT_MODE_PARTIAL;
1095 /* Note : we should remove the "program" callback. */
1099 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
1104 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
1106 /* Inform the demuxer about waited group (needed only for DVB) */
1107 if( i_es_out_mode == ES_OUT_MODE_ALL )
1109 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
1111 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
1113 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1,
1118 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP,
1119 (int) var_GetInteger( p_input, "program" ), NULL );
1123 static int Init( input_thread_t * p_input )
1128 for( i = 0; i < p_input->p->p_item->i_options; i++ )
1130 if( !strncmp( p_input->p->p_item->ppsz_options[i], "meta-file", 9 ) )
1132 msg_Dbg( p_input, "Input is a meta file: disabling unneeded options" );
1133 var_SetString( p_input, "sout", "" );
1134 var_SetBool( p_input, "sout-all", false );
1135 var_SetString( p_input, "input-slave", "" );
1136 var_SetInteger( p_input, "input-repeat", 0 );
1137 var_SetString( p_input, "sub-file", "" );
1138 var_SetBool( p_input, "sub-autodetect-file", false );
1142 InitStatistics( p_input );
1144 ret = InitSout( p_input );
1145 if( ret != VLC_SUCCESS )
1150 p_input->p->p_es_out_display = input_EsOutNew( p_input, p_input->p->i_rate );
1151 p_input->p->p_es_out = input_EsOutTimeshiftNew( p_input, p_input->p->p_es_out_display, p_input->p->i_rate );
1152 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, false );
1153 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
1155 var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
1156 var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
1159 input_ChangeState( p_input, OPENING_S );
1160 input_SendEventCache( p_input, 0.0 );
1163 if( InputSourceInit( p_input, &p_input->p->input,
1164 p_input->p->p_item->psz_uri, NULL ) )
1169 InitTitle( p_input );
1171 /* Load master infos */
1174 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_LENGTH,
1178 i_length = input_item_GetDuration( p_input->p->p_item );
1179 input_SendEventTimes( p_input, 0.0, 0, i_length );
1181 if( !p_input->b_preparsing )
1183 StartTitle( p_input );
1184 LoadSubtitles( p_input );
1185 LoadSlaves( p_input );
1186 InitPrograms( p_input );
1189 if( !p_input->b_preparsing && p_input->p->p_sout )
1191 p_input->p->b_out_pace_control = (p_input->p->p_sout->i_out_pace_nocontrol > 0);
1193 if( p_input->p->b_can_pace_control && p_input->p->b_out_pace_control )
1195 /* We don't want a high input priority here or we'll
1196 * end-up sucking up all the CPU time */
1197 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
1200 msg_Dbg( p_input, "starting in %s mode",
1201 p_input->p->b_out_pace_control ? "async" : "sync" );
1204 p_meta = vlc_meta_New();
1207 /* Get meta data from users */
1208 InputMetaUser( p_input, p_meta );
1210 /* Get meta data from master input */
1211 InputSourceMeta( p_input, &p_input->p->input, p_meta );
1213 /* And from slave */
1214 for( int i = 0; i < p_input->p->i_slave; i++ )
1215 InputSourceMeta( p_input, p_input->p->slave[i], p_meta );
1218 InputUpdateMeta( p_input, p_meta );
1221 msg_Dbg( p_input, "`%s' successfully opened",
1222 p_input->p->p_item->psz_uri );
1224 /* initialization is complete */
1225 input_ChangeState( p_input, PLAYING_S );
1230 input_ChangeState( p_input, ERROR_S );
1232 if( p_input->p->p_es_out )
1233 es_out_Delete( p_input->p->p_es_out );
1234 if( p_input->p->p_es_out_display )
1235 es_out_Delete( p_input->p->p_es_out_display );
1236 if( p_input->p->p_resource )
1238 if( p_input->p->p_sout )
1239 input_resource_RequestSout( p_input->p->p_resource,
1240 p_input->p->p_sout, NULL );
1241 input_resource_SetInput( p_input->p->p_resource, NULL );
1247 if( !p_input->b_preparsing && libvlc_stats( p_input ) )
1249 #define EXIT_COUNTER( c ) do { if( p_input->p->counters.p_##c ) \
1250 stats_CounterClean( p_input->p->counters.p_##c );\
1251 p_input->p->counters.p_##c = NULL; } while(0)
1252 EXIT_COUNTER( read_bytes );
1253 EXIT_COUNTER( read_packets );
1254 EXIT_COUNTER( demux_read );
1255 EXIT_COUNTER( input_bitrate );
1256 EXIT_COUNTER( demux_bitrate );
1257 EXIT_COUNTER( demux_corrupted );
1258 EXIT_COUNTER( demux_discontinuity );
1259 EXIT_COUNTER( played_abuffers );
1260 EXIT_COUNTER( lost_abuffers );
1261 EXIT_COUNTER( displayed_pictures );
1262 EXIT_COUNTER( lost_pictures );
1263 EXIT_COUNTER( decoded_audio );
1264 EXIT_COUNTER( decoded_video );
1265 EXIT_COUNTER( decoded_sub );
1267 if( p_input->p->p_sout )
1269 EXIT_COUNTER( sout_sent_packets );
1270 EXIT_COUNTER( sout_sent_bytes );
1271 EXIT_COUNTER( sout_send_bitrate );
1276 /* Mark them deleted */
1277 p_input->p->input.p_demux = NULL;
1278 p_input->p->input.p_stream = NULL;
1279 p_input->p->input.p_access = NULL;
1280 p_input->p->p_es_out = NULL;
1281 p_input->p->p_es_out_display = NULL;
1282 p_input->p->p_sout = NULL;
1284 return VLC_EGENERIC;
1287 /*****************************************************************************
1288 * End: end the input thread
1289 *****************************************************************************/
1290 static void End( input_thread_t * p_input )
1294 /* We are at the end */
1295 input_ChangeState( p_input, END_S );
1297 /* Clean control variables */
1298 input_ControlVarStop( p_input );
1300 /* Stop es out activity */
1301 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, false );
1302 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
1304 /* Clean up master */
1305 InputSourceClean( &p_input->p->input );
1308 for( i = 0; i < p_input->p->i_slave; i++ )
1310 InputSourceClean( p_input->p->slave[i] );
1311 free( p_input->p->slave[i] );
1313 free( p_input->p->slave );
1315 /* Unload all modules */
1316 if( p_input->p->p_es_out )
1317 es_out_Delete( p_input->p->p_es_out );
1318 if( p_input->p->p_es_out_display )
1319 es_out_Delete( p_input->p->p_es_out_display );
1321 if( !p_input->b_preparsing )
1323 #define CL_CO( c ) stats_CounterClean( p_input->p->counters.p_##c ); p_input->p->counters.p_##c = NULL;
1324 if( libvlc_stats( p_input ) )
1326 /* make sure we are up to date */
1327 stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
1328 CL_CO( read_bytes );
1329 CL_CO( read_packets );
1330 CL_CO( demux_read );
1331 CL_CO( input_bitrate );
1332 CL_CO( demux_bitrate );
1333 CL_CO( demux_corrupted );
1334 CL_CO( demux_discontinuity );
1335 CL_CO( played_abuffers );
1336 CL_CO( lost_abuffers );
1337 CL_CO( displayed_pictures );
1338 CL_CO( lost_pictures );
1339 CL_CO( decoded_audio) ;
1340 CL_CO( decoded_video );
1341 CL_CO( decoded_sub) ;
1344 /* Close optional stream output instance */
1345 if( p_input->p->p_sout )
1347 CL_CO( sout_sent_packets );
1348 CL_CO( sout_sent_bytes );
1349 CL_CO( sout_send_bitrate );
1354 vlc_mutex_lock( &p_input->p->p_item->lock );
1355 if( p_input->p->i_attachment > 0 )
1357 for( i = 0; i < p_input->p->i_attachment; i++ )
1358 vlc_input_attachment_Delete( p_input->p->attachment[i] );
1359 TAB_CLEAN( p_input->p->i_attachment, p_input->p->attachment );
1361 vlc_mutex_unlock( &p_input->p->p_item->lock );
1364 input_resource_RequestSout( p_input->p->p_resource,
1365 p_input->p->p_sout, NULL );
1366 input_resource_SetInput( p_input->p->p_resource, NULL );
1369 /*****************************************************************************
1371 *****************************************************************************/
1372 void input_ControlPush( input_thread_t *p_input,
1373 int i_type, vlc_value_t *p_val )
1375 vlc_mutex_lock( &p_input->p->lock_control );
1376 if( i_type == INPUT_CONTROL_SET_DIE )
1378 /* Special case, empty the control */
1379 for( int i = 0; i < p_input->p->i_control; i++ )
1381 input_control_t *p_ctrl = &p_input->p->control[i];
1382 ControlRelease( p_ctrl->i_type, p_ctrl->val );
1384 p_input->p->i_control = 0;
1387 if( p_input->p->i_control >= INPUT_CONTROL_FIFO_SIZE )
1389 msg_Err( p_input, "input control fifo overflow, trashing type=%d",
1392 ControlRelease( i_type, *p_val );
1401 memset( &c.val, 0, sizeof(c.val) );
1403 p_input->p->control[p_input->p->i_control++] = c;
1405 vlc_cond_signal( &p_input->p->wait_control );
1406 vlc_mutex_unlock( &p_input->p->lock_control );
1409 static inline int ControlPop( input_thread_t *p_input,
1410 int *pi_type, vlc_value_t *p_val,
1411 mtime_t i_deadline )
1413 input_thread_private_t *p_sys = p_input->p;
1415 vlc_mutex_lock( &p_sys->lock_control );
1416 while( p_sys->i_control <= 0 )
1418 if( !vlc_object_alive( p_input ) || i_deadline < 0 )
1420 vlc_mutex_unlock( &p_sys->lock_control );
1421 return VLC_EGENERIC;
1424 if( vlc_cond_timedwait( &p_sys->wait_control, &p_sys->lock_control,
1427 vlc_mutex_unlock( &p_sys->lock_control );
1428 return VLC_EGENERIC;
1433 *pi_type = p_sys->control[0].i_type;
1434 *p_val = p_sys->control[0].val;
1437 if( p_sys->i_control > 0 )
1438 memmove( &p_sys->control[0], &p_sys->control[1],
1439 sizeof(*p_sys->control) * p_sys->i_control );
1440 vlc_mutex_unlock( &p_sys->lock_control );
1445 static void ControlReduce( input_thread_t *p_input )
1447 vlc_mutex_lock( &p_input->p->lock_control );
1449 for( int i = 1; i < p_input->p->i_control; i++ )
1451 const int i_lt = p_input->p->control[i-1].i_type;
1452 const int i_ct = p_input->p->control[i].i_type;
1454 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1455 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->p->i_control,
1459 ( i_ct == INPUT_CONTROL_SET_STATE ||
1460 i_ct == INPUT_CONTROL_SET_RATE ||
1461 i_ct == INPUT_CONTROL_SET_POSITION ||
1462 i_ct == INPUT_CONTROL_SET_TIME ||
1463 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1464 i_ct == INPUT_CONTROL_SET_TITLE ||
1465 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1466 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1469 // msg_Dbg( p_input, "merged at %d", i );
1470 /* Remove the i-1 */
1471 for( j = i; j < p_input->p->i_control; j++ )
1472 p_input->p->control[j-1] = p_input->p->control[j];
1473 p_input->p->i_control--;
1477 /* TODO but that's not that important
1478 - merge SET_X with SET_X_CMD
1479 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1480 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1485 vlc_mutex_unlock( &p_input->p->lock_control );
1488 static void ControlRelease( int i_type, vlc_value_t val )
1492 case INPUT_CONTROL_ADD_SUBTITLE:
1493 case INPUT_CONTROL_ADD_SLAVE:
1494 free( val.psz_string );
1503 static void ControlPause( input_thread_t *p_input, mtime_t i_control_date )
1505 int i_ret = VLC_SUCCESS;
1506 int i_state = PAUSE_S;
1508 if( p_input->p->b_can_pause )
1510 if( p_input->p->input.p_access )
1511 i_ret = access_Control( p_input->p->input.p_access,
1512 ACCESS_SET_PAUSE_STATE, true );
1514 i_ret = demux_Control( p_input->p->input.p_demux,
1515 DEMUX_SET_PAUSE_STATE, true );
1519 msg_Warn( p_input, "cannot set pause state" );
1520 i_state = p_input->p->i_state;
1527 i_ret = es_out_SetPauseState( p_input->p->p_es_out, p_input->p->b_can_pause, true, i_control_date );
1530 msg_Warn( p_input, "cannot set pause state at es_out level" );
1531 i_state = p_input->p->i_state;
1535 /* Switch to new state */
1536 input_ChangeState( p_input, i_state );
1540 static void ControlUnpause( input_thread_t *p_input, mtime_t i_control_date )
1542 int i_ret = VLC_SUCCESS;
1544 if( p_input->p->b_can_pause )
1546 if( p_input->p->input.p_access )
1547 i_ret = access_Control( p_input->p->input.p_access,
1548 ACCESS_SET_PAUSE_STATE, false );
1550 i_ret = demux_Control( p_input->p->input.p_demux,
1551 DEMUX_SET_PAUSE_STATE, false );
1554 /* FIXME What to do ? */
1555 msg_Warn( p_input, "cannot unset pause -> EOF" );
1556 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1560 /* Switch to play */
1561 input_ChangeState( p_input, PLAYING_S );
1565 es_out_SetPauseState( p_input->p->p_es_out, false, false, i_control_date );
1568 static bool Control( input_thread_t *p_input,
1569 int i_type, vlc_value_t val )
1571 const mtime_t i_control_date = mdate();
1572 /* FIXME b_force_update is abused, it should be carefully checked */
1573 bool b_force_update = false;
1576 return b_force_update;
1580 case INPUT_CONTROL_SET_DIE:
1581 msg_Dbg( p_input, "control: stopping input" );
1583 /* Mark all submodules to die */
1584 ObjectKillChildrens( p_input, VLC_OBJECT(p_input) );
1587 case INPUT_CONTROL_SET_POSITION:
1588 case INPUT_CONTROL_SET_POSITION_OFFSET:
1592 if( p_input->p->b_recording )
1594 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) ignored while recording" );
1597 f_pos = val.f_float;
1598 if( i_type != INPUT_CONTROL_SET_POSITION )
1599 f_pos += var_GetFloat( p_input, "position" );
1602 else if( f_pos > 1.0 )
1604 /* Reset the decoders states and clock sync (before calling the demuxer */
1605 es_out_SetTime( p_input->p->p_es_out, -1 );
1606 if( demux_Control( p_input->p->input.p_demux, DEMUX_SET_POSITION,
1607 f_pos, !p_input->p->b_fast_seek ) )
1609 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1610 "%2.1f%% failed", f_pos * 100 );
1614 if( p_input->p->i_slave > 0 )
1615 SlaveSeek( p_input );
1616 p_input->p->input.b_eof = false;
1618 b_force_update = true;
1623 case INPUT_CONTROL_SET_TIME:
1624 case INPUT_CONTROL_SET_TIME_OFFSET:
1629 if( p_input->p->b_recording )
1631 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) ignored while recording" );
1635 i_time = val.i_time;
1636 if( i_type != INPUT_CONTROL_SET_TIME )
1637 i_time += var_GetTime( p_input, "time" );
1642 /* Reset the decoders states and clock sync (before calling the demuxer */
1643 es_out_SetTime( p_input->p->p_es_out, -1 );
1645 i_ret = demux_Control( p_input->p->input.p_demux,
1646 DEMUX_SET_TIME, i_time,
1647 !p_input->p->b_fast_seek );
1652 /* Emulate it with a SET_POS */
1653 demux_Control( p_input->p->input.p_demux,
1654 DEMUX_GET_LENGTH, &i_length );
1657 double f_pos = (double)i_time / (double)i_length;
1658 i_ret = demux_Control( p_input->p->input.p_demux,
1659 DEMUX_SET_POSITION, f_pos,
1660 !p_input->p->b_fast_seek );
1665 msg_Warn( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) %"PRId64
1666 " failed or not possible", i_time );
1670 if( p_input->p->i_slave > 0 )
1671 SlaveSeek( p_input );
1672 p_input->p->input.b_eof = false;
1674 b_force_update = true;
1679 case INPUT_CONTROL_SET_STATE:
1680 if( ( val.i_int == PLAYING_S && p_input->p->i_state == PAUSE_S ) ||
1681 ( val.i_int == PAUSE_S && p_input->p->i_state == PAUSE_S ) )
1683 ControlUnpause( p_input, i_control_date );
1685 b_force_update = true;
1687 else if( val.i_int == PAUSE_S && p_input->p->i_state == PLAYING_S /* &&
1688 p_input->p->b_can_pause */ )
1690 ControlPause( p_input, i_control_date );
1692 b_force_update = true;
1694 else if( val.i_int == PAUSE_S && !p_input->p->b_can_pause && 0 )
1696 b_force_update = true;
1698 /* Correct "state" value */
1699 input_ChangeState( p_input, p_input->p->i_state );
1701 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1703 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1707 case INPUT_CONTROL_SET_RATE:
1708 case INPUT_CONTROL_SET_RATE_SLOWER:
1709 case INPUT_CONTROL_SET_RATE_FASTER:
1714 /* Get rate and direction */
1715 if( i_type == INPUT_CONTROL_SET_RATE )
1717 i_rate = abs( val.i_int );
1718 i_rate_sign = val.i_int < 0 ? -1 : 1;
1722 static const int ppi_factor[][2] = {
1723 {1,64}, {1,32}, {1,16}, {1,8}, {1,4}, {1,3}, {1,2}, {2,3},
1725 {3,2}, {2,1}, {3,1}, {4,1}, {8,1}, {16,1}, {32,1}, {64,1},
1732 i_rate_sign = p_input->p->i_rate < 0 ? -1 : 1;
1736 for( i = 0; ppi_factor[i][0] != 0; i++ )
1738 const int i_test_r = INPUT_RATE_DEFAULT * ppi_factor[i][0] / ppi_factor[i][1];
1739 const int i_test_e = abs( abs( p_input->p->i_rate ) - i_test_r );
1740 if( i_test_e < i_error )
1747 assert( i_idx >= 0 && ppi_factor[i_idx][0] != 0 );
1749 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1751 if( ppi_factor[i_idx+1][0] > 0 )
1752 i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx+1][0] / ppi_factor[i_idx+1][1];
1754 i_rate = INPUT_RATE_MAX+1;
1758 assert( i_type == INPUT_CONTROL_SET_RATE_FASTER );
1760 i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx-1][0] / ppi_factor[i_idx-1][1];
1762 i_rate = INPUT_RATE_MIN-1;
1766 /* Check rate bound */
1767 if( i_rate < INPUT_RATE_MIN )
1769 msg_Dbg( p_input, "cannot set rate faster" );
1770 i_rate = INPUT_RATE_MIN;
1772 else if( i_rate > INPUT_RATE_MAX )
1774 msg_Dbg( p_input, "cannot set rate slower" );
1775 i_rate = INPUT_RATE_MAX;
1778 /* Apply direction */
1779 if( i_rate_sign < 0 )
1781 if( p_input->p->input.b_rescale_ts )
1783 msg_Dbg( p_input, "cannot set negative rate" );
1784 i_rate = p_input->p->i_rate;
1785 assert( i_rate > 0 );
1789 i_rate *= i_rate_sign;
1793 if( i_rate != INPUT_RATE_DEFAULT &&
1794 ( ( !p_input->p->b_can_rate_control && !p_input->p->input.b_rescale_ts ) ||
1795 ( p_input->p->p_sout && !p_input->p->b_out_pace_control ) ) )
1797 msg_Dbg( p_input, "cannot change rate" );
1798 i_rate = INPUT_RATE_DEFAULT;
1800 if( i_rate != p_input->p->i_rate &&
1801 !p_input->p->b_can_pace_control && p_input->p->b_can_rate_control )
1804 if( p_input->p->input.p_access )
1806 i_ret = VLC_EGENERIC;
1810 if( !p_input->p->input.b_rescale_ts )
1811 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1813 i_ret = demux_Control( p_input->p->input.p_demux,
1814 DEMUX_SET_RATE, &i_rate );
1818 msg_Warn( p_input, "ACCESS/DEMUX_SET_RATE failed" );
1819 i_rate = p_input->p->i_rate;
1824 if( i_rate != p_input->p->i_rate )
1826 p_input->p->i_rate = i_rate;
1827 input_SendEventRate( p_input, i_rate );
1829 if( p_input->p->input.b_rescale_ts )
1831 const int i_rate_source = (p_input->p->b_can_pace_control || p_input->p->b_can_rate_control ) ? i_rate : INPUT_RATE_DEFAULT;
1832 es_out_SetRate( p_input->p->p_es_out, i_rate_source, i_rate );
1835 b_force_update = true;
1840 case INPUT_CONTROL_SET_PROGRAM:
1841 /* No need to force update, es_out does it if needed */
1842 es_out_Control( p_input->p->p_es_out,
1843 ES_OUT_SET_GROUP, val.i_int );
1845 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1849 case INPUT_CONTROL_SET_ES:
1850 /* No need to force update, es_out does it if needed */
1851 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, val.i_int );
1854 case INPUT_CONTROL_RESTART_ES:
1855 es_out_Control( p_input->p->p_es_out_display, ES_OUT_RESTART_ES_BY_ID, val.i_int );
1858 case INPUT_CONTROL_SET_AUDIO_DELAY:
1859 if( !es_out_SetDelay( p_input->p->p_es_out_display, AUDIO_ES, val.i_time ) )
1861 input_SendEventAudioDelay( p_input, val.i_time );
1862 UpdatePtsDelay( p_input );
1866 case INPUT_CONTROL_SET_SPU_DELAY:
1867 if( !es_out_SetDelay( p_input->p->p_es_out_display, SPU_ES, val.i_time ) )
1869 input_SendEventSubtitleDelay( p_input, val.i_time );
1870 UpdatePtsDelay( p_input );
1874 case INPUT_CONTROL_SET_TITLE:
1875 case INPUT_CONTROL_SET_TITLE_NEXT:
1876 case INPUT_CONTROL_SET_TITLE_PREV:
1877 if( p_input->p->b_recording )
1879 msg_Err( p_input, "INPUT_CONTROL_SET_TITLE(*) ignored while recording" );
1882 if( p_input->p->input.b_title_demux &&
1883 p_input->p->input.i_title > 0 )
1886 /* FIXME handle demux title */
1887 demux_t *p_demux = p_input->p->input.p_demux;
1890 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1891 i_title = p_demux->info.i_title - 1;
1892 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1893 i_title = p_demux->info.i_title + 1;
1895 i_title = val.i_int;
1897 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1899 es_out_SetTime( p_input->p->p_es_out, -1 );
1901 demux_Control( p_demux, DEMUX_SET_TITLE, i_title );
1902 input_SendEventTitle( p_input, i_title );
1905 else if( p_input->p->input.i_title > 0 )
1907 access_t *p_access = p_input->p->input.p_access;
1910 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1911 i_title = p_access->info.i_title - 1;
1912 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1913 i_title = p_access->info.i_title + 1;
1915 i_title = val.i_int;
1917 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1919 es_out_SetTime( p_input->p->p_es_out, -1 );
1921 stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
1922 ACCESS_SET_TITLE, i_title );
1923 input_SendEventTitle( p_input, i_title );
1927 case INPUT_CONTROL_SET_SEEKPOINT:
1928 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1929 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1930 if( p_input->p->b_recording )
1932 msg_Err( p_input, "INPUT_CONTROL_SET_SEEKPOINT(*) ignored while recording" );
1936 if( p_input->p->input.b_title_demux &&
1937 p_input->p->input.i_title > 0 )
1939 demux_t *p_demux = p_input->p->input.p_demux;
1941 int64_t i_input_time;
1942 int64_t i_seekpoint_time;
1944 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1946 i_seekpoint = p_demux->info.i_seekpoint;
1947 i_seekpoint_time = p_input->p->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1948 i_input_time = var_GetTime( p_input, "time" );
1949 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
1951 if( i_input_time < i_seekpoint_time + 3000000 )
1957 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1958 i_seekpoint = p_demux->info.i_seekpoint + 1;
1960 i_seekpoint = val.i_int;
1962 if( i_seekpoint >= 0 && i_seekpoint <
1963 p_input->p->input.title[p_demux->info.i_title]->i_seekpoint )
1966 es_out_SetTime( p_input->p->p_es_out, -1 );
1968 demux_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1969 input_SendEventSeekpoint( p_input, p_demux->info.i_title, i_seekpoint );
1972 else if( p_input->p->input.i_title > 0 )
1974 access_t *p_access = p_input->p->input.p_access;
1976 int64_t i_input_time;
1977 int64_t i_seekpoint_time;
1979 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1981 i_seekpoint = p_access->info.i_seekpoint;
1982 i_seekpoint_time = p_input->p->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1983 i_input_time = var_GetTime( p_input, "time" );
1984 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
1986 if( i_input_time < i_seekpoint_time + 3000000 )
1992 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1993 i_seekpoint = p_access->info.i_seekpoint + 1;
1995 i_seekpoint = val.i_int;
1997 if( i_seekpoint >= 0 && i_seekpoint <
1998 p_input->p->input.title[p_access->info.i_title]->i_seekpoint )
2000 es_out_SetTime( p_input->p->p_es_out, -1 );
2002 stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
2003 ACCESS_SET_SEEKPOINT, i_seekpoint );
2004 input_SendEventSeekpoint( p_input, p_access->info.i_title, i_seekpoint );
2009 case INPUT_CONTROL_ADD_SUBTITLE:
2010 if( val.psz_string )
2011 SubtitleAdd( p_input, val.psz_string, true );
2014 case INPUT_CONTROL_ADD_SLAVE:
2015 if( val.psz_string )
2017 input_source_t *slave = InputSourceNew( p_input );
2019 if( slave && !InputSourceInit( p_input, slave, val.psz_string, NULL ) )
2025 msg_Dbg( p_input, "adding %s as slave on the fly",
2029 if( demux_Control( p_input->p->input.p_demux,
2030 DEMUX_GET_TIME, &i_time ) )
2032 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2033 InputSourceClean( slave );
2037 if( demux_Control( slave->p_demux,
2038 DEMUX_SET_TIME, i_time, true ) )
2040 msg_Err( p_input, "seek failed for new slave" );
2041 InputSourceClean( slave );
2046 /* Get meta (access and demux) */
2047 p_meta = vlc_meta_New();
2050 access_Control( slave->p_access, ACCESS_GET_META, p_meta );
2051 demux_Control( slave->p_demux, DEMUX_GET_META, p_meta );
2052 InputUpdateMeta( p_input, p_meta );
2055 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, slave );
2060 msg_Warn( p_input, "failed to add %s as slave",
2066 case INPUT_CONTROL_SET_RECORD_STATE:
2067 if( !!p_input->p->b_recording != !!val.b_bool )
2069 if( p_input->p->input.b_can_stream_record )
2071 if( demux_Control( p_input->p->input.p_demux,
2072 DEMUX_SET_RECORD_STATE, val.b_bool ) )
2077 if( es_out_SetRecordState( p_input->p->p_es_out_display, val.b_bool ) )
2080 p_input->p->b_recording = val.b_bool;
2082 input_SendEventRecord( p_input, val.b_bool );
2084 b_force_update = true;
2088 case INPUT_CONTROL_SET_FRAME_NEXT:
2089 if( p_input->p->i_state == PAUSE_S )
2091 es_out_SetFrameNext( p_input->p->p_es_out );
2093 else if( p_input->p->i_state == PLAYING_S )
2095 ControlPause( p_input, i_control_date );
2099 msg_Err( p_input, "invalid state for frame next" );
2101 b_force_update = true;
2104 case INPUT_CONTROL_SET_BOOKMARK:
2106 seekpoint_t bookmark;
2108 bookmark.i_time_offset = -1;
2109 bookmark.i_byte_offset = -1;
2111 vlc_mutex_lock( &p_input->p->p_item->lock );
2112 if( val.i_int >= 0 && val.i_int < p_input->p->i_bookmark )
2114 const seekpoint_t *p_bookmark = p_input->p->pp_bookmark[val.i_int];
2115 bookmark.i_time_offset = p_bookmark->i_time_offset;
2116 bookmark.i_byte_offset = p_bookmark->i_byte_offset;
2118 vlc_mutex_unlock( &p_input->p->p_item->lock );
2120 if( bookmark.i_time_offset < 0 && bookmark.i_byte_offset < 0 )
2122 msg_Err( p_input, "invalid bookmark %d", val.i_int );
2126 if( bookmark.i_time_offset >= 0 )
2128 val.i_time = bookmark.i_time_offset;
2129 b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME, val );
2131 else if( bookmark.i_byte_offset >= 0 &&
2132 p_input->p->input.p_stream )
2134 const int64_t i_size = stream_Size( p_input->p->input.p_stream );
2135 if( i_size > 0 && bookmark.i_byte_offset <= i_size )
2137 val.f_float = (double)bookmark.i_byte_offset / i_size;
2138 b_force_update = Control( p_input, INPUT_CONTROL_SET_POSITION, val );
2145 msg_Err( p_input, "not yet implemented" );
2149 ControlRelease( i_type, val );
2150 return b_force_update;
2153 /*****************************************************************************
2154 * UpdateTitleSeekpoint
2155 *****************************************************************************/
2156 static int UpdateTitleSeekpoint( input_thread_t *p_input,
2157 int i_title, int i_seekpoint )
2159 int i_title_end = p_input->p->input.i_title_end -
2160 p_input->p->input.i_title_offset;
2161 int i_seekpoint_end = p_input->p->input.i_seekpoint_end -
2162 p_input->p->input.i_seekpoint_offset;
2164 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
2166 if( i_title > i_title_end ||
2167 ( i_title == i_title_end && i_seekpoint > i_seekpoint_end ) )
2170 else if( i_seekpoint_end >= 0 )
2172 if( i_seekpoint > i_seekpoint_end )
2175 else if( i_title_end >= 0 )
2177 if( i_title > i_title_end )
2182 /*****************************************************************************
2184 *****************************************************************************/
2185 static int UpdateTitleSeekpointFromDemux( input_thread_t *p_input )
2187 demux_t *p_demux = p_input->p->input.p_demux;
2189 /* TODO event-like */
2190 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
2192 input_SendEventTitle( p_input, p_demux->info.i_title );
2194 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
2196 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
2198 input_SendEventSeekpoint( p_input,
2199 p_demux->info.i_title, p_demux->info.i_seekpoint );
2201 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2204 /* Hmmm only works with master input */
2205 if( p_input->p->input.p_demux == p_demux )
2206 return UpdateTitleSeekpoint( p_input,
2207 p_demux->info.i_title,
2208 p_demux->info.i_seekpoint );
2212 static void UpdateGenericFromDemux( input_thread_t *p_input )
2214 demux_t *p_demux = p_input->p->input.p_demux;
2216 if( p_demux->info.i_update & INPUT_UPDATE_META )
2218 vlc_meta_t *p_meta = vlc_meta_New();
2221 demux_Control( p_input->p->input.p_demux, DEMUX_GET_META, p_meta );
2222 InputUpdateMeta( p_input, p_meta );
2224 p_demux->info.i_update &= ~INPUT_UPDATE_META;
2227 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
2231 /*****************************************************************************
2232 * Update*FromAccess:
2233 *****************************************************************************/
2234 static int UpdateTitleSeekpointFromAccess( input_thread_t *p_input )
2236 access_t *p_access = p_input->p->input.p_access;
2238 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
2240 input_SendEventTitle( p_input, p_access->info.i_title );
2242 stream_Control( p_input->p->input.p_stream, STREAM_UPDATE_SIZE );
2244 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
2246 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
2248 input_SendEventSeekpoint( p_input,
2249 p_access->info.i_title, p_access->info.i_seekpoint );
2251 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2253 /* Hmmm only works with master input */
2254 if( p_input->p->input.p_access == p_access )
2255 return UpdateTitleSeekpoint( p_input,
2256 p_access->info.i_title,
2257 p_access->info.i_seekpoint );
2260 static void UpdateGenericFromAccess( input_thread_t *p_input )
2262 access_t *p_access = p_input->p->input.p_access;
2264 if( p_access->info.i_update & INPUT_UPDATE_META )
2266 /* TODO maybe multi - access ? */
2267 vlc_meta_t *p_meta = vlc_meta_New();
2270 access_Control( p_input->p->input.p_access, ACCESS_GET_META, p_meta );
2271 InputUpdateMeta( p_input, p_meta );
2273 p_access->info.i_update &= ~INPUT_UPDATE_META;
2275 if( p_access->info.i_update & INPUT_UPDATE_SIGNAL )
2280 if( access_Control( p_access, ACCESS_GET_SIGNAL, &f_quality, &f_strength ) )
2281 f_quality = f_strength = -1;
2283 input_SendEventSignal( p_input, f_quality, f_strength );
2285 p_access->info.i_update &= ~INPUT_UPDATE_SIGNAL;
2288 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
2291 /*****************************************************************************
2293 *****************************************************************************/
2294 static input_source_t *InputSourceNew( input_thread_t *p_input )
2296 VLC_UNUSED(p_input);
2298 return calloc( 1, sizeof( input_source_t ) );
2301 /*****************************************************************************
2303 *****************************************************************************/
2304 static int InputSourceInit( input_thread_t *p_input,
2305 input_source_t *in, const char *psz_mrl,
2306 const char *psz_forced_demux )
2308 const char *psz_access;
2309 const char *psz_demux;
2313 char *psz_dup = strdup( psz_mrl );
2315 if( psz_dup == NULL )
2319 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_dup );
2321 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
2322 psz_mrl, psz_access, psz_demux, psz_path );
2323 if( !p_input->b_preparsing )
2325 /* Hack to allow udp://@:port syntax */
2327 (strncmp( psz_access, "udp", 3 ) &&
2328 strncmp( psz_access, "rtp", 3 )) )
2330 /* Find optional titles and seekpoints */
2331 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
2332 &in->i_seekpoint_start, &in->i_seekpoint_end );
2335 if( psz_forced_demux && *psz_forced_demux )
2337 psz_demux = psz_forced_demux;
2339 else if( *psz_demux == '\0' )
2341 /* special hack for forcing a demuxer with --demux=module
2342 * (and do nothing with a list) */
2343 char *psz_var_demux = var_GetNonEmptyString( p_input, "demux" );
2345 if( psz_var_demux != NULL &&
2346 !strchr(psz_var_demux, ',' ) &&
2347 !strchr(psz_var_demux, ':' ) )
2349 psz_demux = psz_var_demux;
2351 msg_Dbg( p_input, "enforced demux ` %s'", psz_demux );
2355 /* Try access_demux first */
2356 in->p_demux = demux_New( p_input, psz_access, psz_demux, psz_path,
2357 NULL, p_input->p->p_es_out, false );
2361 /* Preparsing is only for file:// */
2364 if( !*psz_access ) /* path without scheme:// */
2365 psz_access = "file";
2366 if( strcmp( psz_access, "file" ) )
2368 msg_Dbg( p_input, "trying to pre-parse %s", psz_path );
2373 /* Get infos from access_demux */
2374 demux_Control( in->p_demux,
2375 DEMUX_GET_PTS_DELAY, &in->i_pts_delay );
2376 in->i_pts_delay = __MAX( 0, __MIN( in->i_pts_delay, INPUT_PTS_DELAY_MAX ) );
2379 in->b_title_demux = true;
2380 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2381 &in->title, &in->i_title,
2382 &in->i_title_offset, &in->i_seekpoint_offset ) )
2384 TAB_INIT( in->i_title, in->title );
2386 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
2387 &in->b_can_pace_control ) )
2388 in->b_can_pace_control = false;
2390 if( !in->b_can_pace_control )
2392 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_RATE,
2393 &in->b_can_rate_control, &in->b_rescale_ts ) )
2395 in->b_can_rate_control = false;
2396 in->b_rescale_ts = true; /* not used */
2401 in->b_can_rate_control = true;
2402 in->b_rescale_ts = true;
2404 if( demux_Control( in->p_demux, DEMUX_CAN_PAUSE,
2405 &in->b_can_pause ) )
2406 in->b_can_pause = false;
2407 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2408 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2409 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control );
2412 if( demux_Control( in->p_demux, DEMUX_CAN_SEEK, &b_can_seek ) )
2414 var_SetBool( p_input, "can-seek", b_can_seek );
2418 /* Now try a real access */
2419 in->p_access = access_New( p_input, psz_access, psz_demux, psz_path );
2421 /* Access failed, URL encoded ? */
2422 if( in->p_access == NULL && strchr( psz_path, '%' ) )
2424 decode_URI( psz_path );
2426 msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
2427 psz_access, psz_demux, psz_path );
2429 in->p_access = access_New( p_input,
2430 psz_access, psz_demux, psz_path );
2432 if( in->p_access == NULL )
2434 msg_Err( p_input, "open of `%s' failed: %s", psz_mrl,
2436 dialog_Fatal( p_input, _("Your input can't be opened"),
2437 _("VLC is unable to open the MRL '%s'."
2438 " Check the log for details."), psz_mrl );
2442 /* Get infos from access */
2443 if( !p_input->b_preparsing )
2446 access_Control( in->p_access,
2447 ACCESS_GET_PTS_DELAY, &in->i_pts_delay );
2448 in->i_pts_delay = __MAX( 0, __MIN( in->i_pts_delay, INPUT_PTS_DELAY_MAX ) );
2450 in->b_title_demux = false;
2451 if( access_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2452 &in->title, &in->i_title,
2453 &in->i_title_offset, &in->i_seekpoint_offset ) )
2456 TAB_INIT( in->i_title, in->title );
2458 access_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2459 &in->b_can_pace_control );
2460 in->b_can_rate_control = in->b_can_pace_control;
2461 in->b_rescale_ts = true;
2463 access_Control( in->p_access, ACCESS_CAN_PAUSE, &in->b_can_pause );
2464 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2465 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2466 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control );
2468 access_Control( in->p_access, ACCESS_CAN_SEEK, &b_can_seek );
2469 var_SetBool( p_input, "can-seek", b_can_seek );
2474 char **ppsz_input_list;
2476 TAB_INIT( i_input_list, ppsz_input_list );
2478 /* On master stream only, use input-list */
2479 if( &p_input->p->input == in )
2485 psz_parser = var_CreateGetNonEmptyString( p_input, "input-list" );
2487 while( psz_parser && *psz_parser )
2489 char *p = strchr( psz_parser, ',' );
2495 char *psz_name = strdup( psz_parser );
2497 TAB_APPEND( i_input_list, ppsz_input_list, psz_name );
2504 /* Autodetect extra files if none specified */
2505 if( i_input_list <= 0 )
2507 InputGetExtraFiles( p_input, &i_input_list, &ppsz_input_list,
2508 psz_access, psz_path );
2510 if( i_input_list > 0 )
2511 TAB_APPEND( i_input_list, ppsz_input_list, NULL );
2513 /* Create the stream_t */
2514 in->p_stream = stream_AccessNew( in->p_access, ppsz_input_list );
2515 if( ppsz_input_list )
2517 for( int i = 0; ppsz_input_list[i] != NULL; i++ )
2518 free( ppsz_input_list[i] );
2519 TAB_CLEAN( i_input_list, ppsz_input_list );
2522 if( in->p_stream == NULL )
2524 msg_Warn( p_input, "cannot create a stream_t from access" );
2528 /* Add stream filters */
2529 char *psz_stream_filter = var_GetNonEmptyString( p_input,
2531 in->p_stream = stream_FilterChainNew( in->p_stream,
2533 var_GetBool( p_input, "input-record-native" ) );
2534 free( psz_stream_filter );
2536 /* Open a demuxer */
2537 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2539 psz_demux = in->p_access->psz_demux;
2543 /* Take access/stream redirections into account */
2544 char *psz_real_path;
2545 char *psz_buf = NULL;
2546 if( in->p_stream->psz_path )
2548 const char *psz_a, *psz_d;
2549 psz_buf = strdup( in->p_stream->psz_path );
2550 input_SplitMRL( &psz_a, &psz_d, &psz_real_path, psz_buf );
2554 psz_real_path = psz_path;
2556 in->p_demux = demux_New( p_input, psz_access, psz_demux,
2558 in->p_stream, p_input->p->p_es_out,
2559 p_input->b_preparsing );
2563 if( in->p_demux == NULL )
2565 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2566 psz_access, psz_demux, psz_path );
2567 dialog_Fatal( VLC_OBJECT( p_input ),
2568 _("VLC can't recognize the input's format"),
2569 _("The format of '%s' cannot be detected. "
2570 "Have a look at the log for details."), psz_mrl );
2574 /* Get title from demux */
2575 if( !p_input->b_preparsing && in->i_title <= 0 )
2577 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2578 &in->title, &in->i_title,
2579 &in->i_title_offset, &in->i_seekpoint_offset ))
2581 TAB_INIT( in->i_title, in->title );
2585 in->b_title_demux = true;
2592 /* Set record capabilities */
2593 if( demux_Control( in->p_demux, DEMUX_CAN_RECORD, &in->b_can_stream_record ) )
2594 in->b_can_stream_record = false;
2596 if( !var_GetBool( p_input, "input-record-native" ) )
2597 in->b_can_stream_record = false;
2598 var_SetBool( p_input, "can-record", true );
2600 var_SetBool( p_input, "can-record", in->b_can_stream_record );
2604 * FIXME improve for b_preparsing: move it after GET_META and check psz_arturl */
2605 if( 1 || !p_input->b_preparsing )
2608 input_attachment_t **attachment;
2609 if( !demux_Control( in->p_demux, DEMUX_GET_ATTACHMENTS,
2610 &attachment, &i_attachment ) )
2612 vlc_mutex_lock( &p_input->p->p_item->lock );
2613 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2614 i_attachment, attachment );
2615 vlc_mutex_unlock( &p_input->p->p_item->lock );
2618 if( !demux_Control( in->p_demux, DEMUX_GET_FPS, &f_fps ) && f_fps > 0.0 )
2620 vlc_mutex_lock( &p_input->p->p_item->lock );
2621 p_input->p->f_fps = f_fps;
2622 vlc_mutex_unlock( &p_input->p->p_item->lock );
2625 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2626 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2632 demux_Delete( in->p_demux );
2635 stream_Delete( in->p_stream );
2638 access_Delete( in->p_access );
2641 return VLC_EGENERIC;
2644 /*****************************************************************************
2646 *****************************************************************************/
2647 static void InputSourceClean( input_source_t *in )
2652 demux_Delete( in->p_demux );
2655 stream_Delete( in->p_stream );
2658 access_Delete( in->p_access );
2660 if( in->i_title > 0 )
2662 for( i = 0; i < in->i_title; i++ )
2663 vlc_input_title_Delete( in->title[i] );
2664 TAB_CLEAN( in->i_title, in->title );
2668 /*****************************************************************************
2670 *****************************************************************************/
2671 static void InputSourceMeta( input_thread_t *p_input,
2672 input_source_t *p_source, vlc_meta_t *p_meta )
2674 access_t *p_access = p_source->p_access;
2675 demux_t *p_demux = p_source->p_demux;
2677 /* XXX Remember that checking against p_item->p_meta->i_status & ITEM_PREPARSED
2680 /* Read access meta */
2682 access_Control( p_access, ACCESS_GET_META, p_meta );
2684 /* Read demux meta */
2685 demux_Control( p_demux, DEMUX_GET_META, p_meta );
2687 /* If the demux report unsupported meta data, try an external "meta reader" */
2689 if( demux_Control( p_demux, DEMUX_HAS_UNSUPPORTED_META, &b_bool ) )
2694 demux_meta_t *p_demux_meta = p_demux->p_private = calloc( 1, sizeof(*p_demux_meta) );
2698 module_t *p_id3 = module_need( p_demux, "meta reader", NULL, false );
2701 if( p_demux_meta->p_meta )
2703 vlc_meta_Merge( p_meta, p_demux_meta->p_meta );
2704 vlc_meta_Delete( p_demux_meta->p_meta );
2707 if( p_demux_meta->i_attachments > 0 )
2709 vlc_mutex_lock( &p_input->p->p_item->lock );
2710 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2711 p_demux_meta->i_attachments, p_demux_meta->attachments );
2712 vlc_mutex_unlock( &p_input->p->p_item->lock );
2714 module_unneed( p_demux, p_id3 );
2716 free( p_demux_meta );
2720 static void SlaveDemux( input_thread_t *p_input )
2725 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2727 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2731 for( i = 0; i < p_input->p->i_slave; i++ )
2733 input_source_t *in = p_input->p->slave[i];
2739 if( demux_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2744 if( demux_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2746 msg_Err( p_input, "slave[%d] doesn't like "
2747 "DEMUX_GET_TIME -> EOF", i );
2752 if( i_stime >= i_time )
2755 if( ( i_ret = demux_Demux( in->p_demux ) ) <= 0 )
2761 i_ret = demux_Demux( in->p_demux );
2766 msg_Dbg( p_input, "slave %d EOF", i );
2772 static void SlaveSeek( input_thread_t *p_input )
2777 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2779 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2783 for( i = 0; i < p_input->p->i_slave; i++ )
2785 input_source_t *in = p_input->p->slave[i];
2787 if( demux_Control( in->p_demux, DEMUX_SET_TIME, i_time, true ) )
2790 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2800 /*****************************************************************************
2802 *****************************************************************************/
2803 static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta )
2805 static const struct { int i_meta; const char *psz_name; } p_list[] = {
2806 { vlc_meta_Title, "meta-title" },
2807 { vlc_meta_Artist, "meta-artist" },
2808 { vlc_meta_Genre, "meta-genre" },
2809 { vlc_meta_Copyright, "meta-copyright" },
2810 { vlc_meta_Description, "meta-description" },
2811 { vlc_meta_Date, "meta-date" },
2812 { vlc_meta_URL, "meta-url" },
2816 /* Get meta information from user */
2817 for( int i = 0; p_list[i].psz_name; i++ )
2819 char *psz_string = var_GetNonEmptyString( p_input, p_list[i].psz_name );
2823 EnsureUTF8( psz_string );
2824 vlc_meta_Set( p_meta, p_list[i].i_meta, psz_string );
2829 /*****************************************************************************
2830 * InputUpdateMeta: merge p_item meta data with p_meta taking care of
2831 * arturl and locking issue.
2832 *****************************************************************************/
2833 static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta )
2835 input_item_t *p_item = p_input->p->p_item;
2837 char *psz_title = NULL;
2838 char *psz_arturl = input_item_GetArtURL( p_item );
2840 vlc_mutex_lock( &p_item->lock );
2842 if( vlc_meta_Get( p_meta, vlc_meta_Title ) && !p_item->b_fixed_name )
2843 psz_title = strdup( vlc_meta_Get( p_meta, vlc_meta_Title ) );
2845 vlc_meta_Merge( p_item->p_meta, p_meta );
2847 vlc_meta_Delete( p_meta );
2849 if( !psz_arturl || *psz_arturl == '\0' )
2851 const char *psz_tmp = vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL );
2853 psz_arturl = strdup( psz_tmp );
2855 vlc_mutex_unlock( &p_item->lock );
2857 if( psz_arturl && *psz_arturl )
2859 input_item_SetArtURL( p_item, psz_arturl );
2861 if( !strncmp( psz_arturl, "attachment://", strlen("attachment") ) )
2863 /* Don't look for art cover if sout
2864 * XXX It can change when sout has meta data support */
2865 if( p_input->p->p_sout && !p_input->b_preparsing )
2866 input_item_SetArtURL( p_item, "" );
2868 input_ExtractAttachmentAndCacheArt( p_input );
2875 input_item_SetName( p_item, psz_title );
2878 input_item_SetPreparsed( p_item, true );
2880 input_SendEventMeta( p_input );
2882 /** \todo handle sout meta */
2885 static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
2886 int i_new, input_attachment_t **pp_new )
2888 int i_attachment = *pi_attachment;
2889 input_attachment_t **attachment = *ppp_attachment;
2892 attachment = realloc( attachment,
2893 sizeof(input_attachment_t**) * ( i_attachment + i_new ) );
2894 for( i = 0; i < i_new; i++ )
2895 attachment[i_attachment++] = pp_new[i];
2899 *pi_attachment = i_attachment;
2900 *ppp_attachment = attachment;
2902 /*****************************************************************************
2903 * InputGetExtraFiles
2904 * Autodetect extra input list
2905 *****************************************************************************/
2906 static void InputGetExtraFilesPattern( input_thread_t *p_input,
2907 int *pi_list, char ***pppsz_list,
2908 const char *psz_path,
2909 const char *psz_match,
2910 const char *psz_format,
2911 int i_start, int i_stop )
2916 TAB_INIT( i_list, ppsz_list );
2918 char *psz_base = strdup( psz_path );
2922 /* Remove the extension */
2923 char *psz_end = &psz_base[strlen(psz_base)-strlen(psz_match)];
2924 assert( psz_end >= psz_base);
2927 /* Try to list files */
2928 for( int i = i_start; i <= i_stop; i++ )
2933 if( asprintf( &psz_file, psz_format, psz_base, i ) < 0 )
2936 if( utf8_stat( psz_file, &st ) || !S_ISREG( st.st_mode ) || !st.st_size )
2942 msg_Dbg( p_input, "Detected extra file `%s'", psz_file );
2943 TAB_APPEND( i_list, ppsz_list, psz_file );
2948 *pppsz_list = ppsz_list;
2951 static void InputGetExtraFiles( input_thread_t *p_input,
2952 int *pi_list, char ***pppsz_list,
2953 const char *psz_access, const char *psz_path )
2957 const char *psz_match;
2958 const char *psz_format;
2962 /* XXX the order is important */
2963 { ".001", "%s.%.3d", 2, 999 },
2964 { ".part1.rar", "%s.part%.1d.rar",2, 9 },
2965 { ".part01.rar", "%s.part%.2d.rar",2, 99, },
2966 { ".part001.rar", "%s.part%.3d.rar",2, 999 },
2967 { ".rar", "%s.r%.2d", 1, 99 },
2968 { NULL, NULL, 0, 0 }
2971 TAB_INIT( *pi_list, *pppsz_list );
2973 if( ( psz_access && *psz_access && strcmp( psz_access, "file" ) ) || !psz_path )
2976 const size_t i_path = strlen(psz_path);
2978 for( int i = 0; p_pattern[i].psz_match != NULL; i++ )
2980 const size_t i_ext = strlen(p_pattern[i].psz_match );
2982 if( i_path < i_ext )
2984 if( !strcmp( &psz_path[i_path-i_ext], p_pattern[i].psz_match ) )
2986 InputGetExtraFilesPattern( p_input, pi_list, pppsz_list,
2988 p_pattern[i].psz_match, p_pattern[i].psz_format,
2989 p_pattern[i].i_start, p_pattern[i].i_stop );
2996 static void input_ChangeState( input_thread_t *p_input, int i_state )
2998 const bool b_changed = p_input->p->i_state != i_state;
3000 p_input->p->i_state = i_state;
3001 if( i_state == ERROR_S )
3002 p_input->b_error = true;
3003 else if( i_state == END_S )
3004 p_input->b_eof = true;
3008 input_item_SetErrorWhenReading( p_input->p->p_item, p_input->b_error );
3009 input_SendEventState( p_input, i_state );
3014 /*****************************************************************************
3015 * MRLSplit: parse the access, demux and url part of the
3016 * Media Resource Locator.
3017 *****************************************************************************/
3018 void input_SplitMRL( const char **ppsz_access, const char **ppsz_demux, char **ppsz_path,
3021 char *psz_access = NULL;
3022 char *psz_demux = NULL;
3025 /* Either there is an access/demux specification before ://
3026 * or we have a plain local file path. */
3027 psz_path = strstr( psz_dup, "://" );
3028 if( psz_path != NULL )
3031 psz_path += 3; /* skips "://" */
3033 /* Separate access from demux (<access>/<demux>://<path>) */
3034 psz_access = psz_dup;
3035 psz_demux = strchr( psz_access, '/' );
3037 *psz_demux++ = '\0';
3039 /* We really don't want module name substitution here! */
3040 if( psz_access[0] == '$' )
3042 if( psz_demux && psz_demux[0] == '$' )
3049 *ppsz_access = psz_access ? psz_access : (char*)"";
3050 *ppsz_demux = psz_demux ? psz_demux : (char*)"";
3051 *ppsz_path = psz_path;
3054 static inline bool next(char ** src)
3058 long result = strtol( *src, &end, 0 );
3059 if( errno != 0 || result >= LONG_MAX || result <= LONG_MIN ||
3068 /*****************************************************************************
3069 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
3072 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
3073 *****************************************************************************/
3074 static void MRLSections( input_thread_t *p_input, char *psz_source,
3075 int *pi_title_start, int *pi_title_end,
3076 int *pi_chapter_start, int *pi_chapter_end )
3078 char *psz, *psz_end, *psz_next, *psz_check;
3080 *pi_title_start = *pi_title_end = -1;
3081 *pi_chapter_start = *pi_chapter_end = -1;
3083 /* Start by parsing titles and chapters */
3084 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
3087 /* Check we are really dealing with a title/chapter section */
3088 psz_check = psz + 1;
3089 if( !*psz_check ) return;
3090 if( isdigit(*psz_check) )
3091 if(!next(&psz_check)) return;
3092 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
3093 if( *psz_check == ':' && ++psz_check )
3095 if( isdigit(*psz_check) )
3096 if(!next(&psz_check)) return;
3098 if( *psz_check != '-' && *psz_check ) return;
3099 if( *psz_check == '-' && ++psz_check )
3101 if( isdigit(*psz_check) )
3102 if(!next(&psz_check)) return;
3104 if( *psz_check != ':' && *psz_check ) return;
3105 if( *psz_check == ':' && ++psz_check )
3107 if( isdigit(*psz_check) )
3108 if(!next(&psz_check)) return;
3110 if( *psz_check ) return;
3112 /* Separate start and end */
3114 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
3116 /* Look for the start title */
3117 *pi_title_start = strtol( psz, &psz_next, 0 );
3118 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
3119 *pi_title_end = *pi_title_start;
3122 /* Look for the start chapter */
3124 *pi_chapter_start = strtol( psz, &psz_next, 0 );
3125 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
3126 *pi_chapter_end = *pi_chapter_start;
3130 /* Look for the end title */
3131 *pi_title_end = strtol( psz_end, &psz_next, 0 );
3132 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
3135 /* Look for the end chapter */
3136 if( *psz_end ) psz_end++;
3137 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
3138 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
3141 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
3142 psz_source, *pi_title_start, *pi_chapter_start,
3143 *pi_title_end, *pi_chapter_end );
3146 /*****************************************************************************
3147 * input_AddSubtitles: add a subtitles file and enable it
3148 *****************************************************************************/
3149 static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_forced )
3151 input_source_t *sub;
3154 char *psz_path, *psz_extension;
3156 /* if we are provided a subtitle.sub file,
3157 * see if we don't have a subtitle.idx and use it instead */
3158 psz_path = strdup( psz_subtitle );
3161 psz_extension = strrchr( psz_path, '.');
3162 if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
3166 strcpy( psz_extension, ".idx" );
3168 if( !utf8_stat( psz_path, &st ) && S_ISREG( st.st_mode ) )
3170 msg_Dbg( p_input, "using %s subtitles file instead of %s",
3171 psz_path, psz_subtitle );
3172 strcpy( psz_subtitle, psz_path );
3178 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
3180 sub = InputSourceNew( p_input );
3181 if( !sub || InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
3186 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
3189 if( b_forced && !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
3191 if( count.i_int == 0 )
3193 /* if it was first one, there is disable too */
3195 if( count.i_int < list.p_list->i_count )
3197 const int i_id = list.p_list->p_values[count.i_int].i_int;
3199 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_DEFAULT_BY_ID, i_id );
3200 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, i_id );
3202 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
3206 /*****************************************************************************
3208 *****************************************************************************/
3209 void input_UpdateStatistic( input_thread_t *p_input,
3210 input_statistic_t i_type, int i_delta )
3212 assert( p_input->p->i_state != INIT_S );
3214 vlc_mutex_lock( &p_input->p->counters.counters_lock);
3217 #define I(c) stats_UpdateInteger( p_input, p_input->p->counters.c, i_delta, NULL )
3218 case INPUT_STATISTIC_DECODED_VIDEO:
3221 case INPUT_STATISTIC_DECODED_AUDIO:
3224 case INPUT_STATISTIC_DECODED_SUBTITLE:
3227 case INPUT_STATISTIC_SENT_PACKET:
3228 I(p_sout_sent_packets);
3231 case INPUT_STATISTIC_SENT_BYTE:
3233 int i_bytes; /* That's pretty stupid to define it as an integer, it will overflow
3235 if( !stats_UpdateInteger( p_input, p_input->p->counters.p_sout_sent_bytes, i_delta, &i_bytes ) )
3236 stats_UpdateFloat( p_input, p_input->p->counters.p_sout_send_bitrate, i_bytes, NULL );
3240 msg_Err( p_input, "Invalid statistic type %d (internal error)", i_type );
3243 vlc_mutex_unlock( &p_input->p->counters.counters_lock);
3247 /* TODO FIXME nearly the same logic that snapshot code */
3248 char *input_CreateFilename( vlc_object_t *p_obj, const char *psz_path, const char *psz_prefix, const char *psz_extension )
3253 path = utf8_opendir( psz_path );
3258 char *psz_tmp = str_format( p_obj, psz_prefix );
3262 char *psz_tmp2 = filename_sanitize( psz_tmp );
3266 asprintf( &psz_file, "%s"DIR_SEP"%s%s%s",
3268 psz_extension ? "." : "",
3269 psz_extension ? psz_extension : "" ) < 0 )
3276 psz_file = str_format( p_obj, psz_path );
3277 path_sanitize( psz_file );