Commit graph

1178 commits

Author SHA1 Message Date
Wim Taymans
5b436abef7 pod: improve compare function
Use the area to compare two rectangles. Use the width to break a tie.

This way the sorting is at least a bit more predictable and independent
of the order of the arguments.
2025-07-22 14:19:08 +02:00
Wim Taymans
495d6ba796 pod: remove some size checks
These are already done by the caller.
2025-07-22 14:09:10 +02:00
Wim Taymans
e91c541446 pod: disable padding when in body
Disable the padding to pod alignment for everything when we are building
the body of an array or choice.

This makes it possible to use bytes or strings or any other pod of a
fixed size as entries in arrays or choice.
2025-07-22 13:58:11 +02:00
Wim Taymans
b904cb14a9 pod: do size check before calling type/size/data functions
Assume that all the functions that take a type/size/data from a pod have
at least the right number of bytes in the data for the given type.
Callers need to ensure this.

Fix the callers of such functions to always make sure they deref a pod
type/size/body into something of at least the min size of the type.
2025-07-22 13:14:17 +02:00
Wim Taymans
0a52f959ac pod: add a function to return the min size of a type 2025-07-22 13:13:05 +02:00
Wim Taymans
a03bbc79fe pod: fix compilation 2025-07-22 12:20:05 +02:00
Demi Marie Obenour
05bd4547d0 pod: parser: avoid unneeded integer division
SPA_POD_CHOICE_N_VALUES involves an integer division, which is slow.
Replace it with subtraction and comparison.

No functional change intended.
2025-07-22 10:19:33 +00:00
Wim Taymans
da1d4fb30c pod: also check choice size before cast
Do a more thorough test of the choice type by not only checking the type
but also if the size is at least large enough to be able to cast it to
the pod_choice type and look at the contents.
2025-07-22 12:14:06 +02:00
Wim Taymans
ed7398a64a pod: use _deref and _frame in safe place
In the filter, don't _deref or use _frame before we are going to add
more pods to the builder. If we are using a dynamic builder, the
dereffed pod might become invalid when the memory is reallocated.

Instead, take the offset of the frame and deref later when we are not
going to add more things.
2025-07-22 10:06:07 +02:00
Wim Taymans
ff7fb675f1 pod: avoid overflow in _frame() 2025-07-22 09:43:50 +02:00
Wim Taymans
36f288f884 pod: require at least 1 choice value in _can_collect()
We can't collect the choice value when there is none so check for the
number of choice values in _can_collect() as well.
2025-07-21 10:14:39 +02:00
Carlos Rafael Giani
eb3d14053d doc: spa: Add more docs about SPA_IO_Clock and driver operations 2025-07-16 10:58:48 +02:00
Wim Taymans
da9bd36cbb spa: return before entering the error branch
In the normal case we should not go into the error path.
2025-07-15 14:51:24 +02:00
Demi Marie Obenour
b04da87e38 pod: check that choices are not empty
Before using the contents of a choice, check that it is not empty to
avoid reading out of bounds.
2025-07-15 10:13:18 +02:00
Demi Marie Obenour
d37bdf5cbf pod: check for NULL strings in tag utils
SPA_POD_String allows SPA_TYPE_None PODs and turns them to NULL, so
check for them.
2025-07-15 10:13:18 +02:00
Demi Marie Obenour
edef57f6c3 pod: avoid modulo by 0
a % b is undefined behavior if b is 0.
2025-07-15 10:13:18 +02:00
Demi Marie Obenour
fb315b9050 *: Missing bounds checks in POD handling
There were missing bounds checks for ill-formed POD all over the place.
2025-07-15 10:13:17 +02:00
Demi Marie Obenour
7ac94f1a69 pod: ensure strings are NUL-terminated before calling strlen()
SPA_TYPE_String needs to be NUL-terminated, so check that in
spa_pod_compare_value().
2025-07-15 10:13:17 +02:00
Barnabás Pőcze
331bb2f1ed spa: debug: SPA_TYPE_Id is unsigned
The underlying type of `SPA_TYPE_Id` is `uint32_t`, so access
and print it as such.
2025-07-12 19:52:43 +00:00
Barnabás Pőcze
49d9d5e618 spa: param: video: add missing type info for color params
Add the missing type info for:

  * SPA_FORMAT_VIDEO_colorRange
  * SPA_FORMAT_VIDEO_colorMatrix
  * SPA_FORMAT_VIDEO_transferFunction
  * SPA_FORMAT_VIDEO_colorPrimaries
2025-07-12 21:18:23 +02:00
Wim Taymans
a188f1d29f pod: remove alignment checks
We currently often create pods in a uint8_t buffer, which is not aligned
to 8 and might cause deref and other problems.

We should either align the buffer we write into or maybe make the
builder add some padding before the buffer to align it. We have to be
careful with that when we assume the buffer start is the beginning of
the pod..

Fixes #4794
2025-07-10 16:56:26 +02:00
Demi Marie Obenour
b3bf5be1f6 *: Avoid macros that use casts where possible
Use direct field access when the type is known, instead of a macro that
includes a cast.

These were missed in e4fcbef89a.
2025-07-10 14:02:55 +00:00
Barnabás Pőcze
5cf84fa3fe spa: debug: pod: print custom properties with more detail
Previously, custom object properties were printed as "unknown",
and the offset (wrt. `SPA_PROP_START_CUSTOM`) was not displayed.
A custom property is distinct from an "unknown" one. Being able
to quickly differentiate the two is useful. Furthermore, knowing
the custom property id (i.e. the actual numeric id minus
`SPA_PROP_START_CUSTOM`) is also very helpful.

To address the above, print a custom property (i.e. anything with
an id at least `SPA_PROP_START_CUSTOM`) as follows:

  Spa:Pod:Object:Param:Props:Custom:123

where the last component is the custom property id.
2025-07-10 14:01:50 +00:00
Barnabás Pőcze
4a92ec35a6 spa: debug: pod: use the appropriate format specifiers
Use the appropriate format specifiers wrt. the signedness of the type,
as well as use the `PRI*N` macros for the `[u]intN_t` types.
2025-07-10 14:01:50 +00:00
Wim Taymans
d3eb06ab74 pod: improve array copy function
Make a new function to also returnt he child size and type.

Make a new function that accepts the array item size. Check that the
array item size and destination item size match before memcpy the array
contents. This avoids overflowing the target array with a malformed
array pod.
2025-07-08 10:11:11 +02:00
Wim Taymans
ce2f9eebb4 pod: avoid checking size or alignment
For the embedded children, they will always be aligned. We can also
avoid the max size checks for children because this is already checked
for the parent and with the remaining size check.

For arrays and choice we simply don't get any elements in the array when
the sizes are too large.
2025-07-08 10:06:51 +02:00
Wim Taymans
289b33281f pod: check size before getting pod contents
Before accessing the pod contents, check if the size is at least what we
expect it to be or else we might read out of bounds.
2025-07-07 19:40:24 +02:00
Wim Taymans
5f4b4b02f9 pod: remove the ALIGNED from the pod struct
We don't really want to do this here otherwise structs that include a
pod will be padded so that an array of those structs will be aligned.

This makes a test case fail where we have a struct with a choice_body
followed by 3 uint32_t enum values. The size with and without the
aligned attribute is different.
2025-07-07 12:07:05 +02:00
Wim Taymans
a0f5c4153f builder: avoid oveflow 2025-07-07 10:38:56 +02:00
Wim Taymans
8554c9d02a pod: enforce max pod size
Set a max pod size and add some more over and underflow checks
2025-07-07 10:38:56 +02:00
Wim Taymans
2011474936 pod: improve type checks some more 2025-07-07 10:38:56 +02:00
Demi Marie Obenour
e4fcbef89a pod: Improve type-safety in SPA POD code
Use direct field access when the type is known, instead of a macro that
includes a cast.
2025-07-07 10:38:56 +02:00
Wim Taymans
aa2289a25b pod: check pod alignment
Make a SPA_POD_ALIGN = 8 and make sure all pods are aligned to it. Use
the new constant to pad and check alignment. Make some new macros to
check for the pod type, alignment and minimal size.
2025-07-07 10:38:56 +02:00
Wim Taymans
b75ed93e51 pod: improve spa_pod_from_data()
spa_pod_from_data() is now safe against integer overflow.
2025-07-07 10:38:56 +02:00
Michael Olbrich
6294cbeb68 spa: add helper to determine if a video format is RGB 2025-06-27 12:57:01 +00:00
Michael Olbrich
20cdc9155f spa: video/color: add some more transfer functions and color primaries 2025-06-27 12:57:01 +00:00
Michael Olbrich
4c5e3f9015 spa: video/color: drop 'since' comments
These are GStreamer versions that make no sense here.
2025-06-27 12:57:01 +00:00
Pauli Virtanen
64f2f38ec4 bluez5: support LC3-24kHz HFP codec available on some Apple devices
Add support of HFP codec used on eg Apple AirPods 3+, transporting LC3
mono @ 24kHz
2025-06-13 22:15:29 +00:00
Wim Taymans
c1b5fb19ea spa: add volume_ramp_scale enum type info
And link it to the SPA_PROP_volumeRampScale property
2025-06-13 10:06:09 +02:00
Wim Taymans
c2eb173fdc spa: make the wave, pattern and ditherType Int
Properties of type Id should have a type of the enum with the possible
values associated with them.

The other types that don't have a fixed enumeration but are usually
mapped to some constant/description with PropInfo should be Int.

Fixes !2399
2025-06-13 10:06:09 +02:00
Wim Taymans
2393be4543 spa: add SPA_LATENCY_INFO_UNSET
Add a initializer for an unset latency info. Use this for combining
latency info.
2025-06-12 12:12:28 +02:00
Wim Taymans
190d49d874 loop: add docs about the locking 2025-06-10 18:00:01 +02:00
Wim Taymans
88963e9a9c Revert "loop: deprecate the hooks"
This reverts commit 550ec8c2a4.

Before hooks are still useful when integrating other fds in the pipewire
main loop.
2025-06-10 13:08:45 +02:00
Wim Taymans
550ec8c2a4 loop: deprecate the hooks
They were mostly useful for locking and unlocking but since that is
builtin right now, we should remove those eventually.
2025-06-10 12:01:20 +02:00
Wim Taymans
8e32afb863 loop: don't call the hooks around blocking wait
The hooks were previously used to unlock the loop but now that the
lock is handled inside the loop itself and we don't unlock before the
blocking read anymore, we should also not call the hooks.

The blocking invoke function is not meant to be called with any of the
loop context locks acquired in order to avoid a deadlock. Make this (and
other blocking risks) clear in the documentation.

See #4472
2025-06-10 11:57:38 +02:00
Arun Raghavan
56c6e19f99 Revert "spa: loop: Change get_time() timeout to unsigned"
This reverts commit c515f9bf8e. The PW
APIs use int64_t (partly because SPA_NSEC_PER_SEC is an LL), and we
don't want to change already public API.
2025-06-03 15:20:15 +05:30
Arun Raghavan
c515f9bf8e spa: loop: Change get_time() timeout to unsigned
A signed value doesn't really make sense in this context, so let's keep
it unsigned so the semantics are clear. This does break the interface,
but should be okay since it's not in a release yet.
2025-06-03 09:39:30 +00:00
Wim Taymans
38a3ebdca1 adapter: use the right default when filtering default
We should prefer the value of the follower when fixating to the
PortConfig format.

To make this actually work we need to be able to check if the value is
within the configured ranges. Implement the check for all types by
simply comparing the memory. This should then work also for checking
arrays, such as channel positions.
2025-06-03 11:35:59 +02:00
Carlos Rafael Giani
abb55697c1 spa: Add SPA_IO_CLOCK_FLAG_DISCONT 2025-06-02 10:04:13 +00:00
Carlos Rafael Giani
5dd65dccf3 spa: Improve spa_io_clock flags documentation 2025-06-02 10:04:13 +00:00