Exemple #1
0
    def _create_next_thumb(self):
        if not self.wishlist or not self.queue:
            # nothing left to do
            self.debug("Thumbnails generation complete")
            self.stopGeneration()
            self.thumb_cache.commit()
            return
        else:
            self.debug("Missing %d thumbs", len(self.wishlist))

        wish = self._get_wish()
        if wish:
            time = wish
            self.queue.remove(wish)
        else:
            time = self.queue.pop(0)
        self.log('Creating thumb for "%s"' % filename_from_uri(self.uri))
        # append the time to the end of the queue so that if this seek fails
        # another try will be started later
        self.queue.append(time)
        self.pipeline.seek(1.0,
                           Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE,
                           Gst.SeekType.SET, time,
                           Gst.SeekType.NONE, -1)

        # Remove the GSource
        return False
Exemple #2
0
    def _startThumbnailing(self):
        if not self.pipeline:
            # Can happen if stopGeneration is called because the clip has been
            # removed from the timeline after the PreviewGeneratorManager
            # started this job.
            return

        # self.props.width_request = self.nsToPixel(self.ges_elem.get_asset().get_filesource_asset().props.duration)
        # self.props.width = self.nsToPixel(self.ges_elem.get_asset().get_filesource_asset().props.duration)

        self.debug('Now generating thumbnails for: %s',
                   filename_from_uri(self.uri))
        query_success, duration = self.pipeline.query_duration(Gst.Format.TIME)
        if not query_success or duration == -1:
            self.debug("Could not determine duration of: %s", self.uri)
            duration = self.ges_elem.props.duration

        self.queue = list(range(0, duration, self.thumb_period))

        self._checkCPU()

        if self.ges_elem.props.in_point != 0:
            adj = self.get_hadjustment()
            adj.props.page_size = 1.0
            adj.props.value = Zoomable.nsToPixel(self.ges_elem.props.in_point)

        # self._addVisibleThumbnails()
        # Save periodically to avoid the common situation where the user exits
        # the app before a long clip has been fully thumbnailed.
        # Spread timeouts between 30-80 secs to avoid concurrent disk writes.
        random_time = random.randrange(30, 80)
        GLib.timeout_add_seconds(random_time, self._autosave)

        # Remove the GSource
        return False
Exemple #3
0
    def _create_next_thumb(self):
        if not self.wishlist or not self.queue:
            # nothing left to do
            self.debug("Thumbnails generation complete")
            self.stopGeneration()
            self.thumb_cache.commit()
            return
        else:
            self.debug("Missing %d thumbs", len(self.wishlist))

        wish = self._get_wish()
        if wish:
            time = wish
            self.queue.remove(wish)
        else:
            time = self.queue.pop(0)
        self.log('Creating thumb for "%s"' % filename_from_uri(self.uri))
        # append the time to the end of the queue so that if this seek fails
        # another try will be started later
        self.queue.append(time)
        self.pipeline.seek(1.0,
                           Gst.Format.TIME, Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE,
                           Gst.SeekType.SET, time,
                           Gst.SeekType.NONE, -1)

        # Remove the GSource
        return False
Exemple #4
0
    def _startThumbnailing(self):
        if not self.pipeline:
            # Can happen if stopGeneration is called because the clip has been
            # removed from the timeline after the PreviewGeneratorManager
            # started this job.
            return
        self.debug('Now generating thumbnails for: %s', filename_from_uri(self.uri))
        query_success, duration = self.pipeline.query_duration(Gst.Format.TIME)
        if not query_success or duration == -1:
            self.debug("Could not determine duration of: %s", self.uri)
            duration = self.duration
        else:
            self.duration = duration

        self.queue = range(0, duration, self.thumb_period)

        self._checkCPU()

        self._addVisibleThumbnails()
        # Save periodically to avoid the common situation where the user exits
        # the app before a long clip has been fully thumbnailed.
        # Spread timeouts between 30-80 secs to avoid concurrent disk writes.
        random_time = randrange(30, 80)
        GLib.timeout_add_seconds(random_time, self._autosave)

        # Remove the GSource
        return False
Exemple #5
0
    def _startThumbnailing(self):
        self.debug('Now generating thumbnails for "%s"' % filename_from_uri(self.uri))
        self.queue = []
        query_success, duration = self.pipeline.query_duration(Gst.Format.TIME)
        if not query_success or duration == -1:
            self.debug("Could not determine duration of %s" % self.uri)
            duration = self.duration
        else:
            self.duration = duration

        current_time = 0
        while current_time < duration:
            self.queue.append(current_time)
            current_time += self.thumb_period

        self._checkCPU()

        self._addVisibleThumbnails()
        # Save periodically to avoid the common situation where the user exits
        # the app before a long clip has been fully thumbnailed.
        # Spread timeouts between 30-80 secs to avoid concurrent disk writes.
        random_time = randrange(30, 80)
        GLib.timeout_add_seconds(random_time, self._autosave)

        # Remove the GSource
        return False
Exemple #6
0
    def _startThumbnailing(self):
        if not self.pipeline:
            # Can happen if stopGeneration is called because the clip has been
            # removed from the timeline after the PreviewGeneratorManager
            # started this job.
            return
        self.debug('Now generating thumbnails for: %s', filename_from_uri(self.uri))
        query_success, duration = self.pipeline.query_duration(Gst.Format.TIME)
        if not query_success or duration == -1:
            self.debug("Could not determine duration of: %s", self.uri)
            duration = self.duration
        else:
            self.duration = duration

        self.queue = list(range(0, duration, self.thumb_period))

        self._checkCPU()

        self._addVisibleThumbnails()
        # Save periodically to avoid the common situation where the user exits
        # the app before a long clip has been fully thumbnailed.
        # Spread timeouts between 30-80 secs to avoid concurrent disk writes.
        random_time = randrange(30, 80)
        GLib.timeout_add_seconds(random_time, self._autosave)

        # Remove the GSource
        return False
Exemple #7
0
    def _startThumbnailing(self):
        if not self.pipeline:
            # Can happen if stopGeneration is called because the clip has been
            # removed from the timeline after the PreviewGeneratorManager
            # started this job.
            return

        # self.props.width_request = self.nsToPixel(self.ges_elem.get_asset().get_filesource_asset().props.duration)
        # self.props.width = self.nsToPixel(self.ges_elem.get_asset().get_filesource_asset().props.duration)

        self.debug(
            'Now generating thumbnails for: %s', filename_from_uri(self.uri))
        query_success, duration = self.pipeline.query_duration(Gst.Format.TIME)
        if not query_success or duration == -1:
            self.debug("Could not determine duration of: %s", self.uri)
            duration = self.ges_elem.props.duration

        self.queue = list(range(0, duration, self.thumb_period))

        self._checkCPU()

        if self.ges_elem.props.in_point != 0:
            adj = self.get_hadjustment()
            adj.props.page_size = 1.0
            adj.props.value = Zoomable.nsToPixel(self.ges_elem.props.in_point)

        # self._addVisibleThumbnails()
        # Save periodically to avoid the common situation where the user exits
        # the app before a long clip has been fully thumbnailed.
        # Spread timeouts between 30-80 secs to avoid concurrent disk writes.
        random_time = random.randrange(30, 80)
        GLib.timeout_add_seconds(random_time, self._autosave)

        # Remove the GSource
        return False
Exemple #8
0
 def startLevelsDiscoveryWhenIdle(self):
     """
     Start processing waveform (whenever possible)
     """
     self.debug('Waiting for UI to become idle for: %s',
                filename_from_uri(self._uri))
     GLib.idle_add(self._startLevelsDiscovery, priority=GLib.PRIORITY_LOW)
Exemple #9
0
 def __init__(self, uri):
     Loggable.__init__(self)
     self._filehash = hash_file(Gst.uri_get_location(uri))
     self._filename = filename_from_uri(uri)
     thumbs_cache_dir = get_dir(os.path.join(xdg_cache_home(), "thumbs"))
     dbfile = os.path.join(thumbs_cache_dir, self._filehash)
     self._db = sqlite3.connect(dbfile)
     self._cur = self._db.cursor()  # Use this for normal db operations
     self._cur.execute("CREATE TABLE IF NOT EXISTS Thumbs\
                       (Time INTEGER NOT NULL PRIMARY KEY,\
                       Jpeg BLOB NOT NULL)")
Exemple #10
0
 def _checkCPU(self):
     """
     Check the CPU usage and adjust the time interval (+10 or -10%) at
     which the next thumbnail will be generated. Even then, it will only
     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:
         self.interval *= 0.9
         self.log(
             'Thumbnailing sped up (+10%%) to a %.1f ms interval for "%s"' %
             (self.interval, filename_from_uri(self.uri)))
     else:
         self.interval *= 1.1
         self.log(
             'Thumbnailing slowed down (-10%%) to a %.1f ms interval for "%s"' %
             (self.interval, filename_from_uri(self.uri)))
     self.cpu_usage_tracker.reset()
     self._thumb_cb_id = GLib.timeout_add(
         self.interval, self._create_next_thumb)
Exemple #11
0
 def _checkCPU(self):
     """
     Check the CPU usage and adjust the time interval (+10 or -10%) at
     which the next thumbnail will be generated. Even then, it will only
     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:
         self.interval *= 0.9
         self.log(
             'Thumbnailing sped up (+10%%) to a %.1f ms interval for "%s"' %
             (self.interval, filename_from_uri(self.uri)))
     else:
         self.interval *= 1.1
         self.log(
             'Thumbnailing slowed down (-10%%) to a %.1f ms interval for "%s"'
             % (self.interval, filename_from_uri(self.uri)))
     self.cpu_usage_tracker.reset()
     self._thumb_cb_id = GLib.timeout_add(self.interval,
                                          self._create_next_thumb)
Exemple #12
0
 def __init__(self, uri):
     Loggable.__init__(self)
     self._filehash = hash_file(Gst.uri_get_location(uri))
     self._filename = filename_from_uri(uri)
     thumbs_cache_dir = get_dir(os.path.join(xdg_cache_home(), "thumbs"))
     dbfile = os.path.join(thumbs_cache_dir, self._filehash)
     self._db = sqlite3.connect(dbfile)
     self._cur = self._db.cursor()  # Use this for normal db operations
     self._cur.execute("CREATE TABLE IF NOT EXISTS Thumbs\
                       (Time INTEGER NOT NULL PRIMARY KEY,\
                       Jpeg BLOB NOT NULL)")
Exemple #13
0
    def _startLevelsDiscovery(self):
        self.log('Preparing waveforms for "%s"' % filename_from_uri(self._uri))
        filename = hash_file(Gst.uri_get_location(self._uri)) + ".wave"
        cache_dir = get_dir(os.path.join(xdg_cache_home(), "waves"))
        filename = cache_dir + "/" + filename

        if os.path.exists(filename):
            self.samples = pickle.load(open(filename, "rb"))
            self._startRendering()
        else:
            self.wavefile = filename
            self._launchPipeline()
Exemple #14
0
    def _startLevelsDiscovery(self):
        self.log('Preparing waveforms for "%s"' % filename_from_uri(self._uri))
        filename = hash_file(Gst.uri_get_location(self._uri)) + ".wave"
        cache_dir = get_dir(os.path.join(xdg_cache_home(), "waves"))
        filename = cache_dir + "/" + filename

        if os.path.exists(filename):
            self.samples = pickle.load(open(filename, "rb"))
            self._startRendering()
        else:
            self.wavefile = filename
            self._launchPipeline()
Exemple #15
0
 def __init__(self, uri):
     Loggable.__init__(self)
     # TODO: replace with utils.misc.hash_file
     self._filehash = hash_file(Gst.uri_get_location(uri))
     self._filename = filename_from_uri(uri)
     # TODO: replace with pitivi.settings.xdg_cache_home()
     cache_dir = get_dir(os.path.join(xdg_dirs.xdg_cache_home, "pitivi"), autocreate)
     dbfile = os.path.join(get_dir(os.path.join(cache_dir, "thumbs")), self._filehash)
     self._db = sqlite3.connect(dbfile)
     self._cur = self._db.cursor()  # Use this for normal db operations
     self._cur.execute("CREATE TABLE IF NOT EXISTS Thumbs\
                       (Time INTEGER NOT NULL PRIMARY KEY,\
                       Jpeg BLOB NOT NULL)")
Exemple #16
0
    def _launchPipeline(self):
        self.debug('Now generating waveforms for "%s"' % filename_from_uri(self._uri))
        self.peaks = None
        self.pipeline = Gst.parse_launch("uridecodebin name=decode uri=" + self._uri + " ! audioconvert ! level name=wavelevel interval=10000000 post-messages=true ! fakesink qos=false")
        self._level = self.pipeline.get_by_name("wavelevel")
        decode = self.pipeline.get_by_name("decode")
        decode.connect("autoplug-select", self._autoplugSelectCb)
        bus = self.pipeline.get_bus()
        bus.add_signal_watch()

        self.nSamples = self.bElement.get_parent().get_asset().get_duration() / 10000000
        bus.connect("message", self._messageCb)
        self.becomeControlled()
Exemple #17
0
    def _launchPipeline(self):
        self.debug('Now generating waveforms for: %s', filename_from_uri(self._uri))
        self.peaks = None
        self.pipeline = Gst.parse_launch("uridecodebin name=decode uri=" + self._uri + " ! audioconvert ! level name=wavelevel interval=10000000 post-messages=true ! fakesink qos=false name=faked")
        faked = self.pipeline.get_by_name("faked")
        faked.props.sync = True
        self._wavelevel = self.pipeline.get_by_name("wavelevel")
        decode = self.pipeline.get_by_name("decode")
        decode.connect("autoplug-select", self._autoplugSelectCb)
        bus = self.pipeline.get_bus()
        bus.add_signal_watch()

        self.nSamples = self.bElement.get_parent().get_asset().get_duration() / 10000000
        bus.connect("message", self._busMessageCb)
        self.becomeControlled()
Exemple #18
0
    def _launchPipeline(self):
        self.debug(
            'Now generating waveforms for: %s', filename_from_uri(self._uri))
        self.pipeline = Gst.parse_launch("uridecodebin name=decode uri=" +
                                         self._uri + " ! waveformbin name=wave"
                                         " ! fakesink qos=false name=faked")
        faked = self.pipeline.get_by_name("faked")
        faked.props.sync = True
        self._wavebin = self.pipeline.get_by_name("wave")
        asset = self.ges_elem.get_parent().get_asset()
        self._wavebin.props.uri = asset.get_id()
        self._wavebin.props.duration = asset.get_duration()
        decode = self.pipeline.get_by_name("decode")
        decode.connect("autoplug-select", self._autoplugSelectCb)
        bus = self.pipeline.get_bus()
        bus.add_signal_watch()

        asset = self.ges_elem.get_parent().get_asset()
        self.n_samples = asset.get_duration() / SAMPLE_DURATION
        bus.connect("message", self._busMessageCb)
        self.becomeControlled()
Exemple #19
0
    def _launchPipeline(self):
        self.debug('Now generating waveforms for: %s',
                   filename_from_uri(self._uri))
        self.pipeline = Gst.parse_launch("uridecodebin name=decode uri=" +
                                         self._uri + " ! waveformbin name=wave"
                                         " ! fakesink qos=false name=faked")
        faked = self.pipeline.get_by_name("faked")
        faked.props.sync = True
        self._wavebin = self.pipeline.get_by_name("wave")
        asset = self.ges_elem.get_parent().get_asset()
        self._wavebin.props.uri = asset.get_id()
        self._wavebin.props.duration = asset.get_duration()
        decode = self.pipeline.get_by_name("decode")
        decode.connect("autoplug-select", self._autoplugSelectCb)
        bus = self.pipeline.get_bus()
        bus.add_signal_watch()

        asset = self.ges_elem.get_parent().get_asset()
        self.n_samples = asset.get_duration() / SAMPLE_DURATION
        bus.connect("message", self._busMessageCb)
        self.becomeControlled()
Exemple #20
0
    def do_query_tooltip(self, x, y, keyboard_mode, tooltip):
        tooltip.set_markup(
            misc.filename_from_uri(self.ges_clip.get_asset().props.id))

        return True
Exemple #21
0
    def do_query_tooltip(self, x, y, keyboard_mode, tooltip):
        tooltip.set_markup(misc.filename_from_uri(
            self.bClip.get_asset().props.id))

        return True
Exemple #22
0
    def __init__(self, layer, ges_clip):
        SourceClip.__init__(self, layer, ges_clip)
        self.props.has_tooltip = True

        self.set_tooltip_markup(misc.filename_from_uri(ges_clip.get_uri()))
Exemple #23
0
    def _checkCPU(self):
        """
        Check the CPU usage and adjust the time interval (+10 or -10%) at
        which the next thumbnail will be generated. Even then, it will only
        happen when the gobject loop is idle to avoid blocking the UI.
        """
        deltaTime = (datetime.now() - self.lastMoment).total_seconds()
        deltaUsage = resource.getrusage(resource.RUSAGE_SELF).ru_utime - self.lastUsage.ru_utime
        usage_percent = float(deltaUsage) / deltaTime * 100

        if usage_percent < THUMBNAILS_CPU_USAGE:
            self.interval *= 0.9
            self.log('Thumbnailing sped up (+10%%) to a %.1f ms interval for "%s"' % (self.interval, filename_from_uri(self.uri)))
        else:
            self.interval *= 1.1
            self.log('Thumbnailing slowed down (-10%%) to a %.1f ms interval for "%s"' % (self.interval, filename_from_uri(self.uri)))

        self.lastMoment = datetime.now()
        self.lastUsage = resource.getrusage(resource.RUSAGE_SELF)
        self._thumb_cb_id = GLib.timeout_add(self.interval, self._create_next_thumb)

        return False
Exemple #24
0
    def __init__(self, layer, bClip):
        super(UriClip, self).__init__(layer, bClip)
        self.props.has_tooltip = True

        self.set_tooltip_markup(misc.filename_from_uri(bClip.get_uri()))
Exemple #25
0
 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)
Exemple #26
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)
Exemple #27
0
 def startLevelsDiscoveryWhenIdle(self):
     """Starts processing waveform (whenever possible)."""
     self.debug('Waiting for UI to become idle for: %s',
                filename_from_uri(self._uri))
     GLib.idle_add(self._startLevelsDiscovery, priority=GLib.PRIORITY_LOW)
Exemple #28
0
    def __init__(self, layer, ges_clip):
        SourceClip.__init__(self, layer, ges_clip)
        self.props.has_tooltip = True

        self.set_tooltip_markup(misc.filename_from_uri(ges_clip.get_uri()))
Exemple #29
0
 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)
Exemple #30
0
    def __init__(self, layer, bClip):
        super(UriClip, self).__init__(layer, bClip)

        self.set_tooltip_markup(misc.filename_from_uri(bClip.get_uri()))
        self.bClip.selected.connect("selected-changed", self._selectedChangedCb)
Exemple #31
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)