[pitivi] Make setting the XID on the videosink threadsafe.



commit 77f1fec253a98c4abe040e6ecfde056baaac4bce
Author: Alessandro Decina <alessandro d gmail com>
Date:   Mon Sep 7 16:23:34 2009 +0200

    Make setting the XID on the videosink threadsafe.
    
    Fix some DRY violations in the process.

 pitivi/action.py        |   14 --------------
 pitivi/application.py   |    1 -
 pitivi/plumber.py       |   18 ++----------------
 pitivi/ui/mainwindow.py |    2 --
 pitivi/ui/viewer.py     |   36 +++++++-----------------------------
 5 files changed, 9 insertions(+), 62 deletions(-)
---
diff --git a/pitivi/action.py b/pitivi/action.py
index cc75c64..5f488d5 100644
--- a/pitivi/action.py
+++ b/pitivi/action.py
@@ -705,7 +705,6 @@ class ViewAction(Action):
         self.videosink = None
         self.audiosink = None
         self.sync = True
-        self.xid = 0
 
     def getDynamicLinks(self, producer, stream):
         self.debug("producer:%r, stream:%r, sync:%r",
@@ -717,8 +716,6 @@ class ViewAction(Action):
             consumer = DefaultVideoSink()
             self.videosink = consumer
             self.videosink.setSync(self.sync)
-            if self.xid != 0:
-                self.videosink.set_window_xid(self.xid)
 
             res.append((producer, consumer, stream, None))
         # only link audio streams if we're synchronized
@@ -729,17 +726,6 @@ class ViewAction(Action):
             res.append((producer, consumer, stream, None))
         return res
 
-    def set_window_xid(self, xid):
-        """
-        Set the XID where the video consumer should display.
-        """
-        self.debug("xid:%r", xid)
-        # FIXME : What if we have several video sinks ???
-        self.xid = xid
-        if self.videosink:
-            self.videosink.set_window_xid(self.xid)
-
-
     def setSync(self, sync=True):
         """
         Whether the sinks should sync against the running clock and
diff --git a/pitivi/application.py b/pitivi/application.py
index eb9166d..98c0bea 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -26,7 +26,6 @@ Main application
 import gobject
 gobject.threads_init()
 import gtk
-gtk.gdk.threads_init()
 from optparse import OptionParser
 import os
 import sys
diff --git a/pitivi/plumber.py b/pitivi/plumber.py
index f6f51b6..aa37a51 100644
--- a/pitivi/plumber.py
+++ b/pitivi/plumber.py
@@ -41,7 +41,6 @@ class DefaultVideoSink(SinkFactory):
     def __init__(self, *args, **kwargs):
         SinkFactory.__init__(self, *args, **kwargs)
         self.max_bins = 1
-        self._xid = 0
         self._cachedsink = None
         self._realsink = None
         self.sync = True
@@ -69,18 +68,16 @@ class DefaultVideoSink(SinkFactory):
 
         if not autovideosink.implements_interface(interfaces.XOverlay):
             autovideosink.info("doesn't implement XOverlay interface")
+
             self._realsink = autovideosink.get_by_interface(interfaces.XOverlay)
             if not self._realsink:
                 self.info("%s", list(autovideosink.elements()))
                 autovideosink.warning("couldn't even find an XOverlay within!!!")
             else:
                 self._realsink.info("implements XOverlay interface")
-                autovideosink.set_xwindow_id = self._realsink.set_xwindow_id
-                autovideosink.expose = self._realsink.expose
         else:
             self._realsink = autovideosink
-        # FIXME : YUCK, I'm guessing most of these issues (qos/max-lateness)
-        # have been solved since
+
         if self._realsink:
             props = list(self._realsink.props)
             if "force-aspect-ratio"in [prop.name for prop in props]:
@@ -89,9 +86,6 @@ class DefaultVideoSink(SinkFactory):
             self._realsink.props.sync = self.sync
             self._realsink.props.qos = self.sync
 
-        if self._xid != 0:
-            self._realsink.set_xwindow_id(self._xid)
-
         self._cachedsink = autovideosink
         return bin
 
@@ -99,14 +93,6 @@ class DefaultVideoSink(SinkFactory):
         if bin == self._cachedsink:
             self._realsink = None
             self._cachedsink = None
-            self._xid = 0
-
-    def set_window_xid(self, xid):
-        if self._xid != 0:
-            return
-        self._xid = xid
-        if self._cachedsink:
-            self._cachedsink.set_xwindow_id(self._xid)
 
     def setSync(self, sync=True):
         self.debug("sync:%r", sync)
diff --git a/pitivi/ui/mainwindow.py b/pitivi/ui/mainwindow.py
index 333465f..94fa57e 100644
--- a/pitivi/ui/mainwindow.py
+++ b/pitivi/ui/mainwindow.py
@@ -856,9 +856,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
         chooser.show()
 
         dialog.set_size_request(640, 480)
-        gtk.gdk.threads_enter()
         response = dialog.run()
-        gtk.gdk.threads_leave()
 
         if response == gtk.RESPONSE_OK:
             self.log("User chose a URI to save project to")
diff --git a/pitivi/ui/viewer.py b/pitivi/ui/viewer.py
index 95dc423..3043eeb 100644
--- a/pitivi/ui/viewer.py
+++ b/pitivi/ui/viewer.py
@@ -23,7 +23,6 @@
 import gobject
 import gtk
 from gtk import gdk
-gdk.threads_init()
 import gst
 
 from pitivi.action import ViewAction
@@ -172,7 +171,6 @@ class PitiviViewer(gtk.VBox, Loggable):
         self.action = action
         # FIXME: fix this properly?
         self.drawingarea.action = action
-        self.drawingarea.have_set_xid = False
         dar = float(4/3)
         try:
             producer = action.producers[0]
@@ -213,7 +211,6 @@ class PitiviViewer(gtk.VBox, Loggable):
                                       obey_child=False)
         self.pack_start(self.aframe, expand=True)
         self.drawingarea = ViewerWidget(self.action)
-        self.drawingarea.connect_after("expose-event", self._drawingAreaExposeCb)
         self.aframe.add(self.drawingarea)
 
         # Slider
@@ -307,20 +304,6 @@ class PitiviViewer(gtk.VBox, Loggable):
         except:
             self.warning("could not set ratio !")
 
-    def _drawingAreaExposeCb(self, drawingarea, event):
-        drawingarea.disconnect_by_func(self._drawingAreaExposeCb)
-        for state in range(gtk.STATE_INSENSITIVE + 1):
-            drawingarea.modify_bg(state, drawingarea.style.black)
-        self.debug("yay, we are exposed !")
-        if self.pipeline:
-            try:
-                self.pipeline.paused()
-            except:
-                self.currentState = gst.STATE_NULL
-            else:
-                self.currentState = gst.STATE_PAUSED
-        return False
-
     ## gtk.HScale callbacks for self.slider
 
     def _sliderButtonPressCb(self, slider, unused_event):
@@ -455,7 +438,8 @@ class PitiviViewer(gtk.VBox, Loggable):
         name = message.structure.get_name()
         self.log('message:%s / %s', message, name)
         if name == 'prepare-xwindow-id':
-            self.drawingarea.set_xwindow_id()
+            sink = message.src
+            sink.set_xwindow_id(self.drawingarea.window_xid)
 
 
 class ViewerWidget(gtk.DrawingArea, Loggable):
@@ -469,20 +453,14 @@ class ViewerWidget(gtk.DrawingArea, Loggable):
         gtk.DrawingArea.__init__(self)
         Loggable.__init__(self)
         self.action = action # FIXME : Check if it's a view action
-        self.have_set_xid = False
         self.unset_flags(gtk.SENSITIVE)
-
-    def set_xwindow_id(self):
-        """ set the widget's XID on the configured videosink. """
-        self.log("...")
-        if self.have_set_xid:
-            return
-        gtk.gdk.threads_enter()
-        self.action.set_window_xid(self.window.xid)
-        gtk.gdk.threads_leave()
         self.unset_flags(gtk.DOUBLE_BUFFERED)
-        self.have_set_xid = True
+        for state in range(gtk.STATE_INSENSITIVE + 1):
+            self.modify_bg(state, self.style.black)
 
+    def do_realize(self):
+        gtk.DrawingArea.do_realize(self)
+        self.window_xid = self.window.xid
 
 class PlayPauseButton(gtk.Button, Loggable):
     """ Double state gtk.Button which displays play/pause """



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]