Search code examples
gstreamerpython-gstreamer

Assuring EOS in gstreamer sink elements


BLUF: I need to know when a sink element has finished handling an EOS signal.

I have a dynamic pipeline where video data streams to a tee connector, which fans out the video to different files. The parts I attach to the tee can be created at any time, and also stopped at any time. In the ordinary course of events, when I am done with a particular branch of the tee, I would like to stop data flow into the branch, send an EOS into it, and once all the data on that branch has been processed, disconnect all those parts from the tee, set element states to NULL, and do other garbage-collection tasks.

Documentation gives an example of hot-swapping elements in a running pipeline; in particular, step 4 describes how to assure yourself that the element you're swapping has finished processing all data:

4a) pad event probe on element2 src

4b) send EOS to element2, this makes sure that element2 flushes out the last bits of data it holds.

4c) wait for EOS to appear in the probe, drop the EOS

A sink element has no src pad that I can attach to and wait for an EOS to signal completion.

How do I determine when the sink is finished?


Solution

  • If you set message-forward=true in the pipeline the sink will post a message to the bus when it receives and processes the EOS. This will be wrapped in a GST_MESSAGE_ELEMENT and not a GST_MESSAGE_EOS, since the later would only be posted if all the sinks receive an EOS.

    Here are the docs:

    https://gstreamer.freedesktop.org/documentation/gstreamer/gstbin.html?gi-language=c#GstBin:message-forward

    The relevant part:

    message-forward 
    
    “message-forward” gboolean
    Forward all children messages, even those that would normally be filtered by the bin. This can be interesting when one wants to be notified of the EOS state of individual elements, for example.
    
    The messages are converted to an ELEMENT message with the bin as the source. The structure of the message is named GstBinForwarded and contains a field named message that contains the original forwarded GstMessage.