feat(libwebrtc): implement VideoFrameBuffer::CropAndScale on libyuv #26079
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26079"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by ToRaNek on 2026-11-23T07:39:46Z.
What
webrtc::VideoFrameBuffer::CropAndScalewas a stub inlibwebrtc, although it sits in the virtual table of every bufferI420Buffer::Createmakes. This implements it fromapi/video/video_frame_buffer.ccandI420Buffer::CropAndScaleFromofapi/video/i420_buffer.cc, at the commit the library already pins (M134,8d78f5de):ToI420slot, so a guest buffer of another type is scaled from what it converts to, and that reference is released at the end;Create(the width, and half the width rounded up);libyuv::I420Scalewith the box filter.Order and refusals. Upstream creates the destination first and checks afterwards, with
RTC_CHECKs that abort. Here every argument is checked before anything is allocated, and the buffer is created last; for a call that succeeds the two orders give the same result. A refused call throwsstd::invalid_argumentand leaves the result pointer, the reference counts and the heap as they were:int(computed in 64 bits; the chroma stride iswidth / 2 + width % 2, which cannot overflow);INT_MINwould also be negated inside libyuv before its own check;ToI420that returns nothing, a null plane.If libyuv itself fails after that (its only remaining reason is its own allocation), the new buffer is released and
std::runtime_erroris thrown.libyuv. The scaler is upstream's own:
3rdparty/libyuvis a new submodule at10592b60, the revision theDEPSfile of that WebRTC commit pins. Awebrtc_yuvstatic target incore/libs/CMakeLists.txtbuilds the ten sources the scaler needs and is linked privately intolibwebrtc, next tofvad; the configuration stops with thegit submodule update --init 3rdparty/libyuvinstruction when the submodule is empty. ItsLICENSEandPATENTSjoin the noticestools/package_release.pyships withlibwebrtc.prx.libyuv is built as upstream builds it, with its x86 rows chosen from the host CPU. I measured the alternative: on a Zen 2 host, a build limited to the C rows gives other pixels than the SSSE3 and AVX2 rows for the 3/4 and 3/8 ratios (1280x720 to 960x540 for one), and the same pixels for the other ratios I tried, so a C-only build would not follow the console's CPU on common sizes.
Recorded in the debt entry: the module's libyuv revision is unknown; a host without SSSE3 can differ by a rounding step; the refusals above.
Tested
Windows 11, MinGW GCC 15.2, Ryzen 5 3600. Not tested on a console. A reviewer built and ran the two test targets on Ubuntu 24.04 with GCC 13.3 at an earlier head.
guest_webrtc_crop_and_scaletest.(sum * (65536 / 9)) >> 16.ToI420is called once, its result is read and released once; a guest I420 buffer with unusual strides; the same buffer with each plane null in turn.int, flipped crops taller than what is left below the offset, zero and negative widths, zero heights,INT_MIN), 15 scaled sizes (zero, negative,INT_MAXandINT_MINon each axis, sizes whose luma or chroma alone would fit), a null conversion. After each one the result pointer is untouched, no reference is left and the allocator was not called; on a guest buffer a refused size or crop size is reported beforeToI420is called.guest_webrtc_i420_buffer_create_virtualsrequired the stub to throw; it now checks the buffer the slot returns. The 119guest_webrtctests pass.python -m unittest tools.tests.test_package_releasepasses (140 tests), with the libyuv notices added to the WebRTC case.src/VideoFrameBufferCropAndScale.cpp, each rebuilt and run against the test: every table slot, each term and bound of the size, crop and rectangle checks, the 32768 limit on both sides, the 64-bit sums, the magnitude of a negative height, the rounding of the offsets and of the chroma stride, each null-plane test, the origin and the stride of each plane, the order of the planes and of the sizes on both sides of the scaler, the filter, each release. All 89 make the test fail. Not covered by a control: the branch taken when libyuv fails after the buffer exists, and the release of the buffer on that branch, which the test cannot reach. Two terms of upstream's rectangle check,crop_width <= widthandcrop_height <= height, follow from the others and are not repeated.python tools/check_conventions.py --base origin/main,python tools/debt_fold.py --checkandpython core/libs/tests/test_public_headers.py --audit-onlypass.Not verified. I read no console module: the revision of libyuv it embeds and the rows it selects are not known. The failure of libyuv after the buffer is created cannot be provoked from the test.
Overlap (
python tools/pr_overlap.py --branch feat/webrtc-video-frame-buffer-crop-and-scale):The tool reports no conflicting file and no shared export, then ends with
overlap check failed closed: 17 open PRs that conflict withmainshare.gitmodules(#1835),core/libs/CMakeLists.txt(#7275, #8650, #9156, #9293, #9297, #9302, #9383, #12642, #16793, #19542, #20315, #23786, #24322, #24917) orExport.cppandApi.hppoflibwebrtc(#18498, #24668), so it cannot compare them. I compared each by hand (its diff againstmainon those files and oncore/libs/prx/libwebrtc): none mentions libyuv,I420ScaleorCropAndScale.python tools/pr_overlap.py --nameson the symbol answersopen: no matching PS5 export changes.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-23T07:41:32Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
b205cff00c:tools/check_conventions.pypassed.CMakeLists.txtfailed to build.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T07:51:07Z.
Review: CHANGES_REQUESTED
The crop rectangle guard uses the signed
cropHeight, but negative heights are intentionally accepted and libyuv immediately negates them to obtain the row count before scaling. An inverted crop whose magnitude extends past the bottom of the source can therefore pass the current check even though the scaler consumes more rows than the validated rectangle.Please validate
offsetY + magnitude(cropHeight)in a wide integer before any plane-pointer calculation or scaler call, while preserving the original signed height when calling libyuv so valid vertical inversion still works. The regression should prove that a valid inverted crop reaches the scaler, while an oversized inverted extent throws the existinginvalid_argumentwith the result/reference state unchanged and no scaler invocation.Verification at
b205cff00c49eeb1e4390d4e57383efa8d39e260was deliberately memory-safe: a fail-closed scaler stand-in counted dispatches and never read image planes. The exact PR guard forwarded both the valid inverted crop and the oversized extent (exit 7); the magnitude-based control forwarded only the valid case (exit 0). Pinned libyuv'sScalePlaneconfirms the negative-height inversion, and the targeted pinned-libyuv build plus existing positive pixel subset passed. I did not execute an out-of-bounds read. The full standalone suite was not claimed because the reused older libc hit an unwind limitation. Conventions and merge preview passed; hosted release-tools and portability checks are green, with Windows still running. No GPU test was run.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T07:59:10Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: reject invalid crop dimensions before using them to create the destination buffer.
What I ran
Reviewed head
b205cff00c49eeb1e4390d4e57383efa8d39e260and the prepared diff. No build or tests were run.Results
Findings
Blocking
core/libs/prx/libwebrtc/src/VideoFrameBufferCropAndScale.cpp:105: The destination is created before validating the crop. In particular,cropHeight == INT_MINpasses the current upper-bound and negative-offset checks, but libyuv negates negative source height when setting up vertical scaling; negatingINT_MINoverflows. This can invoke undefined behavior for an input the implementation otherwise accepts. Validate crop dimensions before destination creation, rejectingINT_MIN(and any other unsupported dimension) while preserving intentionally supported negative-height flips.Non-blocking
None.
Not verified
The submodule entry is present, but its checkout contents were excluded because it is not plain text; its source files,
LICENSE, andPATENTSwere not inspected. Console behavior and the author-reported build and test runs were not independently verified. The remaining changed files listed in the manifest were not read:core/libs/prx/libwebrtc/tests/VideoFrameBufferCropAndScale.cpp,core/libs/prx/libwebrtc/Export.cpp, andcore/libs/prx/libwebrtc/include/Api.hppwere partially reviewed through the diff where relevant; other changed-file text and tests were not fully verified.To get this to a good state
Reject the
INT_MINcrop height before destination creation and add a regression test that confirms it is refused without allocation or changing the result pointer. Then rerun the crop-and-scale and library test suites.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-23T08:28:04Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
7f04c46d8e:tools/check_conventions.pypassed.CMakeLists.txtfailed to build.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T08:33:49Z.
Review: APPROVED
Re-reviewed fix head
7f04c46d8e08e1ed9cf0be31dd999cd5c494e559. This resolves my negative-height boundary finding. The implementation promotescropHeighttoint64_tbefore negation, validatesmagnitude + offsetYagainst the converted I420 source height before any plane offset orI420Scale, and preserves the original signed height when calling libyuv so valid vertical inversion still works (including theINT_MINconversion boundary).The positive inverted-window fixture reads all three Y/U/V planes backward. Eight refusal cases now verify
invalid_argument, unchanged result pointer/reference count and allocation balance; three accepted boundary controls remain. The result is assigned only after a successful scale, and temporary RAII references unwind on rejection.The pinned libyuv Gitlink is unchanged and the official remote contains the required scale/cpu/header sources at that exact commit. The reported Linux configure failure was a locally uninitialized submodule, not a compiler result. The prior exact-topic Windows job built the libyuv objects and ran
guest_webrtc_crop_and_scalesuccessfully; new portability/release-tools checks are green and the replacement workflow is starting. I deliberately did not execute any out-of-bounds access or GPU test.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T08:34:23Z.
Review: CHANGES_REQUESTED
I need to supersede my approval after the continuing boundary audit found one separate blocker in the same input-validation path. The negative
cropHeightissue is fixed, but the destination chroma stride is still computed as(scaledWidth + 1) / 2in signedintbeforeI420Buffer::Createvalidates dimensions. For a validintinput ofINT_MAX, the addition itself overflows; the later size/dimension rejection cannot make that expression defined.Please validate the destination dimensions before deriving strides and compute the ceil-half width without signed overflow (for example in
int64_t, with a checked conversion, orscaledWidth / 2 + scaledWidth % 2after proving it positive). Add a boundary regression showing the largest input is rejected deterministically with the result pointer/reference/allocation state unchanged and no allocator/scaler call.This is a source-level arithmetic finding at
VideoFrameBufferCropAndScale.cpp:105; I did not execute the undefined expression or any out-of-bounds access. The prior review's evidence for the corrected inverted-crop extent remains valid and does not need to be redone.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T08:42:03Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
7f04c46d8e08e1ed9cf0be31dd999cd5c494e559againstmainusing the prepared diff andrepo_read.py. No commands or tests were run independently.Results
Negative control
Not run independently. The description reports 65 single-change negative controls, each failing the new test.
Findings
Blocking
None.
Non-blocking
Sources
Reviewed the prepared diff and changed source at the pinned head, including
core/libs/prx/libwebrtc/src/VideoFrameBufferCropAndScale.cpp,core/libs/CMakeLists.txt,core/libs/prx/libwebrtc/CMakeLists.txt, and the changed tests and release packaging code.Not verified
3rdparty/libyuvis a changed gitlink and its checked-out contents were unavailable as text; only its pinned commit shown in the diff was reviewed.To get this to a good state
Nothing is required. Optional: verify the pinned submodule contents and console behavior when available.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T08:53:22Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
9e711745aed1a8dc7101bfd642da9e8a9f0dd201. The new ceil-half expression is defined for everyint, but the requested validation order is not fixed yet: line 106 still entersI420Buffer::Createbefore validating either the destination dimensions or the source rectangle.Createallocates the ref-counted object shell beforeI420DataSizerejects the dimensions, so the current allocation-balance assertion does not establish the maintainer-requested zero allocator call; the boundary cases also still expectruntime_errorrather than the requestedinvalid_argument.Continuing the same source-only boundary audit found one separate lower-bound gap at line 114, described inline. Please validate the destination dimensions/size before
Create, and reject non-positive crop widths before plane calculation or scaler dispatch. A fail-closed scaler/allocator counter can cover both without executing an invalid expression.I inspected the exact PR source,
I420Buffer::Create, the test fixture, and pinned libyuvscale.cc. I did not execute undefined arithmetic, an out-of-bounds access, or a GPU test.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T08:56:06Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the implementation and its changed call sites are supported by the inspected code, with the libyuv submodule contents and console behavior not verified.
What I ran
Reviewed head
9e711745aed1a8dc7101bfd642da9e8a9f0dd201using the prepared diff and repository reader. No build or tests were run during this review; results reported in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The changed text files were read, including the implementation, tests, build and packaging changes, debt entry, and
.gitmodules. The3rdparty/libyuvsubmodule pointer was present in the diff, but its checked-out source and license files were excluded as unsupported; their contents were not verified. No tests were run during this review, and no console behavior was verified. The PR description reports Windows/MinGW test runs and explicitly says console behavior is untested.To get this to a good state
Nothing is required.
Sources
The changed implementation and its associated tests are in VideoFrameBufferCropAndScale.cpp at the reviewed commit and its test at the reviewed commit.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-23T09:03:42Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
9e711745ae:tools/check_conventions.pypassed.guest_webrtc_crop_and_scale_tests,guest_webrtc_i420_buffer_create_testsbuilt cleanly.guest_webrtc_i420_buffer_create_create,guest_webrtc_i420_buffer_create_virtuals,guest_webrtc_i420_buffer_create_invalid,guest_webrtc_crop_and_scale):core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hpp,core/libs/prx/libwebrtc/src/VideoFrameBufferCropAndScale.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-23T10:34:58Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d3a8483c27:tools/check_conventions.pypassed.guest_webrtc_crop_and_scale_tests,guest_webrtc_i420_buffer_create_testsbuilt cleanly.guest_webrtc_i420_buffer_create_create,guest_webrtc_i420_buffer_create_virtuals,guest_webrtc_i420_buffer_create_invalid,guest_webrtc_crop_and_scale):core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hpp,core/libs/prx/libwebrtc/src/VideoFrameBufferCropAndScale.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T10:42:28Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed implementation and build/package integration were inspected at head
d3a8483c274de7c7bdbf2fdb16568658d736170f; no concrete blocking defect was verified, but tests were not run and the libyuv submodule contents were unavailable for review.What I ran
No commands or tests were run. I read the prepared description, commits, diff, manifest, review README, and targeted source ranges at the pinned head. The changed files inspected were
.gitmodules,3rdparty/libyuv(submodule pointer only),core/libs/CMakeLists.txt,core/libs/prx/libwebrtc/CMakeLists.txt,core/libs/prx/libwebrtc/Export.cpp,core/libs/prx/libwebrtc/include/Api.hpp,core/libs/prx/libwebrtc/src/VideoFrameBufferCropAndScale.cpp,core/libs/prx/libwebrtc/src/I420Buffer.cpp,core/libs/prx/libwebrtc/tests/I420BufferCreate.cpp(diff),core/libs/prx/libwebrtc/tests/VideoFrameBufferCropAndScale.cpp(diff and selected ranges),docs/dev/debt/changes/feat-webrtc-video-frame-buffer-crop-and-scale.md,tools/package_release.py, andtools/tests/test_package_release.py(diff).3rdparty/libyuvwas excluded because its text was unavailable.Results
Findings
Blocking
None verified.
Non-blocking
No additional comments.
Not verified
The libyuv source and license files at the submodule revision, console behavior, and author-reported build and test results were not independently verified. Some changed test-file ranges were not read in full.
To get this to a good state
Nothing is required. The implementation has extensive author-reported tests, but those results were not rerun during this review.
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T11:46:59Z.
Review: APPROVED
Re-reviewed exact head
d3a8483c274de7c7bdbf2fdb16568658d736170f. This supersedes my earlier change request.The remaining scaler-input/result blockers are fixed: non-positive crop widths and zero crop heights (including the
INT_MINpaths) are rejected before conversion or allocation; destination plane sizing is checked in 64 bits beforeCreate; source extent and null planes are checked before dispatch; and the result is published only afterI420Scalereturns success. Temporary references remain RAII-managed. As clarified earlier, I do not retain the allocation order as a separate blocker.My exact-head source and test syntax checks, diff/merge checks, and conventions check passed. PrivacyOnion independently built and passed the four focused WebRTC tests on Linux with a negative control. The exact-head hosted Windows job is now green: it built and passed
guest_webrtc_crop_and_scale, and completed 5,648 executed tests with zero failures. The Windows relinker, Linux/macOS relinkers, and relinker ASan jobs are also green.I did not test console behavior or a GPU path.
AI-assisted: yes.
Pull request closed