Commit graph

13351 commits

Author SHA1 Message Date
Pauli Virtanen
5f21ee8669 audioconvert: add delay_frac to spa_io_rate_match
Report the "fractional" part of the resampler delay in
spa_io_rate_match::delay_frac, in nanosamples (1/1e9 sample) at node
rate.

The delay values are best reported in units where it is clear what the
clock domain is, so report the value in fractional samples instead of
nanoseconds. Conversion to ns is also just dividision by the appropriate
rate.
2025-01-19 17:11:13 +02:00
Pauli Virtanen
f3a9ebd569 audioconvert: resampler: change resample_phase() unit to input samples
Report fractional delay in input samples instead of nsec at the nominal
input rate, as that is closer to what the value actually means.
2025-01-19 17:11:13 +02:00
Wim Taymans
9889d1ce0a alsa: close the sequence on error. 2025-01-19 15:56:01 +01:00
Wim Taymans
e4fc8d43bb alsa: handle error from _set_client_midi_version()
See #4507
2025-01-19 15:52:48 +01:00
Pauli Virtanen
eb91f097d9 audioconvert: resampler: fix off-by-one issues
Resampler without prefill was sometime outputting with different delay
than with prefill. Adjust initial history by 1 which seems to bring it
more in line.

The resampler phase also appears to depend on how many samples remain in
history which leads to possibly unexpected +-1 variation. Take this into
account in reported phase.

These changes make the resampler delay tests pass.

Both changes are sort of empirical --- I don't fully understand why
these would fix things but they seem to be needed to make the delay
calculations agree with what the resampler outputs.
2025-01-17 19:10:43 +02:00
Pauli Virtanen
79384530b5 audioconvert: resampler: add more resampler delay tests
Test also conversions between different rates, and with and without
prefill.
2025-01-17 19:10:43 +02:00
Pauli Virtanen
07f6dde3dd audioconvert: add function to get phase to resampler API
Support getting any fractional phase part of the resampler delay in its
API.
2025-01-17 19:10:43 +02:00
Wim Taymans
d36a867788 gst: only return the custom flag when in _render()
Make a custom ACQUIRE flag and if it's set, return the custom error
when the pool is empty.
2025-01-17 17:08:07 +01:00
Wim Taymans
c7ccc5abca gst: handle blocking in the _render() function
When we do any other blocking in the render function, we should unblock
and call _wait_preroll() when we go to PAUSED.

We can have this situation when all the buffers are queued in the
pw_stream and we get a new _render() call. We can't get more buffers
from the pool and so we must block and wait.  When we go to PAUSED we
need to unlock and go to _wait_preroll(). Implement this by setting a
pool paused flag that is set when the sink goes to paused, we can then
return a special value that does the wait_preroll().

See !2248
2025-01-17 16:33:15 +01:00
Wim Taymans
85c5d65c97 audioconvert: only consume from input what the resampler used
Keep track of the consumed samples from the input and use that to update
the in_offset. The resampler can tell us how much samples were used.
2025-01-17 12:20:06 +01:00
Wim Taymans
c81910a51c gst: use gst_buffer_get_size() to get the buffer size
_get_sizes() contains the padding and we don't want to copy that.
2025-01-17 12:19:07 +01:00
Taruntej Kanakamalla
86e7429039 gst: pipewiresink: don't flush bufferpool in PLAYING_TO_PAUSED
Setting bufferpool to flushing state in PAUSED state is preventing the
buffer flow if there is a seek/flush event.
Instead, set the bufferpool to flushing during the `flush-start` event
and clear it during the `flush-stop`

Deactivate/activate the stream during flush event only if the sink is
in the PLAYING state. In the PAUSED or READY state, the stream would be
inactive and we do not want to alter that
2025-01-17 13:03:34 +05:30
Wim Taymans
c62905d911 pulse-server: clear old data when jumping forwards
When we write samples, check if we make a jump in the ringbuffer and
clear the samples we jumped over.

If we don't do this, the reader side might pick up old samples that we
didn't write or clear but that are now available for reading after we
made a jump in the ringbuffer.

This migh not be exactly what pulseaudio does but it is good for now.

Fixes #4464
2025-01-16 16:21:22 +01:00
Wim Taymans
cf7e917024 pulse-server: make a function to silence a buffer 2025-01-16 16:16:39 +01:00
Taruntej Kanakamalla
c0a6a7ea32 gst: handle flush event in pipewiresink
flush the pw buffers to the stream's queue during a FLUSH_START event
and return the unqueued pw buffers, if they are dropped/released without
being rendered, so they can be available to be dequeued for the subsequent
`acquire` calls
2025-01-15 17:03:21 +00:00
Taruntej Kanakamalla
b70e99c41a stream: new api to return unused buffer
Push the buffer back to `dequeued` in case of playback and capture.
This will help avoid starvation during events like seek/flush
2025-01-15 17:03:21 +00:00
Wim Taymans
f914cf9327 audioconvert: the delay of the resampler is in input rate
The resampler needs ntaps/2-1 (delay) input samples to produce 1 output
sample so the delay is measured in input rate.
2025-01-15 17:02:39 +01:00
Wim Taymans
0913b3ef7b audioconvert: report delay in input rate
The delay is always expressed in samples at the output rate of the
resampler. For input streams we need to convert this to the expected
input rate.

Make the delay reporting in playback streams more accurate.
2025-01-15 15:25:49 +01:00
Wim Taymans
24bcacc619 conf: remove client-rt.conf
We now automatically move non-rt clients into non-rt threads so the
client-rt.conf is obsolete.

Move the module-rt in client.conf and add conditions to disable modules.

Transparently load client.conf in case applications still specify
client-rt.conf.

Custon configuration in the client-rt.conf.d/ should be moved to
client.conf.d/
2025-01-14 12:40:05 +01:00
Pauli Virtanen
b952cfbe38 bluez5: remove resampler delay fudge factor
The resampler delay was off by one sample, so remove the corresponding
fudge factor here.  This matters for BAP output synchronization.

The resampler has also some fractional delay, so there can still be
sub-sample offset between the original and resampled timelines.  This is
not currently taken into account.
2025-01-13 19:05:58 +02:00
Pauli Virtanen
2c2bed2aeb audioconvert: fix resampler delay value and add test
Resampler delay for N taps is N/2-1 input samples.

Add test that checks this.

When input rate is varying, the resampler also accumulates additional
sub-sample delay. The resampler does not currently have API to report
the instantaneous sub-sample delay.  Add knownfail test for it.
2025-01-13 19:05:58 +02:00
Wim Taymans
049ab37a6d audioconvert: only deactive old filter when new filter loaded
When we fail to load the new filter, keep the old filter active or else
we will cause a crash when we clean up the old graph.
2025-01-13 16:58:28 +01:00
Wim Taymans
0868ff1ada math: improve denormal check
Use isnormal() when we can
2025-01-13 16:10:34 +01:00
Wim Taymans
73e11eea46 audioconvert: add wav stage only when needed 2025-01-13 15:39:32 +01:00
Pauli Virtanen
08700a9eb5 pipewire: use local real time timestamps in logging
Wireplumber and other system services use local real time timestamps in
logging, so it's more convenient if also PW uses them.

Add env var for selecting the timestamp type, default to "local".
2025-01-13 13:48:22 +00:00
Pauli Virtanen
1ec814977c logger: support logging local timestamps and other timestamp logs
In timestamps, support different clocks and local time as formats.

Local real time timestamps are useful when trying to correlate logs from
different sources.
2025-01-13 13:48:22 +00:00
Philippe Normand
13c869801c gst: core: Fixup connection error handling
Commit b57b5703d6 made use of `spa_strerror()`
which is incorrect here because pw_connect sets `errno`, so we should use
`strerror()`.
2025-01-12 11:42:29 +00:00
Philippe Normand
b57b5703d6 gst: core: Properly report connection errors 2025-01-12 11:15:04 +00:00
Pauli Virtanen
b9e130fd8c spa: alsa: do not allow setting Route that is not in current profile
When setting Route param, check that the route actually is part of the
active profile.

Also, check that the device given corresponds to the given route, before
setting properties. acp_device_set_port() also checks this, but we
shouldn't allow updating properties of Routes in non-active profiles.

Setting ports or applying props on devices not part of the profile can
do unexpected things e.g. alter mixer settings.
2025-01-12 11:13:47 +00:00
Pauli Virtanen
7d8657b7f4 audioconvert: recalculate stages on volume change
Volume changes may change mix passthrough status, so force stage
recalculation when they are done.
2025-01-11 16:13:11 +02:00
Sanchayan Maity
fc102e517a bluez5: g722: Fix format specifiers for log
This fixes build failure on 32-bit systems.
2025-01-10 13:24:23 +05:30
Pauli Virtanen
65f6e5ffa7 bluez5: clean up ASHA transport handling
Don't mix endpoint and transport paths, they're generally different.

If ASHA transport already existed, free the old one but not the device,
as the ASHA device existence should track how it appears in DBus.
2025-01-09 22:15:03 +00:00
Arun Raghavan
19c15e2e90 meson: Correctly use fallback for webrtc-audio-processing
If system deps are not found, we need to fallback to
webrtc-audio-processing-2, not webrtc-audio-processing (i.e. 0.3).

Fixes: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/4493
2025-01-09 15:33:32 -05:00
Wim Taymans
1030000890 network-utils: handle inet_ntop errors 2025-01-09 16:28:51 +01:00
Wim Taymans
2093fb2071 NEWS: add all releases to main NEWS file 2025-01-09 16:17:36 +01:00
Sanchayan Maity
b1e4799ea6 bluez5: Ensure codec_id comparison is against codec of right type
G722 codec id for ASHA is chosen arbitrarily to be different from
A2DP and BAP codec IDs. ASHA spec does not specify a codec ID like
A2DP/BAP.

In places where codec_id comparisons are done, ensure that the check
is done against the codec of the right type viz. A2DP/BAP/ASHA.
2025-01-09 14:51:50 +00:00
Sanchayan Maity
c7496c847f bluez5: asha/g722: bump media_codec version 2025-01-09 14:51:50 +00:00
Sanchayan Maity
e83f01a33b bluez5: Clean up ASHA implementation 2025-01-09 14:51:50 +00:00
Sanchayan Maity
13c026417b bluez5: Implement support for ASHA
ASHA is a Bluetooth specification for hearing aids.

For a high level overview of the ASHA Specification for BlueZ.
https://asymptotic.notion.site/ASHA-Spec-for-Bluez-61a46027fd46458d8235e14d6bedb2ce

The original specification in Android.
https://source.android.com/docs/core/connect/bluetooth/asha

Corresponding support in BlueZ.
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/profiles/audio/asha.c

This only implements handling of one side of a ASHA device
pair. Stereo support/handling of both "left" & "right" side
will follow later requiring work on clock synchronization
between the pair.
2025-01-09 14:51:50 +00:00
Sanchayan Maity
41d099a580 bluez5: Add G722 codec for ASHA
For documentation on ASHA, see
https://source.android.com/docs/core/connect/bluetooth/asha
2025-01-09 14:51:50 +00:00
Sanchayan Maity
6a5f2bbd1f bluez5: media-sink: Log need_flush in flush_buffer 2025-01-09 14:51:50 +00:00
Arun Raghavan
71e403bbdb spa: aec: Add support for webrtc-audio-processing-2 2025-01-09 12:06:58 +00:00
Barnabás Pőcze
3752535171 hook: avoid macro expansion of the method names
Fixes #4491
2025-01-09 12:57:23 +01:00
Wim Taymans
509e769aa5 core: inherit the default.clock.quantum-limit from the server
Copy the server value to the context so that the locally allocated
buffers match the server quantum-limit and we don't cause xruns because
of too small buffers.

See #4490
2025-01-09 11:38:07 +01:00
Wim Taymans
48416b32ad audioconvert: improve Buffer params
Make sure we only make the buffer for the follower larger when we
downsample because then we need to ask for more data from the follower
to fill up a quantum.

Never try to make the follower buffer smaller than the quantum limit.
The reason is that the graph rate could be decreased dynamically and
then we would end up with too small buffers.

See #4490
2025-01-09 11:30:02 +01:00
Wim Taymans
feaa36560d pulse-server: increase max rate to 768000
Fixes #4482
2025-01-08 17:23:15 +01:00
Wim Taymans
3a65472e9e audioconvert: add support for filter-graphs
Load multiple graphs with audioconvert.filter-graph.N where N is the
order where the graph is inserted/replaced. Run the graphs before the
channelmixer.

Graphs can be added and removed at runtime.
2025-01-07 13:20:31 +01:00
Wim Taymans
1f4e8b96c2 audioconvert: fix remap stages
Merge remap with convert to simplify some things.
2025-01-07 12:58:59 +01:00
Wim Taymans
c00df67c12 audioconvert: schedule work offline
Instead of recalculating what to do every cycle, we can prepare a
static schedule and just run that. We only need to reevaluate it when
something changes.
2025-01-07 12:58:55 +01:00
Wim Taymans
3fbf84f612 audioconvert: run resampler depending on direction
For input streams, first run the resampler and then the channelmix. This
ensures that the channelmix is run with the rate of the graph instead
of the rate of the input. This is nicer because rate and quantum align
with the graph and the sample accurate volume ramps will work as
intended.

For output streams, leave the resampler after the channelmix for the same
reasons.
2025-01-07 12:03:59 +01:00