From b6eb3b703e74cb09671c3648370124b54cb7b136 Mon Sep 17 00:00:00 2001 From: El Date: Thu, 16 Apr 2026 09:31:49 +0000 Subject: [PATCH] VNC-151 Use arena --- common/rfb/encoders/ScreenEncoderManager.cxx | 23 ++++++++++++-------- common/rfb/encoders/ScreenEncoderManager.h | 6 ++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/common/rfb/encoders/ScreenEncoderManager.cxx b/common/rfb/encoders/ScreenEncoderManager.cxx index 6927986..da7f347 100644 --- a/common/rfb/encoders/ScreenEncoderManager.cxx +++ b/common/rfb/encoders/ScreenEncoderManager.cxx @@ -38,6 +38,7 @@ namespace rfb { base_video_encoder(encoder), available_encoders(encoders) { screens_to_refresh.reserve(T); + arena.initialize(MAX_SCREENS); } template @@ -219,16 +220,20 @@ namespace rfb { if (screens_to_refresh.size() > 1) { tbb::task_group_context ctx; - tbb::parallel_for_each(screens_to_refresh.begin(), screens_to_refresh.end(), [this, pb, &ctx, forceKeyFrame](uint8_t index) { - if (ctx.is_group_execution_cancelled()) - return; + arena.execute([&] { + tbb::parallel_for_each(screens_to_refresh.begin(), + screens_to_refresh.end(), + [this, pb, &ctx, forceKeyFrame](uint8_t index) { + if (ctx.is_group_execution_cancelled()) + return; - auto &screen = screens[index]; - if (auto *encoder = screen.encoder; encoder) { - screen.dirty = encoder->render(pb, forceKeyFrame); - if (!screen.dirty) - ctx.cancel_group_execution(); - } + auto &screen = screens[index]; + if (auto *encoder = screen.encoder; encoder) { + screen.dirty = encoder->render(pb, forceKeyFrame); + if (!screen.dirty) + ctx.cancel_group_execution(); + } + }); }); if (ctx.is_group_execution_cancelled()) diff --git a/common/rfb/encoders/ScreenEncoderManager.h b/common/rfb/encoders/ScreenEncoderManager.h index bb7c810..fa9537a 100644 --- a/common/rfb/encoders/ScreenEncoderManager.h +++ b/common/rfb/encoders/ScreenEncoderManager.h @@ -16,14 +16,14 @@ * USA. */ #pragma once -#include +#include #include #include "KasmVideoConstants.h" #include "VideoEncoder.h" #include "rfb/Encoder.h" #include "rfb/ffmpeg.h" -inline constexpr uint8_t MAX_SCREENS = 8; +inline constexpr uint8_t MAX_SCREENS = 4; namespace rfb { template @@ -41,9 +41,9 @@ namespace rfb { uint64_t mask{}; std::vector screens_to_refresh; - tbb::spin_mutex conn_mutex; std::array screens{}; + tbb::task_arena arena; const FFmpeg &ffmpeg; VideoEncoderParams current_params;