xpra icon
Bug tracker and wiki

Ticket #146: xpra-decompress-padded-nogil.patch

File xpra-decompress-padded-nogil.patch, 2.2 KB (added by Antoine Martin, 8 years ago)

copy the input buffer and pad it with zeroes, allows us to drop the gil

  • src/xpra/x264/codec.pyx

     
    77
    88from libc.stdlib cimport free
    99
     10cdef extern from "string.h":
     11    void * memcpy ( void * destination, void * source, size_t num )
     12    void * memset ( void * ptr, int value, size_t num )
     13
     14cdef extern from "stdlib.h":
     15    void *malloc(size_t size)
     16
    1017cdef extern from "Python.h":
    1118    ctypedef int Py_ssize_t
    1219    ctypedef object PyObject
     
    2431
    2532    x264lib_ctx* init_decoder(int width, int height)
    2633    void clean_decoder(x264lib_ctx *context)
    27     int decompress_image(x264lib_ctx *context, uint8_t *input, int size, uint8_t *(*out)[3], int *outsize, int (*outstride)[3])
     34    int decompress_image(x264lib_ctx *context, uint8_t *input, int size, uint8_t *(*out)[3], int *outsize, int (*outstride)[3]) nogil
    2835    int csc_image_yuv2rgb(x264lib_ctx *ctx, uint8_t *input[3], int stride[3], uint8_t **out, int *outsz, int *outstride) nogil
    2936    void change_encoding_speed(x264lib_ctx *context, int increase)
    3037
     
    94101        cdef int outsize
    95102        cdef int yuvstrides[3]
    96103        cdef int outstride
     104        cdef unsigned char * padded_buf = <uint8_t *> 0
    97105        cdef unsigned char * buf = <uint8_t *> 0
    98106        cdef Py_ssize_t buf_len = 0
    99107        assert self.context!=NULL
    100108        assert self.last_image==NULL
    101109        PyObject_AsReadBuffer(input, <const_void_pp> &buf, &buf_len)
    102         i = decompress_image(self.context, buf, buf_len, &yuvplanes, &outsize, &yuvstrides)
    103         if i!=0:
    104             return i, 0, ""
     110        padded_buf = <unsigned char *> malloc(buf_len+32)
     111        memcpy(padded_buf, buf, buf_len)
     112        memset(padded_buf+buf_len, 0, 32)
    105113        with nogil:
    106             i = csc_image_yuv2rgb(self.context, yuvplanes, yuvstrides, &dout, &outsize, &outstride)
     114            i = decompress_image(self.context, padded_buf, buf_len, &yuvplanes, &outsize, &yuvstrides)
     115            if i==0:
     116                i = csc_image_yuv2rgb(self.context, yuvplanes, yuvstrides, &dout, &outsize, &outstride)
     117            free(padded_buf)
    107118        if i!=0:
    108119            return i, 0, ""
    109120        self.last_image = dout