Skip to content

Add decoded {Audio,Video}Info support to toCMSampleBuffer - #77260

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
jyavenard:eng/Add-decoded-AudioInfo-VideoInfo-support-to-toCMSampleBuffer
Oct 16, 2026
Merged

webkit-commit-queue merged 1 commit into
WebKit:mainfrom
jyavenard:eng/Add-decoded-AudioInfo-VideoInfo-support-to-toCMSampleBuffer

Conversation

@jyavenard

@jyavenard jyavenard commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

b14fee8

Add decoded {Audio,Video}Info support to toCMSampleBuffer
https://bugs.webkit.org/show_bug.cgi?id=327811
rdar://190200035

Reviewed by Jer Noble.

toCMSampleBuffer() and createFormatDescriptionFromTrackInfo() only handled
compressed content. A MediaSamplesBlock holding decoded audio or video
(AudioInfo::isDecoded() / VideoInfo::isDecoded()) either got a compressed-style
format description, or, for LPCM, a sample buffer whose sample count was the
number of items and whose size array held one entry per item instead of
frames.

Decoded audio now produces one constant bitrate sample buffer: the sample count
is the frame count, a single timing entry holds the duration of one frame, and
only interleaved F32 is accepted. Decoded video produces an IOSurface-backed
biplanar CVPixelBuffer repacked from I420, with the colour and aspect ratio
properties attached, and a sample buffer holding that image buffer. A video
block must hold exactly one frame. The extension properties shared by format
descriptions and image buffers are moved into addImageBufferProperties().

* Source/WebCore/platform/graphics/cocoa/CMUtilities.mm:
(WebCore::pixelFormatTypeForDecodedVideo): Added.
(WebCore::addImageBufferProperties): Added, moved from
createFormatDescriptionFromTrackInfo().
(WebCore::createFormatDescriptionFromTrackInfo): Use the pixel format as the
codec type for decoded video, reject decoded audio that isn't F32.
(WebCore::decodedAudioToCMSampleBuffer): Added.
(WebCore::copyI420ToBiplanarPixelBuffer): Added.
(WebCore::decodedVideoToCMSampleBuffer): Added.
(WebCore::toCMSampleBuffer): Handle decoded audio and video.
* Tools/TestWebKitAPI/PlatformCocoa.cmake:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebCore/cocoa/DecodedMediaSamplesBlockTests.mm: Added.
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, AudioToCMSampleBuffer)):
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, AudioDiscontinuityAttachment)):
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, AudioRejectsInvalidData)):
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, VideoToCMSampleBuffer)):
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, VideoWithOddDimensions)):
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, VideoRejectsInvalidData)):
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, VideoFormatDescriptionFromTrackInfo)):

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

770da1e

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ⏳ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug   🧪 wpe-wk2 ⏳ 🧪 win-tests ⏳ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ⏳ 🧪 api-mac ✅ 🧪 api-wpe ⏳ 🛠 vision-apple
loading 🧪 ios-wk2-wpt ⏳ 🧪 api-mac-debug
⏳ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk3-gcc
⏳ 🛠 ios-safer-cpp ⏳ 🧪 mac-AS-debug-wk2 ✅ 🛠 gtk
✅ 🛠 vision loading 🧪 gtk-wk2
✅ 🛠 🧪 merge ✅ 🛠 vision-sim ⏳ 🧪 mac-intel-wk2 ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🛠 mac-safer-cpp ✅ 🛠 playstation
✅ 🛠 tv ✅ 🧪 mac-site-isolation
⏳ 🛠 tv-sim
⏳ 🛠 watch
✅ 🛠 watch-sim

@jyavenard jyavenard self-assigned this Oct 16, 2026
@jyavenard jyavenard added the Media Bugs related to the HTML 5 Media elements. label Oct 16, 2026
@jyavenard
jyavenard requested a review from a team October 16, 2026 08:22
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Oct 16, 2026
@jyavenard jyavenard removed the merging-blocked Applied to prevent a change from being merged label Oct 16, 2026
@jyavenard
jyavenard force-pushed the eng/Add-decoded-AudioInfo-VideoInfo-support-to-toCMSampleBuffer branch from bbb8358 to c2ae121 Compare October 16, 2026 08:54
@webkit-ews-buildbot

Copy link
Copy Markdown
Collaborator

macOS Safer C++ Build #140313 (c2ae121)

❌ Found 1 failing file with 2 issues. 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 Oct 16, 2026
@jyavenard
jyavenard force-pushed the eng/Add-decoded-AudioInfo-VideoInfo-support-to-toCMSampleBuffer branch from c2ae121 to c1de520 Compare October 16, 2026 13:33
@jyavenard
jyavenard force-pushed the eng/Add-decoded-AudioInfo-VideoInfo-support-to-toCMSampleBuffer branch from c1de520 to c2ae121 Compare October 16, 2026 14:08
@webkit-ews-buildbot

Copy link
Copy Markdown
Collaborator

macOS Safer C++ Build #140348 (c2ae121)

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

@jyavenard
jyavenard force-pushed the eng/Add-decoded-AudioInfo-VideoInfo-support-to-toCMSampleBuffer branch from c2ae121 to 2ae2274 Compare October 16, 2026 15:26

// The 8-bit planar formats are repacked into a biplanar buffer when the CVPixelBuffer is created.
switch (*info.pixelFormat()) {
case VideoPixelFormat::I420:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couldn't this whole function be an equality check with this value?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have more to come, I limited to 8bits / I420 for now as the VideoDecoder don't support more than that for now

return createAudioFormatDescription(*audioInfo);
#endif
case kAudioFormatLinearPCM: {
if (audioInfo->sampleFormat() && *audioInfo->sampleFormat() != AudioSampleFormat::F32)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If sampleFormat() is an optional, this deref and nil check is unnecessary.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

not really, they differ when sampleFormat() is nullopt. WebM can contain a PCM 32 when mkv supports is true.

and in this case sampleFormat() would return std::nullopt

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed it to if (audioInfo->isDecoded() && audioInfo->sampleFormat() != AudioSampleFormat::F32) it's clearer

@jyavenard
jyavenard force-pushed the eng/Add-decoded-AudioInfo-VideoInfo-support-to-toCMSampleBuffer branch from 2ae2274 to 770da1e Compare October 16, 2026 16:07
@jyavenard jyavenard added merge-queue Applied to send a pull request to merge-queue and removed merging-blocked Applied to prevent a change from being merged labels Oct 16, 2026
https://bugs.webkit.org/show_bug.cgi?id=327811
rdar://190200035

Reviewed by Jer Noble.

toCMSampleBuffer() and createFormatDescriptionFromTrackInfo() only handled
compressed content. A MediaSamplesBlock holding decoded audio or video
(AudioInfo::isDecoded() / VideoInfo::isDecoded()) either got a compressed-style
format description, or, for LPCM, a sample buffer whose sample count was the
number of items and whose size array held one entry per item instead of
frames.

Decoded audio now produces one constant bitrate sample buffer: the sample count
is the frame count, a single timing entry holds the duration of one frame, and
only interleaved F32 is accepted. Decoded video produces an IOSurface-backed
biplanar CVPixelBuffer repacked from I420, with the colour and aspect ratio
properties attached, and a sample buffer holding that image buffer. A video
block must hold exactly one frame. The extension properties shared by format
descriptions and image buffers are moved into addImageBufferProperties().

* Source/WebCore/platform/graphics/cocoa/CMUtilities.mm:
(WebCore::pixelFormatTypeForDecodedVideo): Added.
(WebCore::addImageBufferProperties): Added, moved from
createFormatDescriptionFromTrackInfo().
(WebCore::createFormatDescriptionFromTrackInfo): Use the pixel format as the
codec type for decoded video, reject decoded audio that isn't F32.
(WebCore::decodedAudioToCMSampleBuffer): Added.
(WebCore::copyI420ToBiplanarPixelBuffer): Added.
(WebCore::decodedVideoToCMSampleBuffer): Added.
(WebCore::toCMSampleBuffer): Handle decoded audio and video.
* Tools/TestWebKitAPI/PlatformCocoa.cmake:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebCore/cocoa/DecodedMediaSamplesBlockTests.mm: Added.
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, AudioToCMSampleBuffer)):
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, AudioDiscontinuityAttachment)):
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, AudioRejectsInvalidData)):
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, VideoToCMSampleBuffer)):
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, VideoWithOddDimensions)):
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, VideoRejectsInvalidData)):
(TestWebKitAPI::TEST(DecodedMediaSamplesBlock, VideoFormatDescriptionFromTrackInfo)):

Canonical link: https://commits.webkit.org/323980@main
@webkit-commit-queue
webkit-commit-queue force-pushed the eng/Add-decoded-AudioInfo-VideoInfo-support-to-toCMSampleBuffer branch from 770da1e to b14fee8 Compare October 16, 2026 16:54
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 323980@main (b14fee8): https://commits.webkit.org/323980@main

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

@webkit-commit-queue
webkit-commit-queue merged commit b14fee8 into WebKit:main Oct 16, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Oct 16, 2026
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