[Spice-commits] 3 commits - server/dcc-encoders.c server/dcc-encoders.h server/dcc.c server/dcc.h

Frediano Ziglio fziglio at kemper.freedesktop.org
Thu Jun 9 21:50:39 UTC 2016


 server/dcc-encoders.c |   66 +++++++++++++++++++++++++++++++++++++++++++-------
 server/dcc-encoders.h |    8 ++++++
 server/dcc.c          |   54 +---------------------------------------
 server/dcc.h          |    4 ---
 4 files changed, 68 insertions(+), 64 deletions(-)

New commits:
commit 21a90ae9867c4ea13d271b05c80dad4a001cf15b
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Jun 3 15:47:02 2016 +0100

    Move image_encoders_compress_lz4 to dcc-encoders.c
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c
index 8790512..7b27aff 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -989,4 +989,54 @@ int image_encoders_compress_jpeg(ImageEncoders *enc, SpiceImage *dest,
     return TRUE;
 }
 
+#ifdef USE_LZ4
+int image_encoders_compress_lz4(ImageEncoders *enc, SpiceImage *dest,
+                                SpiceBitmap *src, compress_send_data_t* o_comp_data,
+                                stat_info_t *stats)
+{
+    Lz4Data *lz4_data = &enc->lz4_data;
+    Lz4EncoderContext *lz4 = enc->lz4;
+    int lz4_size = 0;
+    stat_start_time_t start_time;
+    stat_start_time_init(&start_time, stats);
+
+#ifdef COMPRESS_DEBUG
+    spice_info("LZ4 compress");
+#endif
 
+    encoder_data_init(&lz4_data->data);
+
+    if (setjmp(lz4_data->data.jmp_env)) {
+        encoder_data_reset(&lz4_data->data);
+        return FALSE;
+    }
+
+    if (src->data->flags & SPICE_CHUNKS_FLAGS_UNSTABLE) {
+        spice_chunks_linearize(src->data);
+    }
+
+    lz4_data->data.u.lines_data.chunks = src->data;
+    lz4_data->data.u.lines_data.stride = src->stride;
+    lz4_data->data.u.lines_data.next = 0;
+    lz4_data->data.u.lines_data.reverse = 0;
+
+    lz4_size = lz4_encode(lz4, src->y, src->stride, lz4_data->data.bufs_head->buf.bytes,
+                          sizeof(lz4_data->data.bufs_head->buf),
+                          src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN, src->format);
+
+    // the compressed buffer is bigger than the original data
+    if (lz4_size > (src->y * src->stride)) {
+        longjmp(lz4_data->data.jmp_env, 1);
+    }
+
+    dest->descriptor.type = SPICE_IMAGE_TYPE_LZ4;
+    dest->u.lz4.data_size = lz4_size;
+
+    o_comp_data->comp_buf = lz4_data->data.bufs_head;
+    o_comp_data->comp_buf_size = lz4_size;
+
+    stat_compress_add(stats, start_time, src->stride * src->y,
+                      o_comp_data->comp_buf_size);
+    return TRUE;
+}
+#endif
diff --git a/server/dcc-encoders.h b/server/dcc-encoders.h
index 6f4fac2..d4378de 100644
--- a/server/dcc-encoders.h
+++ b/server/dcc-encoders.h
@@ -197,6 +197,9 @@ int image_encoders_compress_jpeg(ImageEncoders *enc, SpiceImage *dest,
                                  SpiceBitmap *src, compress_send_data_t* o_comp_data,
                                  stat_info_t *jpeg_stats,
                                  stat_info_t *jpeg_alpha_stats);
+int image_encoders_compress_lz4(ImageEncoders *enc, SpiceImage *dest,
+                                SpiceBitmap *src, compress_send_data_t* o_comp_data,
+                                stat_info_t *stats);
 
 #define RED_RELEASE_BUNCH_SIZE 64
 
diff --git a/server/dcc.c b/server/dcc.c
index 4e65d55..0bc0e04 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -784,58 +784,6 @@ glz:
     return TRUE;
 }
 
-#ifdef USE_LZ4
-static int image_encoders_compress_lz4(ImageEncoders *enc, SpiceImage *dest,
-                                       SpiceBitmap *src, compress_send_data_t* o_comp_data,
-                                       stat_info_t *stats)
-{
-    Lz4Data *lz4_data = &enc->lz4_data;
-    Lz4EncoderContext *lz4 = enc->lz4;
-    int lz4_size = 0;
-    stat_start_time_t start_time;
-    stat_start_time_init(&start_time, stats);
-
-#ifdef COMPRESS_DEBUG
-    spice_info("LZ4 compress");
-#endif
-
-    encoder_data_init(&lz4_data->data);
-
-    if (setjmp(lz4_data->data.jmp_env)) {
-        encoder_data_reset(&lz4_data->data);
-        return FALSE;
-    }
-
-    if (src->data->flags & SPICE_CHUNKS_FLAGS_UNSTABLE) {
-        spice_chunks_linearize(src->data);
-    }
-
-    lz4_data->data.u.lines_data.chunks = src->data;
-    lz4_data->data.u.lines_data.stride = src->stride;
-    lz4_data->data.u.lines_data.next = 0;
-    lz4_data->data.u.lines_data.reverse = 0;
-
-    lz4_size = lz4_encode(lz4, src->y, src->stride, lz4_data->data.bufs_head->buf.bytes,
-                          sizeof(lz4_data->data.bufs_head->buf),
-                          src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN, src->format);
-
-    // the compressed buffer is bigger than the original data
-    if (lz4_size > (src->y * src->stride)) {
-        longjmp(lz4_data->data.jmp_env, 1);
-    }
-
-    dest->descriptor.type = SPICE_IMAGE_TYPE_LZ4;
-    dest->u.lz4.data_size = lz4_size;
-
-    o_comp_data->comp_buf = lz4_data->data.bufs_head;
-    o_comp_data->comp_buf_size = lz4_size;
-
-    stat_compress_add(stats, start_time, src->stride * src->y,
-                      o_comp_data->comp_buf_size);
-    return TRUE;
-}
-#endif
-
 #define MIN_DIMENSION_TO_QUIC 3
 /**
  * quic doesn't handle:
commit aa10a2ca2a763b84767fca1d1c5aeb6570a12324
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Jun 9 12:08:48 2016 +0100

    Prepare to move dcc_compress_image_lz4 to ImageEncoders
    
    Remove all DisplayChannel(Client) dependencies.
    Rename function.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/dcc.c b/server/dcc.c
index c3cfb05..4e65d55 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -785,14 +785,15 @@ glz:
 }
 
 #ifdef USE_LZ4
-static int dcc_compress_image_lz4(DisplayChannelClient *dcc, SpiceImage *dest,
-                                  SpiceBitmap *src, compress_send_data_t* o_comp_data)
+static int image_encoders_compress_lz4(ImageEncoders *enc, SpiceImage *dest,
+                                       SpiceBitmap *src, compress_send_data_t* o_comp_data,
+                                       stat_info_t *stats)
 {
-    Lz4Data *lz4_data = &dcc->encoders.lz4_data;
-    Lz4EncoderContext *lz4 = dcc->encoders.lz4;
+    Lz4Data *lz4_data = &enc->lz4_data;
+    Lz4EncoderContext *lz4 = enc->lz4;
     int lz4_size = 0;
     stat_start_time_t start_time;
-    stat_start_time_init(&start_time, &DCC_TO_DC(dcc)->lz4_stat);
+    stat_start_time_init(&start_time, stats);
 
 #ifdef COMPRESS_DEBUG
     spice_info("LZ4 compress");
@@ -829,7 +830,7 @@ static int dcc_compress_image_lz4(DisplayChannelClient *dcc, SpiceImage *dest,
     o_comp_data->comp_buf = lz4_data->data.bufs_head;
     o_comp_data->comp_buf_size = lz4_size;
 
-    stat_compress_add(&DCC_TO_DC(dcc)->lz4_stat, start_time, src->stride * src->y,
+    stat_compress_add(stats, start_time, src->stride * src->y,
                       o_comp_data->comp_buf_size);
     return TRUE;
 }
@@ -965,7 +966,8 @@ int dcc_compress_image(DisplayChannelClient *dcc,
     case SPICE_IMAGE_COMPRESSION_LZ4:
         if (red_channel_client_test_remote_cap(&dcc->common.base,
                                                SPICE_DISPLAY_CAP_LZ4_COMPRESSION)) {
-            success = dcc_compress_image_lz4(dcc, dest, src, o_comp_data);
+            success = image_encoders_compress_lz4(&dcc->encoders, dest, src, o_comp_data,
+                                                  &display_channel->lz4_stat);
             break;
         }
 #endif
commit 6d70d15d64efc5a1dddd9426974c710ab6f896de
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Jun 9 12:08:17 2016 +0100

    Encapsulate lz4 information in ImageEncoders structure
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c
index 0b8ef46..8790512 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -373,14 +373,14 @@ static void image_encoders_init_jpeg(ImageEncoders *enc)
 }
 
 #ifdef USE_LZ4
-static inline void dcc_init_lz4(DisplayChannelClient *dcc)
+static inline void image_encoders_init_lz4(ImageEncoders *enc)
 {
-    dcc->lz4_data.usr.more_space = lz4_usr_more_space;
-    dcc->lz4_data.usr.more_lines = lz4_usr_more_lines;
+    enc->lz4_data.usr.more_space = lz4_usr_more_space;
+    enc->lz4_data.usr.more_lines = lz4_usr_more_lines;
 
-    dcc->lz4 = lz4_encoder_create(&dcc->lz4_data.usr);
+    enc->lz4 = lz4_encoder_create(&enc->lz4_data.usr);
 
-    if (!dcc->lz4) {
+    if (!enc->lz4) {
         spice_critical("create lz4 encoder failed");
     }
 }
@@ -407,7 +407,7 @@ void dcc_encoders_init(DisplayChannelClient *dcc)
     image_encoders_init_lz(enc);
     image_encoders_init_jpeg(enc);
 #ifdef USE_LZ4
-    dcc_init_lz4(dcc);
+    image_encoders_init_lz4(enc);
 #endif
     dcc_init_zlib(dcc);
 
@@ -425,8 +425,8 @@ void dcc_encoders_free(DisplayChannelClient *dcc)
     jpeg_encoder_destroy(enc->jpeg);
     enc->jpeg = NULL;
 #ifdef USE_LZ4
-    lz4_encoder_destroy(dcc->lz4);
-    dcc->lz4 = NULL;
+    lz4_encoder_destroy(enc->lz4);
+    enc->lz4 = NULL;
 #endif
     zlib_encoder_destroy(dcc->zlib);
     dcc->zlib = NULL;
diff --git a/server/dcc-encoders.h b/server/dcc-encoders.h
index ebc1b93..6f4fac2 100644
--- a/server/dcc-encoders.h
+++ b/server/dcc-encoders.h
@@ -172,6 +172,11 @@ struct ImageEncoders {
 
     JpegData jpeg_data;
     JpegEncoderContext *jpeg;
+
+#ifdef USE_LZ4
+    Lz4Data lz4_data;
+    Lz4EncoderContext *lz4;
+#endif
 };
 
 typedef struct compress_send_data_t {
diff --git a/server/dcc.c b/server/dcc.c
index 218baad..c3cfb05 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -788,8 +788,8 @@ glz:
 static int dcc_compress_image_lz4(DisplayChannelClient *dcc, SpiceImage *dest,
                                   SpiceBitmap *src, compress_send_data_t* o_comp_data)
 {
-    Lz4Data *lz4_data = &dcc->lz4_data;
-    Lz4EncoderContext *lz4 = dcc->lz4;
+    Lz4Data *lz4_data = &dcc->encoders.lz4_data;
+    Lz4EncoderContext *lz4 = dcc->encoders.lz4;
     int lz4_size = 0;
     stat_start_time_t start_time;
     stat_start_time_init(&start_time, &DCC_TO_DC(dcc)->lz4_stat);
diff --git a/server/dcc.h b/server/dcc.h
index 034b9b1..bdfc001 100644
--- a/server/dcc.h
+++ b/server/dcc.h
@@ -65,10 +65,6 @@ struct DisplayChannelClient {
 
     int zlib_level;
 
-#ifdef USE_LZ4
-    Lz4Data lz4_data;
-    Lz4EncoderContext *lz4;
-#endif
     ZlibData zlib_data;
     ZlibEncoder *zlib;
 


More information about the Spice-commits mailing list