/*****************************************************************************
* libvlc.c: libvlc instances creation and deletion, interfaces handling
*****************************************************************************
- * Copyright (C) 1998-2008 the VideoLAN team
+ * Copyright (C) 1998-2008 VLC authors and VideoLAN
* $Id$
*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
* Derk-Jan Hartman <hartman at videolan dot org>
* RĂ©mi Denis-Courmont <rem # videolan : org>
*
- * 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.
*****************************************************************************/
/** \file
#include <string.h>
#include <stdlib.h> /* free() */
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#elif defined( WIN32 ) && !defined( UNDER_CE )
-# include <io.h>
-#endif
-
#include "config/vlc_getopt.h"
-#ifdef HAVE_LOCALE_H
-# include <locale.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h> /* isatty() */
#endif
#ifdef HAVE_DBUS
#include <vlc_playlist.h>
#include <vlc_interface.h>
-#include <vlc_aout.h>
-#include "audio_output/aout_internal.h"
-
#include <vlc_charset.h>
#include <vlc_fs.h>
#include <vlc_cpu.h>
#include <vlc_url.h>
-#include <vlc_atomic.h>
#include <vlc_modules.h>
#include "libvlc.h"
static bool b_daemon = false;
#endif
-#undef vlc_gc_init
-#undef vlc_hold
-#undef vlc_release
-
-/**
- * Atomically set the reference count to 1.
- * @param p_gc reference counted object
- * @param pf_destruct destruction calback
- * @return p_gc.
- */
-void *vlc_gc_init (gc_object_t *p_gc, void (*pf_destruct) (gc_object_t *))
-{
- /* There is no point in using the GC if there is no destructor... */
- assert (pf_destruct);
- p_gc->pf_destructor = pf_destruct;
-
- vlc_atomic_set (&p_gc->refs, 1);
- return p_gc;
-}
-
-/**
- * Atomically increment the reference count.
- * @param p_gc reference counted object
- * @return p_gc.
- */
-void *vlc_hold (gc_object_t * p_gc)
-{
- uintptr_t refs;
-
- assert( p_gc );
- refs = vlc_atomic_inc (&p_gc->refs);
- assert (refs != 1); /* there had to be a reference already */
- return p_gc;
-}
-
-/**
- * Atomically decrement the reference count and, if it reaches zero, destroy.
- * @param p_gc reference counted object.
- */
-void vlc_release (gc_object_t *p_gc)
-{
- uintptr_t refs;
-
- assert( p_gc );
- refs = vlc_atomic_dec (&p_gc->refs);
- assert (refs != (uintptr_t)(-1)); /* reference underflow?! */
- if (refs == 0)
- p_gc->pf_destructor (p_gc);
-}
-
/*****************************************************************************
* Local prototypes
*****************************************************************************/
-#if defined( ENABLE_NLS ) && (defined (__APPLE__) || defined (WIN32)) && \
- ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
-static void SetLanguage ( char const * );
-#endif
static void GetFilenames ( libvlc_int_t *, unsigned, const char *const [] );
/**
/* Initialize mutexes */
vlc_mutex_init( &priv->ml_lock );
- vlc_mutex_init( &priv->timer_lock );
vlc_ExitInit( &priv->exit );
return p_libvlc;
*/
#if defined( ENABLE_NLS ) \
&& ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
-# if defined (WIN32) || defined (__APPLE__)
- /* Check if the user specified a custom language */
- char *lang = var_InheritString (p_libvlc, "language");
- if (lang != NULL && strcmp (lang, "auto"))
- SetLanguage (lang);
- free (lang);
-# endif
vlc_bindtextdomain (PACKAGE_NAME);
#endif
/*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
/* 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" )
/* 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 */
- DBusMessage *p_test_msg = NULL;
- DBusMessage *p_test_reply = NULL;
-
- p_test_msg = dbus_message_new_method_call(
- "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2",
- "org.freedesktop.DBus.Introspectable", "Introspect" );
-
- /* block until a reply arrives */
- p_test_reply = dbus_connection_send_with_reply_and_block(
- p_conn, p_test_msg, -1, &dbus_error );
- dbus_message_unref( p_test_msg );
- if( p_test_reply == NULL )
+ if( !dbus_bus_name_has_owner( p_conn, MPRIS_BUS_NAME, &dbus_error ) )
{
- dbus_error_free( &dbus_error );
- msg_Dbg( p_libvlc, "No Media Player is running. "
- "Continuing normally." );
+ 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
{
DBusPendingCall* p_dbus_pending = NULL;
dbus_bool_t b_play;
- dbus_message_unref( p_test_reply );
msg_Warn( p_libvlc, "Another Media Player is running. Exiting");
for( i_input = vlc_optind; i_input < i_argc;i_input++ )
}
/* We need to resolve relative paths in this instance */
- char *psz_mrl = make_URI( ppsz_argv[i_input], NULL );
- const char *psz_after_track = "/";
+ char *psz_mrl;
+ if( strstr( psz_mrl, "://" ) )
+ psz_mrl = strdup( ppsz_argv[i_input] );
+ else
+ psz_mrl = vlc_path2uri( ppsz_argv[i_input], NULL );
+ const char *psz_after_track = MPRIS_APPEND;
if( psz_mrl == NULL )
continue;
psz_mrl );
p_dbus_msg = dbus_message_new_method_call(
- "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2",
- "org.mpris.MediaPlayer2.TrackList", "AddTrack" );
+ MPRIS_BUS_NAME, MPRIS_OBJECT_PATH,
+ MPRIS_TRACKLIST_INTERFACE, "AddTrack" );
if ( NULL == p_dbus_msg )
{
/* we unreference the connection when we've finished with it */
if( p_conn ) dbus_connection_unref( p_conn );
}
-#endif
+
+#undef MPRIS_APPEND
+#undef MPRIS_BUS_NAME
+#undef MPRIS_OBJECT_PATH
+#undef MPRIS_TRACKLIST_INTERFACE
+
+#endif // HAVE_DBUS
/*
* Message queue options
vlc_object_set_name( p_libvlc, "main" );
priv->b_stats = var_InheritBool( p_libvlc, "stats" );
- priv->i_timers = 0;
- priv->pp_timers = NULL;
/*
* Initialize hotkey handling
*/
intf_Create( p_libvlc, "hotkeys,none" );
-#ifdef HAVE_DBUS
- /* loads dbus control interface if in one-instance mode
- * we do it only when playlist exists, because dbus module needs it */
- if( var_InheritBool( p_libvlc, "one-instance" )
- || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" )
- && var_InheritBool( p_libvlc, "started-from-file" ) ) )
- intf_Create( p_libvlc, "dbus,none" );
-
-# if !defined (HAVE_MAEMO)
- /* Prevents the power management daemon from suspending the system
- * when VLC is active */
- if( var_InheritBool( p_libvlc, "inhibit" ) > 0 )
- intf_Create( p_libvlc, "inhibit,none" );
-# endif
+ if( var_InheritBool( p_libvlc, "file-logging" )
+#ifdef HAVE_SYSLOG_H
+ && !var_InheritBool( p_libvlc, "syslog" )
#endif
-
- if( var_InheritBool( p_libvlc, "file-logging" ) &&
- !var_InheritBool( p_libvlc, "syslog" ) )
+ )
{
intf_Create( p_libvlc, "logger,none" );
}
var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
var_Create( p_libvlc, "drawable-nsobject", VLC_VAR_ADDRESS );
#endif
-#ifdef WIN32
+#if defined (WIN32) || defined (__OS2__)
var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_INTEGER );
#endif
/* Free playlist now, all threads are gone */
playlist_Destroy( p_playlist );
- stats_TimersDumpAll( p_libvlc );
- stats_TimersCleanAll( p_libvlc );
msg_Dbg( p_libvlc, "removing stats" );
/* Destroy mutexes */
vlc_ExitDestroy( &priv->exit );
- vlc_mutex_destroy( &priv->timer_lock );
vlc_mutex_destroy( &priv->ml_lock );
#ifndef NDEBUG /* Hack to dump leaked objects tree */
return ret;
}
-#if defined( ENABLE_NLS ) && (defined (__APPLE__) || defined (WIN32)) && \
- ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
-/*****************************************************************************
- * SetLanguage: set the interface language.
- *****************************************************************************
- * We set the LC_MESSAGES locale category for interface messages and buttons,
- * as well as the LC_CTYPE category for string sorting and possible wide
- * character support.
- *****************************************************************************/
-static void SetLanguage ( const char *psz_lang )
-{
-#ifdef __APPLE__
- /* I need that under Darwin, please check it doesn't disturb
- * other platforms. --Meuuh */
- setenv( "LANG", psz_lang, 1 );
-
-#else
- /* We set LC_ALL manually because it is the only way to set
- * the language at runtime under eg. Windows. Beware that this
- * makes the environment unconsistent when libvlc is unloaded and
- * should probably be moved to a safer place like vlc.c. */
- setenv( "LC_ALL", psz_lang, 1 );
-
-#endif
-
- setlocale( LC_ALL, psz_lang );
-}
-#endif
-
/*****************************************************************************
* GetFilenames: parse command line options which are not flags
*****************************************************************************
}
}
- char *mrl = make_URI( args[n], NULL );
- if( !mrl )
- continue;
+ char *mrl = NULL;
+ if( strstr( args[n], "://" ) == NULL )
+ {
+ mrl = vlc_path2uri( 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 );
+ playlist_AddExt( pl_Get( p_vlc ), (mrl != NULL) ? mrl : args[n], NULL,
+ PLAYLIST_INSERT, 0, -1, i_options,
+ ( i_options ? &args[n + 1] : NULL ),
+ VLC_INPUT_OPTION_TRUSTED, true, pl_Unlocked );
free( mrl );
}
}