Skip to content

Commit 08b375e

Browse files
authored
feat(overlay): Add frame count threshold for auto-disable functionality (#71)
* feat(overlay): Add frame count threshold for auto-disable functionality - Introduced `frame_count_to_disable` parameter in OverlayConfig to specify the number of consecutive valid frames required before the overlay auto-disables. - Updated OverlayController to track consecutive received frames and conditionally disable loading based on the new threshold.
1 parent 56e901c commit 08b375e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pytrickle/frame_overlay.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ class OverlayConfig:
213213
progress: Optional[float] = None # Progress value 0.0-1.0 (None = animated)
214214
enabled: bool = True # Whether loading gating is active
215215
auto_timeout_seconds: Optional[float] = 1.5 # Seconds without output before overlay auto-enables
216+
frame_count_to_disable: int = 1 # Consecutive valid frames required before overlay auto-disables
216217

217218
def is_overlay_mode(self) -> bool:
218219
"""Return True if this config is set to overlay mode."""
@@ -232,13 +233,15 @@ def __init__(self, overlay_config: Optional[OverlayConfig]):
232233
self._loading_active = False
233234
self._is_manual_loading = False # Track if loading was set manually
234235
self._frame_counter = 0
236+
self._consecutive_received_frames = 0
235237

236238
def reset(self) -> None:
237239
"""Reset timing/state for a new stream."""
238240
self._last_video_frame_time = time.time()
239241
self._loading_active = False
240242
self._is_manual_loading = False
241243
self._frame_counter = 0
244+
self._consecutive_received_frames = 0
242245

243246
def update_and_apply(
244247
self,
@@ -290,10 +293,14 @@ def _update_loading_state(self, received_frame_from_processor: bool) -> None:
290293
now = time.time()
291294
if received_frame_from_processor:
292295
self._last_video_frame_time = now
293-
# Only auto-disable if loading was set automatically (not manually)
296+
# auto-disable if loading was set automatically (not manually enabled) and `frame_count_to_disable` threshold is reached
297+
self._consecutive_received_frames += 1
294298
if self._loading_active and not self._is_manual_loading:
295-
self._loading_active = False
299+
threshold = max(1, self.overlay_config.frame_count_to_disable)
300+
if self._consecutive_received_frames >= threshold:
301+
self._loading_active = False
296302
else:
303+
self._consecutive_received_frames = 0
297304
# Only auto-enable if not already manually enabled
298305
if not self._is_manual_loading:
299306
timeout = self.overlay_config.auto_timeout_seconds
@@ -310,6 +317,7 @@ def _disable_overlay(self) -> None:
310317
self._loading_active = False
311318
self._is_manual_loading = False
312319
self._frame_counter = 0
320+
self._consecutive_received_frames = 0
313321

314322
def _apply_loading_overlay(
315323
self,

0 commit comments

Comments
 (0)