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 ])
/*****************************************************************************
* vlc_instance.c: vlc.Instance 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"
/* Helper functions */
static Py_ssize_t
pyoptions_to_args(PyObject *py_options, char*** pppsz_args)
{
Py_ssize_t i_size;
Py_ssize_t i_index;
Py_INCREF( py_options );
if( ! PySequence_Check( py_options ) )
{
PyErr_SetString( PyExc_TypeError, "Parameter must be a sequence." );
return -1;
}
i_size = PySequence_Size( py_options );
char **ppsz_args = *pppsz_args = malloc( ( i_size + 1 ) * sizeof( char * ) );
if( ! ppsz_args )
{
PyErr_SetString( PyExc_MemoryError, "Out of memory" );
return -1;
}
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 );
return i_size;
}
static void
free_args(int i_size, char** ppsz_args)
{
int i_index;
for ( i_index = 0; i_index < i_size; i_index++ )
free( ppsz_args[i_index] );
free( ppsz_args );
}
/*****************************************************************************
* 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;
fprintf(stderr, "Instantiating\n");
if( PyArg_ParseTuple( args, "|O", &py_list ) )
{
i_size = pyoptions_to_args( py_list, &ppsz_args );
if( i_size < 0 )
return NULL;
}
else
{
/* No arguments were given. Clear the exception raised
by PyArg_ParseTuple. */
PyErr_Clear( );
}
self = PyObject_New( vlcInstance, &vlcInstance_Type );
Py_BEGIN_ALLOW_THREADS
LIBVLC_TRY
LIBVLC_INSTANCE(self) = libvlc_new( i_size, ppsz_args, &ex );
free_args( i_size, ppsz_args );
LIBVLC_EXCEPT
Py_END_ALLOW_THREADS
Py_INCREF( self );
return ( PyObject * )self;
}
static void
vlcInstance_dealloc( PyObject *self )
{
libvlc_release( LIBVLC_INSTANCE(self) );
PyObject_DEL( self );
}
static PyObject *
vlcInstance_new_media_player( 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( LIBVLC_INSTANCE(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 *
vlcInstance_audio_toggle_mute( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_audio_toggle_mute( LIBVLC_INSTANCE(self), &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(self), &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(self), 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(self), &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_volume( LIBVLC_INSTANCE(self), i_volume, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_audio_get_channel( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_audio_get_channel( LIBVLC_INSTANCE(self), &ex );
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcInstance_audio_set_channel( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_channel;
if( !PyArg_ParseTuple( args, "i", &i_channel ) )
return NULL;
LIBVLC_TRY;
libvlc_audio_set_channel( LIBVLC_INSTANCE(self), i_channel, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
/* vlm_add_broadcast : name, input MRL, output MRL
Keywords: options, enable, loop */
static PyObject *
vlcInstance_vlm_add_broadcast( PyObject *self, PyObject *args, PyObject *kwds )
{
libvlc_exception_t ex;
static char *kwlist[] = { "name", "input", "output",
"options", "enable", "loop", NULL};
char* psz_name = NULL;
char* psz_input = NULL;
char* psz_output = NULL;
PyObject* py_options = NULL;
int i_enable = 1;
int i_loop = 0;
int i_size = 0;
char** ppsz_args = NULL;
if( !PyArg_ParseTupleAndKeywords( args, kwds, "sss|Oii", kwlist,
&psz_name,
&psz_input, &psz_output,
&py_options, &i_enable, &i_loop ) )
return NULL;
if( py_options )
{
i_size = pyoptions_to_args( py_options, &ppsz_args );
}
LIBVLC_TRY;
libvlc_vlm_add_broadcast( LIBVLC_INSTANCE(self),
psz_name, psz_input, psz_output,
i_size, ppsz_args, i_enable, i_loop, &ex);
free_args( i_size, ppsz_args );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_del_media( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_name;
if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL;
LIBVLC_TRY;
libvlc_vlm_del_media( LIBVLC_INSTANCE(self), psz_name, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_set_enabled( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_name;
int i_enabled;
if( !PyArg_ParseTuple( args, "si", &psz_name, &i_enabled ) )
return NULL;
LIBVLC_TRY;
libvlc_vlm_set_enabled( LIBVLC_INSTANCE(self), psz_name, i_enabled, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_set_output( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_name;
char* psz_output;
if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_output ) )
return NULL;
LIBVLC_TRY;
libvlc_vlm_set_output( LIBVLC_INSTANCE(self), psz_name, psz_output, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_set_input( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_name;
char* psz_input;
if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_input ) )
return NULL;
LIBVLC_TRY;
libvlc_vlm_set_input( LIBVLC_INSTANCE(self), psz_name, psz_input, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_add_input( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_name;
char* psz_input;
if( !PyArg_ParseTuple( args, "ss", &psz_name, &psz_input ) )
return NULL;
LIBVLC_TRY;
libvlc_vlm_add_input( LIBVLC_INSTANCE(self), psz_name, psz_input, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_set_loop( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_name;
int i_loop;
if( !PyArg_ParseTuple( args, "si", &psz_name, &i_loop ) )
return NULL;
LIBVLC_TRY;
libvlc_vlm_set_loop( LIBVLC_INSTANCE(self), psz_name, i_loop, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_change_media( PyObject *self, PyObject *args, PyObject *kwds )
{
libvlc_exception_t ex;
static char *kwlist[] = { "name", "input", "output",
"options", "enable", "loop", NULL};
char* psz_name = NULL;
char* psz_input = NULL;
char* psz_output = NULL;
PyObject* py_options = NULL;
int i_enable = 1;
int i_loop = 0;
int i_size = 0;
char** ppsz_args = NULL;
if( !PyArg_ParseTupleAndKeywords( args, kwds, "sss|Oii", kwlist,
&psz_name,
&psz_input, &psz_output,
&py_options, &i_enable, &i_loop ) )
return NULL;
if( py_options )
{
i_size = pyoptions_to_args( py_options, &ppsz_args );
}
LIBVLC_TRY;
libvlc_vlm_change_media( LIBVLC_INSTANCE(self),
psz_name, psz_input, psz_output,
i_size, ppsz_args, i_enable, i_loop, &ex);
free_args( i_size, ppsz_args );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_play_media( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_name;
if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL;
LIBVLC_TRY;
libvlc_vlm_play_media( LIBVLC_INSTANCE(self), psz_name, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_stop_media( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_name;
if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL;
LIBVLC_TRY;
libvlc_vlm_stop_media( LIBVLC_INSTANCE(self), psz_name, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_pause_media( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_name;
if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL;
LIBVLC_TRY;
libvlc_vlm_pause_media( LIBVLC_INSTANCE(self), psz_name, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_seek_media( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_name;
float f_percentage;
if( !PyArg_ParseTuple( args, "sf", &psz_name, &f_percentage ) )
return NULL;
LIBVLC_TRY;
libvlc_vlm_seek_media( LIBVLC_INSTANCE(self), psz_name, f_percentage, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcInstance_vlm_show_media( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_name;
char* psz_ret;
PyObject* o_ret;
if( !PyArg_ParseTuple( args, "s", &psz_name ) )
return NULL;
LIBVLC_TRY;
psz_ret = libvlc_vlm_show_media( LIBVLC_INSTANCE(self), psz_name, &ex );
LIBVLC_EXCEPT;
o_ret = Py_BuildValue( "s", psz_ret );
free( psz_ret );
return o_ret;
}
static PyObject *
vlcInstance_media_new( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
libvlc_media_t *p_media;
char* psz_mrl = NULL;
vlcMedia *p_ret;
if( !PyArg_ParseTuple( args, "s", &psz_mrl ) )
return NULL;
LIBVLC_TRY;
p_media = libvlc_media_new( LIBVLC_INSTANCE(self), psz_mrl, &ex );
LIBVLC_EXCEPT;
p_ret = PyObject_New( vlcMedia, &vlcMedia_Type );
p_ret->p_media = p_media;
Py_INCREF( p_ret ); /* Ah bon ? */
return ( PyObject * )p_ret;
}
/* Method table */
static PyMethodDef vlcInstance_methods[] =
{
{ "get_vlc_id", vlcInstance_get_vlc_id, METH_NOARGS,
"get_vlc_id( ) -> int Get the instance id."},
{ "audio_toggle_mute", vlcInstance_audio_toggle_mute, METH_NOARGS,
"audio_toggle_mute() Toggle the mute state"},
{ "audio_get_mute", vlcInstance_audio_get_mute, METH_NOARGS,
"audio_get_mute() -> int Get the mute state"},
{ "audio_set_mute", vlcInstance_audio_set_mute, METH_VARARGS,
"audio_set_mute(state=int) Set the mute state"},
{ "audio_get_volume", vlcInstance_audio_get_volume, METH_NOARGS,
"audio_get_volume() -> int Get the audio volume"},
{ "audio_set_volume", vlcInstance_audio_set_volume, METH_VARARGS,
"audio_set_volume(volume=int) Set the audio volume"},
{ "audio_get_channel", vlcInstance_audio_get_channel, METH_NOARGS,
"audio_get_channel() -> int Get current audio channel" },
{ "audio_set_channel", vlcInstance_audio_set_channel, METH_VARARGS,
"audio_set_channel(int) Set current audio channel" },
{ "media_new", vlcInstance_media_new, METH_VARARGS,
"media_new(str) -> object Create a media object with the given mrl."},
{ "mediaplayer_new", vlcInstance_new_media_player, METH_NOARGS,
"mediaplayer_new() -> object Create a media player."},
{ "vlm_add_broadcast", vlcInstance_vlm_add_broadcast, METH_VARARGS | METH_KEYWORDS,
"vlm_add_broadcast(name=str, input=str, output=str, options=list, enable=int, loop=int) Add a new broadcast" },
{ "vlm_del_media", vlcInstance_vlm_del_media, METH_VARARGS,
"vlm_del_media(name=str) Delete a media" },
{ "vlm_set_enabled", vlcInstance_vlm_set_enabled, METH_VARARGS,
"vlm_set_enabled(name=str, enabled=int) Enable/disable a media" },
{ "vlm_set_output", vlcInstance_vlm_set_output, METH_VARARGS,
"vlm_set_output(name=str, output=str) Set the output" },
{ "vlm_set_input", vlcInstance_vlm_set_input, METH_VARARGS,
"vlm_set_input(name=str, output=str) Set the input" },
{ "vlm_add_input", vlcInstance_vlm_add_input, METH_VARARGS,
"vlm_add_input(name=str, output=str) Add a media's input MRL" },
{ "vlm_set_loop", vlcInstance_vlm_set_loop, METH_VARARGS,
"vlm_set_loop(name=str, loop=int) Change the looping value" },
{ "vlm_change_media", vlcInstance_vlm_change_media, METH_VARARGS | METH_KEYWORDS,
"vlm_change_media(name=str, input=str, output=str, options=list, enable=int, loop=int) Change the broadcast parameters" },
{ "vlm_play_media", vlcInstance_vlm_play_media, METH_VARARGS,
"vlm_play_media(name=str) Plays the named broadcast." },
{ "vlm_stop_media", vlcInstance_vlm_stop_media, METH_VARARGS,
"vlm_stop_media(name=str) Stops the named broadcast." },
{ "vlm_pause_media", vlcInstance_vlm_pause_media, METH_VARARGS,
"vlm_pause_media(name=str) Pauses the named broadcast." },
{ "vlm_seek_media", vlcInstance_vlm_seek_media, METH_VARARGS,
"vlm_seek_media(name=str, percentage=float) Seeks in the named broadcast." },
{ "vlm_show_media", vlcInstance_vlm_show_media, METH_VARARGS,
"vlm_show_media(name=str) Return information of the named broadcast." },
{ 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(args)", /* 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 */
};
/*****************************************************************************
* 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 */
};
/*****************************************************************************
* vlc_mediacontrol.c: vlc.MediaControl 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"
/*****************************************************************************
* VLC MediaControl object implementation
*****************************************************************************/
/* The MediaControl constructor takes either an existing vlc.Instance or a
list of strings */
static PyObject *
MediaControl_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
{
MediaControl *self;
mediacontrol_Exception *exception = NULL;
PyObject* py_param = NULL;
char** ppsz_args = NULL;
libvlc_instance_t* p_instance = NULL;
Py_ssize_t i_size = 0;
self = PyObject_New( MediaControl, &MediaControl_Type );
fprintf (stderr, "Instantiating mediacontrol\n");
if( PyArg_ParseTuple( args, "O", &py_param ) )
{
if( PyObject_TypeCheck( py_param, &vlcInstance_Type ) == 1 )
{
p_instance = ((vlcInstance*)py_param)->p_instance;
}
else
{
Py_ssize_t i_index;
Py_INCREF( py_param );
if( ! PySequence_Check( py_param ) )
{
PyErr_SetString( PyExc_TypeError, "Parameter must be a vlc.Instance or a sequence of strings." );
Py_DECREF( py_param );
return NULL;
}
i_size = PySequence_Size( py_param );
ppsz_args = malloc( ( i_size + 1 ) * sizeof( char * ) );
if( ! ppsz_args )
{
PyErr_SetString( PyExc_MemoryError, "Out of memory" );
Py_DECREF( py_param );
return NULL;
}
for ( i_index = 0; i_index < i_size; i_index++ )
{
ppsz_args[i_index] =
strdup( PyString_AsString( PyObject_Str(
PySequence_GetItem( py_param,
i_index ) ) ) );
}
ppsz_args[i_size] = NULL;
Py_DECREF( py_param );
}
}
else
{
/* No arguments were given. Clear the exception raised
by PyArg_ParseTuple. */
PyErr_Clear( );
}
Py_BEGIN_ALLOW_THREADS
MC_TRY;
if( p_instance )
{
self->mc = mediacontrol_new_from_instance( p_instance, exception );
Py_INCREF( py_param );
self->vlc_instance = ( vlcInstance* ) py_param;
}
else
{
self->mc = mediacontrol_new( i_size, ppsz_args, exception );
self->vlc_instance = PyObject_New( vlcInstance, &vlcInstance_Type );
self->vlc_instance->p_instance = mediacontrol_get_libvlc_instance( LIBVLC_MC(self) );
}
MC_EXCEPT;
Py_END_ALLOW_THREADS
Py_INCREF( self );
return ( PyObject * )self;
}
static void
MediaControl_dealloc( PyObject *self )
{
fprintf(stderr, "MC dealloc\n");
Py_DECREF( ((MediaControl*)self)->vlc_instance );
PyObject_DEL( self );
}
static PyObject *
MediaControl_get_vlc_instance( PyObject *self, PyObject *args )
{
vlcInstance *p_ret;
p_ret = ((MediaControl*)self)->vlc_instance;
Py_INCREF( p_ret );
return ( PyObject * )p_ret;
}
static PyObject *
MediaControl_get_mediaplayer( PyObject *self, PyObject *args )
{
vlcMediaPlayer *p_ret;
p_ret = PyObject_New( vlcMediaPlayer, &vlcMediaPlayer_Type );
p_ret->p_mp = mediacontrol_get_media_player( LIBVLC_MC(self) );
Py_INCREF( p_ret );
return ( PyObject * )p_ret;
}
/**
* Return the current position in the stream. The returned value can
be relative or absolute ( according to PositionOrigin ) and the unit
is set by PositionKey
*/
static PyObject *
MediaControl_get_media_position( PyObject *self, PyObject *args )
{
mediacontrol_Position* pos;
mediacontrol_Exception* exception = NULL;
PyObject *py_origin;
PyObject *py_key;
PyObject *py_retval;
mediacontrol_PositionOrigin origin;
mediacontrol_PositionKey key;
if( !PyArg_ParseTuple( args, "OO", &py_origin, &py_key ) )
return NULL;
origin = positionOrigin_py_to_c( py_origin );
key = positionKey_py_to_c( py_key );
Py_BEGIN_ALLOW_THREADS
MC_TRY;
pos = mediacontrol_get_media_position( LIBVLC_MC(self), origin, key, exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
py_retval = ( PyObject* )position_c_to_py( pos );
free( pos );
return py_retval;
}
/** Set the media position */
static PyObject *
MediaControl_set_media_position( PyObject *self, PyObject *args )
{
mediacontrol_Exception* exception = NULL;
mediacontrol_Position *a_position;
PyObject *py_pos;
if( !PyArg_ParseTuple( args, "O", &py_pos ) )
return NULL;
a_position = position_py_to_c( py_pos );
if( !a_position )
{
PyErr_SetString( PyExc_MemoryError, "Out of memory" );
return NULL;
}
Py_BEGIN_ALLOW_THREADS
MC_TRY;
mediacontrol_set_media_position( LIBVLC_MC(self), a_position, exception );
free( a_position );
Py_END_ALLOW_THREADS
MC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
MediaControl_start( PyObject *self, PyObject *args )
{
mediacontrol_Position *a_position;
mediacontrol_Exception *exception = NULL;
PyObject *py_pos;
if( !PyArg_ParseTuple( args, "O", &py_pos ) )
{
/* No argument. Use a default 0 value. */
PyErr_Clear( );
py_pos = NULL;
}
a_position = position_py_to_c( py_pos );
if( !a_position )
return NULL;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
mediacontrol_start( LIBVLC_MC(self), a_position, exception );
free( a_position );
Py_END_ALLOW_THREADS
MC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
MediaControl_pause( PyObject *self, PyObject *args )
{
mediacontrol_Exception *exception = NULL;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
mediacontrol_pause( LIBVLC_MC(self), exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
MediaControl_resume( PyObject *self, PyObject *args )
{
mediacontrol_Exception *exception = NULL;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
mediacontrol_resume( LIBVLC_MC(self), exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
MediaControl_stop( PyObject *self, PyObject *args )
{
mediacontrol_Exception *exception = NULL;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
mediacontrol_stop( LIBVLC_MC(self), exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
MediaControl_exit( PyObject *self, PyObject *args )
{
mediacontrol_exit( LIBVLC_MC(self) );
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
MediaControl_set_mrl( PyObject *self, PyObject *args )
{
char *psz_file;
mediacontrol_Exception *exception = NULL;
if( !PyArg_ParseTuple( args, "s", &psz_file ) )
return NULL;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
mediacontrol_set_mrl( LIBVLC_MC(self), psz_file, exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
MediaControl_get_mrl( PyObject *self, PyObject *args )
{
PyObject *py_retval;
char* psz_file;
mediacontrol_Exception *exception = NULL;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
psz_file = mediacontrol_get_mrl( LIBVLC_MC(self), exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
py_retval = Py_BuildValue( "s", psz_file );
free( psz_file );
return py_retval;
}
static PyObject *
MediaControl_snapshot( PyObject *self, PyObject *args )
{
mediacontrol_RGBPicture *p_retval = NULL;
mediacontrol_Exception* exception = NULL;
mediacontrol_Position *a_position = NULL;
PyObject *py_pos = NULL;
PyObject *py_obj = NULL;
if( !PyArg_ParseTuple( args, "O", &py_pos ) )
return NULL;
a_position = position_py_to_c( py_pos );
Py_BEGIN_ALLOW_THREADS
MC_TRY;
p_retval = mediacontrol_snapshot( LIBVLC_MC(self), a_position, exception );
free( a_position );
Py_END_ALLOW_THREADS
MC_EXCEPT;
if( !p_retval )
{
Py_INCREF( Py_None );
return Py_None;
}
/* FIXME: create a real RGBPicture object */
py_obj = PyDict_New();
PyDict_SetItemString( py_obj, "width",
Py_BuildValue( "i", p_retval->width ) );
PyDict_SetItemString( py_obj, "height",
Py_BuildValue( "i", p_retval->height ) );
PyDict_SetItemString( py_obj, "type",
Py_BuildValue( "i", p_retval->type ) );
PyDict_SetItemString( py_obj, "data",
Py_BuildValue( "s#", p_retval->data, p_retval->size ) );
PyDict_SetItemString( py_obj, "date",
Py_BuildValue( "L", p_retval->date ) );
mediacontrol_RGBPicture__free( p_retval );
return py_obj;
}
static PyObject*
MediaControl_display_text( PyObject *self, PyObject *args )
{
mediacontrol_Exception* exception = NULL;
PyObject *py_begin, *py_end;
char* message;
mediacontrol_Position * begin;
mediacontrol_Position * end;
if( !PyArg_ParseTuple( args, "sOO", &message, &py_begin, &py_end ) )
return NULL;
begin = position_py_to_c( py_begin );
end = position_py_to_c( py_end );
Py_BEGIN_ALLOW_THREADS
MC_TRY;
mediacontrol_display_text( LIBVLC_MC(self), message, begin, end, exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
free( begin );
free( end );
Py_INCREF( Py_None );
return Py_None;
}
static PyObject*
MediaControl_get_stream_information( PyObject *self, PyObject *args )
{
mediacontrol_StreamInformation *retval = NULL;
mediacontrol_Exception* exception = NULL;
PyObject *py_obj;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
retval = mediacontrol_get_stream_information(
LIBVLC_MC(self), mediacontrol_MediaTime, exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
py_obj = PyDict_New( );
/* FIXME: create a real StreamInformation object */
PyDict_SetItemString( py_obj, "status",
Py_BuildValue( "i", retval->streamstatus ) );
PyDict_SetItemString( py_obj, "url",
Py_BuildValue( "s", retval->url ) );
PyDict_SetItemString( py_obj, "position",
Py_BuildValue( "L", retval->position ) );
PyDict_SetItemString( py_obj, "length",
Py_BuildValue( "L", retval->length ) );
mediacontrol_StreamInformation__free( retval );
return py_obj;
}
static PyObject*
MediaControl_sound_set_volume( PyObject *self, PyObject *args )
{
mediacontrol_Exception* exception = NULL;
unsigned short volume;
if( !PyArg_ParseTuple( args, "H", &volume ) )
return NULL;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
mediacontrol_sound_set_volume( LIBVLC_MC(self), volume, exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject*
MediaControl_sound_get_volume( PyObject *self, PyObject *args )
{
mediacontrol_Exception* exception = NULL;
PyObject *py_retval;
unsigned short volume;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
volume = mediacontrol_sound_get_volume( LIBVLC_MC(self), exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
py_retval = Py_BuildValue( "H", volume );
return py_retval;
}
static PyObject*
MediaControl_set_rate( PyObject *self, PyObject *args )
{
mediacontrol_Exception* exception = NULL;
int rate;
if( !PyArg_ParseTuple( args, "i", &rate ) )
return NULL;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
mediacontrol_set_rate( LIBVLC_MC(self), rate, exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject*
MediaControl_get_rate( PyObject *self, PyObject *args )
{
mediacontrol_Exception* exception = NULL;
PyObject *py_retval;
int rate;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
rate = mediacontrol_get_rate( LIBVLC_MC(self), exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
py_retval = Py_BuildValue( "i", rate );
return py_retval;
}
static PyObject*
MediaControl_set_fullscreen( PyObject *self, PyObject *args )
{
mediacontrol_Exception* exception = NULL;
int fs;
if( !PyArg_ParseTuple( args, "i", &fs ) )
return NULL;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
mediacontrol_set_fullscreen( LIBVLC_MC(self), fs, exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject*
MediaControl_get_fullscreen( PyObject *self, PyObject *args )
{
mediacontrol_Exception* exception = NULL;
PyObject *py_retval;
int fs;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
fs = mediacontrol_get_fullscreen( LIBVLC_MC(self), exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
py_retval = Py_BuildValue( "i", fs );
return py_retval;
}
static PyObject*
MediaControl_set_visual( PyObject *self, PyObject *args )
{
mediacontrol_Exception* exception = NULL;
WINDOWHANDLE visual;
if( !PyArg_ParseTuple( args, "i", &visual ) )
return NULL;
Py_BEGIN_ALLOW_THREADS
MC_TRY;
mediacontrol_set_visual( LIBVLC_MC(self), visual, exception );
Py_END_ALLOW_THREADS
MC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyMethodDef MediaControl_methods[] =
{
{ "get_vlc_instance", MediaControl_get_vlc_instance, METH_VARARGS,
"get_vlc_instance( ) -> Instance Get embedded vlc.Instance." },
{ "get_mediaplayer", MediaControl_get_mediaplayer, METH_VARARGS,
"get_mediaplayer( ) -> MediaPlayer Get embedded vlc.MediaPlayer." },
{ "get_media_position", MediaControl_get_media_position, METH_VARARGS,
"get_media_position( origin, key ) -> Position Get current media position." },
{ "set_media_position", MediaControl_set_media_position, METH_VARARGS,
"set_media_position( Position ) Set media position" },
{ "start", MediaControl_start, METH_VARARGS,
"start( Position ) Start the player." },
{ "pause", MediaControl_pause, METH_VARARGS,
"pause( Position ) Pause the player." },
{ "resume", MediaControl_resume, METH_VARARGS,
"resume( Position ) Resume the player" },
{ "stop", MediaControl_stop, METH_VARARGS,
"stop( Position ) Stop the player" },
{ "exit", MediaControl_exit, METH_VARARGS,
"exit( ) Exit the player" },
{ "set_mrl", MediaControl_set_mrl, METH_VARARGS,
"set_mrl( str ) Set the file to be played" },
{ "get_mrl", MediaControl_get_mrl, METH_VARARGS,
"get_mrl( ) -> str Get the played file" },
{ "snapshot", MediaControl_snapshot, METH_VARARGS,
"snapshot( Position ) -> dict Take a snapshot" },
{ "display_text", MediaControl_display_text, METH_VARARGS,
"display_text( str, Position, Position ) Display a text on the video" },
{ "get_stream_information", MediaControl_get_stream_information,
METH_VARARGS,
"get_stream_information( ) -> dict Get information about the stream"},
{ "sound_get_volume", MediaControl_sound_get_volume, METH_VARARGS,
"sound_get_volume( ) -> int Get the volume" },
{ "sound_set_volume", MediaControl_sound_set_volume, METH_VARARGS,
"sound_set_volume( int ) Set the volume" },
{ "set_visual", MediaControl_set_visual, METH_VARARGS,
"set_visual( int ) Set the embedding window visual ID" },
{ "get_rate", MediaControl_get_rate, METH_VARARGS,
"get_rate( ) -> int Get the rate" },
{ "set_rate", MediaControl_set_rate, METH_VARARGS,
"set_rate( int ) Set the rate" },
{ "get_fullscreen", MediaControl_get_fullscreen, METH_VARARGS,
"get_fullscreen( ) -> int Get the fullscreen status" },
{ "set_fullscreen", MediaControl_set_fullscreen, METH_VARARGS,
"set_fullscreen( int ) Set the fullscreen status" },
{ NULL, NULL, 0, NULL },
};
static PyTypeObject MediaControl_Type =
{
PyObject_HEAD_INIT( NULL )
0, /*ob_size*/
"vlc.MediaControl", /*tp_name*/
sizeof( MediaControl_Type ), /*tp_basicsize*/
0, /*tp_itemsize*/
( destructor )MediaControl_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*/
"Control of a VLC instance.\n\nvlc.MediaControl(args): initialisation with a list of VLC parameters.\nvlc.MediaControl(instance): initialisation with an existing vlc.Instance", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
MediaControl_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 */
MediaControl_new, /* tp_new */
};
/*****************************************************************************
* vlc_mediaplayer.c: vlc.MediaPlayer 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"
/***********************************************************************
* vlc.Input
***********************************************************************/
static PyObject *
vlcMediaPlayer_get_length( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int64_t i_ret;
LIBVLC_TRY;
i_ret = libvlc_media_player_get_length( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "L", i_ret );
}
static PyObject *
vlcMediaPlayer_get_time( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int64_t i_ret;
LIBVLC_TRY;
i_ret = libvlc_media_player_get_time( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "L", i_ret );
}
static PyObject *
vlcMediaPlayer_set_time( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int64_t i_time;
if( !PyArg_ParseTuple( args, "L", &i_time ) )
return NULL;
LIBVLC_TRY;
libvlc_media_player_set_time( LIBVLC_MEDIAPLAYER(self), i_time, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_get_position( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
float f_ret;
LIBVLC_TRY;
f_ret = libvlc_media_player_get_position( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "f", f_ret );
}
static PyObject *
vlcMediaPlayer_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_media_player_set_position( LIBVLC_MEDIAPLAYER(self), f_pos, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_will_play( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_media_player_will_play( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_get_rate( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
float f_ret;
LIBVLC_TRY;
f_ret = libvlc_media_player_get_rate( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "f", f_ret );
}
static PyObject *
vlcMediaPlayer_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_media_player_set_rate( LIBVLC_MEDIAPLAYER(self), f_rate, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_get_state( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_media_player_get_state( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_has_vout( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_media_player_has_vout( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_get_fps( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
float f_ret;
LIBVLC_TRY;
f_ret = libvlc_media_player_get_fps( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "f", f_ret );
}
static PyObject *
vlcMediaPlayer_audio_get_track( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_audio_get_track( LIBVLC_MEDIAPLAYER(self), &ex );
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_audio_set_track( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_track;
if( !PyArg_ParseTuple( args, "i", &i_track ) )
return NULL;
LIBVLC_TRY;
libvlc_audio_set_track( LIBVLC_MEDIAPLAYER(self), i_track, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_get_chapter( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_media_player_get_chapter( LIBVLC_MEDIAPLAYER(self), &ex );
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_get_chapter_count( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_media_player_get_chapter_count( LIBVLC_MEDIAPLAYER(self), &ex );
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_set_chapter( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_chapter;
if( !PyArg_ParseTuple( args, "i", &i_chapter ) )
return NULL;
LIBVLC_TRY;
libvlc_media_player_set_chapter( LIBVLC_MEDIAPLAYER(self), i_chapter, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_toggle_fullscreen( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_toggle_fullscreen( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_set_fullscreen( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_fullscreen;
if( !PyArg_ParseTuple( args, "i", &i_fullscreen ) )
return NULL;
LIBVLC_TRY;
libvlc_set_fullscreen( LIBVLC_MEDIAPLAYER(self), i_fullscreen, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_get_fullscreen( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_get_fullscreen( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_get_height( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_video_get_height( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_get_width( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_video_get_width( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_get_aspect_ratio( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_ret;
PyObject* o_ret;
LIBVLC_TRY;
psz_ret = libvlc_video_get_aspect_ratio( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
o_ret=Py_BuildValue( "s", psz_ret );
free( psz_ret );
return o_ret;
}
static PyObject *
vlcMediaPlayer_set_aspect_ratio( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_ratio;
if( !PyArg_ParseTuple( args, "s", &psz_ratio ) )
return NULL;
LIBVLC_TRY;
libvlc_video_set_aspect_ratio( LIBVLC_MEDIAPLAYER(self), psz_ratio, &ex);
LIBVLC_EXCEPT;
free( psz_ratio );
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_video_take_snapshot( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
char* psz_filename;
if( !PyArg_ParseTuple( args, "s", &psz_filename ) )
return NULL;
LIBVLC_TRY;
libvlc_video_take_snapshot( LIBVLC_MEDIAPLAYER(self), psz_filename, 0, 0, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_is_seekable( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_media_player_is_seekable( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_can_pause( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_media_player_can_pause( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_play( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_media_player_play( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_pause( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_media_player_pause( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_stop( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
LIBVLC_TRY;
libvlc_media_player_stop( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_set_xwindow( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
uint32_t i_drawable;
if( !PyArg_ParseTuple( args, "i", &i_drawable ) )
return NULL;
LIBVLC_TRY;
libvlc_media_player_set_xwindow( LIBVLC_MEDIAPLAYER(self), i_drawable, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_get_xwindow( PyObject *self, PyObject *args )
{
uint32_t i_ret;
i_ret = libvlc_media_player_get_xwindow( LIBVLC_MEDIAPLAYER(self));
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_set_hwnd( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
void* i_drawable;
if( !PyArg_ParseTuple( args, "l", &i_drawable ) )
return NULL;
LIBVLC_TRY;
libvlc_media_player_set_hwnd( LIBVLC_MEDIAPLAYER(self), (void*) i_drawable, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_get_hwnd( PyObject *self, PyObject *args )
{
void* i_ret;
i_ret = libvlc_media_player_get_hwnd( LIBVLC_MEDIAPLAYER(self));
return Py_BuildValue( "l", i_ret );
}
static PyObject *
vlcMediaPlayer_set_agl( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
uint32_t i_drawable;
if( !PyArg_ParseTuple( args, "i", &i_drawable ) )
return NULL;
LIBVLC_TRY;
libvlc_media_player_set_agl( LIBVLC_MEDIAPLAYER(self), i_drawable, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_get_agl( PyObject *self, PyObject *args )
{
uint32_t i_ret;
i_ret = libvlc_media_player_get_agl( LIBVLC_MEDIAPLAYER(self));
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_set_nsobject( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
void* i_drawable;
if( !PyArg_ParseTuple( args, "l", &i_drawable ) )
return NULL;
LIBVLC_TRY;
libvlc_media_player_set_nsobject( LIBVLC_MEDIAPLAYER(self), (void*) i_drawable, &ex );
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyObject *
vlcMediaPlayer_get_nsobject( PyObject *self, PyObject *args )
{
void* i_ret;
i_ret = libvlc_media_player_get_nsobject( LIBVLC_MEDIAPLAYER(self));
return Py_BuildValue( "l", i_ret );
}
static PyObject *
vlcMediaPlayer_set_media( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
PyObject* py_param = NULL;
if( !PyArg_ParseTuple( args, "O", &py_param ) )
return NULL;
if( PyObject_TypeCheck( py_param, &vlcMedia_Type ) == 1 )
{
LIBVLC_TRY;
libvlc_media_player_set_media( LIBVLC_MEDIAPLAYER(self), ((vlcMedia*)py_param)->p_media, &ex );
LIBVLC_EXCEPT;
}
else
{
PyObject *py_exc = vlc_Exception;
PyErr_SetString( py_exc, "vlc.Media parameter needed" );
return NULL;
}
return NULL;
}
static PyObject *
vlcMediaPlayer_get_media( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
libvlc_media_t *p_media;
vlcMedia *p_ret;
LIBVLC_TRY;
p_media = libvlc_media_player_get_media( LIBVLC_MEDIAPLAYER(self), &ex );
LIBVLC_EXCEPT;
if( !p_media )
{
Py_INCREF( Py_None );
return Py_None;
}
else
{
p_ret = PyObject_New( vlcMedia, &vlcMedia_Type );
p_ret->p_media = p_media;
Py_INCREF( p_ret ); /* Ah bon ? */
return ( PyObject * )p_ret;
}
}
static PyObject *
vlcMediaPlayer_get_spu( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_ret;
LIBVLC_TRY;
i_ret = libvlc_video_get_spu( LIBVLC_MEDIAPLAYER(self), &ex);
LIBVLC_EXCEPT;
return Py_BuildValue( "i", i_ret );
}
static PyObject *
vlcMediaPlayer_set_spu( PyObject *self, PyObject *args )
{
libvlc_exception_t ex;
int i_spu;
if( !PyArg_ParseTuple( args, "i", &i_spu ) )
return NULL;
LIBVLC_TRY;
libvlc_video_set_spu( LIBVLC_MEDIAPLAYER(self), i_spu, &ex);
LIBVLC_EXCEPT;
Py_INCREF( Py_None );
return Py_None;
}
static PyMethodDef vlcMediaPlayer_methods[] =
{
{ "get_length", vlcMediaPlayer_get_length, METH_VARARGS,
"get_length() -> long " },
{ "get_time", vlcMediaPlayer_get_time, METH_VARARGS,
"get_time() -> long" },
{ "set_time", vlcMediaPlayer_set_time, METH_VARARGS,
"set_time(long)" },
{ "get_position", vlcMediaPlayer_get_position, METH_VARARGS,
"get_position() -> float" },
{ "set_position", vlcMediaPlayer_set_position, METH_VARARGS,
"set_position(float)" },
{ "will_play", vlcMediaPlayer_will_play, METH_VARARGS,
"will_play() -> int" },
{ "is_seekable", vlcMediaPlayer_is_seekable, METH_VARARGS,
"is_seekable() -> int" },
{ "can_pause", vlcMediaPlayer_can_pause, METH_VARARGS,
"can_pause() -> int" },
{ "get_rate", vlcMediaPlayer_get_rate, METH_VARARGS,
"get_rate() -> float" },
{ "set_rate", vlcMediaPlayer_set_rate, METH_VARARGS,
"set_rate(float)" },
{ "get_state", vlcMediaPlayer_get_state, METH_VARARGS,
"get_state() -> int" },
{ "has_vout", vlcMediaPlayer_has_vout, METH_VARARGS,
"has_vout() -> int" },
{ "get_fps", vlcMediaPlayer_get_fps, METH_VARARGS,
"get_fps() -> float" },
{ "audio_get_track", vlcMediaPlayer_audio_get_track, METH_VARARGS,
"audio_get_track() -> int Get current audio track" },
{ "audio_set_track", vlcMediaPlayer_audio_set_track, METH_VARARGS,
"audio_set_track(int) Set current audio track" },
{ "toggle_fullscreen", vlcMediaPlayer_toggle_fullscreen, METH_VARARGS,
"toggle_fullscreen() Toggle fullscreen status on video output" },
{ "set_fullscreen", vlcMediaPlayer_set_fullscreen, METH_VARARGS,
"set_fullscreen(bool) Enable or disable fullscreen on a video output" },
{ "get_fullscreen", vlcMediaPlayer_get_fullscreen, METH_VARARGS,
"get_fullscreen() -> bool Get current fullscreen status" },
{ "get_height", vlcMediaPlayer_get_height, METH_VARARGS,
"get_height() -> int Get current video height" },
{ "get_width", vlcMediaPlayer_get_width, METH_VARARGS,
"get_width() -> int Get current video width" },
{ "get_aspect_ratio", vlcMediaPlayer_get_aspect_ratio, METH_VARARGS,
"get_aspect_ratio() -> str Get current video aspect ratio" },
{ "set_aspect_ratio", vlcMediaPlayer_set_aspect_ratio, METH_VARARGS,
"set_aspect_ratio(str) Set new video aspect ratio" },
{ "video_take_snapshot", vlcMediaPlayer_video_take_snapshot, METH_VARARGS,
"video_take_snapshot(filename=str) Take a snapshot of the current video window" },
{ "play", vlcMediaPlayer_play, METH_VARARGS,
"play() Play the media instance" },
{ "pause", vlcMediaPlayer_pause, METH_VARARGS,
"pause() Pause the media instance" },
{ "stop", vlcMediaPlayer_stop, METH_VARARGS,
"stop() Stop the media instance" },
{ "set_xwindow", vlcMediaPlayer_set_xwindow, METH_VARARGS,
"set_xwindow() Set the X-Window id" },
{ "set_nsobject", vlcMediaPlayer_set_nsobject, METH_VARARGS,
"set_nsobject() Set the NSObject" },
{ "set_agl", vlcMediaPlayer_set_agl, METH_VARARGS,
"set_agl() Set the AGL" },
{ "set_hwnd", vlcMediaPlayer_set_hwnd, METH_VARARGS,
"set_hwndl() Set the HWND" },
{ "get_xwindow", vlcMediaPlayer_get_xwindow, METH_VARARGS,
"get_xwindow() Set the X-Window id" },
{ "get_nsobject", vlcMediaPlayer_get_nsobject, METH_VARARGS,
"get_nsobject() Set the NSObject" },
{ "get_agl", vlcMediaPlayer_get_agl, METH_VARARGS,
"get_agl() Set the AGL" },
{ "get_hwnd", vlcMediaPlayer_get_hwnd, METH_VARARGS,
"get_hwndl() Set the HWND" },
{ "get_chapter", vlcMediaPlayer_get_chapter, METH_VARARGS,
"get_chapter() -> int Get current chapter" },
{ "set_chapter", vlcMediaPlayer_set_chapter, METH_VARARGS,
"set_chapter(int) Set current chapter" },
{ "get_chapter_count", vlcMediaPlayer_get_chapter_count, METH_VARARGS,
"get_chapter_count() -> int Get current chapter count" },
{ "set_media", vlcMediaPlayer_set_media, METH_VARARGS,
"set_media(vlc.Media) Set the media that will be used by the media_player" },
{ "get_media", vlcMediaPlayer_get_media, METH_VARARGS,
"get_media() -> vlc.Media Get the media used by the media_player (if any)." },
{ "get_spu", vlcMediaPlayer_get_spu, METH_VARARGS,
"get_spu() -> int Get current video subtitle" },
{ "set_spu", vlcMediaPlayer_set_spu, METH_VARARGS,
"set_spu(int) Set new video subtitle" },
{ NULL } /* Sentinel */
};
static PyTypeObject vlcMediaPlayer_Type =
{
PyObject_HEAD_INIT( NULL )
0, /*ob_size*/
"vlc.MediaPlayer", /*tp_name*/
sizeof( vlcMediaPlayer_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.MediaPlayer object\n\nIt cannot be instantiated standalone, it must be obtained from an existing vlc.Instance object", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
vlcMediaPlayer_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_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