The correct way to restart gstreamer`s pipeline with v4l2src

Christophe Lafolet christophe.lafolet at laposte.net
Sat Oct 3 10:33:31 UTC 2020


Hello

I have a Java application that implement a pipeline like following :

gst-launch-1.0 v4l2src *io-mode=2* device=/dev/video0 ! appsink 
max-buffers=1 drop=true

with "emit-signals=true" and callbacks set.


I stop with pipeline by sending an EOS message to the pipeline to stop 
and consume all buffers, wait EOS on bus and set pipeline to NULL


All works fine for the first start but if I stop and restart immediatly 
the pipeline with another device, an error *"device or resource busy"* 
can be detected for the second start or later

I have found several posts on Internet with the same problem :

- bug of the driver ? No because I have the same problem with USB camera 
or capture card BT878


I have activated log in Gstreamer and detected that when v4l2bufferpool 
is stopping, only buffers in pool are released : for the 4 MMAP buffers 
allocated, only 3 are released on stop

I have tested 3 versions of GStreamer :

- Gstreamer 1.16 and 1.18 : KO

- Gstreamer 1.10 : OK


The problem seems to be in AppSink :

- before GStreamer 1.16, a new Sample was allocated for each 
*|gst_app_sink_try_pull_sample|* : when the user "unref" the sample -> 
the buffer is "unref" and returned in pool

- after version 1.1??, the sample is recycled : the buffer is "unref" 
only on the next *|gst_app_sink_try_pull_sample|* when 
|*gst_sample_set_buffer *is invoked or on |*||gst_app_sink_dispose 
||*which is too late

On stop, when v4l2src change state from PAUSED to READY , the device is 
closed but a buffer is still referenced by the last sample


Is this correct ?

Thanks for your help

Christophe








-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20201003/f78c4dbd/attachment.htm>


More information about the gstreamer-devel mailing list