Skip to content

Commit

Permalink
nogil: after manual review, it *seems* to be ok
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@3572 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jun 4, 2013
1 parent e6dd7ef commit d6091f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
6 changes: 4 additions & 2 deletions src/xpra/codecs/csc_swscale/colorspace_converter.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cdef extern from "csc_swscale.h":
csc_swscale_ctx *init_csc(int src_width, int src_height, const char *src_format,
int dst_width, int dst_height, const char *dst_format, int speed)
void free_csc(csc_swscale_ctx *ctx)
int csc_image(csc_swscale_ctx *ctx, const uint8_t *input_image[3], const int in_stride[3], uint8_t *out[3], int out_stride[3])
int csc_image(csc_swscale_ctx *ctx, const uint8_t *input_image[3], const int in_stride[3], uint8_t *out[3], int out_stride[3]) nogil
void free_csc_image(uint8_t *buf[3])


Expand Down Expand Up @@ -183,6 +183,7 @@ cdef class ColorspaceConverter:
cdef int i #@DuplicatedSignature
cdef int height
cdef int stride
cdef int result
planes = image.get_planes()
assert planes in (0, 1, 3), "invalid number of planes: %s" % planes
input = image.get_pixels()
Expand All @@ -198,7 +199,8 @@ cdef class ColorspaceConverter:
for i in range(planes):
input_stride[i] = strides[i]
PyObject_AsReadBuffer(input[i], <const_void_pp> &input_image[i], &pic_buf_len)
result = csc_image(self.context, input_image, input_stride, output_image, output_stride)
with nogil:
result = csc_image(self.context, input_image, input_stride, output_image, output_stride)
if result != 0:
return None
#now parse the output:
Expand Down
5 changes: 3 additions & 2 deletions src/xpra/codecs/dec_avcodec/decoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cdef extern from "dec_avcodec.h":
dec_avcodec_ctx *init_decoder(int width, int height, const char *colorspace)
void set_decoder_csc_format(dec_avcodec_ctx *ctx, int csc_fmt)
void clean_decoder(dec_avcodec_ctx *)
int decompress_image(dec_avcodec_ctx *ctx, const uint8_t *input_image, int size, uint8_t *out[3], int outstride[3])
int decompress_image(dec_avcodec_ctx *ctx, const uint8_t *input_image, int size, uint8_t *out[3], int outstride[3]) nogil
const char *get_colorspace(dec_avcodec_ctx *)
const char *get_actual_colorspace(dec_avcodec_ctx *)

Expand Down Expand Up @@ -121,7 +121,8 @@ cdef class Decoder:
self.last_image.clone_pixel_data()
self.last_image = None
PyObject_AsReadBuffer(input, <const_void_pp> &buf, &buf_len)
i = decompress_image(self.context, buf, buf_len, dout, outstrides)
with nogil:
i = decompress_image(self.context, buf, buf_len, dout, outstrides)
if i!=0:
return None
out = []
Expand Down
22 changes: 10 additions & 12 deletions src/xpra/codecs/enc_x264/encoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ cdef extern from "enc_x264.h":
const char *colorspace, const char *profile,
int initial_quality, int initial_speed)
void clean_encoder(enc_x264_ctx *)
int compress_image(enc_x264_ctx *ctx, uint8_t *input[3], int in_stride[3], uint8_t **out, int *outsz)
int compress_image(enc_x264_ctx *ctx, uint8_t *input[3], int in_stride[3], uint8_t **out, int *outsz) nogil
int get_encoder_quality(enc_x264_ctx *ctx)
int get_encoder_speed(enc_x264_ctx *ctx)

Expand Down Expand Up @@ -151,6 +151,8 @@ cdef class Encoder:
cdef int strides[3]
cdef uint8_t *pic_buf
cdef Py_ssize_t pic_buf_len = 0
cdef uint8_t *cout
cdef int coutsz
cdef int quality_override = options.get("quality", -1)
cdef int speed_override = options.get("speed", -1)
cdef int saved_quality = get_encoder_quality(self.context)
Expand Down Expand Up @@ -179,23 +181,19 @@ cdef class Encoder:
strides[i] = istrides[i]
print("compress_image strides=%s, planes=%s" % ([x for x in strides], [len(x or "") for x in pic_in]))
try:
return self.do_compress_image(pic_in, strides), self.get_client_options(options)
with nogil:
i = compress_image(self.context, pic_in, strides, &cout, &coutsz)
if i!=0:
return None, {}
coutv = (<char *>cout)[:coutsz]
self.frames += 1
return coutv, self.get_client_options(options)
finally:
if speed_override>=0 and saved_speed!=speed_override:
set_encoding_speed(self.context, saved_speed)
if quality_override>=0 and saved_quality!=quality_override:
set_encoding_quality(self.context, saved_quality)

cdef do_compress_image(self, uint8_t *pic_in[], int strides[]):
cdef int i #@DuplicatedSignature
cdef uint8_t *cout
cdef int coutsz
i = compress_image(self.context, pic_in, strides, &cout, &coutsz)
if i!=0:
return None
coutv = (<char *>cout)[:coutsz]
self.frames += 1
return coutv

def set_encoding_speed(self, int pct):
assert pct>=0 and pct<=100, "invalid percentage: %s" % pct
Expand Down

0 comments on commit d6091f7

Please sign in to comment.