[pitivi] timeline/track.py: Reliable implementation of TrackEffect.getElement()
- From: Edward Hervey <edwardrv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] timeline/track.py: Reliable implementation of TrackEffect.getElement()
- Date: Wed, 22 Sep 2010 13:48:04 +0000 (UTC)
commit 71624851f77e79a4c13046b29e0a8666f4f8fae7
Author: Thibault Saunier <tsaunier gnome org>
Date: Tue Sep 7 11:49:32 2010 +0200
timeline/track.py: Reliable implementation of TrackEffect.getElement()
pitivi/factories/operation.py | 34 ++++++++++++++++++++++++++++++----
pitivi/timeline/track.py | 24 +++++++++++++++++++-----
tests/test_factories_operation.py | 4 ++--
3 files changed, 51 insertions(+), 11 deletions(-)
---
diff --git a/pitivi/factories/operation.py b/pitivi/factories/operation.py
index c5118bb..9f2f2b4 100644
--- a/pitivi/factories/operation.py
+++ b/pitivi/factories/operation.py
@@ -21,7 +21,7 @@
# Boston, MA 02111-1307, USA.
import gst
-from pitivi.factories.base import OperationFactory
+from pitivi.factories.base import OperationFactory, ObjectFactoryError
from pitivi.stream import AudioStream, VideoStream
from gettext import gettext as _
@@ -56,7 +56,7 @@ class TransformFactory(OperationFactory):
def _requestNewInputStream(self, *args):
raise OperationFactoryError("TransformFactory doesn't allow request pads")
-class EffectFactory (TransformFactory):
+class EffectFactory(TransformFactory):
"""
Factories that applies an effect on a stream
"""
@@ -78,6 +78,33 @@ class EffectFactory (TransformFactory):
def getCategories(self):
return self.categories
+ def makeBin(self, input_stream=None, output_stream=None):
+ """
+ Create a bin that consumes the stream described by C{input_stream}.
+
+ If C{input_stream} and/or C{output_stream} are None, it's up to the
+ implementations to return a suitable "default" bin.
+
+ @param input_stream: A L{MultimediaStream}
+ @param output_stream: A L{MultimediaStream}
+ @return: A bin and the element
+ @rtype: C{gst.Bin} and C{gst.Element}
+
+ @see: L{releaseBin}
+ """
+
+ if input_stream is not None and \
+ input_stream not in self.input_streams:
+ raise ObjectFactoryError('unknown stream')
+
+ bin, fx = self._makeBin(input_stream)
+ bin.factory = self
+ self.bins.append(bin)
+ self.current_bins += 1
+ self.emit('bin-created', bin)
+
+ return bin, fx
+
def _makeBin (self, *args):
bin = gst.Bin()
fx = gst.element_factory_make(self.effectname)
@@ -93,14 +120,13 @@ class EffectFactory (TransformFactory):
bin.add_pad(gst.GhostPad("sink", csp.get_pad("sink")))
bin.add_pad(gst.GhostPad("src", fx.get_pad("src")))
- return bin
+ return bin, fx
def _releaseBin(self, bin):
elements = bin.elements()
for element in elements.next():
del element
-
def addInputStream(self, stream):
return OperationFactory.addInputStream(self, stream)
diff --git a/pitivi/timeline/track.py b/pitivi/timeline/track.py
index 84233e1..3654335 100644
--- a/pitivi/timeline/track.py
+++ b/pitivi/timeline/track.py
@@ -644,11 +644,14 @@ class TrackObject(Signallable, Loggable):
if self.gnl_object is None:
raise TrackError()
- bin = self.factory.makeBin(self.stream)
+ bin = self._getBin()
self.gnl_object.add(bin)
self._rebuild_interpolators = True
self._maybeBuildInterpolators()
+ def _getBin(self):
+ return self.factory.makeBin(self.stream)
+
def releaseBin(self):
for bin in list(self.gnl_object.elements()):
self.gnl_object.remove(bin)
@@ -738,6 +741,14 @@ class TrackEffect(TrackObject):
numobjs = 0
+ def __init__(self, factory, stream, start=0,
+ duration=0, in_point=0,
+ media_duration=0, priority=0):
+ TrackObject.__init__(self, factory, stream, start=0,
+ duration=0, in_point=0,
+ media_duration=0, priority=0)
+ self._element = None
+
def _makeGnlObject(self):
effect = gst.element_factory_make('gnloperation',
"gnloperation: " + self.factory.__class__.__name__ +
@@ -745,6 +756,12 @@ class TrackEffect(TrackObject):
TrackEffect.numobjs += 1
return effect
+ def _getBin(self):
+ bin, fx = self.factory.makeBin(self.stream)
+ self._element = fx
+
+ return bin
+
def copy(self):
other = TrackObject.copy(self)
@@ -763,10 +780,7 @@ class TrackEffect(TrackObject):
Permit to get the gst.Element inside the gnl_object that correspond
to the track factory
"""
- #Should we find a better implementation?
- for element in self.gnl_object.recurse():
- if self.factory.name in element.get_name():
- return element
+ return self._element
class Transition(Signallable):
diff --git a/tests/test_factories_operation.py b/tests/test_factories_operation.py
index df01b0b..d36ba69 100644
--- a/tests/test_factories_operation.py
+++ b/tests/test_factories_operation.py
@@ -40,8 +40,8 @@ class TestEffectFactory(TestCase):
self.factory.addInputStream(self.stream)
def testMakeBin (self):
- bin = self.factory.makeBin()
- bin2 = self.factory.makeBin()
+ bin, fx = self.factory.makeBin()
+ bin2, fx = self.factory.makeBin()
csp = bin.elements().next()
self.failUnless(isinstance(bin, gst.Bin))
self.failUnless(csp)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]