[pitivi] previewers: Use the previewers_max_cpu setting for all previewers



commit ee6a0785aa402a35d202185af57d8d06257b84da
Author: Thibault Saunier <tsaunier gnome org>
Date:   Fri Aug 18 11:07:46 2017 -0300

    previewers: Use the previewers_max_cpu setting for all previewers
    
    And do not rely on Zoomable.app to get the info, that attribute look
    quite ugly and we should try to avoid using it all around. Instead pass
    it in the previewer constructor
    
    And stop our differentiation between thumbnails and waveform generation,
    it doesn't seem needed and having two options for that look too much.

 pitivi/timeline/elements.py   |    4 ++--
 pitivi/timeline/previewers.py |   19 ++++++++-----------
 2 files changed, 10 insertions(+), 13 deletions(-)
---
diff --git a/pitivi/timeline/elements.py b/pitivi/timeline/elements.py
index be32471..be108e1 100644
--- a/pitivi/timeline/elements.py
+++ b/pitivi/timeline/elements.py
@@ -779,7 +779,7 @@ class VideoUriSource(VideoSource):
         self.get_style_context().add_class("VideoUriSource")
 
     def _getPreviewer(self):
-        previewer = VideoPreviewer(self._ges_elem)
+        previewer = VideoPreviewer(self._ges_elem, self.timeline.app.settings.previewers_max_cpu)
         previewer.get_style_context().add_class("VideoUriSource")
 
         return previewer
@@ -806,7 +806,7 @@ class AudioUriSource(TimelineElement):
         self.get_style_context().add_class("AudioUriSource")
 
     def _getPreviewer(self):
-        previewer = AudioPreviewer(self._ges_elem)
+        previewer = AudioPreviewer(self._ges_elem, self.timeline.app.settings.previewers_max_cpu)
         previewer.get_style_context().add_class("AudioUriSource")
 
         return previewer
diff --git a/pitivi/timeline/previewers.py b/pitivi/timeline/previewers.py
index edf2574..a24e8aa 100644
--- a/pitivi/timeline/previewers.py
+++ b/pitivi/timeline/previewers.py
@@ -54,12 +54,8 @@ except ImportError:
     import renderer
 
 
-WAVEFORMS_CPU_USAGE = 30
 SAMPLE_DURATION = Gst.SECOND / 100
 
-# A little lower as it's more fluctuating
-THUMBNAILS_CPU_USAGE = 20
-
 THUMB_MARGIN_PX = 3
 # For the waveforms, ensures we always have a little extra surface when
 # scrolling while playing.
@@ -371,10 +367,11 @@ class Previewer(Gtk.Layout):
     # We only need one PreviewGeneratorManager to manage all previewers.
     manager = PreviewGeneratorManager()
 
-    def __init__(self, track_type):
+    def __init__(self, track_type, max_cpu_usage):
         Gtk.Layout.__init__(self)
 
         self.track_type = track_type
+        self._max_cpu_usage = max_cpu_usage
 
     def startGeneration(self):
         """Starts preview generation."""
@@ -405,8 +402,8 @@ class VideoPreviewer(Previewer, Zoomable, Loggable):
     # We could define them in Previewer, but for some reason they are ignored.
     __gsignals__ = PREVIEW_GENERATOR_SIGNALS
 
-    def __init__(self, ges_elem):
-        Previewer.__init__(self, GES.TrackType.VIDEO)
+    def __init__(self, ges_elem, max_cpu_usage):
+        Previewer.__init__(self, GES.TrackType.VIDEO, max_cpu_usage)
         Zoomable.__init__(self)
         Loggable.__init__(self)
 
@@ -489,7 +486,7 @@ class VideoPreviewer(Previewer, Zoomable, Loggable):
         happen when the gobject loop is idle to avoid blocking the UI.
         """
         usage_percent = self.cpu_usage_tracker.usage()
-        if usage_percent < THUMBNAILS_CPU_USAGE:
+        if usage_percent < self._max_cpu_usage:
             self.interval *= 0.9
             self.log(
                 'Thumbnailing sped up (+10%%) to a %.1f ms interval for "%s"',
@@ -880,8 +877,8 @@ class AudioPreviewer(Previewer, Zoomable, Loggable):
 
     __gsignals__ = PREVIEW_GENERATOR_SIGNALS
 
-    def __init__(self, ges_elem):
-        Previewer.__init__(self, GES.TrackType.AUDIO)
+    def __init__(self, ges_elem, max_cpu_usage):
+        Previewer.__init__(self, GES.TrackType.AUDIO, max_cpu_usage)
         Zoomable.__init__(self)
         Loggable.__init__(self)
 
@@ -941,7 +938,7 @@ class AudioPreviewer(Previewer, Zoomable, Loggable):
         # GstCpuThrottlingClock below.
         Gst.ElementFactory.make("uritranscodebin", None)
         clock = GObject.new(GObject.type_from_name("GstCpuThrottlingClock"))
-        clock.props.cpu_usage = self.app.settings.previewers_max_cpu
+        clock.props.cpu_usage = self._max_cpu_usage
         self.pipeline.use_clock(clock)
         faked = self.pipeline.get_by_name("faked")
         faked.props.sync = True


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