Commit graph

59 commits

Author SHA1 Message Date
Barnabás Pőcze
a1cc0f3d86 spa: libcamera: source: rework bool control type info
`SPA_POD_CHOICE_Bool()` assumes that both true and false are available,
which may not be the case for libcamera controls, so manualy construct
the enumerated choice object and only add the actually available options.

(cherry picked from commit 66cc01ee2d)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
f6d3db72a1 spa: libcamera: source: move control enumeration to loop
Remove the `goto`s and instead move everything into a loop.

(cherry picked from commit 44c05cfa7b)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
eb6b9a47fc spa: libcamera: source: separate type info generation
Add a new function `control_details_to_pod()` that builds a
`SPA_TYPE_OBJECT_PropInfo` object describing a libcamera control.

(cherry picked from commit cc187b035b)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
19d9bb7219 spa: libcamera: source: create eventfd before starting camera
An eventfd is used to signal the data loop from the libcamera request
completion event handler. Previously, this eventfd was created and
installed after the camera has been started and requests were queued.

This is problematic because it creates a small time frame where the
libcamera request completion handler will run in a state where the
eventfd is not fully set up.

Fix that by settup up the eventfd before the camera is started.

(cherry picked from commit e0e8bf083d)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
21a61b2194 spa: libcamera: source: generate camera config right away
Currently the plugin uses a single configuration during its entire lifetime.
So generate that configuration during initialization and hold on to it.

This makes the code a bit simpler, and also fixes issues stemming from missed
calls to `spa_libcamera_get_config()` as well as no error checking of
`libcamera::Camera::generateConfiguration()`.

(cherry picked from commit 49be2a1c52)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
1774249bdb spa: libcamera: source: remove SPA_PROP_device{,Name}
`SPA_PROP_deviceName` is an empty string and setting it does nothing.

`SPA_PROP_device` is always the libcamera identifier of the camera,
and setting it has no effect whatsoever in contrast to other plugins
such as v4l2.

So remove them both for now.

(cherry picked from commit 8c4f60af48)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
47aacb2a84 spa: libcamera: source: do not close fd
Currently the plugin does not support importing memory and uses
`libcamera::FrameBufferAllocator` to allocate memory. Every file
descriptor is managed by that object, so they must not be closed
manually.

(cherry picked from commit 429c0e03a3)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
192eab1fea spa: libcamera: source: remove unused enum_fmt member
This was introduced by b2c38a2b3b ("libcamera: work on rewrite"),
but it has never been used.

(cherry picked from commit c167b98ff2)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
a080a4a6f2 spa: libcamera: source: prop_id_to_control(): do range check first
If it is a custom spa property, it will not be found in the lookup
table, so we can return immediately.

(cherry picked from commit 30ce210c2a)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
b775acca60 spa: libcamera: source: fix mapping of libcamera::ColorSpace::TransferFunction::Linear
`SPA_VIDEO_TRANSFER_GAMMA10` should be used to represent a
linear transfer function.

Fixes: 7e202a3844 ("spa: libcamera: add colorimetry support")
(cherry picked from commit 07a4e593bb)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
db23d9fa04 spa: libcamera: source: simplify color space conversion
Instead of using an out parameter, just return the `spa_video_colorimetry`
object; and do the libcamera -> spa conversion in a single place, where
the data is actually added to the pod.

(cherry picked from commit 938195b19f)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
e770ed42c3 spa: libcamera: source: avoid iterator overrun when enumerating controls
Do not overrun the iterator when skipping the initial couple items.
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
0749851cfe spa: libcamera: use nullptr instead of NULL
(cherry picked from commit db3d91ebeb)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
a5ba04a8ba spa: libcamera: use C++ style casts
(cherry picked from commit 4fa11619a2)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
ea67bf1662 spa: libcamera: use anon ns instead of static
Move most things into anonymous namespaces for internal linkage
instead of using `static`. This shortes declarations and makes it
hard to forget.

(cherry picked from commit bb8223bff1)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
c22d9127e1 spa: libcamera: source: inline mmap_init()
The function has a single caller is essentially just a wrapper only
calling `mmap_init()`. So inline it into `spa_libcamera_alloc_buffers()`.

(cherry picked from commit e19a8bb5cd)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
5f77c729c2 spa: libcamera: source: set "corrupted" flag if applicable
If the libcamera `FrameMetadata` reports anything other than `FrameSuccess`,
then set `SPA_META_HEADER_FLAG_CORRUPTED`, notifying the application that
the frame may be unusable.

(cherry picked from commit 561a9d6ebb)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
7414d948ad spa: libcamera: source: use union for transferring control value
Use a union since only one member is active at a time, and use the
proper `libcamera::ControlType` enum to store the type instead of a
bare number. Also remove an unnecessary cast.

(cherry picked from commit 0022fc90b7)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
8181e2e051 spa: libcamera: source: simplify control mapping
Remove the `impl` parameter as it is not used, and use C++ range
based for loops.

(cherry picked from commit f94f4de6ff)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
bf1c57928b spa: libcamera: source: do not make expensive queries multiple times
`StreamFormats::pixelformats()` and `StreamFormats::sizes()` both
return newly created `std::vector`s, so do not call them multiple
times.

(cherry picked from commit 311b3cc37f)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
bdf904ebad spa: libcamera: source: simplify format lookup
Use range based for loops instead of indices.

(cherry picked from commit 489cc49937)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
d1eb5f6d20 spa: libcamera: source: use enum types
Use the appropriate enum types instead of bare `uint32_t`,
this provides better type safety in C++.

(cherry picked from commit 0ea7dc9f19)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
3dd413e131 spa: libcamera: source: handle camera acquire failure
Check the return value of `Camera::acquire()` and return the error
if that fails.

(cherry picked from commit f53ac8d57c)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
a233905f75 spa: libcamera: inline libcamera-utils.cpp
The file is not useful without `libcamera-source.cpp` because it
uses symbols only defined there. And being a non-self-contained
source file, it also breaks clangd. So move its contents directly
to `libcamera-source.cpp`. This makes the file about 2200 lines long,
but I feel that is still manageable (and it is by far not the longest).

(cherry picked from commit 1a1cf55efb)
2025-09-26 09:58:10 +02:00
Barnabás Pőcze
60d95e447a spa: libcamera: clean up includes
Remove some unnecessarily includes.

(cherry picked from commit 5a9cdd724f)
2025-09-19 05:35:47 +02:00
David Turner
8094cdf846 libcamera: Default to auto-focus & auto-exposure
libcamera says that cameras should default to manual focus mode.  This
means that unless pipewire clients specifically change this control,
users with an autofocus-capable camera are left with an out-of-focus
image.  This patch sets the autofocus mode to continuous and enables
auto-exposure (as the default for this is unspecified).

Testing with an imx708 on Raspberry Pi OS on a Raspberry Pi 4, before
this patch the image was generally out of focus in Firefox/webrtc, after
this patch autofocus works correctly.

(cherry picked from commit 3a0ffe21e6)
2025-09-19 05:34:37 +02:00
Wim Taymans
9207fea992 libcemara: take care of index offset when enumerating controls
Add an index offset when enumerating controls. We insert 2 properties
before enumerating the controls so the index of the first control needs
to have an offset of 2.
2025-05-20 10:53:55 +02:00
Wim Taymans
41e35c7b17 v4l2: use dll to track rate difference
Track the difference between the configured and real framerate and use
that as the rate correction to adjust the next_nsec clock field.
2024-11-26 17:14:26 +01:00
Wim Taymans
043245ca11 v4l2: set the NO_RATE clock flag
These sources have very inaccurate position/duration/rate information
that is not suitable for use as a clock so set the NO_RATE flag.
2024-11-26 17:05:20 +01:00
Elliot
d67882fa10 libcamera: allocate memory according to the number of discontiguous memory 2024-10-30 15:20:21 +00:00
Wim Taymans
9d1d1fcbef impl-port: add port.group property
Can be used to group ports together. Mostly because they are all from
the same stream and split into multiple ports by audioconvert/adapter.

Also useful for the alsa sequence to group client ports together.

Also interesting when pw-filter would be able to handle streams in the
future to find out what ports belong to what streams.
2024-06-24 13:38:09 +02:00
Barnabás Pőcze
55fafe8f0b spa: libcamera: remove two unused members 2024-05-15 08:31:03 +00:00
Barnabás Pőcze
da1dbc1120 treewide: fix C++20 compilation error wrt. designated initializers
C++20 introduced designated initializers similar to the ones found
in C99, however, in C++ designated initializers cannot be mixed
with non-designated initializers. GCC rejects mixed initializers
with an error.
2024-05-03 07:16:57 +00:00
Wim Taymans
e4cee8eec2 libcamera: add latency param query
JACK queries this unconditionally but it's a good idea to implement this
like v4l2-source.
2023-11-20 17:51:27 +01: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
f472fd736d fix includes
Only include debug we need. We usually only need the debug types.
2023-01-18 13:12:16 +01:00
Robert Mader
714b438814 libcamera: Check format info for correct flags and modifier 2023-01-12 11:22:25 +00:00
Wim Taymans
afedd107a8 Revert "video: Add extra field indicating if modifier value is valid"
This reverts commit 1e6920c33b.

Causes an ABI break.
2023-01-11 12:21:42 +01:00
Robert Mader
1e6920c33b video: Add extra field indicating if modifier value is valid
The drm format modifier value `0` is actually `DRM_FORMAT_MOD_LINEAR`,
a commonly used modifier. Unfortunately there appears to be no value
that can savely used as placeholder for "no value", as e.g.
`DRM_FORMAT_MOD_INVALID` is often used to indicate an implicit modifier.

Thus add an extra field that clearly indicates whether the modifier
value is set or not, add it to the util fuctions and use it for the
current only user, the libcamera backend.

Fixes 5a6da7d5e1

Closes https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/2943
2023-01-10 22:01:31 +01:00
Wim Taymans
97aafe2234 fix use_buffers checks
We can set 0 buffers even if there is no format.
Return -ENOSPC when too many buffers are set.
2023-01-10 12:30:25 +01:00
Robert Mader
fa799aac86 libcamera: Implement SPA_META_VideoTransform support
libcamera can detect camera transforms/rotation, e.g. from the device
tree, and makes that information usable for clients via
`CameraConfiguration::transform`.
Advertise this information via the VideoTransform meta so Pipewire
clients can adjust their output accordingly.

Rotated cameras are common in mobile devices such as the Pinephone Pro,
which was used to test this feature.
2022-12-05 18:25:36 +01:00
Wim Taymans
bf8981ef61 libcamera: fix setting controls
Use the set_control function of v4l2 and libcamera also to set
properties from a sequence.
2022-11-14 11:22:53 +01:00
Wim Taymans
f6d7d4372b libcamera: add Format to node params as well 2022-11-08 16:24:27 +01:00
Wim Taymans
e0c0d9806f libcamera: clear format info
Or else we end up with invalid data for the fields that did not get
initialized when parsing the format param.
2022-11-02 17:14:01 +01:00
Wim Taymans
51e8ff7d8e libcamera: add EnumFormat param to the node 2022-11-02 10:35:48 +01:00
Wim Taymans
ef4b9745b2 libcamera: handle canceled requests
When a request is canceled, recycle it so we don't run out of buffers.
Implement getting and setting controls.
2022-10-31 19:03:55 +01:00
Wim Taymans
0396ca4931 libcamera: let the session manager set pause-on-idle 2022-10-25 20:27:14 +02:00
Barnabás Pőcze
f9796fc024 spa: libcamera: remove unnecessary typedef 2022-09-15 11:17:47 +00:00
Barnabás Pőcze
02f2d6b48d spa: libcamera: remove unnecessary have_config member
An extra flag is not needed because the `config` pointer can be
checked to determine if a configuration has already been retrieved.
2022-09-15 11:17:47 +00:00
Barnabás Pőcze
9374c15c3d spa: libcamera: use std::optional intead of separate bool flag + value
`std::optional` conveniently encapsulates a value and a bool flag,
so use that instead of manually replicating it.
2022-09-15 11:17:47 +00:00