[Spice-devel,v6,22/26] spice-gtk: Optimize handling of the decoded frame buffer

Submitted by Francois Gouget on Oct. 14, 2015, 3:34 p.m.

Details

Message ID alpine.DEB.2.20.1510141614130.17509@amboise
State New
Headers show

Not browsing as part of any series.

Commit Message

Francois Gouget Oct. 14, 2015, 3:34 p.m.
Also modify the MJPEG video decoder to use Spice's allocator instead of
explicitly depending on the glib one.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
---
 src/channel-display-mjpeg.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/channel-display-mjpeg.c b/src/channel-display-mjpeg.c
index 78e3d5a..c31b436 100644
--- a/src/channel-display-mjpeg.c
+++ b/src/channel-display-mjpeg.c
@@ -39,6 +39,7 @@  typedef struct MJpegDecoder {
     /* ---------- Output frame data ---------- */
 
     uint8_t *out_frame;
+    uint32_t out_size;
 } MJpegDecoder;
 
 
@@ -85,8 +86,12 @@  static uint8_t* mjpeg_decoder_decode_frame(VideoDecoder *video_decoder,
 
     decoder->frame_msg = frame_msg;
     stream_get_dimensions(decoder->base.stream, frame_msg, &width, &height);
-    g_free(decoder->out_frame);
-    dest = decoder->out_frame = g_malloc0(width * height * 4);
+    if (decoder->out_size < width * height * 4) {
+        free(decoder->out_frame);
+        decoder->out_size = width * height * 4;
+        decoder->out_frame = spice_malloc(decoder->out_size);
+    }
+    dest = decoder->out_frame;
 
     jpeg_read_header(&decoder->mjpeg_cinfo, 1);
 #ifdef JCS_EXTENSIONS
@@ -163,7 +168,7 @@  static void mjpeg_decoder_destroy(VideoDecoder* video_decoder)
 {
     MJpegDecoder *decoder = (MJpegDecoder*)video_decoder;
     jpeg_destroy_decompress(&decoder->mjpeg_cinfo);
-    g_free(decoder->out_frame);
+    free(decoder->out_frame);
     free(decoder);
 }