XMLParser::XMLParser( intf_thread_t *pIntf, const string &rFileName ) : SkinObject( pIntf ), m_pXML( NULL ), m_pReader( NULL ), m_pStream( NULL ) { m_pXML = xml_Create( pIntf ); if( !m_pXML ) { msg_Err( getIntf(), "cannot initialize xml" ); return; } LoadCatalog(); char* psz_uri = make_URI( rFileName.c_str(), NULL ); m_pStream = stream_UrlNew( pIntf, psz_uri ); free( psz_uri ); if( !m_pStream ) { msg_Err( getIntf(), "failed to open %s for reading", rFileName.c_str() ); return; } m_pReader = xml_ReaderCreate( m_pXML, m_pStream ); if( !m_pReader ) { msg_Err( getIntf(), "failed to open %s for parsing", rFileName.c_str() ); return; } xml_ReaderUseDTD( m_pReader ); }
/***************************************************************************** * GetFilenames: parse command line options which are not flags ***************************************************************************** * Parse command line for input files as well as their associated options. * An option always follows its associated input and begins with a ":". *****************************************************************************/ static void GetFilenames( libvlc_int_t *p_vlc, unsigned n, const char *const args[] ) { while( n > 0 ) { /* Count the input options */ unsigned i_options = 0; while( args[--n][0] == ':' ) { i_options++; if( n == 0 ) { msg_Warn( p_vlc, "options %s without item", args[n] ); return; /* syntax!? */ } } char *mrl = make_URI( args[n], NULL ); if( !mrl ) continue; playlist_AddExt( pl_Get( p_vlc ), mrl, NULL, PLAYLIST_INSERT, 0, -1, i_options, ( i_options ? &args[n + 1] : NULL ), VLC_INPUT_OPTION_TRUSTED, true, pl_Unlocked ); free( mrl ); } }
void Playtree::insertItems( VarTree& elem, const list<string>& files, bool start ) { bool first = true; VarTree* p_elem = &elem; playlist_item_t* p_node = NULL; int i_pos = -1; playlist_Lock( m_pPlaylist ); if( p_elem->getId() == m_pPlaylist->p_local_category->i_id ) { p_node = m_pPlaylist->p_local_category; i_pos = 0; } else if( p_elem->getId() == m_pPlaylist->p_ml_category->i_id ) { p_node = m_pPlaylist->p_ml_category; i_pos = 0; } else if( p_elem->size() && p_elem->isExpanded() ) { p_node = playlist_ItemGetById( m_pPlaylist, p_elem->getId() ); i_pos = 0; } else { p_node = playlist_ItemGetById( m_pPlaylist, p_elem->parent()->getId() ); i_pos = p_elem->getIndex(); i_pos++; } if( !p_node ) goto fin; for( list<string>::const_iterator it = files.begin(); it != files.end(); ++it, i_pos++, first = false ) { char* psz_uri = make_URI( it->c_str(), NULL ); if( !psz_uri ) continue; input_item_t* pItem = input_item_New( psz_uri, NULL ); if( pItem ) { int i_mode = PLAYLIST_APPEND; if( first && start ) i_mode |= PLAYLIST_GO; playlist_NodeAddInput( m_pPlaylist, pItem, p_node, i_mode, i_pos, pl_Locked ); } free( psz_uri ); } fin: playlist_Unlock( m_pPlaylist ); }
static int vlclua_make_uri( lua_State *L ) { const char *psz_input = luaL_checkstring( L, 1 ); const char *psz_scheme = luaL_optstring( L, 2, NULL ); char *psz_uri = make_URI( psz_input, psz_scheme ); lua_pushstring( L, psz_uri ); free( psz_uri ); return 1; }
static int onNewFileAdded( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { (void)p_this; services_discovery_t *p_sd = p_data; services_discovery_sys_t *p_sys = p_sd->p_sys; (void)psz_var; (void)oldval; char* psz_file = newval.psz_string; if( !psz_file || !*psz_file ) return VLC_EGENERIC; char* psz_uri = make_URI( psz_file, "file" ); input_item_t* p_item = input_item_New( psz_uri, NULL ); if( p_sys->i_type == Picture ) { if( fileType( p_sd, psz_file ) == Picture ) { formatSnapshotItem( p_item ); services_discovery_AddItem( p_sd, p_item, NULL ); msg_Dbg( p_sd, "New snapshot added : %s", psz_file ); } } else if( p_sys->i_type == Audio ) { if( fileType( p_sd, psz_file ) == Audio ) { services_discovery_AddItem( p_sd, p_item, NULL ); msg_Dbg( p_sd, "New recorded audio added : %s", psz_file ); } } else if( p_sys->i_type == Video ) { if( fileType( p_sd, psz_file ) == Video || fileType( p_sd, psz_file ) == Unknown ) { services_discovery_AddItem( p_sd, p_item, NULL ); msg_Dbg( p_sd, "New recorded video added : %s", psz_file ); } } vlc_gc_decref( p_item ); free( psz_uri ); return VLC_SUCCESS; }
int DirInit (access_t *p_access, DIR *handle) { access_sys_t *p_sys = malloc (sizeof (*p_sys)); if (unlikely(p_sys == NULL)) goto error; char *uri; if (!strcmp (p_access->psz_access, "fd")) { if (asprintf (&uri, "fd://%s", p_access->psz_location) == -1) uri = NULL; } else uri = make_URI (p_access->psz_filepath, "file"); if (unlikely(uri == NULL)) goto error; p_access->p_sys = p_sys; p_sys->current = NULL; p_sys->handle = handle; p_sys->uri = uri; p_sys->ignored_exts = var_InheritString (p_access, "ignore-filetypes"); p_sys->i_item_count = 0; p_sys->psz_xspf_extension = strdup( "" ); /* Handle mode */ char *psz = var_InheritString (p_access, "recursive"); if (psz == NULL || !strcasecmp (psz, "none")) p_sys->mode = MODE_NONE; else if( !strcasecmp( psz, "collapse" ) ) p_sys->mode = MODE_COLLAPSE; else p_sys->mode = MODE_EXPAND; free( psz ); access_InitFields(p_access); p_access->pf_read = NULL; p_access->pf_block = DirBlock; p_access->pf_seek = NULL; p_access->pf_control= DirControl; free (p_access->psz_demux); p_access->psz_demux = strdup ("xspf-open"); return VLC_SUCCESS; error: closedir (handle); free (p_sys); return VLC_EGENERIC; }
libvlc_media_t *libvlc_media_new_path( libvlc_instance_t *p_instance, const char *path ) { char *mrl = make_URI( path, "file" ); if( unlikely(mrl == NULL) ) { libvlc_printerr( "Not enough memory" ); return NULL; } libvlc_media_t *m = libvlc_media_new_location( p_instance, mrl ); free( mrl ); return m; }
/* copied from video_filters/erase.c . Gruik ? */ static void LoadMask( filter_t *p_filter, const char *psz_filename ) { image_handler_t *p_image; video_format_t fmt_in, fmt_out; memset( &fmt_in, 0, sizeof( video_format_t ) ); memset( &fmt_out, 0, sizeof( video_format_t ) ); fmt_out.i_chroma = VLC_CODEC_YUVA; if( p_filter->p_sys->p_mask ) picture_Release( p_filter->p_sys->p_mask ); p_image = image_HandlerCreate( p_filter ); char *psz_url = make_URI( psz_filename, NULL ); p_filter->p_sys->p_mask = image_ReadUrl( p_image, psz_url, &fmt_in, &fmt_out ); free( psz_url ); image_HandlerDelete( p_image ); }
int playlist_Import( playlist_t *p_playlist, const char *psz_file ) { input_item_t *p_input; const char *const psz_option = "meta-file"; char *psz_uri = make_URI( psz_file, NULL ); if( psz_uri == NULL ) return VLC_EGENERIC; p_input = input_item_NewExt( psz_uri, psz_file, 1, &psz_option, VLC_INPUT_OPTION_TRUSTED, -1 ); free( psz_uri ); playlist_AddInput( p_playlist, p_input, PLAYLIST_APPEND, PLAYLIST_END, true, false ); return input_Read( p_playlist, p_input ); }
/***************************************************************************** * Run: *****************************************************************************/ static void *Run( void *data ) { services_discovery_t *p_sd = data; services_discovery_sys_t *p_sys = p_sd->p_sys; int canc = vlc_savecancel(); int num_dir = sizeof( p_sys->psz_dir ) / sizeof( p_sys->psz_dir[0] ); for( int i = 0; i < num_dir; i++ ) { char* psz_dir = p_sys->psz_dir[i]; /* make sure the directory exists */ struct stat st; if( psz_dir == NULL || vlc_stat( psz_dir, &st ) || !S_ISDIR( st.st_mode ) ) continue; char* psz_uri = make_URI( psz_dir, "file" ); input_item_t* p_root = input_item_New( psz_uri, NULL ); if( p_sys->i_type == Picture ) input_item_AddOption( p_root, "ignore-filetypes=ini,db,lnk,txt", VLC_INPUT_OPTION_TRUSTED ); input_item_AddOption( p_root, "recursive=collapse", VLC_INPUT_OPTION_TRUSTED ); vlc_event_manager_t *p_em = &p_root->event_manager; vlc_event_attach( p_em, vlc_InputItemSubItemAdded, input_item_subitem_added, p_sd ); input_Read( p_sd, p_root ); vlc_event_detach( p_em, vlc_InputItemSubItemAdded, input_item_subitem_added, p_sd ); vlc_gc_decref( p_root ); free( psz_uri ); } vlc_restorecancel(canc); return NULL; }
int playlist_FindArtInCache( input_item_t *p_item ) { char *psz_path = ArtCachePath( p_item ); if( !psz_path ) return VLC_EGENERIC; /* Check if file exists */ DIR *p_dir = utf8_opendir( psz_path ); if( !p_dir ) { free( psz_path ); return VLC_EGENERIC; } bool b_found = false; char *psz_filename; while( !b_found && (psz_filename = utf8_readdir( p_dir )) ) { if( !strncmp( psz_filename, "art", 3 ) ) { char *psz_file; if( asprintf( &psz_file, "%s" DIR_SEP "%s", psz_path, psz_filename ) != -1 ) { char *psz_uri = make_URI( psz_file ); if( psz_uri ) { input_item_SetArtURL( p_item, psz_uri ); free( psz_uri ); } free( psz_file ); } b_found = true; } free( psz_filename ); } /* */ closedir( p_dir ); free( psz_path ); return b_found ? VLC_SUCCESS : VLC_EGENERIC; }
int playlist_SaveArt( playlist_t *p_playlist, input_item_t *p_item, const uint8_t *p_buffer, int i_buffer, const char *psz_type ) { char *psz_filename = ArtCacheName( p_item, psz_type ); if( !psz_filename ) return VLC_EGENERIC; char *psz_uri = make_URI( psz_filename ); if( !psz_uri ) { free( psz_filename ); return VLC_EGENERIC; } /* Check if we already dumped it */ struct stat s; if( !utf8_stat( psz_filename, &s ) ) { input_item_SetArtURL( p_item, psz_uri ); free( psz_filename ); free( psz_uri ); return VLC_SUCCESS; } /* Dump it otherwise */ FILE *f = utf8_fopen( psz_filename, "wb" ); if( f ) { if( fwrite( p_buffer, i_buffer, 1, f ) != 1 ) { msg_Err( p_playlist, "%s: %m", psz_filename ); } else { msg_Dbg( p_playlist, "album art saved to %s", psz_filename ); input_item_SetArtURL( p_item, psz_uri ); } fclose( f ); } free( psz_filename ); free( psz_uri ); return VLC_SUCCESS; }
/** * It loads the logo image into memory. */ static picture_t *LoadImage( vlc_object_t *p_this, const char *psz_filename ) { if( !psz_filename ) return NULL; video_format_t fmt_in; video_format_Init( &fmt_in, 0 ); video_format_t fmt_out; video_format_Init( &fmt_out, VLC_CODEC_YUVA ); image_handler_t *p_image = image_HandlerCreate( p_this ); if( !p_image ) return NULL; char *psz_url = make_URI( psz_filename, NULL ); picture_t *p_pic = image_ReadUrl( p_image, psz_url, &fmt_in, &fmt_out ); free( psz_url ); image_HandlerDelete( p_image ); return p_pic; }
/** * Add the directory part of the playlist file to the start of the * mrl, if the mrl is a relative file path */ char *ProcessMRL( const char *psz_mrl, const char *psz_prefix ) { /* Check for a protocol name. * for URL, we should look for "://" * for MRL (Media Resource Locator) ([[<access>][/<demux>]:][<source>]), * we should look for ":", so we end up looking simply for ":" * PB: on some file systems, ':' are valid characters though */ /* Simple cases first */ if( !psz_mrl || !*psz_mrl ) return NULL; if( !psz_prefix || !*psz_prefix ) goto uri; /* Check if the line specifies an absolute path */ /* FIXME: that's wrong if the playlist is not a local file */ if( *psz_mrl == DIR_SEP_CHAR ) goto uri; #ifdef WIN32 /* Drive letter (this assumes URL scheme are not a single character) */ if( isalpha(psz_mrl[0]) && psz_mrl[1] == ':' ) goto uri; #endif if( strstr( psz_mrl, "://" ) ) return strdup( psz_mrl ); /* This a relative path, prepend the prefix */ char *ret; char *postfix = encode_URI_component( psz_mrl ); /* FIXME: postfix may not be encoded correctly (esp. slashes) */ if( postfix == NULL || asprintf( &ret, "%s%s", psz_prefix, postfix ) == -1 ) ret = NULL; free( postfix ); return ret; uri: return make_URI( psz_mrl, NULL ); }
int playlist_SaveArt( playlist_t *p_playlist, input_item_t *p_item, const uint8_t *p_buffer, int i_buffer, const char *psz_type ) { char *psz_filename = ArtCacheName( p_item, psz_type ); if( !psz_filename ) return VLC_EGENERIC; char *psz_uri = make_URI( psz_filename, "file" ); if( !psz_uri ) { free( psz_filename ); return VLC_EGENERIC; } /* Check if we already dumped it */ struct stat s; if( !vlc_stat( psz_filename, &s ) ) { input_item_SetArtURL( p_item, psz_uri ); free( psz_filename ); free( psz_uri ); return VLC_SUCCESS; } /* Dump it otherwise */ FILE *f = vlc_fopen( psz_filename, "wb" ); if( f ) { if( fwrite( p_buffer, i_buffer, 1, f ) != 1 ) { msg_Err( p_playlist, "%s: %m", psz_filename ); } else { msg_Dbg( p_playlist, "album art saved to %s", psz_filename ); input_item_SetArtURL( p_item, psz_uri ); } fclose( f ); } free( psz_uri ); /* save uid info */ char *uid = input_item_GetInfo( p_item, "uid", "md5" ); if ( ! *uid ) { free( uid ); goto end; } char *psz_byuiddir = GetDirByItemUIDs( uid ); char *psz_byuidfile = GetFileByItemUID( psz_byuiddir, "arturl" ); ArtCacheCreateDir( psz_byuiddir ); free( psz_byuiddir ); if ( psz_byuidfile ) { f = vlc_fopen( psz_byuidfile, "wb" ); if ( f ) { if( fputs( "file://", f ) < 0 || fputs( psz_filename, f ) < 0 ) msg_Err( p_playlist, "Error writing %s: %m", psz_byuidfile ); fclose( f ); } free( psz_byuidfile ); } free( uid ); /* !save uid info */ end: free( psz_filename ); return VLC_SUCCESS; }
int playlist_MLLoad( playlist_t *p_playlist ) { char *psz_datadir; char *psz_uri = NULL; input_item_t *p_input; if( !config_GetInt( p_playlist, "media-library") ) return VLC_SUCCESS; psz_datadir = config_GetUserDir( VLC_DATA_DIR ); if( !psz_datadir ) /* XXX: This should never happen */ { msg_Err( p_playlist, "no data directory, cannot load media library") ; return VLC_EGENERIC; } if( asprintf( &psz_uri, "%s" DIR_SEP "ml.xspf", psz_datadir ) != -1 ) { /* loosy check for media library file */ struct stat st; int ret = utf8_stat( psz_uri , &st ); free( psz_uri ); if( ret ) { free( psz_datadir ); return VLC_EGENERIC; } } psz_uri = make_URI( psz_datadir ); free( psz_datadir ); psz_datadir = psz_uri; if( psz_datadir == NULL ) return VLC_EGENERIC; /* Force XSPF demux (psz_datadir was a path, now it is a file URI) */ if( asprintf( &psz_uri, "file/xspf-open%s/ml.xspf", psz_datadir+4 ) == -1 ) psz_uri = NULL; free( psz_datadir ); psz_datadir = NULL; if( psz_uri == NULL ) return VLC_ENOMEM; const char *const options[1] = { "meta-file", }; /* that option has to be cleaned in input_item_subitem_added() */ /* vlc_gc_decref() in the same function */ p_input = input_item_NewExt( p_playlist, psz_uri, _("Media Library"), 1, options, VLC_INPUT_OPTION_TRUSTED, -1 ); free( psz_uri ); if( p_input == NULL ) return VLC_EGENERIC; PL_LOCK; if( p_playlist->p_ml_onelevel->p_input ) vlc_gc_decref( p_playlist->p_ml_onelevel->p_input ); if( p_playlist->p_ml_category->p_input ) vlc_gc_decref( p_playlist->p_ml_category->p_input ); p_playlist->p_ml_onelevel->p_input = p_playlist->p_ml_category->p_input = p_input; /* We save the input at two different place, incref */ vlc_gc_incref( p_input ); vlc_gc_incref( p_input ); vlc_event_attach( &p_input->event_manager, vlc_InputItemSubItemAdded, input_item_subitem_added, p_playlist ); pl_priv(p_playlist)->b_doing_ml = true; PL_UNLOCK; stats_TimerStart( p_playlist, "ML Load", STATS_TIMER_ML_LOAD ); input_Read( p_playlist, p_input ); stats_TimerStop( p_playlist,STATS_TIMER_ML_LOAD ); PL_LOCK; pl_priv(p_playlist)->b_doing_ml = false; PL_UNLOCK; vlc_event_detach( &p_input->event_manager, vlc_InputItemSubItemAdded, input_item_subitem_added, p_playlist ); vlc_gc_decref( p_input ); return VLC_SUCCESS; }
int playlist_MLLoad( playlist_t *p_playlist ) { input_item_t *p_input; char *psz_datadir = config_GetUserDir( VLC_DATA_DIR ); if( !psz_datadir ) /* XXX: This should never happen */ { msg_Err( p_playlist, "no data directory, cannot load media library") ; return VLC_EGENERIC; } char *psz_file; if( asprintf( &psz_file, "%s" DIR_SEP "ml.xspf", psz_datadir ) == -1 ) psz_file = NULL; free( psz_datadir ); if( psz_file == NULL ) return VLC_ENOMEM; /* loosy check for media library file */ struct stat st; if( vlc_stat( psz_file, &st ) ) { free( psz_file ); return VLC_EGENERIC; } char *psz_uri = make_URI( psz_file, "file/xspf-open" ); free( psz_file ); if( psz_uri == NULL ) return VLC_ENOMEM; const char *const options[1] = { "meta-file", }; /* that option has to be cleaned in input_item_subitem_tree_added() */ /* vlc_gc_decref() in the same function */ p_input = input_item_NewExt( psz_uri, _("Media Library"), 1, options, VLC_INPUT_OPTION_TRUSTED, -1 ); free( psz_uri ); if( p_input == NULL ) return VLC_EGENERIC; PL_LOCK; if( p_playlist->p_media_library->p_input ) vlc_gc_decref( p_playlist->p_media_library->p_input ); p_playlist->p_media_library->p_input = p_input; vlc_event_attach( &p_input->event_manager, vlc_InputItemSubItemTreeAdded, input_item_subitem_tree_added, p_playlist ); pl_priv(p_playlist)->b_doing_ml = true; PL_UNLOCK; stats_TimerStart( p_playlist, "ML Load", STATS_TIMER_ML_LOAD ); input_Read( p_playlist, p_input ); stats_TimerStop( p_playlist,STATS_TIMER_ML_LOAD ); PL_LOCK; pl_priv(p_playlist)->b_doing_ml = false; PL_UNLOCK; vlc_event_detach( &p_input->event_manager, vlc_InputItemSubItemTreeAdded, input_item_subitem_tree_added, p_playlist ); return VLC_SUCCESS; }
/** * Initialize a libvlc instance * This function initializes a previously allocated libvlc instance: * - CPU detection * - gettext initialization * - message queue, module bank and playlist initialization * - configuration and commandline parsing */ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, const char *ppsz_argv[] ) { libvlc_priv_t *priv = libvlc_priv (p_libvlc); char * psz_modules = NULL; char * psz_parser = NULL; char * psz_control = NULL; playlist_t *p_playlist = NULL; char *psz_val; /* System specific initialization code */ system_Init(); /* Initialize the module bank and load the configuration of the * main module. We need to do this at this stage to be able to display * a short help if required by the user. (short help == main module * options) */ module_InitBank (); /* Get command line options that affect module loading. */ if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, NULL ) ) { module_EndBank (false); return VLC_EGENERIC; } priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" ); /* Announce who we are (TODO: only first instance?) */ msg_Dbg( p_libvlc, "VLC media player - %s", VERSION_MESSAGE ); msg_Dbg( p_libvlc, "%s", COPYRIGHT_MESSAGE ); msg_Dbg( p_libvlc, "revision %s", psz_vlc_changeset ); msg_Dbg( p_libvlc, "configured with %s", CONFIGURE_LINE ); /* Load the builtins and plugins into the module_bank. * We have to do it before config_Load*() because this also gets the * list of configuration options exported by each module and loads their * default values. */ size_t module_count = module_LoadPlugins (p_libvlc); /* * Override default configuration with config file settings */ if( !var_InheritBool( p_libvlc, "ignore-config" ) ) { if( var_InheritBool( p_libvlc, "reset-config" ) ) config_SaveConfigFile( p_libvlc ); /* Save default config */ else config_LoadConfigFile( p_libvlc ); } /* * Override configuration with command line settings */ int vlc_optind; if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) ) { #ifdef WIN32 MessageBox (NULL, TEXT("The command line options could not be parsed.\n" "Make sure they are valid."), TEXT("VLC media player"), MB_OK|MB_ICONERROR); #endif module_EndBank (true); return VLC_EGENERIC; } priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" ); /* * Support for gettext */ #if defined( ENABLE_NLS ) \ && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) ) vlc_bindtextdomain (PACKAGE_NAME); #endif /*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */ msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") ); if (config_PrintHelp (VLC_OBJECT(p_libvlc))) { module_EndBank (true); return VLC_EEXITSUCCESS; } if( module_count <= 1 ) { msg_Err( p_libvlc, "No plugins found! Check your VLC installation."); module_EndBank (true); return VLC_ENOITEM; } #ifdef HAVE_DAEMON /* 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" ); module_EndBank (true); return VLC_EEXIT; } b_daemon = true; /* lets check if we need to write the pidfile */ psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" ); if( psz_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 ) { utf8_fprintf( pidfile, "%d", (int)i_pid ); fclose( pidfile ); } else { msg_Err( p_libvlc, "cannot open pid file for writing: %s (%m)", psz_pidfile ); } } free( psz_pidfile ); } #endif /* FIXME: could be replaced by using Unix sockets */ #ifdef HAVE_DBUS #define MPRIS_APPEND "/org/mpris/MediaPlayer2/TrackList/Append" #define MPRIS_BUS_NAME "org.mpris.MediaPlayer2.vlc" #define MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2" #define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList" dbus_threads_init_default(); if( var_InheritBool( p_libvlc, "one-instance" ) || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" ) && var_InheritBool( p_libvlc, "started-from-file" ) ) ) { /* Initialise D-Bus interface, check for other instances */ DBusConnection *p_conn = NULL; DBusError dbus_error; dbus_error_init( &dbus_error ); /* connect to the session bus */ p_conn = dbus_bus_get( DBUS_BUS_SESSION, &dbus_error ); if( !p_conn ) { msg_Err( p_libvlc, "Failed to connect to D-Bus session daemon: %s", dbus_error.message ); dbus_error_free( &dbus_error ); } else { /* check if VLC is available on the bus * if not: D-Bus control is not enabled on the other * instance and we can't pass MRLs to it */ if( !dbus_bus_name_has_owner( p_conn, MPRIS_BUS_NAME, &dbus_error ) ) { if( dbus_error_is_set( &dbus_error ) ) { msg_Err( p_libvlc, "D-Bus error: %s", dbus_error.message ); dbus_error_free( &dbus_error ); } else msg_Dbg( p_libvlc, "No Media Player is running. " "Continuing normally." ); } else { int i_input; DBusMessage* p_dbus_msg = NULL; DBusMessageIter dbus_args; DBusPendingCall* p_dbus_pending = NULL; dbus_bool_t b_play; msg_Warn( p_libvlc, "Another Media Player is running. Exiting"); for( i_input = vlc_optind; i_input < i_argc;i_input++ ) { /* Skip input options, we can't pass them through D-Bus */ if( ppsz_argv[i_input][0] == ':' ) { msg_Warn( p_libvlc, "Ignoring option %s", ppsz_argv[i_input] ); continue; } /* We need to resolve relative paths in this instance */ char *psz_mrl = make_URI( ppsz_argv[i_input], NULL ); const char *psz_after_track = MPRIS_APPEND; if( psz_mrl == NULL ) continue; msg_Dbg( p_libvlc, "Adds %s to the running Media Player", psz_mrl ); p_dbus_msg = dbus_message_new_method_call( MPRIS_BUS_NAME, MPRIS_OBJECT_PATH, MPRIS_TRACKLIST_INTERFACE, "AddTrack" ); if ( NULL == p_dbus_msg ) { msg_Err( p_libvlc, "D-Bus problem" ); free( psz_mrl ); system_End( ); exit( 1 ); } /* append MRLs */ dbus_message_iter_init_append( p_dbus_msg, &dbus_args ); if ( !dbus_message_iter_append_basic( &dbus_args, DBUS_TYPE_STRING, &psz_mrl ) ) { dbus_message_unref( p_dbus_msg ); free( psz_mrl ); system_End( ); exit( 1 ); } free( psz_mrl ); if( !dbus_message_iter_append_basic( &dbus_args, DBUS_TYPE_OBJECT_PATH, &psz_after_track ) ) { dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } b_play = TRUE; if( var_InheritBool( p_libvlc, "playlist-enqueue" ) ) b_play = FALSE; if ( !dbus_message_iter_append_basic( &dbus_args, DBUS_TYPE_BOOLEAN, &b_play ) ) { dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } /* send message and get a handle for a reply */ if ( !dbus_connection_send_with_reply ( p_conn, p_dbus_msg, &p_dbus_pending, -1 ) ) { msg_Err( p_libvlc, "D-Bus problem" ); dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } if ( NULL == p_dbus_pending ) { msg_Err( p_libvlc, "D-Bus problem" ); dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } dbus_connection_flush( p_conn ); dbus_message_unref( p_dbus_msg ); /* block until we receive a reply */ dbus_pending_call_block( p_dbus_pending ); dbus_pending_call_unref( p_dbus_pending ); } /* processes all command line MRLs */ /* bye bye */ system_End( ); exit( 0 ); } } /* we unreference the connection when we've finished with it */ if( p_conn ) dbus_connection_unref( p_conn ); } #undef MPRIS_APPEND #undef MPRIS_BUS_NAME #undef MPRIS_OBJECT_PATH #undef MPRIS_TRACKLIST_INTERFACE #endif // HAVE_DBUS /* * Message queue options */ /* Last chance to set the verbosity. Once we start interfaces and other * threads, verbosity becomes read-only. */ var_Create( p_libvlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); if( var_InheritBool( p_libvlc, "quiet" ) ) { var_SetInteger( p_libvlc, "verbose", -1 ); priv->i_verbose = -1; } vlc_threads_setup( p_libvlc ); if( priv->b_color ) priv->b_color = var_InheritBool( p_libvlc, "color" ); vlc_CPU_dump( VLC_OBJECT(p_libvlc) ); /* * Choose the best memcpy module */ priv->p_memcpy_module = module_need( p_libvlc, "memcpy", "$memcpy", false ); /* Avoid being called "memcpy":*/ vlc_object_set_name( p_libvlc, "main" ); priv->b_stats = var_InheritBool( p_libvlc, "stats" ); /* * Initialize hotkey handling */ priv->actions = vlc_InitActions( 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 ); /* Create a variable for the Boss Key */ var_Create( p_libvlc, "intf-boss", VLC_VAR_VOID ); /* Create a variable for showing the main interface */ var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL ); /* Create a variable for showing the right click menu */ var_Create( p_libvlc, "intf-popupmenu", VLC_VAR_BOOL ); /* variables for signalling creation of new files */ var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING ); var_Create( p_libvlc, "record-file", VLC_VAR_STRING ); /* some default internal settings */ var_Create( p_libvlc, "window", VLC_VAR_STRING ); var_Create( p_libvlc, "user-agent", VLC_VAR_STRING ); var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" ); /* Initialize playlist and get commandline files */ p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) ); if( !p_playlist ) { msg_Err( p_libvlc, "playlist initialization failed" ); if( priv->p_memcpy_module != NULL ) { module_unneed( p_libvlc, priv->p_memcpy_module ); } module_EndBank (true); return VLC_EGENERIC; } /* System specific configuration */ system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); #if defined(MEDIA_LIBRARY) /* Get the ML */ if( var_GetBool( p_libvlc, "load-media-library-on-startup" ) ) { priv->p_ml = ml_Create( VLC_OBJECT( p_libvlc ), NULL ); if( !priv->p_ml ) { msg_Err( p_libvlc, "ML initialization failed" ); return VLC_EGENERIC; } } else { priv->p_ml = NULL; } #endif /* Add service discovery modules */ psz_modules = var_InheritString( p_libvlc, "services-discovery" ); if( psz_modules ) { char *p = psz_modules, *m; while( ( m = strsep( &p, " :," ) ) != NULL ) playlist_ServicesDiscoveryAdd( p_playlist, m ); free( psz_modules ); } #ifdef ENABLE_VLM /* Initialize VLM if vlm-conf is specified */ psz_parser = var_CreateGetNonEmptyString( p_libvlc, "vlm-conf" ); if( psz_parser ) { priv->p_vlm = vlm_New( p_libvlc ); if( !priv->p_vlm ) msg_Err( p_libvlc, "VLM initialization failed" ); } free( psz_parser ); #endif /* * Load background interfaces */ psz_modules = var_CreateGetNonEmptyString( p_libvlc, "extraintf" ); psz_control = var_CreateGetNonEmptyString( p_libvlc, "control" ); if( psz_modules && psz_control ) { char* psz_tmp; if( asprintf( &psz_tmp, "%s:%s", psz_modules, psz_control ) != -1 ) { free( psz_modules ); psz_modules = psz_tmp; } } else if( psz_control ) { free( psz_modules ); psz_modules = strdup( psz_control ); } psz_parser = psz_modules; while ( psz_parser && *psz_parser ) { char *psz_module, *psz_temp; psz_module = psz_parser; psz_parser = strchr( psz_module, ':' ); if ( psz_parser ) { *psz_parser = '\0'; psz_parser++; } if( asprintf( &psz_temp, "%s,none", psz_module ) != -1) { intf_Create( p_libvlc, psz_temp ); free( psz_temp ); } } free( psz_modules ); free( psz_control ); /* * Always load the hotkeys interface if it exists */ intf_Create( p_libvlc, "hotkeys,none" ); 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" ); if( logmode ) { var_SetString( p_libvlc, "logmode", logmode ); free( logmode ); } var_Destroy( p_libvlc, "logmode" ); } #endif if( var_InheritBool( p_libvlc, "network-synchronisation") ) { intf_Create( p_libvlc, "netsync,none" ); } #ifdef __APPLE__ var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-nsobject", VLC_VAR_ADDRESS ); #endif #if defined (WIN32) || defined (__OS2__) var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_INTEGER ); #endif /* * Get input filenames given as commandline arguments. * We assume that the remaining parameters are filenames * and their input options. */ GetFilenames( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); /* * Get --open argument */ psz_val = var_InheritString( p_libvlc, "open" ); if ( psz_val != NULL ) { playlist_AddExt( p_playlist, psz_val, NULL, PLAYLIST_INSERT, 0, -1, 0, NULL, 0, true, pl_Unlocked ); free( psz_val ); } return VLC_SUCCESS; }
static int FindMeta( vlc_object_t *p_this ) { art_finder_t *p_finder = (art_finder_t *)p_this; input_item_t *p_item = p_finder->p_item; bool b_have_art = false; if( !p_item ) return VLC_EGENERIC; char *psz_dir = input_item_GetURI( p_item ); if( !psz_dir ) return VLC_EGENERIC; char *psz_path = make_path( psz_dir ); free( psz_dir ); if( psz_path == NULL ) return VLC_EGENERIC; char *psz_buf = strrchr( psz_path, DIR_SEP_CHAR ); if( psz_buf ) *++psz_buf = '\0'; else *psz_path = '\0'; /* relative path */ for( int i = -1; !b_have_art && i < i_covers; i++ ) { const char *filename; char *filebuf, *filepath; if( i == -1 ) /* higher priority : configured filename */ { filebuf = var_InheritString( p_this, "album-art-filename" ); if( filebuf == NULL ) continue; filename = filebuf; } else { filename = cover_files[i]; filebuf = NULL; } if( asprintf( &filepath, "%s%s", psz_path, filename ) == -1 ) filepath = NULL; free( filebuf ); if( unlikely(filepath != NULL) ) continue; struct stat dummy; if( vlc_stat( filepath, &dummy ) == 0 ) { char *psz_uri = make_URI( filepath, "file" ); if( psz_uri ) { input_item_SetArtURL( p_item, psz_uri ); free( psz_uri ); b_have_art = true; } } free( filepath ); } free( psz_path ); return b_have_art ? VLC_SUCCESS : VLC_EGENERIC; }