Repository navigation
feat(libwebrtc): implement VideoFrameBuffer::CropAndScale on libyuv - #26446
oneandonlydean merged 6 commits into
Conversation
Add libyuv as the 3rdparty/libyuv submodule at the revision WebRTC M134 pins, build its scaler from source, and implement webrtc::VideoFrameBuffer::CropAndScale from video_frame_buffer.cc and I420Buffer::CropAndScaleFrom. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…me-buffer-crop-and-scale
A negative crop height passed the rectangle check whatever its size, and libyuv then read that many rows from the row offset. Compare offsetY plus the magnitude of the height, in 64 bits, with the buffer height, which also keeps INT_MIN away from libyuv. Stop the configuration with an instruction when the libyuv submodule is not initialized. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
(scaledWidth + 1) / 2 overflowed for INT_MAX before I420Buffer::Create could refuse the size. Compute the chroma stride as scaledWidth / 2 + scaledWidth % 2. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…me-buffer-crop-and-scale
Refuse a scaled size no I420 buffer holds and a crop size libyuv does not accept (width below 1, height 0, either above 32768) before the buffer is converted, and the rectangle and null planes before the destination is created, so a refused call allocates nothing. Throw when libyuv reports a failure instead of returning the buffer unscaled. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against d3a8483c27:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_webrtc_crop_and_scale_tests,guest_webrtc_i420_buffer_create_testsbuilt cleanly. - CTest (
guest_webrtc_i420_buffer_create_create,guest_webrtc_i420_buffer_create_virtuals,guest_webrtc_i420_buffer_create_invalid,guest_webrtc_crop_and_scale):1/4 Test #6393: guest_webrtc_i420_buffer_create_create ..... Passed 0.03 sec 2/4 Test #6395: guest_webrtc_i420_buffer_create_invalid .... Passed 0.03 sec 3/4 Test #6394: guest_webrtc_i420_buffer_create_virtuals ... Passed 0.03 sec 4/4 Test #6396: guest_webrtc_crop_and_scale ................ Passed 0.05 sec 100% tests passed, 0 tests failed out of 4 - Negative control: with
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.1/4 Test #6396: guest_webrtc_crop_and_scale ................***Failed 0.02 sec 2/4 Test #6393: guest_webrtc_i420_buffer_create_create ..... Passed 0.04 sec 3/4 Test #6395: guest_webrtc_i420_buffer_create_invalid .... Passed 0.04 sec 4/4 Test #6394: guest_webrtc_i420_buffer_create_virtuals ...***Failed 0.02 sec 50% tests passed, 2 tests failed out of 4 - Code reading:
- Verified in core/libs/prx/libwebrtc/src/VideoFrameBufferCropAndScale.cpp that all caller pointers (result, buffer, buffer->vtable, source.object, dataY, dataU, dataV) are validated before dereferencing and throw std::invalid_argument on failure.
- Verified in core/libs/prx/libwebrtc/src/VideoFrameBufferCropAndScale.cpp that crop and scaled dimensions are checked using int64_t arithmetic against int::max and MaximumCropDimension (32768), correctly handling negative cropHeight (vertical flip) without integer overflow on INT_MIN.
- Verified RAII reference counting in VideoFrameBufferCropAndScale.cpp for both the converted source buffer and newly allocated destination buffer via struct Reference, preventing leaks if libyuv::I420Scale throws.
- Verified in core/libs/CMakeLists.txt and .gitmodules that 3rdparty/libyuv is added as a submodule, built from source with CMake as a PIC hidden static library, and correctly linked into libwebrtc.
- Verified in tools/package_release.py and tools/tests/test_package_release.py that libyuv LICENSE and PATENTS notices are packaged into release archives for libwebrtc.
- Verified in docs/dev/debt/changes/feat-webrtc-video-frame-buffer-crop-and-scale.md that technical debt documentation adheres to repo fragment conventions without violating code comment restrictions.
Looks Good To Me
catminou4
left a comment
There was a problem hiding this comment.
Built libwebrtc (with the new 3rdparty/libyuv submodule at 10592b60) 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 main control. The debt fragment is honest: scaling follows M134 video_frame_buffer.cc/i420_buffer.cc with libyuv::I420Scale at 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 throws std::invalid_argument). License/patent notices are correctly wired into package_release.py and the files exist in the submodule.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
Progress report (f4c9a67 → d3a8483)📈 System libraries: 46.01% (+0.0025%, +1 implemented function) ✅ 1 implemented
Changed libraries (implemented exports)
|
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)