[pitivi] pipeline: Keep track whether the pipeline has a duration



commit 6c3bde8d48dd637407481585b8198d9dea219005
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue Jan 21 08:54:18 2014 +0100

    pipeline: Keep track whether the pipeline has a duration
    
    This fixes a stacktrace showing up when resizing clips backed by an
    image. An image asset does not have a duration.

 pitivi/utils/pipeline.py |   27 ++++++++++++++++++++++-----
 1 files changed, 22 insertions(+), 5 deletions(-)
---
diff --git a/pitivi/utils/pipeline.py b/pitivi/utils/pipeline.py
index 27d752d..ee80078 100644
--- a/pitivi/utils/pipeline.py
+++ b/pitivi/utils/pipeline.py
@@ -24,14 +24,17 @@
 """
 High-level pipelines
 """
-from pitivi.utils.loggable import Loggable
-from pitivi.utils.signal import Signallable
-from pitivi.utils.misc import format_ns
 
+from gi.repository import GES
 from gi.repository import GLib
 from gi.repository import GObject
 from gi.repository import Gst
-from gi.repository import GES
+from gi.repository import GstPbutils
+
+from pitivi.utils.loggable import Loggable
+from pitivi.utils.misc import format_ns
+from pitivi.utils.signal import Signallable
+
 
 MAX_RECOVERIES = 5
 
@@ -166,6 +169,7 @@ class SimplePipeline(Signallable, Loggable):
         self._listening = False  # for the position handler
         self._listeningInterval = 300  # default 300ms
         self._listeningSigId = 0
+        self._has_duration = True
         self._duration = Gst.CLOCK_TIME_NONE
         self.lastPosition = long(0 * Gst.SECOND)
         self.pendingRecovery = False
@@ -397,7 +401,10 @@ class SimplePipeline(Signallable, Loggable):
 
         # clamp between [0, duration]
         if format == Gst.Format.TIME:
-            position = max(0, min(position, self.getDuration()) - 1)
+            if self._has_duration:
+                position = max(0, min(position, self.getDuration()) - 1)
+            else:
+                position = max(0, position)
 
         res = self._pipeline.seek(1.0, format, Gst.SeekFlags.FLUSH,
                                   Gst.SeekType.SET, position,
@@ -526,6 +533,16 @@ class AssetPipeline(SimplePipeline):
     def setClipUri(self, uri):
         self._pipeline.set_property("uri", uri)
 
+        discoverer = GstPbutils.Discoverer.new(Gst.SECOND)
+        info = discoverer.discover_uri(uri)
+        has_duration = False
+        if info:
+            videos = info.get_video_streams()
+            if videos:
+                video = videos[0]
+                has_duration = not video.is_image()
+        self._has_duration = has_duration
+
 
 class Pipeline(GES.Pipeline, SimplePipeline):
     """


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