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
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
the extension module.
the extension module (and are hardcoded for a standard installation,
i.e. /usr/lib/vlc on *NIX)
For vlc.MediaControl:
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:
i=vlc.Instance('--plugin-path /path/to/vlc/directory'.split())
* Skeleton generation :
* Skeleton generation (for developpers of the module):
** 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
** 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' ]
# To compile in a local vlc tree
vlclocal = Extension('vlc',
sources = [ os.path.join( srcdir, f ) for f in source_files ] +
[ os.path.join( top_builddir, 'src/control/mediacontrol_init.c') ],
sources = [ os.path.join( srcdir, f ) for f in source_files ],
include_dirs = [ top_builddir,
os.path.join( top_builddir, 'include' ),
srcdir,
......
......@@ -443,8 +443,6 @@ vlcInstance_audio_set_volume( PyObject *self, PyObject *args )
return Py_None;
}
/* FIXME: add vlm related bindings here */
/* vlm_add_broadcast : name, input MRL, output MRL
Keywords: options, enable, loop */
static PyObject *
......@@ -693,7 +691,7 @@ static PyMethodDef vlcInstance_methods[] =
{ "audio_set_volume", vlcInstance_audio_set_volume, METH_VARARGS,
"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_del_media", vlcInstance_vlm_del_media, METH_VARARGS,
"vlm_del_media(name=str) Delete a media" },
......@@ -705,7 +703,7 @@ static PyMethodDef vlcInstance_methods[] =
"vlm_set_input(name=str, output=str) Set the input" },
{ "vlm_set_loop", vlcInstance_vlm_set_loop, METH_VARARGS,
"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_play_media", vlcInstance_vlm_play_media, METH_VARARGS,
"vlm_play_media(name=str)" },
......
......@@ -26,45 +26,56 @@
* VLC MediaControl object implementation
*****************************************************************************/
/* The MediaControl constructor takes either an existing vlc.Instance or a
list of strings */
static PyObject *
MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
{
MediaControl *self;
mediacontrol_Exception *exception = NULL;
PyObject* py_list = NULL;
PyObject* py_param = NULL;
char** ppsz_args = NULL;
fprintf(stderr, "mc_new start\n");
libvlc_instance_t* p_instance = NULL;
self = PyObject_New( MediaControl, &MediaControl_Type );
if( PyArg_ParseTuple( args, "O", &py_list ) )
if( PyArg_ParseTuple( args, "O", &py_param ) )
{
int i_size;
int i_index;
Py_INCREF( py_list );
if( ! PySequence_Check( py_list ) )
Py_INCREF( py_param );
if( PyObject_TypeCheck( py_param, &vlcInstance_Type ) == 1 )
{
PyErr_SetString( PyExc_TypeError, "Parameter must be a sequence." );
return NULL;
p_instance = ((vlcInstance*)py_param)->p_instance;
}
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++ )
else
{
ppsz_args[i_index] =
strdup( PyString_AsString( PyObject_Str(
PySequence_GetItem( py_list,
i_index ) ) ) );
int i_size;
int i_index;
if( ! PySequence_Check( py_param ) )
{
PyErr_SetString( PyExc_TypeError, "Parameter must be a vlc.Instance or a sequence of strings." );
Py_DECREF( py_param );
return NULL;
}
i_size = PySequence_Size( py_param );
ppsz_args = malloc( ( i_size + 1 ) * sizeof( char * ) );
if( ! ppsz_args )
{
PyErr_SetString( PyExc_MemoryError, "Out of memory" );
Py_DECREF( py_param );
return NULL;
}
for ( i_index = 0; i_index < i_size; i_index++ )
{
ppsz_args[i_index] =
strdup( PyString_AsString( PyObject_Str(
PySequence_GetItem( py_param,
i_index ) ) ) );
}
ppsz_args[i_size] = NULL;
}
ppsz_args[i_size] = NULL;
Py_DECREF( py_list );
Py_DECREF( py_param );
}
else
{
......@@ -73,16 +84,19 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
PyErr_Clear( );
}
fprintf(stderr, "before mc_new\n");
Py_BEGIN_ALLOW_THREADS
MC_TRY;
self->mc = mediacontrol_new( ppsz_args, exception );
if( p_instance )
{
self->mc = mediacontrol_new_from_instance( p_instance, exception );
}
else
{
self->mc = mediacontrol_new( ppsz_args, exception );
}
MC_EXCEPT;
Py_END_ALLOW_THREADS
fprintf(stderr, "mc_new end\n");
Py_INCREF( self );
return ( PyObject * )self;
}
......@@ -93,6 +107,18 @@ MediaControl_dealloc( PyObject *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
be relative or absolute ( according to PositionOrigin ) and the unit
......@@ -572,8 +598,10 @@ MediaControl_set_visual( PyObject *self, PyObject *args )
static PyMethodDef MediaControl_methods[] =
{
{"get_media_position", MediaControl_get_media_position, METH_VARARGS,
"get_media_position( origin, key ) -> Position Get current media position." },
{ "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." },
{ "set_media_position", MediaControl_set_media_position, METH_VARARGS,
"set_media_position( Position ) Set media position" },
{ "start", MediaControl_start, METH_VARARGS,
......
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