]> git.sesse.net Git - vlc/blob - src/libvlc.c
Remove a bunch of unused deprecated APIs
[vlc] / src / libvlc.c
1 /*****************************************************************************
2  * libvlc.c: Implementation of the old libvlc API
3  *****************************************************************************
4  * Copyright (C) 1998-2007 the VideoLAN team
5  * $Id$
6  *
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>
12  *
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.
17  *
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.
22  *
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  *****************************************************************************/
27
28 /*****************************************************************************
29  * Pretend we are a builtin module
30  *****************************************************************************/
31 #define MODULE_NAME main
32 #define MODULE_PATH main
33 #define __BUILTIN__
34
35 /*****************************************************************************
36  * Preamble
37  *****************************************************************************/
38 #ifdef HAVE_CONFIG_H
39 # include "config.h"
40 #endif
41
42 #include <vlc/vlc.h>
43
44 #include "control/libvlc_internal.h"
45 #include "libvlc.h"
46
47 #include <vlc_playlist.h>
48
49 #include <vlc_aout.h>
50 #include <vlc_vout.h>
51
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 )
58 {
59     return VERSION_MESSAGE;
60 }
61
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 ;                                                      \
70 }
71
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 );
76
77 extern const char psz_vlc_changeset[];
78 const char* VLC_Changeset( void )
79 {
80     return psz_vlc_changeset;
81 }
82
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 );
88
89
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 )
94 {
95     int i_ret;
96     LIBVLC_FUNC;
97
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 ) )
101     {
102         module_config_t *p_item;
103         char const *psz_newvar = psz_var + 6;
104
105         p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
106
107         if( p_item )
108         {
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;
113
114             switch( p_item->i_type )
115             {
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;
128             }
129             if( i_object ) vlc_object_release( p_libvlc );
130             return VLC_SUCCESS;
131         }
132     }
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;
142
143     i_ret = var_Set( p_libvlc, psz_var, value );
144
145     LIBVLC_FUNC_END;
146     return i_ret;
147 }
148
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 )
153 {
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;
159 }
160
161 /*****************************************************************************
162  * VLC_VariableType: get a vlc variable type
163  *****************************************************************************/
164 int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
165 {
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 ) )
171     {
172         module_config_t *p_item;
173         char const *psz_newvar = psz_var + 6;
174
175         p_item = config_FindConfig( VLC_OBJECT(p_libvlc), psz_newvar );
176
177         if( p_item )
178         {
179             switch( p_item->i_type )
180             {
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;
193             }
194         }
195         else
196             i_type = 0;
197     }
198     else
199         i_type = VLC_VAR_TYPE & var_Type( p_libvlc , psz_var );
200
201     LIBVLC_FUNC_END;
202
203     if( i_type > 0 )
204     {
205         *pi_type = i_type;
206         return VLC_SUCCESS;
207     }
208     return VLC_ENOVAR;
209 }
210
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
216
217 #define LIBVLC_PLAYLIST_FUNC_END \
218     pl_Release( p_libvlc ); \
219     if( i_object ) vlc_object_release( p_libvlc );
220
221 /*****************************************************************************
222  * VLC_AddTarget: adds a target for playing.
223  *****************************************************************************
224  * This function adds psz_target to the playlist
225  *****************************************************************************/
226
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 )
230 {
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;
238 }
239
240 /*****************************************************************************
241  * VLC_Play: play the playlist
242  *****************************************************************************/
243 int VLC_Play( int i_object )
244 {
245     LIBVLC_PLAYLIST_FUNC;
246     playlist_Play( p_playlist );
247     LIBVLC_PLAYLIST_FUNC_END;
248     return VLC_SUCCESS;
249 }
250
251 /*****************************************************************************
252  * VLC_Pause: toggle pause
253  *****************************************************************************/
254 int VLC_Pause( int i_object )
255 {
256     LIBVLC_PLAYLIST_FUNC;
257     playlist_Pause( p_playlist );
258     LIBVLC_PLAYLIST_FUNC_END;
259     return VLC_SUCCESS;
260 }
261
262 /*****************************************************************************
263  * VLC_Stop: stop playback
264  *****************************************************************************/
265 int VLC_Stop( int i_object )
266 {
267     LIBVLC_PLAYLIST_FUNC;
268     playlist_Stop( p_playlist );
269     LIBVLC_PLAYLIST_FUNC_END;
270     return VLC_SUCCESS;
271 }
272
273 /*****************************************************************************
274  * VLC_IsPlaying: Query for Playlist Status
275  *****************************************************************************/
276 bool VLC_IsPlaying( int i_object )
277 {
278     bool   b_playing;
279
280     LIBVLC_PLAYLIST_FUNC;
281     if( p_playlist->p_input )
282     {
283         vlc_value_t  val;
284         var_Get( p_playlist->p_input, "state", &val );
285         b_playing = ( val.i_int == PLAYING_S );
286     }
287     else
288     {
289         b_playing = playlist_IsPlaying( p_playlist );
290     }
291     LIBVLC_PLAYLIST_FUNC_END;
292     return b_playing;
293 }
294
295 /**
296  * Get the current position in a input
297  *
298  * Return the current position as a float
299  * \note For some inputs, this will be unknown.
300  *
301  * \param i_object a vlc object id
302  * \return a float in the range of 0.0 - 1.0
303  */
304 float VLC_PositionGet( int i_object )
305 {
306     input_thread_t *p_input;
307     vlc_value_t val;
308     LIBVLC_FUNC;
309
310     p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
311
312     if( !p_input )
313     {
314         if( i_object ) vlc_object_release( p_libvlc );
315         return VLC_ENOOBJ;
316     }
317
318     var_Get( p_input, "position", &val );
319     vlc_object_release( p_input );
320
321     LIBVLC_FUNC_END;
322     return val.f_float;
323 }
324
325 /**
326  * Set the current position in a input
327  *
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.
331  *
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
335  */
336 float VLC_PositionSet( int i_object, float i_position )
337 {
338     input_thread_t *p_input;
339     vlc_value_t val;
340     libvlc_int_t *p_libvlc = vlc_current_object( i_object );
341
342     /* Check that the handle is valid */
343     if( !p_libvlc )
344     {
345         return VLC_ENOOBJ;
346     }
347
348     p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
349
350     if( !p_input )
351     {
352         if( i_object ) vlc_object_release( p_libvlc );
353         return VLC_ENOOBJ;
354     }
355
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 );
360
361     if( i_object ) vlc_object_release( p_libvlc );
362     return val.f_float;
363 }
364
365 /**
366  * Get the current position in a input
367  *
368  * Return the current position in seconds from the start.
369  * \note For some inputs, this will be unknown.
370  *
371  * \param i_object a vlc object id
372  * \return the offset from 0:00 in seconds
373  */
374 int VLC_TimeGet( int i_object )
375 {
376     input_thread_t *p_input;
377     vlc_value_t val;
378     libvlc_int_t *p_libvlc = vlc_current_object( i_object );
379
380     /* Check that the handle is valid */
381     if( !p_libvlc )
382     {
383         return VLC_ENOOBJ;
384     }
385
386     p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
387
388     if( !p_input )
389     {
390         if( i_object ) vlc_object_release( p_libvlc );
391         return VLC_ENOOBJ;
392     }
393
394     var_Get( p_input, "time", &val );
395     vlc_object_release( p_input );
396
397     if( i_object ) vlc_object_release( p_libvlc );
398     return val.i_time  / 1000000;
399 }
400
401 /**
402  * Seek to a position in the current input
403  *
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.
408  *
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
413  */
414 int VLC_TimeSet( int i_object, int i_seconds, bool b_relative )
415 {
416     input_thread_t *p_input;
417     vlc_value_t val;
418     libvlc_int_t *p_libvlc = vlc_current_object( i_object );
419
420     /* Check that the handle is valid */
421     if( !p_libvlc )
422     {
423         return VLC_ENOOBJ;
424     }
425
426     p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
427
428     if( !p_input )
429     {
430         if( i_object ) vlc_object_release( p_libvlc );
431         return VLC_ENOOBJ;
432     }
433
434     if( b_relative )
435     {
436         val.i_time = i_seconds;
437         val.i_time = val.i_time * 1000000L;
438         var_Set( p_input, "time-offset", val );
439     }
440     else
441     {
442         val.i_time = i_seconds;
443         val.i_time = val.i_time * 1000000L;
444         var_Set( p_input, "time", val );
445     }
446     vlc_object_release( p_input );
447
448     if( i_object ) vlc_object_release( p_libvlc );
449     return VLC_SUCCESS;
450 }
451
452 /**
453  * Get the total length of a input
454  *
455  * Return the total length in seconds from the current input.
456  * \note For some inputs, this will be unknown.
457  *
458  * \param i_object a vlc object id
459  * \return the length in seconds
460  */
461 int VLC_LengthGet( int i_object )
462 {
463     input_thread_t *p_input;
464     vlc_value_t val;
465     libvlc_int_t *p_libvlc = vlc_current_object( i_object );
466
467     /* Check that the handle is valid */
468     if( !p_libvlc )
469     {
470         return VLC_ENOOBJ;
471     }
472
473     p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
474
475     if( !p_input )
476     {
477         if( i_object ) vlc_object_release( p_libvlc );
478         return VLC_ENOOBJ;
479     }
480
481     var_Get( p_input, "length", &val );
482     vlc_object_release( p_input );
483
484     if( i_object ) vlc_object_release( p_libvlc );
485     return val.i_time  / 1000000L;
486 }
487
488 /**
489  * Play the input faster than realtime
490  *
491  * 2x, 4x, 8x faster than realtime
492  * \note For some inputs, this will be impossible.
493  *
494  * \param i_object a vlc object id
495  * \return the current speedrate
496  */
497 float VLC_SpeedFaster( int i_object )
498 {
499     input_thread_t *p_input;
500     vlc_value_t val;
501     libvlc_int_t *p_libvlc = vlc_current_object( i_object );
502
503     /* Check that the handle is valid */
504     if( !p_libvlc )
505     {
506         return VLC_ENOOBJ;
507     }
508
509     p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
510
511     if( !p_input )
512     {
513         if( i_object ) vlc_object_release( p_libvlc );
514         return VLC_ENOOBJ;
515     }
516
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 );
521
522     if( i_object ) vlc_object_release( p_libvlc );
523     return val.f_float / INPUT_RATE_DEFAULT;
524 }
525
526 /**
527  * Play the input slower than realtime
528  *
529  * 1/2x, 1/4x, 1/8x slower than realtime
530  * \note For some inputs, this will be impossible.
531  *
532  * \param i_object a vlc object id
533  * \return the current speedrate
534  */
535 float VLC_SpeedSlower( int i_object )
536 {
537     input_thread_t *p_input;
538     vlc_value_t val;
539     libvlc_int_t *p_libvlc = vlc_current_object( i_object );
540
541     /* Check that the handle is valid */
542     if( !p_libvlc )
543     {
544         return VLC_ENOOBJ;
545     }
546
547     p_input = vlc_object_find( p_libvlc, VLC_OBJECT_INPUT, FIND_CHILD );
548
549     if( !p_input )
550     {
551         if( i_object ) vlc_object_release( p_libvlc );
552         return VLC_ENOOBJ;
553     }
554
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 );
559
560     if( i_object ) vlc_object_release( p_libvlc );
561     return val.f_float / INPUT_RATE_DEFAULT;
562 }
563
564 /**
565  * Return the current playlist item
566  *
567  * Returns the index of the playlistitem that is currently selected for play.
568  * This is valid even if nothing is currently playing.
569  *
570  * \param i_object a vlc object id
571  * \return the current index
572  */
573 int VLC_PlaylistIndex( int i_object )
574 {
575     (void)i_object;
576     printf( "This function is deprecated and should not be used anymore" );
577     return -1;
578 }
579
580 /**
581  * Total number of items in the playlist
582  *
583  * \param i_object a vlc object id
584  * \return amount of playlist items
585  */
586 int VLC_PlaylistNumberOfItems( int i_object )
587 {
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;
593 }
594
595 /**
596  * Go to next playlist item
597  * \param i_object a vlc object id
598  * \return VLC_SUCCESS on success
599  */
600 int VLC_PlaylistNext( int i_object )
601 {
602     LIBVLC_PLAYLIST_FUNC;
603     playlist_Next( p_playlist );
604     LIBVLC_PLAYLIST_FUNC_END;
605     return VLC_SUCCESS;
606 }
607
608 /**
609  * Go to previous playlist item
610  * \param i_object a vlc object id
611  * \return VLC_SUCCESS on success
612  */
613 int VLC_PlaylistPrev( int i_object )
614 {
615     LIBVLC_PLAYLIST_FUNC;
616     playlist_Prev( p_playlist );
617     LIBVLC_PLAYLIST_FUNC_END;
618     return VLC_SUCCESS;
619 }
620
621 /**
622  * Empty the playlist
623  */
624 int VLC_PlaylistClear( int i_object )
625 {
626     LIBVLC_PLAYLIST_FUNC;
627     playlist_Clear( p_playlist, true );
628     LIBVLC_PLAYLIST_FUNC_END;
629     return VLC_SUCCESS;
630 }
631
632 /**
633  * Change the volume
634  *
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 %)
638  */
639 int VLC_VolumeSet( int i_object, int i_volume )
640 {
641     audio_volume_t i_vol = 0;
642     LIBVLC_FUNC;
643
644     if( i_volume >= 0 && i_volume <= 200 )
645     {
646         i_vol = i_volume * AOUT_VOLUME_MAX / 200;
647         aout_VolumeSet( p_libvlc, i_vol );
648     }
649     LIBVLC_FUNC_END;
650     return i_vol * 200 / AOUT_VOLUME_MAX;
651 }
652
653 /**
654  * Get the current volume
655  *
656  * Retrieve the current volume.
657  *
658  * \param i_object a vlc object id
659  * \return the current volume (range 0-200 %)
660  */
661 int VLC_VolumeGet( int i_object )
662 {
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;
668 }
669
670 /**
671  * Mute/Unmute the volume
672  *
673  * \param i_object a vlc object id
674  * \return VLC_SUCCESS on success
675  */
676 int VLC_VolumeMute( int i_object )
677 {
678     LIBVLC_FUNC;
679     aout_VolumeMute( p_libvlc, NULL );
680     LIBVLC_FUNC_END;
681     return VLC_SUCCESS;
682 }
683
684 /*****************************************************************************
685  * VLC_FullScreen: toggle fullscreen mode
686  *****************************************************************************/
687 int VLC_FullScreen( int i_object )
688 {
689     vout_thread_t *p_vout;
690     LIBVLC_FUNC;
691     p_vout = vlc_object_find( p_libvlc, VLC_OBJECT_VOUT, FIND_CHILD );
692
693     if( !p_vout )
694     {
695         if( i_object ) vlc_object_release( p_libvlc );
696         return VLC_ENOOBJ;
697     }
698
699     p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
700     vlc_object_release( p_vout );
701     LIBVLC_FUNC_END;
702     return VLC_SUCCESS;
703 }