<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le sam. 3 oct. 2020 09 h 45, Christophe Lafolet <<a href="mailto:christophe.lafolet@laposte.net">christophe.lafolet@laposte.net</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  

    
  
  <div>
    <p><br>
    </p>
    <p>Hello</p>
    <p>I have a Java application that implement a pipeline like
      following :<br>
    </p>
    <p>gst-launch-1.0 v4l2src <b>io-mode=2</b> device=/dev/video0 !
      appsink max-buffers=1 drop=true <br>
    </p>
    <p>with "emit-signals=true" and callbacks set.</p>
    <p><br>
    </p>
    <p>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</p>
    <p><br>
    </p>
    <p>All works fine for the first start but if I stop and restart
      immediatly the pipeline with another device, an error <b>"device
        or resource busy"</b> can be detected for the second start or
      later</p>
    <p>I have found several posts on Internet with the same problem :</p>
    <p>- bug of the driver ? No because I have the same problem with USB
      camera or capture card BT878</p>
    <p><br>
    </p>
    <p>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<br>
    </p>
    <p>I have tested 3 versions of GStreamer : <br>
    </p>
    <p>- Gstreamer 1.16 and 1.18 : KO</p>
    <p>- Gstreamer 1.10 : OK<br>
    </p>
    <p><br>
    </p>
    <p>The problem seems to be in AppSink : <br>
    </p>
    <p>- before GStreamer 1.16, a new Sample was allocated for each <b><code><span>gst_app_sink_try_pull_sample</span></code></b> :
      when the user "unref" the sample -> the buffer is "unref" and
      returned in pool<br>
    </p>
    <p>- after version 1.1??, the sample is recycled : the buffer is
      "unref" only on the next <b><code><span>gst_app_sink_try_pull_sample</span></code></b>
      when <code><span><b>gst_sample_set_buffer </b>is
          invoked or on </span></code><b><code><span><code><span>gst_app_sink_dispose </span></code></span></code></b>which
      is too late<br></p></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">That does not look like a great behaviour to me. The GstSample should be reset to prevent holding on a buffer. Do a search in the issues on gitlab, since I believe similar (but less accurate) reports exist.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><p>
    </p>
    <p>On stop, when v4l2src change state from PAUSED to READY , the
      device is closed but a buffer is still referenced by the last
      sample <br>
    </p>
    <p><br>
    </p>
    <p>Is this correct ?</p></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Correct, that being said, this won't be an issue with newer kernel (and io-mode=dmabuf , the default). We have added orphaning support, which let us detach allocated buffers immediately without closing the fd to /dev/videoX.</div><div dir="auto"><br></div><div dir="auto">This kernel behaviour was also interfering with the ability to keep displaying the last buffer (enable-last-sample) past EOS on video sink.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
    <p>Thanks for your help <br>
    </p>
    <p>Christophe<br>
    </p>
    <p><br>
    </p>
    <p><br>
    </p>
    <p><br>
    </p>
    <p><br>
    </p>
    <p><br>
    </p>
    <p><br>
    </p>
    <p><br>
    </p>
  </div>

_______________________________________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank" rel="noreferrer">gstreamer-devel@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" rel="noreferrer noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel</a><br>
</blockquote></div></div></div>