Commit graph

6989 commits

Author SHA1 Message Date
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
feaa36560d pulse-server: increase max rate to 768000
Fixes #4482
2025-01-08 17:23:15 +01:00
Wim Taymans
3cf9ccf4a7 filter-graph: handle NULL in and out
We need to pass exactly n_inputs and n_outputs pointers to the process
function but make it possible to set some to NULL so that the data is
ignored.
2025-01-07 10:42:04 +01:00
Wim Taymans
49f48a5fda filter-graph: separate data and size for filter graph
Remove the chunk and add separate arrays with data and n_samples. This aligns
better with other methods and makes it possible to more easily reuse
arrays of pointers as input and output.
2025-01-07 10:38:32 +01:00
Wim Taymans
9f9e962dd6 filter-graph: pass spa_pod in get_props 2025-01-07 09:31:48 +01:00
Wim Taymans
c5ae456b9e filter-graph: pass dict to activate functions
This makes it possible to expand it more later.
2025-01-07 09:23:23 +01:00
Elliot Chen
419bc600a8 pipewiresink: split buffer and send them in turn if needed
For some streams, the buffer size is changed and may exceed
the acquired buffer size which is acquired from the pool of
pipewiresink. Need split buffer and send them in turn for
this case.
2025-01-03 15:58:37 +09:00
Arun Raghavan
974117f41a module-rtp: Fix previous typo fix
We want to track the difference between the PTP timestamp (now) and the
last RTP send, not the synthesized next RTP timestamp (which will always
be smoothly incrementing).
2024-12-31 15:24:46 -05:00
Arun Raghavan
c143e89118 module-rtp: Fix typo in check for lagging sender 2024-12-31 11:58:03 -05:00
Arun Raghavan
088d8011f2 tools: Document a couple of missing short form args for pw-loobpack 2024-12-31 11:22:49 -05:00
Elliot Chen
152a6683ef pipewiresink: active stream after finishing preoll when changing state from paused to playing 2024-12-30 11:48:34 +09:00
Niklas Carlsson
51e7ed3421 filter-chain: add sqrt plugin
To take the square root of the signal.
2024-12-20 17:58:08 +00:00
Niklas Carlsson
d7718dbcb7 filter-chain: add abs plugin
To calculate the absolute value of the signal.
2024-12-20 17:58:08 +00:00
Pauli Virtanen
e4ff13a75d module-loopback: support latencyOffsetNsec Prop
Add support for latencyOffsetNsec Prop, which just controls the nsec
part of the ProcessLatency.

This is needed to support latency offset in Pulseaudio apps when using
loopbacks as front-end nodes to underlying sinks.
2024-12-15 20:10:01 +00:00
Barnabás Pőcze
c556cced91 pipewire: module-raop-sink: remove unused function 2024-12-14 23:28:43 +01:00
Barnabás Pőcze
bf43515589 pipewire: thread: fix strerror() argument 2024-12-14 23:28:43 +01:00
Barnabás Pőcze
08c7c7999b pipewire: rtsp-client: use offsetof()
Use `offsetof()` instead of `sizeof()` to correctly determine the offset
of the flexible array member.
2024-12-14 23:28:43 +01:00
Barnabás Pőcze
05ec64623a pw-cli: remove unused INDENT macro 2024-12-14 23:27:45 +01:00
Barnabás Pőcze
b1443185ea gst: sink: remove unnecessary variable
`res` can be removed without changing the behaviour, so do that.
2024-12-14 23:27:45 +01:00
Barnabás Pőcze
1f06d00838 pw-container: fix indentation 2024-12-14 23:27:45 +01:00
Barnabás Pőcze
705c2a652b pipewire: module-vban: fix vban serial header
The expression `VBAN_PROTOCOL_SERIAL | vban_BPSList[14]` is assigned
to an 8 bit field of the header, but, `vban_BPSList[14]` being
115200, it does not fit. Instead, its index, 14, should be
placed in the header.

In addition to fixing the issue, add `-Werror=constant-conversion`,
and clang diagnostic that catches such issues.

Fixes: 1a5514e5cf ("module-vban: create streams per stream_name")
2024-12-14 23:09:45 +01:00
Arun Raghavan
85fa0aae40 gst: src: Set possible_caps before stream connect
The value is used when a the format changes in handle_format_change(),
and while it seems this was typically expected to happen async and thus
protected by the thread lock, there are cases (such as with
auto-port-config) where a param might be set within the
pw_stream_connect() call itself (in the case of auto-port-config, by the
impl_init() of the audioadapter).
2024-12-13 13:44:09 +00:00
Barnabás Pőcze
69dcc7db7b pipewire: context: pw_context_find_format(): fix stack use-after-free
Since fc49c1697a ("context: improve negotiation") it is possible
that the out parameter `format` will be set to `filter`. However,
`filter` is a SPA POD from the local SPA POD builder `fb`, which
references the local buffer `fbuf`.

In those cases, if the callers then make use of the returned SPA POD,
a stack use-after-free happens, such as the one displayed below.

The issue could be reliably triggered by executing the `video-play`
example program, and then trying to use the same camera in firefox.
As seen below, the input node, firefox's, provides no format preference,
causing the output format to be used. Previously, this had led
to the use-after-free described above.

pw.link    | [impl-link.c: 130 link_update_state()] (46.0.1 -> 114.0.0) init -> negotiating (paused-configure)
pw.context | [  context.c: 935 pw_context_find_format()] 0x51e000000080: finding best format 3 1
pw.context | [  context.c: 943 pw_context_find_format()] 0x51e000000080: states 3 1
pw.context | [  context.c: 958 pw_context_find_format()] 0x51e000000080: Got output format:
pw.context | [  context.c: 959 pw_context_find_format()]  video/raw
pw.context | [  context.c: 959 pw_context_find_format()]            format : (Id) YUY2
pw.context | [  context.c: 959 pw_context_find_format()]              size : (Rectangle) 640x480
pw.context | [  context.c: 959 pw_context_find_format()]         framerate : (Fraction) 30/1
pw.context | [  context.c: 966 pw_context_find_format()] 0x51e000000080: no input format filter, using output format: Success
=================================================================
==418404==ERROR: AddressSanitizer: stack-use-after-return on address 0x73993ee46200 at pc 0x739941d31020 bp 0x7fff526b4670 sp 0x7fff526b4660
READ of size 4 at 0x73993ee46200 thread T0
    #0 0x739941d3101f in spa_pod_builder_raw ../spa/include/spa/pod/builder.h:150
    #1 0x739941d3b35d in do_negotiate ../src/pipewire/impl-link.c:294
    #2 0x739941d46214 in check_states ../src/pipewire/impl-link.c:727
    #3 0x739941f14405 in process_work_queue ../src/pipewire/work-queue.c:64
    #4 0x73993d0dbe99 in source_event_func ../spa/plugins/support/loop.c:894
    #5 0x73993d0d6881 in loop_iterate ../spa/plugins/support/loop.c:727
    #6 0x739941d76b05 in spa_loop_control_enter ../spa/include/spa/support/loop.h:264
    #7 0x739941d76d93 in spa_loop_control_leave ../spa/include/spa/support/loop.h:268
    #8 0x739941d78946 in pw_main_loop_quit ../src/pipewire/main-loop.c:109
    #9 0x5a64b3cb1cec in main ../src/daemon/pipewire.c:130
    #10 0x739940c34e07  (/usr/lib/libc.so.6+0x25e07) (BuildId: 98b3d8e0b8c534c769cb871c438b4f8f3a8e4bf3)
    #11 0x739940c34ecb in __libc_start_main (/usr/lib/libc.so.6+0x25ecb) (BuildId: 98b3d8e0b8c534c769cb871c438b4f8f3a8e4bf3)
    #12 0x5a64b3caf3b4 in _start (/pipewire/build/src/daemon/pipewire+0x173b4) (BuildId: f9e8403a377e28bf8bd9cf0a5b89d33f08499917)

Address 0x73993ee46200 is located in stack of thread T0 at offset 512 in frame
    #0 0x739941c6ed5e in pw_context_find_format ../src/pipewire/context.c:907

  This frame has 15 object(s):
    [...]
    [432, 480) 'fb' (line 911)
    [512, 4608) 'fbuf' (line 912) <== Memory access at offset 512 is inside this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-use-after-return ../spa/include/spa/pod/builder.h:150 in spa_pod_builder_raw
    [...]

Fixes: fc49c1697a ("context: improve negotiation")
2024-12-10 22:48:13 +01:00
Wim Taymans
94e823ddad filter-graph: add dcblock and ramp plugins 2024-12-09 15:00:35 +01:00
Wim Taymans
df271d13f3 filter-chain: add ebur128 filter
The EBU R128 filter measures the signal and generates LUFS control
notifications for further processing.

It also adds a plugin that can convert LUFS to a gain (based on a target
LUFS).

Also add an example filter-chain to enable the EBU R128 measurement and
how to use the results to adjust the volume dynamically.

See #2286 #222 #2210
2024-12-09 11:31:33 +01:00
Martin Louazel
8ee1b4b614 context: fix erroneous clamping of quantum for high sample rates
When calculating the adjusted max quantum based off of max_latency, the
first multiplication can overflow uint32_t, leading to the quantum being
wrongfully clamped down.

Signed-off-by: Martin Louazel <martin.louazel@streamunlimited.com>
2024-12-07 18:24:07 +00:00
Torkel Niklasson
bfb5ae18d1 filter-chain: add max builtin plugin
add max which takes two inputs and output the max value of them. it can
e.g. be used to create the same sidechain input to two mono limiters.
2024-12-04 13:17:36 +01:00
Wim Taymans
4c8886f5dc context: use timestamp for load-balancing of loops
We increment the refcount of the loop when we hand it out. We use this
refcount to do some load balancing. In some cases we also decrease the
refcount again when the release_loop() functions is called but we only do
this in some modules. The result is that in most cases the refcount
just keeps on going up and this is misleading.

Change the refcount to a last_used timestamp and prefer to use loops
that have not been used in a while.

Fixes #4436
2024-12-03 13:01:36 +01:00
Wim Taymans
0658ff93d8 gst: add slave-method property
Set the slave-method to none by default to disable the resampler.
2024-12-03 12:11:47 +01:00
Wim Taymans
9419a12e74 gst: add rate control to the sink
Track the elapsed time between buffers and try to keep the buffer fill
level constant by changing the rate of the stream.

See #4374
2024-12-03 12:11:47 +01:00
Taruntej Kanakamalla
922efaf6ed gst: drop empty buffers in pipewiresrc
In case the dequeued buffer is empty or of size 0, skip the buffer
so that the downstream elements do not report an error
2024-12-02 14:15:23 +05:30
Pauli Virtanen
371781e214 pulse-server: fix pulse.cmd load-module not loading multiple overrides
pw_context_conf_section_for_each() stops iterating on nonzero return
value, so make sure 0 is returned on success.
2024-11-28 19:34:22 +00:00
Jonas Holmberg
e9092d7d2f core: Remove redundant declaration
Fix problem when building with -Werror=redundant-decls:

../src/pipewire/core.h:661:7: error: redundant redeclaration of ‘pw_core_get_user_data’ [-Werror=redundant-decls]
  661 | void *pw_core_get_user_data(struct pw_core *core);
      |       ^~~~~~~~~~~~~~~~~~~~~
../src/pipewire/core.h:446:7: note: previous declaration of ‘pw_core_get_user_data’ with type ‘void *(struct pw_core *)’
  446 | void *pw_core_get_user_data(struct pw_core *object);
      |       ^~~~~~~~~~~~~~~~~~~~~
2024-11-27 17:33:11 +01:00
Arun Raghavan
45eee02a99 module-rtp: Account for in-flight samples in RTP receive
When not using PTP as the driver, it is possible that packet receive and
the process() callback are out of sync, meaning that the target buffer
fill level might be off by upto one ptime's worth of samples
occasionally. This would make the DLL hunt for the target rate, and
cause a constantly varying delay.

Accounting for the delta between the packet receive time and the
process() time allows us to eliminate this jitter, resulting in much
more consistent rate matching.
2024-11-27 11:48:50 +00:00
Wim Taymans
89993a3cc6 gst: enable the pipewire ticks as a clock source
Use the pipewire ticks again as the clock source.

This was disabled because the v4l2 sources created bad ticks for the
graph. Now that this is improved we can enable the ticks again.

This has the advantage that simple audio playback does not drift
anymore. The only remaining problem would be timestamp drift or
discontinuities, which we don't handle here yet.
2024-11-26 17:23:00 +01:00
Wim Taymans
3f0fe0032f node: add a clock flag to mark rate/duration inaccurate
Some clocks (v4l2) don't process exactly process buffers at the given
rate/duration so mark this in the clock flags.

We need to use the nsec field in the clock to derive ticks in pw-stream
in that case to get a good clock.
2024-11-26 17:02:02 +01:00
Wim Taymans
ef8d2ab125 gst: mark the pipewiresink as EARLY_PROCESS
We want to receive process callbacks as soon as a buffer is ready for
reuse because we dequeue it for use in our buffer pool.
2024-11-26 16:57:14 +01:00
Wim Taymans
4d4607e62a doc: copy docs from the _methods struct 2024-11-26 13:21:04 +01:00
Wim Taymans
31802d4994 add per type API defines 2024-11-26 11:58:51 +01:00
Wim Taymans
b03f2f7afa make per object IMPL 2024-11-26 11:35:50 +01:00
Wim Taymans
999b26c590 static inline more macros 2024-11-26 11:35:49 +01:00
Wim Taymans
90b0e45037 make static inline -> SPA_API_IMPL
So that we can export the symbols as well.
2024-11-26 11:35:49 +01:00
Wim Taymans
84bd4b7ea9 spa: use static inline for interfaces instead of macro
It gives better typechecking and a path to make a library of functions.
2024-11-26 11:35:49 +01:00
Wim Taymans
5e0e1204d7 impl-node: remove old check
Remove the check for the target rate and duration. The drivers are
supposed to update that now.

The check is a little racy because a new target could have been
configured right after the driver emitted the ready signal. In that
case we should not update the clock values but let the driver run with
the old values and let the new values become active in the next cycle.
2024-11-26 10:59:54 +01:00
Pauli Virtanen
c36c028dd2 pw-dump: don't emit remove events when not monitoring
When pw-dump is called without --monitor, it should output exactly one
JSON array, and no remove event indicators.
2024-11-23 12:11:33 +00:00
Wim Taymans
ae465ccbfc stream: fix EARLY_PROCESS again
It got removed with the async improvements. We shouñd simply ask more
buffers whenever we push one to be dequeued.

See #3480
2024-11-22 12:22:14 +01:00
Wim Taymans
e1fc3de595 modules: use pw_stream_set_rate() some more 2024-11-22 09:55:36 +01:00
Wim Taymans
804df3389a modules: use pw_stream_set_rate() when we can 2024-11-22 09:49:27 +01:00
Wim Taymans
433afeaa1e stream: add function to set adaptive resampler rate
Make a function to set the adaptive resampler.
2024-11-22 09:29:53 +01:00
Wim Taymans
188d920733 pass the right types to the methods
This currently works because we accept void* for these functions but it
will fail when we will use the real types.
2024-11-20 10:17:37 +01:00