Commit 528f1c64 authored by Olivier Aubert's avatar Olivier Aubert

python bindings: begin to complete the libvlc API bindings. Cf TODO for what is left to be done.

parent 22d8f2ec
This diff is collapsed.
This diff is collapsed.
......@@ -315,18 +315,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_media_instance_t *p_md;
vlcInput *p_ret;
libvlc_media_instance_t *p_mi;
vlcMediaInstance *p_ret;
LIBVLC_TRY;
p_md = libvlc_playlist_get_media_instance( 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_md = p_md;
p_ret = PyObject_New( vlcMediaInstance, &vlcMediaInstance_Type );
p_ret->p_mi = p_mi;
Py_INCREF( p_ret ); /* Ah bon ? */
return ( PyObject * )p_ret;
}
......@@ -348,6 +348,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 )
{
......@@ -566,6 +579,23 @@ 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 )
{
......@@ -702,6 +732,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[] =
{
......@@ -729,10 +780,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,
......@@ -749,6 +802,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,
......@@ -759,6 +816,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,
......
/*****************************************************************************
* vlc_mediadescriptor.c: vlc.MediaDescriptor binding
*****************************************************************************
* Copyright (C) 2007 the VideoLAN team
* $Id: vlc_input.c 22643 2007-10-17 13:30:02Z funman $
*
* Authors: Olivier Aubert <oaubert at liris.cnrs.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "vlcglue.h"
/***********************************************************************
* vlc.MediaDescriptor
***********************************************************************/
static void
vlcMediaDescriptor_dealloc( PyObject *self )
{
libvlc_media_descriptor_release( LIBVLC_MEDIADESCRIPTOR->p_md );
PyObject_DEL( self );
}
static PyObject *
vlcMediaDescriptor_add_option( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_options = NULL;
if( !PyArg_ParseTuple( args, "s", &psz_options ) )
return NULL;
LIBVLC_TRY;
libvlc_media_descriptor_add_option( LIBVLC_MEDIADESCRIPTOR->p_md, psz_options, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaDescriptor_get_mrl( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char * psz_mrl;
PyObject * o_ret;
LIBVLC_TRY;
psz_mrl = libvlc_media_descriptor_get_mrl( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
LIBVLC_EXCEPT;
o_ret = Py_BuildValue( "s", psz_mrl );
free( psz_mrl );
return o_ret;
}
static PyObject *
vlcMediaDescriptor_get_state( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
libvlc_state_t i_state;
LIBVLC_TRY;
i_state = libvlc_media_descriptor_get_state( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
LIBVLC_EXCEPT;
/* FIXME: return the defined state constant */
return Py_BuildValue( "i", i_state );
}
static PyObject *
vlcMediaDescriptor_add_tag( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_key;
char* psz_tag;
if( !PyArg_ParseTuple( args, "ss", &psz_key, &psz_tag ) )
return NULL;
LIBVLC_TRY;
libvlc_media_descriptor_add_tag( LIBVLC_MEDIADESCRIPTOR->p_md, psz_key, ( libvlc_tag_t )psz_tag, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaDescriptor_remove_tag( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_key;
char* psz_tag;
if( !PyArg_ParseTuple( args, "ss", &psz_key, &psz_tag ) )
return NULL;
LIBVLC_TRY;
libvlc_media_descriptor_remove_tag( LIBVLC_MEDIADESCRIPTOR->p_md, psz_key, ( libvlc_tag_t )psz_tag, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaDescriptor_tags_count_for_key( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_tag;
int i_ret;
if( !PyArg_ParseTuple( args, "s", &psz_tag ) )
return NULL;
LIBVLC_TRY;
i_ret=libvlc_media_descriptor_tags_count_for_key( LIBVLC_MEDIADESCRIPTOR->p_md, psz_tag, &ex );
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaDescriptor_get_duration( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
libvlc_time_t i_ret;
LIBVLC_TRY;
i_ret = libvlc_media_descriptor_get_duration( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "L", i_ret );
}
static PyObject *
vlcMediaDescriptor_media_instance_new( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
libvlc_media_instance_t *p_mi;
vlcMediaInstance *p_ret;
LIBVLC_TRY;
p_mi = libvlc_media_instance_new_from_media_descriptor( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
LIBVLC_EXCEPT;
p_ret = PyObject_New( vlcMediaInstance, &vlcMediaInstance_Type );
p_ret->p_mi = p_mi;
Py_INCREF( p_ret ); /* Ah bon ? */
return ( PyObject * )p_ret;
}
static PyObject *
vlcMediaDescriptor_is_preparsed( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_media_descriptor_is_preparsed( LIBVLC_MEDIADESCRIPTOR->p_md, &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "L", i_ret );
}
static PyObject *
vlcMediaDescriptor_get_meta( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char * psz_meta = NULL;
char * psz_ret = NULL;
PyObject* o_ret;
int i_index = -1;
int i_loop = 0;
static const char * meta_names[] = { "Title", "Artist", "Genre", "Copyright", "Album", "TrackNumber", "Description", "Rating", "Date", "Setting", "URL", "Language", "NowPlaying", "Publisher", "EncodedBy", "ArtworkURL", "TrackID", NULL };
if( !PyArg_ParseTuple( args, "s", &psz_meta ) )
return NULL;
while( !meta_names[i_loop] )
{
if( !strncmp(meta_names[i_loop], psz_meta, strlen(meta_names[i_loop])) )
{
i_index = i_loop;
break;
}
}
if( i_index < 0 )
{
PyObject *py_exc = vlcInstance_Exception;
PyErr_SetString( py_exc, "Unknown meta attribute" );
return NULL;
}
LIBVLC_TRY;
psz_ret = libvlc_media_descriptor_get_meta( LIBVLC_MEDIADESCRIPTOR->p_md, i_index, &ex);
LIBVLC_EXCEPT;
o_ret = Py_BuildValue( "s", psz_ret );
free( psz_ret );
return o_ret;
}
static PyMethodDef vlcMediaDescriptor_methods[] =
{
{ "add_option", vlcMediaDescriptor_add_option, METH_VARARGS,
"add_option(str) Add an option to the media descriptor." },
{ "get_mrl", vlcMediaDescriptor_get_mrl, METH_VARARGS,
"get_mrl() -> str" },
{ "get_state", vlcMediaDescriptor_get_state, METH_VARARGS,
"get_state() -> int" },
{ "add_tag", vlcMediaDescriptor_add_tag, METH_VARARGS,
"add_tag(key=str, tag=str) Add tag to the media descriptor." },
{ "remove_tag", vlcMediaDescriptor_remove_tag, METH_VARARGS,
"remove_tag(key=str, tag=str) Remove tag from the media descriptor." },
{ "tags_count_for_key", vlcMediaDescriptor_tags_count_for_key, METH_VARARGS,
"tags_count_for_key(str) ." },
{ "get_duration", vlcMediaDescriptor_get_duration, METH_VARARGS,
"get_duration() -> int" },
{ "mediainstance_new", vlcMediaDescriptor_media_instance_new, METH_VARARGS,
"mediainstance_new() -> vlc.MediaInstance Create a Media Instance object from a Media Descriptor" },
{ "is_preparsed", vlcMediaDescriptor_is_preparsed, METH_VARARGS,
"is_preparsed() -> int" },
{ "get_meta", vlcMediaDescriptor_get_meta, METH_VARARGS,
"get_meta(str) -> str Read the meta of the media descriptor." },
{ NULL } /* Sentinel */
};
static PyTypeObject vlcMediaDescriptor_Type =
{
PyObject_HEAD_INIT( NULL )
0, /*ob_size*/
"vlc.MediaDescriptor", /*tp_name*/
sizeof( vlcMediaDescriptor_Type ), /*tp_basicsize*/
0, /*tp_itemsize*/
vlcMediaDescriptor_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"vlc.MediaDescriptor object.", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
vlcMediaDescriptor_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
......@@ -47,8 +47,10 @@ initvlc( void )
{
PyObject* p_module;
vlcInput_Type.tp_new = PyType_GenericNew;
vlcInput_Type.tp_alloc = PyType_GenericAlloc;
vlcMediaInstance_Type.tp_new = PyType_GenericNew;
vlcMediaInstance_Type.tp_alloc = PyType_GenericAlloc;
vlcMediaDescriptor_Type.tp_new = PyType_GenericNew;
vlcMediaDescriptor_Type.tp_alloc = PyType_GenericAlloc;
p_module = Py_InitModule3( "vlc", vlc_methods,
"VLC media player embedding module." );
......@@ -62,7 +64,9 @@ initvlc( void )
return;
if( PyType_Ready( &vlcInstance_Type ) < 0 )
return;
if( PyType_Ready( &vlcInput_Type ) < 0 )
if( PyType_Ready( &vlcMediaInstance_Type ) < 0 )
return;
if( PyType_Ready( &vlcMediaDescriptor_Type ) < 0 )
return;
/* Exceptions */
......@@ -115,9 +119,12 @@ initvlc( void )
Py_INCREF( &vlcInstance_Type );
PyModule_AddObject( p_module, "Instance",
( PyObject * )&vlcInstance_Type );
Py_INCREF( &vlcInput_Type );
PyModule_AddObject( p_module, "Input",
( PyObject * )&vlcInput_Type );
Py_INCREF( &vlcMediaInstance_Type );
PyModule_AddObject( p_module, "MediaInstance",
( PyObject * )&vlcMediaInstance_Type );
Py_INCREF( &vlcMediaDescriptor_Type );
PyModule_AddObject( p_module, "MediaDescriptor",
( PyObject * )&vlcMediaDescriptor_Type );
/* Constants */
PyModule_AddIntConstant( p_module, "AbsolutePosition",
......@@ -133,6 +140,7 @@ initvlc( void )
mediacontrol_SampleCount );
PyModule_AddIntConstant( p_module, "MediaTime",
mediacontrol_MediaTime );
PyModule_AddIntConstant( p_module, "PlayingStatus",
mediacontrol_PlayingStatus );
PyModule_AddIntConstant( p_module, "PauseStatus",
......@@ -147,6 +155,7 @@ initvlc( void )
mediacontrol_EndStatus );
PyModule_AddIntConstant( p_module, "UndefinedStatus",
mediacontrol_UndefinedStatus );
}
......@@ -159,7 +168,7 @@ void * fast_memcpy( void * to, const void * from, size_t len )
/* Horrible hack... Please do not look. Temporary workaround for the
forward declaration mess of python types (cf vlcglue.h). If we do a
separate compilation, we have to declare some types as extern. But
the recommended way to forward declare types in python is
the recommended way to forward declared types in python is
static... I am sorting the mess but in the meantime, this will
produce a working python module.
*/
......@@ -167,3 +176,4 @@ void * fast_memcpy( void * to, const void * from, size_t len )
#include "vlc_position.c"
#include "vlc_instance.c"
#include "vlc_input.c"
#include "vlc_mediadescriptor.c"
......@@ -113,21 +113,33 @@ typedef struct
} PyPosition;
/**********************************************************************
* vlc.Input Object
* vlc.MediaInstance Object
**********************************************************************/
typedef struct
{
PyObject_HEAD
libvlc_media_instance_t* p_md;
} vlcInput;
libvlc_media_instance_t* p_mi;
} vlcMediaInstance;
/**********************************************************************
* vlc.MediaDescriptor Object
**********************************************************************/
typedef struct
{
PyObject_HEAD
libvlc_media_descriptor_t* p_md;
} vlcMediaDescriptor;
/* Forward declarations */
staticforward PyTypeObject MediaControl_Type;
staticforward PyTypeObject PyPosition_Type;
staticforward PyTypeObject vlcInstance_Type;
staticforward PyTypeObject vlcInput_Type;
staticforward PyTypeObject vlcMediaInstance_Type;
staticforward PyTypeObject vlcMediaDescriptor_Type;
#define LIBVLC_INPUT ((vlcInput*)self)
#define LIBVLC_INSTANCE ((vlcInstance*)self)
#define LIBVLC_MEDIAINSTANCE ((vlcMediaInstance*)self)
#define LIBVLC_MEDIADESCRIPTOR ((vlcMediaDescriptor*)self)
#define LIBVLC_TRY libvlc_exception_init( &ex );
......
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