#include "vlc_playlist.h"
#include "vlc_interface.h"
#include "vlc_interaction.h"
-#include "vlc_meta_engine.h"
#include "charset.h"
static input_thread_t * Create ( vlc_object_t *, input_item_t *, char *,
vlc_bool_t );
-static int Init ( input_thread_t *p_input, vlc_bool_t b_quick );
+static int Init ( input_thread_t *p_input );
static void Error ( input_thread_t *p_input );
static void End ( input_thread_t *p_input );
static void MainLoop( input_thread_t *p_input );
static int UpdateFromAccess( input_thread_t * );
static int UpdateFromDemux( input_thread_t * );
-static int UpdateMeta( input_thread_t *, vlc_bool_t );
+static int UpdateMeta( input_thread_t * );
-static void UpdateItemLength( input_thread_t *, int64_t i_length, vlc_bool_t );
+static void UpdateItemLength( input_thread_t *, int64_t i_length );
static void DecodeUrl( char * );
static void MRLSections( input_thread_t *, char *, int *, int *, int *, int *);
static input_source_t *InputSourceNew( input_thread_t *);
static int InputSourceInit( input_thread_t *, input_source_t *,
- char *, char *psz_forced_demux,
- vlc_bool_t b_quick );
+ char *, char *psz_forced_demux );
static void InputSourceClean( input_thread_t *, input_source_t * );
static void SlaveDemux( input_thread_t *p_input );
static void InputMetaUser( input_thread_t *p_input );
-int input_DownloadAndCacheArt( vlc_object_t *p_parent, input_item_t *p_item );
-
/*****************************************************************************
* This function creates a new input, and returns a pointer
* to its description. On error, it returns NULL.
msg_Err( p_parent, "out of memory" );
return NULL;
}
+
+ /* One "randomly" selected input thread is responsible for computing
+ * the global stats. Check if there is already someone doing this */
+ if( p_input->p_libvlc->p_playlist->p_stats && !b_quick )
+ {
+ vlc_mutex_lock( &p_input->p_libvlc->p_playlist->p_stats->lock );
+ if( p_input->p_libvlc->p_playlist->p_stats_computer == NULL )
+ {
+ p_input->p_libvlc->p_playlist->p_stats_computer = p_input;
+ }
+ vlc_mutex_unlock( &p_input->p_libvlc->p_playlist->p_stats->lock );
+ }
+
+ p_input->b_preparsing = b_quick;
p_input->psz_header = psz_header ? strdup( psz_header ) : NULL;
/* Init Common fields */
if( !p_input->input.p_item->p_meta )
p_input->input.p_item->p_meta = vlc_meta_New();
- stats_ReinitInputStats( p_item->p_stats );
+
+ if( !p_item->p_stats )
+ {
+ p_item->p_stats = (input_stats_t*)malloc( sizeof( input_stats_t ) );
+ vlc_mutex_init( p_input, &p_item->p_stats->lock );
+ stats_ReinitInputStats( p_item->p_stats );
+ }
/* No slave */
p_input->i_slave = 0;
input_ControlVarInit( p_input );
p_input->input.i_cr_average = var_GetInteger( p_input, "cr-average" );
- if( !b_quick )
+ if( !p_input->b_preparsing )
{
var_Get( p_input, "bookmarks", &val );
if( val.psz_string )
/* Now we can attach our new input */
vlc_object_attach( p_input, p_parent );
- Init( p_input, VLC_TRUE );
+ Init( p_input );
/* Clean up master */
InputSourceClean( p_input, &p_input->input );
return VLC_SUCCESS;
}
-int __input_SecondaryPreparse( vlc_object_t *p_parent, input_item_t *p_item )
-{
- struct meta_engine_t *p_me;
-
- /* FIXME: don't launch any module if we already have all the needed
- * info. Easiest way to do this would be to add a dummy module.
- * I'll do that later */
-
- p_me = vlc_object_create( p_parent, VLC_OBJECT_META_ENGINE );
- p_me->i_flags |= OBJECT_FLAGS_NOINTERACT;
- p_me->i_mandatory = VLC_META_ENGINE_TITLE
- | VLC_META_ENGINE_ARTIST
- | VLC_META_ENGINE_ART_URL;
- p_me->i_optional = 0;
- p_me->p_item = p_item;
- p_me->p_module = module_Need( p_me, "meta engine", 0, VLC_FALSE );
-
-
- if( !p_me->p_module )
- {
- msg_Err( p_parent, "no suitable meta engine module" );
- vlc_object_detach( p_me );
- vlc_object_destroy( p_me );
- return VLC_EGENERIC;
- }
-
- module_Unneed( p_me, p_me->p_module );
-
- vlc_object_destroy( p_me );
-
- input_DownloadAndCacheArt( p_parent, p_item );
-
- return VLC_SUCCESS;
-}
-
/**
* Request a running input thread to stop and die
*
/* Signal that the thread is launched */
vlc_thread_ready( p_input );
- if( Init( p_input, VLC_FALSE ) )
+ if( Init( p_input ) )
{
/* If we failed, wait before we are killed, and exit */
p_input->b_error = VLC_TRUE;
/* Signal that the thread is launched */
vlc_thread_ready( p_input );
- if( Init( p_input, VLC_FALSE ) )
+ if( Init( p_input ) )
{
/* If we failed, just exit */
return 0;
static void MainLoop( input_thread_t *p_input )
{
int64_t i_intf_update = 0;
+ int i_updates = 0;
while( !p_input->b_die && !p_input->b_error && !p_input->input.b_eof )
{
vlc_bool_t b_force_update = VLC_FALSE;
if( old_val.i_time != val.i_time )
{
- UpdateItemLength( p_input, i_length, VLC_TRUE );
+ UpdateItemLength( p_input, i_length );
}
}
var_SetBool( p_input, "intf-change", VLC_TRUE );
i_intf_update = mdate() + I64C(150000);
}
+ /* 150ms * 8 = ~ 1 second */
+ if( ++i_updates % 8 == 0 )
+ {
+ stats_ComputeInputStats( p_input, p_input->input.p_item->p_stats );
+ /* Are we the thread responsible for computing global stats ? */
+ if( p_input->p_libvlc->p_playlist->p_stats_computer == p_input )
+ {
+ stats_ComputeGlobalStats( p_input->p_libvlc->p_playlist,
+ p_input->p_libvlc->p_playlist->p_stats );
+ }
+ }
}
}
-static int Init( input_thread_t * p_input, vlc_bool_t b_quick )
+static int Init( input_thread_t * p_input )
{
char *psz;
char *psz_subtitle;
* want to add more logic, just force file by file:// or code it ;)
*/
memset( &p_input->counters, 0, sizeof( p_input->counters ) );
- if( !b_quick )
+ if( !p_input->b_preparsing )
{
/* Prepare statistics */
#define INIT_COUNTER( p, type, compute ) p_input->counters.p_##p = \
var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
if( InputSourceInit( p_input, &p_input->input,
- p_input->input.p_item->psz_uri, NULL, b_quick ) )
+ p_input->input.p_item->psz_uri, NULL ) )
{
goto error;
}
/* Create global title (from master) */
- if( !b_quick )
+ if( !p_input->b_preparsing )
{
p_input->i_title = p_input->input.i_title;
p_input->title = p_input->input.title;
&val.i_time ) && val.i_time > 0 )
{
var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
- UpdateItemLength( p_input, val.i_time, b_quick );
+ UpdateItemLength( p_input, val.i_time );
p_input->input.p_item->i_duration = val.i_time;
}
/* Start title/chapter */
- if( !b_quick )
+ if( !p_input->b_preparsing )
{
val.i_int = p_input->input.i_title_start -
p_input->input.i_title_offset;
if( strcmp( psz_subtitle, subs[i] ) )
{
sub = InputSourceNew( p_input );
- if( !InputSourceInit( p_input, sub, subs[i], "subtitle",
- VLC_FALSE ) )
+ if( !InputSourceInit( p_input, sub, subs[i], "subtitle" ) )
{
TAB_APPEND( p_input->i_slave, p_input->slave, sub );
}
+ else free( sub );
}
free( subs[i] );
}
msg_Dbg( p_input, "adding slave input '%s'", psz );
slave = InputSourceNew( p_input );
- if( !InputSourceInit( p_input, slave, psz, NULL, VLC_FALSE ) )
+ if( !InputSourceInit( p_input, slave, psz, NULL ) )
{
TAB_APPEND( p_input->i_slave, p_input->slave, slave );
}
+ else free( slave );
psz = psz_delim;
}
}
}
/* Set up es_out */
- if( !b_quick )
+ if( !p_input->b_preparsing )
{
es_out_Control( p_input->p_es_out, ES_OUT_SET_ACTIVE, VLC_TRUE );
i_es_out_mode = ES_OUT_MODE_AUTO;
demux2_Control( p_input->input.p_demux, DEMUX_GET_META, p_meta );
/* Access_file does not give any meta, and there are no slave */
- if( !b_quick )
+ if( !p_input->b_preparsing )
{
if( p_input->input.p_access )
access2_Control( p_input->input.p_access, ACCESS_GET_META,
}
}
- UpdateMeta( p_input, b_quick );
+ UpdateMeta( p_input );
- if( !b_quick )
+ if( !p_input->b_preparsing )
{
msg_Dbg( p_input, "`%s' successfully opened",
p_input->input.p_item->psz_uri );
#define CL_CO( c ) stats_CounterClean( p_input->counters.p_##c ); p_input->counters.p_##c = NULL;
if( p_input->p_libvlc->b_stats )
{
+ /* make sure we are up to date */
+ stats_ComputeInputStats( p_input, p_input->input.p_item->p_stats );
+ if( p_input->p_libvlc->p_playlist->p_stats_computer == p_input )
+ {
+ stats_ComputeGlobalStats( p_input->p_libvlc->p_playlist,
+ p_input->p_libvlc->p_playlist->p_stats );
+ p_input->p_libvlc->p_playlist->p_stats_computer = NULL;
+ }
vlc_mutex_lock( &p_input->counters.counters_lock );
CL_CO( read_bytes );
CL_CO( read_packets );
{
input_source_t *slave = InputSourceNew( p_input );
- if( !InputSourceInit( p_input, slave, val.psz_string, NULL,
- VLC_FALSE ) )
+ if( !InputSourceInit( p_input, slave, val.psz_string, NULL ) )
{
vlc_meta_t *p_meta = p_input->input.p_item->p_meta;
int64_t i_time;
access2_Control( slave->p_access, ACCESS_GET_META,
p_meta );
demux2_Control( slave->p_demux, DEMUX_GET_META, p_meta );
- UpdateMeta( p_input, VLC_FALSE );
+ UpdateMeta( p_input );
TAB_APPEND( p_input->i_slave, p_input->slave, slave );
}
else
{
+ free( slave );
msg_Warn( p_input, "failed to add %s as slave",
val.psz_string );
}
/* TODO maybe multi - access ? */
vlc_meta_t *p_meta = p_input->input.p_item->p_meta;
access2_Control( p_input->input.p_access,ACCESS_GET_META, p_meta );
- UpdateMeta( p_input, VLC_FALSE );
+ UpdateMeta( p_input );
var_SetBool( p_input, "item-change", p_input->input.p_item->i_id );
p_access->info.i_update &= ~INPUT_UPDATE_META;
}
/*****************************************************************************
* UpdateMeta:
*****************************************************************************/
-static int UpdateMeta( input_thread_t *p_input, vlc_bool_t b_quick )
+static int UpdateMeta( input_thread_t *p_input )
{
vlc_meta_t *p_meta = p_input->input.p_item->p_meta;
if( !p_meta )
/*****************************************************************************
* UpdateItemLength:
*****************************************************************************/
-static void UpdateItemLength( input_thread_t *p_input, int64_t i_length,
- vlc_bool_t b_quick )
+static void UpdateItemLength( input_thread_t *p_input, int64_t i_length )
{
- char psz_buffer[MSTRTIME_MAX_SIZE];
-
vlc_mutex_lock( &p_input->input.p_item->lock );
p_input->input.p_item->i_duration = i_length;
vlc_mutex_unlock( &p_input->input.p_item->lock );
- pl_Yield( p_input );
- var_SetInteger( pl_Get( p_input ), "item-change",
- p_input->input.p_item->i_id );
- pl_Release( p_input )
-
- input_Control( p_input, INPUT_ADD_INFO, _("General"), _("Duration"),
- msecstotimestr( psz_buffer, i_length / 1000 ) );
+ if( !p_input->b_preparsing )
+ {
+ pl_Yield( p_input );
+ var_SetInteger( pl_Get( p_input ), "item-change",
+ p_input->input.p_item->i_id );
+ pl_Release( p_input )
+ }
}
/*****************************************************************************
*****************************************************************************/
static int InputSourceInit( input_thread_t *p_input,
input_source_t *in, char *psz_mrl,
- char *psz_forced_demux, vlc_bool_t b_quick )
+ char *psz_forced_demux )
{
char *psz_dup = strdup( psz_mrl );
char *psz_access;
if( !in ) return VLC_EGENERIC;
/* Split uri */
- if( !b_quick )
+ if( !p_input->b_preparsing )
{
MRLSplit( VLC_OBJECT(p_input), psz_dup,
&psz_access, &psz_demux, &psz_path );
{
psz_path = psz_mrl;
msg_Dbg( p_input, "trying to pre-parse %s", psz_path );
- psz_demux = strdup( "" );
- psz_access = strdup( "file" );
+ psz_demux = "";
+ psz_access = "file";
}
if( in->p_demux )
/* Now try a real access */
in->p_access = access2_New( p_input, psz_access, psz_demux, psz_path,
- b_quick );
+ p_input->b_preparsing );
/* Access failed, URL encoded ? */
if( in->p_access == NULL && strchr( psz_path, '%' ) )
in->p_access = access2_New( p_input,
psz_access, psz_demux, psz_path,
- b_quick );
+ p_input->b_preparsing );
}
#ifndef WIN32 /* Remove this gross hack from the win32 build as colons
* are forbidden in filenames on Win32. */
in->p_access = access2_New( p_input,
psz_access, psz_demux, psz_path,
- b_quick );
+ p_input->b_preparsing );
}
#endif
if( psz_tmp ) free( psz_tmp );
/* Get infos from access */
- if( !b_quick )
+ if( !p_input->b_preparsing )
{
access2_Control( in->p_access,
ACCESS_GET_PTS_DELAY, &i_pts_delay );
input_ChangeState( p_input, BUFFERING_S);
/* Create the stream_t */
- in->p_stream = stream_AccessNew( in->p_access, b_quick );
+ in->p_stream = stream_AccessNew( in->p_access, p_input->b_preparsing );
if( in->p_stream == NULL )
{
msg_Warn( p_input, "cannot create a stream_t from access" );
psz_demux = in->p_access->psz_demux;
}
in->p_demux = demux2_New( p_input, psz_access, psz_demux, psz_path,
- in->p_stream, p_input->p_es_out, b_quick );
+ in->p_stream, p_input->p_es_out,
+ p_input->b_preparsing );
if( in->p_demux == NULL )
{
msg_Err( p_input, "no suitable demux module for `%s/%s://%s'",
}
/* TODO get title from demux */
- if( !b_quick && in->i_title <= 0 )
+ if( !p_input->b_preparsing && in->i_title <= 0 )
{
if( demux2_Control( in->p_demux, DEMUX_GET_TITLE_INFO,
&in->title, &in->i_title,
free( val.psz_string )
GET_META( title, "meta-title" );
- GET_META( author, "meta-author" );
GET_META( artist, "meta-artist" );
GET_META( genre, "meta-genre" );
GET_META( copyright, "meta-copyright" );
var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
sub = InputSourceNew( p_input );
- if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle", VLC_FALSE ) )
+ if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle" ) )
{
TAB_APPEND( p_input->i_slave, p_input->slave, sub );
var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
}
}
+ else free( sub );
return VLC_TRUE;
}
-
-#ifndef MAX_PATH
-# define MAX_PATH 250
-#endif
-int input_DownloadAndCacheArt( vlc_object_t *p_parent, input_item_t *p_item )
-{
- char *psz_artist;
- char *psz_album;
- char *psz_type;
- char *psz_filename;
- int i_status = VLC_EGENERIC;
- int i_ret;
- struct stat a;
-
- if( !p_item->p_meta
- || !p_item->p_meta->psz_arturl
- || !*p_item->p_meta->psz_arturl )
- {
- return VLC_EGENERIC;
- }
- if( !strncmp( p_item->p_meta->psz_arturl, "file", 4 ) )
- {
- return VLC_SUCCESS;
- }
-
- psz_artist = p_item->p_meta->psz_artist;
- psz_album = p_item->p_meta->psz_album;
- psz_type = strrchr( p_item->p_meta->psz_arturl, '.' );
- psz_filename = (char *)malloc( MAX_PATH );
-
-
- snprintf( psz_filename, MAX_PATH,
- "file://%s/" CONFIG_DIR "/art/%s/%s/art%s",
- p_parent->p_libvlc->psz_homedir,
- psz_artist, psz_album, psz_type );
- msg_Dbg( p_parent, "Saving album art to %s", psz_filename );
-
- /* Check if file exists */
- i_ret = utf8_stat( psz_filename+7, &a );
- if( i_ret == 0 )
- {
- msg_Dbg( p_parent, "Album art %s already exists", psz_filename );
- }
- else
- {
- //if( i_ret == -1 && errno == ENOTDIR )
- {
- /* GRUIKKKKKKKKKK (make sure that all the directories exist) */
- char *psz_dir = malloc( MAX_PATH );
- snprintf( psz_dir, MAX_PATH, "%s/" CONFIG_DIR,
- p_parent->p_libvlc->psz_homedir );
- utf8_mkdir( psz_dir );
- snprintf( psz_dir, MAX_PATH, "%s/" CONFIG_DIR "/art",
- p_parent->p_libvlc->psz_homedir );
- utf8_mkdir( psz_dir );
- snprintf( psz_dir, MAX_PATH, "%s/" CONFIG_DIR "/art/%s",
- p_parent->p_libvlc->psz_homedir, psz_artist );
- utf8_mkdir( psz_dir );
- snprintf( psz_dir, MAX_PATH, "%s/" CONFIG_DIR "/art/%s/%s",
- p_parent->p_libvlc->psz_homedir,
- psz_artist, psz_album );
- utf8_mkdir( psz_dir );
- free( psz_dir );
- }
-
- stream_t *p_stream = stream_UrlNew( p_parent,
- p_item->p_meta->psz_arturl );
-
- if( p_stream )
- {
- void *p_buffer = malloc( 1<<16 );
- long int l_read;
- FILE *p_file = utf8_fopen( psz_filename+7, "w" );
- while( ( l_read = stream_Read( p_stream, p_buffer, 1<<16 ) ) )
- {
- fwrite( p_buffer, l_read, 1, p_file );
- }
- free( p_buffer );
- fclose( p_file );
- stream_Delete( p_stream );
- msg_Dbg( p_parent, "Album art saved to %s\n", psz_filename );
- free( p_item->p_meta->psz_arturl );
- p_item->p_meta->psz_arturl = strdup( psz_filename );
- i_status = VLC_SUCCESS;
- }
- }
- free( psz_filename );
-
- return i_status;
-}