diff options
author | Devaev Maxim <[email protected]> | 2018-12-06 22:19:54 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-12-06 22:19:54 +0300 |
commit | 7b6f4b20eafa71339a98110e3451277f09072c3f (patch) | |
tree | 6756504d5cbcb052b6bf5b7163ccc2be81bd3543 /kvmd/apps | |
parent | d4d15d8b745962d7b6ba556f7026dda377595f62 (diff) |
kvmd: supported unix sockets for ustreamer
Diffstat (limited to 'kvmd/apps')
-rw-r--r-- | kvmd/apps/kvmd/__init__.py | 9 | ||||
-rw-r--r-- | kvmd/apps/kvmd/streamer.py | 19 |
2 files changed, 19 insertions, 9 deletions
diff --git a/kvmd/apps/kvmd/__init__.py b/kvmd/apps/kvmd/__init__.py index e50ad1bd..3c3ca6e4 100644 --- a/kvmd/apps/kvmd/__init__.py +++ b/kvmd/apps/kvmd/__init__.py @@ -1,7 +1,5 @@ import asyncio -import aiohttp - from ...application import init from ...logging import get_logger @@ -21,7 +19,6 @@ def main() -> None: config = init()["kvmd"] with gpio.bcm(): loop = asyncio.get_event_loop() - http_session = aiohttp.ClientSession(loop=loop) info_manager = InfoManager( meta_path=str(config["info"]["meta"]), @@ -72,14 +69,14 @@ def main() -> None: quality=int(config["streamer"]["quality"]), desired_fps=int(config["streamer"]["desired_fps"]), - host=str(config["streamer"]["host"]), - port=int(config["streamer"]["port"]), + host=str(config["streamer"].get("host", "localhost")), + port=int(config["streamer"].get("port", 0)), + unix_path=str(config["streamer"].get("unix", "")), timeout=float(config["streamer"]["timeout"]), cmd=list(map(str, config["streamer"]["cmd"])), loop=loop, - http_session=http_session, ) Server( diff --git a/kvmd/apps/kvmd/streamer.py b/kvmd/apps/kvmd/streamer.py index 25fe7527..2527d4e9 100644 --- a/kvmd/apps/kvmd/streamer.py +++ b/kvmd/apps/kvmd/streamer.py @@ -31,12 +31,12 @@ class Streamer: # pylint: disable=too-many-instance-attributes host: str, port: int, + unix_path: str, timeout: float, cmd: List[str], loop: asyncio.AbstractEventLoop, - http_session: aiohttp.ClientSession, ) -> None: self.__cap_power = (gpio.set_output(cap_power) if cap_power > 0 else cap_power) @@ -52,14 +52,19 @@ class Streamer: # pylint: disable=too-many-instance-attributes "desired_fps": desired_fps, } + assert port or unix_path self.__host = host self.__port = port + self.__unix_path = unix_path self.__timeout = timeout self.__cmd = cmd self.__loop = loop - self.__http_session = http_session + if self.__unix_path: + self.__http_session = aiohttp.ClientSession(connector=aiohttp.UnixConnector(path=self.__unix_path)) + else: + self.__http_session = aiohttp.ClientSession() self.__proc_task: Optional[asyncio.Task] = None @@ -154,7 +159,15 @@ 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(host=self.__host, port=self.__port, **self.__params) for part in self.__cmd] + cmd = [ + part.format( + host=self.__host, + port=self.__port, + unix=self.__unix_path, + **self.__params, + ) + for part in self.__cmd + ] proc = await asyncio.create_subprocess_exec( *cmd, stdout=asyncio.subprocess.PIPE, |