/*****************************************************************************
* 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>
#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h> /* isatty() */
+#endif
#ifdef HAVE_DBUS
/* used for one-instance mode */
#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"
* The evil global variables. We handle them with care, don't worry.
*****************************************************************************/
-#ifndef WIN32
+#if !defined(WIN32) && !defined(__OS2__)
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
*****************************************************************************/
/* Initialize mutexes */
vlc_mutex_init( &priv->ml_lock );
- vlc_mutex_init( &priv->timer_lock );
vlc_ExitInit( &priv->exit );
return p_libvlc;
/* 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 = "/";
+ 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
/* 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 );
*/
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" );
-#ifndef WIN32
+#if !defined( WIN32 ) && !defined( __OS2__ )
char* psz_pidfile = NULL;
if( b_daemon )
/* 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 */
char *psz_interface = var_CreateGetNonEmptyString( p_libvlc, "intf" );
if( !psz_interface ) /* "intf" has not been set */
{
-#ifndef WIN32
+#if !defined( WIN32 ) && !defined( __OS2__ )
if( b_daemon )
/* Daemon mode hack.
* We prefer the dummy interface if none is specified. */