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 /*****************************************************************************
114 * This function creates a new input, and returns a pointer
115 * to its description. On error, it returns NULL.
117 * XXX Do not forget to update vlc_input.h if you add new variables.
118 *****************************************************************************/
119 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
120 const char *psz_header, bool b_quick,
121 input_resource_t *p_resource )
123 static const char input_name[] = "input";
124 input_thread_t *p_input = NULL; /* thread descriptor */
127 /* Allocate descriptor */
128 p_input = vlc_custom_create( p_parent, sizeof( *p_input ),
129 VLC_OBJECT_INPUT, input_name );
130 if( p_input == NULL )
133 /* Construct a nice name for the input timer */
134 char psz_timer_name[255];
135 char * psz_name = input_item_GetName( p_item );
136 snprintf( psz_timer_name, sizeof(psz_timer_name),
137 "input launching for '%s'", psz_name );
139 msg_Dbg( p_input, "Creating an input for '%s'", psz_name);
143 /* Start a timer to mesure how long it takes
144 * to launch an input */
145 stats_TimerStart( p_input, psz_timer_name,
146 STATS_TIMER_INPUT_LAUNCHING );
148 p_input->p = calloc( 1, sizeof( input_thread_private_t ) );
152 p_input->b_preparsing = b_quick;
153 p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
155 /* Init Common fields */
156 p_input->b_eof = false;
157 p_input->p->b_can_pace_control = true;
158 p_input->p->i_start = 0;
159 p_input->p->i_time = 0;
160 p_input->p->i_stop = 0;
161 p_input->p->i_run = 0;
162 p_input->p->i_title = 0;
163 p_input->p->title = NULL;
164 p_input->p->i_title_offset = p_input->p->i_seekpoint_offset = 0;
165 p_input->p->i_state = INIT_S;
166 p_input->p->i_rate = INPUT_RATE_DEFAULT;
167 p_input->p->b_recording = false;
168 memset( &p_input->p->bookmark, 0, sizeof(p_input->p->bookmark) );
169 TAB_INIT( p_input->p->i_bookmark, p_input->p->pp_bookmark );
170 TAB_INIT( p_input->p->i_attachment, p_input->p->attachment );
171 p_input->p->p_es_out_display = NULL;
172 p_input->p->p_es_out = NULL;
173 p_input->p->p_sout = NULL;
174 p_input->p->b_out_pace_control = false;
176 vlc_gc_incref( p_item ); /* Released in Destructor() */
177 p_input->p->p_item = p_item;
179 /* Init Input fields */
180 p_input->p->input.p_access = NULL;
181 p_input->p->input.p_stream = NULL;
182 p_input->p->input.p_demux = NULL;
183 p_input->p->input.b_title_demux = false;
184 p_input->p->input.i_title = 0;
185 p_input->p->input.title = NULL;
186 p_input->p->input.i_title_offset = p_input->p->input.i_seekpoint_offset = 0;
187 p_input->p->input.b_can_pace_control = true;
188 p_input->p->input.b_can_rate_control = true;
189 p_input->p->input.b_rescale_ts = true;
190 p_input->p->input.b_eof = false;
192 vlc_mutex_lock( &p_item->lock );
194 if( !p_item->p_stats )
195 p_item->p_stats = stats_NewInputStats( p_input );
196 vlc_mutex_unlock( &p_item->lock );
199 p_input->p->i_slave = 0;
200 p_input->p->slave = NULL;
204 p_input->p->p_resource = p_resource;
206 p_input->p->p_resource = input_resource_New();
207 input_resource_SetInput( p_input->p->p_resource, p_input );
209 /* Init control buffer */
210 vlc_mutex_init( &p_input->p->lock_control );
211 vlc_cond_init( &p_input->p->wait_control );
212 p_input->p->i_control = 0;
213 p_input->p->b_abort = false;
215 /* Parse input options */
216 vlc_mutex_lock( &p_item->lock );
217 assert( (int)p_item->optflagc == p_item->i_options );
218 for( i = 0; i < p_item->i_options; i++ )
219 var_OptionParse( VLC_OBJECT(p_input), p_item->ppsz_options[i],
220 !!(p_item->optflagv[i] & VLC_INPUT_OPTION_TRUSTED) );
221 vlc_mutex_unlock( &p_item->lock );
223 /* Create Object Variables for private use only */
224 input_ConfigVarInit( p_input );
226 /* Create Objects variables for public Get and Set */
227 input_ControlVarInit( p_input );
230 if( !p_input->b_preparsing )
232 char *psz_bookmarks = var_GetNonEmptyString( p_input, "bookmarks" );
235 /* FIXME: have a common cfg parsing routine used by sout and others */
236 char *psz_parser, *psz_start, *psz_end;
237 psz_parser = psz_bookmarks;
238 while( (psz_start = strchr( psz_parser, '{' ) ) )
240 seekpoint_t *p_seekpoint;
243 psz_end = strchr( psz_start, '}' );
244 if( !psz_end ) break;
245 psz_parser = psz_end + 1;
246 backup = *psz_parser;
250 p_seekpoint = vlc_seekpoint_New();
251 while( (psz_end = strchr( psz_start, ',' ) ) )
254 if( !strncmp( psz_start, "name=", 5 ) )
256 p_seekpoint->psz_name = strdup(psz_start + 5);
258 else if( !strncmp( psz_start, "bytes=", 6 ) )
260 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
262 else if( !strncmp( psz_start, "time=", 5 ) )
264 p_seekpoint->i_time_offset = atoll(psz_start + 5) *
267 psz_start = psz_end + 1;
269 msg_Dbg( p_input, "adding bookmark: %s, bytes=%"PRId64", time=%"PRId64,
270 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
271 p_seekpoint->i_time_offset );
272 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
273 vlc_seekpoint_Delete( p_seekpoint );
274 *psz_parser = backup;
276 free( psz_bookmarks );
280 /* Remove 'Now playing' info as it is probably outdated */
281 input_item_SetNowPlaying( p_item, NULL );
282 input_SendEventMeta( p_input );
285 if( p_input->b_preparsing )
286 p_input->i_flags |= OBJECT_FLAGS_QUIET | OBJECT_FLAGS_NOINTERACT;
289 memset( &p_input->p->counters, 0, sizeof( p_input->p->counters ) );
290 vlc_mutex_init( &p_input->p->counters.counters_lock );
292 /* Set the destructor when we are sure we are initialized */
293 vlc_object_set_destructor( p_input, (vlc_destructor_t)Destructor );
295 /* Attach only once we are ready */
296 vlc_object_attach( p_input, p_parent );
302 * Input destructor (called when the object's refcount reaches 0).
304 static void Destructor( input_thread_t * p_input )
307 char * psz_name = input_item_GetName( p_input->p->p_item );
308 msg_Dbg( p_input, "Destroying the input for '%s'", psz_name);
312 stats_TimerDump( p_input, STATS_TIMER_INPUT_LAUNCHING );
313 stats_TimerClean( p_input, STATS_TIMER_INPUT_LAUNCHING );
315 if( p_input->p->p_resource )
316 input_resource_Delete( p_input->p->p_resource );
318 vlc_gc_decref( p_input->p->p_item );
320 vlc_mutex_destroy( &p_input->p->counters.counters_lock );
322 for( int i = 0; i < p_input->p->i_control; i++ )
324 input_control_t *p_ctrl = &p_input->p->control[i];
325 ControlRelease( p_ctrl->i_type, p_ctrl->val );
328 vlc_cond_destroy( &p_input->p->wait_control );
329 vlc_mutex_destroy( &p_input->p->lock_control );
334 * Initialize an input thread and run it. You will need to monitor the
335 * thread to clean up after it is done
337 * \param p_parent a vlc_object
338 * \param p_item an input item
339 * \return a pointer to the spawned input thread
341 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
342 input_item_t *p_item )
344 return __input_CreateThreadExtended( p_parent, p_item, NULL, NULL );
348 input_thread_t *__input_CreateThreadExtended( vlc_object_t *p_parent,
349 input_item_t *p_item,
350 const char *psz_log, input_resource_t *p_resource )
352 input_thread_t *p_input;
354 p_input = Create( p_parent, p_item, psz_log, false, p_resource );
358 /* Create thread and wait for its readiness. */
359 if( vlc_thread_create( p_input, "input", Run,
360 VLC_THREAD_PRIORITY_INPUT ) )
362 input_ChangeState( p_input, ERROR_S );
363 msg_Err( p_input, "cannot create input thread" );
364 vlc_object_detach( p_input );
365 vlc_object_release( p_input );
373 * Initialize an input thread and run it. This thread will clean after itself,
374 * you can forget about it. It can work either in blocking or non-blocking mode
376 * \param p_parent a vlc_object
377 * \param p_item an input item
378 * \param b_block should we block until read is finished ?
379 * \return an error code, VLC_SUCCESS on success
381 int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
384 input_thread_t *p_input;
386 p_input = Create( p_parent, p_item, NULL, false, NULL );
392 RunAndDestroy( VLC_OBJECT(p_input) );
397 if( vlc_thread_create( p_input, "input", RunAndDestroy,
398 VLC_THREAD_PRIORITY_INPUT ) )
400 input_ChangeState( p_input, ERROR_S );
401 msg_Err( p_input, "cannot create input thread" );
402 vlc_object_release( p_input );
410 * Initialize an input and initialize it to preparse the item
411 * This function is blocking. It will only accept parsing regular files.
413 * \param p_parent a vlc_object_t
414 * \param p_item an input item
415 * \return VLC_SUCCESS or an error
417 int input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
419 input_thread_t *p_input;
421 /* Allocate descriptor */
422 p_input = Create( p_parent, p_item, NULL, true, NULL );
426 if( !Init( p_input ) )
429 vlc_object_detach( p_input );
430 vlc_object_release( p_input );
436 * Request a running input thread to stop and die
438 * \param the input thread to stop
440 void input_StopThread( input_thread_t *p_input, bool b_abort )
442 /* Set die for input and ALL of this childrens (even (grand-)grand-childrens)
443 * It is needed here even if it is done in INPUT_CONTROL_SET_DIE handler to
444 * unlock the control loop */
445 ObjectKillChildrens( p_input, VLC_OBJECT(p_input) );
447 vlc_mutex_lock( &p_input->p->lock_control );
448 p_input->p->b_abort |= b_abort;
449 vlc_mutex_unlock( &p_input->p->lock_control );
451 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
454 input_resource_t *input_DetachResource( input_thread_t *p_input )
456 assert( p_input->b_dead );
458 input_resource_SetInput( p_input->p->p_resource, NULL );
460 input_resource_t *p_resource = input_resource_Detach( p_input->p->p_resource );
461 p_input->p->p_sout = NULL;
467 * Get the item from an input thread
468 * FIXME it does not increase ref count of the item.
469 * if it is used after p_input is destroyed nothing prevent it from
472 input_item_t *input_GetItem( input_thread_t *p_input )
474 assert( p_input && p_input->p );
475 return p_input->p->p_item;
478 /*****************************************************************************
479 * ObjectKillChildrens
480 *****************************************************************************/
481 static void ObjectKillChildrens( input_thread_t *p_input, vlc_object_t *p_obj )
486 /* FIXME ObjectKillChildrens seems a very bad idea in fact */
487 i = vlc_internals( p_obj )->i_object_type;
488 if( i == VLC_OBJECT_VOUT ||i == VLC_OBJECT_AOUT ||
489 p_obj == VLC_OBJECT(p_input->p->p_sout) ||
490 i == VLC_OBJECT_DECODER || i == VLC_OBJECT_PACKETIZER )
493 vlc_object_kill( p_obj );
495 p_list = vlc_list_children( p_obj );
496 for( i = 0; i < p_list->i_count; i++ )
497 ObjectKillChildrens( p_input, p_list->p_values[i].p_object );
498 vlc_list_release( p_list );
501 /*****************************************************************************
502 * Run: main thread loop
503 * This is the "normal" thread that spawns the input processing chain,
504 * reads the stream, cleans up and waits
505 *****************************************************************************/
506 static void *Run( vlc_object_t *p_this )
508 input_thread_t *p_input = (input_thread_t *)p_this;
509 const int canc = vlc_savecancel();
511 if( Init( p_input ) )
520 /* Tell we're dead */
521 vlc_mutex_lock( &p_input->p->lock_control );
522 const bool b_abort = p_input->p->b_abort;
523 vlc_mutex_unlock( &p_input->p->lock_control );
526 input_SendEventAbort( p_input );
527 input_SendEventDead( p_input );
529 vlc_restorecancel( canc );
533 /*****************************************************************************
534 * RunAndDestroy: main thread loop
535 * This is the "just forget me" thread that spawns the input processing chain,
536 * reads the stream, cleans up and releases memory
537 *****************************************************************************/
538 static void *RunAndDestroy( vlc_object_t *p_this )
540 input_thread_t *p_input = (input_thread_t *)p_this;
541 const int canc = vlc_savecancel();
543 if( Init( p_input ) )
553 vlc_object_release( p_input );
554 vlc_restorecancel( canc );
558 /*****************************************************************************
559 * Main loop: Fill buffers from access, and demux
560 *****************************************************************************/
564 * It asks the demuxer to demux some data
566 static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, mtime_t *pi_start_mdate )
572 if( ( p_input->p->i_stop > 0 && p_input->p->i_time >= p_input->p->i_stop ) ||
573 ( p_input->p->i_run > 0 && *pi_start_mdate+p_input->p->i_run < mdate() ) )
576 i_ret = demux_Demux( p_input->p->input.p_demux );
580 if( p_input->p->input.p_demux->info.i_update )
582 if( p_input->p->input.b_title_demux )
584 i_ret = UpdateTitleSeekpointFromDemux( p_input );
587 UpdateGenericFromDemux( p_input );
589 else if( p_input->p->input.p_access &&
590 p_input->p->input.p_access->info.i_update )
592 if( !p_input->p->input.b_title_demux )
594 i_ret = UpdateTitleSeekpointFromAccess( p_input );
597 UpdateGenericFromAccess( p_input );
601 if( i_ret == 0 ) /* EOF */
603 int i_repeat = var_GetInteger( p_input, "input-repeat" );
606 /* End of file - we do not set b_die because only the
607 * playlist is allowed to do so. */
608 msg_Dbg( p_input, "EOF reached" );
609 p_input->p->input.b_eof = true;
615 msg_Dbg( p_input, "repeating the same input (%d)", i_repeat );
619 var_SetInteger( p_input, "input-repeat", i_repeat );
622 /* Seek to start title/seekpoint */
623 val.i_int = p_input->p->input.i_title_start -
624 p_input->p->input.i_title_offset;
625 if( val.i_int < 0 || val.i_int >= p_input->p->input.i_title )
627 input_ControlPush( p_input,
628 INPUT_CONTROL_SET_TITLE, &val );
630 val.i_int = p_input->p->input.i_seekpoint_start -
631 p_input->p->input.i_seekpoint_offset;
632 if( val.i_int > 0 /* TODO: check upper boundary */ )
633 input_ControlPush( p_input,
634 INPUT_CONTROL_SET_SEEKPOINT, &val );
636 /* Seek to start position */
637 if( p_input->p->i_start > 0 )
639 val.i_time = p_input->p->i_start;
640 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
646 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
651 *pi_start_mdate = mdate();
656 input_ChangeState( p_input, ERROR_S );
659 if( i_ret > 0 && p_input->p->i_slave > 0 )
661 SlaveDemux( p_input );
667 * It update the variables used by the interfaces
669 static void MainLoopInterface( input_thread_t *p_input )
671 double f_position = 0.0;
673 mtime_t i_length = 0;
675 /* update input status variables */
676 if( demux_Control( p_input->p->input.p_demux,
677 DEMUX_GET_POSITION, &f_position ) )
680 if( demux_Control( p_input->p->input.p_demux,
681 DEMUX_GET_TIME, &i_time ) )
683 p_input->p->i_time = i_time;
685 if( demux_Control( p_input->p->input.p_demux,
686 DEMUX_GET_LENGTH, &i_length ) )
689 es_out_SetTimes( p_input->p->p_es_out, f_position, i_time, i_length );
691 /* update current bookmark */
692 vlc_mutex_lock( &p_input->p->p_item->lock );
693 p_input->p->bookmark.i_time_offset = i_time;
694 if( p_input->p->input.p_stream )
695 p_input->p->bookmark.i_byte_offset = stream_Tell( p_input->p->input.p_stream );
696 vlc_mutex_unlock( &p_input->p->p_item->lock );
701 * It updates the globals statics
703 static void MainLoopStatistic( input_thread_t *p_input )
705 stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
706 input_SendEventStatistics( p_input );
711 * The main input loop.
713 static void MainLoop( input_thread_t *p_input )
715 mtime_t i_start_mdate = mdate();
716 mtime_t i_intf_update = 0;
717 mtime_t i_statistic_update = 0;
719 /* Start the timer */
720 stats_TimerStop( p_input, STATS_TIMER_INPUT_LAUNCHING );
722 while( vlc_object_alive( p_input ) && !p_input->b_error )
733 b_force_update = false;
735 /* FIXME if p_input->p->i_state == PAUSE_S the access/access_demux
736 * is paused -> this may cause problem with some of them
737 * The same problem can be seen when seeking while paused */
738 b_paused = p_input->p->i_state == PAUSE_S &&
739 !es_out_GetBuffering( p_input->p->p_es_out );
743 if( !p_input->p->input.b_eof )
745 MainLoopDemux( p_input, &b_force_update, &i_start_mdate );
747 i_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
749 else if( !p_input->b_eof && !es_out_GetEmpty( p_input->p->p_es_out ) )
751 msg_Dbg( p_input, "waiting decoder fifos to empty" );
752 i_wakeup = mdate() + INPUT_IDLE_SLEEP;
762 i_deadline = i_wakeup;
764 i_deadline = __MIN( i_intf_update, i_statistic_update );
767 ControlReduce( p_input );
768 while( !ControlPop( p_input, &i_type, &val, i_deadline ) )
771 msg_Dbg( p_input, "control type=%d", i_type );
773 if( Control( p_input, i_type, val ) )
774 b_force_update = true;
777 /* Update interface and statistics */
779 if( i_intf_update < i_current || b_force_update )
781 MainLoopInterface( p_input );
782 i_intf_update = i_current + INT64_C(250000);
783 b_force_update = false;
785 if( i_statistic_update < i_current )
787 MainLoopStatistic( p_input );
788 i_statistic_update = i_current + INT64_C(1000000);
791 /* Check if i_wakeup is still valid */
794 mtime_t i_new_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
798 } while( i_current < i_wakeup );
801 if( !p_input->b_error )
802 input_ChangeState( p_input, END_S );
805 static void InitStatistics( input_thread_t * p_input )
807 if( p_input->b_preparsing ) return;
809 /* Prepare statistics */
810 #define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \
811 stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
812 if( libvlc_stats( p_input ) )
814 INIT_COUNTER( read_bytes, INTEGER, COUNTER );
815 INIT_COUNTER( read_packets, INTEGER, COUNTER );
816 INIT_COUNTER( demux_read, INTEGER, COUNTER );
817 INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE );
818 INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE );
819 INIT_COUNTER( demux_corrupted, INTEGER, COUNTER );
820 INIT_COUNTER( demux_discontinuity, INTEGER, COUNTER );
821 INIT_COUNTER( played_abuffers, INTEGER, COUNTER );
822 INIT_COUNTER( lost_abuffers, INTEGER, COUNTER );
823 INIT_COUNTER( displayed_pictures, INTEGER, COUNTER );
824 INIT_COUNTER( lost_pictures, INTEGER, COUNTER );
825 INIT_COUNTER( decoded_audio, INTEGER, COUNTER );
826 INIT_COUNTER( decoded_video, INTEGER, COUNTER );
827 INIT_COUNTER( decoded_sub, INTEGER, COUNTER );
828 p_input->p->counters.p_sout_send_bitrate = NULL;
829 p_input->p->counters.p_sout_sent_packets = NULL;
830 p_input->p->counters.p_sout_sent_bytes = NULL;
831 if( p_input->p->counters.p_demux_bitrate )
832 p_input->p->counters.p_demux_bitrate->update_interval = 1000000;
833 if( p_input->p->counters.p_input_bitrate )
834 p_input->p->counters.p_input_bitrate->update_interval = 1000000;
839 static int InitSout( input_thread_t * p_input )
841 if( p_input->b_preparsing )
844 /* Find a usable sout and attach it to p_input */
845 char *psz = var_GetNonEmptyString( p_input, "sout" );
846 if( psz && strncasecmp( p_input->p->p_item->psz_uri, "vlc:", 4 ) )
848 p_input->p->p_sout = input_resource_RequestSout( p_input->p->p_resource, NULL, psz );
849 if( !p_input->p->p_sout )
851 input_ChangeState( p_input, ERROR_S );
852 msg_Err( p_input, "cannot start stream output instance, " \
857 if( libvlc_stats( p_input ) )
859 INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
860 INIT_COUNTER( sout_sent_bytes, INTEGER, COUNTER );
861 INIT_COUNTER( sout_send_bitrate, FLOAT, DERIVATIVE );
862 if( p_input->p->counters.p_sout_send_bitrate )
863 p_input->p->counters.p_sout_send_bitrate->update_interval =
869 input_resource_RequestSout( p_input->p->p_resource, NULL, NULL );
877 static void InitTitle( input_thread_t * p_input )
879 input_source_t *p_master = &p_input->p->input;
881 if( p_input->b_preparsing )
884 /* Create global title (from master) */
885 p_input->p->i_title = p_master->i_title;
886 p_input->p->title = p_master->title;
887 p_input->p->i_title_offset = p_master->i_title_offset;
888 p_input->p->i_seekpoint_offset = p_master->i_seekpoint_offset;
889 if( p_input->p->i_title > 0 )
891 /* Setup variables */
892 input_ControlVarNavigation( p_input );
893 input_SendEventTitle( p_input, 0 );
897 p_input->p->b_can_pace_control = p_master->b_can_pace_control;
898 p_input->p->b_can_pause = p_master->b_can_pause;
899 p_input->p->b_can_rate_control = p_master->b_can_rate_control;
902 static void StartTitle( input_thread_t * p_input )
906 /* Start title/chapter */
907 val.i_int = p_input->p->input.i_title_start -
908 p_input->p->input.i_title_offset;
909 if( val.i_int > 0 && val.i_int < p_input->p->input.i_title )
910 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
912 val.i_int = p_input->p->input.i_seekpoint_start -
913 p_input->p->input.i_seekpoint_offset;
914 if( val.i_int > 0 /* TODO: check upper boundary */ )
915 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
917 /* Start/stop/run time */
918 p_input->p->i_start = INT64_C(1000000) * var_GetInteger( p_input, "start-time" );
919 p_input->p->i_stop = INT64_C(1000000) * var_GetInteger( p_input, "stop-time" );
920 p_input->p->i_run = INT64_C(1000000) * var_GetInteger( p_input, "run-time" );
921 if( p_input->p->i_run < 0 )
923 msg_Warn( p_input, "invalid run-time ignored" );
924 p_input->p->i_run = 0;
927 const mtime_t i_length = var_GetTime( p_input, "length" );
928 if( p_input->p->i_start > 0 )
930 if( p_input->p->i_start >= i_length )
932 msg_Warn( p_input, "invalid start-time ignored" );
938 msg_Dbg( p_input, "starting at time: %ds",
939 (int)( p_input->p->i_start / INT64_C(1000000) ) );
941 s.i_time = p_input->p->i_start;
942 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
945 if( p_input->p->i_stop > 0 && p_input->p->i_stop <= p_input->p->i_start )
947 msg_Warn( p_input, "invalid stop-time ignored" );
948 p_input->p->i_stop = 0;
950 p_input->p->b_fast_seek = var_GetBool( p_input, "input-fast-seek" );
953 static void LoadSubtitles( input_thread_t *p_input )
956 /* Get fps and set it if not already set */
957 const double f_fps = p_input->p->f_fps;
960 float f_requested_fps;
962 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
963 var_SetFloat( p_input, "sub-original-fps", f_fps );
965 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
966 if( f_requested_fps != f_fps )
968 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
970 var_SetFloat( p_input, "sub-fps", f_requested_fps );
974 const int i_delay = var_CreateGetInteger( p_input, "sub-delay" );
976 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
978 /* Look for and add subtitle files */
979 char *psz_subtitle = var_GetNonEmptyString( p_input, "sub-file" );
980 if( psz_subtitle != NULL )
982 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
983 SubtitleAdd( p_input, psz_subtitle, true );
986 if( var_GetBool( p_input, "sub-autodetect-file" ) )
988 char *psz_autopath = var_GetNonEmptyString( p_input, "sub-autodetect-path" );
989 char **ppsz_subs = subtitles_Detect( p_input, psz_autopath,
990 p_input->p->p_item->psz_uri );
991 free( psz_autopath );
993 for( int i = 0; ppsz_subs && ppsz_subs[i]; i++ )
995 /* Try to autoselect the first autodetected subtitles file
996 * if no subtitles file was specified */
997 bool b_forced = i == 0 && !psz_subtitle;
999 if( !psz_subtitle || strcmp( psz_subtitle, ppsz_subs[i] ) )
1000 SubtitleAdd( p_input, ppsz_subs[i], b_forced );
1002 free( ppsz_subs[i] );
1006 free( psz_subtitle );
1009 static void LoadSlaves( input_thread_t *p_input )
1011 char *psz = var_GetNonEmptyString( p_input, "input-slave" );
1015 char *psz_org = psz;
1016 while( psz && *psz )
1018 while( *psz == ' ' || *psz == '#' )
1021 char *psz_delim = strchr( psz, '#' );
1023 *psz_delim++ = '\0';
1028 msg_Dbg( p_input, "adding slave input '%s'", psz );
1030 input_source_t *p_slave = InputSourceNew( p_input );
1031 if( p_slave && !InputSourceInit( p_input, p_slave, psz, NULL ) )
1032 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, p_slave );
1041 static void UpdatePtsDelay( input_thread_t *p_input )
1043 input_thread_private_t *p_sys = p_input->p;
1045 /* Get max pts delay from input source */
1046 mtime_t i_pts_delay = p_sys->input.i_pts_delay;
1047 for( int i = 0; i < p_sys->i_slave; i++ )
1048 i_pts_delay = __MAX( i_pts_delay, p_sys->slave[i]->i_pts_delay );
1050 if( i_pts_delay < 0 )
1053 /* Take care of audio/spu delay */
1054 const mtime_t i_audio_delay = var_GetTime( p_input, "audio-delay" );
1055 const mtime_t i_spu_delay = var_GetTime( p_input, "spu-delay" );
1056 const mtime_t i_extra_delay = __MIN( i_audio_delay, i_spu_delay );
1057 if( i_extra_delay < 0 )
1058 i_pts_delay -= i_extra_delay;
1060 /* Update cr_average depending on the caching */
1061 const int i_cr_average = var_GetInteger( p_input, "cr-average" ) * i_pts_delay / DEFAULT_PTS_DELAY;
1064 es_out_SetJitter( p_input->p->p_es_out, i_pts_delay, i_cr_average );
1067 static void InitPrograms( input_thread_t * p_input )
1072 /* Compute correct pts_delay */
1073 UpdatePtsDelay( p_input );
1076 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, true );
1077 i_es_out_mode = ES_OUT_MODE_AUTO;
1079 if( p_input->p->p_sout )
1081 if( var_GetBool( p_input, "sout-all" ) )
1083 i_es_out_mode = ES_OUT_MODE_ALL;
1088 var_Get( p_input, "programs", &val );
1089 if( val.p_list && val.p_list->i_count )
1091 i_es_out_mode = ES_OUT_MODE_PARTIAL;
1092 /* Note : we should remove the "program" callback. */
1096 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
1101 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
1103 /* Inform the demuxer about waited group (needed only for DVB) */
1104 if( i_es_out_mode == ES_OUT_MODE_ALL )
1106 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
1108 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
1110 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1,
1115 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP,
1116 (int) var_GetInteger( p_input, "program" ), NULL );
1120 static int Init( input_thread_t * p_input )
1125 for( i = 0; i < p_input->p->p_item->i_options; i++ )
1127 if( !strncmp( p_input->p->p_item->ppsz_options[i], "meta-file", 9 ) )
1129 msg_Dbg( p_input, "Input is a meta file: disabling unneeded options" );
1130 var_SetString( p_input, "sout", "" );
1131 var_SetBool( p_input, "sout-all", false );
1132 var_SetString( p_input, "input-slave", "" );
1133 var_SetInteger( p_input, "input-repeat", 0 );
1134 var_SetString( p_input, "sub-file", "" );
1135 var_SetBool( p_input, "sub-autodetect-file", false );
1139 InitStatistics( p_input );
1141 ret = InitSout( p_input );
1142 if( ret != VLC_SUCCESS )
1147 p_input->p->p_es_out_display = input_EsOutNew( p_input, p_input->p->i_rate );
1148 p_input->p->p_es_out = input_EsOutTimeshiftNew( p_input, p_input->p->p_es_out_display, p_input->p->i_rate );
1149 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, false );
1150 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
1152 var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
1153 var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
1156 input_ChangeState( p_input, OPENING_S );
1157 input_SendEventCache( p_input, 0.0 );
1160 if( InputSourceInit( p_input, &p_input->p->input,
1161 p_input->p->p_item->psz_uri, NULL ) )
1166 InitTitle( p_input );
1168 /* Load master infos */
1171 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_LENGTH,
1175 i_length = input_item_GetDuration( p_input->p->p_item );
1176 input_SendEventTimes( p_input, 0.0, 0, i_length );
1178 if( !p_input->b_preparsing )
1180 StartTitle( p_input );
1181 LoadSubtitles( p_input );
1182 LoadSlaves( p_input );
1183 InitPrograms( p_input );
1186 if( !p_input->b_preparsing && p_input->p->p_sout )
1188 p_input->p->b_out_pace_control = (p_input->p->p_sout->i_out_pace_nocontrol > 0);
1190 if( p_input->p->b_can_pace_control && p_input->p->b_out_pace_control )
1192 /* We don't want a high input priority here or we'll
1193 * end-up sucking up all the CPU time */
1194 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
1197 msg_Dbg( p_input, "starting in %s mode",
1198 p_input->p->b_out_pace_control ? "async" : "sync" );
1201 p_meta = vlc_meta_New();
1204 /* Get meta data from users */
1205 InputMetaUser( p_input, p_meta );
1207 /* Get meta data from master input */
1208 InputSourceMeta( p_input, &p_input->p->input, p_meta );
1210 /* And from slave */
1211 for( int i = 0; i < p_input->p->i_slave; i++ )
1212 InputSourceMeta( p_input, p_input->p->slave[i], p_meta );
1215 InputUpdateMeta( p_input, p_meta );
1218 msg_Dbg( p_input, "`%s' successfully opened",
1219 p_input->p->p_item->psz_uri );
1221 /* initialization is complete */
1222 input_ChangeState( p_input, PLAYING_S );
1227 input_ChangeState( p_input, ERROR_S );
1229 if( p_input->p->p_es_out )
1230 es_out_Delete( p_input->p->p_es_out );
1231 if( p_input->p->p_es_out_display )
1232 es_out_Delete( p_input->p->p_es_out_display );
1233 if( p_input->p->p_resource )
1235 if( p_input->p->p_sout )
1236 input_resource_RequestSout( p_input->p->p_resource,
1237 p_input->p->p_sout, NULL );
1238 input_resource_SetInput( p_input->p->p_resource, NULL );
1244 if( !p_input->b_preparsing && libvlc_stats( p_input ) )
1246 #define EXIT_COUNTER( c ) do { if( p_input->p->counters.p_##c ) \
1247 stats_CounterClean( p_input->p->counters.p_##c );\
1248 p_input->p->counters.p_##c = NULL; } while(0)
1249 EXIT_COUNTER( read_bytes );
1250 EXIT_COUNTER( read_packets );
1251 EXIT_COUNTER( demux_read );
1252 EXIT_COUNTER( input_bitrate );
1253 EXIT_COUNTER( demux_bitrate );
1254 EXIT_COUNTER( demux_corrupted );
1255 EXIT_COUNTER( demux_discontinuity );
1256 EXIT_COUNTER( played_abuffers );
1257 EXIT_COUNTER( lost_abuffers );
1258 EXIT_COUNTER( displayed_pictures );
1259 EXIT_COUNTER( lost_pictures );
1260 EXIT_COUNTER( decoded_audio );
1261 EXIT_COUNTER( decoded_video );
1262 EXIT_COUNTER( decoded_sub );
1264 if( p_input->p->p_sout )
1266 EXIT_COUNTER( sout_sent_packets );
1267 EXIT_COUNTER( sout_sent_bytes );
1268 EXIT_COUNTER( sout_send_bitrate );
1273 /* Mark them deleted */
1274 p_input->p->input.p_demux = NULL;
1275 p_input->p->input.p_stream = NULL;
1276 p_input->p->input.p_access = NULL;
1277 p_input->p->p_es_out = NULL;
1278 p_input->p->p_es_out_display = NULL;
1279 p_input->p->p_sout = NULL;
1281 return VLC_EGENERIC;
1284 /*****************************************************************************
1285 * End: end the input thread
1286 *****************************************************************************/
1287 static void End( input_thread_t * p_input )
1291 /* We are at the end */
1292 input_ChangeState( p_input, END_S );
1294 /* Clean control variables */
1295 input_ControlVarStop( p_input );
1297 /* Stop es out activity */
1298 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, false );
1299 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
1301 /* Clean up master */
1302 InputSourceClean( &p_input->p->input );
1305 for( i = 0; i < p_input->p->i_slave; i++ )
1307 InputSourceClean( p_input->p->slave[i] );
1308 free( p_input->p->slave[i] );
1310 free( p_input->p->slave );
1312 /* Unload all modules */
1313 if( p_input->p->p_es_out )
1314 es_out_Delete( p_input->p->p_es_out );
1315 if( p_input->p->p_es_out_display )
1316 es_out_Delete( p_input->p->p_es_out_display );
1318 if( !p_input->b_preparsing )
1320 #define CL_CO( c ) stats_CounterClean( p_input->p->counters.p_##c ); p_input->p->counters.p_##c = NULL;
1321 if( libvlc_stats( p_input ) )
1323 /* make sure we are up to date */
1324 stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
1325 CL_CO( read_bytes );
1326 CL_CO( read_packets );
1327 CL_CO( demux_read );
1328 CL_CO( input_bitrate );
1329 CL_CO( demux_bitrate );
1330 CL_CO( demux_corrupted );
1331 CL_CO( demux_discontinuity );
1332 CL_CO( played_abuffers );
1333 CL_CO( lost_abuffers );
1334 CL_CO( displayed_pictures );
1335 CL_CO( lost_pictures );
1336 CL_CO( decoded_audio) ;
1337 CL_CO( decoded_video );
1338 CL_CO( decoded_sub) ;
1341 /* Close optional stream output instance */
1342 if( p_input->p->p_sout )
1344 CL_CO( sout_sent_packets );
1345 CL_CO( sout_sent_bytes );
1346 CL_CO( sout_send_bitrate );
1351 vlc_mutex_lock( &p_input->p->p_item->lock );
1352 if( p_input->p->i_attachment > 0 )
1354 for( i = 0; i < p_input->p->i_attachment; i++ )
1355 vlc_input_attachment_Delete( p_input->p->attachment[i] );
1356 TAB_CLEAN( p_input->p->i_attachment, p_input->p->attachment );
1358 vlc_mutex_unlock( &p_input->p->p_item->lock );
1361 input_resource_RequestSout( p_input->p->p_resource,
1362 p_input->p->p_sout, NULL );
1363 input_resource_SetInput( p_input->p->p_resource, NULL );
1366 /*****************************************************************************
1368 *****************************************************************************/
1369 void input_ControlPush( input_thread_t *p_input,
1370 int i_type, vlc_value_t *p_val )
1372 vlc_mutex_lock( &p_input->p->lock_control );
1373 if( i_type == INPUT_CONTROL_SET_DIE )
1375 /* Special case, empty the control */
1376 for( int i = 0; i < p_input->p->i_control; i++ )
1378 input_control_t *p_ctrl = &p_input->p->control[i];
1379 ControlRelease( p_ctrl->i_type, p_ctrl->val );
1381 p_input->p->i_control = 0;
1384 if( p_input->p->i_control >= INPUT_CONTROL_FIFO_SIZE )
1386 msg_Err( p_input, "input control fifo overflow, trashing type=%d",
1389 ControlRelease( i_type, *p_val );
1398 memset( &c.val, 0, sizeof(c.val) );
1400 p_input->p->control[p_input->p->i_control++] = c;
1402 vlc_cond_signal( &p_input->p->wait_control );
1403 vlc_mutex_unlock( &p_input->p->lock_control );
1406 static inline int ControlPop( input_thread_t *p_input,
1407 int *pi_type, vlc_value_t *p_val,
1408 mtime_t i_deadline )
1410 input_thread_private_t *p_sys = p_input->p;
1412 vlc_mutex_lock( &p_sys->lock_control );
1413 while( p_sys->i_control <= 0 )
1415 if( !vlc_object_alive( p_input ) || i_deadline < 0 )
1417 vlc_mutex_unlock( &p_sys->lock_control );
1418 return VLC_EGENERIC;
1421 if( vlc_cond_timedwait( &p_sys->wait_control, &p_sys->lock_control,
1424 vlc_mutex_unlock( &p_sys->lock_control );
1425 return VLC_EGENERIC;
1430 *pi_type = p_sys->control[0].i_type;
1431 *p_val = p_sys->control[0].val;
1434 if( p_sys->i_control > 0 )
1435 memmove( &p_sys->control[0], &p_sys->control[1],
1436 sizeof(*p_sys->control) * p_sys->i_control );
1437 vlc_mutex_unlock( &p_sys->lock_control );
1442 static void ControlReduce( input_thread_t *p_input )
1444 vlc_mutex_lock( &p_input->p->lock_control );
1446 for( int i = 1; i < p_input->p->i_control; i++ )
1448 const int i_lt = p_input->p->control[i-1].i_type;
1449 const int i_ct = p_input->p->control[i].i_type;
1451 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1452 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->p->i_control,
1456 ( i_ct == INPUT_CONTROL_SET_STATE ||
1457 i_ct == INPUT_CONTROL_SET_RATE ||
1458 i_ct == INPUT_CONTROL_SET_POSITION ||
1459 i_ct == INPUT_CONTROL_SET_TIME ||
1460 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1461 i_ct == INPUT_CONTROL_SET_TITLE ||
1462 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1463 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1466 // msg_Dbg( p_input, "merged at %d", i );
1467 /* Remove the i-1 */
1468 for( j = i; j < p_input->p->i_control; j++ )
1469 p_input->p->control[j-1] = p_input->p->control[j];
1470 p_input->p->i_control--;
1474 /* TODO but that's not that important
1475 - merge SET_X with SET_X_CMD
1476 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1477 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1482 vlc_mutex_unlock( &p_input->p->lock_control );
1485 static void ControlRelease( int i_type, vlc_value_t val )
1489 case INPUT_CONTROL_ADD_SUBTITLE:
1490 case INPUT_CONTROL_ADD_SLAVE:
1491 free( val.psz_string );
1500 static void ControlPause( input_thread_t *p_input, mtime_t i_control_date )
1502 int i_ret = VLC_SUCCESS;
1503 int i_state = PAUSE_S;
1505 if( p_input->p->b_can_pause )
1507 if( p_input->p->input.p_access )
1508 i_ret = access_Control( p_input->p->input.p_access,
1509 ACCESS_SET_PAUSE_STATE, true );
1511 i_ret = demux_Control( p_input->p->input.p_demux,
1512 DEMUX_SET_PAUSE_STATE, true );
1516 msg_Warn( p_input, "cannot set pause state" );
1517 i_state = p_input->p->i_state;
1524 i_ret = es_out_SetPauseState( p_input->p->p_es_out, p_input->p->b_can_pause, true, i_control_date );
1527 msg_Warn( p_input, "cannot set pause state at es_out level" );
1528 i_state = p_input->p->i_state;
1532 /* Switch to new state */
1533 input_ChangeState( p_input, i_state );
1537 static void ControlUnpause( input_thread_t *p_input, mtime_t i_control_date )
1539 int i_ret = VLC_SUCCESS;
1541 if( p_input->p->b_can_pause )
1543 if( p_input->p->input.p_access )
1544 i_ret = access_Control( p_input->p->input.p_access,
1545 ACCESS_SET_PAUSE_STATE, false );
1547 i_ret = demux_Control( p_input->p->input.p_demux,
1548 DEMUX_SET_PAUSE_STATE, false );
1551 /* FIXME What to do ? */
1552 msg_Warn( p_input, "cannot unset pause -> EOF" );
1553 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1557 /* Switch to play */
1558 input_ChangeState( p_input, PLAYING_S );
1562 es_out_SetPauseState( p_input->p->p_es_out, false, false, i_control_date );
1565 static bool Control( input_thread_t *p_input,
1566 int i_type, vlc_value_t val )
1568 const mtime_t i_control_date = mdate();
1569 /* FIXME b_force_update is abused, it should be carefully checked */
1570 bool b_force_update = false;
1573 return b_force_update;
1577 case INPUT_CONTROL_SET_DIE:
1578 msg_Dbg( p_input, "control: stopping input" );
1580 /* Mark all submodules to die */
1581 ObjectKillChildrens( p_input, VLC_OBJECT(p_input) );
1584 case INPUT_CONTROL_SET_POSITION:
1585 case INPUT_CONTROL_SET_POSITION_OFFSET:
1589 if( p_input->p->b_recording )
1591 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) ignored while recording" );
1594 f_pos = val.f_float;
1595 if( i_type != INPUT_CONTROL_SET_POSITION )
1596 f_pos += var_GetFloat( p_input, "position" );
1599 else if( f_pos > 1.0 )
1601 /* Reset the decoders states and clock sync (before calling the demuxer */
1602 es_out_SetTime( p_input->p->p_es_out, -1 );
1603 if( demux_Control( p_input->p->input.p_demux, DEMUX_SET_POSITION,
1604 f_pos, !p_input->p->b_fast_seek ) )
1606 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1607 "%2.1f%% failed", f_pos * 100 );
1611 if( p_input->p->i_slave > 0 )
1612 SlaveSeek( p_input );
1613 p_input->p->input.b_eof = false;
1615 b_force_update = true;
1620 case INPUT_CONTROL_SET_TIME:
1621 case INPUT_CONTROL_SET_TIME_OFFSET:
1626 if( p_input->p->b_recording )
1628 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) ignored while recording" );
1632 i_time = val.i_time;
1633 if( i_type != INPUT_CONTROL_SET_TIME )
1634 i_time += var_GetTime( p_input, "time" );
1639 /* Reset the decoders states and clock sync (before calling the demuxer */
1640 es_out_SetTime( p_input->p->p_es_out, -1 );
1642 i_ret = demux_Control( p_input->p->input.p_demux,
1643 DEMUX_SET_TIME, i_time,
1644 !p_input->p->b_fast_seek );
1649 /* Emulate it with a SET_POS */
1650 demux_Control( p_input->p->input.p_demux,
1651 DEMUX_GET_LENGTH, &i_length );
1654 double f_pos = (double)i_time / (double)i_length;
1655 i_ret = demux_Control( p_input->p->input.p_demux,
1656 DEMUX_SET_POSITION, f_pos,
1657 !p_input->p->b_fast_seek );
1662 msg_Warn( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) %"PRId64
1663 " failed or not possible", i_time );
1667 if( p_input->p->i_slave > 0 )
1668 SlaveSeek( p_input );
1669 p_input->p->input.b_eof = false;
1671 b_force_update = true;
1676 case INPUT_CONTROL_SET_STATE:
1677 if( ( val.i_int == PLAYING_S && p_input->p->i_state == PAUSE_S ) ||
1678 ( val.i_int == PAUSE_S && p_input->p->i_state == PAUSE_S ) )
1680 ControlUnpause( p_input, i_control_date );
1682 b_force_update = true;
1684 else if( val.i_int == PAUSE_S && p_input->p->i_state == PLAYING_S /* &&
1685 p_input->p->b_can_pause */ )
1687 ControlPause( p_input, i_control_date );
1689 b_force_update = true;
1691 else if( val.i_int == PAUSE_S && !p_input->p->b_can_pause && 0 )
1693 b_force_update = true;
1695 /* Correct "state" value */
1696 input_ChangeState( p_input, p_input->p->i_state );
1698 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1700 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1704 case INPUT_CONTROL_SET_RATE:
1705 case INPUT_CONTROL_SET_RATE_SLOWER:
1706 case INPUT_CONTROL_SET_RATE_FASTER:
1711 /* Get rate and direction */
1712 if( i_type == INPUT_CONTROL_SET_RATE )
1714 i_rate = abs( val.i_int );
1715 i_rate_sign = val.i_int < 0 ? -1 : 1;
1719 static const int ppi_factor[][2] = {
1720 {1,64}, {1,32}, {1,16}, {1,8}, {1,4}, {1,3}, {1,2}, {2,3},
1722 {3,2}, {2,1}, {3,1}, {4,1}, {8,1}, {16,1}, {32,1}, {64,1},
1729 i_rate_sign = p_input->p->i_rate < 0 ? -1 : 1;
1733 for( i = 0; ppi_factor[i][0] != 0; i++ )
1735 const int i_test_r = INPUT_RATE_DEFAULT * ppi_factor[i][0] / ppi_factor[i][1];
1736 const int i_test_e = abs( abs( p_input->p->i_rate ) - i_test_r );
1737 if( i_test_e < i_error )
1744 assert( i_idx >= 0 && ppi_factor[i_idx][0] != 0 );
1746 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1748 if( ppi_factor[i_idx+1][0] > 0 )
1749 i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx+1][0] / ppi_factor[i_idx+1][1];
1751 i_rate = INPUT_RATE_MAX+1;
1755 assert( i_type == INPUT_CONTROL_SET_RATE_FASTER );
1757 i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx-1][0] / ppi_factor[i_idx-1][1];
1759 i_rate = INPUT_RATE_MIN-1;
1763 /* Check rate bound */
1764 if( i_rate < INPUT_RATE_MIN )
1766 msg_Dbg( p_input, "cannot set rate faster" );
1767 i_rate = INPUT_RATE_MIN;
1769 else if( i_rate > INPUT_RATE_MAX )
1771 msg_Dbg( p_input, "cannot set rate slower" );
1772 i_rate = INPUT_RATE_MAX;
1775 /* Apply direction */
1776 if( i_rate_sign < 0 )
1778 if( p_input->p->input.b_rescale_ts )
1780 msg_Dbg( p_input, "cannot set negative rate" );
1781 i_rate = p_input->p->i_rate;
1782 assert( i_rate > 0 );
1786 i_rate *= i_rate_sign;
1790 if( i_rate != INPUT_RATE_DEFAULT &&
1791 ( ( !p_input->p->b_can_rate_control && !p_input->p->input.b_rescale_ts ) ||
1792 ( p_input->p->p_sout && !p_input->p->b_out_pace_control ) ) )
1794 msg_Dbg( p_input, "cannot change rate" );
1795 i_rate = INPUT_RATE_DEFAULT;
1797 if( i_rate != p_input->p->i_rate &&
1798 !p_input->p->b_can_pace_control && p_input->p->b_can_rate_control )
1801 if( p_input->p->input.p_access )
1803 i_ret = VLC_EGENERIC;
1807 if( !p_input->p->input.b_rescale_ts )
1808 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1810 i_ret = demux_Control( p_input->p->input.p_demux,
1811 DEMUX_SET_RATE, &i_rate );
1815 msg_Warn( p_input, "ACCESS/DEMUX_SET_RATE failed" );
1816 i_rate = p_input->p->i_rate;
1821 if( i_rate != p_input->p->i_rate )
1823 p_input->p->i_rate = i_rate;
1824 input_SendEventRate( p_input, i_rate );
1826 if( p_input->p->input.b_rescale_ts )
1828 const int i_rate_source = (p_input->p->b_can_pace_control || p_input->p->b_can_rate_control ) ? i_rate : INPUT_RATE_DEFAULT;
1829 es_out_SetRate( p_input->p->p_es_out, i_rate_source, i_rate );
1832 b_force_update = true;
1837 case INPUT_CONTROL_SET_PROGRAM:
1838 /* No need to force update, es_out does it if needed */
1839 es_out_Control( p_input->p->p_es_out,
1840 ES_OUT_SET_GROUP, val.i_int );
1842 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1846 case INPUT_CONTROL_SET_ES:
1847 /* No need to force update, es_out does it if needed */
1848 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, val.i_int );
1851 case INPUT_CONTROL_RESTART_ES:
1852 es_out_Control( p_input->p->p_es_out_display, ES_OUT_RESTART_ES_BY_ID, val.i_int );
1855 case INPUT_CONTROL_SET_AUDIO_DELAY:
1856 if( !es_out_SetDelay( p_input->p->p_es_out_display, AUDIO_ES, val.i_time ) )
1858 input_SendEventAudioDelay( p_input, val.i_time );
1859 UpdatePtsDelay( p_input );
1863 case INPUT_CONTROL_SET_SPU_DELAY:
1864 if( !es_out_SetDelay( p_input->p->p_es_out_display, SPU_ES, val.i_time ) )
1866 input_SendEventSubtitleDelay( p_input, val.i_time );
1867 UpdatePtsDelay( p_input );
1871 case INPUT_CONTROL_SET_TITLE:
1872 case INPUT_CONTROL_SET_TITLE_NEXT:
1873 case INPUT_CONTROL_SET_TITLE_PREV:
1874 if( p_input->p->b_recording )
1876 msg_Err( p_input, "INPUT_CONTROL_SET_TITLE(*) ignored while recording" );
1879 if( p_input->p->input.b_title_demux &&
1880 p_input->p->input.i_title > 0 )
1883 /* FIXME handle demux title */
1884 demux_t *p_demux = p_input->p->input.p_demux;
1887 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1888 i_title = p_demux->info.i_title - 1;
1889 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1890 i_title = p_demux->info.i_title + 1;
1892 i_title = val.i_int;
1894 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1896 es_out_SetTime( p_input->p->p_es_out, -1 );
1898 demux_Control( p_demux, DEMUX_SET_TITLE, i_title );
1899 input_SendEventTitle( p_input, i_title );
1902 else if( p_input->p->input.i_title > 0 )
1904 access_t *p_access = p_input->p->input.p_access;
1907 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1908 i_title = p_access->info.i_title - 1;
1909 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1910 i_title = p_access->info.i_title + 1;
1912 i_title = val.i_int;
1914 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1916 es_out_SetTime( p_input->p->p_es_out, -1 );
1918 stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
1919 ACCESS_SET_TITLE, i_title );
1920 input_SendEventTitle( p_input, i_title );
1924 case INPUT_CONTROL_SET_SEEKPOINT:
1925 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1926 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1927 if( p_input->p->b_recording )
1929 msg_Err( p_input, "INPUT_CONTROL_SET_SEEKPOINT(*) ignored while recording" );
1933 if( p_input->p->input.b_title_demux &&
1934 p_input->p->input.i_title > 0 )
1936 demux_t *p_demux = p_input->p->input.p_demux;
1938 int64_t i_input_time;
1939 int64_t i_seekpoint_time;
1941 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1943 i_seekpoint = p_demux->info.i_seekpoint;
1944 i_seekpoint_time = p_input->p->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1945 i_input_time = var_GetTime( p_input, "time" );
1946 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
1948 if( i_input_time < i_seekpoint_time + 3000000 )
1954 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1955 i_seekpoint = p_demux->info.i_seekpoint + 1;
1957 i_seekpoint = val.i_int;
1959 if( i_seekpoint >= 0 && i_seekpoint <
1960 p_input->p->input.title[p_demux->info.i_title]->i_seekpoint )
1963 es_out_SetTime( p_input->p->p_es_out, -1 );
1965 demux_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1966 input_SendEventSeekpoint( p_input, p_demux->info.i_title, i_seekpoint );
1969 else if( p_input->p->input.i_title > 0 )
1971 access_t *p_access = p_input->p->input.p_access;
1973 int64_t i_input_time;
1974 int64_t i_seekpoint_time;
1976 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1978 i_seekpoint = p_access->info.i_seekpoint;
1979 i_seekpoint_time = p_input->p->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1980 i_input_time = var_GetTime( p_input, "time" );
1981 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
1983 if( i_input_time < i_seekpoint_time + 3000000 )
1989 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1990 i_seekpoint = p_access->info.i_seekpoint + 1;
1992 i_seekpoint = val.i_int;
1994 if( i_seekpoint >= 0 && i_seekpoint <
1995 p_input->p->input.title[p_access->info.i_title]->i_seekpoint )
1997 es_out_SetTime( p_input->p->p_es_out, -1 );
1999 stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
2000 ACCESS_SET_SEEKPOINT, i_seekpoint );
2001 input_SendEventSeekpoint( p_input, p_access->info.i_title, i_seekpoint );
2006 case INPUT_CONTROL_ADD_SUBTITLE:
2007 if( val.psz_string )
2008 SubtitleAdd( p_input, val.psz_string, true );
2011 case INPUT_CONTROL_ADD_SLAVE:
2012 if( val.psz_string )
2014 input_source_t *slave = InputSourceNew( p_input );
2016 if( slave && !InputSourceInit( p_input, slave, val.psz_string, NULL ) )
2022 msg_Dbg( p_input, "adding %s as slave on the fly",
2026 if( demux_Control( p_input->p->input.p_demux,
2027 DEMUX_GET_TIME, &i_time ) )
2029 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2030 InputSourceClean( slave );
2034 if( demux_Control( slave->p_demux,
2035 DEMUX_SET_TIME, i_time, true ) )
2037 msg_Err( p_input, "seek failed for new slave" );
2038 InputSourceClean( slave );
2043 /* Get meta (access and demux) */
2044 p_meta = vlc_meta_New();
2047 access_Control( slave->p_access, ACCESS_GET_META, p_meta );
2048 demux_Control( slave->p_demux, DEMUX_GET_META, p_meta );
2049 InputUpdateMeta( p_input, p_meta );
2052 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, slave );
2057 msg_Warn( p_input, "failed to add %s as slave",
2063 case INPUT_CONTROL_SET_RECORD_STATE:
2064 if( !!p_input->p->b_recording != !!val.b_bool )
2066 if( p_input->p->input.b_can_stream_record )
2068 if( demux_Control( p_input->p->input.p_demux,
2069 DEMUX_SET_RECORD_STATE, val.b_bool ) )
2074 if( es_out_SetRecordState( p_input->p->p_es_out_display, val.b_bool ) )
2077 p_input->p->b_recording = val.b_bool;
2079 input_SendEventRecord( p_input, val.b_bool );
2081 b_force_update = true;
2085 case INPUT_CONTROL_SET_FRAME_NEXT:
2086 if( p_input->p->i_state == PAUSE_S )
2088 es_out_SetFrameNext( p_input->p->p_es_out );
2090 else if( p_input->p->i_state == PLAYING_S )
2092 ControlPause( p_input, i_control_date );
2096 msg_Err( p_input, "invalid state for frame next" );
2098 b_force_update = true;
2101 case INPUT_CONTROL_SET_BOOKMARK:
2103 seekpoint_t bookmark;
2105 bookmark.i_time_offset = -1;
2106 bookmark.i_byte_offset = -1;
2108 vlc_mutex_lock( &p_input->p->p_item->lock );
2109 if( val.i_int >= 0 && val.i_int < p_input->p->i_bookmark )
2111 const seekpoint_t *p_bookmark = p_input->p->pp_bookmark[val.i_int];
2112 bookmark.i_time_offset = p_bookmark->i_time_offset;
2113 bookmark.i_byte_offset = p_bookmark->i_byte_offset;
2115 vlc_mutex_unlock( &p_input->p->p_item->lock );
2117 if( bookmark.i_time_offset < 0 && bookmark.i_byte_offset < 0 )
2119 msg_Err( p_input, "invalid bookmark %d", val.i_int );
2123 if( bookmark.i_time_offset >= 0 )
2125 val.i_time = bookmark.i_time_offset;
2126 b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME, val );
2128 else if( bookmark.i_byte_offset >= 0 &&
2129 p_input->p->input.p_stream )
2131 const int64_t i_size = stream_Size( p_input->p->input.p_stream );
2132 if( i_size > 0 && bookmark.i_byte_offset <= i_size )
2134 val.f_float = (double)bookmark.i_byte_offset / i_size;
2135 b_force_update = Control( p_input, INPUT_CONTROL_SET_POSITION, val );
2142 msg_Err( p_input, "not yet implemented" );
2146 ControlRelease( i_type, val );
2147 return b_force_update;
2150 /*****************************************************************************
2151 * UpdateTitleSeekpoint
2152 *****************************************************************************/
2153 static int UpdateTitleSeekpoint( input_thread_t *p_input,
2154 int i_title, int i_seekpoint )
2156 int i_title_end = p_input->p->input.i_title_end -
2157 p_input->p->input.i_title_offset;
2158 int i_seekpoint_end = p_input->p->input.i_seekpoint_end -
2159 p_input->p->input.i_seekpoint_offset;
2161 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
2163 if( i_title > i_title_end ||
2164 ( i_title == i_title_end && i_seekpoint > i_seekpoint_end ) )
2167 else if( i_seekpoint_end >= 0 )
2169 if( i_seekpoint > i_seekpoint_end )
2172 else if( i_title_end >= 0 )
2174 if( i_title > i_title_end )
2179 /*****************************************************************************
2181 *****************************************************************************/
2182 static int UpdateTitleSeekpointFromDemux( input_thread_t *p_input )
2184 demux_t *p_demux = p_input->p->input.p_demux;
2186 /* TODO event-like */
2187 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
2189 input_SendEventTitle( p_input, p_demux->info.i_title );
2191 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
2193 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
2195 input_SendEventSeekpoint( p_input,
2196 p_demux->info.i_title, p_demux->info.i_seekpoint );
2198 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2201 /* Hmmm only works with master input */
2202 if( p_input->p->input.p_demux == p_demux )
2203 return UpdateTitleSeekpoint( p_input,
2204 p_demux->info.i_title,
2205 p_demux->info.i_seekpoint );
2209 static void UpdateGenericFromDemux( input_thread_t *p_input )
2211 demux_t *p_demux = p_input->p->input.p_demux;
2213 if( p_demux->info.i_update & INPUT_UPDATE_META )
2215 vlc_meta_t *p_meta = vlc_meta_New();
2218 demux_Control( p_input->p->input.p_demux, DEMUX_GET_META, p_meta );
2219 InputUpdateMeta( p_input, p_meta );
2221 p_demux->info.i_update &= ~INPUT_UPDATE_META;
2224 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
2228 /*****************************************************************************
2229 * Update*FromAccess:
2230 *****************************************************************************/
2231 static int UpdateTitleSeekpointFromAccess( input_thread_t *p_input )
2233 access_t *p_access = p_input->p->input.p_access;
2235 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
2237 input_SendEventTitle( p_input, p_access->info.i_title );
2239 stream_Control( p_input->p->input.p_stream, STREAM_UPDATE_SIZE );
2241 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
2243 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
2245 input_SendEventSeekpoint( p_input,
2246 p_access->info.i_title, p_access->info.i_seekpoint );
2248 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2250 /* Hmmm only works with master input */
2251 if( p_input->p->input.p_access == p_access )
2252 return UpdateTitleSeekpoint( p_input,
2253 p_access->info.i_title,
2254 p_access->info.i_seekpoint );
2257 static void UpdateGenericFromAccess( input_thread_t *p_input )
2259 access_t *p_access = p_input->p->input.p_access;
2261 if( p_access->info.i_update & INPUT_UPDATE_META )
2263 /* TODO maybe multi - access ? */
2264 vlc_meta_t *p_meta = vlc_meta_New();
2267 access_Control( p_input->p->input.p_access, ACCESS_GET_META, p_meta );
2268 InputUpdateMeta( p_input, p_meta );
2270 p_access->info.i_update &= ~INPUT_UPDATE_META;
2272 if( p_access->info.i_update & INPUT_UPDATE_SIGNAL )
2277 if( access_Control( p_access, ACCESS_GET_SIGNAL, &f_quality, &f_strength ) )
2278 f_quality = f_strength = -1;
2280 input_SendEventSignal( p_input, f_quality, f_strength );
2282 p_access->info.i_update &= ~INPUT_UPDATE_SIGNAL;
2285 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
2288 /*****************************************************************************
2290 *****************************************************************************/
2291 static input_source_t *InputSourceNew( input_thread_t *p_input )
2293 VLC_UNUSED(p_input);
2295 return calloc( 1, sizeof( input_source_t ) );
2298 /*****************************************************************************
2300 *****************************************************************************/
2301 static int InputSourceInit( input_thread_t *p_input,
2302 input_source_t *in, const char *psz_mrl,
2303 const char *psz_forced_demux )
2305 const char *psz_access;
2306 const char *psz_demux;
2310 char *psz_dup = strdup( psz_mrl );
2312 if( psz_dup == NULL )
2316 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_dup );
2318 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
2319 psz_mrl, psz_access, psz_demux, psz_path );
2320 if( !p_input->b_preparsing )
2322 /* Hack to allow udp://@:port syntax */
2324 (strncmp( psz_access, "udp", 3 ) &&
2325 strncmp( psz_access, "rtp", 3 )) )
2327 /* Find optional titles and seekpoints */
2328 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
2329 &in->i_seekpoint_start, &in->i_seekpoint_end );
2332 if( psz_forced_demux && *psz_forced_demux )
2334 psz_demux = psz_forced_demux;
2336 else if( *psz_demux == '\0' )
2338 /* special hack for forcing a demuxer with --demux=module
2339 * (and do nothing with a list) */
2340 char *psz_var_demux = var_GetNonEmptyString( p_input, "demux" );
2342 if( psz_var_demux != NULL &&
2343 !strchr(psz_var_demux, ',' ) &&
2344 !strchr(psz_var_demux, ':' ) )
2346 psz_demux = psz_var_demux;
2348 msg_Dbg( p_input, "enforced demux ` %s'", psz_demux );
2352 /* Try access_demux first */
2353 in->p_demux = demux_New( p_input, psz_access, psz_demux, psz_path,
2354 NULL, p_input->p->p_es_out, false );
2358 /* Preparsing is only for file:// */
2361 if( !*psz_access ) /* path without scheme:// */
2362 psz_access = "file";
2363 if( strcmp( psz_access, "file" ) )
2365 msg_Dbg( p_input, "trying to pre-parse %s", psz_path );
2370 /* Get infos from access_demux */
2371 demux_Control( in->p_demux,
2372 DEMUX_GET_PTS_DELAY, &in->i_pts_delay );
2374 in->b_title_demux = true;
2375 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2376 &in->title, &in->i_title,
2377 &in->i_title_offset, &in->i_seekpoint_offset ) )
2379 TAB_INIT( in->i_title, in->title );
2381 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
2382 &in->b_can_pace_control ) )
2383 in->b_can_pace_control = false;
2385 if( !in->b_can_pace_control )
2387 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_RATE,
2388 &in->b_can_rate_control, &in->b_rescale_ts ) )
2390 in->b_can_rate_control = false;
2391 in->b_rescale_ts = true; /* not used */
2396 in->b_can_rate_control = true;
2397 in->b_rescale_ts = true;
2399 if( demux_Control( in->p_demux, DEMUX_CAN_PAUSE,
2400 &in->b_can_pause ) )
2401 in->b_can_pause = false;
2402 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2403 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2404 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control );
2407 if( demux_Control( in->p_demux, DEMUX_CAN_SEEK, &b_can_seek ) )
2409 var_SetBool( p_input, "can-seek", b_can_seek );
2413 /* Now try a real access */
2414 in->p_access = access_New( p_input, psz_access, psz_demux, psz_path );
2416 /* Access failed, URL encoded ? */
2417 if( in->p_access == NULL && strchr( psz_path, '%' ) )
2419 decode_URI( psz_path );
2421 msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
2422 psz_access, psz_demux, psz_path );
2424 in->p_access = access_New( p_input,
2425 psz_access, psz_demux, psz_path );
2427 if( in->p_access == NULL )
2429 msg_Err( p_input, "open of `%s' failed: %s", psz_mrl,
2431 dialog_Fatal( p_input, _("Your input can't be opened"),
2432 _("VLC is unable to open the MRL '%s'."
2433 " Check the log for details."), psz_mrl );
2437 /* Get infos from access */
2438 if( !p_input->b_preparsing )
2441 access_Control( in->p_access,
2442 ACCESS_GET_PTS_DELAY, &in->i_pts_delay );
2444 in->b_title_demux = false;
2445 if( access_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2446 &in->title, &in->i_title,
2447 &in->i_title_offset, &in->i_seekpoint_offset ) )
2450 TAB_INIT( in->i_title, in->title );
2452 access_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2453 &in->b_can_pace_control );
2454 in->b_can_rate_control = in->b_can_pace_control;
2455 in->b_rescale_ts = true;
2457 access_Control( in->p_access, ACCESS_CAN_PAUSE, &in->b_can_pause );
2458 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2459 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2460 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control );
2462 access_Control( in->p_access, ACCESS_CAN_SEEK, &b_can_seek );
2463 var_SetBool( p_input, "can-seek", b_can_seek );
2468 char **ppsz_input_list;
2470 TAB_INIT( i_input_list, ppsz_input_list );
2472 /* On master stream only, use input-list */
2473 if( &p_input->p->input == in )
2479 psz_parser = var_CreateGetNonEmptyString( p_input, "input-list" );
2481 while( psz_parser && *psz_parser )
2483 char *p = strchr( psz_parser, ',' );
2489 char *psz_name = strdup( psz_parser );
2491 TAB_APPEND( i_input_list, ppsz_input_list, psz_name );
2498 /* Autodetect extra files if none specified */
2499 if( i_input_list <= 0 )
2501 InputGetExtraFiles( p_input, &i_input_list, &ppsz_input_list,
2502 psz_access, psz_path );
2504 if( i_input_list > 0 )
2505 TAB_APPEND( i_input_list, ppsz_input_list, NULL );
2507 /* Create the stream_t */
2508 in->p_stream = stream_AccessNew( in->p_access, ppsz_input_list );
2509 if( ppsz_input_list )
2511 for( int i = 0; ppsz_input_list[i] != NULL; i++ )
2512 free( ppsz_input_list[i] );
2513 TAB_CLEAN( i_input_list, ppsz_input_list );
2516 if( in->p_stream == NULL )
2518 msg_Warn( p_input, "cannot create a stream_t from access" );
2522 /* Add stream filters */
2523 char *psz_stream_filter = var_GetNonEmptyString( p_input,
2525 in->p_stream = stream_FilterChainNew( in->p_stream,
2527 var_GetBool( p_input, "input-record-native" ) );
2528 free( psz_stream_filter );
2530 /* Open a demuxer */
2531 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2533 psz_demux = in->p_access->psz_demux;
2537 /* Take access/stream redirections into account */
2538 char *psz_real_path;
2539 char *psz_buf = NULL;
2540 if( in->p_stream->psz_path )
2542 const char *psz_a, *psz_d;
2543 psz_buf = strdup( in->p_stream->psz_path );
2544 input_SplitMRL( &psz_a, &psz_d, &psz_real_path, psz_buf );
2548 psz_real_path = psz_path;
2550 in->p_demux = demux_New( p_input, psz_access, psz_demux,
2552 in->p_stream, p_input->p->p_es_out,
2553 p_input->b_preparsing );
2557 if( in->p_demux == NULL )
2559 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2560 psz_access, psz_demux, psz_path );
2561 dialog_Fatal( VLC_OBJECT( p_input ),
2562 _("VLC can't recognize the input's format"),
2563 _("The format of '%s' cannot be detected. "
2564 "Have a look at the log for details."), psz_mrl );
2568 /* Get title from demux */
2569 if( !p_input->b_preparsing && in->i_title <= 0 )
2571 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2572 &in->title, &in->i_title,
2573 &in->i_title_offset, &in->i_seekpoint_offset ))
2575 TAB_INIT( in->i_title, in->title );
2579 in->b_title_demux = true;
2586 /* Set record capabilities */
2587 if( demux_Control( in->p_demux, DEMUX_CAN_RECORD, &in->b_can_stream_record ) )
2588 in->b_can_stream_record = false;
2590 if( !var_GetBool( p_input, "input-record-native" ) )
2591 in->b_can_stream_record = false;
2592 var_SetBool( p_input, "can-record", true );
2594 var_SetBool( p_input, "can-record", in->b_can_stream_record );
2598 * FIXME improve for b_preparsing: move it after GET_META and check psz_arturl */
2599 if( 1 || !p_input->b_preparsing )
2602 input_attachment_t **attachment;
2603 if( !demux_Control( in->p_demux, DEMUX_GET_ATTACHMENTS,
2604 &attachment, &i_attachment ) )
2606 vlc_mutex_lock( &p_input->p->p_item->lock );
2607 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2608 i_attachment, attachment );
2609 vlc_mutex_unlock( &p_input->p->p_item->lock );
2612 if( !demux_Control( in->p_demux, DEMUX_GET_FPS, &f_fps ) && f_fps > 0.0 )
2614 vlc_mutex_lock( &p_input->p->p_item->lock );
2615 p_input->p->f_fps = f_fps;
2616 vlc_mutex_unlock( &p_input->p->p_item->lock );
2619 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2620 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2626 demux_Delete( in->p_demux );
2629 stream_Delete( in->p_stream );
2632 access_Delete( in->p_access );
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
2674 /* Read access meta */
2676 access_Control( p_access, ACCESS_GET_META, p_meta );
2678 /* Read demux meta */
2679 demux_Control( p_demux, DEMUX_GET_META, p_meta );
2681 /* If the demux report unsupported meta data, try an external "meta reader" */
2683 if( demux_Control( p_demux, DEMUX_HAS_UNSUPPORTED_META, &b_bool ) )
2688 demux_meta_t *p_demux_meta = p_demux->p_private = calloc( 1, sizeof(*p_demux_meta) );
2692 module_t *p_id3 = module_need( p_demux, "meta reader", NULL, false );
2695 if( p_demux_meta->p_meta )
2697 vlc_meta_Merge( p_meta, p_demux_meta->p_meta );
2698 vlc_meta_Delete( p_demux_meta->p_meta );
2701 if( p_demux_meta->i_attachments > 0 )
2703 vlc_mutex_lock( &p_input->p->p_item->lock );
2704 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2705 p_demux_meta->i_attachments, p_demux_meta->attachments );
2706 vlc_mutex_unlock( &p_input->p->p_item->lock );
2708 module_unneed( p_demux, p_id3 );
2710 free( p_demux_meta );
2714 static void SlaveDemux( input_thread_t *p_input )
2719 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2721 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2725 for( i = 0; i < p_input->p->i_slave; i++ )
2727 input_source_t *in = p_input->p->slave[i];
2733 if( demux_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2738 if( demux_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2740 msg_Err( p_input, "slave[%d] doesn't like "
2741 "DEMUX_GET_TIME -> EOF", i );
2746 if( i_stime >= i_time )
2749 if( ( i_ret = demux_Demux( in->p_demux ) ) <= 0 )
2755 i_ret = demux_Demux( in->p_demux );
2760 msg_Dbg( p_input, "slave %d EOF", i );
2766 static void SlaveSeek( input_thread_t *p_input )
2771 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2773 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2777 for( i = 0; i < p_input->p->i_slave; i++ )
2779 input_source_t *in = p_input->p->slave[i];
2781 if( demux_Control( in->p_demux, DEMUX_SET_TIME, i_time, true ) )
2784 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2794 /*****************************************************************************
2796 *****************************************************************************/
2797 static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta )
2799 static const struct { int i_meta; const char *psz_name; } p_list[] = {
2800 { vlc_meta_Title, "meta-title" },
2801 { vlc_meta_Artist, "meta-artist" },
2802 { vlc_meta_Genre, "meta-genre" },
2803 { vlc_meta_Copyright, "meta-copyright" },
2804 { vlc_meta_Description, "meta-description" },
2805 { vlc_meta_Date, "meta-date" },
2806 { vlc_meta_URL, "meta-url" },
2810 /* Get meta information from user */
2811 for( int i = 0; p_list[i].psz_name; i++ )
2813 char *psz_string = var_GetNonEmptyString( p_input, p_list[i].psz_name );
2817 EnsureUTF8( psz_string );
2818 vlc_meta_Set( p_meta, p_list[i].i_meta, psz_string );
2823 /*****************************************************************************
2824 * InputUpdateMeta: merge p_item meta data with p_meta taking care of
2825 * arturl and locking issue.
2826 *****************************************************************************/
2827 static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta )
2829 input_item_t *p_item = p_input->p->p_item;
2831 char *psz_title = NULL;
2832 char *psz_arturl = input_item_GetArtURL( p_item );
2834 vlc_mutex_lock( &p_item->lock );
2836 if( vlc_meta_Get( p_meta, vlc_meta_Title ) && !p_item->b_fixed_name )
2837 psz_title = strdup( vlc_meta_Get( p_meta, vlc_meta_Title ) );
2839 vlc_meta_Merge( p_item->p_meta, p_meta );
2841 vlc_meta_Delete( p_meta );
2843 if( !psz_arturl || *psz_arturl == '\0' )
2845 const char *psz_tmp = vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL );
2847 psz_arturl = strdup( psz_tmp );
2849 vlc_mutex_unlock( &p_item->lock );
2851 if( psz_arturl && *psz_arturl )
2853 input_item_SetArtURL( p_item, psz_arturl );
2855 if( !strncmp( psz_arturl, "attachment://", strlen("attachment") ) )
2857 /* Don't look for art cover if sout
2858 * XXX It can change when sout has meta data support */
2859 if( p_input->p->p_sout && !p_input->b_preparsing )
2860 input_item_SetArtURL( p_item, "" );
2862 input_ExtractAttachmentAndCacheArt( p_input );
2869 input_item_SetName( p_item, psz_title );
2872 input_item_SetPreparsed( p_item, true );
2874 input_SendEventMeta( p_input );
2876 /** \todo handle sout meta */
2879 static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
2880 int i_new, input_attachment_t **pp_new )
2882 int i_attachment = *pi_attachment;
2883 input_attachment_t **attachment = *ppp_attachment;
2886 attachment = realloc( attachment,
2887 sizeof(input_attachment_t**) * ( i_attachment + i_new ) );
2888 for( i = 0; i < i_new; i++ )
2889 attachment[i_attachment++] = pp_new[i];
2893 *pi_attachment = i_attachment;
2894 *ppp_attachment = attachment;
2896 /*****************************************************************************
2897 * InputGetExtraFiles
2898 * Autodetect extra input list
2899 *****************************************************************************/
2900 static void InputGetExtraFilesPattern( input_thread_t *p_input,
2901 int *pi_list, char ***pppsz_list,
2902 const char *psz_path,
2903 const char *psz_match,
2904 const char *psz_format,
2905 int i_start, int i_stop )
2910 TAB_INIT( i_list, ppsz_list );
2912 char *psz_base = strdup( psz_path );
2916 /* Remove the extension */
2917 char *psz_end = &psz_base[strlen(psz_base)-strlen(psz_match)];
2918 assert( psz_end >= psz_base);
2921 /* Try to list files */
2922 for( int i = i_start; i <= i_stop; i++ )
2927 if( asprintf( &psz_file, psz_format, psz_base, i ) < 0 )
2930 if( utf8_stat( psz_file, &st ) || !S_ISREG( st.st_mode ) || !st.st_size )
2936 msg_Dbg( p_input, "Detected extra file `%s'", psz_file );
2937 TAB_APPEND( i_list, ppsz_list, psz_file );
2942 *pppsz_list = ppsz_list;
2945 static void InputGetExtraFiles( input_thread_t *p_input,
2946 int *pi_list, char ***pppsz_list,
2947 const char *psz_access, const char *psz_path )
2951 const char *psz_match;
2952 const char *psz_format;
2956 /* XXX the order is important */
2957 { ".001", "%s.%.3d", 2, 999 },
2958 { ".part1.rar", "%s.part%.1d.rar",2, 9 },
2959 { ".part01.rar", "%s.part%.2d.rar",2, 99, },
2960 { ".part001.rar", "%s.part%.3d.rar",2, 999 },
2961 { ".rar", "%s.r%.2d", 1, 99 },
2962 { NULL, NULL, 0, 0 }
2965 TAB_INIT( *pi_list, *pppsz_list );
2967 if( ( psz_access && *psz_access && strcmp( psz_access, "file" ) ) || !psz_path )
2970 const size_t i_path = strlen(psz_path);
2972 for( int i = 0; p_pattern[i].psz_match != NULL; i++ )
2974 const size_t i_ext = strlen(p_pattern[i].psz_match );
2976 if( i_path < i_ext )
2978 if( !strcmp( &psz_path[i_path-i_ext], p_pattern[i].psz_match ) )
2980 InputGetExtraFilesPattern( p_input, pi_list, pppsz_list,
2982 p_pattern[i].psz_match, p_pattern[i].psz_format,
2983 p_pattern[i].i_start, p_pattern[i].i_stop );
2990 static void input_ChangeState( input_thread_t *p_input, int i_state )
2992 const bool b_changed = p_input->p->i_state != i_state;
2994 p_input->p->i_state = i_state;
2995 if( i_state == ERROR_S )
2996 p_input->b_error = true;
2997 else if( i_state == END_S )
2998 p_input->b_eof = true;
3002 input_item_SetErrorWhenReading( p_input->p->p_item, p_input->b_error );
3003 input_SendEventState( p_input, i_state );
3008 /*****************************************************************************
3009 * MRLSplit: parse the access, demux and url part of the
3010 * Media Resource Locator.
3011 *****************************************************************************/
3012 void input_SplitMRL( const char **ppsz_access, const char **ppsz_demux, char **ppsz_path,
3015 char *psz_access = NULL;
3016 char *psz_demux = NULL;
3019 /* Either there is an access/demux specification before ://
3020 * or we have a plain local file path. */
3021 psz_path = strstr( psz_dup, "://" );
3022 if( psz_path != NULL )
3025 psz_path += 3; /* skips "://" */
3027 /* Separate access from demux (<access>/<demux>://<path>) */
3028 psz_access = psz_dup;
3029 psz_demux = strchr( psz_access, '/' );
3031 *psz_demux++ = '\0';
3033 /* We really don't want module name substitution here! */
3034 if( psz_access[0] == '$' )
3036 if( psz_demux && psz_demux[0] == '$' )
3043 *ppsz_access = psz_access ? psz_access : (char*)"";
3044 *ppsz_demux = psz_demux ? psz_demux : (char*)"";
3045 *ppsz_path = psz_path;
3048 static inline bool next(char ** src)
3052 long result = strtol( *src, &end, 0 );
3053 if( errno != 0 || result >= LONG_MAX || result <= LONG_MIN ||
3062 /*****************************************************************************
3063 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
3066 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
3067 *****************************************************************************/
3068 static void MRLSections( input_thread_t *p_input, char *psz_source,
3069 int *pi_title_start, int *pi_title_end,
3070 int *pi_chapter_start, int *pi_chapter_end )
3072 char *psz, *psz_end, *psz_next, *psz_check;
3074 *pi_title_start = *pi_title_end = -1;
3075 *pi_chapter_start = *pi_chapter_end = -1;
3077 /* Start by parsing titles and chapters */
3078 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
3081 /* Check we are really dealing with a title/chapter section */
3082 psz_check = psz + 1;
3083 if( !*psz_check ) return;
3084 if( isdigit(*psz_check) )
3085 if(!next(&psz_check)) return;
3086 if( *psz_check != ':' && *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 != '-' && *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 ) return;
3106 /* Separate start and end */
3108 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
3110 /* Look for the start title */
3111 *pi_title_start = strtol( psz, &psz_next, 0 );
3112 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
3113 *pi_title_end = *pi_title_start;
3116 /* Look for the start chapter */
3118 *pi_chapter_start = strtol( psz, &psz_next, 0 );
3119 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
3120 *pi_chapter_end = *pi_chapter_start;
3124 /* Look for the end title */
3125 *pi_title_end = strtol( psz_end, &psz_next, 0 );
3126 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
3129 /* Look for the end chapter */
3130 if( *psz_end ) psz_end++;
3131 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
3132 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
3135 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
3136 psz_source, *pi_title_start, *pi_chapter_start,
3137 *pi_title_end, *pi_chapter_end );
3140 /*****************************************************************************
3141 * input_AddSubtitles: add a subtitles file and enable it
3142 *****************************************************************************/
3143 static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_forced )
3145 input_source_t *sub;
3148 char *psz_path, *psz_extension;
3150 /* if we are provided a subtitle.sub file,
3151 * see if we don't have a subtitle.idx and use it instead */
3152 psz_path = strdup( psz_subtitle );
3155 psz_extension = strrchr( psz_path, '.');
3156 if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
3160 strcpy( psz_extension, ".idx" );
3162 if( !utf8_stat( psz_path, &st ) && S_ISREG( st.st_mode ) )
3164 msg_Dbg( p_input, "using %s subtitles file instead of %s",
3165 psz_path, psz_subtitle );
3166 strcpy( psz_subtitle, psz_path );
3172 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
3174 sub = InputSourceNew( p_input );
3175 if( !sub || InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
3180 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
3183 if( b_forced && !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
3185 if( count.i_int == 0 )
3187 /* if it was first one, there is disable too */
3189 if( count.i_int < list.p_list->i_count )
3191 const int i_id = list.p_list->p_values[count.i_int].i_int;
3193 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_DEFAULT_BY_ID, i_id );
3194 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, i_id );
3196 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
3200 /*****************************************************************************
3202 *****************************************************************************/
3203 void input_UpdateStatistic( input_thread_t *p_input,
3204 input_statistic_t i_type, int i_delta )
3206 assert( p_input->p->i_state != INIT_S );
3208 vlc_mutex_lock( &p_input->p->counters.counters_lock);
3211 #define I(c) stats_UpdateInteger( p_input, p_input->p->counters.c, i_delta, NULL )
3212 case INPUT_STATISTIC_DECODED_VIDEO:
3215 case INPUT_STATISTIC_DECODED_AUDIO:
3218 case INPUT_STATISTIC_DECODED_SUBTITLE:
3221 case INPUT_STATISTIC_SENT_PACKET:
3222 I(p_sout_sent_packets);
3225 case INPUT_STATISTIC_SENT_BYTE:
3227 int i_bytes; /* That's pretty stupid to define it as an integer, it will overflow
3229 if( !stats_UpdateInteger( p_input, p_input->p->counters.p_sout_sent_bytes, i_delta, &i_bytes ) )
3230 stats_UpdateFloat( p_input, p_input->p->counters.p_sout_send_bitrate, i_bytes, NULL );
3234 msg_Err( p_input, "Invalid statistic type %d (internal error)", i_type );
3237 vlc_mutex_unlock( &p_input->p->counters.counters_lock);
3241 /* TODO FIXME nearly the same logic that snapshot code */
3242 char *input_CreateFilename( vlc_object_t *p_obj, const char *psz_path, const char *psz_prefix, const char *psz_extension )
3247 path = utf8_opendir( psz_path );
3252 char *psz_tmp = str_format( p_obj, psz_prefix );
3256 filename_sanitize( psz_tmp );
3257 if( asprintf( &psz_file, "%s"DIR_SEP"%s%s%s",
3259 psz_extension ? "." : "",
3260 psz_extension ? psz_extension : "" ) < 0 )
3267 psz_file = str_format( p_obj, psz_path );
3268 path_sanitize( psz_file );