Skip to content

[Cocoa] Adopt VTDecompressionSessionDecodeFrameWithMultiImageCapableOutputHandler to decode stereo images #47186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jyavenard
Copy link
Member

@jyavenard jyavenard commented Jun 25, 2025

c0688ab

[Cocoa] Adopt VTDecompressionSessionDecodeFrameWithMultiImageCapableOutputHandler to decode stereo images
https://bugs.webkit.org/show_bug.cgi?id=295143
rdar://154516073

Reviewed by Jer Noble.

In 296748@main we fixed a regression caused by 295444@main. The change was
a simple temporary workaround to disable MediaSourcePrefersDecompressionSession
for spatial or immersive videos as WebCoreDecompressionSession didn't
decode stereo images. We now use the VTDecompressionSessionDecodeFrameWithMultiImageCapableOutputHandler
method instead which can handle both images in CMSampleBuffer to decode.

We add support for decoding multi-images (stereo) samples and readback of
such images.

As such, we can revert 296748@main which is no longer needed.

We make WebCoreDecompression's WorkQueue a singleton. It simplifies the code
a bit and this workqueue carries very little load as all the object it uses already
use their own workqueues.

Spatial portal manually tested on visionOS.
Added test to verify decoding and readback when playing a spatial video in stereo mode.

* LayoutTests/media/media-source/content/test-spatial-manifest.json: Added.
* LayoutTests/media/media-source/content/test-spatial.mp4: Added.
* LayoutTests/media/media-source/media-source-paint-stereo-to-canvas-expected.txt: Added.
* LayoutTests/media/media-source/media-source-paint-stereo-to-canvas.html: Added.
* Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.cpp: Adding dynamically linked methods
* Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.h:
* Source/WebCore/platform/cocoa/VideoToolboxSoftLink.cpp: Adding dynamically linked methods
* Source/WebCore/platform/cocoa/VideoToolboxSoftLink.h:
* Source/WebCore/platform/graphics/avfoundation/FormatDescriptionUtilities.cpp:
(WebCore::spatialVideoMetadataFromFormatDescription): Remove canLoad method for symbols that will always be found.
* Source/WebCore/platform/graphics/cocoa/VideoMediaSampleRenderer.mm:
(WebCore::VideoMediaSampleRenderer::enqueueSample): Revert 296748@main as it's no longer needed.
(WebCore::VideoMediaSampleRenderer::decodeNextSampleIfNeeded):
(WebCore::VideoMediaSampleRenderer::imageForSample const): Handle multi-images sample
(WebCore::VideoMediaSampleRenderer::assignResourceOwner): Amend to assign all multi-images sample's IOSurfaces

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

96af1f0

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

@jyavenard jyavenard self-assigned this Jun 25, 2025
@jyavenard jyavenard added the Media Bugs related to the HTML 5 Media elements. label Jun 25, 2025
@webkit-ews-buildbot
Copy link
Collaborator

Safer C++ Build #41549 (5e4a146)

❌ Found 1 failing file with 1 issue. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@jyavenard jyavenard force-pushed the eng/Safari-shows-black-UI-after-entering-Portal-Mode-for-MSE-spatial-Videos branch from 5e4a146 to 6eb05b2 Compare June 25, 2025 23:17
@jyavenard jyavenard force-pushed the eng/Safari-shows-black-UI-after-entering-Portal-Mode-for-MSE-spatial-Videos branch from 6eb05b2 to 701b299 Compare June 26, 2025 02:15
@jyavenard jyavenard force-pushed the eng/Safari-shows-black-UI-after-entering-Portal-Mode-for-MSE-spatial-Videos branch from 701b299 to 16bafbc Compare June 26, 2025 02:37
@jyavenard jyavenard force-pushed the eng/Safari-shows-black-UI-after-entering-Portal-Mode-for-MSE-spatial-Videos branch from 16bafbc to c655439 Compare June 26, 2025 02:40
@webkit-ews-buildbot
Copy link
Collaborator

Safer C++ Build #41610 (6eb05b2)

❌ Found 1 failing file with 1 issue. Please address these issues before landing. See WebKit Guidelines for Safer C++ Programming.
(cc @rniwa)

@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 26, 2025
Copy link
Contributor

@jernoble jernoble left a comment

Choose a reason for hiding this comment

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

r=me with nit

Comment on lines 157 to 162
#if PLATFORM(VISION)
m_stereoViewMap.clear();
RetainPtr<CFMutableArrayRef> layersArray = nullptr;
// Get the tag collection array
CFArrayRef rawTagCollectionArray = nullptr;
if (auto status = PAL::CMVideoFormatDescriptionCopyTagCollectionArray(videoFormatDescription, &rawTagCollectionArray); status == noErr && rawTagCollectionArray) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this is a pretty deep nested if/for/if/if section. Consider refactoring to use continue or early return to flatten and make the resulting code more readable.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's a draft still.

@jyavenard jyavenard removed the merging-blocked Applied to prevent a change from being merged label Jun 27, 2025
@jyavenard jyavenard force-pushed the eng/Safari-shows-black-UI-after-entering-Portal-Mode-for-MSE-spatial-Videos branch from c655439 to ca45962 Compare June 27, 2025 12:28
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 27, 2025
@jyavenard jyavenard removed the merging-blocked Applied to prevent a change from being merged label Jun 28, 2025
@jyavenard jyavenard force-pushed the eng/Safari-shows-black-UI-after-entering-Portal-Mode-for-MSE-spatial-Videos branch from ca45962 to 7f5d9c5 Compare June 28, 2025 07:25
@jyavenard jyavenard changed the title Safari shows black UI after entering Portal Mode for MSE spatial Videos. [Cocoa] Adopt VTDecompressionSessionDecodeFrameWithMultiImageCapableOutputHandler to decode stereo images Jun 28, 2025
@jyavenard jyavenard force-pushed the eng/Safari-shows-black-UI-after-entering-Portal-Mode-for-MSE-spatial-Videos branch from 7f5d9c5 to 460473b Compare June 28, 2025 07:42
@jyavenard jyavenard requested a review from jernoble June 28, 2025 07:43
@jyavenard jyavenard marked this pull request as ready for review June 28, 2025 07:43
@jyavenard jyavenard requested review from cdumez and rniwa as code owners June 28, 2025 07:43
@jyavenard jyavenard force-pushed the eng/Safari-shows-black-UI-after-entering-Portal-Mode-for-MSE-spatial-Videos branch from 460473b to 7bc6408 Compare June 28, 2025 08:12
@jyavenard jyavenard force-pushed the eng/Safari-shows-black-UI-after-entering-Portal-Mode-for-MSE-spatial-Videos branch from 7bc6408 to a350070 Compare June 28, 2025 10:00
@jyavenard jyavenard changed the title [Cocoa] Adopt VTDecompressionSessionDecodeFrameWithMultiImageCapableOutputHandler to decode stereo images test disabling HEVC stereo key Jun 28, 2025
@jyavenard jyavenard force-pushed the eng/Safari-shows-black-UI-after-entering-Portal-Mode-for-MSE-spatial-Videos branch from 132092b to 4a997dd Compare June 28, 2025 11:58
@jyavenard jyavenard changed the title test disabling HEVC stereo key have video in DOM and visible. Jun 28, 2025
@jyavenard jyavenard force-pushed the eng/Safari-shows-black-UI-after-entering-Portal-Mode-for-MSE-spatial-Videos branch from 4a997dd to 35e3261 Compare June 28, 2025 14:12
@jyavenard jyavenard changed the title have video in DOM and visible. [Cocoa] Adopt VTDecompressionSessionDecodeFrameWithMultiImageCapableOutputHandler to decode stereo images Jun 28, 2025
@jyavenard jyavenard force-pushed the eng/Safari-shows-black-UI-after-entering-Portal-Mode-for-MSE-spatial-Videos branch from 35e3261 to 96af1f0 Compare June 28, 2025 15:38
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jun 28, 2025
@jyavenard jyavenard requested a review from a team June 28, 2025 22:56
@jyavenard jyavenard removed the merging-blocked Applied to prevent a change from being merged label Jun 30, 2025
@jyavenard jyavenard added the merge-queue Applied to send a pull request to merge-queue label Jul 1, 2025
…utputHandler to decode stereo images

https://bugs.webkit.org/show_bug.cgi?id=295143
rdar://154516073

Reviewed by Jer Noble.

In 296748@main we fixed a regression caused by 295444@main. The change was
a simple temporary workaround to disable MediaSourcePrefersDecompressionSession
for spatial or immersive videos as WebCoreDecompressionSession didn't
decode stereo images. We now use the VTDecompressionSessionDecodeFrameWithMultiImageCapableOutputHandler
method instead which can handle both images in CMSampleBuffer to decode.

We add support for decoding multi-images (stereo) samples and readback of
such images.

As such, we can revert 296748@main which is no longer needed.

We make WebCoreDecompression's WorkQueue a singleton. It simplifies the code
a bit and this workqueue carries very little load as all the object it uses already
use their own workqueues.

Spatial portal manually tested on visionOS.
Added test to verify decoding and readback when playing a spatial video in stereo mode.

* LayoutTests/media/media-source/content/test-spatial-manifest.json: Added.
* LayoutTests/media/media-source/content/test-spatial.mp4: Added.
* LayoutTests/media/media-source/media-source-paint-stereo-to-canvas-expected.txt: Added.
* LayoutTests/media/media-source/media-source-paint-stereo-to-canvas.html: Added.
* Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.cpp: Adding dynamically linked methods
* Source/WebCore/PAL/pal/cf/CoreMediaSoftLink.h:
* Source/WebCore/platform/cocoa/VideoToolboxSoftLink.cpp: Adding dynamically linked methods
* Source/WebCore/platform/cocoa/VideoToolboxSoftLink.h:
* Source/WebCore/platform/graphics/avfoundation/FormatDescriptionUtilities.cpp:
(WebCore::spatialVideoMetadataFromFormatDescription): Remove canLoad method for symbols that will always be found.
* Source/WebCore/platform/graphics/cocoa/VideoMediaSampleRenderer.mm:
(WebCore::VideoMediaSampleRenderer::enqueueSample): Revert 296748@main as it's no longer needed.
(WebCore::VideoMediaSampleRenderer::decodeNextSampleIfNeeded):
(WebCore::VideoMediaSampleRenderer::imageForSample const): Handle multi-images sample
(WebCore::VideoMediaSampleRenderer::assignResourceOwner): Amend to assign all multi-images sample's IOSurfaces

Canonical link: https://commits.webkit.org/296854@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Safari-shows-black-UI-after-entering-Portal-Mode-for-MSE-spatial-Videos branch from 96af1f0 to c0688ab Compare July 1, 2025 06:47
@webkit-commit-queue
Copy link
Collaborator

Committed 296854@main (c0688ab): https://commits.webkit.org/296854@main

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

@webkit-commit-queue webkit-commit-queue merged commit c0688ab into WebKit:main Jul 1, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Media Bugs related to the HTML 5 Media elements.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants