forked from Github/frigate
Rewrite events communication to use zmq instead of mp.Queue (#10627)
* Move to using zmq for events updating * Use event updater in manual events handler * Formatting
This commit is contained in:
@@ -6,24 +6,24 @@ import logging
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
from multiprocessing import Queue
|
||||
from typing import Optional
|
||||
|
||||
import cv2
|
||||
|
||||
from frigate.comms.events_updater import EventUpdatePublisher
|
||||
from frigate.config import CameraConfig, FrigateConfig
|
||||
from frigate.const import CLIPS_DIR
|
||||
from frigate.events.maintainer import EventTypeEnum
|
||||
from frigate.events.types import EventStateEnum, EventTypeEnum
|
||||
from frigate.util.image import draw_box_with_label
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ExternalEventProcessor:
|
||||
def __init__(self, config: FrigateConfig, queue: Queue) -> None:
|
||||
def __init__(self, config: FrigateConfig) -> None:
|
||||
self.config = config
|
||||
self.queue = queue
|
||||
self.default_thumbnail = None
|
||||
self.event_sender = EventUpdatePublisher()
|
||||
|
||||
def create_manual_event(
|
||||
self,
|
||||
@@ -48,10 +48,10 @@ class ExternalEventProcessor:
|
||||
camera_config, label, event_id, draw, snapshot_frame
|
||||
)
|
||||
|
||||
self.queue.put(
|
||||
self.event_sender.publish(
|
||||
(
|
||||
EventTypeEnum.api,
|
||||
"new",
|
||||
EventStateEnum.start,
|
||||
camera,
|
||||
{
|
||||
"id": event_id,
|
||||
@@ -77,8 +77,13 @@ class ExternalEventProcessor:
|
||||
|
||||
def finish_manual_event(self, event_id: str, end_time: float) -> None:
|
||||
"""Finish external event with indeterminate duration."""
|
||||
self.queue.put(
|
||||
(EventTypeEnum.api, "end", None, {"id": event_id, "end_time": end_time})
|
||||
self.event_sender.publish(
|
||||
(
|
||||
EventTypeEnum.api,
|
||||
EventStateEnum.end,
|
||||
None,
|
||||
{"id": event_id, "end_time": end_time},
|
||||
)
|
||||
)
|
||||
|
||||
def _write_images(
|
||||
@@ -135,3 +140,6 @@ class ExternalEventProcessor:
|
||||
thumb = cv2.resize(img_frame, dsize=(width, 175), interpolation=cv2.INTER_AREA)
|
||||
ret, jpg = cv2.imencode(".jpg", thumb)
|
||||
return base64.b64encode(jpg.tobytes()).decode("utf-8")
|
||||
|
||||
def stop(self):
|
||||
self.event_sender.stop()
|
||||
|
||||
Reference in New Issue
Block a user