From 5f7ca2b124151a0398aa9d5843db8dbf6994f602 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Wed, 14 Feb 2024 07:34:41 -0700 Subject: [PATCH] Cleanup port defining --- frigate/comms/inter_process.py | 3 ++- frigate/events/audio.py | 9 ++------- frigate/output/preview.py | 7 ++----- frigate/record/maintainer.py | 6 +----- frigate/video.py | 8 ++------ 5 files changed, 9 insertions(+), 24 deletions(-) diff --git a/frigate/comms/inter_process.py b/frigate/comms/inter_process.py index 94f328154..c312bf869 100644 --- a/frigate/comms/inter_process.py +++ b/frigate/comms/inter_process.py @@ -56,7 +56,8 @@ class InterProcessCommunicator(Communicator): class InterProcessRequestor: """Simplifies sending data to InterProcessCommunicator and getting a reply.""" - def __init__(self, port: int) -> None: + def __init__(self) -> None: + port = os.environ.get("INTER_PROCESS_COMM_PORT") or PORT_INTER_PROCESS_COMM self.context = zmq.Context() self.socket = self.context.socket(zmq.REQ) self.socket.connect(f"tcp://127.0.0.1:{port}") diff --git a/frigate/events/audio.py b/frigate/events/audio.py index 2d8faf9a4..a28b00e68 100644 --- a/frigate/events/audio.py +++ b/frigate/events/audio.py @@ -3,7 +3,6 @@ import datetime import logging import multiprocessing as mp -import os import signal import threading import time @@ -23,7 +22,6 @@ from frigate.const import ( AUDIO_MIN_CONFIDENCE, AUDIO_SAMPLE_RATE, FRIGATE_LOCALHOST, - PORT_INTER_PROCESS_COMM, ) from frigate.ffmpeg_presets import parse_preset_input from frigate.log import LogPipe @@ -191,11 +189,8 @@ class AudioEventMaintainer(threading.Thread): self.logpipe = LogPipe(f"ffmpeg.{self.config.name}.audio") self.audio_listener = None - # create communication for finished previews - INTER_PROCESS_COMM_PORT = ( - os.environ.get("INTER_PROCESS_COMM_PORT") or PORT_INTER_PROCESS_COMM - ) - self.requestor = InterProcessRequestor(INTER_PROCESS_COMM_PORT) + # create communication for audio detections + self.requestor = InterProcessRequestor() def detect_audio(self, audio) -> None: if not self.feature_metrics[self.config.name]["audio_enabled"].value: diff --git a/frigate/output/preview.py b/frigate/output/preview.py index 2794be2bc..61ca248b7 100644 --- a/frigate/output/preview.py +++ b/frigate/output/preview.py @@ -13,7 +13,7 @@ import numpy as np from frigate.comms.inter_process import InterProcessRequestor from frigate.config import CameraConfig, RecordQualityEnum -from frigate.const import CACHE_DIR, CLIPS_DIR, INSERT_PREVIEW, PORT_INTER_PROCESS_COMM +from frigate.const import CACHE_DIR, CLIPS_DIR, INSERT_PREVIEW from frigate.ffmpeg_presets import ( FPS_VFR_PARAM, EncodeTypeEnum, @@ -137,10 +137,7 @@ class PreviewRecorder: ) # create communication for finished previews - INTER_PROCESS_COMM_PORT = ( - os.environ.get("INTER_PROCESS_COMM_PORT") or PORT_INTER_PROCESS_COMM - ) - self.requestor = InterProcessRequestor(INTER_PROCESS_COMM_PORT) + self.requestor = InterProcessRequestor() y, u1, u2, v1, v2 = get_yuv_crop( self.config.frame_shape_yuv, diff --git a/frigate/record/maintainer.py b/frigate/record/maintainer.py index f2f7d42c5..a67d84c16 100644 --- a/frigate/record/maintainer.py +++ b/frigate/record/maintainer.py @@ -25,7 +25,6 @@ from frigate.const import ( INSERT_MANY_RECORDINGS, MAX_SEGMENT_DURATION, MAX_SEGMENTS_IN_CACHE, - PORT_INTER_PROCESS_COMM, RECORD_DIR, ) from frigate.models import Event, Recordings @@ -71,10 +70,7 @@ class RecordingMaintainer(threading.Thread): self.config = config # create communication for retained recordings - INTER_PROCESS_COMM_PORT = ( - os.environ.get("INTER_PROCESS_COMM_PORT") or PORT_INTER_PROCESS_COMM - ) - self.requestor = InterProcessRequestor(INTER_PROCESS_COMM_PORT) + self.requestor = InterProcessRequestor() self.object_recordings_info_queue = object_recordings_info_queue self.audio_recordings_info_queue = audio_recordings_info_queue diff --git a/frigate/video.py b/frigate/video.py index dad498618..774da4c99 100755 --- a/frigate/video.py +++ b/frigate/video.py @@ -18,7 +18,6 @@ from frigate.const import ( ATTRIBUTE_LABEL_MAP, CACHE_DIR, CACHE_SEGMENT_FORMAT, - PORT_INTER_PROCESS_COMM, REQUEST_REGION_GRID, ) from frigate.log import LogPipe @@ -433,11 +432,8 @@ def track_camera( frame_manager = SharedMemoryFrameManager() - # create communication for finished previews - INTER_PROCESS_COMM_PORT = ( - os.environ.get("INTER_PROCESS_COMM_PORT") or PORT_INTER_PROCESS_COMM - ) - requestor = InterProcessRequestor(INTER_PROCESS_COMM_PORT) + # create communication for region grid updates + requestor = InterProcessRequestor() process_frames( name,