Skip to content

[GTK][WPE] BubblewrapLauncher: Expose all V4L2 devices#61600

Merged
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
dos1:v4l2-sandbox
Mar 30, 2026
Merged

[GTK][WPE] BubblewrapLauncher: Expose all V4L2 devices#61600
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
dos1:v4l2-sandbox

Conversation

@dos1
Copy link
Copy Markdown
Contributor

@dos1 dos1 commented Mar 29, 2026

67bd935

[GTK][WPE] BubblewrapLauncher: Expose all V4L2 devices
https://bugs.webkit.org/show_bug.cgi?id=311007

Reviewed by Claudio Saavedra and Patrick Griffis.

Although GTK uses xdg-desktop-portal for cameras, it still needs V4L2
devices to be exposed in the sandbox to make V4L2 video decode work.

WPE already exposed some nodes, but not enough for some platforms,
such as i.MX 8M Quad, where there are 2 camera and 2 VPU nodes.

Make both GTK and WPE expose all V4L2 nodes.

* Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp:
(WebKit::bindV4l):
(WebKit::bubblewrapSpawn):

Canonical link: https://commits.webkit.org/310201@main

4140b87

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
✅ 🧪 api-ios ✅ 🛠 gtk
✅ 🛠 ios-safer-cpp ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress 🛠 playstation
✅ 🛠 🧪 unsafe-merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@dos1 dos1 requested a review from a team as a code owner March 29, 2026 00:21
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Mar 29, 2026
Copy link
Copy Markdown
Contributor

@TingPing TingPing left a comment

Choose a reason for hiding this comment

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

This could all be done with std::filesystem, personally I'm not sure the result is any nicer though.

Comment thread Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp Outdated
Comment thread Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp Outdated
@dos1 dos1 requested a review from TingPing March 29, 2026 08:26
@philn
Copy link
Copy Markdown
Member

philn commented Mar 29, 2026

This could all be done with std::filesystem

IIRC we currently prefer WTF::FileSystem.

Copy link
Copy Markdown
Member

@csaavedra csaavedra left a comment

Choose a reason for hiding this comment

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

For C-style char* the preferred wrapper nowadays is CStringView. Some comments on that line. But I am not sure, perhaps this could be done somehow else instead of glib filesystem API.

StringView name = StringView::fromLatin1(entry);
StringView suffix;

if (name.startsWith("video"_s))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you use CStringView, here you can use startsWith(name.span(), "video"_s).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ended up using WTF::FileSystem, which made string handling easier.

}

while (const char* entry = g_dir_read_name(devDir.get())) {
StringView name = StringView::fromLatin1(entry);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please use CStringView instead.

StringView suffix;

if (name.startsWith("video"_s))
suffix = name.substring(strlen("video"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of creating another string you can get a span from the CStringView.

Comment thread Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp Outdated
Comment on lines +505 to +513
if (name.startsWith("video"_s))
suffix = name.substring(strlen("video"));
else if (name.startsWith("media"_s))
suffix = name.substring(strlen("media"));
else if (name.startsWith("v4l-subdev"_s))
suffix = name.substring(strlen("v4l-subdev"));

if (suffix.isEmpty() || !suffix.containsOnly<isASCIIDigit>())
continue;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm thinking that to avoid all the repetition this could be a small helper function that will match the format you are looking for, then you could have a std::array<ASCIILiteral> with "video", "media", "v4-subdev", etc, and use a lambda to find a match.

@dos1 dos1 requested a review from csaavedra March 29, 2026 10:01
Comment on lines +506 to +507
if (suffix.isEmpty() || !suffix.containsOnly<isASCIIDigit>())
continue;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You don't really use the suffix, this could be done inside the lambda and make it return a bool if you found a match.

}));

for (auto& entry : FileSystem::listDirectory("/dev"_s)) {
StringView fileName(entry);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can probably do all of this right away with a String, so the StringView is not really needed.

@dos1 dos1 requested a review from csaavedra March 29, 2026 11:00
Copy link
Copy Markdown
Member

@csaavedra csaavedra left a comment

Choose a reason for hiding this comment

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

Still some things to iron out. For correctness I will leave the r+ to Patrick.

Comment thread Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp Outdated
Comment thread Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp Outdated
Comment thread Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp Outdated
Comment thread Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp Outdated
Copy link
Copy Markdown
Member

@csaavedra csaavedra left a comment

Choose a reason for hiding this comment

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

There a couple of nits, otherwise looks ok to me. But please wait for a review from @TingPing for actual bubblewrap functionality part or any other comments he might have.

Comment thread Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp Outdated
continue;

CString path = FileSystem::pathByAppendingComponent("/dev"_s, fileName).utf8();
args.appendVector(Vector<CString>({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Vector::appendList() is more efficient, as it avoids having to create an intermediate vector.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The entire file uses appendVector for this, so I think it'll be best to make that a separate change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you planning to fix this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like you have beat me to it!

@csaavedra csaavedra removed the merging-blocked Applied to prevent a change from being merged label Mar 30, 2026
@csaavedra csaavedra added unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing GLib Suggested Backport - 2.52 Suggest this merge request be backported to the webkitglib/2.52 stable branch labels Mar 30, 2026
https://bugs.webkit.org/show_bug.cgi?id=311007

Reviewed by Claudio Saavedra and Patrick Griffis.

Although GTK uses xdg-desktop-portal for cameras, it still needs V4L2
devices to be exposed in the sandbox to make V4L2 video decode work.

WPE already exposed some nodes, but not enough for some platforms,
such as i.MX 8M Quad, where there are 2 camera and 2 VPU nodes.

Make both GTK and WPE expose all V4L2 nodes.

* Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp:
(WebKit::bindV4l):
(WebKit::bubblewrapSpawn):

Canonical link: https://commits.webkit.org/310201@main
@webkit-commit-queue
Copy link
Copy Markdown
Collaborator

Committed 310201@main (67bd935): https://commits.webkit.org/310201@main

Reviewed commits have been landed. Closing PR #61600 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 67bd935 into WebKit:main Mar 30, 2026
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Mar 30, 2026
@aperezdc
Copy link
Copy Markdown
Contributor

Backported into webkitglib/2.52 as commit 2e84277

@aperezdc aperezdc removed the GLib Suggested Backport - 2.52 Suggest this merge request be backported to the webkitglib/2.52 stable branch label Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants