feat(libwebrtc): implement VideoFrameBuffer::CropAndScale on libyuv (#26446)

* feat(libwebrtc): implement VideoFrameBuffer::CropAndScale on libyuv
* fix(libwebrtc): measure a flipped crop by its magnitude in CropAndScale
* fix(libwebrtc): halve the scaled width without overflow in CropAndScale
* fix(libwebrtc): check every CropAndScale argument before allocating
This commit is contained in:
Gordon authored and GitHub committed 2026-11-25 15:12:20 +13:00
1 parent 90c248ef7b
commit ebc9fea155
12 files changed
+747 -10

No files matched your search

+3
View File
@@ -113,3 +113,6 @@
[submodule "3rdparty/libpng"]
path = 3rdparty/libpng
url = https://github.com/pnggroup/libpng.git
[submodule "3rdparty/libyuv"]
path = 3rdparty/libyuv
url = https://chromium.googlesource.com/libyuv/libyuv
Vendored Submodule
+1
Submodule 3rdparty/libyuv added at 10592b60c0.
+19
View File
@@ -240,6 +240,25 @@ target_compile_options(fvad PRIVATE $<$<C_COMPILER_ID:GNU,Clang,AppleClang>:-fno
target_sources(libwebrtc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/prx/libwebrtc/Vad.cpp)
target_include_directories(libwebrtc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/3rdparty/libfvad/src)
target_link_libraries(libwebrtc PRIVATE fvad)
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/3rdparty/libyuv/source/scale.cc)
message(FATAL_ERROR "libyuv: ${CMAKE_SOURCE_DIR}/3rdparty/libyuv/source/scale.cc is missing; initialize the submodule with git submodule update --init 3rdparty/libyuv")
endif()
add_library(webrtc_yuv STATIC EXCLUDE_FROM_ALL
${CMAKE_SOURCE_DIR}/3rdparty/libyuv/source/cpu_id.cc
${CMAKE_SOURCE_DIR}/3rdparty/libyuv/source/planar_functions.cc
${CMAKE_SOURCE_DIR}/3rdparty/libyuv/source/row_any.cc
${CMAKE_SOURCE_DIR}/3rdparty/libyuv/source/row_common.cc
${CMAKE_SOURCE_DIR}/3rdparty/libyuv/source/row_gcc.cc
${CMAKE_SOURCE_DIR}/3rdparty/libyuv/source/scale.cc
${CMAKE_SOURCE_DIR}/3rdparty/libyuv/source/scale_any.cc
${CMAKE_SOURCE_DIR}/3rdparty/libyuv/source/scale_common.cc
${CMAKE_SOURCE_DIR}/3rdparty/libyuv/source/scale_gcc.cc
${CMAKE_SOURCE_DIR}/3rdparty/libyuv/source/scale_uv.cc)
target_include_directories(webrtc_yuv PUBLIC ${CMAKE_SOURCE_DIR}/3rdparty/libyuv/include)
set_target_properties(webrtc_yuv PROPERTIES POSITION_INDEPENDENT_CODE ON CXX_VISIBILITY_PRESET hidden)
target_compile_options(webrtc_yuv PRIVATE -w)
target_link_libraries(libwebrtc PRIVATE webrtc_yuv)
if(MINGW OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_options(libwebrtc PRIVATE LINKER:--exclude-libs,ALL)
endif()
+11
View File
@@ -93,6 +93,7 @@ target_sources(libwebrtc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/PlatformThread.
target_sources(libwebrtc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/I420Buffer.cpp)
target_sources(libwebrtc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/WavReader.cpp)
target_sources(libwebrtc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/VideoFrameBuffer.cpp)
target_sources(libwebrtc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/VideoFrameBufferCropAndScale.cpp)
target_sources(libwebrtc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/KeyParams.cpp)
target_sources(libwebrtc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/ColorSpace.cpp)
target_sources(libwebrtc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/IceServer.cpp)
@@ -764,6 +765,16 @@ if(BUILD_TESTING)
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libwebrtc>;PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
endforeach()
add_test_executable(guest_webrtc_crop_and_scale_tests ${CMAKE_CURRENT_SOURCE_DIR}/tests/VideoFrameBufferCropAndScale.cpp)
target_include_directories(guest_webrtc_crop_and_scale_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_webrtc_crop_and_scale_tests PRIVATE libwebrtc libc)
configure_windows_unwind(guest_webrtc_crop_and_scale_tests)
add_test(NAME guest_webrtc_crop_and_scale COMMAND guest_webrtc_crop_and_scale_tests)
set_tests_properties(guest_webrtc_crop_and_scale PROPERTIES TIMEOUT 20)
if(WIN32)
set_tests_properties(guest_webrtc_crop_and_scale PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libwebrtc>;PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
endif()
add_test_executable(guest_webrtc_video_frame_buffer_tests ${CMAKE_CURRENT_SOURCE_DIR}/tests/VideoFrameBuffer.cpp)
target_include_directories(guest_webrtc_video_frame_buffer_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_webrtc_video_frame_buffer_tests PRIVATE libwebrtc libc)
-5
View File
@@ -215,11 +215,6 @@ int APS5_VABI _ZN3rtc15CurrentThreadIdEv_nid_postfix(void) {
return scePthreadGetthreadid();
}
int APS5_VABI _ZN6webrtc16VideoFrameBuffer12CropAndScaleEiiiiii_nid_postfix(void) {
NotImplemented_nid_no_patch(__func__);
return 0;
}
APS5_EXPORT("R+hhR9jq4sU", libwebrtcUnknown14);
int APS5_VABI libwebrtcUnknown14(void) {
NotImplemented_nid_no_patch("R+hhR9jq4sU");
+1 -1
View File
@@ -187,7 +187,7 @@ std::uint8_t* APS5_VABI _ZN6webrtc10I420Buffer12MutableDataUEv_nid_postfix(WebRt
std::uint8_t* APS5_VABI _ZN6webrtc10I420Buffer12MutableDataVEv_nid_postfix(WebRtcI420Buffer* buffer);
void** APS5_VABI _ZN6webrtc19I420BufferInterface6ToI420Ev_nid_postfix(void** result, WebRtcVideoFrameBuffer* buffer);
const void* APS5_VABI _ZNK6webrtc19I420BufferInterface7GetI420Ev_nid_postfix(const WebRtcVideoFrameBuffer* buffer);
int APS5_VABI _ZN6webrtc16VideoFrameBuffer12CropAndScaleEiiiiii_nid_postfix(void);
void** APS5_VABI _ZN6webrtc16VideoFrameBuffer12CropAndScaleEiiiiii_nid_postfix(void** result, WebRtcVideoFrameBuffer* buffer, int offsetX, int offsetY, int cropWidth, int cropHeight, int scaledWidth, int scaledHeight);
void** APS5_VABI _ZN6webrtc16VideoFrameBuffer20GetMappedFrameBufferEN3rtc9ArrayViewINS0_4TypeELln4711EEE_nid_postfix(void** result, WebRtcVideoFrameBuffer* buffer, WebRtcVideoFrameBufferTypes types);
int APS5_VABI libwebrtcUnknown14(void);
int APS5_VABI _ZNK6webrtc19I420BufferInterface11ChromaWidthEv_nid_postfix(const void* buffer);
@@ -0,0 +1,150 @@
/*
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
/*
* Copyright (c) 2011, The WebRTC project authors. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Google nor the names of its contributors may
* be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/api/video/video_frame_buffer.cc */
/* https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/api/video/i420_buffer.cc */
#include "prx/libwebrtc/libwebrtc.hpp"
#include "libyuv/scale.h"
#include <cstddef>
#include <cstdint>
#include <limits>
#include <stdexcept>
namespace {
constexpr std::size_t ReleaseSlot = 1;
constexpr std::size_t WidthSlot = 5;
constexpr std::size_t HeightSlot = 6;
constexpr std::size_t ToI420Slot = 7;
constexpr std::size_t StrideYSlot = 14;
constexpr std::size_t StrideUSlot = 15;
constexpr std::size_t StrideVSlot = 16;
constexpr std::size_t DataYSlot = 17;
constexpr std::size_t DataUSlot = 18;
constexpr std::size_t DataVSlot = 19;
constexpr int MaximumCropDimension = 32768;
using ToI420 = void** (APS5_VABI*)(void** result, void* buffer);
void* Slot(const void* object, std::size_t slot) {
return const_cast<void*>((*static_cast<const void* const* const*>(object))[slot]);
}
template<typename TResult>
TResult Call(const void* object, std::size_t slot) {
return reinterpret_cast<TResult (APS5_VABI*)(const void*)>(Slot(object, slot))(object);
}
struct Reference {
void* object = nullptr;
~Reference() {
if (object) Call<std::int32_t>(object, ReleaseSlot);
}
};
} // namespace
extern "C" {
void** APS5_VABI _ZN6webrtc16VideoFrameBuffer12CropAndScaleEiiiiii_nid_postfix(
void** result, WebRtcVideoFrameBuffer* buffer, int offsetX, int offsetY, int cropWidth, int cropHeight, int scaledWidth, int scaledHeight) {
if (!result) throw std::invalid_argument("VideoFrameBuffer::CropAndScale requires a result");
if (!buffer || !buffer->vtable) throw std::invalid_argument("VideoFrameBuffer::CropAndScale requires a buffer with a vtable");
if (scaledWidth <= 0 || scaledHeight <= 0) throw std::invalid_argument("VideoFrameBuffer::CropAndScale requires a positive scaled size");
const int chromaStride = scaledWidth / 2 + scaledWidth % 2;
const std::int64_t chromaRows = (std::int64_t{scaledHeight} + 1) / 2;
if (std::int64_t{scaledWidth} * scaledHeight + 2 * std::int64_t{chromaStride} * chromaRows > std::numeric_limits<int>::max())
throw std::invalid_argument("VideoFrameBuffer::CropAndScale requires a scaled size whose planes fit in int");
const std::int64_t rows = cropHeight < 0 ? -std::int64_t{cropHeight} : std::int64_t{cropHeight};
if (cropWidth <= 0 || cropWidth > MaximumCropDimension || rows == 0 || rows > MaximumCropDimension)
throw std::invalid_argument("VideoFrameBuffer::CropAndScale requires a crop size the scaler accepts");
Reference source;
reinterpret_cast<ToI420>(Slot(buffer, ToI420Slot))(&source.object, buffer);
if (!source.object) throw std::invalid_argument("VideoFrameBuffer::CropAndScale requires a buffer that converts to I420");
const std::int64_t sourceWidth = Call<std::int32_t>(source.object, WidthSlot);
const std::int64_t sourceHeight = Call<std::int32_t>(source.object, HeightSlot);
if (std::int64_t{cropWidth} + offsetX > sourceWidth || rows + offsetY > sourceHeight || offsetX < 0 || offsetY < 0)
throw std::invalid_argument("VideoFrameBuffer::CropAndScale requires a crop rectangle inside the buffer");
const int uvOffsetX = offsetX / 2;
const int uvOffsetY = offsetY / 2;
offsetX = uvOffsetX * 2;
offsetY = uvOffsetY * 2;
const int strideY = Call<std::int32_t>(source.object, StrideYSlot);
const int strideU = Call<std::int32_t>(source.object, StrideUSlot);
const int strideV = Call<std::int32_t>(source.object, StrideVSlot);
const std::uint8_t* dataY = Call<const std::uint8_t*>(source.object, DataYSlot);
const std::uint8_t* dataU = Call<const std::uint8_t*>(source.object, DataUSlot);
const std::uint8_t* dataV = Call<const std::uint8_t*>(source.object, DataVSlot);
if (!dataY || !dataU || !dataV) throw std::invalid_argument("VideoFrameBuffer::CropAndScale requires a buffer with three planes");
const std::uint8_t* planeY = dataY + std::ptrdiff_t{strideY} * offsetY + offsetX;
const std::uint8_t* planeU = dataU + std::ptrdiff_t{strideU} * uvOffsetY + uvOffsetX;
const std::uint8_t* planeV = dataV + std::ptrdiff_t{strideV} * uvOffsetY + uvOffsetX;
WebRtcRefCountedI420Buffer* created = nullptr;
_ZN6webrtc10I420Buffer6CreateEiiiii_nid_postfix(&created, scaledWidth, scaledHeight, scaledWidth, chromaStride, chromaStride);
Reference target{created};
WebRtcI420Buffer& destination = created->buffer;
if (libyuv::I420Scale(planeY, strideY, planeU, strideU, planeV, strideV, cropWidth, cropHeight,
_ZN6webrtc10I420Buffer12MutableDataYEv_nid_postfix(&destination), destination.strideY,
_ZN6webrtc10I420Buffer12MutableDataUEv_nid_postfix(&destination), destination.strideU,
_ZN6webrtc10I420Buffer12MutableDataVEv_nid_postfix(&destination), destination.strideV,
destination.width, destination.height, libyuv::kFilterBox) != 0)
throw std::runtime_error("VideoFrameBuffer::CropAndScale could not scale the planes");
target.object = nullptr;
*result = created;
return result;
}
}
@@ -162,8 +162,9 @@ void TestVirtuals() {
const std::int32_t types[] = {1};
RequireRuntimeError([&] { CallIndirect<void*, 10>(buffer, &mapped, WebRtcVideoFrameBufferTypes{types, 1}); }, "GetMappedFrameBuffer");
void* cropped = nullptr;
RequireRuntimeError([&] { CallIndirect<void*, 9>(buffer, &cropped, 0, 0, 6, 5, 3, 2); }, "CropAndScale");
Require(mapped == nullptr && cropped == nullptr && buffer->refCount.load() == 1);
Require(CallIndirect<void*, 9>(buffer, &cropped, 0, 0, 6, 5, 3, 2) == &cropped && cropped != nullptr && cropped != buffer);
Require(Call<int, 5>(cropped) == 3 && Call<int, 6>(cropped) == 2 && Call<std::int32_t, 1>(cropped) == 0);
Require(mapped == nullptr && buffer->refCount.load() == 1);
WebRtcGuestString representation;
std::memset(&representation, 0xcc, sizeof(representation));
Require(CallIndirect<WebRtcGuestString, 11>(buffer, &representation) == &representation);
@@ -0,0 +1,544 @@
#include "prx/libwebrtc/libwebrtc.hpp"
#include "prx/libc/libc.hpp"
#include "prx/libc/include/ApplicationHeap.hpp"
#include <algorithm>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <source_location>
#include <stdexcept>
#include <unordered_map>
#include <vector>
namespace {
std::unordered_map<void*, std::size_t> allocations;
std::size_t allocationCalls = 0;
void Require(bool condition, std::source_location location = std::source_location::current()) {
if (condition) return;
std::fprintf(stderr, "libwebrtc VideoFrameBuffer::CropAndScale check failed at line %u\n", location.line());
std::abort();
}
void* APS5_VABI Allocate_nid_no_patch(std::size_t size) {
++allocationCalls;
auto* pointer = std::malloc(size);
if (pointer) {
allocations.emplace(pointer, size);
std::memset(pointer, 0xa5, size);
}
return pointer;
}
void APS5_VABI Free_nid_no_patch(void* pointer) {
if (!pointer) return;
Require(allocations.erase(pointer) == 1);
std::free(pointer);
}
void* APS5_VABI Calloc_nid_no_patch(std::size_t count, std::size_t size) { return std::calloc(count, size); }
void* APS5_VABI Reallocate_nid_no_patch(void* pointer, std::size_t size) { return std::realloc(pointer, size); }
void* APS5_VABI Align_nid_no_patch(std::size_t, std::size_t size) { return Allocate_nid_no_patch(size); }
void* APS5_VABI Realign_nid_no_patch(void* pointer, std::size_t size, std::size_t) { return Reallocate_nid_no_patch(pointer, size); }
int APS5_VABI PosixAlign_nid_no_patch(void** pointer, std::size_t alignment, std::size_t size) {
*pointer = Align_nid_no_patch(alignment, size);
return *pointer ? 0 : 12;
}
template<typename TException, typename TAction>
void RequireThrows(TAction action, std::source_location location = std::source_location::current()) {
try {
action();
} catch (const TException&) {
return;
}
Require(false, location);
}
const void* Entry(const void* object, std::size_t slot) {
return (*static_cast<const void* const* const*>(object))[slot];
}
template<typename TResult, std::size_t TSlot, typename... TArguments>
TResult Call(const void* object, TArguments... arguments) {
using Function = TResult(APS5_VABI*)(const void*, TArguments...);
return reinterpret_cast<Function>(const_cast<void*>(Entry(object, TSlot)))(object, arguments...);
}
using Buffer = WebRtcRefCountedI420Buffer;
Buffer* Create(int width, int height, int strideY, int strideU, int strideV) {
Buffer* buffer = nullptr;
_ZN6webrtc10I420Buffer6CreateEiiiii_nid_postfix(&buffer, width, height, strideY, strideU, strideV);
Require(buffer != nullptr);
return buffer;
}
void Release(const void* buffer) {
Require(Call<std::int32_t, 1>(buffer) == 0);
}
struct Planes {
const std::uint8_t* y;
const std::uint8_t* u;
const std::uint8_t* v;
int strideY;
int strideU;
int strideV;
int width;
int height;
explicit Planes(const void* buffer)
: y(Call<const std::uint8_t*, 17>(buffer)), u(Call<const std::uint8_t*, 18>(buffer)), v(Call<const std::uint8_t*, 19>(buffer)),
strideY(Call<int, 14>(buffer)), strideU(Call<int, 15>(buffer)), strideV(Call<int, 16>(buffer)),
width(Call<int, 5>(buffer)), height(Call<int, 6>(buffer)) {}
int Y(int column, int row) const { return y[row * strideY + column]; }
int U(int column, int row) const { return u[row * strideU + column]; }
int V(int column, int row) const { return v[row * strideV + column]; }
int ChromaWidth() const { return (width + 1) / 2; }
int ChromaHeight() const { return (height + 1) / 2; }
};
int PatternY(int column, int row) { return 16 + (column * 7 + row * 13 + column * row) % 220; }
int PatternU(int column, int row) { return 5 + (column * 31 + row * 17) % 240; }
int PatternV(int column, int row) { return 250 - (column * 11 + row * 29) % 240; }
Buffer* CreatePattern(int width, int height, int strideY, int strideU, int strideV) {
Buffer* buffer = Create(width, height, strideY, strideU, strideV);
const Planes planes(buffer);
const int chromaHeight = planes.ChromaHeight();
std::memset(buffer->buffer.data, 0xee, static_cast<std::size_t>(strideY) * height + static_cast<std::size_t>(strideU + strideV) * chromaHeight);
for (int row = 0; row < height; ++row)
for (int column = 0; column < width; ++column) const_cast<std::uint8_t*>(planes.y)[row * strideY + column] = static_cast<std::uint8_t>(PatternY(column, row));
for (int row = 0; row < chromaHeight; ++row)
for (int column = 0; column < planes.ChromaWidth(); ++column) {
const_cast<std::uint8_t*>(planes.u)[row * strideU + column] = static_cast<std::uint8_t>(PatternU(column, row));
const_cast<std::uint8_t*>(planes.v)[row * strideV + column] = static_cast<std::uint8_t>(PatternV(column, row));
}
return buffer;
}
Buffer* CropAndScale(void* source, int offsetX, int offsetY, int cropWidth, int cropHeight, int scaledWidth, int scaledHeight) {
using Function = void** (APS5_VABI*)(void**, void*, int, int, int, int, int, int);
void* result = nullptr;
Require(reinterpret_cast<Function>(const_cast<void*>(Entry(source, 9)))(&result, source, offsetX, offsetY, cropWidth, cropHeight, scaledWidth, scaledHeight) == &result);
Require(result != nullptr && result != source);
auto* buffer = static_cast<Buffer*>(result);
Require(buffer->refCount.load() == 1 && Call<std::int32_t, 4>(buffer) == 1);
Require(buffer->buffer.width == scaledWidth && buffer->buffer.height == scaledHeight);
Require(buffer->buffer.strideY == scaledWidth && buffer->buffer.strideU == (scaledWidth + 1) / 2 && buffer->buffer.strideV == (scaledWidth + 1) / 2);
return buffer;
}
void TestCopy() {
const int sizes[][5] = {{6, 5, 8, 3, 4}, {5, 3, 7, 4, 5}, {1, 1, 1, 1, 1}, {64, 48, 64, 32, 32}, {33, 17, 40, 20, 17}};
for (const auto& size : sizes) {
Buffer* source = CreatePattern(size[0], size[1], size[2], size[3], size[4]);
const std::size_t before = allocations.size();
Buffer* copy = CropAndScale(source, 0, 0, size[0], size[1], size[0], size[1]);
Require(allocations.size() == before + 2 && source->refCount.load() == 1);
const Planes planes(copy);
for (int row = 0; row < size[1]; ++row)
for (int column = 0; column < size[0]; ++column) Require(planes.Y(column, row) == PatternY(column, row));
for (int row = 0; row < planes.ChromaHeight(); ++row)
for (int column = 0; column < planes.ChromaWidth(); ++column)
Require(planes.U(column, row) == PatternU(column, row) && planes.V(column, row) == PatternV(column, row));
Release(copy);
Release(source);
}
}
void TestHalfAndQuarter() {
Buffer* source = CreatePattern(16, 16, 19, 9, 11);
const Planes from(source);
Buffer* half = CropAndScale(source, 0, 0, 16, 16, 8, 8);
const Planes halved(half);
for (int row = 0; row < 8; ++row)
for (int column = 0; column < 8; ++column)
Require(halved.Y(column, row) == (from.Y(2 * column, 2 * row) + from.Y(2 * column + 1, 2 * row) + from.Y(2 * column, 2 * row + 1) + from.Y(2 * column + 1, 2 * row + 1) + 2) / 4);
for (int row = 0; row < 4; ++row)
for (int column = 0; column < 4; ++column) {
Require(halved.U(column, row) == (from.U(2 * column, 2 * row) + from.U(2 * column + 1, 2 * row) + from.U(2 * column, 2 * row + 1) + from.U(2 * column + 1, 2 * row + 1) + 2) / 4);
Require(halved.V(column, row) == (from.V(2 * column, 2 * row) + from.V(2 * column + 1, 2 * row) + from.V(2 * column, 2 * row + 1) + from.V(2 * column + 1, 2 * row + 1) + 2) / 4);
}
Release(half);
Buffer* quarter = CropAndScale(source, 0, 0, 16, 16, 4, 4);
const Planes quartered(quarter);
for (int row = 0; row < 4; ++row)
for (int column = 0; column < 4; ++column) {
int sum = 0;
for (int y = 0; y < 4; ++y)
for (int x = 0; x < 4; ++x) sum += from.Y(4 * column + x, 4 * row + y);
Require(quartered.Y(column, row) == (sum + 8) / 16);
}
for (int row = 0; row < 2; ++row)
for (int column = 0; column < 2; ++column) {
int sumU = 0;
int sumV = 0;
for (int y = 0; y < 4; ++y)
for (int x = 0; x < 4; ++x) {
sumU += from.U(4 * column + x, 4 * row + y);
sumV += from.V(4 * column + x, 4 * row + y);
}
Require(quartered.U(column, row) == (sumU + 8) / 16 && quartered.V(column, row) == (sumV + 8) / 16);
}
Release(quarter);
Buffer* cropped = CropAndScale(source, 4, 8, 8, 8, 4, 4);
const Planes window(cropped);
for (int row = 0; row < 4; ++row)
for (int column = 0; column < 4; ++column)
Require(window.Y(column, row) == (from.Y(4 + 2 * column, 8 + 2 * row) + from.Y(5 + 2 * column, 8 + 2 * row) + from.Y(4 + 2 * column, 9 + 2 * row) + from.Y(5 + 2 * column, 9 + 2 * row) + 2) / 4);
for (int row = 0; row < 2; ++row)
for (int column = 0; column < 2; ++column)
Require(window.U(column, row) == (from.U(2 + 2 * column, 4 + 2 * row) + from.U(3 + 2 * column, 4 + 2 * row) + from.U(2 + 2 * column, 5 + 2 * row) + from.U(3 + 2 * column, 5 + 2 * row) + 2) / 4);
Release(cropped);
Release(source);
}
void TestOffsetsAreMadeEven() {
Buffer* source = CreatePattern(12, 12, 12, 6, 7);
const int offsets[][4] = {{3, 5, 2, 4}, {2, 4, 2, 4}, {1, 1, 0, 0}, {0, 7, 0, 6}, {7, 0, 6, 0}, {8, 8, 8, 8}};
for (const auto& offset : offsets) {
Buffer* cropped = CropAndScale(source, offset[0], offset[1], 4, 4, 4, 4);
const Planes planes(cropped);
for (int row = 0; row < 4; ++row)
for (int column = 0; column < 4; ++column) Require(planes.Y(column, row) == PatternY(offset[2] + column, offset[3] + row));
for (int row = 0; row < 2; ++row)
for (int column = 0; column < 2; ++column) {
Require(planes.U(column, row) == PatternU(offset[2] / 2 + column, offset[3] / 2 + row));
Require(planes.V(column, row) == PatternV(offset[2] / 2 + column, offset[3] / 2 + row));
}
Release(cropped);
}
Release(source);
}
void TestANegativeHeightFlips() {
Buffer* source = CreatePattern(8, 8, 10, 5, 4);
Buffer* flipped = CropAndScale(source, 0, 0, 8, -8, 8, 8);
const Planes planes(flipped);
for (int row = 0; row < 8; ++row)
for (int column = 0; column < 8; ++column) Require(planes.Y(column, row) == PatternY(column, 7 - row));
for (int row = 0; row < 4; ++row)
for (int column = 0; column < 4; ++column) Require(planes.U(column, row) == PatternU(column, 3 - row) && planes.V(column, row) == PatternV(column, 3 - row));
Release(flipped);
Buffer* window = CropAndScale(source, 0, 2, 8, -4, 8, 4);
const Planes rows(window);
for (int row = 0; row < 4; ++row)
for (int column = 0; column < 8; ++column) Require(rows.Y(column, row) == PatternY(column, 5 - row));
for (int row = 0; row < 2; ++row)
for (int column = 0; column < 4; ++column) Require(rows.U(column, row) == PatternU(column, 2 - row) && rows.V(column, row) == PatternV(column, 2 - row));
Release(window);
Release(source);
}
void TestUniformPlanes() {
const int cases[][5] = {{7, 5, 3, 9, 0}, {4, 4, 9, 7, 0}, {640, 360, 320, 180, 0}, {10, 10, 7, 7, 0}, {1, 1, 5, 5, 0}, {16, 16, 12, 12, 0}, {64, 64, 16, 16, 0}, {20, 28, 13, 9, 0},
{1280, 720, 960, 540, 0}, {1280, 720, 854, 480, 0}, {33, 17, 11, 5, 1}, {300, 200, 37, 23, 1}, {9, 9, 3, 3, 1}, {20, 28, 7, 5, 1}, {64, 64, 24, 24, 1}};
for (const auto& item : cases) {
Buffer* source = Create(item[0], item[1], item[0] + 3, (item[0] + 1) / 2 + 1, (item[0] + 1) / 2);
const Planes from(source);
std::memset(const_cast<std::uint8_t*>(from.y), 77, static_cast<std::size_t>(from.strideY) * item[1]);
std::memset(const_cast<std::uint8_t*>(from.u), 33, static_cast<std::size_t>(from.strideU) * from.ChromaHeight());
std::memset(const_cast<std::uint8_t*>(from.v), 201, static_cast<std::size_t>(from.strideV) * from.ChromaHeight());
Buffer* scaled = CropAndScale(source, 0, 0, item[0], item[1], item[2], item[3]);
const Planes planes(scaled);
const int loss = item[4];
for (int row = 0; row < item[3]; ++row)
for (int column = 0; column < item[2]; ++column) Require(planes.Y(column, row) <= 77 && planes.Y(column, row) >= 77 - loss);
for (int row = 0; row < planes.ChromaHeight(); ++row)
for (int column = 0; column < planes.ChromaWidth(); ++column) {
Require(planes.U(column, row) <= 33 && planes.U(column, row) >= 33 - loss);
Require(planes.V(column, row) <= 201 && planes.V(column, row) >= 201 - loss);
}
Release(scaled);
Release(source);
}
}
std::uint32_t Checksum(const Planes& planes) {
std::uint32_t hash = 2166136261u;
for (int row = 0; row < planes.height; ++row)
for (int column = 0; column < planes.width; ++column) hash = (hash ^ static_cast<std::uint32_t>(planes.Y(column, row))) * 16777619u;
for (int row = 0; row < planes.ChromaHeight(); ++row)
for (int column = 0; column < planes.ChromaWidth(); ++column) hash = (hash ^ static_cast<std::uint32_t>(planes.U(column, row))) * 16777619u;
for (int row = 0; row < planes.ChromaHeight(); ++row)
for (int column = 0; column < planes.ChromaWidth(); ++column) hash = (hash ^ static_cast<std::uint32_t>(planes.V(column, row))) * 16777619u;
return hash;
}
void TestThirdAndThreeQuarters() {
Buffer* source = CreatePattern(18, 18, 21, 9, 12);
const Planes from(source);
Buffer* third = CropAndScale(source, 0, 0, 18, 18, 6, 6);
const Planes thirds(third);
for (int row = 0; row < 6; ++row)
for (int column = 0; column < 6; ++column) {
int sum = 0;
for (int y = 0; y < 3; ++y)
for (int x = 0; x < 3; ++x) sum += from.Y(3 * column + x, 3 * row + y);
Require(thirds.Y(column, row) == (sum * (65536 / 9)) >> 16);
}
for (int row = 0; row < 3; ++row)
for (int column = 0; column < 3; ++column) {
int sumU = 0;
int sumV = 0;
for (int y = 0; y < 3; ++y)
for (int x = 0; x < 3; ++x) {
sumU += from.U(3 * column + x, 3 * row + y);
sumV += from.V(3 * column + x, 3 * row + y);
}
Require(thirds.U(column, row) == (sumU * (65536 / 9)) >> 16 && thirds.V(column, row) == (sumV * (65536 / 9)) >> 16);
}
Release(third);
Release(source);
Buffer* wide = Create(64, 64, 64, 32, 32);
std::uint32_t seed = 12345;
for (int index = 0; index < 64 * 64 + 2 * 32 * 32; ++index) {
seed = seed * 1103515245u + 12345u;
wide->buffer.data[index] = static_cast<std::uint8_t>(seed >> 16);
}
Buffer* threeQuarters = CropAndScale(wide, 0, 0, 64, 64, 48, 48);
Require(Checksum(Planes(threeQuarters)) == 0xa07acbb5u);
Release(threeQuarters);
Release(wide);
}
void TestScaledValuesStayInsideTheCrop() {
Buffer* source = Create(40, 28, 40, 20, 20);
const Planes from(source);
for (int row = 0; row < 28; ++row)
for (int column = 0; column < 40; ++column) const_cast<std::uint8_t*>(from.y)[row * 40 + column] = static_cast<std::uint8_t>(column < 20 ? 250 : 100 + (row * 3 + column) % 50);
for (int row = 0; row < 14; ++row)
for (int column = 0; column < 20; ++column) {
const_cast<std::uint8_t*>(from.u)[row * 20 + column] = static_cast<std::uint8_t>(column < 10 ? 3 : 60 + (row + column) % 30);
const_cast<std::uint8_t*>(from.v)[row * 20 + column] = static_cast<std::uint8_t>(column < 10 ? 240 : 120 + (row * 5 + column) % 40);
}
const int sizes[][2] = {{7, 5}, {13, 9}, {40, 56}, {20, 14}, {19, 27}, {5, 7}};
for (const auto& size : sizes) {
Buffer* scaled = CropAndScale(source, 20, 0, 20, 28, size[0], size[1]);
const Planes planes(scaled);
for (int row = 0; row < size[1]; ++row)
for (int column = 0; column < size[0]; ++column) Require(planes.Y(column, row) >= 100 && planes.Y(column, row) < 150);
for (int row = 0; row < planes.ChromaHeight(); ++row)
for (int column = 0; column < planes.ChromaWidth(); ++column) {
Require(planes.U(column, row) >= 60 && planes.U(column, row) < 90);
Require(planes.V(column, row) >= 120 && planes.V(column, row) < 160);
}
Release(scaled);
}
Release(source);
}
struct GuestBuffer {
void* const* vtable;
void* converted = nullptr;
int conversions = 0;
int references = 0;
int releases = 0;
int width = 0;
int height = 0;
int strideY = 0;
int strideU = 0;
int strideV = 0;
std::vector<std::uint8_t> y;
std::vector<std::uint8_t> u;
std::vector<std::uint8_t> v;
};
void APS5_VABI GuestAddRef(GuestBuffer* buffer) { ++buffer->references; }
std::int32_t APS5_VABI GuestRelease(GuestBuffer* buffer) {
++buffer->releases;
return 1;
}
void APS5_VABI GuestUnexpected(GuestBuffer*) { Require(false); }
std::int32_t APS5_VABI GuestType(const GuestBuffer*) { return 0; }
std::int32_t APS5_VABI GuestWidth(const GuestBuffer* buffer) { return buffer->width; }
std::int32_t APS5_VABI GuestHeight(const GuestBuffer* buffer) { return buffer->height; }
void** APS5_VABI GuestToI420(void** result, GuestBuffer* buffer) {
++buffer->conversions;
if (buffer->converted) Call<void, 0>(buffer->converted);
*result = buffer->converted;
return result;
}
std::int32_t APS5_VABI GuestStrideY(const GuestBuffer* buffer) { return buffer->strideY; }
std::int32_t APS5_VABI GuestStrideU(const GuestBuffer* buffer) { return buffer->strideU; }
std::int32_t APS5_VABI GuestStrideV(const GuestBuffer* buffer) { return buffer->strideV; }
const std::uint8_t* APS5_VABI GuestDataY(const GuestBuffer* buffer) { return buffer->y.data(); }
const std::uint8_t* APS5_VABI GuestDataU(const GuestBuffer* buffer) { return buffer->u.data(); }
const std::uint8_t* APS5_VABI GuestDataV(const GuestBuffer* buffer) { return buffer->v.data(); }
void* const guestVtable[] = {
nullptr, nullptr,
reinterpret_cast<void*>(&GuestAddRef), reinterpret_cast<void*>(&GuestRelease),
reinterpret_cast<void*>(&GuestUnexpected), reinterpret_cast<void*>(&GuestUnexpected),
reinterpret_cast<void*>(&GuestType), reinterpret_cast<void*>(&GuestWidth), reinterpret_cast<void*>(&GuestHeight),
reinterpret_cast<void*>(&GuestToI420), reinterpret_cast<void*>(&GuestUnexpected),
reinterpret_cast<void*>(&_ZN6webrtc16VideoFrameBuffer12CropAndScaleEiiiiii_nid_postfix),
reinterpret_cast<void*>(&GuestUnexpected), reinterpret_cast<void*>(&GuestUnexpected),
reinterpret_cast<void*>(&GuestUnexpected), reinterpret_cast<void*>(&GuestUnexpected),
reinterpret_cast<void*>(&GuestStrideY), reinterpret_cast<void*>(&GuestStrideU), reinterpret_cast<void*>(&GuestStrideV),
reinterpret_cast<void*>(&GuestDataY), reinterpret_cast<void*>(&GuestDataU), reinterpret_cast<void*>(&GuestDataV),
reinterpret_cast<void*>(&GuestUnexpected),
};
void TestAGuestBufferIsConverted() {
Buffer* converted = CreatePattern(8, 8, 9, 5, 6);
GuestBuffer native{guestVtable + 2};
native.converted = converted;
native.width = 1000;
native.height = 1000;
Buffer* scaled = CropAndScale(&native, 2, 2, 4, 4, 4, 4);
Require(native.conversions == 1 && native.references == 0 && native.releases == 0 && converted->refCount.load() == 1);
const Planes planes(scaled);
for (int row = 0; row < 4; ++row)
for (int column = 0; column < 4; ++column) Require(planes.Y(column, row) == PatternY(2 + column, 2 + row));
Require(planes.U(1, 1) == PatternU(2, 2) && planes.V(0, 1) == PatternV(1, 2));
Release(scaled);
void* untouched = &native;
using Function = void** (APS5_VABI*)(void**, void*, int, int, int, int, int, int);
const auto cropAndScale = reinterpret_cast<Function>(const_cast<void*>(Entry(&native, 9)));
RequireThrows<std::invalid_argument>([&] { cropAndScale(&untouched, &native, 0, 0, 9, 8, 4, 4); });
Require(native.conversions == 2 && converted->refCount.load() == 1 && untouched == &native);
RequireThrows<std::invalid_argument>([&] { cropAndScale(&untouched, &native, 0, 0, 8, 8, 0, 4); });
RequireThrows<std::invalid_argument>([&] { cropAndScale(&untouched, &native, 0, 0, 8, 8, 4, -1); });
RequireThrows<std::invalid_argument>([&] { cropAndScale(&untouched, &native, 0, 0, 8, 8, INT_MAX, 4); });
RequireThrows<std::invalid_argument>([&] { cropAndScale(&untouched, &native, 0, 0, 8, 8, 4, INT_MAX); });
RequireThrows<std::invalid_argument>([&] { cropAndScale(&untouched, &native, 0, 0, 8, 8, INT_MAX, INT_MAX); });
for (const int width : {0, -4, INT_MIN, 32769, INT_MAX}) RequireThrows<std::invalid_argument>([&] { cropAndScale(&untouched, &native, 0, 0, width, 4, 4, 4); });
for (const int height : {0, INT_MIN, 32769, -32769, INT_MAX}) RequireThrows<std::invalid_argument>([&] { cropAndScale(&untouched, &native, 0, 0, 4, height, 4, 4); });
Require(native.conversions == 2 && untouched == &native);
native.converted = nullptr;
const std::size_t before = allocations.size();
RequireThrows<std::invalid_argument>([&] { cropAndScale(&untouched, &native, 0, 0, 8, 8, 4, 4); });
Require(native.conversions == 3 && untouched == &native && allocations.size() == before);
Release(converted);
GuestBuffer planar{guestVtable + 2};
planar.converted = &planar;
planar.width = 6;
planar.height = 4;
planar.strideY = 11;
planar.strideU = 7;
planar.strideV = 5;
planar.y.assign(11 * 4, 0xee);
planar.u.assign(7 * 2, 0xee);
planar.v.assign(5 * 2, 0xee);
for (int row = 0; row < 4; ++row)
for (int column = 0; column < 6; ++column) planar.y[row * 11 + column] = static_cast<std::uint8_t>(PatternY(column, row));
for (int row = 0; row < 2; ++row)
for (int column = 0; column < 3; ++column) {
planar.u[row * 7 + column] = static_cast<std::uint8_t>(PatternU(column, row));
planar.v[row * 5 + column] = static_cast<std::uint8_t>(PatternV(column, row));
}
Buffer* copy = CropAndScale(&planar, 0, 0, 6, 4, 6, 4);
Require(planar.conversions == 1 && planar.references == 1 && planar.releases == 1);
const Planes copied(copy);
for (int row = 0; row < 4; ++row)
for (int column = 0; column < 6; ++column) Require(copied.Y(column, row) == PatternY(column, row));
for (int row = 0; row < 2; ++row)
for (int column = 0; column < 3; ++column) Require(copied.U(column, row) == PatternU(column, row) && copied.V(column, row) == PatternV(column, row));
Release(copy);
RequireThrows<std::invalid_argument>([&] { cropAndScale(&untouched, &planar, 0, 0, 6, 5, 6, 4); });
Require(planar.references == 2 && planar.releases == 2);
for (int plane = 0; plane < 3; ++plane) {
GuestBuffer partial = planar;
partial.converted = &partial;
partial.references = 0;
partial.releases = 0;
(plane == 0 ? partial.y : plane == 1 ? partial.u : partial.v) = std::vector<std::uint8_t>();
const std::size_t calls = allocationCalls;
RequireThrows<std::invalid_argument>([&] { cropAndScale(&untouched, &partial, 0, 0, 6, 4, 6, 4); });
Require(partial.references == 1 && partial.releases == 1 && allocationCalls == calls && untouched == &native);
}
}
void TestTheScalerLimits() {
Buffer* wide = Create(40000, 2, 40000, 20000, 20000);
Buffer* tall = Create(2, 40000, 2, 1, 1);
using Function = void** (APS5_VABI*)(void**, void*, int, int, int, int, int, int);
const auto cropAndScale = reinterpret_cast<Function>(const_cast<void*>(Entry(wide, 9)));
void* result = wide;
const std::size_t calls = allocationCalls;
RequireThrows<std::invalid_argument>([&] { cropAndScale(&result, wide, 0, 0, 32769, 2, 4, 2); });
RequireThrows<std::invalid_argument>([&] { cropAndScale(&result, wide, 0, 0, 40000, 2, 4, 2); });
RequireThrows<std::invalid_argument>([&] { cropAndScale(&result, tall, 0, 0, 2, 32769, 2, 4); });
RequireThrows<std::invalid_argument>([&] { cropAndScale(&result, tall, 0, 0, 2, -32769, 2, 4); });
RequireThrows<std::invalid_argument>([&] { cropAndScale(&result, tall, 0, 0, 2, 40000, 2, 4); });
Require(result == wide && allocationCalls == calls && wide->refCount.load() == 1 && tall->refCount.load() == 1);
Release(CropAndScale(wide, 0, 0, 32768, 2, 4, 2));
Release(CropAndScale(wide, 7232, 0, 32768, 2, 4, 2));
Release(CropAndScale(tall, 0, 0, 2, 32768, 2, 4));
Release(CropAndScale(tall, 0, 7232, 2, -32768, 2, 4));
Release(wide);
Release(tall);
}
void TestInvalid() {
Buffer* source = CreatePattern(8, 6, 8, 4, 4);
using Function = void** (APS5_VABI*)(void**, void*, int, int, int, int, int, int);
const auto cropAndScale = reinterpret_cast<Function>(const_cast<void*>(Entry(source, 9)));
void* result = source;
const std::size_t before = allocations.size();
const std::size_t calls = allocationCalls;
RequireThrows<std::invalid_argument>([&] { cropAndScale(nullptr, source, 0, 0, 8, 6, 8, 6); });
RequireThrows<std::invalid_argument>([&] { cropAndScale(&result, nullptr, 0, 0, 8, 6, 8, 6); });
WebRtcVideoFrameBuffer empty{nullptr};
RequireThrows<std::invalid_argument>([&] { cropAndScale(&result, &empty, 0, 0, 8, 6, 8, 6); });
const int rejected[][4] = {{0, 0, 9, 6}, {0, 0, 8, 7}, {1, 0, 8, 6}, {0, 1, 8, 6}, {2, 0, 7, 6}, {0, 2, 8, 5}, {-1, 0, 8, 6}, {0, -1, 8, 6}, {-2, -2, 4, 4},
{1, 0, INT_MAX, 6}, {0, 1, 8, INT_MAX}, {INT_MAX, 0, 1, 6}, {0, INT_MAX, 8, 1}, {INT_MAX, INT_MAX, INT_MAX, INT_MAX},
{0, 0, 8, -7}, {0, 4, 8, -4}, {0, 1, 8, -6}, {0, 0, 8, INT_MIN}, {0, 1, 8, INT_MIN}, {0, 0, 8, -INT_MAX}, {0, 6, 8, -1}, {0, INT_MAX, 8, INT_MIN},
{0, 0, 0, 6}, {0, 0, 8, 0}, {8, 6, 0, 0}, {0, 0, -8, 6}, {0, 0, INT_MIN, 6}, {8, 0, -1, 6}, {0, 0, -1, -1}, {0, 0, 0, 0}, {INT_MAX, 0, INT_MIN, 6}};
for (const auto& crop : rejected) {
RequireThrows<std::invalid_argument>([&] { cropAndScale(&result, source, crop[0], crop[1], crop[2], crop[3], 4, 4); });
Require(result == source && source->refCount.load() == 1 && allocations.size() == before && allocationCalls == calls);
}
const int sizes[][2] = {{0, 4}, {4, 0}, {-4, 4}, {4, -4}, {0, 0}, {INT_MAX, 4}, {4, INT_MAX}, {INT_MAX, INT_MAX}, {INT_MAX - 1, 2}, {INT_MIN, 4}, {4, INT_MIN}, {-1, -1}, {40000, 40000}, {60000, 30000}, {46342, 46342}};
for (const auto& size : sizes) {
RequireThrows<std::invalid_argument>([&] { cropAndScale(&result, source, 0, 0, 8, 6, size[0], size[1]); });
Require(result == source && source->refCount.load() == 1 && allocations.size() == before && allocationCalls == calls);
}
const int accepted[][4] = {{0, 0, 8, 6}, {2, 2, 6, 4}, {7, 5, 1, 1}, {0, 0, 8, -6}, {0, 2, 8, -4}, {0, 5, 8, -1}};
for (const auto& crop : accepted) {
Buffer* scaled = CropAndScale(source, crop[0], crop[1], crop[2], crop[3], 4, 4);
Require(source->refCount.load() == 1);
Release(scaled);
Require(allocations.size() == before);
}
Release(source);
}
}
int main() {
void* api[10] = {reinterpret_cast<void*>(&Allocate_nid_no_patch), reinterpret_cast<void*>(&Free_nid_no_patch),
reinterpret_cast<void*>(&Calloc_nid_no_patch), reinterpret_cast<void*>(&Reallocate_nid_no_patch),
reinterpret_cast<void*>(&Align_nid_no_patch), reinterpret_cast<void*>(&Realign_nid_no_patch), reinterpret_cast<void*>(&PosixAlign_nid_no_patch)};
ApplicationHeapRegister_nid_no_patch(api);
try {
TestCopy();
TestHalfAndQuarter();
TestOffsetsAreMadeEven();
TestANegativeHeightFlips();
TestUniformPlanes();
TestThirdAndThreeQuarters();
TestScaledValuesStayInsideTheCrop();
TestAGuestBufferIsConverted();
TestTheScalerLimits();
TestInvalid();
Require(allocations.empty());
} catch (const std::exception& error) {
std::fprintf(stderr, "VideoFrameBuffer::CropAndScale exception: %s\n", error.what());
return 1;
}
std::puts("libwebrtc VideoFrameBuffer::CropAndScale tests passed");
return 0;
}
@@ -0,0 +1,5 @@
# libwebrtc
## add Public source implementations
- [webrtc::VideoFrameBuffer::CropAndScale](../../../core/libs/prx/libwebrtc/src/VideoFrameBufferCropAndScale.cpp) (libwebrtc) - nothing is checked on the console. Follows [video_frame_buffer.cc](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/api/video/video_frame_buffer.cc) and `CropAndScaleFrom` of [i420_buffer.cc](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/api/video/i420_buffer.cc), scaling with `libyuv::I420Scale` from `3rdparty/libyuv` at M134's DEPS revision (`10592b60`); the module's revision is unknown, and without SSSE3 a pixel can differ by one step. Arguments are checked before allocating and throw `std::invalid_argument`: a scaled size no I420 buffer holds, a crop libyuv refuses (width below 1, height 0, either above 32768) or outside the buffer, a null `ToI420` or plane. Upstream aborts on some, reads past the planes for a too tall flipped crop, and returns the buffer unscaled when libyuv refuses.
+2
View File
@@ -129,6 +129,8 @@ def package(platform, build, output, version):
if "libwebrtc.prx" in expected:
licenses.append((ROOT / "3rdparty/libfvad/LICENSE", "libs/licenses/libfvad.txt"))
licenses.append((ROOT / "3rdparty/libfvad/PATENTS", "libs/licenses/libfvad-patents.txt"))
licenses.append((ROOT / "3rdparty/libyuv/LICENSE", "libs/licenses/libyuv.txt"))
licenses.append((ROOT / "3rdparty/libyuv/PATENTS", "libs/licenses/libyuv-patents.txt"))
if "libSceAjm.native.prx" in expected:
licenses.append((ROOT / "3rdparty/vgmstream/COPYING", "libs/licenses/vgmstream.txt"))
if "libSceVorbisDec.prx" in expected:
+8 -2
View File
@@ -996,7 +996,7 @@ class ReleasePackageTests(unittest.TestCase):
(self.build / "CMakeCache.txt").write_bytes(cache.encode("utf-8"))
self.assertEqual(package_release.tracy_runtime("windows", self.build), [client])
def test_webrtc_library_archives_include_vad_notices(self):
def test_webrtc_library_archives_include_vad_and_scaler_notices(self):
(self.source / "core/libs/prx/libwebrtc").mkdir()
(self.unpatched.parent / "libwebrtc.prx").write_bytes(b"unpatched library")
(self.library.parent / "libwebrtc.prx").write_bytes(b"WebRTC library bytes")
@@ -1004,8 +1004,14 @@ class ReleasePackageTests(unittest.TestCase):
source.mkdir(parents=True)
(source / "LICENSE").write_bytes(b"VAD license\n")
(source / "PATENTS").write_bytes(b"VAD patent grant\n")
source = self.source / "3rdparty/libyuv"
source.mkdir(parents=True)
(source / "LICENSE").write_bytes(b"Scaler license\n")
(source / "PATENTS").write_bytes(b"Scaler patent grant\n")
package_release.package("linux", self.build, self.output, "v1")
for archive_name, content in {"libfvad.txt": b"VAD license\n", "libfvad-patents.txt": b"VAD patent grant\n"}.items():
notices = {"libfvad.txt": b"VAD license\n", "libfvad-patents.txt": b"VAD patent grant\n",
"libyuv.txt": b"Scaler license\n", "libyuv-patents.txt": b"Scaler patent grant\n"}
for archive_name, content in notices.items():
with zipfile.ZipFile(self.output / "prx-linux-v1.zip") as archive:
self.assertEqual(archive.read("libs/licenses/" + archive_name), content)
with tarfile.open(self.output / "prx-linux-v1.tar.gz") as archive: