kvmd: supported unix sockets for ustreamer

This commit is contained in:
Devaev Maxim 2018-12-06 22:19:54 +03:00
parent d4d15d8b74
commit 7b6f4b20ea
2 changed files with 19 additions and 9 deletions

View File

@ -1,7 +1,5 @@
import asyncio import asyncio
import aiohttp
from ...application import init from ...application import init
from ...logging import get_logger from ...logging import get_logger
@ -21,7 +19,6 @@ def main() -> None:
config = init()["kvmd"] config = init()["kvmd"]
with gpio.bcm(): with gpio.bcm():
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
http_session = aiohttp.ClientSession(loop=loop)
info_manager = InfoManager( info_manager = InfoManager(
meta_path=str(config["info"]["meta"]), meta_path=str(config["info"]["meta"]),
@ -72,14 +69,14 @@ def main() -> None:
quality=int(config["streamer"]["quality"]), quality=int(config["streamer"]["quality"]),
desired_fps=int(config["streamer"]["desired_fps"]), desired_fps=int(config["streamer"]["desired_fps"]),
host=str(config["streamer"]["host"]), host=str(config["streamer"].get("host", "localhost")),
port=int(config["streamer"]["port"]), port=int(config["streamer"].get("port", 0)),
unix_path=str(config["streamer"].get("unix", "")),
timeout=float(config["streamer"]["timeout"]), timeout=float(config["streamer"]["timeout"]),
cmd=list(map(str, config["streamer"]["cmd"])), cmd=list(map(str, config["streamer"]["cmd"])),
loop=loop, loop=loop,
http_session=http_session,
) )
Server( Server(

View File

@ -31,12 +31,12 @@ class Streamer: # pylint: disable=too-many-instance-attributes
host: str, host: str,
port: int, port: int,
unix_path: str,
timeout: float, timeout: float,
cmd: List[str], cmd: List[str],
loop: asyncio.AbstractEventLoop, loop: asyncio.AbstractEventLoop,
http_session: aiohttp.ClientSession,
) -> None: ) -> None:
self.__cap_power = (gpio.set_output(cap_power) if cap_power > 0 else cap_power) 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, "desired_fps": desired_fps,
} }
assert port or unix_path
self.__host = host self.__host = host
self.__port = port self.__port = port
self.__unix_path = unix_path
self.__timeout = timeout self.__timeout = timeout
self.__cmd = cmd self.__cmd = cmd
self.__loop = loop 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 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 while True: # pylint: disable=too-many-nested-blocks
proc: Optional[asyncio.subprocess.Process] = None # pylint: disable=no-member proc: Optional[asyncio.subprocess.Process] = None # pylint: disable=no-member
try: 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( proc = await asyncio.create_subprocess_exec(
*cmd, *cmd,
stdout=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE,