[pitivi] First effect integration in the non UI timeline



commit c8bc64e579e002dc687867a88652830e2f6521ca
Author: Thibault Saunier <tsaunier src gnome org>
Date:   Fri May 21 11:17:03 2010 -0400

    First effect integration in the non UI timeline

 pitivi/timeline/timeline.py |   40 +++++++++++++++++++++++++++++++++++++++-
 pitivi/timeline/track.py    |   11 +++++++++++
 tests/common.py             |    9 +++++++++
 tests/test_timeline.py      |   23 ++++++++++++++++++++++-
 4 files changed, 81 insertions(+), 2 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 48f938f..4a9c8ec 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -25,7 +25,8 @@ from bisect import bisect_left
 from pitivi.signalinterface import Signallable
 from pitivi.log.loggable import Loggable
 from pitivi.utils import UNKNOWN_DURATION, closest_item, PropertyChangeTracker
-from pitivi.timeline.track import TrackObject, SourceTrackObject, TrackError
+from pitivi.timeline.track import TrackObject, SourceTrackObject,\
+     EffectTrackObject, TrackError
 from pitivi.stream import match_stream_groups_map
 from pitivi.utils import start_insort_right, infinity, getPreviousObject, \
         getNextObject
@@ -1664,6 +1665,8 @@ class Timeline(Signallable, Loggable):
         timeline_object = TimelineObject(factory)
         start = 0
         for stream, track in stream_map.iteritems():
+            self.debug( "Stream: " + str(stream) + "\nTrack :" + str(track) +\
+                        "\n Track duration:" + str(track.duration))
             start = max(start, track.duration)
             track_object = SourceTrackObject(factory, stream)
             track.addTrackObject(track_object)
@@ -1673,6 +1676,41 @@ class Timeline(Signallable, Loggable):
         self.addTimelineObject(timeline_object)
         return timeline_object
 
+    def addEffectFactory(self, factory):
+        """
+        Creates a TimelineObject for the given EffectFactory and adds it to the timeline.
+
+        @param factory: The EffectFactory to add.
+        @type factory: L{EffectFactory}
+        @raises TimelineError: if C{strict} is True and no exact mapping could be calculated.
+        """
+        self.debug("factory:%r", factory)
+
+        output_streams = factory.getOutputStreams()
+        if not output_streams:
+            raise TimelineError()
+
+        stream_map = self._getSourceFactoryStreamMap(factory)
+        if len(stream_map) < len(output_streams):
+            # we couldn't assign each stream to a track automatically,
+            # error out and require the caller to pass a stream_map
+            self.error("Couldn't find a complete stream mapping (self:%d < factory:%d)",
+                       len(stream_map), len(output_streams))
+
+        timeline_object = TimelineObject(factory)
+        start = 0
+        for stream, track in stream_map.iteritems():
+            self.debug("Stream: " + str(stream) + "\nTrack :" + str(track) +\
+                       "\nTrack duration:" + str(track.duration))
+            start = max(start, track.duration)
+            track_object = EffectTrackObject(factory, stream)
+            track.addTrackObject(track_object)
+            timeline_object.addTrackObject(track_object)
+
+        timeline_object.start = start
+        self.addTimelineObject(timeline_object)
+        return timeline_object
+
     def _getSourceFactoryStreamMap(self, factory):
         # track.stream -> track
         track_stream_to_track_map = dict((track.stream, track)
diff --git a/pitivi/timeline/track.py b/pitivi/timeline/track.py
index 0594c00..2d7c34a 100644
--- a/pitivi/timeline/track.py
+++ b/pitivi/timeline/track.py
@@ -705,6 +705,17 @@ class SourceTrackObject(TrackObject):
         SourceTrackObject.numobjs += 1
         return source
 
+class EffectTrackObject(TrackObject):
+
+    numobjs = 0
+
+    def _makeGnlObject(self):
+        effect = gst.element_factory_make('gnloperation',
+            "gnloperation: " + self.factory.__class__.__name__ +
+            str(SourceTrackObject.numobjs))
+        EffectTrackObject.numobjs += 1
+        return effect
+
 class Transition(Signallable):
 
     __signals__ = {
diff --git a/tests/common.py b/tests/common.py
index 1598b0d..388c6d7 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -9,6 +9,7 @@ import os
 import gc
 import unittest
 from pitivi.factories.base import ObjectFactory, SourceFactory, SinkFactory
+from pitivi.factories.operation import VideoEffectFactory, AudioEffectFactory
 from pitivi.pipeline import Pipeline
 
 detect_leaks = os.environ.get("PITIVI_TEST_DETECT_LEAKS", "1") not in ("0", "")
@@ -161,3 +162,11 @@ class StubFactory(SourceFactory):
 
     def _releaseBin(self, bin):
         pass
+
+class FakeVideoEffectFactory(VideoEffectFactory):
+    def __init__(self):
+        VideoEffectFactory.__init__(self, 'identity', "identity")
+
+class FakeAudioEffectFactory(AudioEffectFactory):
+    def __init__(self):
+        AudioEffectFactory.__init__(self, 'identity', "identity")
diff --git a/tests/test_timeline.py b/tests/test_timeline.py
index 8cf956a..aa7d243 100644
--- a/tests/test_timeline.py
+++ b/tests/test_timeline.py
@@ -23,7 +23,8 @@ import pygst
 pygst.require("0.10")
 import gst
 
-from tests.common import FakeSourceFactory
+from tests.common import FakeSourceFactory, FakeVideoEffectFactory,\
+     FakeAudioEffectFactory
 from pitivi.timeline.timeline import Timeline, TimelineObject, TimelineError, \
         Selection, Link, TimelineEdges, MoveContext, TrimStartContext, \
         TrimEndContext
@@ -1030,6 +1031,8 @@ class TestTimelineAddFactory(TestCase):
         self.timeline.addTrack(self.video_track2)
 
         self.factory = StubFactory()
+        self.video_effect_factory = FakeVideoEffectFactory()
+        self.audio_effect_factory = FakeAudioEffectFactory()
 
     def tearDown(self):
         del self.audio_stream1
@@ -1043,6 +1046,8 @@ class TestTimelineAddFactory(TestCase):
         del self.video_track2
         del self.timeline
         del self.factory
+        del self.video_effect_factory
+        del self.audio_effect_factory
         TestCase.tearDown(self)
 
     def testNoStreams(self):
@@ -1064,6 +1069,22 @@ class TestTimelineAddFactory(TestCase):
         self.failUnlessEqual(len(self.video_track1.track_objects), 1)
         self.failUnlessEqual(len(self.video_track2.track_objects), 0)
 
+    def testVideoEffectOnly(self):
+        self.video_effect_factory.addOutputStream(self.video_stream1)
+        self.timeline.addEffectFactory(self.video_effect_factory)
+        self.failUnlessEqual(len(self.audio_track1.track_objects), 0)
+        self.failUnlessEqual(len(self.audio_track2.track_objects), 0)
+        self.failUnlessEqual(len(self.video_track1.track_objects), 1)
+        self.failUnlessEqual(len(self.video_track2.track_objects), 0)
+
+    def testAudioEffectOnly(self):
+        self.audio_effect_factory.addOutputStream(self.audio_stream1)
+        self.timeline.addEffectFactory(self.audio_effect_factory)
+        self.failUnlessEqual(len(self.audio_track1.track_objects), 0)
+        self.failUnlessEqual(len(self.audio_track2.track_objects), 0)
+        self.failUnlessEqual(len(self.video_track1.track_objects), 1)
+        self.failUnlessEqual(len(self.video_track2.track_objects), 0)
+
     def test1Audio1Video(self):
         self.factory.addOutputStream(self.audio_stream1)
         self.factory.addOutputStream(self.video_stream1)



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