mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-14 11:25:39 +00:00
examples: Port the sink example to GstBaseSink
Also we now need to explicitly call Gst.init() from python bindings.
This commit is contained in:
parent
1f26b4ad2b
commit
7dffdb6864
1 changed files with 13 additions and 26 deletions
|
@ -11,42 +11,29 @@
|
||||||
# in 20 lines in python and place into the gstreamer registry
|
# in 20 lines in python and place into the gstreamer registry
|
||||||
# so it can be autoplugged or used from parse_launch.
|
# so it can be autoplugged or used from parse_launch.
|
||||||
#
|
#
|
||||||
# Run this script with GST_DEBUG=python:5 to see the debug
|
# You can run the example from the source doing from gst-python/:
|
||||||
# messages
|
#
|
||||||
|
# $ export GST_PLUGIN_PATH=$GST_PLUGIN_PATH:$PWD/plugin:$PWD/examples/plugins
|
||||||
|
# $ GST_DEBUG=python:4 gst-launch-1.0 fakesrc num-buffers=10 ! mysink
|
||||||
|
|
||||||
from gi.repository import Gst, GObject
|
from gi.repository import Gst, GObject, GstBase
|
||||||
|
Gst.init(None)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Simple Sink element created entirely in python
|
# Simple Sink element created entirely in python
|
||||||
#
|
#
|
||||||
class MySink(Gst.Element):
|
class MySink(GstBase.BaseSink):
|
||||||
__gstmetadata__ = ('CustomSink','Sink', \
|
__gstmetadata__ = ('CustomSink','Sink', \
|
||||||
'Custom test sink element', 'Edward Hervey')
|
'Custom test sink element', 'Edward Hervey')
|
||||||
|
|
||||||
__gsttemplates__ = Gst.PadTemplate.new ("sinkpadtemplate",
|
__gsttemplates__ = Gst.PadTemplate.new("sink",
|
||||||
Gst.PadDirection.SINK,
|
Gst.PadDirection.SINK,
|
||||||
Gst.PadPresence.ALWAYS,
|
Gst.PadPresence.ALWAYS,
|
||||||
Gst.Caps.new_any())
|
Gst.Caps.new_any())
|
||||||
|
|
||||||
def __init__(self):
|
def do_render(self, buffer):
|
||||||
Gst.Element.__init__(self)
|
Gst.info("timestamp(buffer):%s" % (Gst.TIME_ARGS(buffer.pts)))
|
||||||
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
|
return Gst.FlowReturn.OK
|
||||||
|
|
||||||
def eventfunc(self, pad, event):
|
|
||||||
Gst.info("%s event:%r" % (pad, event.type))
|
|
||||||
return True
|
|
||||||
|
|
||||||
GObject.type_register(MySink)
|
GObject.type_register(MySink)
|
||||||
__gstelementfactory__ = ("mysink", Gst.Rank.NONE, MySink)
|
__gstelementfactory__ = ("mysink", Gst.Rank.NONE, MySink)
|
||||||
|
|
Loading…
Reference in a new issue