From 1a88595e9408019ad0b2ea529ebb71c98228c8b5 Mon Sep 17 00:00:00 2001 From: Daniel Kamil Kozar Date: Sun, 8 May 2016 11:29:50 +0200 Subject: [PATCH] sort the conversion tasks in descending order according to duration. --- soundconverter/gstreamer.py | 47 ++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/soundconverter/gstreamer.py b/soundconverter/gstreamer.py index dcea0b32..d65b9904 100644 --- a/soundconverter/gstreamer.py +++ b/soundconverter/gstreamer.py @@ -295,13 +295,22 @@ def __init__(self, sound_file): Pipeline.__init__(self) self.sound_file = sound_file - command = '%s location="%s" ! typefind name=typefinder ! fakesink' % \ + command = '%s location="%s" ! decodebin name=decoder ! fakesink' % \ (gstreamer_source, encode_filename(self.sound_file.uri)) self.add_command(command) - self.add_signal('typefinder', 'have-type', self.have_type) + self.add_signal('decoder', 'pad-added', self.pad_added) + # 'typefind' is the name of the typefind element created inside + # decodebin. we can't use our own typefind before decodebin anymore, + # since its caps would've been the same as decodebin's sink caps. + self.add_signal('typefind', 'have-type', self.have_type) def set_found_type_hook(self, found_type_hook): self.found_type_hook = found_type_hook + + def pad_added(self, decoder, pad): + """ called when a decoded pad is created """ + self.query_duration() + self.done() def have_type(self, typefind, probability, caps): mime_type = caps.to_string() @@ -316,9 +325,20 @@ def have_type(self, typefind, probability, caps): if fnmatch(self.sound_file.uri, t): self.sound_file.mime_type = None log('filename blacklisted (%s): %s' % (t, self.sound_file.filename_for_display)) - - self.done() + return True + + def query_duration(self): + """ + Ask for the duration of the current pipeline. + """ + try: + if not self.sound_file.duration and self.pipeline: + self.sound_file.duration = self.pipeline.query_duration(Gst.Format.TIME)[1] / Gst.SECOND + if self.sound_file.duration <= 0: + self.sound_file.duration = None + except Gst.QueryError: + self.sound_file.duration = None def finished(self): Pipeline.finished(self) @@ -346,18 +366,6 @@ def __init__(self, sound_file): def have_type(self, typefind, probability, caps): pass - def query_duration(self): - """ - Ask for the duration of the current pipeline. - """ - try: - if not self.sound_file.duration and self.pipeline: - self.sound_file.duration = self.pipeline.query_duration(Gst.Format.TIME)[1] / Gst.SECOND - if self.sound_file.duration <= 0: - self.sound_file.duration = None - except Gst.QueryError: - self.sound_file.duration = None - def query_position(self): """ Ask for the stream position of the current pipeline. @@ -414,11 +422,9 @@ def append_tag(self, taglist, tag, unused_udata): tags['date'] = dt.to_iso8601_string()[:10] self.sound_file.tags.update(tags) - self.query_duration() def pad_added(self, decoder, pad): """ called when a decoded pad is created """ - self.query_duration() self.processing = True def finished(self): @@ -432,7 +438,6 @@ def get_input_uri(self): def get_duration(self): """ return the total duration of the sound file """ - self.query_duration() return self.sound_file.duration def get_position(self): @@ -794,3 +799,7 @@ def abort(self): TaskQueue.abort(self) self.window.set_sensitive() self.reset_counters() + + def start(self): + self.waiting_tasks.sort(key=Converter.get_duration,reverse=True) + TaskQueue.start(self)