Merging gst-build
[platform/upstream/gstreamer.git] / subprojects / gst-python / old_examples / sinkelement-registry.py
1 #!/usr/bin/env python
2 # -*- Mode: Python -*-
3 # vi:si:et:sw=4:sts=4:ts=4
4
5 # sinkelement.py
6 # (c) 2005 Edward Hervey <edward@fluendo.com>
7 # (c) 2007 Jan Schmidt <jan@fluendo.com>
8 # Licensed under LGPL
9 #
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.
13 #
14 # Run this script with GST_DEBUG=python:5 to see the debug
15 # messages
16
17 import pygst
18 pygst.require('0.10')
19 import gst
20 import gobject
21 gobject.threads_init ()
22
23 #
24 # Simple Sink element created entirely in python
25 #
26
27 class MySink(gst.Element):
28     __gstdetails__ = ('CustomSink','Sink', \
29                       'Custom test sink element', 'Edward Hervey')
30
31     _sinkpadtemplate = gst.PadTemplate ("sinkpadtemplate",
32                                         gst.PAD_SINK,
33                                         gst.PAD_ALWAYS,
34                                         gst.caps_new_any())
35
36     def __init__(self):
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)
42
43         gst.info('setting chain/event functions')
44         self.sinkpad.set_chain_function(self.chainfunc)
45         self.sinkpad.set_event_function(self.eventfunc)
46         
47     def chainfunc(self, pad, buffer):
48         self.info("%s timestamp(buffer):%d" % (pad, buffer.timestamp))
49         return gst.FLOW_OK
50
51     def eventfunc(self, pad, event):
52         self.info("%s event:%r" % (pad, event.type))
53         return True
54
55 gobject.type_register(MySink)
56
57 # Register the element into this process' registry.
58 gst.element_register (MySink, 'mysink', gst.RANK_MARGINAL)
59
60 print "Use --gst-debug=python:3 to see output from this example"
61
62 #
63 # Code to test the MySink class
64 #
65 gst.info('About to create MySink')
66 pipeline = gst.parse_launch ("fakesrc ! mysink")
67 pipeline.set_state(gst.STATE_PLAYING)
68
69 gobject.MainLoop().run()