📄 vlcglue.c
字号:
case VLC_VAR_LIST : p_retval = PyString_FromString( "A VLC list ( not handled yet )" ); break; case VLC_VAR_MUTEX : p_retval = PyString_FromString( "A mutex" ); break; default: p_retval = Py_None; } Py_INCREF( p_retval ); return p_retval;}static PyObject *vlcObject_var_type( PyObject *self, PyObject *args ){ char *psz_name; PyObject *p_retval; int i_type; if( !PyArg_ParseTuple( args, "s", &psz_name ) ) return NULL; i_type = var_Type( VLCSELF->p_object, psz_name ); switch ( i_type ) { case VLC_VAR_VOID : p_retval = PyString_FromString( "Void" ); break; case VLC_VAR_BOOL : p_retval = PyString_FromString( "Boolean" ); break; case VLC_VAR_INTEGER : p_retval = PyString_FromString( "Integer" ); break; case VLC_VAR_HOTKEY : p_retval = PyString_FromString( "Hotkey" ); break; case VLC_VAR_FILE : p_retval = PyString_FromString( "File" ); break; case VLC_VAR_STRING : p_retval = PyString_FromString( "String" ); break; case VLC_VAR_DIRECTORY : p_retval = PyString_FromString( "Directory" ); break; case VLC_VAR_VARIABLE : p_retval = PyString_FromString( "Variable" ); break; case VLC_VAR_MODULE : p_retval = PyString_FromString( "Module" ); break; case VLC_VAR_FLOAT : p_retval = PyString_FromString( "Float" ); break; case VLC_VAR_TIME : p_retval = PyString_FromString( "Time" ); break; case VLC_VAR_ADDRESS : p_retval = PyString_FromString( "Address" ); break; case VLC_VAR_LIST : p_retval = PyString_FromString( "List" ); break; case VLC_VAR_MUTEX : p_retval = PyString_FromString( "Mutex" ); break; default: p_retval = PyString_FromString( "Unknown" ); } return p_retval;}/* Do a var_Set call on the object. Parameter: the variable name. */static PyObject *vlcObject_var_set( PyObject *self, PyObject *args ){ vlc_value_t value; char *psz_name; PyObject *py_value; int i_type; vlc_object_t *p_obj; if( !PyArg_ParseTuple( args, "sO", &psz_name, &py_value ) ) return NULL; p_obj = VLCSELF->p_object; i_type = var_Type( p_obj, psz_name ); switch ( i_type ) { case VLC_VAR_VOID : break; case VLC_VAR_BOOL : value.b_bool = PyInt_AsLong( py_value ); break; case VLC_VAR_INTEGER : case VLC_VAR_HOTKEY : value.i_int = PyInt_AsLong( py_value ); break; case VLC_VAR_FILE : case VLC_VAR_STRING : case VLC_VAR_DIRECTORY : case VLC_VAR_VARIABLE : value.psz_string = strdup( PyString_AsString( py_value ) ); break; case VLC_VAR_MODULE : /* FIXME: we should check the PyObject type and get its p_object */ value.p_object = ( ( vlcObject* )p_obj )->p_object; break; case VLC_VAR_FLOAT : value.f_float = PyFloat_AsDouble( py_value ); break; case VLC_VAR_TIME : value.i_time = PyLong_AsLongLong( py_value ); break; case VLC_VAR_ADDRESS : value.p_address = ( char* )PyLong_AsVoidPtr( py_value ); break; case VLC_VAR_LIST : /* FIXME */ value.p_list = NULL; break; case VLC_VAR_MUTEX : break; } var_Set( p_obj, psz_name, value ); Py_INCREF( Py_None ); return Py_None;}static PyObject *vlcObject_var_list( PyObject *self, PyObject *args ){ PyObject *p_retval; int i_size; int i_index; i_size = VLCSELF->p_object->i_vars; p_retval = PyTuple_New( i_size ); for ( i_index = 0 ; i_index < i_size ; i_index++ ) { PyTuple_SetItem( p_retval, i_index, Py_BuildValue( "s", VLCSELF->p_object->p_vars[i_index].psz_name ) ); } return p_retval;}/* Do a config_Get call on the object. Parameter: the variable name. */static PyObject *vlcObject_config_get( PyObject *self, PyObject *args ){ PyObject *p_retval; vlc_value_t value; char *psz_name; module_config_t *p_config; if( !PyArg_ParseTuple( args, "s", &psz_name ) ) return NULL; p_config = config_FindConfig( VLCSELF->p_object, psz_name ); if( !p_config ) { PyErr_SetString( PyExc_StandardError, "Error: config variable does not exist.\n" ); return NULL; } switch ( p_config->i_type ) { case CONFIG_ITEM_BOOL : p_retval = PyBool_FromLong( p_config->i_value ); break; case CONFIG_ITEM_INTEGER : p_retval = PyInt_FromLong( ( long )p_config->i_value ); break; case CONFIG_ITEM_KEY : p_retval = PyString_FromFormat( "A hotkey variable ( %d )", p_config->i_value ); break; case CONFIG_ITEM_FILE : case CONFIG_ITEM_STRING : case CONFIG_ITEM_DIRECTORY : case CONFIG_ITEM_MODULE : vlc_mutex_lock( p_config->p_lock ); if( p_config->psz_value ) p_retval = PyString_FromString( p_config->psz_value ); else p_retval = PyString_FromString( "" ); vlc_mutex_unlock( p_config->p_lock ); break; p_retval = ( PyObject* )PyObject_New( vlcObject, &vlcObject_Type ); ( ( vlcObject* )p_retval )->p_object = value.p_object; break; case CONFIG_ITEM_FLOAT : p_retval = PyFloat_FromDouble( ( double )p_config->f_value ); break; default: p_retval = Py_None; Py_INCREF( p_retval ); } return p_retval;}/* Do a config_put* call on the object. Parameter: the variable name. */static PyObject *vlcObject_config_set( PyObject *self, PyObject *args ){ char *psz_name; PyObject *py_value; vlc_object_t *p_obj; module_config_t *p_config; if( !PyArg_ParseTuple( args, "sO", &psz_name, &py_value ) ) return NULL; p_obj = VLCSELF->p_object; p_config = config_FindConfig( p_obj, psz_name ); /* sanity checks */ if( !p_config ) { PyErr_SetString( PyExc_StandardError, "Error: option does not exist.\n" ); return NULL; } switch ( p_config->i_type ) { case CONFIG_ITEM_BOOL : case CONFIG_ITEM_INTEGER : case CONFIG_ITEM_KEY : config_PutInt( p_obj, psz_name, PyInt_AsLong( py_value ) ); break; case CONFIG_ITEM_FILE : case CONFIG_ITEM_STRING : case CONFIG_ITEM_DIRECTORY : case CONFIG_ITEM_MODULE : config_PutPsz( p_obj, psz_name, PyString_AsString( py_value ) ); break; case CONFIG_ITEM_FLOAT : config_PutFloat( p_obj, psz_name, PyFloat_AsDouble( py_value ) ); break; } Py_INCREF( Py_None ); return Py_None;}static PyObject *vlcObject_children( PyObject *self, PyObject *args ){ PyObject *p_retval; int i_size; int i_index; i_size = VLCSELF->p_object->i_children; p_retval = PyTuple_New( i_size ); for ( i_index = 0 ; i_index < i_size ; i_index++ ) { PyTuple_SetItem( p_retval, i_index, Py_BuildValue( "i", VLCSELF->p_object->pp_children[i_index]->i_object_id ) ); } return p_retval;}/* Method table */static PyMethodDef vlcObject_methods[] ={ { "get", vlcObject_var_get, METH_VARARGS, "get( str ) -> value Get a variable value."}, { "set", vlcObject_var_set, METH_VARARGS, "set( str, value ) Set a variable value" }, { "config_get", vlcObject_config_get, METH_VARARGS, "config_get( str ) -> value Get a configuration option." }, { "config_set", vlcObject_config_set, METH_VARARGS, "config_set( str, value ) Set a configuration option" }, { "type", vlcObject_var_type, METH_VARARGS, "type( str ) -> str Get a variable type" }, { "list", vlcObject_var_list, METH_NOARGS, "list( ) List the available variables" }, { "children", vlcObject_children, METH_NOARGS, "children( ) List the children ids" }, { "find_object", vlcObject_find_object, METH_VARARGS, "find_object( str ) -> Object Find the object of a given type.\n\nAvailable types are : aout, decoder, input, httpd, intf, playlist, root, vlc, vout"}, { "find_id", vlcObject_find_id, METH_VARARGS, "find_id( int ) -> Object Find an object by id" }, { "info", vlcObject_info, METH_NOARGS, "info( ) -> dict Return information about the object" }, { "release", vlcObject_release, METH_NOARGS, "release( ) -> Release the VLC Object" }, { NULL, NULL, 0, NULL },};static PyTypeObject vlcObject_Type ={ PyObject_HEAD_INIT( NULL ) 0, /*ob_size*/ "vlc.Object", /*tp_name*/ sizeof( vlcObject_Type ), /*tp_basicsize*/ 0, /*tp_itemsize*/ ( destructor )vlcObject_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ "Expose VLC object infrastructure.", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ vlcObject_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ vlcObject_new, /* tp_new */};/***************************************************************************** * VLC MediaControl object implementation *****************************************************************************/static PyObject *MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds ){ MediaControl *self; mediacontrol_Exception *exception = NULL; PyObject* py_list = NULL; char** ppsz_args = NULL; self = PyObject_New( MediaControl, &MediaControl_Type ); if( PyArg_ParseTuple( args, "O", &py_list ) ) { int i_size; int i_index; Py_INCREF( py_list ); if( ! PySequence_Check( py_list ) ) { PyErr_SetString( PyExc_TypeError, "Parameter must be a sequence." ); return NULL; } i_size = PySequence_Size( py_list ); ppsz_args = malloc( ( i_size + 1 ) * sizeof( char * ) ); if( ! ppsz_args ) { PyErr_SetString( PyExc_MemoryError, "Out of memory" ); return NULL; } for ( i_index = 0; i_index < i_size; i_index++ ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -