Commit graph

52 commits

Author SHA1 Message Date
Nicolas Dufresne
f2fa61b6c5 vl42allocator: Don't dup exported dmabufs
We can now use the new GstFAllocator to ask the allocator not to close
the wrapped FD. This way the dup is no longer needed.
2018-10-24 11:55:32 +01:00
Nicolas Dufresne
b25a01fab9 v4l2allocator: Don't dup imported DMABuf FD
There is no specific needs to duplicate the FD. Unlike the exportation,
we don't depend on code that will call close. This will make debugging
easyer since the traced FD will match the exporter.
2018-10-24 11:55:32 +01:00
Nicolas Dufresne
d6d8187345 v4l2allocator: Trace the buffer index we import to
https://bugzilla.gnome.org/show_bug.cgi?id=583890
2018-08-27 13:41:30 -04:00
Nicolas Dufresne
0649b0ab0f v4l2allocator: Fix userptr importation
The length passed to the driver was always 0 instead of the size of
the memory. This would fail validation in videobuf2.
2018-07-13 22:58:35 -04:00
Nicolas Dufresne
57d7ae8496 v4l2allocator: Add support for data_offset
In MPLANE mode, the driver may set data_offset, which represent some
padding at the start of the buffer used internally. This portion of the
data need to be skipped, though it is included in bytesused.

This patch removes frame size sanity check as the method used will no
longer work. This check was simply there to help detect broken kernel
drivers. It would be re-implement by estimating the plane size, which is
not totally trivial and may be too much work for a simple debug check.

https://bugzilla.gnome.org/show_bug.cgi?id=733501
2017-11-03 15:47:11 -04:00
Nicolas Dufresne
5a6fe4ed29 v4l2: Fix compilation without libv4l2 2017-07-24 16:45:40 -04:00
Nicolas Dufresne
2ee90e2b39 v4l2: Keep ref to element in allocator/pool
Removes the FIXME/Question in the buffer pool and add a ref to the
element in the GstAllocator too. This ref is strictly required to keep
the GstV4l2Object structure around.
2017-07-24 16:27:36 -04:00
Nicolas Dufresne
31d8a1d929 v4l2: Add run-time environment to enable libv4l2
The library has started preventing a lot of interesting use cases,
like CREATE_BUFS, DMABuf, usage of TRY_FMT. As the libv4l2 is totally
inactive and not maintained, we decided to disable it. As a convenience
we added a run-time environment that let you enable it for testing.

  GST_V4L2_USE_LIBV4L2=1

This of course only works if you have enabled libv4l2 at build time.
2017-07-24 14:19:02 -04:00
Nicolas Dufresne
bec03858fa v4l2: Merge v4l2_calls.h into gstv4l2object.h
First step of a larger cleanup, all function from v4l2_calls are in fact
methods on GstV4l2Object. This split makes the code really confusing.
This also remove no longer unused macros.
2017-07-17 20:48:28 -04:00
Matt Fischer
e8a4678738 v4l2allocator: Fix memory leak with dmabuf
This patch fixes a memory leak that is caused if the dmabuf file
descriptor dup fails.  Previously, _cleanup_failed_alloc() would
not unref the memory because mems_allocated had not yet been
incremented.

https://bugzilla.gnome.org/show_bug.cgi?id=784302
2017-06-28 17:03:05 -04:00
Sebastian Dröge
2c6016667b gst: Clear floating flag in constructor of all GstObject subclasses that are not owned by any parent
https://bugzilla.gnome.org/show_bug.cgi?id=743062
2017-05-17 10:41:01 +03:00
Jean-Christophe Trotin
7f763f2710 v4l2allocator: reference memory before the buffer is queued
In gst_v4l2_allocator_qbuf(), the memory is referenced after the
buffer is queued. Once queued (VIDIOC_QBUF), the buffer might be handled
by the V4L2 driver (e.g. decoded) and dequeued (gst_v4l2_allocator_dqbuf),
through a different thread, before the memory is referenced (gst_memory_ref).
In this case, in gst_v4l2_allocator_dqbuf(), the memory is unreferenced
(gst_memory_unref) before having been referenced: the memory refcount
reaches 0, and the memory is freed.
So, to avoid this crossing case, in gst_v4l2_allocator_qbuf(), the
memory shall be referenced before the buffer is queued.

https://bugzilla.gnome.org/show_bug.cgi?id=777399
2017-01-24 11:30:57 -05:00
Jean-Christophe Trotin
2b80cd14b0 v4l2allocator: fix memory type in allocator probe
The buffer memory type provided to the VIDIOC_CREATE_BUFS ioctl shall
be set with the value ("memory") given as input parameter of the
gst_v4l2_allocator_probe() function.

https://bugzilla.gnome.org/show_bug.cgi?id=777327
2017-01-16 10:19:18 -05:00
William Manley
56b1d088a9 v4l2: Warn, don't assert if v4l gives us a buffer with a too large size
I've seen problems where the `bytesused` field of `v4l2_buffer` would be
a silly number causing the later call to:

    gst_memory_resize (group->mem[i], 0, group->planes[i].bytesused);

to result in this error to be printed:

    (pulsevideo:11): GStreamer-CRITICAL **: gst_memory_resize: assertion 'size + mem->offset + offset <= mem->maxsize' failed

besides causing who-knows what other problems.

We make the assumption that this buffer has still been dequeued correctly
so just clamp to a valid size so downstream elements won't end up in
undefined behaviour.

The invalid `v4l2_buffer` I saw from my capture device was:

    buffer = {
      index = 0,
      type = 1,
      bytesused = 534748928, // <- Invalid
      flags = 8260, // V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC | V4L2_BUF_FLAG_ERROR | V4L2_BUF_FLAG_DONE
      field = 01330, // <- Invalid
      timestamp = {
        tv_sec = 0,
        tv_usec = 0
      },
      timecode = {
        type = 0,
        flags = 0,
        frames = 0 '\000',
        seconds = 0 '\000',
        minutes = 0 '\000',
        hours = 0 '\000',
        userbits = "\000\000\000"
      },
      sequence = 0,
      memory = 2,
      m = {
        offset = 3537219584,
        userptr = 140706665836544, // Could be nonsense, not sure
        planes = 0x7ff8d2d5b000,
        fd = -757747712
      },
      length = 2764800,
      reserved2 = 0,
      reserved = 0
    }

This is from gdb with my own annotations added.

This was with gst-plugins-good 1.8.1, a Magewell XI100DUSB-HDMI video
capture device and kernel 3.13 using a dodgy HDMI cable which is great at
breaking HDMI capture devices.  I'm using io-mode=userptr and have built
gst-plugins-good without libv4l.

https://bugzilla.gnome.org/show_bug.cgi?id=769765
2016-11-01 20:12:56 +02:00
Luis de Bethencourt
2c52174167 v4l2allocator: Fix spelling of reenqueueing
To match commit 7d7074cef0. I love the idea
of aiming for the maximum number of consecutive vowels.
2016-02-08 15:35:19 +00:00
Nicolas Dufresne
7d7074cef0 v4l2allocator: Fix spelling of queueing
Didn't know which one to choose between queuing and queueing, so I picked
the one with the biggest amount of vowels in a row ;-P (both are
acceptable apparently)
2016-02-08 10:19:31 -05:00
Philipp Zabel
95bab88225 gstv4l2bufferpool: handle -EPIPE from DQBUF to signal EOS
The V4L2 decoder signals EOS by returning -EPIPE from DQBUF after the
last buffer.

https://bugzilla.gnome.org/show_bug.cgi?id=743338
2015-06-09 21:56:40 -04:00
Aurélien Zanelli
600027a1ee v4l2bufferpool: fix import_userptr() in single-planar API when n_planes > 1
In the V4L2 single-planar API, when format is semi-planar/planar,
drivers expect the planes to be contiguous in memory.
So this commit change the way we handle semi-planar/planar format
(n_planes > 1) when we use the single-planar API (group->n_mem == 1).

To check that planes are contiguous and have expected size, ie: no
padding. We test the fact that plane 'i' start address + plane 'i'
expected size equals to plane 'i + 1' start address. If not, we return
in error.

Math are done in bufferpool rather than in allocator because the
former is aware of video info.

https://bugzilla.gnome.org/show_bug.cgi?id=738013
2015-02-25 14:25:01 -05:00
Aurélien Zanelli
ac3cb8817e v4l2allocator: let bufferpool calculate image size when importing userptr
Offset are relative to the buffer and there is no guarantee substracting
them will give us the plane size. So we let bufferpool make the math as
it is more aware of video info than allocator and pass a size array to
allocator import function.

Pointed out by Nicolas Dufresne <nicolas.dufresne@collabora.com>

https://bugzilla.gnome.org/show_bug.cgi?id=738013
2015-02-25 14:24:49 -05:00
Nicolas Dufresne
f5ef99fe5e v4l2allocator: Fix freeing of shared memory
When memory (that has been shared using gst_memory_share()) are freed,
the memory (or the DMABUF FD) should not bee freed. These memories have
a parent. This also removes the extra _v4l2mem_free function and avoid
calling close twice on the DMABUF FD.

https://bugzilla.gnome.org/show_bug.cgi?id=744573
2015-02-15 16:21:55 -05:00
Nicolas Dufresne
f7c682f802 v4l2allocator: Add protection against driver bug
v4l2loopback driver has a this nasty bug that if the queue is larger
then 2 buffers, it returns random index on dqbuf. So far we assumed
that the index was always right, which would lead to memory being
unref twice, and eventually crash.
2015-01-08 23:55:28 -05:00
Nicolas Dufresne
3e876215b7 v4l2: Don't use allocator size to iterate
As the buffer array is fixed size and small, it's safer to simply
use this static size to cleanup the buffers. This is also more
consistent with the rest. The associated method is no longer
required and can be dropped.
2015-01-08 23:55:28 -05:00
Nicolas Dufresne
1fe4a19dc2 v4l2allocator: Add protection against broken libv4l2
It looks like libv4l2 support for CREATE_BUF is incomplete. That
combine with existing bugs may lead to crash in GStreamer. These
check will make it robust by:

- Checking create buf index isn't an already in used index
- Checking that the index out of QUERYBUF matches the requested
  index
2014-12-16 13:42:22 -05:00
Nicolas Dufresne
b80edd2ee2 v4l2allocator: Fix CREATE_BUF probing
Current for every memory type we where probing MMAP CREATE_BUFS ioct.

https://bugzilla.gnome.org/show_bug.cgi?id=741134
2014-12-04 17:00:25 -05:00
Nicolas Dufresne
ea4d9745e4 Revert "v4l2allocator: Remove unused variable"
This reverts commit ad4480d534.
2014-11-24 10:36:54 -05:00
Nicolas Dufresne
43d5a523f1 Revert "v4l2: move vb_queue probing from allocator to v4l2object"
This reverts commit ec6b8b84af.
2014-11-24 10:36:30 -05:00
Nicolas Dufresne
ad4480d534 v4l2allocator: Remove unused variable
this was introduced by commit ec6b8b

https://bugzilla.gnome.org/show_bug.cgi?id=699382
2014-11-21 11:44:24 -05:00
Benjamin Gaignard
ec6b8b84af v4l2: move vb_queue probing from allocator to v4l2object
The goal is to make those information available in v4l2_object
to be able later to select the best allocation method for the pool

https://bugzilla.gnome.org/show_bug.cgi?id=699382
2014-11-21 11:28:18 -05:00
Aurélien Zanelli
36532f5070 v4l2allocator: fix error message if allocator is already active
https://bugzilla.gnome.org/show_bug.cgi?id=739789
2014-11-07 10:42:40 -05:00
Peter Korsgaard
d3eea8f606 v4l2allocator: O_CLOEXEC needs _GNU_SOURCE
Similar to 94f3d6fc / bz 709423

On some systems (E.G. uClibc and older Glibc versions), O_CLOEXEC is only
defined when _GNU_SOURCE is specified, so do so.

https://bugzilla.gnome.org/show_bug.cgi?id=736670
2014-09-16 10:20:22 +03:00
Nicolas Dufresne
5c933fa781 v4l2allocator: Workaround driver that don't support REQBUFS(0)
There is still around 18 drivers not yet ported to videobuf2. These driver
don't support freeing buffetrs through REQBUFS(0) hence for these the
memory type probing fails. In order to gain back our previous behaviour in
presence of these, we implement a workaround that assuming MMAP is
supported. Note that an allocator is only created for device with
STREAMING support in the device capabilities. In such case one of MMAP,
USERPTR and DMABUF is required. Though DMABUF came afterward, so is
not an option and in practice none of these drivers will only do USERPTR.

https://bugzilla.gnome.org/show_bug.cgi?id=735660

Also-by: Hans de Goede <hdegoede@redhat.com>
2014-09-09 18:45:34 -04:00
Nicolas Dufresne
0ac0cbcc0e v4l2allocator: Use qdata instead of parenting to DmabufMemory
Parenting V4l2Memory to DmabufMemory was in conflict with recent
optimization in DmabufMemory to avoid dup(), and didn't work with
memory sharing. Instead, use a qdata and it's destroy notify.

https://bugzilla.gnome.org/show_bug.cgi?id=730441
2014-07-11 09:49:27 +02:00
Nicolas Dufresne
e2fd7e274e v4l2bufferpool: Port to bufferpool flush_start/stop method
Port the buffer pool to use the new flush_start/flush_stop virtual
methods added to GstBufferPool.

https://bugzilla.gnome.org/show_bug.cgi?id=727611
2014-05-26 13:43:30 -04:00
Nicolas Dufresne
2e89f4ecff Revert "v4l2bufferpool: Port to bufferpool flush_start/stop method"
This reverts commit 2e0fb42e86.

Conflicts:
	sys/v4l2/gstv4l2allocator.c
	sys/v4l2/gstv4l2bufferpool.c
	sys/v4l2/gstv4l2videodec.c
2014-05-24 20:00:14 -04:00
Nicolas Dufresne
2cb6b9775c v4l2allocator: Add debug assert to detect calls in the wrong state 2014-05-24 15:38:53 -04:00
Nicolas Dufresne
1f70b21926 v4l2allocator: Reset count when stopped 2014-05-24 15:38:53 -04:00
Nicolas Dufresne
2e0fb42e86 v4l2bufferpool: Port to bufferpool flush_start/stop method 2014-05-24 15:38:53 -04:00
Nicolas Dufresne
58716e054f v4l2allocator: Don't trace twice the same message 2014-05-16 21:48:29 -04:00
Nicolas Dufresne
7986c55dcb v4l2allocator: Fix use of atomic active marker
https://bugzilla.gnome.org/show_bug.cgi?id=730207
2014-05-15 12:21:35 -04:00
Nicolas Dufresne
dfdd1ba9d9 v4l2allocator: Reset imported buffer size with expected size
This ensure that the buffer pool won't always discard buffer with these
memory when they are released.
2014-05-08 15:56:37 -04:00
Nicolas Dufresne
1304c74c6a v4l2allocator: Reset flushed group
This ensure that a flushed group memory are the same size as when they
where originally allocated / imported.
2014-05-08 15:56:37 -04:00
Nicolas Dufresne
7aed4a9806 v4l2allocator: Add a method to read number of allocated group 2014-05-08 15:56:37 -04:00
Nicolas Dufresne
b2dab42ce8 v4l2allocator: Fix libv4l2 support
Need to include config.h, otherwise we endup directly using the
ioct/mmap/munmap calls and need to vall v4l2_munmap.
2014-05-08 15:56:37 -04:00
Nicolas Dufresne
428d63c2e5 v4l2allocator: Set the flags on the object
We where not setting the probed flags on the allocator, which mean even if
CREATE_BUFS was supported on some driver, it would endup being ignored.
2014-05-08 15:56:37 -04:00
Nicolas Dufresne
a946a7cde6 v4l2allocator: There is not group on error 2014-05-08 15:56:37 -04:00
Nicolas Dufresne
74a64be001 v4l2-allocator: Add S to REQBUFS/CREATE_BUFS enum
All enum that has REQBUFS and CREATE_BUFS where missing S, which was
confusing since they are supposed to match with associcated ioctl name. This
also fixes the yet unused CAN_REQUEST flag check.
2014-05-08 15:56:37 -04:00
Nicolas Dufresne
62605e11eb v4l2: Fixup USERPTR/DMABUF capture support 2014-05-08 15:56:37 -04:00
Nicolas Dufresne
92bdd596f2 v4l2: Add DMABUF and USERPTR importation 2014-05-08 15:56:36 -04:00
Nicolas Dufresne
a114a32d22 v4l2allocator: Valid FD are bigger or equal to zero 2014-05-08 15:56:36 -04:00
Nicolas Dufresne
1ab90ababa v4l2: Add dmabuf export support
This can be enabled sing io-mode=dmabuf. This will enabled mmap base
drivers to export the buffers as dmabuf.
2014-05-08 15:56:36 -04:00