Skip to content

Commit

Permalink
#389:
Browse files Browse the repository at this point in the history
* try to handle transient failures and re-init the context
* return an exit code from the test capture tool

git-svn-id: https://xpra.org/svn/Xpra/trunk@15727 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 27, 2017
1 parent d923e4f commit 9ce3d2d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 24 deletions.
3 changes: 3 additions & 0 deletions src/xpra/codecs/codec_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def get_subsampling_divs(pixel_format):
class TransientCodecException(Exception):
pass

class CodecStateException(Exception):
pass


class _codec_spec(object):

Expand Down
36 changes: 19 additions & 17 deletions src/xpra/codecs/nvfbc/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,25 @@ def main():
log("Capture()", exc_info=True)
log.error("Error: failed to create test capture instance:")
log.error(" %s", e)
else:
image = c.get_image()
assert image
from PIL import Image
w = image.get_width()
h = image.get_height()
pixels = image.get_pixels()
stride = image.get_rowstride()
rgb_format = image.get_pixel_format()
try:
img = Image.frombuffer("RGB", (w, h), pixels, "raw", rgb_format, stride, 1)
filename = os.path.join(get_download_dir(), "screenshot-%s-%i.png" % (rgb_format, time.time()))
img.save(filename, "png")
log.info("screenshot saved to %s", filename)
except Exception as e:
log.warn("not saved %s: %s", rgb_format, e)
return 1
image = c.get_image()
assert image
from PIL import Image
w = image.get_width()
h = image.get_height()
pixels = image.get_pixels()
stride = image.get_rowstride()
rgb_format = image.get_pixel_format()
try:
img = Image.frombuffer("RGB", (w, h), pixels, "raw", rgb_format, stride, 1)
filename = os.path.join(get_download_dir(), "screenshot-%s-%i.png" % (rgb_format, time.time()))
img.save(filename, "png")
log.info("screenshot saved to %s", filename)
return 0
except Exception as e:
log.warn("not saved %s: %s", rgb_format, e)
return 1


if __name__ == "__main__":
main()
sys.exit(main())
12 changes: 6 additions & 6 deletions src/xpra/codecs/nvfbc/fbc_capture.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import sys

from xpra.os_util import WIN32
from xpra.codecs.image_wrapper import ImageWrapper
from xpra.codecs.codec_constants import TransientCodecException
from xpra.codecs.codec_constants import TransientCodecException, CodecStateException
from xpra.codecs.nv_util import get_nvidia_module_version, get_cards

from xpra.log import Logger
Expand Down Expand Up @@ -474,12 +474,12 @@ cdef class NvFBC_Capture:
cdef NVFBCRESULT res
with nogil:
res = self.context.NvFBCToSysGrabFrame(&grab)
if res!=0 and grab_info.bMustRecreate:
pass #TODO!
if res!=0 and grab_info.dwDriverInternalError:
pass
if res==NVFBC_ERROR_INVALIDATED_SESSION:
pass #retry!
raise CodecStateException("NvFBC driver internal error")
if res==NVFBC_ERROR_DYNAMIC_DISABLE:
raise CodecStateException("NvFBC capture has been disabled")
if (res!=0 and grab_info.bMustRecreate) or res==NVFBC_ERROR_INVALIDATED_SESSION:
raise TransientCodecException("NvFBC context invalidated")
log("NvFBCToSysGrabFrame(%#x)=%i", <uintptr_t> &grab, res)
raiseNvFBC(res, "NvFBCToSysGrabFrame")
info = {
Expand Down
18 changes: 17 additions & 1 deletion src/xpra/platform/win32/shadow_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from xpra.util import XPRA_APP_ID
from xpra.scripts.config import InitException
from xpra.codecs.codec_constants import CodecStateException, TransientCodecException
from xpra.server.gtk_server_base import GTKServerBase
from xpra.server.shadow.gtk_shadow_server_base import GTKShadowServerBase
from xpra.server.shadow.root_window_model import RootWindowModel
Expand Down Expand Up @@ -94,6 +95,9 @@ def init_capture(self):

def cleanup(self):
RootWindowModel.cleanup(self)
self.cleanup_capture()

def cleanup_capture(self):
c = self.capture
if c:
self.capture = None
Expand Down Expand Up @@ -225,7 +229,19 @@ def get_root_window_size(self):
return w, h

def get_image(self, x, y, width, height, logger=None):
return self.capture.get_image(x, y, width, height)
try:
return self.capture.get_image(x, y, width, height)
except CodecStateException as e:
#maybe we should exit here?
log.warn("Warning: %s", e)
self.cleanup_capture()
self.init_capture()
return None
except TransientCodecException as e:
log.warn("Warning: %s", e)
self.cleanup_capture()
self.init_capture()
return None

def take_screenshot(self):
return self.capture.take_screenshot()
Expand Down

0 comments on commit 9ce3d2d

Please sign in to comment.