diff options
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/apps/__init__.py | 12 | ||||
-rw-r--r-- | kvmd/apps/cleanup/__init__.py | 3 | ||||
-rw-r--r-- | kvmd/apps/kvmd/server.py | 4 | ||||
-rw-r--r-- | kvmd/apps/kvmd/streamer.py | 50 |
4 files changed, 15 insertions, 54 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index e95342e8..ac140466 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -92,7 +92,6 @@ from ..validators.kvm import valid_ugpio_mode from ..validators.kvm import valid_ugpio_view_table from ..validators.hw import valid_gpio_pin -from ..validators.hw import valid_gpio_pin_optional from ..validators.hw import valid_otg_gadget from ..validators.hw import valid_otg_id @@ -313,14 +312,9 @@ def _get_config_scheme() -> Dict: }, "streamer": { - "cap_pin": Option(-1, type=valid_gpio_pin_optional), - "conv_pin": Option(-1, type=valid_gpio_pin_optional), - - "sync_delay": Option(0.0, type=valid_float_f0), - "init_delay": Option(1.0, type=valid_float_f0), - "init_restart_after": Option(0.0, type=valid_float_f0), - "shutdown_delay": Option(10.0, type=valid_float_f01), - "state_poll": Option(1.0, type=valid_float_f01), + "reset_delay": Option(1.0, type=valid_float_f0), + "shutdown_delay": Option(10.0, type=valid_float_f01), + "state_poll": Option(1.0, type=valid_float_f01), "quality": Option(80, type=(lambda arg: (valid_stream_quality(arg) if arg else 0))), # 0 for disabled feature "desired_fps": Option(30, type=valid_stream_fps), diff --git a/kvmd/apps/cleanup/__init__.py b/kvmd/apps/cleanup/__init__.py index 708e3399..5b6f2860 100644 --- a/kvmd/apps/cleanup/__init__.py +++ b/kvmd/apps/cleanup/__init__.py @@ -57,9 +57,6 @@ def _clear_gpio(config: Section) -> None: ("msd_relay/target", config.msd.target_pin), ("msd_relay/reset", config.msd.reset_pin), ] if config.msd.type == "relay" else []), - - ("streamer/cap", config.streamer.cap_pin), - ("streamer/conv", config.streamer.conv_pin), ]: if pin >= 0: logger.info("Writing 0 to GPIO pin=%d (%s)", pin, name) diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py index f50c3688..3e3bf4a2 100644 --- a/kvmd/apps/kvmd/server.py +++ b/kvmd/apps/kvmd/server.py @@ -401,7 +401,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins while True: cur = (self.__has_stream_clients() or self.__snapshoter.snapshoting()) if not prev and cur: - await self.__streamer.ensure_start(init_restart=True) + await self.__streamer.ensure_start(reset=False) elif prev and not cur: await self.__streamer.ensure_stop(immediately=False) @@ -412,7 +412,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins self.__streamer.set_params(self.__new_streamer_params) self.__new_streamer_params = {} if start: - await self.__streamer.ensure_start(init_restart=False) + await self.__streamer.ensure_start(reset=self.__reset_streamer) self.__reset_streamer = False prev = cur diff --git a/kvmd/apps/kvmd/streamer.py b/kvmd/apps/kvmd/streamer.py index e2c0442c..afddb1db 100644 --- a/kvmd/apps/kvmd/streamer.py +++ b/kvmd/apps/kvmd/streamer.py @@ -40,7 +40,6 @@ from ... import tools from ... import aiotools from ... import aioproc from ... import htclient -from ... import gpio # ===== @@ -120,12 +119,8 @@ class _StreamerParams: class Streamer: # pylint: disable=too-many-instance-attributes def __init__( # pylint: disable=too-many-arguments,too-many-locals self, - cap_pin: int, - conv_pin: int, - sync_delay: float, - init_delay: float, - init_restart_after: float, + reset_delay: float, shutdown_delay: float, state_poll: float, @@ -141,12 +136,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes **params_kwargs: Any, ) -> None: - self.__cap_pin = (gpio.set_output(cap_pin, False) if cap_pin >= 0 else -1) - self.__conv_pin = (gpio.set_output(conv_pin, False) if conv_pin >= 0 else -1) - - self.__sync_delay = sync_delay - self.__init_delay = init_delay - self.__init_restart_after = init_restart_after + self.__reset_delay = reset_delay self.__shutdown_delay = shutdown_delay self.__state_poll = state_poll @@ -177,7 +167,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes # ===== @aiotools.atomic - async def ensure_start(self, init_restart: bool) -> None: + async def ensure_start(self, reset: bool) -> None: if not self.__streamer_task or self.__stop_task: logger = get_logger(0) @@ -190,14 +180,11 @@ class Streamer: # pylint: disable=too-many-instance-attributes else: await asyncio.gather(self.__stop_task, return_exceptions=True) + if reset and self.__reset_delay > 0: + logger.info("Waiting %.2f seconds for reset delay ...", self.__reset_delay) + await asyncio.sleep(self.__reset_delay) logger.info("Starting streamer ...") await self.__inner_start() - if self.__init_restart_after > 0.0 and init_restart: - await asyncio.sleep(self.__init_restart_after) - logger.info("Stopping streamer to restart ...") - await self.__inner_stop() - logger.info("Starting again ...") - await self.__inner_start() @aiotools.atomic async def ensure_stop(self, immediately: bool) -> None: @@ -344,13 +331,10 @@ class Streamer: # pylint: disable=too-many-instance-attributes @aiotools.atomic async def cleanup(self) -> None: - try: - await self.ensure_stop(immediately=True) - if self.__http_session: - await self.__http_session.close() - self.__http_session = None - finally: - await self.__set_hw_enabled(False) + await self.ensure_stop(immediately=True) + if self.__http_session: + await self.__http_session.close() + self.__http_session = None # ===== @@ -374,7 +358,6 @@ class Streamer: # pylint: disable=too-many-instance-attributes @aiotools.atomic async def __inner_start(self) -> None: assert not self.__streamer_task - await self.__set_hw_enabled(True) self.__streamer_task = asyncio.create_task(self.__streamer_task_loop()) @aiotools.atomic @@ -383,21 +366,8 @@ class Streamer: # pylint: disable=too-many-instance-attributes self.__streamer_task.cancel() await asyncio.gather(self.__streamer_task, return_exceptions=True) await self.__kill_streamer_proc() - await self.__set_hw_enabled(False) self.__streamer_task = None - @aiotools.atomic - async def __set_hw_enabled(self, enabled: bool) -> None: - # XXX: This sequence is very important to enable converter and cap board - if self.__cap_pin >= 0: - gpio.write(self.__cap_pin, enabled) - if self.__conv_pin >= 0: - if enabled: - await asyncio.sleep(self.__sync_delay) - gpio.write(self.__conv_pin, enabled) - if enabled: - await asyncio.sleep(self.__init_delay) - # ===== async def __streamer_task_loop(self) -> None: # pylint: disable=too-many-branches |