<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <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
            class="nf">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 class="nf">gst_app_sink_try_pull_sample</span></code></b>
      when <code><span class="n"><b>gst_sample_set_buffer </b>is
          invoked or on </span></code><b><code><span class="n"><code><span
                class="nf">gst_app_sink_dispose </span></code></span></code></b>which
      is too late<br>
    </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>
    <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>
  </body>
</html>