X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=bindings%2Fpython%2Fvlc_instance.c;h=23459be8a1ac429388a4b8f497d639e6a8290f4f;hb=88fc2c2874b49d4a3619049480e15b0c23113287;hp=fbceaf8f84bad974853814b1fa65692b2d2bbf92;hpb=c9958ed21646465252d2d196e24beac4d1e91d02;p=vlc diff --git a/bindings/python/vlc_instance.c b/bindings/python/vlc_instance.c index fbceaf8f84..23459be8a1 100644 --- a/bindings/python/vlc_instance.c +++ b/bindings/python/vlc_instance.c @@ -23,13 +23,13 @@ #include "vlcglue.h" /* Helper functions */ -static int +static Py_ssize_t pyoptions_to_args(PyObject *py_options, char*** pppsz_args) { - int i_size; - int i_index; + Py_ssize_t i_size; + Py_ssize_t i_index; char** ppsz_args = *pppsz_args; - + ppsz_args = NULL; Py_INCREF( py_options ); @@ -82,9 +82,6 @@ vlcInstance_new( PyTypeObject *type, PyObject *args, PyObject *kwds ) char** ppsz_args = NULL; int i_size = 0; - self = PyObject_New( vlcInstance, &vlcInstance_Type ); - - if( PyArg_ParseTuple( args, "O", &py_list ) ) { i_size = pyoptions_to_args( py_list, &ppsz_args ); @@ -98,6 +95,8 @@ vlcInstance_new( PyTypeObject *type, PyObject *args, PyObject *kwds ) PyErr_Clear( ); } + self = PyObject_New( vlcInstance, &vlcInstance_Type ); + Py_BEGIN_ALLOW_THREADS LIBVLC_TRY LIBVLC_INSTANCE->p_instance = libvlc_new( i_size, ppsz_args, &ex ); @@ -112,9 +111,8 @@ vlcInstance_new( PyTypeObject *type, PyObject *args, PyObject *kwds ) static void vlcInstance_dealloc( PyObject *self ) { - libvlc_exception_t ex; - libvlc_destroy( LIBVLC_INSTANCE->p_instance, &ex ); - PyMem_DEL( self ); + libvlc_release( LIBVLC_INSTANCE->p_instance ); + PyObject_DEL( self ); } static PyObject * @@ -156,7 +154,7 @@ vlcInstance_playlist_play( PyObject *self, PyObject *args ) return NULL; if( py_options ) - { + { i_size = pyoptions_to_args( py_options, &ppsz_args ); } @@ -271,7 +269,7 @@ vlcInstance_playlist_add( PyObject *self, PyObject *args) } if( py_options ) - { + { i_size = pyoptions_to_args( py_options, &ppsz_args ); } @@ -316,18 +314,18 @@ vlcInstance_playlist_delete_item( PyObject *self, PyObject *args ) } static PyObject * -vlcInstance_playlist_get_input( PyObject *self, PyObject *args ) +vlcInstance_playlist_get_media_instance( PyObject *self, PyObject *args ) { libvlc_exception_t ex; - libvlc_input_t *p_input; - vlcInput *p_ret; + libvlc_media_instance_t *p_mi; + vlcMediaInstance *p_ret; LIBVLC_TRY; - p_input = libvlc_playlist_get_input( LIBVLC_INSTANCE->p_instance, &ex ); + p_mi = libvlc_playlist_get_media_instance( LIBVLC_INSTANCE->p_instance, &ex ); LIBVLC_EXCEPT; - p_ret = PyObject_New( vlcInput, &vlcInput_Type ); - p_ret->p_input = p_input; + p_ret = PyObject_New( vlcMediaInstance, &vlcMediaInstance_Type ); + p_ret->p_mi = p_mi; Py_INCREF( p_ret ); /* Ah bon ? */ return ( PyObject * )p_ret; } @@ -349,6 +347,19 @@ vlcInstance_video_set_parent( PyObject *self, PyObject *args ) return Py_None; } +static PyObject * +vlcInstance_video_get_parent( PyObject *self, PyObject *args ) +{ + libvlc_exception_t ex; + libvlc_drawable_t i_ret; + + LIBVLC_TRY; + i_ret = libvlc_video_get_parent( LIBVLC_INSTANCE->p_instance, &ex ); + LIBVLC_EXCEPT; + + return Py_BuildValue( "L", i_ret ); +} + static PyObject * vlcInstance_video_set_size( PyObject *self, PyObject *args ) { @@ -428,7 +439,7 @@ vlcInstance_audio_set_volume( PyObject *self, PyObject *args ) return NULL; LIBVLC_TRY; - libvlc_audio_set_mute( LIBVLC_INSTANCE->p_instance, i_volume, &ex ); + libvlc_audio_set_volume( LIBVLC_INSTANCE->p_instance, i_volume, &ex ); LIBVLC_EXCEPT; Py_INCREF( Py_None ); return Py_None; @@ -438,28 +449,25 @@ static PyObject * vlcInstance_audio_get_channel( PyObject *self, PyObject *args ) { libvlc_exception_t ex; - char* psz_ret; - PyObject* o_ret; + int i_ret; LIBVLC_TRY; - psz_ret = libvlc_audio_get_channel( LIBVLC_INSTANCE->p_instance, &ex ); + i_ret = libvlc_audio_get_channel( LIBVLC_INSTANCE->p_instance, &ex ); LIBVLC_EXCEPT; - o_ret=Py_BuildValue( "s", psz_ret ); - free( psz_ret ); - return o_ret; + return Py_BuildValue( "i", i_ret ); } static PyObject * vlcInstance_audio_set_channel( PyObject *self, PyObject *args ) { libvlc_exception_t ex; - char* psz_channel; + int i_channel; - if( !PyArg_ParseTuple( args, "s", &psz_channel ) ) + if( !PyArg_ParseTuple( args, "i", &i_channel ) ) return NULL; LIBVLC_TRY; - libvlc_audio_set_channel( LIBVLC_INSTANCE->p_instance, psz_channel, &ex ); + libvlc_audio_set_channel( LIBVLC_INSTANCE->p_instance, i_channel, &ex ); LIBVLC_EXCEPT; Py_INCREF( Py_None ); return Py_None; @@ -471,7 +479,7 @@ static PyObject * vlcInstance_vlm_add_broadcast( PyObject *self, PyObject *args, PyObject *kwds ) { libvlc_exception_t ex; - static char *kwlist[] = { "name", "input", "output", + static char *kwlist[] = { "name", "input", "output", "options", "enable", "loop", NULL}; char* psz_name = NULL; char* psz_input = NULL; @@ -482,19 +490,19 @@ vlcInstance_vlm_add_broadcast( PyObject *self, PyObject *args, PyObject *kwds ) int i_size = 0; char** ppsz_args = NULL; - if( !PyArg_ParseTupleAndKeywords( args, kwds, "sss|Oii", kwlist, + if( !PyArg_ParseTupleAndKeywords( args, kwds, "sss|Oii", kwlist, &psz_name, - &psz_input, &psz_output, - &py_options, &i_enable, &i_loop ) ) + &psz_input, &psz_output, + &py_options, &i_enable, &i_loop ) ) return NULL; - + if( py_options ) { i_size = pyoptions_to_args( py_options, &ppsz_args ); } - + LIBVLC_TRY; - libvlc_vlm_add_broadcast( LIBVLC_INSTANCE->p_instance, + libvlc_vlm_add_broadcast( LIBVLC_INSTANCE->p_instance, psz_name, psz_input, psz_output, i_size, ppsz_args, i_enable, i_loop, &ex); free_args( i_size, ppsz_args ); @@ -525,7 +533,7 @@ vlcInstance_vlm_set_enabled( PyObject *self, PyObject *args ) libvlc_exception_t ex; char* psz_name; int i_enabled; - + if( !PyArg_ParseTuple( args, "si", &psz_name, &i_enabled ) ) return NULL; @@ -542,7 +550,7 @@ vlcInstance_vlm_set_output( PyObject *self, PyObject *args ) libvlc_exception_t ex; char* psz_name; char* psz_output; - + if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_output ) ) return NULL; @@ -559,7 +567,7 @@ vlcInstance_vlm_set_input( PyObject *self, PyObject *args ) libvlc_exception_t ex; char* psz_name; char* psz_input; - + if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_input ) ) return NULL; @@ -570,13 +578,30 @@ vlcInstance_vlm_set_input( PyObject *self, PyObject *args ) return Py_None; } +static PyObject * +vlcInstance_vlm_add_input( PyObject *self, PyObject *args ) +{ + libvlc_exception_t ex; + char* psz_name; + char* psz_input; + + if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_input ) ) + return NULL; + + LIBVLC_TRY; + libvlc_vlm_add_input( LIBVLC_INSTANCE->p_instance, psz_name, psz_input, &ex); + LIBVLC_EXCEPT; + Py_INCREF( Py_None ); + return Py_None; +} + static PyObject * vlcInstance_vlm_set_loop( PyObject *self, PyObject *args ) { libvlc_exception_t ex; char* psz_name; int i_loop; - + if( !PyArg_ParseTuple( args, "si", &psz_name, &i_loop ) ) return NULL; @@ -591,7 +616,7 @@ static PyObject * vlcInstance_vlm_change_media( PyObject *self, PyObject *args, PyObject *kwds ) { libvlc_exception_t ex; - static char *kwlist[] = { "name", "input", "output", + static char *kwlist[] = { "name", "input", "output", "options", "enable", "loop", NULL}; char* psz_name = NULL; char* psz_input = NULL; @@ -602,19 +627,19 @@ vlcInstance_vlm_change_media( PyObject *self, PyObject *args, PyObject *kwds ) int i_size = 0; char** ppsz_args = NULL; - if( !PyArg_ParseTupleAndKeywords( args, kwds, "sss|Oii", kwlist, + if( !PyArg_ParseTupleAndKeywords( args, kwds, "sss|Oii", kwlist, &psz_name, - &psz_input, &psz_output, - &py_options, &i_enable, &i_loop ) ) + &psz_input, &psz_output, + &py_options, &i_enable, &i_loop ) ) return NULL; - + if( py_options ) { i_size = pyoptions_to_args( py_options, &ppsz_args ); } - + LIBVLC_TRY; - libvlc_vlm_change_media( LIBVLC_INSTANCE->p_instance, + libvlc_vlm_change_media( LIBVLC_INSTANCE->p_instance, psz_name, psz_input, psz_output, i_size, ppsz_args, i_enable, i_loop, &ex); free_args( i_size, ppsz_args ); @@ -628,7 +653,7 @@ vlcInstance_vlm_play_media( PyObject *self, PyObject *args ) { libvlc_exception_t ex; char* psz_name; - + if( !PyArg_ParseTuple( args, "s", &psz_name ) ) return NULL; @@ -660,7 +685,7 @@ vlcInstance_vlm_pause_media( PyObject *self, PyObject *args ) { libvlc_exception_t ex; char* psz_name; - + if( !PyArg_ParseTuple( args, "s", &psz_name ) ) return NULL; @@ -677,7 +702,7 @@ vlcInstance_vlm_seek_media( PyObject *self, PyObject *args ) libvlc_exception_t ex; char* psz_name; float f_percentage; - + if( !PyArg_ParseTuple( args, "sf", &psz_name, &f_percentage ) ) return NULL; @@ -706,6 +731,27 @@ vlcInstance_vlm_show_media( PyObject *self, PyObject *args ) return o_ret; } +static PyObject * +vlcInstance_media_descriptor_new( PyObject *self, PyObject *args ) +{ + libvlc_exception_t ex; + libvlc_media_descriptor_t *p_md; + char* psz_mrl = NULL; + vlcMediaDescriptor *p_ret; + + if( !PyArg_ParseTuple( args, "s", &psz_mrl ) ) + return NULL; + + LIBVLC_TRY; + p_md = libvlc_media_descriptor_new( LIBVLC_INSTANCE->p_instance, psz_mrl, &ex ); + LIBVLC_EXCEPT; + + p_ret = PyObject_New( vlcMediaDescriptor, &vlcMediaDescriptor_Type ); + p_ret->p_md = p_md; + Py_INCREF( p_ret ); /* Ah bon ? */ + return ( PyObject * )p_ret; +} + /* Method table */ static PyMethodDef vlcInstance_methods[] = { @@ -733,10 +779,12 @@ static PyMethodDef vlcInstance_methods[] = "playlist_add(mrl=str, name=str, options=list) -> int Add a new item to the playlist. options is a list of strings."}, { "playlist_delete_item", vlcInstance_playlist_delete_item, METH_VARARGS, "playlist_delete_item(id=int) Delete the given item"}, - { "playlist_get_input", vlcInstance_playlist_get_input, METH_VARARGS, - "playlist_get_input() -> object Return the current input"}, + { "playlist_get_media_instance", vlcInstance_playlist_get_media_instance, METH_VARARGS, + "playlist_get_media_instance() -> object Return the current media instance"}, { "video_set_parent", vlcInstance_video_set_parent, METH_VARARGS, - "video_set_parent(xid=int) Set the parent xid or HWND"}, + "video_set_parent(xid=int) Set the parent xid/HWND/CGrafPort"}, + { "video_get_parent", vlcInstance_video_get_parent, METH_VARARGS, + "video_get_parent(xid=int) Get the parent xid/HWND/CGrafPort"}, { "video_set_size", vlcInstance_video_set_size, METH_VARARGS, "video_set_size(width=int, height=int) Set the video width and height"}, { "audio_toggle_mute", vlcInstance_audio_toggle_mute, METH_VARARGS, @@ -753,6 +801,10 @@ static PyMethodDef vlcInstance_methods[] = "audio_get_channel() -> int Get current audio channel" }, { "audio_set_channel", vlcInstance_audio_set_channel, METH_VARARGS, "audio_set_channel(int) Set current audio channel" }, + + { "media_descriptor_new", vlcInstance_media_descriptor_new, METH_VARARGS, + "media_descriptor_new(str) -> object Create a media descriptor with the given mrl."}, + { "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, @@ -763,6 +815,8 @@ static PyMethodDef vlcInstance_methods[] = "vlm_set_output(name=str, output=str) Set the output" }, { "vlm_set_input", vlcInstance_vlm_set_input, METH_VARARGS, "vlm_set_input(name=str, output=str) Set the input" }, + { "vlm_add_input", vlcInstance_vlm_add_input, METH_VARARGS, + "vlm_add_input(name=str, output=str) Add a media's input MRL" }, { "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_VARARGS | METH_KEYWORDS,