notify: unref the notification popup after we have finished using it. fix a big memor...
[vlc.git] / bindings / python / vlc_input.c
blob32dd0239e16214e3d8d704e408036df1ff3e1286
1 /*****************************************************************************
2 * vlc_input.c: vlc.Input binding
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
5 * $Id$
7 * Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.fr>
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.
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.
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"
25 /***********************************************************************
26 * vlc.Input
27 ***********************************************************************/
29 static PyObject *
30 vlcInput_get_length( PyObject *self, PyObject *args )
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 );
40 static PyObject *
41 vlcInput_get_time( PyObject *self, PyObject *args )
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 );
51 static PyObject *
52 vlcInput_set_time( PyObject *self, PyObject *args )
54 libvlc_exception_t ex;
55 vlc_int64_t i_time;
57 if( !PyArg_ParseTuple( args, "L", &i_time ) )
58 return NULL;
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;
67 static PyObject *
68 vlcInput_get_position( PyObject *self, PyObject *args )
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 );
78 static PyObject *
79 vlcInput_set_position( PyObject *self, PyObject *args )
81 libvlc_exception_t ex;
82 float f_pos;
84 if( !PyArg_ParseTuple( args, "f", &f_pos ) )
85 return NULL;
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;
94 static PyObject *
95 vlcInput_will_play( PyObject *self, PyObject *args )
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 );
105 static PyObject *
106 vlcInput_get_rate( PyObject *self, PyObject *args )
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 );
116 static PyObject *
117 vlcInput_set_rate( PyObject *self, PyObject *args )
119 libvlc_exception_t ex;
120 float f_rate;
122 if( !PyArg_ParseTuple( args, "f", &f_rate ) )
123 return NULL;
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;
132 static PyObject *
133 vlcInput_get_state( PyObject *self, PyObject *args )
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 );
143 static PyObject *
144 vlcInput_has_vout( PyObject *self, PyObject *args )
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 );
154 static PyObject *
155 vlcInput_get_fps( PyObject *self, PyObject *args )
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 );
165 static PyObject *
166 vlcInput_audio_get_track( PyObject *self, PyObject *args )
168 libvlc_exception_t ex;
169 int i_ret;
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 );
177 static PyObject *
178 vlcInput_audio_set_track( PyObject *self, PyObject *args )
180 libvlc_exception_t ex;
181 int i_track;
183 if( !PyArg_ParseTuple( args, "i", &i_track ) )
184 return NULL;
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;
193 static PyObject *
194 vlcInput_toggle_fullscreen( PyObject *self, PyObject *args )
196 libvlc_exception_t ex;
198 LIBVLC_TRY;
199 libvlc_toggle_fullscreen( LIBVLC_INPUT->p_md, &ex);
200 LIBVLC_EXCEPT;
201 Py_INCREF( Py_None );
202 return Py_None;
205 static PyObject *
206 vlcInput_set_fullscreen( PyObject *self, PyObject *args )
208 libvlc_exception_t ex;
209 int i_fullscreen;
211 if( !PyArg_ParseTuple( args, "i", &i_fullscreen ) )
212 return NULL;
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;
221 static PyObject *
222 vlcInput_get_fullscreen( PyObject *self, PyObject *args )
224 libvlc_exception_t ex;
225 int i_ret;
227 LIBVLC_TRY;
228 i_ret = libvlc_get_fullscreen( LIBVLC_INPUT->p_md, &ex);
229 LIBVLC_EXCEPT;
230 return Py_BuildValue( "i", i_ret );
233 static PyObject *
234 vlcInput_get_height( PyObject *self, PyObject *args )
236 libvlc_exception_t ex;
237 int i_ret;
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 );
245 static PyObject *
246 vlcInput_get_width( PyObject *self, PyObject *args )
248 libvlc_exception_t ex;
249 int i_ret;
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 );
257 static PyObject *
258 vlcInput_get_aspect_ratio( PyObject *self, PyObject *args )
260 libvlc_exception_t ex;
261 char* psz_ret;
262 PyObject* o_ret;
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;
272 static PyObject *
273 vlcInput_set_aspect_ratio( PyObject *self, PyObject *args )
275 libvlc_exception_t ex;
276 char* psz_ratio;
278 if( !PyArg_ParseTuple( args, "s", &psz_ratio ) )
279 return NULL;
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;
289 static PyObject *
290 vlcInput_video_take_snapshot( PyObject *self, PyObject *args )
292 libvlc_exception_t ex;
293 char* psz_filename;
295 if( !PyArg_ParseTuple( args, "s", &psz_filename ) )
296 return NULL;
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;
305 static PyObject *
306 vlcInput_video_resize( PyObject *self, PyObject *args )
308 libvlc_exception_t ex;
309 int i_width;
310 int i_height;
312 if( !PyArg_ParseTuple( args, "ii", &i_width, &i_height ) )
313 return NULL;
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;
322 static PyObject *
323 vlcInput_video_reparent( PyObject *self, PyObject *args )
325 libvlc_exception_t ex;
326 WINDOWHANDLE i_visual;
327 int i_ret;
329 if( !PyArg_ParseTuple( args, "i", &i_visual ) )
330 return NULL;
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 );
338 static PyMethodDef vlcInput_methods[] =
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" },
387 { NULL } /* Sentinel */
390 static PyTypeObject vlcInput_Type =
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 */