1 /*****************************************************************************
2 * vlcglue.c: VLC Module
3 *****************************************************************************
4 * Copyright (C) 1998-2004 the VideoLAN team
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 /* PyEval_InitThreads(); */
55 http://base.bel-epa.com/pyapache/Python/MySQL-python/MySQL-python-0.3.0/_mysqlmodule.c */
57 m = Py_InitModule3( "vlc", vlc_methods,
58 "VLC media player embedding module.");
63 if (PyType_Ready(&PyPosition_Type) < 0)
65 if (PyType_Ready(&MediaControl_Type) < 0)
67 #ifdef VLCOBJECT_SUPPORT
68 if (PyType_Ready(&vlcObject_Type) < 0)
73 MediaControl_InternalException =
74 PyErr_NewException("vlc.InternalException", NULL, NULL);
75 Py_INCREF(MediaControl_InternalException);
76 PyModule_AddObject(m, "InternalException", MediaControl_InternalException);
78 MediaControl_PositionKeyNotSupported =
79 PyErr_NewException("vlc.PositionKeyNotSupported", NULL, NULL);
80 Py_INCREF(MediaControl_PositionKeyNotSupported);
81 PyModule_AddObject(m, "PositionKeyNotSupported",
82 MediaControl_PositionKeyNotSupported);
84 MediaControl_PositionOriginNotSupported=
85 PyErr_NewException("vlc.InvalidPosition", NULL, NULL);
86 Py_INCREF(MediaControl_PositionOriginNotSupported);
87 PyModule_AddObject(m, "PositionOriginNotSupported",
88 MediaControl_PositionOriginNotSupported);
90 MediaControl_InvalidPosition =
91 PyErr_NewException("vlc.InvalidPosition", NULL, NULL);
92 Py_INCREF(MediaControl_InvalidPosition);
93 PyModule_AddObject(m, "InvalidPosition", MediaControl_InvalidPosition);
95 MediaControl_PlaylistException =
96 PyErr_NewException("vlc.PlaylistException", NULL, NULL);
97 Py_INCREF(MediaControl_PlaylistException);
98 PyModule_AddObject(m, "PlaylistException", MediaControl_PlaylistException);
101 Py_INCREF(&PyPosition_Type);
102 PyModule_AddObject(m, "Position", (PyObject *)&PyPosition_Type);
104 Py_INCREF(&MediaControl_Type);
105 PyModule_AddObject(m, "MediaControl", (PyObject *)&MediaControl_Type);
107 #ifdef VLCOBJECT_SUPPORT
108 Py_INCREF(&vlcObject_Type);
109 PyModule_AddObject(m, "Object", (PyObject *)&vlcObject_Type);
113 PyModule_AddIntConstant(m, "AbsolutePosition",
114 mediacontrol_AbsolutePosition);
115 PyModule_AddIntConstant(m, "RelativePosition",
116 mediacontrol_RelativePosition);
117 PyModule_AddIntConstant(m, "ModuloPosition",
118 mediacontrol_ModuloPosition);
120 PyModule_AddIntConstant(m, "ByteCount", mediacontrol_ByteCount);
121 PyModule_AddIntConstant(m, "SampleCount", mediacontrol_SampleCount);
122 PyModule_AddIntConstant(m, "MediaTime", mediacontrol_MediaTime);
123 PyModule_AddIntConstant(m, "PlayingStatus", mediacontrol_PlayingStatus);
124 PyModule_AddIntConstant(m, "PauseStatus", mediacontrol_PauseStatus);
125 PyModule_AddIntConstant(m, "ForwardStatus", mediacontrol_ForwardStatus);
126 PyModule_AddIntConstant(m, "BackwardStatus", mediacontrol_BackwardStatus);
127 PyModule_AddIntConstant(m, "InitStatus", mediacontrol_InitStatus);
128 PyModule_AddIntConstant(m, "EndStatus", mediacontrol_EndStatus);
129 PyModule_AddIntConstant(m, "UndefinedStatus", mediacontrol_UndefinedStatus);
133 /* Make libpostproc happy... */
134 void * fast_memcpy(void * to, const void * from, size_t len)
136 return memcpy(to, from, len);
140 /*****************************************************************************
141 * VLCObject implementation
142 *****************************************************************************/
144 #ifdef VLCOBJECT_SUPPORT
146 static PyObject *vlcObject_new(
147 PyTypeObject *type, PyObject *args, PyObject *kwds)
150 vlc_object_t *p_object;
153 self = PyObject_New(vlcObject, &vlcObject_Type);
155 if ( !PyArg_ParseTuple(args, "i", &i_id) )
158 /* Maybe we were already initialized */
159 p_object = (vlc_object_t*)vlc_current_object(i_id);
163 /* Try to initialize */
165 p_object = (vlc_object_t*)vlc_current_object(i_id);
170 PyErr_SetString(PyExc_StandardError, "Unable to get object.");
174 self->p_object = p_object;
175 self->b_released = 0;
177 Py_INCREF( self ); /* Ah bon ? */
178 return (PyObject *)self;
181 static PyObject * vlcObject_release( PyObject *self )
183 if( VLCSELF->b_released == 0 )
185 vlc_object_release( VLCSELF->p_object );
186 VLCSELF->b_released = 1;
192 static void vlcObject_dealloc(PyObject *self)
194 vlcObject_release( self );
198 static PyObject * vlcObject_find_object(PyObject *self, PyObject *args)
205 if ( !PyArg_ParseTuple(args, "s", &psz_name) )
209 (aout, decoder, input, httpd, intf, playlist, root, vlc, vout)
214 i_object_type = VLC_OBJECT_AOUT;
217 i_object_type = VLC_OBJECT_DECODER;
220 i_object_type = VLC_OBJECT_HTTPD;
223 if (strlen(psz_name) < 3)
224 i_object_type = VLC_OBJECT_INTF;
225 else if (psz_name[2] == 't')
226 i_object_type = VLC_OBJECT_INTF;
228 i_object_type = VLC_OBJECT_INPUT;
231 i_object_type = VLC_OBJECT_PLAYLIST;
234 i_object_type = VLC_OBJECT_ROOT;
237 if (strlen(psz_name) < 3)
238 i_object_type = VLC_OBJECT_VLC;
239 else if (psz_name[1] == 'l')
240 i_object_type = VLC_OBJECT_VLC;
242 i_object_type = VLC_OBJECT_VOUT;
245 /* FIXME: raise an exception */
249 p_obj = vlc_object_find( VLCSELF->p_object, i_object_type, FIND_ANYWHERE );
257 retval = PyObject_New(vlcObject, &vlcObject_Type);
259 retval->p_object = p_obj;
261 return (PyObject *)retval;
264 static PyObject * vlcObject_info(PyObject *self, PyObject *args)
269 p_obj = VLCSELF->p_object;
271 /* Return information about the object as a dict. */
272 retval = PyDict_New();
274 PyDict_SetItemString(retval, "object-id",
275 Py_BuildValue("l", p_obj->i_object_id));
276 PyDict_SetItemString(retval, "object-type",
277 Py_BuildValue("s", p_obj->psz_object_type));
278 PyDict_SetItemString(retval, "object-name",
279 Py_BuildValue("s", p_obj->psz_object_name));
280 PyDict_SetItemString(retval, "thread",
281 PyBool_FromLong(p_obj->b_thread));
282 PyDict_SetItemString(retval, "thread-id",
283 PyLong_FromLongLong(p_obj->thread_id));
284 PyDict_SetItemString(retval, "refcount",
285 PyInt_FromLong(p_obj->i_refcount));
290 static PyObject * vlcObject_find_id(PyObject *self, PyObject *args)
293 vlc_object_t* p_object;
296 if ( !PyArg_ParseTuple(args, "i", &i_id) )
299 p_object = (vlc_object_t*)vlc_current_object(i_id);
307 retval = PyObject_NEW(vlcObject, &vlcObject_Type);
309 retval->p_object = p_object;
311 return (PyObject *)retval;
314 /* Do a var_Get call on the object. Parameter: the variable name. */
315 /* FIXME: We should make them attributes */
316 static PyObject * vlcObject_var_get(PyObject *self, PyObject *args)
323 if ( !PyArg_ParseTuple(args, "s", &psz_name) )
326 if( var_Get( VLCSELF->p_object, psz_name, &value ) != VLC_SUCCESS )
328 PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n");
332 i_type = var_Type (VLCSELF->p_object, psz_name);
337 retval = PyString_FromString("A void variable");
340 retval = PyBool_FromLong(value.b_bool);
342 case VLC_VAR_INTEGER :
343 retval = PyInt_FromLong((long)value.i_int);
345 case VLC_VAR_HOTKEY :
346 retval = PyString_FromFormat("A hotkey variable (%d)", value.i_int);
349 case VLC_VAR_STRING :
350 case VLC_VAR_DIRECTORY :
351 case VLC_VAR_VARIABLE :
352 retval = PyString_FromString(value.psz_string);
354 case VLC_VAR_MODULE :
355 retval = (PyObject*)PyObject_New(vlcObject, &vlcObject_Type);
356 ((vlcObject*)retval)->p_object = value.p_object;
359 retval = PyFloat_FromDouble((double)value.f_float);
362 retval = PyLong_FromLongLong(value.i_time);
364 case VLC_VAR_ADDRESS :
365 retval = PyString_FromString("A VLC address (not handled yet)");
368 retval = PyString_FromString("A VLC list (not handled yet)");
371 retval = PyString_FromString("A mutex");
381 static PyObject * vlcObject_var_type(PyObject *self,
388 if ( !PyArg_ParseTuple(args, "s", &psz_name))
391 i_type = var_Type(VLCSELF->p_object, psz_name);
396 retval = PyString_FromString("Void");
399 retval = PyString_FromString("Boolean");
401 case VLC_VAR_INTEGER :
402 retval = PyString_FromString("Integer");
404 case VLC_VAR_HOTKEY :
405 retval = PyString_FromString("Hotkey");
408 retval = PyString_FromString("File");
410 case VLC_VAR_STRING :
411 retval = PyString_FromString("String");
413 case VLC_VAR_DIRECTORY :
414 retval = PyString_FromString("Directory");
416 case VLC_VAR_VARIABLE :
417 retval = PyString_FromString("Variable");
419 case VLC_VAR_MODULE :
420 retval = PyString_FromString("Module");
423 retval = PyString_FromString("Float");
426 retval = PyString_FromString("Time");
428 case VLC_VAR_ADDRESS :
429 retval = PyString_FromString("Address");
432 retval = PyString_FromString("List");
435 retval = PyString_FromString("Mutex");
438 retval = PyString_FromString("Unknown");
443 /* Do a var_Set call on the object. Parameter: the variable name. */
444 /* FIXME: We should make them attributes */
445 static PyObject * vlcObject_var_set(PyObject *self,
454 if ( !PyArg_ParseTuple(args, "sO", &psz_name, &py_value) )
457 p_obj = VLCSELF->p_object;
458 i_type = var_Type(p_obj, psz_name);
465 value.b_bool = PyInt_AsLong(py_value);
467 case VLC_VAR_INTEGER :
468 case VLC_VAR_HOTKEY :
469 value.i_int = PyInt_AsLong(py_value);
472 case VLC_VAR_STRING :
473 case VLC_VAR_DIRECTORY :
474 case VLC_VAR_VARIABLE :
475 value.psz_string = strdup(PyString_AsString(py_value));
477 case VLC_VAR_MODULE :
478 /* FIXME: we should check the PyObject type and get its p_object */
479 value.p_object = ((vlcObject*)p_obj)->p_object;
482 value.f_float = PyFloat_AsDouble(py_value);
485 value.i_time = PyLong_AsLongLong(py_value);
487 case VLC_VAR_ADDRESS :
488 value.p_address = (char*)PyLong_AsVoidPtr(py_value);
498 var_Set(p_obj, psz_name, value);
504 static PyObject * vlcObject_var_list(PyObject *self,
511 i_size = VLCSELF->p_object->i_vars;
512 retval = PyTuple_New(i_size);
514 for (i_index = 0 ; i_index < i_size ; i_index++)
516 PyTuple_SetItem(retval, i_index,
517 Py_BuildValue("s", VLCSELF->p_object->p_vars[i_index].psz_name));
520 /* Py_INCREF(retval); */
524 /* Do a config_Get call on the object. Parameter: the variable name. */
525 static PyObject * vlcObject_config_get(PyObject *self,
531 module_config_t *p_config;
533 if ( !PyArg_ParseTuple(args, "s", &psz_name) )
536 p_config = config_FindConfig( VLCSELF->p_object, psz_name );
540 PyErr_SetString(PyExc_StandardError, "Error: config variable does not exist.\n");
545 switch (p_config->i_type)
547 case CONFIG_ITEM_BOOL :
548 retval = PyBool_FromLong(p_config->i_value);
550 case CONFIG_ITEM_INTEGER :
551 retval = PyInt_FromLong((long)p_config->i_value);
553 case CONFIG_ITEM_KEY :
554 retval = PyString_FromFormat("A hotkey variable (%d)", p_config->i_value);
556 case CONFIG_ITEM_FILE :
557 case CONFIG_ITEM_STRING :
558 case CONFIG_ITEM_DIRECTORY :
559 case CONFIG_ITEM_MODULE :
560 vlc_mutex_lock( p_config->p_lock );
561 if( p_config->psz_value )
562 retval = PyString_FromString( p_config->psz_value );
564 retval = PyString_FromString( "" );
565 vlc_mutex_unlock( p_config->p_lock );
567 retval = (PyObject*)PyObject_New(vlcObject, &vlcObject_Type);
568 ((vlcObject*)retval)->p_object = value.p_object;
570 case CONFIG_ITEM_FLOAT :
571 retval = PyFloat_FromDouble((double)p_config->f_value);
581 /* Do a var_Set call on the object. Parameter: the variable name. */
582 /* FIXME: We should make them attributes */
583 static PyObject * vlcObject_config_set(PyObject *self,
589 module_config_t *p_config;
592 if ( !PyArg_ParseTuple(args, "sO", &psz_name, &py_value) )
595 p_obj = VLCSELF->p_object;
596 p_config = config_FindConfig( p_obj, psz_name );
600 PyErr_SetString(PyExc_StandardError,
601 "Error: option does not exist.\n");
606 switch (p_config->i_type)
608 case CONFIG_ITEM_BOOL :
609 case CONFIG_ITEM_INTEGER :
610 case CONFIG_ITEM_KEY :
611 config_PutInt(p_obj, psz_name, PyInt_AsLong(py_value));
613 case CONFIG_ITEM_FILE :
614 case CONFIG_ITEM_STRING :
615 case CONFIG_ITEM_DIRECTORY :
616 case CONFIG_ITEM_MODULE :
617 config_PutPsz(p_obj, psz_name, PyString_AsString(py_value));
619 case CONFIG_ITEM_FLOAT :
620 config_PutFloat(p_obj, psz_name, PyFloat_AsDouble(py_value));
627 static PyObject * vlcObject_children(PyObject *self,
634 i_size = VLCSELF->p_object->i_children;
635 retval = PyTuple_New(i_size);
637 for (i_index = 0 ; i_index < i_size ; i_index++)
639 PyTuple_SetItem(retval, i_index,
641 VLCSELF->p_object->pp_children[i_index]->i_object_id));
644 /* Py_INCREF(retval); */
650 static PyMethodDef vlcObject_methods[] =
652 { "get", vlcObject_var_get, METH_VARARGS,
653 "get(str) -> value Get a variable value."},
654 { "set", vlcObject_var_set, METH_VARARGS,
655 "set(str, value) Set a variable value" },
656 { "config_get", vlcObject_config_get, METH_VARARGS,
657 "config_get(str) -> value Get a configuration option." },
658 { "config_set", vlcObject_config_set, METH_VARARGS,
659 "config_set(str, value) Set a configuration option" },
660 { "type", vlcObject_var_type, METH_VARARGS,
661 "type(str) -> str Get a variable type" },
662 { "list", vlcObject_var_list, METH_VARARGS,
663 "list() List the available variables" },
664 { "children", vlcObject_children, METH_VARARGS,
665 "children() List the children ids" },
666 { "find_object", vlcObject_find_object, METH_VARARGS,
667 "find_object(str) -> Object Find the object of a given type.\n\nAvailable types are : aout, decoder, input, httpd, intf, playlist, root, vlc, vout"},
668 { "find_id", vlcObject_find_id, METH_VARARGS,
669 "find_id(int) -> Object Find an object by id" },
670 { "info", vlcObject_info, METH_VARARGS,
671 "info() -> dict Return information about the object" },
672 { "release", vlcObject_release, METH_VARARGS,
673 "release() -> Release the VLC Object" },
674 { NULL, NULL, 0, NULL },
677 static PyTypeObject vlcObject_Type =
679 PyObject_HEAD_INIT(NULL)
681 "vlc.Object", /*tp_name*/
682 sizeof(vlcObject_Type), /*tp_basicsize*/
684 (destructor)vlcObject_dealloc, /*tp_dealloc*/
691 0, /*tp_as_sequence*/
699 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
700 "Explore VLC objects.", /* tp_doc */
703 0, /* tp_richcompare */
704 0, /* tp_weaklistoffset */
707 vlcObject_methods, /* tp_methods */
712 0, /* tp_descr_get */
713 0, /* tp_descr_set */
714 0, /* tp_dictoffset */
717 vlcObject_new, /* tp_new */
723 /*****************************************************************************
724 * VLC MediaControl object implementation
725 *****************************************************************************/
727 static PyObject *MediaControl_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
730 mediacontrol_Exception *exception = NULL;
731 PyObject* py_list = NULL;
732 char** ppsz_args = NULL;
734 self = PyObject_New(MediaControl, &MediaControl_Type);
736 if (PyArg_ParseTuple(args, "O", &py_list))
742 if (! PySequence_Check(py_list))
744 PyErr_SetString(PyExc_TypeError, "Parameter must be a sequence.");
747 i_size = PySequence_Size(py_list);
748 ppsz_args = malloc(i_size + 1);
751 PyErr_SetString(PyExc_MemoryError, "Out of memory");
755 for ( i_index = 0; i_index < i_size; i_index++ )
758 strdup( PyString_AsString( PyObject_Str(
759 PySequence_GetItem(py_list,
762 ppsz_args[i_size] = NULL;
767 /* No arguments were given. Clear the exception raised
768 by PyArg_ParseTuple. */
772 Py_BEGIN_ALLOW_THREADS
774 self->mc = mediacontrol_new( ppsz_args, exception );
779 return (PyObject *)self;
782 static void MediaControl_dealloc(PyObject *self)
788 * Returns the current position in the stream. The returned value can
789 be relative or absolute (according to PositionOrigin) and the unit
790 is set by PositionKey
792 static PyObject * MediaControl_get_media_position(
793 PyObject *self, PyObject *args)
795 mediacontrol_Position* pos;
796 mediacontrol_Exception* exception = NULL;
800 mediacontrol_PositionOrigin origin;
801 mediacontrol_PositionKey key;
803 if( !PyArg_ParseTuple( args, "OO", &py_origin, &py_key ) )
806 origin = positionOrigin_py_to_c(py_origin);
807 key = positionKey_py_to_c(py_key);
809 Py_BEGIN_ALLOW_THREADS
811 pos = mediacontrol_get_media_position(SELF->mc, origin, key, exception);
815 py_retval = (PyObject*)position_c_to_py(pos);
820 /** Sets the media position */
821 static PyObject *MediaControl_set_media_position(
822 PyObject *self, PyObject *args )
824 mediacontrol_Exception* exception = NULL;
825 mediacontrol_Position *a_position;
828 if( !PyArg_ParseTuple( args, "O", &py_pos ) )
831 a_position = position_py_to_c(py_pos);
834 PyErr_SetString(PyExc_MemoryError, "Out of memory");
838 Py_BEGIN_ALLOW_THREADS
840 mediacontrol_set_media_position( SELF->mc, a_position, exception );
849 static PyObject *MediaControl_start(PyObject *self, PyObject *args)
851 mediacontrol_Position *a_position;
852 mediacontrol_Exception *exception = NULL;
855 if( !PyArg_ParseTuple(args, "O", &py_pos ) )
858 a_position = position_py_to_c(py_pos);
862 Py_BEGIN_ALLOW_THREADS
864 mediacontrol_start(SELF->mc, a_position, exception);
873 static PyObject *MediaControl_pause(PyObject *self, PyObject *args)
875 mediacontrol_Position *a_position;
876 mediacontrol_Exception *exception = NULL;
879 if( !PyArg_ParseTuple(args, "O", &py_pos ) )
882 a_position = position_py_to_c(py_pos);
884 Py_BEGIN_ALLOW_THREADS
886 mediacontrol_pause(SELF->mc, a_position, exception);
891 Py_INCREF( Py_None );
895 static PyObject * MediaControl_resume(PyObject *self, PyObject *args)
897 mediacontrol_Position *a_position;
898 mediacontrol_Exception *exception = NULL;
901 if( !PyArg_ParseTuple(args, "O", &py_pos ) )
904 a_position = position_py_to_c(py_pos);
906 Py_BEGIN_ALLOW_THREADS
908 mediacontrol_start(SELF->mc, a_position, exception);
917 static PyObject *MediaControl_stop(PyObject *self, PyObject *args)
919 mediacontrol_Position *a_position;
920 mediacontrol_Exception *exception = NULL;
923 if( !PyArg_ParseTuple(args, "O", &py_pos ) )
926 a_position = position_py_to_c(py_pos);
928 Py_BEGIN_ALLOW_THREADS
930 mediacontrol_stop(SELF->mc, a_position, exception);
939 static PyObject *MediaControl_exit(PyObject *self, PyObject *args)
941 mediacontrol_exit(SELF->mc);
946 static PyObject *MediaControl_playlist_add_item(PyObject *self, PyObject *args)
949 mediacontrol_Exception *exception = NULL;
951 if ( !PyArg_ParseTuple(args, "s", &psz_file) )
954 Py_BEGIN_ALLOW_THREADS
956 mediacontrol_playlist_add_item(SELF->mc, psz_file, exception);
964 static PyObject * MediaControl_playlist_clear( PyObject *self,
967 mediacontrol_Exception *exception = NULL;
969 Py_BEGIN_ALLOW_THREADS
971 mediacontrol_playlist_clear(SELF->mc, exception);
979 static PyObject * MediaControl_playlist_get_list( PyObject *self,
983 mediacontrol_Exception *exception = NULL;
984 mediacontrol_PlaylistSeq* pl;
988 Py_BEGIN_ALLOW_THREADS
990 pl = mediacontrol_playlist_get_list(SELF->mc, exception);
994 i_playlist_size = pl->size;
996 py_retval = PyList_New( i_playlist_size );
998 for (i_index = 0 ; i_index < i_playlist_size ; i_index++)
1000 PyList_SetItem( py_retval, i_index,
1001 Py_BuildValue("s", pl->data[i_index] ) );
1003 mediacontrol_PlaylistSeq__free(pl);
1009 static PyObject * MediaControl_snapshot(PyObject *self, PyObject *args)
1011 mediacontrol_RGBPicture *retval = NULL;
1012 mediacontrol_Exception* exception = NULL;
1013 mediacontrol_Position *a_position = NULL;
1014 PyObject *py_pos = NULL;
1015 PyObject *py_obj = NULL;
1017 if( !PyArg_ParseTuple(args, "O", &py_pos))
1020 a_position = position_py_to_c(py_pos);
1022 Py_BEGIN_ALLOW_THREADS
1024 retval = mediacontrol_snapshot(SELF->mc, a_position, exception);
1026 Py_END_ALLOW_THREADS
1031 Py_INCREF( Py_None );
1035 /* FIXME: create a real RGBPicture object */
1036 py_obj = PyDict_New();
1038 PyDict_SetItemString(py_obj, "width",
1039 Py_BuildValue("i", retval->width) );
1040 PyDict_SetItemString(py_obj, "height",
1041 Py_BuildValue("i", retval->height) );
1042 PyDict_SetItemString(py_obj, "type",
1043 Py_BuildValue("i", retval->type) );
1044 PyDict_SetItemString(py_obj, "data",
1045 Py_BuildValue("s#", retval->data, retval->size) );
1047 /* Py_INCREF(py_obj); */
1051 static PyObject* MediaControl_display_text(PyObject *self, PyObject *args)
1053 mediacontrol_Exception* exception = NULL;
1054 PyObject *py_begin, *py_end;
1056 mediacontrol_Position * begin;
1057 mediacontrol_Position * end;
1059 if( !PyArg_ParseTuple(args, "sOO", &message, &py_begin, &py_end))
1062 begin = position_py_to_c(py_begin);
1063 end = position_py_to_c(py_end);
1065 Py_BEGIN_ALLOW_THREADS
1067 mediacontrol_display_text(SELF->mc, message, begin, end, exception);
1068 Py_END_ALLOW_THREADS
1078 static PyObject* MediaControl_get_stream_information(
1079 PyObject *self, PyObject *args)
1081 mediacontrol_StreamInformation *retval = NULL;
1082 mediacontrol_Exception* exception = NULL;
1085 Py_BEGIN_ALLOW_THREADS
1087 retval = mediacontrol_get_stream_information(
1088 SELF->mc, mediacontrol_MediaTime, exception);
1089 Py_END_ALLOW_THREADS
1092 py_obj = PyDict_New();
1094 /* FIXME: create a real StreamInformation object */
1095 PyDict_SetItemString(py_obj, "status",
1096 Py_BuildValue("i", retval->streamstatus));
1097 PyDict_SetItemString(py_obj, "url",
1098 Py_BuildValue("s", retval->url));
1099 PyDict_SetItemString(py_obj, "position",
1100 Py_BuildValue("L", retval->position));
1101 PyDict_SetItemString(py_obj, "length",
1102 Py_BuildValue("L", retval->length));
1107 /* Py_INCREF(py_obj); */
1111 static PyObject* MediaControl_sound_set_volume(PyObject *self, PyObject *args)
1113 mediacontrol_Exception* exception = NULL;
1114 unsigned short volume;
1116 if (!PyArg_ParseTuple(args, "H", &volume))
1119 Py_BEGIN_ALLOW_THREADS
1121 mediacontrol_sound_set_volume(SELF->mc, volume, exception);
1122 Py_END_ALLOW_THREADS
1129 static PyObject* MediaControl_sound_get_volume(PyObject *self, PyObject *args)
1131 mediacontrol_Exception* exception = NULL;
1132 PyObject *py_retval;
1133 unsigned short volume;
1135 Py_BEGIN_ALLOW_THREADS
1137 volume=mediacontrol_sound_get_volume(SELF->mc, exception);
1138 Py_END_ALLOW_THREADS
1141 py_retval = Py_BuildValue("H", volume);
1145 static PyObject* MediaControl_set_visual(PyObject *self, PyObject *args)
1147 mediacontrol_Exception* exception = NULL;
1148 WINDOWHANDLE visual;
1150 if (!PyArg_ParseTuple(args, "i", &visual))
1153 Py_BEGIN_ALLOW_THREADS
1155 mediacontrol_set_visual(SELF->mc, visual, exception);
1156 Py_END_ALLOW_THREADS
1163 static PyMethodDef MediaControl_methods[] =
1165 {"get_media_position", MediaControl_get_media_position, METH_VARARGS,
1166 "get_media_position(origin, key) -> Position Get current media position." },
1167 { "set_media_position", MediaControl_set_media_position, METH_VARARGS,
1168 "set_media_position(Position) Set media position" },
1169 { "start", MediaControl_start, METH_VARARGS,
1170 "start(Position) Start the player." },
1171 { "pause", MediaControl_pause, METH_VARARGS,
1172 "pause(Position) Pause the player." },
1173 { "resume", MediaControl_resume, METH_VARARGS,
1174 "resume(Position) Resume the player" },
1175 { "stop", MediaControl_stop, METH_VARARGS,
1176 "stop(Position) Stop the player" },
1177 { "exit", MediaControl_exit, METH_VARARGS,
1178 "exit() Exit the player" },
1179 { "playlist_add_item", MediaControl_playlist_add_item, METH_VARARGS,
1180 "playlist_add_item(str) Add an item to the playlist" },
1181 { "playlist_get_list", MediaControl_playlist_get_list, METH_VARARGS,
1182 "playlist_get_list() -> list Get the contents of the playlist" },
1183 { "playlist_clear", MediaControl_playlist_clear, METH_VARARGS,
1184 "clear() Clear the playlist." },
1185 { "snapshot", MediaControl_snapshot, METH_VARARGS,
1186 "snapshot(Position) -> dict Take a snapshot" },
1187 { "display_text", MediaControl_display_text, METH_VARARGS,
1188 "display_text(str, Position, Position) Display a text on the video" },
1189 { "get_stream_information", MediaControl_get_stream_information,
1191 "get_stream_information() -> dict Get information about the stream"},
1192 { "sound_get_volume", MediaControl_sound_get_volume, METH_VARARGS,
1193 "sound_get_volume() -> int Get the volume" },
1194 { "sound_set_volume", MediaControl_sound_set_volume, METH_VARARGS,
1195 "sound_set_volume(int) Set the volume" },
1196 { "set_visual", MediaControl_set_visual, METH_VARARGS,
1197 "set_visual(int) Set the embedding window visual ID" },
1198 { NULL, NULL, 0, NULL },
1201 static PyTypeObject MediaControl_Type =
1203 PyObject_HEAD_INIT(NULL)
1205 "vlc.MediaControl", /*tp_name*/
1206 sizeof(MediaControl_Type), /*tp_basicsize*/
1208 (destructor)MediaControl_dealloc, /*tp_dealloc*/
1215 0, /*tp_as_sequence*/
1216 0, /*tp_as_mapping*/
1223 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
1224 "Control of a VLC instance.", /* tp_doc */
1225 0, /* tp_traverse */
1227 0, /* tp_richcompare */
1228 0, /* tp_weaklistoffset */
1230 0, /* tp_iternext */
1231 MediaControl_methods, /* tp_methods */
1236 0, /* tp_descr_get */
1237 0, /* tp_descr_set */
1238 0, /* tp_dictoffset */
1241 MediaControl_new, /* tp_new */
1244 /***********************************************************************
1246 ***********************************************************************/
1249 static int PyPosition_init( PyPosition *self, PyObject *args, PyObject *kwds )
1251 self->origin = mediacontrol_AbsolutePosition;
1252 self->key = mediacontrol_MediaTime;
1257 mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key )
1259 mediacontrol_PositionKey key_position = mediacontrol_MediaTime;
1262 if( !PyArg_Parse( py_key, "i", &key ) )
1264 PyErr_SetString (MediaControl_InternalException, "Invalid key value");
1265 return key_position;
1270 case 0: key = mediacontrol_ByteCount; break;
1271 case 1: key = mediacontrol_SampleCount; break;
1272 case 2: key = mediacontrol_MediaTime; break;
1274 return key_position;
1277 mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin )
1279 mediacontrol_PositionOrigin origin_position =
1280 mediacontrol_AbsolutePosition;
1283 if(!PyArg_Parse(py_origin,"i", &origin))
1285 PyErr_SetString( MediaControl_InternalException,
1286 "Invalid origin value");
1287 return origin_position;
1292 case 0: origin_position = mediacontrol_AbsolutePosition; break;
1293 case 1: origin_position = mediacontrol_RelativePosition; break;
1294 case 2: origin_position = mediacontrol_ModuloPosition; break;
1297 return origin_position;
1300 /* Methods for transforming the Position Python object to Position structure*/
1301 mediacontrol_Position* position_py_to_c( PyObject * py_position )
1303 mediacontrol_Position * a_position = NULL;
1304 PyPosition *pos = (PyPosition*)py_position;
1306 a_position = (mediacontrol_Position*)malloc(sizeof(mediacontrol_Position));
1309 PyErr_SetString(PyExc_MemoryError, "Out of memory");
1313 if (PyObject_IsInstance(py_position, (PyObject*)&PyPosition_Type))
1315 a_position->origin = pos->origin;
1316 a_position->key = pos->key;
1317 a_position->value = pos->value;
1321 /* Feature: if we give an integer, it will be considered as
1322 a relative position in mediatime */
1323 a_position->origin = mediacontrol_RelativePosition;
1324 a_position->key = mediacontrol_MediaTime;
1325 a_position->value = PyLong_AsLongLong(py_position);
1330 PyPosition* position_c_to_py(mediacontrol_Position *position)
1332 PyPosition* py_retval;
1334 py_retval = PyObject_New(PyPosition, &PyPosition_Type);
1335 py_retval->origin = position->origin;
1336 py_retval->key = position->key;
1337 py_retval->value = position->value;
1342 static PyMethodDef PyPosition_methods[] =
1344 { NULL } /* Sentinel */
1347 static PyMemberDef PyPosition_members[] =
1349 { "origin", T_INT, offsetof(PyPosition, origin), 0, "Position origin" },
1350 { "key", T_INT, offsetof(PyPosition, key), 0, "Position key" },
1351 { "value", T_ULONG, offsetof(PyPosition, value), 0, "Position value" },
1352 { NULL } /* Sentinel */
1355 static PyTypeObject PyPosition_Type =
1357 PyObject_HEAD_INIT(NULL)
1359 "vlc.Position", /*tp_name*/
1360 sizeof(PyPosition_Type), /*tp_basicsize*/
1369 0, /*tp_as_sequence*/
1370 0, /*tp_as_mapping*/
1377 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
1378 "Represent a Position with origin, key and value", /* tp_doc */
1379 0, /* tp_traverse */
1381 0, /* tp_richcompare */
1382 0, /* tp_weaklistoffset */
1384 0, /* tp_iternext */
1385 PyPosition_methods, /* tp_methods */
1386 PyPosition_members, /* tp_members */
1390 0, /* tp_descr_get */
1391 0, /* tp_descr_set */
1392 0, /* tp_dictoffset */
1393 (initproc)PyPosition_init, /* tp_init */