How to flush inside pushsrc based element?

Carlos Rafael Giani crg7475 at mailbox.org
Sat Oct 31 09:14:02 UTC 2020


I have a GstPushSrc based element that receives data over an IPC 
protocol. Said protocol is made of an in-band and an out-of-band 
channel. In-band carries the actual media data and format information, 
out-of-band transmits notifications. One of these notifications is the 
flush command.

The flush command instructs the receiver to flush any data it currently 
has. It is used when the sender just loaded new media for example. There 
are some minor additional details to that, but the relevant part is that 
as soon as the out-of-band flush command is received, this is done in an 
onFlush() callback:

gst_element_send_event(GST_ELEMENT(src), gst_event_new_flush_start());
gst_element_send_event(GST_ELEMENT(src), gst_event_new_flush_stop(TRUE));

Note that data is received by a background thread. Said thread will call 
the onFlush callback.

In parallel, there is a receiveInBandMessage() that blocks until a 
message is received (done in the same background thread mentioned 
above), the receive operation is canceled, or an error occurs. This 
function is called inside create().

The problems occur when receiveInBandMessage() blocks in create() and at 
the same time onFlush() is called. create() holds basesrc's live lock, 
but so does the gst_base_src_send_event() function when handling 
FLUSH_STOP. A deadlock results.

To my surprise, I did not find any basesrc/pushsrc based element that 
receives flush commands from somewhere or gets them in some other way. 
So, there is no existing example on how to initiate flushing from within 
a basesrc, especially if said flushing is initiated from a separate 
thread (due to an async notification mechanism). So now I wonder how 
this should be done properly.

Does it even make sense to have basesrc set itself to flushing here? 
Because if not, then perhaps just pushing the flush events directly out 
of the srcpad (circumventing the flush logic in gst_base_src_send_event) 
would work. In other words, the gst_element_send_event() calls would be 
replaced by gst_pad_push_event().

Thoughts?



More information about the gstreamer-devel mailing list