]> git.sesse.net Git - vlc/blob - bindings/python/vlc_instance.c
python bindings : fix pyoptions_to_args and a memleak in the same time
[vlc] / bindings / python / vlc_instance.c
1 /*****************************************************************************
2  * vlc_instance.c: vlc.Instance binding
3  *****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23 #include "vlcglue.h"
24
25 /* Helper functions */
26 static Py_ssize_t
27 pyoptions_to_args(PyObject *py_options, char*** pppsz_args)
28 {
29     Py_ssize_t i_size;
30     Py_ssize_t  i_index;
31
32     Py_INCREF( py_options );
33     if( ! PySequence_Check( py_options ) )
34     {
35         PyErr_SetString( PyExc_TypeError, "Parameter must be a sequence." );
36         return -1;
37     }
38     i_size = PySequence_Size( py_options );
39
40     char **ppsz_args = *pppsz_args = malloc( ( i_size + 1 ) * sizeof( char * ) );
41
42     if( ! ppsz_args )
43     {
44         PyErr_SetString( PyExc_MemoryError, "Out of memory" );
45         return -1;
46     }
47
48     for ( i_index = 0; i_index < i_size; i_index++ )
49     {
50         ppsz_args[i_index] =
51             strdup( PyString_AsString( PyObject_Str(
52                                            PySequence_GetItem( py_options,
53                                                                i_index ) ) ) );
54     }
55     ppsz_args[i_size] = NULL;
56     Py_DECREF( py_options );
57     return i_size;
58 }
59
60 static void
61 free_args(int i_size, char** ppsz_args)
62 {
63     int i_index;
64
65     for ( i_index = 0; i_index < i_size; i_index++ )
66         free( ppsz_args[i_index] );
67     free( ppsz_args );
68 }
69
70 /*****************************************************************************
71  * Instance object implementation
72  *****************************************************************************/
73
74 static PyObject *
75 vlcInstance_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
76 {
77     vlcInstance *self;
78     libvlc_exception_t ex;
79     PyObject* py_list = NULL;
80     char** ppsz_args = NULL;
81     int i_size = 0;
82
83     if( PyArg_ParseTuple( args, "O", &py_list ) )
84     {
85         i_size = pyoptions_to_args( py_list, &ppsz_args );
86         if( i_size < 0 )
87             return NULL;
88     }
89     else
90     {
91         /* No arguments were given. Clear the exception raised
92            by PyArg_ParseTuple. */
93         PyErr_Clear( );
94     }
95
96     self = PyObject_New( vlcInstance, &vlcInstance_Type );
97
98     Py_BEGIN_ALLOW_THREADS
99     LIBVLC_TRY
100     LIBVLC_INSTANCE->p_instance = libvlc_new( i_size, ppsz_args, &ex );
101     free_args( i_size, ppsz_args );
102     LIBVLC_EXCEPT
103     Py_END_ALLOW_THREADS
104
105     Py_INCREF( self );
106     return ( PyObject * )self;
107 }
108
109 static void
110 vlcInstance_dealloc( PyObject *self )
111 {
112     libvlc_release( LIBVLC_INSTANCE->p_instance );
113     PyObject_DEL( self );
114 }
115
116 static PyObject *
117 vlcInstance_get_vlc_id( PyObject *self, PyObject *args )
118 {
119     return Py_BuildValue( "i", libvlc_get_vlc_id( LIBVLC_INSTANCE->p_instance ) );
120 }
121
122 /* Set loop variable */
123 static PyObject *
124 vlcInstance_playlist_loop( PyObject *self, PyObject *args )
125 {
126     libvlc_exception_t ex;
127     int i_loop = 0;
128
129     if( !PyArg_ParseTuple( args, "i", &i_loop ) )
130         return NULL;
131
132     LIBVLC_TRY;
133     libvlc_playlist_loop( LIBVLC_INSTANCE->p_instance, i_loop, &ex );
134     LIBVLC_EXCEPT;
135
136     Py_INCREF( Py_None );
137     return Py_None;
138 }
139
140 /* Playlist play. 2 parameters: i_id, the id to play
141    l_options: a list of options */
142 static PyObject *
143 vlcInstance_playlist_play( PyObject *self, PyObject *args )
144 {
145     libvlc_exception_t ex;
146     int i_id = -1;
147     PyObject *py_options = NULL;
148     int i_size = 0;
149     char** ppsz_args = NULL;
150
151     if( !PyArg_ParseTuple( args, "|iO", &i_id, &py_options ) )
152         return NULL;
153
154     if( py_options )
155     {
156         i_size = pyoptions_to_args( py_options, &ppsz_args );
157     }
158
159     LIBVLC_TRY;
160     libvlc_playlist_play( LIBVLC_INSTANCE->p_instance, i_id, i_size, ppsz_args, &ex );
161     free_args( i_size, ppsz_args );
162     LIBVLC_EXCEPT;
163
164     Py_INCREF( Py_None );
165     return Py_None;
166 }
167
168 static PyObject *
169 vlcInstance_playlist_pause( PyObject *self, PyObject *args )
170 {
171     libvlc_exception_t ex;
172     LIBVLC_TRY;
173     libvlc_playlist_pause( LIBVLC_INSTANCE->p_instance, &ex );
174     LIBVLC_EXCEPT;
175     Py_INCREF( Py_None );
176     return Py_None;
177 }
178
179 static PyObject *
180 vlcInstance_playlist_isplaying( PyObject *self, PyObject *args )
181 {
182     libvlc_exception_t ex;
183     int i_ret;
184
185     LIBVLC_TRY;
186     i_ret = libvlc_playlist_isplaying( LIBVLC_INSTANCE->p_instance, &ex );
187     LIBVLC_EXCEPT;
188     return Py_BuildValue( "i", i_ret );
189 }
190
191 static PyObject *
192 vlcInstance_playlist_items_count( PyObject *self, PyObject *args )
193 {
194     libvlc_exception_t ex;
195     int i_ret;
196
197     LIBVLC_TRY;
198     i_ret = libvlc_playlist_items_count( LIBVLC_INSTANCE->p_instance, &ex );
199     LIBVLC_EXCEPT;
200     return Py_BuildValue( "i", i_ret );
201 }
202
203 static PyObject *
204 vlcInstance_playlist_stop( PyObject *self, PyObject *args )
205 {
206     libvlc_exception_t ex;
207     LIBVLC_TRY;
208     libvlc_playlist_stop( LIBVLC_INSTANCE->p_instance, &ex );
209     LIBVLC_EXCEPT;
210     Py_INCREF( Py_None );
211     return Py_None;
212 }
213
214 static PyObject *
215 vlcInstance_playlist_next( PyObject *self, PyObject *args )
216 {
217     libvlc_exception_t ex;
218     LIBVLC_TRY;
219     libvlc_playlist_next( LIBVLC_INSTANCE->p_instance, &ex );
220     LIBVLC_EXCEPT;
221     Py_INCREF( Py_None );
222     return Py_None;
223 }
224
225 static PyObject *
226 vlcInstance_playlist_prev( PyObject *self, PyObject *args )
227 {
228     libvlc_exception_t ex;
229     LIBVLC_TRY;
230     libvlc_playlist_prev( LIBVLC_INSTANCE->p_instance, &ex );
231     LIBVLC_EXCEPT;
232     Py_INCREF( Py_None );
233     return Py_None;
234 }
235
236 static PyObject *
237 vlcInstance_playlist_clear( PyObject *self, PyObject *args )
238 {
239     libvlc_exception_t ex;
240     LIBVLC_TRY;
241     libvlc_playlist_clear( LIBVLC_INSTANCE->p_instance, &ex );
242     LIBVLC_EXCEPT;
243     Py_INCREF( Py_None );
244     return Py_None;
245 }
246
247 /* Add a playlist item. Main parameter: URI.
248    Optional parameters: name, options */
249 static PyObject *
250 vlcInstance_playlist_add( PyObject *self, PyObject *args)
251 {
252     libvlc_exception_t ex;
253     int i_ret;
254     char* psz_uri = NULL;
255     char* psz_name = NULL;
256     PyObject *py_options = NULL;
257     int i_size = 0;
258     char** ppsz_args = NULL;
259
260     if( !PyArg_ParseTuple( args, "s|sO", &psz_uri, &psz_name, &py_options ) )
261         return NULL;
262
263     if( !psz_name )
264     {
265         /* Set a default name */
266         psz_name = strdup( psz_uri );
267     }
268
269     if( py_options )
270     {
271         i_size = pyoptions_to_args( py_options, &ppsz_args );
272     }
273
274     LIBVLC_TRY;
275     if( ppsz_args )
276     {
277         i_ret = libvlc_playlist_add_extended( LIBVLC_INSTANCE->p_instance,
278                                               psz_uri,
279                                               psz_name,
280                                               i_size,
281                                               ppsz_args,
282                                               &ex );
283         free_args( i_size, ppsz_args );
284     }
285     else
286     {
287         i_ret = libvlc_playlist_add( LIBVLC_INSTANCE->p_instance,
288                                      psz_uri,
289                                      psz_name,
290                                      &ex );
291     }
292     LIBVLC_EXCEPT;
293
294     return Py_BuildValue( "i", i_ret );
295 }
296
297 static PyObject *
298 vlcInstance_playlist_delete_item( PyObject *self, PyObject *args )
299 {
300     libvlc_exception_t ex;
301     int i_id;
302     int i_ret;
303
304     if( !PyArg_ParseTuple( args, "i", &i_id ) )
305         return NULL;
306
307     LIBVLC_TRY;
308     i_ret = libvlc_playlist_delete_item( LIBVLC_INSTANCE->p_instance, i_id, &ex );
309     LIBVLC_EXCEPT;
310
311     return Py_BuildValue( "i", i_ret );
312 }
313
314 static PyObject *
315 vlcInstance_playlist_get_media_instance( PyObject *self, PyObject *args )
316 {
317     libvlc_exception_t ex;
318     libvlc_media_instance_t *p_mi;
319     vlcMediaInstance *p_ret;
320
321     LIBVLC_TRY;
322     p_mi = libvlc_playlist_get_media_instance( LIBVLC_INSTANCE->p_instance, &ex );
323     LIBVLC_EXCEPT;
324
325     p_ret = PyObject_New( vlcMediaInstance, &vlcMediaInstance_Type );
326     p_ret->p_mi = p_mi;
327     Py_INCREF( p_ret ); /* Ah bon ? */
328     return ( PyObject * )p_ret;
329 }
330
331 static PyObject *
332 vlcInstance_video_set_parent( PyObject *self, PyObject *args )
333 {
334     libvlc_exception_t ex;
335     int i_drawable;
336
337     if( !PyArg_ParseTuple( args, "i", &i_drawable ) )
338         return NULL;
339
340     LIBVLC_TRY;
341     libvlc_video_set_parent( LIBVLC_INSTANCE->p_instance, (libvlc_drawable_t) i_drawable, &ex );
342     LIBVLC_EXCEPT;
343
344     Py_INCREF( Py_None );
345     return Py_None;
346 }
347
348 static PyObject *
349 vlcInstance_video_get_parent( PyObject *self, PyObject *args )
350 {
351     libvlc_exception_t ex;
352     libvlc_drawable_t i_ret;
353
354     LIBVLC_TRY;
355     i_ret = libvlc_video_get_parent( LIBVLC_INSTANCE->p_instance, &ex );
356     LIBVLC_EXCEPT;
357
358     return Py_BuildValue( "L", i_ret );
359 }
360
361 static PyObject *
362 vlcInstance_video_set_size( PyObject *self, PyObject *args )
363 {
364     libvlc_exception_t ex;
365     int i_width;
366     int i_height;
367
368     if( !PyArg_ParseTuple( args, "ii", &i_width, &i_height ) )
369         return NULL;
370
371     LIBVLC_TRY;
372     libvlc_video_set_size( LIBVLC_INSTANCE->p_instance, i_width, i_height, &ex );
373     LIBVLC_EXCEPT;
374
375     Py_INCREF( Py_None );
376     return Py_None;
377 }
378
379 static PyObject *
380 vlcInstance_audio_toggle_mute( PyObject *self, PyObject *args )
381 {
382     libvlc_exception_t ex;
383     LIBVLC_TRY;
384     libvlc_audio_toggle_mute( LIBVLC_INSTANCE->p_instance, &ex );
385     LIBVLC_EXCEPT;
386     Py_INCREF( Py_None );
387     return Py_None;
388 }
389
390 static PyObject *
391 vlcInstance_audio_get_mute( PyObject *self, PyObject *args )
392 {
393     libvlc_exception_t ex;
394     int i_ret;
395
396     LIBVLC_TRY;
397     i_ret = libvlc_audio_get_mute( LIBVLC_INSTANCE->p_instance, &ex );
398     LIBVLC_EXCEPT;
399     return Py_BuildValue( "i", i_ret );
400 }
401
402 static PyObject *
403 vlcInstance_audio_set_mute( PyObject *self, PyObject *args )
404 {
405     libvlc_exception_t ex;
406     int i_mute;
407
408     if( !PyArg_ParseTuple( args, "i", &i_mute ) )
409         return NULL;
410
411     LIBVLC_TRY;
412     libvlc_audio_set_mute( LIBVLC_INSTANCE->p_instance, i_mute, &ex );
413     LIBVLC_EXCEPT;
414     Py_INCREF( Py_None );
415     return Py_None;
416 }
417
418 static PyObject *
419 vlcInstance_audio_get_volume( PyObject *self, PyObject *args )
420 {
421     libvlc_exception_t ex;
422     int i_ret;
423
424     LIBVLC_TRY;
425     i_ret = libvlc_audio_get_volume( LIBVLC_INSTANCE->p_instance, &ex );
426     LIBVLC_EXCEPT;
427     return Py_BuildValue( "i", i_ret );
428 }
429
430 static PyObject *
431 vlcInstance_audio_set_volume( PyObject *self, PyObject *args )
432 {
433     libvlc_exception_t ex;
434     int i_volume;
435
436     if( !PyArg_ParseTuple( args, "i", &i_volume ) )
437         return NULL;
438
439     LIBVLC_TRY;
440     libvlc_audio_set_volume( LIBVLC_INSTANCE->p_instance, i_volume, &ex );
441     LIBVLC_EXCEPT;
442     Py_INCREF( Py_None );
443     return Py_None;
444 }
445
446 static PyObject *
447 vlcInstance_audio_get_channel( PyObject *self, PyObject *args )
448 {
449     libvlc_exception_t ex;
450     int i_ret;
451
452     LIBVLC_TRY;
453     i_ret = libvlc_audio_get_channel( LIBVLC_INSTANCE->p_instance, &ex );
454     LIBVLC_EXCEPT;
455     return Py_BuildValue( "i", i_ret );
456 }
457
458 static PyObject *
459 vlcInstance_audio_set_channel( PyObject *self, PyObject *args )
460 {
461     libvlc_exception_t ex;
462     int i_channel;
463
464     if( !PyArg_ParseTuple( args, "i", &i_channel ) )
465         return NULL;
466
467     LIBVLC_TRY;
468     libvlc_audio_set_channel( LIBVLC_INSTANCE->p_instance, i_channel, &ex );
469     LIBVLC_EXCEPT;
470     Py_INCREF( Py_None );
471     return Py_None;
472 }
473
474 /* vlm_add_broadcast : name, input MRL, output MRL
475    Keywords: options, enable, loop */
476 static PyObject *
477 vlcInstance_vlm_add_broadcast( PyObject *self, PyObject *args, PyObject *kwds )
478 {
479     libvlc_exception_t ex;
480     static char *kwlist[] = { "name", "input", "output",
481                               "options", "enable", "loop", NULL};
482     char* psz_name = NULL;
483     char* psz_input = NULL;
484     char* psz_output = NULL;
485     PyObject* py_options = NULL;
486     int i_enable = 1;
487     int i_loop = 0;
488     int i_size = 0;
489     char** ppsz_args = NULL;
490
491     if( !PyArg_ParseTupleAndKeywords( args, kwds, "sss|Oii", kwlist,
492                                       &psz_name,
493                       &psz_input, &psz_output,
494                       &py_options, &i_enable, &i_loop ) )
495         return NULL;
496  
497     if( py_options )
498     {
499         i_size = pyoptions_to_args( py_options, &ppsz_args );
500     }
501  
502     LIBVLC_TRY;
503     libvlc_vlm_add_broadcast( LIBVLC_INSTANCE->p_instance,
504                               psz_name, psz_input, psz_output,
505                               i_size, ppsz_args, i_enable, i_loop, &ex);
506     free_args( i_size, ppsz_args );
507     LIBVLC_EXCEPT;
508     Py_INCREF( Py_None );
509     return Py_None;
510 }
511
512 static PyObject *
513 vlcInstance_vlm_del_media( PyObject *self, PyObject *args )
514 {
515     libvlc_exception_t ex;
516     char* psz_name;
517
518     if( !PyArg_ParseTuple( args, "s", &psz_name ) )
519         return NULL;
520
521     LIBVLC_TRY;
522     libvlc_vlm_del_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex);
523     LIBVLC_EXCEPT;
524     Py_INCREF( Py_None );
525     return Py_None;
526 }
527
528 static PyObject *
529 vlcInstance_vlm_set_enabled( PyObject *self, PyObject *args )
530 {
531     libvlc_exception_t ex;
532     char* psz_name;
533     int i_enabled;
534  
535     if( !PyArg_ParseTuple( args, "si", &psz_name, &i_enabled ) )
536         return NULL;
537
538     LIBVLC_TRY;
539     libvlc_vlm_set_enabled( LIBVLC_INSTANCE->p_instance, psz_name, i_enabled, &ex);
540     LIBVLC_EXCEPT;
541     Py_INCREF( Py_None );
542     return Py_None;
543 }
544
545 static PyObject *
546 vlcInstance_vlm_set_output( PyObject *self, PyObject *args )
547 {
548     libvlc_exception_t ex;
549     char* psz_name;
550     char* psz_output;
551  
552     if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_output ) )
553         return NULL;
554
555     LIBVLC_TRY;
556     libvlc_vlm_set_output( LIBVLC_INSTANCE->p_instance, psz_name, psz_output, &ex);
557     LIBVLC_EXCEPT;
558     Py_INCREF( Py_None );
559     return Py_None;
560 }
561
562 static PyObject *
563 vlcInstance_vlm_set_input( PyObject *self, PyObject *args )
564 {
565     libvlc_exception_t ex;
566     char* psz_name;
567     char* psz_input;
568  
569     if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_input ) )
570         return NULL;
571
572     LIBVLC_TRY;
573     libvlc_vlm_set_input( LIBVLC_INSTANCE->p_instance, psz_name, psz_input, &ex);
574     LIBVLC_EXCEPT;
575     Py_INCREF( Py_None );
576     return Py_None;
577 }
578
579 static PyObject *
580 vlcInstance_vlm_add_input( PyObject *self, PyObject *args )
581 {
582     libvlc_exception_t ex;
583     char* psz_name;
584     char* psz_input;
585  
586     if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_input ) )
587         return NULL;
588
589     LIBVLC_TRY;
590     libvlc_vlm_add_input( LIBVLC_INSTANCE->p_instance, psz_name, psz_input, &ex);
591     LIBVLC_EXCEPT;
592     Py_INCREF( Py_None );
593     return Py_None;
594 }
595
596 static PyObject *
597 vlcInstance_vlm_set_loop( PyObject *self, PyObject *args )
598 {
599     libvlc_exception_t ex;
600     char* psz_name;
601     int i_loop;
602  
603     if( !PyArg_ParseTuple( args, "si", &psz_name, &i_loop ) )
604         return NULL;
605
606     LIBVLC_TRY;
607     libvlc_vlm_set_loop( LIBVLC_INSTANCE->p_instance, psz_name, i_loop, &ex);
608     LIBVLC_EXCEPT;
609     Py_INCREF( Py_None );
610     return Py_None;
611 }
612
613 static PyObject *
614 vlcInstance_vlm_change_media( PyObject *self, PyObject *args, PyObject *kwds )
615 {
616     libvlc_exception_t ex;
617     static char *kwlist[] = { "name", "input", "output",
618                               "options", "enable", "loop", NULL};
619     char* psz_name = NULL;
620     char* psz_input = NULL;
621     char* psz_output = NULL;
622     PyObject* py_options = NULL;
623     int i_enable = 1;
624     int i_loop = 0;
625     int i_size = 0;
626     char** ppsz_args = NULL;
627
628     if( !PyArg_ParseTupleAndKeywords( args, kwds, "sss|Oii", kwlist,
629                                       &psz_name,
630                       &psz_input, &psz_output,
631                       &py_options, &i_enable, &i_loop ) )
632         return NULL;
633  
634     if( py_options )
635     {
636         i_size = pyoptions_to_args( py_options, &ppsz_args );
637     }
638  
639     LIBVLC_TRY;
640     libvlc_vlm_change_media( LIBVLC_INSTANCE->p_instance,
641                               psz_name, psz_input, psz_output,
642                               i_size, ppsz_args, i_enable, i_loop, &ex);
643     free_args( i_size, ppsz_args );
644     LIBVLC_EXCEPT;
645     Py_INCREF( Py_None );
646     return Py_None;
647 }
648
649 static PyObject *
650 vlcInstance_vlm_play_media( PyObject *self, PyObject *args )
651 {
652     libvlc_exception_t ex;
653     char* psz_name;
654  
655     if( !PyArg_ParseTuple( args, "s", &psz_name ) )
656         return NULL;
657
658     LIBVLC_TRY;
659     libvlc_vlm_play_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex);
660     LIBVLC_EXCEPT;
661     Py_INCREF( Py_None );
662     return Py_None;
663 }
664
665 static PyObject *
666 vlcInstance_vlm_stop_media( PyObject *self, PyObject *args )
667 {
668     libvlc_exception_t ex;
669     char* psz_name;
670
671     if( !PyArg_ParseTuple( args, "s", &psz_name ) )
672         return NULL;
673
674     LIBVLC_TRY;
675     libvlc_vlm_stop_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex);
676     LIBVLC_EXCEPT;
677     Py_INCREF( Py_None );
678     return Py_None;
679 }
680
681 static PyObject *
682 vlcInstance_vlm_pause_media( PyObject *self, PyObject *args )
683 {
684     libvlc_exception_t ex;
685     char* psz_name;
686  
687     if( !PyArg_ParseTuple( args, "s", &psz_name ) )
688         return NULL;
689
690     LIBVLC_TRY;
691     libvlc_vlm_pause_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex);
692     LIBVLC_EXCEPT;
693     Py_INCREF( Py_None );
694     return Py_None;
695 }
696
697 static PyObject *
698 vlcInstance_vlm_seek_media( PyObject *self, PyObject *args )
699 {
700     libvlc_exception_t ex;
701     char* psz_name;
702     float f_percentage;
703  
704     if( !PyArg_ParseTuple( args, "sf", &psz_name, &f_percentage ) )
705         return NULL;
706
707     LIBVLC_TRY;
708     libvlc_vlm_seek_media( LIBVLC_INSTANCE->p_instance, psz_name, f_percentage, &ex);
709     LIBVLC_EXCEPT;
710     Py_INCREF( Py_None );
711     return Py_None;
712 }
713
714 static PyObject *
715 vlcInstance_vlm_show_media( PyObject *self, PyObject *args )
716 {
717     libvlc_exception_t ex;
718     char* psz_name;
719     char* psz_ret;
720     PyObject* o_ret;
721
722     if( !PyArg_ParseTuple( args, "s", &psz_name ) )
723         return NULL;
724     LIBVLC_TRY;
725     psz_ret = libvlc_vlm_show_media( LIBVLC_INSTANCE->p_instance, psz_name, &ex );
726     LIBVLC_EXCEPT;
727     o_ret = Py_BuildValue( "s", psz_ret );
728     free( psz_ret );
729     return o_ret;
730 }
731
732 static PyObject *
733 vlcInstance_media_descriptor_new( PyObject *self, PyObject *args )
734 {
735     libvlc_exception_t ex;
736     libvlc_media_descriptor_t *p_md;
737     char* psz_mrl = NULL;
738     vlcMediaDescriptor *p_ret;
739
740     if( !PyArg_ParseTuple( args, "s", &psz_mrl ) )
741         return NULL;
742
743     LIBVLC_TRY;
744     p_md = libvlc_media_descriptor_new( LIBVLC_INSTANCE->p_instance, psz_mrl, &ex );
745     LIBVLC_EXCEPT;
746
747     p_ret = PyObject_New( vlcMediaDescriptor, &vlcMediaDescriptor_Type );
748     p_ret->p_md = p_md;
749     Py_INCREF( p_ret ); /* Ah bon ? */
750     return ( PyObject * )p_ret;
751 }
752
753 /* Method table */
754 static PyMethodDef vlcInstance_methods[] =
755 {
756     { "get_vlc_id", vlcInstance_get_vlc_id, METH_VARARGS,
757       "get_vlc_id( ) -> int        Get the instance id."},
758     { "playlist_loop", vlcInstance_playlist_loop, METH_VARARGS,
759       "playlist_loop(bool)         Set loop variable" },
760     { "playlist_play", vlcInstance_playlist_play, METH_VARARGS,
761       "playlist_play(id=int, options=list)   Play the given playlist item (-1 for current item) with optional options (a list of strings)" },
762     { "playlist_pause", vlcInstance_playlist_pause, METH_VARARGS,
763       "playlist_pause()            Pause the current stream"},
764     { "playlist_isplaying", vlcInstance_playlist_isplaying, METH_VARARGS,
765       "playlist_isplaying() -> int     Return True if the playlist if playing"},
766     { "playlist_items_count", vlcInstance_playlist_items_count, METH_VARARGS,
767       "playlist_items_count() -> int   Return the number of items in the playlist"},
768     { "playlist_stop", vlcInstance_playlist_stop, METH_VARARGS,
769       "playlist_stop()             Stop the current stream"},
770     { "playlist_next", vlcInstance_playlist_next, METH_VARARGS,
771       "playlist_next()             Play the next item"},
772     { "playlist_prev", vlcInstance_playlist_prev, METH_VARARGS,
773       "playlist_prev()             Play the previous item"},
774     { "playlist_clear", vlcInstance_playlist_clear, METH_VARARGS,
775       "playlist_clear()            Clear the playlist"},
776     { "playlist_add", vlcInstance_playlist_add, METH_VARARGS,
777       "playlist_add(mrl=str, name=str, options=list) -> int  Add a new item to the playlist. options is a list of strings."},
778     { "playlist_delete_item", vlcInstance_playlist_delete_item, METH_VARARGS,
779       "playlist_delete_item(id=int)   Delete the given item"},
780     { "playlist_get_media_instance", vlcInstance_playlist_get_media_instance, METH_VARARGS,
781       "playlist_get_media_instance() -> object   Return the current media instance"},
782     { "video_set_parent", vlcInstance_video_set_parent, METH_VARARGS,
783       "video_set_parent(xid=int)       Set the parent xid/HWND/CGrafPort"},
784     { "video_get_parent", vlcInstance_video_get_parent, METH_VARARGS,
785       "video_get_parent(xid=int)       Get the parent xid/HWND/CGrafPort"},
786     { "video_set_size", vlcInstance_video_set_size, METH_VARARGS,
787       "video_set_size(width=int, height=int)    Set the video width and height"},
788     { "audio_toggle_mute", vlcInstance_audio_toggle_mute, METH_VARARGS,
789       "audio_toggle_mute()         Toggle the mute state"},
790     { "audio_get_mute", vlcInstance_audio_get_mute, METH_VARARGS,
791       "audio_get_mute() -> int     Get the mute state"},
792     { "audio_set_mute", vlcInstance_audio_set_mute, METH_VARARGS,
793       "audio_set_mute(state=int)         Set the mute state"},
794     { "audio_get_volume", vlcInstance_audio_get_volume, METH_VARARGS,
795       "audio_get_volume() -> int   Get the audio volume"},
796     { "audio_set_volume", vlcInstance_audio_set_volume, METH_VARARGS,
797       "audio_set_volume(volume=int)       Set the audio volume"},
798     { "audio_get_channel", vlcInstance_audio_get_channel, METH_VARARGS,
799       "audio_get_channel() -> int  Get current audio channel" },
800     { "audio_set_channel", vlcInstance_audio_set_channel, METH_VARARGS,
801       "audio_set_channel(int)      Set current audio channel" },
802
803     { "media_descriptor_new", vlcInstance_media_descriptor_new, METH_VARARGS,
804       "media_descriptor_new(str) -> object   Create a media descriptor with the given mrl."},
805
806     { "vlm_add_broadcast", vlcInstance_vlm_add_broadcast, METH_VARARGS | METH_KEYWORDS,
807       "vlm_add_broadcast(name=str, input=str, output=str, options=list, enable=int, loop=int)   Add a new broadcast" },
808     { "vlm_del_media", vlcInstance_vlm_del_media, METH_VARARGS,
809       "vlm_del_media(name=str)    Delete a media" },
810     { "vlm_set_enabled", vlcInstance_vlm_set_enabled, METH_VARARGS,
811       "vlm_set_enabled(name=str, enabled=int)    Enable/disable a media" },
812     { "vlm_set_output", vlcInstance_vlm_set_output, METH_VARARGS,
813       "vlm_set_output(name=str, output=str)      Set the output" },
814     { "vlm_set_input", vlcInstance_vlm_set_input, METH_VARARGS,
815       "vlm_set_input(name=str, output=str)       Set the input" },
816     { "vlm_add_input", vlcInstance_vlm_add_input, METH_VARARGS,
817       "vlm_add_input(name=str, output=str)       Add a media's input MRL" },
818     { "vlm_set_loop", vlcInstance_vlm_set_loop, METH_VARARGS,
819       "vlm_set_loop(name=str, loop=int)          Change the looping value" },
820     { "vlm_change_media", vlcInstance_vlm_change_media, METH_VARARGS | METH_KEYWORDS,
821       "vlm_change_media(name=str, input=str, output=str, options=list, enable=int, loop=int)   Change the broadcast parameters" },
822     { "vlm_play_media", vlcInstance_vlm_play_media, METH_VARARGS,
823       "vlm_play_media(name=str)       Plays the named broadcast." },
824     { "vlm_stop_media", vlcInstance_vlm_stop_media, METH_VARARGS,
825       "vlm_stop_media(name=str)       Stops the named broadcast." },
826     { "vlm_pause_media", vlcInstance_vlm_pause_media, METH_VARARGS,
827       "vlm_pause_media(name=str)      Pauses the named broadcast." },
828     { "vlm_seek_media", vlcInstance_vlm_seek_media, METH_VARARGS,
829       "vlm_seek_media(name=str, percentage=float)  Seeks in the named broadcast." },
830     { "vlm_show_media", vlcInstance_vlm_show_media, METH_VARARGS,
831       "vlm_show_media(name=str)       Return information of the named broadcast." },
832
833     { NULL, NULL, 0, NULL },
834 };
835
836 static PyTypeObject vlcInstance_Type =
837 {
838     PyObject_HEAD_INIT( NULL )
839     0,                          /*ob_size*/
840     "vlc.Instance",             /*tp_name*/
841     sizeof( vlcInstance_Type ), /*tp_basicsize*/
842     0,                          /*tp_itemsize*/
843     ( destructor )vlcInstance_dealloc,      /*tp_dealloc*/
844     0,                         /*tp_print*/
845     0,                         /*tp_getattr*/
846     0,                         /*tp_setattr*/
847     0,                         /*tp_compare*/
848     0,                         /*tp_repr*/
849     0,                         /*tp_as_number*/
850     0,                         /*tp_as_sequence*/
851     0,                         /*tp_as_mapping*/
852     0,                         /*tp_hash */
853     0,                         /*tp_call*/
854     0,                         /*tp_str*/
855     0,                         /*tp_getattro*/
856     0,                         /*tp_setattro*/
857     0,                         /*tp_as_buffer*/
858     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
859     "VLC Instance(args)\n\nNote: if args is specified, the first arg is interpreted as an executable name to get the directory of the VLC plugins.",  /* tp_doc */
860     0,                     /* tp_traverse */
861     0,                     /* tp_clear */
862     0,                     /* tp_richcompare */
863     0,                     /* tp_weaklistoffset */
864     0,                     /* tp_iter */
865     0,                     /* tp_iternext */
866     vlcInstance_methods,             /* tp_methods */
867     0,             /* tp_members */
868     0,                         /* tp_getset */
869     0,                         /* tp_base */
870     0,                         /* tp_dict */
871     0,                         /* tp_descr_get */
872     0,                         /* tp_descr_set */
873     0,                         /* tp_dictoffset */
874     0,                         /* tp_init */
875     0,                         /* tp_alloc */
876     vlcInstance_new,          /* tp_new */
877 };