Commit graph

869 commits

Author SHA1 Message Date
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
Nicolas Dufresne
3282df51a4 v4l2bufferpool: Improve buffer validation
Improve buffer validation by making sure each memory are the right
one and that each memory is writable. This fixes tearing issues in
case downstream uses gst_buffer_make_writable() or other type
of GstBuffer copy where memory are only reffed.

https://bugzilla.gnome.org/show_bug.cgi?id=739754
2014-11-07 10:42:40 -05:00
Aurélien Zanelli
8fdfb58ec4 v4l2bufferpool: fix typo in flags
https://bugzilla.gnome.org/show_bug.cgi?id=739549
2014-11-03 08:59:50 -05:00
Tim-Philipp Müller
cde3ce38e1 v4l2src: fix a couple of minor leaks 2014-11-02 23:41:24 +00:00
Simon Farnsworth
02040d507c v4l2: Clean up interlace support
Rather than try and guess interlace support as part of checking supported
sizes, look for interlace support specifically in its own function.

As a cleanup, use V4L2_FIELD_ANY when probing sizes, which should result in
the driver doing the right thing.

With my capture setup, this gets me the following sample caps:

For 1080i resolution:
video/x-raw, format=(string)YUY2, width=(int)1920, height=(int)1080, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)interleaved, framerate=(fraction){ 25/1, 30/1 }

For 720p resolution:
video/x-raw, format=(string)YUY2, width=(int)1280, height=(int)720, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, framerate=(fraction){ 50/1, 60/1 }

For 576i/p resolution (both possible at the point of query):
video/x-raw, format=(string)YUY2, width=(int)720, height=(int)576, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string){ progressive, interleaved }, framerate=(fraction){ 25/1, 50/1 }

This, in turn, makes 576i work correctly; with the old code,
the caps would be interlace-mode=progressive for interlaced video.

https://bugzilla.gnome.org/show_bug.cgi?id=726194
2014-11-01 11:46:13 -04:00
Aurélien Zanelli
1dcc883261 v4l2bufferpool: cleanly handle streamon failure for output device
On streamon failure, the queued buffer is not released from the
bufferpool class point of view because it is queued to the driver and
the flush logic is not performed since we are not in streaming state.
It causes the v4l2 bufferpool to always return that stop method failed
and to leak v4l2 objects and buffers.

This commit solve this by performing the flush logic in error case, ie
flushing the allocator and restoring queued buffer state to non-queued.

https://bugzilla.gnome.org/show_bug.cgi?id=738102
2014-10-29 16:24:20 -04:00
Aurélien Zanelli
8e9c752eca v4l2bufferpool: implement dispose method
Unref objects in dispose method rather than in finalize in order to
prevent circular reference.

https://bugzilla.gnome.org/show_bug.cgi?id=738102
2014-10-29 16:24:11 -04:00
Aurélien Zanelli
7ed27c264c v4l2bufferpool: check that allocator is non null when stopping pool
Otherwise, we could dereference NULL allocator when the stop method is
called by the GstBufferPool's finalize method.

https://bugzilla.gnome.org/show_bug.cgi?id=738102
2014-10-29 16:24:01 -04:00
Nicolas Dufresne
cc709d06de v4l2sink: Implement unlock/unlock_stop
This will prevent deadlocks, but will also properly flush the pool and allocator
when going to READY state. It should also fix issues reported on mailing list
when seeking is performed.

https://bugzilla.gnome.org/show_bug.cgi?id=738152
2014-10-29 16:22:14 -04:00
Tim-Philipp Müller
31b8cfecc2 pulse, v4l2: add missing G_END_DECLS in some places 2014-10-28 21:32:06 +00:00
Aurélien Zanelli
cfb4c02187 v4l2object: set colorspace for output devices
When the v4l2 device is an output device, the application shall set the
colorspace. So map GStreamer colorimetry info to V4L2 colorspace and set
on set_format. In case we have no colorimetry information, we try to
guess it according to pixel format and video size.

https://bugzilla.gnome.org/show_bug.cgi?id=737579
2014-09-29 21:23:01 -04:00
Tim-Philipp Müller
46df0cedb7 v4l2: remove redundant struct declaration 2014-09-27 16:01:21 +01: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
Ognyan Tonchev
b417c3409b v4l2sink: Unref pool after usage
https://bugzilla.gnome.org/show_bug.cgi?id=736384
2014-09-10 08:26:18 -04:00
Nicolas Dufresne
de6db03b53 v4l2transform: Don't rank it for now
This will prevent the converter to be picked automatically in case
someone implement dynamic converter selection support. I'd like this
to be ranked only for known device, as it's hard to be sure a device is
a converter suited for general purpose. Re-negotiation is also needed
before we can rank it.

https://bugzilla.gnome.org/show_bug.cgi?id=733607
2014-09-09 19:03:50 -04:00
Nicolas Dufresne
b706103fab v4l2: Detect bad drivers timestamps
Even though the UVC driver do a great deal of effort to prevent bad
timestamp to be sent to userspace, there still exist UVC hardware that
are so buggy that the timestamp endup nearly random. This code detect
and ignore timestamp from these drivers, making these camera usable.
This has been tested on both invalid and valid cameras, making sure it
does not trigger for valid cameras.

https://bugzilla.gnome.org/show_bug.cgi?id=732910
2014-09-09 18:50:59 -04: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
743c6a4475 v4l2: Merge min_buffers_for* variable into one
Reuse the same min_buffers variable for both capture and output, this
reduce the length of lines and make the code more readable.

https://bugzilla.gnome.org/show_bug.cgi?id=736072
2014-09-09 18:39:23 -04:00