Commit 612953e0 authored by Olivier Aubert's avatar Olivier Aubert

python-cytpes: fix MediaControl API support

parent e863f5c9
...@@ -4,3 +4,14 @@ ...@@ -4,3 +4,14 @@
* Support multiple VLC versions: define a front-end module which will * Support multiple VLC versions: define a front-end module which will
load the appropriate versionned module from a subdirectory. load the appropriate versionned module from a subdirectory.
* Support options: --debug/-c, --output/-o, --check-symbols/-s, ...
* Use setup.py
* Refactor code:
class Parser(list_of_includes) -> properties enums, methods...,
dump()
check()...
class PythonGenerator(parser) -> p.save( filename )
...@@ -114,10 +114,10 @@ typ2class={ ...@@ -114,10 +114,10 @@ typ2class={
'mediacontrol_Instance*': 'MediaControl', 'mediacontrol_Instance*': 'MediaControl',
'mediacontrol_Exception*': 'MediaControlException', 'mediacontrol_Exception*': 'MediaControlException',
'mediacontrol_RGBPicture*': 'RGBPicture', 'mediacontrol_RGBPicture*': 'ctypes.POINTER(RGBPicture)',
'mediacontrol_PlaylistSeq*': 'MediaControlPlaylistSeq', 'mediacontrol_PlaylistSeq*': 'MediaControlPlaylistSeq',
'mediacontrol_Position*': 'MediaControlPosition', 'mediacontrol_Position*': 'ctypes.POINTER(MediaControlPosition)',
'mediacontrol_StreamInformation*': 'MediaControlStreamInformation', 'mediacontrol_StreamInformation*': 'ctypes.POINTER(MediaControlStreamInformation)',
'WINDOWHANDLE': 'ctypes.c_ulong', 'WINDOWHANDLE': 'ctypes.c_ulong',
'void': 'None', 'void': 'None',
......
...@@ -97,6 +97,9 @@ class PlaylistItem(ctypes.Structure): ...@@ -97,6 +97,9 @@ class PlaylistItem(ctypes.Structure):
('name', ctypes.c_char_p), ('name', ctypes.c_char_p),
] ]
def __str__(self):
return "PlaylistItem #%d %s (%uri)" % (self.id, self.name, self.uri)
class LogMessage(ctypes.Structure): class LogMessage(ctypes.Structure):
_fields_= [ _fields_= [
('size', ctypes.c_uint), ('size', ctypes.c_uint),
...@@ -108,15 +111,22 @@ class LogMessage(ctypes.Structure): ...@@ -108,15 +111,22 @@ class LogMessage(ctypes.Structure):
] ]
def __str__(self): def __str__(self):
print "vlc.LogMessage(%d:%s): %s" % (self.severity, self.type, self.message) return "vlc.LogMessage(%d:%s): %s" % (self.severity, self.type, self.message)
class MediaControlPosition(ctypes.Structure): class MediaControlPosition(ctypes.Structure):
_fields_= [ _fields_= [
('origin', ctypes.c_ushort), ('origin', ctypes.c_int),
('key', ctypes.c_ushort), ('key', ctypes.c_int),
('value', ctypes.c_longlong), ('value', ctypes.c_longlong),
] ]
def __str__(self):
return "MediaControlPosition %ld (%s, %s)" % (
self.value,
str(PositionOrigin(self.origin)),
str(PositionKey(self.key))
)
@staticmethod @staticmethod
def from_param(arg): def from_param(arg):
if isinstance(arg, (int, long)): if isinstance(arg, (int, long)):
...@@ -127,15 +137,6 @@ class MediaControlPosition(ctypes.Structure): ...@@ -127,15 +137,6 @@ class MediaControlPosition(ctypes.Structure):
else: else:
return arg return arg
class MediaControlPositionOrigin(ctypes.c_uint):
enum=(
'AbsolutePosition',
'RelativePosition',
'ModuloPosition',
)
def __repr__(self):
return self.enum[self.value]
class MediaControlException(ctypes.Structure): class MediaControlException(ctypes.Structure):
_fields_= [ _fields_= [
('code', ctypes.c_int), ('code', ctypes.c_int),
...@@ -149,20 +150,35 @@ class MediaControlException(ctypes.Structure): ...@@ -149,20 +150,35 @@ class MediaControlException(ctypes.Structure):
class MediaControlStreamInformation(ctypes.Structure): class MediaControlStreamInformation(ctypes.Structure):
_fields_= [ _fields_= [
('code', ctypes.c_int), ('status', ctypes.c_int),
('message', ctypes.c_char_p), ('url', ctypes.c_char_p),
('position', ctypes.c_longlong),
('length', ctypes.c_longlong),
] ]
def __str__(self):
return "%s (%s) : %ld / %ld" % (self.url,
str(PlayerStatus(self.status)),
self.position,
self.length)
class RGBPicture(ctypes.Structure): class RGBPicture(ctypes.Structure):
_fields_= [ _fields_= [
('width', ctypes.c_int), ('width', ctypes.c_int),
('height', ctypes.c_int), ('height', ctypes.c_int),
('type', ctypes.c_uint32), ('type', ctypes.c_uint32),
('date', ctypes.c_longlong), ('date', ctypes.c_ulonglong),
('size', ctypes.c_int), ('size', ctypes.c_int),
('data', ctypes.c_char_p), ('data_pointer', ctypes.c_void_p),
] ]
@property
def data(self):
return ctypes.string_at(self.data_pointer, self.size)
def __str__(self):
return "RGBPicture (%d, %d) - %ld ms - %d bytes" % (self.width, self.height, self.date, self.size)
def free(self): def free(self):
mediacontrol_RGBPicture__free(self) mediacontrol_RGBPicture__free(self)
......
...@@ -77,6 +77,48 @@ class MediaControl: ...@@ -77,6 +77,48 @@ class MediaControl:
e=MediaControlException() e=MediaControlException()
return mediacontrol_new(len(p), p, e) return mediacontrol_new(len(p), p, e)
def get_media_position(self, origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime):
e=MediaControlException()
p=mediacontrol_get_media_position(self, origin, key, e)
if p:
return p.contents
else:
return None
def set_media_position(self, pos):
if not isinstance(pos, MediaControlPosition):
pos=MediaControlPosition(origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime, value=long(pos))
e=MediaControlException()
mediacontrol_set_media_position(self, pos, e)
def start(self, pos=0):
if not isinstance(pos, MediaControlPosition):
pos=MediaControlPosition(origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime, value=long(pos))
e=MediaControlException()
mediacontrol_start(self, pos, e)
def snapshot(self, pos=0):
if not isinstance(pos, MediaControlPosition):
pos=MediaControlPosition(origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime, value=long(pos))
e=MediaControlException()
p=mediacontrol_snapshot(self, pos, e)
if p:
return p.contents
else:
return None
def display_text(self, message='', begin=0, end=1000):
if not isinstance(begin, MediaControlPosition):
begin=MediaControlPosition(origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime, value=long(begin))
if not isinstance(end, MediaControlPosition):
begin=MediaControlPosition(origin=PositionOrigin.AbsolutePosition, key=PositionKey.MediaTime, value=long(end))
e=MediaControlException()
mediacontrol_display_text(self, message, begin, end, e)
def get_stream_information(self, key=PositionKey.MediaTime):
e=MediaControlException()
return mediacontrol_get_stream_information(self, key, e).contents
class MediaPlayer: class MediaPlayer:
"""Create a new MediaPlayer instance. """Create a new MediaPlayer instance.
......
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