/*****************************************************************************
* input.c: input thread
*****************************************************************************
- * Copyright (C) 1998-2007 the VideoLAN team
+ * Copyright (C) 1998-2007 VLC authors and VideoLAN
* $Id$
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar <fenrir@via.ecp.fr>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
static int UpdateTitleSeekpointFromDemux( input_thread_t * );
static void UpdateGenericFromDemux( input_thread_t * );
-static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
+static void MRLSections( const char *, int *, int *, int *, int *);
static input_source_t *InputSourceNew( input_thread_t *);
static int InputSourceInit( input_thread_t *, input_source_t *,
static void ObjectKillChildrens( input_thread_t *p_input, vlc_object_t *p_obj )
{
vlc_list_t *p_list;
- int i;
/* FIXME ObjectKillChildrens seems a very bad idea in fact */
- i = vlc_internals( p_obj )->i_object_type;
- if( i == VLC_OBJECT_VOUT ||i == VLC_OBJECT_AOUT ||
- p_obj == VLC_OBJECT(p_input->p->p_sout) ||
- i == VLC_OBJECT_DECODER )
+ if( p_obj == VLC_OBJECT(p_input->p->p_sout) )
return;
vlc_object_kill( p_obj );
p_list = vlc_list_children( p_obj );
- for( i = 0; i < p_list->i_count; i++ )
+ for( int i = 0; i < p_list->i_count; i++ )
ObjectKillChildrens( p_input, p_list->p_values[i].p_object );
vlc_list_release( p_list );
}
const char *psz_header, bool b_quick,
input_resource_t *p_resource )
{
- static const char input_name[] = "input";
input_thread_t *p_input = NULL; /* thread descriptor */
int i;
/* Allocate descriptor */
- p_input = vlc_custom_create( p_parent, sizeof( *p_input ),
- VLC_OBJECT_INPUT, input_name );
+ p_input = vlc_custom_create( p_parent, sizeof( *p_input ), "input" );
if( p_input == NULL )
return NULL;
free( psz_name );
- /* Start a timer to mesure how long it takes
- * to launch an input */
- stats_TimerStart( p_input, psz_timer_name,
- STATS_TIMER_INPUT_LAUNCHING );
-
p_input->p = calloc( 1, sizeof( input_thread_private_t ) );
if( !p_input->p )
return NULL;
p_input->p->title = NULL;
p_input->p->i_title_offset = p_input->p->i_seekpoint_offset = 0;
p_input->p->i_state = INIT_S;
- double f_rate = var_InheritFloat( p_input, "rate" );
- if( f_rate <= 0. )
- {
- msg_Warn( p_input, "Negative or zero rate values are forbidden" );
- f_rate = 1.;
- }
- p_input->p->i_rate = INPUT_RATE_DEFAULT / f_rate;
+ p_input->p->i_rate = INPUT_RATE_DEFAULT;
p_input->p->b_recording = false;
memset( &p_input->p->bookmark, 0, sizeof(p_input->p->bookmark) );
TAB_INIT( p_input->p->i_bookmark, p_input->p->pp_bookmark );
free( psz_name );
#endif
- stats_TimerDump( p_input, STATS_TIMER_INPUT_LAUNCHING );
- stats_TimerClean( p_input, STATS_TIMER_INPUT_LAUNCHING );
-
if( p_input->p->p_es_out_display )
es_out_Delete( p_input->p->p_es_out_display );
{
msg_Dbg( p_input, "EOF reached" );
p_input->p->input.b_eof = true;
+ es_out_Eos(p_input->p->p_es_out);
}
else if( i_ret < 0 )
{
bool b_pause_after_eof = b_interactive &&
var_CreateGetBool( p_input, "play-and-pause" );
- /* Start the timer */
- stats_TimerStop( p_input, STATS_TIMER_INPUT_LAUNCHING );
-
while( vlc_object_alive( p_input ) && !p_input->b_error )
{
bool b_force_update;
if( p_input->b_preparsing ) return;
/* Prepare statistics */
-#define INIT_COUNTER( c, type, compute ) p_input->p->counters.p_##c = \
- stats_CounterCreate( p_input, VLC_VAR_##type, STATS_##compute);
+#define INIT_COUNTER( c, compute ) p_input->p->counters.p_##c = \
+ stats_CounterCreate( STATS_##compute);
if( libvlc_stats( p_input ) )
{
- INIT_COUNTER( read_bytes, INTEGER, COUNTER );
- INIT_COUNTER( read_packets, INTEGER, COUNTER );
- INIT_COUNTER( demux_read, INTEGER, COUNTER );
- INIT_COUNTER( input_bitrate, FLOAT, DERIVATIVE );
- INIT_COUNTER( demux_bitrate, FLOAT, DERIVATIVE );
- INIT_COUNTER( demux_corrupted, INTEGER, COUNTER );
- INIT_COUNTER( demux_discontinuity, INTEGER, COUNTER );
- INIT_COUNTER( played_abuffers, INTEGER, COUNTER );
- INIT_COUNTER( lost_abuffers, INTEGER, COUNTER );
- INIT_COUNTER( displayed_pictures, INTEGER, COUNTER );
- INIT_COUNTER( lost_pictures, INTEGER, COUNTER );
- INIT_COUNTER( decoded_audio, INTEGER, COUNTER );
- INIT_COUNTER( decoded_video, INTEGER, COUNTER );
- INIT_COUNTER( decoded_sub, INTEGER, COUNTER );
+ INIT_COUNTER( read_bytes, COUNTER );
+ INIT_COUNTER( read_packets, COUNTER );
+ INIT_COUNTER( demux_read, COUNTER );
+ INIT_COUNTER( input_bitrate, DERIVATIVE );
+ INIT_COUNTER( demux_bitrate, DERIVATIVE );
+ INIT_COUNTER( demux_corrupted, COUNTER );
+ INIT_COUNTER( demux_discontinuity, COUNTER );
+ INIT_COUNTER( played_abuffers, COUNTER );
+ INIT_COUNTER( lost_abuffers, COUNTER );
+ INIT_COUNTER( displayed_pictures, COUNTER );
+ INIT_COUNTER( lost_pictures, COUNTER );
+ INIT_COUNTER( decoded_audio, COUNTER );
+ INIT_COUNTER( decoded_video, COUNTER );
+ INIT_COUNTER( decoded_sub, COUNTER );
p_input->p->counters.p_sout_send_bitrate = NULL;
p_input->p->counters.p_sout_sent_packets = NULL;
p_input->p->counters.p_sout_sent_bytes = NULL;
- if( p_input->p->counters.p_demux_bitrate )
- p_input->p->counters.p_demux_bitrate->update_interval = 1000000;
- if( p_input->p->counters.p_input_bitrate )
- p_input->p->counters.p_input_bitrate->update_interval = 1000000;
}
}
}
if( libvlc_stats( p_input ) )
{
- INIT_COUNTER( sout_sent_packets, INTEGER, COUNTER );
- INIT_COUNTER( sout_sent_bytes, INTEGER, COUNTER );
- INIT_COUNTER( sout_send_bitrate, FLOAT, DERIVATIVE );
- if( p_input->p->counters.p_sout_send_bitrate )
- p_input->p->counters.p_sout_send_bitrate->update_interval =
- 1000000;
+ INIT_COUNTER( sout_sent_packets, COUNTER );
+ INIT_COUNTER( sout_sent_bytes, COUNTER );
+ INIT_COUNTER( sout_send_bitrate, DERIVATIVE );
}
}
else
if( p_input->b_preparsing )
return;
+ vlc_mutex_lock( &p_input->p->p_item->lock );
/* Create global title (from master) */
p_input->p->i_title = p_master->i_title;
p_input->p->title = p_master->title;
p_input->p->b_can_pace_control = p_master->b_can_pace_control;
p_input->p->b_can_pause = p_master->b_can_pause;
p_input->p->b_can_rate_control = p_master->b_can_rate_control;
+ vlc_mutex_unlock( &p_input->p->p_item->lock );
}
static void StartTitle( input_thread_t * p_input )
LoadSubtitles( p_input );
LoadSlaves( p_input );
InitPrograms( p_input );
+
+ double f_rate = var_InheritFloat( p_input, "rate" );
+ if( f_rate != 0.0 && f_rate != 1.0 )
+ {
+ vlc_value_t val = { .i_int = INPUT_RATE_DEFAULT / f_rate };
+ input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &val );
+ }
}
if( !p_input->b_preparsing && p_input->p->p_sout )
p_input->p->input.p_stream )
{
const uint64_t i_size = stream_Size( p_input->p->input.p_stream );
- if( i_size > 0 && bookmark.i_byte_offset <= i_size )
+ if( i_size > 0 && (uint64_t)bookmark.i_byte_offset <= i_size )
{
val.f_float = (double)bookmark.i_byte_offset / i_size;
b_force_update = Control( p_input, INPUT_CONTROL_SET_POSITION, val );
input_source_t *in, const char *psz_mrl,
const char *psz_forced_demux, bool b_in_can_fail )
{
- const char *psz_access;
- const char *psz_demux;
- char *psz_path;
+ const char *psz_access, *psz_demux, *psz_path, *psz_anchor;
char *psz_var_demux = NULL;
double f_fps;
goto error;
/* Split uri */
- input_SplitMRL( &psz_access, &psz_demux, &psz_path, psz_dup );
+ input_SplitMRL( &psz_access, &psz_demux, &psz_path, &psz_anchor, psz_dup );
msg_Dbg( p_input, "`%s' gives access `%s' demux `%s' path `%s'",
psz_mrl, psz_access, psz_demux, psz_path );
if( !p_input->b_preparsing )
{
- /* Hack to allow udp://@:port syntax */
- if( !psz_access ||
- (strncmp( psz_access, "udp", 3 ) &&
- strncmp( psz_access, "rtp", 3 )) )
- {
- /* Find optional titles and seekpoints */
- MRLSections( p_input, psz_path, &in->i_title_start, &in->i_title_end,
+ /* Find optional titles and seekpoints */
+ MRLSections( psz_anchor, &in->i_title_start, &in->i_title_end,
&in->i_seekpoint_start, &in->i_seekpoint_end );
- }
-
if( psz_forced_demux && *psz_forced_demux )
{
psz_demux = psz_forced_demux;
return;
demux_meta_t *p_demux_meta =
- vlc_custom_create( p_demux, sizeof( *p_demux_meta ),
- VLC_OBJECT_GENERIC, "demux meta" );
+ vlc_custom_create( p_demux, sizeof( *p_demux_meta ), "demux meta" );
if( !p_demux_meta )
return;
p_demux_meta->p_demux = p_demux;
* MRLSplit: parse the access, demux and url part of the
* Media Resource Locator.
*****************************************************************************/
-void input_SplitMRL( const char **ppsz_access, const char **ppsz_demux,
- char **ppsz_path, char *psz_dup )
+void input_SplitMRL( const char **access, const char **demux,
+ const char **path, const char **anchor, char *buf )
{
char *p;
/* Separate <path> from <access>[/<demux>]:// */
- p = strstr( psz_dup, "://" );
+ p = strstr( buf, "://" );
if( p != NULL )
{
*p = '\0';
p += 3; /* skips "://" */
- *ppsz_path = p;
+ *path = p;
/* Remove HTML anchor if present (not supported).
* The hash symbol itself should be URI-encoded. */
p = strchr( p, '#' );
- if( p )
- *p = '\0';
+ if( p != NULL )
+ {
+ *(p++) = '\0';
+ *anchor = p;
+ }
+ else
+ *anchor = "";
}
else
{
#ifndef NDEBUG
fprintf( stderr, "%s(\"%s\") probably not a valid URI!\n", __func__,
- psz_dup );
+ buf );
#endif
/* Note: this is a valid non const pointer to "": */
- *ppsz_path = psz_dup + strlen( psz_dup );
+ *path = buf + strlen( buf );
}
/* Separate access from demux */
- p = strchr( psz_dup, '/' );
+ p = strchr( buf, '/' );
if( p != NULL )
{
*(p++) = '\0';
if( p[0] == '$' )
p++;
- *ppsz_demux = p;
+ *demux = p;
}
else
- *ppsz_demux = "";
+ *demux = "";
/* We really don't want module name substitution here! */
- p = psz_dup;
+ p = buf;
if( p[0] == '$' )
p++;
- *ppsz_access = p;
+ *access = p;
}
-static inline bool next(char ** src)
+static const char *MRLSeekPoint( const char *str, int *title, int *chapter )
{
char *end;
- errno = 0;
- long result = strtol( *src, &end, 0 );
- if( errno != 0 || result >= LONG_MAX || result <= LONG_MIN ||
- end == *src )
+ unsigned long u;
+
+ /* Look for the title */
+ u = strtoul( str, &end, 0 );
+ *title = (str == end || u > (unsigned long)INT_MAX) ? -1 : (int)u;
+ str = end;
+
+ /* Look for the chapter */
+ if( *str == ':' )
{
- return false;
+ str++;
+ u = strtoul( str, &end, 0 );
+ *chapter = (str == end || u > (unsigned long)INT_MAX) ? -1 : (int)u;
+ str = end;
}
- *src = end;
- return true;
+ else
+ *chapter = -1;
+
+ return str;
}
+
/*****************************************************************************
* MRLSections: parse title and seekpoint info from the Media Resource Locator.
*
* Syntax:
- * [url][@[title-start][:chapter-start][-[title-end][:chapter-end]]]
+ * [url][@[title_start][:chapter_start][-[title_end][:chapter_end]]]
*****************************************************************************/
-static void MRLSections( input_thread_t *p_input, char *psz_source,
+static void MRLSections( const char *p,
int *pi_title_start, int *pi_title_end,
int *pi_chapter_start, int *pi_chapter_end )
{
- char *psz, *psz_end, *psz_next, *psz_check;
-
- *pi_title_start = *pi_title_end = -1;
- *pi_chapter_start = *pi_chapter_end = -1;
-
- /* Start by parsing titles and chapters */
- if( !psz_source || !( psz = strrchr( psz_source, '@' ) ) ) return;
-
-
- /* Check we are really dealing with a title/chapter section */
- psz_check = psz + 1;
- if( !*psz_check ) return;
- if( isdigit(*psz_check) )
- if(!next(&psz_check)) return;
- if( *psz_check != ':' && *psz_check != '-' && *psz_check ) return;
- if( *psz_check == ':' && ++psz_check )
- {
- if( isdigit(*psz_check) )
- if(!next(&psz_check)) return;
- }
- if( *psz_check != '-' && *psz_check ) return;
- if( *psz_check == '-' && ++psz_check )
- {
- if( isdigit(*psz_check) )
- if(!next(&psz_check)) return;
- }
- if( *psz_check != ':' && *psz_check ) return;
- if( *psz_check == ':' && ++psz_check )
- {
- if( isdigit(*psz_check) )
- if(!next(&psz_check)) return;
- }
- if( *psz_check ) return;
+ *pi_title_start = *pi_title_end = *pi_chapter_start = *pi_chapter_end = -1;
- /* Separate start and end */
- *psz++ = 0;
- if( ( psz_end = strchr( psz, '-' ) ) ) *psz_end++ = 0;
+ int title_start, chapter_start, title_end, chapter_end;
- /* Look for the start title */
- *pi_title_start = strtol( psz, &psz_next, 0 );
- if( !*pi_title_start && psz == psz_next ) *pi_title_start = -1;
- *pi_title_end = *pi_title_start;
- psz = psz_next;
+ if( !p )
+ return;
- /* Look for the start chapter */
- if( *psz ) psz++;
- *pi_chapter_start = strtol( psz, &psz_next, 0 );
- if( !*pi_chapter_start && psz == psz_next ) *pi_chapter_start = -1;
- *pi_chapter_end = *pi_chapter_start;
+ if( *p != '-' )
+ p = MRLSeekPoint( p, &title_start, &chapter_start );
+ else
+ title_start = chapter_start = -1;
- if( psz_end )
- {
- /* Look for the end title */
- *pi_title_end = strtol( psz_end, &psz_next, 0 );
- if( !*pi_title_end && psz_end == psz_next ) *pi_title_end = -1;
- psz_end = psz_next;
+ if( *p == '-' )
+ p = MRLSeekPoint( p + 1, &title_end, &chapter_end );
+ else
+ title_end = chapter_end = -1;
- /* Look for the end chapter */
- if( *psz_end ) psz_end++;
- *pi_chapter_end = strtol( psz_end, &psz_next, 0 );
- if( !*pi_chapter_end && psz_end == psz_next ) *pi_chapter_end = -1;
- }
+ if( *p ) /* syntax error */
+ return;
- msg_Dbg( p_input, "source=`%s' title=%d/%d seekpoint=%d/%d",
- psz_source, *pi_title_start, *pi_chapter_start,
- *pi_title_end, *pi_chapter_end );
+ *pi_title_start = title_start;
+ *pi_title_end = title_end;
+ *pi_chapter_start = chapter_start;
+ *pi_chapter_end = chapter_end;
}
/*****************************************************************************
vlc_mutex_lock( &p_input->p->counters.counters_lock);
switch( i_type )
{
-#define I(c) stats_UpdateInteger( p_input, p_input->p->counters.c, i_delta, NULL )
+#define I(c) stats_Update( p_input->p->counters.c, i_delta, NULL )
case INPUT_STATISTIC_DECODED_VIDEO:
I(p_decoded_video);
break;
#undef I
case INPUT_STATISTIC_SENT_BYTE:
{
- int i_bytes; /* That's pretty stupid to define it as an integer, it will overflow
- really fast ... */
- if( !stats_UpdateInteger( p_input, p_input->p->counters.p_sout_sent_bytes, i_delta, &i_bytes ) )
- stats_UpdateFloat( p_input, p_input->p->counters.p_sout_send_bitrate, i_bytes, NULL );
+ uint64_t bytes;
+
+ stats_Update( p_input->p->counters.p_sout_sent_bytes, i_delta, &bytes );
+ stats_Update( p_input->p->counters.p_sout_send_bitrate, bytes, NULL );
break;
}
default: