From 758583cb2c6cb3f64a119742e9965a736291e56b Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sat, 16 Mar 2013 06:44:42 +0000 Subject: [PATCH] remove rgbimage wrapper: since we copy from the swscale buffer to a python string anyway, do it early to prevent races between the decoding thread and the paint thread: previously we could end up copying from the swscaled buffer too late: after a new frame is decoded (and the buffer may have been freed, size changed, etc - I couldn't make it misbehave, but the design was broken) git-svn-id: https://xpra.org/svn/Xpra/trunk@2991 3bb7dfac-3a0b-4e04-842a-767bc560f471 --- src/xpra/vpx/codec.pyx | 31 +------------------------------ src/xpra/window_backing.py | 6 +++--- src/xpra/x264/codec.pyx | 31 +------------------------------ 3 files changed, 5 insertions(+), 63 deletions(-) diff --git a/src/xpra/vpx/codec.pyx b/src/xpra/vpx/codec.pyx index 33a7df2233..2f7807e820 100644 --- a/src/xpra/vpx/codec.pyx +++ b/src/xpra/vpx/codec.pyx @@ -54,33 +54,6 @@ cdef class xcoder: def get_height(self): return self.height -cdef class RGBImage: - cdef uint8_t *data - cdef int size - cdef int rowstride - - cdef init(self, uint8_t *data, int size, int rowstride): - self.data = data - self.size = size - self.rowstride = rowstride - - cdef free(self): - assert self.data!=NULL - xmemfree(self.data) - self.data = NULL - - def get_data(self): - return (self.data)[:self.size] - - def get_size(self): - return self.size - - def get_rowstride(self): - return self.rowstride - - def __dealloc__(self): #@DuplicatedSignature - self.free() - cdef class Decoder(xcoder): @@ -136,9 +109,7 @@ cdef class Decoder(xcoder): i = csc_image_yuv2rgb(self.context, yuvplanes, yuvstrides, &dout, &outsize, &outstride) if i!=0: return i, None - rgb_image = RGBImage() - rgb_image.init(dout, outsize, outstride) - return i, rgb_image + return i, (dout)[:outsize], outstride cdef class Encoder(xcoder): diff --git a/src/xpra/window_backing.py b/src/xpra/window_backing.py index 9edc581938..3bad7f2692 100644 --- a/src/xpra/window_backing.py +++ b/src/xpra/window_backing.py @@ -164,13 +164,13 @@ def paint_with_video_decoder(self, factory, coding, img_data, x, y, width, heigh def do_video_paint(self, coding, img_data, x, y, width, height, options, callbacks): if DRAW_DEBUG: log.info("paint_with_video_decoder: options=%s, decoder=%s", options, type(self._video_decoder)) - err, rgb_image = self._video_decoder.decompress_image_to_rgb(img_data, options) - success = err==0 and rgb_image and rgb_image.get_size()>0 + err, data, rowstride = self._video_decoder.decompress_image_to_rgb(img_data, options) + success = err==0 and data is not None and rowstride>0 if not success: raise Exception("paint_with_video_decoder: %s decompression error %s on %s bytes of picture data for %sx%s pixels, options=%s" % ( coding, err, len(img_data), width, height, options)) #this will also take care of firing callbacks (from the UI thread): - gobject.idle_add(self.do_paint_rgb24, rgb_image.get_data(), x, y, width, height, rgb_image.get_rowstride(), options, callbacks) + gobject.idle_add(self.do_paint_rgb24, data, x, y, width, height, rowstride, options, callbacks) def cairo_draw(self, context): diff --git a/src/xpra/x264/codec.pyx b/src/xpra/x264/codec.pyx index 88e5ca4f85..b8e587e08f 100644 --- a/src/xpra/x264/codec.pyx +++ b/src/xpra/x264/codec.pyx @@ -88,33 +88,6 @@ cdef class xcoder: def get_type(self): return "x264" -cdef class RGBImage: - cdef uint8_t *data - cdef int size - cdef int rowstride - - cdef init(self, uint8_t *data, int size, int rowstride): - self.data = data - self.size = size - self.rowstride = rowstride - - cdef free(self): - assert self.data!=NULL - xmemfree(self.data) - self.data = NULL - - def get_data(self): - return (self.data)[:self.size] - - def get_size(self): - return self.size - - def get_rowstride(self): - return self.rowstride - - def __dealloc__(self): #@DuplicatedSignature - self.free() - cdef class Decoder(xcoder): @@ -183,9 +156,7 @@ cdef class Decoder(xcoder): xmemfree(padded_buf) if i!=0: return i, None - rgb_image = RGBImage() - rgb_image.init(dout, outsize, outstride) - return i, rgb_image + return i, (dout)[:outsize], outstride cdef class Encoder(xcoder):