| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
#ifdef HAVE_CONFIG_H |
|---|
| 36 |
# include "config.h" |
|---|
| 37 |
#endif |
|---|
| 38 |
|
|---|
| 39 |
#include <vlc_common.h> |
|---|
| 40 |
#include "control/libvlc_internal.h" |
|---|
| 41 |
#include <vlc_input.h> |
|---|
| 42 |
|
|---|
| 43 |
#include "modules/modules.h" |
|---|
| 44 |
#include "config/configuration.h" |
|---|
| 45 |
#include "interface/interface.h" |
|---|
| 46 |
|
|---|
| 47 |
#include <errno.h> |
|---|
| 48 |
#include <stdio.h> |
|---|
| 49 |
#include <string.h> |
|---|
| 50 |
#include <stdlib.h> |
|---|
| 51 |
|
|---|
| 52 |
#ifndef WIN32 |
|---|
| 53 |
# include <netinet/in.h> |
|---|
| 54 |
#endif |
|---|
| 55 |
|
|---|
| 56 |
#ifdef HAVE_UNISTD_H |
|---|
| 57 |
# include <unistd.h> |
|---|
| 58 |
#elif defined( WIN32 ) && !defined( UNDER_CE ) |
|---|
| 59 |
# include <io.h> |
|---|
| 60 |
#endif |
|---|
| 61 |
|
|---|
| 62 |
#ifdef WIN32 |
|---|
| 63 |
# include "extras/getopt.h" |
|---|
| 64 |
#endif |
|---|
| 65 |
|
|---|
| 66 |
#ifdef HAVE_LOCALE_H |
|---|
| 67 |
# include <locale.h> |
|---|
| 68 |
#endif |
|---|
| 69 |
|
|---|
| 70 |
#ifdef HAVE_DBUS |
|---|
| 71 |
|
|---|
| 72 |
# include <dbus/dbus.h> |
|---|
| 73 |
#endif |
|---|
| 74 |
|
|---|
| 75 |
#ifdef HAVE_HAL |
|---|
| 76 |
# include <hal/libhal.h> |
|---|
| 77 |
#endif |
|---|
| 78 |
|
|---|
| 79 |
#include <vlc_playlist.h> |
|---|
| 80 |
#include <vlc_interface.h> |
|---|
| 81 |
|
|---|
| 82 |
#include <vlc_aout.h> |
|---|
| 83 |
#include "audio_output/aout_internal.h" |
|---|
| 84 |
|
|---|
| 85 |
#include <vlc_vout.h> |
|---|
| 86 |
|
|---|
| 87 |
#include <vlc_sout.h> |
|---|
| 88 |
#include "stream_output/stream_output.h" |
|---|
| 89 |
|
|---|
| 90 |
#include <vlc_charset.h> |
|---|
| 91 |
|
|---|
| 92 |
#include "libvlc.h" |
|---|
| 93 |
|
|---|
| 94 |
#include "playlist/playlist_internal.h" |
|---|
| 95 |
|
|---|
| 96 |
#include <vlc_vlm.h> |
|---|
| 97 |
|
|---|
| 98 |
#include <assert.h> |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
static libvlc_int_t * p_static_vlc = NULL; |
|---|
| 104 |
static unsigned i_instances = 0; |
|---|
| 105 |
|
|---|
| 106 |
static bool b_daemon = false; |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
void __vlc_gc_incref( gc_object_t * p_gc ) |
|---|
| 112 |
{ |
|---|
| 113 |
assert( p_gc->i_gc_refcount > 0 ); |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
p_gc->i_gc_refcount ++; |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
void __vlc_gc_decref( gc_object_t *p_gc ) |
|---|
| 120 |
{ |
|---|
| 121 |
assert( p_gc ); |
|---|
| 122 |
assert( p_gc->i_gc_refcount > 0 ); |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
p_gc->i_gc_refcount -- ; |
|---|
| 126 |
|
|---|
| 127 |
if( p_gc->i_gc_refcount == 0 ) |
|---|
| 128 |
{ |
|---|
| 129 |
p_gc->pf_destructor( p_gc ); |
|---|
| 130 |
|
|---|
| 131 |
} |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
void |
|---|
| 135 |
__vlc_gc_init( gc_object_t * p_gc, void (*pf_destructor)( gc_object_t * ), |
|---|
| 136 |
void * arg) |
|---|
| 137 |
{ |
|---|
| 138 |
p_gc->i_gc_refcount = 1; |
|---|
| 139 |
p_gc->pf_destructor = pf_destructor; |
|---|
| 140 |
p_gc->p_destructor_arg = arg; |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
#if defined( ENABLE_NLS ) && (defined (__APPLE__) || defined (WIN32)) && \ |
|---|
| 147 |
( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) ) |
|---|
| 148 |
static void SetLanguage ( char const * ); |
|---|
| 149 |
#endif |
|---|
| 150 |
static inline int LoadMessages (void); |
|---|
| 151 |
static int GetFilenames ( libvlc_int_t *, int, const char *[] ); |
|---|
| 152 |
static void Help ( libvlc_int_t *, char const *psz_help_name ); |
|---|
| 153 |
static void Usage ( libvlc_int_t *, char const *psz_module_name ); |
|---|
| 154 |
static void ListModules ( libvlc_int_t *, bool ); |
|---|
| 155 |
static void Version ( void ); |
|---|
| 156 |
|
|---|
| 157 |
#ifdef WIN32 |
|---|
| 158 |
static void ShowConsole ( bool ); |
|---|
| 159 |
static void PauseConsole ( void ); |
|---|
| 160 |
#endif |
|---|
| 161 |
static int ConsoleWidth ( void ); |
|---|
| 162 |
|
|---|
| 163 |
static int VerboseCallback( vlc_object_t *, char const *, |
|---|
| 164 |
vlc_value_t, vlc_value_t, void * ); |
|---|
| 165 |
|
|---|
| 166 |
static void InitDeviceValues( libvlc_int_t * ); |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
libvlc_int_t * libvlc_InternalCreate( void ) |
|---|
| 173 |
{ |
|---|
| 174 |
libvlc_int_t *p_libvlc; |
|---|
| 175 |
libvlc_priv_t *priv; |
|---|
| 176 |
char *psz_env = NULL; |
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
if (vlc_threads_init ()) |
|---|
| 181 |
return NULL; |
|---|
| 182 |
|
|---|
| 183 |
libvlc_global_data_t *p_libvlc_global = vlc_global(); |
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
vlc_mutex_t *lock = var_AcquireMutex( "libvlc" ); |
|---|
| 187 |
if( i_instances == 0 ) |
|---|
| 188 |
{ |
|---|
| 189 |
|
|---|
| 190 |
cpu_flags = CPUCapabilities(); |
|---|
| 191 |
|
|---|
| 192 |
p_libvlc_global->p_module_bank = NULL; |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
p_libvlc = vlc_custom_create( VLC_OBJECT(p_libvlc_global), |
|---|
| 197 |
sizeof (*p_libvlc) + sizeof (libvlc_priv_t), |
|---|
| 198 |
VLC_OBJECT_LIBVLC, "libvlc" ); |
|---|
| 199 |
if( p_libvlc != NULL ) |
|---|
| 200 |
i_instances++; |
|---|
| 201 |
vlc_mutex_unlock( lock ); |
|---|
| 202 |
|
|---|
| 203 |
if( p_libvlc == NULL ) |
|---|
| 204 |
return NULL; |
|---|
| 205 |
|
|---|
| 206 |
priv = libvlc_priv (p_libvlc); |
|---|
| 207 |
priv->p_playlist = NULL; |
|---|
| 208 |
priv->p_interaction = NULL; |
|---|
| 209 |
priv->p_vlm = NULL; |
|---|
| 210 |
p_libvlc->psz_object_name = strdup( "libvlc" ); |
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
msg_Create( p_libvlc ); |
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
psz_env = getenv( "VLC_VERBOSE" ); |
|---|
| 217 |
if( psz_env != NULL ) |
|---|
| 218 |
priv->i_verbose = atoi( psz_env ); |
|---|
| 219 |
else |
|---|
| 220 |
priv->i_verbose = 3; |
|---|
| 221 |
#if defined( HAVE_ISATTY ) && !defined( WIN32 ) |
|---|
| 222 |
priv->b_color = isatty( 2 ); |
|---|
| 223 |
#else |
|---|
| 224 |
priv->b_color = false; |
|---|
| 225 |
#endif |
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
msg_Dbg( p_libvlc, COPYRIGHT_MESSAGE ); |
|---|
| 229 |
msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE ); |
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
vlc_mutex_init( &priv->timer_lock ); |
|---|
| 233 |
vlc_mutex_init( &priv->config_lock ); |
|---|
| 234 |
|
|---|
| 235 |
priv->threads_count = 0; |
|---|
| 236 |
vlc_mutex_init (&priv->threads_lock); |
|---|
| 237 |
vlc_cond_init (NULL, &priv->threads_wait); |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
p_static_vlc = p_libvlc; |
|---|
| 241 |
|
|---|
| 242 |
return p_libvlc; |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, |
|---|
| 254 |
const char *ppsz_argv[] ) |
|---|
| 255 |
{ |
|---|
| 256 |
libvlc_global_data_t *p_libvlc_global = vlc_global(); |
|---|
| 257 |
libvlc_priv_t *priv = libvlc_priv (p_libvlc); |
|---|
| 258 |
char p_capabilities[200]; |
|---|
| 259 |
char * p_tmp = NULL; |
|---|
| 260 |
char * psz_modules = NULL; |
|---|
| 261 |
char * psz_parser = NULL; |
|---|
| 262 |
char * psz_control = NULL; |
|---|
| 263 |
bool b_exit = false; |
|---|
| 264 |
int i_ret = VLC_EEXIT; |
|---|
| 265 |
playlist_t *p_playlist = NULL; |
|---|
| 266 |
vlc_value_t val; |
|---|
| 267 |
#if defined( ENABLE_NLS ) \ |
|---|
| 268 |
&& ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) ) |
|---|
| 269 |
# if defined (WIN32) || defined (__APPLE__) |
|---|
| 270 |
char * psz_language; |
|---|
| 271 |
#endif |
|---|
| 272 |
#endif |
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
system_Init( p_libvlc, &i_argc, ppsz_argv ); |
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
if( i_argc > 0 && ppsz_argv[0][0] ) |
|---|
| 279 |
{ |
|---|
| 280 |
free( p_libvlc->psz_object_name ); |
|---|
| 281 |
|
|---|
| 282 |
const char *psz_exe = strrchr( ppsz_argv[0], '/' ); |
|---|
| 283 |
if( psz_exe && *(psz_exe + 1) ) |
|---|
| 284 |
p_libvlc->psz_object_name = strdup( psz_exe + 1 ); |
|---|
| 285 |
else |
|---|
| 286 |
p_libvlc->psz_object_name = strdup( ppsz_argv[0] ); |
|---|
| 287 |
} |
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
LoadMessages (); |
|---|
| 293 |
|
|---|
| 294 |
|
|---|
| 295 |
msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") ); |
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
module_InitBank( p_libvlc ); |
|---|
| 302 |
|
|---|
| 303 |
if( config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, true ) ) |
|---|
| 304 |
{ |
|---|
| 305 |
module_EndBank( p_libvlc ); |
|---|
| 306 |
return VLC_EGENERIC; |
|---|
| 307 |
} |
|---|
| 308 |
|
|---|
| 309 |
#ifdef __APPLE__ |
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
vlc_thread_set_priority( p_libvlc, VLC_THREAD_PRIORITY_LOW ); |
|---|
| 313 |
#endif |
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
if( config_GetInt( p_libvlc, "help" ) > 0 ) |
|---|
| 317 |
{ |
|---|
| 318 |
Help( p_libvlc, "help" ); |
|---|
| 319 |
b_exit = true; |
|---|
| 320 |
i_ret = VLC_EEXITSUCCESS; |
|---|
| 321 |
} |
|---|
| 322 |
|
|---|
| 323 |
else if( config_GetInt( p_libvlc, "version" ) > 0 ) |
|---|
| 324 |
{ |
|---|
| 325 |
Version(); |
|---|
| 326 |
b_exit = true; |
|---|
| 327 |
i_ret = VLC_EEXITSUCCESS; |
|---|
| 328 |
} |
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
priv->psz_configfile = config_GetCustomConfigFile( p_libvlc ); |
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 |
if( config_GetInt( p_libvlc, "reset-plugins-cache" ) > 0 ) |
|---|
| 335 |
{ |
|---|
| 336 |
p_libvlc_global->p_module_bank->b_cache_delete = true; |
|---|
| 337 |
} |
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
priv->i_verbose = config_GetInt( p_libvlc, "verbose" ); |
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
#ifndef WIN32 |
|---|
| 344 |
if( config_GetInt( p_libvlc, "daemon" ) > 0 ) |
|---|
| 345 |
{ |
|---|
| 346 |
#ifdef HAVE_DAEMON |
|---|
| 347 |
char *psz_pidfile = NULL; |
|---|
| 348 |
|
|---|
| 349 |
if( daemon( 1, 0) != 0 ) |
|---|
| 350 |
{ |
|---|
| 351 |
msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" ); |
|---|
| 352 |
b_exit = true; |
|---|
| 353 |
} |
|---|
| 354 |
b_daemon = true; |
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
psz_pidfile = config_GetPsz( p_libvlc, "pidfile" ); |
|---|
| 358 |
if( psz_pidfile != NULL ) |
|---|
| 359 |
{ |
|---|
| 360 |
FILE *pidfile; |
|---|
| 361 |
pid_t i_pid = getpid (); |
|---|
| 362 |
msg_Dbg( p_libvlc, "PID is %d, writing it to %s", |
|---|
| 363 |
i_pid, psz_pidfile ); |
|---|
| 364 |
pidfile = utf8_fopen( psz_pidfile,"w" ); |
|---|
| 365 |
if( pidfile != NULL ) |
|---|
| 366 |
{ |
|---|
| 367 |
utf8_fprintf( pidfile, "%d", (int)i_pid ); |
|---|
| 368 |
fclose( pidfile ); |
|---|
| 369 |
} |
|---|
| 370 |
else |
|---|
| 371 |
{ |
|---|
| 372 |
msg_Err( p_libvlc, "cannot open pid file for writing: %s (%m)", |
|---|
| 373 |
psz_pidfile ); |
|---|
| 374 |
} |
|---|
| 375 |
} |
|---|
| 376 |
free( psz_pidfile ); |
|---|
| 377 |
|
|---|
| 378 |
#else |
|---|
| 379 |
pid_t i_pid; |
|---|
| 380 |
|
|---|
| 381 |
if( ( i_pid = fork() ) < 0 ) |
|---|
| 382 |
{ |
|---|
| 383 |
msg_Err( p_libvlc, "unable to fork vlc to daemon mode" ); |
|---|
| 384 |
b_exit = true; |
|---|
| 385 |
} |
|---|
| 386 |
else if( i_pid ) |
|---|
| 387 |
{ |
|---|
| 388 |
|
|---|
| 389 |
msg_Dbg( p_libvlc, "closing parent process" ); |
|---|
| 390 |
b_exit = true; |
|---|
| 391 |
i_ret = VLC_EEXITSUCCESS; |
|---|
| 392 |
} |
|---|
| 393 |
else |
|---|
| 394 |
{ |
|---|
| 395 |
|
|---|
| 396 |
msg_Dbg( p_libvlc, "daemon spawned" ); |
|---|
| 397 |
close( STDIN_FILENO ); |
|---|
| 398 |
close( STDOUT_FILENO ); |
|---|
| 399 |
close( STDERR_FILENO ); |
|---|
| 400 |
|
|---|
| 401 |
b_daemon = true; |
|---|
| 402 |
} |
|---|
| 403 |
#endif |
|---|
| 404 |
} |
|---|
| 405 |
#endif |
|---|
| 406 |
|
|---|
| 407 |
if( b_exit ) |
|---|
| 408 |
{ |
|---|
| 409 |
module_EndBank( p_libvlc ); |
|---|
| 410 |
return i_ret; |
|---|
| 411 |
} |
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
#if defined( ENABLE_NLS ) \ |
|---|
| 415 |
&& ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) ) |
|---|
| 416 |
# if defined (WIN32) || defined (__APPLE__) |
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
if( !config_GetInt( p_libvlc, "ignore-config" ) ) |
|---|
| 421 |
config_LoadConfigFile( p_libvlc, "main" ); |
|---|
| 422 |
config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, true ); |
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
psz_language = config_GetPsz( p_libvlc, "language" ); |
|---|
| 426 |
if( psz_language && *psz_language && strcmp( psz_language, "auto" ) ) |
|---|
| 427 |
{ |
|---|
| 428 |
bool b_cache_delete = p_libvlc_global->p_module_bank->b_cache_delete; |
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
SetLanguage( psz_language ); |
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") ); |
|---|
| 435 |
|
|---|
| 436 |
module_EndBank( p_libvlc ); |
|---|
| 437 |
module_InitBank( p_libvlc ); |
|---|
| 438 |
if( !config_GetInt( p_libvlc, "ignore-config" ) ) |
|---|
| 439 |
config_LoadConfigFile( p_libvlc, "main" ); |
|---|
| 440 |
config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, true ); |
|---|
| 441 |
p_libvlc_global->p_module_bank->b_cache_delete = b_cache_delete; |
|---|
| 442 |
} |
|---|
| 443 |
free( psz_language ); |
|---|
| 444 |
# endif |
|---|
| 445 |
#endif |
|---|
| 446 |
|
|---|
| 447 |
|
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
module_LoadBuiltins( p_libvlc ); |
|---|
| 454 |
module_LoadPlugins( p_libvlc ); |
|---|
| 455 |
if( p_libvlc->b_die ) |
|---|
| 456 |
{ |
|---|
| 457 |
b_exit = true; |
|---|
| 458 |
} |
|---|
| 459 |
|
|---|
| 460 |
msg_Dbg( p_libvlc, "module bank initialized, found %i modules", |
|---|
| 461 |
vlc_internals( p_libvlc_global->p_module_bank )->i_children ); |
|---|
| 462 |
|
|---|
| 463 |
|
|---|
| 464 |
if( (p_tmp = config_GetPsz( p_libvlc, "module" )) ) |
|---|
| 465 |
{ |
|---|
| 466 |
Help( p_libvlc, p_tmp ); |
|---|
| 467 |
free( p_tmp ); |
|---|
| 468 |
b_exit = true; |
|---|
| 469 |
i_ret = VLC_EEXITSUCCESS; |
|---|
| 470 |
} |
|---|
| 471 |
|
|---|
| 472 |
else if( config_GetInt( p_libvlc, "full-help" ) > 0 ) |
|---|
| 473 |
{ |
|---|
| 474 |
config_PutInt( p_libvlc, "advanced", 1); |
|---|
| 475 |
config_PutInt( p_libvlc, "help-verbose", 1); |
|---|
| 476 |
Help( p_libvlc, "full-help" ); |
|---|
| 477 |
b_exit = true; |
|---|
| 478 |
i_ret = VLC_EEXITSUCCESS; |
|---|
| 479 |
} |
|---|
| 480 |
|
|---|
| 481 |
else if( config_GetInt( p_libvlc, "longhelp" ) > 0 ) |
|---|
| 482 |
{ |
|---|
| 483 |
Help( p_libvlc, "longhelp" ); |
|---|
| 484 |
b_exit = true; |
|---|
| 485 |
i_ret = VLC_EEXITSUCCESS; |
|---|
| 486 |
} |
|---|
| 487 |
|
|---|
| 488 |
else if( config_GetInt( p_libvlc, "list" ) > 0 ) |
|---|
| 489 |
{ |
|---|
| 490 |
ListModules( p_libvlc, false ); |
|---|
| 491 |
b_exit = true; |
|---|
| 492 |
i_ret = VLC_EEXITSUCCESS; |
|---|
| 493 |
} |
|---|
| 494 |
else if( config_GetInt( p_libvlc, "list-verbose" ) > 0 ) |
|---|
| 495 |
{ |
|---|
| 496 |
ListModules( p_libvlc, true ); |
|---|
| 497 |
b_exit = true; |
|---|
| 498 |
i_ret = VLC_EEXITSUCCESS; |
|---|
| 499 |
} |
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
if( !config_GetInt( p_libvlc, "ignore-config" ) ) |
|---|
| 503 |
{ |
|---|
| 504 |
if( config_GetInt( p_libvlc, "reset-config" ) > 0 ) |
|---|
| 505 |
{ |
|---|
| 506 |
config_ResetAll( p_libvlc ); |
|---|
| 507 |
config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, true ); |
|---|
| 508 |
config_SaveConfigFile( p_libvlc, NULL ); |
|---|
| 509 |
} |
|---|
| 510 |
if( config_GetInt( p_libvlc, "save-config" ) > 0 ) |
|---|
| 511 |
{ |
|---|
| 512 |
config_LoadConfigFile( p_libvlc, NULL ); |
|---|
| 513 |
config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, true ); |
|---|
| 514 |
config_SaveConfigFile( p_libvlc, NULL ); |
|---|
| 515 |
} |
|---|
| 516 |
} |
|---|
| 517 |
|
|---|
| 518 |
if( b_exit ) |
|---|
| 519 |
{ |
|---|
| 520 |
module_EndBank( p_libvlc ); |
|---|
| 521 |
return i_ret; |
|---|
| 522 |
} |
|---|
| 523 |
|
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 |
|
|---|
| 527 |
InitDeviceValues( p_libvlc ); |
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
|
|---|
| 532 |
if( !config_GetInt( p_libvlc, "ignore-config" ) ) |
|---|
| 533 |
config_LoadConfigFile( p_libvlc, NULL ); |
|---|
| 534 |
|
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
|
|---|
| 538 |
if( config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, false ) ) |
|---|
| 539 |
{ |
|---|
| 540 |
#ifdef WIN32 |
|---|
| 541 |
ShowConsole( false ); |
|---|
| 542 |
|
|---|
| 543 |
fprintf( stderr, "The command line options couldn't be loaded, check " |
|---|
| 544 |
"that they are valid.\n" ); |
|---|
| 545 |
PauseConsole(); |
|---|
| 546 |
#endif |
|---|
| 547 |
module_EndBank( p_libvlc ); |
|---|
| 548 |
return VLC_EGENERIC; |
|---|
| 549 |
} |
|---|
| 550 |
|
|---|
| 551 |
|
|---|
| 552 |
|
|---|
| 553 |
|
|---|
| 554 |
system_Configure( p_libvlc, &i_argc, ppsz_argv ); |
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 |
#ifdef HAVE_DBUS |
|---|
| 558 |
dbus_threads_init_default(); |
|---|
| 559 |
|
|---|
| 560 |
if( config_GetInt( p_libvlc, "one-instance" ) > 0 ) |
|---|
| 561 |
{ |
|---|
| 562 |
|
|---|
| 563 |
DBusConnection *p_conn = NULL; |
|---|
| 564 |
DBusError dbus_error; |
|---|
| 565 |
|
|---|
| 566 |
dbus_error_init( &dbus_error ); |
|---|
| 567 |
|
|---|
| 568 |
|
|---|
| 569 |
p_conn = dbus_bus_get( DBUS_BUS_SESSION, &dbus_error ); |
|---|
| 570 |
if( !p_conn ) |
|---|
| 571 |
{ |
|---|
| 572 |
msg_Err( p_libvlc, "Failed to connect to D-Bus session daemon: %s", |
|---|
| 573 |
dbus_error.message ); |
|---|
| 574 |
dbus_error_free( &dbus_error ); |
|---|
| 575 |
} |
|---|
| 576 |
else |
|---|
| 577 |
{ |
|---|
| 578 |
|
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 |
DBusMessage *p_test_msg = NULL; |
|---|
| 582 |
DBusMessage *p_test_reply = NULL; |
|---|
| 583 |
p_test_msg = dbus_message_new_method_call( |
|---|
| 584 |
"org.mpris.vlc", "/", |
|---|
| 585 |
"org.freedesktop.MediaPlayer", "Identity" ); |
|---|
| 586 |
|
|---|
| 587 |
p_test_reply = dbus_connection_send_with_reply_and_block( |
|---|
| 588 |
p_conn, p_test_msg, -1, &dbus_error ); |
|---|
| 589 |
dbus_message_unref( p_test_msg ); |
|---|
| 590 |
if( p_test_reply == NULL ) |
|---|
| 591 |
{ |
|---|
| 592 |
dbus_error_free( &dbus_error ); |
|---|
| 593 |
msg_Dbg( p_libvlc, "No Media Player is running. " |
|---|
| 594 |
"Continuing normally." ); |
|---|
| 595 |
} |
|---|
| 596 |
else |
|---|
| 597 |
{ |
|---|
| 598 |
int i_input; |
|---|
| 599 |
DBusMessage* p_dbus_msg = NULL; |
|---|
| 600 |
DBusMessageIter dbus_args; |
|---|
| 601 |
DBusPendingCall* p_dbus_pending = NULL; |
|---|
| 602 |
dbus_bool_t b_play; |
|---|
| 603 |
|
|---|
| 604 |
dbus_message_unref( p_test_reply ); |
|---|
| 605 |
msg_Warn( p_libvlc, "Another Media Player is running. Exiting"); |
|---|
| 606 |
|
|---|
| 607 |
for( i_input = optind;i_input < i_argc;i_input++ ) |
|---|
| 608 |
{ |
|---|
| 609 |
msg_Dbg( p_libvlc, "Adds %s to the running Media Player", |
|---|
| 610 |
ppsz_argv[i_input] ); |
|---|
| 611 |
|
|---|
| 612 |
p_dbus_msg = dbus_message_new_method_call( |
|---|
| 613 |
"org.mpris.vlc", "/TrackList", |
|---|
| 614 |
"org.freedesktop.MediaPlayer", "AddTrack" ); |
|---|
| 615 |
|
|---|
| 616 |
if ( NULL == p_dbus_msg ) |
|---|
| 617 |
{ |
|---|
| 618 |
msg_Err( p_libvlc, "D-Bus problem" ); |
|---|
| 619 |
system_End( p_libvlc ); |
|---|
| 620 |
exit( VLC_ETIMEOUT ); |
|---|
| 621 |
} |
|---|
| 622 |
|
|---|
| 623 |
|
|---|
| 624 |
dbus_message_iter_init_append( p_dbus_msg, &dbus_args ); |
|---|
| 625 |
if ( !dbus_message_iter_append_basic( &dbus_args, |
|---|
| 626 |
DBUS_TYPE_STRING, &ppsz_argv[i_input] ) ) |
|---|
| 627 |
{ |
|---|
| 628 |
dbus_message_unref( p_dbus_msg ); |
|---|
| 629 |
system_End( p_libvlc ); |
|---|
| 630 |
exit( VLC_ENOMEM ); |
|---|
| 631 |
} |
|---|
| 632 |
b_play = TRUE; |
|---|
| 633 |
if( config_GetInt( p_libvlc, "playlist-enqueue" ) > 0 ) |
|---|
| 634 |
b_play = FALSE; |
|---|
| 635 |
if ( !dbus_message_iter_append_basic( &dbus_args, |
|---|
| 636 |
DBUS_TYPE_BOOLEAN, &b_play ) ) |
|---|
| 637 |
{ |
|---|
| 638 |
dbus_message_unref( p_dbus_msg ); |
|---|
| 639 |
system_End( p_libvlc ); |
|---|
| 640 |
exit( VLC_ENOMEM ); |
|---|
| 641 |
} |
|---|
| 642 |
|
|---|
| 643 |
|
|---|
| 644 |
if ( !dbus_connection_send_with_reply ( p_conn, |
|---|
| 645 |
p_dbus_msg, &p_dbus_pending, -1 ) ) |
|---|
| 646 |
{ |
|---|
| 647 |
msg_Err( p_libvlc, "D-Bus problem" ); |
|---|
| 648 |
dbus_message_unref( p_dbus_msg ); |
|---|
| 649 |
system_End( p_libvlc ); |
|---|
| 650 |
exit( VLC_ETIMEOUT ); |
|---|
| 651 |
} |
|---|
| 652 |
|
|---|
| 653 |
if ( NULL == p_dbus_pending ) |
|---|
| 654 |
{ |
|---|
| 655 |
msg_Err( p_libvlc, "D-Bus problem" ); |
|---|
| 656 |
dbus_message_unref( p_dbus_msg ); |
|---|
| 657 |
system_End( p_libvlc ); |
|---|
| 658 |
exit( VLC_ETIMEOUT ); |
|---|
| 659 |
} |
|---|
| 660 |
dbus_connection_flush( p_conn ); |
|---|
| 661 |
dbus_message_unref( p_dbus_msg ); |
|---|
| 662 |
|
|---|
| 663 |
dbus_pending_call_block( p_dbus_pending ); |
|---|
| 664 |
dbus_pending_call_unref( p_dbus_pending ); |
|---|
| 665 |
} |
|---|
| 666 |
|
|---|
| 667 |
|
|---|
| 668 |
system_End( p_libvlc ); |
|---|
| 669 |
exit( VLC_SUCCESS ); |
|---|
| 670 |
} |
|---|
| 671 |
} |
|---|
| 672 |
|
|---|
| 673 |
if( p_conn ) dbus_connection_unref( p_conn ); |
|---|
| 674 |
} |
|---|
| 675 |
#endif |
|---|
| 676 |
|
|---|
| 677 |
|
|---|
| 678 |
|
|---|
| 679 |
|
|---|
| 680 |
|
|---|
| 681 |
var_Create( p_libvlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); |
|---|
| 682 |
if( config_GetInt( p_libvlc, "quiet" ) > 0 ) |
|---|
| 683 |
{ |
|---|
| 684 |
val.i_int = -1; |
|---|
| 685 |
var_Set( p_libvlc, "verbose", val ); |
|---|
| 686 |
} |
|---|
| 687 |
var_AddCallback( p_libvlc, "verbose", VerboseCallback, NULL ); |
|---|
| 688 |
var_Change( p_libvlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL ); |
|---|
| 689 |
|
|---|
| 690 |
if( priv->b_color ) |
|---|
| 691 |
priv->b_color = config_GetInt( p_libvlc, "color" ) > 0; |
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
|
|---|
| 696 |
msg_Flush( p_libvlc ); |
|---|
| 697 |
|
|---|
| 698 |
if( !config_GetInt( p_libvlc, "fpu" ) ) |
|---|
| 699 |
cpu_flags &= ~CPU_CAPABILITY_FPU; |
|---|
| 700 |
|
|---|
| 701 |
#if defined( __i386__ ) || defined( __x86_64__ ) |
|---|
| 702 |
if( !config_GetInt( p_libvlc, "mmx" ) ) |
|---|
| 703 |
cpu_flags &= ~CPU_CAPABILITY_MMX; |
|---|
| 704 |
if( !config_GetInt( p_libvlc, "3dn" ) ) |
|---|
| 705 |
cpu_flags &= ~CPU_CAPABILITY_3DNOW; |
|---|
| 706 |
if( !config_GetInt( p_libvlc, "mmxext" ) ) |
|---|
| 707 |
cpu_flags &= ~CPU_CAPABILITY_MMXEXT; |
|---|
| 708 |
if( !config_GetInt( p_libvlc, "sse" ) ) |
|---|
| 709 |
cpu_flags &= ~CPU_CAPABILITY_SSE; |
|---|
| 710 |
if( !config_GetInt( p_libvlc, "sse2" ) ) |
|---|
| 711 |
cpu_flags &= ~CPU_CAPABILITY_SSE2; |
|---|
| 712 |
#endif |
|---|
| 713 |
#if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ ) |
|---|
| 714 |
if( !config_GetInt( p_libvlc, "altivec" ) ) |
|---|
| 715 |
cpu_flags &= ~CPU_CAPABILITY_ALTIVEC; |
|---|
| 716 |
#endif |
|---|
| 717 |
|
|---|
| 718 |
#define PRINT_CAPABILITY( capability, string ) \ |
|---|
| 719 |
if( vlc_CPU() & capability ) \ |
|---|
| 720 |
{ \ |
|---|
| 721 |
strncat( p_capabilities, string " ", \ |
|---|
| 722 |
sizeof(p_capabilities) - strlen(p_capabilities) ); \ |
|---|
| 723 |
p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \ |
|---|
| 724 |
} |
|---|
| 725 |
|
|---|
| 726 |
p_capabilities[0] = '\0'; |
|---|
| 727 |
PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" ); |
|---|
| 728 |
PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" ); |
|---|
| 729 |
PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" ); |
|---|
| 730 |
PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" ); |
|---|
| 731 |
PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" ); |
|---|
| 732 |
PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" ); |
|---|
| 733 |
PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" ); |
|---|
| 734 |
PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" ); |
|---|
| 735 |
PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" ); |
|---|
| 736 |
PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" ); |
|---|
| 737 |
msg_Dbg( p_libvlc, "CPU has capabilities %s", p_capabilities ); |
|---|
| 738 |
|
|---|
| 739 |
|
|---|
| 740 |
|
|---|
| 741 |
|
|---|
| 742 |
priv->p_memcpy_module = module_Need( p_libvlc, "memcpy", "$memcpy", 0 ); |
|---|
| 743 |
|
|---|
| 744 |
priv->b_stats = config_GetInt( p_libvlc, "stats" ) > 0; |
|---|
| 745 |
priv->i_timers = 0; |
|---|
| 746 |
priv->pp_timers = NULL; |
|---|
| 747 |
|
|---|
| 748 |
|
|---|
| 749 |
p_libvlc->p_stats = (global_stats_t *)malloc( sizeof( global_stats_t ) ); |
|---|
| 750 |
if( !p_libvlc->p_stats ) |
|---|
| 751 |
{ |
|---|
| 752 |
vlc_object_release( p_libvlc ); |
|---|
| 753 |
return VLC_ENOMEM; |
|---|
| 754 |
} |
|---|
| 755 |
vlc_mutex_init( &p_libvlc->p_stats->lock ); |
|---|
| 756 |
priv->p_stats_computer = NULL; |
|---|
| 757 |
|
|---|
| 758 |
|
|---|
| 759 |
ARRAY_INIT( priv->input_items ); |
|---|
| 760 |
priv->i_last_input_id = 0; |
|---|
| 761 |
|
|---|
| 762 |
|
|---|
| 763 |
|
|---|
| 764 |
|
|---|
| 765 |
var_Create( p_libvlc, "key-pressed", VLC_VAR_INTEGER ); |
|---|
| 766 |
var_Create( p_libvlc, "key-action", VLC_VAR_INTEGER ); |
|---|
| 767 |
p_libvlc->p_hotkeys = malloc( libvlc_hotkeys_size ); |
|---|
| 768 |
|
|---|
| 769 |
memcpy( p_libvlc->p_hotkeys, libvlc_hotkeys, libvlc_hotkeys_size ); |
|---|
| 770 |
var_AddCallback( p_libvlc, "key-pressed", vlc_key_to_action, |
|---|
| 771 |
p_libvlc->p_hotkeys ); |
|---|
| 772 |
|
|---|
| 773 |
|
|---|
| 774 |
priv->p_interaction = interaction_Init( p_libvlc ); |
|---|
| 775 |
|
|---|
| 776 |
|
|---|
| 777 |
playlist_ThreadCreate( p_libvlc ); |
|---|
| 778 |
if( !priv->p_playlist ) |
|---|
| 779 |
{ |
|---|
| 780 |
msg_Err( p_libvlc, "playlist initialization failed" ); |
|---|
| 781 |
if( priv->p_memcpy_module != NULL ) |
|---|
| 782 |
{ |
|---|
| 783 |
module_Unneed( p_libvlc, priv->p_memcpy_module ); |
|---|
| 784 |
} |
|---|
| 785 |
module_EndBank( p_libvlc ); |
|---|
| 786 |
return VLC_EGENERIC; |
|---|
| 787 |
} |
|---|
| 788 |
p_playlist = priv->p_playlist; |
|---|
| 789 |
|
|---|
| 790 |
psz_modules = config_GetPsz( p_playlist, "services-discovery" ); |
|---|
| 791 |
if( psz_modules && *psz_modules ) |
|---|
| 792 |
{ |
|---|
| 793 |
|
|---|
| 794 |
playlist_ServicesDiscoveryAdd( p_playlist, psz_modules ); |
|---|
| 795 |
} |
|---|
| 796 |
free( psz_modules ); |
|---|
| 797 |
|
|---|
| 798 |
#ifdef ENABLE_VLM |
|---|
| 799 |
|
|---|
| 800 |
psz_parser = config_GetPsz( p_libvlc, "vlm-conf" ); |
|---|
| 801 |
if( psz_parser && *psz_parser ) |
|---|
| 802 |
{ |
|---|
| 803 |
priv->p_vlm = vlm_New( p_libvlc ); |
|---|
| 804 |
if( !priv->p_vlm ) |
|---|
| 805 |
msg_Err( p_libvlc, "VLM initialization failed" ); |
|---|
| 806 |
} |
|---|
| 807 |
free( psz_parser ); |
|---|
| 808 |
#endif |
|---|
| 809 |
|
|---|
| 810 |
|
|---|
| 811 |
|
|---|
| 812 |
|
|---|
| 813 |
psz_modules = config_GetPsz( p_libvlc, "extraintf" ); |
|---|
| 814 |
psz_control = config_GetPsz( p_libvlc, "control" ); |
|---|
| 815 |
|
|---|
| 816 |
if( psz_modules && *psz_modules && psz_control && *psz_control ) |
|---|
| 817 |
{ |
|---|
| 818 |
psz_modules = (char *)realloc( psz_modules, strlen( psz_modules ) + |
|---|
| 819 |
strlen( psz_control ) + 1 ); |
|---|
| 820 |
sprintf( psz_modules, "%s:%s", psz_modules, psz_control ); |
|---|
| 821 |
} |
|---|
| 822 |
else if( psz_control && *psz_control ) |
|---|
| 823 |
{ |
|---|
| 824 |
free( psz_modules ); |
|---|
| 825 |
psz_modules = strdup( psz_control ); |
|---|
| 826 |
} |
|---|
| 827 |
|
|---|
| 828 |
psz_parser = psz_modules; |
|---|
| 829 |
while ( psz_parser && *psz_parser ) |
|---|
| 830 |
{ |
|---|
| 831 |
char *psz_module, *psz_temp; |
|---|
| 832 |
psz_module = psz_parser; |
|---|
| 833 |
psz_parser = strchr( psz_module, ':' ); |
|---|
| 834 |
if ( psz_parser ) |
|---|
| 835 |
{ |
|---|
| 836 |
*psz_parser = '\0'; |
|---|
| 837 |
psz_parser++; |
|---|
| 838 |
} |
|---|
| 839 |
psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") ); |
|---|
| 840 |
if( psz_temp ) |
|---|
| 841 |
{ |
|---|
| 842 |
sprintf( psz_temp, "%s,none", psz_module ); |
|---|
| 843 |
libvlc_InternalAddIntf( p_libvlc, psz_temp ); |
|---|
| 844 |
free( psz_temp ); |
|---|
| 845 |
} |
|---|
| 846 |
} |
|---|
| 847 |
free( psz_modules ); |
|---|
| 848 |
free( psz_control ); |
|---|
| 849 |
|
|---|
| 850 |
|
|---|
| 851 |
|
|---|
| 852 |
|
|---|
| 853 |
libvlc_InternalAddIntf( p_libvlc, "hotkeys,none" ); |
|---|
| 854 |
|
|---|
| 855 |
#ifdef HAVE_DBUS |
|---|
| 856 |
|
|---|
| 857 |
|
|---|
| 858 |
if( config_GetInt( p_libvlc, "one-instance" ) > 0 ) |
|---|
| 859 |
libvlc_InternalAddIntf( p_libvlc, "dbus,none" ); |
|---|
| 860 |
|
|---|
| 861 |
|
|---|
| 862 |
|
|---|
| 863 |
if( config_GetInt( p_libvlc, "inhibit" ) > 0 ) |
|---|
| 864 |
libvlc_InternalAddIntf( p_libvlc, "inhibit,none" ); |
|---|
| 865 |
#endif |
|---|
| 866 |
|
|---|
| 867 |
|
|---|
| 868 |
|
|---|
| 869 |
|
|---|
| 870 |
|
|---|
| 871 |
#ifdef HAVE_X11_XLIB_H |
|---|
| 872 |
if( config_GetInt( p_libvlc, "disable-screensaver" ) ) |
|---|
| 873 |
{ |
|---|
| 874 |
libvlc_InternalAddIntf( p_libvlc, "screensaver,none" ); |
|---|
| 875 |
} |
|---|
| 876 |
#endif |
|---|
| 877 |
|
|---|
| 878 |
if( config_GetInt( p_libvlc, "file-logging" ) > 0 ) |
|---|
| 879 |
{ |
|---|
| 880 |
libvlc_InternalAddIntf( p_libvlc, "logger,none" ); |
|---|
| 881 |
} |
|---|
| 882 |
#ifdef HAVE_SYSLOG_H |
|---|
| 883 |
if( config_GetInt( p_libvlc, "syslog" ) > 0 ) |
|---|
| 884 |
{ |
|---|
| 885 |
char *logmode = var_CreateGetString( p_libvlc, |
|---|