Skip to content

Commit

Permalink
whitespace, formatting
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@21771 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 21, 2019
1 parent 658f615 commit c7b0f33
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 95 deletions.
12 changes: 8 additions & 4 deletions src/xpra/codecs/jpeg/decoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def decompress_to_yuv(data, int width, int height, options={}):
assert w==width and h==height, "invalid picture dimensions: %ix%i, expected %ix%i" % (w, h, width, height)
subsamp_str = "YUV%sP" % TJSAMP_STR.get(subsamp, subsamp)
assert subsamp in (TJSAMP_444, TJSAMP_422, TJSAMP_420), "unsupported JPEG colour subsampling: %s" % subsamp_str
log("jpeg.decompress_to_yuv size: %4ix%-4i, subsampling=%-4s, colorspace=%s", w, h, subsamp_str, TJCS_STR.get(cs, cs))
log("jpeg.decompress_to_yuv size: %4ix%-4i, subsampling=%-4s, colorspace=%s",
w, h, subsamp_str, TJCS_STR.get(cs, cs))
#allocate YUV buffers:
cdef unsigned long plane_sizes[3]
cdef unsigned char *planes[3]
Expand Down Expand Up @@ -189,7 +190,8 @@ def decompress_to_yuv(data, int width, int height, options={}):
close()
if LOG_PERF:
elapsed = monotonic_time()-start
log("decompress jpeg to %s: %4i MB/s (%9i bytes in %2.1fms)", subsamp_str, float(total_size)/elapsed//1024//1024, total_size, 1000*elapsed)
log("decompress jpeg to %s: %4i MB/s (%9i bytes in %2.1fms)",
subsamp_str, float(total_size)/elapsed//1024//1024, total_size, 1000*elapsed)
return ImageWrapper(0, 0, w, h, pyplanes, subsamp_str, 24, pystrides, ImageWrapper._3_PLANES)


Expand Down Expand Up @@ -219,7 +221,8 @@ def decompress_to_rgb(rgb_format, data, int width, int height, options={}):
raise Exception("failed to decompress JPEG header: %s" % get_error_str())
assert w==width and h==height, "invalid picture dimensions: %ix%i, expected %ix%i" % (w, h, width, height)
subsamp_str = TJSAMP_STR.get(subsamp, subsamp)
log("jpeg.decompress_to_rgb: size=%4ix%-4i, subsampling=%3s, colorspace=%s", w, h, subsamp_str, TJCS_STR.get(cs, cs))
log("jpeg.decompress_to_rgb: size=%4ix%-4i, subsampling=%3s, colorspace=%s",
w, h, subsamp_str, TJCS_STR.get(cs, cs))
cdef MemBuf membuf
cdef unsigned char *dst_buf
cdef int stride, flags = 0 #TJFLAG_BOTTOMUP
Expand All @@ -242,7 +245,8 @@ def decompress_to_rgb(rgb_format, data, int width, int height, options={}):
close()
if LOG_PERF:
elapsed = monotonic_time()-start
log("decompress jpeg to %s: %4i MB/s (%9i bytes in %2.1fms)", rgb_format, float(size)/elapsed//1024//1024, size, 1000*elapsed)
log("decompress jpeg to %s: %4i MB/s (%9i bytes in %2.1fms)",
rgb_format, float(size)/elapsed//1024//1024, size, 1000*elapsed)
return ImageWrapper(0, 0, w, h, memoryview(membuf), rgb_format, 24, stride, ImageWrapper.PACKED)


Expand Down
20 changes: 12 additions & 8 deletions src/xpra/codecs/nvenc/encoder.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ import os
import sys
import numpy
from collections import deque, OrderedDict
import ctypes
from ctypes import cdll as loader, POINTER

from pycuda import driver

from xpra.os_util import WIN32, OSX, LINUX, PYTHON3, bytestostr, strtobytes
from xpra.util import AtomicInteger, engs, csv, pver, envint, envbool, first_time
from xpra.codecs.cuda_common.cuda_context import init_all_devices, get_devices, select_device, get_device_info, get_device_name, \
get_cuda_info, get_pycuda_info, device_info, reset_state, \
get_CUDA_function, record_device_failure, record_device_success, CUDA_ERRORS_INFO
from xpra.codecs.cuda_common.cuda_context import (
init_all_devices, get_devices, select_device, get_device_info, get_device_name,
get_cuda_info, get_pycuda_info, device_info, reset_state,
get_CUDA_function, record_device_failure, record_device_success, CUDA_ERRORS_INFO,
)
from xpra.codecs.codec_constants import video_spec, TransientCodecException
from xpra.codecs.image_wrapper import ImageWrapper
from xpra.codecs.nv_util import get_nvidia_module_version, get_license_keys, validate_driver_yuv444lossless, get_cards

from xpra.codecs.nv_util import (
get_nvidia_module_version, get_license_keys,
validate_driver_yuv444lossless, get_cards,
)
from xpra.log import Logger
log = Logger("encoder", "nvenc")

import ctypes
from ctypes import cdll as loader, POINTER
log = Logger("encoder", "nvenc")

from libc.stdint cimport uintptr_t, uint8_t, uint16_t, uint32_t, int32_t, uint64_t
from libc.stdlib cimport free, malloc
Expand Down
3 changes: 2 additions & 1 deletion src/xpra/codecs/nvfbc/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def main():
rgb_format = image.get_pixel_format()
try:
img = Image.frombuffer("RGB", (w, h), pixels, "raw", rgb_format, stride, 1)
filename = os.path.join(os.path.expanduser(get_download_dir()), "screenshot-%s-%i.png" % (rgb_format, time.time()))
filename = os.path.join(os.path.expanduser(get_download_dir()),
"screenshot-%s-%i.png" % (rgb_format, time.time()))
img.save(filename, "png")
log.info("screenshot saved to %s", filename)
return 0
Expand Down
4 changes: 3 additions & 1 deletion src/xpra/codecs/nvfbc/cuda_image_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def may_download(self):
self.wait_for_stream()
self.pixels = host_buffer.tobytes()
elapsed = monotonic_time()-start
log("may_download() from %#x to %s, size=%s, elapsed=%ims - %iMB/s", int(self.cuda_device_buffer), host_buffer, self.buffer_size, int(1000*elapsed), self.buffer_size/elapsed/1024/1024)
log("may_download() from %#x to %s, size=%s, elapsed=%ims - %iMB/s",
int(self.cuda_device_buffer), host_buffer, self.buffer_size,
int(1000*elapsed), self.buffer_size/elapsed/1024/1024)
self.free_cuda()
ctx.pop()

Expand Down
3 changes: 2 additions & 1 deletion src/xpra/codecs/pillow/encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def encode(coding, image, quality, speed, supports_transparency):
rgb = "RGB"
bpp = 24
except Exception:
log.error("PIL_encode%s converting %s pixels from %s to %s failed", (w, h, coding, "%s bytes" % image.get_size(), pixel_format, image.get_rowstride()), type(pixels), pixel_format, rgb, exc_info=True)
log.error("PIL_encode%s converting %s pixels from %s to %s failed",
(w, h, coding, "%s bytes" % image.get_size(), pixel_format, image.get_rowstride()), type(pixels), pixel_format, rgb, exc_info=True)
raise
client_options = {}
if coding in ("jpeg", "webp", "jpeg2000"):
Expand Down
90 changes: 45 additions & 45 deletions src/xpra/codecs/v4l2/pusher.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -127,33 +127,33 @@ V4L2_CAP_STREAMING = 0x04000000
V4L2_CAP_DEVICE_CAPS = 0x80000000

V4L2_CAPS = {
V4L2_CAP_VIDEO_CAPTURE : "VIDEO_CAPTURE",
V4L2_CAP_VIDEO_CAPTURE_MPLANE : "VIDEO_CAPTURE_MPLANE",
V4L2_CAP_VIDEO_OUTPUT : "VIDEO_OUTPUT",
V4L2_CAP_VIDEO_OUTPUT_MPLANE : "VIDEO_OUTPUT_MPLANE",
V4L2_CAP_VIDEO_M2M : "VIDEO_M2M",
V4L2_CAP_VIDEO_M2M_MPLANE : "VIDEO_M2M_MPLANE",
V4L2_CAP_VIDEO_OVERLAY : "VIDEO_OVERLAY",
V4L2_CAP_VBI_CAPTURE : "VBI_CAPTURE",
V4L2_CAP_VBI_OUTPUT : "VBI_OUTPUT",
V4L2_CAP_SLICED_VBI_CAPTURE : "SLICED_VBI_CAPTURE",
V4L2_CAP_SLICED_VBI_OUTPUT : "SLICED_VBI_OUTPUT",
V4L2_CAP_RDS_CAPTURE : "RDS_CAPTURE",
V4L2_CAP_VIDEO_OUTPUT_OVERLAY : "VIDEO_OUTPUT_OVERLAY",
V4L2_CAP_HW_FREQ_SEEK : "HW_FREQ_SEEK",
V4L2_CAP_RDS_OUTPUT : "RDS_OUTPUT",
V4L2_CAP_TUNER : "TUNER",
V4L2_CAP_AUDIO : "AUDIO",
V4L2_CAP_RADIO : "RADIO",
V4L2_CAP_MODULATOR : "MODULATOR",
V4L2_CAP_SDR_CAPTURE : "SDR_CAPTURE",
V4L2_CAP_EXT_PIX_FORMAT : "EXT_PIX_FORMAT",
V4L2_CAP_SDR_OUTPUT : "SDR_OUTPUT",
V4L2_CAP_READWRITE : "READWRITE",
V4L2_CAP_ASYNCIO : "ASYNCIO",
V4L2_CAP_STREAMING : "STREAMING",
V4L2_CAP_DEVICE_CAPS : "DEVICE_CAPS",
}
V4L2_CAP_VIDEO_CAPTURE : "VIDEO_CAPTURE",
V4L2_CAP_VIDEO_CAPTURE_MPLANE : "VIDEO_CAPTURE_MPLANE",
V4L2_CAP_VIDEO_OUTPUT : "VIDEO_OUTPUT",
V4L2_CAP_VIDEO_OUTPUT_MPLANE : "VIDEO_OUTPUT_MPLANE",
V4L2_CAP_VIDEO_M2M : "VIDEO_M2M",
V4L2_CAP_VIDEO_M2M_MPLANE : "VIDEO_M2M_MPLANE",
V4L2_CAP_VIDEO_OVERLAY : "VIDEO_OVERLAY",
V4L2_CAP_VBI_CAPTURE : "VBI_CAPTURE",
V4L2_CAP_VBI_OUTPUT : "VBI_OUTPUT",
V4L2_CAP_SLICED_VBI_CAPTURE : "SLICED_VBI_CAPTURE",
V4L2_CAP_SLICED_VBI_OUTPUT : "SLICED_VBI_OUTPUT",
V4L2_CAP_RDS_CAPTURE : "RDS_CAPTURE",
V4L2_CAP_VIDEO_OUTPUT_OVERLAY : "VIDEO_OUTPUT_OVERLAY",
V4L2_CAP_HW_FREQ_SEEK : "HW_FREQ_SEEK",
V4L2_CAP_RDS_OUTPUT : "RDS_OUTPUT",
V4L2_CAP_TUNER : "TUNER",
V4L2_CAP_AUDIO : "AUDIO",
V4L2_CAP_RADIO : "RADIO",
V4L2_CAP_MODULATOR : "MODULATOR",
V4L2_CAP_SDR_CAPTURE : "SDR_CAPTURE",
V4L2_CAP_EXT_PIX_FORMAT : "EXT_PIX_FORMAT",
V4L2_CAP_SDR_OUTPUT : "SDR_OUTPUT",
V4L2_CAP_READWRITE : "READWRITE",
V4L2_CAP_ASYNCIO : "ASYNCIO",
V4L2_CAP_STREAMING : "STREAMING",
V4L2_CAP_DEVICE_CAPS : "DEVICE_CAPS",
}


FIELD_STR = {
Expand Down Expand Up @@ -204,10 +204,10 @@ for k,v in FORMAT_STR.items():

log("v4l2.pusher init")
print_nested_dict({
"FIELD_STR" : FIELD_STR,
"COLORSPACE_STR" : COLORSPACE_STR,
"FORMAT_STR" : dict((hex(k),v) for k,v in FORMAT_STR.items()),
}, print_fn=log.debug)
"FIELD_STR" : FIELD_STR,
"COLORSPACE_STR" : COLORSPACE_STR,
"FORMAT_STR" : dict((hex(k),v) for k,v in FORMAT_STR.items()),
}, print_fn=log.debug)


def query_video_device(device="/dev/video0"):
Expand All @@ -220,12 +220,12 @@ def query_video_device(device="/dev/video0"):
if r<0:
return {}
info = {
"driver" : vid_caps.driver,
"card" : vid_caps.card,
"bus_info" : vid_caps.bus_info,
"version" : vid_caps.version,
"capabilities" : [v for k,v in V4L2_CAPS.items() if vid_caps.capabilities & k],
}
"driver" : vid_caps.driver,
"card" : vid_caps.card,
"bus_info" : vid_caps.bus_info,
"version" : vid_caps.version,
"capabilities" : [v for k,v in V4L2_CAPS.items() if vid_caps.capabilities & k],
}
IF ENABLE_DEVICE_CAPS:
info["device_caps"] = [v for k,v in V4L2_CAPS.items() if vid_caps.device_caps & k]
return dict((k,v) for k,v in info.items() if v)
Expand All @@ -247,8 +247,8 @@ def get_type():
def get_info():
global COLORSPACES, MAX_WIDTH, MAX_HEIGHT
return {
"version" : get_version(),
}
"version" : get_version(),
}

def get_input_colorspaces():
return ["YUV420P"] #,"YUV422P"
Expand Down Expand Up @@ -361,12 +361,12 @@ cdef class Pusher:
def get_info(self): #@DuplicatedSignature
info = get_info()
info.update({
"frames" : int(self.frames),
"width" : self.width,
"height" : self.height,
"src_format": self.src_format,
"device" : self.device_name,
})
"frames" : int(self.frames),
"width" : self.width,
"height" : self.height,
"src_format": self.src_format,
"device" : self.device_name,
})
return info

def __repr__(self):
Expand Down
25 changes: 13 additions & 12 deletions src/xpra/codecs/webp/decode.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ cdef extern from "webp/decode.h":

ERROR_TO_NAME = {
#VP8_STATUS_OK
VP8_STATUS_OUT_OF_MEMORY : "out of memory",
VP8_STATUS_INVALID_PARAM : "invalid parameter",
VP8_STATUS_BITSTREAM_ERROR : "bitstream error",
VP8_STATUS_UNSUPPORTED_FEATURE : "unsupported feature",
VP8_STATUS_SUSPENDED : "suspended",
VP8_STATUS_USER_ABORT : "user abort",
VP8_STATUS_NOT_ENOUGH_DATA : "not enough data",
}
VP8_STATUS_OUT_OF_MEMORY : "out of memory",
VP8_STATUS_INVALID_PARAM : "invalid parameter",
VP8_STATUS_BITSTREAM_ERROR : "bitstream error",
VP8_STATUS_UNSUPPORTED_FEATURE : "unsupported feature",
VP8_STATUS_SUSPENDED : "suspended",
VP8_STATUS_USER_ABORT : "user abort",
VP8_STATUS_NOT_ENOUGH_DATA : "not enough data",
}

def get_version():
cdef int version = WebPGetDecoderVersion()
Expand All @@ -147,9 +147,9 @@ def get_version():

def get_info():
return {
"version" : get_version(),
"encodings" : get_encodings(),
}
"version" : get_version(),
"encodings" : get_encodings(),
}

def webp_check(int ret):
if ret==0:
Expand Down Expand Up @@ -288,7 +288,8 @@ def decompress_yuv(data, has_alpha=False):
YUVA.a = NULL
strides = (YUVA.y_stride, YUVA.u_stride, YUVA.v_stride)
config.output.is_external_memory = 1
log("WebPDecode: image size %ix%i : buffer=%#x, strides=%s", w, h, <uintptr_t> buf, strides)
log("WebPDecode: image size %ix%i : buffer=%#x, strides=%s",
w, h, <uintptr_t> buf, strides)
webp_check(WebPDecode(data, len(data), &config))
if alpha:
planes = (
Expand Down
46 changes: 23 additions & 23 deletions src/xpra/codecs/webp/encode.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -282,26 +282,26 @@ cdef extern from "webp/encode.h":

ERROR_TO_NAME = {
#VP8_ENC_OK
VP8_ENC_ERROR_OUT_OF_MEMORY : "memory error allocating objects",
VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY : "memory error while flushing bits",
VP8_ENC_ERROR_NULL_PARAMETER : "a pointer parameter is NULL",
VP8_ENC_ERROR_INVALID_CONFIGURATION : "configuration is invalid",
VP8_ENC_ERROR_BAD_DIMENSION : "picture has invalid width/height",
VP8_ENC_ERROR_PARTITION0_OVERFLOW : "partition is bigger than 512k",
VP8_ENC_ERROR_PARTITION_OVERFLOW : "partition is bigger than 16M",
VP8_ENC_ERROR_BAD_WRITE : "error while flushing bytes",
VP8_ENC_ERROR_FILE_TOO_BIG : "file is bigger than 4G",
VP8_ENC_ERROR_USER_ABORT : "abort request by user",
}
VP8_ENC_ERROR_OUT_OF_MEMORY : "memory error allocating objects",
VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY : "memory error while flushing bits",
VP8_ENC_ERROR_NULL_PARAMETER : "a pointer parameter is NULL",
VP8_ENC_ERROR_INVALID_CONFIGURATION : "configuration is invalid",
VP8_ENC_ERROR_BAD_DIMENSION : "picture has invalid width/height",
VP8_ENC_ERROR_PARTITION0_OVERFLOW : "partition is bigger than 512k",
VP8_ENC_ERROR_PARTITION_OVERFLOW : "partition is bigger than 16M",
VP8_ENC_ERROR_BAD_WRITE : "error while flushing bytes",
VP8_ENC_ERROR_FILE_TOO_BIG : "file is bigger than 4G",
VP8_ENC_ERROR_USER_ABORT : "abort request by user",
}

PRESETS = {
WEBP_PRESET_DEFAULT : "default",
WEBP_PRESET_PICTURE : "picture",
WEBP_PRESET_PHOTO : "photo",
WEBP_PRESET_DRAWING : "drawing",
WEBP_PRESET_ICON : "icon",
WEBP_PRESET_TEXT : "text",
}
WEBP_PRESET_DEFAULT : "default",
WEBP_PRESET_PICTURE : "picture",
WEBP_PRESET_PHOTO : "photo",
WEBP_PRESET_DRAWING : "drawing",
WEBP_PRESET_ICON : "icon",
WEBP_PRESET_TEXT : "text",
}
PRESET_NAME_TO_CONSTANT = {}
for k,v in PRESETS.items():
PRESET_NAME_TO_CONSTANT[v] = k
Expand All @@ -313,11 +313,11 @@ CONTENT_TYPE_PRESET = {
}

IMAGE_HINT = {
WEBP_HINT_DEFAULT : "default",
WEBP_HINT_PICTURE : "picture",
WEBP_HINT_PHOTO : "photo",
WEBP_HINT_GRAPH : "graph",
}
WEBP_HINT_DEFAULT : "default",
WEBP_HINT_PICTURE : "picture",
WEBP_HINT_PHOTO : "photo",
WEBP_HINT_GRAPH : "graph",
}
HINT_NAME_TO_CONSTANT = {}
for k,v in IMAGE_HINT.items():
HINT_NAME_TO_CONSTANT[v] = k
Expand Down

0 comments on commit c7b0f33

Please sign in to comment.