Commit graph

63 commits

Author SHA1 Message Date
Wim Taymans
fa1ec61cf0 profiler: add followerClock block
Add a new followerClock block in the profiler info. This is only set
when the follower could be a driver and it contains the clock info used
for following the driver, mostly the rate difference and delay.

Dump this info in pw-profiler -J

Make sure we always set the info in the clock, especially also when we
are following.
2024-10-09 11:31:54 +02:00
Wim Taymans
ce89ce304d alsa: fix compilation wirh -UFASTPATH 2024-07-30 09:53:14 +02:00
Wim Taymans
94bb5a2dd2 alsa: add UMP support
Use the new UMP alsa sequencer API to make it produce UMP packets.

Set the alsa sequencer to MIDI2.0, which will make it convert all
messages to MIDI-2.0 UMP automatically. We can copy this straight into
the control buffers.

This also solves some problems with large sysex messages that are now
nicely split into chunks with UMP.
2024-07-30 09:38:40 +02:00
Wim Taymans
1ae4374ccf Fix compilation with -Werror=float-conversion
Better make the conversions explicit so that we don't get any surprises.

Fixes #4065
2024-06-18 12:17:56 +02:00
Wim Taymans
37224ac84c alsa-seq: configure pool sizes better
The default kernel pool size on the input is 200 cells. A cell is
about 28 bytes long so the maximum message that can be received in one
go is about 5600 bytes. This causes problems when using amidi to upload
larger sysex messages because they simply can't be received by the
sequencer.

It if however possible to increase this limit with the set_client_pool()
function. Increase the pool size to at least the quantum_limit * 2.
This ensures we can receive and send at least 2 quantums of raw data,
which should be a fairly long sysex message.

Make a min and max value for the pool size. There is an upper limit of
2000 in the kernel but make this configurable and clamp the final
pool size to the min/max.

Make the MAX_EVENT_SIZE 256, because this is how the sequencer seems to
splits the input data as well and it results in less wasted space in the
output buffer.

See #4005
2024-05-13 15:25:52 +02:00
Wim Taymans
ea0ba1162e alsa-seq: warn when receive fails
This can happen when allocation fails or the message is too long.
2024-05-13 15:17:21 +02:00
Wim Taymans
89edb9f6c5 control: use quantum_limit for midi buffer size
Instead of the arbitrary default.
2024-05-10 11:49:31 +02:00
Wim Taymans
7e87bd9b34 alsa-seq: try to not overflow the output buffer
Keep some room in the output buffer to store the worst case event
and save it for the next cycle.
2024-05-10 11:33:44 +02:00
Wim Taymans
e897a8afc4 control: warn when we overflow the control buffer 2024-05-09 19:33:30 +02:00
Wim Taymans
cb8330c798 alsa-seq: handle large control events
Handle the case where the control event is large and needs to be
encoded into multiple midi events.
2024-05-09 18:49:00 +02:00
Wim Taymans
7dcfe81690 alsa-seq: improve midi encode some more
snd_midi_event_encode() will reset the encoder when it returns an
encoded event. It is possible that the function returns with an encoded
event when the internal buffer is full, in that case we need to push the
event and continue encoding without reseting the encoder.

0 is not a snd_midi_event_encode() error, so don't handle it like
one.
2024-05-09 18:32:14 +02:00
Wim Taymans
1c056661b6 alsa-seq: handle fragmented midi messages
The messages, mostly sysex, can be split over multiple control message.

This happens when we read large messages from the sequencer, the
snd_seq_event_input function returns split messages that we transfer to
control messages directly.

When we send those messages out, however, the encoder wants the complete
message before it will return a valid event that we can send out. Keep
on calling the encoder with the control events until we get a complete
message that we can send out.

Fixes #4005
2024-05-09 16:18:29 +02:00
Wim Taymans
758805d65d alsa: fix rate matching in the sequencer
The alsa sequencer rate matching was not actually working correctly.
It would compare the previous queue time with the current time and
compare that to the quantum. This would include uncorrected errors from
jitter and would result in the timeouts being scaled in the wrong
direction forever.

Instead, calculate an ideal queue time and compare our current queue
time against that. We then use the correction to scale the timeout or
the next queue time prediction.

Also use the predicted time as the base time for the event timestamps.
this results in less jitter.

Fixes #3657
2023-12-05 15:12:27 +01:00
Wim Taymans
c153f39720 alsa: reset dll when we reprogram the timers 2023-12-05 15:11:01 +01:00
Wim Taymans
7b6680ba57 plugins: simplify target_ handling
Drivers should only read the target_ values in the timeout, update the
timeout with the new duration and then update the position.

For the position we simply need to add the previous duration to the
position and then set the new duration + rate.

Otherwise, everything else should read the duration/rate and not use
the target_ values.
2023-03-24 11:36:15 +01:00
Wim Taymans
6e8625cf96 node: update the duration/rate from the target
Before scheduling the graph from the driver, update the duration and
rate with the new targets.
2023-03-23 18:39: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
f44d55f6c2 handle read from timerfd correctly
When reading the timerfd gives an error, we should return right away
because the timeout did not happen.

If we change the timerfd timeout before reading it, we can get -EAGAIN.
Don't log an error in that case but wait for the new timeout.
2022-12-09 17:30:31 +01:00
Pauli Virtanen
e96b0ed4a8 alsa: minor fixes in seq code
port_enum_params should use right param id for SPA_PARAM_Format.

Fix typoed , instead of ; at end of line. Pop frame before putting
state.offset, in case there would be padding added (apparently usually
no).
2022-11-08 09:33:56 +00:00
Wim Taymans
71879961db alsa-seq: avoid division by 0
Make sure the rate in the state is updated in all cases and make sure
that it never has anything with a 0 in it to avoid division by zero.
2022-10-21 13:15:36 +02:00
Wim Taymans
4c1115cf1d alsa-seq: attempt to get more data in timeout
Also emit the NEED_DATA status so that the graph will pull in new
midi data even when we don't output anything.

Fixes #2775
2022-10-20 17:44:42 +02:00
Wim Taymans
54b499b1cf alsa: do the right log level checks
spa_log_level_enabled does not work when a custom log level has
been set. Use spa_log_level_topic_enabled instead.
2022-08-05 15:03:22 +02:00
Wim Taymans
a13f65f583 alsa-seq: disable the running status
Running status is not something we want in the PipeWire graph.
2022-06-20 16:18:42 +02:00
Wim Taymans
25d9039f2e alsa-seq: handle midi event decoder errors 2022-06-20 16:12:49 +02:00
Wim Taymans
40f50deae9 alsa: remove NoteOn 0-velocity fixup
Pass MIDI events as they are.

JACK requires NoteOn 0-velocity midi events to be patched to NoteOff
events for compatibility with LV2 plugins. Let's do this patchup in
the JACK layer then and add an option to disable it.

It's best to pass the midi messages unmodified and then patch them up
wherever they need patching up.
2022-06-20 15:51:33 +02:00
Wim Taymans
1bf1497855 spa: mode dll to utils 2022-03-30 17:22:26 +02:00
Wim Taymans
dfdd9a6b3b alsa: don't prefix NAME, log topics are enough 2021-10-03 08:05:40 +02:00
Peter Hutterer
e9d869b46f spa: implement a log topic for alsa 2021-09-28 09:35:39 +02:00
Wim Taymans
92f35b99a0 alsa: don't mix process return and alsa err
Use a separate error field for the alsa errors, we already use the res
field for the process result.
2021-09-20 12:24:09 +02:00
Wim Taymans
d793086174 alsa-seq: fix port delete
We need to first mark the removed port as invalid, and then look for the
last valid port in the port array otherwise last_port becomes 0 and
midi dataflow stops.

Fixes #1601
2021-09-14 18:08:30 +02:00
Wim Taymans
c54f64cd13 alsa: clean up rate matching code
Remove some useless fields.
Use macros for time<->rate conversions.
2021-09-06 12:55:06 +02:00
Wim Taymans
034dd00813 alsa-seq: use better clock rate matching
Match the elapsed queue time against the elapsed graph time.
2021-09-02 18:37:27 +02:00
Wim Taymans
c2c7dd040a alsa: CLAMP the error just in case something goes wrong.
The calculation of the elapsed time is actually not a good idea because
it becomes larger and larger and a tiny change in the rate could result
in a large difference that would make things fail quickly.

Until that is fixed, this patch will need to do..
2021-09-02 17:31:02 +02:00
Wim Taymans
0b758a2301 alsa-seq: fix off-by-one for event offset
The event offsets need to go from 0 to quantum-1 to be valid to the
current midi event buffer.

Fixes #1395
2021-07-05 16:25:11 +02:00
Konstantin Kharlamov
ed9560fb03 alsa: fix "now.tv_sec maybe used uninitialized" warnings
Fixes a number of warnings that look like this:

    In file included from ../spa/include/spa/utils/result.h:37,
                     from ../spa/plugins/alsa/alsa-seq.c:35:
    In function ‘set_timers’,
        inlined from ‘do_reassign_follower’ at ../spa/plugins/alsa/alsa-seq.c:909:2:
    ../spa/include/spa/utils/defs.h:191:39: warning: ‘now.tv_sec’ may be used uninitialized [-Wmaybe-uninitialized]
      191 | #define SPA_TIMESPEC_TO_NSEC(ts) ((ts)->tv_sec * SPA_NSEC_PER_SEC + (ts)->tv_nsec)
          |                                   ~~~~^~~~~~~~
    ../spa/plugins/alsa/alsa-seq.c:840:28: note: in expansion of macro ‘SPA_TIMESPEC_TO_NSEC’
      840 |         state->next_time = SPA_TIMESPEC_TO_NSEC(&now);
          |                            ^~~~~~~~~~~~~~~~~~~~
    ../spa/plugins/alsa/alsa-seq.c: In function ‘do_reassign_follower’:
    ../spa/plugins/alsa/alsa-seq.c:836:25: note: ‘now’ declared here
      836 |         struct timespec now;
          |                         ^~~

The reason for these warnings is that spa_system_clock_gettime() may
fail if a version check fails, but the code in question didn't check for
the possible fail. If it failed, then execution would continue, and the
arguments that were passed to the macro will be used uninitialized.

Fix this by checking whether function succeeded.
2021-06-22 22:42:25 +03:00
Wim Taymans
5b2b256ecd alsa: initialize reserve array 2021-03-30 09:40:10 +02:00
Wim Taymans
149471631e alsa: use higher ports for listening
Allocate up to the first 16 ports, use the last 2 ports and free the
first 14 ports.

This ensure our ports are not among the first ports so that port 128
and following are for normal apps, what is usually expected when
PipeWire is not running.

Fixes #951
2021-03-29 17:05:03 +02:00
Wim Taymans
b07bfd0661 alsa: fix dll handling
Pass the right value for the rate, we need to pass the graph rate.
Don't reduce bandwidth, it is not needed.

Fixes timings for reading the alsa-sequencer.
2021-03-14 21:42:17 +01:00
Wim Taymans
d776a0917d alsa: refactor dll code 2020-12-09 12:09:40 +01:00
Wim Taymans
7d88c37e5b alsa-seq: clear the midi event queue on close to avoid leak 2020-06-02 17:13:53 +02:00
Wim Taymans
a19bab4b16 avoid following NULL pointers 2020-05-20 15:24:25 +02:00
Wim Taymans
8dcd6c4417 improve debug 2020-05-09 19:21:55 +02:00
Wim Taymans
995fafa5be alsa-seq: remove the queue for system announce port
The announce messages are not put in a queue so we don't need
to allocate one (and a timer). Without the timer, we avoid wakeups
and consume less power.

See #225
2020-05-06 11:19:46 +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
Wim Taymans
74665de68e alsa-seq: keep track of last port
Keep track of the last port and only iterate until that port.
2020-03-31 17:52:22 +02:00
Wim Taymans
e6675ff2a8 alsa-seq: unsubscribe when paused/suspended
When we are suspended or paused, unsubscribe from the ports so that
we don't block the hardware devices.

See #225
2020-03-31 12:14:52 +02:00
Wim Taymans
a528189d26 slave -> follower
We use master/follower terminology everywhere.
2020-02-21 10:47:32 +01:00
Philipp Zabel
cb1071bce7 alsa-seq: fix seq_open error path
If snd_seq_open fails, do not call snd_seq_close(NULL).
2020-02-07 19:07:14 +01:00
Wim Taymans
50ce87df32 node: we are supposed to produce data when != HAVE_DATA
We can produce data whenever the io area status != HAVE_DATA. We
don't need to look for NEED_DATA.
Also recycling buffer happens whenever the status != HAVE_DATA.
2020-02-04 12:59:16 +01:00
Wim Taymans
9657486a81 alsa-seq: update duration when slaved as well 2019-12-18 13:27:29 +01:00