python: Add a Gst.init_python function to be called from plugins
[platform/upstream/gstreamer.git] / subprojects / gst-python / examples / plugins / python / identity.py
1 #!/usr/bin/env python
2 # -*- Mode: Python -*-
3 # vi:si:et:sw=4:sts=4:ts=4
4
5 # identity.py
6 # 2016 Marianna S. Buschle <msb@qtec.com>
7 #
8 # Simple identity element in python
9 #
10 # You can run the example from the source doing from gst-python/:
11 #
12 #  $ export GST_PLUGIN_PATH=$GST_PLUGIN_PATH:$PWD/plugin:$PWD/examples/plugins
13 #  $ GST_DEBUG=python:4 gst-launch-1.0 fakesrc num-buffers=10 ! identity_py ! fakesink
14
15 import gi
16 gi.require_version('GstBase', '1.0')
17
18 from gi.repository import Gst, GObject, GstBase
19 Gst.init_python()
20
21 #
22 # Simple Identity element created entirely in python
23 #
24 class Identity(GstBase.BaseTransform):
25     __gstmetadata__ = ('Identity Python','Transform', \
26                       'Simple identity element written in python', 'Marianna S. Buschle')
27
28     __gsttemplates__ = (Gst.PadTemplate.new("src",
29                                            Gst.PadDirection.SRC,
30                                            Gst.PadPresence.ALWAYS,
31                                            Gst.Caps.new_any()),
32                        Gst.PadTemplate.new("sink",
33                                            Gst.PadDirection.SINK,
34                                            Gst.PadPresence.ALWAYS,
35                                            Gst.Caps.new_any()))
36
37     def do_transform_ip(self, buffer):
38         Gst.info("timestamp(buffer):%s" % (Gst.TIME_ARGS(buffer.pts)))
39         return Gst.FlowReturn.OK
40
41 GObject.type_register(Identity)
42 __gstelementfactory__ = ("identity_py", Gst.Rank.NONE, Identity)