diff options
author | Devaev Maxim <[email protected]> | 2021-02-06 21:17:08 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2021-02-06 21:24:36 +0300 |
commit | 30bc03fa396ba4978f389d3707d0b0c9f9ebbc84 (patch) | |
tree | e16c248a77f21517cfea4677116cf96c89d5eeea | |
parent | 3de55653fad66b8b49b877018d2d21d9e4137aba (diff) |
fix
-rw-r--r-- | kvmd/apps/__init__.py | 27 | ||||
-rw-r--r-- | kvmd/apps/kvmd/__init__.py | 3 | ||||
-rw-r--r-- | kvmd/apps/kvmd/streamer.py | 18 |
3 files changed, 34 insertions, 14 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index a797d2c4..708c50f9 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -201,7 +201,19 @@ def _patch_raw(raw_config: Dict) -> None: if max_fps is not None: if not isinstance(streamer_config.get("desired_fps"), dict): streamer_config["desired_fps"] = {} - streamer_config["desired_fps"] = {"max": max_fps} + streamer_config["desired_fps"]["max"] = max_fps + del streamer_config["max_fps"] + + resolution = streamer_config.get("resolution") + if resolution is not None and not isinstance(resolution, dict): + streamer_config["resolution"] = {"default": resolution} + + available_resolutions = streamer_config.get("available_resolutions") + if available_resolutions is not None: + if not isinstance(streamer_config.get("resolution"), dict): + streamer_config["resolution"] = {} + streamer_config["resolution"]["available"] = available_resolutions + del streamer_config["available_resolutions"] def _patch_dynamic( # pylint: disable=too-many-locals @@ -372,9 +384,16 @@ def _get_config_scheme() -> Dict: "shutdown_delay": Option(10.0, type=valid_float_f01), "state_poll": Option(1.0, type=valid_float_f01), - "quality": Option(80, type=_make_ifarg(valid_stream_quality, 0)), - "resolution": Option("", type=_make_ifarg(valid_stream_resolution, "")), - "available_resolutions": Option([], type=functools.partial(valid_string_list, subval=valid_stream_resolution)), + "quality": Option(80, type=_make_ifarg(valid_stream_quality, 0)), + + "resolution": { + "default": Option("", type=_make_ifarg(valid_stream_resolution, ""), unpack_as="resolution"), + "available": Option( + [], + type=functools.partial(valid_string_list, subval=valid_stream_resolution), + unpack_as="available_resolutions", + ), + }, "desired_fps": { "default": Option(30, type=valid_stream_fps, unpack_as="desired_fps"), diff --git a/kvmd/apps/kvmd/__init__.py b/kvmd/apps/kvmd/__init__.py index 7e570278..2a6dbeef 100644 --- a/kvmd/apps/kvmd/__init__.py +++ b/kvmd/apps/kvmd/__init__.py @@ -68,7 +68,8 @@ def main(argv: Optional[List[str]]=None) -> None: hid = get_hid_class(config.hid.type)(**hid_kwargs) streamer = Streamer( - **config.streamer._unpack(ignore=["forever", "desired_fps", "h264_bitrate", "h264_gop"]), + **config.streamer._unpack(ignore=["forever", "desired_fps", "resolution", "h264_bitrate", "h264_gop"]), + **config.streamer.resolution._unpack(), **config.streamer.desired_fps._unpack(), **config.streamer.h264_bitrate._unpack(), **config.streamer.h264_gop._unpack(), diff --git a/kvmd/apps/kvmd/streamer.py b/kvmd/apps/kvmd/streamer.py index 6f26a422..b7f57797 100644 --- a/kvmd/apps/kvmd/streamer.py +++ b/kvmd/apps/kvmd/streamer.py @@ -76,19 +76,19 @@ class _StreamerParams: desired_fps_max: int, h264_bitrate: int, - h264_min_bitrate: int, - h264_max_bitrate: int, + h264_bitrate_min: int, + h264_bitrate_max: int, h264_gop: int, - h264_min_gop: int, - h264_max_gop: int, + h264_gop_min: int, + h264_gop_max: int, ) -> None: self.__has_quality = bool(quality) self.__has_resolution = bool(resolution) self.__has_h264 = bool(h264_bitrate) - self.__params: Dict = {self.__DESIRED_FPS: min(desired_fps, desired_fps_min)} + self.__params: Dict = {self.__DESIRED_FPS: min(max(desired_fps, desired_fps_min), desired_fps_max)} self.__limits: Dict = {self.__DESIRED_FPS: {"min": desired_fps_min, "max": desired_fps_max}} if self.__has_quality: @@ -99,10 +99,10 @@ class _StreamerParams: self.__limits[self.__AVAILABLE_RESOLUTIONS] = available_resolutions if self.__has_h264: - self.__params[self.__H264_BITRATE] = min(max(h264_bitrate, h264_min_bitrate), h264_max_bitrate) - self.__limits[self.__H264_BITRATE] = {"min": h264_min_bitrate, "max": h264_max_bitrate} - self.__params[self.__H264_GOP] = min(max(h264_gop, h264_min_gop), h264_max_gop) - self.__limits[self.__H264_GOP] = {"min": h264_min_gop, "max": h264_max_gop} + self.__params[self.__H264_BITRATE] = min(max(h264_bitrate, h264_bitrate_min), h264_bitrate_max) + self.__limits[self.__H264_BITRATE] = {"min": h264_bitrate_min, "max": h264_bitrate_max} + self.__params[self.__H264_GOP] = min(max(h264_gop, h264_gop_min), h264_gop_max) + self.__limits[self.__H264_GOP] = {"min": h264_gop_min, "max": h264_gop_max} def get_features(self) -> Dict: return { |