New vu meter visualization.
[vlc.git] / src / libvlc.c
blob5cbf80e0030c911bcc89f88ef8983445450d2d75
1 /*****************************************************************************
2 * libvlc.c: Implementation of the old libvlc API
3 *****************************************************************************
4 * Copyright (C) 1998-2007 the VideoLAN team
5 * $Id$
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Gildas Bazin <gbazin@videolan.org>
10 * Derk-Jan Hartman <hartman at videolan dot org>
11 * RĂ©mi Denis-Courmont <rem # videolan : org>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
28 /*****************************************************************************
29 * Pretend we are a builtin module
30 *****************************************************************************/
31 #define MODULE_NAME main
32 #define MODULE_PATH main
33 #define __BUILTIN__
35 /*****************************************************************************
36 * Preamble
37 *****************************************************************************/
38 #ifdef HAVE_CONFIG_H
39 # include "config.h"
40 #endif
42 #include <vlc/vlc.h>
44 #include "control/libvlc_internal.h"
45 #include "libvlc.h"
47 #include <vlc_playlist.h>
49 #include <vlc_aout.h>
50 #include <vlc_vout.h>
52 /*****************************************************************************
53 * VLC_Version: return the libvlc version.
54 *****************************************************************************
55 * This function returns full version string (numeric version and codename).
56 *****************************************************************************/
57 char const * VLC_Version( void )
59 return VERSION_MESSAGE;
62 /*****************************************************************************
63 * VLC_CompileBy, VLC_CompileHost, VLC_CompileDomain,
64 * VLC_Compiler, VLC_Changeset
65 *****************************************************************************/
66 #define DECLARE_VLC_VERSION( func, var ) \
67 char const * VLC_##func ( void ) \
68 { \
69 return VLC_##var ; \
72 DECLARE_VLC_VERSION( CompileBy, COMPILE_BY );
73 DECLARE_VLC_VERSION( CompileHost, COMPILE_HOST );
74 DECLARE_VLC_VERSION( CompileDomain, COMPILE_DOMAIN );
75 DECLARE_VLC_VERSION( Compiler, COMPILER );
77 extern const char psz_vlc_changeset[];
78 const char* VLC_Changeset( void )
80 return psz_vlc_changeset;
83 #define LIBVLC_FUNC \
84 libvlc_int_t * p_libvlc = vlc_current_object( i_object ); \
85 if( !p_libvlc ) return VLC_ENOOBJ;
86 #define LIBVLC_FUNC_END \
87 if( i_object ) vlc_object_release( p_libvlc );
90 /*****************************************************************************
91 * VLC_VariableSet: set a "safe" vlc variable
92 *****************************************************************************/
93 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
95 int i_ret;
96 LIBVLC_FUNC;
98 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
99 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
100 if( !strncmp( psz_var, "conf::", 6 ) )
102 module_config_t *p_item;
103 char const *psz_newvar = psz_var + 6;
105 p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
107 if( p_item )
109 /* VLC_VariableSet is only used from the browser plugins, so we
110 * can pretty much assume that the input is _not_ trusted. */
111 if( !p_item->b_safe )
112 return VLC_EGENERIC;
114 switch( p_item->i_type )
116 case CONFIG_ITEM_BOOL:
117 config_PutInt( p_libvlc, psz_newvar, value.b_bool );
118 break;
119 case CONFIG_ITEM_INTEGER:
120 config_PutInt( p_libvlc, psz_newvar, value.i_int );
121 break;
122 case CONFIG_ITEM_FLOAT:
123 config_PutFloat( p_libvlc, psz_newvar, value.f_float );
124 break;
125 default:
126 config_PutPsz( p_libvlc, psz_newvar, value.psz_string );
127 break;
129 if( i_object ) vlc_object_release( p_libvlc );
130 return VLC_SUCCESS;
133 /* EXPLICIT HACK (this is the legacy API anyway):
134 * VLC_VariableSet is only used from the browser plugins, so we
135 * can pretty much assume that the input is _not_ trusted. */
136 module_config_t *p_item;
137 p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_var );
138 if( !p_item )
139 return VLC_ENOVAR;
140 if( !p_item->b_safe )
141 return VLC_EGENERIC;
143 i_ret = var_Set( p_libvlc, psz_var, value );
145 LIBVLC_FUNC_END;
146 return i_ret;
149 /*****************************************************************************
150 * VLC_VariableGet: get a vlc variable
151 *****************************************************************************/
152 int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
154 int i_ret;
155 LIBVLC_FUNC;
156 i_ret = var_Get( p_libvlc , psz_var, p_value );
157 LIBVLC_FUNC_END;
158 return i_ret;
161 /*****************************************************************************
162 * VLC_VariableType: get a vlc variable type
163 *****************************************************************************/
164 int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
166 int i_type;
167 LIBVLC_FUNC;
168 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
169 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
170 if( !strncmp( psz_var, "conf::", 6 ) )
172 module_config_t *p_item;
173 char const *psz_newvar = psz_var + 6;
175 p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
177 if( p_item )
179 switch( p_item->i_type )
181 case CONFIG_ITEM_BOOL:
182 i_type = VLC_VAR_BOOL;
183 break;
184 case CONFIG_ITEM_INTEGER:
185 i_type = VLC_VAR_INTEGER;
186 break;
187 case CONFIG_ITEM_FLOAT:
188 i_type = VLC_VAR_FLOAT;
189 break;
190 default:
191 i_type = VLC_VAR_STRING;
192 break;
195 else
196 i_type = 0;
198 else
199 i_type = VLC_VAR_TYPE & var_Type( p_libvlc , psz_var );
201 LIBVLC_FUNC_END;
203 if( i_type > 0 )
205 *pi_type = i_type;
206 return VLC_SUCCESS;
208 return VLC_ENOVAR;
211 #define LIBVLC_PLAYLIST_FUNC \
212 libvlc_int_t *p_libvlc = vlc_current_object( i_object );\
213 if( !p_libvlc ) return VLC_ENOOBJ; \
214 playlist_t *p_playlist = pl_Yield( p_libvlc ); \
215 if( !p_playlist ) return VLC_ENOOBJ
217 #define LIBVLC_PLAYLIST_FUNC_END \
218 pl_Release( p_libvlc ); \
219 if( i_object ) vlc_object_release( p_libvlc );
221 /*****************************************************************************
222 * VLC_AddTarget: adds a target for playing.
223 *****************************************************************************
224 * This function adds psz_target to the playlist
225 *****************************************************************************/
227 int VLC_AddTarget( int i_object, char const *psz_target,
228 char const **ppsz_options, int i_options,
229 int i_mode, int i_pos )
231 int i_err;
232 LIBVLC_PLAYLIST_FUNC;
233 i_err = playlist_AddExt( p_playlist, psz_target,
234 NULL, i_mode, i_pos, -1,
235 ppsz_options, i_options, true, false );
236 LIBVLC_PLAYLIST_FUNC_END;
237 return i_err;
240 /*****************************************************************************
241 * VLC_Play: play the playlist
242 *****************************************************************************/
243 int VLC_Play( int i_object )
245 LIBVLC_PLAYLIST_FUNC;
246 playlist_Play( p_playlist );
247 LIBVLC_PLAYLIST_FUNC_END;
248 return VLC_SUCCESS;
251 /*****************************************************************************
252 * VLC_Pause: toggle pause
253 *****************************************************************************/
254 int VLC_Pause( int i_object )
256 LIBVLC_PLAYLIST_FUNC;
257 playlist_Pause( p_playlist );
258 LIBVLC_PLAYLIST_FUNC_END;
259 return VLC_SUCCESS;
262 /*****************************************************************************
263 * VLC_Stop: stop playback
264 *****************************************************************************/
265 int VLC_Stop( int i_object )
267 LIBVLC_PLAYLIST_FUNC;
268 playlist_Stop( p_playlist );
269 LIBVLC_PLAYLIST_FUNC_END;
270 return VLC_SUCCESS;
273 /*****************************************************************************
274 * VLC_IsPlaying: Query for Playlist Status
275 *****************************************************************************/
276 bool VLC_IsPlaying( int i_object )
278 bool b_playing;
280 LIBVLC_PLAYLIST_FUNC;
281 if( p_playlist->p_input )
283 vlc_value_t val;
284 var_Get( p_playlist->p_input, "state", &val );
285 b_playing = ( val.i_int == PLAYING_S );
287 else
289 b_playing = playlist_IsPlaying( p_playlist );
291 LIBVLC_PLAYLIST_FUNC_END;
292 return b_playing;
296 * Get the current position in a input
298 * Return the current position as a float
299 * \note For some inputs, this will be unknown.
301 * \param i_object a vlc object id
302 * \return a float in the range of 0.0 - 1.0
304 float VLC_PositionGet( int i_object )
306 input_thread_t *p_input;
307 vlc_value_t val;
308 LIBVLC_FUNC;
310 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
312 if( !p_input )
314 if( i_object ) vlc_object_release( p_libvlc );
315 return VLC_ENOOBJ;
318 var_Get( p_input, "position", &val );
319 vlc_object_release( p_input );
321 LIBVLC_FUNC_END;
322 return val.f_float;
326 * Set the current position in a input
328 * Set the current position in a input and then return
329 * the current position as a float.
330 * \note For some inputs, this will be unknown.
332 * \param i_object a vlc object id
333 * \param i_position a float in the range of 0.0 - 1.0
334 * \return a float in the range of 0.0 - 1.0
336 float VLC_PositionSet( int i_object, float i_position )
338 input_thread_t *p_input;
339 vlc_value_t val;
340 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
342 /* Check that the handle is valid */
343 if( !p_libvlc )
345 return VLC_ENOOBJ;
348 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
350 if( !p_input )
352 if( i_object ) vlc_object_release( p_libvlc );
353 return VLC_ENOOBJ;
356 val.f_float = i_position;
357 var_Set( p_input, "position", val );
358 var_Get( p_input, "position", &val );
359 vlc_object_release( p_input );
361 if( i_object ) vlc_object_release( p_libvlc );
362 return val.f_float;
366 * Get the current position in a input
368 * Return the current position in seconds from the start.
369 * \note For some inputs, this will be unknown.
371 * \param i_object a vlc object id
372 * \return the offset from 0:00 in seconds
374 int VLC_TimeGet( int i_object )
376 input_thread_t *p_input;
377 vlc_value_t val;
378 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
380 /* Check that the handle is valid */
381 if( !p_libvlc )
383 return VLC_ENOOBJ;
386 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
388 if( !p_input )
390 if( i_object ) vlc_object_release( p_libvlc );
391 return VLC_ENOOBJ;
394 var_Get( p_input, "time", &val );
395 vlc_object_release( p_input );
397 if( i_object ) vlc_object_release( p_libvlc );
398 return val.i_time / 1000000;
402 * Seek to a position in the current input
404 * Seek i_seconds in the current input. If b_relative is set,
405 * then the seek will be relative to the current position, otherwise
406 * it will seek to i_seconds from the beginning of the input.
407 * \note For some inputs, this will be unknown.
409 * \param i_object a vlc object id
410 * \param i_seconds seconds from current position or from beginning of input
411 * \param b_relative seek relative from current position
412 * \return VLC_SUCCESS on success
414 int VLC_TimeSet( int i_object, int i_seconds, bool b_relative )
416 input_thread_t *p_input;
417 vlc_value_t val;
418 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
420 /* Check that the handle is valid */
421 if( !p_libvlc )
423 return VLC_ENOOBJ;
426 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
428 if( !p_input )
430 if( i_object ) vlc_object_release( p_libvlc );
431 return VLC_ENOOBJ;
434 if( b_relative )
436 val.i_time = i_seconds;
437 val.i_time = val.i_time * 1000000L;
438 var_Set( p_input, "time-offset", val );
440 else
442 val.i_time = i_seconds;
443 val.i_time = val.i_time * 1000000L;
444 var_Set( p_input, "time", val );
446 vlc_object_release( p_input );
448 if( i_object ) vlc_object_release( p_libvlc );
449 return VLC_SUCCESS;
453 * Get the total length of a input
455 * Return the total length in seconds from the current input.
456 * \note For some inputs, this will be unknown.
458 * \param i_object a vlc object id
459 * \return the length in seconds
461 int VLC_LengthGet( int i_object )
463 input_thread_t *p_input;
464 vlc_value_t val;
465 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
467 /* Check that the handle is valid */
468 if( !p_libvlc )
470 return VLC_ENOOBJ;
473 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
475 if( !p_input )
477 if( i_object ) vlc_object_release( p_libvlc );
478 return VLC_ENOOBJ;
481 var_Get( p_input, "length", &val );
482 vlc_object_release( p_input );
484 if( i_object ) vlc_object_release( p_libvlc );
485 return val.i_time / 1000000L;
489 * Play the input faster than realtime
491 * 2x, 4x, 8x faster than realtime
492 * \note For some inputs, this will be impossible.
494 * \param i_object a vlc object id
495 * \return the current speedrate
497 float VLC_SpeedFaster( int i_object )
499 input_thread_t *p_input;
500 vlc_value_t val;
501 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
503 /* Check that the handle is valid */
504 if( !p_libvlc )
506 return VLC_ENOOBJ;
509 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
511 if( !p_input )
513 if( i_object ) vlc_object_release( p_libvlc );
514 return VLC_ENOOBJ;
517 val.b_bool = true;
518 var_Set( p_input, "rate-faster", val );
519 var_Get( p_input, "rate", &val );
520 vlc_object_release( p_input );
522 if( i_object ) vlc_object_release( p_libvlc );
523 return val.f_float / INPUT_RATE_DEFAULT;
527 * Play the input slower than realtime
529 * 1/2x, 1/4x, 1/8x slower than realtime
530 * \note For some inputs, this will be impossible.
532 * \param i_object a vlc object id
533 * \return the current speedrate
535 float VLC_SpeedSlower( int i_object )
537 input_thread_t *p_input;
538 vlc_value_t val;
539 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
541 /* Check that the handle is valid */
542 if( !p_libvlc )
544 return VLC_ENOOBJ;
547 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
549 if( !p_input )
551 if( i_object ) vlc_object_release( p_libvlc );
552 return VLC_ENOOBJ;
555 val.b_bool = true;
556 var_Set( p_input, "rate-slower", val );
557 var_Get( p_input, "rate", &val );
558 vlc_object_release( p_input );
560 if( i_object ) vlc_object_release( p_libvlc );
561 return val.f_float / INPUT_RATE_DEFAULT;
565 * Return the current playlist item
567 * Returns the index of the playlistitem that is currently selected for play.
568 * This is valid even if nothing is currently playing.
570 * \param i_object a vlc object id
571 * \return the current index
573 int VLC_PlaylistIndex( int i_object )
575 (void)i_object;
576 printf( "This function is deprecated and should not be used anymore" );
577 return -1;
581 * Total number of items in the playlist
583 * \param i_object a vlc object id
584 * \return amount of playlist items
586 int VLC_PlaylistNumberOfItems( int i_object )
588 int i_size;
589 LIBVLC_PLAYLIST_FUNC;
590 i_size = p_playlist->items.i_size;
591 LIBVLC_PLAYLIST_FUNC_END;
592 return i_size;
596 * Go to next playlist item
597 * \param i_object a vlc object id
598 * \return VLC_SUCCESS on success
600 int VLC_PlaylistNext( int i_object )
602 LIBVLC_PLAYLIST_FUNC;
603 playlist_Next( p_playlist );
604 LIBVLC_PLAYLIST_FUNC_END;
605 return VLC_SUCCESS;
609 * Go to previous playlist item
610 * \param i_object a vlc object id
611 * \return VLC_SUCCESS on success
613 int VLC_PlaylistPrev( int i_object )
615 LIBVLC_PLAYLIST_FUNC;
616 playlist_Prev( p_playlist );
617 LIBVLC_PLAYLIST_FUNC_END;
618 return VLC_SUCCESS;
622 * Empty the playlist
624 int VLC_PlaylistClear( int i_object )
626 LIBVLC_PLAYLIST_FUNC;
627 playlist_Clear( p_playlist, true );
628 LIBVLC_PLAYLIST_FUNC_END;
629 return VLC_SUCCESS;
633 * Change the volume
635 * \param i_object a vlc object id
636 * \param i_volume something in a range from 0-200
637 * \return the new volume (range 0-200 %)
639 int VLC_VolumeSet( int i_object, int i_volume )
641 audio_volume_t i_vol = 0;
642 LIBVLC_FUNC;
644 if( i_volume >= 0 && i_volume <= 200 )
646 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
647 aout_VolumeSet( p_libvlc, i_vol );
649 LIBVLC_FUNC_END;
650 return i_vol * 200 / AOUT_VOLUME_MAX;
654 * Get the current volume
656 * Retrieve the current volume.
658 * \param i_object a vlc object id
659 * \return the current volume (range 0-200 %)
661 int VLC_VolumeGet( int i_object )
663 audio_volume_t i_volume;
664 LIBVLC_FUNC;
665 aout_VolumeGet( p_libvlc, &i_volume );
666 LIBVLC_FUNC_END;
667 return i_volume*200/AOUT_VOLUME_MAX;
671 * Mute/Unmute the volume
673 * \param i_object a vlc object id
674 * \return VLC_SUCCESS on success
676 int VLC_VolumeMute( int i_object )
678 LIBVLC_FUNC;
679 aout_VolumeMute( p_libvlc, NULL );
680 LIBVLC_FUNC_END;
681 return VLC_SUCCESS;
684 /*****************************************************************************
685 * VLC_FullScreen: toggle fullscreen mode
686 *****************************************************************************/
687 int VLC_FullScreen( int i_object )
689 vout_thread_t *p_vout;
690 LIBVLC_FUNC;
691 p_vout = vlc_object_find( p_libvlc, VLC_OBJECT_VOUT, FIND_CHILD );
693 if( !p_vout )
695 if( i_object ) vlc_object_release( p_libvlc );
696 return VLC_ENOOBJ;
699 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
700 vlc_object_release( p_vout );
701 LIBVLC_FUNC_END;
702 return VLC_SUCCESS;