1 /*****************************************************************************
2 * libvlc.c: Implementation of the old libvlc API
3 *****************************************************************************
4 * Copyright (C) 1998-2007 the VideoLAN team
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
35 /*****************************************************************************
37 *****************************************************************************/
42 #include <vlc_common.h>
44 #include "control/libvlc_internal.h"
47 #include <vlc_playlist.h>
53 libvlc_int_t * p_libvlc = vlc_current_object( i_object ); \
54 if( !p_libvlc ) return VLC_ENOOBJ;
55 #define LIBVLC_FUNC_END \
56 if( i_object ) vlc_object_release( p_libvlc );
59 /*****************************************************************************
60 * VLC_VariableSet: set a "safe" vlc variable
61 *****************************************************************************/
62 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
67 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
68 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
69 if( !strncmp( psz_var, "conf::", 6 ) )
71 module_config_t *p_item;
72 char const *psz_newvar = psz_var + 6;
74 p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
78 /* VLC_VariableSet is only used from the browser plugins, so we
79 * can pretty much assume that the input is _not_ trusted. */
83 switch( p_item->i_type )
85 case CONFIG_ITEM_BOOL:
86 config_PutInt( p_libvlc, psz_newvar, value.b_bool );
88 case CONFIG_ITEM_INTEGER:
89 config_PutInt( p_libvlc, psz_newvar, value.i_int );
91 case CONFIG_ITEM_FLOAT:
92 config_PutFloat( p_libvlc, psz_newvar, value.f_float );
95 config_PutPsz( p_libvlc, psz_newvar, value.psz_string );
98 if( i_object ) vlc_object_release( p_libvlc );
102 /* EXPLICIT HACK (this is the legacy API anyway):
103 * VLC_VariableSet is only used from the browser plugins, so we
104 * can pretty much assume that the input is _not_ trusted. */
105 module_config_t *p_item;
106 p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_var );
109 if( !p_item->b_safe )
112 i_ret = var_Set( p_libvlc, psz_var, value );
118 /*****************************************************************************
119 * VLC_VariableGet: get a vlc variable
120 *****************************************************************************/
121 int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
125 i_ret = var_Get( p_libvlc , psz_var, p_value );
130 /*****************************************************************************
131 * VLC_VariableType: get a vlc variable type
132 *****************************************************************************/
133 int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
137 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
138 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
139 if( !strncmp( psz_var, "conf::", 6 ) )
141 module_config_t *p_item;
142 char const *psz_newvar = psz_var + 6;
144 p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
148 switch( p_item->i_type )
150 case CONFIG_ITEM_BOOL:
151 i_type = VLC_VAR_BOOL;
153 case CONFIG_ITEM_INTEGER:
154 i_type = VLC_VAR_INTEGER;
156 case CONFIG_ITEM_FLOAT:
157 i_type = VLC_VAR_FLOAT;
160 i_type = VLC_VAR_STRING;
168 i_type = VLC_VAR_TYPE & var_Type( p_libvlc , psz_var );
180 #define LIBVLC_PLAYLIST_FUNC \
181 libvlc_int_t *p_libvlc = vlc_current_object( i_object );\
182 if( !p_libvlc ) return VLC_ENOOBJ; \
183 playlist_t *p_playlist = pl_Yield( p_libvlc ); \
184 if( !p_playlist ) return VLC_ENOOBJ
186 #define LIBVLC_PLAYLIST_FUNC_END \
187 pl_Release( p_libvlc ); \
188 if( i_object ) vlc_object_release( p_libvlc );
190 /*****************************************************************************
191 * VLC_AddTarget: adds a target for playing.
192 *****************************************************************************
193 * This function adds psz_target to the playlist
194 *****************************************************************************/
196 int VLC_AddTarget( int i_object, char const *psz_target,
197 char const **ppsz_options, int i_options,
198 int i_mode, int i_pos )
201 LIBVLC_PLAYLIST_FUNC;
202 i_err = playlist_AddExt( p_playlist, psz_target,
203 NULL, i_mode, i_pos, -1,
204 ppsz_options, i_options, true, false );
205 LIBVLC_PLAYLIST_FUNC_END;
209 /*****************************************************************************
210 * VLC_Play: play the playlist
211 *****************************************************************************/
212 int VLC_Play( int i_object )
214 LIBVLC_PLAYLIST_FUNC;
215 playlist_Play( p_playlist );
216 LIBVLC_PLAYLIST_FUNC_END;
220 /*****************************************************************************
221 * VLC_Pause: toggle pause
222 *****************************************************************************/
223 int VLC_Pause( int i_object )
225 LIBVLC_PLAYLIST_FUNC;
226 playlist_Pause( p_playlist );
227 LIBVLC_PLAYLIST_FUNC_END;
231 /*****************************************************************************
232 * VLC_Stop: stop playback
233 *****************************************************************************/
234 int VLC_Stop( int i_object )
236 LIBVLC_PLAYLIST_FUNC;
237 playlist_Stop( p_playlist );
238 LIBVLC_PLAYLIST_FUNC_END;
242 /*****************************************************************************
243 * VLC_IsPlaying: Query for Playlist Status
244 *****************************************************************************/
245 bool VLC_IsPlaying( int i_object )
249 LIBVLC_PLAYLIST_FUNC;
250 if( p_playlist->p_input )
253 var_Get( p_playlist->p_input, "state", &val );
254 b_playing = ( val.i_int == PLAYING_S );
258 b_playing = playlist_IsPlaying( p_playlist );
260 LIBVLC_PLAYLIST_FUNC_END;
265 * Get the current position in a input
267 * Return the current position as a float
268 * \note For some inputs, this will be unknown.
270 * \param i_object a vlc object id
271 * \return a float in the range of 0.0 - 1.0
273 float VLC_PositionGet( int i_object )
275 input_thread_t *p_input;
279 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
283 if( i_object ) vlc_object_release( p_libvlc );
287 var_Get( p_input, "position", &val );
288 vlc_object_release( p_input );
295 * Set the current position in a input
297 * Set the current position in a input and then return
298 * the current position as a float.
299 * \note For some inputs, this will be unknown.
301 * \param i_object a vlc object id
302 * \param i_position a float in the range of 0.0 - 1.0
303 * \return a float in the range of 0.0 - 1.0
305 float VLC_PositionSet( int i_object, float i_position )
307 input_thread_t *p_input;
309 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
311 /* Check that the handle is valid */
317 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
321 if( i_object ) vlc_object_release( p_libvlc );
325 val.f_float = i_position;
326 var_Set( p_input, "position", val );
327 var_Get( p_input, "position", &val );
328 vlc_object_release( p_input );
330 if( i_object ) vlc_object_release( p_libvlc );
335 * Get the current position in a input
337 * Return the current position in seconds from the start.
338 * \note For some inputs, this will be unknown.
340 * \param i_object a vlc object id
341 * \return the offset from 0:00 in seconds
343 int VLC_TimeGet( int i_object )
345 input_thread_t *p_input;
347 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
349 /* Check that the handle is valid */
355 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
359 if( i_object ) vlc_object_release( p_libvlc );
363 var_Get( p_input, "time", &val );
364 vlc_object_release( p_input );
366 if( i_object ) vlc_object_release( p_libvlc );
367 return val.i_time / 1000000;
371 * Seek to a position in the current input
373 * Seek i_seconds in the current input. If b_relative is set,
374 * then the seek will be relative to the current position, otherwise
375 * it will seek to i_seconds from the beginning of the input.
376 * \note For some inputs, this will be unknown.
378 * \param i_object a vlc object id
379 * \param i_seconds seconds from current position or from beginning of input
380 * \param b_relative seek relative from current position
381 * \return VLC_SUCCESS on success
383 int VLC_TimeSet( int i_object, int i_seconds, bool b_relative )
385 input_thread_t *p_input;
387 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
389 /* Check that the handle is valid */
395 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
399 if( i_object ) vlc_object_release( p_libvlc );
405 val.i_time = i_seconds;
406 val.i_time = val.i_time * 1000000L;
407 var_Set( p_input, "time-offset", val );
411 val.i_time = i_seconds;
412 val.i_time = val.i_time * 1000000L;
413 var_Set( p_input, "time", val );
415 vlc_object_release( p_input );
417 if( i_object ) vlc_object_release( p_libvlc );
422 * Get the total length of a input
424 * Return the total length in seconds from the current input.
425 * \note For some inputs, this will be unknown.
427 * \param i_object a vlc object id
428 * \return the length in seconds
430 int VLC_LengthGet( int i_object )
432 input_thread_t *p_input;
434 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
436 /* Check that the handle is valid */
442 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
446 if( i_object ) vlc_object_release( p_libvlc );
450 var_Get( p_input, "length", &val );
451 vlc_object_release( p_input );
453 if( i_object ) vlc_object_release( p_libvlc );
454 return val.i_time / 1000000L;
458 * Play the input faster than realtime
460 * 2x, 4x, 8x faster than realtime
461 * \note For some inputs, this will be impossible.
463 * \param i_object a vlc object id
464 * \return the current speedrate
466 float VLC_SpeedFaster( int i_object )
468 input_thread_t *p_input;
470 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
472 /* Check that the handle is valid */
478 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
482 if( i_object ) vlc_object_release( p_libvlc );
487 var_Set( p_input, "rate-faster", val );
488 var_Get( p_input, "rate", &val );
489 vlc_object_release( p_input );
491 if( i_object ) vlc_object_release( p_libvlc );
492 return val.f_float / INPUT_RATE_DEFAULT;
496 * Play the input slower than realtime
498 * 1/2x, 1/4x, 1/8x slower than realtime
499 * \note For some inputs, this will be impossible.
501 * \param i_object a vlc object id
502 * \return the current speedrate
504 float VLC_SpeedSlower( int i_object )
506 input_thread_t *p_input;
508 libvlc_int_t *p_libvlc = vlc_current_object( i_object );
510 /* Check that the handle is valid */
516 p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
520 if( i_object ) vlc_object_release( p_libvlc );
525 var_Set( p_input, "rate-slower", val );
526 var_Get( p_input, "rate", &val );
527 vlc_object_release( p_input );
529 if( i_object ) vlc_object_release( p_libvlc );
530 return val.f_float / INPUT_RATE_DEFAULT;
534 * Return the current playlist item
536 * Returns the index of the playlistitem that is currently selected for play.
537 * This is valid even if nothing is currently playing.
539 * \param i_object a vlc object id
540 * \return the current index
542 int VLC_PlaylistIndex( int i_object )
545 printf( "This function is deprecated and should not be used anymore" );
550 * Total number of items in the playlist
552 * \param i_object a vlc object id
553 * \return amount of playlist items
555 int VLC_PlaylistNumberOfItems( int i_object )
558 LIBVLC_PLAYLIST_FUNC;
559 i_size = p_playlist->items.i_size;
560 LIBVLC_PLAYLIST_FUNC_END;
565 * Go to next playlist item
566 * \param i_object a vlc object id
567 * \return VLC_SUCCESS on success
569 int VLC_PlaylistNext( int i_object )
571 LIBVLC_PLAYLIST_FUNC;
572 playlist_Next( p_playlist );
573 LIBVLC_PLAYLIST_FUNC_END;
578 * Go to previous playlist item
579 * \param i_object a vlc object id
580 * \return VLC_SUCCESS on success
582 int VLC_PlaylistPrev( int i_object )
584 LIBVLC_PLAYLIST_FUNC;
585 playlist_Prev( p_playlist );
586 LIBVLC_PLAYLIST_FUNC_END;
593 int VLC_PlaylistClear( int i_object )
595 LIBVLC_PLAYLIST_FUNC;
596 playlist_Clear( p_playlist, true );
597 LIBVLC_PLAYLIST_FUNC_END;
604 * \param i_object a vlc object id
605 * \param i_volume something in a range from 0-200
606 * \return the new volume (range 0-200 %)
608 int VLC_VolumeSet( int i_object, int i_volume )
610 audio_volume_t i_vol = 0;
613 if( i_volume >= 0 && i_volume <= 200 )
615 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
616 aout_VolumeSet( p_libvlc, i_vol );
619 return i_vol * 200 / AOUT_VOLUME_MAX;
623 * Get the current volume
625 * Retrieve the current volume.
627 * \param i_object a vlc object id
628 * \return the current volume (range 0-200 %)
630 int VLC_VolumeGet( int i_object )
632 audio_volume_t i_volume;
634 aout_VolumeGet( p_libvlc, &i_volume );
636 return i_volume*200/AOUT_VOLUME_MAX;
640 * Mute/Unmute the volume
642 * \param i_object a vlc object id
643 * \return VLC_SUCCESS on success
645 int VLC_VolumeMute( int i_object )
648 aout_VolumeMute( p_libvlc, NULL );
653 /*****************************************************************************
654 * VLC_FullScreen: toggle fullscreen mode
655 *****************************************************************************/
656 int VLC_FullScreen( int i_object )
658 vout_thread_t *p_vout;
660 p_vout = vlc_object_find( p_libvlc, VLC_OBJECT_VOUT, FIND_CHILD );
664 if( i_object ) vlc_object_release( p_libvlc );
668 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
669 vlc_object_release( p_vout );