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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
26 /**************************************************************************
28 **************************************************************************/
30 #ifndef vlcMODINIT_FUNC /* declarations for DLL import/export */
31 #define vlcMODINIT_FUNC void
34 static PyMethodDef vlc_methods[] = {
35 { NULL } /* Sentinel */
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;
50 PyPosition_Type.tp_new = PyType_GenericNew;
51 PyPosition_Type.tp_alloc = PyType_GenericAlloc;
53 p_module = Py_InitModule3( "vlc", vlc_methods,
54 "VLC media player embedding module." );
59 if( PyType_Ready( &PyPosition_Type ) < 0 )
61 if( PyType_Ready( &MediaControl_Type ) < 0 )
63 if( PyType_Ready( &vlcObject_Type ) < 0 )
67 MediaControl_InternalException =
68 PyErr_NewException( "vlc.InternalException", NULL, NULL );
69 Py_INCREF( MediaControl_InternalException );
70 PyModule_AddObject( p_module, "InternalException",
71 MediaControl_InternalException );
73 MediaControl_PositionKeyNotSupported =
74 PyErr_NewException( "vlc.PositionKeyNotSupported", NULL, NULL );
75 Py_INCREF( MediaControl_PositionKeyNotSupported );
76 PyModule_AddObject( p_module, "PositionKeyNotSupported",
77 MediaControl_PositionKeyNotSupported );
79 MediaControl_PositionOriginNotSupported=
80 PyErr_NewException( "vlc.InvalidPosition", NULL, NULL );
81 Py_INCREF( MediaControl_PositionOriginNotSupported );
82 PyModule_AddObject( p_module, "PositionOriginNotSupported",
83 MediaControl_PositionOriginNotSupported );
85 MediaControl_InvalidPosition =
86 PyErr_NewException( "vlc.InvalidPosition", NULL, NULL );
87 Py_INCREF( MediaControl_InvalidPosition );
88 PyModule_AddObject( p_module, "InvalidPosition",
89 MediaControl_InvalidPosition );
91 MediaControl_PlaylistException =
92 PyErr_NewException( "vlc.PlaylistException", NULL, NULL );
93 Py_INCREF( MediaControl_PlaylistException );
94 PyModule_AddObject( p_module, "PlaylistException",
95 MediaControl_PlaylistException );
98 Py_INCREF( &PyPosition_Type );
99 PyModule_AddObject( p_module, "Position",
100 ( PyObject * )&PyPosition_Type );
102 Py_INCREF( &MediaControl_Type );
103 PyModule_AddObject( p_module, "MediaControl",
104 ( PyObject * )&MediaControl_Type );
106 Py_INCREF( &vlcObject_Type );
107 PyModule_AddObject( p_module, "Object",
108 ( PyObject * )&vlcObject_Type );
111 PyModule_AddIntConstant( p_module, "AbsolutePosition",
112 mediacontrol_AbsolutePosition );
113 PyModule_AddIntConstant( p_module, "RelativePosition",
114 mediacontrol_RelativePosition );
115 PyModule_AddIntConstant( p_module, "ModuloPosition",
116 mediacontrol_ModuloPosition );
118 PyModule_AddIntConstant( p_module, "ByteCount",
119 mediacontrol_ByteCount );
120 PyModule_AddIntConstant( p_module, "SampleCount",
121 mediacontrol_SampleCount );
122 PyModule_AddIntConstant( p_module, "MediaTime",
123 mediacontrol_MediaTime );
124 PyModule_AddIntConstant( p_module, "PlayingStatus",
125 mediacontrol_PlayingStatus );
126 PyModule_AddIntConstant( p_module, "PauseStatus",
127 mediacontrol_PauseStatus );
128 PyModule_AddIntConstant( p_module, "ForwardStatus",
129 mediacontrol_ForwardStatus );
130 PyModule_AddIntConstant( p_module, "BackwardStatus",
131 mediacontrol_BackwardStatus );
132 PyModule_AddIntConstant( p_module, "InitStatus",
133 mediacontrol_InitStatus );
134 PyModule_AddIntConstant( p_module, "EndStatus",
135 mediacontrol_EndStatus );
136 PyModule_AddIntConstant( p_module, "UndefinedStatus",
137 mediacontrol_UndefinedStatus );
141 /* Make libpostproc happy... */
142 void * fast_memcpy( void * to, const void * from, size_t len )
144 return memcpy( to, from, len );
148 /*****************************************************************************
149 * VLCObject implementation
150 *****************************************************************************/
153 *vlcObject_new( PyTypeObject *p_type, PyObject *p_args, PyObject *p_kwds )
156 vlc_object_t *p_object;
159 self = PyObject_New( vlcObject, &vlcObject_Type );
161 if( !PyArg_ParseTuple( p_args, "i", &i_id ) )
164 /* Maybe we were already initialized */
165 p_object = ( vlc_object_t* )vlc_current_object( i_id );
169 /* Try to initialize */
171 p_object = ( vlc_object_t* )vlc_current_object( i_id );
176 PyErr_SetString( PyExc_StandardError, "Unable to get object." );
180 self->p_object = p_object;
181 self->b_released = 0;
183 Py_INCREF( self ); /* Ah bon ? */
184 return ( PyObject * )self;
188 vlcObject_release( PyObject *self, PyObject *p_args )
190 if( VLCSELF->b_released == 0 )
192 vlc_object_release( VLCSELF->p_object );
193 VLCSELF->b_released = 1;
195 Py_INCREF( Py_None );
200 vlcObject_dealloc( PyObject *self )
202 vlcObject_release( self, NULL );
207 vlcObject_find_object( PyObject *self, PyObject *args )
214 if( !PyArg_ParseTuple( args, "s", &psz_name ) )
218 ( aout, decoder, input, httpd, intf, playlist, root, vlc, vout )
220 switch ( psz_name[0] )
223 i_object_type = VLC_OBJECT_AOUT;
226 i_object_type = VLC_OBJECT_DECODER;
229 i_object_type = VLC_OBJECT_HTTPD;
232 if( strlen( psz_name ) < 3 )
233 i_object_type = VLC_OBJECT_INTF;
234 else if( psz_name[2] == 't' )
235 i_object_type = VLC_OBJECT_INTF;
237 i_object_type = VLC_OBJECT_INPUT;
240 i_object_type = VLC_OBJECT_PLAYLIST;
243 i_object_type = VLC_OBJECT_ROOT;
246 if( strlen( psz_name ) < 3 )
247 i_object_type = VLC_OBJECT_VLC;
248 else if( psz_name[1] == 'l' )
249 i_object_type = VLC_OBJECT_VLC;
251 i_object_type = VLC_OBJECT_VOUT;
254 /* FIXME: raise an exception ? */
258 p_obj = vlc_object_find( VLCSELF->p_object, i_object_type, FIND_ANYWHERE );
262 Py_INCREF( Py_None );
266 p_retval = PyObject_New( vlcObject, &vlcObject_Type );
268 p_retval->p_object = p_obj;
270 return ( PyObject * )p_retval;
274 vlcObject_info( PyObject *self, PyObject *args )
279 p_obj = VLCSELF->p_object;
281 /* Return information about the object as a dict. */
282 p_retval = PyDict_New();
284 PyDict_SetItemString( p_retval, "object-id",
285 Py_BuildValue( "l", p_obj->i_object_id ) );
286 PyDict_SetItemString( p_retval, "object-type",
287 Py_BuildValue( "s", p_obj->psz_object_type ) );
288 PyDict_SetItemString( p_retval, "object-name",
289 Py_BuildValue( "s", p_obj->psz_object_name ) );
290 PyDict_SetItemString( p_retval, "thread",
291 PyBool_FromLong( p_obj->b_thread ) );
292 PyDict_SetItemString( p_retval, "thread-id",
293 PyLong_FromLongLong( p_obj->thread_id ) );
294 PyDict_SetItemString( p_retval, "refcount",
295 PyInt_FromLong( p_obj->i_refcount ) );
301 vlcObject_find_id( PyObject *self, PyObject *args )
304 vlc_object_t* p_object;
307 if( !PyArg_ParseTuple( args, "i", &i_id ) )
310 p_object = ( vlc_object_t* )vlc_current_object( i_id );
314 Py_INCREF( Py_None );
318 p_retval = PyObject_NEW( vlcObject, &vlcObject_Type );
320 p_retval->p_object = p_object;
322 return ( PyObject * )p_retval;
325 /* Do a var_Get call on the object. Parameter: the variable name. */
327 vlcObject_var_get( PyObject *self, PyObject *args )
334 if( !PyArg_ParseTuple( args, "s", &psz_name ) )
337 if( var_Get( VLCSELF->p_object, psz_name, &value ) != VLC_SUCCESS )
339 PyErr_SetString( PyExc_StandardError,
340 "Error: variable does not exist.\n" );
344 i_type = var_Type ( VLCSELF->p_object, psz_name );
349 p_retval = PyString_FromString( "A void variable" );
352 p_retval = PyBool_FromLong( value.b_bool );
354 case VLC_VAR_INTEGER :
355 p_retval = PyInt_FromLong( ( long )value.i_int );
357 case VLC_VAR_HOTKEY :
358 p_retval = PyString_FromFormat( "A hotkey variable ( %d )", value.i_int );
361 case VLC_VAR_STRING :
362 case VLC_VAR_DIRECTORY :
363 case VLC_VAR_VARIABLE :
364 p_retval = PyString_FromString( value.psz_string );
366 case VLC_VAR_MODULE :
367 p_retval = ( PyObject* )PyObject_New( vlcObject, &vlcObject_Type );
368 ( ( vlcObject* )p_retval )->p_object = value.p_object;
371 p_retval = PyFloat_FromDouble( ( double )value.f_float );
374 p_retval = PyLong_FromLongLong( value.i_time );
376 case VLC_VAR_ADDRESS :
377 p_retval = PyString_FromString( "A VLC address ( not handled yet )" );
380 p_retval = PyString_FromString( "A VLC list ( not handled yet )" );
383 p_retval = PyString_FromString( "A mutex" );
389 Py_INCREF( p_retval );
394 vlcObject_var_type( PyObject *self, PyObject *args )
400 if( !PyArg_ParseTuple( args, "s", &psz_name ) )
403 i_type = var_Type( VLCSELF->p_object, psz_name );
408 p_retval = PyString_FromString( "Void" );
411 p_retval = PyString_FromString( "Boolean" );
413 case VLC_VAR_INTEGER :
414 p_retval = PyString_FromString( "Integer" );
416 case VLC_VAR_HOTKEY :
417 p_retval = PyString_FromString( "Hotkey" );
420 p_retval = PyString_FromString( "File" );
422 case VLC_VAR_STRING :
423 p_retval = PyString_FromString( "String" );
425 case VLC_VAR_DIRECTORY :
426 p_retval = PyString_FromString( "Directory" );
428 case VLC_VAR_VARIABLE :
429 p_retval = PyString_FromString( "Variable" );
431 case VLC_VAR_MODULE :
432 p_retval = PyString_FromString( "Module" );
435 p_retval = PyString_FromString( "Float" );
438 p_retval = PyString_FromString( "Time" );
440 case VLC_VAR_ADDRESS :
441 p_retval = PyString_FromString( "Address" );
444 p_retval = PyString_FromString( "List" );
447 p_retval = PyString_FromString( "Mutex" );
450 p_retval = PyString_FromString( "Unknown" );
455 /* Do a var_Set call on the object. Parameter: the variable name. */
457 vlcObject_var_set( PyObject *self, PyObject *args )
465 if( !PyArg_ParseTuple( args, "sO", &psz_name, &py_value ) )
468 p_obj = VLCSELF->p_object;
469 i_type = var_Type( p_obj, psz_name );
476 value.b_bool = PyInt_AsLong( py_value );
478 case VLC_VAR_INTEGER :
479 case VLC_VAR_HOTKEY :
480 value.i_int = PyInt_AsLong( py_value );
483 case VLC_VAR_STRING :
484 case VLC_VAR_DIRECTORY :
485 case VLC_VAR_VARIABLE :
486 value.psz_string = strdup( PyString_AsString( py_value ) );
488 case VLC_VAR_MODULE :
489 /* FIXME: we should check the PyObject type and get its p_object */
490 value.p_object = ( ( vlcObject* )p_obj )->p_object;
493 value.f_float = PyFloat_AsDouble( py_value );
496 value.i_time = PyLong_AsLongLong( py_value );
498 case VLC_VAR_ADDRESS :
499 value.p_address = ( char* )PyLong_AsVoidPtr( py_value );
509 var_Set( p_obj, psz_name, value );
511 Py_INCREF( Py_None );
516 vlcObject_var_list( PyObject *self, PyObject *args )
522 i_size = VLCSELF->p_object->i_vars;
523 p_retval = PyTuple_New( i_size );
525 for ( i_index = 0 ; i_index < i_size ; i_index++ )
527 PyTuple_SetItem( p_retval, i_index,
528 Py_BuildValue( "s", VLCSELF->p_object->p_vars[i_index].psz_name ) );
534 /* Do a config_Get call on the object. Parameter: the variable name. */
536 vlcObject_config_get( PyObject *self, PyObject *args )
541 module_config_t *p_config;
543 if( !PyArg_ParseTuple( args, "s", &psz_name ) )
546 p_config = config_FindConfig( VLCSELF->p_object, psz_name );
550 PyErr_SetString( PyExc_StandardError,
551 "Error: config variable does not exist.\n" );
555 switch ( p_config->i_type )
557 case CONFIG_ITEM_BOOL :
558 p_retval = PyBool_FromLong( p_config->i_value );
560 case CONFIG_ITEM_INTEGER :
561 p_retval = PyInt_FromLong( ( long )p_config->i_value );
563 case CONFIG_ITEM_KEY :
564 p_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 p_retval = PyString_FromString( p_config->psz_value );
574 p_retval = PyString_FromString( "" );
575 vlc_mutex_unlock( p_config->p_lock );
577 p_retval = ( PyObject* )PyObject_New( vlcObject, &vlcObject_Type );
578 ( ( vlcObject* )p_retval )->p_object = value.p_object;
580 case CONFIG_ITEM_FLOAT :
581 p_retval = PyFloat_FromDouble( ( double )p_config->f_value );
585 Py_INCREF( p_retval );
591 /* Do a config_put* call on the object. Parameter: the variable name. */
593 vlcObject_config_set( PyObject *self, PyObject *args )
598 module_config_t *p_config;
601 if( !PyArg_ParseTuple( args, "sO", &psz_name, &py_value ) )
604 p_obj = VLCSELF->p_object;
605 p_config = config_FindConfig( p_obj, psz_name );
609 PyErr_SetString( PyExc_StandardError,
610 "Error: option does not exist.\n" );
614 switch ( p_config->i_type )
616 case CONFIG_ITEM_BOOL :
617 case CONFIG_ITEM_INTEGER :
618 case CONFIG_ITEM_KEY :
619 config_PutInt( p_obj, psz_name, PyInt_AsLong( py_value ) );
621 case CONFIG_ITEM_FILE :
622 case CONFIG_ITEM_STRING :
623 case CONFIG_ITEM_DIRECTORY :
624 case CONFIG_ITEM_MODULE :
625 config_PutPsz( p_obj, psz_name, PyString_AsString( py_value ) );
627 case CONFIG_ITEM_FLOAT :
628 config_PutFloat( p_obj, psz_name, PyFloat_AsDouble( py_value ) );
631 Py_INCREF( Py_None );
636 vlcObject_children( PyObject *self, PyObject *args )
642 i_size = VLCSELF->p_object->i_children;
643 p_retval = PyTuple_New( i_size );
645 for ( i_index = 0 ; i_index < i_size ; i_index++ )
647 PyTuple_SetItem( p_retval, i_index,
649 VLCSELF->p_object->pp_children[i_index]->i_object_id ) );
657 static PyMethodDef vlcObject_methods[] =
659 { "get", vlcObject_var_get, METH_VARARGS,
660 "get( str ) -> value Get a variable value."},
661 { "set", vlcObject_var_set, METH_VARARGS,
662 "set( str, value ) Set a variable value" },
663 { "config_get", vlcObject_config_get, METH_VARARGS,
664 "config_get( str ) -> value Get a configuration option." },
665 { "config_set", vlcObject_config_set, METH_VARARGS,
666 "config_set( str, value ) Set a configuration option" },
667 { "type", vlcObject_var_type, METH_VARARGS,
668 "type( str ) -> str Get a variable type" },
669 { "list", vlcObject_var_list, METH_NOARGS,
670 "list( ) List the available variables" },
671 { "children", vlcObject_children, METH_NOARGS,
672 "children( ) List the children ids" },
673 { "find_object", vlcObject_find_object, METH_VARARGS,
674 "find_object( str ) -> Object Find the object of a given type.\n\nAvailable types are : aout, decoder, input, httpd, intf, playlist, root, vlc, vout"},
675 { "find_id", vlcObject_find_id, METH_VARARGS,
676 "find_id( int ) -> Object Find an object by id" },
677 { "info", vlcObject_info, METH_NOARGS,
678 "info( ) -> dict Return information about the object" },
679 { "release", vlcObject_release, METH_NOARGS,
680 "release( ) -> Release the VLC Object" },
681 { NULL, NULL, 0, NULL },
684 static PyTypeObject vlcObject_Type =
686 PyObject_HEAD_INIT( NULL )
688 "vlc.Object", /*tp_name*/
689 sizeof( vlcObject_Type ), /*tp_basicsize*/
691 ( destructor )vlcObject_dealloc, /*tp_dealloc*/
698 0, /*tp_as_sequence*/
706 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
707 "Expose VLC object infrastructure.", /* tp_doc */
710 0, /* tp_richcompare */
711 0, /* tp_weaklistoffset */
714 vlcObject_methods, /* tp_methods */
719 0, /* tp_descr_get */
720 0, /* tp_descr_set */
721 0, /* tp_dictoffset */
724 vlcObject_new, /* tp_new */
727 /*****************************************************************************
728 * VLC MediaControl object implementation
729 *****************************************************************************/
732 MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
735 mediacontrol_Exception *exception = NULL;
736 PyObject* py_list = NULL;
737 char** ppsz_args = NULL;
739 self = PyObject_New( MediaControl, &MediaControl_Type );
741 if( PyArg_ParseTuple( args, "O", &py_list ) )
746 Py_INCREF( py_list );
747 if( ! PySequence_Check( py_list ) )
749 PyErr_SetString( PyExc_TypeError, "Parameter must be a sequence." );
752 i_size = PySequence_Size( py_list );
753 ppsz_args = malloc( i_size + 1 );
756 PyErr_SetString( PyExc_MemoryError, "Out of memory" );
760 for ( i_index = 0; i_index < i_size; i_index++ )
763 strdup( PyString_AsString( PyObject_Str(
764 PySequence_GetItem( py_list,
767 ppsz_args[i_size] = NULL;
768 Py_DECREF( py_list );
772 /* No arguments were given. Clear the exception raised
773 by PyArg_ParseTuple. */
777 Py_BEGIN_ALLOW_THREADS
779 self->mc = mediacontrol_new( ppsz_args, exception );
784 return ( PyObject * )self;
788 MediaControl_dealloc( PyObject *self )
794 * Return the current position in the stream. The returned value can
795 be relative or absolute ( according to PositionOrigin ) and the unit
796 is set by PositionKey
799 MediaControl_get_media_position( PyObject *self, PyObject *args )
801 mediacontrol_Position* pos;
802 mediacontrol_Exception* exception = NULL;
806 mediacontrol_PositionOrigin origin;
807 mediacontrol_PositionKey key;
809 if( !PyArg_ParseTuple( args, "OO", &py_origin, &py_key ) )
812 origin = positionOrigin_py_to_c( py_origin );
813 key = positionKey_py_to_c( py_key );
815 Py_BEGIN_ALLOW_THREADS
817 pos = mediacontrol_get_media_position( SELF->mc, origin, key, exception );
821 py_retval = ( PyObject* )position_c_to_py( pos );
826 /** Set the media position */
828 MediaControl_set_media_position( PyObject *self, PyObject *args )
830 mediacontrol_Exception* exception = NULL;
831 mediacontrol_Position *a_position;
834 if( !PyArg_ParseTuple( args, "O", &py_pos ) )
837 a_position = position_py_to_c( py_pos );
840 PyErr_SetString( PyExc_MemoryError, "Out of memory" );
844 Py_BEGIN_ALLOW_THREADS
846 mediacontrol_set_media_position( SELF->mc, a_position, exception );
851 Py_INCREF( Py_None );
856 MediaControl_start( PyObject *self, PyObject *args )
858 mediacontrol_Position *a_position;
859 mediacontrol_Exception *exception = NULL;
862 if( !PyArg_ParseTuple( args, "O", &py_pos ) )
864 /* No argument. Use a default 0 value. */
868 a_position = position_py_to_c( py_pos );
872 Py_BEGIN_ALLOW_THREADS
874 mediacontrol_start( SELF->mc, a_position, exception );
879 Py_INCREF( Py_None );
884 MediaControl_pause( PyObject *self, PyObject *args )
886 mediacontrol_Position *a_position;
887 mediacontrol_Exception *exception = NULL;
890 if( !PyArg_ParseTuple( args, "O", &py_pos ) )
892 /* No argument. Use a default 0 value. */
896 a_position = position_py_to_c( py_pos );
900 Py_BEGIN_ALLOW_THREADS
902 mediacontrol_pause( SELF->mc, a_position, exception );
907 Py_INCREF( Py_None );
912 MediaControl_resume( PyObject *self, PyObject *args )
914 mediacontrol_Position *a_position;
915 mediacontrol_Exception *exception = NULL;
918 if( !PyArg_ParseTuple( args, "O", &py_pos ) )
920 /* No argument. Use a default 0 value. */
924 a_position = position_py_to_c( py_pos );
928 Py_BEGIN_ALLOW_THREADS
930 mediacontrol_start( SELF->mc, a_position, exception );
935 Py_INCREF( Py_None );
940 MediaControl_stop( PyObject *self, PyObject *args )
942 mediacontrol_Position *a_position;
943 mediacontrol_Exception *exception = NULL;
946 if( !PyArg_ParseTuple( args, "O", &py_pos ) )
948 /* No argument. Use a default 0 value. */
952 a_position = position_py_to_c( py_pos );
956 Py_BEGIN_ALLOW_THREADS
958 mediacontrol_stop( SELF->mc, a_position, exception );
963 Py_INCREF( Py_None );
968 MediaControl_exit( PyObject *self, PyObject *args )
970 mediacontrol_exit( SELF->mc );
971 Py_INCREF( Py_None );
976 MediaControl_playlist_add_item( PyObject *self, PyObject *args )
979 mediacontrol_Exception *exception = NULL;
981 if( !PyArg_ParseTuple( args, "s", &psz_file ) )
984 Py_BEGIN_ALLOW_THREADS
986 mediacontrol_playlist_add_item( SELF->mc, psz_file, exception );
990 Py_INCREF( Py_None );
995 MediaControl_playlist_clear( PyObject *self, PyObject *args )
997 mediacontrol_Exception *exception = NULL;
999 Py_BEGIN_ALLOW_THREADS
1001 mediacontrol_playlist_clear( SELF->mc, exception );
1002 Py_END_ALLOW_THREADS
1005 Py_INCREF( Py_None );
1010 MediaControl_playlist_get_list( PyObject *self, PyObject *args )
1012 PyObject *py_retval;
1013 mediacontrol_Exception *exception = NULL;
1014 mediacontrol_PlaylistSeq* pl;
1016 int i_playlist_size;
1018 Py_BEGIN_ALLOW_THREADS
1020 pl = mediacontrol_playlist_get_list( SELF->mc, exception );
1021 Py_END_ALLOW_THREADS
1024 i_playlist_size = pl->size;
1026 py_retval = PyList_New( i_playlist_size );
1028 for ( i_index = 0 ; i_index < i_playlist_size ; i_index++ )
1030 PyList_SetItem( py_retval, i_index,
1031 Py_BuildValue( "s", pl->data[i_index] ) );
1033 mediacontrol_PlaylistSeq__free( pl );
1040 MediaControl_snapshot( PyObject *self, PyObject *args )
1042 mediacontrol_RGBPicture *p_retval = NULL;
1043 mediacontrol_Exception* exception = NULL;
1044 mediacontrol_Position *a_position = NULL;
1045 PyObject *py_pos = NULL;
1046 PyObject *py_obj = NULL;
1048 if( !PyArg_ParseTuple( args, "O", &py_pos ) )
1051 a_position = position_py_to_c( py_pos );
1053 Py_BEGIN_ALLOW_THREADS
1055 p_retval = mediacontrol_snapshot( SELF->mc, a_position, exception );
1057 Py_END_ALLOW_THREADS
1062 Py_INCREF( Py_None );
1066 /* FIXME: create a real RGBPicture object */
1067 py_obj = PyDict_New();
1069 PyDict_SetItemString( py_obj, "width",
1070 Py_BuildValue( "i", p_retval->width ) );
1071 PyDict_SetItemString( py_obj, "height",
1072 Py_BuildValue( "i", p_retval->height ) );
1073 PyDict_SetItemString( py_obj, "type",
1074 Py_BuildValue( "i", p_retval->type ) );
1075 PyDict_SetItemString( py_obj, "data",
1076 Py_BuildValue( "s#", p_retval->data, p_retval->size ) );
1082 MediaControl_display_text( PyObject *self, PyObject *args )
1084 mediacontrol_Exception* exception = NULL;
1085 PyObject *py_begin, *py_end;
1087 mediacontrol_Position * begin;
1088 mediacontrol_Position * end;
1090 if( !PyArg_ParseTuple( args, "sOO", &message, &py_begin, &py_end ) )
1093 begin = position_py_to_c( py_begin );
1094 end = position_py_to_c( py_end );
1096 Py_BEGIN_ALLOW_THREADS
1098 mediacontrol_display_text( SELF->mc, message, begin, end, exception );
1099 Py_END_ALLOW_THREADS
1105 Py_INCREF( Py_None );
1110 MediaControl_get_stream_information( PyObject *self, PyObject *args )
1112 mediacontrol_StreamInformation *retval = NULL;
1113 mediacontrol_Exception* exception = NULL;
1116 Py_BEGIN_ALLOW_THREADS
1118 retval = mediacontrol_get_stream_information(
1119 SELF->mc, mediacontrol_MediaTime, exception );
1120 Py_END_ALLOW_THREADS
1123 py_obj = PyDict_New( );
1125 /* FIXME: create a real StreamInformation object */
1126 PyDict_SetItemString( py_obj, "status",
1127 Py_BuildValue( "i", retval->streamstatus ) );
1128 PyDict_SetItemString( py_obj, "url",
1129 Py_BuildValue( "s", retval->url ) );
1130 PyDict_SetItemString( py_obj, "position",
1131 Py_BuildValue( "L", retval->position ) );
1132 PyDict_SetItemString( py_obj, "length",
1133 Py_BuildValue( "L", retval->length ) );
1135 free( retval->url );
1142 MediaControl_sound_set_volume( PyObject *self, PyObject *args )
1144 mediacontrol_Exception* exception = NULL;
1145 unsigned short volume;
1147 if( !PyArg_ParseTuple( args, "H", &volume ) )
1150 Py_BEGIN_ALLOW_THREADS
1152 mediacontrol_sound_set_volume( SELF->mc, volume, exception );
1153 Py_END_ALLOW_THREADS
1156 Py_INCREF( Py_None );
1161 MediaControl_sound_get_volume( PyObject *self, PyObject *args )
1163 mediacontrol_Exception* exception = NULL;
1164 PyObject *py_retval;
1165 unsigned short volume;
1167 Py_BEGIN_ALLOW_THREADS
1169 volume = mediacontrol_sound_get_volume( SELF->mc, exception );
1170 Py_END_ALLOW_THREADS
1173 py_retval = Py_BuildValue( "H", volume );
1178 MediaControl_set_visual( PyObject *self, PyObject *args )
1180 mediacontrol_Exception* exception = NULL;
1181 WINDOWHANDLE visual;
1183 if( !PyArg_ParseTuple( args, "i", &visual ) )
1186 Py_BEGIN_ALLOW_THREADS
1188 mediacontrol_set_visual( SELF->mc, visual, exception );
1189 Py_END_ALLOW_THREADS
1192 Py_INCREF( Py_None );
1196 static PyMethodDef MediaControl_methods[] =
1198 {"get_media_position", MediaControl_get_media_position, METH_VARARGS,
1199 "get_media_position( origin, key ) -> Position Get current media position." },
1200 { "set_media_position", MediaControl_set_media_position, METH_VARARGS,
1201 "set_media_position( Position ) Set media position" },
1202 { "start", MediaControl_start, METH_VARARGS,
1203 "start( Position ) Start the player." },
1204 { "pause", MediaControl_pause, METH_VARARGS,
1205 "pause( Position ) Pause the player." },
1206 { "resume", MediaControl_resume, METH_VARARGS,
1207 "resume( Position ) Resume the player" },
1208 { "stop", MediaControl_stop, METH_VARARGS,
1209 "stop( Position ) Stop the player" },
1210 { "exit", MediaControl_exit, METH_VARARGS,
1211 "exit( ) Exit the player" },
1212 { "playlist_add_item", MediaControl_playlist_add_item, METH_VARARGS,
1213 "playlist_add_item( str ) Add an item to the playlist" },
1214 { "playlist_get_list", MediaControl_playlist_get_list, METH_VARARGS,
1215 "playlist_get_list( ) -> list Get the contents of the playlist" },
1216 { "playlist_clear", MediaControl_playlist_clear, METH_VARARGS,
1217 "clear( ) Clear the playlist." },
1218 { "snapshot", MediaControl_snapshot, METH_VARARGS,
1219 "snapshot( Position ) -> dict Take a snapshot" },
1220 { "display_text", MediaControl_display_text, METH_VARARGS,
1221 "display_text( str, Position, Position ) Display a text on the video" },
1222 { "get_stream_information", MediaControl_get_stream_information,
1224 "get_stream_information( ) -> dict Get information about the stream"},
1225 { "sound_get_volume", MediaControl_sound_get_volume, METH_VARARGS,
1226 "sound_get_volume( ) -> int Get the volume" },
1227 { "sound_set_volume", MediaControl_sound_set_volume, METH_VARARGS,
1228 "sound_set_volume( int ) Set the volume" },
1229 { "set_visual", MediaControl_set_visual, METH_VARARGS,
1230 "set_visual( int ) Set the embedding window visual ID" },
1231 { NULL, NULL, 0, NULL },
1234 static PyTypeObject MediaControl_Type =
1236 PyObject_HEAD_INIT( NULL )
1238 "vlc.MediaControl", /*tp_name*/
1239 sizeof( MediaControl_Type ), /*tp_basicsize*/
1241 ( destructor )MediaControl_dealloc, /*tp_dealloc*/
1248 0, /*tp_as_sequence*/
1249 0, /*tp_as_mapping*/
1256 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
1257 "Control of a VLC instance.", /* tp_doc */
1258 0, /* tp_traverse */
1260 0, /* tp_richcompare */
1261 0, /* tp_weaklistoffset */
1263 0, /* tp_iternext */
1264 MediaControl_methods, /* tp_methods */
1269 0, /* tp_descr_get */
1270 0, /* tp_descr_set */
1271 0, /* tp_dictoffset */
1274 MediaControl_new, /* tp_new */
1277 /***********************************************************************
1279 ***********************************************************************/
1283 PyPosition_init( PyPosition *self, PyObject *args, PyObject *kwds )
1285 self->origin = mediacontrol_AbsolutePosition;
1286 self->key = mediacontrol_MediaTime;
1291 mediacontrol_PositionKey
1292 positionKey_py_to_c( PyObject * py_key )
1294 mediacontrol_PositionKey key_position = mediacontrol_MediaTime;
1297 if( !PyArg_Parse( py_key, "i", &key ) )
1299 PyErr_SetString ( MediaControl_InternalException, "Invalid key value" );
1300 return key_position;
1305 case 0: key = mediacontrol_ByteCount; break;
1306 case 1: key = mediacontrol_SampleCount; break;
1307 case 2: key = mediacontrol_MediaTime; break;
1309 return key_position;
1312 mediacontrol_PositionOrigin
1313 positionOrigin_py_to_c( PyObject * py_origin )
1315 mediacontrol_PositionOrigin origin_position = mediacontrol_AbsolutePosition;
1318 if( !PyArg_Parse( py_origin,"i", &origin ) )
1320 PyErr_SetString( MediaControl_InternalException,
1321 "Invalid origin value" );
1322 return origin_position;
1327 case 0: origin_position = mediacontrol_AbsolutePosition; break;
1328 case 1: origin_position = mediacontrol_RelativePosition; break;
1329 case 2: origin_position = mediacontrol_ModuloPosition; break;
1332 return origin_position;
1335 /* Methods for transforming the Position Python object to Position structure*/
1336 mediacontrol_Position*
1337 position_py_to_c( PyObject * py_position )
1339 mediacontrol_Position * a_position = NULL;
1340 PyPosition *pos = ( PyPosition* )py_position;
1342 a_position = ( mediacontrol_Position* )malloc( sizeof( mediacontrol_Position ) );
1345 PyErr_SetString( PyExc_MemoryError, "Out of memory" );
1351 /* If we give a NULL value, it will be considered as
1352 a 0 relative position in mediatime */
1353 a_position->origin = mediacontrol_RelativePosition;
1354 a_position->key = mediacontrol_MediaTime;
1355 a_position->value = 0;
1357 else if( PyObject_IsInstance( py_position, ( PyObject* )&PyPosition_Type ) )
1359 a_position->origin = pos->origin;
1360 a_position->key = pos->key;
1361 a_position->value = pos->value;
1365 /* Feature: if we give an integer, it will be considered as
1366 a relative position in mediatime */
1367 a_position->origin = mediacontrol_RelativePosition;
1368 a_position->key = mediacontrol_MediaTime;
1369 a_position->value = PyLong_AsLongLong( py_position );
1375 position_c_to_py( mediacontrol_Position *position )
1377 PyPosition* py_retval;
1379 py_retval = PyObject_New( PyPosition, &PyPosition_Type );
1380 py_retval->origin = position->origin;
1381 py_retval->key = position->key;
1382 py_retval->value = position->value;
1387 static PyMethodDef PyPosition_methods[] =
1389 { NULL } /* Sentinel */
1392 static PyMemberDef PyPosition_members[] =
1394 { "origin", T_INT, offsetof( PyPosition, origin ), 0, "Position origin" },
1395 { "key", T_INT, offsetof( PyPosition, key ), 0, "Position key" },
1396 { "value", T_ULONG, offsetof( PyPosition, value ), 0, "Position value" },
1397 { NULL } /* Sentinel */
1400 static PyTypeObject PyPosition_Type =
1402 PyObject_HEAD_INIT( NULL )
1404 "vlc.Position", /*tp_name*/
1405 sizeof( PyPosition_Type ), /*tp_basicsize*/
1414 0, /*tp_as_sequence*/
1415 0, /*tp_as_mapping*/
1422 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
1423 "Represent a Position with origin, key and value", /* tp_doc */
1424 0, /* tp_traverse */
1426 0, /* tp_richcompare */
1427 0, /* tp_weaklistoffset */
1429 0, /* tp_iternext */
1430 PyPosition_methods, /* tp_methods */
1431 PyPosition_members, /* tp_members */
1435 0, /* tp_descr_get */
1436 0, /* tp_descr_set */
1437 0, /* tp_dictoffset */
1438 ( initproc )PyPosition_init, /* tp_init */