]> git.sesse.net Git - vlc/blob - bindings/python/vlc_input.c
0fb040e2282988d06e3673cb7bf94c1858983b8e
[vlc] / bindings / python / vlc_input.c
1 /*****************************************************************************
2  * vlc_input.c: vlc.Input 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 /***********************************************************************
26  * vlc.Input
27  ***********************************************************************/
28
29 static PyObject *
30 vlcInput_get_length( PyObject *self, PyObject *args )
31 {
32     libvlc_exception_t ex;
33     vlc_int64_t i_ret;
34     LIBVLC_TRY;
35     i_ret = libvlc_media_instance_get_length( LIBVLC_INPUT->p_md, &ex);
36     LIBVLC_EXCEPT;
37     return Py_BuildValue( "L", i_ret );
38 }
39
40 static PyObject *
41 vlcInput_get_time( PyObject *self, PyObject *args )
42 {
43     libvlc_exception_t ex;
44     vlc_int64_t i_ret;
45     LIBVLC_TRY;
46     i_ret = libvlc_media_instance_get_time( LIBVLC_INPUT->p_md, &ex);
47     LIBVLC_EXCEPT;
48     return Py_BuildValue( "L", i_ret );
49 }
50
51 static PyObject *
52 vlcInput_set_time( PyObject *self, PyObject *args )
53 {
54     libvlc_exception_t ex;
55     vlc_int64_t i_time;
56
57     if( !PyArg_ParseTuple( args, "L", &i_time ) )
58         return NULL;
59
60     LIBVLC_TRY;
61     libvlc_media_instance_set_time( LIBVLC_INPUT->p_md, i_time, &ex);
62     LIBVLC_EXCEPT;
63     Py_INCREF( Py_None );
64     return Py_None;
65 }
66
67 static PyObject *
68 vlcInput_get_position( PyObject *self, PyObject *args )
69 {
70     libvlc_exception_t ex;
71     float f_ret;
72     LIBVLC_TRY;
73     f_ret = libvlc_media_instance_get_position( LIBVLC_INPUT->p_md, &ex);
74     LIBVLC_EXCEPT;
75     return Py_BuildValue( "f", f_ret );
76 }
77
78 static PyObject *
79 vlcInput_set_position( PyObject *self, PyObject *args )
80 {
81     libvlc_exception_t ex;
82     float f_pos;
83
84     if( !PyArg_ParseTuple( args, "f", &f_pos ) )
85         return NULL;
86
87     LIBVLC_TRY;
88     libvlc_media_instance_set_position( LIBVLC_INPUT->p_md, f_pos, &ex);
89     LIBVLC_EXCEPT;
90     Py_INCREF( Py_None );
91     return Py_None;
92 }
93
94 static PyObject *
95 vlcInput_will_play( PyObject *self, PyObject *args )
96 {
97     libvlc_exception_t ex;
98     int i_ret;
99     LIBVLC_TRY;
100     i_ret = libvlc_media_instance_will_play( LIBVLC_INPUT->p_md, &ex);
101     LIBVLC_EXCEPT;
102     return Py_BuildValue( "i", i_ret );
103 }
104
105 static PyObject *
106 vlcInput_get_rate( PyObject *self, PyObject *args )
107 {
108     libvlc_exception_t ex;
109     float f_ret;
110     LIBVLC_TRY;
111     f_ret = libvlc_media_instance_get_rate( LIBVLC_INPUT->p_md, &ex);
112     LIBVLC_EXCEPT;
113     return Py_BuildValue( "f", f_ret );
114 }
115
116 static PyObject *
117 vlcInput_set_rate( PyObject *self, PyObject *args )
118 {
119     libvlc_exception_t ex;
120     float f_rate;
121
122     if( !PyArg_ParseTuple( args, "f", &f_rate ) )
123         return NULL;
124
125     LIBVLC_TRY;
126     libvlc_media_instance_set_rate( LIBVLC_INPUT->p_md, f_rate, &ex);
127     LIBVLC_EXCEPT;
128     Py_INCREF( Py_None );
129     return Py_None;
130 }
131
132 static PyObject *
133 vlcInput_get_state( PyObject *self, PyObject *args )
134 {
135     libvlc_exception_t ex;
136     int i_ret;
137     LIBVLC_TRY;
138     i_ret = libvlc_media_instance_get_state( LIBVLC_INPUT->p_md, &ex);
139     LIBVLC_EXCEPT;
140     return Py_BuildValue( "i", i_ret );
141 }
142
143 static PyObject *
144 vlcInput_has_vout( PyObject *self, PyObject *args )
145 {
146     libvlc_exception_t ex;
147     int i_ret;
148     LIBVLC_TRY;
149     i_ret = libvlc_media_instance_has_vout( LIBVLC_INPUT->p_md, &ex);
150     LIBVLC_EXCEPT;
151     return Py_BuildValue( "i", i_ret );
152 }
153
154 static PyObject *
155 vlcInput_get_fps( PyObject *self, PyObject *args )
156 {
157     libvlc_exception_t ex;
158     float f_ret;
159     LIBVLC_TRY;
160     f_ret = libvlc_media_instance_get_fps( LIBVLC_INPUT->p_md, &ex);
161     LIBVLC_EXCEPT;
162     return Py_BuildValue( "f", f_ret );
163 }
164
165 static PyObject *
166 vlcInput_audio_get_track( PyObject *self, PyObject *args )
167 {
168     libvlc_exception_t ex;
169     int i_ret;
170
171     LIBVLC_TRY;
172     i_ret = libvlc_audio_get_track( LIBVLC_INPUT->p_md, &ex );
173     LIBVLC_EXCEPT;
174     return Py_BuildValue( "i", i_ret );
175 }
176
177 static PyObject *
178 vlcInput_audio_set_track( PyObject *self, PyObject *args )
179 {
180     libvlc_exception_t ex;
181     int i_track;
182
183     if( !PyArg_ParseTuple( args, "i", &i_track ) )
184         return NULL;
185
186     LIBVLC_TRY;
187     libvlc_audio_set_track( LIBVLC_INPUT->p_md, i_track, &ex );
188     LIBVLC_EXCEPT;
189     Py_INCREF( Py_None );
190     return Py_None;
191 }
192
193 static PyObject *
194 vlcInput_toggle_fullscreen( PyObject *self, PyObject *args )
195 {
196     libvlc_exception_t ex;
197
198     LIBVLC_TRY;
199     libvlc_toggle_fullscreen( LIBVLC_INPUT->p_md, &ex);
200     LIBVLC_EXCEPT;
201     Py_INCREF( Py_None );
202     return Py_None;    
203 }
204
205 static PyObject *
206 vlcInput_set_fullscreen( PyObject *self, PyObject *args )
207 {
208     libvlc_exception_t ex;
209     int i_fullscreen;
210
211     if( !PyArg_ParseTuple( args, "i", &i_fullscreen ) )
212         return NULL;
213
214     LIBVLC_TRY;
215     libvlc_set_fullscreen( LIBVLC_INPUT->p_md, i_fullscreen, &ex);
216     LIBVLC_EXCEPT;
217     Py_INCREF( Py_None );
218     return Py_None;
219 }
220
221 static PyObject *
222 vlcInput_get_fullscreen( PyObject *self, PyObject *args )
223 {
224     libvlc_exception_t ex;
225     int i_ret;
226
227     LIBVLC_TRY;
228     i_ret = libvlc_get_fullscreen( LIBVLC_INPUT->p_md, &ex);
229     LIBVLC_EXCEPT;
230     return Py_BuildValue( "i", i_ret );
231 }
232
233 static PyObject *
234 vlcInput_get_height( PyObject *self, PyObject *args )
235 {
236     libvlc_exception_t ex;
237     int i_ret;
238
239     LIBVLC_TRY;
240     i_ret = libvlc_video_get_height( LIBVLC_INPUT->p_md, &ex);
241     LIBVLC_EXCEPT;
242     return Py_BuildValue( "i", i_ret );
243 }
244
245 static PyObject *
246 vlcInput_get_width( PyObject *self, PyObject *args )
247 {
248     libvlc_exception_t ex;
249     int i_ret;
250
251     LIBVLC_TRY;
252     i_ret = libvlc_video_get_width( LIBVLC_INPUT->p_md, &ex);
253     LIBVLC_EXCEPT;
254     return Py_BuildValue( "i", i_ret );
255 }
256
257 static PyObject *
258 vlcInput_get_aspect_ratio( PyObject *self, PyObject *args )
259 {
260     libvlc_exception_t ex;
261     char* psz_ret;
262     PyObject* o_ret;
263
264     LIBVLC_TRY;
265     psz_ret = libvlc_video_get_aspect_ratio( LIBVLC_INPUT->p_md, &ex);
266     LIBVLC_EXCEPT;
267     o_ret=Py_BuildValue( "s", psz_ret );
268     free( psz_ret );
269     return o_ret;
270 }
271
272 static PyObject *
273 vlcInput_set_aspect_ratio( PyObject *self, PyObject *args )
274 {
275     libvlc_exception_t ex;
276     char* psz_ratio;
277
278     if( !PyArg_ParseTuple( args, "s", &psz_ratio ) )
279         return NULL;
280
281     LIBVLC_TRY;
282     libvlc_video_set_aspect_ratio( LIBVLC_INPUT->p_md, psz_ratio, &ex);
283     LIBVLC_EXCEPT;
284     free( psz_ratio );
285     Py_INCREF( Py_None );
286     return Py_None;
287 }
288
289 static PyObject *
290 vlcInput_video_take_snapshot( PyObject *self, PyObject *args )
291 {
292     libvlc_exception_t ex;
293     char* psz_filename;
294
295     if( !PyArg_ParseTuple( args, "s", &psz_filename ) )
296         return NULL;
297
298     LIBVLC_TRY;
299     libvlc_video_take_snapshot( LIBVLC_INPUT->p_md, psz_filename, &ex);
300     LIBVLC_EXCEPT;
301     Py_INCREF( Py_None );
302     return Py_None;
303 }
304
305 static PyObject *
306 vlcInput_video_resize( PyObject *self, PyObject *args )
307 {
308     libvlc_exception_t ex;
309     int i_width;
310     int i_height;
311
312     if( !PyArg_ParseTuple( args, "ii", &i_width, &i_height ) )
313         return NULL;
314
315     LIBVLC_TRY;
316     libvlc_video_resize( LIBVLC_INPUT->p_md, i_width, i_height, &ex);
317     LIBVLC_EXCEPT;
318     Py_INCREF( Py_None );
319     return Py_None;
320 }
321
322 static PyObject *
323 vlcInput_video_reparent( PyObject *self, PyObject *args )
324 {
325     libvlc_exception_t ex;
326     WINDOWHANDLE i_visual;
327     int i_ret;
328
329     if( !PyArg_ParseTuple( args, "i", &i_visual ) )
330         return NULL;
331
332     LIBVLC_TRY;
333     i_ret = libvlc_video_reparent( LIBVLC_INPUT->p_md, i_visual, &ex);
334     LIBVLC_EXCEPT;
335     return Py_BuildValue( "i", i_ret );
336 }
337
338 static PyMethodDef vlcInput_methods[] =
339 {
340     { "get_length", vlcInput_get_length, METH_VARARGS,
341       "get_length() -> long    " },
342     { "get_time", vlcInput_get_time, METH_VARARGS,
343       "get_time() -> long" },
344     { "set_time", vlcInput_set_time, METH_VARARGS,
345       "set_time(long)" },
346     { "get_position", vlcInput_get_position, METH_VARARGS,
347       "get_position() -> float" },
348     { "set_position", vlcInput_set_position, METH_VARARGS,
349       "set_position(float)" },
350     { "will_play", vlcInput_will_play, METH_VARARGS,
351       "will_play() -> int" },
352     { "get_rate", vlcInput_get_rate, METH_VARARGS,
353       "get_rate() -> float" },
354     { "set_rate", vlcInput_set_rate, METH_VARARGS,
355       "set_rate(float)" },
356     { "get_state", vlcInput_get_state, METH_VARARGS,
357       "get_state() -> int" },
358     { "has_vout", vlcInput_has_vout, METH_VARARGS,
359       "has_vout() -> int" },
360     { "get_fps", vlcInput_get_fps, METH_VARARGS,
361       "get_fps() -> float" },
362     { "audio_get_track", vlcInput_audio_get_track, METH_VARARGS,
363       "audio_get_track() -> int    Get current audio track" },
364     { "audio_set_track", vlcInput_audio_set_track, METH_VARARGS,
365       "audio_set_track(int)        Set current audio track" },
366     { "toggle_fullscreen", vlcInput_toggle_fullscreen, METH_VARARGS,
367       "toggle_fullscreen()    Toggle fullscreen status on video output" },
368     { "set_fullscreen", vlcInput_set_fullscreen, METH_VARARGS,
369       "set_fullscreen(bool)    Enable or disable fullscreen on a video output" },
370     { "get_fullscreen", vlcInput_get_fullscreen, METH_VARARGS,
371       "get_fullscreen() -> bool    Get current fullscreen status" },
372     { "get_height", vlcInput_get_height, METH_VARARGS,
373       "get_height() -> int           Get current video height" },
374     { "get_width", vlcInput_get_width, METH_VARARGS,
375       "get_width() -> int           Get current video width" },
376     { "get_aspect_ratio", vlcInput_get_aspect_ratio, METH_VARARGS,
377       "get_aspect_ratio() -> str    Get current video aspect ratio" },
378     { "set_aspect_ratio", vlcInput_set_aspect_ratio, METH_VARARGS,
379       "set_aspect_ratio(str)        Set new video aspect ratio" },
380     { "video_take_snapshot", vlcInput_video_take_snapshot, METH_VARARGS,
381       "video_take_snapshot(filename=str)        Take a snapshot of the current video window" },
382     { "video_resize", vlcInput_video_resize, METH_VARARGS,
383       "video_resize(width=int, height=int)      Resize the current video output window" },
384     { "video_reparent", vlcInput_video_reparent, METH_VARARGS,
385       "video_reparent(visual=int)               change the parent for the current video output" },
386
387     { NULL }  /* Sentinel */
388 };
389
390 static PyTypeObject vlcInput_Type =
391 {
392     PyObject_HEAD_INIT( NULL )
393     0,                         /*ob_size*/
394     "vlc.Input",            /*tp_name*/
395     sizeof( vlcInput_Type ),   /*tp_basicsize*/
396     0,                         /*tp_itemsize*/
397     0,                         /*tp_dealloc*/
398     0,                         /*tp_print*/
399     0,                         /*tp_getattr*/
400     0,                         /*tp_setattr*/
401     0,                         /*tp_compare*/
402     0,                         /*tp_repr*/
403     0,                         /*tp_as_number*/
404     0,                         /*tp_as_sequence*/
405     0,                         /*tp_as_mapping*/
406     0,                         /*tp_hash */
407     0,                         /*tp_call*/
408     0,                         /*tp_str*/
409     0,                         /*tp_getattro*/
410     0,                         /*tp_setattro*/
411     0,                         /*tp_as_buffer*/
412     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
413     "vlc.Input object\n\nIt cannot be instanciated standalone, it must be obtained from an existing vlc.Instance object",  /* tp_doc */
414     0,                        /* tp_traverse */
415     0,                        /* tp_clear */
416     0,                         /* tp_richcompare */
417     0,                         /* tp_weaklistoffset */
418     0,                         /* tp_iter */
419     0,                          /* tp_iternext */
420     vlcInput_methods,          /* tp_methods */
421     0,                         /* tp_members */
422     0,                         /* tp_getset */
423     0,                         /* tp_base */
424     0,                         /* tp_dict */
425     0,                         /* tp_descr_get */
426     0,                         /* tp_descr_set */
427     0,                         /* tp_dictoffset */
428     0,                         /* tp_init */
429     0,                         /* tp_alloc */
430     0,                         /* tp_new */
431 };
432