Commit graph

36 commits

Author SHA1 Message Date
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
Wim Taymans
3131acea46 alsa-seq: close seq device
When we unload, close the seq device again so that the source is
removed from the main loop.
2019-11-28 11:21:41 +01:00
Wim Taymans
d94019ccd2 io: Add current video frame size to position
Add some padding, tweak some padding
Remove count in the clock, it's useless
For video frames we will want to use metadata to place
this on individual buffers.
2019-10-29 14:08:40 +01:00
Wim Taymans
9ffec214b8 fix includes 2019-10-25 15:01:02 +02:00
Wim Taymans
fa25900682 alsa-seq: fix for being a slave 2019-10-22 12:24:04 +02:00
Wim Taymans
b37bf7e068 alsa-seq: ask for more data when consumed 2019-10-16 10:44:40 +02:00
Wim Taymans
93a2defbb8 alsa-seq: reset buffers 2019-10-02 18:02:40 +02:00
Wim Taymans
6e0ffb0c47 flags: change flag macros
SPA_FLAG_CHECK -> SPA_FLAG_IS_SET
SPA_FLAG_UNSET -> SPA_FLAG_CLEAR
Add SPA_FLAG_UPDATE
2019-10-02 18:00:42 +02:00
Wim Taymans
44840c4a55 alsa-seq: add some comments 2019-09-26 15:17:00 +02:00
Wim Taymans
f539b42a03 alsa: improve midi
Add some debug
Ignore ports without buffers.
2019-09-26 11:57:25 +02:00
Wim Taymans
8d472befaa alsa-seq: Improve connection setup 2019-09-25 10:48:25 +02:00
Wim Taymans
f0b3ed5257 alsa-seq: improve timings
Track the position of the clock instead of our own timer.
Implement stop.
2019-09-25 10:14:25 +02:00
Wim Taymans
387b281f5c alsa-seq: use dll to track queue timer
Also increase timer resolution to get less jitter.
2019-09-24 17:23:39 +02:00
Wim Taymans
818fb9e904 alsa: add midi bridge
Add a node that exposes all midi input and output ports and converts to
and from PipeWire control streams.
2019-09-19 16:57:00 +02:00