[vlc-devel] commit: python-cytpes: fix MediaControl API support (Olivier Aubert )
git version control
git at videolan.org
Mon Aug 10 00:35:26 CEST 2009
vlc | branch: master | Olivier Aubert <olivier.aubert at liris.cnrs.fr> | Sun Aug 9 22:53:29 2009 +0200| [612953e02506efa7b1502a72eb7c96c91e12ada6] | committer: Olivier Aubert
python-cytpes: fix MediaControl API support
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=612953e02506efa7b1502a72eb7c96c91e12ada6
---
bindings/python-ctypes/TODO | 11 ++++++++
bindings/python-ctypes/generate.py | 6 ++--
bindings/python-ctypes/header.py | 48 ++++++++++++++++++++++++------------
bindings/python-ctypes/override.py | 44 ++++++++++++++++++++++++++++++++-
4 files changed, 89 insertions(+), 20 deletions(-)
diff --git a/bindings/python-ctypes/TODO b/bindings/python-ctypes/TODO
index 087d87b..088fd6a 100644
--- a/bindings/python-ctypes/TODO
+++ b/bindings/python-ctypes/TODO
@@ -4,3 +4,14 @@
* Support multiple VLC versions: define a front-end module which will
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 )
diff --git a/bindings/python-ctypes/generate.py b/bindings/python-ctypes/generate.py
index 87a5b37..3fbb644 100755
--- a/bindings/python-ctypes/generate.py
+++ b/bindings/python-ctypes/generate.py
@@ -114,10 +114,10 @@ typ2class={
'mediacontrol_Instance*': 'MediaControl',
'mediacontrol_Exception*': 'MediaControlException',
- 'mediacontrol_RGBPicture*': 'RGBPicture',
+ 'mediacontrol_RGBPicture*': 'ctypes.POINTER(RGBPicture)',
'mediacontrol_PlaylistSeq*': 'MediaControlPlaylistSeq',
- 'mediacontrol_Position*': 'MediaControlPosition',
- 'mediacontrol_StreamInformation*': 'MediaControlStreamInformation',
+ 'mediacontrol_Position*': 'ctypes.POINTER(MediaControlPosition)',
+ 'mediacontrol_StreamInformation*': 'ctypes.POINTER(MediaControlStreamInformation)',
'WINDOWHANDLE': 'ctypes.c_ulong',
'void': 'None',
diff --git a/bindings/python-ctypes/header.py b/bindings/python-ctypes/header.py
index e375ef8..e81c6f8 100755
--- a/bindings/python-ctypes/header.py
+++ b/bindings/python-ctypes/header.py
@@ -97,6 +97,9 @@ class PlaylistItem(ctypes.Structure):
('name', ctypes.c_char_p),
]
+ def __str__(self):
+ return "PlaylistItem #%d %s (%uri)" % (self.id, self.name, self.uri)
+
class LogMessage(ctypes.Structure):
_fields_= [
('size', ctypes.c_uint),
@@ -108,15 +111,22 @@ class LogMessage(ctypes.Structure):
]
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):
_fields_= [
- ('origin', ctypes.c_ushort),
- ('key', ctypes.c_ushort),
+ ('origin', ctypes.c_int),
+ ('key', ctypes.c_int),
('value', ctypes.c_longlong),
]
+ def __str__(self):
+ return "MediaControlPosition %ld (%s, %s)" % (
+ self.value,
+ str(PositionOrigin(self.origin)),
+ str(PositionKey(self.key))
+ )
+
@staticmethod
def from_param(arg):
if isinstance(arg, (int, long)):
@@ -127,15 +137,6 @@ class MediaControlPosition(ctypes.Structure):
else:
return arg
-class MediaControlPositionOrigin(ctypes.c_uint):
- enum=(
- 'AbsolutePosition',
- 'RelativePosition',
- 'ModuloPosition',
- )
- def __repr__(self):
- return self.enum[self.value]
-
class MediaControlException(ctypes.Structure):
_fields_= [
('code', ctypes.c_int),
@@ -149,20 +150,35 @@ class MediaControlException(ctypes.Structure):
class MediaControlStreamInformation(ctypes.Structure):
_fields_= [
- ('code', ctypes.c_int),
- ('message', ctypes.c_char_p),
+ ('status', ctypes.c_int),
+ ('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):
_fields_= [
('width', ctypes.c_int),
('height', ctypes.c_int),
('type', ctypes.c_uint32),
- ('date', ctypes.c_longlong),
+ ('date', ctypes.c_ulonglong),
('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):
mediacontrol_RGBPicture__free(self)
diff --git a/bindings/python-ctypes/override.py b/bindings/python-ctypes/override.py
index 54a0b01..79d1115 100644
--- a/bindings/python-ctypes/override.py
+++ b/bindings/python-ctypes/override.py
@@ -77,6 +77,48 @@ class MediaControl:
e=MediaControlException()
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:
"""Create a new MediaPlayer instance.
@@ -101,7 +143,7 @@ class MediaPlayer:
if p:
o.set_media(i.media_new(p[0]))
return o
-
+
def get_instance(self):
"""Return the associated vlc.Instance.
"""
More information about the vlc-devel
mailing list