summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Ospite <ao2@ao2.it>2019-01-09 11:39:19 +0100
committerAntonio Ospite <ao2@ao2.it>2019-01-09 12:32:37 +0100
commit1cece5bde5a1cdefd06ae9fd21bc95e29d99ac85 (patch)
treeb95283dcb935010568a5ab028044576dcfb13290
parenta37b7c7a13288f84b21dbfe0ac95a0db9d574bc1 (diff)
overrides: add a set_caps() method to the Pad override
The C API provides the gst_pad_set_caps() helper which makes it easier to set caps on pads (see gst/gstcompat.h in gstreamer core). Add such handy helper to the python bindings too. The implementation follows as close as possible the one in gstcompat.h with two changes: 1. the type check on the pad has been removed because self is guaranteed to be a Gst.Pad in python. 2. the null check on the caps has been extended to be a type check. Fixes https://gitlab.freedesktop.org/gstreamer/gst-python/issues/19
-rw-r--r--gi/overrides/Gst.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/gi/overrides/Gst.py b/gi/overrides/Gst.py
index 2e5189b..499e82f 100644
--- a/gi/overrides/Gst.py
+++ b/gi/overrides/Gst.py
@@ -156,6 +156,22 @@ class Pad(Gst.Pad):
def query_caps(self, filter=None):
return Gst.Pad.query_caps(self, filter)
+ def set_caps(self, caps):
+ if not isinstance(caps, Gst.Caps):
+ raise TypeError("%s is not a Gst.Caps." % (type(caps)))
+
+ if not caps.is_fixed():
+ return False
+
+ event = Gst.Event.new_caps(caps)
+
+ if self.direction == Gst.PadDirection.SRC:
+ res = self.push_event(event)
+ else:
+ res = self.send_event(event)
+
+ return res
+
def link(self, pad):
ret = Gst.Pad.link(self, pad)
if ret != Gst.PadLinkReturn.OK: