mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-15 07:35:27 +03:00
Do not start audio processor when no audio cameras are configured
This commit is contained in:
parent
9616d9a524
commit
4f3164c2ac
@ -6,7 +6,7 @@ import secrets
|
|||||||
import shutil
|
import shutil
|
||||||
from multiprocessing import Queue
|
from multiprocessing import Queue
|
||||||
from multiprocessing.synchronize import Event as MpEvent
|
from multiprocessing.synchronize import Event as MpEvent
|
||||||
from typing import Any
|
from typing import Any, Optional
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
import uvicorn
|
import uvicorn
|
||||||
@ -77,6 +77,8 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class FrigateApp:
|
class FrigateApp:
|
||||||
|
audio_process: Optional[mp.Process] = None
|
||||||
|
|
||||||
# TODO: Fix FrigateConfig usage, so we can properly annotate it here without mypy erroring out.
|
# TODO: Fix FrigateConfig usage, so we can properly annotate it here without mypy erroring out.
|
||||||
def __init__(self, config: Any) -> None:
|
def __init__(self, config: Any) -> None:
|
||||||
self.stop_event: MpEvent = mp.Event()
|
self.stop_event: MpEvent = mp.Event()
|
||||||
@ -439,8 +441,15 @@ class FrigateApp:
|
|||||||
capture_process.start()
|
capture_process.start()
|
||||||
logger.info(f"Capture process started for {name}: {capture_process.pid}")
|
logger.info(f"Capture process started for {name}: {capture_process.pid}")
|
||||||
|
|
||||||
def start_audio_processors(self) -> None:
|
def start_audio_processor(self) -> None:
|
||||||
self.audio_process = AudioProcessor(self.config, self.camera_metrics)
|
audio_cameras = [
|
||||||
|
c
|
||||||
|
for c in self.config.cameras.values()
|
||||||
|
if c.enabled and c.audio.enabled_in_config
|
||||||
|
]
|
||||||
|
|
||||||
|
if audio_cameras:
|
||||||
|
self.audio_process = AudioProcessor(audio_cameras, self.camera_metrics)
|
||||||
self.audio_process.start()
|
self.audio_process.start()
|
||||||
self.processes["audio_detector"] = self.audio_process.pid or 0
|
self.processes["audio_detector"] = self.audio_process.pid or 0
|
||||||
|
|
||||||
@ -580,7 +589,7 @@ class FrigateApp:
|
|||||||
self.start_detected_frames_processor()
|
self.start_detected_frames_processor()
|
||||||
self.start_camera_processors()
|
self.start_camera_processors()
|
||||||
self.start_camera_capture_processes()
|
self.start_camera_capture_processes()
|
||||||
self.start_audio_processors()
|
self.start_audio_processor()
|
||||||
self.start_storage_maintainer()
|
self.start_storage_maintainer()
|
||||||
self.init_external_event_processor()
|
self.init_external_event_processor()
|
||||||
self.start_stats_emitter()
|
self.start_stats_emitter()
|
||||||
@ -626,6 +635,7 @@ class FrigateApp:
|
|||||||
).execute()
|
).execute()
|
||||||
|
|
||||||
# stop the audio process
|
# stop the audio process
|
||||||
|
if self.audio_process:
|
||||||
self.audio_process.terminate()
|
self.audio_process.terminate()
|
||||||
self.audio_process.join()
|
self.audio_process.join()
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ from frigate.camera import CameraMetrics
|
|||||||
from frigate.comms.config_updater import ConfigSubscriber
|
from frigate.comms.config_updater import ConfigSubscriber
|
||||||
from frigate.comms.detections_updater import DetectionPublisher, DetectionTypeEnum
|
from frigate.comms.detections_updater import DetectionPublisher, DetectionTypeEnum
|
||||||
from frigate.comms.inter_process import InterProcessRequestor
|
from frigate.comms.inter_process import InterProcessRequestor
|
||||||
from frigate.config import CameraConfig, CameraInput, FfmpegConfig, FrigateConfig
|
from frigate.config import CameraConfig, CameraInput, FfmpegConfig
|
||||||
from frigate.const import (
|
from frigate.const import (
|
||||||
AUDIO_DURATION,
|
AUDIO_DURATION,
|
||||||
AUDIO_FORMAT,
|
AUDIO_FORMAT,
|
||||||
@ -68,18 +68,14 @@ def get_ffmpeg_command(ffmpeg: FfmpegConfig) -> list[str]:
|
|||||||
class AudioProcessor(util.Process):
|
class AudioProcessor(util.Process):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
config: FrigateConfig,
|
cameras: list[CameraConfig],
|
||||||
camera_metrics: dict[str, CameraMetrics],
|
camera_metrics: dict[str, CameraMetrics],
|
||||||
):
|
):
|
||||||
super().__init__(name="frigate.audio_manager", daemon=True)
|
super().__init__(name="frigate.audio_manager", daemon=True)
|
||||||
|
|
||||||
self.logger = logging.getLogger(self.name)
|
self.logger = logging.getLogger(self.name)
|
||||||
self.camera_metrics = camera_metrics
|
self.camera_metrics = camera_metrics
|
||||||
self.audio_cameras = [
|
self.cameras = cameras
|
||||||
c
|
|
||||||
for c in config.cameras.values()
|
|
||||||
if c.enabled and c.audio.enabled_in_config
|
|
||||||
]
|
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
stop_event = threading.Event()
|
stop_event = threading.Event()
|
||||||
@ -88,11 +84,11 @@ class AudioProcessor(util.Process):
|
|||||||
threading.current_thread().name = "process:audio_manager"
|
threading.current_thread().name = "process:audio_manager"
|
||||||
signal.signal(signal.SIGTERM, lambda sig, frame: sys.exit())
|
signal.signal(signal.SIGTERM, lambda sig, frame: sys.exit())
|
||||||
|
|
||||||
if len(self.audio_cameras) == 0:
|
if len(self.cameras) == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for camera in self.audio_cameras:
|
for camera in self.cameras:
|
||||||
audio_thread = AudioEventMaintainer(
|
audio_thread = AudioEventMaintainer(
|
||||||
camera,
|
camera,
|
||||||
self.camera_metrics,
|
self.camera_metrics,
|
||||||
@ -101,7 +97,7 @@ class AudioProcessor(util.Process):
|
|||||||
audio_threads.append(audio_thread)
|
audio_threads.append(audio_thread)
|
||||||
audio_thread.start()
|
audio_thread.start()
|
||||||
|
|
||||||
self.logger.info(f"Audio process started (pid: {self.pid})")
|
self.logger.info(f"Audio processor started (pid: {self.pid})")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
signal.pause()
|
signal.pause()
|
||||||
@ -116,7 +112,7 @@ class AudioProcessor(util.Process):
|
|||||||
for thread in audio_threads:
|
for thread in audio_threads:
|
||||||
if thread.is_alive():
|
if thread.is_alive():
|
||||||
self.logger.warning(f"Thread {thread.name} is still alive")
|
self.logger.warning(f"Thread {thread.name} is still alive")
|
||||||
self.logger.info("Exiting audio process")
|
self.logger.info("Exiting audio processor")
|
||||||
|
|
||||||
|
|
||||||
class AudioEventMaintainer(threading.Thread):
|
class AudioEventMaintainer(threading.Thread):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user