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"
46 #include "ressource.h"
49 #include "../stream_output/stream_output.h"
51 #include <vlc_interface.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_ressource_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 ControlPopNoLock( input_thread_t *, int *, vlc_value_t *, mtime_t i_deadline );
77 static void ControlReduce( input_thread_t * );
78 static bool Control( input_thread_t *, int, vlc_value_t );
80 static int UpdateTitleSeekpointFromAccess( input_thread_t * );
81 static void UpdateGenericFromAccess( input_thread_t * );
83 static int UpdateTitleSeekpointFromDemux( input_thread_t * );
84 static void UpdateGenericFromDemux( input_thread_t * );
86 static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
88 static input_source_t *InputSourceNew( input_thread_t *);
89 static int InputSourceInit( input_thread_t *, input_source_t *,
90 const char *, const char *psz_forced_demux );
91 static void InputSourceClean( input_source_t * );
92 static void InputSourceMeta( input_thread_t *, input_source_t *, vlc_meta_t * );
95 //static void InputGetAttachments( input_thread_t *, input_source_t * );
96 static void SlaveDemux( input_thread_t *p_input );
97 static void SlaveSeek( input_thread_t *p_input );
99 static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta );
100 static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta );
101 static void InputGetExtraFiles( input_thread_t *p_input,
102 int *pi_list, char ***pppsz_list,
103 const char *psz_access, const char *psz_path );
105 static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
106 int i_new, input_attachment_t **pp_new );
108 static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_forced );
110 static void input_ChangeState( input_thread_t *p_input, int i_state ); /* TODO fix name */
112 /*****************************************************************************
113 * This function creates a new input, and returns a pointer
114 * to its description. On error, it returns NULL.
116 * XXX Do not forget to update vlc_input.h if you add new variables.
117 *****************************************************************************/
118 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
119 const char *psz_header, bool b_quick,
120 input_ressource_t *p_ressource )
122 static const char input_name[] = "input";
123 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 /* One "randomly" selected input thread is responsible for computing
153 * the global stats. Check if there is already someone doing this */
154 if( p_input->p_libvlc->p_stats && !b_quick )
156 libvlc_priv_t *p_private = libvlc_priv( p_input->p_libvlc );
157 vlc_mutex_lock( &p_input->p_libvlc->p_stats->lock );
158 if( p_private->p_stats_computer == NULL )
159 p_private->p_stats_computer = p_input;
160 vlc_mutex_unlock( &p_input->p_libvlc->p_stats->lock );
163 p_input->b_preparsing = b_quick;
164 p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
166 /* Init Common fields */
167 p_input->b_eof = false;
168 p_input->p->b_can_pace_control = true;
169 p_input->p->i_start = 0;
170 p_input->p->i_time = 0;
171 p_input->p->i_stop = 0;
172 p_input->p->i_run = 0;
173 p_input->p->i_title = 0;
174 p_input->p->title = NULL;
175 p_input->p->i_title_offset = p_input->p->i_seekpoint_offset = 0;
176 p_input->p->i_state = INIT_S;
177 p_input->p->i_rate = INPUT_RATE_DEFAULT;
178 p_input->p->b_recording = false;
179 memset( &p_input->p->bookmark, 0, sizeof(p_input->p->bookmark) );
180 TAB_INIT( p_input->p->i_bookmark, p_input->p->pp_bookmark );
181 TAB_INIT( p_input->p->i_attachment, p_input->p->attachment );
182 p_input->p->p_es_out_display = NULL;
183 p_input->p->p_es_out = NULL;
184 p_input->p->p_sout = NULL;
185 p_input->p->b_out_pace_control = false;
186 p_input->p->i_pts_delay = 0;
187 p_input->p->i_cr_average = 0;
189 vlc_gc_incref( p_item ); /* Released in Destructor() */
190 p_input->p->p_item = p_item;
192 /* Init Input fields */
193 p_input->p->input.p_access = NULL;
194 p_input->p->input.p_stream = NULL;
195 p_input->p->input.p_demux = NULL;
196 p_input->p->input.b_title_demux = false;
197 p_input->p->input.i_title = 0;
198 p_input->p->input.title = NULL;
199 p_input->p->input.i_title_offset = p_input->p->input.i_seekpoint_offset = 0;
200 p_input->p->input.b_can_pace_control = true;
201 p_input->p->input.b_can_rate_control = true;
202 p_input->p->input.b_rescale_ts = true;
203 p_input->p->input.b_eof = false;
205 vlc_mutex_lock( &p_item->lock );
207 if( !p_item->p_stats )
208 p_item->p_stats = stats_NewInputStats( p_input );
209 vlc_mutex_unlock( &p_item->lock );
212 p_input->p->i_slave = 0;
213 p_input->p->slave = NULL;
217 p_input->p->p_ressource = p_ressource;
219 p_input->p->p_ressource = input_ressource_New();
220 input_ressource_SetInput( p_input->p->p_ressource, p_input );
222 /* Init control buffer */
223 vlc_mutex_init( &p_input->p->lock_control );
224 vlc_cond_init( &p_input->p->wait_control );
225 p_input->p->i_control = 0;
227 /* Parse input options */
228 vlc_mutex_lock( &p_item->lock );
229 assert( (int)p_item->optflagc == p_item->i_options );
230 for( i = 0; i < p_item->i_options; i++ )
231 var_OptionParse( VLC_OBJECT(p_input), p_item->ppsz_options[i],
232 !!(p_item->optflagv[i] & VLC_INPUT_OPTION_TRUSTED) );
233 vlc_mutex_unlock( &p_item->lock );
235 /* Create Object Variables for private use only */
236 input_ConfigVarInit( p_input );
238 /* Create Objects variables for public Get and Set */
239 input_ControlVarInit( p_input );
242 p_input->p->i_cr_average = var_GetInteger( p_input, "cr-average" );
244 if( !p_input->b_preparsing )
246 var_Get( p_input, "bookmarks", &val );
249 /* FIXME: have a common cfg parsing routine used by sout and others */
250 char *psz_parser, *psz_start, *psz_end;
251 psz_parser = val.psz_string;
252 while( (psz_start = strchr( psz_parser, '{' ) ) )
254 seekpoint_t *p_seekpoint;
257 psz_end = strchr( psz_start, '}' );
258 if( !psz_end ) break;
259 psz_parser = psz_end + 1;
260 backup = *psz_parser;
264 p_seekpoint = vlc_seekpoint_New();
265 while( (psz_end = strchr( psz_start, ',' ) ) )
268 if( !strncmp( psz_start, "name=", 5 ) )
270 p_seekpoint->psz_name = strdup(psz_start + 5);
272 else if( !strncmp( psz_start, "bytes=", 6 ) )
274 p_seekpoint->i_byte_offset = atoll(psz_start + 6);
276 else if( !strncmp( psz_start, "time=", 5 ) )
278 p_seekpoint->i_time_offset = atoll(psz_start + 5) *
281 psz_start = psz_end + 1;
283 msg_Dbg( p_input, "adding bookmark: %s, bytes=%"PRId64", time=%"PRId64,
284 p_seekpoint->psz_name, p_seekpoint->i_byte_offset,
285 p_seekpoint->i_time_offset );
286 input_Control( p_input, INPUT_ADD_BOOKMARK, p_seekpoint );
287 vlc_seekpoint_Delete( p_seekpoint );
288 *psz_parser = backup;
290 free( val.psz_string );
294 /* Remove 'Now playing' info as it is probably outdated */
295 input_item_SetNowPlaying( p_item, NULL );
296 input_SendEventMeta( p_input );
299 if( p_input->b_preparsing )
300 p_input->i_flags |= OBJECT_FLAGS_QUIET | OBJECT_FLAGS_NOINTERACT;
303 memset( &p_input->p->counters, 0, sizeof( p_input->p->counters ) );
304 vlc_mutex_init( &p_input->p->counters.counters_lock );
306 /* Set the destructor when we are sure we are initialized */
307 vlc_object_set_destructor( p_input, (vlc_destructor_t)Destructor );
309 /* Attach only once we are ready */
310 vlc_object_attach( p_input, p_parent );
316 * Input destructor (called when the object's refcount reaches 0).
318 static void Destructor( input_thread_t * p_input )
321 char * psz_name = input_item_GetName( p_input->p->p_item );
322 msg_Dbg( p_input, "Destroying the input for '%s'", psz_name);
326 stats_TimerDump( p_input, STATS_TIMER_INPUT_LAUNCHING );
327 stats_TimerClean( p_input, STATS_TIMER_INPUT_LAUNCHING );
329 if( p_input->p->p_ressource )
330 input_ressource_Delete( p_input->p->p_ressource );
332 vlc_gc_decref( p_input->p->p_item );
334 vlc_mutex_destroy( &p_input->p->counters.counters_lock );
336 vlc_cond_destroy( &p_input->p->wait_control );
337 vlc_mutex_destroy( &p_input->p->lock_control );
342 * Initialize an input thread and run it. You will need to monitor the
343 * thread to clean up after it is done
345 * \param p_parent a vlc_object
346 * \param p_item an input item
347 * \return a pointer to the spawned input thread
349 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
350 input_item_t *p_item )
352 return __input_CreateThreadExtended( p_parent, p_item, NULL, NULL );
356 input_thread_t *__input_CreateThreadExtended( vlc_object_t *p_parent,
357 input_item_t *p_item,
358 const char *psz_log, input_ressource_t *p_ressource )
360 input_thread_t *p_input;
362 p_input = Create( p_parent, p_item, psz_log, false, p_ressource );
366 /* Create thread and wait for its readiness. */
367 if( vlc_thread_create( p_input, "input", Run,
368 VLC_THREAD_PRIORITY_INPUT ) )
370 input_ChangeState( p_input, ERROR_S );
371 msg_Err( p_input, "cannot create input thread" );
372 vlc_object_detach( p_input );
373 vlc_object_release( p_input );
381 * Initialize an input thread and run it. This thread will clean after itself,
382 * you can forget about it. It can work either in blocking or non-blocking mode
384 * \param p_parent a vlc_object
385 * \param p_item an input item
386 * \param b_block should we block until read is finished ?
387 * \return an error code, VLC_SUCCESS on success
389 int __input_Read( vlc_object_t *p_parent, input_item_t *p_item,
392 input_thread_t *p_input;
394 p_input = Create( p_parent, p_item, NULL, false, NULL );
400 RunAndDestroy( VLC_OBJECT(p_input) );
405 if( vlc_thread_create( p_input, "input", RunAndDestroy,
406 VLC_THREAD_PRIORITY_INPUT ) )
408 input_ChangeState( p_input, ERROR_S );
409 msg_Err( p_input, "cannot create input thread" );
410 vlc_object_release( p_input );
418 * Initialize an input and initialize it to preparse the item
419 * This function is blocking. It will only accept to parse files
421 * \param p_parent a vlc_object_t
422 * \param p_item an input item
423 * \return VLC_SUCCESS or an error
425 int __input_Preparse( vlc_object_t *p_parent, input_item_t *p_item )
427 input_thread_t *p_input;
429 /* Allocate descriptor */
430 p_input = Create( p_parent, p_item, NULL, true, NULL );
434 if( !Init( p_input ) )
437 vlc_object_detach( p_input );
438 vlc_object_release( p_input );
444 * Request a running input thread to stop and die
446 * \param the input thread to stop
448 void input_StopThread( input_thread_t *p_input )
450 /* Set die for input and ALL of this childrens (even (grand-)grand-childrens)
451 * It is needed here even if it is done in INPUT_CONTROL_SET_DIE handler to
452 * unlock the control loop */
453 ObjectKillChildrens( p_input, VLC_OBJECT(p_input) );
455 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
458 input_ressource_t *input_DetachRessource( input_thread_t *p_input )
460 assert( p_input->b_dead );
462 input_ressource_t *p_ressource = p_input->p->p_ressource;
463 input_ressource_SetInput( p_ressource, NULL );
465 p_input->p->p_ressource = NULL;
466 p_input->p->p_sout = NULL;
472 * Get the item from an input thread
473 * FIXME it does not increase ref count of the item.
474 * if it is used after p_input is destroyed nothing prevent it from
477 input_item_t *input_GetItem( input_thread_t *p_input )
479 assert( p_input && p_input->p );
480 return p_input->p->p_item;
483 /*****************************************************************************
484 * ObjectKillChildrens
485 *****************************************************************************/
486 static void ObjectKillChildrens( input_thread_t *p_input, vlc_object_t *p_obj )
491 /* FIXME ObjectKillChildrens seems a very bad idea in fact */
492 i = vlc_internals( p_obj )->i_object_type;
493 if( i == VLC_OBJECT_VOUT ||i == VLC_OBJECT_AOUT ||
494 p_obj == VLC_OBJECT(p_input->p->p_sout) ||
495 i == VLC_OBJECT_DECODER || i == VLC_OBJECT_PACKETIZER )
498 vlc_object_kill( p_obj );
500 p_list = vlc_list_children( p_obj );
501 for( i = 0; i < p_list->i_count; i++ )
502 ObjectKillChildrens( p_input, p_list->p_values[i].p_object );
503 vlc_list_release( p_list );
506 /*****************************************************************************
507 * Run: main thread loop
508 * This is the "normal" thread that spawns the input processing chain,
509 * reads the stream, cleans up and waits
510 *****************************************************************************/
511 static void *Run( vlc_object_t *p_this )
513 input_thread_t *p_input = (input_thread_t *)p_this;
514 const int canc = vlc_savecancel();
516 if( Init( p_input ) )
525 /* Tell we're dead */
526 input_SendEventDead( p_input );
527 vlc_restorecancel( canc );
531 /*****************************************************************************
532 * RunAndDestroy: main thread loop
533 * This is the "just forget me" thread that spawns the input processing chain,
534 * reads the stream, cleans up and releases memory
535 *****************************************************************************/
536 static void *RunAndDestroy( vlc_object_t *p_this )
538 input_thread_t *p_input = (input_thread_t *)p_this;
539 const int canc = vlc_savecancel();
541 if( Init( p_input ) )
551 vlc_object_release( p_input );
552 vlc_restorecancel( canc );
556 /*****************************************************************************
557 * Main loop: Fill buffers from access, and demux
558 *****************************************************************************/
562 * It asks the demuxer to demux some data
564 static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed, mtime_t *pi_start_mdate )
570 if( ( p_input->p->i_stop > 0 && p_input->p->i_time >= p_input->p->i_stop ) ||
571 ( p_input->p->i_run > 0 && *pi_start_mdate+p_input->p->i_run < mdate() ) )
574 i_ret = demux_Demux( p_input->p->input.p_demux );
578 if( p_input->p->input.p_demux->info.i_update )
580 if( p_input->p->input.b_title_demux )
582 i_ret = UpdateTitleSeekpointFromDemux( p_input );
585 UpdateGenericFromDemux( p_input );
587 else if( p_input->p->input.p_access &&
588 p_input->p->input.p_access->info.i_update )
590 if( !p_input->p->input.b_title_demux )
592 i_ret = UpdateTitleSeekpointFromAccess( p_input );
595 UpdateGenericFromAccess( p_input );
599 if( i_ret == 0 ) /* EOF */
603 var_Get( p_input, "input-repeat", &repeat );
604 if( repeat.i_int == 0 )
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)",
617 if( repeat.i_int > 0 )
620 var_Set( p_input, "input-repeat", repeat );
623 /* Seek to start title/seekpoint */
624 val.i_int = p_input->p->input.i_title_start -
625 p_input->p->input.i_title_offset;
626 if( val.i_int < 0 || val.i_int >= p_input->p->input.i_title )
628 input_ControlPush( p_input,
629 INPUT_CONTROL_SET_TITLE, &val );
631 val.i_int = p_input->p->input.i_seekpoint_start -
632 p_input->p->input.i_seekpoint_offset;
633 if( val.i_int > 0 /* TODO: check upper boundary */ )
634 input_ControlPush( p_input,
635 INPUT_CONTROL_SET_SEEKPOINT, &val );
637 /* Seek to start position */
638 if( p_input->p->i_start > 0 )
640 val.i_time = p_input->p->i_start;
641 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME,
647 input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
652 *pi_start_mdate = mdate();
657 input_ChangeState( p_input, ERROR_S );
660 if( i_ret > 0 && p_input->p->i_slave > 0 )
662 SlaveDemux( p_input );
668 * It update the variables used by the interfaces
670 static void MainLoopInterface( input_thread_t *p_input )
672 double f_position = 0.0;
674 mtime_t i_length = 0;
676 /* update input status variables */
677 if( demux_Control( p_input->p->input.p_demux,
678 DEMUX_GET_POSITION, &f_position ) )
681 if( demux_Control( p_input->p->input.p_demux,
682 DEMUX_GET_TIME, &i_time ) )
684 p_input->p->i_time = i_time;
686 if( demux_Control( p_input->p->input.p_demux,
687 DEMUX_GET_LENGTH, &i_length ) )
690 es_out_SetTimes( p_input->p->p_es_out, f_position, i_time, i_length );
692 /* update current bookmark */
693 vlc_mutex_lock( &p_input->p->p_item->lock );
694 p_input->p->bookmark.i_time_offset = i_time;
695 if( p_input->p->input.p_stream )
696 p_input->p->bookmark.i_byte_offset = stream_Tell( p_input->p->input.p_stream );
697 vlc_mutex_unlock( &p_input->p->p_item->lock );
702 * It updates the globals statics
704 static void MainLoopStatistic( input_thread_t *p_input )
706 stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
707 /* Are we the thread responsible for computing global stats ? */
708 if( libvlc_priv( p_input->p_libvlc )->p_stats_computer == p_input )
710 stats_ComputeGlobalStats( p_input->p_libvlc,
711 p_input->p_libvlc->p_stats );
713 input_SendEventStatistics( p_input );
718 * The main input loop.
720 static void MainLoop( input_thread_t *p_input )
722 mtime_t i_start_mdate = mdate();
723 mtime_t i_intf_update = 0;
724 mtime_t i_statistic_update = 0;
726 /* Start the timer */
727 stats_TimerStop( p_input, STATS_TIMER_INPUT_LAUNCHING );
729 while( vlc_object_alive( p_input ) && !p_input->b_error )
740 b_force_update = false;
742 /* FIXME if p_input->p->i_state == PAUSE_S the access/access_demux
743 * is paused -> this may cause problem with some of them
744 * The same problem can be seen when seeking while paused */
745 b_paused = p_input->p->i_state == PAUSE_S &&
746 !es_out_GetBuffering( p_input->p->p_es_out );
750 if( !p_input->p->input.b_eof )
752 MainLoopDemux( p_input, &b_force_update, &i_start_mdate );
754 i_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
756 else if( !p_input->b_eof && !es_out_GetEmpty( p_input->p->p_es_out ) )
758 msg_Dbg( p_input, "waiting decoder fifos to empty" );
759 i_wakeup = mdate() + INPUT_IDLE_SLEEP;
769 i_deadline = i_wakeup;
771 i_deadline = __MIN( i_intf_update, i_statistic_update );
774 vlc_mutex_lock( &p_input->p->lock_control );
775 ControlReduce( p_input );
776 while( !ControlPopNoLock( p_input, &i_type, &val, i_deadline ) )
778 msg_Dbg( p_input, "control type=%d", i_type );
780 if( Control( p_input, i_type, val ) )
781 b_force_update = true;
783 vlc_mutex_unlock( &p_input->p->lock_control );
785 /* Update interface and statistics */
787 if( i_intf_update < i_current || b_force_update )
789 MainLoopInterface( p_input );
790 i_intf_update = i_current + INT64_C(250000);
791 b_force_update = false;
793 if( i_statistic_update < i_current )
795 MainLoopStatistic( p_input );
796 i_statistic_update = i_current + INT64_C(1000000);
799 /* Check if i_wakeup is still valid */
802 mtime_t i_new_wakeup = es_out_GetWakeup( p_input->p->p_es_out );
806 } while( i_current < i_wakeup );
809 if( !p_input->b_error )
810 input_ChangeState( p_input, END_S );
813 static void InitStatistics( input_thread_t * p_input )
815 if( p_input->b_preparsing ) return;
817 /* Prepare statistics */
818 #define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \
819 stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
820 if( libvlc_stats( p_input ) )
822 INIT_COUNTER( read_bytes, INTEGER, COUNTER );
823 INIT_COUNTER( read_packets, INTEGER, COUNTER );
824 INIT_COUNTER( demux_read, INTEGER, COUNTER );
825 INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE );
826 INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE );
827 INIT_COUNTER( played_abuffers, INTEGER, COUNTER );
828 INIT_COUNTER( lost_abuffers, INTEGER, COUNTER );
829 INIT_COUNTER( displayed_pictures, INTEGER, COUNTER );
830 INIT_COUNTER( lost_pictures, INTEGER, COUNTER );
831 INIT_COUNTER( decoded_audio, INTEGER, COUNTER );
832 INIT_COUNTER( decoded_video, INTEGER, COUNTER );
833 INIT_COUNTER( decoded_sub, INTEGER, COUNTER );
834 p_input->p->counters.p_sout_send_bitrate = NULL;
835 p_input->p->counters.p_sout_sent_packets = NULL;
836 p_input->p->counters.p_sout_sent_bytes = NULL;
837 if( p_input->p->counters.p_demux_bitrate )
838 p_input->p->counters.p_demux_bitrate->update_interval = 1000000;
839 if( p_input->p->counters.p_input_bitrate )
840 p_input->p->counters.p_input_bitrate->update_interval = 1000000;
845 static int InitSout( input_thread_t * p_input )
847 if( p_input->b_preparsing )
850 /* Find a usable sout and attach it to p_input */
851 char *psz = var_GetNonEmptyString( p_input, "sout" );
852 if( psz && strncasecmp( p_input->p->p_item->psz_uri, "vlc:", 4 ) )
854 p_input->p->p_sout = input_ressource_RequestSout( p_input->p->p_ressource, NULL, psz );
855 if( !p_input->p->p_sout )
857 input_ChangeState( p_input, ERROR_S );
858 msg_Err( p_input, "cannot start stream output instance, " \
863 if( libvlc_stats( p_input ) )
865 INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
866 INIT_COUNTER( sout_sent_bytes, INTEGER, COUNTER );
867 INIT_COUNTER( sout_send_bitrate, FLOAT, DERIVATIVE );
868 if( p_input->p->counters.p_sout_send_bitrate )
869 p_input->p->counters.p_sout_send_bitrate->update_interval =
875 input_ressource_RequestSout( p_input->p->p_ressource, NULL, NULL );
883 static void InitTitle( input_thread_t * p_input )
885 input_source_t *p_master = &p_input->p->input;
887 if( p_input->b_preparsing )
890 /* Create global title (from master) */
891 p_input->p->i_title = p_master->i_title;
892 p_input->p->title = p_master->title;
893 p_input->p->i_title_offset = p_master->i_title_offset;
894 p_input->p->i_seekpoint_offset = p_master->i_seekpoint_offset;
895 if( p_input->p->i_title > 0 )
897 /* Setup variables */
898 input_ControlVarNavigation( p_input );
899 input_ControlVarTitle( p_input, 0 );
903 p_input->p->b_can_pace_control = p_master->b_can_pace_control;
904 p_input->p->b_can_pause = p_master->b_can_pause;
905 p_input->p->b_can_rate_control = p_master->b_can_rate_control;
908 if( p_input->p->i_pts_delay < 0 )
909 p_input->p->i_pts_delay = 0;
911 /* If the desynchronisation requested by the user is < 0, we need to
912 * cache more data. */
913 const int i_desynch = var_GetInteger( p_input, "audio-desync" );
915 p_input->p->i_pts_delay -= i_desynch * 1000;
917 /* Update cr_average depending on the caching */
918 p_input->p->i_cr_average *= (10 * p_input->p->i_pts_delay / 200000);
919 p_input->p->i_cr_average /= 10;
920 if( p_input->p->i_cr_average < 10 )
921 p_input->p->i_cr_average = 10;
924 static void StartTitle( input_thread_t * p_input )
928 /* Start title/chapter */
929 val.i_int = p_input->p->input.i_title_start -
930 p_input->p->input.i_title_offset;
931 if( val.i_int > 0 && val.i_int < p_input->p->input.i_title )
932 input_ControlPush( p_input, INPUT_CONTROL_SET_TITLE, &val );
934 val.i_int = p_input->p->input.i_seekpoint_start -
935 p_input->p->input.i_seekpoint_offset;
936 if( val.i_int > 0 /* TODO: check upper boundary */ )
937 input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &val );
939 /* Start/stop/run time */
940 p_input->p->i_start = INT64_C(1000000) * var_GetInteger( p_input, "start-time" );
941 p_input->p->i_stop = INT64_C(1000000) * var_GetInteger( p_input, "stop-time" );
942 p_input->p->i_run = INT64_C(1000000) * var_GetInteger( p_input, "run-time" );
943 if( p_input->p->i_run < 0 )
945 msg_Warn( p_input, "invalid run-time ignored" );
946 p_input->p->i_run = 0;
949 const mtime_t i_length = var_GetTime( p_input, "length" );
950 if( p_input->p->i_start > 0 )
952 if( p_input->p->i_start >= i_length )
954 msg_Warn( p_input, "invalid start-time ignored" );
960 msg_Dbg( p_input, "starting at time: %ds",
961 (int)( p_input->p->i_start / INT64_C(1000000) ) );
963 s.i_time = p_input->p->i_start;
964 input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &s );
967 if( p_input->p->i_stop > 0 && p_input->p->i_stop <= p_input->p->i_start )
969 msg_Warn( p_input, "invalid stop-time ignored" );
970 p_input->p->i_stop = 0;
974 static void LoadSubtitles( input_thread_t *p_input )
977 /* Get fps and set it if not already set */
978 const double f_fps = p_input->p->f_fps;
981 float f_requested_fps;
983 var_Create( p_input, "sub-original-fps", VLC_VAR_FLOAT );
984 var_SetFloat( p_input, "sub-original-fps", f_fps );
986 f_requested_fps = var_CreateGetFloat( p_input, "sub-fps" );
987 if( f_requested_fps != f_fps )
989 var_Create( p_input, "sub-fps", VLC_VAR_FLOAT|
991 var_SetFloat( p_input, "sub-fps", f_requested_fps );
995 const int i_delay = var_CreateGetInteger( p_input, "sub-delay" );
997 var_SetTime( p_input, "spu-delay", (mtime_t)i_delay * 100000 );
999 /* Look for and add subtitle files */
1000 char *psz_subtitle = var_GetNonEmptyString( p_input, "sub-file" );
1001 if( psz_subtitle != NULL )
1003 msg_Dbg( p_input, "forced subtitle: %s", psz_subtitle );
1004 SubtitleAdd( p_input, psz_subtitle, true );
1007 if( var_GetBool( p_input, "sub-autodetect-file" ) )
1009 char *psz_autopath = var_GetNonEmptyString( p_input, "sub-autodetect-path" );
1010 char **ppsz_subs = subtitles_Detect( p_input, psz_autopath,
1011 p_input->p->p_item->psz_uri );
1012 free( psz_autopath );
1014 for( int i = 0; ppsz_subs && ppsz_subs[i]; i++ )
1016 /* Try to autoselect the first autodetected subtitles file
1017 * if no subtitles file was specified */
1018 bool b_forced = i == 0 && !psz_subtitle;
1020 if( !psz_subtitle || strcmp( psz_subtitle, ppsz_subs[i] ) )
1021 SubtitleAdd( p_input, ppsz_subs[i], b_forced );
1023 free( ppsz_subs[i] );
1027 free( psz_subtitle );
1030 static void LoadSlaves( input_thread_t *p_input )
1032 char *psz = var_GetNonEmptyString( p_input, "input-slave" );
1036 char *psz_org = psz;
1037 while( psz && *psz )
1039 while( *psz == ' ' || *psz == '#' )
1042 char *psz_delim = strchr( psz, '#' );
1044 *psz_delim++ = '\0';
1049 msg_Dbg( p_input, "adding slave input '%s'", psz );
1051 input_source_t *p_slave = InputSourceNew( p_input );
1052 if( p_slave && !InputSourceInit( p_input, p_slave, psz, NULL ) )
1053 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, p_slave );
1062 static void InitPrograms( input_thread_t * p_input )
1068 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, true );
1069 i_es_out_mode = ES_OUT_MODE_AUTO;
1071 if( p_input->p->p_sout )
1073 var_Get( p_input, "sout-all", &val );
1076 i_es_out_mode = ES_OUT_MODE_ALL;
1081 var_Get( p_input, "programs", &val );
1082 if( val.p_list && val.p_list->i_count )
1084 i_es_out_mode = ES_OUT_MODE_PARTIAL;
1085 /* Note : we should remove the "program" callback. */
1089 var_Change( p_input, "programs", VLC_VAR_FREELIST, &val,
1094 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, i_es_out_mode );
1096 /* Inform the demuxer about waited group (needed only for DVB) */
1097 if( i_es_out_mode == ES_OUT_MODE_ALL )
1099 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1, NULL );
1101 else if( i_es_out_mode == ES_OUT_MODE_PARTIAL )
1103 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1,
1108 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP,
1109 (int) var_GetInteger( p_input, "program" ), NULL );
1113 static int Init( input_thread_t * p_input )
1118 for( i = 0; i < p_input->p->p_item->i_options; i++ )
1120 if( !strncmp( p_input->p->p_item->ppsz_options[i], "meta-file", 9 ) )
1122 msg_Dbg( p_input, "Input is a meta file: disabling unneeded options" );
1123 var_SetString( p_input, "sout", "" );
1124 var_SetBool( p_input, "sout-all", false );
1125 var_SetString( p_input, "input-slave", "" );
1126 var_SetInteger( p_input, "input-repeat", 0 );
1127 var_SetString( p_input, "sub-file", "" );
1128 var_SetBool( p_input, "sub-autodetect-file", false );
1132 InitStatistics( p_input );
1134 ret = InitSout( p_input );
1135 if( ret != VLC_SUCCESS )
1136 return ret; /* FIXME: goto error; should be better here */
1140 p_input->p->p_es_out_display = input_EsOutNew( p_input, p_input->p->i_rate );
1141 p_input->p->p_es_out = input_EsOutTimeshiftNew( p_input, p_input->p->p_es_out_display, p_input->p->i_rate );
1142 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, false );
1143 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
1145 var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
1146 var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
1149 input_ChangeState( p_input, OPENING_S );
1150 input_SendEventCache( p_input, 0.0 );
1153 if( InputSourceInit( p_input, &p_input->p->input,
1154 p_input->p->p_item->psz_uri, NULL ) )
1159 InitTitle( p_input );
1161 /* Load master infos */
1164 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_LENGTH,
1168 i_length = input_item_GetDuration( p_input->p->p_item );
1169 input_SendEventTimes( p_input, 0.0, 0, i_length );
1171 if( !p_input->b_preparsing )
1173 StartTitle( p_input );
1174 LoadSubtitles( p_input );
1175 LoadSlaves( p_input );
1176 InitPrograms( p_input );
1179 if( !p_input->b_preparsing && p_input->p->p_sout )
1181 p_input->p->b_out_pace_control = (p_input->p->p_sout->i_out_pace_nocontrol > 0);
1183 if( p_input->p->b_can_pace_control && p_input->p->b_out_pace_control )
1185 /* We don't want a high input priority here or we'll
1186 * end-up sucking up all the CPU time */
1187 vlc_thread_set_priority( p_input, VLC_THREAD_PRIORITY_LOW );
1190 msg_Dbg( p_input, "starting in %s mode",
1191 p_input->p->b_out_pace_control ? "async" : "sync" );
1194 p_meta = vlc_meta_New();
1197 /* Get meta data from users */
1198 InputMetaUser( p_input, p_meta );
1200 /* Get meta data from master input */
1201 InputSourceMeta( p_input, &p_input->p->input, p_meta );
1203 /* And from slave */
1204 for( int i = 0; i < p_input->p->i_slave; i++ )
1205 InputSourceMeta( p_input, p_input->p->slave[i], p_meta );
1208 InputUpdateMeta( p_input, p_meta );
1211 if( !p_input->b_preparsing )
1213 msg_Dbg( p_input, "`%s' successfully opened",
1214 p_input->p->p_item->psz_uri );
1218 /* initialization is complete */
1219 input_ChangeState( p_input, PLAYING_S );
1224 input_ChangeState( p_input, ERROR_S );
1226 if( p_input->p->p_es_out )
1227 es_out_Delete( p_input->p->p_es_out );
1228 if( p_input->p->p_es_out_display )
1229 es_out_Delete( p_input->p->p_es_out_display );
1230 if( p_input->p->p_ressource )
1232 if( p_input->p->p_sout )
1233 input_ressource_RequestSout( p_input->p->p_ressource,
1234 p_input->p->p_sout, NULL );
1235 input_ressource_SetInput( p_input->p->p_ressource, NULL );
1238 if( !p_input->b_preparsing && libvlc_stats( p_input ) )
1240 #define EXIT_COUNTER( c ) do { if( p_input->p->counters.p_##c ) \
1241 stats_CounterClean( p_input->p->counters.p_##c );\
1242 p_input->p->counters.p_##c = NULL; } while(0)
1243 EXIT_COUNTER( read_bytes );
1244 EXIT_COUNTER( read_packets );
1245 EXIT_COUNTER( demux_read );
1246 EXIT_COUNTER( input_bitrate );
1247 EXIT_COUNTER( demux_bitrate );
1248 EXIT_COUNTER( played_abuffers );
1249 EXIT_COUNTER( lost_abuffers );
1250 EXIT_COUNTER( displayed_pictures );
1251 EXIT_COUNTER( lost_pictures );
1252 EXIT_COUNTER( decoded_audio );
1253 EXIT_COUNTER( decoded_video );
1254 EXIT_COUNTER( decoded_sub );
1256 if( p_input->p->p_sout )
1258 EXIT_COUNTER( sout_sent_packets );
1259 EXIT_COUNTER( sout_sent_bytes );
1260 EXIT_COUNTER( sout_send_bitrate );
1265 /* Mark them deleted */
1266 p_input->p->input.p_demux = NULL;
1267 p_input->p->input.p_stream = NULL;
1268 p_input->p->input.p_access = NULL;
1269 p_input->p->p_es_out = NULL;
1270 p_input->p->p_es_out_display = NULL;
1271 p_input->p->p_sout = NULL;
1273 return VLC_EGENERIC;
1276 /*****************************************************************************
1277 * End: end the input thread
1278 *****************************************************************************/
1279 static void End( input_thread_t * p_input )
1283 /* We are at the end */
1284 input_ChangeState( p_input, END_S );
1286 /* Clean control variables */
1287 input_ControlVarStop( p_input );
1289 /* Stop es out activity */
1290 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_ACTIVE, false );
1291 es_out_Control( p_input->p->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
1293 /* Clean up master */
1294 InputSourceClean( &p_input->p->input );
1297 for( i = 0; i < p_input->p->i_slave; i++ )
1299 InputSourceClean( p_input->p->slave[i] );
1300 free( p_input->p->slave[i] );
1302 free( p_input->p->slave );
1304 /* Unload all modules */
1305 if( p_input->p->p_es_out )
1306 es_out_Delete( p_input->p->p_es_out );
1307 if( p_input->p->p_es_out_display )
1308 es_out_Delete( p_input->p->p_es_out_display );
1310 if( !p_input->b_preparsing )
1312 #define CL_CO( c ) stats_CounterClean( p_input->p->counters.p_##c ); p_input->p->counters.p_##c = NULL;
1313 if( libvlc_stats( p_input ) )
1315 libvlc_priv_t *p_private = libvlc_priv( p_input->p_libvlc );
1317 /* make sure we are up to date */
1318 stats_ComputeInputStats( p_input, p_input->p->p_item->p_stats );
1319 if( p_private->p_stats_computer == p_input )
1321 stats_ComputeGlobalStats( p_input->p_libvlc,
1322 p_input->p_libvlc->p_stats );
1323 /* FIXME how can it be thread safe ? */
1324 p_private->p_stats_computer = NULL;
1326 CL_CO( read_bytes );
1327 CL_CO( read_packets );
1328 CL_CO( demux_read );
1329 CL_CO( input_bitrate );
1330 CL_CO( demux_bitrate );
1331 CL_CO( played_abuffers );
1332 CL_CO( lost_abuffers );
1333 CL_CO( displayed_pictures );
1334 CL_CO( lost_pictures );
1335 CL_CO( decoded_audio) ;
1336 CL_CO( decoded_video );
1337 CL_CO( decoded_sub) ;
1340 /* Close optional stream output instance */
1341 if( p_input->p->p_sout )
1343 CL_CO( sout_sent_packets );
1344 CL_CO( sout_sent_bytes );
1345 CL_CO( sout_send_bitrate );
1350 if( p_input->p->i_attachment > 0 )
1352 for( i = 0; i < p_input->p->i_attachment; i++ )
1353 vlc_input_attachment_Delete( p_input->p->attachment[i] );
1354 TAB_CLEAN( p_input->p->i_attachment, p_input->p->attachment );
1358 input_ressource_RequestSout( p_input->p->p_ressource,
1359 p_input->p->p_sout, NULL );
1360 input_ressource_SetInput( p_input->p->p_ressource, NULL );
1363 /*****************************************************************************
1365 *****************************************************************************/
1366 void input_ControlPush( input_thread_t *p_input,
1367 int i_type, vlc_value_t *p_val )
1369 vlc_mutex_lock( &p_input->p->lock_control );
1370 if( i_type == INPUT_CONTROL_SET_DIE )
1372 /* Special case, empty the control */
1373 p_input->p->i_control = 1;
1374 p_input->p->control[0].i_type = i_type;
1375 memset( &p_input->p->control[0].val, 0, sizeof( vlc_value_t ) );
1377 else if( p_input->p->i_control >= INPUT_CONTROL_FIFO_SIZE )
1379 msg_Err( p_input, "input control fifo overflow, trashing type=%d",
1384 p_input->p->control[p_input->p->i_control].i_type = i_type;
1386 p_input->p->control[p_input->p->i_control].val = *p_val;
1388 memset( &p_input->p->control[p_input->p->i_control].val, 0,
1389 sizeof( vlc_value_t ) );
1391 p_input->p->i_control++;
1393 vlc_cond_signal( &p_input->p->wait_control );
1394 vlc_mutex_unlock( &p_input->p->lock_control );
1397 static inline int ControlPopNoLock( input_thread_t *p_input,
1398 int *pi_type, vlc_value_t *p_val,
1399 mtime_t i_deadline )
1402 while( p_input->p->i_control <= 0 )
1404 if( !vlc_object_alive( p_input ) )
1405 return VLC_EGENERIC;
1407 if( i_deadline < 0 )
1408 return VLC_EGENERIC;
1410 if( vlc_cond_timedwait( &p_input->p->wait_control, &p_input->p->lock_control, i_deadline ) )
1411 return VLC_EGENERIC;
1414 *pi_type = p_input->p->control[0].i_type;
1415 *p_val = p_input->p->control[0].val;
1417 p_input->p->i_control--;
1418 if( p_input->p->i_control > 0 )
1422 for( i = 0; i < p_input->p->i_control; i++ )
1424 p_input->p->control[i].i_type = p_input->p->control[i+1].i_type;
1425 p_input->p->control[i].val = p_input->p->control[i+1].val;
1432 static void ControlReduce( input_thread_t *p_input )
1439 for( i = 1; i < p_input->p->i_control; i++ )
1441 const int i_lt = p_input->p->control[i-1].i_type;
1442 const int i_ct = p_input->p->control[i].i_type;
1444 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1445 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->p->i_control,
1449 ( i_ct == INPUT_CONTROL_SET_STATE ||
1450 i_ct == INPUT_CONTROL_SET_RATE ||
1451 i_ct == INPUT_CONTROL_SET_POSITION ||
1452 i_ct == INPUT_CONTROL_SET_TIME ||
1453 i_ct == INPUT_CONTROL_SET_PROGRAM ||
1454 i_ct == INPUT_CONTROL_SET_TITLE ||
1455 i_ct == INPUT_CONTROL_SET_SEEKPOINT ||
1456 i_ct == INPUT_CONTROL_SET_BOOKMARK ) )
1459 // msg_Dbg( p_input, "merged at %d", i );
1460 /* Remove the i-1 */
1461 for( j = i; j < p_input->p->i_control; j++ )
1462 p_input->p->control[j-1] = p_input->p->control[j];
1463 p_input->p->i_control--;
1467 /* TODO but that's not that important
1468 - merge SET_X with SET_X_CMD
1469 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1470 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1477 static void ControlPause( input_thread_t *p_input, mtime_t i_control_date )
1479 int i_ret = VLC_SUCCESS;
1480 int i_state = PAUSE_S;
1482 if( p_input->p->b_can_pause )
1484 if( p_input->p->input.p_access )
1485 i_ret = access_Control( p_input->p->input.p_access,
1486 ACCESS_SET_PAUSE_STATE, true );
1488 i_ret = demux_Control( p_input->p->input.p_demux,
1489 DEMUX_SET_PAUSE_STATE, true );
1493 msg_Warn( p_input, "cannot set pause state" );
1494 i_state = p_input->p->i_state;
1501 i_ret = es_out_SetPauseState( p_input->p->p_es_out, p_input->p->b_can_pause, true, i_control_date );
1504 msg_Warn( p_input, "cannot set pause state at es_out level" );
1505 i_state = p_input->p->i_state;
1509 /* Switch to new state */
1510 input_ChangeState( p_input, i_state );
1514 static void ControlUnpause( input_thread_t *p_input, mtime_t i_control_date )
1516 int i_ret = VLC_SUCCESS;
1518 if( p_input->p->b_can_pause )
1520 if( p_input->p->input.p_access )
1521 i_ret = access_Control( p_input->p->input.p_access,
1522 ACCESS_SET_PAUSE_STATE, false );
1524 i_ret = demux_Control( p_input->p->input.p_demux,
1525 DEMUX_SET_PAUSE_STATE, false );
1528 /* FIXME What to do ? */
1529 msg_Warn( p_input, "cannot unset pause -> EOF" );
1530 vlc_mutex_unlock( &p_input->p->lock_control );
1531 input_ControlPush( p_input, INPUT_CONTROL_SET_DIE, NULL );
1532 vlc_mutex_lock( &p_input->p->lock_control );
1536 /* Switch to play */
1537 input_ChangeState( p_input, PLAYING_S );
1541 es_out_SetPauseState( p_input->p->p_es_out, false, false, i_control_date );
1544 static bool Control( input_thread_t *p_input, int i_type,
1547 const mtime_t i_control_date = mdate();
1548 /* FIXME b_force_update is abused, it should be carefully checked */
1549 bool b_force_update = false;
1552 return b_force_update;
1556 case INPUT_CONTROL_SET_DIE:
1557 msg_Dbg( p_input, "control: stopping input" );
1559 /* Mark all submodules to die */
1560 ObjectKillChildrens( p_input, VLC_OBJECT(p_input) );
1563 case INPUT_CONTROL_SET_POSITION:
1564 case INPUT_CONTROL_SET_POSITION_OFFSET:
1568 if( p_input->p->b_recording )
1570 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) ignored while recording" );
1573 f_pos = val.f_float;
1574 if( i_type != INPUT_CONTROL_SET_POSITION )
1575 f_pos += var_GetFloat( p_input, "position" );
1578 else if( f_pos > 1.0 )
1580 /* Reset the decoders states and clock sync (before calling the demuxer */
1581 es_out_SetTime( p_input->p->p_es_out, -1 );
1582 if( demux_Control( p_input->p->input.p_demux, DEMUX_SET_POSITION,
1585 msg_Err( p_input, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1586 "%2.1f%% failed", f_pos * 100 );
1590 if( p_input->p->i_slave > 0 )
1591 SlaveSeek( p_input );
1592 p_input->p->input.b_eof = false;
1594 b_force_update = true;
1599 case INPUT_CONTROL_SET_TIME:
1600 case INPUT_CONTROL_SET_TIME_OFFSET:
1605 if( p_input->p->b_recording )
1607 msg_Err( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) ignored while recording" );
1611 i_time = val.i_time;
1612 if( i_type != INPUT_CONTROL_SET_TIME )
1613 i_time += var_GetTime( p_input, "time" );
1618 /* Reset the decoders states and clock sync (before calling the demuxer */
1619 es_out_SetTime( p_input->p->p_es_out, -1 );
1621 i_ret = demux_Control( p_input->p->input.p_demux,
1622 DEMUX_SET_TIME, i_time );
1627 /* Emulate it with a SET_POS */
1628 demux_Control( p_input->p->input.p_demux,
1629 DEMUX_GET_LENGTH, &i_length );
1632 double f_pos = (double)i_time / (double)i_length;
1633 i_ret = demux_Control( p_input->p->input.p_demux,
1634 DEMUX_SET_POSITION, f_pos );
1639 msg_Warn( p_input, "INPUT_CONTROL_SET_TIME(_OFFSET) %"PRId64
1640 " failed or not possible", i_time );
1644 if( p_input->p->i_slave > 0 )
1645 SlaveSeek( p_input );
1646 p_input->p->input.b_eof = false;
1648 b_force_update = true;
1653 case INPUT_CONTROL_SET_STATE:
1654 if( ( val.i_int == PLAYING_S && p_input->p->i_state == PAUSE_S ) ||
1655 ( val.i_int == PAUSE_S && p_input->p->i_state == PAUSE_S ) )
1657 ControlUnpause( p_input, i_control_date );
1659 b_force_update = true;
1661 else if( val.i_int == PAUSE_S && p_input->p->i_state == PLAYING_S /* &&
1662 p_input->p->b_can_pause */ )
1664 ControlPause( p_input, i_control_date );
1666 b_force_update = true;
1668 else if( val.i_int == PAUSE_S && !p_input->p->b_can_pause && 0 )
1670 b_force_update = true;
1672 /* Correct "state" value */
1673 input_ChangeState( p_input, p_input->p->i_state );
1675 else if( val.i_int != PLAYING_S && val.i_int != PAUSE_S )
1677 msg_Err( p_input, "invalid state in INPUT_CONTROL_SET_STATE" );
1681 case INPUT_CONTROL_SET_RATE:
1682 case INPUT_CONTROL_SET_RATE_SLOWER:
1683 case INPUT_CONTROL_SET_RATE_FASTER:
1688 /* Get rate and direction */
1689 if( i_type == INPUT_CONTROL_SET_RATE )
1691 i_rate = abs( val.i_int );
1692 i_rate_sign = val.i_int < 0 ? -1 : 1;
1696 static const int ppi_factor[][2] = {
1697 {1,64}, {1,32}, {1,16}, {1,8}, {1,4}, {1,3}, {1,2}, {2,3},
1699 {3,2}, {2,1}, {3,1}, {4,1}, {8,1}, {16,1}, {32,1}, {64,1},
1706 i_rate_sign = p_input->p->i_rate < 0 ? -1 : 1;
1710 for( i = 0; ppi_factor[i][0] != 0; i++ )
1712 const int i_test_r = INPUT_RATE_DEFAULT * ppi_factor[i][0] / ppi_factor[i][1];
1713 const int i_test_e = abs( abs( p_input->p->i_rate ) - i_test_r );
1714 if( i_test_e < i_error )
1721 assert( i_idx >= 0 && ppi_factor[i_idx][0] != 0 );
1723 if( i_type == INPUT_CONTROL_SET_RATE_SLOWER )
1725 if( ppi_factor[i_idx+1][0] > 0 )
1726 i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx+1][0] / ppi_factor[i_idx+1][1];
1728 i_rate = INPUT_RATE_MAX+1;
1732 assert( i_type == INPUT_CONTROL_SET_RATE_FASTER );
1734 i_rate = INPUT_RATE_DEFAULT * ppi_factor[i_idx-1][0] / ppi_factor[i_idx-1][1];
1736 i_rate = INPUT_RATE_MIN-1;
1740 /* Check rate bound */
1741 if( i_rate < INPUT_RATE_MIN )
1743 msg_Dbg( p_input, "cannot set rate faster" );
1744 i_rate = INPUT_RATE_MIN;
1746 else if( i_rate > INPUT_RATE_MAX )
1748 msg_Dbg( p_input, "cannot set rate slower" );
1749 i_rate = INPUT_RATE_MAX;
1752 /* Apply direction */
1753 if( i_rate_sign < 0 )
1755 if( p_input->p->input.b_rescale_ts )
1757 msg_Dbg( p_input, "cannot set negative rate" );
1758 i_rate = p_input->p->i_rate;
1759 assert( i_rate > 0 );
1763 i_rate *= i_rate_sign;
1767 if( i_rate != INPUT_RATE_DEFAULT &&
1768 ( ( !p_input->p->b_can_rate_control && !p_input->p->input.b_rescale_ts ) ||
1769 ( p_input->p->p_sout && !p_input->p->b_out_pace_control ) ) )
1771 msg_Dbg( p_input, "cannot change rate" );
1772 i_rate = INPUT_RATE_DEFAULT;
1774 if( i_rate != p_input->p->i_rate &&
1775 !p_input->p->b_can_pace_control && p_input->p->b_can_rate_control )
1778 if( p_input->p->input.p_access )
1780 i_ret = VLC_EGENERIC;
1784 if( !p_input->p->input.b_rescale_ts )
1785 es_out_Control( p_input->p->p_es_out, ES_OUT_RESET_PCR );
1787 i_ret = demux_Control( p_input->p->input.p_demux,
1788 DEMUX_SET_RATE, &i_rate );
1792 msg_Warn( p_input, "ACCESS/DEMUX_SET_RATE failed" );
1793 i_rate = p_input->p->i_rate;
1798 if( i_rate != p_input->p->i_rate )
1800 p_input->p->i_rate = i_rate;
1801 input_SendEventRate( p_input, i_rate );
1803 if( p_input->p->input.b_rescale_ts )
1805 const int i_rate_source = (p_input->p->b_can_pace_control || p_input->p->b_can_rate_control ) ? i_rate : INPUT_RATE_DEFAULT;
1806 es_out_SetRate( p_input->p->p_es_out, i_rate_source, i_rate );
1809 b_force_update = true;
1814 case INPUT_CONTROL_SET_PROGRAM:
1815 /* No need to force update, es_out does it if needed */
1816 es_out_Control( p_input->p->p_es_out,
1817 ES_OUT_SET_GROUP, val.i_int );
1819 demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, val.i_int,
1823 case INPUT_CONTROL_SET_ES:
1824 /* No need to force update, es_out does it if needed */
1825 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, val.i_int );
1828 case INPUT_CONTROL_RESTART_ES:
1829 es_out_Control( p_input->p->p_es_out_display, ES_OUT_RESTART_ES_BY_ID, val.i_int );
1832 case INPUT_CONTROL_SET_AUDIO_DELAY:
1833 if( !es_out_SetDelay( p_input->p->p_es_out_display, AUDIO_ES, val.i_time ) )
1834 input_SendEventAudioDelay( p_input, val.i_time );
1837 case INPUT_CONTROL_SET_SPU_DELAY:
1838 if( !es_out_SetDelay( p_input->p->p_es_out_display, SPU_ES, val.i_time ) )
1839 input_SendEventSubtitleDelay( p_input, val.i_time );
1842 case INPUT_CONTROL_SET_TITLE:
1843 case INPUT_CONTROL_SET_TITLE_NEXT:
1844 case INPUT_CONTROL_SET_TITLE_PREV:
1845 if( p_input->p->b_recording )
1847 msg_Err( p_input, "INPUT_CONTROL_SET_TITLE(*) ignored while recording" );
1850 if( p_input->p->input.b_title_demux &&
1851 p_input->p->input.i_title > 0 )
1854 /* FIXME handle demux title */
1855 demux_t *p_demux = p_input->p->input.p_demux;
1858 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1859 i_title = p_demux->info.i_title - 1;
1860 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1861 i_title = p_demux->info.i_title + 1;
1863 i_title = val.i_int;
1865 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1867 es_out_SetTime( p_input->p->p_es_out, -1 );
1869 demux_Control( p_demux, DEMUX_SET_TITLE, i_title );
1870 input_ControlVarTitle( p_input, i_title );
1873 else if( p_input->p->input.i_title > 0 )
1875 access_t *p_access = p_input->p->input.p_access;
1878 if( i_type == INPUT_CONTROL_SET_TITLE_PREV )
1879 i_title = p_access->info.i_title - 1;
1880 else if( i_type == INPUT_CONTROL_SET_TITLE_NEXT )
1881 i_title = p_access->info.i_title + 1;
1883 i_title = val.i_int;
1885 if( i_title >= 0 && i_title < p_input->p->input.i_title )
1887 es_out_SetTime( p_input->p->p_es_out, -1 );
1889 stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
1890 ACCESS_SET_TITLE, i_title );
1894 case INPUT_CONTROL_SET_SEEKPOINT:
1895 case INPUT_CONTROL_SET_SEEKPOINT_NEXT:
1896 case INPUT_CONTROL_SET_SEEKPOINT_PREV:
1897 if( p_input->p->b_recording )
1899 msg_Err( p_input, "INPUT_CONTROL_SET_SEEKPOINT(*) ignored while recording" );
1903 if( p_input->p->input.b_title_demux &&
1904 p_input->p->input.i_title > 0 )
1906 demux_t *p_demux = p_input->p->input.p_demux;
1908 int64_t i_input_time;
1909 int64_t i_seekpoint_time;
1911 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1913 i_seekpoint = p_demux->info.i_seekpoint;
1914 i_seekpoint_time = p_input->p->input.title[p_demux->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1915 i_input_time = var_GetTime( p_input, "time" );
1916 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
1918 if( i_input_time < i_seekpoint_time + 3000000 )
1924 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1925 i_seekpoint = p_demux->info.i_seekpoint + 1;
1927 i_seekpoint = val.i_int;
1929 if( i_seekpoint >= 0 && i_seekpoint <
1930 p_input->p->input.title[p_demux->info.i_title]->i_seekpoint )
1933 es_out_SetTime( p_input->p->p_es_out, -1 );
1935 demux_Control( p_demux, DEMUX_SET_SEEKPOINT, i_seekpoint );
1938 else if( p_input->p->input.i_title > 0 )
1940 access_t *p_access = p_input->p->input.p_access;
1942 int64_t i_input_time;
1943 int64_t i_seekpoint_time;
1945 if( i_type == INPUT_CONTROL_SET_SEEKPOINT_PREV )
1947 i_seekpoint = p_access->info.i_seekpoint;
1948 i_seekpoint_time = p_input->p->input.title[p_access->info.i_title]->seekpoint[i_seekpoint]->i_time_offset;
1949 i_input_time = var_GetTime( p_input, "time" );
1950 if( i_seekpoint_time >= 0 && i_input_time >= 0 )
1952 if( i_input_time < i_seekpoint_time + 3000000 )
1958 else if( i_type == INPUT_CONTROL_SET_SEEKPOINT_NEXT )
1959 i_seekpoint = p_access->info.i_seekpoint + 1;
1961 i_seekpoint = val.i_int;
1963 if( i_seekpoint >= 0 && i_seekpoint <
1964 p_input->p->input.title[p_access->info.i_title]->i_seekpoint )
1966 es_out_SetTime( p_input->p->p_es_out, -1 );
1968 stream_Control( p_input->p->input.p_stream, STREAM_CONTROL_ACCESS,
1969 ACCESS_SET_SEEKPOINT, i_seekpoint );
1974 case INPUT_CONTROL_ADD_SUBTITLE:
1975 if( val.psz_string )
1977 SubtitleAdd( p_input, val.psz_string, true );
1978 free( val.psz_string );
1982 case INPUT_CONTROL_ADD_SLAVE:
1983 if( val.psz_string )
1985 input_source_t *slave = InputSourceNew( p_input );
1987 if( slave && !InputSourceInit( p_input, slave, val.psz_string, NULL ) )
1993 msg_Dbg( p_input, "adding %s as slave on the fly",
1997 if( demux_Control( p_input->p->input.p_demux,
1998 DEMUX_GET_TIME, &i_time ) )
2000 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2001 InputSourceClean( slave );
2005 if( demux_Control( slave->p_demux,
2006 DEMUX_SET_TIME, i_time ) )
2008 msg_Err( p_input, "seek failed for new slave" );
2009 InputSourceClean( slave );
2014 /* Get meta (access and demux) */
2015 p_meta = vlc_meta_New();
2018 access_Control( slave->p_access, ACCESS_GET_META, p_meta );
2019 demux_Control( slave->p_demux, DEMUX_GET_META, p_meta );
2020 InputUpdateMeta( p_input, p_meta );
2023 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, slave );
2028 msg_Warn( p_input, "failed to add %s as slave",
2032 free( val.psz_string );
2036 case INPUT_CONTROL_SET_RECORD_STATE:
2037 if( !!p_input->p->b_recording != !!val.b_bool )
2039 if( p_input->p->input.b_can_stream_record )
2041 if( demux_Control( p_input->p->input.p_demux,
2042 DEMUX_SET_RECORD_STATE, val.b_bool ) )
2047 if( es_out_SetRecordState( p_input->p->p_es_out_display, val.b_bool ) )
2050 p_input->p->b_recording = val.b_bool;
2052 input_SendEventRecord( p_input, val.b_bool );
2054 b_force_update = true;
2058 case INPUT_CONTROL_SET_FRAME_NEXT:
2059 if( p_input->p->i_state == PAUSE_S )
2061 es_out_SetFrameNext( p_input->p->p_es_out );
2063 else if( p_input->p->i_state == PLAYING_S )
2065 ControlPause( p_input, i_control_date );
2069 msg_Err( p_input, "invalid state for frame next" );
2071 b_force_update = true;
2074 case INPUT_CONTROL_SET_BOOKMARK:
2076 seekpoint_t bookmark;
2078 bookmark.i_time_offset = -1;
2079 bookmark.i_byte_offset = -1;
2081 vlc_mutex_lock( &p_input->p->p_item->lock );
2082 if( val.i_int >= 0 && val.i_int < p_input->p->i_bookmark )
2084 const seekpoint_t *p_bookmark = p_input->p->pp_bookmark[val.i_int];
2085 bookmark.i_time_offset = p_bookmark->i_time_offset;
2086 bookmark.i_byte_offset = p_bookmark->i_byte_offset;
2088 vlc_mutex_unlock( &p_input->p->p_item->lock );
2090 if( bookmark.i_time_offset < 0 && bookmark.i_byte_offset < 0 )
2092 msg_Err( p_input, "invalid bookmark %d", val.i_int );
2096 if( bookmark.i_time_offset >= 0 )
2098 val.i_time = bookmark.i_time_offset;
2099 b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME, val );
2101 else if( bookmark.i_byte_offset >= 0 &&
2102 p_input->p->input.p_stream )
2104 const int64_t i_size = stream_Size( p_input->p->input.p_stream );
2105 if( i_size > 0 && bookmark.i_byte_offset <= i_size )
2107 val.f_float = (double)bookmark.i_byte_offset / i_size;
2108 b_force_update = Control( p_input, INPUT_CONTROL_SET_POSITION, val );
2115 msg_Err( p_input, "not yet implemented" );
2119 return b_force_update;
2122 /*****************************************************************************
2123 * UpdateTitleSeekpoint
2124 *****************************************************************************/
2125 static int UpdateTitleSeekpoint( input_thread_t *p_input,
2126 int i_title, int i_seekpoint )
2128 int i_title_end = p_input->p->input.i_title_end -
2129 p_input->p->input.i_title_offset;
2130 int i_seekpoint_end = p_input->p->input.i_seekpoint_end -
2131 p_input->p->input.i_seekpoint_offset;
2133 if( i_title_end >= 0 && i_seekpoint_end >= 0 )
2135 if( i_title > i_title_end ||
2136 ( i_title == i_title_end && i_seekpoint > i_seekpoint_end ) )
2139 else if( i_seekpoint_end >= 0 )
2141 if( i_seekpoint > i_seekpoint_end )
2144 else if( i_title_end >= 0 )
2146 if( i_title > i_title_end )
2151 /*****************************************************************************
2153 *****************************************************************************/
2154 static int UpdateTitleSeekpointFromDemux( input_thread_t *p_input )
2156 demux_t *p_demux = p_input->p->input.p_demux;
2158 /* TODO event-like */
2159 if( p_demux->info.i_update & INPUT_UPDATE_TITLE )
2161 input_SendEventTitle( p_input, p_demux->info.i_title );
2163 p_demux->info.i_update &= ~INPUT_UPDATE_TITLE;
2165 if( p_demux->info.i_update & INPUT_UPDATE_SEEKPOINT )
2167 input_SendEventSeekpoint( p_input,
2168 p_demux->info.i_title, p_demux->info.i_seekpoint );
2170 p_demux->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2173 /* Hmmm only works with master input */
2174 if( p_input->p->input.p_demux == p_demux )
2175 return UpdateTitleSeekpoint( p_input,
2176 p_demux->info.i_title,
2177 p_demux->info.i_seekpoint );
2181 static void UpdateGenericFromDemux( input_thread_t *p_input )
2183 demux_t *p_demux = p_input->p->input.p_demux;
2185 if( p_demux->info.i_update & INPUT_UPDATE_META )
2187 vlc_meta_t *p_meta = vlc_meta_New();
2190 demux_Control( p_input->p->input.p_demux, DEMUX_GET_META, p_meta );
2191 InputUpdateMeta( p_input, p_meta );
2193 p_demux->info.i_update &= ~INPUT_UPDATE_META;
2196 p_demux->info.i_update &= ~INPUT_UPDATE_SIZE;
2200 /*****************************************************************************
2201 * Update*FromAccess:
2202 *****************************************************************************/
2203 static int UpdateTitleSeekpointFromAccess( input_thread_t *p_input )
2205 access_t *p_access = p_input->p->input.p_access;
2207 if( p_access->info.i_update & INPUT_UPDATE_TITLE )
2209 input_SendEventTitle( p_input, p_access->info.i_title );
2211 stream_Control( p_input->p->input.p_stream, STREAM_UPDATE_SIZE );
2213 p_access->info.i_update &= ~INPUT_UPDATE_TITLE;
2215 if( p_access->info.i_update & INPUT_UPDATE_SEEKPOINT )
2217 input_SendEventSeekpoint( p_input,
2218 p_access->info.i_title, p_access->info.i_seekpoint );
2220 p_access->info.i_update &= ~INPUT_UPDATE_SEEKPOINT;
2222 /* Hmmm only works with master input */
2223 if( p_input->p->input.p_access == p_access )
2224 return UpdateTitleSeekpoint( p_input,
2225 p_access->info.i_title,
2226 p_access->info.i_seekpoint );
2229 static void UpdateGenericFromAccess( input_thread_t *p_input )
2231 access_t *p_access = p_input->p->input.p_access;
2233 if( p_access->info.i_update & INPUT_UPDATE_META )
2235 /* TODO maybe multi - access ? */
2236 vlc_meta_t *p_meta = vlc_meta_New();
2239 access_Control( p_input->p->input.p_access, ACCESS_GET_META, p_meta );
2240 InputUpdateMeta( p_input, p_meta );
2242 p_access->info.i_update &= ~INPUT_UPDATE_META;
2244 if( p_access->info.i_update & INPUT_UPDATE_SIGNAL )
2249 if( access_Control( p_access, ACCESS_GET_SIGNAL, &f_quality, &f_strength ) )
2250 f_quality = f_strength = -1;
2252 input_SendEventSignal( p_input, f_quality, f_strength );
2254 p_access->info.i_update &= ~INPUT_UPDATE_SIGNAL;
2257 p_access->info.i_update &= ~INPUT_UPDATE_SIZE;
2260 /*****************************************************************************
2262 *****************************************************************************/
2263 static input_source_t *InputSourceNew( input_thread_t *p_input )
2265 VLC_UNUSED(p_input);
2267 return calloc( 1, sizeof( input_source_t ) );
2270 /*****************************************************************************
2272 *****************************************************************************/
2273 static int InputSourceInit( input_thread_t *p_input,
2274 input_source_t *in, const char *psz_mrl,
2275 const char *psz_forced_demux )
2277 char psz_dup[strlen(psz_mrl) + 1];
2278 const char *psz_access;
2279 const char *psz_demux;
2284 strcpy( psz_dup, psz_mrl );
2287 input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_dup );
2289 msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
2290 psz_mrl, psz_access, psz_demux, psz_path );
2291 if( !p_input->b_preparsing )
2293 /* Hack to allow udp://@:port syntax */
2295 (strncmp( psz_access, "udp", 3 ) &&
2296 strncmp( psz_access, "rtp", 3 )) )
2298 /* Find optional titles and seekpoints */
2299 MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
2300 &in->i_seekpoint_start, &in->i_seekpoint_end );
2303 if( psz_forced_demux && *psz_forced_demux )
2305 psz_demux = psz_forced_demux;
2307 else if( *psz_demux == '\0' )
2309 /* special hack for forcing a demuxer with --demux=module
2310 * (and do nothing with a list) */
2311 char *psz_var_demux = var_GetNonEmptyString( p_input, "demux" );
2313 if( psz_var_demux != NULL &&
2314 !strchr(psz_var_demux, ',' ) &&
2315 !strchr(psz_var_demux, ':' ) )
2317 psz_demux = psz_var_demux;
2319 msg_Dbg( p_input, "enforced demux ` %s'", psz_demux );
2323 /* Try access_demux first */
2324 in->p_demux = demux_New( p_input, psz_access, psz_demux, psz_path,
2325 NULL, p_input->p->p_es_out, false );
2329 /* Preparsing is only for file:// */
2332 if( !*psz_access ) /* path without scheme:// */
2333 psz_access = "file";
2334 if( strcmp( psz_access, "file" ) )
2336 msg_Dbg( p_input, "trying to pre-parse %s", psz_path );
2341 int64_t i_pts_delay;
2343 /* Get infos from access_demux */
2344 demux_Control( in->p_demux,
2345 DEMUX_GET_PTS_DELAY, &i_pts_delay );
2346 p_input->p->i_pts_delay = __MAX( p_input->p->i_pts_delay, i_pts_delay );
2348 in->b_title_demux = true;
2349 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2350 &in->title, &in->i_title,
2351 &in->i_title_offset, &in->i_seekpoint_offset ) )
2353 TAB_INIT( in->i_title, in->title );
2355 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_PACE,
2356 &in->b_can_pace_control ) )
2357 in->b_can_pace_control = false;
2359 if( !in->b_can_pace_control )
2361 if( demux_Control( in->p_demux, DEMUX_CAN_CONTROL_RATE,
2362 &in->b_can_rate_control, &in->b_rescale_ts ) )
2364 in->b_can_rate_control = false;
2365 in->b_rescale_ts = true; /* not used */
2370 in->b_can_rate_control = true;
2371 in->b_rescale_ts = true;
2373 if( demux_Control( in->p_demux, DEMUX_CAN_PAUSE,
2374 &in->b_can_pause ) )
2375 in->b_can_pause = false;
2376 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2377 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2378 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control );
2380 int ret = demux_Control( in->p_demux, DEMUX_CAN_SEEK,
2382 if( ret != VLC_SUCCESS )
2384 var_Set( p_input, "can-seek", val );
2388 int64_t i_pts_delay;
2390 /* Now try a real access */
2391 in->p_access = access_New( p_input, psz_access, psz_demux, psz_path );
2393 /* Access failed, URL encoded ? */
2394 if( in->p_access == NULL && strchr( psz_path, '%' ) )
2396 decode_URI( psz_path );
2398 msg_Dbg( p_input, "retrying with access `%s' demux `%s' path `%s'",
2399 psz_access, psz_demux, psz_path );
2401 in->p_access = access_New( p_input,
2402 psz_access, psz_demux, psz_path );
2404 if( in->p_access == NULL )
2406 msg_Err( p_input, "open of `%s' failed: %s", psz_mrl,
2408 intf_UserFatal( VLC_OBJECT( p_input), false,
2409 _("Your input can't be opened"),
2410 _("VLC is unable to open the MRL '%s'."
2411 " Check the log for details."), psz_mrl );
2415 /* Get infos from access */
2416 if( !p_input->b_preparsing )
2418 access_Control( in->p_access,
2419 ACCESS_GET_PTS_DELAY, &i_pts_delay );
2420 p_input->p->i_pts_delay = __MAX( p_input->p->i_pts_delay, i_pts_delay );
2422 in->b_title_demux = false;
2423 if( access_Control( in->p_access, ACCESS_GET_TITLE_INFO,
2424 &in->title, &in->i_title,
2425 &in->i_title_offset, &in->i_seekpoint_offset ) )
2428 TAB_INIT( in->i_title, in->title );
2430 access_Control( in->p_access, ACCESS_CAN_CONTROL_PACE,
2431 &in->b_can_pace_control );
2432 in->b_can_rate_control = in->b_can_pace_control;
2433 in->b_rescale_ts = true;
2435 access_Control( in->p_access, ACCESS_CAN_PAUSE,
2437 var_SetBool( p_input, "can-pause", in->b_can_pause || !in->b_can_pace_control ); /* XXX temporary because of es_out_timeshift*/
2438 var_SetBool( p_input, "can-rate", !in->b_can_pace_control || in->b_can_rate_control ); /* XXX temporary because of es_out_timeshift*/
2439 var_SetBool( p_input, "can-rewind", !in->b_rescale_ts && !in->b_can_pace_control );
2441 access_Control( in->p_access, ACCESS_CAN_SEEK,
2443 var_Set( p_input, "can-seek", val );
2448 char **ppsz_input_list;
2450 TAB_INIT( i_input_list, ppsz_input_list );
2452 /* On master stream only, use input-list */
2453 if( &p_input->p->input == in )
2459 psz_parser = var_CreateGetNonEmptyString( p_input, "input-list" );
2461 while( psz_parser && *psz_parser )
2463 char *p = strchr( psz_parser, ',' );
2469 char *psz_name = strdup( psz_parser );
2471 TAB_APPEND( i_input_list, ppsz_input_list, psz_name );
2478 /* Autodetect extra files if none specified */
2479 if( i_input_list <= 0 )
2481 InputGetExtraFiles( p_input, &i_input_list, &ppsz_input_list,
2482 psz_access, psz_path );
2484 if( i_input_list > 0 )
2485 TAB_APPEND( i_input_list, ppsz_input_list, NULL );
2487 /* Create the stream_t */
2488 in->p_stream = stream_AccessNew( in->p_access, ppsz_input_list );
2489 if( ppsz_input_list )
2491 for( int i = 0; ppsz_input_list[i] != NULL; i++ )
2492 free( ppsz_input_list[i] );
2493 TAB_CLEAN( i_input_list, ppsz_input_list );
2496 if( in->p_stream == NULL )
2498 msg_Warn( p_input, "cannot create a stream_t from access" );
2502 /* Add stream filters */
2503 char *psz_stream_filter = var_GetNonEmptyString( p_input,
2505 in->p_stream = stream_FilterChainNew( in->p_stream,
2507 var_GetBool( p_input, "input-record-native" ) );
2508 free( psz_stream_filter );
2510 /* Open a demuxer */
2511 if( *psz_demux == '\0' && *in->p_access->psz_demux )
2513 psz_demux = in->p_access->psz_demux;
2517 /* Take access redirections into account */
2518 char *psz_real_path;
2519 char *psz_buf = NULL;
2520 if( in->p_access->psz_path )
2522 const char *psz_a, *psz_d;
2523 psz_buf = strdup( in->p_access->psz_path );
2524 input_SplitMRL( &psz_a, &psz_d, &psz_real_path, psz_buf );
2528 psz_real_path = psz_path;
2530 in->p_demux = demux_New( p_input, psz_access, psz_demux,
2532 in->p_stream, p_input->p->p_es_out,
2533 p_input->b_preparsing );
2537 if( in->p_demux == NULL )
2539 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
2540 psz_access, psz_demux, psz_path );
2541 intf_UserFatal( VLC_OBJECT( p_input ), false,
2542 _("VLC can't recognize the input's format"),
2543 _("The format of '%s' cannot be detected. "
2544 "Have a look at the log for details."), psz_mrl );
2548 /* Get title from demux */
2549 if( !p_input->b_preparsing && in->i_title <= 0 )
2551 if( demux_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
2552 &in->title, &in->i_title,
2553 &in->i_title_offset, &in->i_seekpoint_offset ))
2555 TAB_INIT( in->i_title, in->title );
2559 in->b_title_demux = true;
2564 /* Set record capabilities */
2565 if( demux_Control( in->p_demux, DEMUX_CAN_RECORD, &in->b_can_stream_record ) )
2566 in->b_can_stream_record = false;
2568 if( !var_GetBool( p_input, "input-record-native" ) )
2569 in->b_can_stream_record = false;
2570 var_SetBool( p_input, "can-record", true );
2572 var_SetBool( p_input, "can-record", in->b_can_stream_record );
2576 * FIXME improve for b_preparsing: move it after GET_META and check psz_arturl */
2577 if( 1 || !p_input->b_preparsing )
2580 input_attachment_t **attachment;
2581 if( !demux_Control( in->p_demux, DEMUX_GET_ATTACHMENTS,
2582 &attachment, &i_attachment ) )
2584 vlc_mutex_lock( &p_input->p->p_item->lock );
2585 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2586 i_attachment, attachment );
2587 vlc_mutex_unlock( &p_input->p->p_item->lock );
2590 if( !demux_Control( in->p_demux, DEMUX_GET_FPS, &f_fps ) && f_fps > 0.0 )
2592 vlc_mutex_lock( &p_input->p->p_item->lock );
2593 p_input->p->f_fps = f_fps;
2594 vlc_mutex_unlock( &p_input->p->p_item->lock );
2597 if( var_GetInteger( p_input, "clock-synchro" ) != -1 )
2598 in->b_can_pace_control = !var_GetInteger( p_input, "clock-synchro" );
2604 demux_Delete( in->p_demux );
2607 stream_Delete( in->p_stream );
2610 access_Delete( in->p_access );
2612 return VLC_EGENERIC;
2615 /*****************************************************************************
2617 *****************************************************************************/
2618 static void InputSourceClean( input_source_t *in )
2623 demux_Delete( in->p_demux );
2626 stream_Delete( in->p_stream );
2629 access_Delete( in->p_access );
2631 if( in->i_title > 0 )
2633 for( i = 0; i < in->i_title; i++ )
2634 vlc_input_title_Delete( in->title[i] );
2635 TAB_CLEAN( in->i_title, in->title );
2639 /*****************************************************************************
2641 *****************************************************************************/
2642 static void InputSourceMeta( input_thread_t *p_input,
2643 input_source_t *p_source, vlc_meta_t *p_meta )
2645 access_t *p_access = p_source->p_access;
2646 demux_t *p_demux = p_source->p_demux;
2648 /* XXX Remember that checking against p_item->p_meta->i_status & ITEM_PREPARSED
2651 /* Read access meta */
2653 access_Control( p_access, ACCESS_GET_META, p_meta );
2655 /* Read demux meta */
2656 demux_Control( p_demux, DEMUX_GET_META, p_meta );
2658 /* If the demux report unsupported meta data, try an external "meta reader" */
2660 if( demux_Control( p_demux, DEMUX_HAS_UNSUPPORTED_META, &b_bool ) )
2665 demux_meta_t *p_demux_meta = p_demux->p_private = calloc( 1, sizeof(*p_demux_meta) );
2669 module_t *p_id3 = module_need( p_demux, "meta reader", NULL, false );
2672 if( p_demux_meta->p_meta )
2674 vlc_meta_Merge( p_meta, p_demux_meta->p_meta );
2675 vlc_meta_Delete( p_demux_meta->p_meta );
2678 if( p_demux_meta->i_attachments > 0 )
2680 vlc_mutex_lock( &p_input->p->p_item->lock );
2681 AppendAttachment( &p_input->p->i_attachment, &p_input->p->attachment,
2682 p_demux_meta->i_attachments, p_demux_meta->attachments );
2683 vlc_mutex_unlock( &p_input->p->p_item->lock );
2685 module_unneed( p_demux, p_id3 );
2687 free( p_demux_meta );
2691 static void SlaveDemux( input_thread_t *p_input )
2696 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2698 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2702 for( i = 0; i < p_input->p->i_slave; i++ )
2704 input_source_t *in = p_input->p->slave[i];
2710 if( demux_Control( in->p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_time ) )
2715 if( demux_Control( in->p_demux, DEMUX_GET_TIME, &i_stime ) )
2717 msg_Err( p_input, "slave[%d] doesn't like "
2718 "DEMUX_GET_TIME -> EOF", i );
2723 if( i_stime >= i_time )
2726 if( ( i_ret = demux_Demux( in->p_demux ) ) <= 0 )
2732 i_ret = demux_Demux( in->p_demux );
2737 msg_Dbg( p_input, "slave %d EOF", i );
2743 static void SlaveSeek( input_thread_t *p_input )
2748 if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_TIME, &i_time ) )
2750 msg_Err( p_input, "demux doesn't like DEMUX_GET_TIME" );
2754 for( i = 0; i < p_input->p->i_slave; i++ )
2756 input_source_t *in = p_input->p->slave[i];
2758 if( demux_Control( in->p_demux, DEMUX_SET_TIME, i_time ) )
2761 msg_Err( p_input, "seek failed for slave %d -> EOF", i );
2771 /*****************************************************************************
2773 *****************************************************************************/
2774 static void InputMetaUser( input_thread_t *p_input, vlc_meta_t *p_meta )
2778 /* Get meta information from user */
2779 #define GET_META( field, s ) do { \
2780 var_Get( p_input, (s), &val ); \
2781 if( val.psz_string && *val.psz_string ) \
2782 vlc_meta_Set( p_meta, vlc_meta_ ## field, val.psz_string ); \
2783 free( val.psz_string ); } while(0)
2785 GET_META( Title, "meta-title" );
2786 GET_META( Artist, "meta-artist" );
2787 GET_META( Genre, "meta-genre" );
2788 GET_META( Copyright, "meta-copyright" );
2789 GET_META( Description, "meta-description" );
2790 GET_META( Date, "meta-date" );
2791 GET_META( URL, "meta-url" );
2795 /*****************************************************************************
2796 * InputUpdateMeta: merge p_item meta data with p_meta taking care of
2797 * arturl and locking issue.
2798 *****************************************************************************/
2799 static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta )
2801 input_item_t *p_item = p_input->p->p_item;
2803 char *psz_title = NULL;
2804 char *psz_arturl = input_item_GetArtURL( p_item );
2806 vlc_mutex_lock( &p_item->lock );
2808 if( vlc_meta_Get( p_meta, vlc_meta_Title ) && !p_item->b_fixed_name )
2809 psz_title = strdup( vlc_meta_Get( p_meta, vlc_meta_Title ) );
2811 vlc_meta_Merge( p_item->p_meta, p_meta );
2813 vlc_meta_Delete( p_meta );
2815 if( psz_arturl && *psz_arturl )
2817 vlc_meta_Set( p_item->p_meta, vlc_meta_ArtworkURL, psz_arturl );
2819 if( !strncmp( psz_arturl, "attachment://", strlen("attachment") ) )
2821 /* Don't look for art cover if sout
2822 * XXX It can change when sout has meta data support */
2823 if( p_input->p->p_sout && !p_input->b_preparsing )
2824 vlc_meta_Set( p_item->p_meta, vlc_meta_ArtworkURL, "" );
2826 input_ExtractAttachmentAndCacheArt( p_input );
2831 vlc_mutex_unlock( &p_item->lock );
2835 input_item_SetName( p_item, psz_title );
2838 input_item_SetPreparsed( p_item, true );
2840 input_SendEventMeta( p_input );
2842 /** \todo handle sout meta */
2845 static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_attachment,
2846 int i_new, input_attachment_t **pp_new )
2848 int i_attachment = *pi_attachment;
2849 input_attachment_t **attachment = *ppp_attachment;
2852 attachment = realloc( attachment,
2853 sizeof(input_attachment_t**) * ( i_attachment + i_new ) );
2854 for( i = 0; i < i_new; i++ )
2855 attachment[i_attachment++] = pp_new[i];
2859 *pi_attachment = i_attachment;
2860 *ppp_attachment = attachment;
2862 /*****************************************************************************
2863 * InputGetExtraFiles
2864 * Autodetect extra input list
2865 *****************************************************************************/
2866 static void InputGetExtraFilesPattern( input_thread_t *p_input,
2867 int *pi_list, char ***pppsz_list,
2868 const char *psz_path,
2869 const char *psz_match,
2870 const char *psz_format,
2871 int i_start, int i_stop )
2876 TAB_INIT( i_list, ppsz_list );
2878 char *psz_base = strdup( psz_path );
2882 /* Remove the extension */
2883 char *psz_end = &psz_base[strlen(psz_base)-strlen(psz_match)];
2884 assert( psz_end >= psz_base);
2887 /* Try to list files */
2888 for( int i = i_start; i <= i_stop; i++ )
2893 if( asprintf( &psz_file, psz_format, psz_base, i ) < 0 )
2896 if( utf8_stat( psz_file, &st ) || !S_ISREG( st.st_mode ) || !st.st_size )
2902 msg_Dbg( p_input, "Detected extra file `%s'", psz_file );
2903 TAB_APPEND( i_list, ppsz_list, psz_file );
2908 *pppsz_list = ppsz_list;
2911 static void InputGetExtraFiles( input_thread_t *p_input,
2912 int *pi_list, char ***pppsz_list,
2913 const char *psz_access, const char *psz_path )
2917 const char *psz_match;
2918 const char *psz_format;
2922 /* XXX the order is important */
2923 { ".001", "%s.%.3d", 2, 999 },
2924 { ".part1.rar", "%s.part%.1d.rar",2, 9 },
2925 { ".part01.rar", "%s.part%.2d.rar",2, 99, },
2926 { ".part001.rar", "%s.part%.3d.rar",2, 999 },
2927 { ".rar", "%s.r%.2d", 1, 99 },
2928 { NULL, NULL, 0, 0 }
2931 TAB_INIT( *pi_list, *pppsz_list );
2933 if( ( psz_access && *psz_access && strcmp( psz_access, "file" ) ) || !psz_path )
2936 const size_t i_path = strlen(psz_path);
2938 for( int i = 0; p_pattern[i].psz_match != NULL; i++ )
2940 const size_t i_ext = strlen(p_pattern[i].psz_match );
2942 if( i_path < i_ext )
2944 if( !strcmp( &psz_path[i_path-i_ext], p_pattern[i].psz_match ) )
2946 InputGetExtraFilesPattern( p_input, pi_list, pppsz_list,
2948 p_pattern[i].psz_match, p_pattern[i].psz_format,
2949 p_pattern[i].i_start, p_pattern[i].i_stop );
2956 static void input_ChangeState( input_thread_t *p_input, int i_state )
2958 const bool b_changed = p_input->p->i_state != i_state;
2960 p_input->p->i_state = i_state;
2961 if( i_state == ERROR_S )
2962 p_input->b_error = true;
2963 else if( i_state == END_S )
2964 p_input->b_eof = true;
2968 input_item_SetErrorWhenReading( p_input->p->p_item, p_input->b_error );
2969 input_SendEventState( p_input, i_state );
2974 /*****************************************************************************
2975 * MRLSplit: parse the access, demux and url part of the
2976 * Media Resource Locator.
2977 *****************************************************************************/
2978 void input_SplitMRL( const char **ppsz_access, const char **ppsz_demux, char **ppsz_path,
2981 char *psz_access = NULL;
2982 char *psz_demux = NULL;
2985 /* Either there is an access/demux specification before ://
2986 * or we have a plain local file path. */
2987 psz_path = strstr( psz_dup, "://" );
2988 if( psz_path != NULL )
2991 psz_path += 3; /* skips "://" */
2993 /* Separate access from demux (<access>/<demux>://<path>) */
2994 psz_access = psz_dup;
2995 psz_demux = strchr( psz_access, '/' );
2997 *psz_demux++ = '\0';
2999 /* We really don't want module name substitution here! */
3000 if( psz_access[0] == '$' )
3002 if( psz_demux && psz_demux[0] == '$' )
3009 *ppsz_access = psz_access ? psz_access : (char*)"";
3010 *ppsz_demux = psz_demux ? psz_demux : (char*)"";
3011 *ppsz_path = psz_path;
3014 static inline bool next(char ** src)
3018 long result = strtol( *src, &end, 0 );
3019 if( errno != 0 || result >= LONG_MAX || result <= LONG_MIN ||
3028 /*****************************************************************************
3029 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
3032 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
3033 *****************************************************************************/
3034 static void MRLSections( input_thread_t *p_input, char *psz_source,
3035 int *pi_title_start, int *pi_title_end,
3036 int *pi_chapter_start, int *pi_chapter_end )
3038 char *psz, *psz_end, *psz_next, *psz_check;
3040 *pi_title_start = *pi_title_end = -1;
3041 *pi_chapter_start = *pi_chapter_end = -1;
3043 /* Start by parsing titles and chapters */
3044 if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
3047 /* Check we are really dealing with a title/chapter section */
3048 psz_check = psz + 1;
3049 if( !*psz_check ) return;
3050 if( isdigit(*psz_check) )
3051 if(!next(&psz_check)) return;
3052 if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
3053 if( *psz_check == ':' && ++psz_check )
3055 if( isdigit(*psz_check) )
3056 if(!next(&psz_check)) return;
3058 if( *psz_check != '-' && *psz_check ) return;
3059 if( *psz_check == '-' && ++psz_check )
3061 if( isdigit(*psz_check) )
3062 if(!next(&psz_check)) return;
3064 if( *psz_check != ':' && *psz_check ) return;
3065 if( *psz_check == ':' && ++psz_check )
3067 if( isdigit(*psz_check) )
3068 if(!next(&psz_check)) return;
3070 if( *psz_check ) return;
3072 /* Separate start and end */
3074 if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
3076 /* Look for the start title */
3077 *pi_title_start = strtol( psz, &psz_next, 0 );
3078 if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
3079 *pi_title_end = *pi_title_start;
3082 /* Look for the start chapter */
3084 *pi_chapter_start = strtol( psz, &psz_next, 0 );
3085 if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
3086 *pi_chapter_end = *pi_chapter_start;
3090 /* Look for the end title */
3091 *pi_title_end = strtol( psz_end, &psz_next, 0 );
3092 if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
3095 /* Look for the end chapter */
3096 if( *psz_end ) psz_end++;
3097 *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
3098 if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
3101 msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
3102 psz_source, *pi_title_start, *pi_chapter_start,
3103 *pi_title_end, *pi_chapter_end );
3106 /*****************************************************************************
3107 * input_AddSubtitles: add a subtitles file and enable it
3108 *****************************************************************************/
3109 static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_forced )
3111 input_source_t *sub;
3114 char *psz_path, *psz_extension;
3116 /* if we are provided a subtitle.sub file,
3117 * see if we don't have a subtitle.idx and use it instead */
3118 psz_path = strdup( psz_subtitle );
3121 psz_extension = strrchr( psz_path, '.');
3122 if( psz_extension && strcmp( psz_extension, ".sub" ) == 0 )
3126 strcpy( psz_extension, ".idx" );
3128 if( !utf8_stat( psz_path, &st ) && S_ISREG( st.st_mode ) )
3130 msg_Dbg( p_input, "using %s subtitles file instead of %s",
3131 psz_path, psz_subtitle );
3132 strcpy( psz_subtitle, psz_path );
3138 var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
3140 sub = InputSourceNew( p_input );
3141 if( !sub || InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
3146 TAB_APPEND( p_input->p->i_slave, p_input->p->slave, sub );
3149 if( b_forced && !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
3151 if( count.i_int == 0 )
3153 /* if it was first one, there is disable too */
3155 if( count.i_int < list.p_list->i_count )
3157 const int i_id = list.p_list->p_values[count.i_int].i_int;
3159 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_DEFAULT_BY_ID, i_id );
3160 es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, i_id );
3162 var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
3166 /*****************************************************************************
3168 *****************************************************************************/
3169 void input_UpdateStatistic( input_thread_t *p_input,
3170 input_statistic_t i_type, int i_delta )
3172 assert( p_input->p->i_state != INIT_S );
3174 vlc_mutex_lock( &p_input->p->counters.counters_lock);
3177 #define I(c) stats_UpdateInteger( p_input, p_input->p->counters.c, i_delta, NULL )
3178 case INPUT_STATISTIC_DECODED_VIDEO:
3181 case INPUT_STATISTIC_DECODED_AUDIO:
3184 case INPUT_STATISTIC_DECODED_SUBTITLE:
3187 case INPUT_STATISTIC_SENT_PACKET:
3188 I(p_sout_sent_packets);
3191 case INPUT_STATISTIC_SENT_BYTE:
3193 int i_bytes; /* That's pretty stupid to define it as an integer, it will overflow
3195 if( !stats_UpdateInteger( p_input, p_input->p->counters.p_sout_sent_bytes, i_delta, &i_bytes ) )
3196 stats_UpdateFloat( p_input, p_input->p->counters.p_sout_send_bitrate, i_bytes, NULL );
3200 msg_Err( p_input, "Invalid statistic type %d (internal error)", i_type );
3203 vlc_mutex_unlock( &p_input->p->counters.counters_lock);
3207 /* TODO FIXME nearly the same logic that snapshot code */
3208 char *input_CreateFilename( vlc_object_t *p_obj, const char *psz_path, const char *psz_prefix, const char *psz_extension )
3213 path = utf8_opendir( psz_path );
3218 char *psz_tmp = str_format( p_obj, psz_prefix );
3222 filename_sanitize( psz_tmp );
3223 if( asprintf( &psz_file, "%s"DIR_SEP"%s%s%s",
3225 psz_extension ? "." : "",
3226 psz_extension ? psz_extension : "" ) < 0 )
3233 psz_file = str_format( p_obj, psz_path );
3234 path_sanitize( psz_file );