Gst.Event is a control message that travels through the pipeline pads.
Buffers carry media data; events carry pipeline control information such as
EOS, CAPS, SEGMENT, FLUSH_START, or application-defined commands.
The main idea is direction:
Event direction
Flow
Common use
Downstream
source to sink
caps, segment, eos, custom app command
Upstream
sink to source
seek, navigation, latency query result path
In a Python plugin, a simple way to listen for downstream events is to inherit
from GstBase.BaseTransform and override do_sink_event(). The plugin checks
the event type, reads the attached GstStructure, handles the fields it knows,
then calls the parent implementation so normal GStreamer events still continue
through the element.
Minimal Plugin
This element listens for a custom downstream event named app-control.
importgigi.require_version("Gst","1.0")gi.require_version("GstBase","1.0")fromgi.repositoryimportGst,GstBase,GObjectGst.init(None)classEventListener(GstBase.BaseTransform):__gstmetadata__=("EventListener","Transform","Listen to custom downstream events","example",)__gsttemplates__=(Gst.PadTemplate.new("sink",Gst.PadDirection.SINK,Gst.PadPresence.ALWAYS,Gst.Caps.new_any(),),Gst.PadTemplate.new("src",Gst.PadDirection.SRC,Gst.PadPresence.ALWAYS,Gst.Caps.new_any(),),)defdo_sink_event(self,event):ifevent.type==Gst.EventType.CUSTOM_DOWNSTREAM:structure=event.get_structure()ifstructureandstructure.get_name()=="app-control":print("event:",structure.get_value("command"),structure.get_value("value"),)returnGstBase.BaseTransform.do_sink_event(self,event)defdo_transform_ip(self,buffer):returnGst.FlowReturn.OKGObject.type_register(EventListener)__gstelementfactory__=("eventlistener",Gst.Rank.NONE,EventListener,)
Minimal Application
The application creates a normal pipeline, finds the plugin by name, builds a
custom downstream event, and sends it to the plugin sink pad.
For a quick test, put the plugin file under python/eventlistener.py, then run
the application with GST_PLUGIN_PATH pointing at the directory that contains
that python/ folder: