diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt index 17c443f..0c129be 100644 --- a/common/rfb/CMakeLists.txt +++ b/common/rfb/CMakeLists.txt @@ -78,6 +78,7 @@ set(RFB_SOURCES encoders/VideoEncoderFactory.cxx encoders/EncoderProbe.cpp encoders/EncoderConfiguration.cpp + encoders/utils.cpp ) if (UNIX) diff --git a/common/rfb/encoders/FFMPEGVAAPIEncoder.cxx b/common/rfb/encoders/FFMPEGVAAPIEncoder.cxx index 4d26887..d02ae5b 100644 --- a/common/rfb/encoders/FFMPEGVAAPIEncoder.cxx +++ b/common/rfb/encoders/FFMPEGVAAPIEncoder.cxx @@ -29,6 +29,7 @@ extern "C" { #include "KasmVideoConstants.h" #include "rfb/encodings.h" +#include static rfb::LogWriter vlog("FFMPEGVAAPIEncoder"); @@ -64,22 +65,6 @@ namespace rfb { pkt_guard.reset(pkt); } - void FFMPEGVAAPIEncoder::write_compact(rdr::OutStream *os, int value) { - auto b = value & 0x7F; - if (value <= 0x7F) { - os->writeU8(b); - } else { - os->writeU8(b | 0x80); - b = value >> 7 & 0x7F; - if (value <= 0x3FFF) { - os->writeU8(b); - } else { - os->writeU8(b | 0x80); - os->writeU8(value >> 14 & 0xFF); - } - } - } - bool FFMPEGVAAPIEncoder::init(int width, int height, VideoEncoderParams params) { current_params = params; AVHWFramesContext *frames_ctx{}; @@ -280,7 +265,7 @@ namespace rfb { os->writeU8(layout.id); os->writeU8(msg_codec_id); os->writeU8(pkt->flags & AV_PKT_FLAG_KEY); - write_compact(os, pkt->size); + encoders::write_compact(os, pkt->size); os->writeBytes(&pkt->data[0], pkt->size); vlog.debug("Screen id %d, codec %d, frame size: %d", layout.id, msg_codec_id, pkt->size); diff --git a/common/rfb/encoders/FFMPEGVAAPIEncoder.h b/common/rfb/encoders/FFMPEGVAAPIEncoder.h index 8703025..ebc77d2 100644 --- a/common/rfb/encoders/FFMPEGVAAPIEncoder.h +++ b/common/rfb/encoders/FFMPEGVAAPIEncoder.h @@ -46,7 +46,6 @@ class FFMPEGVAAPIEncoder final : public VideoEncoder { int bpp{}; const char *dri_node{}; - static void write_compact(rdr::OutStream *os, int value); [[nodiscard]] bool init(int width, int height, VideoEncoderParams params); template diff --git a/common/rfb/encoders/SoftwareEncoder.cxx b/common/rfb/encoders/SoftwareEncoder.cxx index fb1f84d..99d03d8 100644 --- a/common/rfb/encoders/SoftwareEncoder.cxx +++ b/common/rfb/encoders/SoftwareEncoder.cxx @@ -27,6 +27,7 @@ extern "C" { #include #include #include +#include static rfb::LogWriter vlog("SoftwareEncoder"); @@ -139,7 +140,7 @@ namespace rfb { os->writeU8(layout.id); os->writeU8(msg_codec_id); os->writeU8(pkt->flags & AV_PKT_FLAG_KEY); - write_compact(os, pkt->size); + encoders::write_compact(os, pkt->size); os->writeBytes(&pkt->data[0], pkt->size); vlog.debug("Screen id %d, codec %d, frame size: %d", layout.id, msg_codec_id, pkt->size); @@ -154,22 +155,6 @@ namespace rfb { os->writeU8(kasmVideoSkip); } - void SoftwareEncoder::write_compact(rdr::OutStream *os, int value) { - auto b = value & 0x7F; - if (value <= 0x7F) { - os->writeU8(b); - } else { - os->writeU8(b | 0x80); - b = value >> 7 & 0x7F; - if (value <= 0x3FFF) { - os->writeU8(b); - } else { - os->writeU8(b | 0x80); - os->writeU8(value >> 14 & 0xFF); - } - } - } - bool SoftwareEncoder::init(int width, int height, VideoEncoderParams params) { current_params = params; vlog.debug("FRAME RESIZE (%d, %d): RATE: %d, GOP: %d, QUALITY: %d", width, height, current_params.frame_rate, current_params.group_of_picture, current_params.quality); diff --git a/common/rfb/encoders/SoftwareEncoder.h b/common/rfb/encoders/SoftwareEncoder.h index 968916a..6a6e2c4 100644 --- a/common/rfb/encoders/SoftwareEncoder.h +++ b/common/rfb/encoders/SoftwareEncoder.h @@ -40,7 +40,6 @@ namespace rfb { int64_t pts{}; int bpp{}; - static void write_compact(rdr::OutStream *os, int value); [[nodiscard]] bool init(int width, int height, VideoEncoderParams params); template diff --git a/common/rfb/encoders/utils.cpp b/common/rfb/encoders/utils.cpp new file mode 100644 index 0000000..6ac5b96 --- /dev/null +++ b/common/rfb/encoders/utils.cpp @@ -0,0 +1,19 @@ +#include "utils.h" + +namespace rfb::encoders { + void write_compact(rdr::OutStream *os, int value) { + auto b = value & 0x7F; + if (value <= 0x7F) { + os->writeU8(b); + } else { + os->writeU8(b | 0x80); + b = value >> 7 & 0x7F; + if (value <= 0x3FFF) { + os->writeU8(b); + } else { + os->writeU8(b | 0x80); + os->writeU8(value >> 14 & 0xFF); + } + } + } +} // namespace rfb::encoders diff --git a/common/rfb/encoders/utils.h b/common/rfb/encoders/utils.h new file mode 100644 index 0000000..5289647 --- /dev/null +++ b/common/rfb/encoders/utils.h @@ -0,0 +1,7 @@ +#pragma once + +#include "rdr/OutStream.h" + +namespace rfb::encoders { + void write_compact(rdr::OutStream *os, int value); +} // namespace rfb::encoders