Skip to content

linux-pipewire: Use dynamic pod builder#10459

Open
GeorgesStavracas wants to merge 1 commit intoobsproject:masterfrom
GeorgesStavracas:gbsneto/dynamic-pod-builder
Open

linux-pipewire: Use dynamic pod builder#10459
GeorgesStavracas wants to merge 1 commit intoobsproject:masterfrom
GeorgesStavracas:gbsneto/dynamic-pod-builder

Conversation

@GeorgesStavracas
Copy link
Member

Description

Use the dynamic pod builder, which resizes the pod buffer as needed, instead of a static 4096 buffer which can overflow.

Motivation and Context

The dynamic pod builder implements a dynamically growing buffer for the pods, which can indeed grow quite a lot depending on e.g. the number of modifiers and formats that the GPU advertises.

How Has This Been Tested?

  • Add any PipeWire-based source (window or monitor captures, or the PipeWire camera)
  • Notice they still work

Types of changes

  • Tweak (non-breaking change to improve existing functionality)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@GeorgesStavracas GeorgesStavracas added Enhancement Improvement to existing functionality Linux Affects Linux labels Mar 29, 2024
@GeorgesStavracas
Copy link
Member Author

@columbarius this should have the same effect as of #8293, mind reviewing this PR?

@RytoEX RytoEX added this to the OBS Studio (Next Version) milestone Mar 29, 2024
@GeorgesStavracas GeorgesStavracas marked this pull request as draft March 29, 2024 20:19
The dynamic pod builder implements a dynamically growing buffer for the
pods, which can indeed grow quite a lot depending on e.g. the number of
modifiers and formats that the GPU advertises.

Use that instead of a static 4096 buffer. Build a single pod with each
dynamic pod builder, and put the result in a (also dynamic) GPtrArray
which holds all pointers to pods.
@GeorgesStavracas GeorgesStavracas force-pushed the gbsneto/dynamic-pod-builder branch from fbc22a9 to 76ac74d Compare March 29, 2024 21:01
@GeorgesStavracas GeorgesStavracas marked this pull request as ready for review March 29, 2024 21:02
@GeorgesStavracas
Copy link
Member Author

For reference, I copied the approach from PipeWire's own code in gstpipewireformat.c.

@GeorgesStavracas GeorgesStavracas added the Seeking Testers Build artifacts on CI label Mar 29, 2024
Copy link
Collaborator

@tytan652 tytan652 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM

const struct spa_pod **params;
params = bzalloc(2 * obs_pw_stream->format_info.num *
sizeof(struct spa_pod *));
params = g_ptr_array_new_full(2 * obs_pw_stream->format_info.num *
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to use a dynamic array we should use the obs DARRAY to keep consistency with the rest of obs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DARRAY in this kind of code path (not cold) should be avoided.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all negotiation is cold. And second we know the size so there arnt any performance concerns to begin with. Its just a matter of using the api we all know or using the gptr api.

struct spa_fraction min_framerate;
struct spa_fraction framerate;

spa_pod_dynamic_builder_init(&pod_builder, NULL, 0, 4096);
Copy link
Collaborator

@kkartaltepe kkartaltepe Mar 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a lot smaller now. instead of 50 formats with 50 modifiers it just needs to hold the 50 modifiers. I assume it grows automatically, but we can just see what the size is on amd and use that I guess.

struct spa_fraction min_framerate;
struct spa_fraction framerate;

spa_pod_dynamic_builder_init(&pod_builder, NULL, 0, 4096);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spa_pod_dynamic_builder_clean is referenced in other places. I cant find any docs on spa_pod_dynamic_builder (not sure why i hoped it would exist), but can you confirm that we dont need to clean up after init.

@kkartaltepe
Copy link
Collaborator

Seems to work fine on my amd box, maybe we should also backport this into 30.1 or something since there are some lingering reports of crash on pipewire start which have been related to these buffers being too small before.

@columbarius
Copy link
Contributor

@columbarius this should have the same effect as of #8293, mind reviewing this PR?

I'm not really a fan of adding more g_ptr and autopointer magic to the pipewire code, since it complicates the code for those not familiar with them (myself included).

An alternative approach would be one builder, but recording the offsets of the different pods and then collecting them at the end: columbarius, https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/master/src/modules/module-filter-chain.c#L1525

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Improvement to existing functionality Linux Affects Linux Seeking Testers Build artifacts on CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants