xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #159: xpra-264-server-memalign.patch

File xpra-264-server-memalign.patch, 2.0 KB (added by Antoine Martin, 9 years ago)

memcopy the pixel data so it is memaligned before we do the colourspace conversion

  • src/xpra/x264/codec.pyx

    ### Eclipse Workspace Patch 1.0
    #P Xpra
     
    2626cdef extern from "x264lib.h":
    2727    x264lib_ctx* init_encoder(int width, int height)
    2828    void clean_encoder(x264lib_ctx *context)
    29     x264_picture_t* csc_image_rgb2yuv(x264lib_ctx *ctx, uint8_t *input, int stride)
     29    x264_picture_t* csc_image_rgb2yuv(x264lib_ctx *ctx, uint8_t *input, int stride) nogil
    3030    int compress_image(x264lib_ctx *ctx, x264_picture_t *pic_in, uint8_t **out, int *outsz) nogil
    3131
    3232    x264lib_ctx* init_decoder(int width, int height)
     
    143143    def compress_image(self, input, rowstride):
    144144        cdef x264_picture_t *pic_in = NULL
    145145        cdef uint8_t *cout
    146         cdef int coutsz
     146        cdef int coutsz, stride
     147        cdef uint8_t *padded_buf = NULL
    147148        cdef uint8_t *buf = NULL
    148149        cdef Py_ssize_t buf_len = 0
    149150        assert self.context!=NULL
    150151        #colourspace conversion with gil held:
    151152        PyObject_AsReadBuffer(input, <const_void_pp> &buf, &buf_len)
    152         pic_in = csc_image_rgb2yuv(self.context, buf, rowstride)
    153         assert pic_in!=NULL, "colourspace conversion failed"
    154         #actual compression (no gil):
    155         with nogil:
    156             i = compress_image(self.context, pic_in, &cout, &coutsz)
     153        i = posix_memalign(<void **> &padded_buf, 32, buf_len+32)
    157154        if i!=0:
    158155            return i, 0, ""
     156        memcpy(padded_buf, buf, buf_len)
     157        memset(padded_buf+buf_len, 0, 32)
     158        stride = rowstride
     159        with nogil:
     160            pic_in = csc_image_rgb2yuv(self.context, padded_buf, stride)
     161            if i==0 and pic_in!=NULL:
     162                #actual compression (no gil):
     163                i = compress_image(self.context, pic_in, &cout, &coutsz)
     164            free(padded_buf)
     165        if i==0 or pic_in==NULL:
     166            return i, 0, ""
    159167        coutv = (<char *>cout)[:coutsz]
    160168        return  i, coutsz, coutv
    161169