[pitivi] pipeline: Simplify AssetPipeline constructor



commit 0f7fee527a645f20987350d2776197d818b0445c
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Sun Jan 20 01:57:38 2019 +0100

    pipeline: Simplify AssetPipeline constructor
    
    It does not handle clips anymore, because it's easy enough to pass
    `clip.props.uri` instead.

 pitivi/mediafilespreviewer.py |  6 +++---
 pitivi/utils/pipeline.py      | 25 ++++++++++++++++++-------
 pitivi/viewer/viewer.py       |  7 ++++---
 3 files changed, 25 insertions(+), 13 deletions(-)
---
diff --git a/pitivi/mediafilespreviewer.py b/pitivi/mediafilespreviewer.py
index a2f266df..090f6000 100644
--- a/pitivi/mediafilespreviewer.py
+++ b/pitivi/mediafilespreviewer.py
@@ -84,7 +84,7 @@ class PreviewWidget(Gtk.Grid, Loggable):
         self.error_message = None
 
         # playbin for play pics
-        self.player = AssetPipeline(clip=None, name="preview-player")
+        self.player = AssetPipeline(name="preview-player")
         self.player.connect('eos', self._pipelineEosCb)
         self.player.connect('error', self._pipelineErrorCb)
         self.player._bus.connect('message::tag', self._tag_found_cb)
@@ -253,7 +253,7 @@ class PreviewWidget(Gtk.Grid, Loggable):
             else:
                 self.current_preview_type = 'video'
                 self.preview_image.hide()
-                self.player.setClipUri(self.current_selected_uri)
+                self.player.uri = self.current_selected_uri
                 self.player.setState(Gst.State.PAUSED)
                 self.pos_adj.props.upper = duration
                 video_width = video.get_square_width()
@@ -289,7 +289,7 @@ class PreviewWidget(Gtk.Grid, Loggable):
                 beautify_stream(audio),
                 _("<b>Duration</b>: %s") % pretty_duration])
             self.player.setState(Gst.State.NULL)
-            self.player.setClipUri(self.current_selected_uri)
+            self.player.uri = self.current_selected_uri
             self.player.setState(Gst.State.PAUSED)
             self.play_button.show()
             self.seeker.show()
diff --git a/pitivi/utils/pipeline.py b/pitivi/utils/pipeline.py
index 44757de0..3f9f6eaa 100644
--- a/pitivi/utils/pipeline.py
+++ b/pitivi/utils/pipeline.py
@@ -506,24 +506,35 @@ class SimplePipeline(GObject.Object, Loggable):
 
 
 class AssetPipeline(SimplePipeline):
-    """Pipeline for playing a single clip."""
+    """Pipeline for playing a single asset.
 
-    def __init__(self, clip=None, name=None):
+    Attributes:
+        uri (str): The low-level pipeline.
+    """
+
+    def __init__(self, uri=None, name=None):
         ges_pipeline = Gst.ElementFactory.make("playbin", name)
         SimplePipeline.__init__(self, ges_pipeline)
 
-        self.clip = clip
-        if self.clip:
-            self.setClipUri(self.clip.props.uri)
+        self.__uri = None
+        if uri:
+            self.uri = uri
 
     def create_sink(self):
         video_sink, sink_widget = SimplePipeline.create_sink(self)
         self._pipeline.set_property("video_sink", video_sink)
-
         return video_sink, sink_widget
 
-    def setClipUri(self, uri):
+    @property
+    def uri(self):
+        # We could maybe get it using `self._pipeline.get_property`, but
+        # after setting the state to Gst.State.PAUSED, it becomes None.
+        return self.__uri
+
+    @uri.setter
+    def uri(self, uri):
         self._pipeline.set_property("uri", uri)
+        self.__uri = uri
 
 
 class Pipeline(GES.Pipeline, SimplePipeline):
diff --git a/pitivi/viewer/viewer.py b/pitivi/viewer/viewer.py
index 73b34909..c6d6a67e 100644
--- a/pitivi/viewer/viewer.py
+++ b/pitivi/viewer/viewer.py
@@ -512,14 +512,15 @@ class ViewerContainer(Gtk.Box, Loggable):
         if self.project.pipeline.getState() == Gst.State.PLAYING:
             self.project.pipeline.setState(Gst.State.PAUSED)
 
-        if self.trim_pipeline and clip is not self.trim_pipeline.clip:
+        uri = clip.props.uri
+        if self.trim_pipeline and uri != self.trim_pipeline.uri:
             # Seems to be the trim preview pipeline for a different clip.
             self.trim_pipeline.release()
             self.trim_pipeline = None
 
         if not self.trim_pipeline:
-            self.debug("Creating temporary pipeline for clip %s", clip.props.uri)
-            self.trim_pipeline = AssetPipeline(clip)
+            self.debug("Creating temporary pipeline for clip %s", uri)
+            self.trim_pipeline = AssetPipeline(uri)
             unused_video_sink, sink_widget = self.trim_pipeline.create_sink()
             # Add the widget to a hidden container and make it appear later
             # when it's ready. If we show it before the initial seek completion,


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