Author: tack
Date: Sun Feb 24 12:30:24 2008
New Revision: 3129

Log:
Update to new (actually not so new, kaa.xine has done this for some time)
method of outputting frame to shmem.  Rather than polling, child gets
alerted via fd, which alerts parent via ipc.


Modified:
   trunk/popcorn/src/backends/xine/child.py
   trunk/popcorn/src/backends/xine/main.py
   trunk/popcorn/src/backends/xine/player.py

Modified: trunk/popcorn/src/backends/xine/child.py
==============================================================================
--- trunk/popcorn/src/backends/xine/child.py    (original)
+++ trunk/popcorn/src/backends/xine/child.py    Sun Feb 24 12:30:24 2008
@@ -29,6 +29,8 @@
 # python imports
 import sys
 import logging
+import os
+import struct
 
 # kaa imports
 import kaa
@@ -57,15 +59,14 @@
 
 class XinePlayerChild(Player):
 
-    def __init__(self, osd_shmkey, frame_shmkey):
+    def __init__(self, osd_shmkey):
         Player.__init__(self)
 
         self._xine = xine.Xine()
         self._vfilter = FilterChain(self._xine)
         self._stream = self._vo = self._ao = None
         self._osd_shmkey = int(osd_shmkey)
-        self._frame_shmkey = int(frame_shmkey)
-        self._osd_shmem = self._frame_shmem = None
+        self._osd_shmem = None
 
         self._window_size = 0, 0
         self._window_aspect = -1
@@ -234,11 +235,6 @@
 
 
     def _osd_configure(self, width, height, aspect):
-        frame_shmem_size = width * height * 4 + 16
-        #if self._frame_shmem and self._frame_shmem.size != frame_shmem_size:
-        if not self._frame_shmem:
-            self._frame_shmem = kaa.shm.create_memory(self._frame_shmkey, 
frame_shmem_size)
-            self._frame_shmem.attach()
         if not self._osd_shmem:
             self._osd_shmem = kaa.shm.create_memory(self._osd_shmkey, 2000 * 
2000 * 4 + 16)
             self._osd_shmem.attach()
@@ -247,7 +243,7 @@
         # FIXME: don't hardcode buffer dimensions
         assert(width*height*4 < 2000*2000*4)
         self.parent.osd_configure(width, height, aspect)
-        return self._osd_shmem.addr + 16, width * 4, self._frame_shmem.addr
+        return self._osd_shmem.addr + 16, width * 4
 
 
     def _handle_xine_event(self, event):
@@ -285,6 +281,12 @@
         self._vo.send_gui_data(xine.GUI_SEND_DRAWABLE_CHANGED, wid)
         self._vo_settings = None
 
+    def _frame_notify_cb(self, fd):
+        size = struct.calcsize("LL8s")
+        packet = os.read(fd, size)
+        shmid, offset, padding = struct.unpack('LL8s', packet)
+        self.parent.frame_notify(shmid, offset)
+
 
     def configure_video(self, wid, size, aspect, colorkey):
         """
@@ -315,9 +317,13 @@
         # if colorkey is not None:
         #     self._xine.set_config_value("video.device.xv_colorkey", colorkey)
 
+        frame_notify_pipe = os.pipe()
+        kaa.IOMonitor(self._frame_notify_cb, 
frame_notify_pipe[0]).register(frame_notify_pipe[0])
+
         control_return = []
         self._vo = self._xine.open_video_driver(
             "kaa", control_return = control_return,
+            notify_fd = frame_notify_pipe[1],
             osd_configure_cb = kaa.WeakCallback(self._osd_configure),
             frame_output_cb = kaa.WeakCallback(self._xine_frame_output_cb),
             dest_size_cb = kaa.WeakCallback(self._xine_dest_size_cb),

Modified: trunk/popcorn/src/backends/xine/main.py
==============================================================================
--- trunk/popcorn/src/backends/xine/main.py     (original)
+++ trunk/popcorn/src/backends/xine/main.py     Sun Feb 24 12:30:24 2008
@@ -12,7 +12,7 @@
 
 from child import XinePlayerChild as Xine
 
-player = Xine(sys.argv[1], sys.argv[2])
+player = Xine(sys.argv[1])
 kaa.main.run()
 
 # Remove shared memory.  We don't detach right away, because the vo
@@ -20,8 +20,6 @@
 # to that memory.
 if player._osd_shmem:
     kaa.shm.remove_memory(player._osd_shmem.shmid)
-if player._frame_shmem:
-    kaa.shm.remove_memory(player._frame_shmem.shmid)
 
 # Force garbage collection for testing.
 del player

Modified: trunk/popcorn/src/backends/xine/player.py
==============================================================================
--- trunk/popcorn/src/backends/xine/player.py   (original)
+++ trunk/popcorn/src/backends/xine/player.py   Sun Feb 24 12:30:24 2008
@@ -48,16 +48,16 @@
 # get logging object
 log = logging.getLogger('popcorn.xine')
 
-BUFFER_UNLOCKED = 0x10
-BUFFER_LOCKED = 0x20
+BUFFER_UNLOCKED = 0x00
+BUFFER_LOCKED = 0x01
 
 class Xine(MediaPlayer):
 
     def __init__(self, properties):
         super(Xine, self).__init__(properties)
-        self._check_new_frame_timer = kaa.WeakTimer(self._check_new_frame)
         self._is_in_menu = False
         self._cur_frame_output_mode = [True, False, None] # vo, shmem, size
+        self._locked_buffer_offsets = []
         self._child_spawn()
 
 
@@ -70,7 +70,7 @@
         script = os.path.join(os.path.dirname(__file__), 'main.py')
         self._xine = ChildProcess(self, script, gdb = log.getEffectiveLevel() 
== logging.DEBUG)
         self._xine.set_stop_command(kaa.WeakCallback(self._xine.die))
-        signal = self._xine.start(str(self._osd_shmkey), 
str(self._frame_shmkey))
+        signal = self._xine.start(str(self._osd_shmkey))
         signal.connect_weak(self._child_exited)
         self._xine_configured = False
 
@@ -99,7 +99,6 @@
         if self._frame_shmem:
             try:
                 self._frame_shmem.detach()
-                kaa.shm.remove_memory(self._frame_shmem.shmid)
             except kaa.shm.error:
                 pass
             self._frame_shmem = None
@@ -141,16 +140,10 @@
             if shmid:
                 self._osd_shmem = kaa.shm.memory(shmid)
                 self._osd_shmem.attach()
-        if not self._frame_shmem:
-            shmid = kaa.shm.getshmid(self._frame_shmkey)
-            if shmid:
-                self._frame_shmem = kaa.shm.memory(shmid)
-                self._frame_shmem.attach()
 
         # TODO: remember these values and emit them to new connections to
         # this signal after this point.
-        self.signals["osd_configure"].emit(\
-            width, height, self._osd_shmem.addr + 16, width, height)
+        self.signals["osd_configure"].emit(width, height, self._osd_shmem.addr 
+ 16, width, height)
 
 
     def _child_resize(self, size):
@@ -185,6 +178,25 @@
             self.state = STATE_IDLE
 
 
+    def _child_frame_notify(self, shmid, offset):
+        if not self._frame_shmem or shmid != self._frame_shmem.shmid:
+            if self._frame_shmem:
+                self._frame_shmem.detach()
+            self._frame_shmem = kaa.shm.memory(shmid)
+            self._frame_shmem.attach()
+
+        try:
+            lock, width, height, aspect = struct.unpack("bhhd", 
self._frame_shmem.read(16, offset))
+        except kaa.shm.error:
+            self._frame_shmem.detach()
+            self._frame_shmem = None
+            return
+
+        if width > 0 and height > 0 and aspect > 0:
+            self._locked_buffer_offsets.append(offset)
+            a = self._frame_shmem.addr + 32 + offset
+            self.signals["frame"].emit(width, height, aspect, a, "yv12")
+
     #
     # Window handling
     #
@@ -431,12 +443,6 @@
             return
 
         vo, notify, size = self._cur_frame_output_mode
-
-        if notify:
-            self._check_new_frame_timer.start(0.01)
-        else:
-            self._check_new_frame_timer.stop()
-
         log.debug('Setting frame output: vo=%s notify=%s size=%s' % (vo, 
notify, size))
         self._xine.set_frame_output_mode(vo, notify, size)
 
@@ -446,28 +452,9 @@
         Unlocks the frame buffer provided by the last 'frame' signal
         See generic.unlock_frame_buffer for details.
         """
+        offset = self._locked_buffer_offsets.pop(0)
         try:
-            self._frame_shmem.write(chr(BUFFER_UNLOCKED))
+            self._frame_shmem.write(chr(BUFFER_UNLOCKED), offset)
         except kaa.shm.error:
             self._frame_shmem.detach()
             self._frame_shmem = None
-
-
-    def _check_new_frame(self):
-        if not self._frame_shmem:
-            return
-
-        try:
-            lock, width, height, aspect = struct.unpack(\
-                "hhhd", self._frame_shmem.read(16))
-        except kaa.shm.error:
-            self._frame_shmem.detach()
-            self._frame_shmem = None
-            return
-
-        if lock & BUFFER_UNLOCKED:
-            return
-
-        if width > 0 and height > 0 and aspect > 0:
-            a = self._frame_shmem.addr + 16
-            self.signals["frame"].emit(width, height, aspect, a, "bgr32")

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to