VNC-151 Refactor write_compact to use shared utility function

This commit is contained in:
El 2026-02-02 00:55:08 +00:00
parent cadd5a9546
commit fc24bf9961
No known key found for this signature in database
GPG Key ID: 205388FEB607950A
7 changed files with 31 additions and 36 deletions

View File

@ -78,6 +78,7 @@ set(RFB_SOURCES
encoders/VideoEncoderFactory.cxx
encoders/EncoderProbe.cpp
encoders/EncoderConfiguration.cpp
encoders/utils.cpp
)
if (UNIX)

View File

@ -29,6 +29,7 @@ extern "C" {
#include "KasmVideoConstants.h"
#include "rfb/encodings.h"
#include <rfb/encoders/utils.h>
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);

View File

@ -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<typename T>

View File

@ -27,6 +27,7 @@ extern "C" {
#include <rfb/encodings.h>
#include <rfb/ffmpeg.h>
#include <fmt/format.h>
#include <rfb/encoders/utils.h>
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);

View File

@ -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<typename T>

View File

@ -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

View File

@ -0,0 +1,7 @@
#pragma once
#include "rdr/OutStream.h"
namespace rfb::encoders {
void write_compact(rdr::OutStream *os, int value);
} // namespace rfb::encoders