Move update header out of encoders

abstract-encoders
Andri Yngvason 2021-12-12 16:05:29 +00:00
parent 8b2c81c3dd
commit 65c0e91c37
7 changed files with 22 additions and 23 deletions

View File

@ -22,7 +22,6 @@
struct vec;
int encode_rect_count(struct vec* dst, uint32_t count);
int encode_rect_head(struct vec* dst, enum rfb_encodings encoding,
uint32_t x, uint32_t y, uint32_t width, uint32_t height);
uint32_t calc_bytes_per_cpixel(const struct rfb_pixel_format* fmt);

View File

@ -45,6 +45,8 @@ struct encoder {
uint16_t x_pos;
uint16_t y_pos;
int n_rects;
void (*on_done)(struct encoder*, struct rcbuf* result);
void* userdata;
};

View File

@ -20,16 +20,6 @@
#include <arpa/inet.h>
int encode_rect_count(struct vec* dst, uint32_t count)
{
struct rfb_server_fb_update_msg msg = {
.type = RFB_SERVER_TO_CLIENT_FRAMEBUFFER_UPDATE,
.n_rects = htons(count),
};
return vec_append(dst, &msg, sizeof(msg));
}
int encode_rect_head(struct vec* dst, enum rfb_encodings encoding,
uint32_t x, uint32_t y, uint32_t width, uint32_t height)
{

View File

@ -93,6 +93,8 @@ static int raw_encode_frame(struct raw_encoder* self, struct vec* dst,
{
int rc = -1;
self->encoder.n_rects = 0;
int n_rects = 0;
struct pixman_box16* box = pixman_region_rectangles(region, &n_rects);
if (n_rects > UINT16_MAX) {
@ -108,10 +110,6 @@ static int raw_encode_frame(struct raw_encoder* self, struct vec* dst,
if (rc < 0)
return -1;
rc = encode_rect_count(dst, n_rects);
if (rc < 0)
return -1;
for (int i = 0; i < n_rects; ++i) {
int x = box[i].x1;
int y = box[i].y1;
@ -124,6 +122,7 @@ static int raw_encode_frame(struct raw_encoder* self, struct vec* dst,
return -1;
}
self->encoder.n_rects = n_rects;
return 0;
}

View File

@ -28,6 +28,7 @@
#include "usdt.h"
#include "encoder.h"
#include "tight.h"
#include "enc-util.h"
#include <stdlib.h>
#include <unistd.h>
@ -1223,12 +1224,19 @@ static bool client_has_encoding(const struct nvnc_client* client,
return false;
}
static void finish_fb_update(struct nvnc_client* client, struct rcbuf* payload)
static void finish_fb_update(struct nvnc_client* client, struct rcbuf* payload,
int n_rects)
{
client_ref(client);
if (client->net_stream->state != STREAM_STATE_CLOSED) {
DTRACE_PROBE1(neatvnc, send_fb_start, client);
struct rfb_server_fb_update_msg update_msg = {
.type = RFB_SERVER_TO_CLIENT_FRAMEBUFFER_UPDATE,
.n_rects = htons(n_rects),
};
stream_write(client->net_stream, &update_msg,
sizeof(update_msg), NULL, NULL);
rcbuf_ref(payload);
stream_send(client->net_stream, payload, on_write_frame_done,
client);
@ -1251,7 +1259,7 @@ static void finish_fb_update(struct nvnc_client* client, struct rcbuf* payload)
static void on_encode_frame_done(struct encoder* encoder, struct rcbuf* result)
{
struct nvnc_client* client = encoder->userdata;
finish_fb_update(client, result);
finish_fb_update(client, result, encoder->n_rects);
client_unref(client);
}

View File

@ -514,6 +514,8 @@ static void on_tight_finished(void* obj)
struct rcbuf* result = rcbuf_new(self->dst.data, self->dst.len);
assert(result);
self->encoder.n_rects = self->n_rects;
if (self->encoder.on_done)
self->encoder.on_done(&self->encoder, result);
@ -580,6 +582,8 @@ static int tight_encoder_encode(struct encoder* encoder, struct nvnc_fb* fb,
struct tight_encoder* self = tight_encoder(encoder);
int rc;
self->encoder.n_rects = 0;
rc = rfb_pixfmt_from_fourcc(&self->sfmt, nvnc_fb_get_fourcc_format(fb));
assert(rc == 0);
@ -598,8 +602,6 @@ static int tight_encoder_encode(struct encoder* encoder, struct nvnc_fb* fb,
self->n_rects = tight_apply_damage(self, damage);
assert(self->n_rects > 0);
encode_rect_count(&self->dst, self->n_rects);
nvnc_fb_ref(self->fb);
if (tight_schedule_encoding_jobs(self) < 0) {

View File

@ -299,6 +299,8 @@ static int zrle_encode_frame(struct zrle_encoder* self, z_stream* zs,
{
int rc = -1;
self->encoder.n_rects = 0;
int n_rects = 0;
struct pixman_box16* box = pixman_region_rectangles(region, &n_rects);
if (n_rects > UINT16_MAX) {
@ -310,10 +312,6 @@ static int zrle_encode_frame(struct zrle_encoder* self, z_stream* zs,
if (rc < 0)
return -1;
rc = encode_rect_count(dst, n_rects);
if (rc < 0)
return -1;
for (int i = 0; i < n_rects; ++i) {
int x = box[i].x1;
int y = box[i].y1;
@ -326,6 +324,7 @@ static int zrle_encode_frame(struct zrle_encoder* self, z_stream* zs,
return -1;
}
self->encoder.n_rects = n_rects;
return 0;
}