[pitivi/ges: 33/287] Use the standard gst.Discoverer everywhere
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi/ges: 33/287] Use the standard gst.Discoverer everywhere
- Date: Thu, 15 Mar 2012 16:28:36 +0000 (UTC)
commit 9f81ecc4095ac2414478c24195d7ca173243c81e
Author: Thibault Saunier <thibault saunier collabora com>
Date: Tue Aug 30 21:37:07 2011 -0300
Use the standard gst.Discoverer everywhere
Remove any reference to the python Discoverer
pitivi/Makefile.am | 1 -
pitivi/discoverer.py | 729 ---------------------------------------
pitivi/project.py | 14 +-
pitivi/sourcelist.py | 60 +---
pitivi/ui/filechooserpreview.py | 81 ++---
pitivi/ui/mainwindow.py | 6 +-
pitivi/ui/sourcelist.py | 6 -
po/POTFILES.in | 1 -
tests/Makefile.am | 1 -
tests/test_discoverer.py | 504 ---------------------------
10 files changed, 58 insertions(+), 1345 deletions(-)
---
diff --git a/pitivi/Makefile.am b/pitivi/Makefile.am
index b77a1ff..48d7d84 100644
--- a/pitivi/Makefile.am
+++ b/pitivi/Makefile.am
@@ -15,7 +15,6 @@ pitivi_PYTHON = \
application.py \
check.py \
configure.py \
- discoverer.py \
effects.py \
encode.py \
instance.py \
diff --git a/pitivi/project.py b/pitivi/project.py
index 7726156..7e27e17 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -86,8 +86,6 @@ class Project(Signallable, Loggable):
self.urichanged = False
self.format = None
self.sources = SourceList()
- self.sources.connect("source-added", self._sourceAddedCb)
- self.sources.connect("source-removed", self._sourceRemovedCb)
self._dirty = False
@@ -155,12 +153,6 @@ class Project(Signallable, Loggable):
for fact in self.sources.getSources():
fact.setFilterCaps(self._videocaps)
- if self.pipeline.get_state() != gst.STATE_NULL:
- self.pipeline.set_state(gst.STATE_READY)
- self.pipeline.set_state(gst.STATE_PAUSED)
-
- def _sourceAddedCb(self, sourcelist, factory):
- factory.setFilterCaps(self._videocaps)
-
- def _sourceRemovedCb(self, sourclist, uri, factory):
- self.timeline.removeFactory(factory)
+ if self.pipeline.getState() != gst.STATE_NULL:
+ self.pipeline.stop()
+ self.pipeline.pause()
diff --git a/pitivi/sourcelist.py b/pitivi/sourcelist.py
index 0e07fa8..e52e54b 100644
--- a/pitivi/sourcelist.py
+++ b/pitivi/sourcelist.py
@@ -28,6 +28,8 @@ import urllib
from pitivi.discoverer import Discoverer
from pitivi.signalinterface import Signallable
from pitivi.log.loggable import Loggable
+import gst
+from pitivi.factories.file import FileSourceFactory
class SourceListError(Exception):
@@ -35,7 +37,7 @@ class SourceListError(Exception):
class SourceList(Signallable, Loggable):
- discovererClass = Discoverer
+ discovererClass = gst.pbutils.Discoverer
"""
Contains the sources for a project, stored as SourceFactory objects.
@@ -51,8 +53,6 @@ class SourceList(Signallable, Loggable):
Signals:
- C{source-added} : A source has been discovered and added to the SourceList.
- C{source-removed} : A source was removed from the SourceList.
- - C{missing-plugins} : A source has been discovered but some plugins are
- missing in order to decode all of its streams.
- C{discovery-error} : The given uri is not a media file.
- C{ready} : No more files are being discovered/added.
- C{starting} : Some files are being discovered/added.
@@ -61,7 +61,6 @@ class SourceList(Signallable, Loggable):
__signals__ = {
"ready": [],
"starting": [],
- "missing-plugins": ["uri", "factory", "details", "descriptions"],
"source-added": ["factory"],
"source-removed": ["uri"],
"discovery-error": ["uri", "reason"],
@@ -77,13 +76,7 @@ class SourceList(Signallable, Loggable):
self.nb_file_to_import = 1
self.nb_imported_files = 0
- self.discoverer = self.discovererClass()
- self.discoverer.connect("discovery-error", self._discoveryErrorCb)
- self.discoverer.connect("discovery-done", self._discoveryDoneCb)
- self.discoverer.connect("starting", self._discovererStartingCb)
- self.discoverer.connect("ready", self._discovererReadyCb)
- self.discoverer.connect("missing-plugins",
- self._discovererMissingPluginsCb)
+ self.discoverer = self.discovererClass(gst.SECOND)
def addUri(self, uri):
"""
@@ -95,9 +88,15 @@ class SourceList(Signallable, Loggable):
# uri is already added. Nothing to do.
return
self._sources[uri] = None
- # Tell the discoverer to investigate the URI and report back when
- # it has the info or failed.
- self.discoverer.addUri(uri)
+
+ try:
+ self.discoverer.discover_uri(uri)
+ except Exception, e:
+ self.emit("discovery-error", uri, e, "")
+ return
+
+ factory = FileSourceFactory(uri)
+ self.addFactory(factory)
def addUris(self, uris):
"""
@@ -109,6 +108,7 @@ class SourceList(Signallable, Loggable):
self.nb_imported_files = 0
for uri in uris:
self.addUri(uri)
+ self.emit("ready")
def removeUri(self, uri):
"""
@@ -155,35 +155,3 @@ class SourceList(Signallable, Loggable):
@return: A list of SourceFactory objects which must not be changed.
"""
return self._ordered_sources
-
- def _discoveryDoneCb(self, discoverer, uri, factory):
- """Handles the success of a URI info gathering operation."""
- if factory.uri not in self._sources:
- # The source was removed while it was being scanned. Nothing to do.
- return
- self.addFactory(factory)
-
- def _discoveryErrorCb(self, discoverer, uri, reason, extra):
- """Handles the failure of a URI info gathering operation."""
- try:
- del self._sources[uri]
- except KeyError:
- # The source was removed while it was being scanned. Nothing to do.
- pass
- self.emit("discovery-error", uri, reason, extra)
-
- def _discovererStartingCb(self, unused_discoverer):
- """Handles the start of the URI info gathering operations."""
- self.emit("starting")
-
- def _discovererReadyCb(self, unused_discoverer):
- """Handles the finish of the URI info gathering operations."""
- self.emit("ready")
-
- def _discovererMissingPluginsCb(self, discoverer, uri, factory,
- details, descriptions, missingPluginsCallback):
- if factory.uri not in self._sources:
- # The source was removed while it was being scanned. Nothing to do.
- return None
- return self.emit('missing-plugins', uri, factory,
- details, descriptions, missingPluginsCallback)
diff --git a/pitivi/ui/filechooserpreview.py b/pitivi/ui/filechooserpreview.py
index 7002a94..e84dcec 100644
--- a/pitivi/ui/filechooserpreview.py
+++ b/pitivi/ui/filechooserpreview.py
@@ -6,12 +6,9 @@ import pango
import os
from pitivi.log.loggable import Loggable
-from pitivi.discoverer import Discoverer
from pitivi.ui.common import beautify_stream
-from pitivi.stream import AudioStream, VideoStream
from pitivi.utils import beautify_length, uri_is_valid
from pitivi.configure import get_pixmap_dir
-from pitivi.factories.file import PictureFileSourceFactory
from pitivi.settings import GlobalSettings
from gettext import gettext as _
from pitivi.ui.common import SPACING
@@ -57,9 +54,7 @@ class PreviewWidget(gtk.VBox, Loggable):
self.preview_cache = {}
self.preview_cache_errors = {}
- self.discoverer = Discoverer()
- self.discoverer.connect('discovery-done', self._update_preview_cb)
- self.discoverer.connect('discovery-error', self._error_detected_cb)
+ self.discoverer = gst.pbutils.Discoverer(gst.SECOND)
#playbin for play pics
self.player = get_playbin()
@@ -149,43 +144,42 @@ class PreviewWidget(gtk.VBox, Loggable):
self.current_selected_uri = uri
if uri in self.preview_cache: # Already discovered
self.log(uri + " already in cache")
- self.show_preview(uri)
+ self.show_preview(uri, None)
elif uri in self.preview_cache_errors:
self.log(uri + " already in error cache")
self.show_error(uri)
else:
self.log("Call discoverer for " + uri)
- self.discoverer.addUri(uri)
-
- def _update_preview_cb(self, dscvr, uri, factory):
- if factory is None:
- self.error("Discoverer does not handle " + uri)
- # Add to cache
- self.preview_cache[uri] = factory
- # Show uri only if is the selected one
- if self.current_selected_uri == uri:
- self.show_preview(uri)
-
- def _error_detected_cb(self, discoverer, uri, mess, details):
- if details is not None:
- self.preview_cache_errors[uri] = (mess, details)
+ try:
+ info = self.discoverer.discover_uri(uri)
+ except Exception, e:
+ if e is not None:
+ self.preview_cache_errors[uri] = e
+ if self.current_selected_uri == uri:
+ self.show_error(uri)
+ return
+
if self.current_selected_uri == uri:
- self.show_error(uri)
+ self.show_preview(uri, info)
+
+ def show_preview(self, uri, info):
- def show_preview(self, uri):
- self.log("Show preview for " + uri)
- factory = self.preview_cache.get(uri, None)
- if factory is None:
+ if info:
+ self.preview_cache[uri] = info
+ else:
+ self.log("Show preview for " + uri)
+ info = self.preview_cache.get(uri, None)
+
+ if info is None:
self.log("No preview for " + uri)
return
- if not factory.duration or factory.duration == gst.CLOCK_TIME_NONE:
- duration = ''
- else:
- duration = beautify_length(factory.duration)
- video = factory.getOutputStreams(VideoStream)
- if video:
- video = video[0]
- if type(factory) == PictureFileSourceFactory:
+
+ duration = beautify_length(info.get_duration())
+
+ videos = info.get_video_streams()
+ if videos:
+ video = videos[0]
+ if video.is_image():
self.current_preview_type = 'image'
self.preview_video.hide()
pixbuf = gtk.gdk.pixbuf_new_from_file(gst.uri_get_location(uri))
@@ -207,9 +201,10 @@ class PreviewWidget(gtk.VBox, Loggable):
self.player.set_property("video-sink", self.__videosink)
self.player.set_property("uri", self.current_selected_uri)
self.player.set_state(gst.STATE_PAUSED)
- self.clip_duration = factory.duration
+ self.clip_duration = info.get_duration()
self.pos_adj.upper = self.clip_duration
- w, h = self.__get_best_size(video.par * video.width, video.height)
+ w, h = self.__get_best_size((video.get_par_num() / video.get_par_denom()) * video.get_width(),
+ video.get_height())
self.preview_video.set_size_request(w, h)
self.preview_video.show()
self.bbox.show()
@@ -218,14 +213,17 @@ class PreviewWidget(gtk.VBox, Loggable):
self.b_zoom_in.show()
self.b_zoom_out.show()
self.description = _(u"<b>Resolution</b>: %dÃ%d") % \
- (video.par * video.width, video.height) + "\n" + \
- _("<b>Duration</b>: %s") % duration + "\n"
+ ((video.get_par_num() / video.get_par_denom()) * video.get_width(), video.get_height()) +\
+ "\n" + _("<b>Duration</b>: %s") % duration + "\n"
else:
self.current_preview_type = 'audio'
self.preview_video.hide()
- audio = factory.getOutputStreams(AudioStream)
+ audio = info.get_video_streams()
+
+ if not audio:
+ return
+
audio = audio[0]
- self.clip_duration = factory.duration
self.pos_adj.upper = self.clip_duration
self.preview_image.set_from_file(DEFAULT_AUDIO_IMAGE)
self.preview_image.show()
@@ -390,7 +388,7 @@ class PreviewWidget(gtk.VBox, Loggable):
self.l_tags.set_markup(text)
def _on_b_details_clicked_cb(self, unused_button):
- mess, detail = self.preview_cache_errors.get(self.current_selected_uri, (None, None))
+ mess = self.preview_cache_errors.get(self.current_selected_uri, None)
if mess is not None:
dialog = gtk.MessageDialog(None,
gtk.DIALOG_MODAL,
@@ -399,7 +397,6 @@ class PreviewWidget(gtk.VBox, Loggable):
mess)
dialog.set_icon_name("pitivi")
dialog.set_title(_("Error while analyzing a file"))
- dialog.set_property("secondary-text", detail)
dialog.run()
dialog.destroy()
diff --git a/pitivi/ui/mainwindow.py b/pitivi/ui/mainwindow.py
index 6084d65..fae258f 100644
--- a/pitivi/ui/mainwindow.py
+++ b/pitivi/ui/mainwindow.py
@@ -688,7 +688,8 @@ class PitiviMainWindow(gtk.Window, Loggable):
self.project = project
self.timeline.project = self.project
self.clipconfig.project = self.project
- self._connectToProjectSources(project.sources)
+ #FIXME we should reanable it when possible with GES
+ #self._connectToProjectSources(project.sources)
duration = 0
can_render = duration > 0
self._syncDoUndo(self.app.action_log)
@@ -909,9 +910,6 @@ class PitiviMainWindow(gtk.Window, Loggable):
def _connectToProjectSources(self, sourcelist):
sourcelist.connect("missing-plugins", self._sourceListMissingPluginsCb)
- def _disconnectFromProjectSources(self, sourcelist):
- sourcelist.disconnect_by_func(self._sourceListMissingPluginsCb)
-
def _actionLogCommit(self, action_log, stack, nested):
if nested:
return
diff --git a/pitivi/ui/sourcelist.py b/pitivi/ui/sourcelist.py
index 9d07e30..8cd0185 100644
--- a/pitivi/ui/sourcelist.py
+++ b/pitivi/ui/sourcelist.py
@@ -453,8 +453,6 @@ class SourceList(gtk.VBox, Loggable):
self.project_signals.connect(
project.sources, "discovery-error", None, self._discoveryErrorCb)
self.project_signals.connect(
- project.sources, "missing-plugins", None, self._missingPluginsCb)
- self.project_signals.connect(
project.sources, "ready", None, self._sourcesStoppedImportingCb)
self.project_signals.connect(
project.sources, "starting", None, self._sourcesStartedImportingCb)
@@ -636,10 +634,6 @@ class SourceList(gtk.VBox, Loggable):
error = (uri, reason, extra)
self._errors.append(error)
- def _missingPluginsCb(self, sourcelist, uri, factory, details, descriptions, cb):
- error = (uri, "Missing plugins", "\n".join(descriptions))
- self._errors.append(error)
-
def _sourcesStartedImportingCb(self, sourcelist):
self._progressbar.show()
self._updateProgressbar()
diff --git a/po/POTFILES.in b/po/POTFILES.in
index febd416..5134d9a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -14,7 +14,6 @@ data/pitivi.desktop.in.in
[type: gettext/glade]data/ui/startupwizard.ui
pitivi/application.py
pitivi/check.py
-pitivi/discoverer.py
pitivi/effects.py
pitivi/factories/base.py
pitivi/factories/file.py
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c016f1f..a1003aa 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -8,7 +8,6 @@ tests = \
test_binary_search.py \
test_cache.py \
test_common.py \
- test_discoverer.py \
test_encode.py \
test_etree_formatter.py \
test_factories_base.py \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]