Return a buffer from an otherpool has unwanted side effects that lead to leaks and
prevents deactivating the pool. Instead, we change the _process() API so it can
replace the internal buffer with the buffer from the downstream pool. This implied
moving from _fill() to _create() method in the src.
Buffer refcounting is a bit hard, because of the duality between CAPTURE and
OUTPUT mode. In the long term, we should consider having two seperate pool
instead of this mess. At least state should be better kept this way.
Pre-configuring the pool is error prone, since it may hide a configuration failure and
endup with a pool that is not configured the way it should (e.g. no video meta, wrong
queue size, etc.)
In order to correctly set the pool min/max, we need to probe for CREATE_BUFS
ioctl. This can be done as soon as the format has been negotiated using a
count of 0.
Now that we might be copying out buffer (e.g. downstream don't support video
meta bug we need it) we need to move the EOS handling inside the process
method.
In certain cases we cannot live without video meta and/or crop meta
being enabled in our internal buffer pool. Ensure this is always the case,
regardless of having support for allocation query.
Buffer pool was guessing wrongly the number of planes rather
then reading the value from obj->n_v4l2_planes. This was causing
format YU12 (I420) to fail upon check.
With years the amount of ifdef have grown up and we are not even sure if the
old code path compiles. Each time we need to update the v4l2 framework to add
the new feature, we break compilation on older kernel. With exception of two
controls in the video orientation control, this patch get rid of all ifdef by
including the latest version of videodev2.h inside GStreamer.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=723446
We correctly indicate the field ordering on interlaced buffers, but fail to
flag them as containing interlaced video, which we need to do here because
we signal interlace-mode=mixed in our caps. This means that downstream
elements (like vaapipostproc from gstreamer-vaapi) don't recognise these
buffers as in need of deinterlacing.
Fix this by setting the interlaced flag on all interlaced buffers.
Signed-off-by: Simon Farnsworth <simon.farnsworth@onelan.co.uk>
https://bugzilla.gnome.org/show_bug.cgi?id=724899
STREAMOFF set all v4l2buffers to DEQUEUE state.
Then for CAPTURE we call QBUF on each buffer.
For OUTPUT the buffers are just push back in the GstBufferPool
base class 's queue.
But the loop actually looks like the same.
https://bugzilla.gnome.org/show_bug.cgi?id=720568
so that the buffer informations can be retrieved the same way
in both MPLANE and non-MPLANE mode.
Here "emulating" means "manually fill in the plane".
Fixes bug https://bugzilla.gnome.org/show_bug.cgi?id=712754
This api is in linux kernel since version 2.6.39,
and present in all version 3.
The commit that adds the API in master branch of the
linux kernel source is:
f8f3914cf9
v4l2 doc: "Some devices require data for each input
or output video frame to be placed in discontiguous
memory buffers"
There are newer structures 'struct v4l2_pix_format_mplane'
and 'struct v4l2_plane'.
So the pixel format is not setup with the same API when using
multi-planar.
Also for gst-v4l2, one of the difference is that in GstV4l2Meta
there are now one mem pointer for each maped plane.
When not using multi-planar, this commit takes care of keeping
the same code path than previously. So that the 2 cases are
in two different blocks triggered from V4L2_TYPE_IS_MULTIPLANAR.
Fixes bug https://bugzilla.gnome.org/show_bug.cgi?id=712754
On some systems (E.G. uClibc and older Glibc versions), O_CLOEXEC is only
defined when _GNU_SOURCE is specified, so do so.
_GNU_SOURCE needs to be defined before any system headers are included,
so move the fcntl.h section up.
https://bugzilla.gnome.org/show_bug.cgi?id=709423
If the pool is stopped while gst_v4l2_buffer_pool_dqbuf() waits for a
buffer then the return value is GST_FLOW_FLUSHING. In this case the buffer
to queue must also be released. Otherwise is will never be deleted or
returned to its pool.
https://bugzilla.gnome.org/show_bug.cgi?id=703764
The pool accesses data from the v4l2object so it must exist at least
as long as the pool. Refcount the element which controls the object
live-time.
https://bugzilla.gnome.org/show_bug.cgi?id=701650
Without this the following sequence fails:
- set_caps()
- object_stop() (does nothing)
- set_format() -> VIDIOC_S_FMT
- set_config() -> VIDIOC_REQBUFS with count = N
- set_caps()
- object_stop()
- pool_finalize()
- set_format() -> VIDIOC_S_FMT => EBUSY
Usually the pool is started after set_config(), in which case object_stop()
will result in a pool_stop and therefore VIDIOC_REQBUFS with count = 0 but
that is not guaranteed.
Also calling VIDIOC_REQBUFS with count = 0 in pool_finalize() if necessary
fixes this problem.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=701543
This is a followup patch for #700781, which is not quite correct.
The buffer handling is quite complicated here.
The original code intended to the the following:
- gst_v4l2_buffer_pool_process() calls QBUF and adds the buffer to the
local list.
- The sink calls gst_buffer_unref() which returns the buffer to the pool
but not the 'free list'.
- Some time later DQBUF returns the buffer and
gst_v4l2_buffer_pool_release_buffer() puts in on the 'free list'.
If the buffer must be copied then (parent_class)->acquire_buffer() is
called directly to keep the buffer in the pool.
This has two problems:
1. If gst_v4l2_buffer_pool_release_buffer() is called before the buffer is
returned to the pool, then the buffer is put on the 'free list' twice.
This can happen if a reference to the buffer is kept outside the sink,
of if DQBUF returns the buffer, that was just queued with QBUF.
2. If buffers are copied, then all buffers are in the pool at all times. As
a result gst_v4l2_buffer_pool_stop() and gst_v4l2_buffer_pool_dqbuf()
can access pool->buffers at the same time, which can lead to memory
corruption.
The patch for #700781 fixes those problems, but with the side effect that
there are always buffers outside the pool (because they are queued) and
the pool is never stopped.
This patch fixes this by releasing the reference to the buffer after
handling it (to avoid problem 2.) so it can be returned to the pool.
gst_v4l2_buffer_pool_release_buffer() is only called if the buffer is
already in the pool (to avoid problem 1.).
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=701375