]> git.sesse.net Git - vlc/blob - src/libvlc.c
* all: rework of the input.
[vlc] / src / libvlc.c
1 /*****************************************************************************
2  * libvlc.c: main libvlc source
3  *****************************************************************************
4  * Copyright (C) 1998-2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Vincent Seguin <seguin@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          Gildas Bazin <gbazin@netcourrier.com>
10  *          Derk-Jan Hartman <hartman at videolan dot org>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
25  *****************************************************************************/
26
27 /*****************************************************************************
28  * Pretend we are a builtin module
29  *****************************************************************************/
30 #define MODULE_NAME main
31 #define MODULE_PATH main
32 #define __BUILTIN__
33
34 /*****************************************************************************
35  * Preamble
36  *****************************************************************************/
37 #include <vlc/vlc.h>
38 #include <vlc/input.h>
39
40 #ifdef HAVE_ERRNO_H
41 #   include <errno.h>                                              /* ENOMEM */
42 #endif
43 #include <stdio.h>                                              /* sprintf() */
44 #include <string.h>                                            /* strerror() */
45 #include <stdlib.h>                                                /* free() */
46
47 #ifndef WIN32
48 #   include <netinet/in.h>                            /* BSD: struct in_addr */
49 #endif
50
51 #ifdef HAVE_UNISTD_H
52 #   include <unistd.h>
53 #elif defined( WIN32 ) && !defined( UNDER_CE )
54 #   include <io.h>
55 #endif
56
57 #ifdef WIN32                       /* optind, getopt(), included in unistd.h */
58 #   include "extras/getopt.h"
59 #endif
60
61 #ifdef HAVE_LOCALE_H
62 #   include <locale.h>
63 #endif
64
65 #include "vlc_cpu.h"                                        /* CPU detection */
66 #include "os_specific.h"
67
68 #include "vlc_error.h"
69
70 #include "vlc_playlist.h"
71 #include "vlc_interface.h"
72
73 #include "audio_output.h"
74
75 #include "vlc_video.h"
76 #include "video_output.h"
77
78 #include "stream_output.h"
79
80 #include "libvlc.h"
81
82 /*****************************************************************************
83  * The evil global variable. We handle it with care, don't worry.
84  *****************************************************************************/
85 static libvlc_t   libvlc;
86 static libvlc_t * p_libvlc;
87 static vlc_t *    p_static_vlc;
88
89 /*****************************************************************************
90  * Local prototypes
91  *****************************************************************************/
92 static void SetLanguage   ( char const * );
93 static int  GetFilenames  ( vlc_t *, int, char *[] );
94 static void Usage         ( vlc_t *, char const *psz_module_name );
95 static void ListModules   ( vlc_t * );
96 static void Version       ( void );
97
98 #ifdef WIN32
99 static void ShowConsole   ( void );
100 #endif
101 static int  ConsoleWidth  ( void );
102
103 static int  VerboseCallback( vlc_object_t *, char const *,
104                              vlc_value_t, vlc_value_t, void * );
105
106 /*****************************************************************************
107  * vlc_current_object: return the current object.
108  *****************************************************************************
109  * If i_object is non-zero, return the corresponding object. Otherwise,
110  * return the statically allocated p_vlc object.
111  *****************************************************************************/
112 vlc_t * vlc_current_object( int i_object )
113 {
114     if( i_object )
115     {
116          return vlc_object_get( p_libvlc, i_object );
117     }
118
119     return p_static_vlc;
120 }
121
122 /*****************************************************************************
123  * VLC_Version: return the libvlc version.
124  *****************************************************************************
125  * This function returns full version string (numeric version and codename).
126  *****************************************************************************/
127 char const * VLC_Version( void )
128 {
129     return VERSION_MESSAGE;
130 }
131
132 /*****************************************************************************
133  * VLC_Error: strerror() equivalent
134  *****************************************************************************
135  * This function returns full version string (numeric version and codename).
136  *****************************************************************************/
137 char const * VLC_Error( int i_err )
138 {
139     return vlc_error( i_err );
140 }
141
142 /*****************************************************************************
143  * VLC_Create: allocate a vlc_t structure, and initialize libvlc if needed.
144  *****************************************************************************
145  * This function allocates a vlc_t structure and returns a negative value
146  * in case of failure. Also, the thread system is initialized.
147  *****************************************************************************/
148 int VLC_Create( void )
149 {
150     int i_ret;
151     vlc_t * p_vlc = NULL;
152     vlc_value_t lockval;
153
154     /* &libvlc never changes, so we can safely call this multiple times. */
155     p_libvlc = &libvlc;
156
157     /* vlc_threads_init *must* be the first internal call! No other call is
158      * allowed before the thread system has been initialized. */
159     i_ret = vlc_threads_init( p_libvlc );
160     if( i_ret < 0 )
161     {
162         return i_ret;
163     }
164
165     /* Now that the thread system is initialized, we don't have much, but
166      * at least we have var_Create */
167     var_Create( p_libvlc, "libvlc", VLC_VAR_MUTEX );
168     var_Get( p_libvlc, "libvlc", &lockval );
169     vlc_mutex_lock( lockval.p_address );
170     if( !libvlc.b_ready )
171     {
172         char *psz_env;
173
174         /* Guess what CPU we have */
175         libvlc.i_cpu = CPUCapabilities();
176
177         /* Find verbosity from VLC_VERBOSE environment variable */
178         psz_env = getenv( "VLC_VERBOSE" );
179         libvlc.i_verbose = psz_env ? atoi( psz_env ) : -1;
180
181 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
182         libvlc.b_color = isatty( 2 ); /* 2 is for stderr */
183 #else
184         libvlc.b_color = VLC_FALSE;
185 #endif
186
187         /* Initialize message queue */
188         msg_Create( p_libvlc );
189
190         /* Announce who we are */
191         msg_Dbg( p_libvlc, COPYRIGHT_MESSAGE );
192         msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
193
194         /* The module bank will be initialized later */
195         libvlc.p_module_bank = NULL;
196
197         libvlc.b_ready = VLC_TRUE;
198     }
199     vlc_mutex_unlock( lockval.p_address );
200     var_Destroy( p_libvlc, "libvlc" );
201
202     /* Allocate a vlc object */
203     p_vlc = vlc_object_create( p_libvlc, VLC_OBJECT_VLC );
204     if( p_vlc == NULL )
205     {
206         return VLC_EGENERIC;
207     }
208     p_vlc->thread_id = 0;
209     vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
210
211     p_vlc->psz_object_name = "root";
212
213     /* Initialize mutexes */
214     vlc_mutex_init( p_vlc, &p_vlc->config_lock );
215 #ifdef SYS_DARWIN
216     vlc_mutex_init( p_vlc, &p_vlc->quicktime_lock );
217 #endif
218
219     /* Store our newly allocated structure in the global list */
220     vlc_object_attach( p_vlc, p_libvlc );
221
222     /* Store data for the non-reentrant API */
223     p_static_vlc = p_vlc;
224
225     return p_vlc->i_object_id;
226 }
227
228 /*****************************************************************************
229  * VLC_Init: initialize a vlc_t structure.
230  *****************************************************************************
231  * This function initializes a previously allocated vlc_t structure:
232  *  - CPU detection
233  *  - gettext initialization
234  *  - message queue, module bank and playlist initialization
235  *  - configuration and commandline parsing
236  *****************************************************************************/
237 int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
238 {
239     char         p_capabilities[200];
240     char *       p_tmp;
241     char *       psz_modules;
242     char *       psz_parser;
243     char *       psz_language;
244     vlc_bool_t   b_exit = VLC_FALSE;
245     vlc_t *      p_vlc = vlc_current_object( i_object );
246     module_t    *p_help_module;
247     playlist_t  *p_playlist;
248
249     if( !p_vlc )
250     {
251         return VLC_ENOOBJ;
252     }
253
254     /*
255      * System specific initialization code
256      */
257     system_Init( p_vlc, &i_argc, ppsz_argv );
258
259     /* Get the executable name (similar to the basename command) */
260     if( i_argc > 0 )
261     {
262         p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
263         while( *p_tmp )
264         {
265             if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
266             else ++p_tmp;
267         }
268     }
269     else
270     {
271         p_vlc->psz_object_name = "vlc";
272     }
273
274     /*
275      * Support for gettext
276      */
277     SetLanguage( "" );
278
279     /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
280     msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
281
282     /* Initialize the module bank and load the configuration of the
283      * main module. We need to do this at this stage to be able to display
284      * a short help if required by the user. (short help == main module
285      * options) */
286     module_InitBank( p_vlc );
287
288     /* Hack: insert the help module here */
289     p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
290     if( p_help_module == NULL )
291     {
292         module_EndBank( p_vlc );
293         if( i_object ) vlc_object_release( p_vlc );
294         return VLC_EGENERIC;
295     }
296     p_help_module->psz_object_name = "help";
297     p_help_module->psz_longname = N_("Help options");
298     config_Duplicate( p_help_module, p_help_config );
299     vlc_object_attach( p_help_module, libvlc.p_module_bank );
300     /* End hack */
301
302     if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE ) )
303     {
304         vlc_object_detach( p_help_module );
305         config_Free( p_help_module );
306         vlc_object_destroy( p_help_module );
307         module_EndBank( p_vlc );
308         if( i_object ) vlc_object_release( p_vlc );
309         return VLC_EGENERIC;
310     }
311
312     /* Check for short help option */
313     if( config_GetInt( p_vlc, "help" ) )
314     {
315         fprintf( stdout, _("Usage: %s [options] [items]...\n"),
316                          p_vlc->psz_object_name );
317         Usage( p_vlc, "main" );
318         Usage( p_vlc, "help" );
319         b_exit = VLC_TRUE;
320     }
321     /* Check for version option */
322     else if( config_GetInt( p_vlc, "version" ) )
323     {
324         Version();
325         b_exit = VLC_TRUE;
326     }
327
328     /* Set the config file stuff */
329     p_vlc->psz_homedir = config_GetHomeDir();
330     p_vlc->psz_configfile = config_GetPsz( p_vlc, "config" );
331
332     /* Check for plugins cache options */
333     if( config_GetInt( p_vlc, "reset-plugins-cache" ) )
334     {
335         libvlc.p_module_bank->b_cache_delete = VLC_TRUE;
336     }
337
338     /* Hack: remove the help module here */
339     vlc_object_detach( p_help_module );
340     /* End hack */
341
342     if( b_exit )
343     {
344         config_Free( p_help_module );
345         vlc_object_destroy( p_help_module );
346         module_EndBank( p_vlc );
347         if( i_object ) vlc_object_release( p_vlc );
348         return VLC_EEXIT;
349     }
350
351     /* Check for translation config option */
352 #if defined( ENABLE_NLS ) \
353      && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
354
355     /* This ain't really nice to have to reload the config here but it seems
356      * the only way to do it. */
357     config_LoadConfigFile( p_vlc, "main" );
358     config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
359
360     /* Check if the user specified a custom language */
361     psz_language = config_GetPsz( p_vlc, "language" );
362     if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
363     {
364         vlc_bool_t b_cache_delete = libvlc.p_module_bank->b_cache_delete;
365
366         /* Reset the default domain */
367         SetLanguage( psz_language );
368
369         /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
370         msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
371
372         textdomain( PACKAGE );
373
374 #if defined( ENABLE_UTF8 )
375         bind_textdomain_codeset( PACKAGE, "UTF-8" );
376 #endif
377
378         module_EndBank( p_vlc );
379         module_InitBank( p_vlc );
380         config_LoadConfigFile( p_vlc, "main" );
381         config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
382         libvlc.p_module_bank->b_cache_delete = b_cache_delete;
383     }
384     if( psz_language ) free( psz_language );
385 #endif
386
387     /*
388      * Load the builtins and plugins into the module_bank.
389      * We have to do it before config_Load*() because this also gets the
390      * list of configuration options exported by each module and loads their
391      * default values.
392      */
393     module_LoadBuiltins( p_vlc );
394     module_LoadPlugins( p_vlc );
395     if( p_vlc->b_die )
396     {
397         b_exit = VLC_TRUE;
398     }
399
400     msg_Dbg( p_vlc, "module bank initialized, found %i modules",
401                     libvlc.p_module_bank->i_children );
402
403     /* Hack: insert the help module here */
404     vlc_object_attach( p_help_module, libvlc.p_module_bank );
405     /* End hack */
406
407     /* Check for help on modules */
408     if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
409     {
410         Usage( p_vlc, p_tmp );
411         free( p_tmp );
412         b_exit = VLC_TRUE;
413     }
414     /* Check for long help option */
415     else if( config_GetInt( p_vlc, "longhelp" ) )
416     {
417         Usage( p_vlc, NULL );
418         b_exit = VLC_TRUE;
419     }
420     /* Check for module list option */
421     else if( config_GetInt( p_vlc, "list" ) )
422     {
423         ListModules( p_vlc );
424         b_exit = VLC_TRUE;
425     }
426
427     /* Check for config file options */
428     if( config_GetInt( p_vlc, "reset-config" ) )
429     {
430         vlc_object_detach( p_help_module );
431         config_ResetAll( p_vlc );
432         config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
433         config_SaveConfigFile( p_vlc, NULL );
434         vlc_object_attach( p_help_module, libvlc.p_module_bank );
435     }
436     if( config_GetInt( p_vlc, "save-config" ) )
437     {
438         vlc_object_detach( p_help_module );
439         config_LoadConfigFile( p_vlc, NULL );
440         config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
441         config_SaveConfigFile( p_vlc, NULL );
442         vlc_object_attach( p_help_module, libvlc.p_module_bank );
443     }
444
445     /* Hack: remove the help module here */
446     vlc_object_detach( p_help_module );
447     /* End hack */
448
449     if( b_exit )
450     {
451         config_Free( p_help_module );
452         vlc_object_destroy( p_help_module );
453         module_EndBank( p_vlc );
454         if( i_object ) vlc_object_release( p_vlc );
455         return VLC_EEXIT;
456     }
457
458     /*
459      * Override default configuration with config file settings
460      */
461     config_LoadConfigFile( p_vlc, NULL );
462
463     /* Hack: insert the help module here */
464     vlc_object_attach( p_help_module, libvlc.p_module_bank );
465     /* End hack */
466
467     /*
468      * Override configuration with command line settings
469      */
470     if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
471     {
472 #ifdef WIN32
473         ShowConsole();
474         /* Pause the console because it's destroyed when we exit */
475         fprintf( stderr, "The command line options couldn't be loaded, check "
476                  "that they are valid.\nPress the RETURN key to continue..." );
477         getchar();
478 #endif
479         vlc_object_detach( p_help_module );
480         config_Free( p_help_module );
481         vlc_object_destroy( p_help_module );
482         module_EndBank( p_vlc );
483         if( i_object ) vlc_object_release( p_vlc );
484         return VLC_EGENERIC;
485     }
486
487     /* Hack: remove the help module here */
488     vlc_object_detach( p_help_module );
489     config_Free( p_help_module );
490     vlc_object_destroy( p_help_module );
491     /* End hack */
492
493     /*
494      * System specific configuration
495      */
496     system_Configure( p_vlc, &i_argc, ppsz_argv );
497
498     /*
499      * Message queue options
500      */
501
502     var_Create( p_vlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
503     if( config_GetInt( p_vlc, "quiet" ) )
504     {
505         vlc_value_t val;
506         val.i_int = -1;
507         var_Set( p_vlc, "verbose", val );
508     }
509     var_AddCallback( p_vlc, "verbose", VerboseCallback, NULL );
510     var_Change( p_vlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
511
512     libvlc.b_color = libvlc.b_color && config_GetInt( p_vlc, "color" );
513
514     /*
515      * Output messages that may still be in the queue
516      */
517     msg_Flush( p_vlc );
518
519     /* p_vlc initialization. FIXME ? */
520
521 #if defined( __i386__ )
522     if( !config_GetInt( p_vlc, "mmx" ) )
523         libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
524     if( !config_GetInt( p_vlc, "3dn" ) )
525         libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
526     if( !config_GetInt( p_vlc, "mmxext" ) )
527         libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
528     if( !config_GetInt( p_vlc, "sse" ) )
529         libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
530     if( !config_GetInt( p_vlc, "sse2" ) )
531         libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
532 #endif
533 #if defined( __powerpc__ ) || defined( SYS_DARWIN )
534     if( !config_GetInt( p_vlc, "altivec" ) )
535         libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
536 #endif
537
538 #define PRINT_CAPABILITY( capability, string )                              \
539     if( libvlc.i_cpu & capability )                                         \
540     {                                                                       \
541         strncat( p_capabilities, string " ",                                \
542                  sizeof(p_capabilities) - strlen(p_capabilities) );         \
543         p_capabilities[sizeof(p_capabilities) - 1] = '\0';                  \
544     }
545
546     p_capabilities[0] = '\0';
547     PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
548     PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
549     PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
550     PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
551     PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
552     PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
553     PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
554     PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
555     PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
556     PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
557     msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
558
559     /*
560      * Choose the best memcpy module
561      */
562     p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy", 0 );
563
564     if( p_vlc->pf_memcpy == NULL )
565     {
566         p_vlc->pf_memcpy = memcpy;
567     }
568
569     if( p_vlc->pf_memset == NULL )
570     {
571         p_vlc->pf_memset = memset;
572     }
573
574     /*
575      * Initialize hotkey handling
576      */
577     var_Create( p_vlc, "key-pressed", VLC_VAR_INTEGER );
578     p_vlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
579     /* Do a copy (we don't need to modify the strings) */
580     memcpy( p_vlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
581
582     /*
583      * Initialize playlist and get commandline files
584      */
585     p_playlist = playlist_Create( p_vlc );
586     if( !p_playlist )
587     {
588         msg_Err( p_vlc, "playlist initialization failed" );
589         if( p_vlc->p_memcpy_module != NULL )
590         {
591             module_Unneed( p_vlc, p_vlc->p_memcpy_module );
592         }
593         module_EndBank( p_vlc );
594         if( i_object ) vlc_object_release( p_vlc );
595         return VLC_EGENERIC;
596     }
597
598     /*
599      * Load background interfaces
600      */
601     psz_modules = config_GetPsz( p_vlc, "extraintf" );
602     psz_parser = psz_modules;
603     while ( psz_parser && *psz_parser )
604     {
605         char *psz_module, *psz_temp;
606         psz_module = psz_parser;
607         psz_parser = strchr( psz_module, ',' );
608         if ( psz_parser )
609         {
610             *psz_parser = '\0';
611             psz_parser++;
612         }
613         psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
614         if( psz_temp )
615         {
616             sprintf( psz_temp, "%s,none", psz_module );
617             VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
618             free( psz_temp );
619         }
620     }
621     if ( psz_modules )
622     {
623         free( psz_modules );
624     }
625
626     /*
627      * Allways load the hotkeys interface if it exists
628      */
629     VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
630
631     /*
632      * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
633      */
634     var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
635     var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
636     var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
637     var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
638     var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
639     var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
640     var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
641     var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
642     var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
643     var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
644     var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
645     var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
646
647     /*
648      * Get input filenames given as commandline arguments
649      */
650     GetFilenames( p_vlc, i_argc, ppsz_argv );
651
652     if( i_object ) vlc_object_release( p_vlc );
653     return VLC_SUCCESS;
654 }
655
656 /*****************************************************************************
657  * VLC_AddIntf: add an interface
658  *****************************************************************************
659  * This function opens an interface plugin and runs it. If b_block is set
660  * to 0, VLC_AddIntf will return immediately and let the interface run in a
661  * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
662  * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
663  * the playlist when it is completely initialised.
664  *****************************************************************************/
665 int VLC_AddIntf( int i_object, char const *psz_module,
666                  vlc_bool_t b_block, vlc_bool_t b_play )
667 {
668     int i_err;
669     intf_thread_t *p_intf;
670     vlc_t *p_vlc = vlc_current_object( i_object );
671
672     if( !p_vlc )
673     {
674         return VLC_ENOOBJ;
675     }
676
677     /* Try to create the interface */
678     p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf" );
679
680     if( p_intf == NULL )
681     {
682         msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
683         if( i_object ) vlc_object_release( p_vlc );
684         return VLC_EGENERIC;
685     }
686
687     /* Interface doesn't handle play on start so do it ourselves */
688     if( !p_intf->b_play && b_play ) VLC_Play( i_object );
689
690     /* Try to run the interface */
691     p_intf->b_play = b_play;
692     p_intf->b_block = b_block;
693     i_err = intf_RunThread( p_intf );
694     if( i_err )
695     {
696         vlc_object_detach( p_intf );
697         intf_Destroy( p_intf );
698         if( i_object ) vlc_object_release( p_vlc );
699         return i_err;
700     }
701
702     if( i_object ) vlc_object_release( p_vlc );
703     return VLC_SUCCESS;
704 }
705
706 /*****************************************************************************
707  * VLC_Die: ask vlc to die.
708  *****************************************************************************
709  * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
710  * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
711  *****************************************************************************/
712 int VLC_Die( int i_object )
713 {
714     vlc_t *p_vlc = vlc_current_object( i_object );
715
716     if( !p_vlc )
717     {
718         return VLC_ENOOBJ;
719     }
720
721     p_vlc->b_die = VLC_TRUE;
722
723     if( i_object ) vlc_object_release( p_vlc );
724     return VLC_SUCCESS;
725 }
726
727 /*****************************************************************************
728  * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
729  *****************************************************************************/
730 int VLC_CleanUp( int i_object )
731 {
732     intf_thread_t      * p_intf;
733     playlist_t         * p_playlist;
734     vout_thread_t      * p_vout;
735     aout_instance_t    * p_aout;
736     announce_handler_t * p_announce;
737     vlc_t *p_vlc = vlc_current_object( i_object );
738
739     /* Check that the handle is valid */
740     if( !p_vlc )
741     {
742         return VLC_ENOOBJ;
743     }
744
745     /*
746      * Ask the interfaces to stop and destroy them
747      */
748     msg_Dbg( p_vlc, "removing all interfaces" );
749     while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
750     {
751         intf_StopThread( p_intf );
752         vlc_object_detach( p_intf );
753         vlc_object_release( p_intf );
754         intf_Destroy( p_intf );
755     }
756
757     /*
758      * Free playlists
759      */
760     msg_Dbg( p_vlc, "removing all playlists" );
761     while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
762                                           FIND_CHILD )) )
763     {
764         vlc_object_detach( p_playlist );
765         vlc_object_release( p_playlist );
766         playlist_Destroy( p_playlist );
767     }
768
769     /*
770      * Free video outputs
771      */
772     msg_Dbg( p_vlc, "removing all video outputs" );
773     while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
774     {
775         vlc_object_detach( p_vout );
776         vlc_object_release( p_vout );
777         vout_Destroy( p_vout );
778     }
779
780     /*
781      * Free audio outputs
782      */
783     msg_Dbg( p_vlc, "removing all audio outputs" );
784     while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
785     {
786         vlc_object_detach( (vlc_object_t *)p_aout );
787         vlc_object_release( (vlc_object_t *)p_aout );
788         aout_Delete( p_aout );
789     }
790
791     /*
792      * Free announce handler(s?)
793      */
794     msg_Dbg( p_vlc, "removing announce handler" );
795     while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
796                                                  FIND_CHILD ) ) )
797    {
798         vlc_object_detach( p_announce );
799         vlc_object_release( p_announce );
800         announce_HandlerDestroy( p_announce );
801    }
802
803     if( i_object ) vlc_object_release( p_vlc );
804     return VLC_SUCCESS;
805 }
806
807 /*****************************************************************************
808  * VLC_Destroy: Destroy everything.
809  *****************************************************************************
810  * This function requests the running threads to finish, waits for their
811  * termination, and destroys their structure.
812  *****************************************************************************/
813 int VLC_Destroy( int i_object )
814 {
815     vlc_t *p_vlc = vlc_current_object( i_object );
816
817     if( !p_vlc )
818     {
819         return VLC_ENOOBJ;
820     }
821
822     /*
823      * Free allocated memory
824      */
825     if( p_vlc->p_memcpy_module )
826     {
827         module_Unneed( p_vlc, p_vlc->p_memcpy_module );
828         p_vlc->p_memcpy_module = NULL;
829     }
830
831     /*
832      * Free module bank !
833      */
834     module_EndBank( p_vlc );
835
836     if( p_vlc->psz_homedir )
837     {
838         free( p_vlc->psz_homedir );
839         p_vlc->psz_homedir = NULL;
840     }
841
842     if( p_vlc->psz_configfile )
843     {
844         free( p_vlc->psz_configfile );
845         p_vlc->psz_configfile = NULL;
846     }
847
848     if( p_vlc->p_hotkeys )
849     {
850         free( p_vlc->p_hotkeys );
851         p_vlc->p_hotkeys = NULL;
852     }
853
854     /*
855      * System specific cleaning code
856      */
857     system_End( p_vlc );
858
859     /* Destroy mutexes */
860     vlc_mutex_destroy( &p_vlc->config_lock );
861
862     vlc_object_detach( p_vlc );
863
864     /* Release object before destroying it */
865     if( i_object ) vlc_object_release( p_vlc );
866
867     vlc_object_destroy( p_vlc );
868
869     /* Stop thread system: last one out please shut the door! */
870     vlc_threads_end( p_libvlc );
871
872     return VLC_SUCCESS;
873 }
874
875 /*****************************************************************************
876  * VLC_VariableSet: set a vlc variable
877  *****************************************************************************/
878 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
879 {
880     vlc_t *p_vlc = vlc_current_object( i_object );
881     int i_ret;
882
883     if( !p_vlc )
884     {
885         return VLC_ENOOBJ;
886     }
887
888     /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
889      * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
890     if( !strncmp( psz_var, "conf::", 6 ) )
891     {
892         module_config_t *p_item;
893         char const *psz_newvar = psz_var + 6;
894
895         p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
896
897         if( p_item )
898         {
899             switch( p_item->i_type )
900             {
901                 case CONFIG_ITEM_BOOL:
902                     config_PutInt( p_vlc, psz_newvar, value.b_bool );
903                     break;
904                 case CONFIG_ITEM_INTEGER:
905                     config_PutInt( p_vlc, psz_newvar, value.i_int );
906                     break;
907                 case CONFIG_ITEM_FLOAT:
908                     config_PutFloat( p_vlc, psz_newvar, value.f_float );
909                     break;
910                 default:
911                     config_PutPsz( p_vlc, psz_newvar, value.psz_string );
912                     break;
913             }
914             if( i_object ) vlc_object_release( p_vlc );
915             return VLC_SUCCESS;
916         }
917     }
918
919     i_ret = var_Set( p_vlc, psz_var, value );
920
921     if( i_object ) vlc_object_release( p_vlc );
922     return i_ret;
923 }
924
925 /*****************************************************************************
926  * VLC_VariableGet: get a vlc variable
927  *****************************************************************************/
928 int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
929 {
930     vlc_t *p_vlc = vlc_current_object( i_object );
931     int i_ret;
932
933     if( !p_vlc )
934     {
935         return VLC_ENOOBJ;
936     }
937
938     i_ret = var_Get( p_vlc, psz_var, p_value );
939
940     if( i_object ) vlc_object_release( p_vlc );
941     return i_ret;
942 }
943
944 /*****************************************************************************
945  * VLC_AddTarget: adds a target for playing.
946  *****************************************************************************
947  * This function adds psz_target to the current playlist. If a playlist does
948  * not exist, it will create one.
949  *****************************************************************************/
950 int VLC_AddTarget( int i_object, char const *psz_target,
951                    char const **ppsz_options, int i_options,
952                    int i_mode, int i_pos )
953 {
954     int i_err;
955     playlist_t *p_playlist;
956     vlc_t *p_vlc = vlc_current_object( i_object );
957
958     if( !p_vlc )
959     {
960         return VLC_ENOOBJ;
961     }
962
963     p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
964
965     if( p_playlist == NULL )
966     {
967         msg_Dbg( p_vlc, "no playlist present, creating one" );
968         p_playlist = playlist_Create( p_vlc );
969
970         if( p_playlist == NULL )
971         {
972             if( i_object ) vlc_object_release( p_vlc );
973             return VLC_EGENERIC;
974         }
975
976         vlc_object_yield( p_playlist );
977     }
978
979     i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
980                              i_mode, i_pos, -1, ppsz_options, i_options);
981
982     vlc_object_release( p_playlist );
983
984     if( i_object ) vlc_object_release( p_vlc );
985     return i_err;
986 }
987
988 /*****************************************************************************
989  * VLC_Play: play
990  *****************************************************************************/
991 int VLC_Play( int i_object )
992 {
993     playlist_t * p_playlist;
994     vlc_t *p_vlc = vlc_current_object( i_object );
995
996     /* Check that the handle is valid */
997     if( !p_vlc )
998     {
999         return VLC_ENOOBJ;
1000     }
1001
1002     p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1003
1004     if( !p_playlist )
1005     {
1006         if( i_object ) vlc_object_release( p_vlc );
1007         return VLC_ENOOBJ;
1008     }
1009
1010     playlist_Play( p_playlist );
1011     vlc_object_release( p_playlist );
1012
1013     if( i_object ) vlc_object_release( p_vlc );
1014     return VLC_SUCCESS;
1015 }
1016
1017 /*****************************************************************************
1018  * VLC_Pause: toggle pause
1019  *****************************************************************************/
1020 int VLC_Pause( int i_object )
1021 {
1022     playlist_t * p_playlist;
1023     vlc_t *p_vlc = vlc_current_object( i_object );
1024
1025     /* Check that the handle is valid */
1026     if( !p_vlc )
1027     {
1028         return VLC_ENOOBJ;
1029     }
1030
1031     p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1032
1033     if( !p_playlist )
1034     {
1035         if( i_object ) vlc_object_release( p_vlc );
1036         return VLC_ENOOBJ;
1037     }
1038
1039     playlist_Pause( p_playlist );
1040     vlc_object_release( p_playlist );
1041
1042     if( i_object ) vlc_object_release( p_vlc );
1043     return VLC_SUCCESS;
1044 }
1045
1046 /*****************************************************************************
1047  * VLC_Pause: toggle pause
1048  *****************************************************************************/
1049 int VLC_Stop( int i_object )
1050 {
1051     playlist_t * p_playlist;
1052     vlc_t *p_vlc = vlc_current_object( i_object );
1053
1054     /* Check that the handle is valid */
1055     if( !p_vlc )
1056     {
1057         return VLC_ENOOBJ;
1058     }
1059
1060     p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1061
1062     if( !p_playlist )
1063     {
1064         if( i_object ) vlc_object_release( p_vlc );
1065         return VLC_ENOOBJ;
1066     }
1067
1068     playlist_Stop( p_playlist );
1069     vlc_object_release( p_playlist );
1070
1071     if( i_object ) vlc_object_release( p_vlc );
1072     return VLC_SUCCESS;
1073 }
1074
1075 /*****************************************************************************
1076  * VLC_IsPlaying: Query for Playlist Status
1077  *****************************************************************************/
1078 vlc_bool_t VLC_IsPlaying( int i_object )
1079 {
1080     playlist_t * p_playlist;
1081     vlc_bool_t   b_playing;
1082
1083     vlc_t *p_vlc = vlc_current_object( i_object );
1084
1085     /* Check that the handle is valid */
1086     if( !p_vlc )
1087     {
1088         return VLC_ENOOBJ;
1089     }
1090
1091     p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1092
1093     if( !p_playlist )
1094     {
1095         if( i_object ) vlc_object_release( p_vlc );
1096         return VLC_ENOOBJ;
1097     }
1098
1099     b_playing = playlist_IsPlaying( p_playlist );
1100     vlc_object_release( p_playlist );
1101
1102     if( i_object ) vlc_object_release( p_vlc );
1103     return b_playing;
1104 }
1105
1106 /**
1107  * Get the current position in a input
1108  *
1109  * Return the current position as a float
1110  * \note For some inputs, this will be unknown.
1111  *
1112  * \param i_object a vlc object id
1113  * \return a float in the range of 0.0 - 1.0
1114  */
1115 float VLC_PositionGet( int i_object )
1116 {
1117     input_thread_t *p_input;
1118     vlc_value_t val;
1119     vlc_t *p_vlc = vlc_current_object( i_object );
1120
1121     /* Check that the handle is valid */
1122     if( !p_vlc )
1123     {
1124         return VLC_ENOOBJ;
1125     }
1126
1127     p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1128
1129     if( !p_input )
1130     {
1131         if( i_object ) vlc_object_release( p_vlc );
1132         return VLC_ENOOBJ;
1133     }
1134
1135     var_Get( p_input, "position", &val );
1136     vlc_object_release( p_input );
1137
1138     if( i_object ) vlc_object_release( p_vlc );
1139     return val.f_float;
1140 }
1141
1142 /**
1143  * Set the current position in a input
1144  *
1145  * Set the current position in a input and then return
1146  * the current position as a float.
1147  * \note For some inputs, this will be unknown.
1148  *
1149  * \param i_object a vlc object id
1150  * \param i_position a float in the range of 0.0 - 1.0
1151  * \return a float in the range of 0.0 - 1.0
1152  */
1153 float VLC_PositionSet( int i_object, float i_position )
1154 {
1155     input_thread_t *p_input;
1156     vlc_value_t val;
1157     vlc_t *p_vlc = vlc_current_object( i_object );
1158
1159     /* Check that the handle is valid */
1160     if( !p_vlc )
1161     {
1162         return VLC_ENOOBJ;
1163     }
1164
1165     p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1166
1167     if( !p_input )
1168     {
1169         if( i_object ) vlc_object_release( p_vlc );
1170         return VLC_ENOOBJ;
1171     }
1172
1173     val.f_float = i_position;
1174     var_Set( p_input, "position", val );
1175     var_Get( p_input, "position", &val );
1176     vlc_object_release( p_input );
1177
1178     if( i_object ) vlc_object_release( p_vlc );
1179     return val.f_float;
1180 }
1181
1182 /**
1183  * Get the current position in a input
1184  *
1185  * Return the current position in seconds from the start.
1186  * \note For some inputs, this will be unknown.
1187  *
1188  * \param i_object a vlc object id
1189  * \return the offset from 0:00 in seconds
1190  */
1191 int VLC_TimeGet( int i_object )
1192 {
1193     input_thread_t *p_input;
1194     vlc_value_t val;
1195     vlc_t *p_vlc = vlc_current_object( i_object );
1196
1197     /* Check that the handle is valid */
1198     if( !p_vlc )
1199     {
1200         return VLC_ENOOBJ;
1201     }
1202
1203     p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1204
1205     if( !p_input )
1206     {
1207         if( i_object ) vlc_object_release( p_vlc );
1208         return VLC_ENOOBJ;
1209     }
1210
1211     var_Get( p_input, "time", &val );
1212     vlc_object_release( p_input );
1213
1214     if( i_object ) vlc_object_release( p_vlc );
1215     return val.i_time  / 1000000;
1216 }
1217
1218 /**
1219  * Seek to a position in the current input
1220  *
1221  * Seek i_seconds in the current input. If b_relative is set,
1222  * then the seek will be relative to the current position, otherwise
1223  * it will seek to i_seconds from the beginning of the input.
1224  * \note For some inputs, this will be unknown.
1225  *
1226  * \param i_object a vlc object id
1227  * \param i_seconds seconds from current position or from beginning of input
1228  * \param b_relative seek relative from current position
1229  * \return VLC_SUCCESS on success
1230  */
1231 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1232 {
1233     input_thread_t *p_input;
1234     vlc_value_t val;
1235     vlc_t *p_vlc = vlc_current_object( i_object );
1236
1237     /* Check that the handle is valid */
1238     if( !p_vlc )
1239     {
1240         return VLC_ENOOBJ;
1241     }
1242
1243     p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1244
1245     if( !p_input )
1246     {
1247         if( i_object ) vlc_object_release( p_vlc );
1248         return VLC_ENOOBJ;
1249     }
1250
1251     if( b_relative )
1252     {
1253         val.i_time = i_seconds * 1000000;
1254         var_Set( p_input, "time-offset", val );
1255     }
1256     else
1257     {
1258         val.i_time = i_seconds * 1000000;
1259         var_Set( p_input, "time", val );
1260     }
1261     vlc_object_release( p_input );
1262
1263     if( i_object ) vlc_object_release( p_vlc );
1264     return VLC_SUCCESS;
1265 }
1266
1267 /**
1268  * Get the total length of a input
1269  *
1270  * Return the total length in seconds from the current input.
1271  * \note For some inputs, this will be unknown.
1272  *
1273  * \param i_object a vlc object id
1274  * \return the length in seconds
1275  */
1276 int VLC_LengthGet( int i_object )
1277 {
1278     input_thread_t *p_input;
1279     vlc_value_t val;
1280     vlc_t *p_vlc = vlc_current_object( i_object );
1281
1282     /* Check that the handle is valid */
1283     if( !p_vlc )
1284     {
1285         return VLC_ENOOBJ;
1286     }
1287
1288     p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1289
1290     if( !p_input )
1291     {
1292         if( i_object ) vlc_object_release( p_vlc );
1293         return VLC_ENOOBJ;
1294     }
1295
1296     var_Get( p_input, "length", &val );
1297     vlc_object_release( p_input );
1298
1299     if( i_object ) vlc_object_release( p_vlc );
1300     return val.i_time  / 1000000;
1301 }
1302
1303 /**
1304  * Play the input faster than realtime
1305  *
1306  * 2x, 4x, 8x faster than realtime
1307  * \note For some inputs, this will be impossible.
1308  *
1309  * \param i_object a vlc object id
1310  * \return the current speedrate
1311  */
1312 float VLC_SpeedFaster( int i_object )
1313 {
1314     input_thread_t *p_input;
1315     vlc_value_t val;
1316     vlc_t *p_vlc = vlc_current_object( i_object );
1317
1318     /* Check that the handle is valid */
1319     if( !p_vlc )
1320     {
1321         return VLC_ENOOBJ;
1322     }
1323
1324     p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1325
1326     if( !p_input )
1327     {
1328         if( i_object ) vlc_object_release( p_vlc );
1329         return VLC_ENOOBJ;
1330     }
1331
1332     val.b_bool = VLC_TRUE;
1333     var_Set( p_input, "rate-faster", val );
1334     var_Get( p_input, "rate", &val );
1335     vlc_object_release( p_input );
1336
1337     if( i_object ) vlc_object_release( p_vlc );
1338     return val.f_float / INPUT_RATE_DEFAULT;
1339 }
1340
1341 /**
1342  * Play the input slower than realtime
1343  *
1344  * 1/2x, 1/4x, 1/8x slower than realtime
1345  * \note For some inputs, this will be impossible.
1346  *
1347  * \param i_object a vlc object id
1348  * \return the current speedrate
1349  */
1350 float VLC_SpeedSlower( int i_object )
1351 {
1352     input_thread_t *p_input;
1353     vlc_value_t val;
1354     vlc_t *p_vlc = vlc_current_object( i_object );
1355
1356     /* Check that the handle is valid */
1357     if( !p_vlc )
1358     {
1359         return VLC_ENOOBJ;
1360     }
1361
1362     p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1363
1364     if( !p_input )
1365     {
1366         if( i_object ) vlc_object_release( p_vlc );
1367         return VLC_ENOOBJ;
1368     }
1369
1370     val.b_bool = VLC_TRUE;
1371     var_Set( p_input, "rate-slower", val );
1372     var_Get( p_input, "rate", &val );
1373     vlc_object_release( p_input );
1374
1375     if( i_object ) vlc_object_release( p_vlc );
1376     return val.f_float / INPUT_RATE_DEFAULT;
1377 }
1378
1379 /**
1380  * Return the current playlist item
1381  *
1382  * Returns the index of the playlistitem that is currently selected for play.
1383  * This is valid even if nothing is currently playing.
1384  *
1385  * \param i_object a vlc object id
1386  * \return the current index
1387  */
1388 int VLC_PlaylistIndex( int i_object )
1389 {
1390     int i_index;
1391     playlist_t * p_playlist;
1392     vlc_t *p_vlc = vlc_current_object( i_object );
1393
1394     /* Check that the handle is valid */
1395     if( !p_vlc )
1396     {
1397         return VLC_ENOOBJ;
1398     }
1399
1400     p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1401
1402     if( !p_playlist )
1403     {
1404         if( i_object ) vlc_object_release( p_vlc );
1405         return VLC_ENOOBJ;
1406     }
1407
1408     i_index = p_playlist->i_index;
1409     vlc_object_release( p_playlist );
1410
1411     if( i_object ) vlc_object_release( p_vlc );
1412     return i_index;
1413 }
1414
1415 /**
1416  * Total amount of items in the playlist
1417  *
1418  * \param i_object a vlc object id
1419  * \return amount of playlist items
1420  */
1421 int VLC_PlaylistNumberOfItems( int i_object )
1422 {
1423     int i_size;
1424     playlist_t * p_playlist;
1425     vlc_t *p_vlc = vlc_current_object( i_object );
1426
1427     /* Check that the handle is valid */
1428     if( !p_vlc )
1429     {
1430         return VLC_ENOOBJ;
1431     }
1432
1433     p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1434
1435     if( !p_playlist )
1436     {
1437         if( i_object ) vlc_object_release( p_vlc );
1438         return VLC_ENOOBJ;
1439     }
1440
1441     i_size = p_playlist->i_size;
1442     vlc_object_release( p_playlist );
1443
1444     if( i_object ) vlc_object_release( p_vlc );
1445     return i_size;
1446 }
1447
1448 /**
1449  * Next playlist item
1450  *
1451  * Skip to the next playlistitem and play it.
1452  *
1453  * \param i_object a vlc object id
1454  * \return VLC_SUCCESS on success
1455  */
1456 int VLC_PlaylistNext( int i_object )
1457 {
1458     playlist_t * p_playlist;
1459     vlc_t *p_vlc = vlc_current_object( i_object );
1460
1461     /* Check that the handle is valid */
1462     if( !p_vlc )
1463     {
1464         return VLC_ENOOBJ;
1465     }
1466
1467     p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1468
1469     if( !p_playlist )
1470     {
1471         if( i_object ) vlc_object_release( p_vlc );
1472         return VLC_ENOOBJ;
1473     }
1474
1475     playlist_Next( p_playlist );
1476     vlc_object_release( p_playlist );
1477
1478     if( i_object ) vlc_object_release( p_vlc );
1479     return VLC_SUCCESS;
1480 }
1481
1482 /**
1483  * Previous playlist item
1484  *
1485  * Skip to the previous playlistitem and play it.
1486  *
1487  * \param i_object a vlc object id
1488  * \return VLC_SUCCESS on success
1489  */
1490 int VLC_PlaylistPrev( int i_object )
1491 {
1492     playlist_t * p_playlist;
1493     vlc_t *p_vlc = vlc_current_object( i_object );
1494
1495     /* Check that the handle is valid */
1496     if( !p_vlc )
1497     {
1498         return VLC_ENOOBJ;
1499     }
1500
1501     p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1502
1503     if( !p_playlist )
1504     {
1505         if( i_object ) vlc_object_release( p_vlc );
1506         return VLC_ENOOBJ;
1507     }
1508
1509     playlist_Prev( p_playlist );
1510     vlc_object_release( p_playlist );
1511
1512     if( i_object ) vlc_object_release( p_vlc );
1513     return VLC_SUCCESS;
1514 }
1515
1516
1517 /*****************************************************************************
1518  * VLC_PlaylistClear: Empty the playlist
1519  *****************************************************************************/
1520 int VLC_PlaylistClear( int i_object )
1521 {
1522     int i_err;
1523     playlist_t * p_playlist;
1524     vlc_t *p_vlc = vlc_current_object( i_object );
1525
1526     /* Check that the handle is valid */
1527     if( !p_vlc )
1528     {
1529         return VLC_ENOOBJ;
1530     }
1531
1532     p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1533
1534     if( !p_playlist )
1535     {
1536         if( i_object ) vlc_object_release( p_vlc );
1537         return VLC_ENOOBJ;
1538     }
1539
1540     i_err = playlist_Clear( p_playlist );
1541
1542     vlc_object_release( p_playlist );
1543
1544     if( i_object ) vlc_object_release( p_vlc );
1545     return i_err;
1546 }
1547
1548 /**
1549  * Change the volume
1550  *
1551  * \param i_object a vlc object id
1552  * \param i_volume something in a range from 0-200
1553  * \return the new volume (range 0-200 %)
1554  */
1555 int VLC_VolumeSet( int i_object, int i_volume )
1556 {
1557     audio_volume_t i_vol = 0;
1558     vlc_t *p_vlc = vlc_current_object( i_object );
1559
1560     /* Check that the handle is valid */
1561     if( !p_vlc )
1562     {
1563         return VLC_ENOOBJ;
1564     }
1565
1566     if( i_volume >= 0 && i_volume <= 200 )
1567     {
1568         i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1569         aout_VolumeSet( p_vlc, i_vol );
1570     }
1571
1572     if( i_object ) vlc_object_release( p_vlc );
1573     return i_vol * 200 / AOUT_VOLUME_MAX;
1574 }
1575
1576 /**
1577  * Get the current volume
1578  *
1579  * Retrieve the current volume.
1580  *
1581  * \param i_object a vlc object id
1582  * \return the current volume (range 0-200 %)
1583  */
1584 int VLC_VolumeGet( int i_object )
1585 {
1586     audio_volume_t i_volume;
1587     vlc_t *p_vlc = vlc_current_object( i_object );
1588
1589     /* Check that the handle is valid */
1590     if( !p_vlc )
1591     {
1592         return VLC_ENOOBJ;
1593     }
1594
1595     aout_VolumeGet( p_vlc, &i_volume );
1596
1597     if( i_object ) vlc_object_release( p_vlc );
1598     return i_volume*200/AOUT_VOLUME_MAX;
1599 }
1600
1601 /**
1602  * Mute/Unmute the volume
1603  *
1604  * \param i_object a vlc object id
1605  * \return VLC_SUCCESS on success
1606  */
1607 int VLC_VolumeMute( int i_object )
1608 {
1609     vlc_t *p_vlc = vlc_current_object( i_object );
1610
1611     /* Check that the handle is valid */
1612     if( !p_vlc )
1613     {
1614         return VLC_ENOOBJ;
1615     }
1616
1617     aout_VolumeMute( p_vlc, NULL );
1618
1619     if( i_object ) vlc_object_release( p_vlc );
1620     return VLC_SUCCESS;
1621 }
1622
1623 /*****************************************************************************
1624  * VLC_FullScreen: toggle fullscreen mode
1625  *****************************************************************************/
1626 int VLC_FullScreen( int i_object )
1627 {
1628     vout_thread_t *p_vout;
1629     vlc_t *p_vlc = vlc_current_object( i_object );
1630
1631     if( !p_vlc )
1632     {
1633         return VLC_ENOOBJ;
1634     }
1635
1636     p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1637
1638     if( !p_vout )
1639     {
1640         if( i_object ) vlc_object_release( p_vlc );
1641         return VLC_ENOOBJ;
1642     }
1643
1644     p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1645     vlc_object_release( p_vout );
1646
1647     if( i_object ) vlc_object_release( p_vlc );
1648     return VLC_SUCCESS;
1649 }
1650
1651 /* following functions are local */
1652
1653 /*****************************************************************************
1654  * SetLanguage: set the interface language.
1655  *****************************************************************************
1656  * We set the LC_MESSAGES locale category for interface messages and buttons,
1657  * as well as the LC_CTYPE category for string sorting and possible wide
1658  * character support.
1659  *****************************************************************************/
1660 static void SetLanguage ( char const *psz_lang )
1661 {
1662 #if defined( ENABLE_NLS ) \
1663      && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1664
1665     char *          psz_path;
1666 #if defined( SYS_DARWIN ) || defined ( WIN32 ) || defined( SYS_BEOS )
1667     char            psz_tmp[1024];
1668 #endif
1669
1670     if( psz_lang && !*psz_lang )
1671     {
1672 #   if defined( HAVE_LC_MESSAGES )
1673         setlocale( LC_MESSAGES, psz_lang );
1674 #   endif
1675         setlocale( LC_CTYPE, psz_lang );
1676     }
1677     else if( psz_lang )
1678     {
1679 #ifdef SYS_DARWIN
1680         /* I need that under Darwin, please check it doesn't disturb
1681          * other platforms. --Meuuh */
1682         setenv( "LANG", psz_lang, 1 );
1683
1684 #elif defined( SYS_BEOS ) || defined( WIN32 )
1685         /* We set LC_ALL manually because it is the only way to set
1686          * the language at runtime under eg. Windows. Beware that this
1687          * makes the environment unconsistent when libvlc is unloaded and
1688          * should probably be moved to a safer place like vlc.c. */
1689         static char psz_lcall[20];
1690         snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1691         psz_lcall[19] = '\0';
1692         putenv( psz_lcall );
1693 #endif
1694
1695         setlocale( LC_ALL, psz_lang );
1696     }
1697
1698     /* Specify where to find the locales for current domain */
1699 #if !defined( SYS_DARWIN ) && !defined( WIN32 ) && !defined( SYS_BEOS )
1700     psz_path = LOCALEDIR;
1701 #else
1702     snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
1703               "locale" );
1704     psz_path = psz_tmp;
1705 #endif
1706     if( !bindtextdomain( PACKAGE, psz_path ) )
1707     {
1708         fprintf( stderr, "warning: no domain %s in directory %s\n",
1709                  PACKAGE, psz_path );
1710     }
1711
1712     /* Set the default domain */
1713     textdomain( PACKAGE );
1714
1715 #if defined( ENABLE_UTF8 )
1716     bind_textdomain_codeset( PACKAGE, "UTF-8" );
1717 #endif
1718
1719 #endif
1720 }
1721
1722 /*****************************************************************************
1723  * GetFilenames: parse command line options which are not flags
1724  *****************************************************************************
1725  * Parse command line for input files as well as their associated options.
1726  * An option always follows its associated input and begins with a ":".
1727  *****************************************************************************/
1728 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
1729 {
1730     int i_opt, i_options;
1731
1732     /* We assume that the remaining parameters are filenames
1733      * and their input options */
1734     for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
1735     {
1736         i_options = 0;
1737
1738         /* Count the input options */
1739         while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
1740         {
1741             i_options++;
1742             i_opt--;
1743         }
1744
1745         /* TODO: write an internal function of this one, to avoid
1746          *       unnecessary lookups. */
1747         VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
1748                        (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
1749                                         NULL ), i_options,
1750                        PLAYLIST_INSERT, 0 );
1751     }
1752
1753     return VLC_SUCCESS;
1754 }
1755
1756 /*****************************************************************************
1757  * Usage: print program usage
1758  *****************************************************************************
1759  * Print a short inline help. Message interface is initialized at this stage.
1760  *****************************************************************************/
1761 static void Usage( vlc_t *p_this, char const *psz_module_name )
1762 {
1763 #define FORMAT_STRING "  %s --%s%s%s%s%s%s%s "
1764     /* short option ------'    |     | | | |  | |
1765      * option name ------------'     | | | |  | |
1766      * <bra -------------------------' | | |  | |
1767      * option type or "" --------------' | |  | |
1768      * ket> -----------------------------' |  | |
1769      * padding spaces ---------------------'  | |
1770      * comment -------------------------------' |
1771      * comment suffix --------------------------'
1772      *
1773      * The purpose of having bra and ket is that we might i18n them as well.
1774      */
1775 #define LINE_START 8
1776 #define PADDING_SPACES 25
1777     vlc_list_t *p_list;
1778     module_t *p_parser;
1779     module_config_t *p_item;
1780     char psz_spaces[PADDING_SPACES+LINE_START+1];
1781     char psz_format[sizeof(FORMAT_STRING)];
1782     char psz_buffer[1000];
1783     char psz_short[4];
1784     int i_index;
1785     int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1786     vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
1787
1788     memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
1789     psz_spaces[PADDING_SPACES+LINE_START] = '\0';
1790
1791     strcpy( psz_format, FORMAT_STRING );
1792
1793 #ifdef WIN32
1794     ShowConsole();
1795 #endif
1796
1797     /* List all modules */
1798     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1799
1800     /* Enumerate the config for each module */
1801     for( i_index = 0; i_index < p_list->i_count; i_index++ )
1802     {
1803         vlc_bool_t b_help_module;
1804
1805         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1806
1807         if( psz_module_name && strcmp( psz_module_name,
1808                                        p_parser->psz_object_name ) )
1809         {
1810             continue;
1811         }
1812
1813         /* Ignore modules without config options */
1814         if( !p_parser->i_config_items )
1815         {
1816             continue;
1817         }
1818
1819         /* Ignore modules with only advanced config options if requested */
1820         if( !b_advanced )
1821         {
1822             for( p_item = p_parser->p_config;
1823                  p_item->i_type != CONFIG_HINT_END;
1824                  p_item++ )
1825             {
1826                 if( (p_item->i_type & CONFIG_ITEM) &&
1827                     !p_item->b_advanced ) break;
1828             }
1829             if( p_item->i_type == CONFIG_HINT_END ) continue;
1830         }
1831
1832         /* Print name of module */
1833         if( strcmp( "main", p_parser->psz_object_name ) )
1834         fprintf( stdout, "\n %s\n", p_parser->psz_longname );
1835
1836         b_help_module = !strcmp( "help", p_parser->psz_object_name );
1837
1838         /* Print module options */
1839         for( p_item = p_parser->p_config;
1840              p_item->i_type != CONFIG_HINT_END;
1841              p_item++ )
1842         {
1843             char *psz_text;
1844             char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1845             char *psz_suf = "", *psz_prefix = NULL;
1846             int i;
1847
1848             /* Skip advanced options if requested */
1849             if( p_item->b_advanced && !b_advanced )
1850             {
1851                 continue;
1852             }
1853
1854             switch( p_item->i_type )
1855             {
1856             case CONFIG_HINT_CATEGORY:
1857             case CONFIG_HINT_USAGE:
1858                 if( !strcmp( "main", p_parser->psz_object_name ) )
1859                 fprintf( stdout, "\n %s\n", p_item->psz_text );
1860                 break;
1861
1862             case CONFIG_ITEM_STRING:
1863             case CONFIG_ITEM_FILE:
1864             case CONFIG_ITEM_DIRECTORY:
1865             case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1866                 if( !p_item->ppsz_list )
1867                 {
1868                     psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1869                     break;
1870                 }
1871                 else
1872                 {
1873                     psz_bra = " {";
1874                     psz_type = psz_buffer;
1875                     psz_type[0] = '\0';
1876                     for( i = 0; p_item->ppsz_list[i]; i++ )
1877                     {
1878                         if( i ) strcat( psz_type, "," );
1879                         strcat( psz_type, p_item->ppsz_list[i] );
1880                     }
1881                     psz_ket = "}";
1882                     break;
1883                 }
1884             case CONFIG_ITEM_INTEGER:
1885             case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
1886                 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1887                 break;
1888             case CONFIG_ITEM_FLOAT:
1889                 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1890                 break;
1891             case CONFIG_ITEM_BOOL:
1892                 psz_bra = ""; psz_type = ""; psz_ket = "";
1893                 if( !b_help_module )
1894                 {
1895                     psz_suf = p_item->i_value ? _(" (default enabled)") :
1896                                                 _(" (default disabled)");
1897                 }
1898                 break;
1899             }
1900
1901             if( !psz_type )
1902             {
1903                 continue;
1904             }
1905
1906             /* Add short option if any */
1907             if( p_item->i_short )
1908             {
1909                 sprintf( psz_short, "-%c,", p_item->i_short );
1910             }
1911             else
1912             {
1913                 strcpy( psz_short, "   " );
1914             }
1915
1916             i = PADDING_SPACES - strlen( p_item->psz_name )
1917                  - strlen( psz_bra ) - strlen( psz_type )
1918                  - strlen( psz_ket ) - 1;
1919
1920             if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1921             {
1922                 /* If option is of type --foo-bar, we print its counterpart
1923                  * as --no-foo-bar, but if it is of type --foobar (without
1924                  * dashes in the name) we print it as --nofoobar. Both
1925                  * values are of course valid, only the display changes. */
1926                 psz_prefix = strchr( p_item->psz_name, '-' ) ? ", --no-"
1927                                                              : ", --no";
1928                 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
1929             }
1930
1931             if( i < 0 )
1932             {
1933                 psz_spaces[0] = '\n';
1934                 i = 0;
1935             }
1936             else
1937             {
1938                 psz_spaces[i] = '\0';
1939             }
1940
1941             if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1942             {
1943                 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1944                          psz_prefix, p_item->psz_name, psz_bra, psz_type,
1945                          psz_ket, psz_spaces );
1946             }
1947             else
1948             {
1949                 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1950                          "", "", psz_bra, psz_type, psz_ket, psz_spaces );
1951             }
1952
1953             psz_spaces[i] = ' ';
1954
1955             /* We wrap the rest of the output */
1956             sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
1957             psz_text = psz_buffer;
1958             while( *psz_text )
1959             {
1960                 char *psz_parser, *psz_word;
1961                 int i_end = strlen( psz_text );
1962
1963                 /* If the remaining text fits in a line, print it. */
1964                 if( i_end <= i_width )
1965                 {
1966                     fprintf( stdout, "%s\n", psz_text );
1967                     break;
1968                 }
1969
1970                 /* Otherwise, eat as many words as possible */
1971                 psz_parser = psz_text;
1972                 do
1973                 {
1974                     psz_word = psz_parser;
1975                     psz_parser = strchr( psz_word, ' ' );
1976                     /* If no space was found, we reached the end of the text
1977                      * block; otherwise, we skip the space we just found. */
1978                     psz_parser = psz_parser ? psz_parser + 1
1979                                             : psz_text + i_end;
1980
1981                 } while( psz_parser - psz_text <= i_width );
1982
1983                 /* We cut a word in one of these cases:
1984                  *  - it's the only word in the line and it's too long.
1985                  *  - we used less than 80% of the width and the word we are
1986                  *    going to wrap is longer than 40% of the width, and even
1987                  *    if the word would have fit in the next line. */
1988                 if( psz_word == psz_text
1989                      || ( psz_word - psz_text < 80 * i_width / 100
1990                            && psz_parser - psz_word > 40 * i_width / 100 ) )
1991                 {
1992                     char c = psz_text[i_width];
1993                     psz_text[i_width] = '\0';
1994                     fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
1995                     psz_text += i_width;
1996                     psz_text[0] = c;
1997                 }
1998                 else
1999                 {
2000                     psz_word[-1] = '\0';
2001                     fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2002                     psz_text = psz_word;
2003                 }
2004             }
2005         }
2006     }
2007
2008     /* Release the module list */
2009     vlc_list_release( p_list );
2010
2011 #ifdef WIN32        /* Pause the console because it's destroyed when we exit */
2012     fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2013     getchar();
2014 #endif
2015 }
2016
2017 /*****************************************************************************
2018  * ListModules: list the available modules with their description
2019  *****************************************************************************
2020  * Print a list of all available modules (builtins and plugins) and a short
2021  * description for each one.
2022  *****************************************************************************/
2023 static void ListModules( vlc_t *p_this )
2024 {
2025     vlc_list_t *p_list;
2026     module_t *p_parser;
2027     char psz_spaces[22];
2028     int i_index;
2029
2030     memset( psz_spaces, ' ', 22 );
2031
2032 #ifdef WIN32
2033     ShowConsole();
2034 #endif
2035
2036     /* Usage */
2037     fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
2038                      p_this->p_vlc->psz_object_name );
2039
2040     fprintf( stdout, _("[module]              [description]\n") );
2041
2042     /* List all modules */
2043     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2044
2045     /* Enumerate each module */
2046     for( i_index = 0; i_index < p_list->i_count; i_index++ )
2047     {
2048         int i;
2049
2050         p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2051
2052         /* Nasty hack, but right now I'm too tired to think about a nice
2053          * solution */
2054         i = 22 - strlen( p_parser->psz_object_name ) - 1;
2055         if( i < 0 ) i = 0;
2056         psz_spaces[i] = 0;
2057
2058         fprintf( stdout, "  %s%s %s\n", p_parser->psz_object_name,
2059                          psz_spaces, p_parser->psz_longname );
2060
2061         psz_spaces[i] = ' ';
2062     }
2063
2064     vlc_list_release( p_list );
2065
2066 #ifdef WIN32        /* Pause the console because it's destroyed when we exit */
2067     fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2068     getchar();
2069 #endif
2070 }
2071
2072 /*****************************************************************************
2073  * Version: print complete program version
2074  *****************************************************************************
2075  * Print complete program version and build number.
2076  *****************************************************************************/
2077 static void Version( void )
2078 {
2079 #ifdef WIN32
2080     ShowConsole();
2081 #endif
2082
2083     fprintf( stdout, VERSION_MESSAGE "\n" );
2084     fprintf( stdout,
2085       _("This program comes with NO WARRANTY, to the extent permitted by "
2086         "law.\nYou may redistribute it under the terms of the GNU General "
2087         "Public License;\nsee the file named COPYING for details.\n"
2088         "Written by the VideoLAN team; see the AUTHORS file.\n") );
2089
2090 #ifdef WIN32        /* Pause the console because it's destroyed when we exit */
2091     fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2092     getchar();
2093 #endif
2094 }
2095
2096 /*****************************************************************************
2097  * ShowConsole: On Win32, create an output console for debug messages
2098  *****************************************************************************
2099  * This function is useful only on Win32.
2100  *****************************************************************************/
2101 #ifdef WIN32 /*  */
2102 static void ShowConsole( void )
2103 {
2104 #   ifndef UNDER_CE
2105     AllocConsole();
2106     freopen( "CONOUT$", "w", stdout );
2107     freopen( "CONOUT$", "w", stderr );
2108     freopen( "CONIN$", "r", stdin );
2109 #   endif
2110     return;
2111 }
2112 #endif
2113
2114 /*****************************************************************************
2115  * ConsoleWidth: Return the console width in characters
2116  *****************************************************************************
2117  * We use the stty shell command to get the console width; if this fails or
2118  * if the width is less than 80, we default to 80.
2119  *****************************************************************************/
2120 static int ConsoleWidth( void )
2121 {
2122     int i_width = 80;
2123
2124 #ifndef WIN32
2125     char buf[20], *psz_parser;
2126     FILE *file;
2127     int i_ret;
2128
2129     file = popen( "stty size 2>/dev/null", "r" );
2130     if( file )
2131     {
2132         i_ret = fread( buf, 1, 20, file );
2133         if( i_ret > 0 )
2134         {
2135             buf[19] = '\0';
2136             psz_parser = strchr( buf, ' ' );
2137             if( psz_parser )
2138             {
2139                 i_ret = atoi( psz_parser + 1 );
2140                 if( i_ret >= 80 )
2141                 {
2142                     i_width = i_ret;
2143                 }
2144             }
2145         }
2146
2147         pclose( file );
2148     }
2149 #endif
2150
2151     return i_width;
2152 }
2153
2154 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2155                      vlc_value_t old_val, vlc_value_t new_val, void *param)
2156 {
2157     vlc_t *p_vlc = (vlc_t *)p_this;
2158
2159     if( new_val.i_int >= -1 )
2160     {
2161         p_vlc->p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );
2162     }
2163     return VLC_SUCCESS;
2164 }