-* 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())
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
return Py_None;
}
-/* FIXME: add vlm related bindings here */
-
/* vlm_add_broadcast : name, input MRL, output MRL
Keywords: options, enable, loop */
static PyObject *
{ "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" },
"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)" },
* 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
{
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;
}
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
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,