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 *****************************************************************************/
44 #include "control/libvlc_internal.h"
47 #include <vlc_playlist.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 ) \
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
;
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
)
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
);
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
)
114 switch( p_item
->i_type
)
116 case CONFIG_ITEM_BOOL
:
117 config_PutInt( p_libvlc
, psz_newvar
, value
.b_bool
);
119 case CONFIG_ITEM_INTEGER
:
120 config_PutInt( p_libvlc
, psz_newvar
, value
.i_int
);
122 case CONFIG_ITEM_FLOAT
:
123 config_PutFloat( p_libvlc
, psz_newvar
, value
.f_float
);
126 config_PutPsz( p_libvlc
, psz_newvar
, value
.psz_string
);
129 if( i_object
) vlc_object_release( p_libvlc
);
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
);
140 if( !p_item
->b_safe
)
143 i_ret
= var_Set( p_libvlc
, psz_var
, value
);
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
)
156 i_ret
= var_Get( p_libvlc
, psz_var
, p_value
);
161 /*****************************************************************************
162 * VLC_VariableType: get a vlc variable type
163 *****************************************************************************/
164 int VLC_VariableType( int i_object
, char const *psz_var
, int *pi_type
)
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
);
179 switch( p_item
->i_type
)
181 case CONFIG_ITEM_BOOL
:
182 i_type
= VLC_VAR_BOOL
;
184 case CONFIG_ITEM_INTEGER
:
185 i_type
= VLC_VAR_INTEGER
;
187 case CONFIG_ITEM_FLOAT
:
188 i_type
= VLC_VAR_FLOAT
;
191 i_type
= VLC_VAR_STRING
;
199 i_type
= VLC_VAR_TYPE
& var_Type( p_libvlc
, psz_var
);
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
)
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
;
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
;
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
;
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
;
273 /*****************************************************************************
274 * VLC_IsPlaying: Query for Playlist Status
275 *****************************************************************************/
276 bool VLC_IsPlaying( int i_object
)
280 LIBVLC_PLAYLIST_FUNC
;
281 if( p_playlist
->p_input
)
284 var_Get( p_playlist
->p_input
, "state", &val
);
285 b_playing
= ( val
.i_int
== PLAYING_S
);
289 b_playing
= playlist_IsPlaying( p_playlist
);
291 LIBVLC_PLAYLIST_FUNC_END
;
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
;
310 p_input
= vlc_object_find( p_libvlc
, VLC_OBJECT_INPUT
, FIND_CHILD
);
314 if( i_object
) vlc_object_release( p_libvlc
);
318 var_Get( p_input
, "position", &val
);
319 vlc_object_release( p_input
);
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
;
340 libvlc_int_t
*p_libvlc
= vlc_current_object( i_object
);
342 /* Check that the handle is valid */
348 p_input
= vlc_object_find( p_libvlc
, VLC_OBJECT_INPUT
, FIND_CHILD
);
352 if( i_object
) vlc_object_release( p_libvlc
);
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
);
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
;
378 libvlc_int_t
*p_libvlc
= vlc_current_object( i_object
);
380 /* Check that the handle is valid */
386 p_input
= vlc_object_find( p_libvlc
, VLC_OBJECT_INPUT
, FIND_CHILD
);
390 if( i_object
) vlc_object_release( p_libvlc
);
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
;
418 libvlc_int_t
*p_libvlc
= vlc_current_object( i_object
);
420 /* Check that the handle is valid */
426 p_input
= vlc_object_find( p_libvlc
, VLC_OBJECT_INPUT
, FIND_CHILD
);
430 if( i_object
) vlc_object_release( p_libvlc
);
436 val
.i_time
= i_seconds
;
437 val
.i_time
= val
.i_time
* 1000000L;
438 var_Set( p_input
, "time-offset", val
);
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
);
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
;
465 libvlc_int_t
*p_libvlc
= vlc_current_object( i_object
);
467 /* Check that the handle is valid */
473 p_input
= vlc_object_find( p_libvlc
, VLC_OBJECT_INPUT
, FIND_CHILD
);
477 if( i_object
) vlc_object_release( p_libvlc
);
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
;
501 libvlc_int_t
*p_libvlc
= vlc_current_object( i_object
);
503 /* Check that the handle is valid */
509 p_input
= vlc_object_find( p_libvlc
, VLC_OBJECT_INPUT
, FIND_CHILD
);
513 if( i_object
) vlc_object_release( p_libvlc
);
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
;
539 libvlc_int_t
*p_libvlc
= vlc_current_object( i_object
);
541 /* Check that the handle is valid */
547 p_input
= vlc_object_find( p_libvlc
, VLC_OBJECT_INPUT
, FIND_CHILD
);
551 if( i_object
) vlc_object_release( p_libvlc
);
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
)
576 printf( "This function is deprecated and should not be used anymore" );
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
)
589 LIBVLC_PLAYLIST_FUNC
;
590 i_size
= p_playlist
->items
.i_size
;
591 LIBVLC_PLAYLIST_FUNC_END
;
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
;
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
;
624 int VLC_PlaylistClear( int i_object
)
626 LIBVLC_PLAYLIST_FUNC
;
627 playlist_Clear( p_playlist
, true );
628 LIBVLC_PLAYLIST_FUNC_END
;
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;
644 if( i_volume
>= 0 && i_volume
<= 200 )
646 i_vol
= i_volume
* AOUT_VOLUME_MAX
/ 200;
647 aout_VolumeSet( p_libvlc
, i_vol
);
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
;
665 aout_VolumeGet( p_libvlc
, &i_volume
);
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
)
679 aout_VolumeMute( p_libvlc
, NULL
);
684 /*****************************************************************************
685 * VLC_FullScreen: toggle fullscreen mode
686 *****************************************************************************/
687 int VLC_FullScreen( int i_object
)
689 vout_thread_t
*p_vout
;
691 p_vout
= vlc_object_find( p_libvlc
, VLC_OBJECT_VOUT
, FIND_CHILD
);
695 if( i_object
) vlc_object_release( p_libvlc
);
699 p_vout
->i_changes
|= VOUT_FULLSCREEN_CHANGE
;
700 vlc_object_release( p_vout
);