Commit graph

7238 commits

Author SHA1 Message Date
Taruntej Kanakamalla
d5e2cc94cd gst: sink: update clock before every trigger process
Get the clock pointer using the io_changed stream event.
and update the clock before triggering the process

The clock needs to be updated in the data loop thread
and before triggering the process so move the calls to
`pw_stream_trigger_process` from gstreamer thread context
into the data loop thread context by invoking a callback
and update the clock inside the data loop callback
before the trigger
2025-05-08 18:57:44 +05:30
Wim Taymans
8bcf0460d1 filter-graph: add latency option to the convolver
Sometimes you want to use the convolver as a delay without adding
latency so add a latency option to tweak the automatic latency
reporting. Use this in the upmix rear delay filters.
2025-05-07 17:18:15 +02:00
Wim Taymans
8ee51cd88f filter-graph: add latency support for the delay plugin 2025-05-07 16:55:44 +02:00
Wim Taymans
e545efdb6e filter-chain: implement filter-graph latency
Collect the latency of the graph in filter-chain. We do this by first
inspecting the LATENCY ports on the plugins and us the notify value as
the latency on the node.

We then walk the graph from source to sink and for each node take the
max latency of all linked upstream peer nodes. We end up with the max
latency of the graph and emit this in the graph properties.

We then listen for the graph latency property and use that to update the
process_latency of the filter-chain, which will then update the latency
on the filter-chain ports.

Fixes #4678
2025-05-07 16:00:41 +02:00
Wim Taymans
5bf3a0c454 filter-graph: add a debug node
Add a node that logs audio or control data to the log.
2025-05-07 10:44:57 +02:00
Wim Taymans
8c8fd97698 filter-chain: support ProcessLatency
Allow setting ProcessLatency on the nodes and add this latency to the
reported Latency.

See #4678
2025-05-06 19:15:16 +02:00
Wim Taymans
20246b5c0e netjack2: add driver.mode again
This configures the default number of audio and midi ports per stream
to 0 depending on the mode.

Improve docs a little.

See #4666
2025-05-06 10:44:14 +02:00
Wim Taymans
faf5ae0c2f impl-link: improve negotiation
Make a function to create a filter. This is a pod that has all valid
defaults fixated and the invalid ones left unfixated.

Use this filter is a first attempt to negotiate a link format. The
effect is that a format will be chosen first that matches all the valid
defaults as much as possible instead of negotiating to the first thing
that matches.

Suppose we have a higher priority port with the format:

 foo/bar
    key: { default:1024, min:1, max:2048 }

And another port with two params:

 foo/bar
    key: 512
    rate: 2/1
 foo/bar
    key: 1024
    rate: 30/1

By first trying key: 1024 we negotiate to the more specific second property
with the higher rate.
2025-05-05 10:12:26 +02:00
Wim Taymans
2940c9ff7b examples: add rate as a constant 2025-05-05 09:45:57 +02:00
Arun Raghavan
21a468a9cd gst: Add H.265 support
Same as H.264 for now, we might eventually want to add more stream
formats etc.
2025-05-05 07:38:25 +00:00
Wim Taymans
2ea8d3430c tools: add c key to reset ERR counters
Reset the ERR counters when pressing the c key. This only makes the
current pw-top start counting from 0 again, it does not change anything
globally on the server. It's still usefull because you can use it to
let it count the number of new errors since the keypress.
2025-04-30 15:10:15 +02:00
Wim Taymans
237c0197c6 filter-chain: add props only once
Only add the properties offset in the builder after we actually got a
property or else we end up with the same property twice.
2025-04-30 12:20:31 +02:00
Wim Taymans
664359a020 netjack2: use strncpy to copy the header
It pads the remaining bytes in the header with 0 bytes so that the
memory doesn't contain uninitialized data.
2025-04-30 11:02:58 +02:00
Wim Taymans
a9083c7519 netjack2: improve shutdown
Destroy the sources from the io handler immediately when there is an
error so that we don't end up in endless error wakeups.

Schedule the free from the main loop and make sure only one can ever
run.
2025-04-30 11:00:42 +02:00
Wim Taymans
743d86500c netjack2: fix trace_fp compilation 2025-04-29 18:36:54 +02:00
Wim Taymans
6e8db1cd4a netjack2: handle connection errors in more cases 2025-04-29 18:09:02 +02:00
Wim Taymans
c7b318523d netjack2: set timeout to sane value again 2025-04-29 17:35:40 +02:00
Wim Taymans
3856d29646 netjack2: implement driver and manager roles correctly
The manager is actually not supposed to decide much about the number of
audio and midi ports. It should just suggest a default when connecting
driver doesn't know.

Add a audio.ports parameters to manager and driver to suggest/ask for
the amount of audio ports. Let the audio.position/audio.channels be a
specification of the channel mask in case it matches the requested
channels, otherwise use AUX channels for the ports.

This means that we must derive the mode (sink/source/audio/midi) from
the ports that are negotiated in the manager and the driver, so delay
this until after negotiation.

Make sure all the possible modes work. For midi only streams, we can't
wait for the session manager to perform a PortConfig so do that
ourselves. Make sure we only use a source trigger when we have a sink.

Fixes #4666
2025-04-29 17:17:14 +02:00
Wim Taymans
18a5f884be netjack2: make function to clear events
Make a separate function to clear events instead of passing NULL as the
midi buffer and segfaulting.
2025-04-29 16:26:30 +02:00
Wim Taymans
78fe234bfe netjack2: copy the node.group to streams
Just in case we want them to be scheduled in the same group.
2025-04-29 09:17:35 +02:00
Wim Taymans
40dbc5f00f netjack2: keep per stream io_position
And handle the trigger failure with a warning and fallback.
2025-04-29 09:16:54 +02:00
Wim Taymans
3d6e77e96d netjack2: warn when the trigger fails 2025-04-29 09:16:01 +02:00
Wim Taymans
07f033c8da netjack2: keep position io per stream
Keep a position info for the stream it was set and then use the position
info for the stream that is driving the graph. Otherwise we might use a
destroyed position info.
2025-04-28 12:23:15 +02:00
Wim Taymans
b6cb76bf8d netjack2: implement ifname in the driver
See #4666
2025-04-28 11:13:33 +02:00
Wim Taymans
93ee66dcab netjack2: Improve docs
Remove unused option.
Clarify that channels and midi port are chosen by the server.

See #4666
2025-04-28 11:12:48 +02:00
Wim Taymans
41665e6bb8 examples: handle I420 and IYUV formats
They are represented in PipeWire with 3 planes now.
2025-04-24 11:18:12 +02:00
Wim Taymans
7d6e2a6417 impl-link: refactor format negotiation
Make a new port_info structure that holds the link port information for
input and output. We can use this in some places and remove some
redundant code.

We can also pass a reference to this port_info as the work-queue
object, which makes it more natural to find the associated port info in
the various work queue callbacks.

Move the private pw_context_find_format to the link implementation,
where is it actually used.

Rework the format negotiation code to use an array of 2 port_info
structures with the two ports to negotiate. The negiotiation will
always use the first port_info as higher priority.

Make sure a driver port has a lower priority than the other port. We want
to negotiate the source/sink to something close that what is
provided/requested by the client. The client can always adapt to the
driver port format fields by giving a "don't care" value for the format
property (either unspecified or with an out of range default value).
2025-04-24 11:17:49 +02:00
Philippe Normand
2e409c0237 gst: src: Attach video meta when receiving DMABufs from PipeWire
Fixes getDisplayMedia() in WebKitGTK after regression introduced by:
https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/2330
2025-04-22 10:48:00 +01:00
Arun Raghavan
ebe9381236 gst: handle blocks and size allocation for encoded format
In case of encoded video we get n_planes as 0 from the video info so
passing that as n_datas is failing during the buffer negotiation. Make
sure to use an appropriate value based on whether we have raw video or
not.

Co-authored-by: Taruntej Kanakamalla <taruntej@asymptotic.io>
2025-04-17 15:21:38 -04:00
Wim Taymans
55f71520db midifile: unpack the UMP SysRT bytes correctly
They are packed in a native endian uint32_t so read it like that and
then use shifts to get the right bytes.
2025-04-16 18:33:36 +02:00
Simon Ruderich
c4a88dfe6c midifile: decode UMP SysRT messages 2025-04-16 17:57:44 +02:00
Christian Glombek
9e3f9607a6 raop: Add fp_sap25 encryption type
Add support for FairPlay SAP v2.5 (encryption type 5) type devices such as Apple Home Pod Minis.

Apparently only these devices require the `POST /feedback` heartbeat, so fix that.
2025-04-10 23:13:46 +02:00
Pauli Virtanen
42b92a3487 pw-loopback: add missing --channel-map long option 2025-04-09 07:47:32 +00:00
Sanchayan Maity
bb1bb07f6c gstpipewiresrc: Handle stream being disconnected
When PW source is used with something like Camera and the camera is
disconnected, all buffers are removed and stream will be paused.

When using PW sink with source, the sink side pipeline can go to EOS.
This again results in all the buffers being removed and stream being
paused on the source side. PW source side pipeline can also crash if
the sink was in the middle of frame copying a buffer to render which
got removed.

Handle this scenario by sending a flush-start event at the start of
buffer removal and flush-stop at the end followed by an end of stream
or pipeline error depending on user selection.
2025-04-09 07:45:27 +00:00
Wim Taymans
a99ed4da2a raop: fix byte array initialization
Initialize the byte array with bytes instead of a string because the 0
byte at the end of the string does not fit in the array and causes a
compiler warning.
2025-04-04 16:12:41 +02:00
Wim Taymans
8205038ffb buffers: increase max datas limit
Increase the max amount of buffer datas allowed.
2025-04-04 15:46:03 +02:00
Wim Taymans
a9f12537d1 pulse: clamp channel numbers to right values
When converting between pipewire and pulse channelmaps, make sure we
clamp the channel numbers to the the right limit.
2025-04-04 15:46:03 +02:00
Wim Taymans
722776cf65 Remove some hardcoded channel number values
Mostly related to the number of channels.
2025-04-04 15:46:03 +02:00
Sanchayan Maity
77143e54d9 gstpipewiresrc: Fix re-linking for audio
For a pipeline like below, we might want to dynamically switch the audio
source.

gst-launch-1.0 -e pipewiresrc autoconnect=false ! queue ! audioconvert ! autoaudiosink

On switching to a different audio source, any one of driver, quantum
or clock rate might change which changes the return `result` value of
gst_pipewire_clock_get_internal_time.

This can result in the basesrc create function incorrectly waiting in
gst_clock_id_wait. We post clock lost message to fix this. In the case
of gst-launch, it will set the pipeline to PAUSED and then PLAYING to
to force a new clock and a new base_time distribution.

Without the clock lost message, the following can be seen

before re-linking to a different source
0:00:30.887602864 79499 0x7fffe8000d40 DEBUG              GST_CLOCK gstsystemclock.c:1158:gst_system_clock_id_wait_jitter_unlocked:<pipewireclock0> entry 0x7fffd803fad0 time 0:00:17.024565416 now 0:00:17.024109144 diff (time-now) 456272

after re-linking to a different source
0:00:45.790843245 79499 0x7fffe8000d40 DEBUG              GST_CLOCK gstsystemclock.c:1158:gst_system_clock_id_wait_jitter_unlocked:<pipewireclock0> entry 0x7fffd803fad0 time 0:00:31.927694059 now 0:00:17.066883864 diff (time-now) 14860810195

With the clock lost message, the following can be seen

before re-linking to a different source
0:01:09.336533552 89461 0x7fffe8000d40 DEBUG              GST_CLOCK gstsystemclock.c:1158:gst_system_clock_id_wait_jitter_unlocked:<pipewireclock0> entry 0x7fffd803fad0 time 0:00:58.198536772 now 0:00:58.197444926 diff (time-now) 1091846

after re-linking to a different source
0:01:21.659827958 89461 0x7fffe8000d40 DEBUG              GST_CLOCK gstsystemclock.c:1158:gst_system_clock_id_wait_jitter_unlocked:<pipewireclock0> entry 0x7fffd803fad0 time 0:28:24.853517646 now 0:28:24.853527204 diff (time-now) -9558

Note the difference in `time` and `now` fields of the above log message.

This is easy to reproduce by using a pipewiresink as the audio source
with a pipeline like below, as one of the sources during switching.

gst-launch-1.0 -e audiotestsrc wave=ticks ! audioconvert ! audio/x-raw,format=F32LE,rate=48000,channels=1 !
pipewiresink stream-properties="props,media.class=Audio/Source,node.description=pwsink" client-name=pwsink

Applications need to handle the GST_MESSAGE_CLOCK_LOST message in their
bus handlers.
2025-04-03 19:20:34 +05:30
Arun Raghavan
dd683176c2 gst: sink: Set provide clock flag if not in provide mode
Handle a theoretical corner case of an element that is first started
with mode=provide, and then restarted without mode=provide.
2025-04-03 06:59:31 -04:00
Wim Taymans
832c5a6d25 fix printf modifier for gsize
Fixes #4641
2025-04-02 13:25:31 +02:00
Taruntej Kanakamalla
ee2c6eb41e gst: sink: Manage buffer pool memory manually
Let's make sure we own the memory in buffers, so that we can be
resilient to the PW link going away. This currently maintains the status
quo of copying data into the pipewirepool for sending to the remote end,
but moves the allocation of buffers so that ownership is maintained by
the sink in all cases.

There are some tricky corners, especially with bufferpool vs. buffers
param negotiation -- bufferpool parameters can be negotiated in
GStreamer before the link even comes up, so we try to adapt the buffers
param to use the negotiated value. For now, that is more brittle than
tying those two aspects together. We can revisit this if we can find a
way to tie pipeline state and link state more closely.

Co-authored-by: Arun Raghavan <arun@asymptotic.io>
2025-04-02 08:20:38 +00:00
Arun Raghavan
1b258f4ecc gst: sink: Only add VideoCrop meta for video 2025-04-02 08:20:38 +00:00
Wim Taymans
aca673b3ab impl-link: improve debug log
Log the format after we patch it up and log some context lines.

Move some info log to debug.
2025-04-01 10:19:40 +02:00
Wim Taymans
5f4c0cdd1e improve debug and error reporting a little 2025-03-28 16:08:57 +01:00
Wim Taymans
afb4a2f49c Revert "gst: src: Minor fix for offsets"
This reverts commit 4c200183b9.

The offset is already applied when we share/copy the memory in the
target buffer.
2025-03-26 17:56:14 +01:00
Arun Raghavan
d7cb68bfc7 gst: pool: Some refinements to min/max handling
A number of changes for correctness.

  1) We expose the actualy min and max values we support in the
     allocation query.

  2) We don't support max_buffers as 0, as unlimited buffers is not an
     option

  3) In ParamBuffers, we request the max_buffers from bufferpool config,
     as we cannot dynamically allocate buffers
2025-03-26 12:08:35 -04:00
Arun Raghavan
5ef13489db gst: sink: Correctly set size and offset on planar data
We need to make sure the memory sizes are correctly initialised so the
meta makes sense, and we don't copy the meta from the input buffer as
that doesn't make sense given we have our own meta already.
2025-03-26 12:08:35 -04:00
Arun Raghavan
dfdc3e333a gst: sink: Minor style consistency fixup 2025-03-26 09:51:53 -04:00
Arun Raghavan
4c200183b9 gst: src: Minor fix for offsets
I don't see any actual usage of left/top padding (yet), but we should
account for chunk offset in addition to the overall size.
2025-03-26 09:26:38 -04:00