Commit 4e88f3b2 authored by Olivier Aubert's avatar Olivier Aubert

python bindings: add support for the new libvlc API

parent c340ebcb
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
# Building the Python binding # Building the Python binding
############################################################################### ###############################################################################
EXTRA_DIST = vlcglue.c vlcglue.h setup.py vlcwrapper.py EXTRA_DIST = vlcglue.h setup.py vlcwrapper.py \
vlc_module.c vlc_object.c \
vlc_mediacontrol.c vlc_position.c \
vlc_instance.c vlc_input.c
if BUILD_PYTHON if BUILD_PYTHON
......
* 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.
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 :
** 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
...@@ -21,15 +21,8 @@ except KeyError: ...@@ -21,15 +21,8 @@ except KeyError:
if not srcdir: if not srcdir:
srcdir = '.' srcdir = '.'
#if os.sys.platform in ('win32', 'darwin'): vlclib="-lvlc"
# Do not use PIC version on win32 and Mac OS X picflag=''
if True:
# PIC version seems to be disabled on all platforms
vlclib=os.path.join( top_builddir, 'src', 'libvlc.a' )
picflag=''
else:
vlclib=os.path.join( top_builddir, 'src', 'libvlc_pic.a' )
picflag='pic'
def get_vlcconfig(): def get_vlcconfig():
vlcconfig=None vlcconfig=None
...@@ -69,39 +62,47 @@ def get_ldflags(): ...@@ -69,39 +62,47 @@ def get_ldflags():
ldflags = [] ldflags = []
if os.sys.platform == 'darwin': if os.sys.platform == 'darwin':
ldflags = "-read_only_relocs warning".split() ldflags = "-read_only_relocs warning".split()
ldflags.extend(os.popen('%s --libs vlc %s builtin' % (vlcconfig, ldflags.extend(os.popen('%s --libs vlc %s' % (vlcconfig,
picflag), picflag),
'r').readline().rstrip().split()) 'r').readline().rstrip().split())
if os.sys.platform == 'darwin': if os.sys.platform == 'darwin':
ldflags.append('-lstdc++') ldflags.append('-lstdc++')
return ldflags return ldflags
#source_files = [ 'vlc_module.c', 'vlc_object.c', 'vlc_mediacontrol.c',
# 'vlc_position.c', 'vlc_instance.c', 'vlc_input.c' ]
source_files = [ 'vlc_module.c' ]
# To compile in a local vlc tree # To compile in a local vlc tree
vlclocal = Extension('vlc', vlclocal = Extension('vlc',
sources = [ os.path.join( srcdir, 'vlcglue.c'), sources = [ os.path.join( srcdir, f ) for f in source_files ] +
os.path.join( srcdir, '../../src/control/mediacontrol_init.c')], [ os.path.join( top_builddir, 'src/control/mediacontrol_init.c') ],
include_dirs = [ top_builddir, include_dirs = [ top_builddir,
os.path.join( srcdir, '../../include'), os.path.join( top_builddir, 'include' ),
os.path.join( srcdir, '../../', '/usr/win32/include') ], srcdir,
'/usr/win32/include' ],
extra_objects = [ vlclib ], extra_objects = [ vlclib ],
extra_compile_args = get_cflags(), extra_compile_args = get_cflags(),
extra_link_args = [ '-L' + top_builddir ] + get_ldflags(), extra_link_args = [ '-L' + top_builddir ] + get_ldflags(),
) )
setup (name = 'MediaControl', setup (name = 'VLC Bindings',
version = get_vlc_version(), version = get_vlc_version(),
scripts = [ os.path.join( srcdir, 'vlcwrapper.py') ], #scripts = [ os.path.join( srcdir, 'vlcwrapper.py') ],
keywords = [ 'vlc', 'video' ], keywords = [ 'vlc', 'video' ],
license = "GPL", license = "GPL",
description = """VLC bindings for python. description = """VLC bindings for python.
This module provides a MediaControl object, which implements an API This module provides bindings for the native libvlc API of the VLC
inspired from the OMG Audio/Video Stream 1.0 specification. Moreover, video player. Documentation can be found on the VLC wiki :
the module provides a Object type, which gives a low-level access to http://wiki.videolan.org/index.php/ExternalAPI
the vlc objects and their variables.
Documentation can be found on the VLC wiki : The module also provides a Object type, which gives a low-level access
to the vlc objects and their variables.
This module also provides a MediaControl object, which implements an
API inspired from the OMG Audio/Video Stream 1.0 specification.
Documentation can be found on the VLC wiki :
http://wiki.videolan.org/index.php/PythonBinding http://wiki.videolan.org/index.php/PythonBinding
Example session: Example session:
...@@ -135,5 +136,6 @@ o.info() ...@@ -135,5 +136,6 @@ o.info()
i=o.find_object('input') i=o.find_object('input')
i.list() i.list()
i.get('time') i.get('time')
""", """,
ext_modules = [ vlclocal ]) ext_modules = [ vlclocal ])
/*****************************************************************************
* vlc_input.c: vlc.Input binding
*****************************************************************************
* Copyright (C) 2006 the VideoLAN team
* $Id: $
*
* Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.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.Input
***********************************************************************/
static PyObject *
vlcInput_get_length( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
vlc_int64_t i_ret;
LIBVLC_TRY;
i_ret = libvlc_input_get_length( LIBVLC_INPUT->p_input, &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "L", i_ret );
}
static PyObject *
vlcInput_get_time( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
vlc_int64_t i_ret;
LIBVLC_TRY;
i_ret = libvlc_input_get_time( LIBVLC_INPUT->p_input, &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "L", i_ret );
}
static PyObject *
vlcInput_set_time( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
vlc_int64_t i_time;
if( !PyArg_ParseTuple( args, "L", &i_time ) )
return NULL;
LIBVLC_TRY;
libvlc_input_set_time( LIBVLC_INPUT->p_input, i_time, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInput_get_position( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
float f_ret;
LIBVLC_TRY;
f_ret = libvlc_input_get_position( LIBVLC_INPUT->p_input, &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "f", f_ret );
}
static PyObject *
vlcInput_set_position( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
float f_pos;
if( !PyArg_ParseTuple( args, "f", &f_pos ) )
return NULL;
LIBVLC_TRY;
libvlc_input_set_position( LIBVLC_INPUT->p_input, f_pos, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInput_will_play( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_input_will_play( LIBVLC_INPUT->p_input, &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcInput_get_rate( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
float f_ret;
LIBVLC_TRY;
f_ret = libvlc_input_get_rate( LIBVLC_INPUT->p_input, &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "f", f_ret );
}
static PyObject *
vlcInput_set_rate( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
float f_rate;
if( !PyArg_ParseTuple( args, "f", &f_rate ) )
return NULL;
LIBVLC_TRY;
libvlc_input_set_rate( LIBVLC_INPUT->p_input, f_rate, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInput_get_state( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_input_get_state( LIBVLC_INPUT->p_input, &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcInput_has_vout( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_input_has_vout( LIBVLC_INPUT->p_input, &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcInput_get_fps( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
float f_ret;
LIBVLC_TRY;
f_ret = libvlc_input_get_fps( LIBVLC_INPUT->p_input, &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "f", f_ret );
}
static PyMethodDef vlcInput_methods[] =
{
{ "get_length", vlcInput_get_length, METH_VARARGS,
"get_length() -> long" },
{ "get_time", vlcInput_get_time, METH_VARARGS,
"get_time() -> long" },
{ "set_time", vlcInput_set_time, METH_VARARGS,
"set_time(long)" },
{ "get_position", vlcInput_get_position, METH_VARARGS,
"get_position() -> float" },
{ "set_position", vlcInput_set_position, METH_VARARGS,
"set_position(float)" },
{ "will_play", vlcInput_will_play, METH_VARARGS,
"will_play() -> int" },
{ "get_rate", vlcInput_get_rate, METH_VARARGS,
"get_rate() -> float" },
{ "set_rate", vlcInput_set_rate, METH_VARARGS,
"set_rate(float)" },
{ "get_state", vlcInput_get_state, METH_VARARGS,
"get_state() -> int" },
{ "has_vout", vlcInput_has_vout, METH_VARARGS,
"has_vout() -> int" },
{ "get_fps", vlcInput_get_fps, METH_VARARGS,
"get_fps() -> float" },
{ NULL } /* Sentinel */
};
static PyTypeObject vlcInput_Type =
{
PyObject_HEAD_INIT( NULL )
0, /*ob_size*/
"vlc.Input", /*tp_name*/
sizeof( vlcInput_Type ), /*tp_basicsize*/
0, /*tp_itemsize*/
0, /*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.Input object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
vlcInput_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 */
};
/*****************************************************************************
* vlc_instance.c: vlc.Instance binding
*****************************************************************************
* Copyright (C) 2006 the VideoLAN team
* $Id: $
*
* Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.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"
/*****************************************************************************
* Instance object implementation
*****************************************************************************/
static PyObject *
vlcInstance_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
{
vlcInstance *self;
libvlc_exception_t ex;
PyObject* py_list = NULL;
char** ppsz_args = NULL;
int i_size = 0;
self = PyObject_New( vlcInstance, &vlcInstance_Type );
if( PyArg_ParseTuple( args, "O", &py_list ) )
{
int i_index;
Py_INCREF( py_list );
if( ! PySequence_Check( py_list ) )
{
PyErr_SetString( PyExc_TypeError, "Parameter must be a sequence." );
return NULL;
}
i_size = PySequence_Size( py_list );
ppsz_args = malloc( ( i_size + 2 ) * sizeof( char * ) );
if( ! ppsz_args )
{
PyErr_SetString( PyExc_MemoryError, "Out of memory" );
return NULL;
}
/* FIXME: we define a default args[0], since the libvlc API
needs one. But it would be cleaner to fix the libvlc API.
*/
ppsz_args[0] = strdup("vlc");
for ( i_index = 0; i_index < i_size; i_index++ )
{
ppsz_args[i_index + 1] =
strdup( PyString_AsString( PyObject_Str(
PySequence_GetItem( py_list,
i_index ) ) ) );
}
ppsz_args[i_size + 1] = NULL;
/* Since we prepended the arg[0] */
i_size += 1;
Py_DECREF( py_list );
}
else
{
/* No arguments were given. Clear the exception raised
by PyArg_ParseTuple. */
PyErr_Clear( );
}
Py_BEGIN_ALLOW_THREADS
LIBVLC_TRY
LIBVLC_INSTANCE->p_instance = libvlc_new( i_size, ppsz_args, &ex );
LIBVLC_EXCEPT
Py_END_ALLOW_THREADS
Py_INCREF( self );
return ( PyObject * )self;
}
static void
vlcInstance_dealloc( PyObject *self )
{
libvlc_exception_t ex;
libvlc_destroy( LIBVLC_INSTANCE->p_instance, &ex );
PyMem_DEL( self );
}
static PyObject *
vlcInstance_get_vlc_id( PyObject *self, PyObject *args )
{
return Py_BuildValue( "i", libvlc_get_vlc_id( LIBVLC_INSTANCE->p_instance ) );
}
/* Playlist play. 2 parameters: i_id, the id to play
l_options: a list of options */
static PyObject *
vlcInstance_playlist_play( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_id = -1;
PyObject *py_options = NULL;
int i_size = 0;
char** ppsz_args = NULL;
if( !PyArg_ParseTuple( args, "|iO", &i_id, &py_options ) )
return NULL;
if( py_options )
{
/* Options were given. Convert them to a char** */
int i_index;
Py_INCREF( py_options );
if( ! PySequence_Check( py_options ) )
{
PyErr_SetString( PyExc_TypeError, "Parameter must be a sequence." );
return NULL;
}
i_size = PySequence_Size( py_options );
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++ )
{
ppsz_args[i_index] =
strdup( PyString_AsString( PyObject_Str(
PySequence_GetItem( py_options,
i_index ) ) ) );
}
ppsz_args[i_size] = NULL;
Py_DECREF( py_options );
}
LIBVLC_TRY;
libvlc_playlist_play( LIBVLC_INSTANCE->p_instance, i_id, i_size, ppsz_args, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_playlist_pause( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_playlist_pause( LIBVLC_INSTANCE->p_instance, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_playlist_isplaying( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_playlist_isplaying( LIBVLC_INSTANCE->p_instance, &ex );
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcInstance_playlist_items_count( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_playlist_items_count( LIBVLC_INSTANCE->p_instance, &ex );
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcInstance_playlist_stop( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_playlist_stop( LIBVLC_INSTANCE->p_instance, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_playlist_next( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_playlist_next( LIBVLC_INSTANCE->p_instance, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_playlist_prev( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_playlist_prev( LIBVLC_INSTANCE->p_instance, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_playlist_clear( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_playlist_clear( LIBVLC_INSTANCE->p_instance, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
/* Add a playlist item. Main parameter: URI.
Optional parameters: name, options */
static PyObject *
vlcInstance_playlist_add( PyObject *self, PyObject *args)
{
libvlc_exception_t ex;
int i_ret;
char* psz_uri = NULL;
char* psz_name = NULL;
PyObject *py_options = NULL;
int i_size = 0;
char** ppsz_args = NULL;
if( !PyArg_ParseTuple( args, "s|sO", &psz_uri, &psz_name, &py_options ) )
return NULL;
if( !psz_name )
{
/* Set a default name */
psz_name = strdup( psz_uri );
}
if( py_options )
{
/* Options were given. Convert them to a char** */
int i_index;
Py_INCREF( py_options );
if( ! PySequence_Check( py_options ) )
{
PyErr_SetString( PyExc_TypeError, "Parameter must be a sequence." );
return NULL;
}
i_size = PySequence_Size( py_options );
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++ )
{
ppsz_args[i_index] =
strdup( PyString_AsString( PyObject_Str(
PySequence_GetItem( py_options,
i_index ) ) ) );
}
ppsz_args[i_size] = NULL;
Py_DECREF( py_options );
}
LIBVLC_TRY;
if( ppsz_args )
{
i_ret = libvlc_playlist_add_extended( LIBVLC_INSTANCE->p_instance,
psz_uri,
psz_name,
i_size,
ppsz_args,
&ex );
}
else
{
i_ret = libvlc_playlist_add( LIBVLC_INSTANCE->p_instance,
psz_uri,
psz_name,
&ex );
}
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcInstance_playlist_delete_item( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_id;
int i_ret;
if( !PyArg_ParseTuple( args, "i", &i_id ) )
return NULL;
LIBVLC_TRY;
i_ret = libvlc_playlist_delete_item( LIBVLC_INSTANCE->p_instance, i_id, &ex );
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcInstance_playlist_get_input( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
libvlc_input_t *p_input;
vlcInput *p_ret;
LIBVLC_TRY;
p_input = libvlc_playlist_get_input( LIBVLC_INSTANCE->p_instance, &ex );
LIBVLC_EXCEPT;
p_ret = PyObject_New( vlcInput, &vlcInput_Type );
p_ret->p_input = p_input;
Py_INCREF( p_ret ); /* Ah bon ? */
return ( PyObject * )p_ret;
}
static PyObject *
vlcInstance_video_set_parent( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_drawable;
if( !PyArg_ParseTuple( args, "i", &i_drawable ) )
return NULL;
LIBVLC_TRY;
libvlc_video_set_parent( LIBVLC_INSTANCE->p_instance, (libvlc_drawable_t) i_drawable, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_video_set_size( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_width;
int i_height;
if( !PyArg_ParseTuple( args, "ii", &i_width, &i_height ) )
return NULL;
LIBVLC_TRY;
libvlc_video_set_size( LIBVLC_INSTANCE->p_instance, i_width, i_height, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_audio_toggle_mute( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_audio_toggle_mute( LIBVLC_INSTANCE->p_instance, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_audio_get_mute( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_audio_get_mute( LIBVLC_INSTANCE->p_instance, &ex );
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcInstance_audio_set_mute( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_mute;
if( !PyArg_ParseTuple( args, "i", &i_mute ) )
return NULL;
LIBVLC_TRY;
libvlc_audio_set_mute( LIBVLC_INSTANCE->p_instance, i_mute, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_audio_get_volume( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_audio_get_volume( LIBVLC_INSTANCE->p_instance, &ex );
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcInstance_audio_set_volume( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_volume;
if( !PyArg_ParseTuple( args, "i", &i_volume ) )
return NULL;
LIBVLC_TRY;
libvlc_audio_set_mute( LIBVLC_INSTANCE->p_instance, i_volume, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
/* FIXME: add vlm related bindings here */
/* static PyObject *
vlcInstance_vlm_add_broadcast( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
FIXME libvlc_vlm_add_broadcast( LIBVLC_INSTANCE->p_instance, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_del_media( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_vlm_del_media( LIBVLC_INSTANCE->p_instance, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_set_enabled( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_vlm_set_enabled( LIBVLC_INSTANCE->p_instance, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_set_output( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_vlm_set_output( LIBVLC_INSTANCE->p_instance, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_set_input( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_vlm_set_input( LIBVLC_INSTANCE->p_instance, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_set_loop( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_vlm_set_loop( LIBVLC_INSTANCE->p_instance, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_change_media( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_vlm_change_media( LIBVLC_INSTANCE->p_instance, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_play_media( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_vlm_play_media( LIBVLC_INSTANCE->p_instance, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_stop_media( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_vlm_stop_media( LIBVLC_INSTANCE->p_instance, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_pause_media( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_vlm_pause_media( LIBVLC_INSTANCE->p_instance, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
*/
/* Method table */
static PyMethodDef vlcInstance_methods[] =
{
{ "get_vlc_id", vlcInstance_get_vlc_id, METH_VARARGS,
"get_vlc_id( ) -> int Get the instance id."},
{ "playlist_play", vlcInstance_playlist_play, METH_VARARGS,
"playlist_play( int, options ) Play the given playlist item (-1 for current item) with optional options (a list of strings)" },
{ "playlist_pause", vlcInstance_playlist_pause, METH_VARARGS,
"playlist_pause() Pause the current stream"},
{ "playlist_isplaying", vlcInstance_playlist_isplaying, METH_VARARGS,
"playlist_isplaying() -> int Return True if the playlist if playing"},
{ "playlist_items_count", vlcInstance_playlist_items_count, METH_VARARGS,
"playlist_items_count() -> int Return the number of items in the playlist"},
{ "playlist_stop", vlcInstance_playlist_stop, METH_VARARGS,
"playlist_stop() Stop the current stream"},
{ "playlist_next", vlcInstance_playlist_next, METH_VARARGS,
"playlist_next() Play the next item"},
{ "playlist_prev", vlcInstance_playlist_prev, METH_VARARGS,
"playlist_prev() Play the previous item"},
{ "playlist_clear", vlcInstance_playlist_clear, METH_VARARGS,
"playlist_clear() Clear the playlist"},
{ "playlist_add", vlcInstance_playlist_add, METH_VARARGS,
"playlist_add( str, str, options ) -> int Add a new item to the playlist. Second argument is its name. options is a list of strings."},
{ "playlist_delete_item", vlcInstance_playlist_delete_item, METH_VARARGS,
"playlist_delete_item(int) Delete the given item"},
{ "playlist_get_input", vlcInstance_playlist_get_input, METH_VARARGS,
"playlist_get_input() -> object Return the current input"},
{ "video_set_parent", vlcInstance_video_set_parent, METH_VARARGS,
"video_set_parent(int) Set the parent xid or HWND"},
{ "video_set_size", vlcInstance_video_set_size, METH_VARARGS,
"video_set_size(int, int) Set the video width and height"},
{ "audio_toggle_mute", vlcInstance_audio_toggle_mute, METH_VARARGS,
"audio_toggle_mute() Toggle the mute state"},
{ "audio_get_mute", vlcInstance_audio_get_mute, METH_VARARGS,
"audio_get_mute() -> int Get the mute state"},
{ "audio_set_mute", vlcInstance_audio_set_mute, METH_VARARGS,
"audio_set_mute(int) Set the mute state"},
{ "audio_get_volume", vlcInstance_audio_get_volume, METH_VARARGS,
"audio_get_volume() -> int Get the audio volume"},
{ "audio_set_volume", vlcInstance_audio_set_volume, METH_VARARGS,
"audio_set_volume(int) Set the audio volume"},
{ NULL, NULL, 0, NULL },
};
static PyTypeObject vlcInstance_Type =
{
PyObject_HEAD_INIT( NULL )
0, /*ob_size*/
"vlc.Instance", /*tp_name*/
sizeof( vlcInstance_Type ), /*tp_basicsize*/
0, /*tp_itemsize*/
( destructor )vlcInstance_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 Instance.", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
vlcInstance_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 */
vlcInstance_new, /* tp_new */
};
/***************************************************************************** /*****************************************************************************
* vlcglue.c: VLC Module * vlc_mediacontrol.c: vlc.MediaControl binding
***************************************************************************** *****************************************************************************
* Copyright (C) 1998-2004 the VideoLAN team * Copyright (C) 2006 the VideoLAN team
* $Id$ * $Id: $
* *
* Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.fr> * Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.fr>
* Clément Stenac <zorglub@videolan.org>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -23,712 +22,6 @@ ...@@ -23,712 +22,6 @@
*****************************************************************************/ *****************************************************************************/
#include "vlcglue.h" #include "vlcglue.h"
/**************************************************************************
* VLC Module
**************************************************************************/
#ifndef vlcMODINIT_FUNC /* declarations for DLL import/export */
#define vlcMODINIT_FUNC void
#endif
static PyMethodDef vlc_methods[] = {
{ NULL } /* Sentinel */
};
/* Module globals */
PyObject* MediaControl_InternalException = NULL;
PyObject* MediaControl_PositionKeyNotSupported = NULL;
PyObject *MediaControl_PositionOriginNotSupported = NULL;
PyObject* MediaControl_InvalidPosition = NULL;
PyObject *MediaControl_PlaylistException = NULL;
vlcMODINIT_FUNC
initvlc( void )
{
PyObject* p_module;
PyPosition_Type.tp_new = PyType_GenericNew;
PyPosition_Type.tp_alloc = PyType_GenericAlloc;
p_module = Py_InitModule3( "vlc", vlc_methods,
"VLC media player embedding module." );
if( !p_module )
return;
if( PyType_Ready( &PyPosition_Type ) < 0 )
return;
if( PyType_Ready( &MediaControl_Type ) < 0 )
return;
if( PyType_Ready( &vlcObject_Type ) < 0 )
return;
/* Exceptions */
MediaControl_InternalException =
PyErr_NewException( "vlc.InternalException", NULL, NULL );
Py_INCREF( MediaControl_InternalException );
PyModule_AddObject( p_module, "InternalException",
MediaControl_InternalException );
MediaControl_PositionKeyNotSupported =
PyErr_NewException( "vlc.PositionKeyNotSupported", NULL, NULL );
Py_INCREF( MediaControl_PositionKeyNotSupported );
PyModule_AddObject( p_module, "PositionKeyNotSupported",
MediaControl_PositionKeyNotSupported );
MediaControl_PositionOriginNotSupported=
PyErr_NewException( "vlc.InvalidPosition", NULL, NULL );
Py_INCREF( MediaControl_PositionOriginNotSupported );
PyModule_AddObject( p_module, "PositionOriginNotSupported",
MediaControl_PositionOriginNotSupported );
MediaControl_InvalidPosition =
PyErr_NewException( "vlc.InvalidPosition", NULL, NULL );
Py_INCREF( MediaControl_InvalidPosition );
PyModule_AddObject( p_module, "InvalidPosition",
MediaControl_InvalidPosition );
MediaControl_PlaylistException =
PyErr_NewException( "vlc.PlaylistException", NULL, NULL );
Py_INCREF( MediaControl_PlaylistException );
PyModule_AddObject( p_module, "PlaylistException",
MediaControl_PlaylistException );
/* Types */
Py_INCREF( &PyPosition_Type );
PyModule_AddObject( p_module, "Position",
( PyObject * )&PyPosition_Type );
Py_INCREF( &MediaControl_Type );
PyModule_AddObject( p_module, "MediaControl",
( PyObject * )&MediaControl_Type );
Py_INCREF( &vlcObject_Type );
PyModule_AddObject( p_module, "Object",
( PyObject * )&vlcObject_Type );
/* Constants */
PyModule_AddIntConstant( p_module, "AbsolutePosition",
mediacontrol_AbsolutePosition );
PyModule_AddIntConstant( p_module, "RelativePosition",
mediacontrol_RelativePosition );
PyModule_AddIntConstant( p_module, "ModuloPosition",
mediacontrol_ModuloPosition );
PyModule_AddIntConstant( p_module, "ByteCount",
mediacontrol_ByteCount );
PyModule_AddIntConstant( p_module, "SampleCount",
mediacontrol_SampleCount );
PyModule_AddIntConstant( p_module, "MediaTime",
mediacontrol_MediaTime );
PyModule_AddIntConstant( p_module, "PlayingStatus",
mediacontrol_PlayingStatus );
PyModule_AddIntConstant( p_module, "PauseStatus",
mediacontrol_PauseStatus );
PyModule_AddIntConstant( p_module, "ForwardStatus",
mediacontrol_ForwardStatus );
PyModule_AddIntConstant( p_module, "BackwardStatus",
mediacontrol_BackwardStatus );
PyModule_AddIntConstant( p_module, "InitStatus",
mediacontrol_InitStatus );
PyModule_AddIntConstant( p_module, "EndStatus",
mediacontrol_EndStatus );
PyModule_AddIntConstant( p_module, "UndefinedStatus",
mediacontrol_UndefinedStatus );
}
/* Make libpostproc happy... */
void * fast_memcpy( void * to, const void * from, size_t len )
{
return memcpy( to, from, len );
}
/*****************************************************************************
* VLCObject implementation
*****************************************************************************/
static PyObject
*vlcObject_new( PyTypeObject *p_type, PyObject *p_args, PyObject *p_kwds )
{
vlcObject *self;
vlc_object_t *p_object;
int i_id;
self = PyObject_New( vlcObject, &vlcObject_Type );
if( !PyArg_ParseTuple( p_args, "i", &i_id ) )
return NULL;
/* Maybe we were already initialized */
p_object = ( vlc_object_t* )vlc_current_object( i_id );
if( !p_object )
{
/* Try to initialize */
i_id = VLC_Create();
if( i_id < 0 )
{
PyErr_SetString( PyExc_StandardError, "Unable to create a VLC instance." );
return NULL;
}
p_object = ( vlc_object_t* )vlc_current_object( i_id );
}
if( !p_object )
{
PyErr_SetString( PyExc_StandardError, "Unable to get object." );
return NULL;
}
self->p_object = p_object;
self->b_released = 0;
Py_INCREF( self ); /* Ah bon ? */
return ( PyObject * )self;
}
static PyObject *
vlcObject_release( PyObject *self, PyObject *p_args )
{
if( VLCSELF->b_released == 0 )
{
vlc_object_release( VLCSELF->p_object );
VLCSELF->b_released = 1;
}
Py_INCREF( Py_None );
return Py_None;
}
static void
vlcObject_dealloc( PyObject *self )
{
vlcObject_release( self, NULL );
PyMem_DEL( self );
}
static PyObject *
vlcObject_find_object( PyObject *self, PyObject *args )
{
vlcObject *p_retval;
vlc_object_t *p_obj;
char *psz_name;
int i_object_type;
if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL;
/* psz_name is in
( aout, decoder, input, httpd, intf, playlist, root, vlc, vout )
*/
switch ( psz_name[0] )
{
case 'a':
i_object_type = VLC_OBJECT_AOUT;
break;
case 'd':
i_object_type = VLC_OBJECT_DECODER;
break;
case 'h':
i_object_type = VLC_OBJECT_HTTPD;
break;
case 'i':
if( strlen( psz_name ) < 3 )
i_object_type = VLC_OBJECT_INTF;
else if( psz_name[2] == 't' )
i_object_type = VLC_OBJECT_INTF;
else
i_object_type = VLC_OBJECT_INPUT;
break;
case 'p':
i_object_type = VLC_OBJECT_PLAYLIST;
break;
case 'r':
i_object_type = VLC_OBJECT_ROOT;
break;
case 'v':
if( strlen( psz_name ) < 3 )
i_object_type = VLC_OBJECT_VLC;
else if( psz_name[1] == 'l' )
i_object_type = VLC_OBJECT_VLC;
else
i_object_type = VLC_OBJECT_VOUT;
break;
default:
/* FIXME: raise an exception ? */
return Py_None;
}
p_obj = vlc_object_find( VLCSELF->p_object, i_object_type, FIND_ANYWHERE );
if( !p_obj )
{
Py_INCREF( Py_None );
return Py_None;
}
p_retval = PyObject_New( vlcObject, &vlcObject_Type );
p_retval->p_object = p_obj;
return ( PyObject * )p_retval;
}
static PyObject *
vlcObject_info( PyObject *self, PyObject *args )
{
PyObject *p_retval;
vlc_object_t *p_obj;
p_obj = VLCSELF->p_object;
/* Return information about the object as a dict. */
p_retval = PyDict_New();
PyDict_SetItemString( p_retval, "object-id",
Py_BuildValue( "l", p_obj->i_object_id ) );
PyDict_SetItemString( p_retval, "object-type",
Py_BuildValue( "s", p_obj->psz_object_type ) );
PyDict_SetItemString( p_retval, "object-name",
Py_BuildValue( "s", p_obj->psz_object_name ) );
PyDict_SetItemString( p_retval, "thread",
PyBool_FromLong( p_obj->b_thread ) );
PyDict_SetItemString( p_retval, "thread-id",
PyLong_FromLongLong( p_obj->thread_id ) );
PyDict_SetItemString( p_retval, "refcount",
PyInt_FromLong( p_obj->i_refcount ) );
return p_retval;
}
static PyObject *
vlcObject_find_id( PyObject *self, PyObject *args )
{
vlcObject *p_retval;
vlc_object_t* p_object;
int i_id;
if( !PyArg_ParseTuple( args, "i", &i_id ) )
return NULL;
p_object = ( vlc_object_t* )vlc_current_object( i_id );
if( !p_object )
{
Py_INCREF( Py_None );
return Py_None;
}
p_retval = PyObject_NEW( vlcObject, &vlcObject_Type );
p_retval->p_object = p_object;
return ( PyObject * )p_retval;
}
/* Do a var_Get call on the object. Parameter: the variable name. */
static PyObject *
vlcObject_var_get( PyObject *self, PyObject *args )
{
PyObject *p_retval;
vlc_value_t value;
char *psz_name;
int i_type;
if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL;
if( var_Get( VLCSELF->p_object, psz_name, &value ) != VLC_SUCCESS )
{
PyErr_SetString( PyExc_StandardError,
"Error: variable does not exist.\n" );
return NULL;
}
i_type = var_Type ( VLCSELF->p_object, psz_name );
switch ( i_type )
{
case VLC_VAR_VOID :
p_retval = PyString_FromString( "A void variable" );
break;
case VLC_VAR_BOOL :
p_retval = PyBool_FromLong( value.b_bool );
break;
case VLC_VAR_INTEGER :
p_retval = PyInt_FromLong( ( long )value.i_int );
break;
case VLC_VAR_HOTKEY :
p_retval = PyString_FromFormat( "A hotkey variable ( %d )", value.i_int );
break;
case VLC_VAR_FILE :
case VLC_VAR_STRING :
case VLC_VAR_DIRECTORY :
case VLC_VAR_VARIABLE :
p_retval = PyString_FromString( value.psz_string );
break;
case VLC_VAR_MODULE :
p_retval = ( PyObject* )PyObject_New( vlcObject, &vlcObject_Type );
( ( vlcObject* )p_retval )->p_object = value.p_object;
break;
case VLC_VAR_FLOAT :
p_retval = PyFloat_FromDouble( ( double )value.f_float );
break;
case VLC_VAR_TIME :
p_retval = PyLong_FromLongLong( value.i_time );
break;
case VLC_VAR_ADDRESS :
p_retval = PyString_FromString( "A VLC address ( not handled yet )" );
break;
case VLC_VAR_LIST :
p_retval = PyString_FromString( "A VLC list ( not handled yet )" );
break;
case VLC_VAR_MUTEX :
p_retval = PyString_FromString( "A mutex" );
break;
default:
p_retval = Py_None;
}
Py_INCREF( p_retval );
return p_retval;
}
static PyObject *
vlcObject_var_type( PyObject *self, PyObject *args )
{
char *psz_name;
PyObject *p_retval;
int i_type;
if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL;
i_type = var_Type( VLCSELF->p_object, psz_name );
switch ( i_type )
{
case VLC_VAR_VOID :
p_retval = PyString_FromString( "Void" );
break;
case VLC_VAR_BOOL :
p_retval = PyString_FromString( "Boolean" );
break;
case VLC_VAR_INTEGER :
p_retval = PyString_FromString( "Integer" );
break;
case VLC_VAR_HOTKEY :
p_retval = PyString_FromString( "Hotkey" );
break;
case VLC_VAR_FILE :
p_retval = PyString_FromString( "File" );
break;
case VLC_VAR_STRING :
p_retval = PyString_FromString( "String" );
break;
case VLC_VAR_DIRECTORY :
p_retval = PyString_FromString( "Directory" );
break;
case VLC_VAR_VARIABLE :
p_retval = PyString_FromString( "Variable" );
break;
case VLC_VAR_MODULE :
p_retval = PyString_FromString( "Module" );
break;
case VLC_VAR_FLOAT :
p_retval = PyString_FromString( "Float" );
break;
case VLC_VAR_TIME :
p_retval = PyString_FromString( "Time" );
break;
case VLC_VAR_ADDRESS :
p_retval = PyString_FromString( "Address" );
break;
case VLC_VAR_LIST :
p_retval = PyString_FromString( "List" );
break;
case VLC_VAR_MUTEX :
p_retval = PyString_FromString( "Mutex" );
break;
default:
p_retval = PyString_FromString( "Unknown" );
}
return p_retval;
}
/* Do a var_Set call on the object. Parameter: the variable name. */
static PyObject *
vlcObject_var_set( PyObject *self, PyObject *args )
{
vlc_value_t value;
char *psz_name;
PyObject *py_value;
int i_type;
vlc_object_t *p_obj;
if( !PyArg_ParseTuple( args, "sO", &psz_name, &py_value ) )
return NULL;
p_obj = VLCSELF->p_object;
i_type = var_Type( p_obj, psz_name );
switch ( i_type )
{
case VLC_VAR_VOID :
break;
case VLC_VAR_BOOL :
value.b_bool = PyInt_AsLong( py_value );
break;
case VLC_VAR_INTEGER :
case VLC_VAR_HOTKEY :
value.i_int = PyInt_AsLong( py_value );
break;
case VLC_VAR_FILE :
case VLC_VAR_STRING :
case VLC_VAR_DIRECTORY :
case VLC_VAR_VARIABLE :
value.psz_string = strdup( PyString_AsString( py_value ) );
break;
case VLC_VAR_MODULE :
/* FIXME: we should check the PyObject type and get its p_object */
value.p_object = ( ( vlcObject* )p_obj )->p_object;
break;
case VLC_VAR_FLOAT :
value.f_float = PyFloat_AsDouble( py_value );
break;
case VLC_VAR_TIME :
value.i_time = PyLong_AsLongLong( py_value );
break;
case VLC_VAR_ADDRESS :
value.p_address = ( char* )PyLong_AsVoidPtr( py_value );
break;
case VLC_VAR_LIST :
/* FIXME */
value.p_list = NULL;
break;
case VLC_VAR_MUTEX :
break;
}
var_Set( p_obj, psz_name, value );
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcObject_var_list( PyObject *self, PyObject *args )
{
PyObject *p_retval;
int i_size;
int i_index;
i_size = VLCSELF->p_object->i_vars;
p_retval = PyTuple_New( i_size );
for ( i_index = 0 ; i_index < i_size ; i_index++ )
{
PyTuple_SetItem( p_retval, i_index,
Py_BuildValue( "s", VLCSELF->p_object->p_vars[i_index].psz_name ) );
}
return p_retval;
}
/* Do a config_Get call on the object. Parameter: the variable name. */
static PyObject *
vlcObject_config_get( PyObject *self, PyObject *args )
{
PyObject *p_retval;
vlc_value_t value;
char *psz_name;
module_config_t *p_config;
if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL;
p_config = config_FindConfig( VLCSELF->p_object, psz_name );
if( !p_config )
{
PyErr_SetString( PyExc_StandardError,
"Error: config variable does not exist.\n" );
return NULL;
}
switch ( p_config->i_type )
{
case CONFIG_ITEM_BOOL :
p_retval = PyBool_FromLong( p_config->i_value );
break;
case CONFIG_ITEM_INTEGER :
p_retval = PyInt_FromLong( ( long )p_config->i_value );
break;
case CONFIG_ITEM_KEY :
p_retval = PyString_FromFormat( "A hotkey variable ( %d )", p_config->i_value );
break;
case CONFIG_ITEM_FILE :
case CONFIG_ITEM_STRING :
case CONFIG_ITEM_DIRECTORY :
case CONFIG_ITEM_MODULE :
vlc_mutex_lock( p_config->p_lock );
if( p_config->psz_value )
p_retval = PyString_FromString( p_config->psz_value );
else
p_retval = PyString_FromString( "" );
vlc_mutex_unlock( p_config->p_lock );
break;
p_retval = ( PyObject* )PyObject_New( vlcObject, &vlcObject_Type );
( ( vlcObject* )p_retval )->p_object = value.p_object;
break;
case CONFIG_ITEM_FLOAT :
p_retval = PyFloat_FromDouble( ( double )p_config->f_value );
break;
default:
p_retval = Py_None;
Py_INCREF( p_retval );
}
return p_retval;
}
/* Do a config_put* call on the object. Parameter: the variable name. */
static PyObject *
vlcObject_config_set( PyObject *self, PyObject *args )
{
char *psz_name;
PyObject *py_value;
vlc_object_t *p_obj;
module_config_t *p_config;
if( !PyArg_ParseTuple( args, "sO", &psz_name, &py_value ) )
return NULL;
p_obj = VLCSELF->p_object;
p_config = config_FindConfig( p_obj, psz_name );
/* sanity checks */
if( !p_config )
{
PyErr_SetString( PyExc_StandardError,
"Error: option does not exist.\n" );
return NULL;
}
switch ( p_config->i_type )
{
case CONFIG_ITEM_BOOL :
case CONFIG_ITEM_INTEGER :
case CONFIG_ITEM_KEY :
config_PutInt( p_obj, psz_name, PyInt_AsLong( py_value ) );
break;
case CONFIG_ITEM_FILE :
case CONFIG_ITEM_STRING :
case CONFIG_ITEM_DIRECTORY :
case CONFIG_ITEM_MODULE :
config_PutPsz( p_obj, psz_name, PyString_AsString( py_value ) );
break;
case CONFIG_ITEM_FLOAT :
config_PutFloat( p_obj, psz_name, PyFloat_AsDouble( py_value ) );
break;
}
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcObject_children( PyObject *self, PyObject *args )
{
PyObject *p_retval;
int i_size;
int i_index;
i_size = VLCSELF->p_object->i_children;
p_retval = PyTuple_New( i_size );
for ( i_index = 0 ; i_index < i_size ; i_index++ )
{
PyTuple_SetItem( p_retval, i_index,
Py_BuildValue( "i",
VLCSELF->p_object->pp_children[i_index]->i_object_id ) );
}
return p_retval;
}
/* Method table */
static PyMethodDef vlcObject_methods[] =
{
{ "get", vlcObject_var_get, METH_VARARGS,
"get( str ) -> value Get a variable value."},
{ "set", vlcObject_var_set, METH_VARARGS,
"set( str, value ) Set a variable value" },
{ "config_get", vlcObject_config_get, METH_VARARGS,
"config_get( str ) -> value Get a configuration option." },
{ "config_set", vlcObject_config_set, METH_VARARGS,
"config_set( str, value ) Set a configuration option" },
{ "type", vlcObject_var_type, METH_VARARGS,
"type( str ) -> str Get a variable type" },
{ "list", vlcObject_var_list, METH_NOARGS,
"list( ) List the available variables" },
{ "children", vlcObject_children, METH_NOARGS,
"children( ) List the children ids" },
{ "find_object", vlcObject_find_object, METH_VARARGS,
"find_object( str ) -> Object Find the object of a given type.\n\nAvailable types are : aout, decoder, input, httpd, intf, playlist, root, vlc, vout"},
{ "find_id", vlcObject_find_id, METH_VARARGS,
"find_id( int ) -> Object Find an object by id" },
{ "info", vlcObject_info, METH_NOARGS,
"info( ) -> dict Return information about the object" },
{ "release", vlcObject_release, METH_NOARGS,
"release( ) -> Release the VLC Object" },
{ NULL, NULL, 0, NULL },
};
static PyTypeObject vlcObject_Type =
{
PyObject_HEAD_INIT( NULL )
0, /*ob_size*/
"vlc.Object", /*tp_name*/
sizeof( vlcObject_Type ), /*tp_basicsize*/
0, /*tp_itemsize*/
( destructor )vlcObject_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*/
"Expose VLC object infrastructure.", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
vlcObject_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 */
vlcObject_new, /* tp_new */
};
/***************************************************************************** /*****************************************************************************
* VLC MediaControl object implementation * VLC MediaControl object implementation
*****************************************************************************/ *****************************************************************************/
...@@ -741,6 +34,7 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds ) ...@@ -741,6 +34,7 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
PyObject* py_list = NULL; PyObject* py_list = NULL;
char** ppsz_args = NULL; char** ppsz_args = NULL;
fprintf(stderr, "mc_new start\n");
self = PyObject_New( MediaControl, &MediaControl_Type ); self = PyObject_New( MediaControl, &MediaControl_Type );
if( PyArg_ParseTuple( args, "O", &py_list ) ) if( PyArg_ParseTuple( args, "O", &py_list ) )
...@@ -779,12 +73,16 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds ) ...@@ -779,12 +73,16 @@ MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
PyErr_Clear( ); PyErr_Clear( );
} }
fprintf(stderr, "before mc_new\n");
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
MC_TRY; MC_TRY;
self->mc = mediacontrol_new( ppsz_args, exception ); self->mc = mediacontrol_new( ppsz_args, exception );
MC_EXCEPT; MC_EXCEPT;
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
fprintf(stderr, "mc_new end\n");
Py_INCREF( self ); Py_INCREF( self );
return ( PyObject * )self; return ( PyObject * )self;
} }
...@@ -1360,169 +658,3 @@ static PyTypeObject MediaControl_Type = ...@@ -1360,169 +658,3 @@ static PyTypeObject MediaControl_Type =
0, /* tp_alloc */ 0, /* tp_alloc */
MediaControl_new, /* tp_new */ MediaControl_new, /* tp_new */
}; };
/***********************************************************************
* Position
***********************************************************************/
static int
PyPosition_init( PyPosition *self, PyObject *args, PyObject *kwds )
{
self->origin = mediacontrol_AbsolutePosition;
self->key = mediacontrol_MediaTime;
self->value = 0;
return 0;
}
mediacontrol_PositionKey
positionKey_py_to_c( PyObject * py_key )
{
mediacontrol_PositionKey key_position = mediacontrol_MediaTime;
int key;
if( !PyArg_Parse( py_key, "i", &key ) )
{
PyErr_SetString ( MediaControl_InternalException, "Invalid key value" );
return key_position;
}
switch ( key )
{
case 0: key = mediacontrol_ByteCount; break;
case 1: key = mediacontrol_SampleCount; break;
case 2: key = mediacontrol_MediaTime; break;
}
return key_position;
}
mediacontrol_PositionOrigin
positionOrigin_py_to_c( PyObject * py_origin )
{
mediacontrol_PositionOrigin origin_position = mediacontrol_AbsolutePosition;
int origin;
if( !PyArg_Parse( py_origin,"i", &origin ) )
{
PyErr_SetString( MediaControl_InternalException,
"Invalid origin value" );
return origin_position;
}
switch ( origin )
{
case 0: origin_position = mediacontrol_AbsolutePosition; break;
case 1: origin_position = mediacontrol_RelativePosition; break;
case 2: origin_position = mediacontrol_ModuloPosition; break;
}
return origin_position;
}
/* Methods for transforming the Position Python object to Position structure*/
mediacontrol_Position*
position_py_to_c( PyObject * py_position )
{
mediacontrol_Position * a_position = NULL;
PyPosition *pos = ( PyPosition* )py_position;
a_position = ( mediacontrol_Position* )malloc( sizeof( mediacontrol_Position ) );
if( !a_position )
{
PyErr_SetString( PyExc_MemoryError, "Out of memory" );
return NULL;
}
if( !py_position )
{
/* If we give a NULL value, it will be considered as
a 0 relative position in mediatime */
a_position->origin = mediacontrol_RelativePosition;
a_position->key = mediacontrol_MediaTime;
a_position->value = 0;
}
else if( PyObject_IsInstance( py_position, ( PyObject* )&PyPosition_Type ) )
{
a_position->origin = pos->origin;
a_position->key = pos->key;
a_position->value = ntohll(pos->value);
}
else
{
/* Feature: if we give an integer, it will be considered as
a relative position in mediatime */
a_position->origin = mediacontrol_RelativePosition;
a_position->key = mediacontrol_MediaTime;
a_position->value = PyLong_AsLongLong( py_position );
}
return a_position;
}
PyPosition*
position_c_to_py( mediacontrol_Position *position )
{
PyPosition* py_retval;
py_retval = PyObject_New( PyPosition, &PyPosition_Type );
py_retval->origin = position->origin;
py_retval->key = position->key;
py_retval->value = position->value;
return py_retval;
}
static PyMethodDef PyPosition_methods[] =
{
{ NULL } /* Sentinel */
};
static PyMemberDef PyPosition_members[] =
{
{ "origin", T_INT, offsetof( PyPosition, origin ), 0, "Position origin" },
{ "key", T_INT, offsetof( PyPosition, key ), 0, "Position key" },
{ "value", T_ULONG, offsetof( PyPosition, value ), 0, "Position value" },
{ NULL } /* Sentinel */
};
static PyTypeObject PyPosition_Type =
{
PyObject_HEAD_INIT( NULL )
0, /*ob_size*/
"vlc.Position", /*tp_name*/
sizeof( PyPosition_Type ), /*tp_basicsize*/
0, /*tp_itemsize*/
0, /*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*/
"Represent a Position with origin, key and value", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
PyPosition_methods, /* tp_methods */
PyPosition_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
( initproc )PyPosition_init, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
/*****************************************************************************
* vlc_module.c: vlc python binding module
*****************************************************************************
* Copyright (C) 2006 the VideoLAN team
* $Id: $
*
* Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.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.
*****************************************************************************/
/* We need to access some internal features of VLC (for vlc_object) */
#define __VLC__
#include "vlcglue.h"
/**************************************************************************
* VLC Module
**************************************************************************/
#ifndef vlcMODINIT_FUNC /* declarations for DLL import/export */
#define vlcMODINIT_FUNC void
#endif
static PyMethodDef vlc_methods[] = {
{ NULL } /* Sentinel */
};
/* Module globals */
PyObject* MediaControl_InternalException = NULL;
PyObject* MediaControl_PositionKeyNotSupported = NULL;
PyObject *MediaControl_PositionOriginNotSupported = NULL;
PyObject* MediaControl_InvalidPosition = NULL;
PyObject *MediaControl_PlaylistException = NULL;
vlcMODINIT_FUNC
initvlc( void )
{
PyObject* p_module;
PyPosition_Type.tp_new = PyType_GenericNew;
PyPosition_Type.tp_alloc = PyType_GenericAlloc;
vlcInput_Type.tp_new = PyType_GenericNew;
vlcInput_Type.tp_alloc = PyType_GenericAlloc;
p_module = Py_InitModule3( "vlc", vlc_methods,
"VLC media player embedding module." );
if( !p_module )
return;
if( PyType_Ready( &PyPosition_Type ) < 0 )
return;
if( PyType_Ready( &MediaControl_Type ) < 0 )
return;
if( PyType_Ready( &vlcObject_Type ) < 0 )
return;
if( PyType_Ready( &vlcInstance_Type ) < 0 )
return;
if( PyType_Ready( &vlcInput_Type ) < 0 )
return;
/* Exceptions */
MediaControl_InternalException =
PyErr_NewException( "vlc.InternalException", NULL, NULL );
Py_INCREF( MediaControl_InternalException );
PyModule_AddObject( p_module, "InternalException",
MediaControl_InternalException );
MediaControl_PositionKeyNotSupported =
PyErr_NewException( "vlc.PositionKeyNotSupported", NULL, NULL );
Py_INCREF( MediaControl_PositionKeyNotSupported );
PyModule_AddObject( p_module, "PositionKeyNotSupported",
MediaControl_PositionKeyNotSupported );
MediaControl_PositionOriginNotSupported=
PyErr_NewException( "vlc.InvalidPosition", NULL, NULL );
Py_INCREF( MediaControl_PositionOriginNotSupported );
PyModule_AddObject( p_module, "PositionOriginNotSupported",
MediaControl_PositionOriginNotSupported );
MediaControl_InvalidPosition =
PyErr_NewException( "vlc.InvalidPosition", NULL, NULL );
Py_INCREF( MediaControl_InvalidPosition );
PyModule_AddObject( p_module, "InvalidPosition",
MediaControl_InvalidPosition );
MediaControl_PlaylistException =
PyErr_NewException( "vlc.PlaylistException", NULL, NULL );
Py_INCREF( MediaControl_PlaylistException );
PyModule_AddObject( p_module, "PlaylistException",
MediaControl_PlaylistException );
/* Exceptions */
vlcInstance_Exception =
PyErr_NewException( "vlc.InstanceException", NULL, NULL );
Py_INCREF( vlcInstance_Exception );
PyModule_AddObject( p_module, "InstanceException",
vlcInstance_Exception );
/* Types */
Py_INCREF( &PyPosition_Type );
PyModule_AddObject( p_module, "Position",
( PyObject * )&PyPosition_Type );
Py_INCREF( &MediaControl_Type );
PyModule_AddObject( p_module, "MediaControl",
( PyObject * )&MediaControl_Type );
Py_INCREF( &vlcObject_Type );
PyModule_AddObject( p_module, "Object",
( PyObject * )&vlcObject_Type );
Py_INCREF( &vlcInstance_Type );
PyModule_AddObject( p_module, "Instance",
( PyObject * )&vlcInstance_Type );
Py_INCREF( &vlcInput_Type );
PyModule_AddObject( p_module, "Input",
( PyObject * )&vlcInput_Type );
/* Constants */
PyModule_AddIntConstant( p_module, "AbsolutePosition",
mediacontrol_AbsolutePosition );
PyModule_AddIntConstant( p_module, "RelativePosition",
mediacontrol_RelativePosition );
PyModule_AddIntConstant( p_module, "ModuloPosition",
mediacontrol_ModuloPosition );
PyModule_AddIntConstant( p_module, "ByteCount",
mediacontrol_ByteCount );
PyModule_AddIntConstant( p_module, "SampleCount",
mediacontrol_SampleCount );
PyModule_AddIntConstant( p_module, "MediaTime",
mediacontrol_MediaTime );
PyModule_AddIntConstant( p_module, "PlayingStatus",
mediacontrol_PlayingStatus );
PyModule_AddIntConstant( p_module, "PauseStatus",
mediacontrol_PauseStatus );
PyModule_AddIntConstant( p_module, "ForwardStatus",
mediacontrol_ForwardStatus );
PyModule_AddIntConstant( p_module, "BackwardStatus",
mediacontrol_BackwardStatus );
PyModule_AddIntConstant( p_module, "InitStatus",
mediacontrol_InitStatus );
PyModule_AddIntConstant( p_module, "EndStatus",
mediacontrol_EndStatus );
PyModule_AddIntConstant( p_module, "UndefinedStatus",
mediacontrol_UndefinedStatus );
}
/* Make libpostproc happy... */
void * fast_memcpy( void * to, const void * from, size_t len )
{
return memcpy( to, from, 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
static... I am sorting the mess but in the meantime, this will
produce a working python module.
*/
#include "vlc_mediacontrol.c"
#include "vlc_position.c"
#include "vlc_instance.c"
#include "vlc_input.c"
#include "vlc_object.c"
/*****************************************************************************
* vlc_object.c: vlc.Object
*****************************************************************************
* Copyright (C) 2006 the VideoLAN team
* $Id: $
*
* Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.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.
*****************************************************************************/
/* We need to access some internal features of VLC */
#define __VLC__
#include "vlcglue.h"
/*****************************************************************************
* VLCObject implementation
*****************************************************************************/
static PyObject
*vlcObject_new( PyTypeObject *p_type, PyObject *p_args, PyObject *p_kwds )
{
vlcObject *self;
vlc_object_t *p_object;
int i_id;
self = PyObject_New( vlcObject, &vlcObject_Type );
if( !PyArg_ParseTuple( p_args, "i", &i_id ) )
return NULL;
/* Maybe we were already initialized */
p_object = ( vlc_object_t* )vlc_current_object( i_id );
if( !p_object )
{
/* Try to initialize */
i_id = VLC_Create();
if( i_id < 0 )
{
PyErr_SetString( PyExc_StandardError, "Unable to create a VLC instance." );
return NULL;
}
p_object = ( vlc_object_t* )vlc_current_object( i_id );
}
if( !p_object )
{
PyErr_SetString( PyExc_StandardError, "Unable to get object." );
return NULL;
}
self->p_object = p_object;
self->b_released = 0;
Py_INCREF( self ); /* Ah bon ? */
return ( PyObject * )self;
}
static PyObject *
vlcObject_release( PyObject *self, PyObject *p_args )
{
if( VLCSELF->b_released == 0 )
{
vlc_object_release( VLCSELF->p_object );
VLCSELF->b_released = 1;
}
Py_INCREF( Py_None );
return Py_None;
}
static void
vlcObject_dealloc( PyObject *self )
{
vlcObject_release( self, NULL );
PyMem_DEL( self );
}
static PyObject *
vlcObject_find_object( PyObject *self, PyObject *args )
{
vlcObject *p_retval;
vlc_object_t *p_obj;
char *psz_name;
int i_object_type;
if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL;
/* psz_name is in
( aout, decoder, input, httpd, intf, playlist, root, vlc, vout )
*/
if( !strncmp( psz_name, "aout", 4 ) )
{
i_object_type = VLC_OBJECT_AOUT;
}
else if (! strncmp( psz_name, "decoder", 7 ) )
{
i_object_type = VLC_OBJECT_DECODER;
}
else if (! strncmp( psz_name, "httpd", 5 ) )
{
i_object_type = VLC_OBJECT_HTTPD;
}
else if (! strncmp( psz_name, "intf", 4 ) )
{
i_object_type = VLC_OBJECT_INTF;
}
else if (! strncmp( psz_name, "input", 5 ) )
{
i_object_type = VLC_OBJECT_INPUT;
}
else if (! strncmp( psz_name, "playlist", 8 ) )
{
i_object_type = VLC_OBJECT_PLAYLIST;
}
else if (! strncmp( psz_name, "root", 4 ) )
{
i_object_type = VLC_OBJECT_ROOT;
}
else if (! strncmp( psz_name, "libvlc", 6 ) )
{
i_object_type = VLC_OBJECT_LIBVLC;
}
else if (! strncmp( psz_name, "vout", 4 ) )
{
i_object_type = VLC_OBJECT_VOUT;
}
else
{
/* FIXME: raise an exception ? */
Py_INCREF( Py_None );
return Py_None;
}
p_obj = vlc_object_find( VLCSELF->p_object, i_object_type, FIND_ANYWHERE );
if( !p_obj )
{
Py_INCREF( Py_None );
return Py_None;
}
p_retval = PyObject_New( vlcObject, &vlcObject_Type );
p_retval->p_object = p_obj;
return ( PyObject * )p_retval;
}
static PyObject *
vlcObject_info( PyObject *self, PyObject *args )
{
PyObject *p_retval;
vlc_object_t *p_obj;
p_obj = VLCSELF->p_object;
/* Return information about the object as a dict. */
p_retval = PyDict_New();
PyDict_SetItemString( p_retval, "object-id",
Py_BuildValue( "l", p_obj->i_object_id ) );
PyDict_SetItemString( p_retval, "object-type",
Py_BuildValue( "s", p_obj->psz_object_type ) );
PyDict_SetItemString( p_retval, "object-name",
Py_BuildValue( "s", p_obj->psz_object_name ) );
PyDict_SetItemString( p_retval, "thread",
PyBool_FromLong( p_obj->b_thread ) );
PyDict_SetItemString( p_retval, "thread-id",
PyLong_FromLongLong( p_obj->thread_id ) );
PyDict_SetItemString( p_retval, "refcount",
PyInt_FromLong( p_obj->i_refcount ) );
return p_retval;
}
static PyObject *
vlcObject_find_id( PyObject *self, PyObject *args )
{
vlcObject *p_retval;
vlc_object_t* p_object;
int i_id;
if( !PyArg_ParseTuple( args, "i", &i_id ) )
return NULL;
p_object = ( vlc_object_t* )vlc_current_object( i_id );
if( !p_object )
{
Py_INCREF( Py_None );
return Py_None;
}
p_retval = PyObject_NEW( vlcObject, &vlcObject_Type );
p_retval->p_object = p_object;
return ( PyObject * )p_retval;
}
/* Do a var_Get call on the object. Parameter: the variable name. */
static PyObject *
vlcObject_var_get( PyObject *self, PyObject *args )
{
PyObject *p_retval;
vlc_value_t value;
char *psz_name;
int i_type;
if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL;
if( var_Get( VLCSELF->p_object, psz_name, &value ) != VLC_SUCCESS )
{
PyErr_SetString( PyExc_StandardError,
"Error: variable does not exist.\n" );
return NULL;
}
i_type = var_Type ( VLCSELF->p_object, psz_name );
switch ( i_type )
{
case VLC_VAR_VOID :
p_retval = PyString_FromString( "A void variable" );
break;
case VLC_VAR_BOOL :
p_retval = PyBool_FromLong( value.b_bool );
break;
case VLC_VAR_INTEGER :
p_retval = PyInt_FromLong( ( long )value.i_int );
break;
case VLC_VAR_HOTKEY :
p_retval = PyString_FromFormat( "A hotkey variable ( %d )", value.i_int );
break;
case VLC_VAR_FILE :
case VLC_VAR_STRING :
case VLC_VAR_DIRECTORY :
case VLC_VAR_VARIABLE :
p_retval = PyString_FromString( value.psz_string );
break;
case VLC_VAR_MODULE :
p_retval = ( PyObject* )PyObject_New( vlcObject, &vlcObject_Type );
( ( vlcObject* )p_retval )->p_object = value.p_object;
break;
case VLC_VAR_FLOAT :
p_retval = PyFloat_FromDouble( ( double )value.f_float );
break;
case VLC_VAR_TIME :
p_retval = PyLong_FromLongLong( value.i_time );
break;
case VLC_VAR_ADDRESS :
p_retval = PyString_FromString( "A VLC address ( not handled yet )" );
break;
case VLC_VAR_LIST :
p_retval = PyString_FromString( "A VLC list ( not handled yet )" );
break;
case VLC_VAR_MUTEX :
p_retval = PyString_FromString( "A mutex" );
break;
default:
p_retval = Py_None;
}
Py_INCREF( p_retval );
return p_retval;
}
static PyObject *
vlcObject_var_type( PyObject *self, PyObject *args )
{
char *psz_name;
PyObject *p_retval;
int i_type;
if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL;
i_type = var_Type( VLCSELF->p_object, psz_name );
switch ( i_type )
{
case VLC_VAR_VOID :
p_retval = PyString_FromString( "Void" );
break;
case VLC_VAR_BOOL :
p_retval = PyString_FromString( "Boolean" );
break;
case VLC_VAR_INTEGER :
p_retval = PyString_FromString( "Integer" );
break;
case VLC_VAR_HOTKEY :
p_retval = PyString_FromString( "Hotkey" );
break;
case VLC_VAR_FILE :
p_retval = PyString_FromString( "File" );
break;
case VLC_VAR_STRING :
p_retval = PyString_FromString( "String" );
break;
case VLC_VAR_DIRECTORY :
p_retval = PyString_FromString( "Directory" );
break;
case VLC_VAR_VARIABLE :
p_retval = PyString_FromString( "Variable" );
break;
case VLC_VAR_MODULE :
p_retval = PyString_FromString( "Module" );
break;
case VLC_VAR_FLOAT :
p_retval = PyString_FromString( "Float" );
break;
case VLC_VAR_TIME :
p_retval = PyString_FromString( "Time" );
break;
case VLC_VAR_ADDRESS :
p_retval = PyString_FromString( "Address" );
break;
case VLC_VAR_LIST :
p_retval = PyString_FromString( "List" );
break;
case VLC_VAR_MUTEX :
p_retval = PyString_FromString( "Mutex" );
break;
default:
p_retval = PyString_FromString( "Unknown" );
}
return p_retval;
}
/* Do a var_Set call on the object. Parameter: the variable name. */
static PyObject *
vlcObject_var_set( PyObject *self, PyObject *args )
{
vlc_value_t value;
char *psz_name;
PyObject *py_value;
int i_type;
vlc_object_t *p_obj;
if( !PyArg_ParseTuple( args, "sO", &psz_name, &py_value ) )
return NULL;
p_obj = VLCSELF->p_object;
i_type = var_Type( p_obj, psz_name );
switch ( i_type )
{
case VLC_VAR_VOID :
break;
case VLC_VAR_BOOL :
value.b_bool = PyInt_AsLong( py_value );
break;
case VLC_VAR_INTEGER :
case VLC_VAR_HOTKEY :
value.i_int = PyInt_AsLong( py_value );
break;
case VLC_VAR_FILE :
case VLC_VAR_STRING :
case VLC_VAR_DIRECTORY :
case VLC_VAR_VARIABLE :
value.psz_string = strdup( PyString_AsString( py_value ) );
break;
case VLC_VAR_MODULE :
/* FIXME: we should check the PyObject type and get its p_object */
value.p_object = ( ( vlcObject* )p_obj )->p_object;
break;
case VLC_VAR_FLOAT :
value.f_float = PyFloat_AsDouble( py_value );
break;
case VLC_VAR_TIME :
value.i_time = PyLong_AsLongLong( py_value );
break;
case VLC_VAR_ADDRESS :
value.p_address = ( char* )PyLong_AsVoidPtr( py_value );
break;
case VLC_VAR_LIST :
/* FIXME */
value.p_list = NULL;
break;
case VLC_VAR_MUTEX :
break;
}
var_Set( p_obj, psz_name, value );
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcObject_var_list( PyObject *self, PyObject *args )
{
PyObject *p_retval;
int i_size;
int i_index;
i_size = VLCSELF->p_object->i_vars;
p_retval = PyTuple_New( i_size );
for ( i_index = 0 ; i_index < i_size ; i_index++ )
{
PyTuple_SetItem( p_retval, i_index,
Py_BuildValue( "s", VLCSELF->p_object->p_vars[i_index].psz_name ) );
}
return p_retval;
}
/* Do a config_Get call on the object. Parameter: the variable name. */
static PyObject *
vlcObject_config_get( PyObject *self, PyObject *args )
{
PyObject *p_retval;
vlc_value_t value;
char *psz_name;
module_config_t *p_config;
if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL;
p_config = config_FindConfig( VLCSELF->p_object, psz_name );
if( !p_config )
{
PyErr_SetString( PyExc_StandardError,
"Error: config variable does not exist.\n" );
return NULL;
}
switch ( p_config->i_type )
{
case CONFIG_ITEM_BOOL :
p_retval = PyBool_FromLong( p_config->i_value );
break;
case CONFIG_ITEM_INTEGER :
p_retval = PyInt_FromLong( ( long )p_config->i_value );
break;
case CONFIG_ITEM_KEY :
p_retval = PyString_FromFormat( "A hotkey variable ( %d )", p_config->i_value );
break;
case CONFIG_ITEM_FILE :
case CONFIG_ITEM_STRING :
case CONFIG_ITEM_DIRECTORY :
case CONFIG_ITEM_MODULE :
vlc_mutex_lock( p_config->p_lock );
if( p_config->psz_value )
p_retval = PyString_FromString( p_config->psz_value );
else
p_retval = PyString_FromString( "" );
vlc_mutex_unlock( p_config->p_lock );
break;
p_retval = ( PyObject* )PyObject_New( vlcObject, &vlcObject_Type );
( ( vlcObject* )p_retval )->p_object = value.p_object;
break;
case CONFIG_ITEM_FLOAT :
p_retval = PyFloat_FromDouble( ( double )p_config->f_value );
break;
default:
p_retval = Py_None;
Py_INCREF( p_retval );
}
return p_retval;
}
/* Do a config_put* call on the object. Parameter: the variable name. */
static PyObject *
vlcObject_config_set( PyObject *self, PyObject *args )
{
char *psz_name;
PyObject *py_value;
vlc_object_t *p_obj;
module_config_t *p_config;
if( !PyArg_ParseTuple( args, "sO", &psz_name, &py_value ) )
return NULL;
p_obj = VLCSELF->p_object;
p_config = config_FindConfig( p_obj, psz_name );
/* sanity checks */
if( !p_config )
{
PyErr_SetString( PyExc_StandardError,
"Error: option does not exist.\n" );
return NULL;
}
switch ( p_config->i_type )
{
case CONFIG_ITEM_BOOL :
case CONFIG_ITEM_INTEGER :
case CONFIG_ITEM_KEY :
config_PutInt( p_obj, psz_name, PyInt_AsLong( py_value ) );
break;
case CONFIG_ITEM_FILE :
case CONFIG_ITEM_STRING :
case CONFIG_ITEM_DIRECTORY :
case CONFIG_ITEM_MODULE :
config_PutPsz( p_obj, psz_name, PyString_AsString( py_value ) );
break;
case CONFIG_ITEM_FLOAT :
config_PutFloat( p_obj, psz_name, PyFloat_AsDouble( py_value ) );
break;
}
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcObject_children( PyObject *self, PyObject *args )
{
PyObject *p_retval;
int i_size;
int i_index;
i_size = VLCSELF->p_object->i_children;
p_retval = PyTuple_New( i_size );
for ( i_index = 0 ; i_index < i_size ; i_index++ )
{
PyTuple_SetItem( p_retval, i_index,
Py_BuildValue( "i",
VLCSELF->p_object->pp_children[i_index]->i_object_id ) );
}
return p_retval;
}
/* Method table */
static PyMethodDef vlcObject_methods[] =
{
{ "get", vlcObject_var_get, METH_VARARGS,
"get( str ) -> value Get a variable value."},
{ "set", vlcObject_var_set, METH_VARARGS,
"set( str, value ) Set a variable value" },
{ "config_get", vlcObject_config_get, METH_VARARGS,
"config_get( str ) -> value Get a configuration option." },
{ "config_set", vlcObject_config_set, METH_VARARGS,
"config_set( str, value ) Set a configuration option" },
{ "type", vlcObject_var_type, METH_VARARGS,
"type( str ) -> str Get a variable type" },
{ "list", vlcObject_var_list, METH_NOARGS,
"list( ) List the available variables" },
{ "children", vlcObject_children, METH_NOARGS,
"children( ) List the children ids" },
{ "find_object", vlcObject_find_object, METH_VARARGS,
"find_object( str ) -> Object Find the object of a given type.\n\nAvailable types are : aout, decoder, input, httpd, intf, playlist, root, vlc, vout"},
{ "find_id", vlcObject_find_id, METH_VARARGS,
"find_id( int ) -> Object Find an object by id" },
{ "info", vlcObject_info, METH_NOARGS,
"info( ) -> dict Return information about the object" },
{ "release", vlcObject_release, METH_NOARGS,
"release( ) -> Release the VLC Object" },
{ NULL, NULL, 0, NULL },
};
static PyTypeObject vlcObject_Type =
{
PyObject_HEAD_INIT( NULL )
0, /*ob_size*/
"vlc.Object", /*tp_name*/
sizeof( vlcObject_Type ), /*tp_basicsize*/
0, /*tp_itemsize*/
( destructor )vlcObject_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*/
"Expose VLC object infrastructure.", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
vlcObject_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 */
vlcObject_new, /* tp_new */
};
/*****************************************************************************
* vlc_position.c: vlc.Position binding
*****************************************************************************
* Copyright (C) 2006 the VideoLAN team
* $Id: $
*
* Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.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"
/***********************************************************************
* Position
***********************************************************************/
static int
PyPosition_init( PyPosition *self, PyObject *args, PyObject *kwds )
{
self->origin = mediacontrol_AbsolutePosition;
self->key = mediacontrol_MediaTime;
self->value = 0;
return 0;
}
mediacontrol_PositionKey
positionKey_py_to_c( PyObject * py_key )
{
mediacontrol_PositionKey key_position = mediacontrol_MediaTime;
int key;
if( !PyArg_Parse( py_key, "i", &key ) )
{
PyErr_SetString ( MediaControl_InternalException, "Invalid key value" );
return key_position;
}
switch ( key )
{
case 0: key = mediacontrol_ByteCount; break;
case 1: key = mediacontrol_SampleCount; break;
case 2: key = mediacontrol_MediaTime; break;
}
return key_position;
}
mediacontrol_PositionOrigin
positionOrigin_py_to_c( PyObject * py_origin )
{
mediacontrol_PositionOrigin origin_position = mediacontrol_AbsolutePosition;
int origin;
if( !PyArg_Parse( py_origin,"i", &origin ) )
{
PyErr_SetString( MediaControl_InternalException,
"Invalid origin value" );
return origin_position;
}
switch ( origin )
{
case 0: origin_position = mediacontrol_AbsolutePosition; break;
case 1: origin_position = mediacontrol_RelativePosition; break;
case 2: origin_position = mediacontrol_ModuloPosition; break;
}
return origin_position;
}
/* Methods for transforming the Position Python object to Position structure*/
mediacontrol_Position*
position_py_to_c( PyObject * py_position )
{
mediacontrol_Position * a_position = NULL;
PyPosition *pos = ( PyPosition* )py_position;
a_position = ( mediacontrol_Position* )malloc( sizeof( mediacontrol_Position ) );
if( !a_position )
{
PyErr_SetString( PyExc_MemoryError, "Out of memory" );
return NULL;
}
if( !py_position )
{
/* If we give a NULL value, it will be considered as
a 0 relative position in mediatime */
a_position->origin = mediacontrol_RelativePosition;
a_position->key = mediacontrol_MediaTime;
a_position->value = 0;
}
else if( PyObject_IsInstance( py_position, ( PyObject* )&PyPosition_Type ) )
{
a_position->origin = pos->origin;
a_position->key = pos->key;
a_position->value = ntohll(pos->value);
}
else
{
/* Feature: if we give an integer, it will be considered as
a relative position in mediatime */
a_position->origin = mediacontrol_RelativePosition;
a_position->key = mediacontrol_MediaTime;
a_position->value = PyLong_AsLongLong( py_position );
}
return a_position;
}
PyPosition*
position_c_to_py( mediacontrol_Position *position )
{
PyPosition* py_retval;
py_retval = PyObject_New( PyPosition, &PyPosition_Type );
py_retval->origin = position->origin;
py_retval->key = position->key;
py_retval->value = position->value;
return py_retval;
}
static PyMethodDef PyPosition_methods[] =
{
{ NULL } /* Sentinel */
};
static PyMemberDef PyPosition_members[] =
{
{ "origin", T_INT, offsetof( PyPosition, origin ), 0, "Position origin" },
{ "key", T_INT, offsetof( PyPosition, key ), 0, "Position key" },
{ "value", T_ULONG, offsetof( PyPosition, value ), 0, "Position value" },
{ NULL } /* Sentinel */
};
static PyTypeObject PyPosition_Type =
{
PyObject_HEAD_INIT( NULL )
0, /*ob_size*/
"vlc.Position", /*tp_name*/
sizeof( PyPosition_Type ), /*tp_basicsize*/
0, /*tp_itemsize*/
0, /*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*/
"Represent a Position with origin, key and value", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
PyPosition_methods, /* tp_methods */
PyPosition_members, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
( initproc )PyPosition_init, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
...@@ -21,14 +21,15 @@ ...@@ -21,14 +21,15 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#ifndef _VLCGLUE_H
#define _VLCGLUE_H 1
#include <Python.h> #include <Python.h>
#include "structmember.h" #include "structmember.h"
#define __VLC__
#include <stdio.h> #include <stdio.h>
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/libvlc.h>
#include <vlc/mediacontrol_structures.h> #include <vlc/mediacontrol_structures.h>
#include <vlc/mediacontrol.h> #include <vlc/mediacontrol.h>
...@@ -70,6 +71,7 @@ PyObject *MediaControl_PositionKeyNotSupported; ...@@ -70,6 +71,7 @@ PyObject *MediaControl_PositionKeyNotSupported;
PyObject *MediaControl_PositionOriginNotSupported; PyObject *MediaControl_PositionOriginNotSupported;
PyObject *MediaControl_InvalidPosition; PyObject *MediaControl_InvalidPosition;
PyObject *MediaControl_PlaylistException; PyObject *MediaControl_PlaylistException;
PyObject *vlcInstance_Exception;
/********************************************************************** /**********************************************************************
* VLC Object * VLC Object
...@@ -86,8 +88,6 @@ typedef struct ...@@ -86,8 +88,6 @@ typedef struct
int b_released; int b_released;
} vlcObject; } vlcObject;
staticforward PyTypeObject vlcObject_Type;
/********************************************************************** /**********************************************************************
* MediaControl Object * MediaControl Object
**********************************************************************/ **********************************************************************/
...@@ -95,9 +95,7 @@ typedef struct ...@@ -95,9 +95,7 @@ typedef struct
{ {
PyObject_HEAD PyObject_HEAD
mediacontrol_Instance* mc; mediacontrol_Instance* mc;
}MediaControl; } MediaControl;
staticforward PyTypeObject MediaControl_Type;
/********************************************************************** /**********************************************************************
* Position Object * Position Object
...@@ -110,7 +108,42 @@ typedef struct ...@@ -110,7 +108,42 @@ typedef struct
PY_LONG_LONG value; PY_LONG_LONG value;
} PyPosition; } PyPosition;
/**********************************************************************
* vlc.Instance Object
**********************************************************************/
typedef struct
{
PyObject_HEAD
libvlc_instance_t* p_instance;
} vlcInstance;
#define LIBVLC_INSTANCE ((vlcInstance*)self)
/**********************************************************************
* vlc.Input Object
**********************************************************************/
typedef struct
{
PyObject_HEAD
libvlc_input_t* p_input;
} vlcInput;
/* Forward declarations */
staticforward PyTypeObject vlcObject_Type;
staticforward PyTypeObject MediaControl_Type;
staticforward PyTypeObject PyPosition_Type; staticforward PyTypeObject PyPosition_Type;
staticforward PyTypeObject vlcInstance_Type;
staticforward PyTypeObject vlcInput_Type;
#define LIBVLC_INPUT ((vlcInput*)self)
#define LIBVLC_TRY libvlc_exception_init( &ex );
#define LIBVLC_EXCEPT if( libvlc_exception_raised( &ex ) ) { \
PyObject *py_exc = vlcInstance_Exception; \
PyErr_SetString( py_exc, libvlc_exception_get_message( &ex ) ); \
return NULL; \
}
mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key ); mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key );
mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin ); mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin );
...@@ -124,3 +157,4 @@ PyPosition * position_c_to_py( mediacontrol_Position * position ); ...@@ -124,3 +157,4 @@ PyPosition * position_c_to_py( mediacontrol_Position * position );
#define ntohll(x) (x) #define ntohll(x) (x)
#endif #endif
#endif
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