fixed h264 accumulating

This commit is contained in:
Devaev Maxim 2021-02-03 21:38:16 +03:00
parent db4dc5de45
commit 32bd2453eb

View File

@ -242,6 +242,7 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
if not self._encodings.has_h264:
self.__fb_h264_data = b""
raise StreamerPermError("The client doesn't want to accept H264 anymore")
self.__append_h264_data(frame)
await self._send_fb_h264(self.__fb_h264_data)
else:
raise RuntimeError(f"Unknown format: {frame['format']}")
@ -251,13 +252,7 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
self.__fb_h264_data = b""
elif self._encodings.has_h264 and frame["format"] == StreamFormats.H264:
if frame["key"]:
self.__fb_h264_data = frame["data"]
elif len(self.__fb_h264_data) + len(frame["data"]) > 4194304: # 4Mb
get_logger(0).info("Accumulated H264 buffer is too big; resetting ...")
self.__fb_h264_data = frame["data"]
else:
self.__fb_h264_data += frame["data"]
self.__append_h264_data(frame)
async def __resize_fb_unsafe(self, frame: Dict) -> bool:
width = frame["width"]
@ -272,6 +267,15 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes
await self._send_resize(width, height)
return True
def __append_h264_data(self, frame: Dict) -> None:
if frame["key"]:
self.__fb_h264_data = frame["data"]
elif len(self.__fb_h264_data) + len(frame["data"]) > 4194304: # 4Mb
get_logger(0).info("Accumulated H264 buffer is too big; resetting ...")
self.__fb_h264_data = frame["data"]
else:
self.__fb_h264_data += frame["data"]
async def __send_fb_stub(self, text: str, no_lock: bool=False) -> None:
if not no_lock:
await self.__lock.acquire()