Commit 6880e8ec authored by Olivier Aubert's avatar Olivier Aubert

python bindings: changes from the libvlc API: a MediaControl can now be...

python bindings: changes from the libvlc API: a MediaControl can now be created from scratch (with a list of strings as parameters) or from an existing vlc.Instance. MediaControl.get_instance() return the associated vlc.Instance in all cases.
parent 673593dc
* Compilation
* Testing * Testing
If you try to compile the bindings from a development tree, you will If you try to compile the bindings from a development tree, you will
have to specify the path for VLC modules, which cannot be guessed by have to specify the path for VLC modules, which cannot be guessed by
the extension module. the extension module (and are hardcoded for a standard installation,
i.e. /usr/lib/vlc on *NIX)
For vlc.MediaControl: For vlc.MediaControl:
mc=vlc.MediaControl('--plugin-path /path/to/vlc/directory'.split()) mc=vlc.MediaControl('--plugin-path /path/to/vlc/directory'.split())
...@@ -12,11 +11,11 @@ mc=vlc.MediaControl('--plugin-path /path/to/vlc/directory'.split()) ...@@ -12,11 +11,11 @@ mc=vlc.MediaControl('--plugin-path /path/to/vlc/directory'.split())
For vlc.Instance: For vlc.Instance:
i=vlc.Instance('--plugin-path /path/to/vlc/directory'.split()) i=vlc.Instance('--plugin-path /path/to/vlc/directory'.split())
* Skeleton generation : * Skeleton generation (for developpers of the module):
** For method bindings: ** For method bindings:
perl -n -e 'print "static PyObject *\nvlcInput_$2( PyObject *self, PyObject *args )\n{\n libvlc_exception_t ex;\n LIBVLC_TRY;\n $1_$2( self->p_input, &ex); LIBVLC_EXCEPT;\n Py_INCREF( Py_None );\n return Py_None;\n}\n\n" if /(libvlc_input)_(\w+)/ and ($2 ne "t")' ../../include/vlc/libvlc.h perl -n -e 'print "static PyObject *\nvlcInput_$2( PyObject *self, PyObject *args )\n{\n libvlc_exception_t ex;\n LIBVLC_TRY;\n $1_$2( self->p_input, &ex); LIBVLC_EXCEPT;\n Py_INCREF( Py_None );\n return Py_None;\n}\n\n" if /(libvlc_input)_(\w+)/ and ($2 ne "t")' ../../include/vlc/libvlc.h
** For method table: ** For method table:
perl -n -e 'print " { \"$2\", $1_$2, METH_VARARGS,\n \"$2()\" },\n" if /^(vlcInput)_(\w+)/' vlc_instance.c perl -n -e 'print " { \"$2\", $1_$2, METH_VARARGS,\n \"$2()\" },\n" if /^(vlcInstance)_(\w+)/' vlc_instance.c
...@@ -75,8 +75,7 @@ source_files = [ 'vlc_module.c' ] ...@@ -75,8 +75,7 @@ source_files = [ 'vlc_module.c' ]
# To compile in a local vlc tree # To compile in a local vlc tree
vlclocal = Extension('vlc', vlclocal = Extension('vlc',
sources = [ os.path.join( srcdir, f ) for f in source_files ] + sources = [ os.path.join( srcdir, f ) for f in source_files ],
[ os.path.join( top_builddir, 'src/control/mediacontrol_init.c') ],
include_dirs = [ top_builddir, include_dirs = [ top_builddir,
os.path.join( top_builddir, 'include' ), os.path.join( top_builddir, 'include' ),
srcdir, srcdir,
......
...@@ -443,8 +443,6 @@ vlcInstance_audio_set_volume( PyObject *self, PyObject *args ) ...@@ -443,8 +443,6 @@ vlcInstance_audio_set_volume( PyObject *self, PyObject *args )
return Py_None; return Py_None;
} }
/* FIXME: add vlm related bindings here */
/* vlm_add_broadcast : name, input MRL, output MRL /* vlm_add_broadcast : name, input MRL, output MRL
Keywords: options, enable, loop */ Keywords: options, enable, loop */
static PyObject * static PyObject *
...@@ -693,7 +691,7 @@ static PyMethodDef vlcInstance_methods[] = ...@@ -693,7 +691,7 @@ static PyMethodDef vlcInstance_methods[] =
{ "audio_set_volume", vlcInstance_audio_set_volume, METH_VARARGS, { "audio_set_volume", vlcInstance_audio_set_volume, METH_VARARGS,
"audio_set_volume(volume=int) Set the audio volume"}, "audio_set_volume(volume=int) Set the audio volume"},
{ "vlm_add_broadcast", vlcInstance_vlm_add_broadcast, METH_KEYWORDS, { "vlm_add_broadcast", vlcInstance_vlm_add_broadcast, METH_VARARGS | METH_KEYWORDS,
"vlm_add_broadcast(name=str, input=str, output=str, options=list, enable=int, loop=int) Add a new broadcast" }, "vlm_add_broadcast(name=str, input=str, output=str, options=list, enable=int, loop=int) Add a new broadcast" },
{ "vlm_del_media", vlcInstance_vlm_del_media, METH_VARARGS, { "vlm_del_media", vlcInstance_vlm_del_media, METH_VARARGS,
"vlm_del_media(name=str) Delete a media" }, "vlm_del_media(name=str) Delete a media" },
...@@ -705,7 +703,7 @@ static PyMethodDef vlcInstance_methods[] = ...@@ -705,7 +703,7 @@ static PyMethodDef vlcInstance_methods[] =
"vlm_set_input(name=str, output=str) Set the input" }, "vlm_set_input(name=str, output=str) Set the input" },
{ "vlm_set_loop", vlcInstance_vlm_set_loop, METH_VARARGS, { "vlm_set_loop", vlcInstance_vlm_set_loop, METH_VARARGS,
"vlm_set_loop(name=str, loop=int) Change the looping value" }, "vlm_set_loop(name=str, loop=int) Change the looping value" },
{ "vlm_change_media", vlcInstance_vlm_change_media, METH_KEYWORDS, { "vlm_change_media", vlcInstance_vlm_change_media, METH_VARARGS | METH_KEYWORDS,
"vlm_change_media(name=str, input=str, output=str, options=list, enable=int, loop=int) Change the broadcast parameters" }, "vlm_change_media(name=str, input=str, output=str, options=list, enable=int, loop=int) Change the broadcast parameters" },
{ "vlm_play_media", vlcInstance_vlm_play_media, METH_VARARGS, { "vlm_play_media", vlcInstance_vlm_play_media, METH_VARARGS,
"vlm_play_media(name=str)" }, "vlm_play_media(name=str)" },
......
...@@ -26,33 +26,43 @@ ...@@ -26,33 +26,43 @@
* VLC MediaControl object implementation * VLC MediaControl object implementation
*****************************************************************************/ *****************************************************************************/
/* The MediaControl constructor takes either an existing vlc.Instance or a
list of strings */
static PyObject * static PyObject *
MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds ) 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_param = NULL;
char** ppsz_args = NULL; char** ppsz_args = NULL;
libvlc_instance_t* p_instance = NULL;
fprintf(stderr, "mc_new start\n");
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_param ) )
{
Py_INCREF( py_param );
if( PyObject_TypeCheck( py_param, &vlcInstance_Type ) == 1 )
{
p_instance = ((vlcInstance*)py_param)->p_instance;
}
else
{ {
int i_size; int i_size;
int i_index; int i_index;
Py_INCREF( py_list ); if( ! PySequence_Check( py_param ) )
if( ! PySequence_Check( py_list ) )
{ {
PyErr_SetString( PyExc_TypeError, "Parameter must be a sequence." ); PyErr_SetString( PyExc_TypeError, "Parameter must be a vlc.Instance or a sequence of strings." );
Py_DECREF( py_param );
return NULL; return NULL;
} }
i_size = PySequence_Size( py_list ); i_size = PySequence_Size( py_param );
ppsz_args = malloc( ( i_size + 1 ) * sizeof( char * ) ); ppsz_args = malloc( ( i_size + 1 ) * sizeof( char * ) );
if( ! ppsz_args ) if( ! ppsz_args )
{ {
PyErr_SetString( PyExc_MemoryError, "Out of memory" ); PyErr_SetString( PyExc_MemoryError, "Out of memory" );
Py_DECREF( py_param );
return NULL; return NULL;
} }
...@@ -60,11 +70,12 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds ) ...@@ -60,11 +70,12 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
{ {
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_param,
i_index ) ) ) ); i_index ) ) ) );
} }
ppsz_args[i_size] = NULL; ppsz_args[i_size] = NULL;
Py_DECREF( py_list ); }
Py_DECREF( py_param );
} }
else else
{ {
...@@ -73,16 +84,19 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds ) ...@@ -73,16 +84,19 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
PyErr_Clear( ); PyErr_Clear( );
} }
fprintf(stderr, "before mc_new\n");
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
if( p_instance )
{
self->mc = mediacontrol_new_from_instance( p_instance, exception );
}
else
{
self->mc = mediacontrol_new( ppsz_args, exception ); self->mc = mediacontrol_new( ppsz_args, exception );
}
MC_EXCEPT; MC_EXCEPT;
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
fprintf(stderr, "mc_new end\n");
Py_INCREF( self ); Py_INCREF( self );
return ( PyObject * )self; return ( PyObject * )self;
} }
...@@ -93,6 +107,18 @@ MediaControl_dealloc( PyObject *self ) ...@@ -93,6 +107,18 @@ MediaControl_dealloc( PyObject *self )
PyMem_DEL( self ); PyMem_DEL( self );
} }
static PyObject *
MediaControl_get_instance( PyObject *self, PyObject *args )
{
vlcInstance *p_ret;
p_ret = PyObject_New( vlcInstance, &vlcInstance_Type );
if( !p_ret )
return NULL;
p_ret->p_instance = mediacontrol_get_libvlc_instance( SELF->mc );
return ( PyObject * )p_ret;
}
/** /**
* Return 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
...@@ -572,7 +598,9 @@ MediaControl_set_visual( PyObject *self, PyObject *args ) ...@@ -572,7 +598,9 @@ MediaControl_set_visual( PyObject *self, PyObject *args )
static PyMethodDef MediaControl_methods[] = static PyMethodDef MediaControl_methods[] =
{ {
{"get_media_position", MediaControl_get_media_position, METH_VARARGS, { "get_instance", MediaControl_get_instance, METH_VARARGS,
"get_instance( ) -> Instance Get matching vlc.Instance." },
{ "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" },
......
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