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.
28 build_date="This will be replaced by the build date"
30 if sys.platform == 'linux2':
31 dll=ctypes.CDLL('libvlc.so')
32 elif sys.platform == 'win32':
33 dll=ctypes.CDLL('libvlc.dll')
34 elif sys.platform == 'darwin':
35 # FIXME: should find a means to configure path
36 dll=ctypes.CDLL('/Applications/VLC.app/Contents/MacOS/lib/libvlc.2.dylib')
38 class ListPOINTER(object):
39 '''Just like a POINTER but accept a list of ctype as an argument.
41 def __init__(self, etype):
44 def from_param(self, param):
45 if isinstance(param, (list,tuple)):
46 return (self.etype * len(param))(*param)
48 # From libvlc_structures.h
49 class VLCException(ctypes.Structure):
51 ('raised', ctypes.c_int),
52 ('code', ctypes.c_int),
53 ('message', ctypes.c_char_p),
56 libvlc_exception_init(self)
59 libvlc_exception_clear(self)
61 class PlaylistItem(ctypes.Structure):
64 ('uri', ctypes.c_char_p),
65 ('name', ctypes.c_char_p),
68 class LogMessage(ctypes.Structure):
70 ('size', ctypes.c_uint),
71 ('severity', ctypes.c_int),
72 ('type', ctypes.c_char_p),
73 ('name', ctypes.c_char_p),
74 ('header', ctypes.c_char_p),
75 ('message', ctypes.c_char_p),
78 class MediaControlPosition(ctypes.Structure):
80 ('origin', ctypes.c_ushort),
81 ('key', ctypes.c_ushort),
82 ('value', ctypes.c_longlong),
87 if isinstance(arg, (int, long)):
88 p=MediaControlPosition()
95 class MediaControlPositionOrigin(ctypes.c_uint):
102 return self.enum[self.value]
104 class MediaControlException(ctypes.Structure):
106 ('code', ctypes.c_int),
107 ('message', ctypes.c_char_p),
110 mediacontrol_exception_init(self)
113 mediacontrol_exception_free(self)
115 class MediaControlStreamInformation(ctypes.Structure):
117 ('code', ctypes.c_int),
118 ('message', ctypes.c_char_p),
121 class RGBPicture(ctypes.Structure):
123 ('width', ctypes.c_int),
124 ('height', ctypes.c_int),
125 ('type', ctypes.c_uint32),
126 ('date', ctypes.c_longlong),
127 ('size', ctypes.c_int),
128 ('data', ctypes.c_char_p),
132 mediacontrol_RGBPicture__free(self)
134 # Decorator for callback methods
135 callbackmethod=ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_void_p)
137 def check_vlc_exception(result, func, args):
138 """Error checking method for functions using an exception in/out parameter.
141 # Take into account both VLCException and MediacontrolException
142 c=getattr(ex, 'raised', getattr(ex, 'code', 0))
144 raise Exception(args[-1].message)