Commit 51356824 authored by Rémi Duraffort's avatar Rémi Duraffort

Remove the python bindings. The python bindings is now autogenerated.

The autogenerated python bindings is now hosted in a specific git directory at:
git.videolan.org/vlc/bindings/python.git.
parent d9a487c2
include vlcglue.h
include vlc_mediacontrol.c
include vlc_position.c
include vlc_instance.c
include vlc_mediaplayer.c
include vlc_media.c
include vlcwidget.py
********************************************
IMPORTANT NOTE
********************************************
This native version of VLC bindings is now deprecated. Please use the
new ctypes-based bindings, which can be found in the
bindings/python-ctypes directory of the VLC source tree.
* 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 (and are hardcoded for a standard installation,
i.e. /usr/lib/vlc on *NIX)
For vlc.MediaControl:
mc=vlc.MediaControl('--plugin-path /path/to/vlc/directory'.split())
For vlc.Instance:
i=vlc.Instance('--plugin-path /path/to/vlc/directory'.split())
* Skeleton generation (for developers of the module):
** For method bindings:
perl -n -e 'print "static PyObject *\nvlcInput_$2( PyObject *self, PyObject *args )\n{\n libvlc_exception_t ex;\n LIBVLC_TRY;\n $1_$2( self->p_input, &ex); LIBVLC_EXCEPT;\n Py_INCREF( Py_None );\n return Py_None;\n}\n\n" if /(libvlc_input)_(\w+)/ and ($2 ne "t")' ../../include/vlc/libvlc.h
** For method table:
perl -n -e 'print " { \"$2\", $1_$2, METH_VARARGS,\n \"$2()\" },\n" if /^(vlcInstance)_(\w+)/' vlc_instance.c
Source: python-vlc
Section: contrib/libs
Priority: optional
Maintainer: Jason Scheunemann <jason.scheunemann@yahoo.com>
Build-Depends: cdbs, debhelper (>= 7), python-central (>=0.5.6), python-setuptools, python-dev, libvlc-dev (>= 1.0.0)
XS-Python-Version: 2.5
Standards-Version: 3.8.0
Homepage: http://wiki.videolan.org/PythonBinding
Package: python-vlc
Architecture: any
XB-Python-Version: ${python:Versions}
Depends: ${python:Depends}, ${misc:Depends}, vlc (>= 1.0.0)
Description: VLC bindings for python.
VLC bindings for python.
#!/usr/bin/make -f
DEB_PYTHON_SYSTEM=pycentral
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/python-distutils.mk
# Add here any variable or target overrides you need.
%define name python-vlc
%define version 1.0.0.90
%define unmangled_version 1.0.0.90
%define release 1
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
Summary: VLC bindings for python.
Name: %{name}
Version: %{version}
Release: %{release}
Source0: %{name}-%{unmangled_version}.tar.gz
License: GPL
Group: Development/Libraries
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
Prefix: %{_prefix}
Vendor: Olivier Aubert <olivier.aubert@liris.cnrs.fr>
Url: http://wiki.videolan.org/PythonBinding
%description
VLC bindings for python.
This module provides bindings for the native libvlc API of the VLC
video player. Documentation can be found on the VLC wiki :
http://wiki.videolan.org/ExternalAPI
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/PythonBinding
Example session (for the MediaControl API):
import vlc
mc=vlc.MediaControl(['--verbose', '1'])
mc.playlist_add_item('movie.mpg')
# Start the movie at 2000ms
p=vlc.Position()
p.origin=vlc.RelativePosition
p.key=vlc.MediaTime
p.value=2000
mc.start(p)
# which could be abbreviated as
# mc.start(2000)
# for the default conversion from int is to make a RelativePosition in MediaTime
# Display some text during 2000ms
mc.display_text('Some useless information', 0, 2000)
# Pause the video
mc.pause(0)
# Get status information
mc.get_stream_information()
%prep
%setup -n %{name}-%{unmangled_version}
%build
env CFLAGS="$RPM_OPT_FLAGS" python setup.py build
%install
python setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES
%clean
rm -rf $RPM_BUILD_ROOT
%files -f INSTALLED_FILES
%defattr(-,root,root)
%{python_sitelib}/vlcwidget.pyo
import sys
from distutils.core import setup, Extension
import os
import commands
# Get build variables (buildir, srcdir)
top_builddir = os.path.join( '..', '..' )
os.environ['top_builddir'] = top_builddir
# Determine the extra link args. Normally, vlc-config should take care
# of this and return the right path values, from a development tree or
# an installed version.
libtool=False
linkargs=[]
d=os.path.join(top_builddir, 'src', '.libs')
if os.path.exists(d):
# We are in a development tree, which was compiled with libtool
libtool=True
linkargs=[ '-L' + d ]
else:
d=os.path.join(top_builddir, 'src')
# We are in a development tree, which was compiled without libtool
if os.path.exists(d):
linkargs=[ '-L' + d ]
# For out-of-tree compilations
srcdir = '.'
def get_vlcconfig():
vlcconfig=None
for n in ( 'vlc-config',
os.path.join( top_builddir, 'vlc-config' )):
if os.path.exists(n):
vlcconfig=n
break
status, output = commands.getstatusoutput('pkg-config libvlc --exists')
if status == 0:
vlcconfig="pkg-config libvlc"
if vlcconfig is None:
print "*** Warning *** Cannot find vlc-config. Will try sane defaults."
elif os.sys.platform == 'win32':
# Win32 does not know how to invoke the shell itself.
vlcconfig="sh %s" % vlcconfig
return vlcconfig
def get_vlc_version():
vlcconfig=get_vlcconfig()
if vlcconfig is None:
return ""
else:
version=os.popen('%s --modversion' % vlcconfig, 'r').readline().strip()
return version
def get_cflags():
vlcconfig=get_vlcconfig()
if vlcconfig is None:
return []
else:
cflags=os.popen('%s --cflags ' % vlcconfig, 'r').readline().strip()
return cflags
def get_ldflags():
vlcconfig=get_vlcconfig()
if vlcconfig is None:
return [ '-lvlc' ]
else:
ldflags = []
if os.sys.platform == 'darwin':
ldflags = "-read_only_relocs warning".split()
ldflags.extend(os.popen('%s --libs ' % vlcconfig,
'r').readline().rstrip().split())
if os.sys.platform == 'darwin':
ldflags.append('-lstdc++')
if not '-lvlc' in ldflags:
# Some broken vlc-config can exist (esp. on win32). Try to
# workaround the problem.
ldflags.append('-lvlc')
return ldflags
# Import
if '--force-deprecated' in sys.argv:
sys.argv.remove('--force-deprecated')
else:
print """This native version of VLC bindings is now deprecated.
Please use the new ctypes-based bindings, which can be built from the
bindings/python-ctypes directory of the VLC source tree, or directly
get the generated python module from
http://www.advene.org/download/python-ctypes
However, if you insist on building this deprecated version, you should
pass the --force-deprecated option on the setup.py command line.
"""
sys.exit(1)
#source_files = [ 'vlc_module.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
vlclocal = Extension('vlc',
sources = [ os.path.join( srcdir, f ) for f in source_files ],
include_dirs = [ top_builddir,
srcdir ],
extra_objects = [ ],
extra_compile_args = get_cflags(),
extra_link_args = linkargs + get_ldflags(),
)
setup (name = 'python-vlc',
version = '1.0.0.90',
author='Olivier Aubert',
author_email='olivier.aubert@liris.cnrs.fr',
url='http://wiki.videolan.org/PythonBinding',
py_modules=['vlcwidget'],
keywords = [ 'vlc', 'video' ],
license = "GPL",
description = "VLC bindings for python.",
long_description = """VLC bindings for python.
This module provides bindings for the native libvlc API of the VLC
video player. Documentation can be found on the VLC wiki :
http://wiki.videolan.org/ExternalAPI
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/PythonBinding
Example session (for the MediaControl API):
import vlc
mc=vlc.MediaControl(['--verbose', '1'])
mc.playlist_add_item('movie.mpg')
# Start the movie at 2000ms
p=vlc.Position()
p.origin=vlc.RelativePosition
p.key=vlc.MediaTime
p.value=2000
mc.start(p)
# which could be abbreviated as
# mc.start(2000)
# for the default conversion from int is to make a RelativePosition in MediaTime
# Display some text during 2000ms
mc.display_text('Some useless information', 0, 2000)
# Pause the video
mc.pause(0)
# Get status information
mc.get_stream_information()
""",
ext_modules = [ vlclocal ])
This diff is collapsed.
/*****************************************************************************
* vlc_media.c: vlc.Media binding
*****************************************************************************
* Copyright (C) 2007 the VideoLAN team
* $Id$
*
* Authors: Olivier Aubert <olivier.aubert 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.Media
***********************************************************************/
static PyObject *
vlcMedia_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
{
fprintf(stderr, "vlcMedia_new called\n");
PyErr_SetString( PyExc_TypeError, "vlc.Media can be instantiated by itself. You should use vlc.Instance().media_new(mrl)." );
return NULL;
}
static void
vlcMedia_dealloc( PyObject *self )
{
libvlc_media_release( LIBVLC_MEDIA(self) );
PyObject_DEL( self );
}
static PyObject *
vlcMedia_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_add_option( LIBVLC_MEDIA(self), psz_options, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMedia_get_mrl( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char * psz_mrl;
PyObject * o_ret;
LIBVLC_TRY;
psz_mrl = libvlc_media_get_mrl( LIBVLC_MEDIA(self), &ex);
LIBVLC_EXCEPT;
o_ret = Py_BuildValue( "s", psz_mrl );
free( psz_mrl );
return o_ret;
}
static PyObject *
vlcMedia_get_state( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
libvlc_state_t i_state;
LIBVLC_TRY;
i_state = libvlc_media_get_state( LIBVLC_MEDIA(self), &ex);
LIBVLC_EXCEPT;
/* FIXME: return the defined state constant */
return Py_BuildValue( "i", i_state );
}
static PyObject *
vlcMedia_get_duration( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
libvlc_time_t i_ret;
LIBVLC_TRY;
i_ret = libvlc_media_get_duration( LIBVLC_MEDIA(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "L", i_ret );
}
static PyObject *
vlcMedia_media_player_new( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
libvlc_media_player_t *p_mp;
vlcMediaPlayer *p_ret;
LIBVLC_TRY;
p_mp = libvlc_media_player_new_from_media( LIBVLC_MEDIA(self), &ex);
LIBVLC_EXCEPT;
p_ret = PyObject_New( vlcMediaPlayer, &vlcMediaPlayer_Type );
p_ret->p_mp = p_mp;
Py_INCREF( p_ret ); /* Ah bon ? */
return ( PyObject * )p_ret;
}
static PyObject *
vlcMedia_is_preparsed( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_media_is_preparsed( LIBVLC_MEDIA(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "L", i_ret );
}
static PyObject *
vlcMedia_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;
}
i_loop++;
}
if( i_index < 0 )
{
PyObject *py_exc = vlc_Exception;
PyErr_SetString( py_exc, "Unknown meta attribute" );
return NULL;
}
LIBVLC_TRY;
psz_ret = libvlc_media_get_meta( LIBVLC_MEDIA(self), i_index, &ex);
LIBVLC_EXCEPT;
o_ret = Py_BuildValue( "s", psz_ret );
free( psz_ret );
return o_ret;
}
static PyMethodDef vlcMedia_methods[] =
{
{ "add_option", vlcMedia_add_option, METH_VARARGS,
"add_option(str) Add an option to the media." },
{ "get_mrl", vlcMedia_get_mrl, METH_VARARGS,
"get_mrl() -> str" },
{ "get_state", vlcMedia_get_state, METH_VARARGS,
"get_state() -> int" },
{ "get_duration", vlcMedia_get_duration, METH_VARARGS,
"get_duration() -> int" },
{ "mediaplayer_new", vlcMedia_media_player_new, METH_VARARGS,
"mediaplayer_new() -> vlc.MediaPlayer Create a MediaPlayer object from a Media" },
{ "is_preparsed", vlcMedia_is_preparsed, METH_VARARGS,
"is_preparsed() -> int" },
{ "get_meta", vlcMedia_get_meta, METH_VARARGS,
"get_meta(str) -> str Read the meta of the media." },
{ NULL } /* Sentinel */
};
static PyTypeObject vlcMedia_Type =
{
PyObject_HEAD_INIT( NULL )
0, /*ob_size*/
"vlc.Media", /*tp_name*/
sizeof( vlcMedia_Type ), /*tp_basicsize*/
0, /*tp_itemsize*/
vlcMedia_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.Media object.", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
vlcMedia_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 */
vlcMedia_new, /* tp_new */
};
This diff is collapsed.
This diff is collapsed.
/*****************************************************************************
* vlc_module.c: vlc python binding module
*****************************************************************************
* Copyright (C) 2006,2007,2008,2009 the VideoLAN team
* $Id$
*
* Authors: Olivier Aubert <olivier.aubert 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 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;
/* vlcMediaPlayer_Type.tp_new = PyType_GenericNew; */
vlcMediaPlayer_Type.tp_alloc = PyType_GenericAlloc;
/* vlcMedia_Type.tp_new = PyType_GenericNew; */
vlcMedia_Type.tp_alloc = PyType_GenericAlloc;
vlcInstance_Type.tp_alloc = PyType_GenericAlloc;
MediaControl_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( &vlcInstance_Type ) < 0 )
return;
if( PyType_Ready( &vlcMediaPlayer_Type ) < 0 )
return;
if( PyType_Ready( &vlcMedia_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 */
vlc_Exception =
PyErr_NewException( "vlc.InstanceException", NULL, NULL );
Py_INCREF( vlc_Exception );
PyModule_AddObject( p_module, "InstanceException",
vlc_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( &vlcInstance_Type );
PyModule_AddObject( p_module, "Instance",
( PyObject * )&vlcInstance_Type );
Py_INCREF( &vlcMediaPlayer_Type );
PyModule_AddObject( p_module, "MediaPlayer",
( PyObject * )&vlcMediaPlayer_Type );
Py_INCREF( &vlcMedia_Type );
PyModule_AddObject( p_module, "Media",
( PyObject * )&vlcMedia_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, "InitStatus",
mediacontrol_InitStatus );
PyModule_AddIntConstant( p_module, "EndStatus",
mediacontrol_EndStatus );
PyModule_AddIntConstant( p_module, "UndefinedStatus",
mediacontrol_UndefinedStatus );
}
/* 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 declared 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_mediaplayer.c"
#include "vlc_media.c"
/*****************************************************************************
* vlc_position.c: vlc.Position binding
*****************************************************************************
* Copyright (C) 2006,2007,2008,2009 the VideoLAN team
* $Id$
*
* Authors: Olivier Aubert <olivier.aubert 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"
/***********************************************************************
* Position
***********************************************************************/
static PyObject *
PyPosition_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
{
PyPosition *self;
static char *kwlist[] = { "value", "origin", "key", NULL};
self = PyObject_New( PyPosition, &PyPosition_Type );
self->value=0;
self->origin=mediacontrol_AbsolutePosition;
self->key=mediacontrol_MediaTime;
if(! PyArg_ParseTupleAndKeywords( args, kwds, "|lii", kwlist,
&(self->value),
&(self->origin),
&(self->key) ) )
{
return NULL;
}
if( self->key != mediacontrol_MediaTime
&& self->key != mediacontrol_ByteCount
&& self->key != mediacontrol_SampleCount )
{
PyErr_SetString ( MediaControl_InternalException, "Invalid key value" );
return NULL;
}
if( self->origin != mediacontrol_AbsolutePosition
&& self->origin != mediacontrol_RelativePosition
&& self->origin != mediacontrol_ModuloPosition )
{
PyErr_SetString ( MediaControl_InternalException, "Invalid origin value" );
return NULL;
}
Py_INCREF( self );
return ( PyObject * )self;
}
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 value, origin and key", /* 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 */
0, /* tp_init */
0, /* tp_alloc */
PyPosition_new, /* tp_new */
};
/*****************************************************************************
* vlcglue.h: Main header for the Python binding
*****************************************************************************
* Copyright (C) 1998-2004 the VideoLAN team
* $Id$
*
* Authors: Olivier Aubert <olivier.aubert at liris.cnrs.fr>
* Clément Stenac <zorglub@videolan.org>
*
* 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.
*****************************************************************************/
#ifndef _VLCGLUE_H
#define _VLCGLUE_H 1
#include <Python.h>
#include "structmember.h"
#include <stdio.h>
#include <vlc/vlc.h>
#include <vlc/libvlc.h>
#include <vlc/mediacontrol_structures.h>
#include <vlc/mediacontrol.h>
/* Python 2.5 64-bit support compatibility define */
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
typedef int Py_ssize_t;
#define PY_SSIZE_T_MAX INT_MAX
#define PY_SSIZE_T_MIN INT_MIN
#endif
/**********************************************************************
* Exceptions handling
**********************************************************************/
#define MC_TRY exception=mediacontrol_exception_create( )
#define MC_EXCEPT \
if( exception && exception->code ) { \
PyObject *py_exc = MediaControl_InternalException; \
switch( exception->code ) { \
case mediacontrol_InternalException: \
py_exc = MediaControl_InternalException; \
break; \
case mediacontrol_PlaylistException: \
py_exc = MediaControl_PlaylistException; \
break; \
case mediacontrol_InvalidPosition: \
py_exc = MediaControl_InvalidPosition; \
break; \
case mediacontrol_PositionKeyNotSupported: \
py_exc = MediaControl_PositionKeyNotSupported; \
break; \
case mediacontrol_PositionOriginNotSupported: \
py_exc = MediaControl_PositionOriginNotSupported; \
break; \
} \
PyErr_SetString( py_exc, exception->message ); \
mediacontrol_exception_free( exception ); \
return NULL; \
} else if( exception ) { mediacontrol_exception_free( exception ); }
PyObject *MediaControl_InternalException;
PyObject *MediaControl_PositionKeyNotSupported;
PyObject *MediaControl_PositionOriginNotSupported;
PyObject *MediaControl_InvalidPosition;
PyObject *MediaControl_PlaylistException;
PyObject *vlc_Exception;
/**********************************************************************
* vlc.Instance Object
**********************************************************************/
typedef struct
{
PyObject_HEAD
libvlc_instance_t* p_instance;
} vlcInstance;
/**********************************************************************
* MediaControl Object
**********************************************************************/
typedef struct
{
PyObject_HEAD
mediacontrol_Instance* mc;
vlcInstance *vlc_instance;
} MediaControl;
/**********************************************************************
* Position Object
**********************************************************************/
typedef struct
{
PyObject_HEAD
int origin;
int key;
PY_LONG_LONG value;
} PyPosition;
/**********************************************************************
* vlc.MediaPlayer Object
**********************************************************************/
typedef struct
{
PyObject_HEAD
libvlc_media_player_t* p_mp;
} vlcMediaPlayer;
/**********************************************************************
* vlc.Media Object
**********************************************************************/
typedef struct
{
PyObject_HEAD
libvlc_media_t* p_media;
} vlcMedia;
/* Forward declarations */
staticforward PyTypeObject MediaControl_Type;
staticforward PyTypeObject PyPosition_Type;
staticforward PyTypeObject vlcInstance_Type;
staticforward PyTypeObject vlcMediaPlayer_Type;
staticforward PyTypeObject vlcMedia_Type;
#define LIBVLC_INSTANCE(self) (((vlcInstance*)self)->p_instance)
#define LIBVLC_MEDIAPLAYER(self) (((vlcMediaPlayer*)self)->p_mp)
#define LIBVLC_MEDIA(self) (((vlcMedia*)self)->p_media)
#define LIBVLC_MC(self) (((MediaControl*)self)->mc)
#define LIBVLC_TRY libvlc_exception_init( &ex );
#define LIBVLC_EXCEPT if( libvlc_exception_raised( &ex ) ) { \
PyObject *py_exc = vlc_Exception; \
PyErr_SetString( py_exc, libvlc_errmsg() ); \
return NULL; \
}
mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key );
mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin );
mediacontrol_Position * position_py_to_c( PyObject * py_position );
PyPosition * position_c_to_py( mediacontrol_Position * position );
/* Long long conversion on Mac os X/ppc */
#if defined (__ppc__) || defined(__ppc64__)
#define ntohll(x) ((long long) x >> 64)
#else
#define ntohll(x) (x)
#endif
#endif
#! /usr/bin/python
"""VLC Widget classes.
This module provides two helper classes, to ease the embedding of a
VLC component inside a pygtk application.
VLCWidget is a simple VLC widget.
DecoratedVLCWidget provides simple player controls.
$Id$
"""
import gtk
import sys
import vlc
from gettext import gettext as _
class VLCWidget(gtk.DrawingArea):
"""Simple VLC widget.
Its player can be controlled through the 'player' attribute, which
is a MediaControl instance.
"""
def __init__(self, *p):
gtk.DrawingArea.__init__(self)
self.player=vlc.MediaControl(*p)
def handle_embed(*p):
if sys.platform == 'win32':
xidattr='handle'
else:
xidattr='xid'
self.player.set_visual(getattr(self.window, xidattr))
return True
self.connect("map-event", handle_embed)
self.set_size_request(320, 200)
class DecoratedVLCWidget(gtk.VBox):
"""Decorated VLC widget.
VLC widget decorated with a player control toolbar.
Its player can be controlled through the 'player' attribute, which
is a MediaControl instance.
"""
def __init__(self, *p):
gtk.VBox.__init__(self)
self._vlc_widget=VLCWidget(*p)
self.player=self._vlc_widget.player
self.pack_start(self._vlc_widget, expand=True)
self._toolbar = self.get_player_control_toolbar()
self.pack_start(self._toolbar, expand=False)
def get_player_control_toolbar(self):
"""Return a player control toolbar
"""
tb=gtk.Toolbar()
tb.set_style(gtk.TOOLBAR_ICONS)
def on_play(b):
self.player.start(0)
return True
def on_stop(b):
self.player.stop(0)
return True
def on_pause(b):
self.player.pause(0)
return True
tb_list = (
(_("Play"), _("Play"), gtk.STOCK_MEDIA_PLAY,
on_play),
(_("Pause"), _("Pause"), gtk.STOCK_MEDIA_PAUSE,
on_pause),
(_("Stop"), _("Stop"), gtk.STOCK_MEDIA_STOP,
on_stop),
)
for text, tooltip, stock, callback in tb_list:
b=gtk.ToolButton(stock)
b.connect("clicked", callback)
tb.insert(b, -1)
tb.show_all()
return tb
class VideoPlayer:
"""Example video player.
"""
def __init__(self):
self.vlc = DecoratedVLCWidget()
def main(self, fname):
self.vlc.player.set_mrl(fname)
self.popup()
gtk.main()
def popup(self):
w=gtk.Window()
w.add(self.vlc)
w.show_all()
w.connect("destroy", gtk.main_quit)
return w
if __name__ == '__main__':
if not sys.argv[1:]:
print "You must provide a movie filename"
sys.exit(1)
p=VideoPlayer()
p.main(sys.argv[1])
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