1 /*****************************************************************************
2 * input.c: input thread
3 * Read a stream, demultiplex and parse it before sending it to
5 *****************************************************************************
6 * Copyright (C) 1998-2004 VideoLAN
9 * Authors: Christophe Massiot <massiot@via.ecp.fr>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
32 #include <vlc/input.h>
33 #include <vlc/decoder.h>
36 #ifdef HAVE_SYS_TIMES_H
37 # include <sys/times.h>
40 #include "stream_output.h"
42 #include "vlc_interface.h"
45 #include "../../modules/demux/util/sub.h"
47 /*****************************************************************************
49 *****************************************************************************/
50 struct input_thread_sys_t
54 subtitle_demux_t **sub;
59 static int RunThread ( input_thread_t *p_input );
60 static int InitThread ( input_thread_t *p_input );
61 static void ErrorThread( input_thread_t *p_input );
62 static void EndThread ( input_thread_t *p_input );
64 static void ParseOption( input_thread_t *p_input, const char *psz_option );
66 static void DecodeUrl ( char * );
68 /*****************************************************************************
70 *****************************************************************************/
71 static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
72 vlc_value_t oldval, vlc_value_t newval, void *p_data );
73 static int TimeCallback ( vlc_object_t *p_this, char const *psz_cmd,
74 vlc_value_t oldval, vlc_value_t newval, void *p_data );
75 static int StateCallback ( vlc_object_t *p_this, char const *psz_cmd,
76 vlc_value_t oldval, vlc_value_t newval, void *p_data );
77 static int RateCallback ( vlc_object_t *p_this, char const *psz_cmd,
78 vlc_value_t oldval, vlc_value_t newval, void *p_data );
79 static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
80 vlc_value_t oldval, vlc_value_t newval, void *p_data );
82 /*****************************************************************************
83 * input_CreateThread: creates a new input thread
84 *****************************************************************************
85 * This function creates a new input, and returns a pointer
86 * to its description. On error, it returns NULL.
87 *****************************************************************************/
88 input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
89 input_item_t *p_item )
92 input_thread_t *p_input; /* thread descriptor */
96 /* Allocate descriptor */
97 p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
100 msg_Err( p_parent, "out of memory" );
104 /* Store pointer to input item descriptor */
105 p_input->p_item = p_item;
107 /* Parse input options */
108 vlc_mutex_lock( &p_item->lock );
109 for( i = 0; i < p_item->i_options; i++ )
111 msg_Dbg( p_input, "option: %s", p_item->ppsz_options[i] );
112 ParseOption( p_input, p_item->ppsz_options[i] );
114 vlc_mutex_unlock( &p_item->lock );
116 /* Create a few object variables we'll need later on */
117 var_Create( p_input, "video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
118 var_Create( p_input, "audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
119 var_Create( p_input, "audio-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
120 var_Create( p_input, "spu-channel", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
121 var_Create( p_input, "sub-file", VLC_VAR_FILE | VLC_VAR_DOINHERIT );
122 var_Create( p_input, "sub-autodetect-file", VLC_VAR_BOOL |
124 var_Create( p_input, "sub-autodetect-path", VLC_VAR_STRING |
126 var_Create( p_input, "sub-autodetect-fuzzy", VLC_VAR_INTEGER |
129 var_Create( p_input, "sout", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
130 var_Create( p_input, "sout-all", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
131 var_Create( p_input, "sout-audio", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
132 var_Create( p_input, "sout-video", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
133 var_Create( p_input, "sout-keep", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
135 /* repeat variable */
136 var_Create( p_input, "input-repeat", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
138 /* start/stop time */
139 var_Create( p_input, "start-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
140 var_Create( p_input, "stop-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
143 var_Create( p_input, "minimize-threads", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
147 /* position variable */
148 var_Create( p_input, "position", VLC_VAR_FLOAT ); /* position 0.0->1.0 */
149 var_Create( p_input, "position-offset", VLC_VAR_FLOAT ); /* relative */
151 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
152 var_AddCallback( p_input, "position", PositionCallback, NULL );
153 var_AddCallback( p_input, "position-offset", PositionCallback, NULL );
156 var_Create( p_input, "time", VLC_VAR_TIME );
157 var_Create( p_input, "time-offset", VLC_VAR_TIME ); /* relative */
159 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
160 var_AddCallback( p_input, "time", TimeCallback, NULL );
161 var_AddCallback( p_input, "time-offset", TimeCallback, NULL );
163 /* length variable */
164 var_Create( p_input, "length", VLC_VAR_TIME );
166 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
169 var_Create( p_input, "rate", VLC_VAR_INTEGER );
170 var_Create( p_input, "rate-slower", VLC_VAR_VOID );
171 var_Create( p_input, "rate-faster", VLC_VAR_VOID );
172 val.i_int = DEFAULT_RATE;
173 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
174 var_AddCallback( p_input, "rate", RateCallback, NULL );
175 var_AddCallback( p_input, "rate-slower", RateCallback, NULL );
176 var_AddCallback( p_input, "rate-faster", RateCallback, NULL );
179 var_Create( p_input, "state", VLC_VAR_INTEGER );
181 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
182 var_AddCallback( p_input, "state", StateCallback, NULL );
185 var_Create( p_input, "demuxed-id3", VLC_VAR_BOOL );
186 val.b_bool = VLC_FALSE;
187 var_Change( p_input, "demuxed-id3", VLC_VAR_SETVALUE, &val, NULL );
189 /* Initialize thread properties */
191 p_input->b_out_pace_control = VLC_FALSE;
192 p_input->p_sys = NULL;
195 vlc_mutex_lock( &p_item->lock );
196 p_input->psz_source = strdup( p_item->psz_uri );
197 vlc_mutex_unlock( &p_item->lock );
203 p_input->p_es_out = NULL;
206 p_input->p_demux = NULL;
207 p_input->pf_demux = NULL;
208 p_input->pf_rewind = NULL;
209 p_input->pf_demux_control = demux_vaControlDefault;
210 p_input->i_cr_average = config_GetInt( p_input, "cr-average" );
213 p_input->p_access = NULL;
214 p_input->pf_access_control = NULL;
216 p_input->i_bufsize = 0;
218 p_input->i_pts_delay = DEFAULT_PTS_DELAY;
220 /* Initialize statistics */
221 p_input->c_loops = 0;
222 p_input->stream.c_packets_read = 0;
223 p_input->stream.c_packets_trashed = 0;
226 vlc_mutex_init( p_input, &p_input->stream.stream_lock );
227 vlc_cond_init( p_input, &p_input->stream.stream_wait );
228 vlc_mutex_init( p_input, &p_input->stream.control.control_lock );
230 /* Initialize stream description */
231 p_input->stream.b_changed = 0;
232 p_input->stream.i_es_number = 0;
233 p_input->stream.i_selected_es_number = 0;
234 p_input->stream.i_pgrm_number = 0;
235 p_input->stream.i_new_status = p_input->stream.i_new_rate = 0;
236 p_input->stream.b_new_mute = MUTE_NO_CHANGE;
237 p_input->stream.i_mux_rate = 0;
238 p_input->stream.b_seekable = 0;
239 p_input->stream.p_sout = NULL;
241 /* no stream, no program, no area, no es */
242 p_input->stream.p_new_program = NULL;
244 p_input->stream.i_area_nb = 0;
245 p_input->stream.pp_areas = NULL;
246 p_input->stream.p_selected_area = NULL;
247 p_input->stream.p_new_area = NULL;
249 p_input->stream.pp_selected_es = NULL;
250 p_input->stream.p_removed_es = NULL;
251 p_input->stream.p_newly_selected_es = NULL;
253 /* By default there is one area in a stream */
254 input_AddArea( p_input, 0, 1 );
255 p_input->stream.p_selected_area = p_input->stream.pp_areas[0];
257 /* Initialize stream control properties. */
258 p_input->stream.control.i_status = INIT_S;
259 p_input->stream.control.i_rate = DEFAULT_RATE;
260 p_input->stream.control.b_mute = 0;
261 p_input->stream.control.b_grayscale = config_GetInt( p_input, "grayscale");
263 msg_Info( p_input, "playlist item `%s'", p_input->psz_source );
266 var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
267 var_Create( p_input, "bookmark", VLC_VAR_INTEGER | VLC_VAR_HASCHOICE |
269 val.psz_string = _("Bookmark");
270 var_Change( p_input, "bookmark", VLC_VAR_SETTEXT, &val, NULL );
271 var_AddCallback( p_input, "bookmark", BookmarkCallback, NULL );
273 p_input->i_bookmarks = 0;
274 p_input->pp_bookmarks = NULL;
276 var_Get( p_input, "bookmarks", &val );
279 /* FIXME: have a common cfg parsing routine used by sout and others */
280 char *psz_parser, *psz_start, *psz_end;
281 psz_parser = val.psz_string;
282 while( (psz_start = strchr( psz_parser, '{' ) ) )
284 seekpoint_t seekpoint;
287 psz_end = strchr( psz_start, '}' );
288 if( !psz_end ) break;
289 psz_parser = psz_end + 1;
290 backup = *psz_parser;
294 seekpoint.psz_name = 0;
295 seekpoint.i_byte_offset = 0;
296 seekpoint.i_time_offset = 0;
297 while( (psz_end = strchr( psz_start, ',' ) ) )
300 if( !strncmp( psz_start, "name=", 5 ) )
302 seekpoint.psz_name = psz_start + 5;
304 else if( !strncmp( psz_start, "bytes=", 6 ) )
306 seekpoint.i_byte_offset = atoll(psz_start + 6);
308 else if( !strncmp( psz_start, "time=", 5 ) )
310 seekpoint.i_time_offset = atoll(psz_start + 5) * 1000000;
312 psz_start = psz_end + 1;
314 msg_Dbg( p_input, "adding bookmark: %s, bytes="I64Fd", time="I64Fd,
315 seekpoint.psz_name, seekpoint.i_byte_offset,
316 seekpoint.i_time_offset );
317 input_Control( p_input, INPUT_ADD_BOOKMARK, &seekpoint );
318 *psz_parser = backup;
320 free( val.psz_string );
323 vlc_object_attach( p_input, p_parent );
325 /* Create thread and wait for its readiness. */
326 if( vlc_thread_create( p_input, "input", RunThread,
327 VLC_THREAD_PRIORITY_INPUT, VLC_TRUE ) )
329 msg_Err( p_input, "cannot create input thread" );
337 /*****************************************************************************
338 * input_StopThread: mark an input thread as zombie
339 *****************************************************************************
340 * This function should not return until the thread is effectively cancelled.
341 *****************************************************************************/
342 void input_StopThread( input_thread_t *p_input )
347 /* Make the thread exit from a possible vlc_cond_wait() */
348 vlc_mutex_lock( &p_input->stream.stream_lock );
350 /* Request thread destruction */
352 /* Temporary demux2 hack */
353 p_demux = (demux_t *)vlc_object_find( p_input, VLC_OBJECT_DEMUX, FIND_CHILD );
357 vlc_object_release( p_demux );
360 /* Temporary access2 hack */
361 p_access = (access_t *)vlc_object_find( p_input, VLC_OBJECT_ACCESS, FIND_CHILD );
365 vlc_object_release( p_access );
370 vlc_cond_signal( &p_input->stream.stream_wait );
371 vlc_mutex_unlock( &p_input->stream.stream_lock );
374 /*****************************************************************************
375 * input_DestroyThread: mark an input thread as zombie
376 *****************************************************************************
377 * This function should not return until the thread is effectively cancelled.
378 *****************************************************************************/
379 void input_DestroyThread( input_thread_t *p_input )
381 /* Join the thread */
382 vlc_thread_join( p_input );
384 /* Destroy Mutex locks */
385 vlc_mutex_destroy( &p_input->stream.control.control_lock );
386 vlc_cond_destroy( &p_input->stream.stream_wait );
387 vlc_mutex_destroy( &p_input->stream.stream_lock );
390 /*****************************************************************************
391 * RunThread: main thread loop
392 *****************************************************************************
393 * Thread in charge of processing the network packets and demultiplexing.
394 *****************************************************************************/
395 static int RunThread( input_thread_t *p_input )
398 mtime_t i_update_next = -1;
400 /* Signal right now, otherwise we'll get stuck in a peek */
401 vlc_thread_ready( p_input );
403 if( InitThread( p_input ) )
405 /* If we failed, wait before we are killed, and exit */
406 p_input->b_error = 1;
408 ErrorThread( p_input );
410 /* Tell we're dead */
416 /* initialization is complete */
417 vlc_mutex_lock( &p_input->stream.stream_lock );
418 p_input->stream.b_changed = 1;
419 p_input->stream.control.i_status = PLAYING_S;
420 vlc_mutex_unlock( &p_input->stream.stream_lock );
422 val.i_int = PLAYING_S;
423 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
425 while( !p_input->b_die && !p_input->b_error && !p_input->b_eof )
427 unsigned int i, i_count;
431 vlc_mutex_lock( &p_input->stream.stream_lock );
433 if( p_input->stream.p_new_program )
435 if( p_input->pf_set_program != NULL )
438 /* Reinitialize buffer manager. */
439 input_AccessReinit( p_input );
441 p_input->pf_set_program( p_input,
442 p_input->stream.p_new_program );
444 /* Escape all decoders for the stream discontinuity they
446 input_EscapeDiscontinuity( p_input );
448 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
450 pgrm_descriptor_t * p_pgrm
451 = p_input->stream.pp_programs[i];
453 /* Reinitialize synchro. */
454 p_pgrm->i_synchro_state = SYNCHRO_REINIT;
457 p_input->stream.p_new_program = NULL;
460 if( p_input->stream.p_new_area )
462 if( p_input->stream.b_seekable && p_input->pf_set_area != NULL )
464 input_AccessReinit( p_input );
466 p_input->pf_set_area( p_input, p_input->stream.p_new_area );
468 /* Escape all decoders for the stream discontinuity they
470 input_EscapeDiscontinuity( p_input );
472 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
474 pgrm_descriptor_t * p_pgrm
475 = p_input->stream.pp_programs[i];
477 /* Reinitialize synchro. */
478 p_pgrm->i_synchro_state = SYNCHRO_REINIT;
481 p_input->stream.p_new_area = NULL;
484 if( p_input->stream.p_selected_area->i_seek != NO_SEEK )
486 if( p_input->stream.p_selected_area->i_size > 0 )
490 double f = (double)p_input->stream.p_selected_area->i_seek /
491 (double)p_input->stream.p_selected_area->i_size;
493 vlc_mutex_unlock( &p_input->stream.stream_lock );
494 demux_Control( p_input, DEMUX_SET_POSITION, f );
495 vlc_mutex_lock( &p_input->stream.stream_lock );
497 /* Escape all decoders for the stream discontinuity they
499 input_EscapeDiscontinuity( p_input );
501 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
503 pgrm_descriptor_t * p_pgrm=p_input->stream.pp_programs[i];
505 /* Reinitialize synchro. */
506 p_pgrm->i_synchro_state = SYNCHRO_REINIT;
509 vlc_mutex_unlock( &p_input->stream.stream_lock );
510 if( !demux_Control( p_input, DEMUX_GET_TIME, &i_time ) )
515 /* Help in bar display */
517 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
520 for( i = 0; i < p_input->p_sys->i_sub; i++ )
522 subtitle_Seek( p_input->p_sys->sub[i], i_time );
525 if( !demux_Control( p_input, DEMUX_GET_POSITION, &f ) )
527 val.f_float = (float)f;
528 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
530 vlc_mutex_lock( &p_input->stream.stream_lock );
532 p_input->stream.p_selected_area->i_seek = NO_SEEK;
535 if( p_input->stream.p_removed_es )
537 input_UnselectES( p_input, p_input->stream.p_removed_es );
538 p_input->stream.p_removed_es = NULL;
541 if( p_input->stream.p_newly_selected_es )
543 input_SelectES( p_input, p_input->stream.p_newly_selected_es );
544 p_input->stream.p_newly_selected_es = NULL;
547 if( p_input->stream.b_new_mute != MUTE_NO_CHANGE )
549 if( p_input->stream.b_new_mute )
551 input_EscapeAudioDiscontinuity( p_input );
554 vlc_mutex_lock( &p_input->stream.control.control_lock );
555 p_input->stream.control.b_mute = p_input->stream.b_new_mute;
556 vlc_mutex_unlock( &p_input->stream.control.control_lock );
558 p_input->stream.b_new_mute = MUTE_NO_CHANGE;
561 vlc_mutex_unlock( &p_input->stream.stream_lock );
563 /* Read and demultiplex some data. */
564 i_count = p_input->pf_demux( p_input );
570 var_Get( p_input, "input-repeat", &repeat );
571 if( repeat.i_int == 0 || p_input->stream.i_area_nb <= 0 )
573 /* End of file - we do not set b_die because only the
574 * playlist is allowed to do so. */
575 msg_Info( p_input, "EOF reached" );
580 msg_Dbg( p_input, "repeating the same input (%d)", repeat.i_int );
581 if( repeat.i_int > 0 )
584 var_Set( p_input, "input-repeat", repeat );
587 p_input->stream.p_new_area = p_input->stream.pp_areas[0];
588 p_input->stream.p_new_area->i_seek = 0;
591 else if( i_count < 0 )
593 p_input->b_error = 1;
596 if( !p_input->b_error && !p_input->b_eof && i_update_next < mdate() )
603 /* update input status variables */
604 if( !demux_Control( p_input, DEMUX_GET_POSITION, &d_pos ) )
606 val.f_float = (float)d_pos;
607 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
609 if( !demux_Control( p_input, DEMUX_GET_TIME, &i_time ) )
612 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
614 if( !demux_Control( p_input, DEMUX_GET_LENGTH, &i_length ) )
617 var_Get( p_input, "length", &old_val );
618 val.i_time = i_length;
619 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
620 if( old_val.i_time != val.i_time )
622 char psz_buffer[MSTRTIME_MAX_SIZE];
624 vlc_mutex_lock( &p_input->p_item->lock );
625 p_input->p_item->i_duration = i_length;
626 vlc_mutex_unlock( &p_input->p_item->lock );
628 input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
629 msecstotimestr( psz_buffer, i_length / 1000 ) );
633 /* Check stop-time */
634 if( p_input->p_sys->i_stop_time > 0 && p_input->p_sys->i_stop_time < i_time )
636 msg_Warn( p_input, "EOF reached because of stop-time" );
641 for( i = 0; i < p_input->p_sys->i_sub; i++ )
643 subtitle_Demux( p_input->p_sys->sub[i], i_time );
646 i_update_next = mdate() + I64C(150000);
650 if( p_input->b_error || p_input->b_eof )
652 ErrorThread( p_input );
655 EndThread( p_input );
660 /*****************************************************************************
661 * InitThread: init the input Thread
662 *****************************************************************************/
663 static int InitThread( input_thread_t * p_input )
665 vlc_meta_t *p_meta = NULL, *p_meta_user = NULL;
670 /* Parse source string. Syntax : [[<access>][/<demux>]:][<source>] */
671 char * psz_parser = p_input->psz_dupsource = strdup(p_input->psz_source);
672 vlc_value_t val, val1;
673 int64_t i_microsecondperframe;
675 subtitle_demux_t *p_sub_toselect = NULL;
676 char *psz_sub_file = NULL;
678 /* Skip the plug-in names */
679 while( *psz_parser && *psz_parser != ':' )
683 #if defined( WIN32 ) || defined( UNDER_CE )
684 if( psz_parser - p_input->psz_dupsource == 1 )
686 msg_Warn( p_input, "drive letter %c: found in source string",
687 p_input->psz_dupsource[0] ) ;
694 p_input->psz_access = p_input->psz_demux = "";
695 p_input->psz_name = p_input->psz_source;
696 free( p_input->psz_dupsource );
697 p_input->psz_dupsource = NULL;
701 *psz_parser++ = '\0';
703 /* let's skip '//' */
704 if( psz_parser[0] == '/' && psz_parser[1] == '/' )
709 p_input->psz_name = psz_parser ;
711 /* Come back to parse the access and demux plug-ins */
712 psz_parser = p_input->psz_dupsource;
717 p_input->psz_access = "";
719 else if( *psz_parser == '/' )
722 p_input->psz_access = "";
727 p_input->psz_access = psz_parser;
729 while( *psz_parser && *psz_parser != '/' )
734 if( *psz_parser == '/' )
736 *psz_parser++ = '\0';
743 p_input->psz_demux = "";
747 p_input->psz_demux = psz_parser;
751 msg_Dbg( p_input, "access `%s', demux `%s', name `%s'",
752 p_input->psz_access, p_input->psz_demux, p_input->psz_name );
754 if( input_AccessInit( p_input ) == -1 )
756 free( p_input->psz_source );
757 if( p_input->psz_dupsource != NULL )
759 free( p_input->psz_dupsource );
765 /* Initialize optional stream output. (before demuxer)*/
766 var_Get( p_input, "sout", &val );
767 if( val.psz_string != NULL )
769 if ( *val.psz_string && (p_input->stream.p_sout =
770 sout_NewInstance( p_input, val.psz_string )) == NULL )
772 msg_Err( p_input, "cannot start stream output instance, aborting" );
773 free( val.psz_string );
775 input_AccessEnd( p_input );
776 free( p_input->psz_source );
777 if( p_input->psz_dupsource != NULL )
779 free( p_input->psz_dupsource );
783 free( val.psz_string );
786 p_input->p_es_out = input_EsOutNew( p_input );
787 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_FALSE );
788 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE, ES_OUT_MODE_NONE );
790 /* Find and open appropriate access module */
791 p_input->p_access = module_Need( p_input, "access",
792 p_input->psz_access, VLC_TRUE );
794 /* Maybe we had an encoded url */
795 if( !p_input->p_access && strchr( p_input->psz_name, '%' ) )
797 DecodeUrl( p_input->psz_name );
799 msg_Dbg( p_input, "retying with %s", p_input->psz_name );
800 p_input->p_access = module_Need( p_input, "access",
801 p_input->psz_access, VLC_TRUE );
803 #ifndef WIN32 /* Remove this gross hack from the win32 build as colons
804 * are forbidden in filenames on Win32. */
806 /* Maybe we got something like: /Volumes/toto:titi/gabu.mpg */
807 if ( p_input->p_access == NULL
808 && (*p_input->psz_demux || *p_input->psz_access) )
810 p_input->psz_access = p_input->psz_demux = "";
811 p_input->psz_name = p_input->psz_source;
812 free( p_input->psz_dupsource);
813 p_input->psz_dupsource = NULL;
815 p_input->p_access = module_Need( p_input, "access",
816 p_input->psz_access, VLC_TRUE );
819 if( p_input->p_access == NULL )
821 msg_Err( p_input, "no suitable access module for `%s/%s://%s'",
822 p_input->psz_access, p_input->psz_demux, p_input->psz_name );
823 if ( p_input->stream.p_sout != NULL )
825 sout_DeleteInstance( p_input->stream.p_sout );
828 input_AccessEnd( p_input );
829 free( p_input->psz_source );
830 if( p_input->psz_dupsource != NULL )
832 free( p_input->psz_dupsource );
834 input_EsOutDelete( p_input->p_es_out );
838 /* Waiting for stream. */
841 p_input->i_bufsize = p_input->i_mtu;
845 p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
848 /* If the desynchronisation requested by the user is < 0, we need to
849 * cache more data. */
850 var_Create( p_input, "audio-desync", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
851 var_Get( p_input, "audio-desync", &val );
853 p_input->i_pts_delay -= (val.i_int * 1000);
855 if( p_input->p_current_data == NULL && p_input->pf_read != NULL )
857 while( !input_FillBuffer( p_input ) )
859 if( p_input->b_die || p_input->b_error || p_input->b_eof )
861 module_Unneed( p_input, p_input->p_access );
862 if ( p_input->stream.p_sout != NULL )
864 sout_DeleteInstance( p_input->stream.p_sout );
866 input_AccessEnd( p_input );
867 free( p_input->psz_source );
868 if( p_input->psz_dupsource != NULL )
870 free( p_input->psz_dupsource );
872 input_EsOutDelete( p_input->p_es_out );
878 /* Create the stream_t facilities */
879 p_input->s = input_StreamNew( p_input );
880 if( p_input->s == NULL )
882 /* should never occur yet */
884 msg_Err( p_input, "cannot create stream_t" );
886 module_Unneed( p_input, p_input->p_access );
887 if ( p_input->stream.p_sout != NULL )
889 sout_DeleteInstance( p_input->stream.p_sout );
891 input_AccessEnd( p_input );
892 free( p_input->psz_source );
893 if( p_input->psz_dupsource != NULL )
895 free( p_input->psz_dupsource );
897 input_EsOutDelete( p_input->p_es_out );
901 /* Find and open appropriate demux module */
903 module_Need( p_input, "demux",
904 (p_input->psz_demux && *p_input->psz_demux) ?
905 p_input->psz_demux : "$demux",
906 (p_input->psz_demux && *p_input->psz_demux) ?
907 VLC_TRUE : VLC_FALSE );
909 if( p_input->p_demux == NULL )
911 msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
912 p_input->psz_access, p_input->psz_demux, p_input->psz_name );
914 input_StreamDelete( p_input->s );
915 module_Unneed( p_input, p_input->p_access );
916 if ( p_input->stream.p_sout != NULL )
918 sout_DeleteInstance( p_input->stream.p_sout );
920 input_AccessEnd( p_input );
921 free( p_input->psz_source );
922 if( p_input->psz_dupsource != NULL )
924 free( p_input->psz_dupsource );
926 input_EsOutDelete( p_input->p_es_out );
930 /* Init input_thread_sys_t */
931 p_input->p_sys = malloc( sizeof( input_thread_sys_t ) );
932 p_input->p_sys->i_sub = 0;
933 p_input->p_sys->sub = NULL;
935 p_input->p_sys->i_stop_time = 0;
937 /* Get meta information from user */
938 var_Create( p_input, "meta-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
939 var_Create( p_input, "meta-author", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
940 var_Create( p_input, "meta-artist", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
941 var_Create( p_input, "meta-genre", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
942 var_Create( p_input, "meta-copyright", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
943 var_Create( p_input, "meta-description", VLC_VAR_STRING|VLC_VAR_DOINHERIT);
944 var_Create( p_input, "meta-date", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
945 var_Create( p_input, "meta-url", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
946 if( (p_meta_user = vlc_meta_New()) )
950 var_Get( p_input, "meta-title", &val );
951 if( val.psz_string && *val.psz_string )
952 vlc_meta_Add( p_meta_user, VLC_META_TITLE, val.psz_string );
953 if( val.psz_string ) free( val.psz_string );
954 var_Get( p_input, "meta-author", &val );
955 if( val.psz_string && *val.psz_string )
956 vlc_meta_Add( p_meta_user, VLC_META_AUTHOR, val.psz_string );
957 if( val.psz_string ) free( val.psz_string );
958 var_Get( p_input, "meta-artist", &val );
959 if( val.psz_string && *val.psz_string )
960 vlc_meta_Add( p_meta_user, VLC_META_ARTIST, val.psz_string );
961 if( val.psz_string ) free( val.psz_string );
962 var_Get( p_input, "meta-genre", &val );
963 if( val.psz_string && *val.psz_string )
964 vlc_meta_Add( p_meta_user, VLC_META_GENRE, val.psz_string );
965 if( val.psz_string ) free( val.psz_string );
966 var_Get( p_input, "meta-copyright", &val );
967 if( val.psz_string && *val.psz_string )
968 vlc_meta_Add( p_meta_user, VLC_META_COPYRIGHT, val.psz_string );
969 if( val.psz_string ) free( val.psz_string );
970 var_Get( p_input, "meta-description", &val );
971 if( val.psz_string && *val.psz_string )
972 vlc_meta_Add( p_meta_user, VLC_META_DESCRIPTION, val.psz_string );
973 if( val.psz_string ) free( val.psz_string );
974 var_Get( p_input, "meta-date", &val );
975 if( val.psz_string && *val.psz_string )
976 vlc_meta_Add( p_meta_user, VLC_META_DATE, val.psz_string );
977 if( val.psz_string ) free( val.psz_string );
978 var_Get( p_input, "meta-url", &val );
979 if( val.psz_string && *val.psz_string )
980 vlc_meta_Add( p_meta_user, VLC_META_URL, val.psz_string );
981 if( val.psz_string ) free( val.psz_string );
984 /* Get meta informations from demuxer */
985 if( !demux_Control( p_input, DEMUX_GET_META, &p_meta ) ||
986 ( p_meta_user && p_meta_user->i_meta ) )
990 /* Merge demux and user metadata */
991 if( !p_meta ){ p_meta = p_meta_user; p_meta_user = NULL; }
992 else if( p_meta && p_meta_user ) vlc_meta_Merge( p_meta, p_meta_user );
994 msg_Dbg( p_input, "meta informations:" );
995 if( p_meta->i_meta > 0 )
997 for( i = 0; i < p_meta->i_meta; i++ )
999 msg_Dbg( p_input, " - '%s' = '%s'", _(p_meta->name[i]),
1001 if( !strcmp( p_meta->name[i], VLC_META_TITLE ) &&
1003 input_Control( p_input, INPUT_SET_NAME, p_meta->value[i] );
1005 if( !strcmp( p_meta->name[i], VLC_META_AUTHOR ) )
1006 input_Control( p_input, INPUT_ADD_INFO, _("General"),
1007 _("Author"), p_meta->value[i] );
1009 input_Control( p_input, INPUT_ADD_INFO, _("File"),
1010 _(p_meta->name[i]), "%s", p_meta->value[i] );
1013 for( i = 0; i < p_meta->i_track; i++ )
1015 vlc_meta_t *tk = p_meta->track[i];
1018 msg_Dbg( p_input, " - track[%d]:", i );
1019 if( tk->i_meta > 0 )
1021 char *psz_cat = malloc( strlen(_("Stream")) + 10 );
1022 sprintf( psz_cat, "%s %d", _("Stream"), i );
1024 for( j = 0; j < tk->i_meta; j++ )
1026 msg_Dbg( p_input, " - '%s' = '%s'", _(tk->name[j]),
1029 input_Control( p_input, INPUT_ADD_INFO, psz_cat,
1030 _(tk->name[j]), "%s", tk->value[j] );
1035 if( p_input->stream.p_sout && p_input->stream.p_sout->p_meta == NULL )
1037 p_input->stream.p_sout->p_meta = p_meta;
1041 vlc_meta_Delete( p_meta );
1044 if( p_meta_user ) vlc_meta_Delete( p_meta_user );
1047 if( !demux_Control( p_input, DEMUX_GET_LENGTH, &i_length ) &&
1050 char psz_buffer[MSTRTIME_MAX_SIZE];
1052 vlc_mutex_lock( &p_input->p_item->lock );
1053 p_input->p_item->i_duration = i_length;
1054 vlc_mutex_unlock( &p_input->p_item->lock );
1056 input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
1057 msecstotimestr( psz_buffer, i_length / 1000 ) );
1059 /* Set start time */
1060 var_Get( p_input, "start-time", &val );
1063 double f_pos = val.i_int * I64C(1000000) / (double)i_length;
1067 msg_Warn( p_input, "invalid start-time, ignored (start-time "
1068 ">= media length)" );
1072 p_input->stream.p_selected_area->i_seek =
1073 (int64_t)( f_pos * (double)p_input->stream.p_selected_area->i_size );
1075 msg_Dbg( p_input, "start-time %ds (%2.2f)", val.i_int, f_pos );
1080 /* Set stop-time and check validity */
1081 var_Get( p_input, "stop-time", &val );
1086 var_Get( p_input, "start-time", &start );
1087 if( start.i_int >= val.i_int )
1089 msg_Warn( p_input, "invalid stop-time, ignored (stop-time < "
1094 p_input->p_sys->i_stop_time = (int64_t)val.i_int * I64C(1000000);
1095 msg_Dbg( p_input, "stop-time %ds", val.i_int );
1100 if( demux_Control( p_input, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 )
1102 i_microsecondperframe = 0;
1106 i_microsecondperframe = (int64_t)( (double)1000000.0 / (double)f_fps );
1109 /* Look for and add subtitle files */
1110 var_Get( p_input, "sub-file", &val );
1111 if( val.psz_string && *val.psz_string )
1113 subtitle_demux_t *p_sub;
1115 msg_Dbg( p_input, "force subtitle: %s", val.psz_string );
1116 if( ( p_sub = subtitle_New( p_input, strdup(val.psz_string),
1117 i_microsecondperframe ) ) )
1119 p_sub_toselect = p_sub;
1120 TAB_APPEND( p_input->p_sys->i_sub, p_input->p_sys->sub, p_sub );
1123 psz_sub_file = val.psz_string;
1125 var_Get( p_input, "sub-autodetect-file", &val );
1126 var_Get( p_input, "sub-autodetect-path", &val1 );
1129 subtitle_demux_t *p_sub;
1131 char **tmp = subtitles_Detect( p_input, val1.psz_string, p_input->psz_name );
1133 for( i = 0; *tmp2 != NULL; i++ )
1135 if( psz_sub_file == NULL || strcmp( psz_sub_file, *tmp2 ) )
1137 if( ( p_sub = subtitle_New( p_input, *tmp2,
1138 i_microsecondperframe ) ) )
1140 TAB_APPEND( p_input->p_sys->i_sub, p_input->p_sys->sub,
1147 free( val1.psz_string );
1149 if( psz_sub_file ) free( psz_sub_file );
1151 es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
1152 val.b_bool = VLC_FALSE;
1153 if( p_input->stream.p_sout )
1155 var_Get( p_input, "sout-all", &val );
1157 es_out_Control( p_input->p_es_out, ES_OUT_SET_MODE,
1158 val.b_bool ? ES_OUT_MODE_ALL : ES_OUT_MODE_AUTO );
1159 if( p_sub_toselect )
1161 es_out_Control( p_input->p_es_out, ES_OUT_SET_ES,
1162 p_sub_toselect->p_es, VLC_TRUE );
1165 if( p_input->stream.p_sout )
1167 if( p_input->stream.p_sout->i_out_pace_nocontrol > 0 )
1169 p_input->b_out_pace_control = VLC_FALSE;
1173 p_input->b_out_pace_control = VLC_TRUE;
1175 msg_Dbg( p_input, "starting in %s mode",
1176 p_input->b_out_pace_control ? "asynch" : "synch" );
1182 /*****************************************************************************
1183 * ErrorThread: RunThread() error loop
1184 *****************************************************************************
1185 * This function is called when an error occured during thread main's loop.
1186 *****************************************************************************/
1187 static void ErrorThread( input_thread_t *p_input )
1189 while( !p_input->b_die )
1192 msleep( INPUT_IDLE_SLEEP );
1196 /*****************************************************************************
1197 * EndThread: end the input thread
1198 *****************************************************************************/
1199 static void EndThread( input_thread_t * p_input )
1202 #ifdef HAVE_SYS_TIMES_H
1203 /* Display statistics */
1204 struct tms cpu_usage;
1205 times( &cpu_usage );
1207 msg_Dbg( p_input, "%ld loops consuming user: %ld, system: %ld",
1208 p_input->c_loops, cpu_usage.tms_utime, cpu_usage.tms_stime );
1210 msg_Dbg( p_input, "%ld loops", p_input->c_loops );
1214 /* DumpStream: printf some info for debugging purpose */
1215 #define S p_input->stream
1216 msg_Dbg( p_input, "dumping stream ID 0x%x [OK:%ld/D:%ld]", S.i_stream_id,
1217 S.c_packets_read, S.c_packets_trashed );
1220 char psz_time1[MSTRTIME_MAX_SIZE];
1221 char psz_time2[MSTRTIME_MAX_SIZE];
1223 msg_Dbg( p_input, "seekable stream, position: "I64Fd"/"I64Fd" (%s/%s)",
1224 S.p_selected_area->i_tell, S.p_selected_area->i_size,
1225 input_OffsetToTime( p_input, psz_time1,
1226 S.p_selected_area->i_tell ),
1227 input_OffsetToTime( p_input, psz_time2,
1228 S.p_selected_area->i_size ) );
1231 msg_Dbg( p_input, "pace %scontrolled", S.b_pace_control ? "" : "un-" );
1233 for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
1235 #define P p_input->stream.pp_programs[i]
1236 msg_Dbg( p_input, "dumping program 0x%x, version %d (%s)",
1237 P->i_number, P->i_version,
1238 P->b_is_ok ? "complete" : "partial" );
1240 for( j = 0; j < p_input->stream.pp_programs[i]->i_es_number; j++ )
1242 #define ES p_input->stream.pp_programs[i]->pp_es[j]
1243 msg_Dbg( p_input, "ES 0x%x, "
1244 "stream 0x%x, fourcc `%4.4s', %s [OK:%ld/ERR:%ld]",
1245 ES->i_id, ES->i_stream_id, (char*)&ES->i_fourcc,
1246 ES->p_dec != NULL ? "selected" : "not selected",
1247 ES->c_packets, ES->c_invalid_packets );
1252 /* Free demultiplexer's data */
1253 if( p_input->p_demux ) module_Unneed( p_input, p_input->p_demux );
1255 /* Free all ES and destroy all decoder threads */
1256 input_EndStream( p_input );
1258 /* Close optional stream output instance */
1259 if( p_input->stream.p_sout )
1261 vlc_object_t *p_pl =
1262 vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1265 if( var_Get( p_input, "sout-keep", &keep ) >= 0 && keep.b_bool && p_pl )
1267 /* attach sout to the playlist */
1268 msg_Warn( p_input, "keeping sout" );
1269 vlc_object_detach( p_input->stream.p_sout );
1270 vlc_object_attach( p_input->stream.p_sout, p_pl );
1274 msg_Warn( p_input, "destroying sout" );
1275 sout_DeleteInstance( p_input->stream.p_sout );
1279 vlc_object_release( p_pl );
1283 /* Destroy subtitles demuxers */
1284 if( p_input->p_sys )
1286 for( i = 0; i < p_input->p_sys->i_sub; i++ )
1288 subtitle_Close( p_input->p_sys->sub[i] );
1290 if( p_input->p_sys->i_sub > 0 )
1292 free( p_input->p_sys->sub );
1295 /* Free input_thread_sys_t */
1296 free( p_input->p_sys );
1299 /* Destroy the stream_t facilities */
1300 if( p_input->s ) input_StreamDelete( p_input->s );
1302 /* Destroy es out */
1303 if( p_input->p_es_out ) input_EsOutDelete( p_input->p_es_out );
1305 /* Close the access plug-in */
1306 if( p_input->p_access ) module_Unneed( p_input, p_input->p_access );
1308 input_AccessEnd( p_input );
1310 /* Free info structures XXX destroy es before 'cause vorbis */
1311 msg_Dbg( p_input, "freeing info structures...");
1313 free( p_input->psz_source );
1314 if( p_input->psz_dupsource != NULL ) free( p_input->psz_dupsource );
1316 /* Tell we're dead */
1317 p_input->b_dead = 1;
1319 /*****************************************************************************
1320 * DecodeUrl: decode a given encoded url
1321 *****************************************************************************/
1322 static void DecodeUrl( char *psz )
1324 char *dup = strdup( psz );
1342 *psz++ = strtol( val, NULL, 16 );
1344 else if( *p == '+' )
1358 /*****************************************************************************
1359 * ParseOption: parses the options for the input
1360 *****************************************************************************
1361 * This function parses the input (config) options and creates their associated
1363 * Options are of the form "[no[-]]foo[=bar]" where foo is the option name and
1364 * bar is the value of the option.
1365 *****************************************************************************/
1366 static void ParseOption( input_thread_t *p_input, const char *psz_option )
1368 char *psz_name = (char *)psz_option;
1369 char *psz_value = strchr( psz_option, '=' );
1370 int i_name_len, i_type;
1371 vlc_bool_t b_isno = VLC_FALSE;
1374 if( psz_value ) i_name_len = psz_value - psz_option;
1375 else i_name_len = strlen( psz_option );
1377 /* It's too much of an hassle to remove the ':' when we parse
1378 * the cmd line :) */
1379 if( i_name_len && *psz_name == ':' )
1385 if( i_name_len == 0 ) return;
1387 psz_name = strndup( psz_name, i_name_len );
1388 if( psz_value ) psz_value++;
1390 i_type = config_GetType( p_input, psz_name );
1392 if( !i_type && !psz_value )
1394 /* check for "no-foo" or "nofoo" */
1395 if( !strncmp( psz_name, "no-", 3 ) )
1397 memmove( psz_name, psz_name + 3, strlen(psz_name) + 1 - 3 );
1399 else if( !strncmp( psz_name, "no", 2 ) )
1401 memmove( psz_name, psz_name + 2, strlen(psz_name) + 1 - 2 );
1403 else goto cleanup; /* Option doesn't exist */
1406 i_type = config_GetType( p_input, psz_name );
1408 if( !i_type ) goto cleanup; /* Option doesn't exist */
1410 else if( !i_type ) goto cleanup; /* Option doesn't exist */
1412 if( ( i_type != VLC_VAR_BOOL ) &&
1413 ( !psz_value || !*psz_value ) ) goto cleanup; /* Invalid value */
1415 /* Create the variable in the input object.
1416 * Children of the input object will be able to retreive this value
1417 * thanks to the inheritance property of the object variables. */
1418 var_Create( p_input, psz_name, i_type );
1423 val.b_bool = !b_isno;
1426 case VLC_VAR_INTEGER:
1427 val.i_int = atoi( psz_value );
1431 val.f_float = atof( psz_value );
1434 case VLC_VAR_STRING:
1435 case VLC_VAR_MODULE:
1437 case VLC_VAR_DIRECTORY:
1438 val.psz_string = psz_value;
1446 var_Set( p_input, psz_name, val );
1448 msg_Dbg( p_input, "set input option: %s to %s", psz_name, psz_value );
1451 if( psz_name ) free( psz_name );
1455 /*****************************************************************************
1456 * input_SetStatus: change the reading status
1457 *****************************************************************************/
1458 static void input_SetStatus( input_thread_t *p_input, int i_mode )
1460 vlc_mutex_lock( &p_input->stream.stream_lock );
1464 case INPUT_STATUS_END:
1465 p_input->stream.i_new_status = PLAYING_S;
1467 msg_Dbg( p_input, "end of stream" );
1470 case INPUT_STATUS_PLAY:
1471 p_input->stream.i_new_status = PLAYING_S;
1472 msg_Dbg( p_input, "playing at normal rate" );
1475 case INPUT_STATUS_PAUSE:
1476 /* XXX: we don't need to check i_status, because input_clock.c
1478 p_input->stream.i_new_status = PAUSE_S;
1479 msg_Dbg( p_input, "toggling pause" );
1482 case INPUT_STATUS_FASTER:
1483 if( p_input->stream.control.i_rate * 4 <= DEFAULT_RATE )
1485 msg_Dbg( p_input, "can not play any faster" );
1489 p_input->stream.i_new_status = FORWARD_S;
1490 p_input->stream.i_new_rate =
1491 p_input->stream.control.i_rate / 2;
1493 if ( p_input->stream.i_new_rate < DEFAULT_RATE )
1495 msg_Dbg( p_input, "playing at %i:1 fast forward",
1496 DEFAULT_RATE / p_input->stream.i_new_rate );
1498 else if ( p_input->stream.i_new_rate > DEFAULT_RATE )
1500 msg_Dbg( p_input, "playing at 1:%i slow motion",
1501 p_input->stream.i_new_rate / DEFAULT_RATE );
1503 else if ( p_input->stream.i_new_rate == DEFAULT_RATE )
1505 p_input->stream.i_new_status = PLAYING_S;
1506 msg_Dbg( p_input, "playing at normal rate" );
1511 case INPUT_STATUS_SLOWER:
1512 if( p_input->stream.control.i_rate >= 8 * DEFAULT_RATE )
1514 msg_Dbg( p_input, "can not play any slower" );
1518 p_input->stream.i_new_status = FORWARD_S;
1519 p_input->stream.i_new_rate =
1520 p_input->stream.control.i_rate * 2;
1522 if ( p_input->stream.i_new_rate < DEFAULT_RATE )
1524 msg_Dbg( p_input, "playing at %i:1 fast forward",
1525 DEFAULT_RATE / p_input->stream.i_new_rate );
1527 else if ( p_input->stream.i_new_rate > DEFAULT_RATE )
1529 msg_Dbg( p_input, "playing at 1:%i slow motion",
1530 p_input->stream.i_new_rate / DEFAULT_RATE );
1532 else if ( p_input->stream.i_new_rate == DEFAULT_RATE )
1534 p_input->stream.i_new_status = PLAYING_S;
1535 msg_Dbg( p_input, "playing at normal rate" );
1544 vlc_cond_signal( &p_input->stream.stream_wait );
1545 vlc_mutex_unlock( &p_input->stream.stream_lock );
1547 /*****************************************************************************
1549 *****************************************************************************/
1550 static void input_SetRate( vlc_object_t * p_this, int i_rate )
1552 input_thread_t *p_input;
1554 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
1556 if( p_input == NULL )
1558 msg_Err( p_this, "no input found" );
1562 vlc_mutex_lock( &p_input->stream.stream_lock );
1564 if( i_rate * 8 < DEFAULT_RATE )
1566 msg_Dbg( p_input, "can not play faster than 8x" );
1567 vlc_mutex_unlock( &p_input->stream.stream_lock );
1570 if( i_rate > DEFAULT_RATE * 8 )
1572 msg_Dbg( p_input, "can not play slower than 1/8x" );
1573 vlc_mutex_unlock( &p_input->stream.stream_lock );
1576 p_input->stream.i_new_status = FORWARD_S;
1577 p_input->stream.i_new_rate = i_rate;
1579 if ( p_input->stream.i_new_rate < DEFAULT_RATE )
1581 msg_Dbg( p_input, "playing at %i:1 fast forward",
1582 DEFAULT_RATE / p_input->stream.i_new_rate );
1584 else if ( p_input->stream.i_new_rate > DEFAULT_RATE )
1586 msg_Dbg( p_input, "playing at 1:%i slow motion",
1587 p_input->stream.i_new_rate / DEFAULT_RATE );
1589 else if ( p_input->stream.i_new_rate == DEFAULT_RATE )
1591 p_input->stream.i_new_status = PLAYING_S;
1592 msg_Dbg( p_input, "playing at normal rate" );
1595 vlc_cond_signal( &p_input->stream.stream_wait );
1596 vlc_mutex_unlock( &p_input->stream.stream_lock );
1598 vlc_object_release( p_input );
1601 /*****************************************************************************
1602 * Callbacks (position, time, state, rate )
1603 *****************************************************************************/
1604 static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
1605 vlc_value_t oldval, vlc_value_t newval,
1608 input_thread_t *p_input = (input_thread_t *)p_this;
1610 msg_Dbg( p_input, "cmd=%s old=%f new=%f", psz_cmd,
1611 oldval.f_float, newval.f_float );
1613 if( !strcmp( psz_cmd, "position-offset" ) )
1616 var_Get( p_input, "position", &val );
1618 newval.f_float += val.f_float;
1620 var_Change( p_input, "position", VLC_VAR_SETVALUE, &newval, NULL );
1622 vlc_mutex_lock( &p_input->stream.stream_lock );
1623 p_input->stream.p_selected_area->i_seek =
1624 (int64_t)( newval.f_float *
1625 (double)p_input->stream.p_selected_area->i_size );
1627 if( p_input->stream.p_selected_area->i_seek < 0 )
1629 p_input->stream.p_selected_area->i_seek = 0;
1631 vlc_mutex_unlock( &p_input->stream.stream_lock );
1636 static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
1637 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1639 input_thread_t *p_input = (input_thread_t *)p_this;
1642 /* FIXME TODO FIXME */
1643 msg_Dbg( p_input, "cmd=%s old=%lld new=%lld", psz_cmd,
1644 oldval.i_time, newval.i_time );
1646 var_Get( p_input, "length", &val );
1647 if( val.i_time > 0 )
1649 val.f_float = (double)newval.i_time / (double)val.i_time;
1650 if( !strcmp( psz_cmd, "time-offset" ) )
1653 var_Set( p_input, "position-offset", val );
1655 var_Get( p_input, "time", &t );
1656 t.i_time += newval.i_time;
1657 var_Change( p_input, "time", VLC_VAR_SETVALUE, &t, NULL );
1661 var_Set( p_input, "position", val );
1662 var_Change( p_input, "time", VLC_VAR_SETVALUE, &newval, NULL );
1667 msg_Warn( p_input, "TimeCallback: length <= 0 -> can't seek" );
1672 static int StateCallback( vlc_object_t *p_this, char const *psz_cmd,
1673 vlc_value_t oldval, vlc_value_t newval,
1676 input_thread_t *p_input = (input_thread_t *)p_this;
1678 msg_Dbg( p_input, "cmd=%s old=%d new=%d",
1679 psz_cmd, oldval.i_int, newval.i_int );
1681 switch( newval.i_int )
1684 input_SetStatus( p_input, INPUT_STATUS_PLAY );
1687 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
1690 input_SetStatus( p_input, INPUT_STATUS_END );
1693 msg_Err( p_input, "cannot set new state (invalid)" );
1694 return VLC_EGENERIC;
1698 static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
1699 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1701 input_thread_t *p_input = (input_thread_t *)p_this;
1703 if( !strcmp( psz_cmd, "rate-slower" ) )
1705 input_SetStatus( p_input, INPUT_STATUS_SLOWER );
1707 else if( !strcmp( psz_cmd, "rate-faster" ) )
1709 input_SetStatus( p_input, INPUT_STATUS_FASTER );
1713 msg_Dbg( p_input, "cmd=%s old=%d new=%d",
1714 psz_cmd, oldval.i_int, newval.i_int );
1715 input_SetRate( p_input, newval.i_int );
1720 static int BookmarkCallback( vlc_object_t *p_this, char const *psz_cmd,
1721 vlc_value_t oldval, vlc_value_t newval, void *p_data )
1723 input_thread_t *p_input = (input_thread_t *)p_this;
1724 return input_Control( p_input, INPUT_SET_BOOKMARK, newval );