[pitivi] Do linking decisions based on negotiated caps when possible.



commit 237fcec496e2a96805cb817a54738d67c7ad0989
Author: Alessandro Decina <alessandro d gmail com>
Date:   Fri Aug 7 13:35:40 2009 +0200

    Do linking decisions based on negotiated caps when possible.

 pitivi/factories/timeline.py |    8 ++++++++
 pitivi/pipeline.py           |   18 ++++++++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/pitivi/factories/timeline.py b/pitivi/factories/timeline.py
index 405be6e..df7a430 100644
--- a/pitivi/factories/timeline.py
+++ b/pitivi/factories/timeline.py
@@ -132,6 +132,14 @@ class TimelineSourceFactory(SourceFactory):
         seek.set_state(gst.STATE_PLAYING)
         pad.link(seek.get_pad('sink'))
         ghost = gst.GhostPad('src%d' % self.pad_num + str(id(pad)), seek.get_pad('src'))
+
+        # if the target pad has negotiated caps, set them on the ghost as well
+        caps = pad.props.caps
+        if caps is None:
+            caps = pad.get_caps()
+        if caps.is_fixed():
+            seek.get_pad("sink").set_caps(caps)
+            ghost.set_caps(caps)
         ghost.set_active(True)
         self.ghosts[pad_id] = ghost
         self.seek_checkers[pad_id] = seek
diff --git a/pitivi/pipeline.py b/pitivi/pipeline.py
index b4887e2..07bb9bf 100644
--- a/pitivi/pipeline.py
+++ b/pitivi/pipeline.py
@@ -821,7 +821,21 @@ class Pipeline(Signallable, Loggable):
         return gst.BUS_PASS
 
     def _binPadAddedCb(self, bin, pad):
-        self.debug("bin:%r, pad:%r (%s)", bin, pad, pad.get_caps().to_string())
+        # Our (semi)automatic linking logic is based on caps.
+        # gst_pad_get_caps returns all the caps a pad can handle, not
+        # necessarily those set with gst_pad_set_caps.
+        # Some of our utility elements (like ImageFreeze and FixSeekStart) have
+        # template caps ANY but they do caps negotiation (call gst_pad_set_caps)
+        # asap, before pushing anything. Therefore we try to get the negotiated
+        # caps first here, and fallback on the template caps.
+        caps = pad.props.caps
+        if caps is None:
+            caps = pad.get_caps()
+
+        if caps.is_any():
+            self.error("got ANY caps, this should never happen")
+
+        self.debug("bin:%r, pad:%r (%s)", bin, pad, caps.to_string())
         self._lock.acquire()
 
         try:
@@ -840,7 +854,7 @@ class Pipeline(Signallable, Loggable):
             if factory is None:
                 raise PipelineError("New pad on an element we don't control ??")
 
-            stream = get_stream_for_caps(pad.get_caps(), pad)
+            stream = get_stream_for_caps(caps, pad)
             if stream not in factory_entry.streams:
                 factory_entry.streams[stream] = StreamEntry(factory_entry,
                         stream, parent=stream_entry)



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