diff options
author | Devaev Maxim <[email protected]> | 2018-11-05 06:13:08 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-11-05 06:13:08 +0300 |
commit | 18a626a30c63367b97af74bc3e30fc6b75cc48dd (patch) | |
tree | 76443a01079bb809f03d88e4220bcb356afabc7e | |
parent | 4e49931a252ebd555ab523673c2c69808c20ab6a (diff) |
soft fps limit
-rw-r--r-- | configs/kvmd/v1-hdmi.conf | 2 | ||||
-rw-r--r-- | configs/kvmd/v1-vga.conf | 2 | ||||
-rw-r--r-- | kvmd/__init__.py | 1 | ||||
-rw-r--r-- | kvmd/server.py | 14 | ||||
-rw-r--r-- | kvmd/streamer.py | 15 | ||||
-rw-r--r-- | testenv/kvmd.conf | 2 | ||||
-rw-r--r-- | web/index.html | 7 | ||||
-rw-r--r-- | web/js/stream.js | 34 |
8 files changed, 72 insertions, 5 deletions
diff --git a/configs/kvmd/v1-hdmi.conf b/configs/kvmd/v1-hdmi.conf index 5d184764..aa70a99b 100644 --- a/configs/kvmd/v1-hdmi.conf +++ b/configs/kvmd/v1-hdmi.conf @@ -51,6 +51,7 @@ kvmd: shutdown_delay: 10.0 quality: 20 + soft_fps: 30 cmd: - "/usr/bin/ustreamer" @@ -59,6 +60,7 @@ kvmd: - "--format=uyvy" - "--encoder=omx" - "--quality={quality}" + - "--soft-fps={soft_fps}" - "--dv-timings" - "--host=127.0.0.1" - "--port=8082" diff --git a/configs/kvmd/v1-vga.conf b/configs/kvmd/v1-vga.conf index 221852e0..cec63f69 100644 --- a/configs/kvmd/v1-vga.conf +++ b/configs/kvmd/v1-vga.conf @@ -51,6 +51,7 @@ kvmd: shutdown_delay: 10.0 quality: 80 + soft_fps: 30 cmd: - "/usr/bin/ustreamer" @@ -59,6 +60,7 @@ kvmd: - "--format=yuyv" - "--encoder=cpu" - "--quality={quality}" + - "--soft-fps={soft_fps}" - "--width=720" - "--height=576" - "--fake-width=800" diff --git a/kvmd/__init__.py b/kvmd/__init__.py index 93f9e2de..5f308bba 100644 --- a/kvmd/__init__.py +++ b/kvmd/__init__.py @@ -61,6 +61,7 @@ def main() -> None: init_delay=float(config["streamer"]["init_delay"]), init_restart_after=float(config["streamer"]["init_restart_after"]), quality=int(config["streamer"]["quality"]), + soft_fps=int(config["streamer"]["soft_fps"]), cmd=list(map(str, config["streamer"]["cmd"])), loop=loop, ) diff --git a/kvmd/server.py b/kvmd/server.py index 16de7dd8..cb9db787 100644 --- a/kvmd/server.py +++ b/kvmd/server.py @@ -141,6 +141,7 @@ class Server: # pylint: disable=too-many-instance-attributes self.__reset_streamer = False self.__streamer_quality = streamer.get_current_quality() + self.__streamer_soft_fps = streamer.get_current_soft_fps() def run(self, host: str, port: int) -> None: self.__hid.start() @@ -355,6 +356,9 @@ class Server: # pylint: disable=too-many-instance-attributes quality = request.query.get("quality") if quality: self.__streamer_quality = _valid_int("quality", quality, 1, 100) + soft_fps = request.query.get("soft_fps") + if soft_fps: + self.__streamer_soft_fps = _valid_int("soft_fps", soft_fps, 1, 30) return _json() async def __streamer_reset_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response: @@ -400,7 +404,7 @@ class Server: # pylint: disable=too-many-instance-attributes cur = len(self.__sockets) if prev == 0 and cur > 0: if not self.__streamer.is_running(): - await self.__streamer.start(self.__streamer_quality) + await self.__streamer.start(self.__streamer_quality, self.__streamer_soft_fps) await self.__broadcast_event("streamer_state", **self.__streamer.get_state()) elif prev > 0 and cur == 0: shutdown_at = time.time() + self.__streamer_shutdown_delay @@ -409,10 +413,14 @@ class Server: # pylint: disable=too-many-instance-attributes await self.__streamer.stop() await self.__broadcast_event("streamer_state", **self.__streamer.get_state()) - if self.__reset_streamer or self.__streamer_quality != self.__streamer.get_current_quality(): + if ( + self.__reset_streamer + or self.__streamer_quality != self.__streamer.get_current_quality() + or self.__streamer_soft_fps != self.__streamer.get_current_soft_fps() + ): if self.__streamer.is_running(): await self.__streamer.stop() - await self.__streamer.start(self.__streamer_quality, no_init_restart=True) + await self.__streamer.start(self.__streamer_quality, self.__streamer_soft_fps, no_init_restart=True) await self.__broadcast_event("streamer_state", **self.__streamer.get_state()) self.__reset_streamer = False diff --git a/kvmd/streamer.py b/kvmd/streamer.py index f4c49bf2..e9cbf0e6 100644 --- a/kvmd/streamer.py +++ b/kvmd/streamer.py @@ -21,6 +21,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes init_delay: float, init_restart_after: float, quality: int, + soft_fps: int, cmd: List[str], loop: asyncio.AbstractEventLoop, ) -> None: @@ -31,17 +32,23 @@ class Streamer: # pylint: disable=too-many-instance-attributes self.__init_delay = init_delay self.__init_restart_after = init_restart_after self.__quality = quality + self.__soft_fps = soft_fps self.__cmd = cmd self.__loop = loop self.__proc_task: Optional[asyncio.Task] = None - async def start(self, quality: int, no_init_restart: bool=False) -> None: + async def start(self, quality: int, soft_fps: int, no_init_restart: bool=False) -> None: logger = get_logger() logger.info("Starting streamer ...") + assert 1 <= quality <= 100 self.__quality = quality + + assert 1 <= soft_fps <= 30 + self.__soft_fps = soft_fps + await self.__inner_start() if self.__init_restart_after > 0.0 and not no_init_restart: logger.info("Stopping streamer to restart ...") @@ -59,10 +66,14 @@ class Streamer: # pylint: disable=too-many-instance-attributes def get_current_quality(self) -> int: return self.__quality + def get_current_soft_fps(self) -> int: + return self.__soft_fps + def get_state(self) -> Dict: return { "is_running": self.is_running(), "quality": self.__quality, + "soft_fps": self.__soft_fps, } def get_app(self) -> str: @@ -110,7 +121,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes while True: # pylint: disable=too-many-nested-blocks proc: Optional[asyncio.subprocess.Process] = None # pylint: disable=no-member try: - cmd = [part.format(quality=self.__quality) for part in self.__cmd] + cmd = [part.format(quality=self.__quality, soft_fps=self.__soft_fps) for part in self.__cmd] proc = await asyncio.create_subprocess_exec( *cmd, stdout=asyncio.subprocess.PIPE, diff --git a/testenv/kvmd.conf b/testenv/kvmd.conf index d95871c3..8982fdb6 100644 --- a/testenv/kvmd.conf +++ b/testenv/kvmd.conf @@ -50,11 +50,13 @@ kvmd: shutdown_delay: 10.0 quality: 80 + soft_fps: 30 cmd: - "/usr/bin/ustreamer" - "--device=/dev/kvmd-streamer" - "--quality={quality}" + - "--soft-fps={soft_fps}" - "--width=800" - "--height=600" - "--host=0.0.0.0" diff --git a/web/index.html b/web/index.html index 99e48cf8..0fac2724 100644 --- a/web/index.html +++ b/web/index.html @@ -86,6 +86,13 @@ </div> <hr> <div class="ctl-dropdown-content-text"> + Soft FPS limit: <span id="stream-soft-fps-value">30</span> + <div class="stream-slider-box"> + <input disabled type="range" id="stream-soft-fps-slider" class="slider" /> + </div> + </div> + <hr> + <div class="ctl-dropdown-content-text"> Stream size: <span id="stream-size-value">100%</span> <div class="stream-slider-box"> <input type="range" id="stream-size-slider" class="slider" /> diff --git a/web/js/stream.js b/web/js/stream.js index 3394951e..5ea48067 100644 --- a/web/js/stream.js +++ b/web/js/stream.js @@ -9,6 +9,7 @@ function Stream() { var __client_id = ""; var __fps = 0; var __quality_timer = null; + var __soft_fps_timer = null; var __init__ = function() { $("stream-led").title = "Stream inactive"; @@ -20,6 +21,13 @@ function Stream() { $("stream-quality-slider").oninput = __setQuality; $("stream-quality-slider").onchange = __setQuality; + $("stream-soft-fps-slider").min = 1; + $("stream-soft-fps-slider").max = 30; + $("stream-soft-fps-slider").step = 1; + $("stream-soft-fps-slider").value = 30; + $("stream-soft-fps-slider").oninput = __setSoftFps; + $("stream-soft-fps-slider").onchange = __setSoftFps; + $("stream-size-slider").min = 20; $("stream-size-slider").max = 200; $("stream-size-slider").step = 5; @@ -50,6 +58,7 @@ function Stream() { $("stream-led").title = "Stream inactive"; $("stream-screenshot-button").disabled = true; $("stream-quality-slider").disabled = true; + $("stream-soft-fps-slider").disabled = true; $("stream-reset-button").disabled = true; __updateStreamHeader(false); __fps = 0; @@ -60,6 +69,11 @@ function Stream() { $("stream-quality-slider").value = response.source.quality; $("stream-quality-value").innerHTML = response.source.quality + "%"; } + if ($("stream-soft-fps-slider").value !== response.source.soft_fps && !__soft_fps_timer) { + $("stream-soft-fps-slider").value = response.source.soft_fps; + $("stream-soft-fps-value").innerHTML = response.source.soft_fps; + } + if (__resolution.width !== response.source.resolution.width || __resolution.height !== response.source.resolution.height) { __resolution = response.source.resolution; @@ -101,6 +115,7 @@ function Stream() { $("stream-led").title = "Stream is active"; $("stream-screenshot-button").disabled = false; $("stream-quality-slider").disabled = false; + $("stream-soft-fps-slider").disabled = false; $("stream-reset-button").disabled = false; __prev_state = true; tools.info("Stream acquired"); @@ -160,6 +175,25 @@ function Stream() { }, 1000); }; + var __setSoftFps = function() { + var soft_fps = $("stream-soft-fps-slider").value; + $("stream-soft-fps-value").innerHTML = soft_fps; + if (__soft_fps_timer) { + clearTimeout(__soft_fps_timer); + } + __soft_fps_timer = setTimeout(function() { + $("stream-soft-fps-slider").disabled = true; + var http = tools.makeRequest("POST", "/kvmd/streamer/set_params?soft_fps=" + soft_fps, function() { + if (http.readyState === 4) { + if (http.status !== 200) { + ui.error("Can't configure stream:<br>", http.responseText); + } + __soft_fps_timer = null; + } + }); + }, 1000); + }; + var __resize = function(center=false) { var size = $("stream-size-slider").value; $("stream-size-value").innerHTML = size + "%"; |