Modules/Externals/Yuv.cmake
Шурупов Илья Викторович d6e54ae611 Chatrooms video capture: conversion pipeline, V4L2 cameras, portal/PipeWire and X11 screens
- libyuv (Externals/Yuv.cmake) for conversion and scaling; MJPEG through the system libjpeg-turbo on Linux
- CapturePipeline: frame pacing, unchanged-frame skip for screens, I420 conversion into pooled buffers
- Linux backends: V4L2 cameras with inotify hot-plug, xdg-desktop-portal ScreenCast + PipeWire, XShm/XDamage
- chatroomsCapture tool (list, camera, screen, bench) and capture unit tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 03:28:15 +03:00

49 lines
2.6 KiB
CMake

# libyuv: pixel format conversion, scaling and rotation with SSE/AVX2 and NEON kernels picked at run time.
# Used by Chatrooms video capture (screen BGRA and camera YUYV/NV12 to I420). Built without JPEG: MJPEG camera
# frames are decoded elsewhere.
set(YUV_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libyuv)
set(YUV_SOURCES
compare.cc compare_common.cc compare_gcc.cc compare_win.cc
convert.cc convert_argb.cc convert_from.cc convert_from_argb.cc convert_to_argb.cc convert_to_i420.cc
cpu_id.cc planar_functions.cc
rotate.cc rotate_any.cc rotate_argb.cc rotate_common.cc rotate_gcc.cc rotate_win.cc
row_any.cc row_common.cc row_gcc.cc row_win.cc
scale.cc scale_any.cc scale_argb.cc scale_common.cc scale_gcc.cc scale_rgb.cc scale_uv.cc scale_win.cc
video_common.cc)
list(TRANSFORM YUV_SOURCES PREPEND ${YUV_DIR}/source/)
add_library(Yuv STATIC ${YUV_SOURCES})
target_include_directories(Yuv PUBLIC ${YUV_DIR}/include)
# SVE2/SME kernels need newer compilers and CPUs than the tablets we target; NEON covers arm64.
target_compile_definitions(Yuv PUBLIC LIBYUV_DISABLE_SVE LIBYUV_DISABLE_SME)
set_target_properties(Yuv PROPERTIES POSITION_INDEPENDENT_CODE ON)
if (NOT MSVC)
# libyuv is always worth optimizing, even in Debug builds: the scalar paths run at a fraction of the speed.
target_compile_options(Yuv PRIVATE -O2 -w)
endif ()
if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64")
add_library(YuvNeon64 OBJECT
${YUV_DIR}/source/compare_neon64.cc ${YUV_DIR}/source/rotate_neon64.cc
${YUV_DIR}/source/row_neon64.cc ${YUV_DIR}/source/scale_neon64.cc)
target_include_directories(YuvNeon64 PRIVATE ${YUV_DIR}/include)
target_compile_definitions(YuvNeon64 PRIVATE LIBYUV_DISABLE_SVE LIBYUV_DISABLE_SME)
# Dot-product and i8mm kernels are only called after the run-time CPU check.
target_compile_options(YuvNeon64 PRIVATE -O2 -w -march=armv8.2-a+dotprod+i8mm)
set_target_properties(YuvNeon64 PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_sources(Yuv PRIVATE $<TARGET_OBJECTS:YuvNeon64>)
endif ()
# MJPEG straight to I420 through the system's libjpeg(-turbo), where there is one: UVC webcams send MJPEG at
# 720p30 and above. Windows (Media Foundation) and Android (Camera2) hand over YUV, so they need no JPEG decoder.
if (NOT ANDROID AND NOT WIN32)
find_package(PkgConfig)
if (PkgConfig_FOUND)
pkg_check_modules(YUV_JPEG IMPORTED_TARGET libjpeg)
if (YUV_JPEG_FOUND)
target_sources(Yuv PRIVATE ${YUV_DIR}/source/convert_jpeg.cc ${YUV_DIR}/source/mjpeg_decoder.cc
${YUV_DIR}/source/mjpeg_validate.cc)
target_compile_definitions(Yuv PUBLIC HAVE_JPEG)
target_link_libraries(Yuv PRIVATE PkgConfig::YUV_JPEG)
endif ()
endif ()
endif ()