[pitivi: 2/4] Use match_stream_groups in Timeline.addSourceFactory.



commit bff8145da495dc52c29b7e462c7479fd4a9395bb
Author: Alessandro Decina <alessandro d gmail com>
Date:   Mon Jun 1 13:23:08 2009 +0200

    Use match_stream_groups in Timeline.addSourceFactory.
---
 pitivi/timeline/timeline.py |   54 ++++++++++++++----------------------------
 tests/test_timeline.py      |    6 +++-
 2 files changed, 22 insertions(+), 38 deletions(-)

diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index f9b5d09..875e2d1 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -21,12 +21,13 @@
 # Boston, MA 02111-1307, USA.
 
 import gst
+from bisect import bisect_right
 
 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 Track, SourceTrackObject, TrackError
-from bisect import bisect_right
+from pitivi.stream import match_stream_groups_map
 
 # Selection modes
 SELECT = 0
@@ -924,41 +925,22 @@ class Timeline(Signallable, Loggable):
 
     # FIXME : Shouldn't this be a private method ??
     def getSourceFactoryStreamMap(self, factory):
-        self.debug("factory:%r", factory)
-        mapped_tracks = []
-        timeline_object = TimelineObject(factory)
-
-        stream_map = {}
-        output_streams = factory.getOutputStreams()
-        for output_stream in output_streams:
-            track = self._getTrackForFactoryStream(factory,
-                    output_stream, mapped_tracks)
-            if track is None:
-                self.debug("no track found for stream %s", output_stream)
-                # couldn't find a track for this stream
-                continue
-
-            stream_map[output_stream] = track
-
-            # we don't want to reuse the same track for different streams coming
-            # from the same source
-            mapped_tracks.append(track)
-
-        return stream_map
-
-    def _getTrackForFactoryStream(self, factory, stream, mapped_tracks):
-        self.debug("factory:%r, stream:%s", factory, stream)
-        for track in self.tracks:
-            if track not in mapped_tracks:
-                self.debug("track.stream:%s", track.stream)
-                if track.stream.isCompatible(stream):
-                    return track
-                else:
-                    self.debug("Stream not compatible")
-            else:
-                self.debug("Track already present in mapped_tracks")
-
-        return None
+        # track.stream -> track
+        track_stream_to_track_map = dict((track.stream, track)
+                for track in self.tracks)
+
+        # output_stream -> track.stream
+        output_stream_to_track_stream_map = \
+                match_stream_groups_map(factory.output_streams,
+                        [track.stream for track in self.tracks])
+
+        # output_stream -> track (result)
+        output_stream_to_track_map = {}
+        for stream, track_stream in output_stream_to_track_stream_map.iteritems():
+            output_stream_to_track_map[stream] = \
+                    track_stream_to_track_map[track_stream]
+
+        return output_stream_to_track_map
 
     def setSelectionToObj(self, obj, mode):
         """
diff --git a/tests/test_timeline.py b/tests/test_timeline.py
index e11510c..2b7bbae 100644
--- a/tests/test_timeline.py
+++ b/tests/test_timeline.py
@@ -586,10 +586,11 @@ class TestTimelineAddFactory(TestCase):
         self.audio_stream2 = AudioStream(gst.Caps('audio/x-raw-int'))
         self.audio_stream3 = AudioStream(gst.Caps('audio/x-raw-int'))
         self.video_stream1 = VideoStream(gst.Caps('video/x-raw-rgb'))
+        self.video_stream2 = VideoStream(gst.Caps('video/x-raw-rgb'))
         self.audio_track1 = Track(self.audio_stream1)
-        self.audio_track2 = Track(self.audio_stream1)
+        self.audio_track2 = Track(self.audio_stream2)
         self.video_track1 = Track(self.video_stream1)
-        self.video_track2 = Track(self.video_stream1)
+        self.video_track2 = Track(self.video_stream2)
         self.timeline = Timeline()
         self.timeline.addTrack(self.audio_track1)
         self.timeline.addTrack(self.audio_track2)
@@ -603,6 +604,7 @@ class TestTimelineAddFactory(TestCase):
         del self.audio_stream2
         del self.audio_stream3
         del self.video_stream1
+        del self.video_stream2
         del self.audio_track1
         del self.audio_track2
         del self.video_track1



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