summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Saunier <tsaunier@gnome.org>2014-06-06 10:30:07 +0200
committerThibault Saunier <tsaunier@gnome.org>2014-06-06 10:35:09 +0200
commited1c9866a22a2a9ac451ec2b55a61f72d1ac5818 (patch)
treec22c6ae4358875fef0571f75f55512d2b73ecd09
parent367d281ab6f2bcc0727aab0661d7075be4c09c11 (diff)
Add an example sink element and override the chain and event functions of pads
Otherwize we will get 2 time acces to the element in it, which does not make much sense. The _full variant can still be used.
-rw-r--r--examples/python/sinkelement.py52
-rw-r--r--gi/overrides/Gst.py18
2 files changed, 70 insertions, 0 deletions
diff --git a/examples/python/sinkelement.py b/examples/python/sinkelement.py
new file mode 100644
index 0000000..639d9b8
--- /dev/null
+++ b/examples/python/sinkelement.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+# -*- Mode: Python -*-
+# vi:si:et:sw=4:sts=4:ts=4
+
+# sinkelement.py
+# (c) 2005 Edward Hervey <edward@fluendo.com>
+# (c) 2007 Jan Schmidt <jan@fluendo.com>
+# Licensed under LGPL
+#
+# Small test application to show how to write a sink element
+# in 20 lines in python and place into the gstreamer registry
+# so it can be autoplugged or used from parse_launch.
+#
+# Run this script with GST_DEBUG=python:5 to see the debug
+# messages
+
+from gi.repository import Gst, GObject
+
+#
+# Simple Sink element created entirely in python
+#
+class MySink(Gst.Element):
+ __gstmetadata__ = ('CustomSink','Sink', \
+ 'Custom test sink element', 'Edward Hervey')
+
+ __gsttemplates__ = Gst.PadTemplate.new ("sinkpadtemplate",
+ Gst.PadDirection.SINK,
+ Gst.PadPresence.ALWAYS,
+ Gst.Caps.new_any())
+
+ def __init__(self):
+ Gst.Element.__init__(self)
+ Gst.info('creating sinkpad')
+ self.sinkpad = Gst.Pad.new_from_template(self.__gsttemplates__, "sink")
+ Gst.info('adding sinkpad to self')
+ self.add_pad(self.sinkpad)
+
+ Gst.info('setting chain/event functions')
+ self.sinkpad.set_chain_function(self.chainfunc)
+ self.sinkpad.set_event_function(self.eventfunc)
+ st = Gst.Structure.from_string("yes,fps=1/2")[0]
+
+ def chainfunc(self, pad, buffer):
+ Gst.info("%s timestamp(buffer):%d" % (pad, buffer.pts))
+ return Gst.FlowReturn.OK
+
+ def eventfunc(self, pad, event):
+ Gst.info("%s event:%r" % (pad, event.type))
+ return True
+
+GObject.type_register(MySink)
+__gstelementfactory__ = ("mysink", Gst.Rank.NONE, MySink)
diff --git a/gi/overrides/Gst.py b/gi/overrides/Gst.py
index c2fa37f..a181673 100644
--- a/gi/overrides/Gst.py
+++ b/gi/overrides/Gst.py
@@ -96,6 +96,24 @@ Caps = override(Caps)
__all__.append('Caps')
class Pad(Gst.Pad):
+ def __init__(self):
+ self._real_chain_func = None
+ self._real_event_func = None
+
+ def _chain_override(self, pad, parent, buf):
+ return self._real_chain_func(pad, buf)
+
+ def _event_override(self, pad, parent, buf):
+ return self._real_event_func(pad, buf)
+
+ def set_chain_function(self, func):
+ self._real_chain_func = func
+ self.set_chain_function_full(self._chain_override, None)
+
+ def set_event_function(self, func):
+ self._real_event_func = func
+ self.set_event_function_full(self._event_override, None)
+
def query_caps(self, filter=None):
return Gst.Pad.query_caps(self, filter)