python-cytpes: fix MediaControl API support
authorOlivier Aubert <olivier.aubert@liris.cnrs.fr>
Sun, 9 Aug 2009 20:53:29 +0000 (22:53 +0200)
committerOlivier Aubert <olivier.aubert@liris.cnrs.fr>
Sun, 9 Aug 2009 22:29:52 +0000 (00:29 +0200)
TODO
generate.py
header.py
override.py

diff --git a/TODO b/TODO
index 087d87b..088fd6a 100644 (file)
--- a/TODO
+++ b/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 )
index 87a5b37..3fbb644 100755 (executable)
@@ -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',
index e375ef8..e81c6f8 100755 (executable)
--- a/header.py
+++ b/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)
 
index 54a0b01..79d1115 100644 (file)
@@ -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.
         """