[pitivi] pipeline: Make sure each pipeline has a cluttersink



commit 0cb568fb5dca8fd1cc58cabe3ef902a00a663338
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Thu Jan 16 16:17:51 2014 +0100

    pipeline: Make sure each pipeline has a cluttersink
    
    Also make it easier to connect a pipeline to a ViewerWidget.

 pitivi/utils/pipeline.py |   28 +++++++++++++++++++++-------
 pitivi/viewer.py         |   23 +++++------------------
 2 files changed, 26 insertions(+), 25 deletions(-)
---
diff --git a/pitivi/utils/pipeline.py b/pitivi/utils/pipeline.py
index 99f7728..2c86cbd 100644
--- a/pitivi/utils/pipeline.py
+++ b/pitivi/utils/pipeline.py
@@ -36,7 +36,6 @@ from gi.repository import GES
 MAX_RECOVERIES = 5
 
 
-# FIXME : define/document a proper hierarchy
 class PipelineError(Exception):
     pass
 
@@ -159,6 +158,7 @@ class SimplePipeline(Signallable, Loggable):
     def __init__(self, pipeline):
         Loggable.__init__(self)
         Signallable.__init__(self)
+
         self._pipeline = pipeline
         self._bus = self._pipeline.get_bus()
         self._bus.add_signal_watch()
@@ -174,6 +174,20 @@ class SimplePipeline(Signallable, Loggable):
         self._next_seek = None
         self._timeout_async_id = 0
 
+        # Create a cluttersink element used for display. Subclasses must connect
+        # it to self._pipeline themselves
+        self._clutter_sink = Gst.ElementFactory.make("cluttersink", None)
+        if isinstance(pipeline, GES.Pipeline):
+            self._pipeline.preview_set_video_sink(self._clutter_sink)
+        else:
+            self._pipeline.set_property("video_sink", self._clutter_sink)
+
+    def connectWithViewer(self, viewer):
+        """
+        Connect the specified ViewerWidget so this pipeline can be displayed.
+        """
+        self._clutter_sink.props.texture = viewer.texture
+
     def release(self):
         """
         Release the L{Pipeline} and all used L{ObjectFactory} and
@@ -501,13 +515,16 @@ class AssetPipeline(SimplePipeline):
     Pipeline for playing a single clip.
     """
 
-    def __init__(self, clip):
-        bPipeline = Gst.ElementFactory.make("playbin", None)
-        bPipeline.set_property("uri", clip.props.uri)
+    def __init__(self, clip, name=None):
+        bPipeline = Gst.ElementFactory.make("playbin", name)
         SimplePipeline.__init__(self, bPipeline)
 
+        self.setClipUri(clip.props.uri)
         self.clip = clip
 
+    def setClipUri(self, uri):
+        self._pipeline.set_property("uri", uri)
+
 
 class Pipeline(GES.Pipeline, SimplePipeline):
     """
@@ -537,9 +554,6 @@ class Pipeline(GES.Pipeline, SimplePipeline):
         GES.Pipeline.__init__(self)
         SimplePipeline.__init__(self, self)
 
-        self.clutter_sink = Gst.ElementFactory.make("cluttersink", None)
-        self.preview_set_video_sink(self.clutter_sink)
-
         self._seeker = Seeker()
         self._seeker.connect("seek", self._seekCb)
         self._seeker.connect("seek-relative", self._seekRelativeCb)
diff --git a/pitivi/viewer.py b/pitivi/viewer.py
index 81a55e0..b350a18 100644
--- a/pitivi/viewer.py
+++ b/pitivi/viewer.py
@@ -93,7 +93,6 @@ class ViewerContainer(Gtk.VBox, Loggable):
         self.log("New ViewerContainer")
 
         self.pipeline = None
-        self.__sink = None
         self.docked = True
         self.seeker = Seeker()
 
@@ -117,16 +116,6 @@ class ViewerContainer(Gtk.VBox, Loggable):
         else:
             return self.external
 
-    @property
-    def sink(self):
-        return self.__sink
-
-    @sink.setter
-    def sink(self, sink):
-        self.__sink = sink
-        self.internal.sink = sink
-        self.external.sink = sink
-
     def setPipeline(self, pipeline, position=None):
         """
         Set the Viewer to the given Pipeline.
@@ -148,7 +137,6 @@ class ViewerContainer(Gtk.VBox, Loggable):
         self.pipeline.connect("position", self._positionCb)
         self.pipeline.connect("duration-changed", self._durationChangedCb)
 
-        self.sink = pipeline.clutter_sink
         self._switch_output_window()
         self._setUiActive()
 
@@ -386,7 +374,7 @@ class ViewerContainer(Gtk.VBox, Loggable):
         self.fullscreen_button.connect("toggled", self._toggleFullscreen)
 
         # if we are playing, switch output immediately
-        if self.sink:
+        if self.pipeline:
             self._switch_output_window()
         self.hide()
         self.external_window.move(self.settings.viewerX, self.settings.viewerY)
@@ -407,7 +395,7 @@ class ViewerContainer(Gtk.VBox, Loggable):
         self.pack_end(self.buttons_container, False, False, 0)
         self.show()
         # if we are playing, switch output immediately
-        if self.sink:
+        if self.pipeline:
             self._switch_output_window()
         self.external_window.hide()
 
@@ -488,18 +476,17 @@ class ViewerContainer(Gtk.VBox, Loggable):
             self.playpause_button.setPlay()
             self.system.uninhibitScreensaver(self.INHIBIT_REASON)
         else:
-            self.sink = None
             self.system.uninhibitScreensaver(self.INHIBIT_REASON)
         self.internal._currentStateCb(self.pipeline, state)
 
     def _switch_output_window(self):
         # Don't do anything if we don't have a pipeline
-        if self.sink is None:
+        if self.pipeline is None:
             return
 
         if self.target.get_realized():
-            self.debug("Connecting the sink pipeline to the viewer's texture")
-            self.sink.props.texture = self.target.texture
+            self.debug("Connecting the pipeline to the viewer's texture")
+            self.pipeline.connectWithViewer(self.target)
         else:
             # Show the widget and wait for the realized callback
             self.log("Target is not realized, showing the widget")


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