Commit graph

191 commits

Author SHA1 Message Date
Wim Taymans
41e937e3fd alsa: add some more debug 2022-09-09 16:33:01 +02:00
Wim Taymans
009e61f585 alsa: improve debug 2022-09-09 12:22:08 +02:00
Wim Taymans
4593ac4113 alsa: pass bool argument properly 2022-09-01 10:18:55 +02:00
Wim Taymans
3215b58bae alsa: save volumes
Instruct the session manager to save the volumes when set with the
ALSA ctrl API.
2022-09-01 09:43:10 +02:00
Wim Taymans
565c385228 alsa: add lock around sw_params
The stream and data is protected with the lock.
2022-07-06 13:46:54 +02:00
Lucas Holt
6a15a02ec2 Add support for MidnightBSD
Fix build issue

Fix build issue
2022-06-19 18:22:47 +00:00
Wim Taymans
b1578ee109 alsa: avoid allocation 2022-05-16 09:36:14 +02:00
Robert Rosengren
cd389240fa alsa-plugin: use ioplug sw_params callback
snd_pcm_sw_params states "The software parameters can be changed at
any time.". Adding the ioplug callback sw_params to get relevant
updates, and if min_avail has changed update the node latency of
the stream.

Ignoring callback received prior to prepare as stream not yet created.
2022-05-16 09:33:01 +02:00
Wim Taymans
61d318125e move PIPEWIRE_PROPS to stream and filter
Make all streams and filters handle PIPEWIRE_PROPS.
The order for applying stream/filter properties is:

1) application provided properties.
2) generic config.
3) match rules.
4) environment variables (PIPEWIRE_PROPS, ...) from generic to
   more specific.
5) defaults.
2022-04-22 09:37:21 +02:00
Quentin Wenger
22fc9eec35 Cleanup argument names in methods and events interfaces
First method argument is object, first event argument is data.

Closes !963
2022-04-15 10:11:49 +02:00
Wim Taymans
5a9d2679ca stream: add pw_stream_get_time_n()
Deprecate pw_stream_get_time() in favour of _get_time_n() that contains
the size of the pw_time structure. Make the old one fill in the fields
up to the buffered field. Make the new one use the size to decide how
much info to fill in.

Add a new buffered field in pw_time that contains the buffered data
inside the converter/resampler. This leaves the queued field with
purely the user provided size in the buffers.

Use get_time_n() in places.
2022-03-29 17:30:38 +02:00
Wim Taymans
7e42c905a8 remove the rate_match io
Now that the stream provides us with a requested size, we don't need to
use the rate_match anymore.
2022-03-29 09:57:49 +02:00
Wim Taymans
c46113faa3 json: spa_json_get_string() writes up to len chars or fail 2022-01-04 10:42:32 +01:00
Wim Taymans
35cbe4e939 buffers: make alignment optional
Make the alignment parameter optional when negotiating buffers.
Default to a 16 bytes alignment and adjust for the max cpu
alignment.
Remove the useless align buffer parameter in plugins, we always
set it to 16 anyway.
2022-01-03 12:32:26 +01:00
Wim Taymans
c1a0a602a5 alsa-plugin: do correct boundary check
The hw_ptr must be wrapped at the boundary value, not after.

See #1941
2021-12-22 20:03:13 +01:00
Jonas Holmberg
6aeb640e31 tests: Add pipewire-alsa stress test
Add test that opens, prepares and closes the alsa pcm device in several
threads simultaneously in an infinite loop.
2021-12-15 16:13:08 +01:00
Wim Taymans
e75282d0f5 alsa-plugin: clip offset and size in capture
Be a bit more careful with the offset and size in the buffer and make
sure we clip them according to the maxsize.
2021-11-25 12:32:24 +01:00
Wim Taymans
955dde5272 alsa-plugin: use hw_avail in _delay for playback
for playback streams we want to include the hw_avail, which is the amount of
data that the hardware can read or the amount of data the application has
written.

This is in contrast to using _avail for the capture stream, which is
what the application can read. hw_avail for a capture stream is how many
samples the hardware can write or the amount of free space.

See #1697
2021-11-24 13:12:23 +01:00
Wim Taymans
743cced63e alsa-plugin: improve debug 2021-11-24 12:40:02 +01:00
Wim Taymans
301e729864 alsa-plugin: fix delay reporting
The delay should be calculated based on the amount of samples available
to the application, not the hardware.

This overreported the delay.

See #1697
2021-11-24 12:24:29 +01:00
Wim Taymans
d8e24fca1c alsa-plugin: don't rate match for capture streams
For capture streams we can simple copy the complete pipewire buffer into
the alsa pcm ringbuffer to make it available for the application.
2021-11-24 12:24:29 +01:00
Wim Taymans
33f087d4db alsa-plugin: don't clamp elapsed time to stream delay
There is no reason to limit the elapsed time to the stream delay, it is
possible that it is larger and then it will be clamped later.
2021-11-24 12:24:29 +01:00
Wim Taymans
6f0c5b6428 alsa-plugin: improve debug 2021-11-24 12:24:29 +01:00
Wim Taymans
5ed4977b38 destroy proxies when global is removed
When a global is removed, also remove the proxies. We can have multiple
proxies to a global otherwise when a client has a sequence of events
queued from the server like this:

Global 1 added
Global 1 removed
Global 1 added

The proxy we added in the firt event would not be destroyed because the
server did not know about it when global 1 was removed and then a
second one would be made.
2021-11-08 12:55:41 +01:00
Wim Taymans
25ddf0e3cf alsa-plugin: fix a compiler warnings 2021-11-02 17:18:58 +01:00
Martin Geier
1b96142903 alsa: do not ignore rate change when stream is already created
gstreamer alsasink can change sample while stream is already created.
In that case, gstreamer calls snd_pcm_ioplug_callback_t::stop,
snd_pcm_ioplug_callback_t::hw_params and snd_pcm_ioplug_callback_t::prepare

Add new flag to the snd_pcm_pipewire_t that is set every time
snd_pcm_pipewire_hw_params is called to prevent using stream with old
sample rate

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2021-11-02 15:37:07 +00:00
Martin Geier
a7d238ed59 alsa: increase precision of delay function
pw->time.delay is delay in number of frames in pw->time.rate domain,
however snd_pcm_pipewire_delay function is suppose to return number of
frames in io->rate domain. Convert pw->time.delay to io->rate domain to
increase precision when the io->rate is not equal to the pw->time.rate

snd_pcm_pipewire_delay should return how many frames are queued in
pipewire, pw_stream_get_time returns numbers of the queued frames before
snd_pcm_pipewire_process is called, however this function inserts (or
removes) some frames from pipewire. Therefore newly inserted (removed)
frames should be added to pw->time.delay to increase precision.

Signed-off-by: Martin Geier <martin.geier@streamunlimited.com>
2021-11-02 15:37:07 +00:00
Wim Taymans
6ebd589659 alsa-plugin: _prepare will clear the draining state
Leave the draining state when _prepare is done.

See #1467
2021-11-02 10:17:31 +01:00
Philippe Normand
cff127a138 pipewire-alsa: Fix build warning
`pos < 0` always evaluates to false, so remove this condition.
2021-10-25 07:26:15 +00:00
Wim Taymans
cefcc2e874 alsa-plugin: store the right value in last_seq
last_seq needs to contain the last received seq, not the last one that
we requested to sync on.
2021-10-08 09:21:32 +02:00
Wim Taymans
f562b16706 alsa-plugin: use log topics 2021-10-03 08:17:43 +02:00
Wim Taymans
3348fd9885 alsa-plugin: make sure we don't deref NULL
Also fixes a warning.
2021-10-01 15:33:51 +02:00
Jonas Holmberg
61a2577941 pipewire-alsa: fix a memory leak
Free node_name.
2021-09-27 11:05:34 +02:00
Wim Taymans
423e8b2f03 Revert "pipewire-alsa: Make it MT safe"
This reverts commit f22dd9d781.

Obsolete now that pw_init and factory loading/unloading has been
made thread safe.
2021-09-21 12:35:03 +02:00
Wim Taymans
64f83158f4 alsa-plugin: improve error handling and recovery
Ignore -ENOENT errors, they are likely because some device was
removed.
Make sure we clear the poll descriptor when nothing is pollable, even
in the error case.
Clear the error after we reported it instead of reporting it forever.

Fixes #1627
2021-09-20 15:48:04 +02:00
Wim Taymans
f6f10669a0 alsa: destroy stream first and then context
This makes things more deterministic.
2021-09-15 20:57:10 +02:00
Jonas Holmberg
f22dd9d781 pipewire-alsa: Make it MT safe
Make pipewire-alsa MT safe so that multi threaded programs can use it
without any extra locks.
2021-09-08 16:36:58 +02:00
Wim Taymans
7846687df8 alsa: suggest rate to graph with node.rate 2021-08-18 09:56:20 +02:00
Wim Taymans
780f2d645d alsa: enable client-rt for alsa clients
So that the pipewire thread is running with RT priority.
2021-08-09 15:28:00 +02:00
Wim Taymans
d88e8edd11 avoid shadowing arguments 2021-07-06 17:55:16 +02:00
Wim Taymans
91f4e4d3c8 alsa: catch and handle some more errors 2021-07-06 17:54:08 +02:00
George Kiagiadakis
df8bd85277 alsa-ctl: filter for and use only the "default" metadata object
Fixes #1384
2021-07-02 17:44:35 +03:00
Barnabás Pőcze
f5d51162c4 treewide: mark things static and const
Mark some structures, arrays static/const at various places.
In some cases this prevents unnecessary initialization
when a function is entered.

All in all, the text segments across all shared
libraries are reduced by about 2 KiB. However,
the total size increases by about 2 KiB as well.
2021-06-30 14:44:08 +02:00
George Kiagiadakis
5ee9133b60 alsa plugin: allow specifying a media.role on the virtual device name
So that we can do:
  aplay -D pipewire:ROLE=Music music.wav
  aplay -D pipewire:ROLE=Notification notice.wav
2021-06-22 14:48:31 +00:00
George Kiagiadakis
59407d2f08 includes: update all references to extensions to point to pipewire/extensions
This also brings the advantage that all tools, examples, modules, components
can also be compiled standalone out-of-tree using libpipewire from the system
2021-06-18 17:54:18 +03:00
Peter Hutterer
da339c286f meson.build: drop HAVE_CONFIG_H
This is an autotools leftover, with meson we're always guaranteed to have
the config.h file.
2021-06-10 09:04:16 +10:00
Peter Hutterer
0054319d88 meson.build: add -D_GNU_SOURCE to the project arguments
This appends it to every compilation command so we can get rid of the c_args
for (almost all) executables.
2021-06-09 07:47:51 +00:00
Peter Hutterer
e0471c6757 pipewire: allow NULL pointers in pw_properties_free()
Just like the real free() we should just ignore a NULL pointer, makes the
caller code easier for those instances where properties are optional.

Patch generated with concinelle with a few manual fixes.
2021-06-02 10:56:46 +00:00
Wim Taymans
5a186ece01 alsa: handle plugin errors better
When the plugins can't be loaded, we fail to make a main_loop.
Handle this case instead of segfaulting.

See #1239
2021-05-28 11:38:02 +02:00
Peter Hutterer
f3f915e897 pipewire-alsa: fix scan-build errors for unused variables
All cases of value stored but never read
2021-05-26 07:51:27 +00:00