Commit graph

9501 commits

Author SHA1 Message Date
Wim Taymans
ef39576150 alsa: rate limit some warnings 2022-09-21 15:52:24 +02:00
Wim Taymans
9632145c9a log: make some more macros
Make a macro to log at a certain level with func,line,file added.
Use the new macros to reduce some redundant arguments.
2022-09-21 15:50:41 +02:00
Wim Taymans
47f2b72088 pulse-server: don't overwrite previous towrite value
And actually take the MAX_BLOCK into account when writing samples to a
client.
2022-09-21 12:00:36 +02:00
Wim Taymans
00a234daf2 pulse-server: limit capture blocks to fragsize
Don't send larger chunks than the fragsize. Some clients don't like
this. Also checked with #2418.

Fixes #2711
2022-09-21 11:34:13 +02:00
Wim Taymans
bd584ca8c0 pulse-server: ignore adjust-latency for capture
Don't update the fragsize, it breaks #2418 again.
2022-09-21 11:34:13 +02:00
Wim Taymans
95cfb531a0 alsa: initialise the format
Otherwise the format is 0 (S8) and only S8 will be allowed.
2022-09-20 17:45:46 +02:00
Wim Taymans
7bf84fa5e2 pod: only call the overflow callback when still needed
When we are already past the size of the buffer, don't bother calling
the overflow callback anymore, the buffer is already corrupted.

Otherwise it would be possible to have the overflow callback fail the
first time around, some data will be skipped, and then the next
overflow callback would succeed, giving the impression that all is
fine.

Add a unit test for this.
2022-09-20 16:59:25 +02:00
Wim Taymans
c9753b0722 alsa: rework parameter handling
Pass the parameters around in a structure.
Add BUFFER_BYTES argument to configure the buffer size.
Add PIPEWIRE_ALSA env variable to set format, rate, channels,
period-bytes and buffer-bytes.
Add more variables in the alsa config file.
2022-09-20 16:24:21 +02:00
Wim Taymans
0ce95e69fd pulse-server: adjust_latency should update the fragsize
Rename MAX_FRAGSIZE to MAX_BLOCK because it does not really limit the
fragsize, just the amount of data we can send in one block.

See #2711
2022-09-20 13:24:30 +02:00
Wim Taymans
3faca67ffe filter-chain: instantiate the nodes when rate is known
Instantiate the graph nodes when the samplerate is known instead of
using a fixed samplerate of 48KHz.

Warn when the convolver samplerate does not match the graph rate. We
might want to resample the IR later.
2022-09-20 11:16:51 +02:00
Wim Taymans
000a6608cf context: suspend all nodes when doing rate change
Suspend all nodes of the driver, even if the driver is already
suspended.

The suspend command makes sure that all nodes renegotiate to the new
graph rate.

This fixes the following sequence of events:

1. Play 44.1KHz file to loopback sink
2. Sink switches to 44.1, negotiates to 44.1
3. Loopback input and output streams negotiate to 44.1. All is good.
4. Stop playback, wait 5 seconds
5. Sink suspends, loopback input suspends (output stream doesn't suspend)
6. Play 48KHz file
7. Sink switches to 48, negotiates to 48. Sink (and followers) don't
   suspend because sink was already suspended.
8. loopback input negotiates to 48, output stays at 44.1 -> failure

This patch fixes step 7. where it now tries to suspend all followers
even when the driver was already suspended. This then ensures that all
followers will try to negotiate to the new driver rate.
2022-09-20 10:56:31 +02:00
Wim Taymans
6b6cd85e54 filter-chain: move debug to fastpath 2022-09-19 17:03:34 +02:00
Wim Taymans
772a12acb7 filter-chain: ref the node handle location
Use a reference to the location in the node where the handle of the
plugin can be found. That way we can change the handle only in the
node and have it changed everywhere else.
2022-09-19 15:20:59 +02:00
Wim Taymans
ac67475e64 filter-chain: move data allocation out of the link loop
The port data allocation does not depend on the links so move it
out of the loop.
2022-09-19 15:17:49 +02:00
Wim Taymans
d1cd199f16 pulse-server: set record latency as fragsize / 2
The record latency is set to fragsize / 2 by pulseaudio, so do the
same in pipewire.

Fixes #2702
2022-09-19 14:45:11 +02:00
Wim Taymans
94336cb2c9 module: use resample.prefill for coupled streams
So that we always process one complete input buffer as an output
buffer without keeping leftovers in the resampler.
2022-09-19 12:51:14 +02:00
Wim Taymans
31f9e18edb audioconvert: add resample.prefill option
Add a resampler option to prefill the resampler with 0. This then
results in the resampler always outputing and consuming the same
amount of data instead of a short buffer in the beginning.
2022-09-19 12:35:49 +02:00
Wim Taymans
d48627d0e7 module-loopback: use trigger to start processing
Move process to playback_process and use trigger from the capture
side to start processing. This ensures the requested size is updated.
2022-09-19 12:34:00 +02:00
Wim Taymans
8a39b22e25 filter-chain: use trigger to start processing
Add a process_playback function and use _trigger in the process_capture
to start processing. This ensure that the requested size is updated
before calling the process function.
2022-09-19 12:14:52 +02:00
Wim Taymans
893c5aab4d stream: update requested size before calling process
We always need to update the latest requested size for output streams
before calling process. If there are no buffers or no suggestion, let
the audioconvert make one before we try again.

This way we always get the most recent requested size.
2022-09-19 12:02:14 +02:00
Wim Taymans
aca85b49ea audioconvert: set stride on output buffers 2022-09-19 12:01:24 +02:00
Wim Taymans
bdfbce8939 pw-cli: don't keep doing syncs in monitor mode
In monitor mode, we only need one sync to get the prompt and then we
just wait until we need to stop. There is no need to keep on syncing
because it consumes a lot of CPU.

Patch by Hiero32

Fixes #2709
2022-09-19 10:57:49 +02:00
Wim Taymans
26e789124f alsa: increase max periods
We can easily split the buffer into smaller periods and get a lower
latency overall.

See #1697
2022-09-17 18:59:45 +02:00
Frédéric Danis
75ae86bf13 bluez5: backend-native: Only send one error message
When rfcomm_hfp_ag() returns false, an "ERROR" reply is sent.
When testing if the SLC is configured, 2 "ERROR" replies are sent, which
should not be done.
2022-09-16 12:32:12 +02:00
Wim Taymans
9755cb9083 examples: add capture from monitor option 2022-09-16 11:38:44 +02:00
Pauli Virtanen
8de03f5c29 bluez5: support and use old api.bluez5.a2dp.* factory names for A2DP
For backward compatibility with old Wireplumber releases, support the
old api.bluez5.a2dp.sink/source names, and use them in object events
instead of the media.sink/source names.
2022-09-15 23:04:37 +03:00
Pauli Virtanen
101287159e bluez5: fix media-sink for A2DP
It's always Audio/Sink for A2DP, never stream.
2022-09-15 19:46:25 +03:00
Pauli Virtanen
13eb00fd44 bluez5: fix error in search/replace for a2dp->media
The A2DP factory source<->sink was erroneously swapped in
commit 00d51c3d31 ("bluez5: Rename codec API from *a2dp* to *media*")
2022-09-15 19:39:26 +03:00
Wim Taymans
92deb1d868 example: improve volume meter output 2022-09-15 16:35:44 +02:00
Wim Taymans
01fedfb9cd examples: add audio capture example 2022-09-15 16:05:15 +02:00
Barnabás Pőcze
83a510cba3 spa: libcamera: fix hook adding logic
Previously, if "add_listener" was called on the monitor device, then it
did not necessarily emit events about all devices because it called
`enum_devices()` which does not emit events about already existing
devices. So the very first listener would get all existing devices,
but subsequent ones would not get events about the existence of devices
that have already been seen by the monitor. Fix that by simply emitting
events about all existing devices if the current listener is not the first.
2022-09-15 11:17:47 +00:00
Barnabás Pőcze
74b66d939a spa: libcamera: do not try to acquire CameraManager if there is already one 2022-09-15 11:17:47 +00:00
Barnabás Pőcze
0f6c5a04c7 spa: libcamera: fix CameraManager event handling
libcamera's CameraManager runs the event handlers on its own thread,
thus synchronization is needed to ensure correct functionality.
Implement that by collecting hotplug events into a mutex protected queue
and signalling the main loop where they can be processed and the
"object_info" event can be safely emitted.
2022-09-15 11:17:47 +00:00
Barnabás Pőcze
f9796fc024 spa: libcamera: remove unnecessary typedef 2022-09-15 11:17:47 +00:00
Barnabás Pőcze
02f2d6b48d spa: libcamera: remove unnecessary have_config member
An extra flag is not needed because the `config` pointer can be
checked to determine if a configuration has already been retrieved.
2022-09-15 11:17:47 +00:00
Barnabás Pőcze
9374c15c3d spa: libcamera: use std::optional intead of separate bool flag + value
`std::optional` conveniently encapsulates a value and a bool flag,
so use that instead of manually replicating it.
2022-09-15 11:17:47 +00:00
Barnabás Pőcze
13357fec20 spa: libcamera: manage libcamera::CameraManager via a shared_ptr
Using a shared_ptr removes the need for manually calling
`libcamera_manager_release()` to drop the reference as it is done
automatically whenever the shared_ptr is destroyed or reset.
2022-09-15 11:17:47 +00:00
Barnabás Pőcze
330686d3aa spa: libcamera: rework construction/destruction of libcamera source impl
Move some things into constructors and try not to depend on the
fact that the storage is zero initialized, try to initialize
everything properly.
2022-09-15 11:17:47 +00:00
Barnabás Pőcze
98193f7d67 spa: libcamera: remove two unused members from libcamera source
Neither `next_fmt`, nor `next_size` were actually used, remove them.
2022-09-15 11:17:47 +00:00
Barnabás Pőcze
222368e562 spa: libcamera: properly construct/destruct libcamera manager impl
Previously, the libcamera manager `impl` object was neither properly
constructed neither properly destructed. As a consequence, for example,
the shared pointers in the `devices` array weren't properly destructed,
although this has been somewhat mitigated by a previous change
that modifed `clear_devices()`.
2022-09-15 11:17:47 +00:00
Barnabás Pőcze
cc229d4b05 spa: libcamera: properly construct/deconstruct libcamera device impl
Previously, the "impl" object was never properly constructed or
destructed, but it more or less worked out since the memory was initialized
to zero bytes and each member had trivial constructors. Except std::shared_ptr,
but an all zero storage happened to be equivalent to a default constructed
shared_ptr.

However, there was the still the problem that the shared_ptr was never
destructed, so it kept the referenced `Camera` object alive, which lead
to memory leaks.

An additional, somewhat unrelated change is that the "props" struct
is removed, and the device identifier is now stored in an `std::string`.
The reason is that `CameraManager::get()` already takes a const std::string reference,
so an std::string must be constructed in any case, so we might as well
take advantage of that and use `std::string` in the "impl" object as well.

Furthermore, wrap the `impl` struct in an anonymous namespace
to avoid name resolution problems.
2022-09-15 11:17:47 +00:00
Barnabás Pőcze
f699fa698e spa: libcamera: remove main loop from manager
The libcamera manager does not actually use the event loop
that it acquires during initialization. Remove it.
2022-09-15 11:17:47 +00:00
Barnabás Pőcze
13208220d8 spa: libcamera: print camera id when it appears/disappears 2022-09-15 11:17:47 +00:00
Barnabás Pőcze
086de7dcac spa: libcamera: properly dispose of shared_ptr
Previously, in `remove_device()`, the last device would be copied into
the slot of the to-be-remove device. The problem with this is that it
left the shared_ptr untouched in the previously last slot, and hence
creating an extra reference. Fix this by moving instead of copying.

A similar problem is present in `clear_devices()` which also
did not properly dispose of the shared_ptrs. Fix that by
calling `reset()` on each device's camera pointer.
2022-09-15 11:17:47 +00:00
Barnabás Pőcze
442a0c54ea spa: libcamera: move shared_ptr to avoid copy 2022-09-15 11:17:47 +00:00
Barnabás Pőcze
ba04a0f936 spa: libcamera: take raw pointer to avoid shared_ptr copy 2022-09-15 11:17:47 +00:00
Barnabás Pőcze
9370fbee3d spa: libcamera: indent with tabs instead of spaces 2022-09-15 11:17:47 +00:00
Frédéric Danis
fdccc10bc7 bluez5: Use SelectProperties Endpoint property to detect device role
BlueZ adds the Endpoint property to the Properties dictionary of
SelectProperties.
This allows to know which remote Endpoint is an acceptor, and so which
local transport should be used as an initiator.
2022-09-15 11:17:20 +00:00
Frédéric Danis
d4b639419a bluez5: Init BAP LC3 coder/decoder depending on direction
For LE Audio, sink and source have their own media transport endpoint.
Media sink or source only needs the coder or decoder respectively.
2022-09-15 11:17:20 +00:00
Frédéric Danis
28b4fbecfb bluez5: Manage BAP linked transports
Multiple transport from the same device may share the same stream (CIS)
and group (CIG) but for different direction, e.g. a speaker and a
microphone. In this case they are linked.
In this case:
- On acquire, if another transport has already been acquired, the new
  transport should not call Acquire or TryAcquire but re-use values from
  the previously acquired transport,
- on release, the closing of transport fd and call to Release should be
  done only for the last transport.
2022-09-15 11:17:20 +00:00