diff options
author | Devaev Maxim <[email protected]> | 2018-06-30 00:04:32 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-06-30 00:04:32 +0300 |
commit | c0ee171edb266ebd0bc405b3e9ed68203182ac61 (patch) | |
tree | 484ab7ebbe67df3327f65942d7ea29de314e92f0 /kvmd | |
parent | 5589ecbac42bb89b3c1c53fa4754744c9292b7d0 (diff) |
refactoring
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/kvmd.yaml | 7 | ||||
-rw-r--r-- | kvmd/kvmd/__init__.py | 2 | ||||
-rw-r--r-- | kvmd/kvmd/streamer.py | 11 |
3 files changed, 14 insertions, 6 deletions
diff --git a/kvmd/kvmd.yaml b/kvmd/kvmd.yaml index 738a752b..3dcc8d04 100644 --- a/kvmd/kvmd.yaml +++ b/kvmd/kvmd.yaml @@ -32,7 +32,12 @@ kvmd: shutdown_delay: 10.0 - cmd: "/usr/bin/mjpg_streamer -i 'input_uvc.so -d /dev/video0 -e 2 -y -n -r 720x576' -o 'output_http.so -l localhost -p 8082'" + cmd: + - "/usr/bin/mjpg_streamer" + - "-i" + - "input_uvc.so -d /dev/video0 -e 2 -y -n -r 720x576" + - "-o" + - "output_http.so -l localhost -p 8082" logging: version: 1 diff --git a/kvmd/kvmd/__init__.py b/kvmd/kvmd/__init__.py index dd615298..ed8ce8da 100644 --- a/kvmd/kvmd/__init__.py +++ b/kvmd/kvmd/__init__.py @@ -30,7 +30,7 @@ def main() -> None: cap_power=int(config["video"]["pinout"]["cap"]), conv_power=int(config["video"]["pinout"]["conv"]), sync_delay=float(config["video"]["sync_delay"]), - cmd=str(config["video"]["cmd"]), + cmd=list(map(str, config["video"]["cmd"])), loop=loop, ) diff --git a/kvmd/kvmd/streamer.py b/kvmd/kvmd/streamer.py index 6e3ccffc..8cb5a486 100644 --- a/kvmd/kvmd/streamer.py +++ b/kvmd/kvmd/streamer.py @@ -1,6 +1,7 @@ import asyncio import asyncio.subprocess +from typing import List from typing import Optional from .logging import get_logger @@ -15,10 +16,12 @@ class Streamer: # pylint: disable=too-many-instance-attributes cap_power: int, conv_power: int, sync_delay: float, - cmd: str, + cmd: List[str], loop: asyncio.AbstractEventLoop, ) -> None: + assert cmd, cmd + self.__cap_power = gpio.set_output(cap_power) self.__conv_power = (gpio.set_output(conv_power) if conv_power > 0 else conv_power) self.__sync_delay = sync_delay @@ -60,8 +63,8 @@ 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: - proc = await asyncio.create_subprocess_shell( - self.__cmd, + proc = await asyncio.create_subprocess_exec( + *self.__cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT, ) @@ -105,7 +108,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes if proc.returncode is not None: raise await proc.wait() - get_logger().info("Streamer killed: pid=%d; retcode=%d") + get_logger().info("Streamer killed: pid=%d; retcode=%d", proc.pid, proc.returncode) except Exception: if proc.returncode is None: get_logger().exception("Can't kill streamer pid=%d", proc.pid) |