diff --git a/include/common.h b/include/common.h index 51debeb..d5d3635 100644 --- a/include/common.h +++ b/include/common.h @@ -24,6 +24,7 @@ #include "neatvnc.h" #include "miniz.h" +#include "tight.h" #include "config.h" #ifdef ENABLE_TLS @@ -71,6 +72,7 @@ struct nvnc_client { bool is_updating; nvnc_client_fn cleanup_fn; z_stream z_stream; + struct tight_encoder tight_encoder; size_t buffer_index; size_t buffer_len; uint8_t msg_buffer[MSG_BUFFER_SIZE]; diff --git a/include/tight.h b/include/tight.h index b8edc1c..8062782 100644 --- a/include/tight.h +++ b/include/tight.h @@ -16,11 +16,20 @@ #pragma once +#include "miniz.h" + struct vec; struct nvnc_client; struct nvnc_fb; struct pixman_region16; -int tight_encode_frame(struct vec* dst, struct nvnc_client* client, +struct tight_encoder { + z_stream zs[4]; +}; + +int tight_encoder_init(struct tight_encoder*); +void tight_encoder_destroy(struct tight_encoder*); + +int tight_encode_frame(struct tight_encoder* self, struct vec* dst, const struct nvnc_fb* fb, struct pixman_region16* region); diff --git a/src/server.c b/src/server.c index b3c1a3d..d1790e8 100644 --- a/src/server.c +++ b/src/server.c @@ -77,6 +77,7 @@ static void client_close(struct nvnc_client* client) LIST_REMOVE(client, link); stream_destroy(client->net_stream); + tight_encoder_destroy(&client->tight_encoder); deflateEnd(&client->z_stream); pixman_region_fini(&client->damage); free(client); @@ -708,6 +709,9 @@ static void on_connection(void* obj) if (rc != Z_OK) goto deflate_failure; + if (tight_encoder_init(&client->tight_encoder) < 0) + goto tight_failure; + pixman_region_init(&client->damage); struct rcbuf* payload = rcbuf_from_string(RFB_VERSION_MESSAGE); @@ -725,6 +729,9 @@ static void on_connection(void* obj) return; payload_failure: + tight_encoder_destroy(&client->tight_encoder); + pixman_region_fini(&client->damage); +tight_failure: deflateEnd(&client->z_stream); deflate_failure: stream_destroy(client->net_stream); @@ -859,7 +866,8 @@ void do_client_update_fb(void* work) break; #ifdef ENABLE_TIGHT case RFB_ENCODING_TIGHT: - tight_encode_frame(&update->frame, client, fb, &update->region); + tight_encode_frame(&client->tight_encoder, &update->frame, fb, + &update->region); break; #endif case RFB_ENCODING_ZRLE: diff --git a/src/tight.c b/src/tight.c index 7617a79..c8825f5 100644 --- a/src/tight.c +++ b/src/tight.c @@ -35,6 +35,17 @@ #define TIGHT_MAX_WIDTH 2048 +int tight_encoder_init(struct tight_encoder* self) +{ + // TODO + return 0; +} + +void tight_encoder_destroy(struct tight_encoder* self) +{ + // TODO +} + enum TJPF get_jpeg_pixfmt(uint32_t fourcc) { switch (fourcc) { @@ -64,9 +75,9 @@ static void tight_encode_size(struct vec* dst, size_t size) vec_fast_append_8(dst, (size >> 14) & 0x7f); } -int tight_encode_box(struct vec* dst, struct nvnc_client* client, - const struct nvnc_fb* fb, uint32_t x, uint32_t y, - uint32_t stride, uint32_t width, uint32_t height) +int tight_encode_box_jpeg(struct tight_encoder* self, struct vec* dst, + const struct nvnc_fb* fb, uint32_t x, uint32_t y, + uint32_t stride, uint32_t width, uint32_t height) { unsigned char* buffer = NULL; @@ -117,7 +128,14 @@ compress_failure: return rc; } -int tight_encode_frame(struct vec* dst, struct nvnc_client* client, +int tight_encode_box(struct tight_encoder* self, struct vec* dst, + const struct nvnc_fb* fb, uint32_t x, uint32_t y, + uint32_t stride, uint32_t width, uint32_t height) +{ + return tight_encode_box_jpeg(self, dst, fb, x, y, stride, width, height); +} + +int tight_encode_frame(struct tight_encoder* self, struct vec* dst, const struct nvnc_fb* fb, struct pixman_region16* region) { int rc = -1; @@ -148,7 +166,7 @@ int tight_encode_frame(struct vec* dst, struct nvnc_client* client, int w = MIN(TIGHT_MAX_WIDTH, box_width); box_width -= w; - rc = tight_encode_box(dst, client, fb, x, y, fb->width, + rc = tight_encode_box(self, dst, fb, x, y, fb->width, w, box_height); if (rc < 0) return -1;