Commit graph

246 commits

Author SHA1 Message Date
Wim Taymans
853a46120e v4l2: Improve format and control enumeration
Use dynamic pod builder so that we can also build complex formats.

Make sure we zero the format before we parse it or else we end up with
potentially uninitialized values.

When ENUM_FRAMESIZES or VIDIOC_ENUM_FRAMEINTERVALS return EINVAL for the
first index, make a dummy result and continue with that. This will
trigger an intersect withe filter so that we end up with something valid
instead of nothing.

Handle 0 framerates without crashing.

See #4063
2024-07-09 14:14:42 +02:00
Wim Taymans
2c1ec7fa43 v4l2: use a dynamic pod builder to handle larger PropInfo
The labels from the vivid driver need more space so use a dynamic
builder to make sure we can handle them.

See #4063
2024-07-09 09:23:49 +02:00
Wim Taymans
fe5a29ac2a v4l2: improve logging a little
Add the device to the error log lines.
2024-06-11 12:15:05 +02:00
Wim Taymans
4d7c81bd90 v4l2: support meta_videotransform on buffers
Advertise support for the videotransform metadata.
Make a new meta.videotransform.transform property to configure the
desired video transformation in the metadata.

This makes it possible for a session manager or other rules to set
a custom transformation on the source.

See #4034
2024-06-07 10:54:46 +02:00
Wim Taymans
61af61a4b3 v4l2: handle empty properties gracefully
When a property is not found or is empty, go on to the next format
instead of failing.

See #3959
2024-04-10 11:06:44 +02:00
Robert Mader
1a2fee260b v4l2: Drop the first frame after camera startup
A quite big number of UVC cameras - due to firmware or kernel driver
issues - have bad timestamps of the first frame, confusing clients
like pipewiresrc.
Drop the first frame, as this seems to be the most reliable workaround
for the time being.

Closes https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/3910
2024-03-30 14:14:44 +01:00
Wim Taymans
842ac9e110 v4l2: set latency on port
Use the duration of one frame as the latency.

See #3910
2024-03-22 11:15:10 +01:00
Wim Taymans
858d4e9e1c buffer: add MAPPABLE data flag
Add a MAPPABLE data flag that hints that the fd in the data is mappable
with a simple mmap/munmap. Normally, DmaBuf is not mappable like that
unless explicitly indicated with this flag.

Set the MAPPABLE flag on the DmaBuf from v4l2 and libcamera fd.

When asked, mmap the buffer memory in all cases when the MAPPABLE
flag is set.

This solves the case where v4l2 has exported DmaBuf and is streaming to
node A and then node B links but doesn't get automatically mmaped
memory.

Fixes #3840
2024-02-08 18:09:08 +01:00
Wim Taymans
bbb83b97c5 v4l2: probe EXPBUF and disable alloc_buffer flag
After we set the format, probe if we can do EXPBUF and enable/disable
the ALLOC_BUFFERS flag on the port.

This should gracefully handle the case where EXPBUF is not available.

Fixes #3821
2024-01-29 16:38:52 +01:00
Wim Taymans
24f510b9b3 v4l2: clear support for alloc_buffers on failure
When we try to alloc buffers but EXPBUF is not supported, make sure to
clear the alloc_buffers flag so that the caller can try again with
allocated buffers instead.

See #3821
2024-01-29 16:10:36 +01:00
Wim Taymans
490558f3de v4l2: improve filter with missing format
When the filter has no format property, just enumerate all possible
framerates. Handle error case where the filter has the wrong type.

Makes gst-launch gstpipewiresrc ! video/x-raw ! fakesink work.

See #1793
2024-01-17 10:11:29 +01:00
Wim Taymans
14b265f646 v4l2: fix format enum with unsupported framerate
Actually count the number of frame fractions we add. If we added 0, we
don't have any supported framerate that intersects with the filter and we
try the next frame size.

See #1793
2024-01-17 09:55:47 +01:00
Wim Taymans
42a099381b v4l2: handle ENOTTY
Instead of erroring out, go to the next format when enumerating frame
size or frame interval.

See #3325
2023-07-04 11:36:37 +02:00
Wim Taymans
b59766c3d1 v4l2: add support fot G_CTRL
Get the current values of the controls and add those to the Props.

Emit a Props param changed event when we update properties.
2023-04-18 16:27:55 +02:00
Wim Taymans
a0457a3bdf camera: work around target_ mishandling
A driver node should use the target_duration and target_rate to adjust
the quantum and rate when the graph starts.

The camera nodes don't currently support any of this and simply enforce
a specific rate and duration for the graph clock. Mark this with a
FIXME. Otherwise, pipewire will complain that the node is ignoring the
configured graph rate.

We should really look at the graph target rate/quantum and only produce
a buffer when it is inside the current graph cycle. This would make it
possible to join audio and camera nodes and have them be in sync.
2023-03-27 09:59:21 +02:00
Barnabás Pőcze
934ab3036e treewide: use SPDX tags to specify copyright information
SPDX tags make the licensing information easy to understand and clear,
and they are machine parseable.

See https://spdx.dev for more information.
2023-02-16 10:54:48 +00:00
Wim Taymans
cfb226b0fb v4l2: improve debug
Add device path to debug lines.
2022-11-14 11:22:53 +01:00
Wim Taymans
ccf2891070 v4l2: fix buffer amount check
When we get buffers from the driver, check if we have at least as many
as we requested. If we have more, that's ok, we will simply not queue
them.

Previously we would ignore the input number of buffers and use the
allocated amount to fill up the buffer array, which might be too small
and then we crash.
2022-11-04 13:10:55 +01:00
Wim Taymans
74447acedb Add some more format checks
The format parse functions don't really check if the parsed values
make any sense so we need to to this ourselves.
2022-11-03 13:10:32 +01:00
Wim Taymans
71d58e6445 v4l2: implement setting controls 2022-10-31 11:33:45 +01:00
Wim Taymans
df094b3649 v4l2: recycle buffers when no io area
When there is no io area to place our buffers, recycle them immediately.
Otherwise we would run out of buffers and stall.
2022-10-24 13:16:08 +02:00
Wim Taymans
a57602cc4d v4l2: remove unused forward declaration 2022-10-24 13:15:42 +02:00
Wim Taymans
9b6e504c19 clean up some more array iterations 2022-10-03 09:20:42 +02:00
Michael Tretter
a745374232 v4l2: fix port param enumeration for devices without controls
It is valid for V4L2 devices to not implement any controls. QUERYCTRL
returns ENOTTY in these cases. Enumerating the controls must not fail in
these cases but return no controls.
2022-06-24 12:16:05 +00:00
Michael Tretter
edd41d8259 v4l2: close v4l2 device on error
The device needs to be closed when the enum_controls function is exited,
but is not closed if the VIDIOC_QUERYCTRL fails. Fix it.
2022-06-24 12:16:05 +00:00
Wim Taymans
7e4f99512f v4l2: cast varargs to the right type
The controls have 64 bits but the int varargs expect an int value, which
is not always 64 bits.

See #2400
2022-05-27 13:30:07 +02:00
Wim Taymans
2f5bba112f spa: Improve PropInfo fields
The PropInfo either has a registered id (and then also a name from the
type-info) or a custom name as a string.
In all cases, the description contains a free form text that clarifies
the property.

Use the description in the stream controls name.
2022-03-30 17:09:08 +02:00
Wim Taymans
57b3fe537e v4l2: handle discrete and stepwize frame size enumeration 2021-10-14 10:15:34 +02:00
Wim Taymans
865635ef10 v4l2: use log topic 2021-10-03 12:12:09 +02:00
Barnabás Pőcze
f5d51162c4 treewide: mark things static and const
Mark some structures, arrays static/const at various places.
In some cases this prevents unnecessary initialization
when a function is entered.

All in all, the text segments across all shared
libraries are reduced by about 2 KiB. However,
the total size increases by about 2 KiB as well.
2021-06-30 14:44:08 +02:00
Wim Taymans
d6a569620c v4l2: DmaBuf and MemFd are mostly the same
If the caller asks for MemFd, pass a DmaBuf because it is mostly
the same for v4l2.

Not very correct but it's not yet trivial to fall back to memfd.
And this way we have something to give to the clients that will work
when the client asks for MemFd or MemPtr.
2021-06-28 14:55:05 +02:00
Wim Taymans
1a0ad3d688 v4l2-utils: only allocate MemPtr when requested 2021-05-06 10:16:21 +02:00
Wim Taymans
941620b733 v4l2: don't expose the internal fd
When allocating memory, just export the mmaped memory and mark the
memory as MemPtr, not MemFd. Set the fd to -1.

Otherwise we might send this fd to the client, making the complete
device accessible to the client.
2021-05-06 09:24:27 +02:00
Wim Taymans
44f49a3ea0 v4l2: add some more debug 2021-05-05 11:23:44 +02:00
Wim Taymans
9c8a578e21 v4l2: don't select DmaBuf when the type mask is invalid
an invalid data type mask means that the caller did not explicitly
allowed DmaBuf so fall back to memptr or memfd.

Fixes #1054
2021-04-15 20:42:11 +02:00
Wim Taymans
af092a9a7e v4l2: respect allowed data types
Check if we can do DmaBuf as the data type before we attempt this.
Otherwise we don't get any data in clients that can't deal with
DmaBuf.
2021-01-21 16:04:37 +01:00
Wim Taymans
bd4663b3cc v4l2: log open/close as info 2020-12-09 17:24:54 +01:00
Wim Taymans
9639f32db5 v4l2: zero some structures before ioctl 2020-09-29 17:06:53 +02:00
Wim Taymans
ced338ad7d v4l2: mmap the buffer again
Some drivers need a mmaped buffer...
2020-09-29 17:06:24 +02:00
Wim Taymans
ed1ee3f164 v4l2: detect driver reusing buffers
Some drivers seem to only use 2 buffers when asked for 16 buffers. We
can see this because the buffer is already queued. In this case, just
use the 2 buffers.

See #294
2020-09-29 12:33:14 +02:00
Wim Taymans
9f1d84e37c v4l2: in alloc buffer, don't mmap, just pass the fd
If we can't use EXPBUF, just put the fd and mapoffset in the buffer
memory. This way we can pass the fd to the client and let it mmap .
2020-09-27 17:07:29 +02:00
Wim Taymans
59990ea049 v4l2: fall back to mmap when EXPBUF fails
If EXPBUF returns and error, try to mmap instead.

Fixes #294
2020-09-27 16:30:51 +02:00
Wim Taymans
cce8f3fb08 v4l2: improve debug 2020-09-27 16:30:06 +02:00
Wim Taymans
7a2741c9e1 v4l2: do TRY_FMT on the filter format
Do a TRY_FMT on the filter format before enumerating the sizes with it
because some drivers don't check the format anymore.

Fixes #294
2020-09-19 13:32:47 +02:00
Wim Taymans
ff4a314022 use fstat when we can
This avoids having things change between the stat and open.
2020-05-20 15:24:25 +02:00
Wim Taymans
42af40675d v4l2: mark data CORRUPTED
We need to mark the data corrupted in the chunk, not buffer flags.
2020-05-09 19:38:16 +02:00
Wim Taymans
8dcd6c4417 improve debug 2020-05-09 19:21:55 +02:00
Wim Taymans
1ca7713057 implement NEAREST flag
when the NEAREST flag is set and the param could not be completely
set, set_param should return 1 to indicate this.
2020-05-08 17:52:30 +02:00
Wim Taymans
12b8e095c7 v4l2: log error when format doesn't match 2020-05-08 17:35:57 +02:00
Wim Taymans
aafd1e7298 improve debug
Improve log so that debug level 3 gives a reasonably readable overview
of what is going on.
2020-04-22 12:47:18 +02:00