[pitivi] previewers: Delay initial thumbnail & waveform processing to when the UI is idle



commit 43255f6ed01ed11663a60cae7a467c3f78697640
Author: Jean-François Fortin Tam <nekohayo gmail com>
Date:   Tue Jul 2 00:39:05 2013 -0400

    previewers: Delay initial thumbnail & waveform processing to when the UI is idle

 pitivi/timeline/elements.py   |    2 +-
 pitivi/timeline/previewers.py |   21 +++++++++++++++------
 2 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/pitivi/timeline/elements.py b/pitivi/timeline/elements.py
index 7591462..cf7fbba 100644
--- a/pitivi/timeline/elements.py
+++ b/pitivi/timeline/elements.py
@@ -53,7 +53,7 @@ def get_preview_for_object(bElement, timeline):
         # previewers[key] = RandomAccessAudioPreviewer(instance, uri)
         # TODO: return waveform previewer
         previewer = AudioPreviewer(bElement, timeline)
-        previewer.startLevelsDiscovery()
+        previewer.startLevelsDiscoveryWhenIdle()
         return previewer
     elif track_type == GES.TrackType.VIDEO:
         if bElement.get_parent().is_image():
diff --git a/pitivi/timeline/previewers.py b/pitivi/timeline/previewers.py
index cc2c716..7ce2107 100644
--- a/pitivi/timeline/previewers.py
+++ b/pitivi/timeline/previewers.py
@@ -102,7 +102,7 @@ class VideoPreviewer(Clutter.ScrollActor, Zoomable, Loggable):
         self.bElement.connect("notify::in-point", self._inpointChangedCb)
         self.bElement.connect("notify::start", self._startChangedCb)
         self._setupPipeline()
-        self._startThumbnailing()
+        self._startThumbnailingWhenIdle()
 
     # Internal API
 
@@ -169,13 +169,15 @@ class VideoPreviewer(Clutter.ScrollActor, Zoomable, Loggable):
             self.interval *= 1.1
             self.log('Thumbnailing slowed down (-10%%) to a %.1f ms interval for "%s"' % (self.interval, 
filename_from_uri(self.uri)))
 
-        GLib.timeout_add(self.interval, self._create_next_thumb)
-
         self.lastMoment = datetime.now()
         self.lastUsage = resource.getrusage(resource.RUSAGE_SELF)
-
+        GLib.timeout_add(self.interval, self._create_next_thumb_when_idle)
         return False
 
+    def _startThumbnailingWhenIdle(self):
+        self.debug('Waiting for UI to become idle for "%s"' % filename_from_uri(self.uri))
+        GLib.idle_add(self._startThumbnailing, priority=GLib.PRIORITY_LOW)
+
     def _startThumbnailing(self):
         self.debug('Now generating thumbnails for "%s"' % filename_from_uri(self.uri))
         self.queue = []
@@ -199,6 +201,10 @@ class VideoPreviewer(Clutter.ScrollActor, Zoomable, Loggable):
         random_time = randrange(30, 80)
         GLib.timeout_add_seconds(random_time, self._autosave)
 
+    def _create_next_thumb_when_idle(self):
+        self.log('Requesting next thumb when idle for "%s"' % filename_from_uri(self.uri))
+        GLib.idle_add(self._create_next_thumb, priority=GLib.PRIORITY_LOW)
+
     def _create_next_thumb(self):
         if not self.queue:
             # nothing left to do
@@ -579,9 +585,8 @@ class PipelineCpuAdapter(Loggable):
                            Gst.SeekType.NONE,
                            -1)
         self.pipeline.set_state(Gst.State.PLAYING)
-
         self.ready = False
-
+        # Keep the glib timer running:
         return True
 
     def _messageCb(self, bus, message):
@@ -633,6 +638,10 @@ class AudioPreviewer(Clutter.Actor, Zoomable, Loggable):
 
         self._callback_id = 0
 
+    def startLevelsDiscoveryWhenIdle(self):
+        self.debug('Waiting for UI to become idle for "%s"' % filename_from_uri(self._uri))
+        GLib.idle_add(self._startLevelsDiscovery, priority=GLib.PRIORITY_LOW)
+
     def _startLevelsDiscovery(self):
         self.log('Preparing waveforms for "%s"' % filename_from_uri(self._uri))
         filename = hash_file(Gst.uri_get_location(self._uri)) + ".wave"


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