1 /*****************************************************************************
2 * vlcglue.c: VLC Module
3 *****************************************************************************
4 * Copyright (C) 1998-2004 the VideoLAN team
5 * $Id: vlc.c 12667 2005-09-25 10:19:26Z zorglub $
7 * Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.fr>
8 * Clément Stenac <zorglub@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
26 /**************************************************************************
28 **************************************************************************/
30 #ifndef vlcMODINIT_FUNC /* declarations for DLL import/export */
31 #define vlcMODINIT_FUNC void
34 static PyMethodDef vlc_methods[] = {
39 PyObject* MediaControl_InternalException = NULL;
40 PyObject* MediaControl_PositionKeyNotSupported = NULL;
41 PyObject *MediaControl_PositionOriginNotSupported = NULL;
42 PyObject* MediaControl_InvalidPosition = NULL;
43 PyObject *MediaControl_PlaylistException = NULL;
45 vlcMODINIT_FUNC initvlc(void)
49 PyPosition_Type.tp_new = PyType_GenericNew;
50 PyPosition_Type.tp_alloc = PyType_GenericAlloc;
52 if (PyType_Ready(&PyPosition_Type) < 0)
54 if (PyType_Ready(&MediaControl_Type) < 0)
56 #ifdef VLCOBJECT_SUPPORT
57 if (PyType_Ready(&vlcObject_Type) < 0)
61 /* PyEval_InitThreads(); */
64 http://base.bel-epa.com/pyapache/Python/MySQL-python/MySQL-python-0.3.0/_mysqlmodule.c */
66 m = Py_InitModule3( "vlc", vlc_methods,
67 "VLC media player embedding module.");
70 MediaControl_InternalException =
71 PyErr_NewException("vlc.InternalException", NULL, NULL);
72 PyModule_AddObject(m, "InternalException", MediaControl_InternalException);
74 MediaControl_PositionKeyNotSupported =
75 PyErr_NewException("vlc.PositionKeyNotSupported", NULL, NULL);
76 PyModule_AddObject(m, "PositionKeyNotSupported",
77 MediaControl_PositionKeyNotSupported);
79 MediaControl_PositionOriginNotSupported=
80 PyErr_NewException("vlc.InvalidPosition", NULL, NULL);
81 PyModule_AddObject(m, "PositionOriginNotSupported",
82 MediaControl_PositionOriginNotSupported);
84 MediaControl_InvalidPosition =
85 PyErr_NewException("vlc.InvalidPosition", NULL, NULL);
86 PyModule_AddObject(m, "InvalidPosition", MediaControl_InvalidPosition);
88 MediaControl_PlaylistException =
89 PyErr_NewException("vlc.PlaylistException", NULL, NULL);
90 PyModule_AddObject(m, "PlaylistException", MediaControl_PlaylistException);
93 Py_INCREF(&PyPosition_Type);
94 PyModule_AddObject(m, "Position", (PyObject *)&PyPosition_Type);
95 Py_INCREF(&MediaControl_Type);
96 PyModule_AddObject(m, "MediaControl", (PyObject *)&MediaControl_Type);
97 #ifdef VLCOBJECT_SUPPORT
98 Py_INCREF(&vlcObject_Type);
99 PyModule_AddObject(m, "Object", (PyObject *)&vlcObject_Type);
103 PyModule_AddIntConstant(m, "AbsolutePosition",
104 mediacontrol_AbsolutePosition);
105 PyModule_AddIntConstant(m, "RelativePosition",
106 mediacontrol_RelativePosition);
107 PyModule_AddIntConstant(m, "ModuloPosition",
108 mediacontrol_ModuloPosition);
110 PyModule_AddIntConstant(m, "ByteCount", mediacontrol_ByteCount);
111 PyModule_AddIntConstant(m, "SampleCount", mediacontrol_SampleCount);
112 PyModule_AddIntConstant(m, "MediaTime", mediacontrol_MediaTime);
113 PyModule_AddIntConstant(m, "PlayingStatus", mediacontrol_PlayingStatus);
114 PyModule_AddIntConstant(m, "PauseStatus", mediacontrol_PauseStatus);
115 PyModule_AddIntConstant(m, "ForwardStatus", mediacontrol_ForwardStatus);
116 PyModule_AddIntConstant(m, "BackwardStatus", mediacontrol_BackwardStatus);
117 PyModule_AddIntConstant(m, "InitStatus", mediacontrol_InitStatus);
118 PyModule_AddIntConstant(m, "EndStatus", mediacontrol_EndStatus);
119 PyModule_AddIntConstant(m, "UndefinedStatus", mediacontrol_UndefinedStatus);
123 /* Make libpostproc happy... */
124 void * fast_memcpy(void * to, const void * from, size_t len)
126 return memcpy(to, from, len);
130 /*****************************************************************************
131 * VLCObject implementation
132 *****************************************************************************/
134 #ifdef VLCOBJECT_SUPPORT
136 static PyObject *vlcObject_new(
137 PyTypeObject *type, PyObject *args, PyObject *kwds)
140 vlc_object_t *p_object;
143 self = PyObject_New(vlcObject, &vlcObject_Type);
145 if ( !PyArg_ParseTuple(args, "i", &i_id) )
148 /* Maybe we were already initialized */
149 p_object = (vlc_object_t*)vlc_current_object(i_id);
153 /* Try to initialize */
155 p_object = (vlc_object_t*)vlc_current_object(i_id);
160 PyErr_SetString(PyExc_StandardError, "Unable to get object.");
164 self->p_object = p_object;
165 self->b_released = 0;
167 Py_INCREF( self ); /* Ah bon ? */
168 return (PyObject *)self;
171 static PyObject * vlcObject_release( PyObject *self )
173 if( VLCSELF->b_released == 0 )
175 vlc_object_release( VLCSELF->p_object );
176 VLCSELF->b_released = 1;
182 static void vlcObject_dealloc(PyObject *self)
184 vlcObject_release( self );
188 static PyObject * vlcObject_find_object(PyObject *self, PyObject *args)
195 if ( !PyArg_ParseTuple(args, "s", &psz_name) )
199 (aout, decoder, input, httpd, intf, playlist, root, vlc, vout)
204 i_object_type = VLC_OBJECT_AOUT;
207 i_object_type = VLC_OBJECT_DECODER;
210 i_object_type = VLC_OBJECT_HTTPD;
213 if (strlen(psz_name) < 3)
214 i_object_type = VLC_OBJECT_INTF;
215 else if (psz_name[2] == 't')
216 i_object_type = VLC_OBJECT_INTF;
218 i_object_type = VLC_OBJECT_INPUT;
221 i_object_type = VLC_OBJECT_PLAYLIST;
224 i_object_type = VLC_OBJECT_ROOT;
227 if (strlen(psz_name) < 3)
228 i_object_type = VLC_OBJECT_VLC;
229 else if (psz_name[1] == 'l')
230 i_object_type = VLC_OBJECT_VLC;
232 i_object_type = VLC_OBJECT_VOUT;
235 /* FIXME: raise an exception */
239 p_obj = vlc_object_find( VLCSELF->p_object, i_object_type, FIND_ANYWHERE );
247 retval = PyObject_New(vlcObject, &vlcObject_Type);
249 retval->p_object = p_obj;
251 return (PyObject *)retval;
254 static PyObject * vlcObject_info(PyObject *self, PyObject *args)
259 p_obj = VLCSELF->p_object;
261 /* Return information about the object as a dict. */
262 retval = PyDict_New();
264 PyDict_SetItemString(retval, "object-id",
265 Py_BuildValue("l", p_obj->i_object_id));
266 PyDict_SetItemString(retval, "object-type",
267 Py_BuildValue("s", p_obj->psz_object_type));
268 PyDict_SetItemString(retval, "object-name",
269 Py_BuildValue("s", p_obj->psz_object_name));
270 PyDict_SetItemString(retval, "thread",
271 PyBool_FromLong(p_obj->b_thread));
272 PyDict_SetItemString(retval, "thread-id",
273 PyLong_FromLongLong(p_obj->thread_id));
274 PyDict_SetItemString(retval, "refcount",
275 PyInt_FromLong(p_obj->i_refcount));
280 static PyObject * vlcObject_find_id(PyObject *self, PyObject *args)
283 vlc_object_t* p_object;
286 if ( !PyArg_ParseTuple(args, "i", &i_id) )
288 PyErr_SetString(PyExc_StandardError, "Error: no id was given.\n");
292 p_object = (vlc_object_t*)vlc_current_object(i_id);
300 retval = PyObject_NEW(vlcObject, &vlcObject_Type);
302 retval->p_object = p_object;
304 return (PyObject *)retval;
307 /* Do a var_Get call on the object. Parameter: the variable name. */
308 /* FIXME: We should make them attributes */
309 static PyObject * vlcObject_var_get(PyObject *self, PyObject *args)
316 if ( !PyArg_ParseTuple(args, "s", &psz_name) )
318 PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n");
323 if( var_Get( VLCSELF->p_object, psz_name, &value ) != VLC_SUCCESS )
325 PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n");
330 i_type = var_Type (VLCSELF->p_object, psz_name);
335 retval = PyString_FromString("A void variable");
338 retval = PyBool_FromLong(value.b_bool);
340 case VLC_VAR_INTEGER :
341 retval = PyInt_FromLong((long)value.i_int);
343 case VLC_VAR_HOTKEY :
344 retval = PyString_FromFormat("A hotkey variable (%d)", value.i_int);
347 case VLC_VAR_STRING :
348 case VLC_VAR_DIRECTORY :
349 case VLC_VAR_VARIABLE :
350 retval = PyString_FromString(value.psz_string);
352 case VLC_VAR_MODULE :
353 retval = (PyObject*)PyObject_New(vlcObject, &vlcObject_Type);
354 ((vlcObject*)retval)->p_object = value.p_object;
357 retval = PyFloat_FromDouble((double)value.f_float);
360 retval = PyLong_FromLongLong(value.i_time);
362 case VLC_VAR_ADDRESS :
363 retval = PyString_FromString("A VLC address (not handled yet)");
366 retval = PyString_FromString("A VLC list (not handled yet)");
369 retval = PyString_FromString("A mutex");
379 static PyObject * vlcObject_var_type(PyObject *self,
386 if ( !PyArg_ParseTuple(args, "s", &psz_name))
388 PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n");
393 i_type = var_Type(VLCSELF->p_object, psz_name);
398 retval = PyString_FromString("Void");
401 retval = PyString_FromString("Boolean");
403 case VLC_VAR_INTEGER :
404 retval = PyString_FromString("Integer");
406 case VLC_VAR_HOTKEY :
407 retval = PyString_FromString("Hotkey");
410 retval = PyString_FromString("File");
412 case VLC_VAR_STRING :
413 retval = PyString_FromString("String");
415 case VLC_VAR_DIRECTORY :
416 retval = PyString_FromString("Directory");
418 case VLC_VAR_VARIABLE :
419 retval = PyString_FromString("Variable");
421 case VLC_VAR_MODULE :
422 retval = PyString_FromString("Module");
425 retval = PyString_FromString("Float");
428 retval = PyString_FromString("Time");
430 case VLC_VAR_ADDRESS :
431 retval = PyString_FromString("Address");
434 retval = PyString_FromString("List");
437 retval = PyString_FromString("Mutex");
440 retval = PyString_FromString("Unknown");
445 /* Do a var_Set call on the object. Parameter: the variable name. */
446 /* FIXME: We should make them attributes */
447 static PyObject * vlcObject_var_set(PyObject *self,
456 if ( !PyArg_ParseTuple(args, "sO", &psz_name, &py_value) )
458 PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n");
463 p_obj = VLCSELF->p_object;
464 i_type = var_Type(p_obj, psz_name);
471 value.b_bool = PyInt_AsLong(py_value);
473 case VLC_VAR_INTEGER :
474 case VLC_VAR_HOTKEY :
475 value.i_int = PyInt_AsLong(py_value);
478 case VLC_VAR_STRING :
479 case VLC_VAR_DIRECTORY :
480 case VLC_VAR_VARIABLE :
481 value.psz_string = strdup(PyString_AsString(py_value));
483 case VLC_VAR_MODULE :
484 /* FIXME: we should check the PyObject type and get its p_object */
485 value.p_object = ((vlcObject*)p_obj)->p_object;
488 value.f_float = PyFloat_AsDouble(py_value);
491 value.i_time = PyLong_AsLongLong(py_value);
493 case VLC_VAR_ADDRESS :
494 value.p_address = (char*)PyLong_AsVoidPtr(py_value);
504 var_Set(p_obj, psz_name, value);
510 static PyObject * vlcObject_var_list(PyObject *self,
517 i_size = VLCSELF->p_object->i_vars;
518 retval = PyTuple_New(i_size);
520 for (i_index = 0 ; i_index < i_size ; i_index++)
522 PyTuple_SetItem(retval, i_index,
523 Py_BuildValue("s", VLCSELF->p_object->p_vars[i_index].psz_name));
526 /* Py_INCREF(retval); */
530 /* Do a config_Get call on the object. Parameter: the variable name. */
531 static PyObject * vlcObject_config_get(PyObject *self,
537 module_config_t *p_config;
539 if ( !PyArg_ParseTuple(args, "s", &psz_name) )
541 PyErr_SetString(PyExc_StandardError, "Error: no config variable name was given.\n");
546 p_config = config_FindConfig( VLCSELF->p_object, psz_name );
550 PyErr_SetString(PyExc_StandardError, "Error: config variable does not exist.\n");
555 switch (p_config->i_type)
557 case CONFIG_ITEM_BOOL :
558 retval = PyBool_FromLong(p_config->i_value);
560 case CONFIG_ITEM_INTEGER :
561 retval = PyInt_FromLong((long)p_config->i_value);
563 case CONFIG_ITEM_KEY :
564 retval = PyString_FromFormat("A hotkey variable (%d)", p_config->i_value);
566 case CONFIG_ITEM_FILE :
567 case CONFIG_ITEM_STRING :
568 case CONFIG_ITEM_DIRECTORY :
569 case CONFIG_ITEM_MODULE :
570 vlc_mutex_lock( p_config->p_lock );
571 if( p_config->psz_value )
572 retval = PyString_FromString( p_config->psz_value );
574 retval = PyString_FromString( "" );
575 vlc_mutex_unlock( p_config->p_lock );
577 retval = (PyObject*)PyObject_New(vlcObject, &vlcObject_Type);
578 ((vlcObject*)retval)->p_object = value.p_object;
580 case CONFIG_ITEM_FLOAT :
581 retval = PyFloat_FromDouble((double)p_config->f_value);
591 /* Do a var_Set call on the object. Parameter: the variable name. */
592 /* FIXME: We should make them attributes */
593 static PyObject * vlcObject_config_set(PyObject *self,
599 module_config_t *p_config;
602 if ( !PyArg_ParseTuple(args, "sO", &psz_name, &py_value) )
604 PyErr_SetString(PyExc_StandardError,
605 "Error: no variable name was given.\n");
610 p_obj = VLCSELF->p_object;
611 p_config = config_FindConfig( p_obj, psz_name );
615 PyErr_SetString(PyExc_StandardError,
616 "Error: option does not exist.\n");
621 switch (p_config->i_type)
623 case CONFIG_ITEM_BOOL :
624 case CONFIG_ITEM_INTEGER :
625 case CONFIG_ITEM_KEY :
626 config_PutInt(p_obj, psz_name, PyInt_AsLong(py_value));
628 case CONFIG_ITEM_FILE :
629 case CONFIG_ITEM_STRING :
630 case CONFIG_ITEM_DIRECTORY :
631 case CONFIG_ITEM_MODULE :
632 config_PutPsz(p_obj, psz_name, PyString_AsString(py_value));
634 case CONFIG_ITEM_FLOAT :
635 config_PutFloat(p_obj, psz_name, PyFloat_AsDouble(py_value));
642 static PyObject * vlcObject_children(PyObject *self,
649 i_size = VLCSELF->p_object->i_children;
650 retval = PyTuple_New(i_size);
652 for (i_index = 0 ; i_index < i_size ; i_index++)
654 PyTuple_SetItem(retval, i_index,
656 VLCSELF->p_object->pp_children[i_index]->i_object_id));
659 /* Py_INCREF(retval); */
665 static PyMethodDef vlcObject_methods[] =
667 { "get", vlcObject_var_get, METH_VARARGS,
668 "get(str) -> value Get a variable value."},
669 { "set", vlcObject_var_set, METH_VARARGS,
670 "set(str, value) Set a variable value" },
671 { "config_get", vlcObject_config_get, METH_VARARGS,
672 "get(str) -> value Get an option value." },
673 { "config_set", vlcObject_config_set, METH_VARARGS,
674 "set(str, value) Set an option value" },
675 { "type", vlcObject_var_type, METH_VARARGS,
676 "type(str) -> str Get a variable type" },
677 { "list", vlcObject_var_list, METH_VARARGS,
678 "list() List the available variables" },
679 { "children", vlcObject_children, METH_VARARGS,
680 "children() List the children ids" },
681 { "find_object", vlcObject_find_object, METH_VARARGS,
682 "find_object(str) -> Object Find the object of a given type.\n\nAvailable types are : aout, decoder, input, httpd, intf, playlist, root, vlc, vout"},
683 { "find_id", vlcObject_find_id, METH_VARARGS,
684 "find_id(int) -> Object Find an object by id" },
685 { "info", vlcObject_info, METH_VARARGS,
686 "info() -> dict Return information about the object" },
687 { "release", vlcObject_release, METH_VARARGS,
688 "release() -> Release the VLC Object" },
689 { NULL, NULL, 0, NULL },
692 static PyTypeObject vlcObject_Type =
694 PyObject_HEAD_INIT(NULL)
696 "vlc.Object", /*tp_name*/
697 sizeof(vlcObject_Type), /*tp_basicsize*/
699 (destructor)vlcObject_dealloc, /*tp_dealloc*/
706 0, /*tp_as_sequence*/
714 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
715 "Explore VLC objects.", /* tp_doc */
718 0, /* tp_richcompare */
719 0, /* tp_weaklistoffset */
722 vlcObject_methods, /* tp_methods */
727 0, /* tp_descr_get */
728 0, /* tp_descr_set */
729 0, /* tp_dictoffset */
732 vlcObject_new, /* tp_new */
738 /*****************************************************************************
739 * VLC MediaControl object implementation
740 *****************************************************************************/
742 static PyObject *MediaControl_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
745 mediacontrol_Exception *exception = NULL;
746 PyObject* py_list = NULL;
747 char** ppsz_args = NULL;
749 self = PyObject_New(MediaControl, &MediaControl_Type);
751 if (PyArg_ParseTuple(args, "O", &py_list))
757 if (! PySequence_Check(py_list))
759 PyErr_SetString(PyExc_TypeError, "Parameter must be a sequence.");
762 i_size = PySequence_Size(py_list);
763 ppsz_args = malloc(i_size + 1);
766 PyErr_SetString(PyExc_MemoryError, "Out of memory");
770 for ( i_index = 0; i_index < i_size; i_index++ )
773 strdup( PyString_AsString( PyObject_Str(
774 PySequence_GetItem(py_list,
777 ppsz_args[i_size] = NULL;
781 Py_BEGIN_ALLOW_THREADS
783 self->mc = mediacontrol_new( ppsz_args, exception );
788 return (PyObject *)self;
791 static void MediaControl_dealloc(PyObject *self)
797 * Returns the current position in the stream. The returned value can
798 be relative or absolute (according to PositionOrigin) and the unit
799 is set by PositionKey
801 static PyObject * MediaControl_get_media_position(
802 PyObject *self, PyObject *args)
804 mediacontrol_Position* pos;
805 mediacontrol_Exception* exception = NULL;
809 mediacontrol_PositionOrigin origin;
810 mediacontrol_PositionKey key;
812 if( !PyArg_ParseTuple( args, "OO", &py_origin, &py_key ) )
815 origin = positionOrigin_py_to_c(py_origin);
816 key = positionKey_py_to_c(py_key);
818 Py_BEGIN_ALLOW_THREADS
820 pos = mediacontrol_get_media_position(SELF->mc, origin, key, exception);
824 py_retval = (PyObject*)position_c_to_py(pos);
829 /** Sets the media position */
830 static PyObject *MediaControl_set_media_position(
831 PyObject *self, PyObject *args )
833 mediacontrol_Exception* exception = NULL;
834 mediacontrol_Position *a_position;
837 if( !PyArg_ParseTuple( args, "O", &py_pos ) )
840 a_position = position_py_to_c(py_pos);
843 PyErr_SetString(PyExc_MemoryError, "Out of memory");
847 Py_BEGIN_ALLOW_THREADS
849 mediacontrol_set_media_position( SELF->mc, a_position, exception );
858 static PyObject *MediaControl_start(PyObject *self, PyObject *args)
860 mediacontrol_Position *a_position;
861 mediacontrol_Exception *exception = NULL;
864 if( !PyArg_ParseTuple(args, "O", &py_pos ) )
867 a_position = position_py_to_c(py_pos);
871 Py_BEGIN_ALLOW_THREADS
873 mediacontrol_start(SELF->mc, a_position, exception);
882 static PyObject *MediaControl_pause(PyObject *self, PyObject *args)
884 mediacontrol_Position *a_position;
885 mediacontrol_Exception *exception = NULL;
888 if( !PyArg_ParseTuple(args, "O", &py_pos ) )
891 a_position = position_py_to_c(py_pos);
893 Py_BEGIN_ALLOW_THREADS
895 mediacontrol_pause(SELF->mc, a_position, exception);
900 Py_INCREF( Py_None );
904 static PyObject * MediaControl_resume(PyObject *self, PyObject *args)
906 mediacontrol_Position *a_position;
907 mediacontrol_Exception *exception = NULL;
910 if( !PyArg_ParseTuple(args, "O", &py_pos ) )
913 a_position = position_py_to_c(py_pos);
915 Py_BEGIN_ALLOW_THREADS
917 mediacontrol_start(SELF->mc, a_position, exception);
926 static PyObject *MediaControl_stop(PyObject *self, PyObject *args)
928 mediacontrol_Position *a_position;
929 mediacontrol_Exception *exception = NULL;
932 if( !PyArg_ParseTuple(args, "O", &py_pos ) )
935 a_position = position_py_to_c(py_pos);
937 Py_BEGIN_ALLOW_THREADS
939 mediacontrol_stop(SELF->mc, a_position, exception);
948 static PyObject *MediaControl_exit(PyObject *self, PyObject *args)
950 mediacontrol_exit(SELF->mc);
955 static PyObject *MediaControl_playlist_add_item(PyObject *self, PyObject *args)
958 mediacontrol_Exception *exception = NULL;
960 if ( !PyArg_ParseTuple(args, "s", &psz_file) )
963 Py_BEGIN_ALLOW_THREADS
965 mediacontrol_playlist_add_item(SELF->mc, psz_file, exception);
973 static PyObject * MediaControl_playlist_clear( PyObject *self,
976 mediacontrol_Exception *exception = NULL;
978 Py_BEGIN_ALLOW_THREADS
980 mediacontrol_playlist_clear(SELF->mc, exception);
988 static PyObject * MediaControl_playlist_get_list( PyObject *self,
992 mediacontrol_Exception *exception = NULL;
993 mediacontrol_PlaylistSeq* pl;
997 Py_BEGIN_ALLOW_THREADS
999 pl = mediacontrol_playlist_get_list(SELF->mc, exception);
1000 Py_END_ALLOW_THREADS
1003 i_playlist_size = pl->size;
1005 py_retval = PyList_New( i_playlist_size );
1007 for (i_index = 0 ; i_index < i_playlist_size ; i_index++)
1009 PyList_SetItem( py_retval, i_index,
1010 Py_BuildValue("s", pl->data[i_index] ) );
1012 mediacontrol_PlaylistSeq__free(pl);
1018 static PyObject * MediaControl_snapshot(PyObject *self, PyObject *args)
1020 mediacontrol_RGBPicture *retval = NULL;
1021 mediacontrol_Exception* exception = NULL;
1022 mediacontrol_Position *a_position = NULL;
1023 PyObject *py_pos = NULL;
1024 PyObject *py_obj = NULL;
1026 if( !PyArg_ParseTuple(args, "O", &py_pos))
1029 a_position = position_py_to_c(py_pos);
1031 Py_BEGIN_ALLOW_THREADS
1033 retval = mediacontrol_snapshot(SELF->mc, a_position, exception);
1035 Py_END_ALLOW_THREADS
1040 Py_INCREF( Py_None );
1044 /* FIXME: create a real RGBPicture object */
1045 py_obj = PyDict_New();
1047 PyDict_SetItemString(py_obj, "width",
1048 Py_BuildValue("i", retval->width) );
1049 PyDict_SetItemString(py_obj, "height",
1050 Py_BuildValue("i", retval->height) );
1051 PyDict_SetItemString(py_obj, "type",
1052 Py_BuildValue("i", retval->type) );
1053 PyDict_SetItemString(py_obj, "data",
1054 Py_BuildValue("s#", retval->data, retval->size) );
1056 /* Py_INCREF(py_obj); */
1060 static PyObject* MediaControl_display_text(PyObject *self, PyObject *args)
1062 mediacontrol_Exception* exception = NULL;
1063 PyObject *py_begin, *py_end;
1065 mediacontrol_Position * begin;
1066 mediacontrol_Position * end;
1068 if( !PyArg_ParseTuple(args, "sOO", &message, &py_begin, &py_end))
1071 begin = position_py_to_c(py_begin);
1072 end = position_py_to_c(py_end);
1074 Py_BEGIN_ALLOW_THREADS
1076 mediacontrol_display_text(SELF->mc, message, begin, end, exception);
1077 Py_END_ALLOW_THREADS
1087 static PyObject* MediaControl_get_stream_information(
1088 PyObject *self, PyObject *args)
1090 mediacontrol_StreamInformation *retval = NULL;
1091 mediacontrol_Exception* exception = NULL;
1094 Py_BEGIN_ALLOW_THREADS
1096 retval = mediacontrol_get_stream_information(
1097 SELF->mc, mediacontrol_MediaTime, exception);
1098 Py_END_ALLOW_THREADS
1101 py_obj = PyDict_New();
1103 /* FIXME: create a real StreamInformation object */
1104 PyDict_SetItemString(py_obj, "status",
1105 Py_BuildValue("i", retval->streamstatus));
1106 PyDict_SetItemString(py_obj, "url",
1107 Py_BuildValue("s", retval->url));
1108 PyDict_SetItemString(py_obj, "position",
1109 Py_BuildValue("L", retval->position));
1110 PyDict_SetItemString(py_obj, "length",
1111 Py_BuildValue("L", retval->length));
1116 /* Py_INCREF(py_obj); */
1120 static PyObject* MediaControl_sound_set_volume(PyObject *self, PyObject *args)
1122 mediacontrol_Exception* exception = NULL;
1123 unsigned short volume;
1125 if (!PyArg_ParseTuple(args, "H", &volume))
1128 Py_BEGIN_ALLOW_THREADS
1130 mediacontrol_sound_set_volume(SELF->mc, volume, exception);
1131 Py_END_ALLOW_THREADS
1138 static PyObject* MediaControl_sound_get_volume(PyObject *self, PyObject *args)
1140 mediacontrol_Exception* exception = NULL;
1141 PyObject *py_retval;
1142 unsigned short volume;
1144 Py_BEGIN_ALLOW_THREADS
1146 volume=mediacontrol_sound_get_volume(SELF->mc, exception);
1147 Py_END_ALLOW_THREADS
1150 py_retval = Py_BuildValue("H", volume);
1154 static PyObject* MediaControl_set_visual(PyObject *self, PyObject *args)
1156 mediacontrol_Exception* exception = NULL;
1157 WINDOWHANDLE visual;
1159 if (!PyArg_ParseTuple(args, "i", &visual))
1162 Py_BEGIN_ALLOW_THREADS
1164 mediacontrol_set_visual(SELF->mc, visual, exception);
1165 Py_END_ALLOW_THREADS
1172 static PyMethodDef MediaControl_methods[] =
1174 {"get_media_position", MediaControl_get_media_position, METH_VARARGS,
1175 "get_media_position(origin, key) -> Position Get current media position." },
1176 { "set_media_position", MediaControl_set_media_position, METH_VARARGS,
1177 "set_media_position(Position) Set media position" },
1178 { "start", MediaControl_start, METH_VARARGS,
1179 "start(Position) Start the player." },
1180 { "pause", MediaControl_pause, METH_VARARGS,
1181 "pause(Position) Pause the player." },
1182 { "resume", MediaControl_resume, METH_VARARGS,
1183 "resume(Position) Resume the player" },
1184 { "stop", MediaControl_stop, METH_VARARGS,
1185 "stop(Position) Stop the player" },
1186 { "exit", MediaControl_exit, METH_VARARGS,
1187 "exit() Exit the player" },
1188 { "playlist_add_item", MediaControl_playlist_add_item, METH_VARARGS,
1189 "playlist_add_item(str) Add an item to the playlist" },
1190 { "playlist_get_list", MediaControl_playlist_get_list, METH_VARARGS,
1191 "playlist_get_list() -> list Get the contents of the playlist" },
1192 { "playlist_clear", MediaControl_playlist_clear, METH_VARARGS,
1193 "clear() Clear the playlist." },
1194 { "snapshot", MediaControl_snapshot, METH_VARARGS,
1195 "snapshot(Position) -> dict Take a snapshot" },
1196 { "display_text", MediaControl_display_text, METH_VARARGS,
1197 "display_text(str, Position, Position) Display a text on the video" },
1198 { "get_stream_information", MediaControl_get_stream_information,
1200 "get_stream_information() -> dict Get information about the stream"},
1201 { "sound_get_volume", MediaControl_sound_get_volume, METH_VARARGS,
1202 "sound_get_volume() -> int Get the volume" },
1203 { "sound_set_volume", MediaControl_sound_set_volume, METH_VARARGS,
1204 "sound_set_volume(int) Set the volume" },
1205 { "set_visual", MediaControl_set_visual, METH_VARARGS,
1206 "set_visual(int) Set the embedding window visual ID" },
1207 { NULL, NULL, 0, NULL },
1210 static PyTypeObject MediaControl_Type =
1212 PyObject_HEAD_INIT(NULL)
1214 "vlc.MediaControl", /*tp_name*/
1215 sizeof(MediaControl_Type), /*tp_basicsize*/
1217 (destructor)MediaControl_dealloc, /*tp_dealloc*/
1224 0, /*tp_as_sequence*/
1225 0, /*tp_as_mapping*/
1232 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
1233 "Control of a VLC instance.", /* tp_doc */
1234 0, /* tp_traverse */
1236 0, /* tp_richcompare */
1237 0, /* tp_weaklistoffset */
1239 0, /* tp_iternext */
1240 MediaControl_methods, /* tp_methods */
1245 0, /* tp_descr_get */
1246 0, /* tp_descr_set */
1247 0, /* tp_dictoffset */
1250 MediaControl_new, /* tp_new */
1253 /***********************************************************************
1255 ***********************************************************************/
1258 static int PyPosition_init( PyPosition *self, PyObject *args, PyObject *kwds )
1260 self->origin = mediacontrol_AbsolutePosition;
1261 self->key = mediacontrol_MediaTime;
1266 mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key )
1268 mediacontrol_PositionKey key_position = mediacontrol_MediaTime;
1271 if( !PyArg_Parse( py_key, "i", &key ) )
1273 PyErr_SetString (MediaControl_InternalException, "Invalid key value");
1274 return key_position;
1279 case 0: key = mediacontrol_ByteCount; break;
1280 case 1: key = mediacontrol_SampleCount; break;
1281 case 2: key = mediacontrol_MediaTime; break;
1283 return key_position;
1286 mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin )
1288 mediacontrol_PositionOrigin origin_position =
1289 mediacontrol_AbsolutePosition;
1292 if(!PyArg_Parse(py_origin,"i", &origin))
1294 PyErr_SetString( MediaControl_InternalException,
1295 "Invalid origin value");
1296 return origin_position;
1301 case 0: origin_position = mediacontrol_AbsolutePosition; break;
1302 case 1: origin_position = mediacontrol_RelativePosition; break;
1303 case 2: origin_position = mediacontrol_ModuloPosition; break;
1306 return origin_position;
1309 /* Methods for transforming the Position Python object to Position structure*/
1310 mediacontrol_Position* position_py_to_c( PyObject * py_position )
1312 mediacontrol_Position * a_position = NULL;
1313 PyPosition *pos = (PyPosition*)py_position;
1315 a_position = (mediacontrol_Position*)malloc(sizeof(mediacontrol_Position));
1318 PyErr_SetString(PyExc_MemoryError, "Out of memory");
1322 if (PyObject_IsInstance(py_position, (PyObject*)&PyPosition_Type))
1324 a_position->origin = pos->origin;
1325 a_position->key = pos->key;
1326 a_position->value = pos->value;
1330 /* Feature: if we give an integer, it will be considered as
1331 a relative position in mediatime */
1332 a_position->origin = mediacontrol_RelativePosition;
1333 a_position->key = mediacontrol_MediaTime;
1334 a_position->value = PyLong_AsLongLong(py_position);
1339 PyPosition* position_c_to_py(mediacontrol_Position *position)
1341 PyPosition* py_retval;
1343 py_retval = PyObject_New(PyPosition, &PyPosition_Type);
1344 py_retval->origin = position->origin;
1345 py_retval->key = position->key;
1346 py_retval->value = position->value;
1351 static PyMethodDef PyPosition_methods[] =
1353 { NULL } /* Sentinel */
1356 static PyMemberDef PyPosition_members[] =
1358 { "origin", T_INT, offsetof(PyPosition, origin), 0, "Position origin" },
1359 { "key", T_INT, offsetof(PyPosition, key), 0, "Position key" },
1360 { "value", T_ULONG, offsetof(PyPosition, value), 0, "Position value" },
1361 { NULL } /* Sentinel */
1364 static PyTypeObject PyPosition_Type =
1366 PyObject_HEAD_INIT(NULL)
1368 "vlc.Position", /*tp_name*/
1369 sizeof(PyPosition_Type), /*tp_basicsize*/
1378 0, /*tp_as_sequence*/
1379 0, /*tp_as_mapping*/
1386 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
1387 "Represent a Position with origin, key and value", /* tp_doc */
1388 0, /* tp_traverse */
1390 0, /* tp_richcompare */
1391 0, /* tp_weaklistoffset */
1393 0, /* tp_iternext */
1394 PyPosition_methods, /* tp_methods */
1395 PyPosition_members, /* tp_members */
1399 0, /* tp_descr_get */
1400 0, /* tp_descr_set */
1401 0, /* tp_dictoffset */
1402 (initproc)PyPosition_init, /* tp_init */