[Spice-devel] [PATCH] mjpeg_encoder: allocate "row" on demand

Christophe Fergeau cfergeau at redhat.com
Wed Jul 6 03:32:53 PDT 2011


It's not used when we use jpeg-turbo colorspaces, so it's better
to allocate it when we know we'll need it rather than always
allocating it even if it won't be used.
---
 server/mjpeg_encoder.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/server/mjpeg_encoder.c b/server/mjpeg_encoder.c
index 8b323ed..7351dae 100644
--- a/server/mjpeg_encoder.c
+++ b/server/mjpeg_encoder.c
@@ -27,7 +27,6 @@
 struct MJpegEncoder {
     int width;
     int height;
-    int stride;
     uint8_t *row;
     int first_frame;
     int quality;
@@ -48,15 +47,8 @@ MJpegEncoder *mjpeg_encoder_new(int width, int height)
     enc->first_frame = TRUE;
     enc->width = width;
     enc->height = height;
-    enc->stride = width * 3;
     enc->quality = 70;
-    if (enc->stride < width) {
-        abort();
-    }
-    enc->row = spice_malloc(enc->stride);
-
     enc->cinfo.err = jpeg_std_error(&enc->jerr);
-
     jpeg_create_compress(&enc->cinfo);
 
     return enc;
@@ -240,6 +232,14 @@ int mjpeg_encoder_start_frame(MJpegEncoder *encoder, SpiceBitmapFmt format,
         return FALSE;
     }
 
+    if ((encoder->pixel_converter != NULL) && (encoder->row == NULL)) {
+        unsigned int stride = encoder->width * 3;
+        if (stride < encoder->width) {
+            return FALSE;
+        }
+        encoder->row = spice_malloc(stride);
+    }
+
     jpeg_mem_dest(&encoder->cinfo, dest, dest_len);
 
     encoder->cinfo.image_width      = encoder->width;
-- 
1.7.6



More information about the Spice-devel mailing list