Commit graph

242 commits

Author SHA1 Message Date
Philipp Zabel
dfc20013cc v4l2bufferpool: support orphaning
Now that the v4l2allocator allows orphaning the V4L2 buffer queue, add
support for orphaning in the v4l2bufferpool. gst_v4l2_buffer_pool_orphan
can be used as a replacement for gst_v4l2_buffer_pool_stop, without
having to wait for buffers to be returned to the pool.
2019-04-05 16:01:55 +00:00
Wonchul Lee
560a6155bd v4l2bufferpool: fix typo resurect to resurrect
https://bugzilla.gnome.org/show_bug.cgi?id=797273
2018-10-24 12:03:13 +01:00
Nicolas Dufresne
480a7bcab8 v4l2bufferpool: Validate stride/offset when importing
This will prevent situation where buffer size allow importing but rendering
goes wrong due to a miss-match in expected stride and offset.

https://bugzilla.gnome.org/show_bug.cgi?id=583890
2018-08-27 13:41:30 -04:00
Nicolas Dufresne
73555b5440 v4l2bufferpool: Fix typo in error message
https://bugzilla.gnome.org/show_bug.cgi?id=583890
2018-08-27 13:41:30 -04:00
Nicolas Dufresne
77c052f0e8 v4l2bufferpool: Only queue buffer if preparation worked
The preparation code imports the buffer, doing bunch of
validation. Only queue the buffer in the driver if the
importation worked. This way we don't rely on the driver
to validate.

https://bugzilla.gnome.org/show_bug.cgi?id=583890
2018-08-27 13:41:30 -04:00
Nicolas Dufresne
90a70e08b7 v4l2bufferpool: Activate the other pool first
This change has no effect. We will need to acquire a buffer from the
pool later in order to validate / adapt with the video alignment for
the downstream buffers.

https://bugzilla.gnome.org/show_bug.cgi?id=583890
2018-08-27 13:41:30 -04:00
Nicolas Dufresne
9e79821b1d v4l2bufferpool: Validate that capture buffers were queued
When the pool is started, we allocate and release buffer, expecting
the pool release-buffer handler to queue them. Though, as we rely
on release function, there is no direct way to detect that this
process didn't work.

To check this, validate that the number of queued buffer is the same
as the number of allocated buffers. This allow returning an error
when buffer importation was refused by the driver.

https://bugzilla.gnome.org/show_bug.cgi?id=583890
2018-07-13 23:13:44 -04:00
Nicolas Dufresne
3b364cea94 v4l2bufferpool: Only return eos for M2M devices
This will avoid sending EOS on v4l2src when a driver sends an empty
buffers. This case would be a bug in the driver, but yet the camera
should keep running.

This also removes the check for corrupted buffers, as this check is
already done later.

https://bugzilla.gnome.org/show_bug.cgi?id=794842
2018-07-13 22:58:57 -04:00
Nicolas Dufresne
38b68cbbd7 v4l2bufferpool: Remove duplicate check
We were calling gst_v4l2_is_buffer_valid() before and inside
gst_v4l2_buffer_pool_qbuf() as we needed to access the group. The second
check failed since the writability of the buffer get inherited from the
GstMemory, which lead to pipeline failure. As we cannot avoid the extra
ref, it would be racy otherwise, just pass the group to _dbuf() so it
does not have to call gst_v4l2_is_buffer_valid() again.

https://bugzilla.gnome.org/show_bug.cgi?id=796692
2018-07-12 15:17:44 -04:00
Nicolas Dufresne
90eade28f2 v4l2bufferpool: Drop truncated frames
Drop truncated frames regardless if they have the ERROR flag or not.
Truncated frame causes video frame map failure in many elements
including cluttersink, glupload etc.
2018-06-07 15:26:32 -04:00
Nicolas Dufresne
e943a11bab v4l2bufferpool: Try return input buffer soon
In this patch we use a non-blocking poll in order to return all input
buffers (buffers from v4l2-output queue). This prevent holding too long
on upstreaming buffer in importing.

https://bugzilla.gnome.org/show_bug.cgi?id=794904
2018-06-07 15:26:32 -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
1f902e2f6e v4l2bufferpool: Don't stop streaming when pool is flushing
The purpose of being able to flush the buffer pool is only to
unlock any blocked operation. Doing streamoff/streamon had the
side effect of turning off and on the camera. As we do a flush_start
/ flush_stop sequence when shutting down, that would cause a really
quick sequence of streamoff/streamon/streamoff/close which was
causing some cameras to stop working.

https://bugzilla.gnome.org/show_bug.cgi?id=783945
2017-09-19 17:33:35 -04:00
Cyril Lashkevich
f2372b46bc v4l2bufferpool: Don't mark jpeg frames as deltas
JPEG formats are encoded, but they never have keyframe flag. But in
fact they are keyframes

https://bugzilla.gnome.org/show_bug.cgi?id=785990
2017-08-08 11:09:52 -04:00
Nicolas Dufresne
d8b18f6b8f v4l2bufferpool: Don't drop buffer ref on qbuf
This function no longer take ownership of the buffer.

CID 1414800
2017-08-02 17:18:43 -04:00
Nicolas Dufresne
ba8aa440bb v4l2bufferpool: Copy flags and timestamp when importing
Whenever we import from downstream pool (userptr or dmabuf-import), we
should copy over the flags and timestamp, otherwise downstream will not
get proper synchronization or will not be able to notice frames that has
corruption in it.

https://bugzilla.gnome.org/show_bug.cgi?id=785680
2017-08-01 09:48:46 -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
52a5658030 v4l2: Block recursive calls to resurect_buffer
When resurrecting a buffer, the subsequent free call can result
in the group-released handler being called again, which causes
a recursive loop.  This patch blocks the signal handler during
the time that it executes, ensuring that the loop will not occur.

https://bugzilla.gnome.org/show_bug.cgi?id=759292
2017-06-29 15:54:42 -04:00
Ayaka
17e52f6ac2 v4l2pool: Fix wrong error message
https://bugzilla.gnome.org/show_bug.cgi?id=728438
2017-05-24 14:00:22 -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
Todor Tomov
081bae2849 v4l2object: Copy timestamp when importing buffers
This is needed for V4L2_OUTPUT interface, and is harmless of
V4L2_CAPTURE interfaces. This will fix timestamp in cases like:

  v4l2src io-mode=dmabuf ! v4l2videoNenc output-io-mode=dmabuf-import !  ...

Same apply for userptr.

https://bugzilla.gnome.org/show_bug.cgi?id=781119
2017-04-10 12:49:39 -04:00
Edgard Lima
8635258046 Update Edgard Lima's email
https://bugzilla.gnome.org/show_bug.cgi?id=779230
2017-02-27 00:34:19 +00:00
Jean-Christophe Trotin
1c2e2d83ce v4l2bufferpool: remove duplicated line of code
https://bugzilla.gnome.org/show_bug.cgi?id=777330
2017-01-16 10:19:34 -05:00
Tim-Philipp Müller
d7b2820b73 Fix indentation 2017-01-09 19:05:10 +00:00
Philipp Zabel
86f243bb12 gstv4l2bufferpool: lock flush_stop against regular qbuf
These can be called from different threads and both manipulate the
pool->buffers array. Lock them properly and let flush_stop move the
array contents into a temporary array on the stack to avoid having
to call release_buffer under the object lock.

https://bugzilla.gnome.org/show_bug.cgi?id=775015
2016-11-24 11:47:07 -05:00
Philipp Zabel
6b5807654b gstv4l2bufferpool: remove critical error message when process is called on an inactive pool
If the pool is inactive, it is guaranteed to also be flushing, so the
following check will return GST_FLOW_FLUSHING anyway.
This can happen if a v4l2src is blocking on DQBUF in create and is sent
an EOS event on another thread. In that case the pool is set to
flushing/inactive without locking, the v4l2src is unblocked, and may
call pool_process with a valid buffer on the already inactive pool.

https://bugzilla.gnome.org/show_bug.cgi?id=775014
2016-11-24 11:47:07 -05:00
Reynaldo H. Verdejo Pinochet
4b16b16aaf v4l2: use opened device caps instead of physical device ones
The same physical device can export multiple devices. In
this case, the capabilities field now contains a union of
all caps available from all exported V4L2 devices alongside
a V4L2_CAP_DEVICE_CAPS flag that should be used to decide
what capabilities to consider. In our case, we need the
ones from the exported device we are using.

https://bugzilla.gnome.org/show_bug.cgi?id=768195
2016-07-07 17:46:06 -04:00
Josep Torra
b7866315a6 v4l2src: check for valid size on raw video buffers
Discard buffers that doesn't contain enough data when dealing
with raw video inputs.

https://bugzilla.gnome.org/show_bug.cgi?id=767086
2016-06-01 17:35:12 +02:00
Tim-Philipp Müller
3333683f64 v4l2: don't use undeclared core debug category symbols 2016-02-20 11:51:56 +00:00
Wim Taymans
b208ae72ee v4l2bufferpool: don't block when resurecting a buffer
When we are resurecting a buffer, don't block. instead let us copy a
buffer.
2015-12-01 18:22:11 +01:00
Hyunjun Ko
afcd462918 v4l2bufferpool: set GST_BUFFER_COPY_FLAGS to copy flags also
https://bugzilla.gnome.org/show_bug.cgi?id=752618
2015-07-23 10:19:46 -04:00
Song Bing
c5950cd04a v4l2bufferpool: Set timestamp when queue buffer.
Should set timestamp when queue buffer.

https://bugzilla.gnome.org/show_bug.cgi?id=752618
2015-07-20 16:49:41 -04: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
Peter Seiderer
f16fe891fb v4l2: use v4l2 capture device sequence counter
Use the v4l2 capture device sequence counter for
setting the GstBuffer offset/offset_end values.

https://bugzilla.gnome.org/show_bug.cgi?id=745441
2015-04-02 17:40:19 -04:00
Tobias Modschiedler
8390288a6e v4l2: Ask the driver about its requirements for min_buffers before initiating buffer pool.
If propose_allocation() had not been called yet, it was possible that the driver was not asked at all.
In buffer pool: Consider minimum number of buffers requested by driver when setting config.

https://bugzilla.gnome.org/show_bug.cgi?id=746834
2015-04-02 17:29:19 -04: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
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
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
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
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