In our example, we want to multiplex several MPEG-TS streams. What usually happens is that some streams use the same PID, thus creating the need to remap some of them.
What you can do is implement all this functionality in the Multiplexer or have another element do it. If you do it in two plugins the question on how to communicate the different elements comes up.
We tried to make the application control the elements in the pipeline by the use of properties and signals posted by the elements.
So, when a MPEGTS stream comes in, the remapper sends a message to the app using the pipeline's bus, telling it what PIDs it is using.
The application keeps track of the PIDs of all other streams and can modify the properties to remap some of the colliding PIDs.
So to post a message to the application's bus you simply have to do the following:
GstBus *bus = GST_ELEMENT_BUS(self);
GstStructure *structure=gst_structure_new("mpegmodderevent", "type", G_TYPE_STRING, event_name, "pid_summary", G_TYPE_VALUE_ARRAY, self->input_pids_by_program, NULL);
GstMessage *msg=gst_message_new_custom(GST_MESSAGE_ELEMENT, GST_OBJECT(self), structure);
gst_bus_post(bus, msg);
A GstMessage simply contains a a structure with the contents - add anything you want - we send an identifier for the event and a GValueArray containing GstStructures (program number and list of PIDs) which maps pretty well to python, too.
If you want to read these messages in a python app, you just have to do the following:
def process_signal(bus, message, user_data):
if message.structure!=None and message.structure.get_name()=='mpegmodderevent' and message.structure['type']=='PMT':
print "Signal received: ", message.structure.get_name(), message.structure['type'], message.structure['pid_summary']
return True
pipe=gst.parse_launch(...)
bus=pipe.get_bus()
bus.add_watch(process_signal, None)
#Important to use GMainLoop to process signals
try:
loop=gobject.MainLoop()
loop.run()
except:
pass
Now you can have a pretty "dumb" element that sends signals, and an application (you can use python for that), that does some of the more difficult logic...
Note: gst-launch also prints out messages with -m option!
No comments:
Post a Comment