4 # Python ctypes bindings for VLC
5 # Copyright (C) 2009 the VideoLAN team
8 # Authors: Olivier Aubert <olivier.aubert at liris.cnrs.fr>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 """This module provides bindings for the
26 U{libvlc<http://wiki.videolan.org/ExternalAPI>} and
27 U{MediaControl<http://wiki.videolan.org/MediaControlAPI>} APIs.
29 You can find documentation at U{http://www.advene.org/download/python-ctypes/}.
31 Basically, the most important class is L{Instance}, which is used to
32 create a libvlc Instance. From this instance, you can then create
33 L{MediaPlayer} and L{MediaListPlayer} instances.
39 build_date="This will be replaced by the build date"
41 if sys.platform == 'linux2':
42 dll=ctypes.CDLL('libvlc.so')
43 elif sys.platform == 'win32':
44 dll=ctypes.CDLL('libvlc.dll')
45 elif sys.platform == 'darwin':
46 # FIXME: should find a means to configure path
47 dll=ctypes.CDLL('/Applications/VLC.app/Contents/MacOS/lib/libvlc.2.dylib')
49 class ListPOINTER(object):
50 '''Just like a POINTER but accept a list of ctype as an argument.
52 def __init__(self, etype):
55 def from_param(self, param):
56 if isinstance(param, (list,tuple)):
57 return (self.etype * len(param))(*param)
59 # From libvlc_structures.h
60 class VLCException(ctypes.Structure):
62 ('raised', ctypes.c_int),
63 ('code', ctypes.c_int),
64 ('message', ctypes.c_char_p),
67 libvlc_exception_init(self)
70 libvlc_exception_clear(self)
72 class PlaylistItem(ctypes.Structure):
75 ('uri', ctypes.c_char_p),
76 ('name', ctypes.c_char_p),
79 class LogMessage(ctypes.Structure):
81 ('size', ctypes.c_uint),
82 ('severity', ctypes.c_int),
83 ('type', ctypes.c_char_p),
84 ('name', ctypes.c_char_p),
85 ('header', ctypes.c_char_p),
86 ('message', ctypes.c_char_p),
90 print "vlc.LogMessage(%d:%s): %s" % (self.severity, self.type, self.message)
92 class MediaControlPosition(ctypes.Structure):
94 ('origin', ctypes.c_ushort),
95 ('key', ctypes.c_ushort),
96 ('value', ctypes.c_longlong),
101 if isinstance(arg, (int, long)):
102 p=MediaControlPosition()
109 class MediaControlPositionOrigin(ctypes.c_uint):
116 return self.enum[self.value]
118 class MediaControlException(ctypes.Structure):
120 ('code', ctypes.c_int),
121 ('message', ctypes.c_char_p),
124 mediacontrol_exception_init(self)
127 mediacontrol_exception_free(self)
129 class MediaControlStreamInformation(ctypes.Structure):
131 ('code', ctypes.c_int),
132 ('message', ctypes.c_char_p),
135 class RGBPicture(ctypes.Structure):
137 ('width', ctypes.c_int),
138 ('height', ctypes.c_int),
139 ('type', ctypes.c_uint32),
140 ('date', ctypes.c_longlong),
141 ('size', ctypes.c_int),
142 ('data', ctypes.c_char_p),
146 mediacontrol_RGBPicture__free(self)
148 def check_vlc_exception(result, func, args):
149 """Error checking method for functions using an exception in/out parameter.
152 # Take into account both VLCException and MediacontrolException
153 c=getattr(ex, 'raised', getattr(ex, 'code', 0))
155 raise Exception(args[-1].message)