1 /*****************************************************************************
2 * libvlc.c: main libvlc source
3 *****************************************************************************
4 * Copyright (C) 1998-2002 VideoLAN
5 * $Id: libvlc.c,v 1.36 2002/10/04 18:07:22 sam Exp $
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Gildas Bazin <gbazin@netcourrier.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
27 * Pretend we are a builtin module
28 *****************************************************************************/
29 #define MODULE_NAME main
30 #define MODULE_PATH main
33 /*****************************************************************************
35 *****************************************************************************/
36 #include <errno.h> /* ENOMEM */
37 #include <stdio.h> /* sprintf() */
38 #include <string.h> /* strerror() */
39 #include <stdlib.h> /* free() */
44 # include <netinet/in.h> /* BSD: struct in_addr */
49 #elif defined( _MSC_VER ) && defined( _WIN32 )
53 #ifdef WIN32 /* optind, getopt(), included in unistd.h */
54 # include "extras/GNUgetopt/getopt.h"
61 #include "vlc_cpu.h" /* CPU detection */
62 #include "os_specific.h"
64 #include "netutils.h" /* network_ChannelJoin */
66 #include "stream_control.h"
67 #include "input_ext-intf.h"
69 #include "vlc_playlist.h"
70 #include "interface.h"
72 #include "audio_output.h"
75 #include "video_output.h"
79 /*****************************************************************************
80 * The evil global variable. We handle it with care, don't worry.
81 *****************************************************************************/
82 static libvlc_t libvlc;
84 //#define GLOBAL_VLC NULL
85 #define GLOBAL_VLC ((vlc_t*)libvlc.pp_children[1])
87 /*****************************************************************************
89 *****************************************************************************/
90 static int GetFilenames ( vlc_t *, int, char *[] );
91 static void Usage ( vlc_t *, const char *psz_module_name );
92 static void ListModules ( vlc_t * );
93 static void Version ( void );
96 static void ShowConsole ( void );
99 /*****************************************************************************
100 * vlc_create: allocate a vlc_t structure, and initialize libvlc if needed.
101 *****************************************************************************
102 * This function allocates a vlc_t structure and returns NULL in case of
103 * failure. Also, the thread system is initialized.
104 *****************************************************************************/
105 vlc_error_t vlc_create( void )
108 vlc_bool_t b_failed = VLC_FALSE;
110 /* This call should be thread-safe, but an additional check will be
111 * necessary afterwards to check that only one p_vlc is created. */
112 p_vlc = vlc_create_r();
119 /* We have created an object, which ensures us that p_global_lock has
120 * been properly initialized. We can now atomically check that we are
121 * the only p_vlc object. */
123 vlc_mutex_lock( libvlc.p_global_lock );
124 if( libvlc.i_children != 1 ) /* FIXME !!! FIXME */
128 vlc_mutex_unlock( libvlc.p_global_lock );
131 /* There can be only one */
134 vlc_destroy_r( p_vlc );
141 vlc_t * vlc_create_r( void )
144 vlc_t * p_vlc = NULL;
145 vlc_mutex_t * p_libvlc_lock;
147 /* vlc_threads_init *must* be the first internal call! No other call is
148 * allowed before the thread system has been initialized. */
149 i_ret = vlc_threads_init( &libvlc );
155 /* Now that the thread system is initialized, we don't have much, but
156 * at least we have vlc_mutex_need */
157 p_libvlc_lock = vlc_mutex_need( &libvlc, "libvlc" );
158 vlc_mutex_lock( p_libvlc_lock );
159 if( !libvlc.b_ready )
163 /* Guess what CPU we have */
164 libvlc.i_cpu = CPUCapabilities();
166 /* Find verbosity from VLC_VERBOSE environment variable */
167 psz_env = getenv( "VLC_VERBOSE" );
168 libvlc.i_verbose = psz_env ? atoi( psz_env ) : 0;
171 libvlc.b_color = isatty( 2 ); /* 2 is for stderr */
173 libvlc.b_color = VLC_FALSE;
176 /* Initialize message queue */
177 msg_Create( &libvlc );
179 /* Announce who we are */
180 msg_Dbg( &libvlc, COPYRIGHT_MESSAGE );
181 msg_Dbg( &libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
183 /* Initialize the module bank and load the configuration of the
184 * main module. We need to do this at this stage to be able to display
185 * a short help if required by the user. (short help == main module
187 module_InitBank( &libvlc );
188 module_LoadMain( &libvlc );
190 libvlc.b_ready = VLC_TRUE;
192 vlc_mutex_unlock( p_libvlc_lock );
193 vlc_mutex_unneed( &libvlc, "libvlc" );
195 /* Allocate a vlc object */
196 p_vlc = vlc_object_create( &libvlc, VLC_OBJECT_VLC );
202 p_vlc->psz_object_name = "root";
204 /* Initialize mutexes */
205 vlc_mutex_init( p_vlc, &p_vlc->config_lock );
207 /* Store our newly allocated structure in the global list */
208 vlc_object_attach( p_vlc, &libvlc );
210 /* Update the handle status */
211 p_vlc->i_status = VLC_STATUS_CREATED;
216 /*****************************************************************************
217 * vlc_init: initialize a vlc_t structure.
218 *****************************************************************************
219 * This function initializes a previously allocated vlc_t structure:
221 * - gettext initialization
222 * - message queue, module bank and playlist initialization
223 * - configuration and commandline parsing
224 *****************************************************************************/
225 vlc_error_t vlc_init( int i_argc, char *ppsz_argv[] )
227 return vlc_init_r( GLOBAL_VLC, i_argc, ppsz_argv );
230 vlc_error_t vlc_init_r( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
232 char p_capabilities[200];
235 module_t *p_help_module;
236 playlist_t *p_playlist;
238 /* Check that the handle is valid */
239 if( !p_vlc || p_vlc->i_status != VLC_STATUS_CREATED )
241 fprintf( stderr, "error: invalid status (!CREATED)\n" );
245 /* Support for gettext */
246 #if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT )
247 # if defined( HAVE_LOCALE_H ) && defined( HAVE_LC_MESSAGES )
248 if( !setlocale( LC_MESSAGES, "" ) )
250 fprintf( stderr, "warning: unsupported locale settings\n" );
253 setlocale( LC_CTYPE, "" );
256 if( !bindtextdomain( PACKAGE, LOCALEDIR ) )
258 fprintf( stderr, "warning: no domain %s in directory %s\n",
259 PACKAGE, LOCALEDIR );
262 textdomain( PACKAGE );
266 * System specific initialization code
268 system_Init( p_vlc, &i_argc, ppsz_argv );
270 /* Get the executable name (similar to the basename command) */
273 p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
276 if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
282 p_vlc->psz_object_name = "vlc";
285 /* Hack: insert the help module here */
286 p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
287 if( p_help_module == NULL )
289 //module_EndBank( p_vlc );
292 p_help_module->psz_object_name = "help";
293 config_Duplicate( p_help_module, p_help_config );
294 vlc_object_attach( p_help_module, libvlc.p_module_bank );
297 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE ) )
299 vlc_object_detach( p_help_module );
300 config_Free( p_help_module );
301 vlc_object_destroy( p_help_module );
302 //module_EndBank( p_vlc );
308 /* Check for short help option */
309 if( config_GetInt( p_vlc, "help" ) )
311 fprintf( stderr, _("Usage: %s [options] [items]...\n\n"),
312 p_vlc->psz_object_name );
313 Usage( p_vlc, "main" );
314 Usage( p_vlc, "help" );
317 /* Check for version option */
318 else if( config_GetInt( p_vlc, "version" ) )
324 /* Hack: remove the help module here */
325 vlc_object_detach( p_help_module );
330 config_Free( p_help_module );
331 vlc_object_destroy( p_help_module );
332 //module_EndBank( p_vlc );
337 * Load the builtins and plugins into the module_bank.
338 * We have to do it before config_Load*() because this also gets the
339 * list of configuration options exported by each module and loads their
342 module_LoadBuiltins( &libvlc );
343 module_LoadPlugins( &libvlc );
344 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
345 libvlc.p_module_bank->i_children );
347 /* Hack: insert the help module here */
348 vlc_object_attach( p_help_module, libvlc.p_module_bank );
351 /* Check for help on modules */
352 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
354 Usage( p_vlc, p_tmp );
358 /* Check for long help option */
359 else if( config_GetInt( p_vlc, "longhelp" ) )
361 Usage( p_vlc, NULL );
364 /* Check for module list option */
365 else if( config_GetInt( p_vlc, "list" ) )
367 ListModules( p_vlc );
371 /* Hack: remove the help module here */
372 vlc_object_detach( p_help_module );
373 config_Free( p_help_module );
374 vlc_object_destroy( p_help_module );
379 //module_EndBank( p_vlc );
384 * Override default configuration with config file settings
386 p_vlc->psz_homedir = config_GetHomeDir();
387 config_LoadConfigFile( p_vlc, NULL );
390 * Override configuration with command line settings
392 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
396 /* Pause the console because it's destroyed when we exit */
397 fprintf( stderr, "The command line options couldn't be loaded, check "
398 "that they are valid.\nPress the RETURN key to continue..." );
401 //module_EndBank( p_vlc );
406 * System specific configuration
408 system_Configure( p_vlc );
411 * Message queue options
413 if( config_GetInt( p_vlc, "quiet" ) )
415 libvlc.i_verbose = 0;
419 int i_tmp = config_GetInt( p_vlc, "verbose" );
422 libvlc.i_verbose = __MIN( i_tmp, 4 );
425 libvlc.b_color = libvlc.b_color || config_GetInt( p_vlc, "color" );
428 * Output messages that may still be in the queue
432 /* p_vlc inititalization. FIXME ? */
433 p_vlc->i_desync = config_GetInt( p_vlc, "desync" ) * (mtime_t)1000;
435 #if defined( __i386__ )
436 if( !config_GetInt( p_vlc, "mmx" ) )
437 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
438 if( !config_GetInt( p_vlc, "3dn" ) )
439 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
440 if( !config_GetInt( p_vlc, "mmxext" ) )
441 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
442 if( !config_GetInt( p_vlc, "sse" ) )
443 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
445 #if defined( __powerpc__ ) || defined( SYS_DARWIN )
446 if( !config_GetInt( p_vlc, "altivec" ) )
447 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
450 #define PRINT_CAPABILITY( capability, string ) \
451 if( libvlc.i_cpu & capability ) \
453 strncat( p_capabilities, string " ", \
454 sizeof(p_capabilities) - strlen(p_capabilities) ); \
455 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
458 p_capabilities[0] = '\0';
459 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
460 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
461 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
462 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
463 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
464 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
465 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
466 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
467 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
468 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
471 * Choose the best memcpy module
473 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy" );
475 if( p_vlc->pf_memcpy == NULL )
477 p_vlc->pf_memcpy = memcpy;
480 if( p_vlc->pf_memset == NULL )
482 p_vlc->pf_memset = memset;
486 * Initialize shared resources and libraries
488 if( config_GetInt( p_vlc, "network-channel" )
489 && network_ChannelCreate( p_vlc ) )
491 /* On error during Channels initialization, switch off channels */
493 "channels initialization failed, deactivating channels" );
494 config_PutInt( p_vlc, "network-channel", VLC_FALSE );
498 * Initialize playlist and get commandline files
500 p_playlist = playlist_Create( p_vlc );
503 msg_Err( p_vlc, "playlist initialization failed" );
504 if( p_vlc->p_memcpy_module != NULL )
506 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
508 //module_EndBank( p_vlc );
512 /* Update the handle status */
513 p_vlc->i_status = VLC_STATUS_STOPPED;
516 * Get input filenames given as commandline arguments
518 GetFilenames( p_vlc, i_argc, ppsz_argv );
523 /*****************************************************************************
524 * vlc_add_intf: add an interface
525 *****************************************************************************
526 * This function opens an interface plugin and runs it. If b_block is set
527 * to 0, vlc_add_intf will return immediately and let the interface run in a
528 * separate thread. If b_block is set to 1, vlc_add_intf will continue until
529 * user requests to quit.
530 *****************************************************************************/
531 vlc_error_t vlc_add_intf( const char *psz_module, vlc_bool_t b_block )
533 return vlc_add_intf_r( GLOBAL_VLC,
534 psz_module, b_block );
537 vlc_error_t vlc_add_intf_r( vlc_t *p_vlc, const char *psz_module,
541 intf_thread_t *p_intf;
542 char *psz_oldmodule = NULL;
544 /* Check that the handle is valid */
545 if( !p_vlc || p_vlc->i_status != VLC_STATUS_RUNNING )
547 fprintf( stderr, "error: invalid status (!RUNNING)\n" );
553 psz_oldmodule = config_GetPsz( p_vlc, "intf" );
554 config_PutPsz( p_vlc, "intf", psz_module );
557 /* Try to create the interface */
558 p_intf = intf_Create( p_vlc );
562 config_PutPsz( p_vlc, "intf", psz_oldmodule );
565 free( psz_oldmodule );
571 msg_Err( p_vlc, "interface initialization failed" );
575 /* Try to run the interface */
576 p_intf->b_block = b_block;
577 err = intf_RunThread( p_intf );
580 vlc_object_detach( p_intf );
581 intf_Destroy( p_intf );
588 /*****************************************************************************
589 * vlc_destroy: stop playing and destroy everything.
590 *****************************************************************************
591 * This function requests the running threads to finish, waits for their
592 * termination, and destroys their structure.
593 *****************************************************************************/
594 vlc_error_t vlc_destroy( void )
596 return vlc_destroy_r( GLOBAL_VLC );
599 vlc_error_t vlc_destroy_r( vlc_t *p_vlc )
601 /* Check that the handle is valid */
602 if( !p_vlc || (p_vlc->i_status != VLC_STATUS_STOPPED
603 && p_vlc->i_status != VLC_STATUS_CREATED) )
605 fprintf( stderr, "error: invalid status "
606 "(!STOPPED&&!CREATED)\n" );
610 if( p_vlc->i_status == VLC_STATUS_STOPPED )
613 * Go back into channel 0 which is the network
615 if( config_GetInt( p_vlc, "network-channel" ) && p_vlc->p_channel )
617 network_ChannelJoin( p_vlc, COMMON_CHANNEL );
621 * Free allocated memory
623 if( p_vlc->p_memcpy_module != NULL )
625 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
628 free( p_vlc->psz_homedir );
631 * XXX: Free module bank !
633 //module_EndBank( p_vlc );
636 * System specific cleaning code
640 /* Update the handle status */
641 p_vlc->i_status = VLC_STATUS_CREATED;
644 /* Update the handle status, just in case */
645 p_vlc->i_status = VLC_STATUS_NONE;
647 /* Destroy mutexes */
648 vlc_mutex_destroy( &p_vlc->config_lock );
650 vlc_object_detach( p_vlc );
652 vlc_object_destroy( p_vlc );
654 /* Stop thread system: last one out please shut the door! */
655 vlc_threads_end( &libvlc );
660 /*****************************************************************************
661 * vlc_die: ask vlc to die.
662 *****************************************************************************
663 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
664 * task. It is your duty to call vlc_end and vlc_destroy afterwards.
665 *****************************************************************************/
666 vlc_error_t vlc_die( void )
668 return vlc_die_r( GLOBAL_VLC );
671 vlc_error_t vlc_die_r( vlc_t *p_vlc )
675 fprintf( stderr, "error: invalid status (!EXIST)\n" );
679 p_vlc->b_die = VLC_TRUE;
684 /*****************************************************************************
685 * vlc_status: return the current vlc status.
686 *****************************************************************************
687 * This function returns the current value of p_vlc->i_status.
688 *****************************************************************************/
689 vlc_status_t vlc_status( void )
691 return vlc_status_r( GLOBAL_VLC );
694 vlc_status_t vlc_status_r( vlc_t *p_vlc )
698 return VLC_STATUS_NONE;
701 return p_vlc->i_status;
704 /*****************************************************************************
705 * vlc_add_target: adds a target for playing.
706 *****************************************************************************
707 * This function adds psz_target to the current playlist. If a playlist does
708 * not exist, it will create one.
709 *****************************************************************************/
710 vlc_error_t vlc_add_target( const char *psz_target, int i_mode, int i_pos )
712 return vlc_add_target_r( GLOBAL_VLC,
713 psz_target, i_mode, i_pos );
716 vlc_error_t vlc_add_target_r( vlc_t *p_vlc, const char *psz_target,
717 int i_mode, int i_pos )
720 playlist_t *p_playlist;
722 if( !p_vlc || ( p_vlc->i_status != VLC_STATUS_STOPPED
723 && p_vlc->i_status != VLC_STATUS_RUNNING ) )
725 fprintf( stderr, "error: invalid status (!STOPPED&&!RUNNING)\n" );
729 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
731 if( p_playlist == NULL )
733 msg_Dbg( p_vlc, "no playlist present, creating one" );
734 p_playlist = playlist_Create( p_vlc );
736 if( p_playlist == NULL )
741 vlc_object_yield( p_playlist );
744 err = playlist_Add( p_playlist, psz_target, i_mode, i_pos );
746 vlc_object_release( p_playlist );
751 /*****************************************************************************
752 * vlc_set: set a vlc variable
753 *****************************************************************************
755 *****************************************************************************/
756 vlc_error_t vlc_set( const char *psz_var, const char *psz_val )
758 return vlc_set_r( GLOBAL_VLC, psz_var, psz_val );
761 vlc_error_t vlc_set_r( vlc_t *p_vlc, const char *psz_var, const char *psz_val )
763 module_config_t *p_config;
767 fprintf( stderr, "error: invalid status\n" );
771 p_config = config_FindConfig( VLC_OBJECT(p_vlc), psz_var );
775 msg_Err( p_vlc, "option %s does not exist", psz_var );
779 vlc_mutex_lock( p_config->p_lock );
781 switch( p_config->i_type )
783 case CONFIG_ITEM_BOOL:
784 if( psz_val && *psz_val )
786 if( !strcmp( psz_val, "off" ) || !strcmp( psz_val, "no" ) )
788 p_config->i_value = VLC_FALSE;
792 p_config->i_value = atoi( psz_val );
797 p_config->i_value = VLC_TRUE;
800 case CONFIG_ITEM_INTEGER:
801 if( psz_val && *psz_val )
803 p_config->i_value = atoi( psz_val );
807 p_config->i_value = 0;
810 case CONFIG_ITEM_FLOAT:
811 if( psz_val && *psz_val )
813 p_config->f_value = (float)atof( psz_val );
817 p_config->f_value = 0.0;
820 case CONFIG_ITEM_STRING:
821 case CONFIG_ITEM_FILE:
822 case CONFIG_ITEM_MODULE:
824 if( p_config->psz_value )
826 free( p_config->psz_value );
831 p_config->psz_value = strdup( psz_val );
835 p_config->psz_value = NULL;
840 if( p_config->pf_callback )
842 vlc_mutex_unlock( p_config->p_lock );
843 p_config->pf_callback( VLC_OBJECT(p_vlc) );
847 vlc_mutex_unlock( p_config->p_lock );
853 /* XXX: temporary hacks */
855 /*****************************************************************************
857 *****************************************************************************/
858 vlc_error_t vlc_play( )
860 return vlc_play_r( GLOBAL_VLC );
863 vlc_error_t vlc_play_r( vlc_t *p_vlc )
865 playlist_t * p_playlist;
867 /* Check that the handle is valid */
868 if( !p_vlc || p_vlc->i_status != VLC_STATUS_STOPPED )
870 fprintf( stderr, "error: invalid status (!STOPPED)\n" );
874 /* Update the handle status */
875 p_vlc->i_status = VLC_STATUS_RUNNING;
877 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
884 vlc_mutex_lock( &p_playlist->object_lock );
885 if( p_playlist->i_size )
887 vlc_mutex_unlock( &p_playlist->object_lock );
888 playlist_Play( p_playlist );
892 vlc_mutex_unlock( &p_playlist->object_lock );
895 vlc_object_release( p_playlist );
900 /*****************************************************************************
902 *****************************************************************************/
903 vlc_error_t vlc_stop( )
905 return vlc_stop_r( GLOBAL_VLC );
908 vlc_error_t vlc_stop_r( vlc_t *p_vlc )
910 intf_thread_t * p_intf;
911 playlist_t * p_playlist;
912 vout_thread_t * p_vout;
913 aout_instance_t * p_aout;
915 /* Check that the handle is valid */
916 if( !p_vlc || ( p_vlc->i_status != VLC_STATUS_STOPPED
917 && p_vlc->i_status != VLC_STATUS_RUNNING ) )
919 fprintf( stderr, "error: invalid status (!STOPPED&&!RUNNING)\n" );
924 * Ask the interfaces to stop and destroy them
926 msg_Dbg( p_vlc, "removing all interfaces" );
927 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
929 intf_StopThread( p_intf );
930 vlc_object_detach( p_intf );
931 vlc_object_release( p_intf );
932 intf_Destroy( p_intf );
938 msg_Dbg( p_vlc, "removing all playlists" );
939 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
942 vlc_object_detach( p_playlist );
943 vlc_object_release( p_playlist );
944 playlist_Destroy( p_playlist );
950 msg_Dbg( p_vlc, "removing all video outputs" );
951 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
953 vlc_object_detach( p_vout );
954 vlc_object_release( p_vout );
955 vout_DestroyThread( p_vout );
961 msg_Dbg( p_vlc, "removing all audio outputs" );
962 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
964 vlc_object_detach( (vlc_object_t *)p_aout );
965 vlc_object_release( (vlc_object_t *)p_aout );
966 aout_Delete( p_aout );
969 /* Update the handle status */
970 p_vlc->i_status = VLC_STATUS_STOPPED;
975 /*****************************************************************************
976 * vlc_pause: toggle pause
977 *****************************************************************************/
978 vlc_error_t vlc_pause( )
980 return vlc_pause_r( GLOBAL_VLC );
983 vlc_error_t vlc_pause_r( vlc_t *p_vlc )
985 input_thread_t *p_input;
987 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
994 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
995 vlc_object_release( p_input );
1000 /*****************************************************************************
1001 * vlc_fullscreen: toggle fullscreen mode
1002 *****************************************************************************/
1003 vlc_error_t vlc_fullscreen( )
1005 return vlc_fullscreen_r( GLOBAL_VLC );
1008 vlc_error_t vlc_fullscreen_r( vlc_t *p_vlc )
1010 vout_thread_t *p_vout;
1012 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1019 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1020 vlc_object_release( p_vout );
1025 /* following functions are local */
1027 /*****************************************************************************
1028 * GetFilenames: parse command line options which are not flags
1029 *****************************************************************************
1030 * Parse command line for input files.
1031 *****************************************************************************/
1032 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
1036 /* We assume that the remaining parameters are filenames */
1037 for( i_opt = optind; i_opt < i_argc; i_opt++ )
1039 vlc_add_target_r( p_vlc, ppsz_argv[ i_opt ],
1040 PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
1046 /*****************************************************************************
1047 * Usage: print program usage
1048 *****************************************************************************
1049 * Print a short inline help. Message interface is initialized at this stage.
1050 *****************************************************************************/
1051 static void Usage( vlc_t *p_this, const char *psz_module_name )
1053 #define FORMAT_STRING " --%s%s%s%s%s%s%s %s%s\n"
1054 /* option name -------------' | | | | | |
1055 * <bra --------------------------' | | | | |
1056 * option type or "" ---------------' | | | |
1057 * ket> ------------------------------' | | |
1058 * padding spaces ----------------------' | |
1059 * comment --------------------------------' |
1060 * comment suffix ---------------------------'
1062 * The purpose of having bra and ket is that we might i18n them as well.
1064 #define LINE_START 8
1065 #define PADDING_SPACES 25
1067 module_t **pp_parser;
1068 module_config_t *p_item;
1069 char psz_spaces[PADDING_SPACES+LINE_START+1];
1070 char psz_format[sizeof(FORMAT_STRING)];
1072 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
1073 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
1075 strcpy( psz_format, FORMAT_STRING );
1081 /* List all modules */
1082 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1084 /* Enumerate the config for each module */
1085 for( pp_parser = (module_t **)p_list->pp_objects ;
1089 vlc_bool_t b_help_module;
1091 if( psz_module_name && strcmp( psz_module_name,
1092 (*pp_parser)->psz_object_name ) )
1097 /* Ignore modules without config options */
1098 if( !(*pp_parser)->i_config_items )
1103 b_help_module = !strcmp( "help", (*pp_parser)->psz_object_name );
1105 /* Print module options */
1106 for( p_item = (*pp_parser)->p_config;
1107 p_item->i_type != CONFIG_HINT_END;
1110 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1111 char *psz_suf = "", *psz_prefix = NULL;
1114 switch( p_item->i_type )
1116 case CONFIG_HINT_CATEGORY:
1117 case CONFIG_HINT_USAGE:
1118 fprintf( stderr, " %s\n", p_item->psz_text );
1121 case CONFIG_ITEM_STRING:
1122 case CONFIG_ITEM_FILE:
1123 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1124 if( !p_item->ppsz_list )
1126 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1132 psz_type = malloc( 1000 );
1133 memset( psz_type, 0, 1000 );
1134 for( i=0; p_item->ppsz_list[i]; i++ )
1136 strcat( psz_type, p_item->ppsz_list[i] );
1137 strcat( psz_type, "|" );
1139 psz_type[ strlen( psz_type ) - 1 ] = '\0';
1143 case CONFIG_ITEM_INTEGER:
1144 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1146 case CONFIG_ITEM_FLOAT:
1147 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1149 case CONFIG_ITEM_BOOL:
1150 psz_bra = ""; psz_type = ""; psz_ket = "";
1151 if( !b_help_module )
1153 psz_suf = p_item->i_value ? _(" (default enabled)") :
1154 _(" (default disabled)");
1159 /* Add short option if any */
1160 if( p_item->i_short )
1162 psz_format[2] = '-';
1163 psz_format[3] = p_item->i_short;
1164 psz_format[4] = ',';
1168 psz_format[2] = ' ';
1169 psz_format[3] = ' ';
1170 psz_format[4] = ' ';
1175 i = PADDING_SPACES - strlen( p_item->psz_name )
1176 - strlen( psz_bra ) - strlen( psz_type )
1177 - strlen( psz_ket ) - 1;
1178 if( p_item->i_type == CONFIG_ITEM_BOOL
1181 /* If option is of type --foo-bar, we print its counterpart
1182 * as --no-foo-bar, but if it is of type --foobar (without
1183 * dashes in the name) we print it as --nofoobar. Both
1184 * values are of course valid, only the display changes. */
1185 vlc_bool_t b_dash = VLC_FALSE;
1186 psz_prefix = p_item->psz_name;
1187 while( *psz_prefix )
1189 if( *psz_prefix++ == '-' )
1198 psz_prefix = ", --no-";
1199 i -= strlen( p_item->psz_name ) + strlen( ", --no-" );
1203 psz_prefix = ", --no";
1204 i -= strlen( p_item->psz_name ) + strlen( ", --no" );
1211 psz_spaces[i] = '\n';
1215 psz_spaces[i] = '\0';
1218 if( p_item->i_type == CONFIG_ITEM_BOOL &&
1221 fprintf( stderr, psz_format, p_item->psz_name, psz_prefix,
1222 p_item->psz_name, psz_bra, psz_type, psz_ket,
1223 psz_spaces, p_item->psz_text, psz_suf );
1227 fprintf( stderr, psz_format, p_item->psz_name, "", "",
1228 psz_bra, psz_type, psz_ket, psz_spaces,
1229 p_item->psz_text, psz_suf );
1231 psz_spaces[i] = ' ';
1232 if ( p_item->ppsz_list )
1240 /* Release the module list */
1241 vlc_list_release( p_list );
1243 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1244 fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
1249 /*****************************************************************************
1250 * ListModules: list the available modules with their description
1251 *****************************************************************************
1252 * Print a list of all available modules (builtins and plugins) and a short
1253 * description for each one.
1254 *****************************************************************************/
1255 static void ListModules( vlc_t *p_this )
1258 module_t **pp_parser;
1259 char psz_spaces[22];
1261 memset( psz_spaces, ' ', 22 );
1268 fprintf( stderr, _("Usage: %s [options] [items]...\n\n"),
1269 p_this->p_vlc->psz_object_name );
1271 fprintf( stderr, _("[module] [description]\n") );
1273 /* List all modules */
1274 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1276 /* Enumerate each module */
1277 for( pp_parser = (module_t **)p_list->pp_objects ;
1283 /* Nasty hack, but right now I'm too tired to think about a nice
1285 i = 22 - strlen( (*pp_parser)->psz_object_name ) - 1;
1289 fprintf( stderr, " %s%s %s\n", (*pp_parser)->psz_object_name,
1290 psz_spaces, (*pp_parser)->psz_longname );
1292 psz_spaces[i] = ' ';
1295 vlc_list_release( p_list );
1297 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1298 fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
1303 /*****************************************************************************
1304 * Version: print complete program version
1305 *****************************************************************************
1306 * Print complete program version and build number.
1307 *****************************************************************************/
1308 static void Version( void )
1314 fprintf( stderr, VERSION_MESSAGE "\n" );
1316 _("This program comes with NO WARRANTY, to the extent permitted by "
1317 "law.\nYou may redistribute it under the terms of the GNU General "
1318 "Public License;\nsee the file named COPYING for details.\n"
1319 "Written by the VideoLAN team at Ecole Centrale, Paris.\n") );
1321 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1322 fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
1327 /*****************************************************************************
1328 * ShowConsole: On Win32, create an output console for debug messages
1329 *****************************************************************************
1330 * This function is useful only on Win32.
1331 *****************************************************************************/
1333 static void ShowConsole( void )
1336 freopen( "CONOUT$", "w", stdout );
1337 freopen( "CONOUT$", "w", stderr );
1338 freopen( "CONIN$", "r", stdin );