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