mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 17:50:29 +08:00
refactoring
This commit is contained in:
parent
5589ecbac4
commit
c0ee171edb
@ -32,7 +32,12 @@ kvmd:
|
|||||||
|
|
||||||
shutdown_delay: 10.0
|
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:
|
logging:
|
||||||
version: 1
|
version: 1
|
||||||
|
|||||||
@ -30,7 +30,7 @@ def main() -> None:
|
|||||||
cap_power=int(config["video"]["pinout"]["cap"]),
|
cap_power=int(config["video"]["pinout"]["cap"]),
|
||||||
conv_power=int(config["video"]["pinout"]["conv"]),
|
conv_power=int(config["video"]["pinout"]["conv"]),
|
||||||
sync_delay=float(config["video"]["sync_delay"]),
|
sync_delay=float(config["video"]["sync_delay"]),
|
||||||
cmd=str(config["video"]["cmd"]),
|
cmd=list(map(str, config["video"]["cmd"])),
|
||||||
loop=loop,
|
loop=loop,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import asyncio.subprocess
|
import asyncio.subprocess
|
||||||
|
|
||||||
|
from typing import List
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from .logging import get_logger
|
from .logging import get_logger
|
||||||
@ -15,10 +16,12 @@ class Streamer: # pylint: disable=too-many-instance-attributes
|
|||||||
cap_power: int,
|
cap_power: int,
|
||||||
conv_power: int,
|
conv_power: int,
|
||||||
sync_delay: float,
|
sync_delay: float,
|
||||||
cmd: str,
|
cmd: List[str],
|
||||||
loop: asyncio.AbstractEventLoop,
|
loop: asyncio.AbstractEventLoop,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
|
assert cmd, cmd
|
||||||
|
|
||||||
self.__cap_power = gpio.set_output(cap_power)
|
self.__cap_power = gpio.set_output(cap_power)
|
||||||
self.__conv_power = (gpio.set_output(conv_power) if conv_power > 0 else conv_power)
|
self.__conv_power = (gpio.set_output(conv_power) if conv_power > 0 else conv_power)
|
||||||
self.__sync_delay = sync_delay
|
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
|
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:
|
||||||
proc = await asyncio.create_subprocess_shell(
|
proc = await asyncio.create_subprocess_exec(
|
||||||
self.__cmd,
|
*self.__cmd,
|
||||||
stdout=asyncio.subprocess.PIPE,
|
stdout=asyncio.subprocess.PIPE,
|
||||||
stderr=asyncio.subprocess.STDOUT,
|
stderr=asyncio.subprocess.STDOUT,
|
||||||
)
|
)
|
||||||
@ -105,7 +108,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
|
|||||||
if proc.returncode is not None:
|
if proc.returncode is not None:
|
||||||
raise
|
raise
|
||||||
await proc.wait()
|
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:
|
except Exception:
|
||||||
if proc.returncode is None:
|
if proc.returncode is None:
|
||||||
get_logger().exception("Can't kill streamer pid=%d", proc.pid)
|
get_logger().exception("Can't kill streamer pid=%d", proc.pid)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user