[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:33:49 UTC 2016


 server/dcc-encoders.c |  143 +++++++++++++++++++++++++++++++++++++++++++++++---
 server/dcc-encoders.h |    9 +++
 server/dcc.c          |  131 +--------------------------------------------
 server/dcc.h          |    3 -
 4 files changed, 148 insertions(+), 138 deletions(-)

New commits:
commit 25c0b204c4d5c0f276721298a75f3fa475738bc2
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Fri Jun 3 15:41:35 2016 +0100

    Move image_encoders_compress_jpeg 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 279c134..0b8ef46 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -862,4 +862,131 @@ int image_encoders_compress_lz(ImageEncoders *enc,
     return TRUE;
 }
 
+int image_encoders_compress_jpeg(ImageEncoders *enc, SpiceImage *dest,
+                                 SpiceBitmap *src, compress_send_data_t* o_comp_data,
+                                 stat_info_t *jpeg_stats, // FIXME put all stats in a structure
+                                 stat_info_t *jpeg_alpha_stats)
+{
+    JpegData *jpeg_data = &enc->jpeg_data;
+    LzData *lz_data = &enc->lz_data;
+    JpegEncoderContext *jpeg = enc->jpeg;
+    LzContext *lz = enc->lz;
+    volatile JpegEncoderImageType jpeg_in_type;
+    int jpeg_size = 0;
+    volatile int has_alpha = FALSE;
+    int alpha_lz_size = 0;
+    int comp_head_filled;
+    int comp_head_left;
+    int stride;
+    uint8_t *lz_out_start_byte;
+    stat_start_time_t start_time;
+    stat_start_time_init(&start_time, jpeg_alpha_stats);
+
+#ifdef COMPRESS_DEBUG
+    spice_info("JPEG compress");
+#endif
+
+    switch (src->format) {
+    case SPICE_BITMAP_FMT_16BIT:
+        jpeg_in_type = JPEG_IMAGE_TYPE_RGB16;
+        break;
+    case SPICE_BITMAP_FMT_24BIT:
+        jpeg_in_type = JPEG_IMAGE_TYPE_BGR24;
+        break;
+    case SPICE_BITMAP_FMT_32BIT:
+        jpeg_in_type = JPEG_IMAGE_TYPE_BGRX32;
+        break;
+    case SPICE_BITMAP_FMT_RGBA:
+        jpeg_in_type = JPEG_IMAGE_TYPE_BGRX32;
+        has_alpha = TRUE;
+        break;
+    default:
+        return FALSE;
+    }
+
+    encoder_data_init(&jpeg_data->data);
+
+    if (setjmp(jpeg_data->data.jmp_env)) {
+        encoder_data_reset(&jpeg_data->data);
+        return FALSE;
+    }
+
+    if (src->data->flags & SPICE_CHUNKS_FLAGS_UNSTABLE) {
+        spice_chunks_linearize(src->data);
+    }
+
+    jpeg_data->data.u.lines_data.chunks = src->data;
+    jpeg_data->data.u.lines_data.stride = src->stride;
+    if ((src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN)) {
+        jpeg_data->data.u.lines_data.next = 0;
+        jpeg_data->data.u.lines_data.reverse = 0;
+        stride = src->stride;
+    } else {
+        jpeg_data->data.u.lines_data.next = src->data->num_chunks - 1;
+        jpeg_data->data.u.lines_data.reverse = 1;
+        stride = -src->stride;
+    }
+    jpeg_size = jpeg_encode(jpeg, enc->jpeg_quality, jpeg_in_type,
+                            src->x, src->y, NULL,
+                            0, stride, jpeg_data->data.bufs_head->buf.bytes,
+                            sizeof(jpeg_data->data.bufs_head->buf));
+
+    // the compressed buffer is bigger than the original data
+    if (jpeg_size > (src->y * src->stride)) {
+        longjmp(jpeg_data->data.jmp_env, 1);
+    }
+
+    if (!has_alpha) {
+        dest->descriptor.type = SPICE_IMAGE_TYPE_JPEG;
+        dest->u.jpeg.data_size = jpeg_size;
+
+        o_comp_data->comp_buf = jpeg_data->data.bufs_head;
+        o_comp_data->comp_buf_size = jpeg_size;
+        o_comp_data->is_lossy = TRUE;
+
+        stat_compress_add(jpeg_stats, start_time, src->stride * src->y,
+                          o_comp_data->comp_buf_size);
+        return TRUE;
+    }
+
+    lz_data->data.bufs_head = jpeg_data->data.bufs_tail;
+    lz_data->data.bufs_tail = lz_data->data.bufs_head;
+
+    comp_head_filled = jpeg_size % sizeof(lz_data->data.bufs_head->buf);
+    comp_head_left = sizeof(lz_data->data.bufs_head->buf) - comp_head_filled;
+    lz_out_start_byte = lz_data->data.bufs_head->buf.bytes + comp_head_filled;
+
+    lz_data->data.u.lines_data.chunks = src->data;
+    lz_data->data.u.lines_data.stride = src->stride;
+    lz_data->data.u.lines_data.next = 0;
+    lz_data->data.u.lines_data.reverse = 0;
+
+    alpha_lz_size = lz_encode(lz, LZ_IMAGE_TYPE_XXXA, src->x, src->y,
+                               !!(src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN),
+                               NULL, 0, src->stride,
+                               lz_out_start_byte,
+                               comp_head_left);
+
+    // the compressed buffer is bigger than the original data
+    if ((jpeg_size + alpha_lz_size) > (src->y * src->stride)) {
+        longjmp(jpeg_data->data.jmp_env, 1);
+    }
+
+    dest->descriptor.type = SPICE_IMAGE_TYPE_JPEG_ALPHA;
+    dest->u.jpeg_alpha.flags = 0;
+    if (src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN) {
+        dest->u.jpeg_alpha.flags |= SPICE_JPEG_ALPHA_FLAGS_TOP_DOWN;
+    }
+
+    dest->u.jpeg_alpha.jpeg_size = jpeg_size;
+    dest->u.jpeg_alpha.data_size = jpeg_size + alpha_lz_size;
+
+    o_comp_data->comp_buf = jpeg_data->data.bufs_head;
+    o_comp_data->comp_buf_size = jpeg_size + alpha_lz_size;
+    o_comp_data->is_lossy = TRUE;
+    stat_compress_add(jpeg_alpha_stats, start_time, src->stride * src->y,
+                      o_comp_data->comp_buf_size);
+    return TRUE;
+}
+
 
diff --git a/server/dcc-encoders.h b/server/dcc-encoders.h
index 0d0eee2..ebc1b93 100644
--- a/server/dcc-encoders.h
+++ b/server/dcc-encoders.h
@@ -188,6 +188,10 @@ int image_encoders_compress_lz(ImageEncoders *enc,
                                SpiceImage *dest, SpiceBitmap *src,
                                compress_send_data_t* o_comp_data,
                                stat_info_t *stats);
+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);
 
 #define RED_RELEASE_BUNCH_SIZE 64
 
diff --git a/server/dcc.c b/server/dcc.c
index ca6f5b5..218baad 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -784,133 +784,6 @@ glz:
     return TRUE;
 }
 
-static int image_encoders_compress_jpeg(ImageEncoders *enc, SpiceImage *dest,
-                                        SpiceBitmap *src, compress_send_data_t* o_comp_data,
-                                        stat_info_t *jpeg_stats, // FIXME put all stats in a structure
-                                        stat_info_t *jpeg_alpha_stats)
-{
-    JpegData *jpeg_data = &enc->jpeg_data;
-    LzData *lz_data = &enc->lz_data;
-    JpegEncoderContext *jpeg = enc->jpeg;
-    LzContext *lz = enc->lz;
-    volatile JpegEncoderImageType jpeg_in_type;
-    int jpeg_size = 0;
-    volatile int has_alpha = FALSE;
-    int alpha_lz_size = 0;
-    int comp_head_filled;
-    int comp_head_left;
-    int stride;
-    uint8_t *lz_out_start_byte;
-    stat_start_time_t start_time;
-    stat_start_time_init(&start_time, jpeg_alpha_stats);
-
-#ifdef COMPRESS_DEBUG
-    spice_info("JPEG compress");
-#endif
-
-    switch (src->format) {
-    case SPICE_BITMAP_FMT_16BIT:
-        jpeg_in_type = JPEG_IMAGE_TYPE_RGB16;
-        break;
-    case SPICE_BITMAP_FMT_24BIT:
-        jpeg_in_type = JPEG_IMAGE_TYPE_BGR24;
-        break;
-    case SPICE_BITMAP_FMT_32BIT:
-        jpeg_in_type = JPEG_IMAGE_TYPE_BGRX32;
-        break;
-    case SPICE_BITMAP_FMT_RGBA:
-        jpeg_in_type = JPEG_IMAGE_TYPE_BGRX32;
-        has_alpha = TRUE;
-        break;
-    default:
-        return FALSE;
-    }
-
-    encoder_data_init(&jpeg_data->data);
-
-    if (setjmp(jpeg_data->data.jmp_env)) {
-        encoder_data_reset(&jpeg_data->data);
-        return FALSE;
-    }
-
-    if (src->data->flags & SPICE_CHUNKS_FLAGS_UNSTABLE) {
-        spice_chunks_linearize(src->data);
-    }
-
-    jpeg_data->data.u.lines_data.chunks = src->data;
-    jpeg_data->data.u.lines_data.stride = src->stride;
-    if ((src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN)) {
-        jpeg_data->data.u.lines_data.next = 0;
-        jpeg_data->data.u.lines_data.reverse = 0;
-        stride = src->stride;
-    } else {
-        jpeg_data->data.u.lines_data.next = src->data->num_chunks - 1;
-        jpeg_data->data.u.lines_data.reverse = 1;
-        stride = -src->stride;
-    }
-    jpeg_size = jpeg_encode(jpeg, enc->jpeg_quality, jpeg_in_type,
-                            src->x, src->y, NULL,
-                            0, stride, jpeg_data->data.bufs_head->buf.bytes,
-                            sizeof(jpeg_data->data.bufs_head->buf));
-
-    // the compressed buffer is bigger than the original data
-    if (jpeg_size > (src->y * src->stride)) {
-        longjmp(jpeg_data->data.jmp_env, 1);
-    }
-
-    if (!has_alpha) {
-        dest->descriptor.type = SPICE_IMAGE_TYPE_JPEG;
-        dest->u.jpeg.data_size = jpeg_size;
-
-        o_comp_data->comp_buf = jpeg_data->data.bufs_head;
-        o_comp_data->comp_buf_size = jpeg_size;
-        o_comp_data->is_lossy = TRUE;
-
-        stat_compress_add(jpeg_stats, start_time, src->stride * src->y,
-                          o_comp_data->comp_buf_size);
-        return TRUE;
-    }
-
-    lz_data->data.bufs_head = jpeg_data->data.bufs_tail;
-    lz_data->data.bufs_tail = lz_data->data.bufs_head;
-
-    comp_head_filled = jpeg_size % sizeof(lz_data->data.bufs_head->buf);
-    comp_head_left = sizeof(lz_data->data.bufs_head->buf) - comp_head_filled;
-    lz_out_start_byte = lz_data->data.bufs_head->buf.bytes + comp_head_filled;
-
-    lz_data->data.u.lines_data.chunks = src->data;
-    lz_data->data.u.lines_data.stride = src->stride;
-    lz_data->data.u.lines_data.next = 0;
-    lz_data->data.u.lines_data.reverse = 0;
-
-    alpha_lz_size = lz_encode(lz, LZ_IMAGE_TYPE_XXXA, src->x, src->y,
-                               !!(src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN),
-                               NULL, 0, src->stride,
-                               lz_out_start_byte,
-                               comp_head_left);
-
-    // the compressed buffer is bigger than the original data
-    if ((jpeg_size + alpha_lz_size) > (src->y * src->stride)) {
-        longjmp(jpeg_data->data.jmp_env, 1);
-    }
-
-    dest->descriptor.type = SPICE_IMAGE_TYPE_JPEG_ALPHA;
-    dest->u.jpeg_alpha.flags = 0;
-    if (src->flags & SPICE_BITMAP_FLAGS_TOP_DOWN) {
-        dest->u.jpeg_alpha.flags |= SPICE_JPEG_ALPHA_FLAGS_TOP_DOWN;
-    }
-
-    dest->u.jpeg_alpha.jpeg_size = jpeg_size;
-    dest->u.jpeg_alpha.data_size = jpeg_size + alpha_lz_size;
-
-    o_comp_data->comp_buf = jpeg_data->data.bufs_head;
-    o_comp_data->comp_buf_size = jpeg_size + alpha_lz_size;
-    o_comp_data->is_lossy = TRUE;
-    stat_compress_add(jpeg_alpha_stats, start_time, src->stride * src->y,
-                      o_comp_data->comp_buf_size);
-    return TRUE;
-}
-
 #ifdef USE_LZ4
 static int dcc_compress_image_lz4(DisplayChannelClient *dcc, SpiceImage *dest,
                                   SpiceBitmap *src, compress_send_data_t* o_comp_data)
commit 9d92a2edc83cf5670a7cf6af298e43156bccfcd6
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Jun 9 12:00:44 2016 +0100

    Prepare to move dcc_compress_image_jpeg 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 b5fbb09..ca6f5b5 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -784,13 +784,15 @@ glz:
     return TRUE;
 }
 
-static int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
-                                   SpiceBitmap *src, compress_send_data_t* o_comp_data)
+static int image_encoders_compress_jpeg(ImageEncoders *enc, SpiceImage *dest,
+                                        SpiceBitmap *src, compress_send_data_t* o_comp_data,
+                                        stat_info_t *jpeg_stats, // FIXME put all stats in a structure
+                                        stat_info_t *jpeg_alpha_stats)
 {
-    JpegData *jpeg_data = &dcc->encoders.jpeg_data;
-    LzData *lz_data = &dcc->encoders.lz_data;
-    JpegEncoderContext *jpeg = dcc->encoders.jpeg;
-    LzContext *lz = dcc->encoders.lz;
+    JpegData *jpeg_data = &enc->jpeg_data;
+    LzData *lz_data = &enc->lz_data;
+    JpegEncoderContext *jpeg = enc->jpeg;
+    LzContext *lz = enc->lz;
     volatile JpegEncoderImageType jpeg_in_type;
     int jpeg_size = 0;
     volatile int has_alpha = FALSE;
@@ -800,7 +802,7 @@ static int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
     int stride;
     uint8_t *lz_out_start_byte;
     stat_start_time_t start_time;
-    stat_start_time_init(&start_time, &DCC_TO_DC(dcc)->jpeg_alpha_stat);
+    stat_start_time_init(&start_time, jpeg_alpha_stats);
 
 #ifdef COMPRESS_DEBUG
     spice_info("JPEG compress");
@@ -846,7 +848,7 @@ static int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
         jpeg_data->data.u.lines_data.reverse = 1;
         stride = -src->stride;
     }
-    jpeg_size = jpeg_encode(jpeg, dcc->encoders.jpeg_quality, jpeg_in_type,
+    jpeg_size = jpeg_encode(jpeg, enc->jpeg_quality, jpeg_in_type,
                             src->x, src->y, NULL,
                             0, stride, jpeg_data->data.bufs_head->buf.bytes,
                             sizeof(jpeg_data->data.bufs_head->buf));
@@ -864,7 +866,7 @@ static int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
         o_comp_data->comp_buf_size = jpeg_size;
         o_comp_data->is_lossy = TRUE;
 
-        stat_compress_add(&DCC_TO_DC(dcc)->jpeg_stat, start_time, src->stride * src->y,
+        stat_compress_add(jpeg_stats, start_time, src->stride * src->y,
                           o_comp_data->comp_buf_size);
         return TRUE;
     }
@@ -904,7 +906,7 @@ static int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
     o_comp_data->comp_buf = jpeg_data->data.bufs_head;
     o_comp_data->comp_buf_size = jpeg_size + alpha_lz_size;
     o_comp_data->is_lossy = TRUE;
-    stat_compress_add(&DCC_TO_DC(dcc)->jpeg_alpha_stat, start_time, src->stride * src->y,
+    stat_compress_add(jpeg_alpha_stats, start_time, src->stride * src->y,
                       o_comp_data->comp_buf_size);
     return TRUE;
 }
@@ -1063,7 +1065,9 @@ int dcc_compress_image(DisplayChannelClient *dcc,
     case SPICE_IMAGE_COMPRESSION_QUIC:
         if (can_lossy && display_channel->enable_jpeg &&
             (src->format != SPICE_BITMAP_FMT_RGBA || !bitmap_has_extra_stride(src))) {
-            success = dcc_compress_image_jpeg(dcc, dest, src, o_comp_data);
+            success = image_encoders_compress_jpeg(&dcc->encoders, dest, src, o_comp_data,
+                                                   &display_channel->jpeg_stat,
+                                                   &display_channel->jpeg_alpha_stat);
             break;
         }
         success = image_encoders_compress_quic(&dcc->encoders, dest, src, o_comp_data,
commit 7b6cb37cc081340f8e39da19ea3334cb6f01d092
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Thu Jun 9 12:00:15 2016 +0100

    Encapsulate jpeg 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 e795065..279c134 100644
--- a/server/dcc-encoders.c
+++ b/server/dcc-encoders.c
@@ -360,14 +360,14 @@ static void dcc_init_glz_data(DisplayChannelClient *dcc)
     dcc->glz_data.usr.free_image = glz_usr_free_image;
 }
 
-static void dcc_init_jpeg(DisplayChannelClient *dcc)
+static void image_encoders_init_jpeg(ImageEncoders *enc)
 {
-    dcc->jpeg_data.usr.more_space = jpeg_usr_more_space;
-    dcc->jpeg_data.usr.more_lines = jpeg_usr_more_lines;
+    enc->jpeg_data.usr.more_space = jpeg_usr_more_space;
+    enc->jpeg_data.usr.more_lines = jpeg_usr_more_lines;
 
-    dcc->jpeg = jpeg_encoder_create(&dcc->jpeg_data.usr);
+    enc->jpeg = jpeg_encoder_create(&enc->jpeg_data.usr);
 
-    if (!dcc->jpeg) {
+    if (!enc->jpeg) {
         spice_critical("create jpeg encoder failed");
     }
 }
@@ -405,7 +405,7 @@ void dcc_encoders_init(DisplayChannelClient *dcc)
     dcc_init_glz_data(dcc);
     image_encoders_init_quic(enc);
     image_encoders_init_lz(enc);
-    dcc_init_jpeg(dcc);
+    image_encoders_init_jpeg(enc);
 #ifdef USE_LZ4
     dcc_init_lz4(dcc);
 #endif
@@ -422,8 +422,8 @@ void dcc_encoders_free(DisplayChannelClient *dcc)
     enc->quic = NULL;
     lz_destroy(enc->lz);
     enc->lz = NULL;
-    jpeg_encoder_destroy(dcc->jpeg);
-    dcc->jpeg = NULL;
+    jpeg_encoder_destroy(enc->jpeg);
+    enc->jpeg = NULL;
 #ifdef USE_LZ4
     lz4_encoder_destroy(dcc->lz4);
     dcc->lz4 = NULL;
diff --git a/server/dcc-encoders.h b/server/dcc-encoders.h
index e4e2726..0d0eee2 100644
--- a/server/dcc-encoders.h
+++ b/server/dcc-encoders.h
@@ -167,6 +167,11 @@ struct ImageEncoders {
 
     LzData lz_data;
     LzContext  *lz;
+
+    int jpeg_quality;
+
+    JpegData jpeg_data;
+    JpegEncoderContext *jpeg;
 };
 
 typedef struct compress_send_data_t {
diff --git a/server/dcc.c b/server/dcc.c
index 2d715d9..b5fbb09 100644
--- a/server/dcc.c
+++ b/server/dcc.c
@@ -379,7 +379,7 @@ DisplayChannelClient *dcc_new(DisplayChannel *display,
     dcc->jpeg_state = jpeg_state;
     dcc->zlib_glz_state = zlib_glz_state;
     // TODO: tune quality according to bandwidth
-    dcc->jpeg_quality = 85;
+    dcc->encoders.jpeg_quality = 85;
 
     size_t stream_buf_size;
     stream_buf_size = 32*1024;
@@ -787,9 +787,9 @@ glz:
 static int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
                                    SpiceBitmap *src, compress_send_data_t* o_comp_data)
 {
-    JpegData *jpeg_data = &dcc->jpeg_data;
+    JpegData *jpeg_data = &dcc->encoders.jpeg_data;
     LzData *lz_data = &dcc->encoders.lz_data;
-    JpegEncoderContext *jpeg = dcc->jpeg;
+    JpegEncoderContext *jpeg = dcc->encoders.jpeg;
     LzContext *lz = dcc->encoders.lz;
     volatile JpegEncoderImageType jpeg_in_type;
     int jpeg_size = 0;
@@ -846,7 +846,7 @@ static int dcc_compress_image_jpeg(DisplayChannelClient *dcc, SpiceImage *dest,
         jpeg_data->data.u.lines_data.reverse = 1;
         stride = -src->stride;
     }
-    jpeg_size = jpeg_encode(jpeg, dcc->jpeg_quality, jpeg_in_type,
+    jpeg_size = jpeg_encode(jpeg, dcc->encoders.jpeg_quality, jpeg_in_type,
                             src->x, src->y, NULL,
                             0, stride, jpeg_data->data.bufs_head->buf.bytes,
                             sizeof(jpeg_data->data.bufs_head->buf));
diff --git a/server/dcc.h b/server/dcc.h
index d10ba87..034b9b1 100644
--- a/server/dcc.h
+++ b/server/dcc.h
@@ -60,14 +60,11 @@ struct DisplayChannelClient {
     SpiceImageCompression image_compression;
     spice_wan_compression_t jpeg_state;
     spice_wan_compression_t zlib_glz_state;
-    int jpeg_quality;
 
     ImageEncoders encoders;
 
     int zlib_level;
 
-    JpegData jpeg_data;
-    JpegEncoderContext *jpeg;
 #ifdef USE_LZ4
     Lz4Data lz4_data;
     Lz4EncoderContext *lz4;


More information about the Spice-commits mailing list