Commit graph

886 commits

Author SHA1 Message Date
Thiago Santos
0a945e7099 v4l2src: delay renegotiation until it is likely buffers were reclaimed
Allow renegotiation to happen when buffers have returned after an allocation
query. As the allocation query is serialized, all buffers from the pool
should have returned and we can stop it to create a new one for the
new format

https://bugzilla.gnome.org/show_bug.cgi?id=682770
2015-03-13 18:48:03 +00:00
Thiago Santos
6cfa6c0da8 v4l2object: add gst_v4l2_object_try_format
Similar to set_format but it uses TRY_FMT instead of S_FMT

https://bugzilla.gnome.org/show_bug.cgi?id=682770
2015-03-13 18:47:55 +00:00
Nicolas Dufresne
eeb4d2e8b1 v4l2bufferpool: Don't update buffer for OUTPUT
For output device, we should not update the buffer with flags and
timestamp when we dequeue. The information in the v4l2_buffer is not
meaningful and it breaks the case where the buffer is rendered at
multiple places.

https://bugzilla.gnome.org/show_bug.cgi?id=745438
2015-03-08 21:15:53 +00:00
Gwenole Beauchesne
8cd40e77b7 v4l2allocator: fix fd leak in DMABUF import mode.
Ensure gst_v4l2_buffer_pool_release_buffer() releases the associated
GstV4l2MemoryGroup. In particular, this allows for closing the DMABUF
handles prior to instantiating new ones.

https://bugzilla.gnome.org/show_bug.cgi?id=745443
2015-03-02 15:10:51 -05:00
Nicolas Dufresne
8e75acc7b7 v4l2bufferpool: Add missing break
This is cosmetic change.
2015-03-01 14:03:04 -05:00
Nicolas Dufresne
76775efe71 v4l2: Workaround driver not setting field correctly
As it's very common, handle driver not setting field in buffers
by using the field value from the format. This workaround a long time
bug in UVC driver. For even buggier driver, we simply assume
progressive as before. We also only warn once, to avoid spamming.
2015-03-01 14:03:04 -05:00
Aurélien Zanelli
88703ae585 v4l2: query crop configuration after each call of S_CROP
S_CROP ioctl is write-only and the device can adjust crop rectangle so
we query back the crop configuration after each S_CROP to know what has
been done.

https://bugzilla.gnome.org/show_bug.cgi?id=736133
2015-02-26 08:38:32 -05:00
Aleix Conchillo Flaqué
63746c4131 v4l2bufferpool: Check corruption flag on the right buffer
We where checking the buffer we are copying to instead of the buffer we
are copying from.

https://bugzilla.gnome.org/show_bug.cgi?id=740040
2015-02-25 20:53:19 -05:00
Aurélien Zanelli
7a1613b9e1 v4l2object: set colorspace in caps for capture devices
This information is set by the driver for a capture device, and so could
be forwarded to pipeline by setting the colorimetry in caps.

https://bugzilla.gnome.org/show_bug.cgi?id=743186
2015-02-25 14:48:20 -05: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
Philippe De Muyter
61a5e5af95 v4l2object: recognize and distinguish all bayer arrangements
Up to now, v4l2src recognized only "bggr" amongst the bayer arrangements.
Recognize now also the "rggb", "gbrg" and "grbg" arrangements.

https://bugzilla.gnome.org/show_bug.cgi?id=742363
2015-02-25 14:14:59 -05:00
Aurélien Zanelli
e57bc43862 v4l2bufferpool: set v4l2_buffer.field when queuing buffer in an output device
According to the current specification, application must set this field
for an output device.

https://bugzilla.gnome.org/show_bug.cgi?id=743013
2015-02-25 10:27:30 -05:00
Nicolas Dufresne
6afd1c5d57 v4l2: Enable copy when no known allocation params
When there is no allocation parameters in the query, enable copy
threshold. When this threshold is reached, the buffer pool will start
copying when the pool reaches a critical level. If the driver supports
CREATE_BUFS, this will be used instead.
2015-02-19 23:16:00 -05:00
Nicolas Dufresne
dfb0ec6d4d v4l2bufferpool: Update allocator flags
When we hit emulated formats, we disable CREATE_BUFS since libv4l2
cope very badly with it. Also clear the allocator flags so we will
never try to allocate more buffers. This fixes failure when the copy
threshold is reached as we where calling CREATE_BUFS, which lead to
libv4l2 instability.
2015-02-19 23:16:00 -05:00
Nicolas Dufresne
7dc475f141 v4l2bufferpool: Use specific debug category
The pool has grown enough that it is now handy to seperate v4l2object
trace from v4l2bufferpool trace.
2015-02-19 23:16:00 -05:00
Luis de Bethencourt
7ca7b1cd9a Revert "v4l2: fraction is reversed"
This reverts commit b91fe36644.
2015-02-18 19:18:00 +00:00
Luis de Bethencourt
b91fe36644 v4l2: fraction is reversed
In the fraction 1 / 2. 1 is the numerator and 2 is the denominator.
The arguments of fraction gst_value_set_fractions() are value,
numerator and denominator.
Also, gst_value_set_fraction() fails if denominator is 0 for obvious
reasons.
2015-02-18 17:49:31 +00:00
Nicolas Dufresne
171bfeccdf v4l2pool: Deactivate other pool
When importing buffers from a downstream pool, we need to deactivate
that pool to ensure it will be usable again later. Relying on the
refcount to reach zero does not work, since elements like xvimagesink
keeps a reference on their proposed pool.
2015-02-18 09:05:37 -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
Peter Seiderer
c88e042458 v4l2object: reuse caps framerate if not overwritten by v4l2 device
Enables duration setting in v4l2src.

https://bugzilla.gnome.org/show_bug.cgi?id=740403
2015-01-22 18:52:44 -05:00
Nicolas Dufresne
f3f4bdd676 v4l2videodec: Proxy getcaps
Replace the sink_query with new getcaps() virtual and use the proxy
helper with the probed caps. This allow upstream element taking decision
base on what is supported downstream.
2015-01-13 16:55:43 -05:00
Nicolas Dufresne
5c67ba7f88 v4l2videodec: Prevent renegotiation
Renegotiation isn't supported, simply prevent it the way we do in
v4l2src.
2015-01-09 16:59:53 -05:00
Nicolas Dufresne
c4aaff5c92 v4l2videodec: Don't unlock the stream lock twice 2015-01-09 16:55: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
e47a5708f0 v4l2bufferpool: Don't clean buffer array in dispose
This should already have been done, plus this code is incorrect
and may lead to crash.

https://bugzilla.gnome.org/show_bug.cgi?id=742074
2015-01-08 23:55:28 -05:00
Nicolas Dufresne
bbcfd594e4 v4l2bufferpool: Don't ref queued output buffer
This partly revert to the old 1.2 behavior. Instead of keeping a
reference to the output buffer queued, we simply release them but
don't forward it to GstBufferPool. This way, the buffer pool don't
need to be flushed to be stopped.

https://bugzilla.gnome.org/show_bug.cgi?id=742074
2015-01-08 23:55:28 -05:00
Nicolas Dufresne
a4b961e275 v4l2bufferpool: Never fail on streamoff
Failing streamoff prevents allocator from being disposed hence
lead to device FD leak. There is no known cases where streamoff
may fails for which we'd still be streaming. streamoff is known
to fail when a device is being unplugged (in which case errno
19/ENODEV is set).

https://bugzilla.gnome.org/show_bug.cgi?id=732734
2015-01-08 11:37:23 -05:00
Nicolas Dufresne
2a1459c88f v4l2pool: Update configuration size
We already update our copy of VideoInfo.size to proper size, now also
the configuration so the size matches on release.

https://bugzilla.gnome.org/show_bug.cgi?id=741420
2014-12-19 12:32:06 -05:00
Nicolas Dufresne
f6259e96c7 v4l2bufferpool: Disable create_buf with libv4l2
Libv4l2 does not work with CREATE_BUFS. Instead of failing on random
error caused by libv4l2, disable CREATE_BUFS when an emulated format is
detected.
2014-12-16 15:00:22 -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
3dae65ede8 v4l2object: Always set format
Right now we try to be clever by detecting if device format have
changed or not, and skip setting format in this case. This is valid
behaviour with V4L2, but it's also very error prone. The rational
for not setting these all the time is for speed, though I can't
measure any noticeable gain on any HW I own. Also, until recently,
we where doing get/set on the format for each format we where
probing, making it near to impossible that the format would match.
This also fixes bug where we where skipping frame-rate setting if
format didn't change.

https://bugzilla.gnome.org/show_bug.cgi?id=740636
2014-12-15 18:38:00 -05:00
Aurélien Zanelli
62193129c5 v4l2bufferpool: set buffer interlace flags when field is V4L2_FIELD_INTERLACED
If v4l2_buffer.field is V4L2_FIELD_INTERLACED, we set corresponding
GstVideoBuffer flags depending on the video standard.
According to V4L2 specification, M/NTSC transmits the bottom field
first, all other standards the top field first.

https://bugzilla.gnome.org/show_bug.cgi?id=737603
2014-12-09 11:00:28 -05:00
Nicolas Dufresne
eb1dcd841a v4l2: Workaround libv4l2 RW emulation bug
When libv4l2 emulates RW mode on top of MMAP devices, the queues are
only initialized on first read. The problem is that poll() will fail
if called before the queues are initialized and streaming. Workaround
this by doing a zero size read when pool is started in that IO mode.

https://bugzilla.gnome.org/show_bug.cgi?id=740633
2014-12-07 17:43:01 -05:00
Nicolas Dufresne
0e05faf91a v4l2: Fix RW io mode
In RW, allocator can be null, max_buffers can be zero, and we need not
to wait while the queue is empty since there is no queue.

https://bugzilla.gnome.org/show_bug.cgi?id=740633
2014-12-07 17:42:48 -05:00
Nicolas Dufresne
d328eea5f2 v4l2bufferpool: Cleanup uneeded check and cases
There is nothing in between the break and the "done:" anymore, plus
USERPTR and DMABUF_IMPORT case is exactly the same.
2014-12-04 17:00:25 -05:00
Nicolas Dufresne
319efc3e20 v4l2pool: Fix CREATE_BUFS support for capture
This patch fixes CREATE_BUFS support for capture devices. Initially we
would only try and allocate more buffers when the copy threshold
is reached. When the threshold was not set (needed) it would never
happen. Another problem is that on capture side, acquire returns
filled buffer, hence need to pool. We need to set a special flag to
force allocation to happen.

https://bugzilla.gnome.org/show_bug.cgi?id=741134
2014-12-04 17:00:25 -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
Aurélien Zanelli
114b84c1a3 v4l2allocator: fix gst_v4l2_allocator_stop prototype
gst_v4l2_allocator_stop returns a GstV4l2Return, not a gboolean.

https://bugzilla.gnome.org/show_bug.cgi?id=739792
2014-12-01 10:08:54 -05:00
Aurélien Zanelli
74eb903727 v4l2bufferpool: unref pool when v4l2_allocator_new() fails
https://bugzilla.gnome.org/show_bug.cgi?id=739791
2014-12-01 10:08:40 -05:00
Nicolas Dufresne
cfa5a9d938 v4l2: Remove last include to linux/videodev2.h
We now use and update our internal copy so we no longer have to ifdef
the entire code for features and defines that where added over the
years.

https://bugzilla.gnome.org/show_bug.cgi?id=740905
2014-11-30 17:55:19 -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
3591a91067 Revert "v4l2object: allow to automatic selection of dmabuf"
This reverts commit e6c2ad5571.
2014-11-24 10:33:29 -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
Nicolas Dufresne
b9992e4347 v4l2: Handle corrupted buffer with empty payload
This allow skipping buffer flagged with ERROR that has no payload.
This is typical behaviour when a recovererable error occured during
capture in the driver, but that no valid data was ever written into that
buffer. This patch also translate V4L2_BUF_FLAG_ERROR into
GST_BUFFER_FLAG_CORRUPTED. Hence decoding error produce
by decoder due to missing frames will now be correctly marked. Finally,
this fixes a buffer leak when EOS is reached.

https://bugzilla.gnome.org/show_bug.cgi?id=740040
2014-11-21 11:29:19 -05:00
Benjamin Gaignard
e6c2ad5571 v4l2object: allow to automatic selection of dmabuf
If the v4l2 queue support dmabuf select this buffer pool mode
and update the query with allocator.
This patch only concern exporting dmabuf and not importing dmabuf
fd from downstream element.

https://bugzilla.gnome.org/show_bug.cgi?id=699382
2014-11-21 11:29:04 -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