diff options
author | Devaev Maxim <[email protected]> | 2021-01-28 10:51:26 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2021-01-28 10:51:26 +0300 |
commit | 6043dfbb7434c6a3d25203965d32c6b139a10960 (patch) | |
tree | 2cfc6b10cb49aebe569a663c6af2bb92d3ad1bb3 | |
parent | 83184952f6f8d834481cd06aee42474c74bb304c (diff) |
api refactoring
-rw-r--r-- | kvmd/apps/kvmd/streamer.py | 13 | ||||
-rw-r--r-- | web/share/js/kvm/stream.js | 3 |
2 files changed, 9 insertions, 7 deletions
diff --git a/kvmd/apps/kvmd/streamer.py b/kvmd/apps/kvmd/streamer.py index 51f737aa..4c4499ab 100644 --- a/kvmd/apps/kvmd/streamer.py +++ b/kvmd/apps/kvmd/streamer.py @@ -55,7 +55,6 @@ class StreamerSnapshot: class _StreamerParams: __DESIRED_FPS = "desired_fps" - __MAX_FPS = "max_fps" __QUALITY = "quality" @@ -84,7 +83,7 @@ class _StreamerParams: self.__has_h264 = bool(h264_bitrate) self.__params: Dict = {self.__DESIRED_FPS: min(desired_fps, max_fps)} - self.__limits: Dict = {self.__MAX_FPS: max_fps} + self.__limits: Dict = {self.__DESIRED_FPS: {"min": 0, "max": max_fps}} if self.__has_quality: self.__params[self.__QUALITY] = quality @@ -117,7 +116,8 @@ class _StreamerParams: new_params = dict(self.__params) if self.__DESIRED_FPS in params: - new_params[self.__DESIRED_FPS] = min(max(params[self.__DESIRED_FPS], 0), self.__limits[self.__MAX_FPS]) + if self.__check_limits_min_max(self.__DESIRED_FPS, params[self.__DESIRED_FPS]): + new_params[self.__DESIRED_FPS] = params[self.__DESIRED_FPS] if self.__QUALITY in params and self.__has_quality: new_params[self.__QUALITY] = min(max(params[self.__QUALITY], 1), 100) @@ -127,13 +127,14 @@ class _StreamerParams: new_params[self.__RESOLUTION] = params[self.__RESOLUTION] if self.__H264_BITRATE in params and self.__has_h264: - min_bitrate = self.__limits[self.__H264_BITRATE]["min"] - max_bitrate = self.__limits[self.__H264_BITRATE]["max"] - if min_bitrate <= params[self.__H264_BITRATE] <= max_bitrate: + if self.__check_limits_min_max(self.__H264_BITRATE, params[self.__H264_BITRATE]): new_params[self.__H264_BITRATE] = params[self.__H264_BITRATE] self.__params = new_params + def __check_limits_min_max(self, key: str, value: int) -> bool: + return (self.__limits[key]["min"] <= value <= self.__limits[key]["max"]) + class Streamer: # pylint: disable=too-many-instance-attributes def __init__( # pylint: disable=too-many-arguments,too-many-locals diff --git a/web/share/js/kvm/stream.js b/web/share/js/kvm/stream.js index 44a28b96..3490d046 100644 --- a/web/share/js/kvm/stream.js +++ b/web/share/js/kvm/stream.js @@ -98,7 +98,8 @@ export function Streamer() { } if (!$("stream-desired-fps-slider").activated) { - $("stream-desired-fps-slider").max = state.limits.max_fps; + $("stream-desired-fps-slider").min = state.limits.desired_fps.min; + $("stream-desired-fps-slider").max = state.limits.desired_fps.max; wm.setElementEnabled($("stream-desired-fps-slider"), true); if ($("stream-desired-fps-slider").value !== state.streamer.source.desired_fps) { $("stream-desired-fps-slider").value = state.streamer.source.desired_fps; |