feat(libwebrtc): implement VideoFrameBuffer::CropAndScale on libyuv #26446
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26446"
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-23T22:41:48Z.
What
Resubmission of #26079, which was closed when my fork left the fork network (I switched it to private by mistake) and cannot be reopened. Same head commit
d3a8483c274; the reviews and the discussion are on #26079.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-23T23:10:23Z.
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 catminou4 on 2026-11-23T23:16:28Z.
Review: COMMENTED
Built
libwebrtc(with the new3rdparty/libyuvsubmodule at10592b60) and ran on Linux (x86-64, GCC 11):guest_webrtc_crop_and_scale— passesguest_webrtc_i420_buffer_create_{create,virtuals,invalid}— all three pass (note: this test is parameterized by case, so it needs the arg; running it bare aborts, which is expected)python3 tools/tests/test_package_release.py— 140 tests OK (the renamedtest_webrtc_library_archives_include_vad_and_scaler_noticescovers the new libyuv LICENSE/PATENTS packaging)New VideoFrameBuffer::CropAndScale / I420BufferCreate surface, so no meaningful
maincontrol. The debt fragment is honest: scaling follows M134video_frame_buffer.cc/i420_buffer.ccwithlibyuv::I420Scaleat M134's DEPS revision, warns the module revision is unknown and that without SSSE3 a pixel can differ by one step, and documents the argument-validation divergences (upstream aborts / reads past planes / returns unscaled where this throwsstd::invalid_argument). License/patent notices are correctly wired intopackage_release.pyand the files exist in the submodule.