summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-11-05 06:13:08 +0300
committerDevaev Maxim <[email protected]>2018-11-05 06:13:08 +0300
commit18a626a30c63367b97af74bc3e30fc6b75cc48dd (patch)
tree76443a01079bb809f03d88e4220bcb356afabc7e /kvmd
parent4e49931a252ebd555ab523673c2c69808c20ab6a (diff)
soft fps limit
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/__init__.py1
-rw-r--r--kvmd/server.py14
-rw-r--r--kvmd/streamer.py15
3 files changed, 25 insertions, 5 deletions
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,