summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-07-15 12:04:10 +0300
committerDevaev Maxim <[email protected]>2018-07-15 12:04:10 +0300
commit25ddee3fb14f94242c6bb466f22cef37962c1620 (patch)
tree7b84c8e684b6a4b1b620111713de8753ff570ed4 /kvmd
parentfbf3f1981a5380b95bb1aaa6fb70ca3b55e86bc9 (diff)
initial restart streamer for crappy video devices
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/configs/kvmd/v1.yaml1
-rw-r--r--kvmd/kvmd/__init__.py1
-rw-r--r--kvmd/kvmd/server.py2
-rw-r--r--kvmd/kvmd/streamer.py34
-rw-r--r--kvmd/testenv/kvmd.yaml1
5 files changed, 28 insertions, 11 deletions
diff --git a/kvmd/configs/kvmd/v1.yaml b/kvmd/configs/kvmd/v1.yaml
index b6dd033d..5d1fc783 100644
--- a/kvmd/configs/kvmd/v1.yaml
+++ b/kvmd/configs/kvmd/v1.yaml
@@ -33,6 +33,7 @@ kvmd:
sync_delay: 1.0
init_delay: 1.0
+ init_restart_after: 1.0
shutdown_delay: 10.0
size:
diff --git a/kvmd/kvmd/__init__.py b/kvmd/kvmd/__init__.py
index 8288e8e3..f21c1d90 100644
--- a/kvmd/kvmd/__init__.py
+++ b/kvmd/kvmd/__init__.py
@@ -44,6 +44,7 @@ def main() -> None:
conv_power=int(config["streamer"]["pinout"]["conv"]),
sync_delay=float(config["streamer"]["sync_delay"]),
init_delay=float(config["streamer"]["init_delay"]),
+ init_restart_after=float(config["streamer"]["init_restart_after"]),
width=int(config["streamer"]["size"]["width"]),
height=int(config["streamer"]["size"]["height"]),
cmd=list(map(str, config["streamer"]["cmd"])),
diff --git a/kvmd/kvmd/server.py b/kvmd/kvmd/server.py
index ae5ec14d..e8d69cc7 100644
--- a/kvmd/kvmd/server.py
+++ b/kvmd/kvmd/server.py
@@ -285,7 +285,7 @@ class Server: # pylint: disable=too-many-instance-attributes
if self.__reset_streamer:
if self.__streamer.is_running():
await self.__streamer.stop()
- await self.__streamer.start()
+ await self.__streamer.start(no_init_restart=True)
self.__reset_streamer = False
prev = cur
diff --git a/kvmd/kvmd/streamer.py b/kvmd/kvmd/streamer.py
index 941519ab..32cc60ab 100644
--- a/kvmd/kvmd/streamer.py
+++ b/kvmd/kvmd/streamer.py
@@ -18,6 +18,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
conv_power: int,
sync_delay: float,
init_delay: float,
+ init_restart_after: float,
width: int,
height: int,
@@ -30,6 +31,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes
self.__conv_power = (gpio.set_output(conv_power) if conv_power > 0 else conv_power)
self.__sync_delay = sync_delay
self.__init_delay = init_delay
+ self.__init_restart_after = init_restart_after
self.__width = width
self.__height = height
@@ -39,19 +41,19 @@ class Streamer: # pylint: disable=too-many-instance-attributes
self.__proc_task: Optional[asyncio.Task] = None
- async def start(self) -> None:
- assert not self.__proc_task
- get_logger().info("Starting streamer ...")
- await self.__set_hw_enabled(True)
- self.__proc_task = self.__loop.create_task(self.__process())
+ async def start(self, no_init_restart: bool=False) -> None:
+ logger = get_logger()
+ logger.info("Starting streamer ...")
+ await self.__inner_start()
+ if self.__init_restart_after > 0.0 and not no_init_restart:
+ logger.info("Stopping streamer to restart ...")
+ await self.__inner_stop()
+ logger.info("Starting again ...")
+ await self.__inner_start()
async def stop(self) -> None:
- assert self.__proc_task
get_logger().info("Stopping streamer ...")
- self.__proc_task.cancel()
- await asyncio.gather(self.__proc_task, return_exceptions=True)
- await self.__set_hw_enabled(False)
- self.__proc_task = None
+ await self.__inner_stop()
def is_running(self) -> bool:
return bool(self.__proc_task)
@@ -69,6 +71,18 @@ class Streamer: # pylint: disable=too-many-instance-attributes
if self.is_running():
await self.stop()
+ async def __inner_start(self) -> None:
+ assert not self.__proc_task
+ await self.__set_hw_enabled(True)
+ self.__proc_task = self.__loop.create_task(self.__process())
+
+ async def __inner_stop(self) -> None:
+ assert self.__proc_task
+ self.__proc_task.cancel()
+ await asyncio.gather(self.__proc_task, return_exceptions=True)
+ await self.__set_hw_enabled(False)
+ self.__proc_task = None
+
async def __set_hw_enabled(self, enabled: bool) -> None:
# XXX: This sequence is very important to enable converter and cap board
if self.__cap_power > 0:
diff --git a/kvmd/testenv/kvmd.yaml b/kvmd/testenv/kvmd.yaml
index fdf9abe2..e1773847 100644
--- a/kvmd/testenv/kvmd.yaml
+++ b/kvmd/testenv/kvmd.yaml
@@ -33,6 +33,7 @@ kvmd:
sync_delay: 1.0
init_delay: 1.0
+ init_restart_after: 1.0
shutdown_delay: 10.0
size: