Skip to content

Commit

Permalink
discard nvjpeg / nvdec decoders on non-transient failures
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Sep 6, 2024
1 parent 9c2953f commit 37fe0a0
Showing 1 changed file with 17 additions and 30 deletions.
47 changes: 17 additions & 30 deletions xpra/client/gui/window_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,44 +477,31 @@ def paint_jpega(self, img_data, x: int, y: int, width: int, height: int,
options: typedict, callbacks: PaintCallbacks) -> None:
self.do_paint_jpeg("jpega", img_data, x, y, width, height, options, callbacks)

def nvdec_decode(self, encoding: str, img_data, x: int, y: int, width: int, height: int, options: typedict):
if not self.nvdec_decoder or width < 16 or height < 16:
return None
if encoding not in self.nvdec_decoder.get_encodings():
def nv_decode(self, encoding: str, img_data, width: int, height: int, options: typedict):
if width < 16 or height < 16:
return None
nvdec = self.nvdec_decoder
nvjpeg = self.nvjpeg_decoder
try:
with self.assign_cuda_context(False):
return self.nvdec_decoder.decompress_and_download(encoding, img_data, width, height, options)
except Exception as e:
if first_time(str(e)):
log.error("Error accessing cuda context", exc_info=True)
else:
log(f"cuda context error, again: {e}")
return None

def nvjpeg_decode(self, encoding: str, data, x: int, y: int, width: int, height: int, options: typedict) -> None:
if not self.nvjpeg_decoder or width < 16 or height < 16:
return None
if encoding not in self.nvjpeg_decoder.get_encodings():
if nvdec and encoding in nvdec.get_encodings():
return nvdec.decompress_and_download(encoding, img_data, width, height, options)
if nvjpeg and encoding in nvjpeg.get_encodings():
return nvjpeg.decompress_and_download("RGB", img_data, options)
return None
except TransientCodecException as e:
log(f"nv_decode failed: {e} - will retry")
return None
try:
with self.assign_cuda_context(False):
return self.nvjpeg_decoder.decompress_and_download("RGB", data)
except Exception as e:
if first_time(str(e)):
log.error("Error accessing cuda context", exc_info=True)
else:
log(f"cuda context error, again: {e}")
return None

def nv_decode(self, encoding: str, img_data, x: int, y: int, width: int, height: int, options: typedict):
return self.nvjpeg_decode(encoding, img_data, x, y, width, height, options) or \
self.nvdec_decode(encoding, img_data, x, y, width, height, options)
except (CodecStateException, RuntimeError) as e:
self.nvdec_decode = self.nvjpeg_decode = None
log(f"nv_decode {encoding=}", exc_info=True)
log.warn("Warning: nv decode error, disabling hardware accelerated decoding for this window")
log.warn(f" {e}")

def do_paint_jpeg(self, encoding: str, img_data, x: int, y: int, width: int, height: int,
options: typedict, callbacks: PaintCallbacks) -> None:
alpha_offset = options.intget("alpha-offset", 0)
img = self.nv_decode(encoding, img_data, x, y, width, height, options)
img = self.nv_decode(encoding, img_data, width, height, options)
if img is None:
if encoding == "jpeg":
rgb_format = "BGRX"
Expand Down

0 comments on commit 37fe0a0

Please sign in to comment.