Commit graph

214 commits

Author SHA1 Message Date
Wim Taymans
dbc5c81e4a spa: avoid using SPA_AUDIO_MAX_CHANNELS
Use SPA_N_ELEMENTS instead of the array we try to handle.
2025-10-21 16:05:33 +02:00
Wim Taymans
818d1435ce treewide: access the position information using helpers
Make sure we don't access out of bounds and that we use the helpers
wherever we can to access the position information.
2025-10-21 13:06:25 +02:00
Wim Taymans
0915ed8be0 adapter: enhance converter flags with follower flags
We don't want to override the converter flags with the follower flags,
just enhance them with specific follower flags. Otherwise we lose the
DYNAMIC_DATA and other port flags from the converter.

See #4918
2025-10-01 11:03:53 +02:00
Wim Taymans
f1e1f720bf adapter: fix Start of adapter
Commit cbbf37c3b8 changed the logic of the
Start command. Before this commit, when there was no converter, the
follower would always get the Start command. After the commit, the
follower would only get Start when previously Paused.

This however breaks when we set a format or buffers on the follower
without a converter because those actions might change the state of the
follower to Paused implicitly.

We should simply remove the started check here and always call Start on
the converter and follower, the implementations themselves will keep track
if anything needs to be done.

Fixes #4911
2025-09-24 12:36:13 +02:00
Wim Taymans
1e5a938e43 adapter: disable rate_match for the video adapter
We don't actually implement this for the video adapter. We should
ideally check for the SPA_IO_RateMatch param to decide this..
2025-09-09 15:10:12 +02:00
Carlos Rafael Giani
67711e899c audioadapter: Add more log lines 2025-07-16 10:58:48 +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
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
Wim Taymans
e126f9bcbf adapter: only clear the NEED_CONFIGURE flag when mode != none
As long as we are in the 'none' PortConfig mode, we set the NEED_CONFIGURE
flag.

This fixes early start in audioadpter nodes because PortConfig is set to
none at init time and this used to clear the NEED_CONFIGURE flag, which
would start the node before the session manager could to a PortConfig
and cause a -22 error.
2025-05-27 15:38:51 +02:00
Wim Taymans
548fa0ec48 adapter:handle -ENOENT when enumerating buffers
When the follower has no buffer suggestion, it can return -ENOENT, which
should not generate an error but simply use the converter buffer
suggestion instead.
2025-05-27 15:00:43 +02:00
Wim Taymans
417a72365e adapter: negotiate from target to follower
Now that the filter functions prefer the filter default value, use the
target object as a filter for buffer allocation as well.
2025-05-27 09:30:52 +02:00
Wim Taymans
12f8ca664b adapter: log command errors when no converter 2025-05-20 10:42:59 +02:00
Wim Taymans
b80189c3dd adapter: handle -ENOTSUP for commands
When using custom commands, the converter might return -ENOTSUP and
we should ignore this.
2025-05-19 17:23:30 +02:00
Wim Taymans
399ff82ab2 adapter: always negotiate from convert to follower
Make the converter format a higher priority in all cases. The converter
has been negotiated first and is able to make a better suggestion for
the ideal format in all cases.
2025-05-05 10:33:07 +02:00
Wim Taymans
14eb03a821 videoconvert: Enumerate follower params better
Make sure we increment the next counter even when we are in passthrough
mode or the property is not readable.
2025-05-05 10:31:37 +02:00
Wim Taymans
5c547d58d1 adapter: handle builder overflow 2025-04-02 10:39:34 +02:00
Wim Taymans
da69bddb95 adapter: Improve convert setup
Always do configure_convert, even when the passthrough state didn't
change, for example when going from none to convert.
2025-04-01 16:31:25 +02:00
Wim Taymans
1adc9e5445 videoadapter: init the builder for each param
Or else we keep on adding items until we overflow.
2025-04-01 16:24:40 +02:00
Wim Taymans
abc03ec810 adapter: fix buffer alloc order
Prefer to let the follower allocate buffers. If we are allocating
buffers, first do use_buffers on the allocating node or else the
non-allocating node just ends up with NULL buffers.
2025-03-27 09:29:52 +01:00
Wim Taymans
ea7cfb9e94 audioconvert: make sure the converter is in None mode
The audioconverter starts in Convert mode, so make sure it goes to the
None mode before we attempt to reconfigure ourselves.

Also remove the ports on audioconvert when going to None mode. This used
to somewhat work because we configured it in DSP mode without any
params, which is like None without ports.
2025-03-26 10:26:41 +01:00
Wim Taymans
beb075c5a6 adapter: only use DYNAMIC buffer data when supported 2025-03-26 09:51:09 +01:00
Wim Taymans
6015fa353a adapter: call reconfigure_mode instead of configure_convert
configure_convert does not set up the current mode, so call the more
complete reconfigure_mode to set the initial converter mode.
2025-03-26 09:43:58 +01:00
Wim Taymans
7e67daa292 audioadapter: negotiate formats from output to input
Try to avoid conversions by taking the output port format and using that
as a filter for the input port format.

Because filtering pods prefer the values of the filter, this will prefer
the output format values and thus avoid conversions.
2025-03-24 11:39:20 +01:00
Wim Taymans
4e421e0012 audioadapter: return error code from set_param 2025-03-14 13:26:21 +01:00
Wim Taymans
110d8572c0 audioadapter: fix EnumPortConfig without converter
If we don't have a converter, we always work in passthrough mode and
EnumPortConfig can use the same code as PortConfig in all cases.

See !2265
2025-01-28 12:39:31 +01:00
Wim Taymans
ce31e66fb7 audioadapter: only add/remove port when passthrough changed
We only need to switch between the converter ports and the follower port
when we switch between passthrough. Avoid emiting remove of the (non
existing) follower ports when the mode changes from none to DSP at startup.
2025-01-27 10:20:55 +01:00
Arun Raghavan
43f148677e spa: audioadapter: Enum follower formats first in convert mode 2025-01-26 18:58:36 -05:00
Arun Raghavan
beb81e8f4e spa: audioadapter: Explicitly track port mode
Will be useful for convert-mode-specific EnumFormats.
2025-01-26 18:52:51 -05:00
Wim Taymans
b72eed8f03 audioadapter: don't emit result events for internal param enums
All of the _sync param enum calls are internal end should not result in
a result event externally.

See !2260
2025-01-25 16:34:35 +01:00
Arun Raghavan
980d37fb80 audioadapter: Trivial whitespace fix
Makes an annoying clang warning about mismatched indents.
2025-01-21 10:47:14 -05:00
Wim Taymans
d2c2276088 adapter: pass follower direction to converter
Partially revert 86af9de739

The PortParam does not give enough information to derive the direction
of the converter. If the converter is configured in convert/convert
there is just no way to know when to output a quantum or not.

Fix this by doing a quick probe of the follower and then pass the
direction to the converter.

See !2227
2025-01-21 11:43:11 +01:00
Wim Taymans
8cd3fc6922 adapter: increase max-retry to 64
When the follower doesn't produce enough data for this many attempts,
bail and cause an xrun to avoid an infinite loop.

The limit of 8 cause real-life problems and should be larger. It should
probably depend on the expected size per cycle (node.latency) and the
current quantum but we don't always have this information.

See #4334
2024-10-07 09:28:39 +02:00
Wim Taymans
563186eff6 adapter: also forward the RequestProcess events 2024-09-16 17:01:50 +02:00
Wim Taymans
ce390d5b22 spa: add spa_json_object_next
This gets the next key and value from an object. This function is better
because it will skip key/value pairs that don't fit in the array to hold
the key.

The previous code patter would stop parsing the object as soon as a key
larger than the available space was found.
2024-09-16 09:50:36 +02:00
Wim Taymans
cd81b5f39a spa: add spa_json_begin_array/object and relaxed versions
Add spa_json_begin_array/object to replace
spa_json_init+spa_json_begin_array/object

This function is better because it does not waste a useless spa_json
structure as an iterator. The relaxed versions also error out when the
container is mismatched because parsing a mismatched container is not
going to give any results anyway.
2024-09-16 09:50:33 +02:00
Wim Taymans
5c2b5fa552 audioadapter: clear the handle as well to avoid leaks 2024-09-09 13:42:44 +02:00
Wim Taymans
ffed9763fd audioadapter: improve convert plugin loader
Use the converter in the current plugin when no plugin loader was given
to make the unit tests work.
2024-09-09 13:26:45 +02:00
Wim Taymans
4d2cdd6da3 audioadapter: dynamically load the audio converter
So that we can plug in other implementations. Also handle the cases
where we can't load a converter.
2024-09-06 17:30:58 +02:00
Wim Taymans
b4c8627a62 audioadapter: improve format negiotiation
First try to pass the format of the converter directly into the
follower. This allows us to avoid conversion when it can be avoided.

Iterate all follower formats (not just the first one) to find something
that intersects with the converter formats.
2024-09-06 15:08:31 +02:00
Wim Taymans
9fb14be4e3 adapter: improve format parsing some more 2024-09-06 15:06:31 +02:00
Wim Taymans
c5a7f30a68 audioadapter: use generic audio format parsing
We don't need to use the raw audio format parsing functions, we can use
the more generic audio ones. This avoids some extra parsing for the
media type and subtype and will support compressed audio formats
as well when the converter handles this.
2024-09-06 14:46:34 +02:00
Wim Taymans
f6803d4c03 audioadapter: pass the config mode around
When we are working in convert mode, configure the converter to convert
mode as well instead of DSP.
2024-09-06 11:20:25 +02:00
Wim Taymans
7036fc76e0 audioadapter: handle port flags better
Save the convert and follower port flags and use them in buffer
allocation.
2024-09-05 12:26:30 +02:00
Wim Taymans
cbbf37c3b8 audioadapter: move some checks around
Move the check for the follower==target to the negotiate functions.

Refer to the target when doing operations. The converter reference
is just some internal element that may or may not be active at the
moment. If we have multiple converter elements, the current active
one will be in target.
2024-09-02 15:18:29 +02:00
Wim Taymans
82e4b9a213 audioadapter: remove redundant statement
The same check is done a little later.
2024-09-02 11:51:40 +02:00
Wim Taymans
61dcd8dede audioconvert: set IO_Buffers only when buffers are negotiated
The IO_Buffers is used in the data thread to check if the port should be
scheduled or not. Make sure it is only set after we set buffers on the
port and cleared before the buffers are cleared.

Make sure we sync the port->io with the data thread.

See #4094
2024-07-29 18:15:06 +02:00
Wim Taymans
e1e0a886d5 stream: improve async handling
We can remove most of the special async handling in adapter, filter and
stream because this is now handled in the core.

Add a node.data-loop property to assign the node to a named data-loop.

Assign the non-rt stream and filter to the main loop. This means that
the node fd will be added to the main-loop and will be woken up directly
without having to wake up the RT thread and invoke the process callback
in the main-loop first. Because non-RT implies async, we can do all of
this like we do our rt processing because the output will only be used
in the next cycle.
2024-04-18 15:20:07 +02:00
Wim Taymans
d24a80c9d5 audioconvert: handle port remove
The info is NULL when the port is removed, don't crash on that.
2024-02-28 11:28:22 +01:00
Wim Taymans
2c0bb6ffd2 audioadapter: recheck formats when EnumFormat changes
When the follower has new EnumFormat, make sure we recheck the formats
the next time the node is started.
2024-02-19 15:10:32 +01:00
Wim Taymans
223d016a5e audioadapter: clear buffers when format is reconfigured
Always clear the Buffers when the format is reconfigured because they
depend on the Format.
2024-02-19 15:09:41 +01:00