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 *****************************************************************************/
38 #include "input_internal.h"
41 #include "../stream_output/stream_output.h"
43 #include <vlc_playlist.h>
44 #include <vlc_interface.h>
46 #include <vlc_demux.h>
47 #include <vlc_charset.h>
49 #ifdef HAVE_SYS_STAT_H
50 # include <sys/stat.h>
53 /*****************************************************************************
55 *****************************************************************************/
56 static int Run ( input_thread_t
*p_input
);
57 static int RunAndDestroy ( input_thread_t
*p_input
);
59 static input_thread_t
* Create ( vlc_object_t
*, input_item_t
*,
60 const char *, vlc_bool_t
, sout_instance_t
* );
61 static int Init ( input_thread_t
*p_input
);
62 static void Error ( input_thread_t
*p_input
);
63 static void End ( input_thread_t
*p_input
);
64 static void MainLoop( input_thread_t
*p_input
);
65 static void Destroy( input_thread_t
*p_input
, sout_instance_t
**pp_sout
);
67 static inline int ControlPopNoLock( input_thread_t
*, int *, vlc_value_t
* );
68 static void ControlReduce( input_thread_t
* );
69 static vlc_bool_t
Control( input_thread_t
*, int, vlc_value_t
);
71 static int UpdateFromAccess( input_thread_t
* );
72 static int UpdateFromDemux( input_thread_t
* );
74 static void UpdateItemLength( input_thread_t
*, int64_t i_length
);
76 static void MRLSections( input_thread_t
*, char *, int *, int *, int *, int *);
78 static input_source_t
*InputSourceNew( input_thread_t
*);
79 static int InputSourceInit( input_thread_t
*, input_source_t
*,
80 const char *, const char *psz_forced_demux
);
81 static void InputSourceClean( input_source_t
* );
83 //static void InputGetAttachments( input_thread_t *, input_source_t * );
84 static void SlaveDemux( input_thread_t
*p_input
);
85 static void SlaveSeek( input_thread_t
*p_input
);
87 static void InputMetaUser( input_thread_t
*p_input
, vlc_meta_t
*p_meta
);
88 static void InputUpdateMeta( input_thread_t
*p_input
, vlc_meta_t
*p_meta
);
90 static sout_instance_t
*SoutFind( vlc_object_t
*p_parent
, input_item_t
*p_item
, vlc_bool_t
* );
91 static void SoutKeep( sout_instance_t
* );
93 static void DemuxMeta( input_thread_t
*p_input
, vlc_meta_t
*p_meta
, demux_t
*p_demux
);
94 static void AppendAttachment( int *pi_attachment
, input_attachment_t
***ppp_attachment
,
95 int i_new
, input_attachment_t
**pp_new
);
97 /*****************************************************************************
98 * This function creates a new input, and returns a pointer
99 * to its description. On error, it returns NULL.
101 * Variables for _public_ use:
104 * - rate,rate-slower, rate-faster
105 * - position, position-offset
106 * - time, time-offset
107 * - title,title-next,title-prev
108 * - chapter,chapter-next, chapter-prev
109 * - program, audio-es, video-es, spu-es
110 * - audio-delay, spu-delay
115 * - seekable (if you can seek, it doesn't say if 'bar display' has be shown or not, for that check position != 0.0)
117 * * For intf callback upon changes
119 * - rate-change for when playback rate changes
120 * TODO explain when Callback is called
121 * TODO complete this list (?)
122 *****************************************************************************/
123 static input_thread_t
*Create( vlc_object_t
*p_parent
, input_item_t
*p_item
,
124 const char *psz_header
, vlc_bool_t b_quick
, sout_instance_t
*p_sout
)
126 input_thread_t
*p_input
= NULL
; /* thread descriptor */
130 /* Allocate descriptor */
131 p_input
= vlc_object_create( p_parent
, VLC_OBJECT_INPUT
);
132 if( p_input
== NULL
)
134 msg_Err( p_parent
, "out of memory" );
137 MALLOC_NULL( p_input
->p
, input_thread_private_t
);
139 /* One "randomly" selected input thread is responsible for computing
140 * the global stats. Check if there is already someone doing this */
141 if( p_input
->p_libvlc
->p_playlist
->p_stats
&& !b_quick
)
143 vlc_mutex_lock( &p_input
->p_libvlc
->p_playlist
->p_stats
->lock
);
144 if( p_input
->p_libvlc
->p_playlist
->p_stats_computer
== NULL
)
146 p_input
->p_libvlc
->p_playlist
->p_stats_computer
= p_input
;
148 vlc_mutex_unlock( &p_input
->p_libvlc
->p_playlist
->p_stats
->lock
);
151 p_input
->b_preparsing
= b_quick
;
152 p_input
->psz_header
= psz_header
? strdup( psz_header
) : NULL
;
154 /* Init Common fields */
155 p_input
->b_eof
= VLC_FALSE
;
156 p_input
->b_can_pace_control
= VLC_TRUE
;
157 p_input
->p
->i_start
= 0;
159 p_input
->p
->i_stop
= 0;
160 p_input
->p
->i_run
= 0;
161 p_input
->p
->i_title
= 0;
162 p_input
->p
->title
= NULL
;
163 p_input
->p
->i_title_offset
= p_input
->p
->i_seekpoint_offset
= 0;
164 p_input
->i_state
= INIT_S
;
165 p_input
->p
->i_rate
= INPUT_RATE_DEFAULT
;
166 TAB_INIT( p_input
->p
->i_bookmark
, p_input
->p
->bookmark
);
167 TAB_INIT( p_input
->p
->i_attachment
, p_input
->p
->attachment
);
168 p_input
->p
->p_es_out
= NULL
;
169 p_input
->p
->p_sout
= NULL
;
170 p_input
->p
->b_sout_keep
= VLC_FALSE
;
171 p_input
->p
->b_out_pace_control
= VLC_FALSE
;
172 p_input
->i_pts_delay
= 0;
174 /* Init Input fields */
175 p_input
->p
->input
.p_item
= p_item
;
176 p_input
->p
->input
.p_access
= NULL
;
177 p_input
->p
->input
.p_stream
= NULL
;
178 p_input
->p
->input
.p_demux
= NULL
;
179 p_input
->p
->input
.b_title_demux
= VLC_FALSE
;
180 p_input
->p
->input
.i_title
= 0;
181 p_input
->p
->input
.title
= NULL
;
182 p_input
->p
->input
.i_title_offset
= p_input
->p
->input
.i_seekpoint_offset
= 0;
183 p_input
->p
->input
.b_can_pace_control
= VLC_TRUE
;
184 p_input
->p
->input
.b_can_rate_control
= VLC_TRUE
;
185 p_input
->p
->input
.b_rescale_ts
= VLC_TRUE
;
186 p_input
->p
->input
.b_eof
= VLC_FALSE
;
187 p_input
->p
->input
.i_cr_average
= 0;
189 vlc_mutex_lock( &p_item
->lock
);
191 if( !p_item
->p_stats
)
192 p_item
->p_stats
= stats_NewInputStats( p_input
);
193 vlc_mutex_unlock( &p_item
->lock
);
196 p_input
->p
->i_slave
= 0;
197 p_input
->p
->slave
= NULL
;
199 /* Init control buffer */
200 vlc_mutex_init( p_input
, &p_input
->p
->lock_control
);
201 p_input
->p
->i_control
= 0;
203 /* Parse input options */
204 vlc_mutex_lock( &p_item
->lock
);
205 for( i
= 0; i
< p_item
->i_options
; i
++ )
206 var_OptionParse( VLC_OBJECT(p_input
), p_item
->ppsz_options
[i
] );
207 vlc_mutex_unlock( &p_item
->lock
);
209 /* Create Object Variables for private use only */
210 input_ConfigVarInit( p_input
);
212 /* Create Objects variables for public Get and Set */
213 input_ControlVarInit( p_input
);
215 p_input
->p
->input
.i_cr_average
= var_GetInteger( p_input
, "cr-average" );
217 if( !p_input
->b_preparsing
)
219 var_Get( p_input
, "bookmarks", &val
);
222 /* FIXME: have a common cfg parsing routine used by sout and others */
223 char *psz_parser
, *psz_start
, *psz_end
;
224 psz_parser
= val
.psz_string
;
225 while( (psz_start
= strchr( psz_parser
, '{' ) ) )
227 seekpoint_t
*p_seekpoint
= vlc_seekpoint_New();
230 psz_end
= strchr( psz_start
, '}' );
231 if( !psz_end
) break;
232 psz_parser
= psz_end
+ 1;
233 backup
= *psz_parser
;
236 while( (psz_end
= strchr( psz_start
, ',' ) ) )
239 if( !strncmp( psz_start
, "name=", 5 ) )
241 p_seekpoint
->psz_name
= strdup(psz_start
+ 5);
243 else if( !strncmp( psz_start
, "bytes=", 6 ) )
245 p_seekpoint
->i_byte_offset
= atoll(psz_start
+ 6);
247 else if( !strncmp( psz_start
, "time=", 5 ) )
249 p_seekpoint
->i_time_offset
= atoll(psz_start
+ 5) *
252 psz_start
= psz_end
+ 1;
254 msg_Dbg( p_input
, "adding bookmark: %s, bytes="I64Fd
", time="I64Fd
,
255 p_seekpoint
->psz_name
, p_seekpoint
->i_byte_offset
,
256 p_seekpoint
->i_time_offset
);
257 input_Control( p_input
, INPUT_ADD_BOOKMARK
, p_seekpoint
);
258 vlc_seekpoint_Delete( p_seekpoint
);
259 *psz_parser
= backup
;
261 free( val
.psz_string
);
265 /* Remove 'Now playing' info as it is probably outdated */
266 input_Control( p_input
, INPUT_DEL_INFO
,
267 _(VLC_META_INFO_CAT
),
268 _(VLC_META_NOW_PLAYING
) );
269 input_item_SetNowPlaying( p_item
, NULL
);
272 if( p_input
->b_preparsing
)
273 p_input
->i_flags
|= OBJECT_FLAGS_QUIET
| OBJECT_FLAGS_NOINTERACT
;
277 p_input
->p
->p_sout
= p_sout
;
279 /* Attach only once we are ready */
280 vlc_object_attach( p_input
, p_parent
);
285 static void Destroy( input_thread_t
*p_input
, sout_instance_t
**pp_sout
)
287 vlc_object_detach( p_input
);
288 input_thread_private_t
*priv
= p_input
->p
;
295 *pp_sout
= priv
->p_sout
;
296 else if( priv
->b_sout_keep
)
297 SoutKeep( priv
->p_sout
);
299 sout_DeleteInstance( priv
->p_sout
);
302 vlc_object_release( p_input
);
303 vlc_mutex_destroy( &priv
->lock_control
);
308 * Initialize an input thread and run it. You will need to monitor the
309 * thread to clean up after it is done
311 * \param p_parent a vlc_object
312 * \param p_item an input item
313 * \return a pointer to the spawned input thread
315 input_thread_t
*__input_CreateThread( vlc_object_t
*p_parent
,
316 input_item_t
*p_item
)
318 vlc_bool_t b_sout_keep
;
319 sout_instance_t
*p_sout
= SoutFind( p_parent
, p_item
, &b_sout_keep
);
320 input_thread_t
*p_input
= __input_CreateThreadExtended( p_parent
, p_item
, NULL
, p_sout
);
322 if( !p_input
&& p_sout
)
325 p_input
->p
->b_sout_keep
= b_sout_keep
;
330 input_thread_t
*__input_CreateThreadExtended( vlc_object_t
*p_parent
,
331 input_item_t
*p_item
,
332 const char *psz_log
, sout_instance_t
*p_sout
)
334 input_thread_t
*p_input
;
336 p_input
= Create( p_parent
, p_item
, psz_log
, VLC_FALSE
, p_sout
);
340 /* Create thread and wait for its readiness. */
341 if( vlc_thread_create( p_input
, "input", Run
,
342 VLC_THREAD_PRIORITY_INPUT
, VLC_TRUE
) )
344 input_ChangeState( p_input
, ERROR_S
);
345 msg_Err( p_input
, "cannot create input thread" );
346 Destroy( p_input
, &p_sout
);
354 * Initialize an input thread and run it. This thread will clean after himself,
355 * you can forget about it. It can work either in blocking or non-blocking mode
357 * \param p_parent a vlc_object
358 * \param p_item an input item
359 * \param b_block should we block until read is finished ?
360 * \return the input object id if non blocking, an error code else
362 int __input_Read( vlc_object_t
*p_parent
, input_item_t
*p_item
,
365 vlc_bool_t b_sout_keep
;
366 sout_instance_t
*p_sout
= SoutFind( p_parent
, p_item
, &b_sout_keep
);
367 input_thread_t
*p_input
;
369 p_input
= Create( p_parent
, p_item
, NULL
, VLC_FALSE
, p_sout
);
370 if( !p_input
&& p_sout
)
375 p_input
->p
->b_sout_keep
= b_sout_keep
;
379 RunAndDestroy( p_input
);
384 if( vlc_thread_create( p_input
, "input", RunAndDestroy
,
385 VLC_THREAD_PRIORITY_INPUT
, VLC_TRUE
) )
387 input_ChangeState( p_input
, ERROR_S
);
388 msg_Err( p_input
, "cannot create input thread" );
389 Destroy( p_input
, NULL
);
393 return p_input
->i_object_id
;
397 * Initialize an input and initialize it to preparse the item
398 * This function is blocking. It will only accept to parse files
400 * \param p_parent a vlc_object_t
401 * \param p_item an input item
402 * \return VLC_SUCCESS or an error
404 int __input_Preparse( vlc_object_t
*p_parent
, input_item_t
*p_item
)
406 input_thread_t
*p_input
;
408 /* Allocate descriptor */
409 p_input
= Create( p_parent
, p_item
, NULL
, VLC_TRUE
, NULL
);
413 if( !Init( p_input
) )
416 Destroy( p_input
, NULL
);
422 * Request a running input thread to stop and die
424 * \param the input thread to stop
426 void input_StopThread( input_thread_t
*p_input
)
431 /* Set die for input */
432 vlc_object_kill( p_input
);
433 /* FIXME: seems to be duplicated in ControlPush(INPUT_CONTROL_SET_DIE) */
435 /* We cannot touch p_input fields directly (we come from another thread),
436 * so use the vlc_object_find way, it's perfectly safe */
438 /* Set die for all access */
439 p_list
= vlc_list_find( p_input
, VLC_OBJECT_ACCESS
, FIND_CHILD
);
440 for( i
= 0; i
< p_list
->i_count
; i
++ )
442 vlc_object_kill( p_list
->p_values
[i
].p_object
);
444 vlc_list_release( p_list
);
446 /* Set die for all stream */
447 p_list
= vlc_list_find( p_input
, VLC_OBJECT_STREAM
, FIND_CHILD
);
448 for( i
= 0; i
< p_list
->i_count
; i
++ )
450 vlc_object_kill( p_list
->p_values
[i
].p_object
);
452 vlc_list_release( p_list
);
454 /* Set die for all demux */
455 p_list
= vlc_list_find( p_input
, VLC_OBJECT_DEMUX
, FIND_CHILD
);
456 for( i
= 0; i
< p_list
->i_count
; i
++ )
458 vlc_object_kill( p_list
->p_values
[i
].p_object
);
460 vlc_list_release( p_list
);
462 input_ControlPush( p_input
, INPUT_CONTROL_SET_DIE
, NULL
);
466 * Clean up a dead input thread
467 * This function does not return until the thread is effectively cancelled.
469 * \param the input thread to kill
471 void input_DestroyThread( input_thread_t
*p_input
)
473 input_DestroyThreadExtended( p_input
, NULL
);
476 void input_DestroyThreadExtended( input_thread_t
*p_input
, sout_instance_t
**pp_sout
)
478 /* Join the thread */
479 vlc_thread_join( p_input
);
482 Destroy( p_input
, pp_sout
);
485 /*****************************************************************************
486 * Run: main thread loop
487 * This is the "normal" thread that spawns the input processing chain,
488 * reads the stream, cleans up and waits
489 *****************************************************************************/
490 static int Run( input_thread_t
*p_input
)
492 /* Signal that the thread is launched */
493 vlc_thread_ready( p_input
);
495 if( Init( p_input
) )
497 /* If we failed, wait before we are killed, and exit */
498 p_input
->b_error
= VLC_TRUE
;
499 playlist_Signal( pl_Get( p_input
) );
503 /* Tell we're dead */
504 p_input
->b_dead
= VLC_TRUE
;
511 if( !p_input
->b_eof
&& !p_input
->b_error
&& p_input
->p
->input
.b_eof
)
513 /* We have finish to demux data but not to play them */
514 while( !p_input
->b_die
)
516 if( input_EsOutDecodersEmpty( p_input
->p
->p_es_out
) )
519 msg_Dbg( p_input
, "waiting decoder fifos to empty" );
521 msleep( INPUT_IDLE_SLEEP
);
524 /* We have finished */
525 p_input
->b_eof
= VLC_TRUE
;
526 playlist_Signal( pl_Get( p_input
) );
529 /* Wait until we are asked to die */
530 if( !p_input
->b_die
)
541 /*****************************************************************************
542 * RunAndDestroy: main thread loop
543 * This is the "just forget me" thread that spawns the input processing chain,
544 * reads the stream, cleans up and releases memory
545 *****************************************************************************/
546 static int RunAndDestroy( input_thread_t
*p_input
)
548 /* Signal that the thread is launched */
549 vlc_thread_ready( p_input
);
551 if( Init( p_input
) )
556 if( !p_input
->b_eof
&& !p_input
->b_error
&& p_input
->p
->input
.b_eof
)
558 /* We have finished demuxing data but not playing it */
559 while( !p_input
->b_die
)
561 if( input_EsOutDecodersEmpty( p_input
->p
->p_es_out
) )
564 msg_Dbg( p_input
, "waiting decoder fifos to empty" );
566 msleep( INPUT_IDLE_SLEEP
);
569 /* We have finished */
570 p_input
->b_eof
= VLC_TRUE
;
578 Destroy( p_input
, NULL
);
582 /*****************************************************************************
583 * Main loop: Fill buffers from access, and demux
584 *****************************************************************************/
585 static void MainLoop( input_thread_t
*p_input
)
587 int64_t i_start_mdate
= mdate();
588 int64_t i_intf_update
= 0;
591 while( !p_input
->b_die
&& !p_input
->b_error
&& !p_input
->p
->input
.b_eof
)
593 vlc_bool_t b_force_update
= VLC_FALSE
;
599 if( p_input
->i_state
!= PAUSE_S
)
601 if( ( p_input
->p
->i_stop
> 0 && p_input
->i_time
>= p_input
->p
->i_stop
) ||
602 ( p_input
->p
->i_run
> 0 && i_start_mdate
+p_input
->p
->i_run
< mdate() ) )
605 i_ret
= p_input
->p
->input
.p_demux
->pf_demux(p_input
->p
->input
.p_demux
);
610 if( p_input
->p
->input
.b_title_demux
&&
611 p_input
->p
->input
.p_demux
->info
.i_update
)
613 i_ret
= UpdateFromDemux( p_input
);
614 b_force_update
= VLC_TRUE
;
616 else if( !p_input
->p
->input
.b_title_demux
&&
617 p_input
->p
->input
.p_access
&&
618 p_input
->p
->input
.p_access
->info
.i_update
)
620 i_ret
= UpdateFromAccess( p_input
);
621 b_force_update
= VLC_TRUE
;
625 if( i_ret
== 0 ) /* EOF */
629 var_Get( p_input
, "input-repeat", &repeat
);
630 if( repeat
.i_int
== 0 )
632 /* End of file - we do not set b_die because only the
633 * playlist is allowed to do so. */
634 input_ChangeState( p_input
, END_S
);
635 msg_Dbg( p_input
, "EOF reached" );
636 p_input
->p
->input
.b_eof
= VLC_TRUE
;
640 msg_Dbg( p_input
, "repeating the same input (%d)",
642 if( repeat
.i_int
> 0 )
645 var_Set( p_input
, "input-repeat", repeat
);
648 /* Seek to start title/seekpoint */
649 val
.i_int
= p_input
->p
->input
.i_title_start
-
650 p_input
->p
->input
.i_title_offset
;
651 if( val
.i_int
< 0 || val
.i_int
>= p_input
->p
->input
.i_title
)
653 input_ControlPush( p_input
,
654 INPUT_CONTROL_SET_TITLE
, &val
);
656 val
.i_int
= p_input
->p
->input
.i_seekpoint_start
-
657 p_input
->p
->input
.i_seekpoint_offset
;
658 if( val
.i_int
> 0 /* TODO: check upper boundary */ )
659 input_ControlPush( p_input
,
660 INPUT_CONTROL_SET_SEEKPOINT
, &val
);
662 /* Seek to start position */
663 if( p_input
->p
->i_start
> 0 )
665 val
.i_time
= p_input
->p
->i_start
;
666 input_ControlPush( p_input
, INPUT_CONTROL_SET_TIME
,
672 input_ControlPush( p_input
, INPUT_CONTROL_SET_POSITION
,
677 i_start_mdate
= mdate();
682 p_input
->b_error
= VLC_TRUE
;
685 if( i_ret
> 0 && p_input
->p
->i_slave
> 0 )
687 SlaveDemux( p_input
);
697 vlc_mutex_lock( &p_input
->p
->lock_control
);
698 ControlReduce( p_input
);
699 while( !ControlPopNoLock( p_input
, &i_type
, &val
) )
701 msg_Dbg( p_input
, "control type=%d", i_type
);
702 if( Control( p_input
, i_type
, val
) )
703 b_force_update
= VLC_TRUE
;
705 vlc_mutex_unlock( &p_input
->p
->lock_control
);
707 if( b_force_update
|| i_intf_update
< mdate() )
711 int64_t i_time
, i_length
;
712 /* update input status variables */
713 if( !demux2_Control( p_input
->p
->input
.p_demux
,
714 DEMUX_GET_POSITION
, &f_pos
) )
716 val
.f_float
= (float)f_pos
;
717 var_Change( p_input
, "position", VLC_VAR_SETVALUE
, &val
, NULL
);
719 if( !demux2_Control( p_input
->p
->input
.p_demux
,
720 DEMUX_GET_TIME
, &i_time
) )
722 p_input
->i_time
= i_time
;
724 var_Change( p_input
, "time", VLC_VAR_SETVALUE
, &val
, NULL
);
726 if( !demux2_Control( p_input
->p
->input
.p_demux
,
727 DEMUX_GET_LENGTH
, &i_length
) )
730 var_Get( p_input
, "length", &old_val
);
731 val
.i_time
= i_length
;
732 var_Change( p_input
, "length", VLC_VAR_SETVALUE
, &val
, NULL
);
734 if( old_val
.i_time
!= val
.i_time
)
736 UpdateItemLength( p_input
, i_length
);
740 var_SetBool( p_input
, "intf-change", VLC_TRUE
);
741 i_intf_update
= mdate() + I64C(150000);
743 /* 150ms * 8 = ~ 1 second */
744 if( ++i_updates
% 8 == 0 )
746 stats_ComputeInputStats( p_input
, p_input
->p
->input
.p_item
->p_stats
);
747 /* Are we the thread responsible for computing global stats ? */
748 if( p_input
->p_libvlc
->p_playlist
->p_stats_computer
== p_input
)
750 stats_ComputeGlobalStats( p_input
->p_libvlc
->p_playlist
,
751 p_input
->p_libvlc
->p_playlist
->p_stats
);
757 static int Init( input_thread_t
* p_input
)
767 /* Initialize optional stream output. (before access/demuxer)
768 * XXX: we add a special case if the uri starts by vlc.
769 * else 'vlc in.file --sout "" vlc:quit' cannot work (the output will
770 * be destroyed in case of a file).
771 * (this will break playing of file starting by 'vlc:' but I don't
772 * want to add more logic, just force file by file:// or code it ;)
774 memset( &p_input
->p
->counters
, 0, sizeof( p_input
->p
->counters
) );
775 vlc_mutex_init( p_input
, &p_input
->p
->counters
.counters_lock
);
777 for( i
= 0; i
< p_input
->p
->input
.p_item
->i_options
; i
++ )
779 if( !strncmp( p_input
->p
->input
.p_item
->ppsz_options
[i
], "meta-file", 9 ) )
781 msg_Dbg( p_input
, "Input is a meta file: disabling unneeded options" );
782 var_SetString( p_input
, "sout", "" );
783 var_SetBool( p_input
, "sout-all", VLC_FALSE
);
784 var_SetString( p_input
, "input-slave", "" );
785 var_SetInteger( p_input
, "input-repeat", 0 );
786 var_SetString( p_input
, "sub-file", "" );
787 var_SetBool( p_input
, "sub-autodetect-file", VLC_FALSE
);
791 if( !p_input
->b_preparsing
)
793 /* Prepare statistics */
794 #define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \
795 stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
796 if( p_input
->p_libvlc
->b_stats
)
798 INIT_COUNTER( read_bytes
, INTEGER
, COUNTER
);
799 INIT_COUNTER( read_packets
, INTEGER
, COUNTER
);
800 INIT_COUNTER( demux_read
, INTEGER
, COUNTER
);
801 INIT_COUNTER( input_bitrate
, FLOAT
, DERIVATIVE
);
802 INIT_COUNTER( demux_bitrate
, FLOAT
, DERIVATIVE
);
803 INIT_COUNTER( played_abuffers
, INTEGER
, COUNTER
);
804 INIT_COUNTER( lost_abuffers
, INTEGER
, COUNTER
);
805 INIT_COUNTER( displayed_pictures
, INTEGER
, COUNTER
);
806 INIT_COUNTER( lost_pictures
, INTEGER
, COUNTER
);
807 INIT_COUNTER( decoded_audio
, INTEGER
, COUNTER
);
808 INIT_COUNTER( decoded_video
, INTEGER
, COUNTER
);
809 INIT_COUNTER( decoded_sub
, INTEGER
, COUNTER
);
810 p_input
->p
->counters
.p_sout_send_bitrate
= NULL
;
811 p_input
->p
->counters
.p_sout_sent_packets
= NULL
;
812 p_input
->p
->counters
.p_sout_sent_bytes
= NULL
;
813 if( p_input
->p
->counters
.p_demux_bitrate
)
814 p_input
->p
->counters
.p_demux_bitrate
->update_interval
= 1000000;
815 if( p_input
->p
->counters
.p_input_bitrate
)
816 p_input
->p
->counters
.p_input_bitrate
->update_interval
= 1000000;
819 /* Find a usable sout and attach it to p_input */
820 psz
= var_GetNonEmptyString( p_input
, "sout" );
821 if( psz
&& strncasecmp( p_input
->p
->input
.p_item
->psz_uri
, "vlc:", 4 ) )
823 /* Check the validity of the provided sout */
824 if( p_input
->p
->p_sout
)
826 if( strcmp( p_input
->p
->p_sout
->psz_sout
, psz
) )
828 msg_Dbg( p_input
, "destroying unusable sout" );
830 sout_DeleteInstance( p_input
->p
->p_sout
);
831 p_input
->p
->p_sout
= NULL
;
835 if( p_input
->p
->p_sout
)
838 msg_Dbg( p_input
, "sout keep: reusing sout" );
839 msg_Dbg( p_input
, "sout keep: you probably want to use "
840 "gather stream_out" );
841 vlc_object_attach( p_input
->p
->p_sout
, p_input
);
845 /* Create a new one */
846 p_input
->p
->p_sout
= sout_NewInstance( p_input
, psz
);
847 if( !p_input
->p
->p_sout
)
849 input_ChangeState( p_input
, ERROR_S
);
850 msg_Err( p_input
, "cannot start stream output instance, " \
857 if( p_input
->p_libvlc
->b_stats
)
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
=
867 else if( p_input
->p
->p_sout
)
869 msg_Dbg( p_input
, "destroying useless sout" );
871 sout_DeleteInstance( p_input
->p
->p_sout
);
872 p_input
->p
->p_sout
= NULL
;
878 p_input
->p
->p_es_out
= input_EsOutNew( p_input
, p_input
->p
->i_rate
);
879 es_out_Control( p_input
->p
->p_es_out
, ES_OUT_SET_ACTIVE
, VLC_FALSE
);
880 es_out_Control( p_input
->p
->p_es_out
, ES_OUT_SET_MODE
, ES_OUT_MODE_NONE
);
882 var_Create( p_input
, "bit-rate", VLC_VAR_INTEGER
);
883 var_Create( p_input
, "sample-rate", VLC_VAR_INTEGER
);
885 if( InputSourceInit( p_input
, &p_input
->p
->input
,
886 p_input
->p
->input
.p_item
->psz_uri
, NULL
) )
891 /* Create global title (from master) */
892 if( !p_input
->b_preparsing
)
894 p_input
->p
->i_title
= p_input
->p
->input
.i_title
;
895 p_input
->p
->title
= p_input
->p
->input
.title
;
896 p_input
->p
->i_title_offset
= p_input
->p
->input
.i_title_offset
;
897 p_input
->p
->i_seekpoint_offset
= p_input
->p
->input
.i_seekpoint_offset
;
898 if( p_input
->p
->i_title
> 0 )
900 /* Setup variables */
901 input_ControlVarNavigation( p_input
);
902 input_ControlVarTitle( p_input
, 0 );
906 p_input
->b_can_pace_control
= p_input
->p
->input
.b_can_pace_control
;
907 p_input
->p
->b_can_pause
= p_input
->p
->input
.b_can_pause
;
908 p_input
->p
->b_can_rate_control
= p_input
->p
->input
.b_can_rate_control
;
911 if( p_input
->i_pts_delay
< 0 )
912 p_input
->i_pts_delay
= 0;
914 /* If the desynchronisation requested by the user is < 0, we need to
915 * cache more data. */
916 var_Get( p_input
, "audio-desync", &val
);
917 if( val
.i_int
< 0 ) p_input
->i_pts_delay
-= (val
.i_int
* 1000);
919 /* Update cr_average depending on the caching */
920 p_input
->p
->input
.i_cr_average
*= (10 * p_input
->i_pts_delay
/ 200000);
921 p_input
->p
->input
.i_cr_average
/= 10;
922 if( p_input
->p
->input
.i_cr_average
< 10 ) p_input
->p
->input
.i_cr_average
= 10;
925 /* Load master infos */
927 if( !demux2_Control( p_input
->p
->input
.p_demux
, DEMUX_GET_LENGTH
,
928 &val
.i_time
) && val
.i_time
> 0 )
930 var_Change( p_input
, "length", VLC_VAR_SETVALUE
, &val
, NULL
);
931 UpdateItemLength( p_input
, val
.i_time
);
935 val
.i_time
= input_item_GetDuration( p_input
->p
->input
.p_item
);
937 { /* fallback: gets length from metadata */
938 var_Change( p_input
, "length", VLC_VAR_SETVALUE
, &val
, NULL
);
939 UpdateItemLength( p_input
, val
.i_time
);
943 /* Start title/chapter */
944 if( !p_input
->b_preparsing
)
946 val
.i_int
= p_input
->p
->input
.i_title_start
-
947 p_input
->p
->input
.i_title_offset
;
948 if( val
.i_int
> 0 && val
.i_int
< p_input
->p
->input
.i_title
)
949 input_ControlPush( p_input
, INPUT_CONTROL_SET_TITLE
, &val
);
950 val
.i_int
= p_input
->p
->input
.i_seekpoint_start
-
951 p_input
->p
->input
.i_seekpoint_offset
;
952 if( val
.i_int
> 0 /* TODO: check upper boundary */ )
953 input_ControlPush( p_input
, INPUT_CONTROL_SET_SEEKPOINT
, &val
);
957 p_input
->p
->i_start
= I64C(1000000) * var_GetInteger( p_input
, "start-time" );
958 p_input
->p
->i_stop
= I64C(1000000) * var_GetInteger( p_input
, "stop-time" );
959 p_input
->p
->i_run
= I64C(1000000) * var_GetInteger( p_input
, "run-time" );
960 if( p_input
->p
->i_run
< 0 )
962 msg_Warn( p_input
, "invalid run-time ignored" );
963 p_input
->p
->i_run
= 0;
966 if( p_input
->p
->i_start
> 0 )
968 if( p_input
->p
->i_start
>= val
.i_time
)
970 msg_Warn( p_input
, "invalid start-time ignored" );
976 msg_Dbg( p_input
, "starting at time: %ds",
977 (int)( p_input
->p
->i_start
/ I64C(1000000) ) );
979 s
.i_time
= p_input
->p
->i_start
;
980 input_ControlPush( p_input
, INPUT_CONTROL_SET_TIME
, &s
);
983 if( p_input
->p
->i_stop
> 0 && p_input
->p
->i_stop
<= p_input
->p
->i_start
)
985 msg_Warn( p_input
, "invalid stop-time ignored" );
986 p_input
->p
->i_stop
= 0;
990 /* Get fps and set it if not already set */
991 if( !demux2_Control( p_input
->p
->input
.p_demux
, DEMUX_GET_FPS
, &f_fps
) &&
994 float f_requested_fps
;
996 var_Create( p_input
, "sub-original-fps", VLC_VAR_FLOAT
);
997 var_SetFloat( p_input
, "sub-original-fps", f_fps
);
999 f_requested_fps
= var_CreateGetFloat( p_input
, "sub-fps" );
1000 if( f_requested_fps
!= f_fps
)
1002 var_Create( p_input
, "sub-fps", VLC_VAR_FLOAT
|
1003 VLC_VAR_DOINHERIT
);
1004 var_SetFloat( p_input
, "sub-fps", f_requested_fps
);
1008 i_delay
= var_CreateGetInteger( p_input
, "sub-delay" );
1011 var_SetTime( p_input
, "spu-delay", (mtime_t
)i_delay
* 100000 );
1014 /* Look for and add subtitle files */
1015 psz_subtitle
= var_GetNonEmptyString( p_input
, "sub-file" );
1016 if( psz_subtitle
!= NULL
)
1018 msg_Dbg( p_input
, "forced subtitle: %s", psz_subtitle
);
1019 input_AddSubtitles( p_input
, psz_subtitle
, VLC_FALSE
);
1022 var_Get( p_input
, "sub-autodetect-file", &val
);
1025 char *psz_autopath
= var_GetNonEmptyString( p_input
, "sub-autodetect-path" );
1026 char **subs
= subtitles_Detect( p_input
, psz_autopath
,
1027 p_input
->p
->input
.p_item
->psz_uri
);
1028 input_source_t
*sub
;
1030 if( psz_autopath
== NULL
)
1031 psz_autopath
= strdup("");
1033 /* Try to autoselect the first autodetected subtitles file
1034 * if no subtitles file was specified */
1035 if( ( psz_subtitle
== NULL
) && subs
&& subs
[0] )
1037 input_AddSubtitles( p_input
, subs
[0], VLC_FALSE
);
1042 /* Then, just add the following subtitles files */
1043 for( ; subs
&& subs
[i
]; i
++ )
1045 if( !psz_subtitle
|| strcmp( psz_subtitle
, subs
[i
] ) )
1047 sub
= InputSourceNew( p_input
);
1048 if( !InputSourceInit( p_input
, sub
, subs
[i
], "subtitle" ) )
1050 TAB_APPEND( p_input
->p
->i_slave
, p_input
->p
->slave
, sub
);
1057 free( psz_autopath
);
1059 free( psz_subtitle
);
1061 /* Look for slave */
1062 psz
= var_GetNonEmptyString( p_input
, "input-slave" );
1066 input_source_t
*slave
;
1067 while( psz
&& *psz
)
1069 while( *psz
== ' ' || *psz
== '#' )
1073 if( ( psz_delim
= strchr( psz
, '#' ) ) )
1075 *psz_delim
++ = '\0';
1082 msg_Dbg( p_input
, "adding slave input '%s'", psz
);
1083 slave
= InputSourceNew( p_input
);
1084 if( !InputSourceInit( p_input
, slave
, psz
, NULL
) )
1086 TAB_APPEND( p_input
->p
->i_slave
, p_input
->p
->slave
, slave
);
1096 p_input
->p
->i_start
= 0;
1097 p_input
->p
->i_start
= 0;
1101 if( !p_input
->b_preparsing
)
1103 es_out_Control( p_input
->p
->p_es_out
, ES_OUT_SET_ACTIVE
, VLC_TRUE
);
1104 i_es_out_mode
= ES_OUT_MODE_AUTO
;
1106 if( p_input
->p
->p_sout
)
1108 var_Get( p_input
, "sout-all", &val
);
1111 i_es_out_mode
= ES_OUT_MODE_ALL
;
1116 var_Get( p_input
, "programs", &val
);
1117 if ( val
.p_list
&& val
.p_list
->i_count
)
1119 i_es_out_mode
= ES_OUT_MODE_PARTIAL
;
1120 /* Note : we should remove the "program" callback. */
1123 var_Change( p_input
, "programs", VLC_VAR_FREELIST
, &val
,
1127 es_out_Control( p_input
->p
->p_es_out
, ES_OUT_SET_MODE
, i_es_out_mode
);
1129 /* Inform the demuxer about waited group (needed only for DVB) */
1130 if( i_es_out_mode
== ES_OUT_MODE_ALL
)
1132 demux2_Control( p_input
->p
->input
.p_demux
, DEMUX_SET_GROUP
, -1, NULL
);
1134 else if( i_es_out_mode
== ES_OUT_MODE_PARTIAL
)
1136 demux2_Control( p_input
->p
->input
.p_demux
, DEMUX_SET_GROUP
, -1,
1141 demux2_Control( p_input
->p
->input
.p_demux
, DEMUX_SET_GROUP
,
1142 (int) var_GetInteger( p_input
, "program" ), NULL
);
1145 if( p_input
->p
->p_sout
)
1147 if( p_input
->p
->p_sout
->i_out_pace_nocontrol
> 0 )
1149 p_input
->p
->b_out_pace_control
= VLC_FALSE
;
1153 p_input
->p
->b_out_pace_control
= VLC_TRUE
;
1156 if( p_input
->b_can_pace_control
&& p_input
->p
->b_out_pace_control
)
1158 /* We don't want a high input priority here or we'll
1159 * end-up sucking up all the CPU time */
1160 vlc_thread_set_priority( p_input
, VLC_THREAD_PRIORITY_LOW
);
1163 msg_Dbg( p_input
, "starting in %s mode",
1164 p_input
->p
->b_out_pace_control
? "async" : "sync" );
1168 p_meta
= vlc_meta_New();
1169 /* Get meta data from users */
1170 InputMetaUser( p_input
, p_meta
);
1172 /* Get meta data from master input */
1173 DemuxMeta( p_input
, p_meta
, p_input
->p
->input
.p_demux
);
1175 /* Access_file does not give any meta, and there are no slave */
1176 if( !p_input
->b_preparsing
)
1178 if( p_input
->p
->input
.p_access
)
1179 access2_Control( p_input
->p
->input
.p_access
, ACCESS_GET_META
,
1182 /* Get meta data from slave input */
1183 for( i
= 0; i
< p_input
->p
->i_slave
; i
++ )
1185 DemuxMeta( p_input
, p_meta
, p_input
->p
->slave
[i
]->p_demux
);
1186 if( p_input
->p
->slave
[i
]->p_access
)
1188 access2_Control( p_input
->p
->slave
[i
]->p_access
,
1189 ACCESS_GET_META
, p_meta
);
1194 InputUpdateMeta( p_input
, p_meta
);
1196 if( !p_input
->b_preparsing
)
1198 msg_Dbg( p_input
, "`%s' successfully opened",
1199 p_input
->p
->input
.p_item
->psz_uri
);
1203 /* initialization is complete */
1204 input_ChangeState( p_input
, PLAYING_S
);
1209 input_ChangeState( p_input
, ERROR_S
);
1211 if( p_input
->p
->p_es_out
)
1212 input_EsOutDelete( p_input
->p
->p_es_out
);
1214 if( p_input
->p
->p_sout
)
1216 vlc_object_detach( p_input
->p
->p_sout
);
1217 sout_DeleteInstance( p_input
->p
->p_sout
);
1221 if( !p_input
->b_preparsing
&& p_input
->p_libvlc
->b_stats
)
1223 #define EXIT_COUNTER( c ) do { if( p_input->p->counters.p_##c ) \
1224 stats_CounterClean( p_input->p->counters.p_##c );\
1225 p_input->p->counters.p_##c = NULL; } while(0)
1226 EXIT_COUNTER( read_bytes
);
1227 EXIT_COUNTER( read_packets
);
1228 EXIT_COUNTER( demux_read
);
1229 EXIT_COUNTER( input_bitrate
);
1230 EXIT_COUNTER( demux_bitrate
);
1231 EXIT_COUNTER( played_abuffers
);
1232 EXIT_COUNTER( lost_abuffers
);
1233 EXIT_COUNTER( displayed_pictures
);
1234 EXIT_COUNTER( lost_pictures
);
1235 EXIT_COUNTER( decoded_audio
);
1236 EXIT_COUNTER( decoded_video
);
1237 EXIT_COUNTER( decoded_sub
);
1239 if( p_input
->p
->p_sout
)
1241 EXIT_COUNTER( sout_sent_packets
);
1242 EXIT_COUNTER (sout_sent_bytes
);
1243 EXIT_COUNTER( sout_send_bitrate
);
1248 /* Mark them deleted */
1249 p_input
->p
->input
.p_demux
= NULL
;
1250 p_input
->p
->input
.p_stream
= NULL
;
1251 p_input
->p
->input
.p_access
= NULL
;
1252 p_input
->p
->p_es_out
= NULL
;
1253 p_input
->p
->p_sout
= NULL
;
1255 return VLC_EGENERIC
;
1258 /*****************************************************************************
1259 * Error: RunThread() error loop
1260 *****************************************************************************
1261 * This function is called when an error occurred during thread main's loop.
1262 *****************************************************************************/
1263 static void Error( input_thread_t
*p_input
)
1265 input_ChangeState( p_input
, ERROR_S
);
1266 while( !p_input
->b_die
)
1269 msleep( INPUT_IDLE_SLEEP
);
1273 /*****************************************************************************
1274 * End: end the input thread
1275 *****************************************************************************/
1276 static void End( input_thread_t
* p_input
)
1280 /* We are at the end */
1281 input_ChangeState( p_input
, END_S
);
1283 /* Clean control variables */
1284 input_ControlVarClean( p_input
);
1286 /* Clean up master */
1287 InputSourceClean( &p_input
->p
->input
);
1290 for( i
= 0; i
< p_input
->p
->i_slave
; i
++ )
1292 InputSourceClean( p_input
->p
->slave
[i
] );
1293 free( p_input
->p
->slave
[i
] );
1295 free( p_input
->p
->slave
);
1297 /* Unload all modules */
1298 if( p_input
->p
->p_es_out
)
1299 input_EsOutDelete( p_input
->p
->p_es_out
);
1301 if( !p_input
->b_preparsing
)
1303 #define CL_CO( c ) stats_CounterClean( p_input->p->counters.p_##c ); p_input->p->counters.p_##c = NULL;
1304 if( p_input
->p_libvlc
->b_stats
)
1306 /* make sure we are up to date */
1307 stats_ComputeInputStats( p_input
, p_input
->p
->input
.p_item
->p_stats
);
1308 if( p_input
->p_libvlc
->p_playlist
->p_stats_computer
== p_input
)
1310 stats_ComputeGlobalStats( p_input
->p_libvlc
->p_playlist
,
1311 p_input
->p_libvlc
->p_playlist
->p_stats
);
1312 p_input
->p_libvlc
->p_playlist
->p_stats_computer
= NULL
;
1314 CL_CO( read_bytes
);
1315 CL_CO( read_packets
);
1316 CL_CO( demux_read
);
1317 CL_CO( input_bitrate
);
1318 CL_CO( demux_bitrate
);
1319 CL_CO( played_abuffers
);
1320 CL_CO( lost_abuffers
);
1321 CL_CO( displayed_pictures
);
1322 CL_CO( lost_pictures
);
1323 CL_CO( decoded_audio
) ;
1324 CL_CO( decoded_video
);
1325 CL_CO( decoded_sub
) ;
1328 /* Close optional stream output instance */
1329 if( p_input
->p
->p_sout
)
1331 CL_CO( sout_sent_packets
);
1332 CL_CO( sout_sent_bytes
);
1333 CL_CO( sout_send_bitrate
);
1335 vlc_object_detach( p_input
->p
->p_sout
);
1340 if( p_input
->p
->i_attachment
> 0 )
1342 for( i
= 0; i
< p_input
->p
->i_attachment
; i
++ )
1343 vlc_input_attachment_Delete( p_input
->p
->attachment
[i
] );
1344 TAB_CLEAN( p_input
->p
->i_attachment
, p_input
->p
->attachment
);
1347 vlc_mutex_destroy( &p_input
->p
->counters
.counters_lock
);
1349 /* Tell we're dead */
1350 p_input
->b_dead
= VLC_TRUE
;
1353 static sout_instance_t
*SoutFind( vlc_object_t
*p_parent
, input_item_t
*p_item
, vlc_bool_t
*pb_sout_keep
)
1355 vlc_bool_t b_keep_sout
= var_CreateGetBool( p_parent
, "sout-keep" );
1356 sout_instance_t
*p_sout
= NULL
;
1359 /* Search sout-keep options
1360 * XXX it has to be done here, but it is duplicated work :( */
1361 vlc_mutex_lock( &p_item
->lock
);
1362 for( i
= 0; i
< p_item
->i_options
; i
++ )
1364 const char *psz_option
= p_item
->ppsz_options
[i
];
1367 if( *psz_option
== ':' )
1370 if( !strcmp( psz_option
, "sout-keep" ) )
1371 b_keep_sout
= VLC_TRUE
;
1372 else if( !strcmp( psz_option
, "no-sout-keep" ) || !strcmp( psz_option
, "nosout-keep" ) )
1373 b_keep_sout
= VLC_FALSE
;
1375 vlc_mutex_unlock( &p_item
->lock
);
1377 /* Find a potential sout to reuse
1378 * XXX it might be unusable but this will be checked later */
1381 /* Remove the sout from the playlist garbage collector */
1382 playlist_t
*p_playlist
= pl_Yield( p_parent
);
1384 vlc_mutex_lock( &p_playlist
->gc_lock
);
1385 p_sout
= vlc_object_find( p_playlist
, VLC_OBJECT_SOUT
, FIND_CHILD
);
1388 if( p_sout
->p_parent
!= VLC_OBJECT(p_playlist
) )
1390 vlc_object_release( p_sout
);
1395 vlc_object_detach( p_sout
); /* Remove it from the GC */
1397 vlc_object_release( p_sout
);
1400 vlc_mutex_unlock( &p_playlist
->gc_lock
);
1402 pl_Release( p_parent
);
1406 *pb_sout_keep
= b_keep_sout
;
1410 static void SoutKeep( sout_instance_t
*p_sout
)
1412 /* attach sout to the playlist */
1413 playlist_t
*p_playlist
= pl_Yield( p_sout
);
1415 msg_Dbg( p_sout
, "sout has been kept" );
1416 vlc_object_attach( p_sout
, p_playlist
);
1418 pl_Release( p_sout
);
1421 /*****************************************************************************
1423 *****************************************************************************/
1424 static inline int ControlPopNoLock( input_thread_t
*p_input
,
1425 int *pi_type
, vlc_value_t
*p_val
)
1427 if( p_input
->p
->i_control
<= 0 )
1429 return VLC_EGENERIC
;
1432 *pi_type
= p_input
->p
->control
[0].i_type
;
1433 *p_val
= p_input
->p
->control
[0].val
;
1435 p_input
->p
->i_control
--;
1436 if( p_input
->p
->i_control
> 0 )
1440 for( i
= 0; i
< p_input
->p
->i_control
; i
++ )
1442 p_input
->p
->control
[i
].i_type
= p_input
->p
->control
[i
+1].i_type
;
1443 p_input
->p
->control
[i
].val
= p_input
->p
->control
[i
+1].val
;
1450 static void ControlReduce( input_thread_t
*p_input
)
1457 for( i
= 1; i
< p_input
->p
->i_control
; i
++ )
1459 const int i_lt
= p_input
->p
->control
[i
-1].i_type
;
1460 const int i_ct
= p_input
->p
->control
[i
].i_type
;
1462 /* XXX We can't merge INPUT_CONTROL_SET_ES */
1463 /* msg_Dbg( p_input, "[%d/%d] l=%d c=%d", i, p_input->p->i_control,
1467 ( i_ct
== INPUT_CONTROL_SET_STATE
||
1468 i_ct
== INPUT_CONTROL_SET_RATE
||
1469 i_ct
== INPUT_CONTROL_SET_POSITION
||
1470 i_ct
== INPUT_CONTROL_SET_TIME
||
1471 i_ct
== INPUT_CONTROL_SET_PROGRAM
||
1472 i_ct
== INPUT_CONTROL_SET_TITLE
||
1473 i_ct
== INPUT_CONTROL_SET_SEEKPOINT
||
1474 i_ct
== INPUT_CONTROL_SET_BOOKMARK
) )
1477 // msg_Dbg( p_input, "merged at %d", i );
1478 /* Remove the i-1 */
1479 for( j
= i
; j
< p_input
->p
->i_control
; j
++ )
1480 p_input
->p
->control
[j
-1] = p_input
->p
->control
[j
];
1481 p_input
->p
->i_control
--;
1485 /* TODO but that's not that important
1486 - merge SET_X with SET_X_CMD
1487 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before a SET_TITLE
1488 - remove SET_SEEKPOINT/SET_POSITION/SET_TIME before another among them
1495 static vlc_bool_t
Control( input_thread_t
*p_input
, int i_type
,
1498 vlc_bool_t b_force_update
= VLC_FALSE
;
1500 if( !p_input
) return b_force_update
;
1504 case INPUT_CONTROL_SET_DIE
:
1505 msg_Dbg( p_input
, "control: stopping input" );
1506 /* Mark all submodules to die */
1507 if( p_input
->p
->input
.p_access
)
1508 vlc_object_kill( p_input
->p
->input
.p_access
);
1509 if( p_input
->p
->input
.p_stream
)
1510 vlc_object_kill( p_input
->p
->input
.p_stream
);
1511 vlc_object_kill( p_input
->p
->input
.p_demux
);
1513 vlc_object_kill( p_input
);
1516 case INPUT_CONTROL_SET_POSITION
:
1517 case INPUT_CONTROL_SET_POSITION_OFFSET
:
1520 if( i_type
== INPUT_CONTROL_SET_POSITION
)
1522 f_pos
= val
.f_float
;
1526 /* Should not fail */
1527 demux2_Control( p_input
->p
->input
.p_demux
,
1528 DEMUX_GET_POSITION
, &f_pos
);
1529 f_pos
+= val
.f_float
;
1531 if( f_pos
< 0.0 ) f_pos
= 0.0;
1532 if( f_pos
> 1.0 ) f_pos
= 1.0;
1533 /* Reset the decoders states and clock sync (before calling the demuxer */
1534 input_EsOutChangePosition( p_input
->p
->p_es_out
);
1535 if( demux2_Control( p_input
->p
->input
.p_demux
, DEMUX_SET_POSITION
,
1538 msg_Err( p_input
, "INPUT_CONTROL_SET_POSITION(_OFFSET) "
1539 "%2.1f%% failed", f_pos
* 100 );
1543 if( p_input
->p
->i_slave
> 0 )
1544 SlaveSeek( p_input
);
1546 b_force_update
= VLC_TRUE
;
1551 case INPUT_CONTROL_SET_TIME
:
1552 case INPUT_CONTROL_SET_TIME_OFFSET
:
1557 if( i_type
== INPUT_CONTROL_SET_TIME
)
1559 i_time
= val
.i_time
;
1563 /* Should not fail */
1564 demux2_Control( p_input
->p
->input
.p_demux
,
1565 DEMUX_GET_TIME
, &i_time
);
1566 i_time
+= val
.i_time
;
1568 if( i_time
< 0 ) i_time
= 0;
1570 /* Reset the decoders states and clock sync (before calling the demuxer */
1571 input_EsOutChangePosition( p_input
->p
->p_es_out
);
1573 i_ret
= demux2_Control( p_input
->p
->input
.p_demux
,
1574 DEMUX_SET_TIME
, i_time
);
1579 /* Emulate it with a SET_POS */
1580 demux2_Control( p_input
->p
->input
.p_demux
,
1581 DEMUX_GET_LENGTH
, &i_length
);
1584 double f_pos
= (double)i_time
/ (double)i_length
;
1585 i_ret
= demux2_Control( p_input
->p
->input
.p_demux
,
1586 DEMUX_SET_POSITION
, f_pos
);
1591 msg_Warn( p_input
, "INPUT_CONTROL_SET_TIME(_OFFSET) "I64Fd
1592 " failed or not possible", i_time
);
1596 if( p_input
->p
->i_slave
> 0 )
1597 SlaveSeek( p_input
);
1599 b_force_update
= VLC_TRUE
;
1604 case INPUT_CONTROL_SET_STATE
:
1605 if( ( val
.i_int
== PLAYING_S
&& p_input
->i_state
== PAUSE_S
) ||
1606 ( val
.i_int
== PAUSE_S
&& p_input
->i_state
== PAUSE_S
) )
1609 if( p_input
->p
->input
.p_access
)
1610 i_ret
= access2_Control( p_input
->p
->input
.p_access
,
1611 ACCESS_SET_PAUSE_STATE
, VLC_FALSE
);
1613 i_ret
= demux2_Control( p_input
->p
->input
.p_demux
,
1614 DEMUX_SET_PAUSE_STATE
, VLC_FALSE
);
1618 /* FIXME What to do ? */
1619 msg_Warn( p_input
, "cannot unset pause -> EOF" );
1620 vlc_mutex_unlock( &p_input
->p
->lock_control
);
1621 input_ControlPush( p_input
, INPUT_CONTROL_SET_DIE
, NULL
);
1622 vlc_mutex_lock( &p_input
->p
->lock_control
);
1625 b_force_update
= VLC_TRUE
;
1627 /* Switch to play */
1628 p_input
->i_state
= PLAYING_S
;
1629 val
.i_int
= PLAYING_S
;
1630 var_Change( p_input
, "state", VLC_VAR_SETVALUE
, &val
, NULL
);
1634 input_EsOutChangeState( p_input
->p
->p_es_out
);
1636 else if( val
.i_int
== PAUSE_S
&& p_input
->i_state
== PLAYING_S
&&
1637 p_input
->p
->b_can_pause
)
1640 if( p_input
->p
->input
.p_access
)
1641 i_ret
= access2_Control( p_input
->p
->input
.p_access
,
1642 ACCESS_SET_PAUSE_STATE
, VLC_TRUE
);
1644 i_ret
= demux2_Control( p_input
->p
->input
.p_demux
,
1645 DEMUX_SET_PAUSE_STATE
, VLC_TRUE
);
1647 b_force_update
= VLC_TRUE
;
1651 msg_Warn( p_input
, "cannot set pause state" );
1652 val
.i_int
= p_input
->i_state
;
1656 val
.i_int
= PAUSE_S
;
1659 /* Switch to new state */
1660 p_input
->i_state
= val
.i_int
;
1661 var_Change( p_input
, "state", VLC_VAR_SETVALUE
, &val
, NULL
);
1665 input_EsOutChangeState( p_input
->p
->p_es_out
);
1667 else if( val
.i_int
== PAUSE_S
&& !p_input
->p
->b_can_pause
)
1669 b_force_update
= VLC_TRUE
;
1671 /* Correct "state" value */
1672 val
.i_int
= p_input
->i_state
;
1673 var_Change( p_input
, "state", VLC_VAR_SETVALUE
, &val
, NULL
);
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
:
1687 if( i_type
== INPUT_CONTROL_SET_RATE
)
1693 static const int ppi_factor
[][2] = {
1694 {1,64}, {1,32}, {1,16}, {1,8}, {1,4}, {1,3}, {1,2}, {2,3},
1696 {3,2}, {2,1}, {3,1}, {4,1}, {8,1}, {16,1}, {32,1}, {64,1},
1705 for( i
= 0; ppi_factor
[i
][0] != 0; i
++ )
1707 const int i_test_r
= INPUT_RATE_DEFAULT
* ppi_factor
[i
][0] / ppi_factor
[i
][1];
1708 const int i_test_e
= abs(p_input
->p
->i_rate
- i_test_r
);
1709 if( i_test_e
< i_error
)
1715 assert( i_idx
>= 0 && ppi_factor
[i_idx
][0] != 0 );
1717 if( i_type
== INPUT_CONTROL_SET_RATE_SLOWER
)
1719 if( ppi_factor
[i_idx
+1][0] > 0 )
1720 i_rate
= INPUT_RATE_DEFAULT
* ppi_factor
[i_idx
+1][0] / ppi_factor
[i_idx
+1][1];
1722 i_rate
= INPUT_RATE_MAX
+1;
1726 assert( i_type
== INPUT_CONTROL_SET_RATE_FASTER
);
1728 i_rate
= INPUT_RATE_DEFAULT
* ppi_factor
[i_idx
-1][0] / ppi_factor
[i_idx
-1][1];
1730 i_rate
= INPUT_RATE_MIN
-1;
1734 if( i_rate
< INPUT_RATE_MIN
)
1736 msg_Dbg( p_input
, "cannot set rate faster" );
1737 i_rate
= INPUT_RATE_MIN
;
1739 else if( i_rate
> INPUT_RATE_MAX
)
1741 msg_Dbg( p_input
, "cannot set rate slower" );
1742 i_rate
= INPUT_RATE_MAX
;
1744 if( i_rate
!= INPUT_RATE_DEFAULT
&&
1745 ( ( !p_input
->b_can_pace_control
&& !p_input
->p
->b_can_rate_control
) ||
1746 ( p_input
->p
->p_sout
&& !p_input
->p
->b_out_pace_control
) ) )
1748 msg_Dbg( p_input
, "cannot change rate" );
1749 i_rate
= INPUT_RATE_DEFAULT
;
1751 if( i_rate
!= p_input
->p
->i_rate
&&
1752 !p_input
->b_can_pace_control
&& p_input
->p
->b_can_rate_control
)
1755 if( p_input
->p
->input
.p_access
)
1756 i_ret
= VLC_EGENERIC
;
1758 i_ret
= demux2_Control( p_input
->p
->input
.p_demux
,
1759 DEMUX_SET_RATE
, &i_rate
);
1762 msg_Warn( p_input
, "ACCESS/DEMUX_SET_RATE failed" );
1763 i_rate
= p_input
->p
->i_rate
;
1768 if( i_rate
!= p_input
->p
->i_rate
)
1771 var_Change( p_input
, "rate", VLC_VAR_SETVALUE
, &val
, NULL
);
1772 var_SetBool( p_input
, "rate-change", VLC_TRUE
);
1774 p_input
->p
->i_rate
= i_rate
;
1776 /* FIXME do we need a RESET_PCR when !p_input->p->input.b_rescale_ts ? */
1777 if( p_input
->p
->input
.b_rescale_ts
)
1778 input_EsOutChangeRate( p_input
->p
->p_es_out
, i_rate
);
1780 b_force_update
= VLC_TRUE
;
1785 case INPUT_CONTROL_SET_PROGRAM
:
1786 /* No need to force update, es_out does it if needed */
1787 es_out_Control( p_input
->p
->p_es_out
,
1788 ES_OUT_SET_GROUP
, val
.i_int
);
1790 demux2_Control( p_input
->p
->input
.p_demux
, DEMUX_SET_GROUP
, val
.i_int
,
1794 case INPUT_CONTROL_SET_ES
:
1795 /* No need to force update, es_out does it if needed */
1796 es_out_Control( p_input
->p
->p_es_out
, ES_OUT_SET_ES
,
1797 input_EsOutGetFromID( p_input
->p
->p_es_out
,
1801 case INPUT_CONTROL_SET_AUDIO_DELAY
:
1802 input_EsOutSetDelay( p_input
->p
->p_es_out
,
1803 AUDIO_ES
, val
.i_time
);
1804 var_Change( p_input
, "audio-delay", VLC_VAR_SETVALUE
, &val
, NULL
);
1807 case INPUT_CONTROL_SET_SPU_DELAY
:
1808 input_EsOutSetDelay( p_input
->p
->p_es_out
,
1809 SPU_ES
, val
.i_time
);
1810 var_Change( p_input
, "spu-delay", VLC_VAR_SETVALUE
, &val
, NULL
);
1813 case INPUT_CONTROL_SET_TITLE
:
1814 case INPUT_CONTROL_SET_TITLE_NEXT
:
1815 case INPUT_CONTROL_SET_TITLE_PREV
:
1816 if( p_input
->p
->input
.b_title_demux
&&
1817 p_input
->p
->input
.i_title
> 0 )
1820 /* FIXME handle demux title */
1821 demux_t
*p_demux
= p_input
->p
->input
.p_demux
;
1824 if( i_type
== INPUT_CONTROL_SET_TITLE_PREV
)
1825 i_title
= p_demux
->info
.i_title
- 1;
1826 else if( i_type
== INPUT_CONTROL_SET_TITLE_NEXT
)
1827 i_title
= p_demux
->info
.i_title
+ 1;
1829 i_title
= val
.i_int
;
1831 if( i_title
>= 0 && i_title
< p_input
->p
->input
.i_title
)
1833 input_EsOutChangePosition( p_input
->p
->p_es_out
);
1835 demux2_Control( p_demux
, DEMUX_SET_TITLE
, i_title
);
1836 input_ControlVarTitle( p_input
, i_title
);
1839 else if( p_input
->p
->input
.i_title
> 0 )
1841 access_t
*p_access
= p_input
->p
->input
.p_access
;
1844 if( i_type
== INPUT_CONTROL_SET_TITLE_PREV
)
1845 i_title
= p_access
->info
.i_title
- 1;
1846 else if( i_type
== INPUT_CONTROL_SET_TITLE_NEXT
)
1847 i_title
= p_access
->info
.i_title
+ 1;
1849 i_title
= val
.i_int
;
1851 if( i_title
>= 0 && i_title
< p_input
->p
->input
.i_title
)
1853 input_EsOutChangePosition( p_input
->p
->p_es_out
);
1855 access2_Control( p_access
, ACCESS_SET_TITLE
, i_title
);
1856 stream_AccessReset( p_input
->p
->input
.p_stream
);
1860 case INPUT_CONTROL_SET_SEEKPOINT
:
1861 case INPUT_CONTROL_SET_SEEKPOINT_NEXT
:
1862 case INPUT_CONTROL_SET_SEEKPOINT_PREV
:
1863 if( p_input
->p
->input
.b_title_demux
&&
1864 p_input
->p
->input
.i_title
> 0 )
1866 demux_t
*p_demux
= p_input
->p
->input
.p_demux
;
1868 int64_t i_input_time
;
1869 int64_t i_seekpoint_time
;
1871 if( i_type
== INPUT_CONTROL_SET_SEEKPOINT_PREV
)
1873 i_seekpoint
= p_demux
->info
.i_seekpoint
;
1874 i_seekpoint_time
= p_input
->p
->input
.title
[p_demux
->info
.i_title
]->seekpoint
[i_seekpoint
]->i_time_offset
;
1875 if( i_seekpoint_time
>= 0 &&
1876 !demux2_Control( p_demux
,
1877 DEMUX_GET_TIME
, &i_input_time
) )
1879 if ( i_input_time
< i_seekpoint_time
+ 3000000 )
1885 else if( i_type
== INPUT_CONTROL_SET_SEEKPOINT_NEXT
)
1886 i_seekpoint
= p_demux
->info
.i_seekpoint
+ 1;
1888 i_seekpoint
= val
.i_int
;
1890 if( i_seekpoint
>= 0 && i_seekpoint
<
1891 p_input
->p
->input
.title
[p_demux
->info
.i_title
]->i_seekpoint
)
1894 input_EsOutChangePosition( p_input
->p
->p_es_out
);
1896 demux2_Control( p_demux
, DEMUX_SET_SEEKPOINT
, i_seekpoint
);
1899 else if( p_input
->p
->input
.i_title
> 0 )
1901 demux_t
*p_demux
= p_input
->p
->input
.p_demux
;
1902 access_t
*p_access
= p_input
->p
->input
.p_access
;
1904 int64_t i_input_time
;
1905 int64_t i_seekpoint_time
;
1907 if( i_type
== INPUT_CONTROL_SET_SEEKPOINT_PREV
)
1909 i_seekpoint
= p_access
->info
.i_seekpoint
;
1910 i_seekpoint_time
= p_input
->p
->input
.title
[p_access
->info
.i_title
]->seekpoint
[i_seekpoint
]->i_time_offset
;
1911 if( i_seekpoint_time
>= 0 &&
1912 demux2_Control( p_demux
,
1913 DEMUX_GET_TIME
, &i_input_time
) )
1915 if ( i_input_time
< i_seekpoint_time
+ 3000000 )
1921 else if( i_type
== INPUT_CONTROL_SET_SEEKPOINT_NEXT
)
1922 i_seekpoint
= p_access
->info
.i_seekpoint
+ 1;
1924 i_seekpoint
= val
.i_int
;
1926 if( i_seekpoint
>= 0 && i_seekpoint
<
1927 p_input
->p
->input
.title
[p_access
->info
.i_title
]->i_seekpoint
)
1929 input_EsOutChangePosition( p_input
->p
->p_es_out
);
1931 access2_Control( p_access
, ACCESS_SET_SEEKPOINT
,
1933 stream_AccessReset( p_input
->p
->input
.p_stream
);
1938 case INPUT_CONTROL_ADD_SLAVE
:
1939 if( val
.psz_string
)
1941 input_source_t
*slave
= InputSourceNew( p_input
);
1943 if( !InputSourceInit( p_input
, slave
, val
.psz_string
, NULL
) )
1949 msg_Dbg( p_input
, "adding %s as slave on the fly",
1953 if( demux2_Control( p_input
->p
->input
.p_demux
,
1954 DEMUX_GET_TIME
, &i_time
) )
1956 msg_Err( p_input
, "demux doesn't like DEMUX_GET_TIME" );
1957 InputSourceClean( slave
);
1961 if( demux2_Control( slave
->p_demux
,
1962 DEMUX_SET_TIME
, i_time
) )
1964 msg_Err( p_input
, "seek failed for new slave" );
1965 InputSourceClean( slave
);
1970 /* Get meta (access and demux) */
1971 p_meta
= vlc_meta_New();
1972 access2_Control( slave
->p_access
, ACCESS_GET_META
,
1974 demux2_Control( slave
->p_demux
, DEMUX_GET_META
, p_meta
);
1975 InputUpdateMeta( p_input
, p_meta
);
1977 TAB_APPEND( p_input
->p
->i_slave
, p_input
->p
->slave
, slave
);
1982 msg_Warn( p_input
, "failed to add %s as slave",
1986 free( val
.psz_string
);
1990 case INPUT_CONTROL_SET_BOOKMARK
:
1992 msg_Err( p_input
, "not yet implemented" );
1996 return b_force_update
;
1999 /*****************************************************************************
2001 *****************************************************************************/
2002 static int UpdateFromDemux( input_thread_t
*p_input
)
2004 demux_t
*p_demux
= p_input
->p
->input
.p_demux
;
2007 if( p_demux
->info
.i_update
& INPUT_UPDATE_TITLE
)
2009 v
.i_int
= p_demux
->info
.i_title
;
2010 var_Change( p_input
, "title", VLC_VAR_SETVALUE
, &v
, NULL
);
2012 input_ControlVarTitle( p_input
, p_demux
->info
.i_title
);
2014 p_demux
->info
.i_update
&= ~INPUT_UPDATE_TITLE
;
2016 if( p_demux
->info
.i_update
& INPUT_UPDATE_SEEKPOINT
)
2018 v
.i_int
= p_demux
->info
.i_seekpoint
;
2019 var_Change( p_input
, "chapter", VLC_VAR_SETVALUE
, &v
, NULL
);
2021 p_demux
->info
.i_update
&= ~INPUT_UPDATE_SEEKPOINT
;
2023 p_demux
->info
.i_update
&= ~INPUT_UPDATE_SIZE
;
2025 /* Hmmm only works with master input */
2026 if( p_input
->p
->input
.p_demux
== p_demux
)
2028 int i_title_end
= p_input
->p
->input
.i_title_end
-
2029 p_input
->p
->input
.i_title_offset
;
2030 int i_seekpoint_end
= p_input
->p
->input
.i_seekpoint_end
-
2031 p_input
->p
->input
.i_seekpoint_offset
;
2033 if( i_title_end
>= 0 && i_seekpoint_end
>= 0 )
2035 if( p_demux
->info
.i_title
> i_title_end
||
2036 ( p_demux
->info
.i_title
== i_title_end
&&
2037 p_demux
->info
.i_seekpoint
> i_seekpoint_end
) ) return 0;
2039 else if( i_seekpoint_end
>=0 )
2041 if( p_demux
->info
.i_seekpoint
> i_seekpoint_end
) return 0;
2043 else if( i_title_end
>= 0 )
2045 if( p_demux
->info
.i_title
> i_title_end
) return 0;
2052 /*****************************************************************************
2054 *****************************************************************************/
2055 static int UpdateFromAccess( input_thread_t
*p_input
)
2057 access_t
*p_access
= p_input
->p
->input
.p_access
;
2060 if( p_access
->info
.i_update
& INPUT_UPDATE_TITLE
)
2062 v
.i_int
= p_access
->info
.i_title
;
2063 var_Change( p_input
, "title", VLC_VAR_SETVALUE
, &v
, NULL
);
2065 input_ControlVarTitle( p_input
, p_access
->info
.i_title
);
2067 stream_AccessUpdate( p_input
->p
->input
.p_stream
);
2069 p_access
->info
.i_update
&= ~INPUT_UPDATE_TITLE
;
2071 if( p_access
->info
.i_update
& INPUT_UPDATE_SEEKPOINT
)
2073 v
.i_int
= p_access
->info
.i_seekpoint
;
2074 var_Change( p_input
, "chapter", VLC_VAR_SETVALUE
, &v
, NULL
);
2075 p_access
->info
.i_update
&= ~INPUT_UPDATE_SEEKPOINT
;
2077 if( p_access
->info
.i_update
& INPUT_UPDATE_META
)
2079 /* TODO maybe multi - access ? */
2080 vlc_meta_t
*p_meta
= vlc_meta_New();
2081 access2_Control( p_input
->p
->input
.p_access
,ACCESS_GET_META
, p_meta
);
2082 InputUpdateMeta( p_input
, p_meta
);
2083 var_SetInteger( pl_Get( p_input
), "item-change", p_input
->p
->input
.p_item
->i_id
);
2084 p_access
->info
.i_update
&= ~INPUT_UPDATE_META
;
2087 p_access
->info
.i_update
&= ~INPUT_UPDATE_SIZE
;
2089 /* Hmmm only works with master input */
2090 if( p_input
->p
->input
.p_access
== p_access
)
2092 int i_title_end
= p_input
->p
->input
.i_title_end
-
2093 p_input
->p
->input
.i_title_offset
;
2094 int i_seekpoint_end
= p_input
->p
->input
.i_seekpoint_end
-
2095 p_input
->p
->input
.i_seekpoint_offset
;
2097 if( i_title_end
>= 0 && i_seekpoint_end
>=0 )
2099 if( p_access
->info
.i_title
> i_title_end
||
2100 ( p_access
->info
.i_title
== i_title_end
&&
2101 p_access
->info
.i_seekpoint
> i_seekpoint_end
) ) return 0;
2103 else if( i_seekpoint_end
>=0 )
2105 if( p_access
->info
.i_seekpoint
> i_seekpoint_end
) return 0;
2107 else if( i_title_end
>= 0 )
2109 if( p_access
->info
.i_title
> i_title_end
) return 0;
2116 /*****************************************************************************
2118 *****************************************************************************/
2119 static void UpdateItemLength( input_thread_t
*p_input
, int64_t i_length
)
2121 input_item_SetDuration( p_input
->p
->input
.p_item
, (mtime_t
) i_length
);
2123 if( !p_input
->b_preparsing
)
2125 pl_Yield( p_input
);
2126 var_SetInteger( pl_Get( p_input
), "item-change",
2127 p_input
->p
->input
.p_item
->i_id
);
2128 pl_Release( p_input
);
2132 /*****************************************************************************
2134 *****************************************************************************/
2135 static input_source_t
*InputSourceNew( input_thread_t
*p_input
)
2137 input_source_t
*in
= (input_source_t
*) malloc( sizeof( input_source_t
) );
2141 msg_Err( p_input
, "out of memory for new input source" );
2146 in
->p_access
= NULL
;
2147 in
->p_stream
= NULL
;
2149 in
->b_title_demux
= VLC_FALSE
;
2150 TAB_INIT( in
->i_title
, in
->title
);
2151 in
->b_can_pause
= VLC_TRUE
;
2152 in
->b_can_pace_control
= VLC_TRUE
;
2153 in
->b_can_rate_control
= VLC_TRUE
;
2154 in
->b_rescale_ts
= VLC_TRUE
;
2155 in
->b_eof
= VLC_FALSE
;
2157 in
->i_cr_average
= 0;
2162 /*****************************************************************************
2164 *****************************************************************************/
2165 static int InputSourceInit( input_thread_t
*p_input
,
2166 input_source_t
*in
, const char *psz_mrl
,
2167 const char *psz_forced_demux
)
2169 char psz_dup
[strlen (psz_mrl
) + 1];
2170 const char *psz_access
;
2171 const char *psz_demux
;
2178 strcpy( psz_dup
, psz_mrl
);
2180 if( !in
) return VLC_EGENERIC
;
2181 if( !p_input
) return VLC_EGENERIC
;
2184 MRLSplit( psz_dup
, &psz_access
, &psz_demux
, &psz_path
);
2186 msg_Dbg( p_input
, "`%s' gives access `%s' demux `%s' path `%s'",
2187 psz_mrl
, psz_access
, psz_demux
, psz_path
);
2188 if( !p_input
->b_preparsing
)
2190 /* Hack to allow udp://@:port syntax */
2192 (strncmp( psz_access
, "udp", 3 ) &&
2193 strncmp( psz_access
, "rtp", 3 )) )
2195 /* Find optional titles and seekpoints */
2196 MRLSections( p_input
, psz_path
, &in
->i_title_start
, &in
->i_title_end
,
2197 &in
->i_seekpoint_start
, &in
->i_seekpoint_end
);
2200 if( psz_forced_demux
&& *psz_forced_demux
)
2202 psz_demux
= psz_forced_demux
;
2204 else if( *psz_demux
== '\0' )
2206 /* special hack for forcing a demuxer with --demux=module
2207 * (and do nothing with a list) */
2208 char *psz_var_demux
= var_GetNonEmptyString( p_input
, "demux" );
2210 if( psz_var_demux
!= NULL
&&
2211 !strchr(psz_var_demux
, ',' ) &&
2212 !strchr(psz_var_demux
, ':' ) )
2214 psz_demux
= psz_var_demux
;
2216 msg_Dbg( p_input
, "enforced demux ` %s'", psz_demux
);
2220 /* Try access_demux if no demux given */
2221 if( *psz_demux
== '\0' )
2223 in
->p_demux
= demux2_New( p_input
, psz_access
, psz_demux
, psz_path
,
2224 NULL
, p_input
->p
->p_es_out
, VLC_FALSE
);
2229 /* Preparsing is only for file:// */
2232 if( !*psz_access
) /* path without scheme:// */
2233 psz_access
= "file";
2234 if( strcmp( psz_access
, "file" ) )
2236 msg_Dbg( p_input
, "trying to pre-parse %s", psz_path
);
2241 int64_t i_pts_delay
;
2243 /* Get infos from access_demux */
2244 demux2_Control( in
->p_demux
,
2245 DEMUX_GET_PTS_DELAY
, &i_pts_delay
);
2246 p_input
->i_pts_delay
= __MAX( p_input
->i_pts_delay
, i_pts_delay
);
2248 in
->b_title_demux
= VLC_TRUE
;
2249 if( demux2_Control( in
->p_demux
, DEMUX_GET_TITLE_INFO
,
2250 &in
->title
, &in
->i_title
,
2251 &in
->i_title_offset
, &in
->i_seekpoint_offset
) )
2256 if( demux2_Control( in
->p_demux
, DEMUX_CAN_CONTROL_PACE
,
2257 &in
->b_can_pace_control
) )
2258 in
->b_can_pace_control
= VLC_FALSE
;
2260 if( !in
->b_can_pace_control
)
2262 if( demux2_Control( in
->p_demux
, DEMUX_CAN_CONTROL_RATE
,
2263 &in
->b_can_rate_control
, &in
->b_rescale_ts
) )
2265 in
->b_can_rate_control
= VLC_FALSE
;
2266 in
->b_rescale_ts
= VLC_TRUE
; /* not used */
2271 in
->b_can_rate_control
= VLC_TRUE
;
2272 in
->b_rescale_ts
= VLC_TRUE
;
2274 if( demux2_Control( in
->p_demux
, DEMUX_CAN_PAUSE
,
2275 &in
->b_can_pause
) )
2276 in
->b_can_pause
= VLC_FALSE
;
2277 var_SetBool( p_input
, "can-pause", in
->b_can_pause
);
2279 int ret
= demux2_Control( in
->p_demux
, DEMUX_CAN_SEEK
,
2281 if( ret
!= VLC_SUCCESS
)
2282 val
.b_bool
= VLC_FALSE
;
2283 var_Set( p_input
, "seekable", val
);
2287 int64_t i_pts_delay
;
2289 input_ChangeState( p_input
, OPENING_S
);
2291 /* Now try a real access */
2292 in
->p_access
= access2_New( p_input
, psz_access
, psz_demux
, psz_path
);
2294 /* Access failed, URL encoded ? */
2295 if( in
->p_access
== NULL
&& strchr( psz_path
, '%' ) )
2297 decode_URI( psz_path
);
2299 msg_Dbg( p_input
, "retrying with access `%s' demux `%s' path `%s'",
2300 psz_access
, psz_demux
, psz_path
);
2302 in
->p_access
= access2_New( p_input
,
2303 psz_access
, psz_demux
, psz_path
);
2305 if( in
->p_access
== NULL
)
2307 msg_Err( p_input
, "open of `%s' failed: %s", psz_mrl
,
2309 intf_UserFatal( VLC_OBJECT( p_input
), VLC_FALSE
,
2310 _("Your input can't be opened"),
2311 _("VLC is unable to open the MRL '%s'."
2312 " Check the log for details."), psz_mrl
);
2317 psz_tmp
= psz
= var_GetNonEmptyString( p_input
, "access-filter" );
2318 while( psz
&& *psz
)
2320 access_t
*p_access
= in
->p_access
;
2321 char *end
= strchr( psz
, ':' );
2326 in
->p_access
= access2_FilterNew( in
->p_access
, psz
);
2327 if( in
->p_access
== NULL
)
2329 in
->p_access
= p_access
;
2330 msg_Warn( p_input
, "failed to insert access filter %s",
2338 /* Get infos from access */
2339 if( !p_input
->b_preparsing
)
2341 access2_Control( in
->p_access
,
2342 ACCESS_GET_PTS_DELAY
, &i_pts_delay
);
2343 p_input
->i_pts_delay
= __MAX( p_input
->i_pts_delay
, i_pts_delay
);
2345 in
->b_title_demux
= VLC_FALSE
;
2346 if( access2_Control( in
->p_access
, ACCESS_GET_TITLE_INFO
,
2347 &in
->title
, &in
->i_title
,
2348 &in
->i_title_offset
, &in
->i_seekpoint_offset
) )
2354 access2_Control( in
->p_access
, ACCESS_CAN_CONTROL_PACE
,
2355 &in
->b_can_pace_control
);
2356 in
->b_can_rate_control
= in
->b_can_pace_control
;
2357 in
->b_rescale_ts
= VLC_TRUE
;
2359 access2_Control( in
->p_access
, ACCESS_CAN_PAUSE
,
2361 var_SetBool( p_input
, "can-pause", in
->b_can_pause
);
2362 access2_Control( in
->p_access
, ACCESS_CAN_SEEK
,
2364 var_Set( p_input
, "seekable", val
);
2367 input_ChangeState( p_input
, BUFFERING_S
);
2369 /* Create the stream_t */
2370 in
->p_stream
= stream_AccessNew( in
->p_access
, p_input
->b_preparsing
);
2371 if( in
->p_stream
== NULL
)
2373 msg_Warn( p_input
, "cannot create a stream_t from access" );
2377 /* Open a demuxer */
2378 if( *psz_demux
== '\0' && *in
->p_access
->psz_demux
)
2380 psz_demux
= in
->p_access
->psz_demux
;
2384 /* Take access redirections into account */
2385 char *psz_real_path
;
2386 char *psz_buf
= NULL
;
2387 if( in
->p_access
->psz_path
)
2389 const char *psz_a
, *psz_d
;
2390 psz_buf
= strdup( in
->p_access
->psz_path
);
2391 MRLSplit( psz_buf
, &psz_a
, &psz_d
, &psz_real_path
);
2395 psz_real_path
= psz_path
;
2397 in
->p_demux
= demux2_New( p_input
, psz_access
, psz_demux
,
2399 in
->p_stream
, p_input
->p
->p_es_out
,
2400 p_input
->b_preparsing
);
2404 if( in
->p_demux
== NULL
)
2406 msg_Err( p_input
, "no suitable demux module for `%s/%s://%s'",
2407 psz_access
, psz_demux
, psz_path
);
2408 intf_UserFatal( VLC_OBJECT( p_input
), VLC_FALSE
,
2409 _("VLC can't recognize the input's format"),
2410 _("The format of '%s' cannot be detected. "
2411 "Have a look the log for details."), psz_mrl
);
2415 /* Get title from demux */
2416 if( !p_input
->b_preparsing
&& in
->i_title
<= 0 )
2418 if( demux2_Control( in
->p_demux
, DEMUX_GET_TITLE_INFO
,
2419 &in
->title
, &in
->i_title
,
2420 &in
->i_title_offset
, &in
->i_seekpoint_offset
))
2422 TAB_INIT( in
->i_title
, in
->title
);
2426 in
->b_title_demux
= VLC_TRUE
;
2432 * FIXME improve for b_preparsing: move it after GET_META and check psz_arturl */
2433 if( 1 || !p_input
->b_preparsing
)
2436 input_attachment_t
**attachment
;
2437 if( !demux2_Control( in
->p_demux
, DEMUX_GET_ATTACHMENTS
,
2438 &attachment
, &i_attachment
) )
2440 vlc_mutex_lock( &p_input
->p
->input
.p_item
->lock
);
2441 AppendAttachment( &p_input
->p
->i_attachment
, &p_input
->p
->attachment
,
2442 i_attachment
, attachment
);
2443 vlc_mutex_unlock( &p_input
->p
->input
.p_item
->lock
);
2446 if( !demux2_Control( in
->p_demux
, DEMUX_GET_FPS
, &f_fps
) )
2448 vlc_mutex_lock( &p_input
->p
->input
.p_item
->lock
);
2450 vlc_mutex_unlock( &p_input
->p
->input
.p_item
->lock
);
2453 if( var_GetInteger( p_input
, "clock-synchro" ) != -1 )
2454 in
->b_can_pace_control
= !var_GetInteger( p_input
, "clock-synchro" );
2459 input_ChangeState( p_input
, ERROR_S
);
2462 demux2_Delete( in
->p_demux
);
2465 stream_Delete( in
->p_stream
);
2468 access2_Delete( in
->p_access
);
2470 return VLC_EGENERIC
;
2473 /*****************************************************************************
2475 *****************************************************************************/
2476 static void InputSourceClean( input_source_t
*in
)
2481 demux2_Delete( in
->p_demux
);
2484 stream_Delete( in
->p_stream
);
2487 access2_Delete( in
->p_access
);
2489 if( in
->i_title
> 0 )
2491 for( i
= 0; i
< in
->i_title
; i
++ )
2492 vlc_input_title_Delete( in
->title
[i
] );
2493 TAB_CLEAN( in
->i_title
, in
->title
);
2497 static void SlaveDemux( input_thread_t
*p_input
)
2502 if( demux2_Control( p_input
->p
->input
.p_demux
, DEMUX_GET_TIME
, &i_time
) )
2504 msg_Err( p_input
, "demux doesn't like DEMUX_GET_TIME" );
2508 for( i
= 0; i
< p_input
->p
->i_slave
; i
++ )
2510 input_source_t
*in
= p_input
->p
->slave
[i
];
2516 if( demux2_Control( in
->p_demux
, DEMUX_SET_NEXT_DEMUX_TIME
, i_time
) )
2521 if( demux2_Control( in
->p_demux
, DEMUX_GET_TIME
, &i_stime
) )
2523 msg_Err( p_input
, "slave[%d] doesn't like "
2524 "DEMUX_GET_TIME -> EOF", i
);
2529 if( i_stime
>= i_time
)
2532 if( ( i_ret
= in
->p_demux
->pf_demux( in
->p_demux
) ) <= 0 )
2538 i_ret
= in
->p_demux
->pf_demux( in
->p_demux
);
2543 msg_Dbg( p_input
, "slave %d EOF", i
);
2544 in
->b_eof
= VLC_TRUE
;
2549 static void SlaveSeek( input_thread_t
*p_input
)
2554 if( !p_input
) return;
2556 if( demux2_Control( p_input
->p
->input
.p_demux
, DEMUX_GET_TIME
, &i_time
) )
2558 msg_Err( p_input
, "demux doesn't like DEMUX_GET_TIME" );
2562 for( i
= 0; i
< p_input
->p
->i_slave
; i
++ )
2564 input_source_t
*in
= p_input
->p
->slave
[i
];
2566 if( demux2_Control( in
->p_demux
, DEMUX_SET_TIME
, i_time
) )
2568 msg_Err( p_input
, "seek failed for slave %d -> EOF", i
);
2569 in
->b_eof
= VLC_TRUE
;
2574 /*****************************************************************************
2576 *****************************************************************************/
2577 static void InputMetaUser( input_thread_t
*p_input
, vlc_meta_t
*p_meta
)
2581 if( !p_meta
) return;
2583 /* Get meta information from user */
2584 #define GET_META( field, s ) \
2585 var_Get( p_input, (s), &val ); \
2586 if( *val.psz_string ) \
2587 vlc_meta_Set( p_meta, vlc_meta_ ## field, val.psz_string ); \
2588 free( val.psz_string )
2590 GET_META( Title
, "meta-title" );
2591 GET_META( Artist
, "meta-artist" );
2592 GET_META( Genre
, "meta-genre" );
2593 GET_META( Copyright
, "meta-copyright" );
2594 GET_META( Description
, "meta-description" );
2595 GET_META( Date
, "meta-date" );
2596 GET_META( URL
, "meta-url" );
2600 /*****************************************************************************
2601 * InputUpdateMeta: merge p_item meta data with p_meta taking care of
2602 * arturl and locking issue.
2603 *****************************************************************************/
2604 static void InputUpdateMeta( input_thread_t
*p_input
, vlc_meta_t
*p_meta
)
2606 input_item_t
*p_item
= p_input
->p
->input
.p_item
;
2607 char * psz_arturl
= NULL
;
2608 char *psz_title
= NULL
;
2610 int i_arturl_event
= VLC_FALSE
;
2615 psz_arturl
= input_item_GetArtURL( p_item
);
2617 vlc_mutex_lock( &p_item
->lock
);
2618 if( vlc_meta_Get( p_meta
, vlc_meta_Title
) && !p_item
->b_fixed_name
)
2619 psz_title
= strdup( vlc_meta_Get( p_meta
, vlc_meta_Title
) );
2621 vlc_meta_Merge( p_item
->p_meta
, p_meta
);
2623 if( psz_arturl
&& *psz_arturl
)
2625 vlc_meta_Set( p_item
->p_meta
, vlc_meta_ArtworkURL
, psz_arturl
);
2626 i_arturl_event
= VLC_TRUE
;
2629 vlc_meta_Delete( p_meta
);
2631 if( psz_arturl
&& !strncmp( psz_arturl
, "attachment://", strlen("attachment") ) )
2633 /* Don't look for art cover if sout
2634 * XXX It can change when sout has meta data support */
2635 if( p_input
->p
->p_sout
&& !p_input
->b_preparsing
)
2637 vlc_meta_Set( p_item
->p_meta
, vlc_meta_ArtworkURL
, "" );
2638 i_arturl_event
= VLC_TRUE
;
2642 input_ExtractAttachmentAndCacheArt( p_input
);
2648 if( vlc_dictionary_keys_count( &p_item
->p_meta
->extra_tags
) > 0 )
2650 p_meta
= vlc_meta_New();
2651 vlc_meta_Merge( p_meta
, input_item_GetMetaObject( p_item
) );
2653 vlc_mutex_unlock( &p_item
->lock
);
2655 input_item_SetPreparsed( p_item
, VLC_TRUE
);
2657 if( i_arturl_event
== VLC_TRUE
)
2661 /* Notify interested third parties */
2662 event
.type
= vlc_InputItemMetaChanged
;
2663 event
.u
.input_item_meta_changed
.meta_type
= vlc_meta_ArtworkURL
;
2664 vlc_event_send( &p_item
->event_manager
, &event
);
2669 input_Control( p_input
, INPUT_SET_NAME
, psz_title
);
2675 char ** ppsz_all_keys
= vlc_dictionary_all_keys( &p_meta
->extra_tags
);
2676 for( i
= 0; ppsz_all_keys
[i
]; i
++ )
2678 input_Control( p_input
, INPUT_ADD_INFO
, _(VLC_META_INFO_CAT
), _(ppsz_all_keys
[i
]),
2679 vlc_dictionary_value_for_key( &p_meta
->extra_tags
, ppsz_all_keys
[i
] ) );
2680 free( ppsz_all_keys
[i
] );
2682 free( ppsz_all_keys
);
2683 vlc_meta_Delete( p_meta
);
2686 /** \todo handle sout meta */
2690 static void AppendAttachment( int *pi_attachment
, input_attachment_t
***ppp_attachment
,
2691 int i_new
, input_attachment_t
**pp_new
)
2693 int i_attachment
= *pi_attachment
;
2694 input_attachment_t
**attachment
= *ppp_attachment
;
2697 attachment
= realloc( attachment
,
2698 sizeof(input_attachment_t
**) * ( i_attachment
+ i_new
) );
2699 for( i
= 0; i
< i_new
; i
++ )
2700 attachment
[i_attachment
++] = pp_new
[i
];
2704 *pi_attachment
= i_attachment
;
2705 *ppp_attachment
= attachment
;
2708 static void DemuxMeta( input_thread_t
*p_input
, vlc_meta_t
*p_meta
, demux_t
*p_demux
)
2715 /* XXX I am not sure it is a great idea, besides, there is more than that
2716 * if we want to do it right */
2717 vlc_mutex_lock( &p_item
->lock
);
2718 if( p_item
->p_meta
&& (p_item
->p_meta
->i_status
& ITEM_PREPARSED
) )
2720 vlc_mutex_unlock( &p_item
->lock
);
2723 vlc_mutex_unlock( &p_item
->lock
);
2726 demux2_Control( p_demux
, DEMUX_GET_META
, p_meta
);
2727 if( demux2_Control( p_demux
, DEMUX_HAS_UNSUPPORTED_META
, &b_bool
) )
2732 p_demux
->p_private
= malloc( sizeof( demux_meta_t
) );
2733 if(! p_demux
->p_private
)
2736 p_id3
= module_Need( p_demux
, "meta reader", NULL
, 0 );
2739 demux_meta_t
*p_demux_meta
= (demux_meta_t
*)p_demux
->p_private
;
2741 if( p_demux_meta
->p_meta
)
2743 vlc_meta_Merge( p_meta
, p_demux_meta
->p_meta
);
2744 vlc_meta_Delete( p_demux_meta
->p_meta
);
2747 if( p_demux_meta
->i_attachments
> 0 )
2749 vlc_mutex_lock( &p_input
->p
->input
.p_item
->lock
);
2750 AppendAttachment( &p_input
->p
->i_attachment
, &p_input
->p
->attachment
,
2751 p_demux_meta
->i_attachments
, p_demux_meta
->attachments
);
2752 vlc_mutex_unlock( &p_input
->p
->input
.p_item
->lock
);
2754 module_Unneed( p_demux
, p_id3
);
2756 free( p_demux
->p_private
);
2760 /*****************************************************************************
2761 * MRLSplit: parse the access, demux and url part of the
2762 * Media Resource Locator.
2763 *****************************************************************************/
2764 void MRLSplit( char *psz_dup
, const char **ppsz_access
, const char **ppsz_demux
,
2767 char *psz_access
= NULL
;
2768 char *psz_demux
= NULL
;
2771 /* Either there is an access/demux specification before ://
2772 * or we have a plain local file path. */
2773 psz_path
= strstr( psz_dup
, "://" );
2774 if( psz_path
!= NULL
)
2777 psz_path
+= 3; /* skips "://" */
2779 /* Separate access from demux (<access>/<demux>://<path>) */
2780 psz_access
= psz_dup
;
2781 psz_demux
= strchr( psz_access
, '/' );
2783 *psz_demux
++ = '\0';
2790 *ppsz_access
= psz_access
? psz_access
: "";
2791 *ppsz_demux
= psz_demux
? psz_demux
: "";
2792 *ppsz_path
= psz_path
? psz_path
: "";
2795 /*****************************************************************************
2796 * MRLSections: parse title and seekpoint info from the Media Resource Locator.
2799 * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
2800 *****************************************************************************/
2801 static void MRLSections( input_thread_t
*p_input
, char *psz_source
,
2802 int *pi_title_start
, int *pi_title_end
,
2803 int *pi_chapter_start
, int *pi_chapter_end
)
2805 char *psz
, *psz_end
, *psz_next
, *psz_check
;
2807 *pi_title_start
= *pi_title_end
= -1;
2808 *pi_chapter_start
= *pi_chapter_end
= -1;
2810 /* Start by parsing titles and chapters */
2811 if( !psz_source
|| !( psz
= strrchr( psz_source
, '@' ) ) ) return;
2813 /* Check we are really dealing with a title/chapter section */
2814 psz_check
= psz
+ 1;
2815 if( !*psz_check
) return;
2816 if( isdigit(*psz_check
) ) strtol( psz_check
, &psz_check
, 0 );
2817 if( *psz_check
!= ':' && *psz_check
!= '-' && *psz_check
) return;
2818 if( *psz_check
== ':' && ++psz_check
)
2819 if( isdigit(*psz_check
) ) strtol( psz_check
, &psz_check
, 0 );
2820 if( *psz_check
!= '-' && *psz_check
) return;
2821 if( *psz_check
== '-' && ++psz_check
)
2822 if( isdigit(*psz_check
) ) strtol( psz_check
, &psz_check
, 0 );
2823 if( *psz_check
!= ':' && *psz_check
) return;
2824 if( *psz_check
== ':' && ++psz_check
)
2825 if( isdigit(*psz_check
) ) strtol( psz_check
, &psz_check
, 0 );
2826 if( *psz_check
) return;
2828 /* Separate start and end */
2830 if( ( psz_end
= strchr( psz
, '-' ) ) ) *psz_end
++ = 0;
2832 /* Look for the start title */
2833 *pi_title_start
= strtol( psz
, &psz_next
, 0 );
2834 if( !*pi_title_start
&& psz
== psz_next
) *pi_title_start
= -1;
2835 *pi_title_end
= *pi_title_start
;
2838 /* Look for the start chapter */
2840 *pi_chapter_start
= strtol( psz
, &psz_next
, 0 );
2841 if( !*pi_chapter_start
&& psz
== psz_next
) *pi_chapter_start
= -1;
2842 *pi_chapter_end
= *pi_chapter_start
;
2846 /* Look for the end title */
2847 *pi_title_end
= strtol( psz_end
, &psz_next
, 0 );
2848 if( !*pi_title_end
&& psz_end
== psz_next
) *pi_title_end
= -1;
2851 /* Look for the end chapter */
2852 if( *psz_end
) psz_end
++;
2853 *pi_chapter_end
= strtol( psz_end
, &psz_next
, 0 );
2854 if( !*pi_chapter_end
&& psz_end
== psz_next
) *pi_chapter_end
= -1;
2857 msg_Dbg( p_input
, "source=`%s' title=%d/%d seekpoint=%d/%d",
2858 psz_source
, *pi_title_start
, *pi_chapter_start
,
2859 *pi_title_end
, *pi_chapter_end
);
2862 /*****************************************************************************
2863 * input_AddSubtitles: add a subtitles file and enable it
2864 *****************************************************************************/
2865 vlc_bool_t
input_AddSubtitles( input_thread_t
*p_input
, char *psz_subtitle
,
2866 vlc_bool_t b_check_extension
)
2868 input_source_t
*sub
;
2871 char *psz_path
, *psz_extension
;
2873 if( b_check_extension
&& !subtitles_Filter( psz_subtitle
) )
2878 /* if we are provided a subtitle.sub file,
2879 * see if we don't have a subtitle.idx and use it instead */
2880 psz_path
= strdup( psz_subtitle
);
2883 psz_extension
= strrchr( psz_path
, '.');
2884 if( psz_extension
&& strcmp( psz_extension
, ".sub" ) == 0 )
2888 strcpy( psz_extension
, ".idx" );
2889 /* FIXME: a portable wrapper for stat() or access() would be more suited */
2890 if( ( f
= utf8_fopen( psz_path
, "rt" ) ) )
2893 msg_Dbg( p_input
, "using %s subtitles file instead of %s",
2894 psz_path
, psz_subtitle
);
2895 strcpy( psz_subtitle
, psz_path
);
2901 var_Change( p_input
, "spu-es", VLC_VAR_CHOICESCOUNT
, &count
, NULL
);
2903 sub
= InputSourceNew( p_input
);
2904 if( !InputSourceInit( p_input
, sub
, psz_subtitle
, "subtitle" ) )
2906 TAB_APPEND( p_input
->p
->i_slave
, p_input
->p
->slave
, sub
);
2909 if( !var_Change( p_input
, "spu-es", VLC_VAR_GETLIST
, &list
, NULL
) )
2911 if( count
.i_int
== 0 )
2913 /* if it was first one, there is disable too */
2915 if( count
.i_int
< list
.p_list
->i_count
)
2917 input_ControlPush( p_input
, INPUT_CONTROL_SET_ES
,
2918 &list
.p_list
->p_values
[count
.i_int
] );
2920 var_Change( p_input
, "spu-es", VLC_VAR_FREELIST
, &list
, NULL
);