[pitivi: 11/14] pipeline: use match_stream in getTeeForFactoryStream. Fixes #630015.



commit 3164ed18bc8200c7c35aecf207236b9bc2437129
Author: Alessandro Decina <alessandro d gmail com>
Date:   Wed Sep 29 16:21:48 2010 +0200

    pipeline: use match_stream in getTeeForFactoryStream. Fixes #630015.

 pitivi/pipeline.py |   26 +++++++++++++++++++-------
 pitivi/stream.py   |    6 ++++--
 2 files changed, 23 insertions(+), 9 deletions(-)
---
diff --git a/pitivi/pipeline.py b/pitivi/pipeline.py
index 9770986..aa80bdb 100644
--- a/pitivi/pipeline.py
+++ b/pitivi/pipeline.py
@@ -27,7 +27,8 @@ from pitivi.signalinterface import Signallable
 from pitivi.factories.base import SourceFactory, SinkFactory
 from pitivi.action import ActionError
 from pitivi.stream import get_src_pads_for_stream, \
-     get_sink_pads_for_stream, get_stream_for_caps
+     get_sink_pads_for_stream, get_stream_for_caps, \
+     match_stream, get_stream_for_pad
 from pitivi.log.loggable import Loggable
 import gobject
 import gst
@@ -619,7 +620,7 @@ class Pipeline(Signallable, Loggable):
         stream_entry = self._getStreamEntryForFactoryStream(factory, stream)
         bin_stream_entry = stream_entry.findBinEntry()
         if bin_stream_entry is None:
-            raise PipelineError()
+            raise PipelineError("couldn't find bin entry")
 
         bin = bin_stream_entry.bin
 
@@ -629,14 +630,25 @@ class Pipeline(Signallable, Loggable):
             return stream_entry.tee
 
         if not automake:
-            raise PipelineError()
+            raise PipelineError("no automake")
 
         self.debug("Really creating a tee")
-        pads = get_src_pads_for_stream(bin, stream)
-        if not pads or len(pads) > 1:
-            raise PipelineError("Can't figure out which source pad to use !")
+        # get the source pads
+        pads = get_src_pads_for_stream(bin, None)
+        # get the corresponding streams
+        streams = [get_stream_for_pad(pad, store_pad=True) for pad in pads]
+        # find the pad that matches the given stream best
+        if stream is None:
+            if len(streams) == 1:
+                stream = streams[0]
+            else:
+                raise PipelineError("bin has multiple compatible pads")
+
+        stream, rank = match_stream(stream, streams)
+        if stream is None:
+            raise PipelineError("bin has no compatible source pads")
 
-        srcpad = pads[0]
+        srcpad = stream.pad
         self.debug("Using pad %r", srcpad)
 
         stream_entry.tee = gst.element_factory_make("tee")
diff --git a/pitivi/stream.py b/pitivi/stream.py
index 683c1ff..6ced245 100644
--- a/pitivi/stream.py
+++ b/pitivi/stream.py
@@ -352,7 +352,7 @@ def get_stream_for_caps(caps, pad=None):
         ret = TextStream(caps, pad_name)
     return ret
 
-def get_stream_for_pad(pad):
+def get_stream_for_pad(pad, store_pad=False):
     log.debug("stream", "pad:%r")
     caps = pad.props.caps
     if caps is None:
@@ -360,6 +360,8 @@ def get_stream_for_pad(pad):
     pad_id = get_pad_id(pad)
     stream = get_stream_for_caps(caps, pad)
     stream.pad_id = pad_id
+    if store_pad:
+        stream.pad = pad
 
     return stream
 
@@ -400,7 +402,7 @@ def get_pads_for_stream(element, stream):
         try:
             ls = [x for x in element.pads() if pad_compatible_stream(x, stream)]
             break
-        except:
+        except TypeError:
             continue
     # FIXME : I'm not 100% certain that checking against the stream pad_name
     # is a good idea ....



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