#include "modules/modules.h"
#include "config/configuration.h"
+#include "playlist/preparser.h"
#include <stdio.h> /* sprintf() */
#include <string.h>
#include <stdlib.h> /* free() */
+#include <errno.h>
#include "config/vlc_getopt.h"
#include <assert.h>
-/*****************************************************************************
- * The evil global variables. We handle them with care, don't worry.
- *****************************************************************************/
-
-#if !defined(_WIN32) && !defined(__OS2__)
-static bool b_daemon = false;
-#endif
-
/*****************************************************************************
* Local prototypes
*****************************************************************************/
return NULL;
priv = libvlc_priv (p_libvlc);
- priv->p_playlist = NULL;
+ priv->playlist = NULL;
priv->p_dialog_provider = NULL;
priv->p_vlm = NULL;
/* Check for daemon mode */
if( var_InheritBool( p_libvlc, "daemon" ) )
{
- char *psz_pidfile = NULL;
-
if( daemon( 1, 0) != 0 )
{
msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
vlc_LogDeinit (p_libvlc);
return VLC_ENOMEM;
}
- b_daemon = true;
/* lets check if we need to write the pidfile */
- psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
- if( psz_pidfile != NULL )
+ char *pidfile = var_InheritString( p_libvlc, "pidfile" );
+ if( pidfile != NULL )
{
- FILE *pidfile;
- pid_t i_pid = getpid ();
- msg_Dbg( p_libvlc, "PID is %d, writing it to %s",
- i_pid, psz_pidfile );
- pidfile = vlc_fopen( psz_pidfile,"w" );
- if( pidfile != NULL )
+ FILE *stream = vlc_fopen( pidfile, "w" );
+ if( stream != NULL )
{
- utf8_fprintf( pidfile, "%d", (int)i_pid );
- fclose( pidfile );
+ fprintf( stream, "%d", (int)getpid() );
+ fclose( stream );
+ msg_Dbg( p_libvlc, "written PID file %s", pidfile );
}
else
- {
- msg_Err( p_libvlc, "cannot open pid file for writing: %s (%m)",
- psz_pidfile );
- }
+ msg_Err( p_libvlc, "cannot write PID file %s: %s",
+ pidfile, vlc_strerror_c(errno) );
+ free( pidfile );
}
- free( psz_pidfile );
+ }
+ else
+ {
+ var_Create( p_libvlc, "pidfile", VLC_VAR_STRING );
+ var_SetString( p_libvlc, "pidfile", "" );
}
#endif
*/
priv->actions = vlc_InitActions( p_libvlc );
+ /*
+ * Meta data handling
+ */
+ priv->parser = playlist_preparser_New(VLC_OBJECT(p_libvlc));
+
/* Create a variable for showing the fullscreen interface */
var_Create( p_libvlc, "intf-toggle-fscontrol", VLC_VAR_BOOL );
var_SetBool( p_libvlc, "intf-toggle-fscontrol", true );
}
if( asprintf( &psz_temp, "%s,none", psz_module ) != -1)
{
- intf_Create( p_libvlc, psz_temp );
+ libvlc_InternalAddIntf( p_libvlc, psz_temp );
free( psz_temp );
}
}
free( psz_modules );
free( psz_control );
- if( var_InheritBool( p_libvlc, "file-logging" )
-#ifdef HAVE_SYSLOG_H
- && !var_InheritBool( p_libvlc, "syslog" )
-#endif
- )
- {
- intf_Create( p_libvlc, "logger,none" );
- }
#ifdef HAVE_SYSLOG_H
if( var_InheritBool( p_libvlc, "syslog" ) )
{
char *logmode = var_CreateGetNonEmptyString( p_libvlc, "logmode" );
var_SetString( p_libvlc, "logmode", "syslog" );
- intf_Create( p_libvlc, "logger,none" );
+ libvlc_InternalAddIntf( p_libvlc, "logger,none" );
if( logmode )
{
}
var_Destroy( p_libvlc, "logmode" );
}
+ else
#endif
+ if( var_InheritBool( p_libvlc, "file-logging" ) )
+ libvlc_InternalAddIntf( p_libvlc, "logger,none" );
if( var_InheritBool( p_libvlc, "network-synchronisation") )
- {
- intf_Create( p_libvlc, "netsync,none" );
- }
+ libvlc_InternalAddIntf( p_libvlc, "netsync,none" );
#ifdef __APPLE__
var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
psz_val = var_InheritString( p_libvlc, "open" );
if ( psz_val != NULL )
{
- playlist_AddExt( pl_Get(p_libvlc), psz_val, NULL, PLAYLIST_INSERT, 0,
- -1, 0, NULL, 0, true, pl_Unlocked );
+ intf_InsertItem( p_libvlc, psz_val, 0, NULL, 0 );
free( psz_val );
}
}
#endif
- /* Free playlist now, all threads are gone */
- playlist_t *p_playlist = libvlc_priv (p_libvlc)->p_playlist;
- if( p_playlist != NULL )
- playlist_Destroy( p_playlist );
-
- msg_Dbg( p_libvlc, "removing stats" );
-
#if !defined( _WIN32 ) && !defined( __OS2__ )
- char* psz_pidfile = NULL;
-
- if( b_daemon )
+ char *pidfile = var_InheritString( p_libvlc, "pidfile" );
+ if( pidfile != NULL )
{
- psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" );
- if( psz_pidfile != NULL )
- {
- msg_Dbg( p_libvlc, "removing pid file %s", psz_pidfile );
- if( unlink( psz_pidfile ) == -1 )
- {
- msg_Dbg( p_libvlc, "removing pid file %s: %m",
- psz_pidfile );
- }
- }
- free( psz_pidfile );
+ msg_Dbg( p_libvlc, "removing PID file %s", pidfile );
+ if( unlink( pidfile ) )
+ msg_Warn( p_libvlc, "cannot remove PID file %s: %s",
+ pidfile, vlc_strerror_c(errno) );
+ free( pidfile );
}
#endif
+ if (priv->parser != NULL)
+ playlist_preparser_Delete(priv->parser);
+
vlc_DeinitActions( p_libvlc, priv->actions );
/* Save the configuration */
vlc_object_release( p_libvlc );
}
-/**
- * Add an interface plugin and run it
- */
-int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module )
-{
- if( !p_libvlc )
- return VLC_EGENERIC;
-
- if( !psz_module ) /* requesting the default interface */
- {
- char *psz_interface = var_CreateGetNonEmptyString( p_libvlc, "intf" );
- if( !psz_interface ) /* "intf" has not been set */
- {
-#if !defined( _WIN32 ) && !defined( __OS2__ )
- if( b_daemon )
- /* Daemon mode hack.
- * We prefer the dummy interface if none is specified. */
- psz_module = "dummy";
- else
-#endif
- msg_Info( p_libvlc, "%s",
- _("Running vlc with the default interface. "
- "Use 'cvlc' to use vlc without interface.") );
- }
- free( psz_interface );
- var_Destroy( p_libvlc, "intf" );
- }
-
- /* Try to create the interface */
- int ret = intf_Create( p_libvlc, psz_module ? psz_module : "$intf" );
- if( ret )
- msg_Err( p_libvlc, "interface \"%s\" initialization failed",
- psz_module ? psz_module : "default" );
- return ret;
-}
-
/*****************************************************************************
* GetFilenames: parse command line options which are not flags
*****************************************************************************
continue;
}
- playlist_AddExt( pl_Get( p_vlc ), (mrl != NULL) ? mrl : args[n], NULL,
- PLAYLIST_INSERT, 0, -1, i_options,
+ intf_InsertItem( p_vlc, (mrl != NULL) ? mrl : args[n], i_options,
( i_options ? &args[n + 1] : NULL ),
- VLC_INPUT_OPTION_TRUSTED, true, pl_Unlocked );
+ VLC_INPUT_OPTION_TRUSTED );
free( mrl );
}
}
+
+/**
+ * Requests extraction of the meta data for an input item (a.k.a. preparsing).
+ * The actual extraction is asynchronous.
+ */
+int libvlc_MetaRequest(libvlc_int_t *libvlc, input_item_t *item)
+{
+ libvlc_priv_t *priv = libvlc_priv(libvlc);
+
+ if (unlikely(priv->parser == NULL))
+ return VLC_ENOMEM;
+
+ playlist_preparser_Push(priv->parser, item);
+ return VLC_SUCCESS;
+}
+
+/**
+ * Requests retrieving/downloading art for an input item.
+ * The retrieval is performed asynchronously.
+ */
+int libvlc_ArtRequest(libvlc_int_t *libvlc, input_item_t *item)
+{
+ libvlc_priv_t *priv = libvlc_priv(libvlc);
+
+ if (unlikely(priv->parser == NULL))
+ return VLC_ENOMEM;
+
+ playlist_preparser_fetcher_Push(priv->parser, item);
+ return VLC_SUCCESS;
+}