[Spice-devel] [PATCH 09/30] Encapsulate jpeg information in EncodersData structure

Jonathon Jongsma jjongsma at redhat.com
Wed Jun 8 20:54:42 UTC 2016


On Tue, 2016-06-07 at 11:17 +0100, Frediano Ziglio wrote:
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  server/dcc-encoders.c | 16 ++++++++--------
>  server/dcc-encoders.h |  5 +++++
>  server/dcc.c          | 28 ++++++++++++++++------------
>  server/dcc.h          |  3 ---
>  4 files changed, 29 insertions(+), 23 deletions(-)
> 
> diff --git a/server/dcc-encoders.c b/server/dcc-encoders.c
> index 015f677..7d74ca3 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 dcc_init_jpeg(EncodersData *enc)

function names again (dcc_ vs encoders_data_)

>  {
> -    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);
>      dcc_init_quic(enc);
>      dcc_init_lz(enc);
> -    dcc_init_jpeg(dcc);
> +    dcc_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 f008bf6..9978a9c 100644
> --- a/server/dcc-encoders.h
> +++ b/server/dcc-encoders.h
> @@ -168,6 +168,11 @@ struct EncodersData {
>  
>      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 7bdb2bd..89035be 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;
> @@ -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 dcc_compress_image_jpeg(EncodersData *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)

Stats change to separate commit? Also change function name to encoders_data_

>  {
> -    JpegData *jpeg_data = &dcc->jpeg_data;
> -    LzData *lz_data = &dcc->encoders.lz_data;
> -    JpegEncoderContext *jpeg = dcc->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->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 = dcc_compress_image_jpeg(&dcc->encoders, dest, src,
> o_comp_data,
> +                                              &display_channel->jpeg_stat,
> +                                              &display_channel-
> >jpeg_alpha_stat);
>              break;
>          }
>          success = dcc_compress_image_quic(&dcc->encoders, dest, src,
> o_comp_data, &display_channel->quic_stat);
> diff --git a/server/dcc.h b/server/dcc.h
> index 532ce7b..b200d50 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;
>  
>      EncodersData encoders;
>  
>      int zlib_level;
>  
> -    JpegData jpeg_data;
> -    JpegEncoderContext *jpeg;
>  #ifdef USE_LZ4
>      Lz4Data lz4_data;
>      Lz4EncoderContext *lz4;


Reviewed-by: Jonathon Jongsma <jjongsma at redhat.com>


More information about the Spice-devel mailing list