mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2025-12-26 14:41:25 +00:00
Remove compress_buf_new
This commit reworks a bit the management of RedCompressBuf so that
compress_buf_new/compress_buf_free become unneeded.
Since d25d6ca0 and the introduction of encoder_data_reset,
compress_buf_free is already unused outside of dcc-encoders.c and could
be static. This in turn makes compress_buf_new a bit odd as the matching
destructor is never used in dcc.c.
This commit introduces an encoder_data_init() method which is hiding
the initialization of the EncoderData structure from the dcc.c code,
allowing to get rid of compress_buf_new() calls from dcc.c code.
It also uses this as an opportunity to stop using GSlice for
RedCompressBuf.
Acked-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
parent
eff5e83936
commit
400a5d13cf
@ -136,18 +136,12 @@ static void glz_usr_free(GlzEncoderUsrContext *usr, void *ptr)
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
RedCompressBuf* compress_buf_new(void)
|
||||
void encoder_data_init(EncoderData *data, DisplayChannelClient *dcc)
|
||||
{
|
||||
RedCompressBuf *buf = g_slice_new(RedCompressBuf);
|
||||
|
||||
buf->send_next = NULL;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
void compress_buf_free(RedCompressBuf *buf)
|
||||
{
|
||||
g_slice_free(RedCompressBuf, buf);
|
||||
data->bufs_tail = g_new(RedCompressBuf, 1);
|
||||
data->bufs_head = data->bufs_tail;
|
||||
data->dcc = dcc;
|
||||
data->bufs_head->send_next = NULL;
|
||||
}
|
||||
|
||||
void encoder_data_reset(EncoderData *data)
|
||||
@ -155,7 +149,7 @@ void encoder_data_reset(EncoderData *data)
|
||||
RedCompressBuf *buf = data->bufs_head;
|
||||
while (buf) {
|
||||
RedCompressBuf *next = buf->send_next;
|
||||
compress_buf_free(buf);
|
||||
g_free(buf);
|
||||
buf = next;
|
||||
}
|
||||
data->bufs_head = data->bufs_tail = NULL;
|
||||
@ -168,7 +162,7 @@ static int encoder_usr_more_space(EncoderData *enc_data, uint8_t **io_ptr)
|
||||
{
|
||||
RedCompressBuf *buf;
|
||||
|
||||
buf = compress_buf_new();
|
||||
buf = g_new(RedCompressBuf, 1);
|
||||
enc_data->bufs_tail->send_next = buf;
|
||||
enc_data->bufs_tail = buf;
|
||||
buf->send_next = NULL;
|
||||
@ -435,7 +429,7 @@ void dcc_encoders_free(DisplayChannelClient *dcc)
|
||||
|
||||
static void marshaller_compress_buf_free(uint8_t *data, void *opaque)
|
||||
{
|
||||
compress_buf_free((RedCompressBuf *) opaque);
|
||||
g_free(opaque);
|
||||
}
|
||||
|
||||
void marshaller_add_compressed(SpiceMarshaller *m,
|
||||
|
||||
@ -51,9 +51,6 @@ void marshaller_add_compressed (SpiceMarshaller *m
|
||||
RedCompressBuf *comp_buf,
|
||||
size_t size);
|
||||
|
||||
RedCompressBuf* compress_buf_new (void);
|
||||
void compress_buf_free (RedCompressBuf *buf);
|
||||
|
||||
#define RED_COMPRESS_BUF_SIZE (1024 * 64)
|
||||
struct RedCompressBuf {
|
||||
/* This buffer provide space for compression algorithms.
|
||||
@ -103,6 +100,7 @@ typedef struct {
|
||||
char message_buf[512];
|
||||
} EncoderData;
|
||||
|
||||
void encoder_data_init(EncoderData *data, DisplayChannelClient *dcc);
|
||||
void encoder_data_reset(EncoderData *data);
|
||||
|
||||
typedef struct {
|
||||
|
||||
31
server/dcc.c
31
server/dcc.c
@ -662,9 +662,7 @@ int dcc_compress_image_glz(DisplayChannelClient *dcc,
|
||||
int glz_size;
|
||||
int zlib_size;
|
||||
|
||||
glz_data->data.bufs_tail = compress_buf_new();
|
||||
glz_data->data.bufs_head = glz_data->data.bufs_tail;
|
||||
glz_data->data.dcc = dcc;
|
||||
encoder_data_init(&glz_data->data, dcc);
|
||||
|
||||
glz_drawable = get_glz_drawable(dcc, drawable);
|
||||
glz_drawable_instance = add_glz_drawable_instance(glz_drawable);
|
||||
@ -689,9 +687,7 @@ int dcc_compress_image_glz(DisplayChannelClient *dcc,
|
||||
stat_start_time_init(&start_time, &display_channel->zlib_glz_stat);
|
||||
zlib_data = &dcc->zlib_data;
|
||||
|
||||
zlib_data->data.bufs_tail = compress_buf_new();
|
||||
zlib_data->data.bufs_head = zlib_data->data.bufs_tail;
|
||||
zlib_data->data.dcc = dcc;
|
||||
encoder_data_init(&zlib_data->data, dcc);
|
||||
|
||||
zlib_data->data.u.compressed_data.next = glz_data->data.bufs_head;
|
||||
zlib_data->data.u.compressed_data.size_left = glz_size;
|
||||
@ -739,9 +735,7 @@ int dcc_compress_image_lz(DisplayChannelClient *dcc,
|
||||
stat_start_time_t start_time;
|
||||
stat_start_time_init(&start_time, &DCC_TO_DC(dcc)->lz_stat);
|
||||
|
||||
lz_data->data.bufs_tail = compress_buf_new();
|
||||
lz_data->data.bufs_head = lz_data->data.bufs_tail;
|
||||
lz_data->data.dcc = dcc;
|
||||
encoder_data_init(&lz_data->data, dcc);
|
||||
|
||||
if (setjmp(lz_data->data.jmp_env)) {
|
||||
encoder_data_reset(&lz_data->data);
|
||||
@ -828,9 +822,7 @@ int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
jpeg_data->data.bufs_tail = compress_buf_new();
|
||||
jpeg_data->data.bufs_head = jpeg_data->data.bufs_tail;
|
||||
jpeg_data->data.dcc = dcc;
|
||||
encoder_data_init(&jpeg_data->data, dcc);
|
||||
|
||||
if (setjmp(jpeg_data->data.jmp_env)) {
|
||||
encoder_data_reset(&jpeg_data->data);
|
||||
@ -928,16 +920,7 @@ int dcc_compress_image_lz4(DisplayChannelClient *dcc, SpiceImage *dest,
|
||||
stat_start_time_t start_time;
|
||||
stat_start_time_init(&start_time, &DCC_TO_DC(dcc)->lz4_stat);
|
||||
|
||||
lz4_data->data.bufs_tail = compress_buf_new();
|
||||
lz4_data->data.bufs_head = lz4_data->data.bufs_tail;
|
||||
|
||||
if (!lz4_data->data.bufs_head) {
|
||||
spice_warning("failed to allocate compress buffer");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
lz4_data->data.bufs_head->send_next = NULL;
|
||||
lz4_data->data.dcc = dcc;
|
||||
encoder_data_init(&lz4_data->data, dcc);
|
||||
|
||||
if (setjmp(lz4_data->data.jmp_env)) {
|
||||
encoder_data_reset(&lz4_data->data);
|
||||
@ -1002,9 +985,7 @@ int dcc_compress_image_quic(DisplayChannelClient *dcc, SpiceImage *dest,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
quic_data->data.bufs_tail = compress_buf_new();
|
||||
quic_data->data.bufs_head = quic_data->data.bufs_tail;
|
||||
quic_data->data.dcc = dcc;
|
||||
encoder_data_init(&quic_data->data, dcc);
|
||||
|
||||
if (setjmp(quic_data->data.jmp_env)) {
|
||||
encoder_data_reset(&quic_data->data);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user