Commit graph

13651 commits

Author SHA1 Message Date
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
774f9cbb80 videconvert: fix compilation on 32 bits 2025-04-02 10:15:37 +02:00
Wim Taymans
bf952a6e4b videoconvert: improve setup of DSP mode
Parse and use DSP formats.

Redo the conversion setup when the formats changed. We usually do this
when starting the node but the formats can change while running as well.
2025-04-01 16:35:32 +02:00
Wim Taymans
da69bddb95 adapter: Improve convert setup
Always do configure_convert, even when the passthrough state didn't
change, for example when going from none to convert.
2025-04-01 16:31:25 +02:00
Wim Taymans
1adc9e5445 videoadapter: init the builder for each param
Or else we keep on adding items until we overflow.
2025-04-01 16:24:40 +02: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
94910f77c9 pod: handle builder overflows
When the builder is overflowed, we might get a NULL pod. This is a valid
situation that we need to handle because it can be used to get the
required builder buffer size.
2025-04-01 10:18:05 +02:00
Wim Taymans
5c5075f4d6 videoconvert-ffmpeg: copy complete passthrough buffer data
We also need to copy the data type, flags and sizes.
2025-03-28 16:10:42 +01:00
Wim Taymans
b23161d772 videoconvert: always put frame size on Format param
We can now set the 0x0 frame size as the default as a wildcard.
2025-03-28 16:09:36 +01:00
Wim Taymans
5f4c0cdd1e improve debug and error reporting a little 2025-03-28 16:08:57 +01:00
Wim Taymans
ae1bbc93d8 videoconvert: return error on invalid formats 2025-03-28 16:08:19 +01:00
Wim Taymans
dba31d7e2a videoadapter: use the supported dataType in Buffer param
Get the dataType field from the Buffer param. This is a mask of the
supported data types for the buffers. Pass this to the allocating node
if there is one, otherwise use MemPtr as the allocated format.
2025-03-28 16:04:54 +01:00
Wim Taymans
d0c4b491da v4l2: handle nearest set_format
The set_format function can return 1 when the format was adjusted to the
nearest supported format so return this from the port_set_param
function.

This instructs the adapter to recheck the configured format so that it
can store the adjuted format on the converter.
2025-03-28 16:00:51 +01:00
Wim Taymans
b501290bd5 audioconvert: support DYNAMIC data again
Because we advertize on out ports that we support DYNAMIC data, we need
to read the data pointer directly from the buffer and only fall back to
our cache (mmaped) pointer when it is NULL.

With DYNAMIC data, the peer element (mixer-dsp) directly copies the
input data pointer into the buffer data in the processing loop in order
to avoid a memcpy when there is no mixing needed.
2025-03-27 17:00:11 +01:00
Wim Taymans
328718f958 audioconvert: add support for buffer data mmap
When there is no data and the buffer is mmapable, try to mmap it. Unmap
again when clearing the buffers.

Use the mmaped data pointer of the buffer when processing.
2025-03-27 15:37:19 +01:00
Wim Taymans
9ceb4310f8 videoconvert: unmap buffer memory as well
Set a flag when we mmaped the buffer memory so that we can unmap it
again when clearing the buffers.
2025-03-27 15:21:12 +01:00
Wim Taymans
abc03ec810 adapter: fix buffer alloc order
Prefer to let the follower allocate buffers. If we are allocating
buffers, first do use_buffers on the allocating node or else the
non-allocating node just ends up with NULL buffers.
2025-03-27 09:29:52 +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
Wim Taymans
479ba33685 videoconvert-ffmpeg: support transcoding
When the input and output is an encoded format but the dimensions are
different, do a decode, scale and encode.
2025-03-26 17:52:26 +01:00
Wim Taymans
f8dcf32c8d videoconvert-ffmpeg: fix passthrough mode
Keep the passthrough flag up to date when we unset a port format or when
it changes.

We should only fill in the buffer data/fd when the ALLOC flag is set.

We should only take the passthrough input buffer as output when we are
in passthrough mode.

Copy the header metadata.
2025-03-26 17:52:26 +01:00
Wim Taymans
2873d7a6cc adapter: add Header metadata by default
Firefox needs this but we should eventually check the Meta Params to
decide on this.
2025-03-26 17:52:26 +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
Wim Taymans
cc6081b70d gst: fix video metadata offsets
The offsets in GStreamer are always offsets into the buffer memory where
the plane starts so set this to the accumulated plane sizes.
2025-03-26 12:30:41 +01:00
Wim Taymans
241ec04d88 videoconvert: support planar formats
Keep track of the per-place strides and sizes and use that to fill the
output buffer.
2025-03-26 12:29:26 +01:00
Wim Taymans
ea7cfb9e94 audioconvert: make sure the converter is in None mode
The audioconverter starts in Convert mode, so make sure it goes to the
None mode before we attempt to reconfigure ourselves.

Also remove the ports on audioconvert when going to None mode. This used
to somewhat work because we configured it in DSP mode without any
params, which is like None without ports.
2025-03-26 10:26:41 +01:00
Wim Taymans
636e123fdd videoconvert-ffmpeg: set better size suggestion
Use a better suggestion for the buffer size.
2025-03-26 09:54:12 +01:00
Wim Taymans
5fb9716ce7 gst: require a buffer size of at least 1
Setting the default size to 0 and outside of the min/max range now means
that there is no suggestion for the size and it should use the
suggestion of the peer.
2025-03-26 09:52:22 +01:00
Wim Taymans
beb075c5a6 adapter: only use DYNAMIC buffer data when supported 2025-03-26 09:51:09 +01:00
Wim Taymans
6015fa353a adapter: call reconfigure_mode instead of configure_convert
configure_convert does not set up the current mode, so call the more
complete reconfigure_mode to set the initial converter mode.
2025-03-26 09:43:58 +01:00
Wim Taymans
aea77dc055 spa: avoid duplicate default value
When filtering an enum/none against a range/step, make sure we don't add
the default value twice.
2025-03-26 09:41:45 +01:00
Arun Raghavan
439d5d04fe gst: sink: Don't provide clock in provide mode
Counter-intuitive as it seems, when we are driving the clock, we can't
also provide a clock from PipeWire to the pipeline -- we need the
pipeline to drive the graph.

So we make the mode control whether we provide a clock or not.
2025-03-25 21:38:15 +00:00
Sanchayan Maity
3c62d29a55 gstpipewiresrc: Fix re-linking
When using PW source, one might want to dynamically link PW source to
a different source. Setting possible_caps to NULL prevents the caps
intersect from returning a successful result on format change. Do not
set possible_caps to NULL as we get that from peer caps which should
stay the same ideally for the duration of pipeline run. That allows
re-linking PW source any number of times with a pipeline like below.

gst-launch-1.0 pipewiresrc autoconnect=false ! queue ! video/x-raw,format=YUY2 ! videoconvert ! xvimagesink

The above pipeline can be made to switch between a camera source and a
screen capture source like wf-recorder.

Note that this fix only improves the status quo and won't work if the
peer caps change due to a re-negotiation.
2025-03-25 17:49:13 +00:00
Arun Raghavan
4ae348254e ci: Bump to latest ci-templates 2025-03-25 17:27:48 +00:00
Sanchayan Maity
eb534b4515 gst: pipewiresrc: Fixate caps if intersect did not return fixated caps
We might end up in a situation where depending on the pipeline,
intersect might not give us fixated caps.

Possible example of such a pipeline can be below.

gst-launch-1.0 -e pipewiresrc target-object=<path> ! audioconvert !
audio/x-raw,format=S16LE,rate=48000,channels=2 ! lamemp3enc !
filesink location=test.mp3

This results in non-fixated caps like below when intersecting caps from
format param and possible_caps which depends on what we have downstream
in the pipeline.

audio/x-raw, layout=(string)interleaved, format=(string)S16LE, rate=(int)48000, channels=(int)2, channel-mask=(bitmask)0x0000000000000003;
audio/x-raw, layout=(string)interleaved, format=(string)S16LE, rate=(int)48000, channels=(int)2

To fix this, fixate the caps explicitly.
2025-03-25 15:47:28 +00:00
Philippe Normand
d37b0b4cd2 gst: deviceprovider: Fix a leak and a heap-use-after-free
The device passed to gst_device_provider_device_add() is transfer:floating, so
we need increase its ref, otherwise the pointer we keep internally will be a
dangling ref.

Also gst_device_provider_device_remove() doesn't actually release the device, so
we have to do it ourselves.

Fixes #4616
2025-03-25 15:33:43 +00:00
Wim Taymans
1515e46d50 ffmeg: fix default number of buffers
Make the MAX buffers different from the min and make sure the default
value is between min and max.
2025-03-25 16:19:50 +01:00
Wim Taymans
437e486d6e spa: improve filter Enum and None results
When we construct an Enum, check if we only added 1 value and remove the
duplicate default value we added. If we added more values, promote the
choice to an enum.
2025-03-25 16:17:38 +01:00
Wim Taymans
4ddb17c4b5 videoconvert: don't load the dummy converter
Just don't load any converter at all, the dummy converter has some
issues.
2025-03-25 15:14:03 +01:00
Philippe Normand
e584cee066 gst: src: Fix buffer pool handling in case of caps renegotiation
In case negotiation is first attempted with unfixed caps, bufferpool support was
unconditionally disabled. Then at a second caps negotiation attempt it wasn't
restored according to the property value.
2025-03-25 12:50:42 +00:00
Arun Raghavan
14b7b31bd9 videoadapter: Use dummy converter by default
The ffmpeg converter doesn't quite work yet for planar formats at least,
so let's leave the dummy as the default till that works.
2025-03-25 08:26:29 -04:00
Wim Taymans
7da66f8a5f spa: simplify filtering 2025-03-25 12:57:40 +01:00
Wim Taymans
fff8f63c0e spa: reject impossible ranges after filtering 2025-03-25 12:50:30 +01:00
Wim Taymans
64b2792d61 spa: refactor range/step check 2025-03-25 12:41:44 +01:00
Wim Taymans
77b23c619e spa: Improve Range/Step code readability
Use min,max,step variables to store the choice values for better
readability.
2025-03-25 11:58:53 +01:00
Wim Taymans
4b3be9cc9b spa: merge Range and Step filter together
They share all of the code and the step just has an extra check for
the step values.
2025-03-25 11:47:28 +01:00
Wim Taymans
b238c9d7a1 pw-cat: improve sndfile file format debug info
Print the endianness, container name and the sample format nicely
instead of dumping the hex values.
2025-03-24 18:49:41 +01:00