3 # vi:si:et:sw=4:sts=4:ts=4
6 # (c) 2005 Edward Hervey <edward@fluendo.com>
7 # (c) 2007 Jan Schmidt <jan@fluendo.com>
10 # Small test application to show how to write a sink element
11 # in 20 lines in python and place into the gstreamer registry
12 # so it can be autoplugged or used from parse_launch.
14 # Run this script with GST_DEBUG=python:5 to see the debug
21 gobject.threads_init ()
24 # Simple Sink element created entirely in python
27 class MySink(gst.Element):
28 __gstdetails__ = ('CustomSink','Sink', \
29 'Custom test sink element', 'Edward Hervey')
31 _sinkpadtemplate = gst.PadTemplate ("sinkpadtemplate",
37 gst.Element.__init__(self)
38 gst.info('creating sinkpad')
39 self.sinkpad = gst.Pad(self._sinkpadtemplate, "sink")
40 gst.info('adding sinkpad to self')
41 self.add_pad(self.sinkpad)
43 gst.info('setting chain/event functions')
44 self.sinkpad.set_chain_function(self.chainfunc)
45 self.sinkpad.set_event_function(self.eventfunc)
47 def chainfunc(self, pad, buffer):
48 self.info("%s timestamp(buffer):%d" % (pad, buffer.timestamp))
51 def eventfunc(self, pad, event):
52 self.info("%s event:%r" % (pad, event.type))
55 gobject.type_register(MySink)
57 # Register the element into this process' registry.
58 gst.element_register (MySink, 'mysink', gst.RANK_MARGINAL)
60 print "Use --gst-debug=python:3 to see output from this example"
63 # Code to test the MySink class
65 gst.info('About to create MySink')
66 pipeline = gst.parse_launch ("fakesrc ! mysink")
67 pipeline.set_state(gst.STATE_PLAYING)
69 gobject.MainLoop().run()