[vlc-devel] code contribution
"?=Andrew Skiba=?koi8-r?Q?"
andrew_skiba at mail.ru
Wed May 12 23:38:22 CEST 2004
Hello.
I've made some changes to the python interface module, vlc/python/vlcmodule.c Those changes are:
* Added functions for VLC_Die and VLC_Destroy - a trivial change
* Added an option to pass VLC_Init any number of arguments (current CVS version always passes 3, first two of which are "vlc" and "--sout"). Note, that the old python code will continue to work correctly, as I check for a string parameter first, and if it's not a string, I try a tuple. The new format is used as following: vlc.init(0, ("--sout", "test.mpg") ) but it allows to ommit "--sout" or to pass a few parameters (I needed to broadcast the stream).
I had to omit the gettext macros _(...) which was the change between 1.4 and 1.5 of vlcmodule.c, because it did not compile. You can always return those macros to lines 149..157
Here follows the difference. Your last CVS version (vlc/python/vlcmodule.c,1.5) is called old.vlcmodule.c and the changed version is called vlcmodule.c
--- old.vlcmodule.c 2004-05-12 23:52:19.065414496 +0300
+++ vlcmodule.c 2004-05-12 23:48:18.329011992 +0300
@@ -16,13 +16,47 @@
static PyObject *vlc_init(PyObject *self, PyObject *args)
{
- int iVlc;
- char *pArgv[] = { "vlc", "--sout", NULL };
- int iRc;
+ int iVlc; //the first argument of VLC_Init
+ char **pArgv; //a variable-length vector for new version
+ char *oldArgv[]={"vlc","--sout",NULL}; //a const-length vector for old version
+ PyObject *arg2; //the second argument is either string or tuple, containing a few strings
+ int count; //count of a variable-length vector
+ int iRc; //the return value of VLC_Init
+ int i; //used for looping
+ PyObject *o; //used for extracting the tuple items
- if (!PyArg_ParseTuple(args, "is", &iVlc, &pArgv[2]))
+ if(!PyArg_ParseTuple(args, "iO", &iVlc, &arg2))
+ return NULL;
+ if(PyString_Check(arg2)) //if we have a string, behave as before
+ {
+ oldArgv[2]=PyString_AsString(arg2);
+ if(!oldArgv[2])
+ return NULL;
+ count=3;
+ pArgv=oldArgv;
+ }
+ else if(PyTuple_Check(arg2)) //the second argument is a tuple
+ {
+ count = PyTuple_Size( arg2 );
+ pArgv = calloc( count, sizeof(char *) );
+ for( i = 0; i < count; i++ )
+ {
+ o=PyTuple_GetItem(arg2, i);
+ if( o == NULL)
+ return NULL;
+ if(! PyString_Check(o))
+ return NULL;
+ pArgv[i] = PyString_AsString(o);
+ }
+ }
+ else
+ {
+ PyErr_SetString(PyExc_TypeError, "a string or a typle is required for second argument");
return NULL;
- iRc = VLC_Init(iVlc, 3, pArgv);
+ }
+ iRc = VLC_Init(iVlc, count, pArgv);
+ if(pArgv != oldArgv)
+ free(pArgv);
return Py_BuildValue("i", iRc);
}
@@ -63,6 +97,41 @@
return Py_BuildValue("i", iRc);
}
+static PyObject *vlc_isplaying(PyObject *self, PyObject *args)
+{
+ int iVlc;
+ int iRc;
+
+ if (!PyArg_ParseTuple(args, "i", &iVlc))
+ return NULL;
+ iRc = VLC_IsPlaying(iVlc);
+ return Py_BuildValue("i", iRc);
+}
+
+
+static PyObject *vlc_die(PyObject *self, PyObject *args)
+{
+ int iVlc;
+ int iRc;
+
+ if (!PyArg_ParseTuple(args, "i", &iVlc))
+ return NULL;
+ iRc = VLC_Die(iVlc);
+ return Py_BuildValue("i", iRc);
+}
+
+static PyObject *vlc_destroy(PyObject *self, PyObject *args)
+{
+ int iVlc;
+ int iRc;
+
+ if (!PyArg_ParseTuple(args, "i", &iVlc))
+ return NULL;
+ iRc = VLC_Destroy(iVlc);
+ return Py_BuildValue("i", iRc);
+}
+
+
static PyObject *vlc_pause(PyObject *self, PyObject *args)
{
@@ -77,12 +146,15 @@
static PyMethodDef VlcMethods[] = {
- {"create", vlc_create, METH_VARARGS, _("Create a vlc thread.")},
- {"init", vlc_init, METH_VARARGS, _("Initialize a vlc thread.")},
- {"addTarget", vlc_addTarget, METH_VARARGS, _("Add a target in the playlist.")},
- {"play", vlc_play, METH_VARARGS, _("Play")},
- {"stop", vlc_stop, METH_VARARGS, _("Stop")},
- {"pause", vlc_pause, METH_VARARGS, _("Pause")},
+ {"create", vlc_create, METH_VARARGS, "Create a vlc thread."},
+ {"init", vlc_init, METH_VARARGS, "Initialize a vlc thread."},
+ {"addTarget", vlc_addTarget, METH_VARARGS, "Add a target in the playlist."},
+ {"play", vlc_play, METH_VARARGS, "Play"},
+ {"stop", vlc_stop, METH_VARARGS, "Stop"},
+ {"isplaying", vlc_isplaying, METH_VARARGS, "IsPlaying"},
+ {"pause", vlc_pause, METH_VARARGS, "Pause"},
+ {"die", vlc_stop, METH_VARARGS, "Die"},
+ {"destroy", vlc_stop, METH_VARARGS, "Destroy"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
--
This is the vlc-devel mailing-list, see http://www.videolan.org/vlc/
To unsubscribe, please read http://developers.videolan.org/lists.html
If you are in trouble, please contact <postmaster at videolan.org>
More information about the vlc-devel
mailing list