]> git.sesse.net Git - vlc/commitdiff
python bindings: changes from the libvlc API: a MediaControl can now be created from...
authorOlivier Aubert <olivier.aubert@liris.cnrs.fr>
Fri, 22 Sep 2006 10:43:15 +0000 (10:43 +0000)
committerOlivier Aubert <olivier.aubert@liris.cnrs.fr>
Fri, 22 Sep 2006 10:43:15 +0000 (10:43 +0000)
bindings/mediacontrol-python/README
bindings/mediacontrol-python/setup.py
bindings/mediacontrol-python/vlc_instance.c
bindings/mediacontrol-python/vlc_mediacontrol.c

index 32c22933f34c63042f484002d9c4497db016f67d..2b5d71907e9d2efedd904da2dea5d88c9fb5e0bf 100644 (file)
@@ -1,10 +1,9 @@
-* 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 
index b681f9ef58e46fbde9da6864c890216417cf032f..e30e1e8cc4edfe190a0d6c4daacc824f3ec86151 100644 (file)
@@ -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,
index 7cc9567759c28d2d3058cc011c23f539aa413723..56a68e81717501d93533cc45326b87d776aa0a23 100644 (file)
@@ -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)" },
index 0722e224e57192605827dc2de044a8cbb4b4a34d..6c60d0b33acf6cc9d5b528f16455639fa18a457d 100644 (file)
  * 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,