Commit 1fb54fc4 authored by Olivier Aubert's avatar Olivier Aubert

python bindings: formatted to VLC coding style

parent 9992f342
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#endif #endif
static PyMethodDef vlc_methods[] = { static PyMethodDef vlc_methods[] = {
{NULL} /* Sentinel */ { NULL } /* Sentinel */
}; };
/* Module globals */ /* Module globals */
...@@ -42,93 +42,106 @@ PyObject *MediaControl_PositionOriginNotSupported = NULL; ...@@ -42,93 +42,106 @@ PyObject *MediaControl_PositionOriginNotSupported = NULL;
PyObject* MediaControl_InvalidPosition = NULL; PyObject* MediaControl_InvalidPosition = NULL;
PyObject *MediaControl_PlaylistException = NULL; PyObject *MediaControl_PlaylistException = NULL;
vlcMODINIT_FUNC initvlc(void) vlcMODINIT_FUNC
initvlc( void )
{ {
PyObject* m; PyObject* p_module;
PyPosition_Type.tp_new = PyType_GenericNew; PyPosition_Type.tp_new = PyType_GenericNew;
PyPosition_Type.tp_alloc = PyType_GenericAlloc; PyPosition_Type.tp_alloc = PyType_GenericAlloc;
m = Py_InitModule3( "vlc", vlc_methods, p_module = Py_InitModule3( "vlc", vlc_methods,
"VLC media player embedding module."); "VLC media player embedding module." );
if (! m) if( !p_module )
return; return;
if (PyType_Ready(&PyPosition_Type) < 0) if( PyType_Ready( &PyPosition_Type ) < 0 )
return; return;
if (PyType_Ready(&MediaControl_Type) < 0) if( PyType_Ready( &MediaControl_Type ) < 0 )
return; return;
#ifdef VLCOBJECT_SUPPORT if( PyType_Ready( &vlcObject_Type ) < 0 )
if (PyType_Ready(&vlcObject_Type) < 0)
return; return;
#endif
/* Exceptions */ /* Exceptions */
MediaControl_InternalException = MediaControl_InternalException =
PyErr_NewException("vlc.InternalException", NULL, NULL); PyErr_NewException( "vlc.InternalException", NULL, NULL );
Py_INCREF(MediaControl_InternalException); Py_INCREF( MediaControl_InternalException );
PyModule_AddObject(m, "InternalException", MediaControl_InternalException); PyModule_AddObject( p_module, "InternalException",
MediaControl_InternalException );
MediaControl_PositionKeyNotSupported = MediaControl_PositionKeyNotSupported =
PyErr_NewException("vlc.PositionKeyNotSupported", NULL, NULL); PyErr_NewException( "vlc.PositionKeyNotSupported", NULL, NULL );
Py_INCREF(MediaControl_PositionKeyNotSupported); Py_INCREF( MediaControl_PositionKeyNotSupported );
PyModule_AddObject(m, "PositionKeyNotSupported", PyModule_AddObject( p_module, "PositionKeyNotSupported",
MediaControl_PositionKeyNotSupported); MediaControl_PositionKeyNotSupported );
MediaControl_PositionOriginNotSupported= MediaControl_PositionOriginNotSupported=
PyErr_NewException("vlc.InvalidPosition", NULL, NULL); PyErr_NewException( "vlc.InvalidPosition", NULL, NULL );
Py_INCREF(MediaControl_PositionOriginNotSupported); Py_INCREF( MediaControl_PositionOriginNotSupported );
PyModule_AddObject(m, "PositionOriginNotSupported", PyModule_AddObject( p_module, "PositionOriginNotSupported",
MediaControl_PositionOriginNotSupported); MediaControl_PositionOriginNotSupported );
MediaControl_InvalidPosition = MediaControl_InvalidPosition =
PyErr_NewException("vlc.InvalidPosition", NULL, NULL); PyErr_NewException( "vlc.InvalidPosition", NULL, NULL );
Py_INCREF(MediaControl_InvalidPosition); Py_INCREF( MediaControl_InvalidPosition );
PyModule_AddObject(m, "InvalidPosition", MediaControl_InvalidPosition); PyModule_AddObject( p_module, "InvalidPosition",
MediaControl_InvalidPosition );
MediaControl_PlaylistException = MediaControl_PlaylistException =
PyErr_NewException("vlc.PlaylistException", NULL, NULL); PyErr_NewException( "vlc.PlaylistException", NULL, NULL );
Py_INCREF(MediaControl_PlaylistException); Py_INCREF( MediaControl_PlaylistException );
PyModule_AddObject(m, "PlaylistException", MediaControl_PlaylistException); PyModule_AddObject( p_module, "PlaylistException",
MediaControl_PlaylistException );
/* Types */ /* Types */
Py_INCREF(&PyPosition_Type); Py_INCREF( &PyPosition_Type );
PyModule_AddObject(m, "Position", (PyObject *)&PyPosition_Type); PyModule_AddObject( p_module, "Position",
( PyObject * )&PyPosition_Type );
Py_INCREF(&MediaControl_Type); Py_INCREF( &MediaControl_Type );
PyModule_AddObject(m, "MediaControl", (PyObject *)&MediaControl_Type); PyModule_AddObject( p_module, "MediaControl",
( PyObject * )&MediaControl_Type );
#ifdef VLCOBJECT_SUPPORT Py_INCREF( &vlcObject_Type );
Py_INCREF(&vlcObject_Type); PyModule_AddObject( p_module, "Object",
PyModule_AddObject(m, "Object", (PyObject *)&vlcObject_Type); ( PyObject * )&vlcObject_Type );
#endif
/* Constants */ /* Constants */
PyModule_AddIntConstant(m, "AbsolutePosition", PyModule_AddIntConstant( p_module, "AbsolutePosition",
mediacontrol_AbsolutePosition); mediacontrol_AbsolutePosition );
PyModule_AddIntConstant(m, "RelativePosition", PyModule_AddIntConstant( p_module, "RelativePosition",
mediacontrol_RelativePosition); mediacontrol_RelativePosition );
PyModule_AddIntConstant(m, "ModuloPosition", PyModule_AddIntConstant( p_module, "ModuloPosition",
mediacontrol_ModuloPosition); mediacontrol_ModuloPosition );
PyModule_AddIntConstant(m, "ByteCount", mediacontrol_ByteCount); PyModule_AddIntConstant( p_module, "ByteCount",
PyModule_AddIntConstant(m, "SampleCount", mediacontrol_SampleCount); mediacontrol_ByteCount );
PyModule_AddIntConstant(m, "MediaTime", mediacontrol_MediaTime); PyModule_AddIntConstant( p_module, "SampleCount",
PyModule_AddIntConstant(m, "PlayingStatus", mediacontrol_PlayingStatus); mediacontrol_SampleCount );
PyModule_AddIntConstant(m, "PauseStatus", mediacontrol_PauseStatus); PyModule_AddIntConstant( p_module, "MediaTime",
PyModule_AddIntConstant(m, "ForwardStatus", mediacontrol_ForwardStatus); mediacontrol_MediaTime );
PyModule_AddIntConstant(m, "BackwardStatus", mediacontrol_BackwardStatus); PyModule_AddIntConstant( p_module, "PlayingStatus",
PyModule_AddIntConstant(m, "InitStatus", mediacontrol_InitStatus); mediacontrol_PlayingStatus );
PyModule_AddIntConstant(m, "EndStatus", mediacontrol_EndStatus); PyModule_AddIntConstant( p_module, "PauseStatus",
PyModule_AddIntConstant(m, "UndefinedStatus", mediacontrol_UndefinedStatus); mediacontrol_PauseStatus );
PyModule_AddIntConstant( p_module, "ForwardStatus",
mediacontrol_ForwardStatus );
PyModule_AddIntConstant( p_module, "BackwardStatus",
mediacontrol_BackwardStatus );
PyModule_AddIntConstant( p_module, "InitStatus",
mediacontrol_InitStatus );
PyModule_AddIntConstant( p_module, "EndStatus",
mediacontrol_EndStatus );
PyModule_AddIntConstant( p_module, "UndefinedStatus",
mediacontrol_UndefinedStatus );
} }
/* Make libpostproc happy... */ /* Make libpostproc happy... */
void * fast_memcpy(void * to, const void * from, size_t len) void * fast_memcpy( void * to, const void * from, size_t len )
{ {
return memcpy(to, from, len); return memcpy( to, from, len );
} }
...@@ -136,74 +149,75 @@ void * fast_memcpy(void * to, const void * from, size_t len) ...@@ -136,74 +149,75 @@ void * fast_memcpy(void * to, const void * from, size_t len)
* VLCObject implementation * VLCObject implementation
*****************************************************************************/ *****************************************************************************/
#ifdef VLCOBJECT_SUPPORT static PyObject
*vlcObject_new( PyTypeObject *p_type, PyObject *p_args, PyObject *p_kwds )
static PyObject *vlcObject_new(
PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
vlcObject *self; vlcObject *self;
vlc_object_t *p_object; vlc_object_t *p_object;
int i_id; int i_id;
self = PyObject_New(vlcObject, &vlcObject_Type); self = PyObject_New( vlcObject, &vlcObject_Type );
if ( !PyArg_ParseTuple(args, "i", &i_id) ) if( !PyArg_ParseTuple( p_args, "i", &i_id ) )
return NULL; return NULL;
/* Maybe we were already initialized */ /* Maybe we were already initialized */
p_object = (vlc_object_t*)vlc_current_object(i_id); p_object = ( vlc_object_t* )vlc_current_object( i_id );
if (! p_object) if( !p_object )
{ {
/* Try to initialize */ /* Try to initialize */
i_id = VLC_Create(); i_id = VLC_Create();
p_object = (vlc_object_t*)vlc_current_object(i_id); p_object = ( vlc_object_t* )vlc_current_object( i_id );
} }
if (! p_object) if( !p_object )
{ {
PyErr_SetString(PyExc_StandardError, "Unable to get object."); PyErr_SetString( PyExc_StandardError, "Unable to get object." );
return NULL; return NULL;
} }
self->p_object = p_object; self->p_object = p_object;
self->b_released = 0; self->b_released = 0;
Py_INCREF( self ); /* Ah bon ? */ Py_INCREF( self ); /* Ah bon ? */
return (PyObject *)self; return ( PyObject * )self;
} }
static PyObject * vlcObject_release( PyObject *self, PyObject *args ) static PyObject *
vlcObject_release( PyObject *self, PyObject *p_args )
{ {
if( VLCSELF->b_released == 0 ) if( VLCSELF->b_released == 0 )
{ {
vlc_object_release( VLCSELF->p_object ); vlc_object_release( VLCSELF->p_object );
VLCSELF->b_released = 1; VLCSELF->b_released = 1;
} }
Py_INCREF( Py_None ); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static void vlcObject_dealloc(PyObject *self) static void
vlcObject_dealloc( PyObject *self )
{ {
vlcObject_release( self, NULL ); vlcObject_release( self, NULL );
PyMem_DEL(self); PyMem_DEL( self );
} }
static PyObject * vlcObject_find_object(PyObject *self, PyObject *args) static PyObject *
vlcObject_find_object( PyObject *self, PyObject *args )
{ {
vlcObject *retval; vlcObject *p_retval;
vlc_object_t *p_obj; vlc_object_t *p_obj;
char *psz_name; char *psz_name;
int i_object_type; int i_object_type;
if ( !PyArg_ParseTuple(args, "s", &psz_name) ) if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL; return NULL;
/* psz_name is in /* psz_name is in
(aout, decoder, input, httpd, intf, playlist, root, vlc, vout) ( aout, decoder, input, httpd, intf, playlist, root, vlc, vout )
*/ */
switch (psz_name[0]) switch ( psz_name[0] )
{ {
case 'a': case 'a':
i_object_type = VLC_OBJECT_AOUT; i_object_type = VLC_OBJECT_AOUT;
...@@ -215,9 +229,9 @@ static PyObject * vlcObject_find_object(PyObject *self, PyObject *args) ...@@ -215,9 +229,9 @@ static PyObject * vlcObject_find_object(PyObject *self, PyObject *args)
i_object_type = VLC_OBJECT_HTTPD; i_object_type = VLC_OBJECT_HTTPD;
break; break;
case 'i': case 'i':
if (strlen(psz_name) < 3) if( strlen( psz_name ) < 3 )
i_object_type = VLC_OBJECT_INTF; i_object_type = VLC_OBJECT_INTF;
else if (psz_name[2] == 't') else if( psz_name[2] == 't' )
i_object_type = VLC_OBJECT_INTF; i_object_type = VLC_OBJECT_INTF;
else else
i_object_type = VLC_OBJECT_INPUT; i_object_type = VLC_OBJECT_INPUT;
...@@ -229,413 +243,413 @@ static PyObject * vlcObject_find_object(PyObject *self, PyObject *args) ...@@ -229,413 +243,413 @@ static PyObject * vlcObject_find_object(PyObject *self, PyObject *args)
i_object_type = VLC_OBJECT_ROOT; i_object_type = VLC_OBJECT_ROOT;
break; break;
case 'v': case 'v':
if (strlen(psz_name) < 3) if( strlen( psz_name ) < 3 )
i_object_type = VLC_OBJECT_VLC; i_object_type = VLC_OBJECT_VLC;
else if (psz_name[1] == 'l') else if( psz_name[1] == 'l' )
i_object_type = VLC_OBJECT_VLC; i_object_type = VLC_OBJECT_VLC;
else else
i_object_type = VLC_OBJECT_VOUT; i_object_type = VLC_OBJECT_VOUT;
break; break;
default: default:
/* FIXME: raise an exception */ /* FIXME: raise an exception ? */
return Py_None; return Py_None;
} }
p_obj = vlc_object_find( VLCSELF->p_object, i_object_type, FIND_ANYWHERE ); p_obj = vlc_object_find( VLCSELF->p_object, i_object_type, FIND_ANYWHERE );
if (! p_obj) if( !p_obj )
{ {
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
retval = PyObject_New(vlcObject, &vlcObject_Type); p_retval = PyObject_New( vlcObject, &vlcObject_Type );
retval->p_object = p_obj; p_retval->p_object = p_obj;
return (PyObject *)retval; return ( PyObject * )p_retval;
} }
static PyObject * vlcObject_info(PyObject *self, PyObject *args) static PyObject *
vlcObject_info( PyObject *self, PyObject *args )
{ {
PyObject *retval; PyObject *p_retval;
vlc_object_t *p_obj; vlc_object_t *p_obj;
p_obj = VLCSELF->p_object; p_obj = VLCSELF->p_object;
/* Return information about the object as a dict. */ /* Return information about the object as a dict. */
retval = PyDict_New(); p_retval = PyDict_New();
PyDict_SetItemString(retval, "object-id", PyDict_SetItemString( p_retval, "object-id",
Py_BuildValue("l", p_obj->i_object_id)); Py_BuildValue( "l", p_obj->i_object_id ) );
PyDict_SetItemString(retval, "object-type", PyDict_SetItemString( p_retval, "object-type",
Py_BuildValue("s", p_obj->psz_object_type)); Py_BuildValue( "s", p_obj->psz_object_type ) );
PyDict_SetItemString(retval, "object-name", PyDict_SetItemString( p_retval, "object-name",
Py_BuildValue("s", p_obj->psz_object_name)); Py_BuildValue( "s", p_obj->psz_object_name ) );
PyDict_SetItemString(retval, "thread", PyDict_SetItemString( p_retval, "thread",
PyBool_FromLong(p_obj->b_thread)); PyBool_FromLong( p_obj->b_thread ) );
PyDict_SetItemString(retval, "thread-id", PyDict_SetItemString( p_retval, "thread-id",
PyLong_FromLongLong(p_obj->thread_id)); PyLong_FromLongLong( p_obj->thread_id ) );
PyDict_SetItemString(retval, "refcount", PyDict_SetItemString( p_retval, "refcount",
PyInt_FromLong(p_obj->i_refcount)); PyInt_FromLong( p_obj->i_refcount ) );
return retval; return p_retval;
} }
static PyObject * vlcObject_find_id(PyObject *self, PyObject *args) static PyObject *
vlcObject_find_id( PyObject *self, PyObject *args )
{ {
vlcObject *retval; vlcObject *p_retval;
vlc_object_t* p_object; vlc_object_t* p_object;
int i_id; int i_id;
if ( !PyArg_ParseTuple(args, "i", &i_id) ) if( !PyArg_ParseTuple( args, "i", &i_id ) )
return NULL; return NULL;
p_object = (vlc_object_t*)vlc_current_object(i_id); p_object = ( vlc_object_t* )vlc_current_object( i_id );
if (! p_object) if( !p_object )
{ {
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
retval = PyObject_NEW(vlcObject, &vlcObject_Type); p_retval = PyObject_NEW( vlcObject, &vlcObject_Type );
retval->p_object = p_object; p_retval->p_object = p_object;
return (PyObject *)retval; return ( PyObject * )p_retval;
} }
/* Do a var_Get call on the object. Parameter: the variable name. */ /* Do a var_Get call on the object. Parameter: the variable name. */
/* FIXME: We should make them attributes */ static PyObject *
static PyObject * vlcObject_var_get(PyObject *self, PyObject *args) vlcObject_var_get( PyObject *self, PyObject *args )
{ {
PyObject *retval; PyObject *p_retval;
vlc_value_t value; vlc_value_t value;
char *psz_name; char *psz_name;
int i_type; int i_type;
if ( !PyArg_ParseTuple(args, "s", &psz_name) ) if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL; return NULL;
if( var_Get( VLCSELF->p_object, psz_name, &value ) != VLC_SUCCESS ) if( var_Get( VLCSELF->p_object, psz_name, &value ) != VLC_SUCCESS )
{ {
PyErr_SetString(PyExc_StandardError, "Error: no variable name was given.\n"); PyErr_SetString( PyExc_StandardError,
return NULL; "Error: variable does not exist.\n" );
return NULL;
} }
i_type = var_Type (VLCSELF->p_object, psz_name); i_type = var_Type ( VLCSELF->p_object, psz_name );
switch (i_type) switch ( i_type )
{ {
case VLC_VAR_VOID : case VLC_VAR_VOID :
retval = PyString_FromString("A void variable"); p_retval = PyString_FromString( "A void variable" );
break; break;
case VLC_VAR_BOOL : case VLC_VAR_BOOL :
retval = PyBool_FromLong(value.b_bool); p_retval = PyBool_FromLong( value.b_bool );
break; break;
case VLC_VAR_INTEGER : case VLC_VAR_INTEGER :
retval = PyInt_FromLong((long)value.i_int); p_retval = PyInt_FromLong( ( long )value.i_int );
break; break;
case VLC_VAR_HOTKEY : case VLC_VAR_HOTKEY :
retval = PyString_FromFormat("A hotkey variable (%d)", value.i_int); p_retval = PyString_FromFormat( "A hotkey variable ( %d )", value.i_int );
break; break;
case VLC_VAR_FILE : case VLC_VAR_FILE :
case VLC_VAR_STRING : case VLC_VAR_STRING :
case VLC_VAR_DIRECTORY : case VLC_VAR_DIRECTORY :
case VLC_VAR_VARIABLE : case VLC_VAR_VARIABLE :
retval = PyString_FromString(value.psz_string); p_retval = PyString_FromString( value.psz_string );
break; break;
case VLC_VAR_MODULE : case VLC_VAR_MODULE :
retval = (PyObject*)PyObject_New(vlcObject, &vlcObject_Type); p_retval = ( PyObject* )PyObject_New( vlcObject, &vlcObject_Type );
((vlcObject*)retval)->p_object = value.p_object; ( ( vlcObject* )p_retval )->p_object = value.p_object;
break; break;
case VLC_VAR_FLOAT : case VLC_VAR_FLOAT :
retval = PyFloat_FromDouble((double)value.f_float); p_retval = PyFloat_FromDouble( ( double )value.f_float );
break; break;
case VLC_VAR_TIME : case VLC_VAR_TIME :
retval = PyLong_FromLongLong(value.i_time); p_retval = PyLong_FromLongLong( value.i_time );
break; break;
case VLC_VAR_ADDRESS : case VLC_VAR_ADDRESS :
retval = PyString_FromString("A VLC address (not handled yet)"); p_retval = PyString_FromString( "A VLC address ( not handled yet )" );
break; break;
case VLC_VAR_LIST : case VLC_VAR_LIST :
retval = PyString_FromString("A VLC list (not handled yet)"); p_retval = PyString_FromString( "A VLC list ( not handled yet )" );
break; break;
case VLC_VAR_MUTEX : case VLC_VAR_MUTEX :
retval = PyString_FromString("A mutex"); p_retval = PyString_FromString( "A mutex" );
break; break;
default: default:
retval = Py_None; p_retval = Py_None;
} }
Py_INCREF(retval); Py_INCREF( p_retval );
return retval; return p_retval;
} }
static PyObject * vlcObject_var_type(PyObject *self, static PyObject *
PyObject *args) vlcObject_var_type( PyObject *self, PyObject *args )
{ {
char *psz_name; char *psz_name;
PyObject *retval; PyObject *p_retval;
int i_type; int i_type;
if ( !PyArg_ParseTuple(args, "s", &psz_name)) if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL; return NULL;
i_type = var_Type(VLCSELF->p_object, psz_name); i_type = var_Type( VLCSELF->p_object, psz_name );
switch (i_type) switch ( i_type )
{ {
case VLC_VAR_VOID : case VLC_VAR_VOID :
retval = PyString_FromString("Void"); p_retval = PyString_FromString( "Void" );
break; break;
case VLC_VAR_BOOL : case VLC_VAR_BOOL :
retval = PyString_FromString("Boolean"); p_retval = PyString_FromString( "Boolean" );
break; break;
case VLC_VAR_INTEGER : case VLC_VAR_INTEGER :
retval = PyString_FromString("Integer"); p_retval = PyString_FromString( "Integer" );
break; break;
case VLC_VAR_HOTKEY : case VLC_VAR_HOTKEY :
retval = PyString_FromString("Hotkey"); p_retval = PyString_FromString( "Hotkey" );
break; break;
case VLC_VAR_FILE : case VLC_VAR_FILE :
retval = PyString_FromString("File"); p_retval = PyString_FromString( "File" );
break; break;
case VLC_VAR_STRING : case VLC_VAR_STRING :
retval = PyString_FromString("String"); p_retval = PyString_FromString( "String" );
break; break;
case VLC_VAR_DIRECTORY : case VLC_VAR_DIRECTORY :
retval = PyString_FromString("Directory"); p_retval = PyString_FromString( "Directory" );
break; break;
case VLC_VAR_VARIABLE : case VLC_VAR_VARIABLE :
retval = PyString_FromString("Variable"); p_retval = PyString_FromString( "Variable" );
break; break;
case VLC_VAR_MODULE : case VLC_VAR_MODULE :
retval = PyString_FromString("Module"); p_retval = PyString_FromString( "Module" );
break; break;
case VLC_VAR_FLOAT : case VLC_VAR_FLOAT :
retval = PyString_FromString("Float"); p_retval = PyString_FromString( "Float" );
break; break;
case VLC_VAR_TIME : case VLC_VAR_TIME :
retval = PyString_FromString("Time"); p_retval = PyString_FromString( "Time" );
break; break;
case VLC_VAR_ADDRESS : case VLC_VAR_ADDRESS :
retval = PyString_FromString("Address"); p_retval = PyString_FromString( "Address" );
break; break;
case VLC_VAR_LIST : case VLC_VAR_LIST :
retval = PyString_FromString("List"); p_retval = PyString_FromString( "List" );
break; break;
case VLC_VAR_MUTEX : case VLC_VAR_MUTEX :
retval = PyString_FromString("Mutex"); p_retval = PyString_FromString( "Mutex" );
break; break;
default: default:
retval = PyString_FromString("Unknown"); p_retval = PyString_FromString( "Unknown" );
} }
return retval; return p_retval;
} }
/* Do a var_Set call on the object. Parameter: the variable name. */ /* Do a var_Set call on the object. Parameter: the variable name. */
/* FIXME: We should make them attributes */ static PyObject *
static PyObject * vlcObject_var_set(PyObject *self, vlcObject_var_set( PyObject *self, PyObject *args )
PyObject *args)
{ {
vlc_value_t value; vlc_value_t value;
char *psz_name; char *psz_name;
PyObject *py_value; PyObject *py_value;
int i_type; int i_type;
vlc_object_t *p_obj; vlc_object_t *p_obj;
if ( !PyArg_ParseTuple(args, "sO", &psz_name, &py_value) ) if( !PyArg_ParseTuple( args, "sO", &psz_name, &py_value ) )
return NULL; return NULL;
p_obj = VLCSELF->p_object; p_obj = VLCSELF->p_object;
i_type = var_Type(p_obj, psz_name); i_type = var_Type( p_obj, psz_name );
switch (i_type) switch ( i_type )
{ {
case VLC_VAR_VOID : case VLC_VAR_VOID :
break; break;
case VLC_VAR_BOOL : case VLC_VAR_BOOL :
value.b_bool = PyInt_AsLong(py_value); value.b_bool = PyInt_AsLong( py_value );
break; break;
case VLC_VAR_INTEGER : case VLC_VAR_INTEGER :
case VLC_VAR_HOTKEY : case VLC_VAR_HOTKEY :
value.i_int = PyInt_AsLong(py_value); value.i_int = PyInt_AsLong( py_value );
break; break;
case VLC_VAR_FILE : case VLC_VAR_FILE :
case VLC_VAR_STRING : case VLC_VAR_STRING :
case VLC_VAR_DIRECTORY : case VLC_VAR_DIRECTORY :
case VLC_VAR_VARIABLE : case VLC_VAR_VARIABLE :
value.psz_string = strdup(PyString_AsString(py_value)); value.psz_string = strdup( PyString_AsString( py_value ) );
break; break;
case VLC_VAR_MODULE : case VLC_VAR_MODULE :
/* FIXME: we should check the PyObject type and get its p_object */ /* FIXME: we should check the PyObject type and get its p_object */
value.p_object = ((vlcObject*)p_obj)->p_object; value.p_object = ( ( vlcObject* )p_obj )->p_object;
break; break;
case VLC_VAR_FLOAT : case VLC_VAR_FLOAT :
value.f_float = PyFloat_AsDouble(py_value); value.f_float = PyFloat_AsDouble( py_value );
break; break;
case VLC_VAR_TIME : case VLC_VAR_TIME :
value.i_time = PyLong_AsLongLong(py_value); value.i_time = PyLong_AsLongLong( py_value );
break; break;
case VLC_VAR_ADDRESS : case VLC_VAR_ADDRESS :
value.p_address = (char*)PyLong_AsVoidPtr(py_value); value.p_address = ( char* )PyLong_AsVoidPtr( py_value );
break; break;
case VLC_VAR_LIST : case VLC_VAR_LIST :
/* FIXME */ /* FIXME */
value.p_list = NULL; value.p_list = NULL;
break; break;
case VLC_VAR_MUTEX : case VLC_VAR_MUTEX :
break; break;
} }
var_Set(p_obj, psz_name, value); var_Set( p_obj, psz_name, value );
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static PyObject * vlcObject_var_list(PyObject *self, PyObject *args) static PyObject *
vlcObject_var_list( PyObject *self, PyObject *args )
{ {
PyObject *retval; PyObject *p_retval;
int i_size; int i_size;
int i_index; int i_index;
i_size = VLCSELF->p_object->i_vars; i_size = VLCSELF->p_object->i_vars;
retval = PyTuple_New(i_size); p_retval = PyTuple_New( i_size );
for (i_index = 0 ; i_index < i_size ; i_index++) for ( i_index = 0 ; i_index < i_size ; i_index++ )
{ {
PyTuple_SetItem(retval, i_index, PyTuple_SetItem( p_retval, i_index,
Py_BuildValue("s", VLCSELF->p_object->p_vars[i_index].psz_name)); Py_BuildValue( "s", VLCSELF->p_object->p_vars[i_index].psz_name ) );
} }
/* Py_INCREF(retval); */ return p_retval;
return retval;
} }
/* Do a config_Get call on the object. Parameter: the variable name. */ /* Do a config_Get call on the object. Parameter: the variable name. */
static PyObject * vlcObject_config_get(PyObject *self, static PyObject *
PyObject *args) vlcObject_config_get( PyObject *self, PyObject *args )
{ {
PyObject *retval; PyObject *p_retval;
vlc_value_t value; vlc_value_t value;
char *psz_name; char *psz_name;
module_config_t *p_config; module_config_t *p_config;
if ( !PyArg_ParseTuple(args, "s", &psz_name) ) if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL; return NULL;
p_config = config_FindConfig( VLCSELF->p_object, psz_name ); p_config = config_FindConfig( VLCSELF->p_object, psz_name );
if( !p_config ) if( !p_config )
{ {
PyErr_SetString(PyExc_StandardError, "Error: config variable does not exist.\n"); PyErr_SetString( PyExc_StandardError,
Py_INCREF(Py_None); "Error: config variable does not exist.\n" );
return Py_None; return NULL;
} }
switch (p_config->i_type) switch ( p_config->i_type )
{ {
case CONFIG_ITEM_BOOL : case CONFIG_ITEM_BOOL :
retval = PyBool_FromLong(p_config->i_value); p_retval = PyBool_FromLong( p_config->i_value );
break; break;
case CONFIG_ITEM_INTEGER : case CONFIG_ITEM_INTEGER :
retval = PyInt_FromLong((long)p_config->i_value); p_retval = PyInt_FromLong( ( long )p_config->i_value );
break; break;
case CONFIG_ITEM_KEY : case CONFIG_ITEM_KEY :
retval = PyString_FromFormat("A hotkey variable (%d)", p_config->i_value); p_retval = PyString_FromFormat( "A hotkey variable ( %d )", p_config->i_value );
break; break;
case CONFIG_ITEM_FILE : case CONFIG_ITEM_FILE :
case CONFIG_ITEM_STRING : case CONFIG_ITEM_STRING :
case CONFIG_ITEM_DIRECTORY : case CONFIG_ITEM_DIRECTORY :
case CONFIG_ITEM_MODULE : case CONFIG_ITEM_MODULE :
vlc_mutex_lock( p_config->p_lock ); vlc_mutex_lock( p_config->p_lock );
if( p_config->psz_value ) if( p_config->psz_value )
retval = PyString_FromString( p_config->psz_value ); p_retval = PyString_FromString( p_config->psz_value );
else else
retval = PyString_FromString( "" ); p_retval = PyString_FromString( "" );
vlc_mutex_unlock( p_config->p_lock ); vlc_mutex_unlock( p_config->p_lock );
break; break;
retval = (PyObject*)PyObject_New(vlcObject, &vlcObject_Type); p_retval = ( PyObject* )PyObject_New( vlcObject, &vlcObject_Type );
((vlcObject*)retval)->p_object = value.p_object; ( ( vlcObject* )p_retval )->p_object = value.p_object;
break; break;
case CONFIG_ITEM_FLOAT : case CONFIG_ITEM_FLOAT :
retval = PyFloat_FromDouble((double)p_config->f_value); p_retval = PyFloat_FromDouble( ( double )p_config->f_value );
break; break;
default: default:
retval = Py_None; p_retval = Py_None;
Py_INCREF(retval); Py_INCREF( p_retval );
} }
return retval; return p_retval;
} }
/* Do a var_Set call on the object. Parameter: the variable name. */ /* Do a config_put* call on the object. Parameter: the variable name. */
/* FIXME: We should make them attributes */ static PyObject *
static PyObject * vlcObject_config_set(PyObject *self, vlcObject_config_set( PyObject *self, PyObject *args )
PyObject *args)
{ {
char *psz_name; char *psz_name;
PyObject *py_value; PyObject *py_value;
vlc_object_t *p_obj; vlc_object_t *p_obj;
module_config_t *p_config; module_config_t *p_config;
if ( !PyArg_ParseTuple(args, "sO", &psz_name, &py_value) ) if( !PyArg_ParseTuple( args, "sO", &psz_name, &py_value ) )
return NULL; return NULL;
p_obj = VLCSELF->p_object; p_obj = VLCSELF->p_object;
p_config = config_FindConfig( p_obj, psz_name ); p_config = config_FindConfig( p_obj, psz_name );
/* sanity checks */ /* sanity checks */
if( !p_config ) if( !p_config )
{ {
PyErr_SetString(PyExc_StandardError, PyErr_SetString( PyExc_StandardError,
"Error: option does not exist.\n"); "Error: option does not exist.\n" );
Py_INCREF(Py_None); return NULL;
return Py_None; }
}
switch (p_config->i_type) switch ( p_config->i_type )
{ {
case CONFIG_ITEM_BOOL : case CONFIG_ITEM_BOOL :
case CONFIG_ITEM_INTEGER : case CONFIG_ITEM_INTEGER :
case CONFIG_ITEM_KEY : case CONFIG_ITEM_KEY :
config_PutInt(p_obj, psz_name, PyInt_AsLong(py_value)); config_PutInt( p_obj, psz_name, PyInt_AsLong( py_value ) );
break; break;
case CONFIG_ITEM_FILE : case CONFIG_ITEM_FILE :
case CONFIG_ITEM_STRING : case CONFIG_ITEM_STRING :
case CONFIG_ITEM_DIRECTORY : case CONFIG_ITEM_DIRECTORY :
case CONFIG_ITEM_MODULE : case CONFIG_ITEM_MODULE :
config_PutPsz(p_obj, psz_name, PyString_AsString(py_value)); config_PutPsz( p_obj, psz_name, PyString_AsString( py_value ) );
break; break;
case CONFIG_ITEM_FLOAT : case CONFIG_ITEM_FLOAT :
config_PutFloat(p_obj, psz_name, PyFloat_AsDouble(py_value)); config_PutFloat( p_obj, psz_name, PyFloat_AsDouble( py_value ) );
break; break;
} }
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static PyObject * vlcObject_children(PyObject *self, PyObject *args) static PyObject *
vlcObject_children( PyObject *self, PyObject *args )
{ {
PyObject *retval; PyObject *p_retval;
int i_size; int i_size;
int i_index; int i_index;
i_size = VLCSELF->p_object->i_children; i_size = VLCSELF->p_object->i_children;
retval = PyTuple_New(i_size); p_retval = PyTuple_New( i_size );
for (i_index = 0 ; i_index < i_size ; i_index++) for ( i_index = 0 ; i_index < i_size ; i_index++ )
{ {
PyTuple_SetItem(retval, i_index, PyTuple_SetItem( p_retval, i_index,
Py_BuildValue("i", Py_BuildValue( "i",
VLCSELF->p_object->pp_children[i_index]->i_object_id)); VLCSELF->p_object->pp_children[i_index]->i_object_id ) );
} }
/* Py_INCREF(retval); */ return p_retval;
return retval;
} }
...@@ -643,38 +657,38 @@ static PyObject * vlcObject_children(PyObject *self, PyObject *args) ...@@ -643,38 +657,38 @@ static PyObject * vlcObject_children(PyObject *self, PyObject *args)
static PyMethodDef vlcObject_methods[] = static PyMethodDef vlcObject_methods[] =
{ {
{ "get", vlcObject_var_get, METH_VARARGS, { "get", vlcObject_var_get, METH_VARARGS,
"get(str) -> value Get a variable value."}, "get( str ) -> value Get a variable value."},
{ "set", vlcObject_var_set, METH_VARARGS, { "set", vlcObject_var_set, METH_VARARGS,
"set(str, value) Set a variable value" }, "set( str, value ) Set a variable value" },
{ "config_get", vlcObject_config_get, METH_VARARGS, { "config_get", vlcObject_config_get, METH_VARARGS,
"config_get(str) -> value Get a configuration option." }, "config_get( str ) -> value Get a configuration option." },
{ "config_set", vlcObject_config_set, METH_VARARGS, { "config_set", vlcObject_config_set, METH_VARARGS,
"config_set(str, value) Set a configuration option" }, "config_set( str, value ) Set a configuration option" },
{ "type", vlcObject_var_type, METH_VARARGS, { "type", vlcObject_var_type, METH_VARARGS,
"type(str) -> str Get a variable type" }, "type( str ) -> str Get a variable type" },
{ "list", vlcObject_var_list, METH_NOARGS, { "list", vlcObject_var_list, METH_NOARGS,
"list() List the available variables" }, "list( ) List the available variables" },
{ "children", vlcObject_children, METH_NOARGS, { "children", vlcObject_children, METH_NOARGS,
"children() List the children ids" }, "children( ) List the children ids" },
{ "find_object", vlcObject_find_object, METH_VARARGS, { "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_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", vlcObject_find_id, METH_VARARGS,
"find_id(int) -> Object Find an object by id" }, "find_id( int ) -> Object Find an object by id" },
{ "info", vlcObject_info, METH_NOARGS, { "info", vlcObject_info, METH_NOARGS,
"info() -> dict Return information about the object" }, "info( ) -> dict Return information about the object" },
{ "release", vlcObject_release, METH_NOARGS, { "release", vlcObject_release, METH_NOARGS,
"release() -> Release the VLC Object" }, "release( ) -> Release the VLC Object" },
{ NULL, NULL, 0, NULL }, { NULL, NULL, 0, NULL },
}; };
static PyTypeObject vlcObject_Type = static PyTypeObject vlcObject_Type =
{ {
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT( NULL )
0, /*ob_size*/ 0, /*ob_size*/
"vlc.Object", /*tp_name*/ "vlc.Object", /*tp_name*/
sizeof(vlcObject_Type), /*tp_basicsize*/ sizeof( vlcObject_Type ), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor)vlcObject_dealloc, /*tp_dealloc*/ ( destructor )vlcObject_dealloc, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
...@@ -690,7 +704,7 @@ static PyTypeObject vlcObject_Type = ...@@ -690,7 +704,7 @@ static PyTypeObject vlcObject_Type =
0, /*tp_setattro*/ 0, /*tp_setattro*/
0, /*tp_as_buffer*/ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"Explore VLC objects.", /* tp_doc */ "Expose VLC object infrastructure.", /* tp_doc */
0, /* tp_traverse */ 0, /* tp_traverse */
0, /* tp_clear */ 0, /* tp_clear */
0, /* tp_richcompare */ 0, /* tp_richcompare */
...@@ -710,56 +724,54 @@ static PyTypeObject vlcObject_Type = ...@@ -710,56 +724,54 @@ static PyTypeObject vlcObject_Type =
vlcObject_new, /* tp_new */ vlcObject_new, /* tp_new */
}; };
#endif
/***************************************************************************** /*****************************************************************************
* VLC MediaControl object implementation * VLC MediaControl object implementation
*****************************************************************************/ *****************************************************************************/
static PyObject *MediaControl_new(PyTypeObject *type, PyObject *args, PyObject *kwds) static PyObject *
MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
{ {
MediaControl *self; MediaControl *self;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
PyObject* py_list = NULL; PyObject* py_list = NULL;
char** ppsz_args = NULL; char** ppsz_args = NULL;
self = PyObject_New(MediaControl, &MediaControl_Type); self = PyObject_New( MediaControl, &MediaControl_Type );
if (PyArg_ParseTuple(args, "O", &py_list)) if( PyArg_ParseTuple( args, "O", &py_list ) )
{ {
int i_size; int i_size;
int i_index; int i_index;
Py_INCREF(py_list); Py_INCREF( py_list );
if (! PySequence_Check(py_list)) if( ! PySequence_Check( py_list ) )
{ {
PyErr_SetString(PyExc_TypeError, "Parameter must be a sequence."); PyErr_SetString( PyExc_TypeError, "Parameter must be a sequence." );
return NULL; return NULL;
} }
i_size = PySequence_Size(py_list); i_size = PySequence_Size( py_list );
ppsz_args = malloc(i_size + 1); ppsz_args = malloc( i_size + 1 );
if (! ppsz_args) if( ! ppsz_args )
{ {
PyErr_SetString(PyExc_MemoryError, "Out of memory"); PyErr_SetString( PyExc_MemoryError, "Out of memory" );
return NULL; return NULL;
} }
for ( i_index = 0; i_index < i_size; i_index++ ) for ( i_index = 0; i_index < i_size; i_index++ )
{ {
ppsz_args[i_index] = ppsz_args[i_index] =
strdup( PyString_AsString( PyObject_Str( strdup( PyString_AsString( PyObject_Str(
PySequence_GetItem(py_list, PySequence_GetItem( py_list,
i_index ) ) ) ); i_index ) ) ) );
} }
ppsz_args[i_size] = NULL; ppsz_args[i_size] = NULL;
Py_DECREF(py_list); Py_DECREF( py_list );
} }
else else
{ {
/* No arguments were given. Clear the exception raised /* No arguments were given. Clear the exception raised
by PyArg_ParseTuple. */ by PyArg_ParseTuple. */
PyErr_Clear(); PyErr_Clear( );
} }
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
...@@ -768,22 +780,23 @@ static PyObject *MediaControl_new(PyTypeObject *type, PyObject *args, PyObject * ...@@ -768,22 +780,23 @@ static PyObject *MediaControl_new(PyTypeObject *type, PyObject *args, PyObject *
MC_EXCEPT; MC_EXCEPT;
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
Py_INCREF(self); Py_INCREF( self );
return (PyObject *)self; return ( PyObject * )self;
} }
static void MediaControl_dealloc(PyObject *self) static void
MediaControl_dealloc( PyObject *self )
{ {
PyMem_DEL(self); PyMem_DEL( self );
} }
/** /**
* Returns the current position in the stream. The returned value can * Return the current position in the stream. The returned value can
be relative or absolute (according to PositionOrigin) and the unit be relative or absolute ( according to PositionOrigin ) and the unit
is set by PositionKey is set by PositionKey
*/ */
static PyObject * MediaControl_get_media_position( static PyObject *
PyObject *self, PyObject *args) MediaControl_get_media_position( PyObject *self, PyObject *args )
{ {
mediacontrol_Position* pos; mediacontrol_Position* pos;
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
...@@ -796,23 +809,23 @@ static PyObject * MediaControl_get_media_position( ...@@ -796,23 +809,23 @@ static PyObject * MediaControl_get_media_position(
if( !PyArg_ParseTuple( args, "OO", &py_origin, &py_key ) ) if( !PyArg_ParseTuple( args, "OO", &py_origin, &py_key ) )
return NULL; return NULL;
origin = positionOrigin_py_to_c(py_origin); origin = positionOrigin_py_to_c( py_origin );
key = positionKey_py_to_c(py_key); key = positionKey_py_to_c( py_key );
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
pos = mediacontrol_get_media_position(SELF->mc, origin, key, exception); pos = mediacontrol_get_media_position( SELF->mc, origin, key, exception );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
py_retval = (PyObject*)position_c_to_py(pos); py_retval = ( PyObject* )position_c_to_py( pos );
free( pos ); free( pos );
return py_retval; return py_retval;
} }
/** Sets the media position */ /** Set the media position */
static PyObject *MediaControl_set_media_position( static PyObject *
PyObject *self, PyObject *args ) MediaControl_set_media_position( PyObject *self, PyObject *args )
{ {
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
mediacontrol_Position *a_position; mediacontrol_Position *a_position;
...@@ -821,10 +834,10 @@ static PyObject *MediaControl_set_media_position( ...@@ -821,10 +834,10 @@ static PyObject *MediaControl_set_media_position(
if( !PyArg_ParseTuple( args, "O", &py_pos ) ) if( !PyArg_ParseTuple( args, "O", &py_pos ) )
return NULL; return NULL;
a_position = position_py_to_c(py_pos); a_position = position_py_to_c( py_pos );
if (!a_position ) if( !a_position )
{ {
PyErr_SetString(PyExc_MemoryError, "Out of memory"); PyErr_SetString( PyExc_MemoryError, "Out of memory" );
return NULL; return NULL;
} }
...@@ -835,57 +848,59 @@ static PyObject *MediaControl_set_media_position( ...@@ -835,57 +848,59 @@ static PyObject *MediaControl_set_media_position(
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static PyObject *MediaControl_start(PyObject *self, PyObject *args) static PyObject *
MediaControl_start( PyObject *self, PyObject *args )
{ {
mediacontrol_Position *a_position; mediacontrol_Position *a_position;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
PyObject *py_pos; PyObject *py_pos;
if( !PyArg_ParseTuple(args, "O", &py_pos ) ) if( !PyArg_ParseTuple( args, "O", &py_pos ) )
{ {
/* No argument. Use a default 0 value. */ /* No argument. Use a default 0 value. */
PyErr_Clear(); PyErr_Clear( );
py_pos = NULL; py_pos = NULL;
} }
a_position = position_py_to_c(py_pos); a_position = position_py_to_c( py_pos );
if ( !a_position ) if( !a_position )
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_start(SELF->mc, a_position, exception); mediacontrol_start( SELF->mc, a_position, exception );
free(a_position); free( a_position );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static PyObject *MediaControl_pause(PyObject *self, PyObject *args) static PyObject *
MediaControl_pause( PyObject *self, PyObject *args )
{ {
mediacontrol_Position *a_position; mediacontrol_Position *a_position;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
PyObject *py_pos; PyObject *py_pos;
if( !PyArg_ParseTuple(args, "O", &py_pos ) ) if( !PyArg_ParseTuple( args, "O", &py_pos ) )
{ {
/* No argument. Use a default 0 value. */ /* No argument. Use a default 0 value. */
PyErr_Clear(); PyErr_Clear( );
py_pos = NULL; py_pos = NULL;
} }
a_position = position_py_to_c(py_pos); a_position = position_py_to_c( py_pos );
if ( !a_position ) if( !a_position )
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_pause(SELF->mc, a_position, exception); mediacontrol_pause( SELF->mc, a_position, exception );
free(a_position); free( a_position );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
...@@ -893,102 +908,106 @@ static PyObject *MediaControl_pause(PyObject *self, PyObject *args) ...@@ -893,102 +908,106 @@ static PyObject *MediaControl_pause(PyObject *self, PyObject *args)
return Py_None; return Py_None;
} }
static PyObject * MediaControl_resume(PyObject *self, PyObject *args) static PyObject *
MediaControl_resume( PyObject *self, PyObject *args )
{ {
mediacontrol_Position *a_position; mediacontrol_Position *a_position;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
PyObject *py_pos; PyObject *py_pos;
if( !PyArg_ParseTuple(args, "O", &py_pos ) ) if( !PyArg_ParseTuple( args, "O", &py_pos ) )
{ {
/* No argument. Use a default 0 value. */ /* No argument. Use a default 0 value. */
PyErr_Clear(); PyErr_Clear( );
py_pos = NULL; py_pos = NULL;
} }
a_position = position_py_to_c(py_pos); a_position = position_py_to_c( py_pos );
if ( !a_position ) if( !a_position )
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_start(SELF->mc, a_position, exception); mediacontrol_start( SELF->mc, a_position, exception );
free(a_position); free( a_position );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static PyObject *MediaControl_stop(PyObject *self, PyObject *args) static PyObject *
MediaControl_stop( PyObject *self, PyObject *args )
{ {
mediacontrol_Position *a_position; mediacontrol_Position *a_position;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
PyObject *py_pos; PyObject *py_pos;
if( !PyArg_ParseTuple(args, "O", &py_pos ) ) if( !PyArg_ParseTuple( args, "O", &py_pos ) )
{ {
/* No argument. Use a default 0 value. */ /* No argument. Use a default 0 value. */
PyErr_Clear(); PyErr_Clear( );
py_pos = NULL; py_pos = NULL;
} }
a_position = position_py_to_c(py_pos); a_position = position_py_to_c( py_pos );
if ( !a_position ) if( !a_position )
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_stop(SELF->mc, a_position, exception); mediacontrol_stop( SELF->mc, a_position, exception );
free(a_position); free( a_position );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static PyObject *MediaControl_exit(PyObject *self, PyObject *args) static PyObject *
MediaControl_exit( PyObject *self, PyObject *args )
{ {
mediacontrol_exit(SELF->mc); mediacontrol_exit( SELF->mc );
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static PyObject *MediaControl_playlist_add_item(PyObject *self, PyObject *args) static PyObject *
MediaControl_playlist_add_item( PyObject *self, PyObject *args )
{ {
char *psz_file; char *psz_file;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
if ( !PyArg_ParseTuple(args, "s", &psz_file) ) if( !PyArg_ParseTuple( args, "s", &psz_file ) )
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_playlist_add_item(SELF->mc, psz_file, exception); mediacontrol_playlist_add_item( SELF->mc, psz_file, exception );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static PyObject * MediaControl_playlist_clear( PyObject *self, static PyObject *
PyObject *args) MediaControl_playlist_clear( PyObject *self, PyObject *args )
{ {
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_playlist_clear(SELF->mc, exception); mediacontrol_playlist_clear( SELF->mc, exception );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static PyObject * MediaControl_playlist_get_list( PyObject *self, static PyObject *
PyObject *args ) MediaControl_playlist_get_list( PyObject *self, PyObject *args )
{ {
PyObject *py_retval; PyObject *py_retval;
mediacontrol_Exception *exception = NULL; mediacontrol_Exception *exception = NULL;
...@@ -998,7 +1017,7 @@ static PyObject * MediaControl_playlist_get_list( PyObject *self, ...@@ -998,7 +1017,7 @@ static PyObject * MediaControl_playlist_get_list( PyObject *self,
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
pl = mediacontrol_playlist_get_list(SELF->mc, exception); pl = mediacontrol_playlist_get_list( SELF->mc, exception );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
...@@ -1006,38 +1025,39 @@ static PyObject * MediaControl_playlist_get_list( PyObject *self, ...@@ -1006,38 +1025,39 @@ static PyObject * MediaControl_playlist_get_list( PyObject *self,
py_retval = PyList_New( i_playlist_size ); py_retval = PyList_New( i_playlist_size );
for (i_index = 0 ; i_index < i_playlist_size ; i_index++) for ( i_index = 0 ; i_index < i_playlist_size ; i_index++ )
{ {
PyList_SetItem( py_retval, i_index, PyList_SetItem( py_retval, i_index,
Py_BuildValue("s", pl->data[i_index] ) ); Py_BuildValue( "s", pl->data[i_index] ) );
} }
mediacontrol_PlaylistSeq__free(pl); mediacontrol_PlaylistSeq__free( pl );
return py_retval; return py_retval;
} }
static PyObject * MediaControl_snapshot(PyObject *self, PyObject *args) static PyObject *
MediaControl_snapshot( PyObject *self, PyObject *args )
{ {
mediacontrol_RGBPicture *retval = NULL; mediacontrol_RGBPicture *p_retval = NULL;
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
mediacontrol_Position *a_position = NULL; mediacontrol_Position *a_position = NULL;
PyObject *py_pos = NULL; PyObject *py_pos = NULL;
PyObject *py_obj = NULL; PyObject *py_obj = NULL;
if( !PyArg_ParseTuple(args, "O", &py_pos)) if( !PyArg_ParseTuple( args, "O", &py_pos ) )
return NULL; return NULL;
a_position = position_py_to_c(py_pos); a_position = position_py_to_c( py_pos );
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
retval = mediacontrol_snapshot(SELF->mc, a_position, exception); p_retval = mediacontrol_snapshot( SELF->mc, a_position, exception );
free( a_position ); free( a_position );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
if( !retval ) if( !p_retval )
{ {
Py_INCREF( Py_None ); Py_INCREF( Py_None );
return Py_None; return Py_None;
...@@ -1046,20 +1066,20 @@ static PyObject * MediaControl_snapshot(PyObject *self, PyObject *args) ...@@ -1046,20 +1066,20 @@ static PyObject * MediaControl_snapshot(PyObject *self, PyObject *args)
/* FIXME: create a real RGBPicture object */ /* FIXME: create a real RGBPicture object */
py_obj = PyDict_New(); py_obj = PyDict_New();
PyDict_SetItemString(py_obj, "width", PyDict_SetItemString( py_obj, "width",
Py_BuildValue("i", retval->width) ); Py_BuildValue( "i", p_retval->width ) );
PyDict_SetItemString(py_obj, "height", PyDict_SetItemString( py_obj, "height",
Py_BuildValue("i", retval->height) ); Py_BuildValue( "i", p_retval->height ) );
PyDict_SetItemString(py_obj, "type", PyDict_SetItemString( py_obj, "type",
Py_BuildValue("i", retval->type) ); Py_BuildValue( "i", p_retval->type ) );
PyDict_SetItemString(py_obj, "data", PyDict_SetItemString( py_obj, "data",
Py_BuildValue("s#", retval->data, retval->size) ); Py_BuildValue( "s#", p_retval->data, p_retval->size ) );
/* Py_INCREF(py_obj); */
return py_obj; return py_obj;
} }
static PyObject* MediaControl_display_text(PyObject *self, PyObject *args) static PyObject*
MediaControl_display_text( PyObject *self, PyObject *args )
{ {
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
PyObject *py_begin, *py_end; PyObject *py_begin, *py_end;
...@@ -1067,27 +1087,27 @@ static PyObject* MediaControl_display_text(PyObject *self, PyObject *args) ...@@ -1067,27 +1087,27 @@ static PyObject* MediaControl_display_text(PyObject *self, PyObject *args)
mediacontrol_Position * begin; mediacontrol_Position * begin;
mediacontrol_Position * end; mediacontrol_Position * end;
if( !PyArg_ParseTuple(args, "sOO", &message, &py_begin, &py_end)) if( !PyArg_ParseTuple( args, "sOO", &message, &py_begin, &py_end ) )
return NULL; return NULL;
begin = position_py_to_c(py_begin); begin = position_py_to_c( py_begin );
end = position_py_to_c(py_end); end = position_py_to_c( py_end );
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_display_text(SELF->mc, message, begin, end, exception); mediacontrol_display_text( SELF->mc, message, begin, end, exception );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
free(begin); free( begin );
free(end); free( end );
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static PyObject* MediaControl_get_stream_information( static PyObject*
PyObject *self, PyObject *args) MediaControl_get_stream_information( PyObject *self, PyObject *args )
{ {
mediacontrol_StreamInformation *retval = NULL; mediacontrol_StreamInformation *retval = NULL;
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
...@@ -1096,48 +1116,49 @@ static PyObject* MediaControl_get_stream_information( ...@@ -1096,48 +1116,49 @@ static PyObject* MediaControl_get_stream_information(
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
retval = mediacontrol_get_stream_information( retval = mediacontrol_get_stream_information(
SELF->mc, mediacontrol_MediaTime, exception); SELF->mc, mediacontrol_MediaTime, exception );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
py_obj = PyDict_New(); py_obj = PyDict_New( );
/* FIXME: create a real StreamInformation object */ /* FIXME: create a real StreamInformation object */
PyDict_SetItemString(py_obj, "status", PyDict_SetItemString( py_obj, "status",
Py_BuildValue("i", retval->streamstatus)); Py_BuildValue( "i", retval->streamstatus ) );
PyDict_SetItemString(py_obj, "url", PyDict_SetItemString( py_obj, "url",
Py_BuildValue("s", retval->url)); Py_BuildValue( "s", retval->url ) );
PyDict_SetItemString(py_obj, "position", PyDict_SetItemString( py_obj, "position",
Py_BuildValue("L", retval->position)); Py_BuildValue( "L", retval->position ) );
PyDict_SetItemString(py_obj, "length", PyDict_SetItemString( py_obj, "length",
Py_BuildValue("L", retval->length)); Py_BuildValue( "L", retval->length ) );
free(retval->url); free( retval->url );
free(retval); free( retval );
/* Py_INCREF(py_obj); */
return py_obj; return py_obj;
} }
static PyObject* MediaControl_sound_set_volume(PyObject *self, PyObject *args) static PyObject*
MediaControl_sound_set_volume( PyObject *self, PyObject *args )
{ {
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
unsigned short volume; unsigned short volume;
if (!PyArg_ParseTuple(args, "H", &volume)) if( !PyArg_ParseTuple( args, "H", &volume ) )
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_sound_set_volume(SELF->mc, volume, exception); mediacontrol_sound_set_volume( SELF->mc, volume, exception );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static PyObject* MediaControl_sound_get_volume(PyObject *self, PyObject *args) static PyObject*
MediaControl_sound_get_volume( PyObject *self, PyObject *args )
{ {
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
PyObject *py_retval; PyObject *py_retval;
...@@ -1145,78 +1166,79 @@ static PyObject* MediaControl_sound_get_volume(PyObject *self, PyObject *args) ...@@ -1145,78 +1166,79 @@ static PyObject* MediaControl_sound_get_volume(PyObject *self, PyObject *args)
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
volume=mediacontrol_sound_get_volume(SELF->mc, exception); volume = mediacontrol_sound_get_volume( SELF->mc, exception );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
py_retval = Py_BuildValue("H", volume); py_retval = Py_BuildValue( "H", volume );
return py_retval; return py_retval;
} }
static PyObject* MediaControl_set_visual(PyObject *self, PyObject *args) static PyObject*
MediaControl_set_visual( PyObject *self, PyObject *args )
{ {
mediacontrol_Exception* exception = NULL; mediacontrol_Exception* exception = NULL;
WINDOWHANDLE visual; WINDOWHANDLE visual;
if (!PyArg_ParseTuple(args, "i", &visual)) if( !PyArg_ParseTuple( args, "i", &visual ) )
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
mediacontrol_set_visual(SELF->mc, visual, exception); mediacontrol_set_visual( SELF->mc, visual, exception );
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
MC_EXCEPT; MC_EXCEPT;
Py_INCREF(Py_None); Py_INCREF( Py_None );
return Py_None; return Py_None;
} }
static PyMethodDef MediaControl_methods[] = static PyMethodDef MediaControl_methods[] =
{ {
{"get_media_position", MediaControl_get_media_position, METH_VARARGS, {"get_media_position", MediaControl_get_media_position, METH_VARARGS,
"get_media_position(origin, key) -> Position Get current media position." }, "get_media_position( origin, key ) -> Position Get current media position." },
{ "set_media_position", MediaControl_set_media_position, METH_VARARGS, { "set_media_position", MediaControl_set_media_position, METH_VARARGS,
"set_media_position(Position) Set media position" }, "set_media_position( Position ) Set media position" },
{ "start", MediaControl_start, METH_VARARGS, { "start", MediaControl_start, METH_VARARGS,
"start(Position) Start the player." }, "start( Position ) Start the player." },
{ "pause", MediaControl_pause, METH_VARARGS, { "pause", MediaControl_pause, METH_VARARGS,
"pause(Position) Pause the player." }, "pause( Position ) Pause the player." },
{ "resume", MediaControl_resume, METH_VARARGS, { "resume", MediaControl_resume, METH_VARARGS,
"resume(Position) Resume the player" }, "resume( Position ) Resume the player" },
{ "stop", MediaControl_stop, METH_VARARGS, { "stop", MediaControl_stop, METH_VARARGS,
"stop(Position) Stop the player" }, "stop( Position ) Stop the player" },
{ "exit", MediaControl_exit, METH_VARARGS, { "exit", MediaControl_exit, METH_VARARGS,
"exit() Exit the player" }, "exit( ) Exit the player" },
{ "playlist_add_item", MediaControl_playlist_add_item, METH_VARARGS, { "playlist_add_item", MediaControl_playlist_add_item, METH_VARARGS,
"playlist_add_item(str) Add an item to the playlist" }, "playlist_add_item( str ) Add an item to the playlist" },
{ "playlist_get_list", MediaControl_playlist_get_list, METH_VARARGS, { "playlist_get_list", MediaControl_playlist_get_list, METH_VARARGS,
"playlist_get_list() -> list Get the contents of the playlist" }, "playlist_get_list( ) -> list Get the contents of the playlist" },
{ "playlist_clear", MediaControl_playlist_clear, METH_VARARGS, { "playlist_clear", MediaControl_playlist_clear, METH_VARARGS,
"clear() Clear the playlist." }, "clear( ) Clear the playlist." },
{ "snapshot", MediaControl_snapshot, METH_VARARGS, { "snapshot", MediaControl_snapshot, METH_VARARGS,
"snapshot(Position) -> dict Take a snapshot" }, "snapshot( Position ) -> dict Take a snapshot" },
{ "display_text", MediaControl_display_text, METH_VARARGS, { "display_text", MediaControl_display_text, METH_VARARGS,
"display_text(str, Position, Position) Display a text on the video" }, "display_text( str, Position, Position ) Display a text on the video" },
{ "get_stream_information", MediaControl_get_stream_information, { "get_stream_information", MediaControl_get_stream_information,
METH_VARARGS, METH_VARARGS,
"get_stream_information() -> dict Get information about the stream"}, "get_stream_information( ) -> dict Get information about the stream"},
{ "sound_get_volume", MediaControl_sound_get_volume, METH_VARARGS, { "sound_get_volume", MediaControl_sound_get_volume, METH_VARARGS,
"sound_get_volume() -> int Get the volume" }, "sound_get_volume( ) -> int Get the volume" },
{ "sound_set_volume", MediaControl_sound_set_volume, METH_VARARGS, { "sound_set_volume", MediaControl_sound_set_volume, METH_VARARGS,
"sound_set_volume(int) Set the volume" }, "sound_set_volume( int ) Set the volume" },
{ "set_visual", MediaControl_set_visual, METH_VARARGS, { "set_visual", MediaControl_set_visual, METH_VARARGS,
"set_visual(int) Set the embedding window visual ID" }, "set_visual( int ) Set the embedding window visual ID" },
{ NULL, NULL, 0, NULL }, { NULL, NULL, 0, NULL },
}; };
static PyTypeObject MediaControl_Type = static PyTypeObject MediaControl_Type =
{ {
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT( NULL )
0, /*ob_size*/ 0, /*ob_size*/
"vlc.MediaControl", /*tp_name*/ "vlc.MediaControl", /*tp_name*/
sizeof(MediaControl_Type), /*tp_basicsize*/ sizeof( MediaControl_Type ), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor)MediaControl_dealloc, /*tp_dealloc*/ ( destructor )MediaControl_dealloc, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
...@@ -1257,7 +1279,8 @@ static PyTypeObject MediaControl_Type = ...@@ -1257,7 +1279,8 @@ static PyTypeObject MediaControl_Type =
***********************************************************************/ ***********************************************************************/
static int PyPosition_init( PyPosition *self, PyObject *args, PyObject *kwds ) static int
PyPosition_init( PyPosition *self, PyObject *args, PyObject *kwds )
{ {
self->origin = mediacontrol_AbsolutePosition; self->origin = mediacontrol_AbsolutePosition;
self->key = mediacontrol_MediaTime; self->key = mediacontrol_MediaTime;
...@@ -1265,63 +1288,65 @@ static int PyPosition_init( PyPosition *self, PyObject *args, PyObject *kwds ) ...@@ -1265,63 +1288,65 @@ static int PyPosition_init( PyPosition *self, PyObject *args, PyObject *kwds )
return 0; return 0;
} }
mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key ) mediacontrol_PositionKey
positionKey_py_to_c( PyObject * py_key )
{ {
mediacontrol_PositionKey key_position = mediacontrol_MediaTime; mediacontrol_PositionKey key_position = mediacontrol_MediaTime;
int key; int key;
if( !PyArg_Parse( py_key, "i", &key ) ) if( !PyArg_Parse( py_key, "i", &key ) )
{ {
PyErr_SetString (MediaControl_InternalException, "Invalid key value"); PyErr_SetString ( MediaControl_InternalException, "Invalid key value" );
return key_position; return key_position;
} }
switch (key) switch ( key )
{ {
case 0: key = mediacontrol_ByteCount; break; case 0: key = mediacontrol_ByteCount; break;
case 1: key = mediacontrol_SampleCount; break; case 1: key = mediacontrol_SampleCount; break;
case 2: key = mediacontrol_MediaTime; break; case 2: key = mediacontrol_MediaTime; break;
} }
return key_position; return key_position;
} }
mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin ) mediacontrol_PositionOrigin
positionOrigin_py_to_c( PyObject * py_origin )
{ {
mediacontrol_PositionOrigin origin_position = mediacontrol_PositionOrigin origin_position = mediacontrol_AbsolutePosition;
mediacontrol_AbsolutePosition;
int origin; int origin;
if(!PyArg_Parse(py_origin,"i", &origin)) if( !PyArg_Parse( py_origin,"i", &origin ) )
{ {
PyErr_SetString( MediaControl_InternalException, PyErr_SetString( MediaControl_InternalException,
"Invalid origin value"); "Invalid origin value" );
return origin_position; return origin_position;
} }
switch (origin) switch ( origin )
{ {
case 0: origin_position = mediacontrol_AbsolutePosition; break; case 0: origin_position = mediacontrol_AbsolutePosition; break;
case 1: origin_position = mediacontrol_RelativePosition; break; case 1: origin_position = mediacontrol_RelativePosition; break;
case 2: origin_position = mediacontrol_ModuloPosition; break; case 2: origin_position = mediacontrol_ModuloPosition; break;
} }
return origin_position; return origin_position;
} }
/* Methods for transforming the Position Python object to Position structure*/ /* Methods for transforming the Position Python object to Position structure*/
mediacontrol_Position* position_py_to_c( PyObject * py_position ) mediacontrol_Position*
position_py_to_c( PyObject * py_position )
{ {
mediacontrol_Position * a_position = NULL; mediacontrol_Position * a_position = NULL;
PyPosition *pos = (PyPosition*)py_position; PyPosition *pos = ( PyPosition* )py_position;
a_position = (mediacontrol_Position*)malloc(sizeof(mediacontrol_Position)); a_position = ( mediacontrol_Position* )malloc( sizeof( mediacontrol_Position ) );
if (! a_position) if( !a_position )
{ {
PyErr_SetString(PyExc_MemoryError, "Out of memory"); PyErr_SetString( PyExc_MemoryError, "Out of memory" );
return NULL; return NULL;
} }
if (! py_position) if( !py_position )
{ {
/* If we give a NULL value, it will be considered as /* If we give a NULL value, it will be considered as
a 0 relative position in mediatime */ a 0 relative position in mediatime */
...@@ -1329,7 +1354,7 @@ mediacontrol_Position* position_py_to_c( PyObject * py_position ) ...@@ -1329,7 +1354,7 @@ mediacontrol_Position* position_py_to_c( PyObject * py_position )
a_position->key = mediacontrol_MediaTime; a_position->key = mediacontrol_MediaTime;
a_position->value = 0; a_position->value = 0;
} }
else if (PyObject_IsInstance(py_position, (PyObject*)&PyPosition_Type)) else if( PyObject_IsInstance( py_position, ( PyObject* )&PyPosition_Type ) )
{ {
a_position->origin = pos->origin; a_position->origin = pos->origin;
a_position->key = pos->key; a_position->key = pos->key;
...@@ -1341,16 +1366,17 @@ mediacontrol_Position* position_py_to_c( PyObject * py_position ) ...@@ -1341,16 +1366,17 @@ mediacontrol_Position* position_py_to_c( PyObject * py_position )
a relative position in mediatime */ a relative position in mediatime */
a_position->origin = mediacontrol_RelativePosition; a_position->origin = mediacontrol_RelativePosition;
a_position->key = mediacontrol_MediaTime; a_position->key = mediacontrol_MediaTime;
a_position->value = PyLong_AsLongLong(py_position); a_position->value = PyLong_AsLongLong( py_position );
} }
return a_position; return a_position;
} }
PyPosition* position_c_to_py(mediacontrol_Position *position) PyPosition*
position_c_to_py( mediacontrol_Position *position )
{ {
PyPosition* py_retval; PyPosition* py_retval;
py_retval = PyObject_New(PyPosition, &PyPosition_Type); py_retval = PyObject_New( PyPosition, &PyPosition_Type );
py_retval->origin = position->origin; py_retval->origin = position->origin;
py_retval->key = position->key; py_retval->key = position->key;
py_retval->value = position->value; py_retval->value = position->value;
...@@ -1365,18 +1391,18 @@ static PyMethodDef PyPosition_methods[] = ...@@ -1365,18 +1391,18 @@ static PyMethodDef PyPosition_methods[] =
static PyMemberDef PyPosition_members[] = static PyMemberDef PyPosition_members[] =
{ {
{ "origin", T_INT, offsetof(PyPosition, origin), 0, "Position origin" }, { "origin", T_INT, offsetof( PyPosition, origin ), 0, "Position origin" },
{ "key", T_INT, offsetof(PyPosition, key), 0, "Position key" }, { "key", T_INT, offsetof( PyPosition, key ), 0, "Position key" },
{ "value", T_ULONG, offsetof(PyPosition, value), 0, "Position value" }, { "value", T_ULONG, offsetof( PyPosition, value ), 0, "Position value" },
{ NULL } /* Sentinel */ { NULL } /* Sentinel */
}; };
static PyTypeObject PyPosition_Type = static PyTypeObject PyPosition_Type =
{ {
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT( NULL )
0, /*ob_size*/ 0, /*ob_size*/
"vlc.Position", /*tp_name*/ "vlc.Position", /*tp_name*/
sizeof(PyPosition_Type), /*tp_basicsize*/ sizeof( PyPosition_Type ), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
0, /*tp_dealloc*/ 0, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
...@@ -1409,7 +1435,7 @@ static PyTypeObject PyPosition_Type = ...@@ -1409,7 +1435,7 @@ static PyTypeObject PyPosition_Type =
0, /* tp_descr_get */ 0, /* tp_descr_get */
0, /* tp_descr_set */ 0, /* tp_descr_set */
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
(initproc)PyPosition_init, /* tp_init */ ( initproc )PyPosition_init, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
0, /* tp_new */ 0, /* tp_new */
}; };
...@@ -25,9 +25,6 @@ ...@@ -25,9 +25,6 @@
#include <Python.h> #include <Python.h>
#include "structmember.h" #include "structmember.h"
/* Undefine the following define to disable low-level vlc Object support */
#define VLCOBJECT_SUPPORT 0
#define __VLC__ #define __VLC__
#include <stdio.h> #include <stdio.h>
...@@ -44,9 +41,9 @@ ...@@ -44,9 +41,9 @@
#define MC_TRY exception=mediacontrol_exception_init(exception) #define MC_TRY exception=mediacontrol_exception_init(exception)
#define MC_EXCEPT \ #define MC_EXCEPT \
if (exception->code) { \ if( exception->code ) { \
PyObject *py_exc = MediaControl_InternalException; \ PyObject *py_exc = MediaControl_InternalException; \
switch (exception->code) { \ switch( exception->code ) { \
case mediacontrol_InternalException: \ case mediacontrol_InternalException: \
py_exc = MediaControl_InternalException; \ py_exc = MediaControl_InternalException; \
break; \ break; \
...@@ -63,10 +60,10 @@ ...@@ -63,10 +60,10 @@
py_exc = MediaControl_PositionOriginNotSupported; \ py_exc = MediaControl_PositionOriginNotSupported; \
break; \ break; \
} \ } \
PyErr_SetString(py_exc, exception->message); \ PyErr_SetString( py_exc, exception->message ); \
mediacontrol_exception_free(exception); \ mediacontrol_exception_free( exception ); \
return NULL; \ return NULL; \
} else { mediacontrol_exception_free(exception); } } else { mediacontrol_exception_free( exception ); }
PyObject *MediaControl_InternalException; PyObject *MediaControl_InternalException;
PyObject *MediaControl_PositionKeyNotSupported; PyObject *MediaControl_PositionKeyNotSupported;
...@@ -77,9 +74,7 @@ PyObject *MediaControl_PlaylistException; ...@@ -77,9 +74,7 @@ PyObject *MediaControl_PlaylistException;
/********************************************************************** /**********************************************************************
* VLC Object * VLC Object
**********************************************************************/ **********************************************************************/
#ifdef VLCOBJECT_SUPPORT #define VLCSELF ( ( vlcObject* )self )
#define VLCSELF ((vlcObject*)self)
/********************************************************************** /**********************************************************************
* VLCObject Object * VLCObject Object
...@@ -93,8 +88,6 @@ typedef struct ...@@ -93,8 +88,6 @@ typedef struct
staticforward PyTypeObject vlcObject_Type; staticforward PyTypeObject vlcObject_Type;
#endif
/********************************************************************** /**********************************************************************
* MediaControl Object * MediaControl Object
**********************************************************************/ **********************************************************************/
...@@ -121,5 +114,5 @@ staticforward PyTypeObject PyPosition_Type; ...@@ -121,5 +114,5 @@ staticforward PyTypeObject PyPosition_Type;
mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key ); mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key );
mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin ); mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin );
mediacontrol_Position* position_py_to_c( PyObject * py_position ); mediacontrol_Position * position_py_to_c( PyObject * py_position );
PyPosition* position_c_to_py(mediacontrol_Position *position); PyPosition * position_c_to_py( mediacontrol_Position * position );
...@@ -41,22 +41,22 @@ extern "C" { ...@@ -41,22 +41,22 @@ extern "C" {
*************************************************************************/ *************************************************************************/
typedef struct { typedef struct {
int width; int width;
int height; int height;
long type; long type;
vlc_int64_t date; vlc_int64_t date;
int size; int size;
char *data; char *data;
} mediacontrol_RGBPicture; } mediacontrol_RGBPicture;
typedef struct { typedef struct {
int size; int size;
char **data; char **data;
} mediacontrol_PlaylistSeq; } mediacontrol_PlaylistSeq;
typedef struct { typedef struct {
int code; int code;
char *message; char *message;
} mediacontrol_Exception; } mediacontrol_Exception;
/* Exception codes */ /* Exception codes */
...@@ -116,8 +116,7 @@ mediacontrol_Instance * ...@@ -116,8 +116,7 @@ mediacontrol_Instance *
mediacontrol_new_from_object( int vlc_object_id, mediacontrol_new_from_object( int vlc_object_id,
mediacontrol_Exception *exception ); mediacontrol_Exception *exception );
mediacontrol_Position * mediacontrol_Position * mediacontrol_get_media_position(
mediacontrol_get_media_position(
mediacontrol_Instance *self, mediacontrol_Instance *self,
const mediacontrol_PositionOrigin an_origin, const mediacontrol_PositionOrigin an_origin,
const mediacontrol_PositionKey a_key, const mediacontrol_PositionKey a_key,
...@@ -132,7 +131,7 @@ void mediacontrol_start( mediacontrol_Instance *self, ...@@ -132,7 +131,7 @@ void mediacontrol_start( mediacontrol_Instance *self,
mediacontrol_Exception *exception ); mediacontrol_Exception *exception );
void mediacontrol_pause( mediacontrol_Instance *self, void mediacontrol_pause( mediacontrol_Instance *self,
const mediacontrol_Position *a_position, const mediacontrol_Position *a_position,
mediacontrol_Exception *exception ); mediacontrol_Exception *exception );
void mediacontrol_resume( mediacontrol_Instance *self, void mediacontrol_resume( mediacontrol_Instance *self,
...@@ -170,8 +169,8 @@ mediacontrol_RGBPicture ** ...@@ -170,8 +169,8 @@ mediacontrol_RGBPicture **
/* Displays the message string, between "begin" and "end" positions */ /* Displays the message string, between "begin" and "end" positions */
void mediacontrol_display_text( mediacontrol_Instance *self, void mediacontrol_display_text( mediacontrol_Instance *self,
const char *message, const char *message,
const mediacontrol_Position *begin, const mediacontrol_Position *begin,
const mediacontrol_Position *end, const mediacontrol_Position *end,
mediacontrol_Exception *exception ); mediacontrol_Exception *exception );
......
...@@ -29,24 +29,23 @@ extern "C" { ...@@ -29,24 +29,23 @@ extern "C" {
# endif # endif
typedef enum { typedef enum {
mediacontrol_AbsolutePosition, mediacontrol_AbsolutePosition,
mediacontrol_RelativePosition, mediacontrol_RelativePosition,
mediacontrol_ModuloPosition mediacontrol_ModuloPosition
} mediacontrol_PositionOrigin; } mediacontrol_PositionOrigin;
typedef enum { typedef enum {
mediacontrol_ByteCount, mediacontrol_ByteCount,
mediacontrol_SampleCount, mediacontrol_SampleCount,
mediacontrol_MediaTime mediacontrol_MediaTime
} mediacontrol_PositionKey; } mediacontrol_PositionKey;
typedef struct { typedef struct {
mediacontrol_PositionOrigin origin; mediacontrol_PositionOrigin origin;
mediacontrol_PositionKey key; mediacontrol_PositionKey key;
long value; long value;
} mediacontrol_Position; } mediacontrol_Position;
# ifdef __cplusplus # ifdef __cplusplus
} }
# endif # endif
......
...@@ -31,12 +31,11 @@ extern "C" { ...@@ -31,12 +31,11 @@ extern "C" {
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include "vlc/control_structures.h" #include "vlc/control_structures.h"
typedef struct { typedef struct {
vlc_object_t *p_vlc; vlc_object_t *p_vlc;
playlist_t *p_playlist; playlist_t *p_playlist;
intf_thread_t *p_intf; intf_thread_t *p_intf;
int vlc_object_id; int vlc_object_id;
} mediacontrol_Instance; } mediacontrol_Instance;
vlc_int64_t mediacontrol_unit_convert( input_thread_t *p_input, vlc_int64_t mediacontrol_unit_convert( input_thread_t *p_input,
...@@ -44,9 +43,8 @@ vlc_int64_t mediacontrol_unit_convert( input_thread_t *p_input, ...@@ -44,9 +43,8 @@ vlc_int64_t mediacontrol_unit_convert( input_thread_t *p_input,
mediacontrol_PositionKey to, mediacontrol_PositionKey to,
vlc_int64_t value ); vlc_int64_t value );
vlc_int64_t mediacontrol_position2microsecond( vlc_int64_t mediacontrol_position2microsecond(
input_thread_t *p_input, input_thread_t *p_input,
const mediacontrol_Position *pos ); const mediacontrol_Position *pos );
# ifdef __cplusplus # ifdef __cplusplus
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment