tight: Prepare for "basic" encoding method

pull/30/head
Andri Yngvason 2020-04-02 21:52:04 +00:00
parent 999c1ef255
commit cfb2abfc58
4 changed files with 44 additions and 7 deletions

View File

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

View File

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

View File

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

View File

@ -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,7 +75,7 @@ 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,
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)
{
@ -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;