-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom classes for Process and Metrics (#13950)
* Subclass Process for audio_process * Introduce custom mp.Process subclass In preparation to switch the multiprocessing startup method away from "fork", we cannot rely on os.fork cloning the log state at fork time. Instead, we have to set up logging before we run the business logic of each process. * Make camera_metrics into a class * Make ptz_metrics into a class * Fixed PtzMotionEstimator.ptz_metrics type annotation * Removed pointless variables * Do not start audio processor when no audio cameras are configured
- Loading branch information
Showing
16 changed files
with
471 additions
and
448 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import multiprocessing as mp | ||
from multiprocessing.sharedctypes import Synchronized | ||
from multiprocessing.synchronize import Event | ||
from typing import Optional | ||
|
||
|
||
class CameraMetrics: | ||
camera_fps: Synchronized | ||
detection_fps: Synchronized | ||
detection_frame: Synchronized | ||
process_fps: Synchronized | ||
skipped_fps: Synchronized | ||
read_start: Synchronized | ||
audio_rms: Synchronized | ||
audio_dBFS: Synchronized | ||
|
||
frame_queue: mp.Queue | ||
|
||
process: Optional[mp.Process] | ||
capture_process: Optional[mp.Process] | ||
ffmpeg_pid: Synchronized | ||
|
||
def __init__(self): | ||
self.camera_fps = mp.Value("d", 0) | ||
self.detection_fps = mp.Value("d", 0) | ||
self.detection_frame = mp.Value("d", 0) | ||
self.process_fps = mp.Value("d", 0) | ||
self.skipped_fps = mp.Value("d", 0) | ||
self.read_start = mp.Value("d", 0) | ||
self.audio_rms = mp.Value("d", 0) | ||
self.audio_dBFS = mp.Value("d", 0) | ||
|
||
self.frame_queue = mp.Queue(maxsize=2) | ||
|
||
self.process = None | ||
self.capture_process = None | ||
self.ffmpeg_pid = mp.Value("i", 0) | ||
|
||
|
||
class PTZMetrics: | ||
autotracker_enabled: Synchronized | ||
|
||
start_time: Synchronized | ||
stop_time: Synchronized | ||
frame_time: Synchronized | ||
zoom_level: Synchronized | ||
max_zoom: Synchronized | ||
min_zoom: Synchronized | ||
|
||
tracking_active: Event | ||
motor_stopped: Event | ||
reset: Event | ||
|
||
def __init__(self, *, autotracker_enabled: bool): | ||
self.autotracker_enabled = mp.Value("i", autotracker_enabled) | ||
|
||
self.start_time = mp.Value("d", 0) | ||
self.stop_time = mp.Value("d", 0) | ||
self.frame_time = mp.Value("d", 0) | ||
self.zoom_level = mp.Value("d", 0) | ||
self.max_zoom = mp.Value("d", 0) | ||
self.min_zoom = mp.Value("d", 0) | ||
|
||
self.tracking_active = mp.Event() | ||
self.motor_stopped = mp.Event() | ||
self.reset = mp.Event() | ||
|
||
self.motor_stopped.set() |
Oops, something went wrong.